Skip to content

Commit 29d700a

Browse files
alokkrsharmazmodem
authored andcommitted
[DebugInfo] Fixing CodeView assert related to lowerBound field of DISubrange.
This is to fix CodeView build failure https://bugs.llvm.org/show_bug.cgi?id=47287 after DIsSubrange upgrade D80197 Assert condition is now removed and Count is calculated in case LowerBound is absent or zero and Count or UpperBound is constant. If Count is unknown it is later handled as VLA (currently Count is set to zero). Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D87406 (cherry picked from commit e45b070)
1 parent d024df4 commit 29d700a

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,11 +1592,16 @@ TypeIndex CodeViewDebug::lowerTypeArray(const DICompositeType *Ty) {
15921592
assert(Element->getTag() == dwarf::DW_TAG_subrange_type);
15931593

15941594
const DISubrange *Subrange = cast<DISubrange>(Element);
1595-
assert(!Subrange->getRawLowerBound() &&
1596-
"codeview doesn't support subranges with lower bounds");
15971595
int64_t Count = -1;
1598-
if (auto *CI = Subrange->getCount().dyn_cast<ConstantInt*>())
1599-
Count = CI->getSExtValue();
1596+
// Calculate the count if either LowerBound is absent or is zero and
1597+
// either of Count or UpperBound are constant.
1598+
auto *LI = Subrange->getLowerBound().dyn_cast<ConstantInt *>();
1599+
if (!Subrange->getRawLowerBound() || (LI && (LI->getSExtValue() == 0))) {
1600+
if (auto *CI = Subrange->getCount().dyn_cast<ConstantInt*>())
1601+
Count = CI->getSExtValue();
1602+
else if (auto *UI = Subrange->getUpperBound().dyn_cast<ConstantInt*>())
1603+
Count = UI->getSExtValue() + 1; // LowerBound is zero
1604+
}
16001605

16011606
// Forward declarations of arrays without a size and VLAs use a count of -1.
16021607
// Emit a count of zero in these cases to match what MSVC does for arrays

0 commit comments

Comments
 (0)