================ @@ -427,6 +427,48 @@ AST_MATCHER(ArraySubscriptExpr, isSafeArraySubscript) { // - e. g. "Try harder to find a NamedDecl to point at in the note." // already duplicated // - call both from Sema and from here + std::function<llvm::APInt(const Expr *exp, unsigned int limit)> + SafeMaskedAccess; + unsigned int RecLimit = 5; + + SafeMaskedAccess = [&](const Expr *exp, unsigned int RecLimit) -> llvm::APInt { + llvm::APInt Max = llvm::APInt::getMaxValue(Finder->getASTContext().getIntWidth(exp->getType())); + Max.setAllBits(); + + if (RecLimit == 0) + return Max; + + //RecLimit--; + + if (const auto *IntLit = dyn_cast<IntegerLiteral>(exp)) { + const APInt ArrIdx = IntLit->getValue(); + return ArrIdx; + } + + if (const auto *BinEx = dyn_cast<BinaryOperator>(exp)) { + llvm::APInt LHS = SafeMaskedAccess(BinEx->getLHS()->IgnoreParenCasts(), RecLimit); + llvm::APInt RHS = SafeMaskedAccess(BinEx->getRHS()->IgnoreParenCasts(), RecLimit); ---------------- malavikasamak wrote:
The code has now re-organized with ASTVisitors. I don't think casts should pose a major challenges anymore, but please let me know if you think otherwise. Also have added more type cast tests to cover all bases. https://github.com/llvm/llvm-project/pull/112284 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits