Skip to content

Commit 9be7840

Browse files
author
Ary Borenszweig
committedMar 28, 2017
Fixed #4202: missing debug location for pointer malloc primitive
1 parent 857743a commit 9be7840

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed
 

‎src/compiler/crystal/codegen/primitives.cr

+11
Original file line numberDiff line numberDiff line change
@@ -423,11 +423,22 @@ class Crystal::CodeGenVisitor
423423
def codegen_primitive_pointer_malloc(node, target_def, call_args)
424424
type = node.type.as(PointerInstanceType)
425425
llvm_type = llvm_embedded_type(type.element_type)
426+
427+
old_debug_location = @current_debug_location
428+
if @debug.line_numbers? && (location = node.location)
429+
set_current_debug_location(node.location)
430+
end
431+
426432
if type.element_type.has_inner_pointers?
427433
last = array_malloc(llvm_type, call_args[1])
428434
else
429435
last = array_malloc_atomic(llvm_type, call_args[1])
430436
end
437+
438+
if @debug.line_numbers?
439+
set_current_debug_location(old_debug_location)
440+
end
441+
431442
last
432443
end
433444

‎src/compiler/crystal/semantic/top_level_visitor.cr

+4-1
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,10 @@ class Crystal::TopLevelVisitor < Crystal::SemanticVisitor
355355
node.raise "method marked as Primitive must have an empty body"
356356
end
357357

358-
node.body = Primitive.new(value)
358+
primitive = Primitive.new(value)
359+
primitive.location = node.location
360+
361+
node.body = primitive
359362
end
360363

361364
def visit(node : Include)

0 commit comments

Comments
 (0)
Please sign in to comment.