[PATCH] D158513: [clang][dataflow] Add two repros for non-convergence involving pointers in loops.
Martin Böhme via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 22 06:53:35 PDT 2023
mboehme created this revision.
Herald added subscribers: martong, xazax.hun.
Herald added a project: All.
mboehme requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
These are broken out from https://reviews.llvm.org/D156658, which it now seems
obvious isn't the right way to solve the non-convergence.
Instead, my plan is to address the non-convergence through pointer value
widening, but the exact way this should be implemented is TBD. In the meantime,
I think there's value in getting these repros submitted to record the current
undesirable behavior.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D158513
Files:
clang/unittests/Analysis/FlowSensitive/TestingSupport.h
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===================================================================
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -2667,11 +2667,7 @@
void target() {}
)";
ASSERT_THAT_ERROR(
- checkDataflowWithNoopAnalysis(
- Code,
- [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
- ASTContext &ASTCtx) {},
- {BuiltinOptions()}),
+ checkDataflowWithNoopAnalysis(Code),
llvm::FailedWithMessage("Cannot analyze templated declarations"));
}
@@ -2683,11 +2679,7 @@
};
)";
ASSERT_THAT_ERROR(
- checkDataflowWithNoopAnalysis(
- Code,
- [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
- ASTContext &ASTCtx) {},
- {BuiltinOptions()}),
+ checkDataflowWithNoopAnalysis(Code),
llvm::FailedWithMessage("Cannot analyze templated declarations"));
}
@@ -3836,6 +3828,52 @@
});
}
+TEST(TransferTest, LoopDereferencingChangingPointerConverges) {
+ std::string Code = R"cc(
+ bool some_condition();
+
+ void target(int i1, int i2) {
+ int *p = &i1;
+ while (true) {
+ (void)*p;
+ if (some_condition())
+ p = &i1;
+ else
+ p = &i2;
+ }
+ }
+ )cc";
+ // FIXME: Implement pointer value widening to make analysis converge.
+ ASSERT_THAT_ERROR(
+ checkDataflowWithNoopAnalysis(Code),
+ llvm::FailedWithMessage("maximum number of iterations reached"));
+}
+
+TEST(TransferTest, LoopDereferencingChangingRecordPointerConverges) {
+ std::string Code = R"cc(
+ struct Lookup {
+ int x;
+ };
+
+ bool some_condition();
+
+ void target(Lookup l1, Lookup l2) {
+ Lookup *l = &l1;
+ while (true) {
+ (void)l->x;
+ if (some_condition())
+ l = &l1;
+ else
+ l = &l2;
+ }
+ }
+ )cc";
+ // FIXME: Implement pointer value widening to make analysis converge.
+ ASSERT_THAT_ERROR(
+ checkDataflowWithNoopAnalysis(Code),
+ llvm::FailedWithMessage("maximum number of iterations reached"));
+}
+
TEST(TransferTest, DoesNotCrashOnUnionThisExpr) {
std::string Code = R"(
union Union {
Index: clang/unittests/Analysis/FlowSensitive/TestingSupport.h
===================================================================
--- clang/unittests/Analysis/FlowSensitive/TestingSupport.h
+++ clang/unittests/Analysis/FlowSensitive/TestingSupport.h
@@ -402,8 +402,8 @@
std::function<
void(const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &,
ASTContext &)>
- VerifyResults,
- DataflowAnalysisOptions Options,
+ VerifyResults = [](const auto &, auto &) {},
+ DataflowAnalysisOptions Options = {BuiltinOptions()},
LangStandard::Kind Std = LangStandard::lang_cxx17,
llvm::StringRef TargetFun = "target");
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158513.552340.patch
Type: text/x-patch
Size: 3008 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230822/05d17863/attachment.bin>
More information about the cfe-commits
mailing list