[clang] Unwrap CountAttributed for debug info (PR #86017)

Yeoul Na via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 21 13:45:49 PDT 2024


https://github.com/rapidsna updated https://github.com/llvm/llvm-project/pull/86017

>From abfcb60e7b65e755733f4d41795aa9cfd44e0cc3 Mon Sep 17 00:00:00 2001
From: Yeoul Na <yeoul_na at apple.com>
Date: Thu, 21 Mar 2024 06:47:05 +0900
Subject: [PATCH 1/3] Unwrap CountAttributed for debug info

Fix crash caused by 3eb9ff30959a670559bcba03d149d4c51bf7c9c9
---
 clang/lib/CodeGen/CGDebugInfo.cpp              |  3 +++
 .../test/CodeGen/attr-counted-by-debug-info.c  | 18 ++++++++++++++++++
 2 files changed, 21 insertions(+)
 create mode 100644 clang/test/CodeGen/attr-counted-by-debug-info.c

diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index 07ecaa81c47d84..7453ed14aef414 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -3463,6 +3463,9 @@ static QualType UnwrapTypeForDebugInfo(QualType T, const ASTContext &C) {
     case Type::BTFTagAttributed:
       T = cast<BTFTagAttributedType>(T)->getWrappedType();
       break;
+    case Type::CountAttributed:
+      T = cast<CountAttributedType>(T)->desugar();
+      break;
     case Type::Elaborated:
       T = cast<ElaboratedType>(T)->getNamedType();
       break;
diff --git a/clang/test/CodeGen/attr-counted-by-debug-info.c b/clang/test/CodeGen/attr-counted-by-debug-info.c
new file mode 100644
index 00000000000000..f3e7897e12d667
--- /dev/null
+++ b/clang/test/CodeGen/attr-counted-by-debug-info.c
@@ -0,0 +1,18 @@
+// RUN: %clang -emit-llvm -DCOUNTED_BY -S -g %s -o - | FileCheck %s
+// RUN: %clang -emit-llvm -S -g %s -o - | FileCheck %s
+
+#ifdef COUNTED_BY
+#define __counted_by(member)    __attribute__((__counted_by__(member)))
+#else
+#define __counted_by(member)
+#endif
+
+struct {
+  int num_counters;
+  long value[] __counted_by(num_counters);
+} agent_send_response_port_num;
+
+// CHECK: !DICompositeType(tag: DW_TAG_array_type, baseType: ![[BT:.*]], elements: ![[ELEMENTS:.*]])
+// ![[BT]] = !DIBasicType(name: "long", size: 64, encoding: DW_ATE_signed)
+// ![[ELEMENTS]] = !{![[COUNT]]}
+// ![[COUNT]] = !DISubrange(count: -1)
\ No newline at end of file

>From 5bb879be895b90dc942d160fbe9dfe657e73db1d Mon Sep 17 00:00:00 2001
From: Yeoul Na <yeoul_na at apple.com>
Date: Thu, 21 Mar 2024 06:59:11 +0900
Subject: [PATCH 2/3] Add missing CHECKs

---
 clang/test/CodeGen/attr-counted-by-debug-info.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/test/CodeGen/attr-counted-by-debug-info.c b/clang/test/CodeGen/attr-counted-by-debug-info.c
index f3e7897e12d667..15197f79e4370c 100644
--- a/clang/test/CodeGen/attr-counted-by-debug-info.c
+++ b/clang/test/CodeGen/attr-counted-by-debug-info.c
@@ -13,6 +13,6 @@ struct {
 } agent_send_response_port_num;
 
 // CHECK: !DICompositeType(tag: DW_TAG_array_type, baseType: ![[BT:.*]], elements: ![[ELEMENTS:.*]])
-// ![[BT]] = !DIBasicType(name: "long", size: 64, encoding: DW_ATE_signed)
-// ![[ELEMENTS]] = !{![[COUNT]]}
-// ![[COUNT]] = !DISubrange(count: -1)
\ No newline at end of file
+// CHECK: ![[BT]] = !DIBasicType(name: "long", size: 64, encoding: DW_ATE_signed)
+// CHECK: ![[ELEMENTS]] = !{![[COUNT:.*]]}
+// CHECK: ![[COUNT]] = !DISubrange(count: -1)
\ No newline at end of file

>From c1da42c5c5154fdc1fe8324dccd5368568d5304e Mon Sep 17 00:00:00 2001
From: Yeoul Na <yeoul_na at apple.com>
Date: Fri, 22 Mar 2024 05:45:31 +0900
Subject: [PATCH 3/3] Fix test.attr-counted-by-debug-info.c to also cover
 32-bit long

---
 clang/test/CodeGen/attr-counted-by-debug-info.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/CodeGen/attr-counted-by-debug-info.c b/clang/test/CodeGen/attr-counted-by-debug-info.c
index 15197f79e4370c..a6c2b1382b796b 100644
--- a/clang/test/CodeGen/attr-counted-by-debug-info.c
+++ b/clang/test/CodeGen/attr-counted-by-debug-info.c
@@ -13,6 +13,6 @@ struct {
 } agent_send_response_port_num;
 
 // CHECK: !DICompositeType(tag: DW_TAG_array_type, baseType: ![[BT:.*]], elements: ![[ELEMENTS:.*]])
-// CHECK: ![[BT]] = !DIBasicType(name: "long", size: 64, encoding: DW_ATE_signed)
+// CHECK: ![[BT]] = !DIBasicType(name: "long", size: {{.*}}, encoding: DW_ATE_signed)
 // CHECK: ![[ELEMENTS]] = !{![[COUNT:.*]]}
 // CHECK: ![[COUNT]] = !DISubrange(count: -1)
\ No newline at end of file



More information about the cfe-commits mailing list