Skip to content

Commit 6f1afb4

Browse files
authored
Fix transTypeComposite bug (#964)
* Fix transTypeComposite bug This is a workaround to fix an error caused by DIBuilder which always creates a node with the DW_TAG_struct_type tag for both class and structure.
1 parent ea6935b commit 6f1afb4

File tree

2 files changed

+79
-4
lines changed

2 files changed

+79
-4
lines changed

lib/SPIRV/SPIRVToLLVMDbgTran.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,12 @@ SPIRVToLLVMDbgTran::transTypeComposite(const SPIRVExtInst *DebugInst) {
267267
DICompositeType *CT = nullptr;
268268
switch (Ops[TagIdx]) {
269269
case SPIRVDebug::Class:
270-
CT = Builder.createClassType(
271-
ParentScope, Name, File, LineNo, Size, Align, 0, Flags, DerivedFrom,
272-
DINodeArray() /*elements*/, nullptr /*VTableHolder*/,
273-
nullptr /*TemplateParams*/, Identifier);
270+
// TODO: should be replaced with createClassType, when bug with creating
271+
// ClassType with llvm::dwarf::DW_TAG_struct_type tag will be fixed
272+
CT = Builder.createReplaceableCompositeType(
273+
llvm::dwarf::DW_TAG_class_type, Name, ParentScope, File, LineNo, 0,
274+
Size, Align, Flags, Identifier);
275+
CT = llvm::MDNode::replaceWithDistinct(llvm::TempDICompositeType(CT));
274276
break;
275277
case SPIRVDebug::Structure:
276278
CT = Builder.createStructType(ParentScope, Name, File, LineNo, Size, Align,
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
; Source code:
2+
; class A {};
3+
; struct B {};
4+
5+
; int main() {
6+
; A a;
7+
; B b;
8+
; return 0;
9+
; }
10+
11+
; RUN: llvm-as %s -o %t.bc
12+
; RUN: llvm-spirv %t.bc -o %t.spv
13+
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
14+
; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM
15+
16+
; ModuleID = 'main.cpp'
17+
source_filename = "main.cpp"
18+
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64"
19+
target triple = "spir64"
20+
21+
%class.A = type { i8 }
22+
%struct.B = type { i8 }
23+
24+
; Function Attrs: noinline norecurse nounwind optnone mustprogress
25+
define dso_local i32 @main() #0 !dbg !6 {
26+
entry:
27+
%retval = alloca i32, align 4
28+
%a = alloca %class.A, align 1
29+
%b = alloca %struct.B, align 1
30+
store i32 0, i32* %retval, align 4
31+
call void @llvm.dbg.declare(metadata %class.A* %a, metadata !11, metadata !DIExpression()), !dbg !13
32+
call void @llvm.dbg.declare(metadata %struct.B* %b, metadata !14, metadata !DIExpression()), !dbg !16
33+
ret i32 0, !dbg !17
34+
}
35+
36+
; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
37+
declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
38+
39+
attributes #0 = { noinline norecurse nounwind optnone mustprogress "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
40+
attributes #1 = { nofree nosync nounwind readnone speculatable willreturn }
41+
42+
!llvm.dbg.cu = !{!0}
43+
!llvm.module.flags = !{!3, !4}
44+
!opencl.used.extensions = !{!2}
45+
!opencl.used.optional.core.features = !{!2}
46+
!opencl.compiler.options = !{!2}
47+
!llvm.ident = !{!5}
48+
49+
; CHECK-LLVM: !DICompositeType
50+
; CHECK-LLVM-SAME: tag: DW_TAG_class_type
51+
; CHECK-LLVM-SAME: name: "A"
52+
; CHECK-LLVM: !DICompositeType
53+
; CHECK-LLVM-SAME: tag: DW_TAG_structure_type
54+
; CHECK-LLVM-SAME: name: "B"
55+
56+
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 13.0.0 (https://github.com/llvm/llvm-project.git 16a50c9e642fd085e5ceb68c403b71b5b2e0607c)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
57+
!1 = !DIFile(filename: "<stdin>", directory: "/export/users")
58+
!2 = !{}
59+
!3 = !{i32 2, !"Debug Info Version", i32 3}
60+
!4 = !{i32 1, !"wchar_size", i32 4}
61+
!5 = !{!"clang version 13.0.0 (https://github.com/llvm/llvm-project.git 16a50c9e642fd085e5ceb68c403b71b5b2e0607c)"}
62+
!6 = distinct !DISubprogram(name: "main", scope: !7, file: !7, line: 4, type: !8, scopeLine: 4, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
63+
!7 = !DIFile(filename: "main.cpp", directory: "/export/users")
64+
!8 = !DISubroutineType(types: !9)
65+
!9 = !{!10}
66+
!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
67+
!11 = !DILocalVariable(name: "a", scope: !6, file: !7, line: 5, type: !12)
68+
!12 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "A", file: !7, line: 1, size: 8, flags: DIFlagTypePassByValue, elements: !2, identifier: "_ZTS1A")
69+
!13 = !DILocation(line: 5, column: 7, scope: !6)
70+
!14 = !DILocalVariable(name: "b", scope: !6, file: !7, line: 6, type: !15)
71+
!15 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "B", file: !7, line: 2, size: 8, flags: DIFlagTypePassByValue, elements: !2, identifier: "_ZTS1B")
72+
!16 = !DILocation(line: 6, column: 7, scope: !6)
73+
!17 = !DILocation(line: 7, column: 5, scope: !6)

0 commit comments

Comments
 (0)