[clang] [clang][analyzer] Fix liveness and analysis of [[assume]] attributes (PR #198618)
Gábor Horváth via cfe-commits
cfe-commits at lists.llvm.org
Wed May 20 06:51:04 PDT 2026
================
@@ -1224,16 +1224,33 @@ void ExprEngine::VisitLambdaExpr(const LambdaExpr *LE, ExplodedNode *Pred,
void ExprEngine::VisitAttributedStmt(const AttributedStmt *A,
ExplodedNode *Pred, ExplodedNodeSet &Dst) {
+ const LocationContext *LCtx = Pred->getLocationContext();
ExplodedNodeSet CheckerPreStmt;
getCheckerManager().runCheckersForPreStmt(CheckerPreStmt, Pred, A, *this);
ExplodedNodeSet EvalSet;
- NodeBuilder Bldr(CheckerPreStmt, EvalSet, *currBldrCtx);
- for (const auto *Attr : getSpecificAttrs<CXXAssumeAttr>(A->getAttrs())) {
- for (ExplodedNode *N : CheckerPreStmt) {
- Visit(Attr->getAssumption()->IgnoreParens(), N, EvalSet);
+ for (ExplodedNode *N : CheckerPreStmt) {
+ ProgramStateRef State = N->getState();
+ for (const auto *Attr : getSpecificAttrs<CXXAssumeAttr>(A->getAttrs())) {
+ SVal AssumedVal = State->getSVal(Attr->getAssumption(), LCtx);
+ if (auto ValidAssumedVal = AssumedVal.getAs<DefinedOrUnknownSVal>()) {
+ State = State->assume(*ValidAssumedVal, true);
+ } else {
+ // The assumption expression has evaluated to UndefinedVal.
----------------
Xazax-hun wrote:
I think my main concern is that if there is something that we do not model in the assume expression, we would lose coverage for all the code after that statement even though the result of that expression would not affect leak into the program state. And the users would not be notified that the code is not being analyzer since we do not produce any warnings based on the undef.
https://github.com/llvm/llvm-project/pull/198618
More information about the cfe-commits
mailing list