[PATCH] D65889: [analyzer] CastValueChecker: Model castAs(), getAs()

Csaba Dabis via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 8 19:03:31 PDT 2019


Charusso added inline comments.


================
Comment at: clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp:26
 class CastValueChecker : public Checker<eval::Call> {
+  enum class CastKind { Checking, Sugar };
+
----------------
NoQ wrote:
> Charusso wrote:
> > NoQ wrote:
> > > Please explain "Checking" and "Sugar". Checking what? Sugar... you mean syntactic sugar? For what?
> > I have no idea what devs mean by those names:
> > - `Checking` kind:
> > > The cast<> operator is a “checked cast” operation.
> > > The dyn_cast<> operator is a “checking cast” operation.
> > from http://llvm.org/docs/ProgrammersManual.html#the-isa-cast-and-dyn-cast-templates
> > 
> > - `Sugar` kind:
> > > Member-template castAs<specific type>. Look through sugar for the underlying instance of <specific type>.
> > > Member-template getAs<specific type>'. Look through sugar for an instance of <specific type>.
> > from https://clang.llvm.org/doxygen/classclang_1_1Type.html#a436b8b08ae7f2404b4712d37986194ce
> > and https://clang.llvm.org/doxygen/classclang_1_1Type.html#adae68e1f4c85ede2d36da45fbefc48a2
> > 
> > - `isa()` would be `Instance` kind:
> > > The isa<> operator works exactly like the Java “instanceof” operator.
> > from http://llvm.org/docs/ProgrammersManual.html#the-isa-cast-and-dyn-cast-templates
> > 
> > If you could imagine better names, please let me know. I have tried to use the definitions.
> `{ Function, Method }`?
These are cool identifiers, thanks!


================
Comment at: clang/test/Analysis/cast-value.cpp:156-167
+void evalNonNullParamNonNullReturn(const Shape *S) {
+  const auto *C = cast<Circle>(S);
+  // expected-note at -1 {{Dynamic cast from 'Shape' to 'Circle' succeeds}}
+  // expected-note at -2 {{Assuming pointer value is null}}
+  // expected-note at -3 {{'C' initialized here}}
+
+  (void)(1 / !(bool)C);
----------------
NoQ wrote:
> Charusso wrote:
> > NoQ wrote:
> > > Mmm, wait a sec. That's a false positive. `cast<>` doesn't accept null pointers. We have `cast_or_null` for this.
> > This `Assuming pointer value is null` note is very random. I believe it is not made by me and my code is fine, so I have printed a graph:
> > {F9759380}
> > Do you see any problem?
> Whoops, sorry, i didn't notice the `!`. Seems fine.
> 
> Yeah, the note is broken. I have another interesting reproducer for a problem with the same note: https://bugs.llvm.org/show_bug.cgi?id=42938
I will leave that not "Done" as `FIXME: Broken notes.`


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

https://reviews.llvm.org/D65889





More information about the cfe-commits mailing list