Skip to content

Commit bd39160

Browse files
committed
Fix access specifiers in debug info
This commit fixes two issues: 1. FlagIsProtected and FlagIsPrivate had wrong values. 2. Set access flags for class/struct/union members which don't have sccess flags set in input LLVM IR, because Clang "optimized" them out in case the flags match with default access specifier of the containing type. This change also required adjustment of LIT tests to reflect the fact that now in DWARF we emit DW_AT_accessibility attribute even for members with deafult access specifier. Signed-off-by: Alexey Sotkin <alexey.sotkin@intel.com>
1 parent fabf003 commit bd39160

File tree

4 files changed

+24
-9
lines changed

4 files changed

+24
-9
lines changed

lib/SPIRV/LLVMToSPIRVDbgTran.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,21 @@ SPIRVWord transDebugFlags(const DINode *DN) {
437437
return Flags;
438438
}
439439

440+
/// Clang doesn't emit access flags for members with default access specifier
441+
/// See clang/lib/CodeGen/CGDebugInfo.cpp: getAccessFlag()
442+
/// In SPIR-V we set the flags even for members with default access specifier
443+
SPIRVWord adjustAccessFlags(DIScope *Scope, SPIRVWord Flags) {
444+
if (Scope && (Flags & SPIRVDebug::FlagAccess) == 0) {
445+
unsigned Tag = Scope->getTag();
446+
if (Tag == dwarf::DW_TAG_class_type)
447+
Flags |= SPIRVDebug::FlagIsPrivate;
448+
else if (Tag == dwarf::DW_TAG_structure_type ||
449+
Tag == dwarf::DW_TAG_union_type)
450+
Flags |= SPIRVDebug::FlagIsPublic;
451+
}
452+
return Flags;
453+
}
454+
440455
/// The following methods (till the end of the file) implement translation of
441456
/// debug instrtuctions described in the spec.
442457

@@ -666,7 +681,7 @@ SPIRVEntry *LLVMToSPIRVDbgTran::transDbgMemberType(const DIDerivedType *MT) {
666681
Ops[OffsetIdx] = SPIRVWriter->transValue(Offset, nullptr)->getId();
667682
ConstantInt *Size = getUInt(M, MT->getSizeInBits());
668683
Ops[SizeIdx] = SPIRVWriter->transValue(Size, nullptr)->getId();
669-
Ops[FlagsIdx] = transDebugFlags(MT);
684+
Ops[FlagsIdx] = adjustAccessFlags(MT->getScope(), transDebugFlags(MT));
670685
if (MT->isStaticMember()) {
671686
if (llvm::Constant *C = MT->getConstant()) {
672687
SPIRVValue *Val = SPIRVWriter->transValue(C, nullptr);
@@ -816,7 +831,7 @@ SPIRVEntry *LLVMToSPIRVDbgTran::transDbgFunction(const DISubprogram *Func) {
816831
else
817832
Ops[ParentIdx] = getScope(Scope)->getId();
818833
Ops[LinkageNameIdx] = BM->getString(Func->getLinkageName().str())->getId();
819-
Ops[FlagsIdx] = transDebugFlags(Func);
834+
Ops[FlagsIdx] = adjustAccessFlags(Scope, transDebugFlags(Func));
820835

821836
SPIRVEntry *DebugFunc = nullptr;
822837
if (!Func->isDefinition()) {

lib/SPIRV/libSPIRV/SPIRV.debug.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ enum Instruction {
5050
};
5151

5252
enum Flag {
53-
FlagIsPrivate = 1 << 0,
54-
FlagIsProtected = 1 << 1,
53+
FlagIsProtected = 1 << 0,
54+
FlagIsPrivate = 1 << 1,
5555
FlagIsPublic = FlagIsPrivate | FlagIsProtected,
5656
FlagAccess = FlagIsPublic,
5757
FlagIsLocal = 1 << 2,

test/DebugInfo/X86/debug-info-access.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@
4040

4141
; CHECK: DW_TAG_member
4242
; CHECK: DW_AT_name {{.*}}"pub_default_static")
43-
; CHECK-NOT: DW_AT_accessibility
43+
; CHECK: DW_AT_accessibility
4444
; CHECK-NOT: DW_TAG
4545
;
4646
; CHECK: DW_TAG_subprogram
4747
; CHECK: DW_AT_name {{.*}}"pub_default")
48-
; CHECK-NOT: DW_AT_accessibility
48+
; CHECK: DW_AT_accessibility
4949
; CHECK: DW_TAG
5050
;
5151
; CHECK: DW_TAG_inheritance
@@ -69,7 +69,7 @@
6969
;
7070
; CHECK: DW_TAG_subprogram
7171
; CHECK: DW_AT_name {{.*}}"priv_default")
72-
; CHECK-NOT: DW_AT_accessibility
72+
; CHECK: DW_AT_accessibility
7373
; CHECK: DW_TAG
7474
;
7575
; CHECK: DW_TAG_member
@@ -79,7 +79,7 @@
7979
;
8080
; CHECK: DW_TAG_subprogram
8181
; CHECK: DW_AT_name {{.*}}"union_pub_default")
82-
; CHECK-NOT: DW_AT_accessibility
82+
; CHECK: DW_AT_accessibility
8383
; CHECK: DW_TAG
8484
;
8585
; CHECK: DW_TAG_subprogram

test/DebugInfo/X86/dwarf-public-names.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ target triple = "spir64-unknown-unknown"
5050

5151
; Skip the output to the header of the pubnames section.
5252
; LINUX: debug_pubnames
53-
; LINUX-NEXT: unit_size = 0x00000128
53+
; LINUX-NEXT: unit_size = 0x0000012b
5454

5555
; Check for each name in the output.
5656
; LINUX-DAG: "ns"

0 commit comments

Comments
 (0)