1 // RUN: %clang_analyze_cc1 -Wno-unused-value -std=c++14 -analyzer-checker=core,debug.ExprInspection,alpha.core.PointerArithm -verify %s
9 while (in
!= p
) // Loop must be entered.
19 return 5/littleX
.zero
; // no-warning
24 class Derived
: public Base
{};
26 void checkPolymorphicUse() {
30 ++p
; // expected-warning{{Pointer arithmetic on a pointer to base class is dangerous}}
33 void checkBitCasts() {
39 void checkBasicarithmetic(int i
) {
45 ++p
; // expected-warning{{Pointer arithmetic on non-array variables relies on memory layout, which is dangerous}}
46 p
= p
+ 2; // expected-warning{{}}
47 p
= 2 + p
; // expected-warning{{}}
48 p
+= 2; // expected-warning{{}}
49 a
+= p
[2]; // expected-warning{{}}
55 void checkArithOnSymbolic(int*p
) {
67 void arrayInStruct() {
79 p
[1] = 1; // expected-warning{{}}
82 void InitState(int* state
) {
83 state
[1] = 1; // expected-warning{{}}
86 int* getArray(int size
) {
92 void checkConditionalArray() {
93 int* maybeArray
= getArray(0);
94 InitState(maybeArray
);
97 void checkMultiDimansionalArray() {
102 unsigned ptrSubtractionNoCrash(char *Begin
, char *End
) {
103 auto N
= End
- Begin
;
110 bool ptrAsIntegerSubtractionNoCrash(__UINTPTR_TYPE__ x
, char *p
) {
111 __UINTPTR_TYPE__ y
= (__UINTPTR_TYPE__
)p
- 1;
116 bool integerAsPtrSubtractionNoCrash(char *p
, __UINTPTR_TYPE__ m
) {
117 auto n
= p
- reinterpret_cast<char*>((__UINTPTR_TYPE__
)1);