[PATCH] D153956: [clang][dataflow] Don't crash if copy constructor arg doesn't have a storage location.
Martin Böhme via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 28 04:16:05 PDT 2023
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGabc8367413ff: [clang][dataflow] Don't crash if copy constructor arg doesn't have a storage… (authored by mboehme).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D153956/new/
https://reviews.llvm.org/D153956
Files:
clang/lib/Analysis/FlowSensitive/Transfer.cpp
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===================================================================
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -2237,6 +2237,21 @@
});
}
+TEST(TransferTest, CopyConstructorArgIsRefReturnedByFunction) {
+ // This is a crash repro.
+ std::string Code = R"(
+ struct S {};
+ const S &returnsSRef();
+ void target() {
+ S s(returnsSRef());
+ }
+ )";
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {});
+}
+
TEST(TransferTest, MoveConstructor) {
std::string Code = R"(
namespace std {
Index: clang/lib/Analysis/FlowSensitive/Transfer.cpp
===================================================================
--- clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -598,7 +598,7 @@
const Expr *Arg = S->getArg(0);
assert(Arg != nullptr);
- auto *ArgLoc = cast<AggregateStorageLocation>(
+ auto *ArgLoc = cast_or_null<AggregateStorageLocation>(
Env.getStorageLocation(*Arg, SkipPast::Reference));
if (ArgLoc == nullptr)
return;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153956.535320.patch
Type: text/x-patch
Size: 1291 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230628/5b075d44/attachment-0001.bin>
More information about the cfe-commits
mailing list