Author: Paul Semel Date: 2023-07-26T08:50:28Z New Revision: bc37893433d35b1448c5d4628d932fafec92efd0
URL: https://github.com/llvm/llvm-project/commit/bc37893433d35b1448c5d4628d932fafec92efd0 DIFF: https://github.com/llvm/llvm-project/commit/bc37893433d35b1448c5d4628d932fafec92efd0.diff LOG: [clang][dataflow] fix bug for transparent ListInitExpr handling This fixes the handling of "transparent" ListInitExpr, when they're only used as a copy constructor for records. Without the fix, the two tests are crashing the process. Added: Modified: clang/lib/Analysis/FlowSensitive/Transfer.cpp clang/unittests/Analysis/FlowSensitive/TransferTest.cpp Removed: ################################################################################ diff --git a/clang/lib/Analysis/FlowSensitive/Transfer.cpp b/clang/lib/Analysis/FlowSensitive/Transfer.cpp index 39faeca4b45ce3..0b7c22fe24e301 100644 --- a/clang/lib/Analysis/FlowSensitive/Transfer.cpp +++ b/clang/lib/Analysis/FlowSensitive/Transfer.cpp @@ -637,6 +637,13 @@ class TransferVisitor : public ConstStmtVisitor<TransferVisitor> { 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<FieldDecl *> Fields = getFieldsForInitListExpr(Type->getAsRecordDecl()); llvm::DenseMap<const ValueDecl *, StorageLocation *> FieldLocs; diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp index edd015bbf10937..5acb28bd87abff 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<DataflowAnalysisState<NoopLattice>> &Results, + ASTContext &ASTCtx) { + const Environment &Env = getEnvironmentAtAnnotation(Results, "p"); + + const ValueDecl *BazDecl = findValueDecl(ASTCtx, "Baz"); + + const auto &FooLoc = + getLocForDecl<AggregateStorageLocation>(ASTCtx, Env, "Foo"); + const auto &BarLoc = + getLocForDecl<AggregateStorageLocation>(ASTCtx, Env, "Bar"); + + const auto *FooBazVal = + cast<IntegerValue>(getFieldValue(&FooLoc, *BazDecl, Env)); + const auto *BarBazVal = + cast<IntegerValue>(getFieldValue(&BarLoc, *BazDecl, Env)); + EXPECT_EQ(FooBazVal, BarBazVal); + }); +} + TEST(TransferTest, CopyConstructorArgIsRefReturnedByFunction) { // This is a crash repro. std::string Code = R"( _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits