[PATCH] Add warnings for undefined behaviors with pointers

Arthur O'Dwyer arthur.j.odwyer at gmail.com
Mon Jun 2 22:08:30 PDT 2014


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;
};

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
>




More information about the cfe-commits mailing list