[clang][dataflow] Don't crash when caller args are missing storage locations

This patch modifies `Environment`'s `pushCall` method to pass over arguments that are missing storage locations, instead of crashing.

Reviewed By: gribozavr2

Differential Revision: https://reviews.llvm.org/D131600
This commit is contained in:
Sam Estep 2022-08-10 17:50:14 +00:00 committed by Wei Yi Tee
parent eda6e49aa8
commit d09d4bd66c
3 changed files with 23 additions and 3 deletions

View File

@ -140,8 +140,6 @@ 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;

View File

@ -253,7 +253,8 @@ void Environment::pushCallInternal(const FunctionDecl *FuncDecl,
const Expr *Arg = Args[ArgIndex];
auto *ArgLoc = getStorageLocation(*Arg, SkipPast::Reference);
assert(ArgLoc != nullptr);
if (ArgLoc == nullptr)
continue;
const VarDecl *Param = *ParamIt;
auto &Loc = createStorageLocation(*Param);

View File

@ -4229,6 +4229,27 @@ 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<std::string, DataflowAnalysisState<NoopLattice>>>
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 {