[clang] [NFC][analyzer] Refactor Environment to map Expr to SVal instead of Stmt to SVal (PR #193295)

Balázs Benics via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 21 12:48:50 PDT 2026


================
@@ -886,7 +886,12 @@ static ProgramStateRef checkElementNonNil(CheckerContext &C,
     assert(ElemDecl->getInit() == nullptr);
     ElementLoc = State->getLValue(ElemDecl, LCtx);
   } else {
-    ElementLoc = State->getSVal(Element, LCtx).getAs<Loc>();
+    const Expr *Ex = dyn_cast<Expr>(Element);
+    if (Ex) {
+      ElementLoc = State->getSVal(Ex, LCtx).getAs<Loc>();
+    } else {
+      ElementLoc = UnknownVal().getAs<Loc>();
----------------
steakhal wrote:

This line is definitely wrong. Once can't cast `Unknown` to anything. You must make the `ElementLoc` type plain `SVal` (the common ancestor of Unknown and Loc).

https://github.com/llvm/llvm-project/pull/193295


More information about the cfe-commits mailing list