1 /* Verify that offsets in "anti-ranges" are handled correctly.
3 { dg-options "-O2 -Wall -ftrack-macro-expansion=0 -fno-ipa-icf" } */
5 typedef __PTRDIFF_TYPE__
ptrdiff_t;
6 typedef __SIZE_TYPE__
size_t;
8 void* memset (void*, int, size_t);
10 void sink (void*, ...);
14 void int_range_add_sub_ (int i
, int j
)
19 char ca5
[5]; // { dg-message "at offset \\\[1, 5]" "note" }
20 char *p0
= ca5
; // offset
21 char *p1
= p0
+ i
; // 1-5
22 char *p2
= p1
+ i
; // 2-5
23 char *p3
= p2
+ j
; // 0-4
24 char *p4
= p3
+ j
; // 0-3
25 char *p5
= p4
+ j
; // 0-2
26 char *p6
= p5
+ j
; // 0-1
27 char *p7
= p6
+ i
; // 1-2
29 memset (p7
, 0, 5); // { dg-warning "writing 5 bytes into a region of size 4" }
31 sink (p0
, p1
, p2
, p3
, p4
, p5
, p6
, p7
);
35 void ruint_arint_add (unsigned i
, int j
)
37 i
|= 1; // [1, UINT_MAX]
38 j
|= 1; // [INT_MIN + 1, -1] U [1, INT_MAX]
40 char a
[5]; // { dg-message "at offset \\\[1, 5]" "note" }
41 char *p0
= a
; // offset
42 char *p1
= p0
+ i
; // 1-5
43 T (memset (p1
, 0, 4));
45 char *p2
= p1
+ j
; // 0-5
46 T (memset (p2
, 0, 5));
48 char *p3
= p2
+ i
; // 1-5
49 T (memset (p3
, 0, 4));
51 char *p4
= p3
+ j
; // 0-5
52 T (memset (p4
, 0, 5));
54 char *p5
= p4
+ i
; // 1-5
55 T (memset (p5
, 0, 4));
57 char *p6
= p5
+ j
; // 0-5
58 T (memset (p6
, 0, 5));
60 char *p7
= p6
+ i
; // 1-5
61 T (memset (p7
, 0, 5)); // { dg-warning "writing 5 bytes into a region of size 4" "" }
65 void warn_ptrdiff_anti_range_add (ptrdiff_t i
)
69 char ca5
[5]; // { dg-message "at offset \\\[1, 5]" "pr?????" }
70 char *p0
= ca5
; // offset
71 char *p1
= p0
+ i
; // 1-5
72 char *p2
= p1
+ i
; // 2-5
73 char *p3
= p2
+ i
; // 3-5
74 char *p4
= p3
+ i
; // 4-5
75 char *p5
= p4
+ i
; // 5
77 memset (p5
, 0, 5); // { dg-warning "writing 5 bytes into a region of size" "pr?????" }
79 sink (p0
, p1
, p2
, p3
, p4
, p5
);
82 void warn_int_anti_range (int i
)
86 char ca5
[5]; // { dg-message "at offset \\\[1, 5]" "pr?????" }
87 char *p0
= ca5
; // offset
88 char *p1
= p0
+ i
; // 1-5
89 char *p2
= p1
+ i
; // 2-5
90 char *p3
= p2
+ i
; // 3-5
91 char *p4
= p3
+ i
; // 4-5
92 char *p5
= p4
+ i
; // 5
94 memset (p5
, 0, 5); // { dg-warning "writing 5 bytes into a region of size" "pr?????" }
96 sink (p0
, p1
, p2
, p3
, p4
, p5
);