diff --git a/clang/lib/Analysis/FlowSensitive/Transfer.cpp b/clang/lib/Analysis/FlowSensitive/Transfer.cpp index 39faeca4b45ce..0b7c22fe24e30 100644 --- a/clang/lib/Analysis/FlowSensitive/Transfer.cpp +++ b/clang/lib/Analysis/FlowSensitive/Transfer.cpp @@ -637,6 +637,13 @@ class TransferVisitor : public ConstStmtVisitor { return; } + // In case the initializer list is transparent, we just need to propagate + // the value that it contains. + if (S->isSemanticForm() && S->isTransparent()) { + propagateValue(*S->getInit(0), *S, Env); + return; + } + std::vector Fields = getFieldsForInitListExpr(Type->getAsRecordDecl()); llvm::DenseMap FieldLocs; diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp index edd015bbf1093..5acb28bd87abf 100644 --- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp +++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp @@ -2183,6 +2183,39 @@ TEST(TransferTest, CopyConstructorWithParens) { }); } +TEST(TransferTest, CopyConstructorWithInitializerListAsSyntacticSugar) { + std::string Code = R"( + struct A { + int Baz; + }; + void target() { + A Foo = {3}; + (void)Foo.Baz; + A Bar = {A(Foo)}; + // [[p]] + } + )"; + runDataflow( + Code, + [](const llvm::StringMap> &Results, + ASTContext &ASTCtx) { + const Environment &Env = getEnvironmentAtAnnotation(Results, "p"); + + const ValueDecl *BazDecl = findValueDecl(ASTCtx, "Baz"); + + const auto &FooLoc = + getLocForDecl(ASTCtx, Env, "Foo"); + const auto &BarLoc = + getLocForDecl(ASTCtx, Env, "Bar"); + + const auto *FooBazVal = + cast(getFieldValue(&FooLoc, *BazDecl, Env)); + const auto *BarBazVal = + cast(getFieldValue(&BarLoc, *BazDecl, Env)); + EXPECT_EQ(FooBazVal, BarBazVal); + }); +} + TEST(TransferTest, CopyConstructorArgIsRefReturnedByFunction) { // This is a crash repro. std::string Code = R"(