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

Internal compiler error from calling is_a? on union of metaclasses #11890

Open
HertzDevil opened this issue Mar 12, 2022 · 0 comments
Open

Internal compiler error from calling is_a? on union of metaclasses #11890

HertzDevil opened this issue Mar 12, 2022 · 0 comments
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:codegen

Comments

@HertzDevil
Copy link
Contributor

The code example in #11188 does not actually compile, up to the is_a? and name calls. Reduced:

class A; end

class B < A
  def self.foo; end
end

class C; end

(B || C).is_a?(A.class)
B.foo

This fails with:

Invalid memory access (signal 11) at address 0x0
[0x55d50d100f06] *Exception::CallStack::print_backtrace:Nil +118 in .build/crystal
[0x55d50d0ce76a] ~procProc(Int32, Pointer(LibC::SiginfoT), Pointer(Void), Nil) +330 in .build/crystal
[0x7f4e5513a200] ?? +139974411526656 in /lib/x86_64-linux-gnu/libpthread.so.0
[0x7f4e5648ba70] _ZN4llvm11PointerType3getEPNS_4TypeEj +32 in /usr/lib/x86_64-linux-gnu/libLLVM-13.so.1
[0x7f4e56364dfc] ?? +139974430576124 in /usr/lib/x86_64-linux-gnu/libLLVM-13.so.1
[0x7f4e56363967] _ZN4llvm25ConstantFoldGetElementPtrEPNS_4TypeEPNS_8ConstantEbNS_8OptionalIjEENS_8ArrayRefIPNS_5ValueEEE +87 in /usr/lib/x86_64-linux-gnu/libLLVM-13.so.1
[0x7f4e563858d9] _ZN4llvm12ConstantExpr16getGetElementPtrEPNS_4TypeEPNS_8ConstantENS_8ArrayRefIPNS_5ValueEEEbNS_8OptionalIjEES2_ +105 in /usr/lib/x86_64-linux-gnu/libLLVM-13.so.1
[0x7f4e56412ff3] ?? +139974431289331 in /usr/lib/x86_64-linux-gnu/libLLVM-13.so.1
[0x7f4e5639c26b] ?? +139974430802539 in /usr/lib/x86_64-linux-gnu/libLLVM-13.so.1
[0x7f4e5639c1cd] LLVMBuildInBoundsGEP +93 in /usr/lib/x86_64-linux-gnu/libLLVM-13.so.1
[0x55d50e0eb24a] *LLVM::Builder#inbounds_gep<LLVM::Value, LLVM::Value, LLVM::Value, String>:LLVM::Value +218 in .build/crystal
[0x55d50e130701] *Crystal::CrystalLLVMBuilder#inbounds_gep<LLVM::Value, LLVM::Value, LLVM::Value, String>:LLVM::Value +241 in .build/crystal
[0x55d50e06d49b] *Crystal::CodeGenVisitor +91 in .build/crystal
[0x55d50e06d42f] *Crystal::CodeGenVisitor +127 in .build/crystal
[0x55d50e06fe48] *Crystal::CodeGenVisitor +72 in .build/crystal
[0x55d50e06fdef] *Crystal::CodeGenVisitor#aggregate_index<LLVM::Value, Int32>:LLVM::Value +47 in .build/crystal
[0x55d50e06fda9] *Crystal::CodeGenVisitor#union_type_id<LLVM::Value>:LLVM::Value +41 in .build/crystal
[0x55d50e073d37] *Crystal::CodeGenVisitor#union_type_and_value_pointer<LLVM::Value, Crystal::MixedUnionType>:Tuple(LLVM::Value, LLVM::Value) +39 in .build/crystal
[0x55d50e073cf1] *Crystal::CodeGenVisitor#type_id_impl<LLVM::Value, Crystal::MixedUnionType>:LLVM::Value +49 in .build/crystal
[0x55d50e073c6e] *Crystal::CodeGenVisitor#type_id<LLVM::Value, Crystal::Type+>:LLVM::Value +974 in .build/crystal
[0x55d50e0c43e4] *Crystal::CodeGenVisitor#visit<Crystal::IsA>:Bool +84 in .build/crystal
[0x55d50d4db1e5] *Crystal::ASTNode+ +3989 in .build/crystal
[0x55d50e084461] *Crystal::CodeGenVisitor#accept<Crystal::ASTNode+>:Nil +17 in .build/crystal
[0x55d50e0b7e34] *Crystal::CodeGenVisitor#visit<Crystal::Expressions>:Bool +276 in .build/crystal
[0x55d50d4da824] *Crystal::ASTNode+ +1492 in .build/crystal
[0x55d50e084461] *Crystal::CodeGenVisitor#accept<Crystal::ASTNode+>:Nil +17 in .build/crystal
[0x55d50d31aa44] *Crystal::Program#codegen<Crystal::ASTNode+, Bool, Crystal::Debug>:Hash(String, Crystal::CodeGenVisitor::ModuleInfo) +68 in .build/crystal
[0x55d50d31a9f3] *Crystal::Program#codegen:debug:single_module<Crystal::ASTNode+, Crystal::Debug, Bool>:Hash(String, Crystal::CodeGenVisitor::ModuleInfo) +19 in .build/crystal
[0x55d50df71bd7] *Crystal::Compiler#codegen<Crystal::Program, Crystal::ASTNode+, Array(Crystal::Compiler::Source), String>:(Tuple(Array(Crystal::Compiler::CompilationUnit), Array(String)) | Nil) +471 in .build/crystal
[0x55d50df7617c] *Crystal::Compiler#compile<Array(Crystal::Compiler::Source), String>:Crystal::Compiler::Result +188 in .build/crystal
[0x55d50e2189d9] *Crystal::Command::CompilerConfig#compile<String>:Crystal::Compiler::Result +57 in .build/crystal
[0x55d50e20f0af] *Crystal::Command#run_command<Bool>:Nil +415 in .build/crystal
[0x55d50e208a17] *Crystal::Command#run:(Bool | Nil) +1367 in .build/crystal
[0x55d50e208389] *Crystal::Command::run<Array(String)>:(Bool | Nil) +25 in .build/crystal
[0x55d50e20834d] *Crystal::Command::run:(Bool | Nil) +29 in .build/crystal
[0x55d50d0ada9e] __crystal_main +2830 in .build/crystal
[0x55d50d2a1f46] *Crystal::main_user_code<Int32, Pointer(Pointer(UInt8))>:Nil +6 in .build/crystal
[0x55d50d2a1e99] *Crystal::main<Int32, Pointer(Pointer(UInt8))>:Int32 +41 in .build/crystal
[0x55d50d0bb076] main +6 in .build/crystal
[0x7f4e54ef17fd] __libc_start_main +205 in /lib/x86_64-linux-gnu/libc.so.6
[0x55d50d0ace7a] _start +42 in .build/crystal
[0x0] ???

This oddly goes away when the result of is_a? is assigned to a variable:

x = (B || C).is_a?(A.class) # => true
B.foo
@HertzDevil HertzDevil added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:codegen labels Mar 12, 2022
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

No branches or pull requests

1 participant