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;
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;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits