-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Description
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
const std = @import("std");
const Vector = std.meta.Vector;
export fn vector_bitcast() u8 {
const a: Vector(4, bool) = [_]bool{ true, false, true, false };
const result_array: [4]bool = a;
return if (result_array[0]) 0 else 1;
}$ /home/guw/github/zig-bootstrap/out/build-zig-host/zig build-obj -I test --zig-lib-dir lib -Denable-llvm -Dconfig_h=/home/guw/github/zig-bootstrap/out/build-zig-host/config.h test/behavior/vector.zig
LLVM Emit Object... zig: /home/guw/github/zig-bootstrap/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp:1475: bool hasVectorBeenPadded(const llvm::DICompositeType*): Assertion `ActualSize >= (NumVecElements * ElementSize) && "Invalid vector size"' failed.
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:
define i8 @vector_bitcast() !dbg !5 {
Entry:
store i8 0, i8* null, align 1, !dbg !19
ret i8 0
}
!llvm.module.flags = !{!0, !1}
!llvm.dbg.cu = !{!2}
!0 = !{i32 2, !"Debug Info Version", i32 3}
!1 = !{i32 2, !"Dwarf Version", i32 4}
!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "zig 0.9.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !4)
!3 = !DIFile(filename: "vector", directory: "test/behavior")
!4 = !{}
!5 = distinct !DISubprogram(name: "vector_bitcast", scope: !6, file: !6, line: 22, type: !7, scopeLine: 22, flags: DIFlagStaticMember, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !10)
!6 = !DIFile(filename: "vector.zig", directory: "/home/guw/github/zig-bootstrap/zig/test/behavior")
!7 = !DISubroutineType(types: !8)
!8 = !{!9}
!9 = !DIBasicType(name: "u8", size: 8, encoding: DW_ATE_unsigned_char)
!10 = !{!11, !17}
!11 = !DILocalVariable(name: "a", scope: !12, file: !6, line: 23, type: !13)
!12 = distinct !DILexicalBlock(scope: !5, file: !6, line: 22, column: 31)
!13 = !DICompositeType(tag: DW_TAG_array_type, baseType: !14, size: 8, align: 1, flags: DIFlagVector, elements: !15)
!14 = !DIBasicType(name: "bool", size: 8, encoding: DW_ATE_boolean)
!15 = !{!16}
!16 = !DISubrange(count: 4, lowerBound: 0)
!17 = !DILocalVariable(name: "result_array", scope: !12, file: !6, line: 24, type: !18)
!18 = !DICompositeType(tag: DW_TAG_array_type, baseType: !14, size: 32, align: 32, elements: !15)
!19 = !DILocation(line: 25, column: 33, scope: !12)Calling llc on it will also fail with the same error (unless built without assertions):
[guw@jinx-fedora zig]$ /home/guw/github/zig-bootstrap/out/host/bin/llc vector.ll
llc: /home/guw/github/zig-bootstrap/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp:1475: bool hasVectorBeenPadded(const llvm::DICompositeType*): Assertion `ActualSize >= (NumVecElements * ElementSize) && "Invalid vector size"' failed.
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:
ais a vector of 4 booleansahas a size of 8 bits- booleans have a size of 8 bits too
- DwarfUnit.cpp doesn't understand how we can fit 4 8-bits booleans inside an 8 bits vector.
Expected 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:
- Zig should say that the vector is made of 1-bit booleans
DwarfUnit.cppshouldn'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
/home/guw/github/zig-bootstrap/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp:1475: bool hasVectorBeenPadded(const llvm::DICompositeType*): Assertion `ActualSize >= (NumVecElements * ElementSize) && "Invalid vector size"' failed.