Skip to content

Commit 2cee5fc

Browse files
[analyzer] Fix zext assertion failure in loop unrolling
1 parent 223521b commit 2cee5fc

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,12 @@ static bool shouldCompletelyUnroll(const Stmt *LoopStmt, ASTContext &ASTCtx,
283283
llvm::APInt InitNum =
284284
Matches[0].getNodeAs<IntegerLiteral>("initNum")->getValue();
285285
auto CondOp = Matches[0].getNodeAs<BinaryOperator>("conditionOperator");
286-
if (InitNum.getBitWidth() != BoundNum.getBitWidth()) {
287-
InitNum = InitNum.zext(BoundNum.getBitWidth());
288-
BoundNum = BoundNum.zext(InitNum.getBitWidth());
289-
}
286+
unsigned MaxWidth = std::max(InitNum.getBitWidth(), BoundNum.getBitWidth());
287+
288+
if (InitNum.getBitWidth() != MaxWidth)
289+
InitNum = InitNum.zext(MaxWidth);
290+
if (BoundNum.getBitWidth() != MaxWidth)
291+
BoundNum = BoundNum.zext(MaxWidth);
290292

291293
if (CondOp->getOpcode() == BO_GE || CondOp->getOpcode() == BO_LE)
292294
maxStep = (BoundNum - InitNum + 1).abs().getZExtValue();

0 commit comments

Comments
 (0)