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

Yitzhak Mandelbaum via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 10 07:52:19 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"));
----------------
ymand wrote:

Sorry, submitted too quickly. I'll follow up with another PR.

I think a comment is enough. We could get the RecordStorageLocation and verify that it contains exactly the expected synthetic field, but I think that's more than is necessary. We're not verifying other aspects of cast internals. WDYT? 

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


More information about the cfe-commits mailing list