1 /* Verify that offsets in "anti-ranges" are handled correctly.
2 { dg-do compile }
3 { dg-options "-O2 -Wall -ftrack-macro-expansion=0" } */
4
5 typedef __PTRDIFF_TYPE__ ptrdiff_t;
6 typedef __SIZE_TYPE__ size_t;
7
8 void* memset (void*, int, size_t);
9
10 void sink (void*, ...);
11 #define T(x) sink (x)
12
13
int_range_add_sub_(int i,int j)14 void int_range_add_sub_ (int i, int j)
15 {
16 if (i < 1) i = 1;
17 if (j > -1) j = -1;
18
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
28
29 memset (p7, 0, 5); // { dg-warning "writing 5 bytes into a region of size 4" }
30
31 sink (p0, p1, p2, p3, p4, p5, p6, p7);
32 }
33
34
ruint_arint_add(unsigned i,int j)35 void ruint_arint_add (unsigned i, int j)
36 {
37 i |= 1; // [1, UINT_MAX]
38 j |= 1; // [INT_MIN + 1, -1] U [1, INT_MAX]
39
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));
44
45 char *p2 = p1 + j; // 0-5
46 T (memset (p2, 0, 5));
47
48 char *p3 = p2 + i; // 1-5
49 T (memset (p3, 0, 4));
50
51 char *p4 = p3 + j; // 0-5
52 T (memset (p4, 0, 5));
53
54 char *p5 = p4 + i; // 1-5
55 T (memset (p5, 0, 4));
56
57 char *p6 = p5 + j; // 0-5
58 T (memset (p6, 0, 5));
59
60 char *p7 = p6 + i; // 1-5
61 T (memset (p7, 0, 5)); // { dg-warning "writing 5 bytes into a region of size 4" "" }
62 }
63
64
warn_ptrdiff_anti_range_add(ptrdiff_t i)65 void warn_ptrdiff_anti_range_add (ptrdiff_t i)
66 {
67 i |= 1;
68
69 char ca5[5]; // { dg-message "at offset \\\[1, 5]" "pr?????" { xfail *-*-* } }
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
76
77 memset (p5, 0, 5); // { dg-warning "writing 5 bytes into a region of size 0" "pr?????" { xfail *-*-* } }
78
79 sink (p0, p1, p2, p3, p4, p5);
80 }
81
warn_int_anti_range(int i)82 void warn_int_anti_range (int i)
83 {
84 i |= 1;
85
86 char ca5[5]; // { dg-message "at offset \\\[1, 5]" "pr?????" { xfail *-*-* } }
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
93
94 memset (p5, 0, 5); // { dg-warning "writing 5 bytes into a region of size 0" "pr?????" { xfail *-*-* } }
95
96 sink (p0, p1, p2, p3, p4, p5);
97 }
98