diff options
author | martinboehme <mboehme@google.com> | 2024-04-25 09:22:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-25 09:22:14 +0200 |
commit | 9b0651f5ae6510577302ea527b2cc79e80ec9ccc (patch) | |
tree | 75c0504a5444cae9941ad11dbf4734a13558c728 /clang/unittests/Analysis/FlowSensitive/TransferTest.cpp | |
parent | 8bfdbb9570c87fc98c9d6b41409e4c59ba285f51 (diff) | |
download | llvm-9b0651f5ae6510577302ea527b2cc79e80ec9ccc.zip llvm-9b0651f5ae6510577302ea527b2cc79e80ec9ccc.tar.gz llvm-9b0651f5ae6510577302ea527b2cc79e80ec9ccc.tar.bz2 |
[clang][dataflow] Don't propagate result objects in nested declarations. (#89903)
Trying to do so can cause crashes -- see newly added test and the
comments in
the fix.
Diffstat (limited to 'clang/unittests/Analysis/FlowSensitive/TransferTest.cpp')
-rw-r--r-- | clang/unittests/Analysis/FlowSensitive/TransferTest.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp index 215e208..5c7c39e 100644 --- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp +++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp @@ -3309,6 +3309,28 @@ TEST(TransferTest, ResultObjectLocationPropagatesThroughConditionalOperator) { }); } +TEST(TransferTest, ResultObjectLocationDontVisitNestedRecordDecl) { + // This is a crash repro. + // We used to crash because when propagating result objects, we would visit + // nested record and function declarations, but we don't model fields used + // only in these. + std::string Code = R"( + struct S1 {}; + struct S2 { S1 s1; }; + void target() { + struct Nested { + void f() { + S2 s2 = { S1() }; + } + }; + } + )"; + runDataflow( + Code, + [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results, + ASTContext &ASTCtx) {}); +} + TEST(TransferTest, StaticCast) { std::string Code = R"( void target(int Foo) { |