[clang] [analyzer] Fix misleading 'initialized here' note for uninitialized d… (PR #198345)

Donát Nagy via cfe-commits cfe-commits at lists.llvm.org
Thu May 21 04:11:40 PDT 2026


================
@@ -1281,20 +1281,20 @@ static void showBRDiagnostics(llvm::raw_svector_ostream &OS, StoreInfo SI) {
     // We don't need to check here, all these conditions were
     // checked by StoreSiteFinder, when it figured out that it is
     // initialization.
-    const auto *DS =
-        cast<DeclStmt>(SI.StoreSite->getLocationAs<PostStmt>()->getStmt());
-
-    if (SI.Value.isUndef()) {
-      if (isa<VarRegion>(SI.Dest)) {
-        const auto *VD = cast<VarDecl>(DS->getSingleDecl());
-
-        if (VD->getInit()) {
-          OS << (HasPrefix ? "initialized" : "Initializing")
-             << " to a garbage value";
-        } else {
-          OS << (HasPrefix ? "declared" : "Declaring")
-             << " without an initial value";
-        }
+    const auto *VR = dyn_cast<VarRegion>(SI.Dest);
+    if (VR) {
+      const auto *VD = VR->getDecl();
----------------
NagyDonat wrote:

> Additionally, the old code's getSingleDecl() would assert/crash on multi-decl statements.
:astonished: 

Thanks for checking and fixing this! :smile:

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


More information about the cfe-commits mailing list