Skip to content

Commit 18f087c

Browse files
author
Esme-Yi
committed
[DebugInfo][Clang] record the access flag for class/struct/union types.
Summary: This patch records the access flag for class/struct/union types in the clang part. The summary of binary size change and debug info size change due to the DW_AT_accessibility attribute are as the following table. They are built with flags of `clang -O0 -g` (no -gz). | section | before | after | change | % | | .debug_loc | 929821 | 929821 |0|0| |.debug_abbrev | 5885289 | 5971547 |+86258|+1.466%| |.debug_info | 497613455 | 498122074 |+508619|+0.102%| |.debug_ranges | 45731664 | 45731664 |0|0| |.debug_str | 233842595 | 233839388 |-3207| -0.001%| |.debug_line | 149773166 | 149764583 |-8583|-0.006%| |total (debug) |933775990 |934359077|+583087 |+0.062%| |total (binary) |1394617288 | 1395200024| +582736|+0.042%| Reviewed By: dblaikie, shchenz Differential Revision: https://reviews.llvm.org/D115503
1 parent 68bc6d7 commit 18f087c

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3633,6 +3633,9 @@ llvm::DICompositeType *CGDebugInfo::CreateLimitedType(const RecordType *Ty) {
36333633
// Record exports it symbols to the containing structure.
36343634
if (CXXRD->isAnonymousStructOrUnion())
36353635
Flags |= llvm::DINode::FlagExportSymbols;
3636+
3637+
Flags |= getAccessFlag(CXXRD->getAccess(),
3638+
dyn_cast<CXXRecordDecl>(CXXRD->getDeclContext()));
36363639
}
36373640

36383641
llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(D);

clang/test/CodeGenCXX/debug-info-access.cpp

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,43 @@ class B : public A {
2525
void priv_default();
2626
};
2727

28+
class C {
29+
public:
30+
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "D",{{.*}} flags: DIFlagPublic | DIFlagTypePassByValue,
31+
struct D {
32+
};
33+
protected:
34+
// CHECK: !DICompositeType(tag: DW_TAG_union_type, name: "E",{{.*}} flags: DIFlagProtected | DIFlagTypePassByValue,
35+
union E {
36+
};
37+
private:
38+
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "J",{{.*}} flags: DIFlagTypePassByValue,
39+
struct J {
40+
};
41+
public:
42+
D d;
43+
E e;
44+
J j;
45+
};
46+
47+
struct F {
48+
private:
49+
// CHECK: !DICompositeType(tag: DW_TAG_union_type, name: "G",{{.*}} flags: DIFlagPrivate | DIFlagTypePassByValue,
50+
union G {
51+
};
52+
public:
53+
G g;
54+
};
55+
56+
union H {
57+
private:
58+
// CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "I",{{.*}} flags: DIFlagPrivate | DIFlagTypePassByValue,
59+
class I {
60+
};
61+
public:
62+
I i;
63+
};
64+
2865
union U {
2966
// CHECK-DAG: !DISubprogram(name: "union_pub_default",{{.*}} line: [[@LINE+1]],{{.*}} flags: DIFlagPrototyped,
3067
void union_pub_default();
@@ -33,7 +70,6 @@ union U {
3370
int union_priv;
3471
};
3572

36-
3773
// CHECK: !DISubprogram(name: "free",
3874
// CHECK-SAME: flags: DIFlagPrototyped,
3975
// CHECK-SAME: spFlags: DISPFlagDefinition
@@ -42,3 +78,6 @@ void free() {}
4278
U u;
4379
A a;
4480
B b;
81+
C c;
82+
F f;
83+
H h;

0 commit comments

Comments
 (0)