Skip to content

Commit

Permalink
Fixed #4202: missing debug location for pointer malloc primitive
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite committed Mar 28, 2017
1 parent 857743a commit 9be7840
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/compiler/crystal/codegen/primitives.cr
Expand Up @@ -423,11 +423,22 @@ class Crystal::CodeGenVisitor
def codegen_primitive_pointer_malloc(node, target_def, call_args)
type = node.type.as(PointerInstanceType)
llvm_type = llvm_embedded_type(type.element_type)

old_debug_location = @current_debug_location
if @debug.line_numbers? && (location = node.location)
set_current_debug_location(node.location)
end

if type.element_type.has_inner_pointers?
last = array_malloc(llvm_type, call_args[1])
else
last = array_malloc_atomic(llvm_type, call_args[1])
end

if @debug.line_numbers?
set_current_debug_location(old_debug_location)
end

last
end

Expand Down
5 changes: 4 additions & 1 deletion src/compiler/crystal/semantic/top_level_visitor.cr
Expand Up @@ -355,7 +355,10 @@ class Crystal::TopLevelVisitor < Crystal::SemanticVisitor
node.raise "method marked as Primitive must have an empty body"
end

node.body = Primitive.new(value)
primitive = Primitive.new(value)
primitive.location = node.location

node.body = primitive
end

def visit(node : Include)
Expand Down

0 comments on commit 9be7840

Please sign in to comment.