aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
diff options
context:
space:
mode:
authorSamira Bazuzi <bazuzi@google.com>2024-07-22 10:22:23 -0400
committerGitHub <noreply@github.com>2024-07-22 10:22:23 -0400
commit83c2bfdacb0593b3a72e93098a55afdcd93d865f (patch)
tree38c9caee9b7ec63ff4f7c8bf933867047ba847ec /clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
parent32cd18975d2e1de5a783e9b1c3c21a234d5723b4 (diff)
downloadllvm-83c2bfdacb0593b3a72e93098a55afdcd93d865f.zip
llvm-83c2bfdacb0593b3a72e93098a55afdcd93d865f.tar.gz
llvm-83c2bfdacb0593b3a72e93098a55afdcd93d865f.tar.bz2
[clang][dataflow] Handle this-capturing lambdas in field initializers. (#99519)
We previously would assume these lambdas appeared inside a method definition and end up crashing.
Diffstat (limited to 'clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp')
-rw-r--r--clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp21
1 files changed, 15 insertions, 6 deletions
diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index f734168..8d7fe18 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -524,12 +524,21 @@ void Environment::initialize() {
assert(VarDecl != nullptr);
setStorageLocation(*VarDecl, createObject(*VarDecl, nullptr));
} else if (Capture.capturesThis()) {
- const auto *SurroundingMethodDecl =
- cast<CXXMethodDecl>(InitialTargetFunc->getNonClosureAncestor());
- QualType ThisPointeeType =
- SurroundingMethodDecl->getFunctionObjectParameterType();
- setThisPointeeStorageLocation(
- cast<RecordStorageLocation>(createObject(ThisPointeeType)));
+ if (auto *Ancestor = InitialTargetFunc->getNonClosureAncestor()) {
+ const auto *SurroundingMethodDecl = cast<CXXMethodDecl>(Ancestor);
+ QualType ThisPointeeType =
+ SurroundingMethodDecl->getFunctionObjectParameterType();
+ setThisPointeeStorageLocation(
+ cast<RecordStorageLocation>(createObject(ThisPointeeType)));
+ } else if (auto *FieldBeingInitialized =
+ dyn_cast<FieldDecl>(Parent->getLambdaContextDecl())) {
+ // This is in a field initializer, rather than a method.
+ setThisPointeeStorageLocation(
+ cast<RecordStorageLocation>(createObject(QualType(
+ FieldBeingInitialized->getParent()->getTypeForDecl(), 0))));
+ } else {
+ assert(false && "Unexpected this-capturing lambda context.");
+ }
}
}
} else if (MethodDecl->isImplicitObjectMemberFunction()) {