Skip to content

Commit

Permalink
Fix translation for static TypeMember for dwarf5 (#2231)
Browse files Browse the repository at this point in the history
This resolves #2224 and fixes #2229
  • Loading branch information
vmaksimo authored Nov 24, 2023
1 parent 32786ff commit 10d1285
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 18 deletions.
2 changes: 1 addition & 1 deletion lib/SPIRV/LLVMToSPIRVDbgTran.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ SPIRVEntry *LLVMToSPIRVDbgTran::transDbgEntryImpl(const MDNode *MDN) {
if (const DIGlobalVariable *GV = dyn_cast<DIGlobalVariable>(DIEntry))
return transDbgGlobalVariable(GV);
if (const DIDerivedType *MT = dyn_cast<DIDerivedType>(DIEntry))
if (MT->isStaticMember())
if (M->getDwarfVersion() >= 5 && MT->isStaticMember())
return transDbgMemberType(MT);
llvm_unreachable("Unxpected debug info type for variable");
case dwarf::DW_TAG_formal_parameter:
Expand Down
38 changes: 24 additions & 14 deletions lib/SPIRV/SPIRVToLLVMDbgTran.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -702,14 +702,19 @@ SPIRVToLLVMDbgTran::transTypeMemberOpenCL(const SPIRVExtInst *DebugInst) {
}
if (SPIRVFlags & SPIRVDebug::FlagIsStaticMember)
Flags |= DINode::FlagStaticMember;
if (Flags & DINode::FlagStaticMember && Ops.size() > MinOperandCount) {
SPIRVValue *ConstVal = BM->get<SPIRVValue>(Ops[ValueIdx]);
assert(isConstantOpCode(ConstVal->getOpCode()) &&
"Static member must be a constant");
llvm::Value *Val = SPIRVReader->transValue(ConstVal, nullptr, nullptr);
if (Flags & DINode::FlagStaticMember) {
llvm::Value *Val = nullptr;
if (Ops.size() > MinOperandCount) {
SPIRVValue *ConstVal = BM->get<SPIRVValue>(Ops[ValueIdx]);
assert(isConstantOpCode(ConstVal->getOpCode()) &&
"Static member must be a constant");
Val = SPIRVReader->transValue(ConstVal, nullptr, nullptr);
}
auto Tag = M->getDwarfVersion() >= 5 ? llvm::dwarf::DW_TAG_variable
: llvm::dwarf::DW_TAG_member;
return getDIBuilder(DebugInst).createStaticMemberType(
Scope, Name, File, LineNo, BaseType, Flags, cast<llvm::Constant>(Val),
llvm::dwarf::DW_TAG_member);
Scope, Name, File, LineNo, BaseType, Flags,
cast_or_null<llvm::Constant>(Val), Tag);
}
uint64_t Size = BM->get<SPIRVConstant>(Ops[SizeIdx])->getZExtIntValue();
uint64_t Alignment = 0;
Expand Down Expand Up @@ -753,14 +758,19 @@ SPIRVToLLVMDbgTran::transTypeMemberNonSemantic(const SPIRVExtInst *DebugInst,
if (SPIRVFlags & SPIRVDebug::FlagBitField)
Flags |= DINode::FlagBitField;

if (Flags & DINode::FlagStaticMember && Ops.size() > MinOperandCount) {
SPIRVValue *ConstVal = BM->get<SPIRVValue>(Ops[ValueIdx]);
assert(isConstantOpCode(ConstVal->getOpCode()) &&
"Static member must be a constant");
llvm::Value *Val = SPIRVReader->transValue(ConstVal, nullptr, nullptr);
if (Flags & DINode::FlagStaticMember) {
llvm::Value *Val = nullptr;
if (Ops.size() > MinOperandCount) {
SPIRVValue *ConstVal = BM->get<SPIRVValue>(Ops[ValueIdx]);
assert(isConstantOpCode(ConstVal->getOpCode()) &&
"Static member must be a constant");
Val = SPIRVReader->transValue(ConstVal, nullptr, nullptr);
}
auto Tag = M->getDwarfVersion() >= 5 ? llvm::dwarf::DW_TAG_variable
: llvm::dwarf::DW_TAG_member;
return getDIBuilder(DebugInst).createStaticMemberType(
Scope, Name, File, LineNo, BaseType, Flags, cast<llvm::Constant>(Val),
llvm::dwarf::DW_TAG_member);
Scope, Name, File, LineNo, BaseType, Flags,
cast_or_null<llvm::Constant>(Val), Tag);
}
uint64_t Size = BM->get<SPIRVConstant>(Ops[SizeIdx])->getZExtIntValue();
uint64_t Alignment = 0;
Expand Down
2 changes: 1 addition & 1 deletion test/DebugInfo/Generic/dwarf-public-names.ll
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ attributes #1 = { nounwind readnone }
!2 = !DICompositeType(tag: DW_TAG_structure_type, name: "C", file: !3, line: 1, size: 8, align: 8, elements: !4)
!3 = !DIFile(filename: "dwarf-public-names.cpp", directory: "/usr2/kparzysz/s.hex/t")
!4 = !{!5, !7, !12}
!5 = !DIDerivedType(tag: DW_TAG_variable, name: "static_member_variable", scope: !2, file: !3, line: 4, baseType: !6, flags: DIFlagStaticMember)
!5 = !DIDerivedType(tag: DW_TAG_member, name: "static_member_variable", scope: !2, file: !3, line: 4, baseType: !6, flags: DIFlagStaticMember)
!6 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
!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)
!8 = !DISubroutineType(types: !9)
Expand Down
58 changes: 58 additions & 0 deletions test/DebugInfo/Generic/static_member_array_dwarf5.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
; RUN: llvm-as < %s -o %t.bc

; RUN: llvm-spirv %t.bc -o %t.spv
; RUN: llvm-spirv -r %t.spv -o - | llvm-dis -o - | FileCheck %s

; RUN: llvm-spirv %t.bc -o %t.spv -spirv-debug-info-version=nonsemantic-shader-100
; RUN: llvm-spirv -r %t.spv -o - | llvm-dis -o - | FileCheck %s

; RUN: llvm-spirv %t.bc -o %t.spv -spirv-debug-info-version=nonsemantic-shader-200
; RUN: llvm-spirv -r %t.spv -o - | llvm-dis -o - | FileCheck %s

; Generated from:
;
; struct A {
; static int fully_specified;
; static int smem[];
; };
;
; int A::fully_specified;
; int A::smem[] = { 0, 1, 2, 3 };

; CHECK: ![[#]] = !DIDerivedType(tag: DW_TAG_variable, name: "smem", scope: ![[#StructTy:]], file: ![[#]], line: 4, baseType: ![[#]], flags: DIFlagPublic | DIFlagStaticMember)
; CHECK: ![[#]] = !DIDerivedType(tag: DW_TAG_variable, name: "fully_specified", scope: ![[#StructTy]], file: ![[#]], line: 3, baseType: ![[#]], flags: DIFlagPublic | DIFlagStaticMember)


source_filename = "static_member_array.cpp"
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "spir64-unknown-unknown"

@_ZN1A15fully_specifiedE = global i32 0, align 4, !dbg !0
@_ZN1A4smemE = global [4 x i32] [i32 0, i32 1, i32 2, i32 3], align 16, !dbg !6

!llvm.dbg.cu = !{!2}
!llvm.module.flags = !{!19, !20, !21}

!0 = distinct !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
!1 = !DIGlobalVariable(name: "fully_specified", linkageName: "_ZN1A15fully_specifiedE", scope: !2, file: !3, line: 7, type: !9, isLocal: false, isDefinition: true, declaration: !15)
!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5)
!3 = !DIFile(filename: "static_member_array.cpp", directory: "")
!4 = !{}
!5 = !{!0, !6}
!6 = distinct !DIGlobalVariableExpression(var: !7, expr: !DIExpression())
!7 = !DIGlobalVariable(name: "smem", linkageName: "_ZN1A4smemE", scope: !2, file: !3, line: 8, type: !8, isLocal: false, isDefinition: true, declaration: !12)
!8 = !DICompositeType(tag: DW_TAG_array_type, baseType: !9, size: 128, elements: !10)
!9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
!10 = !{!11}
!11 = !DISubrange(count: 4)
!12 = !DIDerivedType(tag: DW_TAG_variable, name: "smem", scope: !13, file: !3, line: 4, baseType: !16, flags: DIFlagStaticMember)
!13 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "A", file: !3, line: 1, size: 8, elements: !14, identifier: "_ZTS1A")
!14 = !{!15, !12}
!15 = !DIDerivedType(tag: DW_TAG_variable, name: "fully_specified", scope: !13, file: !3, line: 3, baseType: !9, flags: DIFlagStaticMember)
!16 = !DICompositeType(tag: DW_TAG_array_type, baseType: !9, elements: !17)
!17 = !{!18}
!18 = !DISubrange(count: -1)
!19 = !{i32 2, !"Dwarf Version", i32 5}
!20 = !{i32 2, !"Debug Info Version", i32 3}
!21 = !{i32 1, !"PIC Level", i32 2}

4 changes: 2 additions & 2 deletions test/DebugInfo/NonSemantic/static_member_array.ll
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ target triple = "spir64-unknown-unknown"
!9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
!10 = !{!11}
!11 = !DISubrange(count: 4)
!12 = !DIDerivedType(tag: DW_TAG_variable, name: "smem", scope: !13, file: !3, line: 4, baseType: !16, flags: DIFlagStaticMember)
!12 = !DIDerivedType(tag: DW_TAG_member, name: "smem", scope: !13, file: !3, line: 4, baseType: !16, flags: DIFlagStaticMember)
!13 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "A", file: !3, line: 1, size: 8, elements: !14, identifier: "_ZTS1A")
!14 = !{!15, !12}
!15 = !DIDerivedType(tag: DW_TAG_variable, name: "fully_specified", scope: !13, file: !3, line: 3, baseType: !9, flags: DIFlagStaticMember)
!15 = !DIDerivedType(tag: DW_TAG_member, name: "fully_specified", scope: !13, file: !3, line: 3, baseType: !9, flags: DIFlagStaticMember)
!16 = !DICompositeType(tag: DW_TAG_array_type, baseType: !9, elements: !17)
!17 = !{!18}
!18 = !DISubrange(count: -1)
Expand Down

0 comments on commit 10d1285

Please sign in to comment.