@@ -232,6 +232,42 @@ void DwarfUnit::addUInt(DIEValueList &Block, dwarf::Form Form,
232
232
addUInt (Block, (dwarf::Attribute)0 , Form, Integer);
233
233
}
234
234
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
+
235
271
void DwarfUnit::addSInt (DIEValueList &Die, dwarf::Attribute Attribute,
236
272
std::optional<dwarf::Form> Form, int64_t Integer) {
237
273
if (!Form)
@@ -484,25 +520,7 @@ void DwarfUnit::addConstantValue(DIE &Die, const APInt &Val, bool Unsigned) {
484
520
return ;
485
521
}
486
522
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);
506
524
}
507
525
508
526
void DwarfUnit::addLinkageName (DIE &Die, StringRef LinkageName) {
@@ -972,12 +990,8 @@ void DwarfUnit::constructTypeDIE(DIE &Buffer, const DICompositeType *CTy) {
972
990
DIE &Variant = createAndAddDIE (dwarf::DW_TAG_variant, Buffer);
973
991
if (const ConstantInt *CI =
974
992
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 ()));
981
995
}
982
996
constructMemberDIE (Variant, DDTy);
983
997
} else {
0 commit comments