-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Vector of bool trips LLVM assertion "Invalid vector size" #11587
Comments
I confirmed this affects stage1 but not stage2. |
Given that this works fine if you change it to a vector of u8: export fn vector_bitcast() u8 {
const a: @Vector(4, u8) = [_]u8{ 1, 2, 3, 4 };
const result_array: [4]u8 = a;
return result_array[0];
} I think this is actually llvm/llvm-project#55522. I also tried this patch which had no effect: --- a/src/codegen/llvm.zig
+++ b/src/codegen/llvm.zig
@@ -1476,10 +1476,17 @@ pub const Object = struct {
return array_di_ty;
},
.Vector => {
+ // Lower vector of bool with the element type being a u1 instead so that
+ // LLVM debug info does not get confused and think that the element type has
+ // 8 bits instead of 1.
+ const elem_di_ty = if (ty.childType().zigTypeTag() == .Bool)
+ try o.lowerDebugType(Type.u1, .full)
+ else
+ try o.lowerDebugType(ty.childType(), .full);
const vector_di_ty = dib.createVectorType(
ty.abiSize(target) * 8,
ty.abiAlignment(target) * 8,
- try o.lowerDebugType(ty.childType(), .full),
+ elem_di_ty,
ty.vectorLen(),
);
// The recursive call to `lowerDebugType` means we can't use `gop` anymore.
--- a/src/stage1/analyze.cpp
+++ b/src/stage1/analyze.cpp
@@ -9933,8 +9933,14 @@ static void resolve_llvm_types(CodeGen *g, ZigType *type, ResolveStatus wanted_r
if (type->llvm_di_type != nullptr) return;
type->llvm_type = LLVMVectorType(get_llvm_type(g, type->data.vector.elem_type), type->data.vector.len);
- type->llvm_di_type = ZigLLVMDIBuilderCreateVectorType(g->dbuilder, 8 * type->abi_size,
- type->abi_align, get_llvm_di_type(g, type->data.vector.elem_type), type->data.vector.len);
+ ZigLLVMDIType *elem_di_ty = type->data.vector.elem_type->id == ZigTypeIdBool ?
+ get_llvm_di_type(g, get_int_type(g, false, 1)) :
+ get_llvm_di_type(g, type->data.vector.elem_type) ;
+ type->llvm_di_type = ZigLLVMDIBuilderCreateVectorType(g->dbuilder,
+ 8 * type->abi_size,
+ 8 * type->abi_align,
+ elem_di_ty,
+ type->data.vector.len);
return;
}
case ZigTypeIdFnFrame: We don't actually have a zig issue specifically open to track that upstream issue, however, so this one can be it. |
Hmm looks like actually this is a separate issue from that LLVM issue because this diff did solve the issue: --- a/src/stage1/analyze.cpp
+++ b/src/stage1/analyze.cpp
@@ -9933,8 +9933,15 @@ static void resolve_llvm_types(CodeGen *g, ZigType *type, ResolveStatus wanted_r
if (type->llvm_di_type != nullptr) return;
type->llvm_type = LLVMVectorType(get_llvm_type(g, type->data.vector.elem_type), type->data.vector.len);
- type->llvm_di_type = ZigLLVMDIBuilderCreateVectorType(g->dbuilder, 8 * type->abi_size,
- type->abi_align, get_llvm_di_type(g, type->data.vector.elem_type), type->data.vector.len);
+ ZigLLVMDIType *elem_di_ty = type->data.vector.elem_type->id == ZigTypeIdBool ?
+ ZigLLVMCreateDebugBasicType(g->dbuilder, "bool", 1,
+ ZigLLVMEncoding_DW_ATE_unsigned()) :
+ get_llvm_di_type(g, type->data.vector.elem_type) ;
+ type->llvm_di_type = ZigLLVMDIBuilderCreateVectorType(g->dbuilder,
+ 8 * type->abi_size,
+ 8 * type->abi_align,
+ elem_di_ty,
+ type->data.vector.len);
return;
}
case ZigTypeIdFnFrame: stage2 does not have this issue because integer and boolean types use the proper bit size rather than abi_size * 8. |
@andrewrk here is how I was planning to solve this issue: in codegen.cpp@add_fp_entry use https://github.com/gwenzek/zig/pull/4/files#r912686791 |
stage2 already has this fixed; debug info is given size in bits rather than ABI size (bytes) multiplied by 8. closes #11587
stage2 already has this fixed; debug info is given size in bits rather than ABI size (bytes) multiplied by 8. closes ziglang#11587
Zig Version
0.9.0+my_fork https://github.com/gwenzek/zig/tree/llvm14
(To work on #11274 )
Steps to Reproduce
Simplified version of test/behavior/vector.zig
Note: I'm using LLVM14 built with assertions on, but I don't think that LLVM14 is the main issue since this assertion is 4 years old
https://github.com/llvm/llvm-project/blame/75f9e83ace52773af65dcebca543005ec8a2705d/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp#L1473
A reduced version of the LLVM IR is:
Calling
llc
on it will also fail with the same error (unless built without assertions):As you can see from the IR, the bug is only due to the debug info and not to the actual code.
The issue is that:
a
is a vector of 4 booleansa
has a size of 8 bitsExpected Behavior
I'm not sure what's the correct way of fixing this, but we shouldn't have an assertion error while writing the Dwarf Debug Info
Either:
DwarfUnit.cpp
shouldn't try to assert the vector size (I guess the reader of debug info should make this kind of checks if it's relevant to them)Actual Behavior
The text was updated successfully, but these errors were encountered: