Crystal: Can't build Crystal in release mode (LLVM >= 3.9)

Created on 13 Jan 2017  路  10Comments  路  Source: crystal-lang/crystal

Since #3831 we can't build Crystal in release mode with LLVM >= 3.9 (unless we pass --no-debug) because some calls are still missing a !dbg location. For example:

Module validation failed: inlinable function call in a function with debug info must have a !dbg location
  %146 = call i64 @__crystal_get_exception(%"struct.LibUnwind::Exception.154"* %145)
inlinable function call in a function with debug info must have a !dbg location
  call void @__crystal_raise(%"struct.LibUnwind::Exception.154"* %204)
inlinable function call in a function with debug info must have a !dbg location
  %1 = call %"String::Builder.168"* @"*String::Builder@IO#<<<String>:String::Builder"(%"String::Builder.168"* %0, %String* bitcast ({ i32, i32, i32, [10 x i8] }* @"'git init '" to %String*))
inlinable function call in a function with debug info must have a !dbg location
  %6 = call %"String::Builder.168"* @"*String::Builder@IO#<<<String>:String::Builder"(%"String::Builder.168"* %1, %String* %5)
inlinable function call in a function with debug info must have a !dbg location
  %24 = call i1 @"*Regex#===<String>:Bool"(%Regex* %22, %String* %23, %"Regex::MatchData"** %"$~")

I'm trying to investigate, but this ain't easy to track.

bug compiler

Most helpful comment

I found most of them. Only one left.

All 10 comments

Thanks for the heads up Julien. @ggiraldez maybe you can contribute an additional pair of eyes to this? :)

I reproduced and fixed one: missing a location on StringInterpolation.

I found most of them. Only one left.

@ysbaddaden I still get this problem with Crystal 0.21.1, is that normal?

@soveran to build crystal? or do you hit this error in a project?

We still have the error pop up. Can you try the latest master? If it doesn't pass, please reduce/report the issue.

@ysbaddaden I compiled Crystal from master without issues, then tried to compile toro.cr and got the gdb error. The workaround of passing --no-debug works.

Can you report the issue, with a way to reproduce or (hopefully) a reduced example?

Here's a somewhat reduced example:

require "http/server"

module Example
  abstract class Router
    def self.call(context : HTTP::Server::Context)
      context.response.content_type = "text/plain"
      context.response.print "hello world"
    end

    def self.run(*args)
      server = HTTP::Server.new(*args) do |context|
        call(context)
      end

      Signal::INT.trap do
        server.close
        exit
      end

      puts "#{name} - Listening on port #{server.port}"
      server.listen
    end
  end
end

class Demo < Example::Router
end

Demo.run(8080)

It runs fine when passed --no-debug, but fails otherwise with the following error:

Module validation failed: !dbg attachment points at wrong subprogram for function
!4 = distinct !DISubprogram(name: "run", linkageName: "run", scope: !5, file: !5, line: 10, type: !6, isLocal: true, isDefinition: true, scopeLine: 10, isOptimized: false, unit: !0, variables: !2)
void (i32)* @"*Demo@Example::Router::run<Int32>:Nil"
  %1 = alloca %"->", !dbg !10
!10 = !DILocation(line: 8, column: 7, scope: !11)
!11 = distinct !DISubprogram(name: "call", linkageName: "call", scope: !5, file: !5, line: 5, type: !6, isLocal: true, isDefinition: true, scopeLine: 5, isOptimized: false, unit: !0, variables: !2)
!11 = distinct !DISubprogram(name: "call", linkageName: "call", scope: !5, file: !5, line: 5, type: !6, isLocal: true, isDefinition: true, scopeLine: 5, isOptimized: false, unit: !0, variables: !2)

0x102c8bc13: *raise<String>:NoReturn at ??
0x103c5cc6b: *Crystal::CodeGenVisitor#finish:Nil at ??
0x103b8853e: *Crystal::Compiler#codegen<Crystal::Program, Crystal::ASTNode+, Array(Crystal::Compiler::Source), String>:(Tuple(Array(Crystal::Compiler::CompilationUnit), Array(String)) | Nil) at ??
0x10442e1b4: *Crystal::Compiler#compile<Array(Crystal::Compiler::Source), String>:Crystal::Compiler::Result at ??
0x1044d5219: *Crystal::Command#run_command<Bool>:Nil at ??
0x102ceb229: *Crystal::Command#run:(Bool | Crystal::Compiler::Result | IO::FileDescriptor | Nil) at ??
0x102cb599d: main 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/issues

@soveran That error trace is familiar, I fixed it a couple of days ago here . I tried it with a compiled compiler from master and now it works fine :-)

@asterite Excellent, it works with master :-) Thanks!

Was this page helpful?
0 / 5 - 0 ratings