[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
Tue Aug 29 12:29:29 PDT 2017
efriedma added a reviewer: rsmith.
efriedma added a comment.
I didn't think of this earlier, but strictly speaking, I think "(char*)nullptr+0" isn't undefined in C++? But probably worth emitting the warning anyway; anyone writing out arithmetic on null is probably doing something suspicious, even if it isn't technically undefined.
================
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>;
----------------
The keyword "inttoptr" is part of LLVM, not something we expect users to understand.
================
Comment at: lib/Sema/SemaExpr.cpp:8808
+ Context.getTypeSize(pointerType) ==
+ Context.getTypeSize(IExp->getType()))
+ IsGNUIdiom = true;
----------------
Please make sure you use exactly the same check in Sema and CodeGen (probably easiest to stick a helper into lib/AST/).
https://reviews.llvm.org/D37042
More information about the cfe-commits
mailing list