@@ -1357,7 +1357,7 @@ void DwarfUnit::constructSubrangeDIE(DIE &Buffer, const DISubrange *SR,
1357
1357
if (auto *CI = SR->getCount ().dyn_cast <ConstantInt*>())
1358
1358
Count = CI->getSExtValue ();
1359
1359
1360
- auto addBoundTypeEntry = [&](dwarf::Attribute Attr,
1360
+ auto AddBoundTypeEntry = [&](dwarf::Attribute Attr,
1361
1361
DISubrange::BoundType Bound) -> void {
1362
1362
if (auto *BV = Bound.dyn_cast <DIVariable *>()) {
1363
1363
if (auto *VarDIE = getDIE (BV))
@@ -1375,17 +1375,53 @@ void DwarfUnit::constructSubrangeDIE(DIE &Buffer, const DISubrange *SR,
1375
1375
}
1376
1376
};
1377
1377
1378
- addBoundTypeEntry (dwarf::DW_AT_lower_bound, SR->getLowerBound ());
1378
+ AddBoundTypeEntry (dwarf::DW_AT_lower_bound, SR->getLowerBound ());
1379
1379
1380
1380
if (auto *CV = SR->getCount ().dyn_cast <DIVariable*>()) {
1381
1381
if (auto *CountVarDIE = getDIE (CV))
1382
1382
addDIEEntry (DW_Subrange, dwarf::DW_AT_count, *CountVarDIE);
1383
1383
} else if (Count != -1 )
1384
1384
addUInt (DW_Subrange, dwarf::DW_AT_count, None, Count);
1385
1385
1386
- addBoundTypeEntry (dwarf::DW_AT_upper_bound, SR->getUpperBound ());
1386
+ AddBoundTypeEntry (dwarf::DW_AT_upper_bound, SR->getUpperBound ());
1387
1387
1388
- addBoundTypeEntry (dwarf::DW_AT_byte_stride, SR->getStride ());
1388
+ AddBoundTypeEntry (dwarf::DW_AT_byte_stride, SR->getStride ());
1389
+ }
1390
+
1391
+ void DwarfUnit::constructGenericSubrangeDIE (DIE &Buffer,
1392
+ const DIGenericSubrange *GSR,
1393
+ DIE *IndexTy) {
1394
+ DIE &DwGenericSubrange =
1395
+ createAndAddDIE (dwarf::DW_TAG_generic_subrange, Buffer);
1396
+ addDIEEntry (DwGenericSubrange, dwarf::DW_AT_type, *IndexTy);
1397
+
1398
+ int64_t DefaultLowerBound = getDefaultLowerBound ();
1399
+
1400
+ auto AddBoundTypeEntry = [&](dwarf::Attribute Attr,
1401
+ DIGenericSubrange::BoundType Bound) -> void {
1402
+ if (auto *BV = Bound.dyn_cast <DIVariable *>()) {
1403
+ if (auto *VarDIE = getDIE (BV))
1404
+ addDIEEntry (DwGenericSubrange, Attr, *VarDIE);
1405
+ } else if (auto *BE = Bound.dyn_cast <DIExpression *>()) {
1406
+ if (BE->isSignedConstant ()) {
1407
+ if (Attr != dwarf::DW_AT_lower_bound || DefaultLowerBound == -1 ||
1408
+ static_cast <int64_t >(BE->getElement (1 )) != DefaultLowerBound)
1409
+ addSInt (DwGenericSubrange, Attr, dwarf::DW_FORM_sdata,
1410
+ BE->getElement (1 ));
1411
+ } else {
1412
+ DIELoc *Loc = new (DIEValueAllocator) DIELoc;
1413
+ DIEDwarfExpression DwarfExpr (*Asm, getCU (), *Loc);
1414
+ DwarfExpr.setMemoryLocationKind ();
1415
+ DwarfExpr.addExpression (BE);
1416
+ addBlock (DwGenericSubrange, Attr, DwarfExpr.finalize ());
1417
+ }
1418
+ }
1419
+ };
1420
+
1421
+ AddBoundTypeEntry (dwarf::DW_AT_lower_bound, GSR->getLowerBound ());
1422
+ AddBoundTypeEntry (dwarf::DW_AT_count, GSR->getCount ());
1423
+ AddBoundTypeEntry (dwarf::DW_AT_upper_bound, GSR->getUpperBound ());
1424
+ AddBoundTypeEntry (dwarf::DW_AT_byte_stride, GSR->getStride ());
1389
1425
}
1390
1426
1391
1427
DIE *DwarfUnit::getIndexTyDie () {
@@ -1495,9 +1531,13 @@ void DwarfUnit::constructArrayTypeDIE(DIE &Buffer, const DICompositeType *CTy) {
1495
1531
DINodeArray Elements = CTy->getElements ();
1496
1532
for (unsigned i = 0 , N = Elements.size (); i < N; ++i) {
1497
1533
// FIXME: Should this really be such a loose cast?
1498
- if (auto *Element = dyn_cast_or_null<DINode>(Elements[i]))
1534
+ if (auto *Element = dyn_cast_or_null<DINode>(Elements[i])) {
1499
1535
if (Element->getTag () == dwarf::DW_TAG_subrange_type)
1500
1536
constructSubrangeDIE (Buffer, cast<DISubrange>(Element), IdxTy);
1537
+ else if (Element->getTag () == dwarf::DW_TAG_generic_subrange)
1538
+ constructGenericSubrangeDIE (Buffer, cast<DIGenericSubrange>(Element),
1539
+ IdxTy);
1540
+ }
1501
1541
}
1502
1542
}
1503
1543
0 commit comments