[PATCH] D98798: Produce warning for performing pointer arithmetic on a null pointer.

Jamie Schmeiser via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 19 11:15:51 PDT 2021


jamieschmeiser updated this revision to Diff 346515.
jamieschmeiser edited the summary of this revision.
jamieschmeiser added a comment.

As requested, I have added a new warning option -Wnull-pointer-subtraction (and added it to -Wextra) that does not trigger on system headers.  In addition, I changed the message used such that it states that it is undefined behaviour for C but may be undefined behaviour in C++ to address the concerns that performing the subtraction with a pointer that dynamically becomes null is not undefined behaviour.  Expanded the testing to also test that the warning does not fire on system headers.  Also, updated the release notes to indicate the new option.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98798/new/

https://reviews.llvm.org/D98798

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Sema/Inputs/pointer-subtraction.h
  clang/test/Sema/pointer-subtraction.c
  clang/test/Sema/pointer-subtraction.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98798.346515.patch
Type: text/x-patch
Size: 7148 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210519/07e283a1/attachment-0001.bin>


More information about the cfe-commits mailing list