Skip to content

Commit 4b4b6d6

Browse files
vmaksimosys-ce-bb
authored andcommitted
Fix translation for static TypeMember for dwarf5 (#2231)
This resolves #2224 and fixes #2229 Original commit: KhronosGroup/SPIRV-LLVM-Translator@10d1285
1 parent 5fd4877 commit 4b4b6d6

File tree

5 files changed

+86
-18
lines changed

5 files changed

+86
-18
lines changed

llvm-spirv/lib/SPIRV/LLVMToSPIRVDbgTran.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ SPIRVEntry *LLVMToSPIRVDbgTran::transDbgEntryImpl(const MDNode *MDN) {
360360
if (const DIGlobalVariable *GV = dyn_cast<DIGlobalVariable>(DIEntry))
361361
return transDbgGlobalVariable(GV);
362362
if (const DIDerivedType *MT = dyn_cast<DIDerivedType>(DIEntry))
363-
if (MT->isStaticMember())
363+
if (M->getDwarfVersion() >= 5 && MT->isStaticMember())
364364
return transDbgMemberType(MT);
365365
llvm_unreachable("Unxpected debug info type for variable");
366366
case dwarf::DW_TAG_formal_parameter:

llvm-spirv/lib/SPIRV/SPIRVToLLVMDbgTran.cpp

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -702,14 +702,19 @@ SPIRVToLLVMDbgTran::transTypeMemberOpenCL(const SPIRVExtInst *DebugInst) {
702702
}
703703
if (SPIRVFlags & SPIRVDebug::FlagIsStaticMember)
704704
Flags |= DINode::FlagStaticMember;
705-
if (Flags & DINode::FlagStaticMember && Ops.size() > MinOperandCount) {
706-
SPIRVValue *ConstVal = BM->get<SPIRVValue>(Ops[ValueIdx]);
707-
assert(isConstantOpCode(ConstVal->getOpCode()) &&
708-
"Static member must be a constant");
709-
llvm::Value *Val = SPIRVReader->transValue(ConstVal, nullptr, nullptr);
705+
if (Flags & DINode::FlagStaticMember) {
706+
llvm::Value *Val = nullptr;
707+
if (Ops.size() > MinOperandCount) {
708+
SPIRVValue *ConstVal = BM->get<SPIRVValue>(Ops[ValueIdx]);
709+
assert(isConstantOpCode(ConstVal->getOpCode()) &&
710+
"Static member must be a constant");
711+
Val = SPIRVReader->transValue(ConstVal, nullptr, nullptr);
712+
}
713+
auto Tag = M->getDwarfVersion() >= 5 ? llvm::dwarf::DW_TAG_variable
714+
: llvm::dwarf::DW_TAG_member;
710715
return getDIBuilder(DebugInst).createStaticMemberType(
711-
Scope, Name, File, LineNo, BaseType, Flags, cast<llvm::Constant>(Val),
712-
llvm::dwarf::DW_TAG_member);
716+
Scope, Name, File, LineNo, BaseType, Flags,
717+
cast_or_null<llvm::Constant>(Val), Tag);
713718
}
714719
uint64_t Size = BM->get<SPIRVConstant>(Ops[SizeIdx])->getZExtIntValue();
715720
uint64_t Alignment = 0;
@@ -753,14 +758,19 @@ SPIRVToLLVMDbgTran::transTypeMemberNonSemantic(const SPIRVExtInst *DebugInst,
753758
if (SPIRVFlags & SPIRVDebug::FlagBitField)
754759
Flags |= DINode::FlagBitField;
755760

756-
if (Flags & DINode::FlagStaticMember && Ops.size() > MinOperandCount) {
757-
SPIRVValue *ConstVal = BM->get<SPIRVValue>(Ops[ValueIdx]);
758-
assert(isConstantOpCode(ConstVal->getOpCode()) &&
759-
"Static member must be a constant");
760-
llvm::Value *Val = SPIRVReader->transValue(ConstVal, nullptr, nullptr);
761+
if (Flags & DINode::FlagStaticMember) {
762+
llvm::Value *Val = nullptr;
763+
if (Ops.size() > MinOperandCount) {
764+
SPIRVValue *ConstVal = BM->get<SPIRVValue>(Ops[ValueIdx]);
765+
assert(isConstantOpCode(ConstVal->getOpCode()) &&
766+
"Static member must be a constant");
767+
Val = SPIRVReader->transValue(ConstVal, nullptr, nullptr);
768+
}
769+
auto Tag = M->getDwarfVersion() >= 5 ? llvm::dwarf::DW_TAG_variable
770+
: llvm::dwarf::DW_TAG_member;
761771
return getDIBuilder(DebugInst).createStaticMemberType(
762-
Scope, Name, File, LineNo, BaseType, Flags, cast<llvm::Constant>(Val),
763-
llvm::dwarf::DW_TAG_member);
772+
Scope, Name, File, LineNo, BaseType, Flags,
773+
cast_or_null<llvm::Constant>(Val), Tag);
764774
}
765775
uint64_t Size = BM->get<SPIRVConstant>(Ops[SizeIdx])->getZExtIntValue();
766776
uint64_t Alignment = 0;

llvm-spirv/test/DebugInfo/Generic/dwarf-public-names.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ attributes #1 = { nounwind readnone }
109109
!2 = !DICompositeType(tag: DW_TAG_structure_type, name: "C", file: !3, line: 1, size: 8, align: 8, elements: !4)
110110
!3 = !DIFile(filename: "dwarf-public-names.cpp", directory: "/usr2/kparzysz/s.hex/t")
111111
!4 = !{!5, !7, !12}
112-
!5 = !DIDerivedType(tag: DW_TAG_variable, name: "static_member_variable", scope: !2, file: !3, line: 4, baseType: !6, flags: DIFlagStaticMember)
112+
!5 = !DIDerivedType(tag: DW_TAG_member, name: "static_member_variable", scope: !2, file: !3, line: 4, baseType: !6, flags: DIFlagStaticMember)
113113
!6 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
114114
!7 = !DISubprogram(name: "member_function", linkageName: "_ZN1C15member_functionEv", scope: !2, file: !3, line: 2, type: !8, isLocal: false, isDefinition: false, scopeLine: 2, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, retainedNodes: !11)
115115
!8 = !DISubroutineType(types: !9)
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
; RUN: llvm-as < %s -o %t.bc
2+
3+
; RUN: llvm-spirv %t.bc -o %t.spv
4+
; RUN: llvm-spirv -r %t.spv -o - | llvm-dis -o - | FileCheck %s
5+
6+
; RUN: llvm-spirv %t.bc -o %t.spv -spirv-debug-info-version=nonsemantic-shader-100
7+
; RUN: llvm-spirv -r %t.spv -o - | llvm-dis -o - | FileCheck %s
8+
9+
; RUN: llvm-spirv %t.bc -o %t.spv -spirv-debug-info-version=nonsemantic-shader-200
10+
; RUN: llvm-spirv -r %t.spv -o - | llvm-dis -o - | FileCheck %s
11+
12+
; Generated from:
13+
;
14+
; struct A {
15+
; static int fully_specified;
16+
; static int smem[];
17+
; };
18+
;
19+
; int A::fully_specified;
20+
; int A::smem[] = { 0, 1, 2, 3 };
21+
22+
; CHECK: ![[#]] = !DIDerivedType(tag: DW_TAG_variable, name: "smem", scope: ![[#StructTy:]], file: ![[#]], line: 4, baseType: ![[#]], flags: DIFlagPublic | DIFlagStaticMember)
23+
; CHECK: ![[#]] = !DIDerivedType(tag: DW_TAG_variable, name: "fully_specified", scope: ![[#StructTy]], file: ![[#]], line: 3, baseType: ![[#]], flags: DIFlagPublic | DIFlagStaticMember)
24+
25+
26+
source_filename = "static_member_array.cpp"
27+
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
28+
target triple = "spir64-unknown-unknown"
29+
30+
@_ZN1A15fully_specifiedE = global i32 0, align 4, !dbg !0
31+
@_ZN1A4smemE = global [4 x i32] [i32 0, i32 1, i32 2, i32 3], align 16, !dbg !6
32+
33+
!llvm.dbg.cu = !{!2}
34+
!llvm.module.flags = !{!19, !20, !21}
35+
36+
!0 = distinct !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
37+
!1 = !DIGlobalVariable(name: "fully_specified", linkageName: "_ZN1A15fully_specifiedE", scope: !2, file: !3, line: 7, type: !9, isLocal: false, isDefinition: true, declaration: !15)
38+
!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5)
39+
!3 = !DIFile(filename: "static_member_array.cpp", directory: "")
40+
!4 = !{}
41+
!5 = !{!0, !6}
42+
!6 = distinct !DIGlobalVariableExpression(var: !7, expr: !DIExpression())
43+
!7 = !DIGlobalVariable(name: "smem", linkageName: "_ZN1A4smemE", scope: !2, file: !3, line: 8, type: !8, isLocal: false, isDefinition: true, declaration: !12)
44+
!8 = !DICompositeType(tag: DW_TAG_array_type, baseType: !9, size: 128, elements: !10)
45+
!9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
46+
!10 = !{!11}
47+
!11 = !DISubrange(count: 4)
48+
!12 = !DIDerivedType(tag: DW_TAG_variable, name: "smem", scope: !13, file: !3, line: 4, baseType: !16, flags: DIFlagStaticMember)
49+
!13 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "A", file: !3, line: 1, size: 8, elements: !14, identifier: "_ZTS1A")
50+
!14 = !{!15, !12}
51+
!15 = !DIDerivedType(tag: DW_TAG_variable, name: "fully_specified", scope: !13, file: !3, line: 3, baseType: !9, flags: DIFlagStaticMember)
52+
!16 = !DICompositeType(tag: DW_TAG_array_type, baseType: !9, elements: !17)
53+
!17 = !{!18}
54+
!18 = !DISubrange(count: -1)
55+
!19 = !{i32 2, !"Dwarf Version", i32 5}
56+
!20 = !{i32 2, !"Debug Info Version", i32 3}
57+
!21 = !{i32 1, !"PIC Level", i32 2}
58+

llvm-spirv/test/DebugInfo/NonSemantic/static_member_array.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ target triple = "spir64-unknown-unknown"
6666
!9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
6767
!10 = !{!11}
6868
!11 = !DISubrange(count: 4)
69-
!12 = !DIDerivedType(tag: DW_TAG_variable, name: "smem", scope: !13, file: !3, line: 4, baseType: !16, flags: DIFlagStaticMember)
69+
!12 = !DIDerivedType(tag: DW_TAG_member, name: "smem", scope: !13, file: !3, line: 4, baseType: !16, flags: DIFlagStaticMember)
7070
!13 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "A", file: !3, line: 1, size: 8, elements: !14, identifier: "_ZTS1A")
7171
!14 = !{!15, !12}
72-
!15 = !DIDerivedType(tag: DW_TAG_variable, name: "fully_specified", scope: !13, file: !3, line: 3, baseType: !9, flags: DIFlagStaticMember)
72+
!15 = !DIDerivedType(tag: DW_TAG_member, name: "fully_specified", scope: !13, file: !3, line: 3, baseType: !9, flags: DIFlagStaticMember)
7373
!16 = !DICompositeType(tag: DW_TAG_array_type, baseType: !9, elements: !17)
7474
!17 = !{!18}
7575
!18 = !DISubrange(count: -1)

0 commit comments

Comments
 (0)