[DebugInfo][Clang] record the access flag for class/struct/union types.
authorEsme-Yi <esme.yi@ibm.com>
Mon, 20 Dec 2021 02:40:42 +0000 (02:40 +0000)
committerEsme-Yi <esme.yi@ibm.com>
Mon, 20 Dec 2021 02:40:42 +0000 (02:40 +0000)
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

clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/CodeGenCXX/debug-info-access.cpp

index 7f48b27..0de089b 100644 (file)
@@ -3633,6 +3633,9 @@ llvm::DICompositeType *CGDebugInfo::CreateLimitedType(const RecordType *Ty) {
     // Record exports it symbols to the containing structure.
     if (CXXRD->isAnonymousStructOrUnion())
         Flags |= llvm::DINode::FlagExportSymbols;
+
+    Flags |= getAccessFlag(CXXRD->getAccess(),
+                           dyn_cast<CXXRecordDecl>(CXXRD->getDeclContext()));
   }
 
   llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(D);
index 0759ee1..cd5328b 100644 (file)
@@ -25,6 +25,43 @@ private:
   void priv_default();
 };
 
+class C {
+public:
+  // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "D",{{.*}} flags: DIFlagPublic | DIFlagTypePassByValue,
+  struct D {
+  };
+protected:
+  // CHECK: !DICompositeType(tag: DW_TAG_union_type, name: "E",{{.*}} flags: DIFlagProtected | DIFlagTypePassByValue,
+  union E {
+  };
+private:
+  // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "J",{{.*}} flags: DIFlagTypePassByValue,
+  struct J {
+  };
+public:
+  D d;
+  E e;
+  J j;
+};
+
+struct F {
+private:
+  // CHECK: !DICompositeType(tag: DW_TAG_union_type, name: "G",{{.*}} flags: DIFlagPrivate | DIFlagTypePassByValue,
+  union G {
+  };
+public:
+  G g;
+};
+
+union H {
+private:
+  // CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "I",{{.*}} flags: DIFlagPrivate | DIFlagTypePassByValue,
+  class I {
+  };
+public:
+  I i;
+};
+
 union U {
   // CHECK-DAG: !DISubprogram(name: "union_pub_default",{{.*}} line: [[@LINE+1]],{{.*}} flags: DIFlagPrototyped,
   void union_pub_default();
@@ -33,7 +70,6 @@ private:
   int union_priv;
 };
 
-
 // CHECK: !DISubprogram(name: "free",
 // CHECK-SAME:          flags: DIFlagPrototyped,
 // CHECK-SAME:          spFlags: DISPFlagDefinition
@@ -42,3 +78,6 @@ void free() {}
 U u;
 A a;
 B b;
+C c;
+F f;
+H h;