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/lib/Analysis/FlowSensitive/DataflowEnvironment.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/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp')
-rw-r--r-- | clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp index 3cb656a..636d230 100644 --- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp +++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp @@ -333,6 +333,18 @@ public: } } + bool TraverseDecl(Decl *D) { + // Don't traverse nested record or function declarations. + // - We won't be analyzing code contained in these anyway + // - We don't model fields that are used only in these nested declaration, + // so trying to propagate a result object to initializers of such fields + // would cause an error. + if (isa_and_nonnull<RecordDecl>(D) || isa_and_nonnull<FunctionDecl>(D)) + return true; + + return RecursiveASTVisitor<ResultObjectVisitor>::TraverseDecl(D); + } + bool TraverseBindingDecl(BindingDecl *BD) { // `RecursiveASTVisitor` doesn't traverse holding variables for // `BindingDecl`s by itself, so we need to tell it to. |