[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 02:16:27 PDT 2023
mboehme created this revision.
Herald added subscribers: martong, xazax.hun.
Herald added a reviewer: NoQ.
Herald added a project: All.
mboehme requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
I accidentally used `cast` instead of `cast_or_null`.
Repository:
rG LLVM Github Monorepo
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.535293.patch
Type: text/x-patch
Size: 1291 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230628/d451372a/attachment.bin>
More information about the cfe-commits
mailing list