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

Bit operations causes compiler to hang #1932

Closed
schmee opened this issue Feb 7, 2019 · 5 comments · Fixed by #3260
Closed

Bit operations causes compiler to hang #1932

schmee opened this issue Feb 7, 2019 · 5 comments · Fixed by #3260
Labels
bug Observed behavior contradicts documented or intended behavior upstream An issue with a third party project that Zig uses.
Milestone

Comments

@schmee
Copy link
Sponsor Contributor

schmee commented Feb 7, 2019

The following example hangs the compiler when compiling with zig build-exe test.zig:

fn foo(x: u32) void {
    const p: u48 = (x >> 1) & 1;
}

pub fn main() void {
    foo(1);
}

If you change p to const p = (x >> 1) & 1 (i.e remove the explicit cast to u48) it compiles immediately. If you change the cast to u32 or u64 it compiles. All numbers I tried between 32 and 64 also caused the hang. It seems very specific to these operators: I've tried replacing << and & with various combinations but only this one causes the error. If you inline the function call, it also compiles.

Versions:

➜  zig version
0.3.0+7fc99c33

macOS Mojave 10.14.3

@andrewrk andrewrk added the bug Observed behavior contradicts documented or intended behavior label Feb 9, 2019
@andrewrk andrewrk added this to the 0.4.0 milestone Feb 9, 2019
@andrewrk andrewrk added the upstream An issue with a third party project that Zig uses. label Feb 10, 2019
@andrewrk
Copy link
Member

Nice find. I'm actually able to reproduce this using clang-7 and clang-8 and the LLVM IR file that Zig produces from this source. So it's pretty clearly an LLVM bug. I'm making a bug report now.

@andrewrk
Copy link
Member

Upstream bug report: https://bugs.llvm.org/show_bug.cgi?id=40676

@andrewrk andrewrk added the contributor friendly This issue is limited in scope and/or knowledge of Zig internals. label Feb 10, 2019
@andrewrk andrewrk modified the milestones: 0.4.0, 0.5.0 Feb 10, 2019
@andrewrk
Copy link
Member

It's unlikely this will be fixed in the upcoming llvm 8.0.0 release, since it's already at Release Candidate 2. However I will make it a goal to submit an upstream bug fix before they make the llvm 9 branch.

@schmee
Copy link
Sponsor Contributor Author

schmee commented Feb 10, 2019

I don't know if this is useful or not, but the example file you posted doesn't hang for me on macOS:

➜  clang -c test.ll
warning: overriding the module target triple with x86_64-apple-macosx10.14.0 [-Woverride-module]
1 warning generated.
➜  clang --version
Apple LLVM version 10.0.0 (clang-1000.11.45.5)
Target: x86_64-apple-darwin18.2.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

@andrewrk
Copy link
Member

This is fixed in llvm trunk but not llvm 8.0.rc2. I don't plan to do the bisect necessary to find which commit fixed it, so unless someone else wants to do that before 8 is released, this will remain an open issue until LLVM 9, which corresponds to Zig 0.5.0.

@andrewrk andrewrk removed the contributor friendly This issue is limited in scope and/or knowledge of Zig internals. label Feb 13, 2019
@andrewrk andrewrk mentioned this issue Sep 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior upstream An issue with a third party project that Zig uses.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants