Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

complier bug with --debug v1.2.1 #11385

Closed
will opened this issue Oct 29, 2021 · 9 comments · Fixed by #11390
Closed

complier bug with --debug v1.2.1 #11385

will opened this issue Oct 29, 2021 · 9 comments · Fixed by #11390
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:codegen

Comments

@will
Copy link
Contributor

will commented Oct 29, 2021

With CrunchyData/bridge-cli@cafeb92

On

~/c/cb (compilerbug)> crystal version
Crystal 1.2.1 (2021-10-21)

LLVM: 11.1.0
Default target: x86_64-apple-macosx

A normal build works fine

~/c/cb (compilerbug)> crystal build -o bin/cb src/cli.cr --progress --error-trace

but adding --debug causes a nil assertion error

~/c/cb (compilerbug)> crystal build -o bin/cb src/cli.cr --progress --error-trace --debug
Nil assertion failed (NilAssertionError)
  from raise<NilAssertionError>:NoReturn
  from Nil#not_nil!:NoReturn
  from Crystal::CodeGenVisitor#get_debug_type<Crystal::Type+, Crystal::Type+>:(LibLLVM::MetadataRef | Nil)
  from Crystal::CodeGenVisitor#get_debug_type<Crystal::Type+, Crystal::Type+>:(LibLLVM::MetadataRef | Nil)
  from Crystal::CodeGenVisitor#get_debug_type<Crystal::Type+, Crystal::Type+>:(LibLLVM::MetadataRef | Nil)
  from Crystal::CodeGenVisitor#get_debug_type<Crystal::Type+, Crystal::Type+>:(LibLLVM::MetadataRef | Nil)
  from Crystal::CodeGenVisitor#get_debug_type<Crystal::Type+, Crystal::Type+>:(LibLLVM::MetadataRef | Nil)
  from Crystal::CodeGenVisitor#get_debug_type<Crystal::Type+, Crystal::Type+>:(LibLLVM::MetadataRef | Nil)
  from Crystal::CodeGenVisitor#get_debug_type<Crystal::Type+, Crystal::Type+>:(LibLLVM::MetadataRef | Nil)
  from Crystal::CodeGenVisitor#codegen_fun_signature_non_external<String, Crystal::Def+, Crystal::Type+, Bool, Bool>:Array(Crystal::Arg)
  from Crystal::CodeGenVisitor#codegen_fun<String, Crystal::Def+, Crystal::Type+, Bool, Crystal::CodeGenVisitor::ModuleInfo, Bool, Bool>:LLVM::Function
  from Crystal::CodeGenVisitor#target_def_fun<Crystal::Def+, Crystal::Type+>:LLVM::Function
  from Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::CodeGenVisitor#run_instance_vars_initializers<Crystal::Type+, (Crystal::ClassType+ | Crystal::GenericClassInstanceType+), LLVM::Value>:Nil
  from Crystal::CodeGenVisitor#allocate_aggregate<Crystal::Type+>:LLVM::Value
  from Crystal::CodeGenVisitor#codegen_primitive_allocate<Crystal::Primitive+, Crystal::Def+, Array(LLVM::Value)>:LLVM::Value
  from Crystal::CodeGenVisitor#codegen_primitive<Crystal::Call, Crystal::Primitive+, Crystal::Def+, Array(LLVM::Value)>:Nil
  from Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::CodeGenVisitor#visit<Crystal::Assign>:(Bool | Nil)
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::CodeGenVisitor#codegen_fun<String, Crystal::Def+, Crystal::Type+, Bool, Crystal::CodeGenVisitor::ModuleInfo, Bool, Bool>:LLVM::Function
  from Crystal::CodeGenVisitor#target_def_fun<Crystal::Def+, Crystal::Type+>:LLVM::Function
  from Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::CodeGenVisitor#run_instance_vars_initializers<Crystal::Type+, (Crystal::ClassType+ | Crystal::GenericClassInstanceType+), LLVM::Value>:Nil
  from Crystal::CodeGenVisitor#allocate_aggregate<Crystal::Type+>:LLVM::Value
  from Crystal::CodeGenVisitor#codegen_primitive_allocate<Crystal::Primitive+, Crystal::Def+, Array(LLVM::Value)>:LLVM::Value
  from Crystal::CodeGenVisitor#codegen_primitive<Crystal::Call, Crystal::Primitive+, Crystal::Def+, Array(LLVM::Value)>:Nil
  from Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::CodeGenVisitor#visit<Crystal::Assign>:(Bool | Nil)
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::CodeGenVisitor#codegen_fun<String, Crystal::Def+, Crystal::Type+, Bool, Crystal::CodeGenVisitor::ModuleInfo, Bool, Bool>:LLVM::Function
  from Crystal::CodeGenVisitor#target_def_fun<Crystal::Def+, Crystal::Type+>:LLVM::Function
  from Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::CodeGenVisitor#codegen_fun<String, Crystal::Def+, Crystal::Type+, Bool, Crystal::CodeGenVisitor::ModuleInfo, Bool, Bool>:LLVM::Function
  from Crystal::CodeGenVisitor#target_def_fun<Crystal::Def+, Crystal::Type+>:LLVM::Function
  from Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::CodeGenVisitor#visit<Crystal::Assign>:(Bool | Nil)
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::CodeGenVisitor#codegen_fun<String, Crystal::Def+, Crystal::Type+, Bool, Crystal::CodeGenVisitor::ModuleInfo, Bool, Bool>:LLVM::Function
  from Crystal::CodeGenVisitor#target_def_fun<Crystal::Def+, Crystal::Type+>:LLVM::Function
  from Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool
  from Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::CodeGenVisitor#codegen_fun<String, Crystal::Def+, Crystal::Type+, Bool, Crystal::CodeGenVisitor::ModuleInfo, Bool, Bool>:LLVM::Function
  from Crystal::CodeGenVisitor#target_def_fun<Crystal::Def+, Crystal::Type+>:LLVM::Function
  from Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool
  from Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::CodeGenVisitor#codegen_if_branch<Crystal::CodeGenVisitor::Phi, Crystal::ASTNode+, LLVM::BasicBlock, Bool>:(LLVM::Value | Nil)
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::Compiler#codegen<Crystal::Program, Crystal::ASTNode+, Array(Crystal::Compiler::Source), String>:(Tuple(Array(Crystal::Compiler::CompilationUnit), Array(String)) | Nil)
  from Crystal::Compiler#compile<Array(Crystal::Compiler::Source), String>:Crystal::Compiler::Result
  from __crystal_main
  from main
