From ec936b3186e3512a9297c5a12b58d627ef1a1b32 Mon Sep 17 00:00:00 2001 From: Fangyi Zhou Date: Fri, 25 Apr 2025 09:39:45 +0100 Subject: [Clang][analyzer] Replace Stmt* with ConstCFGElementRef in SymbolConjured (#128251) This PR changes the `Stmt *` field in `SymbolConjured` with `CFGBlock::ConstCFGElementRef`. The motivation is that, when conjuring a symbol, there might not always be a statement available, causing information to be lost for conjured symbols, whereas the CFGElementRef can always be provided at the callsite. Following the idea, this PR changes callsites of functions to create conjured symbols, and replaces them with appropriate `CFGElementRef`s. Closes #57270 --- clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp') diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp index 9c0b79a..3628a14 100644 --- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp @@ -585,7 +585,7 @@ class StdLibraryFunctionsChecker CheckerContext &C) const override { SValBuilder &SVB = C.getSValBuilder(); NonLoc ErrnoSVal = - SVB.conjureSymbolVal(&Tag, Call.getOriginExpr(), + SVB.conjureSymbolVal(&Tag, Call.getCFGElementRef(), C.getLocationContext(), C.getASTContext().IntTy, C.blockCount()) .castAs(); @@ -621,7 +621,7 @@ class StdLibraryFunctionsChecker const Summary &Summary, CheckerContext &C) const override { return errno_modeling::setErrnoStdMustBeChecked(State, C, - Call.getOriginExpr()); + Call.getCFGElementRef()); } const std::string describe(CheckerContext &C) const override { @@ -1482,7 +1482,8 @@ bool StdLibraryFunctionsChecker::evalCall(const CallEvent &Call, const LocationContext *LC = C.getLocationContext(); const auto *CE = cast(Call.getOriginExpr()); SVal V = C.getSValBuilder().conjureSymbolVal( - CE, LC, CE->getType().getCanonicalType(), C.blockCount()); + Call.getCFGElementRef(), LC, CE->getType().getCanonicalType(), + C.blockCount()); State = State->BindExpr(CE, LC, V); C.addTransition(State); -- cgit v1.1