Skip to content

Commit

Permalink
[clang][Sema][NFC] Make worklist in CheckForIntOverflow const
Browse files Browse the repository at this point in the history
  • Loading branch information
tbaederr committed Jul 2, 2023
1 parent 0a9d2fa commit 381e805
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -13745,7 +13745,7 @@ class Sema final {
private:
void CheckImplicitConversions(Expr *E, SourceLocation CC = SourceLocation());
void CheckBoolLikeConversion(Expr *E, SourceLocation CC);
void CheckForIntOverflow(Expr *E);
void CheckForIntOverflow(const Expr *E);
void CheckUnsequencedOperations(const Expr *E);

/// Perform semantic checks on a completed expression. This will either
Expand Down
30 changes: 15 additions & 15 deletions clang/lib/Sema/SemaChecking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15189,39 +15189,39 @@ void Sema::CheckBoolLikeConversion(Expr *E, SourceLocation CC) {

/// Diagnose when expression is an integer constant expression and its evaluation
/// results in integer overflow
void Sema::CheckForIntOverflow (Expr *E) {
void Sema::CheckForIntOverflow (const Expr *E) {
// Use a work list to deal with nested struct initializers.
SmallVector<Expr *, 2> Exprs(1, E);
SmallVector<const Expr *, 2> Exprs(1, E);

do {
Expr *OriginalE = Exprs.pop_back_val();
Expr *E = OriginalE->IgnoreParenCasts();
const Expr *OriginalE = Exprs.pop_back_val();
const Expr *E = OriginalE->IgnoreParenCasts();

if (isa<BinaryOperator, UnaryOperator>(E)) {
E->EvaluateForOverflow(Context);
continue;
}

if (auto InitList = dyn_cast<InitListExpr>(OriginalE))
if (const auto *InitList = dyn_cast<InitListExpr>(OriginalE))
Exprs.append(InitList->inits().begin(), InitList->inits().end());
else if (isa<ObjCBoxedExpr>(OriginalE))
E->EvaluateForOverflow(Context);
else if (auto Call = dyn_cast<CallExpr>(E))
else if (const auto *Call = dyn_cast<CallExpr>(E))
Exprs.append(Call->arg_begin(), Call->arg_end());
else if (auto Message = dyn_cast<ObjCMessageExpr>(E))
else if (const auto *Message = dyn_cast<ObjCMessageExpr>(E))
Exprs.append(Message->arg_begin(), Message->arg_end());
else if (auto Construct = dyn_cast<CXXConstructExpr>(E))
else if (const auto *Construct = dyn_cast<CXXConstructExpr>(E))
Exprs.append(Construct->arg_begin(), Construct->arg_end());
else if (auto Temporary = dyn_cast<CXXBindTemporaryExpr>(E))
else if (const auto *Temporary = dyn_cast<CXXBindTemporaryExpr>(E))
Exprs.push_back(Temporary->getSubExpr());
else if (auto Array = dyn_cast<ArraySubscriptExpr>(E))
else if (const auto *Array = dyn_cast<ArraySubscriptExpr>(E))
Exprs.push_back(Array->getIdx());
else if (auto Compound = dyn_cast<CompoundLiteralExpr>(E))
else if (const auto *Compound = dyn_cast<CompoundLiteralExpr>(E))
Exprs.push_back(Compound->getInitializer());
else if (auto New = dyn_cast<CXXNewExpr>(E)) {
if (New->isArray())
if (auto ArraySize = New->getArraySize())
Exprs.push_back(*ArraySize);
else if (const auto *New = dyn_cast<CXXNewExpr>(E);
New && New->isArray()) {
if (auto ArraySize = New->getArraySize())
Exprs.push_back(*ArraySize);
}
} while (!Exprs.empty());
}
Expand Down

0 comments on commit 381e805

Please sign in to comment.