[clang] [clang][dataflow] Only propagate past CXXDefaultInitExpr if init is (PR #99236)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 16 13:32:29 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Samira Bazuzi (bazuzi)
<details>
<summary>Changes</summary>
rewritten.
---
Full diff: https://github.com/llvm/llvm-project/pull/99236.diff
2 Files Affected:
- (modified) clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp (+6-1)
- (modified) clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp (+2)
``````````diff
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();
``````````
</details>
https://github.com/llvm/llvm-project/pull/99236
More information about the cfe-commits
mailing list