[clang] [Wunsafe-buffer-usage] False positives for & expression indexing constant size array (arr[anything & 0]) (PR #112284)
Malavika Samak via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 21 12:11:33 PST 2025
================
@@ -462,8 +462,25 @@ AST_MATCHER(ArraySubscriptExpr, isSafeArraySubscript) {
// bug
if (ArrIdx.isNonNegative() && ArrIdx.getLimitedValue() < limit)
return true;
- }
- return false;
+ } else if (const auto *BE = dyn_cast<BinaryOperator>(IndexExpr)) {
+ if (BE->getOpcode() != BO_And)
+ return false;
+
+ const Expr *LHS = BE->getLHS();
+ const Expr *RHS = BE->getRHS();
+
+ if ((!LHS->isValueDependent() &&
----------------
malavikasamak wrote:
The Expr::EvaluateAsInt(...) method assumes the expression it operates on in not value dependent. So, we have to check this before hand to make sure the method does not crash. We can only skip this check if we can be guaranteed the expression is never value dependent. I don't think that is true here.
https://github.com/llvm/llvm-project/pull/112284
More information about the cfe-commits
mailing list