[clang] [DebugInfo] Add bit size to _BitInt name in debug info (PR #165583)

via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 29 08:45:01 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-debuginfo

Author: Orlando Cazalet-Hyams (OCHyams)

<details>
<summary>Changes</summary>

Follow on from #<!-- -->164372 

```diff
DWARF for _BitInt(23):

 DW_TAG_base_type
     DW_AT_byte_size (0x04)
     DW_AT_encoding  (DW_ATE_signed)
     DW_AT_bit_size  (0x17)
-    DW_AT_name      ("_BitInt")
+    DW_AT_name      ("_BitInt(23)")
```

This matches GCC. It's what our (Sony) debugger would prefer to see, but it's possibly not useful for LLDB - so maybe we want to avoid doing this with -glldb tuning?

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


2 Files Affected:

- (modified) clang/lib/CodeGen/CGDebugInfo.cpp (+4-1) 
- (modified) clang/test/DebugInfo/Generic/bit-int.c (+2-2) 


``````````diff
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index 07a2cfb21bef2..fd2f6dcf182b5 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1174,7 +1174,10 @@ llvm::DIType *CGDebugInfo::CreateType(const BuiltinType *BT) {
 }
 
 llvm::DIType *CGDebugInfo::CreateType(const BitIntType *Ty) {
-  StringRef Name = Ty->isUnsigned() ? "unsigned _BitInt" : "_BitInt";
+  SmallString<32> Name;
+  llvm::raw_svector_ostream OS(Name);
+  OS << (Ty->isUnsigned() ? "unsigned _BitInt(" : "_BitInt(")
+     << Ty->getNumBits() << ")";
   llvm::dwarf::TypeKind Encoding = Ty->isUnsigned()
                                        ? llvm::dwarf::DW_ATE_unsigned
                                        : llvm::dwarf::DW_ATE_signed;
diff --git a/clang/test/DebugInfo/Generic/bit-int.c b/clang/test/DebugInfo/Generic/bit-int.c
index 94b93013e3b46..88ecc139eee9f 100644
--- a/clang/test/DebugInfo/Generic/bit-int.c
+++ b/clang/test/DebugInfo/Generic/bit-int.c
@@ -4,5 +4,5 @@
 unsigned _BitInt(17) a;
 _BitInt(2) b;
 
-// CHECK: !DIBasicType(name: "_BitInt", size: 8, dataSize: 2, encoding: DW_ATE_signed)
-// CHECK: !DIBasicType(name: "unsigned _BitInt", size: 32,  dataSize: 17, encoding: DW_ATE_unsigned)
+// CHECK: !DIBasicType(name: "_BitInt(2)", size: 8, dataSize: 2, encoding: DW_ATE_signed)
+// CHECK: !DIBasicType(name: "unsigned _BitInt(17)", size: 32,  dataSize: 17, encoding: DW_ATE_unsigned)

``````````

</details>


https://github.com/llvm/llvm-project/pull/165583


More information about the cfe-commits mailing list