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

[Compiler crash] Module validation failed: Invalid bitcast #3691

Closed
TechMagister opened this issue Dec 14, 2016 · 2 comments
Closed

[Compiler crash] Module validation failed: Invalid bitcast #3691

TechMagister opened this issue Dec 14, 2016 · 2 comments

Comments

@TechMagister
Copy link

Crystal 0.20.1+39 [a8fbc2d] (2016-12-14) and Crystal 0.20.1 [18e7617] (2016-12-05) ( Same error but without the backtrace )
Compiled with LLVM version 3.8.0
OS: Linux

My code : https://github.com/TechMagister/i18n.cr
It happens when running spec : crystal spec

With Crystal 0.20.1 [18e7617] (2016-12-05)

Module validation failed: Bitcast requires both operands to be pointer or neither
  %5 = bitcast %"(Bool | Int32)" %arg to %"(Bool | Int32 | NamedTuple(iter: Int32, format: Bool) | String)"*, !dbg !42
Bitcast requires both operands to be pointer or neither
  %3 = bitcast %"(Bool | Int32)" %arg to %"(Bool | Int32 | NamedTuple(iter: Int32, format: Bool))"*, !dbg !42
Bitcast requires both operands to be pointer or neither
  %3 = bitcast %"(Bool | Int32)" %arg to %"(Bool | Int32 | NamedTuple(iter: Int32, format: Bool))"*, !dbg !42

0x53beae: ??? at ??
0x11da247: ??? at ??
0x1130f9d: ??? at ??
0x593016: ??? at ??
0x56023b: main at ??
0x7fc048b32401: __libc_start_main at ??
0x53b7e1: ??? at ??

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/issu
es

With Crystal 0.20.1+39 [a8fbc2d] (2016-12-14)

Module validation failed: Invalid bitcast
  %4 = bitcast %"(Bool | Int32)" %arg to %"(Bool | Int32 | NamedTuple(iter: Int32, format: Bool) | String)"*, !dbg !41
Invalid bitcast
  %3 = bitcast %"(Bool | Int32)" %arg to %"(Bool | Int32 | NamedTuple(iter: Int32, format: Bool))"*, !dbg !41
Invalid bitcast
  %2 = bitcast %"(Bool | Int32)" %arg to %"(Bool | Int32 | NamedTuple(iter: Int32, format: Bool))"*, !dbg !41

0x7513a7: *CallStack::unwind:Array(Pointer(Void)) at ??
0x75133a: *CallStack#initialize:Array(Pointer(Void)) at ??
0x75130a: *CallStack::new:CallStack at ??
0x72b51e: *raise<Exception>:NoReturn at ??
0x72b50e: ??? at ??
0x138fdf3: *LLVM::Module#verify:Nil at ??
0x13e3e98: *Crystal::CodeGenVisitor#finish:Hash(String, LLVM::Module) at ??
0x88f061: *Crystal::Program#codegen<Crystal::ASTNode+, (Array(String) | Bool | Nil), Bool, LLVM::Module, Bool>:Hash(String, LLVM::Module) at ??
0x88efae: *Crystal::Program#codegen:debug:single_module:expose_crystal_main<Crystal::ASTNode+, Bool, (Array(String) | Bool | Nil), Bool>:Hash(String, LLVM::Module) at ??
0xfdf43d: *Crystal::Compiler#codegen<Crystal::Program, Crystal::ASTNode+, Array(Crystal::Compiler::Source), String>:(Array(String) | Nil) at ??
0xfdca06: *Crystal::Compiler#compile<Array(Crystal::Compiler::Source), String>:Crystal::Compiler::Result at ??
0x85c1a3: *Crystal::Command#spec:NoReturn at ??
0x8573f4: *Crystal::Command#run:(Array(Crystal::ImplementationTrace) | Array(Crystal::Init::View+:Class) | Array(String) | Bool | Crystal::Compiler::Result | Hash(String, String) |
 IO::FileDescriptor | Nil) at ??
0x856d4b: *Crystal::Command::run<Array(String)>:(Array(Crystal::ImplementationTrace) | Array(Crystal::Init::View+:Class) | Array(String) | Bool | Crystal::Compiler::Result | Hash(S
tring, String) | IO::FileDescriptor | Nil) at ??
0x856d09: *Crystal::Command::run:(Array(Crystal::ImplementationTrace) | Array(Crystal::Init::View+:Class) | Array(String) | Bool | Crystal::Compiler::Result | Hash(String, String)
| IO::FileDescriptor | Nil) at ??
0x72af39: ??? at ??
0x73d489: main at ??
0x7f5c24175401: __libc_start_main at ??
0x72a0ba: _start at ??
0x0: ??? at ??

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/issu
es
@asterite
Copy link
Member

I'll take a look at this soon, but I see this often enough so I'll say it: don't use **options and then options[:throw] and such. This makes your code very hard to read, write and follow. You should use named arguments. So:

def method(throw = :throw, force_locale = config.locale.to_s)
  # Nothing to do here :-)
end

# Instead of the much more verbose
def method(**options)
  throw = options[:throw]? || :throw
  locale = options[:force_locale]? || config.locale.to_s
end

@asterite
Copy link
Member

Reduced:

def foo(arg)
  arg = ""
end

foo(1 || true)

@asterite asterite added this to the 0.20.2 milestone Dec 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant