Skip to content

Codegen failure on generator branch #4110

@fengb

Description

@fengb

I have attached the new generator-based format to debug.warn and Zig is crashing on codegen. Not sure how it can be reduced since this is a big integration test of whether generators will work.

$ zig test lib/std/fmt/parse_float.zig --override-lib-dir lib
Code Generation [532/691] std.fmtgen.formatType...Segmentation fault: 11

Here's a few culprits:

Debugger session that may or may not be useful:

(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
  * frame #0: 0x00000001031a8fc4 zig`llvm::PointerType::get(llvm::Type*, unsigned int) + 20
    frame #1: 0x0000000103120f3f zig`llvm::GetElementPtrInst::getGEPReturnType(llvm::Type*, llvm::Value*, llvm::ArrayRef<llvm::Value*>) + 63
    frame #2: 0x0000000102bde72c zig`llvm::GetElementPtrInst::Create(llvm::Type*, llvm::Value*, llvm::ArrayRef<llvm::Value*>, llvm::Twine const&, llvm::Instruction*) + 108
    frame #3: 0x0000000101d72d6d zig`llvm::IRBuilder<llvm::ConstantFolder, llvm::IRBuilderDefaultInserter>::CreateConstInBoundsGEP2_32(llvm::Type*, llvm::Value*, unsigned int, unsigned int, llvm::Twine const&) + 189
    frame #4: 0x000000010311f961 zig`LLVMBuildStructGEP + 70
    frame #5: 0x0000000100061c30 zig`ir_render_struct_field_ptr(g=0x000000010981e400, executable=0x00000001377a22d0, instruction=0x00000001355d81a0) at codegen.cpp:4433:34
    frame #6: 0x000000010005c53b zig`ir_render_instruction(g=0x000000010981e400, executable=0x00000001377a22d0, instruction=0x00000001355d81a0) at codegen.cpp:6335:20
    frame #7: 0x000000010005b7a2 zig`ir_render(g=0x000000010981e400, fn_entry=0x00000001377a2250) at codegen.cpp:6497:39
    frame #8: 0x000000010004d418 zig`do_code_gen(g=0x000000010981e400) at codegen.cpp:7846:9
    frame #9: 0x0000000100049980 zig`codegen_build_and_link(g=0x000000010981e400) at codegen.cpp:10480:13
    frame #10: 0x0000000100007dea zig`main(argc=5, argv=0x00007ffeefbff820) at main.cpp:1350:17
    frame #11: 0x00007fff655e02e5 libdyld.dylib`start + 1

(lldb) up 5
frame #5: 0x0000000100061c30 zig`ir_render_struct_field_ptr(g=0x000000010981e400, executable=0x00000001377a22d0, instruction=0x00000001355d81a0) at codegen.cpp:4433:34
   4430	        codegen_report_errors_and_exit(g);
   4431	
   4432	    ir_assert(field->gen_index != SIZE_MAX, &instruction->base);
-> 4433	    LLVMValueRef field_ptr_val = LLVMBuildStructGEP(g->builder, struct_ptr, (unsigned)field->gen_index, "");
   4434	    ZigType *res_type = instruction->base.value->type;
   4435	    ir_assert(res_type->id == ZigTypeIdPointer, &instruction->base);
   4436	    if (res_type->data.pointer.host_int_bytes != 0) {

(lldb) p *instruction
(IrInstructionStructFieldPtr) $4 = {
  base = {
    scope = 0x0000000140545c70
    source_node = 0x000000010c84e760
    llvm_value = 0x0000000000000000
    value = 0x00000001355d8200
    debug_id = 330
    ref_count = 2
    child = 0x0000000000000000
    owner_bb = 0x00000001355d6d90
    spill = 0x0000000000000000
    id = IrInstructionIdStructFieldPtr
    is_gen = false
  }
  struct_ptr = 0x00000001355d80e0
  field = 0x000000010e83ca90
  is_const = false
}

(lldb) po instruction->base.dump()
~/zig/lib/std/fmtgen.zig:1014:26    // const width = options.width orelse 0;
#330| StructFieldPtr        | *const ?usize| 2 | @StructFieldPtr(&#329.width)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorstage1The process of building from source via WebAssembly and the C backend.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions