[clang] [analyzer] Fix uninitialized base class with initializer list when ctor is not declared in the base class (#70464) (PR #70792)

Balazs Benics via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 31 06:21:20 PDT 2023


================
@@ -1222,6 +1222,15 @@ void ExprEngine::ProcessInitializer(const CFGInitializer CFGInit,
       PostInitializer PP(BMI, FieldLoc.getAsRegion(), stackFrame);
       evalBind(Tmp, Init, Pred, FieldLoc, InitVal, /*isInit=*/true, &PP);
     }
+  } else if (BMI->isBaseInitializer() && isa<InitListExpr>(Init)) {
+    // When the base class is initialized with an initialization list, there
+    // will not be a CXXConstructExpr to initialize the base region. Hence, we
+    // need to make the bind for it.
+    StoreManager &StoreMgr = State->getStateManager().getStoreManager();
+    SVal BaseLoc = StoreMgr.evalDerivedToBase(
+        thisVal, QualType(BMI->getBaseClass(), 0), BMI->isBaseVirtual());
+    SVal InitVal = State->getSVal(Init, stackFrame);
+    evalBind(Tmp, Init, Pred, BaseLoc, InitVal, true);
----------------
steakhal wrote:

BTW I can see that in the neighborhood, we also pass a `PostInitializer PP` as the last argument of `evalBind`.
Why don't you do the same here?
To me, we should deal with the same "event"/program point here as everywhere in this function.

Maybe hoist `PostInitializer PP(BMI, FieldLoc.getAsRegion(), stackFrame);` and use `PP` everywhere.

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


More information about the cfe-commits mailing list