Produce warning for performing pointer arithmetic on a null pointer.
authorJamie Schmeiser <schmeise@ca.ibm.com>
Tue, 11 May 2021 15:29:50 +0000 (11:29 -0400)
committerJamie Schmeiser <schmeise@ca.ibm.com>
Tue, 11 May 2021 15:29:50 +0000 (11:29 -0400)
commitdfc1e31d49fe1380c9bab43373995df5fed15e6d
treec2699bfdc8e25bfdfbdbe9de1d5eb636f7822446
parent4eff9469475384a59a9da407e78aa00262edcdd0
Produce warning for performing pointer arithmetic on a null pointer.

Summary:
Test and produce warning for subtracting a pointer from null or subtracting
null from a pointer.  Reuse existing warning that this is undefined
behaviour.  Also add unit test for both warnings.

Reformat to satisfy clang-format.

Respond to review comments:  add additional test.

Respond to review comments:  Do not issue warning for nullptr - nullptr
in C++.

Fix indenting to satisfy clang-format.

Respond to review comments:  Add C++ tests.

Author: Jamie Schmeiser <schmeise@ca.ibm.com>
Reviewed By: efriedma (Eli Friedman), nickdesaulniers (Nick Desaulniers)
Differential Revision: https://reviews.llvm.org/D98798
clang/lib/Sema/SemaExpr.cpp
clang/test/Sema/pointer-addition.c
clang/test/Sema/pointer-addition.cpp [new file with mode: 0644]