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

Audit and consolidate stage1/stage2 tests. All behavior tests passing for self-hosted. #6034

Closed
21 tasks done
Tracked by #89
andrewrk opened this issue Aug 11, 2020 · 3 comments
Closed
21 tasks done
Tracked by #89
Labels
backend-llvm The LLVM backend outputs an LLVM IR Module. enhancement Solving this issue will likely involve adding new logic or components to the codebase. frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Milestone

Comments

@andrewrk
Copy link
Member

andrewrk commented Aug 11, 2020

This is a sub-task of #89.

Aside from #6025, here are all the ones that are left:

  • test.slicing array of length 1 can assume runtime index is always zero... SKIP
  • test.generic function with align param... SKIP
  • test.runtime known array index has best alignment possible... SKIP
  • test.align(N) on functions... SKIP
  • test.issue 529 fixed... SKIP
  • test.bug 920 fixed... SKIP
  • test.bug 1120... SKIP
  • test/behavior/bugs/6781.zig... SKIP
  • test.errdefer with payload... SKIP
  • test.equality of pointers to comptime const... SKIP
  • test.storing an array of type in a field... SKIP
  • test.flags in packed structs... SKIP
  • test.arrays in packed structs... SKIP
  • test.consistent size of packed structs... SKIP
  • test.correct sizeOf and offsets in packed structs... SKIP
  • test.nested packed structs... SKIP
  • test.initializer list expression... SKIP
  • test.initializing tuple with explicit type... SKIP
  • test.output constraint modifiers... SKIP
  • test.alternative constraints... SKIP
  • test.struct/array/union types as input values... SKIP
@andrewrk andrewrk added enhancement Solving this issue will likely involve adding new logic or components to the codebase. frontend Tokenization, parsing, AstGen, Sema, and Liveness. stage1 The process of building from source via WebAssembly and the C backend. labels Aug 11, 2020
@andrewrk andrewrk added this to the 0.8.0 milestone Aug 11, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 May 19, 2021
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 Nov 22, 2021
@andrewrk andrewrk added the backend-llvm The LLVM backend outputs an LLVM IR Module. label Mar 8, 2022
@andrewrk andrewrk removed the stage1 The process of building from source via WebAssembly and the C backend. label May 27, 2022
@andrewrk
Copy link
Member Author

test.storing an array of type in a field... SKIP

Here's a debugging session with debug LLVM:

