[clang] [analyzer] Implement binary operations on LazyCompoundVals (PR #106982)
DonĂ¡t Nagy via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 2 08:18:06 PDT 2024
================
@@ -315,6 +315,62 @@ static bool isFunctionMacroExpansion(SourceLocation Loc,
return EInfo.isFunctionMacroExpansion();
}
+static const LocationContext *getFirstNonCtorCall(const LocationContext *LCtx) {
+ while (llvm::isa_and_nonnull<CXXConstructorDecl>(LCtx->getDecl()))
+ LCtx = LCtx->getParent();
+ return LCtx;
+}
+
+static const MemRegion *getInitializerRegion(const PostInitializer &PI) {
+ return reinterpret_cast<const MemRegion *>(PI.getLocationValue());
+}
+
+/// Based largely on isInitializationOfVar(). Checks if N initializes FR.
+static bool isInitializationOfField(const ExplodedNode *N,
+ const FieldRegion *FR) {
+ std::optional<PostInitializer> P = N->getLocationAs<PostInitializer>();
+ if (!P)
+ return false;
+
+ const MemRegion *InitR = getInitializerRegion(*P);
+
+ if (FR != InitR)
+ return false;
+
+ const MemSpaceRegion *FRSpace = FR->getMemorySpace();
+ const auto *FRCtx = dyn_cast<StackSpaceRegion>(FRSpace);
+
+ if (!FRCtx)
+ return true;
+
+ // The stack frame of N is the constructor, but the FieldRegion is not local
+ // to the constructor, but rather to the caller function.
+ const LocationContext *CallerCtx =
+ getFirstNonCtorCall(N->getLocationContext());
+
+ return FRCtx->getStackFrame() == CallerCtx->getStackFrame();
----------------
NagyDonat wrote:
This looks like you are calling the same method on two different objects of the same type, but IIUC their types are unrelated: `FRCtx` is a `StackSpaceRegion` while `CallerCtx` is a `LocationContext`.
I think it would be helpful to rename `FRCtx` to `FRStackSpace` or something similar to emphasize that it's *not* a (location) context object.
https://github.com/llvm/llvm-project/pull/106982
More information about the cfe-commits
mailing list