diff options
author | martinboehme <mboehme@google.com> | 2024-03-18 13:36:20 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-18 13:36:20 +0100 |
commit | 27d504998ec7ec596bc9ff5d16333aea7a1bac18 (patch) | |
tree | 688d107c11bb1a556d949d0db4ca6215069926fa /clang/lib/Analysis/FlowSensitive | |
parent | 24692088181dd18e491a413d98d9c2ae30464454 (diff) | |
download | llvm-27d504998ec7ec596bc9ff5d16333aea7a1bac18.zip llvm-27d504998ec7ec596bc9ff5d16333aea7a1bac18.tar.gz llvm-27d504998ec7ec596bc9ff5d16333aea7a1bac18.tar.bz2 |
[clang][dataflow] Fix `getResultObjectLocation()` on `CXXDefaultArgExpr`. (#85072)
This patch includes a test that causes an assertion failure without the
other
changes in this patch.
Diffstat (limited to 'clang/lib/Analysis/FlowSensitive')
-rw-r--r-- | clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp | 1 | ||||
-rw-r--r-- | clang/lib/Analysis/FlowSensitive/Transfer.cpp | 19 |
2 files changed, 20 insertions, 0 deletions
diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp index 1d2bd9a..cc1ebd5 100644 --- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp +++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp @@ -771,6 +771,7 @@ static bool isOriginalRecordConstructor(const Expr &RecordPRValue) { return !Init->isSemanticForm() || !Init->isTransparent(); return isa<CXXConstructExpr>(RecordPRValue) || isa<CallExpr>(RecordPRValue) || isa<LambdaExpr>(RecordPRValue) || + isa<CXXDefaultArgExpr>(RecordPRValue) || isa<CXXDefaultInitExpr>(RecordPRValue) || // The framework currently does not propagate the objects created in // the two branches of a `ConditionalOperator` because there is no way diff --git a/clang/lib/Analysis/FlowSensitive/Transfer.cpp b/clang/lib/Analysis/FlowSensitive/Transfer.cpp index 04aa283..8b44bcb 100644 --- a/clang/lib/Analysis/FlowSensitive/Transfer.cpp +++ b/clang/lib/Analysis/FlowSensitive/Transfer.cpp @@ -450,6 +450,25 @@ public: Env.setStorageLocation(*S, *MemberLoc); } + void VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *S) { + const Expr *ArgExpr = S->getExpr(); + assert(ArgExpr != nullptr); + propagateValueOrStorageLocation(*ArgExpr, *S, Env); + + // If this is a prvalue of record type, we consider it to be an "original + // record constructor", which we always require to have a `RecordValue`. + // So make sure we have a value if we didn't propagate one above. + if (S->isPRValue() && S->getType()->isRecordType()) { + if (Env.getValue(*S) == nullptr) { + Value *Val = Env.createValue(S->getType()); + // We're guaranteed to always be able to create a value for record + // types. + assert(Val != nullptr); + Env.setValue(*S, *Val); + } + } + } + void VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *S) { const Expr *InitExpr = S->getExpr(); assert(InitExpr != nullptr); |