diff options
author | Samira Bakon <bazuzi@google.com> | 2025-09-24 14:28:13 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-09-24 18:28:13 +0000 |
commit | f95aacaf0465925e508d019b47efcb635428d049 (patch) | |
tree | a9f069d94de9fcb78145b97ce717a4a108d10862 /clang/unittests/Analysis/FlowSensitive/TransferTest.cpp | |
parent | 89eeecd15c28d399dc533ba24f02cb317b81e3e4 (diff) | |
download | llvm-f95aacaf0465925e508d019b47efcb635428d049.zip llvm-f95aacaf0465925e508d019b47efcb635428d049.tar.gz llvm-f95aacaf0465925e508d019b47efcb635428d049.tar.bz2 |
[clang][dataflow] Copy records relative to the destination type for c… (#160557)
…opy/move assignments.
This mirrors the handling of copy/move constructors.
Also fix a couple capitalizations of variables in an adjacent and
related test.
Diffstat (limited to 'clang/unittests/Analysis/FlowSensitive/TransferTest.cpp')
-rw-r--r-- | clang/unittests/Analysis/FlowSensitive/TransferTest.cpp | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp index d97e2b0..cbd5596 100644 --- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp +++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp @@ -1554,8 +1554,8 @@ TEST(TransferTest, BaseClassInitializerFromSiblingDerivedInstance) { struct DerivedTwo : public Base { int DerivedTwoField; - DerivedTwo(const DerivedOne& d1) - : Base(d1), DerivedTwoField(d1.DerivedOneField) { + DerivedTwo(const DerivedOne& D1) + : Base(D1), DerivedTwoField(D1.DerivedOneField) { (void)BaseField; } }; @@ -1565,7 +1565,34 @@ TEST(TransferTest, BaseClassInitializerFromSiblingDerivedInstance) { [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results, ASTContext &ASTCtx) { // Regression test only; we used to crash when transferring the base - // class initializer from the DerivedToBase-cast `d1`. + // class initializer from the DerivedToBase-cast `D1`. + }, + LangStandard::lang_cxx17, /*ApplyBuiltinTransfer=*/true, "DerivedTwo"); +} + +TEST(TransferTest, CopyAssignmentToDerivedToBase) { + std::string Code = R"cc( + struct Base {}; + +struct DerivedOne : public Base { + int DerivedOneField; +}; + +struct DerivedTwo : public Base { + int DerivedTwoField; + + explicit DerivedTwo(const DerivedOne& D1) { + *static_cast<Base*>(this) = D1; + } +}; +)cc"; + + runDataflow( + Code, + [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results, + ASTContext &ASTCtx) { + // Regression test only; we used to crash when transferring the copy + // assignment operator in the constructor for `DerivedTwo`. }, LangStandard::lang_cxx17, /*ApplyBuiltinTransfer=*/true, "DerivedTwo"); } |