zig: /home/andy/Downloads/llvm-project-13/llvm/include/llvm/IR/Instructions.h:921: llvm::Type* llvm::checkGEPType(llvm::Type*): Assertion `Ty && "Invalid GetElementPtrInst indices for type!"' failed.

Thread 1 "zig" received signal SIGABRT, Aborted.
0x00007ffff7ababaa in raise () from /nix/store/kq5mfvarbjar95xahcf7kd5mfkc64qz3-glibc-2.33-78/lib/libc.so.6
(gdb) up
#1  0x00007ffff7aa5523 in abort () from /nix/store/kq5mfvarbjar95xahcf7kd5mfkc64qz3-glibc-2.33-78/lib/libc.so.6
(gdb) 
#2  0x00007ffff7aa541f in __assert_fail_base.cold.0 () from /nix/store/kq5mfvarbjar95xahcf7kd5mfkc64qz3-glibc-2.33-78/lib/libc.so.6
(gdb) 
#3  0x00007ffff7ab35f2 in __assert_fail () from /nix/store/kq5mfvarbjar95xahcf7kd5mfkc64qz3-glibc-2.33-78/lib/libc.so.6
(gdb) 
#4  0x00000000046a3686 in llvm::checkGEPType (Ty=0x0) at /home/andy/Downloads/llvm-project-13/llvm/include/llvm/IR/Instructions.h:921
921	  assert(Ty && "Invalid GetElementPtrInst indices for type!");
(gdb) p Ty.dump()
Cannot resolve method llvm::Type::dump to any overloaded instance
(gdb) up
#5  0x00000000046a3756 in llvm::GetElementPtrInst::getGEPReturnType (ElTy=0xf24dee8, Ptr=0xf4d9dc0, IdxList=...) at /home/andy/Downloads/llvm-project-13/llvm/include/llvm/IR/Instructions.h:1096
1096	    Type *ResultElemTy = checkGEPType(getIndexedType(ElTy, IdxList));
(gdb) p ElTy->dump()
i8
$1 = void
(gdb) p IdxList->dump()
Couldn't find method llvm::ArrayRef<llvm::Value*>::dump
(gdb) p IdxList
$2 = {
  Data = 0x7ffffffecd70,
  Length = 2
}
(gdb) p IdxList.Data[0]
$3 = (llvm::Value * const) 0xf3496b0
(gdb) p IdxList.Data[0]->dump()
i32 0
$4 = void
(gdb) p IdxList.Data[1]->dump()
i32 0
$5 = void
(gdb) up
#6  0x000000000831f486 in llvm::ConstantFoldGetElementPtr (PointeeTy=0xf24dee8, C=0xf4d9dc0, InBounds=true, InRangeIndex=..., Idxs=...) at /home/andy/Downloads/llvm-project-13/llvm/lib/IR/ConstantFold.cpp:2203
2203	  Type *GEPTy = GetElementPtrInst::getGEPReturnType(
(gdb) 
#7  0x00000000083372e4 in llvm::ConstantExpr::getGetElementPtr (Ty=0xf24dee8, C=0xf4d9dc0, Idxs=..., InBounds=true, InRangeIndex=..., OnlyIfReducedTy=0x0) at /home/andy/Downloads/llvm-project-13/llvm/lib/IR/Constants.cpp:2436
2436	          ConstantFoldGetElementPtr(Ty, C, InBounds, InRangeIndex, Idxs))
(gdb) 
#8  0x0000000005b56299 in llvm::ConstantExpr::getGetElementPtr (Ty=0xf24dee8, C=0xf4d9dc0, IdxList=..., InBounds=true, InRangeIndex=..., OnlyIfReducedTy=0x0) at /home/andy/Downloads/llvm-project-13/llvm/include/llvm/IR/Constants.h:1215
1215	    return getGetElementPtr(
(gdb) 
#9  0x0000000006417a50 in llvm::ConstantExpr::getInBoundsGetElementPtr (Ty=0xf24dee8, C=0xf4d9dc0, IdxList=...) at /home/andy/Downloads/llvm-project-13/llvm/include/llvm/IR/Constants.h:1239
1239	    return getGetElementPtr(Ty, C, IdxList, true);
(gdb) 
#10 0x000000000835d050 in LLVMConstInBoundsGEP (ConstantVal=0xf4d9dc0, ConstantIndices=0x7ffffffecd70, NumIndices=2) at /home/andy/Downloads/llvm-project-13/llvm/lib/IR/Core.cpp:1707
1707	  return wrap(ConstantExpr::getInBoundsGetElementPtr(Ty, Val, IdxList));
(gdb) 
#11 0x00000000010155f3 in codegen.llvm.DeclGen.lowerParentPtr (dg=0x7fffffff03a0, ptr_val={...}, ptr_child_ty={...}) at /home/andy/Downloads/zig/src/codegen/llvm.zig:3548
3548	                        break :blk parent_llvm_ptr.constInBoundsGEP(&indices, indices.len);
(gdb) up
#12 0x000000000100593d in codegen.llvm.DeclGen.lowerValue (dg=0x7fffffff03a0, tv=...) at /home/andy/Downloads/zig/src/codegen/llvm.zig:2938
2938	                    return dg.lowerParentPtr(tv.val, tv.ty.childType());
(gdb) 
#13 0x0000000001541c92 in codegen.llvm.FuncGen.resolveInst (self=0x7fffffff03e0, inst=128) at /home/andy/Downloads/zig/src/codegen/llvm.zig:3861
3861	        const llvm_val = try self.dg.lowerValue(.{ .ty = ty, .val = val });
(gdb) 
#14 0x000000000136f063 in codegen.llvm.FuncGen.airCall (self=0x7fffffff03e0, inst=60, attr=Auto) at /home/andy/Downloads/zig/src/codegen/llvm.zig:4122
4122	                const llvm_arg = try self.resolveInst(arg);
(gdb) p self.dg.decl.name
$6 = (u8 *) 0xf313f40 "test_0"
(gdb) 

In summary it looks like an instance of a Foobar is getting lowered to an LLVM value, but that should be a comptime-only type, never sent to codegen.

@andrewrk
Copy link
Member Author

test.initializer list expression... SKIP

Here's a reduced test case:

comptime {
    var s: S = undefined;
    @ptrCast(*[3]u8, &s)[0] = 0;
}

pub const S = extern struct {
    a: u8,
    b: u8,
    c: u8,
};
thread 292651 panic: index out of bounds
Analyzing test2.zig: test2.zig:comptime_0
      %108 = decl_val("S") token_offset:29:12
      %109 = alloc_comptime_mut(%108) node_offset:29:5
      %110 = store_node(%109, @Zir.Inst.Ref.undef) node_offset:29:16
      %111 = int(3)
      %112 = array_type(%111, @Zir.Inst.Ref.u8_type)
      %113 = ptr_type_simple(%112, One)
      %114 = ptr_cast(%113, %109) node_offset:30:5
      %115 = ref(%114) token_offset:30:5
      %116 = as_node(@Zir.Inst.Ref.usize_type, @Zir.Inst.Ref.zero) node_offset:30:26
      %117 = elem_ptr(%115, %116)
    > %118 = store_node(%117, @Zir.Inst.Ref.zero) node_offset:30:31
      %119 = break_inline(%107, @Zir.Inst.Ref.void_value)
    For full context, use the command
      zig ast-check -t test2.zig


/home/andy/dev/zig/src/value.zig:1367:81: 0x3620a8a in value.Value.readFromMemory (zig)
                        field_vals[i] = try readFromMemory(field.ty, mod, buffer[off..], arena);
                                                                                ^
/home/andy/dev/zig/src/Sema.zig:21219:32: 0x34ac5a5 in Sema.bitCastVal (zig)
    return Value.readFromMemory(new_ty, sema.mod, buffer[buffer_offset..], sema.arena);
                               ^
/home/andy/dev/zig/src/Sema.zig:20527:46: 0x342ce51 in Sema.storePtrVal (zig)
    const bitcasted_val = try sema.bitCastVal(block, src, operand_val, operand_ty, mut_kit.ty, 0);
                                             ^
/home/andy/dev/zig/src/Sema.zig:20457:33: 0x342798b in Sema.storePtr2 (zig)
            try sema.storePtrVal(block, src, ptr_val, operand_val, elem_ty);
                                ^
/home/andy/dev/zig/src/Sema.zig:20391:26: 0x34b19ca in Sema.storePtr (zig)
    return sema.storePtr2(block, src, ptr, src, uncasted_operand, src, .store);
                         ^
/home/andy/dev/zig/src/Sema.zig:4044:25: 0x34126e6 in Sema.zirStoreNode (zig)
    return sema.storePtr(block, src, ptr, operand);
                        ^
/home/andy/dev/zig/src/Sema.zig:1033:38: 0x32341dc in Sema.analyzeBodyInner (zig)
                try sema.zirStoreNode(block, inst);
                                     ^

@andrewrk
Copy link
Member Author

This is done as of 13f02c3. #6025 is still open to track async functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend-llvm The LLVM backend outputs an LLVM IR Module. enhancement Solving this issue will likely involve adding new logic or components to the codebase. frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Projects
None yet
Development

No branches or pull requests

1 participant