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

Andy Kaylor via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 29 15:45:35 PDT 2017

andrew.w.kaylor added inline comments.

Comment at: include/clang/Basic/DiagnosticSemaKinds.td:6032
+def ext_gnu_null_ptr_arith : Extension<
+  "inttoptr casting using arithmetic on a null pointer is a GNU extension">,
+  InGroup<PointerArith>;
rsmith wrote:
> efriedma wrote:
> > The keyword "inttoptr" is part of LLVM, not something we expect users to understand.
> How about something like "arithmetic on null pointer treated as cast from integer to pointer as a GNU extension"?
I like that.  Thanks for the suggestion.

Comment at: lib/Sema/SemaExpr.cpp:8805
+    const PointerType *pointerType = PExp->getType()->getAs<PointerType>();
+    if (!IExp->isIntegerConstantExpr(Context) &&
+        pointerType->getPointeeType()->isCharType() &&
rsmith wrote:
> It seems strange to me to disable this when the RHS is an ICE. If we're going to support this as an extension, we should make the rules for it as simple as we reasonably can; this ICE check seems like an unnecessary complication.
You're probably right.  My thinking was that I wanted to keep the extension idiom as narrow as was reasonable, so these were cases that I felt like I could rule out, but the argument for simplicity is compelling since the alternative isn't doing anything particularly desirable in most cases.


More information about the cfe-commits mailing list