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

2021-07-28 Thread Jamie Schmeiser via Phabricator via cfe-commits
jamieschmeiser added a comment. @crownyanguan Why do you think this caused the linker to crash? It is a warning in the front end. Would it even be executed in your posted command? Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D98798/new/ https://

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

2021-07-28 Thread crownyanguan via Phabricator via cfe-commits
crownyanguan added a comment. This commit also makes the phoronix/pgbench run fail. clang --gcc-toolchain=/usr/bin/.. -target aarch64-unknown-linux-gnu -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-stric

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

2021-07-20 Thread Jamie Schmeiser via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs Review". This revision was automatically updated to reflect the committed changes. Closed by commit rG9cb00b9ecbe7: Reland Produce warning for performing pointer arithmetic on a null pointer. (authored by jamieschmeiser). C

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

2021-07-19 Thread Jamie Schmeiser via Phabricator via cfe-commits
jamieschmeiser added a comment. This was originally approved and landed on May 11th. I agreed to let it be reverted when it was discovered that some headers were triggering the warning. I reworked the code to not generate the warning when coming from system header files and also added option

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

2021-07-12 Thread Kelvin Li via Phabricator via cfe-commits
kkwli0 added a comment. Is the diff from HEAD? CHANGES SINCE LAST ACTION https://reviews.llvm.org/D98798/new/ https://reviews.llvm.org/D98798 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cf

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

2021-07-12 Thread Jamie Schmeiser via Phabricator via cfe-commits
jamieschmeiser added a comment. ping CHANGES SINCE LAST ACTION https://reviews.llvm.org/D98798/new/ https://reviews.llvm.org/D98798 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

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

2021-07-05 Thread Jamie Schmeiser via Phabricator via cfe-commits
jamieschmeiser added a comment. @rsmith @thakis @efriedma If there are no more changes required, please approve. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D98798/new/ https://reviews.llvm.org/D98798 ___ cfe-commits mailing list cfe-commi

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

2021-06-16 Thread Jamie Schmeiser via Phabricator via cfe-commits
jamieschmeiser added a comment. ping CHANGES SINCE LAST ACTION https://reviews.llvm.org/D98798/new/ https://reviews.llvm.org/D98798 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

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

2021-06-07 Thread Jamie Schmeiser via Phabricator via cfe-commits
jamieschmeiser added a comment. @rsmith I separated the C and C++ messages in response to your comments and changed the C++ message to state that "performing pointer subtraction with a null pointer may have undefined behavior" to address your concerns. Are you satisfied? @thakis, the warning

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

2021-06-04 Thread Jamie Schmeiser via Phabricator via cfe-commits
jamieschmeiser added a comment. ping CHANGES SINCE LAST ACTION https://reviews.llvm.org/D98798/new/ https://reviews.llvm.org/D98798 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

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

2021-05-27 Thread Jamie Schmeiser via Phabricator via cfe-commits
jamieschmeiser added a comment. The reason I worded it with 'may' is because, in C++, nullptr - nullptr is defined. If the code is "nullptr - p" or "p - nullptr", it is only undefined behaviour when p is not nullptr, hence the 'may' part of the warning because this is not known at compile time

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

2021-05-27 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment. We tried it, and the warning is still firing in a similar (but not exactly the same) way: In file included from ../../content/browser/accessibility/browser_accessibility_manager_win.cc:19: In file included from ../..\content/browser/renderer_host/legacy_render_widget_

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

2021-05-27 Thread Jamie Schmeiser via Phabricator via cfe-commits
jamieschmeiser added a reviewer: thakis. jamieschmeiser added a comment. ping CHANGES SINCE LAST ACTION https://reviews.llvm.org/D98798/new/ https://reviews.llvm.org/D98798 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.

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

2021-05-25 Thread Jamie Schmeiser via Phabricator via cfe-commits
jamieschmeiser added a comment. @thakis, can you please verify that the changes no longer affect the MS headers? Thanks. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D98798/new/ https://reviews.llvm.org/D98798 ___ cfe-commits mailing list c

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

2021-05-20 Thread Jamie Schmeiser via Phabricator via cfe-commits
jamieschmeiser updated this revision to Diff 346751. jamieschmeiser added a comment. Fix formatting. 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/inc

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

