@@ -232,6 +232,42 @@ void DwarfUnit::addUInt(DIEValueList &Block, dwarf::Form Form,
232232 addUInt (Block, (dwarf::Attribute)0 , Form, Integer);
233233}
234234
235+ void DwarfUnit::addIntAsBlock (DIE &Die, dwarf::Attribute Attribute, const APInt &Val) {
236+ DIEBlock *Block = new (DIEValueAllocator) DIEBlock;
237+
238+ // Get the raw data form of the large APInt.
239+ const uint64_t *Ptr64 = Val.getRawData ();
240+
241+ int NumBytes = Val.getBitWidth () / 8 ; // 8 bits per byte.
242+ bool LittleEndian = Asm->getDataLayout ().isLittleEndian ();
243+
244+ // Output the constant to DWARF one byte at a time.
245+ for (int i = 0 ; i < NumBytes; i++) {
246+ uint8_t c;
247+ if (LittleEndian)
248+ c = Ptr64[i / 8 ] >> (8 * (i & 7 ));
249+ else
250+ c = Ptr64[(NumBytes - 1 - i) / 8 ] >> (8 * ((NumBytes - 1 - i) & 7 ));
251+ addUInt (*Block, dwarf::DW_FORM_data1, c);
252+ }
253+
254+ addBlock (Die, Attribute, Block);
255+ }
256+
257+ void DwarfUnit::addInt (DIE &Die, dwarf::Attribute Attribute,
258+ const APInt &Val, bool Unsigned) {
259+ unsigned CIBitWidth = Val.getBitWidth ();
260+ if (CIBitWidth <= 64 ) {
261+ if (Unsigned)
262+ addUInt (Die, Attribute, std::nullopt , Val.getZExtValue ());
263+ else
264+ addSInt (Die, Attribute, std::nullopt , Val.getSExtValue ());
265+ return ;
266+ }
267+
268+ addIntAsBlock (Die, Attribute, Val);
269+ }
270+
235271void DwarfUnit::addSInt (DIEValueList &Die, dwarf::Attribute Attribute,
236272 std::optional<dwarf::Form> Form, int64_t Integer) {
237273 if (!Form)
@@ -484,25 +520,7 @@ void DwarfUnit::addConstantValue(DIE &Die, const APInt &Val, bool Unsigned) {
484520 return ;
485521 }
486522
487- DIEBlock *Block = new (DIEValueAllocator) DIEBlock;
488-
489- // Get the raw data form of the large APInt.
490- const uint64_t *Ptr64 = Val.getRawData ();
491-
492- int NumBytes = Val.getBitWidth () / 8 ; // 8 bits per byte.
493- bool LittleEndian = Asm->getDataLayout ().isLittleEndian ();
494-
495- // Output the constant to DWARF one byte at a time.
496- for (int i = 0 ; i < NumBytes; i++) {
497- uint8_t c;
498- if (LittleEndian)
499- c = Ptr64[i / 8 ] >> (8 * (i & 7 ));
500- else
501- c = Ptr64[(NumBytes - 1 - i) / 8 ] >> (8 * ((NumBytes - 1 - i) & 7 ));
502- addUInt (*Block, dwarf::DW_FORM_data1, c);
503- }
504-
505- addBlock (Die, dwarf::DW_AT_const_value, Block);
523+ addIntAsBlock (Die, dwarf::DW_AT_const_value, Val);
506524}
507525
508526void DwarfUnit::addLinkageName (DIE &Die, StringRef LinkageName) {
@@ -972,12 +990,8 @@ void DwarfUnit::constructTypeDIE(DIE &Buffer, const DICompositeType *CTy) {
972990 DIE &Variant = createAndAddDIE (dwarf::DW_TAG_variant, Buffer);
973991 if (const ConstantInt *CI =
974992 dyn_cast_or_null<ConstantInt>(DDTy->getDiscriminantValue ())) {
975- if (DD->isUnsignedDIType (Discriminator->getBaseType ()))
976- addUInt (Variant, dwarf::DW_AT_discr_value, std::nullopt ,
977- CI->getZExtValue ());
978- else
979- addSInt (Variant, dwarf::DW_AT_discr_value, std::nullopt ,
980- CI->getSExtValue ());
993+ addInt (Variant, dwarf::DW_AT_discr_value, CI->getValue (),
994+ DD->isUnsignedDIType (Discriminator->getBaseType ()));
981995 }
982996 constructMemberDIE (Variant, DDTy);
983997 } else {
0 commit comments