Skip to content

Conversation

@rapidsna
Copy link
Contributor

Fix crash caused by 3eb9ff3

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:codegen IR generation bugs: mangling, exceptions, etc. debuginfo labels Mar 20, 2024
@llvmbot
Copy link
Member

llvmbot commented Mar 20, 2024

@llvm/pr-subscribers-debuginfo
@llvm/pr-subscribers-clang-codegen

@llvm/pr-subscribers-clang

Author: Yeoul Na (rapidsna)

Changes

Fix crash caused by 3eb9ff3


Full diff: https://github.com/llvm/llvm-project/pull/86017.diff

2 Files Affected:

  • (modified) clang/lib/CodeGen/CGDebugInfo.cpp (+3)
  • (added) clang/test/CodeGen/attr-counted-by-debug-info.c (+18)
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

@rapidsna
Copy link
Contributor Author

Fix crash in #78000

Copy link
Contributor

@delcypher delcypher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for the quick fix.

@nathanchance
Copy link
Member

Thanks, this resolves my reported issue!

@ms178
Copy link

ms178 commented Mar 22, 2024

This patch also resolves my reported issue over at ClangBuiltLinux for compiling the Linux Kernel on a recent LLVM/Clang snapshot.

@rapidsna rapidsna merged commit b1e97d6 into llvm:main Mar 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:codegen IR generation bugs: mangling, exceptions, etc. clang Clang issues not falling into any other category debuginfo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants