Skip to content

Commit

Permalink
[dataflow] Fix crash when InitListExpr is not a prvalue (#80970)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulsemel committed Feb 15, 2024
1 parent 4a32a41 commit ba27993
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
7 changes: 4 additions & 3 deletions clang/lib/Analysis/FlowSensitive/Transfer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -664,9 +664,10 @@ class TransferVisitor : public ConstStmtVisitor<TransferVisitor> {
QualType Type = S->getType();

if (!Type->isStructureOrClassType()) {
if (auto *Val = Env.createValue(Type))
Env.setValue(*S, *Val);

// Until array initialization is implemented, we don't need to care about
// cases where `getNumInits() > 1`.
if (S->getNumInits() == 1)
propagateValueOrStorageLocation(*S->getInit(0), *S, Env);
return;
}

Expand Down
18 changes: 18 additions & 0 deletions clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2349,6 +2349,24 @@ TEST(TransferTest, AssignmentOperatorReturnsByValue) {
ASTContext &ASTCtx) {});
}

TEST(TransferTest, InitListExprAsXValue) {
// This is a crash repro.
std::string Code = R"(
void target() {
bool&& Foo{false};
// [[p]]
}
)";
runDataflow(
Code,
[](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
ASTContext &ASTCtx) {
const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
const auto &FooVal = getValueForDecl<BoolValue>(ASTCtx, Env, "Foo");
ASSERT_TRUE(FooVal.formula().isLiteral(false));
});
}

TEST(TransferTest, CopyConstructor) {
std::string Code = R"(
struct A {
Expand Down

0 comments on commit ba27993

Please sign in to comment.