Error: you've found a bug in the Crystal compiler. Please open an issue, including source code that will allow us to reproduce the bug: https://github.com/crystal-lang/crystal/issues
~/c/cb (compilerbug) [1]> echo $status
1
@will will added the kind:bug A bug in the code. Does not apply to documentation, specs, etc. label Oct 29, 2021
@Blacksmoke16
Copy link
Member

Blacksmoke16 commented Oct 30, 2021

I think this is related to #11384, as i get the same error when running the example from there with --debug. However the --debug flag isn't needed for that other issue. Here's the stack trace from locally built master compiler:

ccrystal run --prelude=empty --stats --progress --debug test.cr
Using compiled compiler at ~/crystal/.build/crystal
Parse:                             00:00:00.000206000 (   0.76MB)
Semantic (top level):              00:00:00.081804854 (  10.51MB)
Semantic (new):                    00:00:00.000202599 (  10.51MB)
Semantic (type declarations):      00:00:00.002491211 (  10.51MB)
Semantic (abstract def check):     00:00:00.000044241 (  10.51MB)
Semantic (ivars initializers):     00:00:00.000763450 (  10.51MB)
Semantic (cvars initializers):     00:00:00.000378951 (  10.51MB)
Semantic (main):                   00:00:00.002807901 (  10.51MB)
Semantic (cleanup):                00:00:00.000003132 (  10.51MB)
Semantic (recursive struct check): 00:00:00.000053628 (  10.51MB)
Nil assertion failed (NilAssertionError)
  from ~/crystal/src/nil.cr:108:5 in 'not_nil!'
  from ~/crystal/src/compiler/crystal/codegen/debug.cr:193:59 in 'create_debug_type'
  from ~/crystal/src/compiler/crystal/codegen/debug.cr:89:43 in 'get_debug_type'
  from ~/crystal/src/compiler/crystal/codegen/debug.cr:309:7 in 'get_debug_type'
  from ~/crystal/src/compiler/crystal/codegen/debug.cr:144:59 in 'create_debug_type'
  from ~/crystal/src/compiler/crystal/codegen/debug.cr:89:43 in 'get_debug_type'
  from ~/crystal/src/compiler/crystal/codegen/debug.cr:309:7 in 'get_debug_type'
  from ~/crystal/src/compiler/crystal/codegen/fun.cr:297:37 in 'codegen_fun_signature_non_external'
  from ~/crystal/src/compiler/crystal/codegen/fun.cr:236:7 in 'codegen_fun_signature'
  from ~/crystal/src/compiler/crystal/codegen/fun.cr:82:7 in 'codegen_fun'
  from ~/crystal/src/compiler/crystal/codegen/fun.cr:51:3 in 'codegen_fun'
  from ~/crystal/src/compiler/crystal/codegen/fun.cr:8:54 in 'target_def_fun'
  from ~/crystal/src/compiler/crystal/codegen/call.cr:458:12 in 'codegen_call'
  from ~/crystal/src/compiler/crystal/codegen/call.cr:35:7 in 'visit'
  from ~/crystal/src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from ~/crystal/src/compiler/crystal/codegen/codegen.cr:2279:7 in 'accept'
  from ~/crystal/src/compiler/crystal/codegen/codegen.cr:667:9 in 'visit'
  from ~/crystal/src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from ~/crystal/src/compiler/crystal/codegen/codegen.cr:2279:7 in 'accept'
  from ~/crystal/src/compiler/crystal/codegen/codegen.cr:67:7 in 'codegen'
  from ~/crystal/src/compiler/crystal/codegen/codegen.cr:65:5 in 'codegen:debug:single_module'
  from ~/crystal/src/compiler/crystal/progress_tracker.cr:22:7 in 'codegen'
  from ~/crystal/src/compiler/crystal/compiler.cr:169:16 in 'compile'
  from ~/crystal/src/compiler/crystal/command.cr:296:3 in 'compile'
  from ~/crystal/src/compiler/crystal/command.cr:208:14 in 'run_command'
  from ~/crystal/src/compiler/crystal/command.cr:101:7 in 'run'
  from ~/crystal/src/compiler/crystal/command.cr:49:5 in 'run'
  from ~/crystal/src/compiler/crystal/command.cr:48:3 in 'run'
  from ~/crystal/src/compiler/crystal.cr:11:1 in '__crystal_main'
  from ~/crystal/src/crystal/main.cr:110:5 in 'main_user_code'
  from ~/crystal/src/crystal/main.cr:96:7 in 'main'
  from ~/crystal/src/crystal/main.cr:119:3 in 'main'
