[PATCH] Add warnings for undefined behaviors with pointers

Richard Trieu rtrieu at google.com
Tue Jun 3 13:12:42 PDT 2014


On Mon, Jun 2, 2014 at 10:08 PM, Arthur O'Dwyer <arthur.j.odwyer at gmail.com>
wrote:

> I think "pointer to reference not equal to null pointer can only be
> false in…" would be better expressed as "address of reference can be
> null only in…"
> and ditto, "this pointer equal to null pointer can only be true in…"
> would be better expressed as "this pointer can be null only in…"
>
> (C++ doesn't have "pointers to references.")
>
> I'm also mildly opposed to the name "-Wundefined-bool-conversion",
> given that the conversions in question are NOT undefined — in fact,
> the reason for the diagnostic is basically that they're TOO defined!
> However, I have no better name to offer as a replacement.
>
> Also, is this case covered by your new diagnostic, or by some old
> diagnostic, or is it still un-covered?
>
> class test3 {
>   void bar() {
>     if (&y) { } // expected-warning of some sort: address of this->y
> cannot be null
>     if (!&y) { }  // expected-warning of some sort: address of this->y
> cannot be null
>   }
>   int y;
> };
>
> This is caught by -Wpointer-bool-conversion, which I believe is on by
default.


> my $.02,
> –Arthur
>
>
> On Mon, Jun 2, 2014 at 9:25 PM, Richard Trieu <rtrieu at google.com> wrote:
> > Extend tautological compare and bool conversion warnings to undefined
> pointer operations.  These are cases where all defined behavior will give
> the expression one value, while the other value can only result from
> undefined behavior, which the optimizer can remove.  These cases are
> addresses of references and the this pointer.  This warning was requested
> in PR19899 in response to commit r209723.
> >
> > http://reviews.llvm.org/D3999
> >
> > Files:
> >   include/clang/Basic/DiagnosticGroups.td
> >   include/clang/Basic/DiagnosticSemaKinds.td
> >   lib/Sema/SemaChecking.cpp
> >   test/SemaCXX/warn-tautological-undefined-compare.cpp
> >   test/SemaCXX/warn-undefined-bool-conversion.cpp
> >
> > _______________________________________________
> > cfe-commits mailing list
> > cfe-commits at cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140603/f4cb2956/attachment.html>


More information about the cfe-commits mailing list