2021-05-19 Thread Jamie Schmeiser via Phabricator via cfe-commits
jamieschmeiser requested review of this revision. jamieschmeiser added a comment. Significant changes made since previously accepted. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D98798/new/ https://reviews.llvm.org/D98798 ___ cfe-commits mai

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

2021-05-19 Thread Jamie Schmeiser via Phabricator via cfe-commits
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 c

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

2021-05-19 Thread Jamie Schmeiser via Phabricator via cfe-commits
jamieschmeiser reopened this revision. jamieschmeiser added a comment. This revision is now accepted and ready to land. Re-opening because it was reverted. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D98798/new/ https://reviews.llvm.org/D98798 __

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

2021-05-12 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments. Comment at: clang/test/Sema/pointer-addition.cpp:5-6 + char *f = (char*)0; + f = (char*)((char*)0 - f); // expected-warning {{performing pointer arithmetic on a null pointer has undefined behavior}} + f = (char*)(f - (char*)0); // expected-warnin

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

2021-05-12 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment. Thanks! Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D98798/new/ https://reviews.llvm.org/D98798 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi

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

2021-05-12 Thread Jamie Schmeiser via Phabricator via cfe-commits
jamieschmeiser added a comment. If this is a problem for you, please revert it and I will take a look when I return. Thanks. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D98798/new/ https://reviews.llvm.org/D98798 ___

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

2021-05-12 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment. @thakis if this is an issue for you, please revert; like you said, we can figure out the issues later. Looking at the warning you showed, we might want to consider suppressing that specific pattern, in addition to (or instead of?) suppressing it in system headers. The

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

2021-05-12 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment. (Now completed the reply, see phab.) In D98798#2754635 , @xbolva00 wrote: > You dont have to use -Wno-… > > You can use pragma to disable this warning for certain location in the code, > eg include of commctrl.h. commctrl.h is in

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

2021-05-12 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a comment. You dont have to use -Wno-… You can use pragma to disable this warning for certain location in the code. -1 for revert just because of this reason. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D98798/new/ https://reviews

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

2021-05-12 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment. (sorry, accidentally hit cmd-enter, not actually done writing) Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D98798/new/ https://reviews.llvm.org/D98798 ___ cfe-commits mailing lis

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

2021-05-12 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment. In D98798#2754449 , @jamieschmeiser wrote: > @thakis, I have some questions about your comments. > Are you sure this is coming from a system header? The path that you gave has > third_party as a directory in the path. Yes. `thir

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

2021-05-12 Thread Jamie Schmeiser via Phabricator via cfe-commits
jamieschmeiser added a comment. @thakis, I have some questions about your comments. Are you sure this is coming from a system header? The path that you gave has third_party as a directory in the path. If the warning were being triggered by code in a system header, I would have expected it to f

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

