[clang] [analyzer] Switch to PostStmt callbacks in ArrayBoundV2 (PR #72107)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 24 05:40:13 PST 2023
================
@@ -34,20 +34,37 @@ using llvm::formatv;
namespace {
enum OOB_Kind { OOB_Precedes, OOB_Exceeds, OOB_Taint };
-class ArrayBoundCheckerV2 :
- public Checker<check::Location> {
+struct Messages {
+ std::string Short, Full;
+};
+
+class ArrayBoundCheckerV2 : public Checker<check::PostStmt<ArraySubscriptExpr>,
+ check::PostStmt<UnaryOperator>,
+ check::PostStmt<MemberExpr>> {
BugType BT{this, "Out-of-bound access"};
BugType TaintBT{this, "Out-of-bound access", categories::TaintedData};
+ void performCheck(const Expr *E, CheckerContext &C) const;
+
void reportOOB(CheckerContext &C, ProgramStateRef ErrorState, OOB_Kind Kind,
- NonLoc Offset, std::string RegName, std::string Msg) const;
+ NonLoc Offset, Messages Msgs) const;
static bool isFromCtypeMacro(const Stmt *S, ASTContext &AC);
public:
- void checkLocation(SVal l, bool isLoad, const Stmt *S,
- CheckerContext &C) const;
+ void checkPostStmt(const ArraySubscriptExpr *E, CheckerContext &C) const {
----------------
DonatNagyE wrote:
Actually there **was** a reason for using `PostStmt`: I'm using `CheckerContext::getSVal(const Expr *)` to get the _result_ of the analyzed subscript/dereference expression, and that's not yet available in the `PreStmt` callback. I could switch to `PreStmt` if I reimplemented the evaluation of these statements, but I don't think that it has any concrete advantages. I'll probably add a comment to mention this.
https://github.com/llvm/llvm-project/pull/72107
More information about the cfe-commits
mailing list