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

Wrong codegen involving uninitialized static array when compiled in release mode #3695

Closed
asterite opened this issue Dec 14, 2016 · 8 comments

Comments

@asterite
Copy link
Member

class Context
  @block = uninitialized UInt8[1]
  @index = 0

  def result
    @block[@index] = 0_u8

    w = [0]

    int = uninitialized UInt32[1]
    int[0] = 0x67452301_u32
    int[0] += w[0]

    res = uninitialized UInt8[4]
    res[0] = (int[0] >> 8).to_u8
    res[1] = 0_u8
    res[2] = 0_u8
    res[3] = 0_u8
    res
  end
end

LibC.printf "%d\n", Context.new.result[0]
Context.new.result

Only on linux, running it in normal mode and release mode gives me 35 and 32 respectively.

@asterite
Copy link
Member Author

Might be a big in LLVM. Somebody should try this with LLVM 3.8 or LLVM 3.9, because the Crystal I'm using is probably using LLVM 3.6 because it comes bundled from the omnibus release.

@RX14
Copy link
Contributor

RX14 commented Dec 14, 2016

I get this using LLVM 3.9 on master: https://aww.moe/flxzvf.txt

@RX14
Copy link
Contributor

RX14 commented Dec 14, 2016

Looks like a null pointer finalizer to me.

@asterite
Copy link
Member Author

@RX14 I mean, if you compile just the above program with LLVM 3.9 in normal and release mode, do you get the same results?

@kostya
Copy link
Contributor

kostya commented Dec 14, 2016

llvm-config --version
3.8.1
crystal 1.cr
35
crystal 1.cr --release
35

@asterite
Copy link
Member Author

@kostya Thank you! What if you use LLVM 3.5 or LLVM 3.6? (if you can try this)

@marcosdsanchez
Copy link
Contributor

marcosdsanchez commented Dec 15, 2016

➜  ~ crystal -v
Crystal 0.20.1 (2016-12-06)
➜  ~ crystal test2.cr 
35
➜  ~ crystal test2.cr --release
35

➜  ~ pacman -Q llvm-libs
llvm-libs 3.9.0-3
➜  ~ uname -a
Linux marcos-macbook-arch 4.4.36-1-lts #1 SMP Fri Dec 2 14:35:21 CET 2016 x86_64 GNU/Linux

@asterite
Copy link
Member Author

asterite commented Mar 3, 2017

Closing as duplicate of #4104

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

4 participants