Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
HertzDevil committed Sep 19, 2024
1 parent 66c330e commit da520f5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
2 changes: 0 additions & 2 deletions spec/compiler/codegen/debug_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,6 @@ describe "Code gen: debug" do

it "has debug info in closure inside if (#5593)" do
codegen(%(
require "prelude"
def foo
if true && true
yield 1
Expand Down
16 changes: 16 additions & 0 deletions src/compiler/crystal/codegen/debug.cr
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,16 @@ module Crystal
old_debug_location = @current_debug_location
set_current_debug_location location
if builder.current_debug_location != llvm_nil && (ptr = alloca)
# FIXME: When debug records are used instead of debug intrinsics, it
# seems inserting them into an empty BasicBlock will instead place them
# in a totally different (next?) function where the variable doesn't
# exist, leading to a "function-local metadata used in wrong function"
# validation error. This might happen when e.g. all variables inside a
# block are closured. Ideally every debug record should immediately
# follow the variable it declares.
{% unless LibLLVM::IS_LT_190 %}
call(do_nothing_fun) if block.instructions.empty?
{% end %}
di_builder.insert_declare_at_end(ptr, var, expr, builder.current_debug_location_metadata, block)
set_current_debug_location old_debug_location
true
Expand All @@ -376,6 +386,12 @@ module Crystal
end
end

private def do_nothing_fun
fetch_typed_fun(@llvm_mod, "llvm.donothing") do
LLVM::Type.function([] of LLVM::Type, @llvm_context.void)
end
end

# Emit debug info for toplevel variables. Used for the main module and all
# required files.
def emit_vars_debug_info(vars)
Expand Down
9 changes: 7 additions & 2 deletions src/intrinsics.cr
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,13 @@ lib LibIntrinsics
{% if flag?(:interpreted) %} @[Primitive(:interpreter_intrinsics_fshr128)] {% end %}
fun fshr128 = "llvm.fshr.i128"(a : UInt128, b : UInt128, count : UInt128) : UInt128

fun va_start = "llvm.va_start"(ap : Void*)
fun va_end = "llvm.va_end"(ap : Void*)
{% if compare_versions(Crystal::LLVM_VERSION, "19.1.0") < 0 %}
fun va_start = "llvm.va_start"(ap : Void*)
fun va_end = "llvm.va_end"(ap : Void*)
{% else %}
fun va_start = "llvm.va_start.p0"(ap : Void*)
fun va_end = "llvm.va_end.p0"(ap : Void*)
{% end %}

{% if flag?(:i386) || flag?(:x86_64) %}
{% if flag?(:interpreted) %} @[Primitive(:interpreter_intrinsics_pause)] {% end %}
Expand Down

0 comments on commit da520f5

Please sign in to comment.