[clang] [llvm] [DebugInfo] Fix endianness in DW_AT_const_value for constexpr arrays (PR #184804)

Shivam Kunwar via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 6 07:21:17 PST 2026


================
@@ -247,10 +245,16 @@ void DwarfUnit::addIntAsBlock(DIE &Die, dwarf::Attribute Attribute, const APInt
       c = Ptr64[i / 8] >> (8 * (i & 7));
     else
       c = Ptr64[(NumBytes - 1 - i) / 8] >> (8 * ((NumBytes - 1 - i) & 7));
-    addUInt(*Block, dwarf::DW_FORM_data1, c);
+    addUInt(Block, dwarf::DW_FORM_data1, c);
   }
+}
 
-  addBlock(Die, Attribute, Block);
+void DwarfUnit::addIntAsBlock(DIE &Die, dwarf::Attribute Attribute,
+                              const APInt &Val) {
+  DIEBlock *Block = new (DIEValueAllocator) DIEBlock;
+  addIntToBlock(*Block, Val);
+  Block->computeSize(Asm->getDwarfFormParams());
----------------
phyBrackets wrote:

You're right that the 4-arg `addBlock` calls computeSize, but the 3-arg overload calls BestForm() before forwarding to it, so `BestForm` sees `Size==0`. That's why I call computeSize explicitly before BestForm. Though maybe the cleaner fix is to move `computeSize` before `BestForm` in the 3-arg overload itself?

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


More information about the cfe-commits mailing list