diff options
author | Shafik Yaghmour <shafik.yaghmour@intel.com> | 2022-11-15 11:06:59 -0800 |
---|---|---|
committer | Shafik Yaghmour <shafik.yaghmour@intel.com> | 2022-11-15 12:07:03 -0800 |
commit | 9332ddfba69c38f9ceef4175b042fba0bb8e67bb (patch) | |
tree | dd6c1aec97e373656bd9ea3545ebb908b5c540e3 /clang/lib/Sema/SemaChecking.cpp | |
parent | eba3fece88f51ca4e7e0a9508f3b012e6bb7e2d0 (diff) | |
download | llvm-9332ddfba69c38f9ceef4175b042fba0bb8e67bb.zip llvm-9332ddfba69c38f9ceef4175b042fba0bb8e67bb.tar.gz llvm-9332ddfba69c38f9ceef4175b042fba0bb8e67bb.tar.bz2 |
[Clang] Extend the number of case Sema::CheckForIntOverflow covers
Currently Sema::CheckForIntOverflow misses several case that other compilers
diagnose for overflow in integral constant expressions. This includes the
arguments of a CXXConstructExpr as well as the expressions used in an
ArraySubscriptExpr, CXXNewExpr and CompoundLiteralExpr.
This fixes https://github.com/llvm/llvm-project/issues/58944
Differential Revision: https://reviews.llvm.org/D137897
Diffstat (limited to 'clang/lib/Sema/SemaChecking.cpp')
-rw-r--r-- | clang/lib/Sema/SemaChecking.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index f46a4d3..5a9c175 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -14660,6 +14660,17 @@ void Sema::CheckForIntOverflow (Expr *E) { Exprs.append(Call->arg_begin(), Call->arg_end()); else if (auto Message = dyn_cast<ObjCMessageExpr>(E)) Exprs.append(Message->arg_begin(), Message->arg_end()); + else if (auto Construct = dyn_cast<CXXConstructExpr>(E)) + Exprs.append(Construct->arg_begin(), Construct->arg_end()); + else if (auto Array = dyn_cast<ArraySubscriptExpr>(E)) + Exprs.push_back(Array->getIdx()); + else if (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.value()); + } } while (!Exprs.empty()); } |