2021-05-12 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment. Two pieces of feedback: 1. This fires in system headers on windows, e.g. like so: ../../third_party/wtl/include\./atlapp.h(336,12): error: performing pointer arithmetic on a null pointer has undefined behavior if the offset is nonzero [-Werror,-Wnull-pointer-arithmeti

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

2021-05-11 Thread Jamie Schmeiser via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes. Closed by commit rGdfc1e31d49fe: Produce warning for performing pointer arithmetic on a null pointer. (authored by jamieschmeiser). Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org

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

2021-05-06 Thread Eli Friedman via Phabricator via cfe-commits
efriedma accepted this revision. efriedma added a comment. This revision is now accepted and ready to land. LGTM CHANGES SINCE LAST ACTION https://reviews.llvm.org/D98798/new/ https://reviews.llvm.org/D98798 ___ cfe-commits mailing list cfe-commits

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

2021-05-06 Thread Jamie Schmeiser via Phabricator via cfe-commits
jamieschmeiser updated this revision to Diff 343483. jamieschmeiser added a comment. Respond to review comments: add C++ test. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D98798/new/ https://reviews.llvm.org/D98798 Files: clang/lib/Sema/SemaExpr.cpp clang/test/Sema/pointer-additio

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

2021-05-03 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments. Comment at: clang/lib/Sema/SemaExpr.cpp:10723-10733 + bool LHSIsNullPtr = LHS.get()->IgnoreParenCasts()->isNullPointerConstant( + Context, Expr::NPC_ValueDependentIsNotNull); + bool RHSIsNullPtr = RHS.get()->IgnoreParenCasts()->i

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

2021-05-03 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment. I didn't see any instances in quick testing on the Linux kernel: x86_64 defconfig, aarch64 defconfig, arm defconfig, x86_64 allmodconfig. So I guess that's a good thing (for Linux)! Comment at: clang/lib/Sema/SemaExpr.cpp:10723-10733 + b

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

2021-05-03 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment. In D98798#2734598 , @xbolva00 wrote: > Maybe Nick could try this patch with linux kernel? Yes! Thank you of thinking of me for this; we're currently sorting issues identified by this warning (as implemented today, for add

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

2021-05-03 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a comment. Maybe Nick could try this patch with linux kernel? CHANGES SINCE LAST ACTION https://reviews.llvm.org/D98798/new/ https://reviews.llvm.org/D98798 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.o

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

2021-05-03 Thread Jamie Schmeiser via Phabricator via cfe-commits
jamieschmeiser added a comment. ping CHANGES SINCE LAST ACTION https://reviews.llvm.org/D98798/new/ https://reviews.llvm.org/D98798 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

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

2021-04-21 Thread Jamie Schmeiser via Phabricator via cfe-commits
jamieschmeiser added a comment. ping CHANGES SINCE LAST ACTION https://reviews.llvm.org/D98798/new/ https://reviews.llvm.org/D98798 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

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

2021-04-12 Thread Jamie Schmeiser via Phabricator via cfe-commits
jamieschmeiser updated this revision to Diff 336828. jamieschmeiser added a comment. Fix indenting. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D98798/new/ https://reviews.llvm.org/D98798 Files: clang/lib/Sema/SemaExpr.cpp clang/test/Sema/pointer-addition.c Index: clang/test/Sem

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

2021-04-09 Thread Jamie Schmeiser via Phabricator via cfe-commits
jamieschmeiser updated this revision to Diff 336567. jamieschmeiser added a comment. Respond to review comments: Do not issue warning for nullptr - nullptr in C++. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D98798/new/ https://reviews.llvm.org/D98798 Files: clang/lib/Sema/SemaExpr

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

2021-04-09 Thread Jamie Schmeiser via Phabricator via cfe-commits
jamieschmeiser added inline comments. Comment at: clang/test/Sema/pointer-addition.c:34 + f = (char*)(f - (char*)0); // expected-warning {{performing pointer arithmetic on a null pointer has undefined behavior}} + f = (char*)((char*)0 - (char*)0); // expected-warning {{perform

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

2021-04-09 Thread Jamie Schmeiser via Phabricator via cfe-commits
jamieschmeiser added inline comments. Comment at: clang/test/Sema/pointer-addition.c:34 + f = (char*)(f - (char*)0); // expected-warning {{performing pointer arithmetic on a null pointer has undefined behavior}} + f = (char*)((char*)0 - (char*)0); // expected-warning {{perform

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

2021-04-09 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments. Comment at: clang/lib/Sema/SemaExpr.cpp:10724 + // Subtracting from a null pointer should produce a warning. + if (LHS.get()->IgnoreParenCasts()->isNullPointerConstant( + Context, Expr::NPC_ValueDependentIsNotNull)) -

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

2021-04-09 Thread Jamie Schmeiser via Phabricator via cfe-commits
jamieschmeiser updated this revision to Diff 336500. jamieschmeiser added a comment. Respond to review comments: add requested test. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D98798/new/ https://reviews.llvm.org/D98798 Files: clang/lib/Sema/SemaExpr.cpp clang/test/Sema/pointer-a

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

2021-04-08 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment. Please add a test for `(char*)0-(char*)0`. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D98798/new/ https://reviews.llvm.org/D98798 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-b

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

2021-04-08 Thread Jamie Schmeiser via Phabricator via cfe-commits
jamieschmeiser updated this revision to Diff 336148. jamieschmeiser added a comment. Reformat to satisfy clang-format CHANGES SINCE LAST ACTION https://reviews.llvm.org/D98798/new/ https://reviews.llvm.org/D98798 Files: clang/lib/Sema/SemaExpr.cpp clang/test/Sema/pointer-addition.c Ind