[PATCH] D37042: Teach clang to tolerate the 'p = nullptr + n' idiom used by glibc

Eli Friedman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 13 15:01:40 PDT 2017


efriedma added inline comments.


================
Comment at: include/clang/Basic/DiagnosticSemaKinds.td:6031
   InGroup<PointerArith>;
+def ext_gnu_null_ptr_arith : Extension<
+  "arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension">,
----------------
andrew.w.kaylor wrote:
> efriedma wrote:
> > andrew.w.kaylor wrote:
> > > efriedma wrote:
> > > > "extension" isn't really right here; this shouldn't be an error in -pedantic-errors mode.  Probably best to just stick this into the NullPointerArithmetic, like the other new warning.
> > > So how should a word the warning?  Just this:
> > > 
> > > "arithmetic on a null pointer treated as a cast from integer to pointer"?
> > That wasn't what I meant; the current wording is fine. I meant this should be something like `def warn_gnu_null_ptr_arith : Warning<`.
> OK.  I think I understand the behavior you wanted.  I just thought maybe the current wording might be technically incorrect.  I wasn't sure how precisely defined we consider "extension" to be in this context.
The part that makes this a little weird is that unlike most extensions, this code is already well-formed.  It's an extension because we're guaranteeing runtime behavior for a construct which has undefined behavior at runtime according to the standard.  (This is in contrast to "implementation-defined" behaviors, which are the gaps in the standard we're allowed to fill in as we see fit.)

Given that, I think calling it a "GNU extension" in the text is fine.


https://reviews.llvm.org/D37042





More information about the cfe-commits mailing list