I've been getting compiler crashes on a fairly large project of mine in 0.6.0, with the following output:
Assertion failed at [...]/compiler/zig/src/ir.cpp:12740 in eval_const_expr_implicit_cast. This is a bug in the Zig compiler.
[...]/compiler/zig/src-self-hosted/stage2.zig:37:5: 0x55bf92e96f1c in stage2_panic (zigstage2)
@panic(ptr[0..len]);
^
[...]/compiler/zig/src/util.cpp:20:17: 0x55bf92e5167b in zig_panic ([...]/compiler/zig/src/util.cpp)
stage2_panic("", 0);
^
[...]/compiler/zig/src/util_base.hpp:53:18: 0x55bf92da1d7f in zig_assert ([...]/compiler/zig/src/ir.cpp)
zig_panic("Assertion failed at %s:%d in %s. This is a bug in the Zig compiler.", file, line, func);
^
[...]/compiler/zig/src/ir.cpp:12740:17: 0x55bf92dced19 in eval_const_expr_implicit_cast ([...]/compiler/zig/src/ir.cpp)
assert(new_type->id == ZigTypeIdFloat);
^
[...]/compiler/zig/src/ir.cpp:12821:43: 0x55bf92dcf17b in ir_resolve_cast ([...]/compiler/zig/src/ir.cpp)
if (!eval_const_expr_implicit_cast(ira, source_instr, cast_op, value->value, value->value->type,
^
[...]/compiler/zig/src/ir.cpp:26077:27: 0x55bf92e02615 in ir_analyze_instruction_int_to_float ([...]/compiler/zig/src/ir.cpp)
return ir_resolve_cast(ira, &instruction->base.base, target, dest_type, CastOpIntToFloat);
^
[...]/compiler/zig/src/ir.cpp:30404:55: 0x55bf92e1276c in ir_analyze_instruction_base ([...]/compiler/zig/src/ir.cpp)
return ir_analyze_instruction_int_to_float(ira, (IrInstSrcIntToFloat *)instruction);
^
[...]/compiler/zig/src/ir.cpp:30626:65: 0x55bf92e132de in ir_analyze ([...]/compiler/zig/src/ir.cpp)
IrInstGen *new_instruction = ir_analyze_instruction_base(ira, old_instruction);
^
[...]/compiler/zig/src/analyze.cpp:4836:44: 0x55bf92e61ce0 in analyze_fn_ir ([...]/compiler/zig/src/analyze.cpp)
ZigType *block_return_type = ir_analyze(g, fn->ir_executable,
^
[...]/compiler/zig/src/analyze.cpp:4952:18: 0x55bf92e622ae in analyze_fn_body ([...]/compiler/zig/src/analyze.cpp)
analyze_fn_ir(g, fn_table_entry, return_type_node);
^
[...]/compiler/zig/src/analyze.cpp:5064:28: 0x55bf92e62b4f in semantic_analyze ([...]/compiler/zig/src/analyze.cpp)
analyze_fn_body(g, fn_entry);
^
[...]/compiler/zig/src/codegen.cpp:9725:25: 0x55bf92d8d0bc in gen_root_source ([...]/compiler/zig/src/codegen.cpp)
semantic_analyze(g);
^
[...]/compiler/zig/src/codegen.cpp:10830:28: 0x55bf92d9177b in codegen_build_and_link ([...]/compiler/zig/src/codegen.cpp)
gen_root_source(g);
^
[...]/compiler/zig/src/main.cpp:1662:39: 0x55bf92d61580 in main0 ([...]/compiler/zig/src/main.cpp)
codegen_build_and_link(g);
^
[...]/compiler/zig/src/main.cpp:1849:24: 0x55bf92d62104 in main ([...]/compiler/zig/src/main.cpp)
auto result = main0(argc, argv);
^
???:?:?: 0x7f7e16b770b2 in ??? (???)
untitled_simulationulation...The following command terminated unexpectedly:
[...]/compiler/zig/build/zig build-exe [...]/untitled_sim/src/engine.zig --library c --library X11 --library GL --c-source -std=c99 [...]/untitled_sim/src/engine/c/sokol.c --release-fast --cache-dir [...]/untitled_sim/zig-cache --name untitled_simulationulation -I [...]/untitled_sim/src/engine/c/sokol --main-pkg-path [...]/untitled_sim/src --cache on
Build failed. The following command failed:
[...]/untitled_sim/zig-cache/o/VGfDv2CaRWSMaPFGLRNNxtKqY_X7p5hZ-IDhh09FQB-PQQzY9Z4sgm3qUIcXxGZO/build [...]/compiler/zig/build/zig [...]/untitled_sim [...]/untitled_sim/zig-cache
...which is different from the ir_gen_negation crash.
I am quite confused, and any help would be appreciated.
One thing you can do is use the debugger to print where in your source code it is tripping up the compiler. p inst->src() and p astnode->src() should do the trick, where inst and astnode are the variables of type IrInstruction and AstNode respectively. It looks like you have some of those in scope in the stack trace.
I'm a bit confused though, this issue tracker is for bugs in master branch only, can we focus on getting your project working against master branch zig?
@andrewrk Compiling LLVM11 on Ubuntu 20.04 seems to be quite the unpleasant activity, so I was trying to avoid it. Compiling lld-11.0.0.src with cmake 3.18.4 gives me
CMake Error at tools/lld/CMakeLists.txt:10 (export_executable_symbols_for_plugins):
Unknown CMake command "export_executable_symbols_for_plugins".
On a related note, I would love if there was the option of downloading a -g enabled zig nightly.
On Ubuntu you can use https://apt.llvm.org/
Alright, turns out I tried compiling on latest master, and it works. I tried earlier this week and it didn't! Not complaining!
However, I did uncover another compiler bug on master in the process. I'll use my newly found llvm-gifted debugging skills to open another issue. Thanks for the time @andrewrk!