ccrystal --version
Using compiled compiler at ~/crystal/.build/crystal
Crystal 1.3.0-dev [01a85441f] (2021-10-29)

LLVM: 12.0.1
Default target: x86_64-apple-macosx

EDIT: Reproduces on Linux too:

Crystal 1.2.1 (2021-10-21)

LLVM: 12.0.1
Default target: x86_64-pc-linux-gnu

@will
Copy link
Contributor Author

will commented Oct 30, 2021

Yeah seems like it could be related for sure. In #11384 though you mention that your issue doesn't repo with homebrew, but for my case I was reporting this on the macos 11.6 homebrew bottle

maxfierke added a commit to maxfierke/crystal that referenced this issue Nov 1, 2021
A file is required but in some contexts it seems to not be available
so we fallback to the file to the "unknown location" used elsewhere
(i.e. "??", line 1, column 1)

Fixes crystal-lang#11384
Fixes crystal-lang#11385
@straight-shoota
Copy link
Member

It does not appear to reproduce with LLVM 10.

Crystal 1.2.1 [4e6c0f26e] (2021-10-21)

LLVM: 10.0.0
Default target: x86_64-unknown-linux-gnu

@will
Copy link
Contributor Author

will commented Nov 3, 2021

Is there a way to work around this in the mean time?

@straight-shoota
Copy link
Member

Using a compiler with LLVM 10 should work. Or 13 maybe, haven't checked that yet.

@rdp
Copy link
Contributor

rdp commented Nov 4, 2021

I get a similar failure:

Crystal 1.2.1 [4e6c0f2] (2021-10-21)

LLVM: 10.0.0
Default target: x86_64-unknown-linux-gnu

FWIW. Wait sometimes I do, sometimes I don't?

@Val
Copy link
Contributor

Val commented Nov 7, 2021

Latest 1.2.1

$ crystal --version
Crystal 1.2.1 [4e6c0f26e] (2021-10-21)

LLVM: 10.0.0
Default target: x86_64-unknown-linux-gnu

A simple source

$ cat false.cr 
STDERR.puts "false"
exit(1)

Another error with --debug

$ crystal build --debug false.cr
Module validation failed: inlinable function call in a function with debug info must have a !dbg location
  %57 = call %"IO::FileDescriptor"** @"~STDERR:read"()
 (Exception)
  from /crystal/src/int.cr:541:9 in 'finish'
  from /crystal/src/compiler/crystal/codegen/codegen.cr:69:7 in 'codegen'
  from /crystal/src/compiler/crystal/compiler.cr:169:16 in 'compile'
  from /crystal/src/compiler/crystal/command.cr:296:3 in 'run'
  from /crystal/src/compiler/crystal.cr:11:1 in '__crystal_main'
  from /crystal/src/crystal/main.cr:110:5 in 'main'
  from src/env/__libc_start_main.c:94:2 in 'libc_start_main_stage2'
Error: you've found a bug in the Crystal compiler. Please open an issue, including source code that will allow us to reproduce the bug: https://github.com/crystal-lang/crystal/issues

And it was the same with crystal 1.2.0 [9f90efe33] (2021-10-13)

@straight-shoota
Copy link
Member

@Val That seems to be a separate bug. It looks related to #11318.

@Val
Copy link
Contributor

Val commented Nov 7, 2021

@straight-shoota Ok but it's still present in 1.2.1. Should I open a new issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:codegen
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants