Skip to content

Commit 7c5edaf

Browse files
committed
fixup! [clang][dataflow] Make cap on block visits configurable by caller.
fix build and test failures
1 parent 1e37ced commit 7c5edaf

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

clang/unittests/Analysis/FlowSensitive/TestingSupport.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "clang/AST/Stmt.h"
55
#include "clang/ASTMatchers/ASTMatchFinder.h"
66
#include "clang/ASTMatchers/ASTMatchers.h"
7+
#include "clang/Analysis/FlowSensitive/NoopAnalysis.h"
78
#include "clang/Basic/LLVM.h"
89
#include "clang/Basic/LangOptions.h"
910
#include "clang/Basic/SourceLocation.h"
@@ -18,7 +19,6 @@
1819
#include "gtest/gtest.h"
1920
#include <cassert>
2021
#include <functional>
21-
#include <memory>
2222
#include <string>
2323
#include <system_error>
2424
#include <utility>

clang/unittests/Analysis/FlowSensitive/TestingSupport.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#include "clang/Analysis/FlowSensitive/DataflowAnalysisContext.h"
3434
#include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
3535
#include "clang/Analysis/FlowSensitive/MatchSwitch.h"
36-
#include "clang/Analysis/FlowSensitive/NoopAnalysis.h"
36+
#include "clang/Analysis/FlowSensitive/NoopLattice.h"
3737
#include "clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h"
3838
#include "clang/Basic/LLVM.h"
3939
#include "clang/Serialization/PCHContainerOperations.h"
@@ -62,6 +62,11 @@ std::ostream &operator<<(std::ostream &OS,
6262

6363
namespace test {
6464

65+
// Caps the number of block visits in any individual analysis. Given that test
66+
// code is typically quite small, we set a low number to help catch any problems
67+
// early. But, the choice is arbitrary.
68+
constexpr std::int32_t MaxBlockVisitsInAnalysis = 2'000;
69+
6570
/// Returns the environment at the program point marked with `Annotation` from
6671
/// the mapping of annotated program points to analysis state.
6772
///
@@ -277,8 +282,10 @@ checkDataflow(AnalysisInputs<AnalysisT> AI,
277282
// If successful, the dataflow analysis returns a mapping from block IDs to
278283
// the post-analysis states for the CFG blocks that have been evaluated.
279284
llvm::Expected<std::vector<std::optional<TypeErasedDataflowAnalysisState>>>
280-
MaybeBlockStates = runTypeErasedDataflowAnalysis(
281-
CFCtx, Analysis, InitEnv, TypeErasedPostVisitCFG);
285+
MaybeBlockStates =
286+
runTypeErasedDataflowAnalysis(CFCtx, Analysis, InitEnv,
287+
TypeErasedPostVisitCFG,
288+
MaxBlockVisitsInAnalysis);
282289
if (!MaybeBlockStates) return MaybeBlockStates.takeError();
283290
AO.BlockStates = *MaybeBlockStates;
284291

clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@
1212
#include "clang/ASTMatchers/ASTMatchers.h"
1313
#include "clang/Analysis/FlowSensitive/DataflowAnalysisContext.h"
1414
#include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
15+
#include "clang/Analysis/FlowSensitive/NoopAnalysis.h"
1516
#include "clang/Analysis/FlowSensitive/RecordOps.h"
1617
#include "clang/Analysis/FlowSensitive/StorageLocation.h"
1718
#include "clang/Analysis/FlowSensitive/Value.h"
1819
#include "clang/Basic/LangStandard.h"
19-
#include "llvm/ADT/ArrayRef.h"
2020
#include "llvm/ADT/SmallVector.h"
2121
#include "llvm/ADT/StringRef.h"
22-
#include "llvm/Support/Casting.h"
2322
#include "llvm/Testing/Support/Error.h"
2423
#include "gmock/gmock.h"
2524
#include "gtest/gtest.h"

clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ TEST_F(DataflowAnalysisTest, NonConvergingAnalysis) {
263263
auto Res = runAnalysis<NonConvergingAnalysis>(
264264
Code, [](ASTContext &C) { return NonConvergingAnalysis(C); });
265265
EXPECT_EQ(llvm::toString(Res.takeError()),
266-
"maximum number of iterations reached");
266+
"maximum number of blocks processed");
267267
}
268268

269269
// Regression test for joins of bool-typed lvalue expressions. The first loop

0 commit comments

Comments
 (0)