Segfault in the compiler when using a bitstruct constant defined using a cast with an operator
Pretty niche, but if I define a global bitstruct and define it's value by casting a number then use it in a math expression it causes the compiler to crash.
Minimal reproducer:
import std::io;
bitstruct BitstructFlags : uint
{
bool first;
bool second;
}
const BitstructFlags B_FIRST = { true, false };
const BitstructFlags B_FIRST2 = (BitstructFlags) 1;
const BitstructFlags B_SECOND = { false, true };
fn void main()
{
BitstructFlags x = B_FIRST2 | B_SECOND;
io::printfn("X: %d", (uint)x);
}
Changing this to either BitstructFlags x = B_FIRST | B_SECOND; or BitstructFlags x = B_FIRST2; avoids the crash, so it's specific to using it in an expression with an operator.
c3c.exe --version
C3 Compiler Version: 0.7.3 (Pre-release, Jun 27 2025 11:52:32)
Installed directory: C:/Data/c3c/build/Debug/
Git Hash: 962a1fc8733c386eeba68360213964da5eabd2a6
Backends: LLVM
LLVM version: 19.1.5
LLVM default target: x86_64-pc-windows-msvc
I love niche bugs
Reports of those bugs at least
This should work now, please have a try.
Thanks, it no longer crashes but the output is incorrect:
import std::io;
bitstruct BitstructFlags : uint
{
bool first;
bool second;
}
const BitstructFlags B_FIRST = { true, false };
const BitstructFlags B_FIRST2 = (BitstructFlags) 1;
const BitstructFlags B_SECOND = { false, true };
fn void main()
{
BitstructFlags x = B_FIRST | B_SECOND;
BitstructFlags y = B_FIRST2 | B_SECOND;
io::printfn("X: %d Y: %d", (uint)x, (uint)y);
}
Output:
X: 3 Y: 1
Please try it, it should be correct now.
Looks all good :+1: