From 26089d4da489dc17711213f917779e480a78ed51 Mon Sep 17 00:00:00 2001 From: Evgenii Stepanov Date: Wed, 10 Aug 2022 14:20:41 -0700 Subject: [PATCH] Revert "[clang][dataflow] Don't crash when caller args are missing storage locations" https://lab.llvm.org/buildbot/#/builders/74/builds/12713 This reverts commit 43b298ea1282f29d448fc0f6ca971bc5fa698355. --- .../FlowSensitive/DataflowEnvironment.h | 2 ++ .../FlowSensitive/DataflowEnvironment.cpp | 3 +-- .../Analysis/FlowSensitive/TransferTest.cpp | 21 ------------------- 3 files changed, 3 insertions(+), 23 deletions(-) diff --git a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h index b3bc52a79a2f..8c169005846e 100644 --- a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h +++ b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h @@ -140,6 +140,8 @@ public: /// The body of the callee must not reference globals. /// /// The arguments of `Call` must map 1:1 to the callee's parameters. + /// + /// Each argument of `Call` must already have a `StorageLocation`. Environment pushCall(const CallExpr *Call) const; Environment pushCall(const CXXConstructExpr *Call) const; diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp index 119ef337c631..e4af68e53e14 100644 --- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp +++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp @@ -253,8 +253,7 @@ void Environment::pushCallInternal(const FunctionDecl *FuncDecl, const Expr *Arg = Args[ArgIndex]; auto *ArgLoc = getStorageLocation(*Arg, SkipPast::Reference); - if (ArgLoc == nullptr) - continue; + assert(ArgLoc != nullptr); const VarDecl *Param = *ParamIt; auto &Loc = createStorageLocation(*Param); diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp index 0e33df3a3800..af06021abccf 100644 --- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp +++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp @@ -4229,27 +4229,6 @@ TEST(TransferTest, ContextSensitiveReturnArg) { /*.BuiltinTransferOptions=*/{/*.ContextSensitive=*/true}}); } -TEST(TransferTest, ContextSensitiveReturnInt) { - std::string Code = R"( - int identity(int x) { return x; } - - void target() { - int y = identity(42); - // [[p]] - } - )"; - runDataflow(Code, - [](llvm::ArrayRef< - std::pair>> - Results, - ASTContext &ASTCtx) { - ASSERT_THAT(Results, ElementsAre(Pair("p", _))); - // This just tests that the analysis doesn't crash. - }, - {/*.ApplyBuiltinTransfer=*/true, - /*.BuiltinTransferOptions=*/{/*.ContextSensitive=*/true}}); -} - TEST(TransferTest, ContextSensitiveMethodLiteral) { std::string Code = R"( class MyClass {