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

Crystal compiler segfault #5721

Closed
xfbs opened this issue Feb 15, 2018 · 3 comments
Closed

Crystal compiler segfault #5721

xfbs opened this issue Feb 15, 2018 · 3 comments

Comments

@xfbs
Copy link

xfbs commented Feb 15, 2018

When compiling this code, the compiler segfaults and I don't know why.

class Crash
  @num = 123
  @hash = Hash(String, Int32).new do
    Int32.new(@num)
  end
end

crash = Crash.new

Here's the compiler output (from crystal build cli.cr, where cli.cr is the above code):

Invalid memory access (signal 11) at address 0x0
[0x105719e0c] __crystal_sigfault_handler +76
[0x7fff88b1a52a] _sigtramp +26
[0x106f38346] _ZN4llvm11PointerType3getEPNS_4TypeEj +26
[0x106eb9903] _ZN4llvm12ConstantExpr16getGetElementPtrEPNS_4TypeEPNS_8ConstantENS_8ArrayRefIPNS_5ValueEEEbNS_8OptionalIjEES2_ +197
[0x1069be213] _ZN4llvm12ConstantExpr24getInBoundsGetElementPtrEPNS_4TypeEPNS_8ConstantENS_8ArrayRefIPNS_5ValueEEE +35
[0x1069be18b] _ZN4llvm9IRBuilderINS_14ConstantFolderENS_24IRBuilderDefaultInserterEE17CreateInBoundsGEPEPNS_4TypeEPNS_5ValueENS_8ArrayRefIS7_EERKNS_5TwineE +91
[0x106ec7b50] LLVMBuildInBoundsGEP +54
[0x105c7d2e0] *Crystal::CodeGenVisitor@Crystal::LLVMBuilderHelper#gep<LLVM::Value, Int32, Int32, String>:LLVM::Value +176
[0x105cc37e4] *Crystal::CodeGenVisitor#read_instance_var<Crystal::Type+, Crystal::Type+, String, LLVM::Value>:Bool +100
[0x105ca035c] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +19132
[0x105cbf2b4] *Crystal::CodeGenVisitor#prepare_call_args_non_external<Crystal::Call, Crystal::Def+, Crystal::Type+>:Tuple(Array(LLVM::Value), Bool) +1156
[0x105cb9b72] *Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool +4434
[0x105c9feac] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +17932
[0x105cae251] *Crystal::CodeGenVisitor#codegen_fun<String, Crystal::Def+, Crystal::Type+, Bool, Crystal::CodeGenVisitor::ModuleInfo, Bool, Bool>:LLVM::Function +4321
[0x105c9cb53] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +4787
[0x105cb9be7] *Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool +4551
[0x105c9feac] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +17932
[0x105cce164] *Crystal::CodeGenVisitor#run_instance_vars_initializers<Crystal::Type+, (Crystal::ClassType+ | Crystal::GenericClassType+), LLVM::Value>:Nil +1012
[0x105ccd506] *Crystal::CodeGenVisitor#allocate_aggregate<Crystal::Type+>:LLVM::Value +3750
[0x105cc4117] *Crystal::CodeGenVisitor#codegen_primitive<Crystal::Call, Crystal::Primitive+, Crystal::Def+, Array(LLVM::Value)>:LLVM::Value +1703
[0x105cb9d07] *Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool +4839
[0x105c9feac] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +17932
[0x105cb363d] *Crystal::CodeGenVisitor#visit<Crystal::Assign>:(Bool | Nil) +317
[0x105c9c86f] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +4047
[0x105c9c6a9] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +3593
[0x105cae251] *Crystal::CodeGenVisitor#codegen_fun<String, Crystal::Def+, Crystal::Type+, Bool, Crystal::CodeGenVisitor::ModuleInfo, Bool, Bool>:LLVM::Function +4321
[0x105cb18b3] *Crystal::CodeGenVisitor#target_def_fun<Crystal::Def+, Crystal::Type+>:LLVM::Function +2611
[0x105cb9d26] *Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool +4870
[0x105c9feac] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +17932
[0x105cb363d] *Crystal::CodeGenVisitor#visit<Crystal::Assign>:(Bool | Nil) +317
[0x105c9c86f] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +4047
[0x105c9c6a9] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +3593
[0x105c57afb] *Crystal::Compiler#codegen<Crystal::Program, Crystal::ASTNode+, Array(Crystal::Compiler::Source), String>:(Tuple(Array(Crystal::Compiler::CompilationUnit), Array(String)) | Nil) +539
[0x106006164] *Crystal::Compiler#compile<Array(Crystal::Compiler::Source), String>:Crystal::Compiler::Result +116
[0x10572d3b7] *Crystal::Command#run:(Bool | Crystal::Compiler::Result | IO::FileDescriptor | Nil) +327
[0x1056f3e0b] main +12427

Information about my system:

$ uname -a
Darwin xfbs-air 15.6.0 Darwin Kernel Version 15.6.0: Tue Jan  9 20:12:05 PST 2018; root:xnu-3248.73.5~1/RELEASE_X86_64 x86_64

$ brew info crystal-lang
crystal-lang: stable 0.24.1 (bottled), HEAD
Fast and statically typed, compiled language with Ruby-like syntax
https://crystal-lang.org/
/usr/local/Cellar/crystal-lang/0.24.1_1 (827 files, 47.6MB)
  Poured from bottle on 2018-01-24 at 12:15:56
/usr/local/Cellar/crystal-lang/0.24.1_2 (827 files, 47.6MB) *
  Poured from bottle on 2018-01-29 at 15:45:04
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/crystal-lang.rb
==> Dependencies
Build: pkg-config, libatomic_ops
Required: libevent, bdw-gc, llvm, pcre, gmp, libyaml
==> Options
--without-release
	Do not build the compiler in release mode
--without-shards
	Do not include `shards` dependency manager
--HEAD
	Install HEAD version
==> Caveats
Bash completion has been installed to:
  /usr/local/etc/bash_completion.d

zsh completions have been installed to:
  /usr/local/share/zsh/site-functions

$ crystal -v
Crystal 0.24.1 (2018-01-27)

LLVM: 5.0.1
Default target: x86_64-apple-macosx
@straight-shoota
Copy link
Member

Reduced example:

class Foo
  @foo = "foo"
  @bar : String = -> { @foo }.call
end

Foo.new

carc.in

@Groogy
Copy link

Groogy commented Apr 2, 2018

It looks like I am getting the same crash but from a little bit different cause. From my code reduced to as minimal as I can

alias Type = Nil | Bool | Int64 | Float64 | String | Time | Bytes | Array(Type) | Hash(Type, Type) | Set(Type)

abstract class BaseNode
  @value : Type
end

class Node(AttachedData) < BaseNode
  def initialize(@data : AttachedData, @value : Type, @key : String | Int32 | Nil)
  end
end

node = Node.new nil, nil, nil

If I take away so the class isn't a generic anymore then it stops failing to compile.

@asterite
Copy link
Member

asterite commented Apr 2, 2018

Duplicate of #2865

@asterite asterite marked this as a duplicate of #2865 Apr 2, 2018
@asterite asterite closed this as completed Apr 2, 2018
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

5 participants