Skip to content

Commit

Permalink
Attach debug locations to auto-generated initialize methods (#11313)
Browse files Browse the repository at this point in the history
  • Loading branch information
HertzDevil authored Oct 28, 2021
1 parent 8a8e36d commit 40fe965
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
11 changes: 11 additions & 0 deletions spec/llvm-ir/argless-initialize-debug-loc.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Foo(T)
# CHECK: define internal %"Foo(Int32)"* @"*Foo(Int32)@Foo(T)::new:Foo(Int32)"(i32 %self)
# CHECK-SAME: !dbg [[LOC1:![0-9]+]]
# CHECK-NEXT: alloca:
# CHECK-NEXT: %_ = alloca %"Foo(Int32)"*
# CHECK-SAME: !dbg [[LOC2:![0-9]+]]
# CHECK: [[LOC2]] = !DILocation
# CHECK-SAME: scope: [[LOC1]]
end

Foo(Int32).new
1 change: 1 addition & 0 deletions spec/llvm-ir/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function test() {

pushd $BUILD_DIR >/dev/null

test argless-initialize-debug-loc.cr "--cross-compile --target x86_64-unknown-linux-gnu --prelude=empty"
test proc-pointer-debug-loc.cr "--cross-compile --target x86_64-unknown-linux-gnu --prelude=empty"

test memset.cr "--cross-compile --target i386-apple-darwin --prelude=empty --no-debug" X32
Expand Down
9 changes: 5 additions & 4 deletions src/compiler/crystal/semantic/new.cr
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ module Crystal

# Also add `initialize`, so `super` in a subclass
# inside an `initialize` will find this one
type.add_def Def.argless_initialize
type.add_def Def.argless_initialize(type)
end

# Check to see if a type doesn't define `initialize`
Expand All @@ -86,7 +86,7 @@ module Crystal
# If the type has `self.new()`, don't override it
unless has_default_self_new
type.metaclass.as(ModuleType).add_def(Def.argless_new(type))
type.add_def(Def.argless_initialize)
type.add_def(Def.argless_initialize(type))
end
else
initialize_owner = nil
Expand Down Expand Up @@ -252,8 +252,9 @@ module Crystal
a_def
end

def self.argless_initialize
Def.new("initialize", body: Nop.new)
def self.argless_initialize(instance_type)
loc = instance_type.locations.try &.first?
Def.new("initialize", body: Nop.new).at(loc)
end

def expand_new_default_arguments(instance_type, args_size, named_args)
Expand Down

0 comments on commit 40fe965

Please sign in to comment.