[PATCH] D67079: [analyzer] CastValueChecker: Model inheritance

Csaba Dabis via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 9 10:34:51 PDT 2019


Charusso added inline comments.


================
Comment at: clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeInfo.h:24
+  DynamicTypeInfo(QualType ty, bool CanBeSub = true)
+      : Ty(ty), CanBeASubClass(CanBeSub) {}
 
----------------
NoQ wrote:
> `Ty(Ty)` is the idiom here.
Good to know, thanks!


================
Comment at: clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp:126
+
+  // If the casts have a common anchestor it could not be a succeeded downcast.
+  for (const auto &PreviousBase : PreviousRD->bases())
----------------
NoQ wrote:
> Counterexample:
> 
> ```
> struct A {};
> struct B : A {};
> struct C : A, B {};
> ```
> 
> Downcast from `C` to `B` should succeed, even though they have a common ancestor `A` (which has the same `CXXRecordDecl` but currently isn't the same object within `C`, but can be, if `B` declares `A` as a virtual base).
So, even it is some kind of anti-pattern as a warning arrive immediately, now I allow `B` to `C` downcasts. Could you explain me more about that virtual idea, please? Based on this possible use-case in my mind two classes are on the same level as every of their bases/vbases are equals.


================
Comment at: clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp:174
+
+constexpr llvm::StringLiteral Vowels = "aeiou";
+
----------------
NoQ wrote:
> Omg lol nice. Did you try to figure out how do other people normally do it?
There is no function for that in `ADT/StringExtras.h` + `grep` did not help, so I realized it is a common way to match vowels. Do you know a better solution?


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

https://reviews.llvm.org/D67079





More information about the cfe-commits mailing list