Skip to content

Commit

Permalink
Fix debug locations for Proc pointers (#11243)
Browse files Browse the repository at this point in the history
  • Loading branch information
HertzDevil authored Sep 29, 2021
1 parent 735f791 commit 9a3f938
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
11 changes: 11 additions & 0 deletions spec/llvm-ir/proc-pointer-debug-loc.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def foo
end

(->foo).call

# CHECK: define internal void @"~procProc(Nil)
# CHECK-SAME: !dbg [[LOC1:![0-9]+]]
# CHECK-NEXT: entry:
# CHECK-NEXT: ret void, !dbg [[LOC2:![0-9]+]]
# CHECK-NEXT: }
# CHECK: [[LOC2]] = !DILocation(line: 4, column: 2, scope: [[LOC1]])
28 changes: 16 additions & 12 deletions spec/llvm-ir/test.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#!/bin/sh
#!/bin/bash

set -euo pipefail

SCRIPT_PATH="$(realpath "$0")"
SCRIPT_ROOT="$(dirname "$SCRIPT_PATH")"

BUILD_DIR=$SCRIPT_ROOT/../../.build
LLVM_CONFIG="$(basename $($SCRIPT_ROOT/../../src/llvm/ext/find-llvm-config))"
FILE_CHECK=FileCheck-"${LLVM_CONFIG#llvm-config-}"
crystal=$SCRIPT_ROOT/../../bin/crystal

mkdir -p $BUILD_DIR
Expand All @@ -16,30 +18,32 @@ function test() {
input_cr="$SCRIPT_ROOT/$1"
output_ll="$BUILD_DIR/${1%.cr}.ll"
compiler_options="$2"
check_prefix="$3"
check_prefix="${3+--check-prefix $3}"

# $BUILD_DIR/test-ir is never used
# pushd $BUILD_DIR + $output_ll is a workaround due to the fact that we can't control
# the filename generated by --emit=llvm-ir
$crystal build --single-module --no-debug --no-color --emit=llvm-ir $2 -o $BUILD_DIR/test-ir $input_cr
FileCheck $input_cr --input-file $output_ll --check-prefix $check_prefix
$crystal build --single-module --no-color --emit=llvm-ir $2 -o $BUILD_DIR/test-ir $input_cr
$FILE_CHECK $input_cr --input-file $output_ll $check_prefix

rm $BUILD_DIR/test-ir.o
rm $output_ll
}

pushd $BUILD_DIR >/dev/null

test memset.cr "--cross-compile --target i386-apple-darwin --prelude=empty" X32
test memset.cr "--cross-compile --target i386-unknown-linux-gnu --prelude=empty" X32
test memset.cr "--cross-compile --target x86_64-apple-darwin --prelude=empty" X64
test memset.cr "--cross-compile --target x86_64-unknown-linux-gnu --prelude=empty" X64
test proc-pointer-debug-loc.cr "--cross-compile --target x86_64-unknown-linux-gnu --prelude=empty"

test memcpy.cr "--cross-compile --target x86_64-apple-darwin --prelude=empty" X64
test memcpy.cr "--cross-compile --target x86_64-unknown-linux-gnu --prelude=empty" X64
test memset.cr "--cross-compile --target i386-apple-darwin --prelude=empty --no-debug" X32
test memset.cr "--cross-compile --target i386-unknown-linux-gnu --prelude=empty --no-debug" X32
test memset.cr "--cross-compile --target x86_64-apple-darwin --prelude=empty --no-debug" X64
test memset.cr "--cross-compile --target x86_64-unknown-linux-gnu --prelude=empty --no-debug" X64

test cast-unions.cr "--cross-compile --target x86_64-apple-darwin --prelude=empty" X64
test assign-unions.cr "--cross-compile --target x86_64-apple-darwin --prelude=empty" X64
test memcpy.cr "--cross-compile --target x86_64-apple-darwin --prelude=empty --no-debug" X64
test memcpy.cr "--cross-compile --target x86_64-unknown-linux-gnu --prelude=empty --no-debug" X64

test cast-unions.cr "--cross-compile --target x86_64-apple-darwin --prelude=empty --no-debug" X64
test assign-unions.cr "--cross-compile --target x86_64-apple-darwin --prelude=empty --no-debug" X64

popd >/dev/null

2 changes: 1 addition & 1 deletion src/compiler/crystal/semantic/literal_expander.cr
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ module Crystal
end

body = Call.new(obj, node.name, call_args).at(node)
proc_literal = ProcLiteral.new(Def.new("->", def_args, body)).at(node)
proc_literal = ProcLiteral.new(Def.new("->", def_args, body).at(node)).at(node)
proc_literal.proc_pointer = node

if assign
Expand Down

0 comments on commit 9a3f938

Please sign in to comment.