[clang] [clang][dataflow] Only propagate past CXXDefaultInitExpr if init is (PR #99236)
Samira Bazuzi via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 16 13:31:57 PDT 2024
https://github.com/bazuzi created https://github.com/llvm/llvm-project/pull/99236
rewritten.
>From 7c75181c590f30cc439af6fa523f3ca78f8a933d Mon Sep 17 00:00:00 2001
From: Samira Bazuzi <bazuzi at google.com>
Date: Tue, 16 Jul 2024 16:25:32 -0400
Subject: [PATCH] [clang][dataflow] Only propagate past CXXDefaultInitExpr if
init is rewritten.
---
clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp | 7 ++++++-
.../Analysis/FlowSensitive/DataflowEnvironmentTest.cpp | 2 ++
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index f734168e647bd..e6be6f9aa1dd0 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -465,7 +465,12 @@ class ResultObjectVisitor : public AnalysisASTVisitor<ResultObjectVisitor> {
}
if (auto *DIE = dyn_cast<CXXDefaultInitExpr>(E)) {
- PropagateResultObject(DIE->getExpr(), Loc);
+ // If it has a rewritten init, we should propagate to that. If it doesn't,
+ // then the CXXDefaultInitExpr is the only initializer available during
+ // the analysis as the underlying Expr is only traversed as a child of the
+ // Decl being initialized, which is not usually in the CFG.
+ if (DIE->hasRewrittenInit())
+ PropagateResultObject(DIE->getExpr(), Loc);
return;
}
diff --git a/clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp b/clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp
index a4ac597bb06d6..f93e5d9ec527a 100644
--- a/clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp
@@ -435,6 +435,8 @@ TEST_F(EnvironmentTest, CXXDefaultInitExprResultObjIsWrappedExprResultObj) {
const auto *Constructor = selectFirst<CXXConstructorDecl>("ctor", Results);
const auto *DefaultInit =
selectFirst<CXXDefaultInitExpr>("default_init_expr", Results);
+ // We only propagate past the `CXXDefaultInitExpr` if it has a rewritten init.
+ ASSERT_TRUE(DefaultInit->hasRewrittenInit());
Environment Env(DAContext, *Constructor);
Env.initialize();
More information about the cfe-commits
mailing list