Skip to content

Commit ba27993

Browse files
authored
[dataflow] Fix crash when InitListExpr is not a prvalue (#80970)
1 parent 4a32a41 commit ba27993

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

clang/lib/Analysis/FlowSensitive/Transfer.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -664,9 +664,10 @@ class TransferVisitor : public ConstStmtVisitor<TransferVisitor> {
664664
QualType Type = S->getType();
665665

666666
if (!Type->isStructureOrClassType()) {
667-
if (auto *Val = Env.createValue(Type))
668-
Env.setValue(*S, *Val);
669-
667+
// Until array initialization is implemented, we don't need to care about
668+
// cases where `getNumInits() > 1`.
669+
if (S->getNumInits() == 1)
670+
propagateValueOrStorageLocation(*S->getInit(0), *S, Env);
670671
return;
671672
}
672673

clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2349,6 +2349,24 @@ TEST(TransferTest, AssignmentOperatorReturnsByValue) {
23492349
ASTContext &ASTCtx) {});
23502350
}
23512351

2352+
TEST(TransferTest, InitListExprAsXValue) {
2353+
// This is a crash repro.
2354+
std::string Code = R"(
2355+
void target() {
2356+
bool&& Foo{false};
2357+
// [[p]]
2358+
}
2359+
)";
2360+
runDataflow(
2361+
Code,
2362+
[](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
2363+
ASTContext &ASTCtx) {
2364+
const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
2365+
const auto &FooVal = getValueForDecl<BoolValue>(ASTCtx, Env, "Foo");
2366+
ASSERT_TRUE(FooVal.formula().isLiteral(false));
2367+
});
2368+
}
2369+
23522370
TEST(TransferTest, CopyConstructor) {
23532371
std::string Code = R"(
23542372
struct A {

0 commit comments

Comments
 (0)