[clang] [clang][dataflow] Fix bug in transfer function of CK_BaseToDerived (PR #208726)

Jan Voung via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 10 08:12:20 PDT 2026


================
@@ -3859,6 +3859,33 @@ TEST(TransferTest, StaticCastBaseToDerivedUnknown) {
       });
 }
 
+TEST(TransferTest, StaticCastBaseToDerivedWithSyntheticFieldsNoModeledFields) {
+  std::string Code = R"cc(
+    struct Base {};
+    struct Derived : public Base {};
+    void target(Base* BPtr) {
+      Derived* DPtr = static_cast<Derived*>(BPtr);
+      (void)DPtr;
+      // [[p]]
+    }
+  )cc";
+  ASSERT_THAT_ERROR(
+      checkDataflowWithNoopAnalysis(
+          Code, ast_matchers::hasName("target"),
+          [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+             ASTContext &ASTCtx) {
+            ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
----------------
jvoung wrote:

Yeah a comment could be enough, and similar to MultipleConstructionsFromStaticCastsBaseToDerived below.

https://github.com/llvm/llvm-project/pull/208726


More information about the cfe-commits mailing list