crystal-lang / crystal

The Crystal Programming Language
https://crystal-lang.org
Apache License 2.0
19.52k stars 1.62k forks source link

Stack smashing detected while compiling #5517

Open silverweed opened 6 years ago

silverweed commented 6 years ago

Crystal version: Crystal 0.24.1 (2017-12-20)

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

OS version: Linux 4.14.8-1-ARCH #1 SMP PREEMPT Wed Dec 20 21:27:44 UTC 2017 x86_64 GNU/Linux

I have a Crystal project I haven't been updating since november. It used to compile fine with Crystal 0.23, but since I upgraded to 0.24 the compiler crashes while compiling it. It doesn't print the usual message "You have found a bug in the compiler", it just aborts. I tried this both on Debian testing and on Archlinux, and on the latter it doesn't simply crash, but it reports a stack smashing detection:

*** stack smashing detected ***: <unknown> terminated
make: *** [Makefile:11: build] Aborted (core dumped)

Since the codebase is not that small (~1900 loc) I haven't been able to write a minimal example, but via git bisect I could track down the commit after which the compiler is unable to compile the app. Unfortunately it's quite a big commit involving several files, all of which compile just fine when compiled standalone.

I built the compiler from source with debug enabled and this is what gdb spits out (using an external link as it's pretty long): GDB output

Are there any more steps I can take to narrow the possible causes?

silverweed commented 6 years ago

Bump: problem is still there with 0.24.2. Can this at least be labeled as a compiler bug?

RX14 commented 6 years ago

Compiled a debug LLVM and got this error:

Cannot create a null constant of that type!
UNREACHABLE executed at ../lib/IR/Constants.cpp:239!
RX14 commented 6 years ago

This happens when calling LLVM::Type#null on a LLVM::Type which is Void. Happens during codegen.

jhass commented 4 years ago

After some compat patches this now produces the following under Crystal 0.33

Module validation failed: Load operand must be a pointer.
  %24 = load void, void <badref>
PHI node operands are not the same type as the result!
  %25 = phi i32 [ 0, %nil ], [ %24, %not_nil ]
Call parameter type does not match function signature!
  call void @"*Nil#not_nil!:NoReturn"(%Nil zeroinitializer)
 i32*  call void @"*SF::Sprite#texture=<SF::Texture+>:Nil"(%"SF::Sprite"* %6, void <badref>)
Invalid operand types for ICmp instruction
  %32 = icmp eq void <badref>, zeroinitializer
Load operand must be a pointer.
  %33 = load void, void <badref>
PHI node operands are not the same type as the result!
  %34 = phi i32 [ 0, %nil1 ], [ %33, %not_nil2 ]
Load operand must be a pointer.
  %36 = load void, void <badref>
Call parameter type does not match function signature!
  %36 = load void, void <badref>
 i32  %37 = call i32 @"~metaclass"(void %36)
 (Exception)
  from Crystal::CodeGenVisitor#finish: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::Command#run:(Bool | Crystal::Compiler::Result | Nil)
  from main
Diff ```diff diff --git a/Makefile b/Makefile index 63b8d1e..2427b4a 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ UNAME := $(shell uname) NCORES = 1 -CRYSTAL = /usr/local/src/crystal-0.23.1-3/bin/crystal +CRYSTAL = crystal EXE = lifishedit ifeq ($(UNAME), Darwin) NCORES = $(shell sysctl -n hw.ncpu) diff --git a/shard.yml b/shard.yml index c37eed8..5339b6d 100644 --- a/shard.yml +++ b/shard.yml @@ -9,4 +9,4 @@ license: Zlib dependencies: crsfml: github: blaxpirit/crsfml - version: 2.4.5 + version: 2.5.0 diff --git a/src/LifishEdit/feedback_text.cr b/src/LifishEdit/feedback_text.cr index e25adb2..351c7d2 100644 --- a/src/LifishEdit/feedback_text.cr +++ b/src/LifishEdit/feedback_text.cr @@ -2,9 +2,7 @@ require "crsfml/graphics" require "./app" module LE - class FeedbackText - FADE_DURATION = SF.seconds(2) def initialize(app : LE::App) @@ -29,7 +27,7 @@ class FeedbackText def refresh c = @text.fill_color if c.a > 0 - @text.fill_color = SF::Color.new(c.r, c.g, c.b, c.a - {c.a, 255/60}.min) + @text.fill_color = SF::Color.new(c.r, c.g, c.b, c.a - {c.a, 255//60}.min) oc = @text.outline_color @text.outline_color = SF::Color.new(oc.r, oc.g, oc.b, @text.fill_color.a) end @@ -41,5 +39,4 @@ class FeedbackText target.draw(@text, states) end end - end diff --git a/src/LifishEdit/menu.cr b/src/LifishEdit/menu.cr index 3a27c56..45d1834 100644 --- a/src/LifishEdit/menu.cr +++ b/src/LifishEdit/menu.cr @@ -4,7 +4,6 @@ require "../clibs/nfd" require "crsfml/graphics" module LE - # A menu callback is a `Proc` taking a `LE::App` as an argument and returning # a `Bool`. If `false` is returned, the app exits after the callback. alias MenuCallback = Proc(LE::App, Bool) @@ -23,7 +22,7 @@ class Menu {:restore, "Restore"}, {:restore_all, "Rstr All"}, {:clear, "Clear"}, - {:quit, "Quit" } + {:quit, "Quit"}, } FONT_SIZE = 16 @@ -68,7 +67,7 @@ class Menu # The rectangle intercepting mouse clicks rect = SF::RectangleShape.new(SF.vector2f(width, @h)) rect.position = SF.vector2f(x, y) - rect.fill_color = SF.color(0, 0, 180 - x * 50 / width) + rect.fill_color = SF.color(0, 0, 180 - x * 50 // width) # The menu text raise "Font is nil!" if @font == nil text = SF::Text.new(b[1], @font, FONT_SIZE) @@ -192,5 +191,4 @@ class Menu end end end - end # module LE diff --git a/src/LifishEdit/save.cr b/src/LifishEdit/save.cr index 4e21869..75915de 100644 --- a/src/LifishEdit/save.cr +++ b/src/LifishEdit/save.cr @@ -5,7 +5,7 @@ class LE::SaveManager # Serializes a `LevelSet` into a JSON string, saving it to `fname` def self.save(levelset : LE::LevelSet, fname : String) fname += ".json" unless fname.ends_with? ".json" - levelset.date = Time.now.to_s + levelset.date = Time.local.to_s File.write(fname, levelset.data.to_pretty_json("\t")) if levelset.app.verbose? STDERR.puts "Saved levelset in #{fname}" ```