[PATCH] D122273: [clang][dataflow] Fix handling of base-class fields

Gábor Horváth via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 31 08:20:56 PDT 2022


xazax.hun added inline comments.


================
Comment at: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp:185
+      // base classes, because they are not visible in derived classes.
+      getFieldsFromClassHierarchy(Base.getType(), /*IgnorePrivateFields=*/true,
+                                  Fields);
----------------
Will this work well for all cases of diamond shape inheritance?

E.g.:
```
struct A { int a; };
struct B : virtual A { int b; };
struct C : virtual A { int c; };
struct D : B, C { int d; };
```

In the above code, I would expect the field `a` to appear only once. I guess this should work well because of the set representation although we will visit A twice.

On the other hand, consider:
```
struct A { int a; };
struct B : A { int b; };
struct C : A { int c; };
struct D : B, C { int d; };
```

Here, in fact, we have 2 instances of the field `a`. Both `B::a` and `C::a` are part of `D`. I suspect that the current implementation might not handle this.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122273/new/

https://reviews.llvm.org/D122273



More information about the cfe-commits mailing list