[clang] acd4b03 - Revert "Revert "[clang][dataflow] Add a test to justify skipping past references in UO_Deref""
Stanislav Gatev via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 19 02:00:59 PST 2022
Author: Stanislav Gatev
Date: 2022-01-19T10:00:01Z
New Revision: acd4b0359097dd8ad166d569a4566879e82a2793
URL: https://github.com/llvm/llvm-project/commit/acd4b0359097dd8ad166d569a4566879e82a2793
DIFF: https://github.com/llvm/llvm-project/commit/acd4b0359097dd8ad166d569a4566879e82a2793.diff
LOG: Revert "Revert "[clang][dataflow] Add a test to justify skipping past references in UO_Deref""
This reverts commit a0262043bb87fdef68c817722de320a5dd9eb9c9.
Add the -fno-delayed-template-parsing arg to fix the failing test on Windows.
Added:
Modified:
clang/lib/Analysis/FlowSensitive/Transfer.cpp
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Analysis/FlowSensitive/Transfer.cpp b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
index 0979f55c5a5c..865191916e50 100644
--- a/clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -182,6 +182,7 @@ class TransferVisitor : public ConstStmtVisitor<TransferVisitor> {
switch (S->getOpcode()) {
case UO_Deref: {
+ // Skip past a reference to handle dereference of a dependent pointer.
const auto *SubExprVal = cast_or_null<PointerValue>(
Env.getValue(*SubExpr, SkipPast::Reference));
if (SubExprVal == nullptr)
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index ea035ba013da..eef1240f0da2 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -50,7 +50,7 @@ class TransferTest : public ::testing::Test {
std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
Results,
ASTContext &ASTCtx) { Match(Results, ASTCtx); },
- {"-fsyntax-only",
+ {"-fsyntax-only", "-fno-delayed-template-parsing",
"-std=" +
std::string(
LangStandard::getLangStandardForKind(Std).getName())}),
@@ -1758,4 +1758,34 @@ TEST_F(TransferTest, AddrOfReference) {
});
}
+TEST_F(TransferTest, DerefDependentPtr) {
+ std::string Code = R"(
+ template <typename T>
+ void target(T *Foo) {
+ T &Bar = *Foo;
+ /*[[p]]*/
+ }
+ )";
+ runDataflow(
+ Code, [](llvm::ArrayRef<
+ std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
+ Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+ const Environment &Env = Results[0].second.Env;
+
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
+
+ const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+ ASSERT_THAT(BarDecl, NotNull());
+
+ const auto *FooVal =
+ cast<PointerValue>(Env.getValue(*FooDecl, SkipPast::None));
+ const auto *BarVal =
+ cast<ReferenceValue>(Env.getValue(*BarDecl, SkipPast::None));
+ EXPECT_EQ(&BarVal->getPointeeLoc(), &FooVal->getPointeeLoc());
+ });
+}
+
} // namespace
More information about the cfe-commits
mailing list