[clang] abc8367 - [clang][dataflow] Don't crash if copy constructor arg doesn't have a storage location.
Martin Braenne via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 28 04:16:02 PDT 2023
Author: Martin Braenne
Date: 2023-06-28T11:15:52Z
New Revision: abc8367413ff377b79e9743ca85252f209f81d65
URL: https://github.com/llvm/llvm-project/commit/abc8367413ff377b79e9743ca85252f209f81d65
DIFF: https://github.com/llvm/llvm-project/commit/abc8367413ff377b79e9743ca85252f209f81d65.diff
LOG: [clang][dataflow] Don't crash if copy constructor arg doesn't have a storage location.
I accidentally used `cast` instead of `cast_or_null`.
Reviewed By: sammccall, xazax.hun
Differential Revision: https://reviews.llvm.org/D153956
Added:
Modified:
clang/lib/Analysis/FlowSensitive/Transfer.cpp
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Analysis/FlowSensitive/Transfer.cpp b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
index c09b6b9a99ac3..54b8b3a108dc0 100644
--- a/clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -598,7 +598,7 @@ class TransferVisitor : public ConstStmtVisitor<TransferVisitor> {
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;
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index 51550adeea894..f41c3f2fdd2f7 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -2237,6 +2237,21 @@ TEST(TransferTest, CopyConstructorWithParens) {
});
}
+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 {
More information about the cfe-commits
mailing list