Skip to content

Commit e45b070

Browse files
alokkrsharmaSouraVX
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
1 parent da92448 commit e45b070

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
@@ -1578,11 +1578,16 @@ TypeIndex CodeViewDebug::lowerTypeArray(const DICompositeType *Ty) {
15781578
assert(Element->getTag() == dwarf::DW_TAG_subrange_type);
15791579

15801580
const DISubrange *Subrange = cast<DISubrange>(Element);
1581-
assert(!Subrange->getRawLowerBound() &&
1582-
"codeview doesn't support subranges with lower bounds");
15831581
int64_t Count = -1;
1584-
if (auto *CI = Subrange->getCount().dyn_cast<ConstantInt*>())
1585-
Count = CI->getSExtValue();
1582+
// Calculate the count if either LowerBound is absent or is zero and
1583+
// either of Count or UpperBound are constant.
1584+
auto *LI = Subrange->getLowerBound().dyn_cast<ConstantInt *>();
1585+
if (!Subrange->getRawLowerBound() || (LI && (LI->getSExtValue() == 0))) {
1586+
if (auto *CI = Subrange->getCount().dyn_cast<ConstantInt*>())
1587+
Count = CI->getSExtValue();
1588+
else if (auto *UI = Subrange->getUpperBound().dyn_cast<ConstantInt*>())
1589+
Count = UI->getSExtValue() + 1; // LowerBound is zero
1590+
}
15861591

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

0 commit comments

Comments
 (0)