1 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fsyntax-only -Wno-unused -verify=addr64,expected %s
2 // RUN: %clang_cc1 -triple i386-pc-linux-gnu -fsyntax-only -Wno-unused -verify=addr32,expected %s
3 // RUN: %clang_cc1 -triple avr-pc-linux-gnu -fsyntax-only -Wno-unused -verify=addr16,expected %s
4
5 struct S {
6 long long a;
7 char b;
8 long long c;
9 short d;
10 };
11
12 struct S s[]; // expected-warning {{tentative array definition}} expected-note {{declared here}} addr16-note {{declared here}}
13
f1(void)14 void f1(void) {
15 ++s[3].a;
16 ++s[7073650413200313099].b;
17 // addr16-warning@-1 {{array index 7073650413200313099 refers past the last possible element for an array in 16-bit address space containing 160-bit (20-byte) elements (max possible 3276 elements)}}
18 // addr32-warning@-2 {{array index 7073650413200313099 refers past the last possible element for an array in 32-bit address space containing 192-bit (24-byte) elements (max possible 178956970 elements)}}
19 // addr64-warning@-3 {{array index 7073650413200313099 refers past the last possible element for an array in 64-bit address space containing 256-bit (32-byte) elements (max possible 576460752303423488 elements)}}
20 ++s[7073650].c;
21 // addr16-warning@-1 {{array index 7073650 refers past the last possible element for an array in 16-bit address space containing 160-bit (20-byte) elements (max possible 3276 elements)}}
22 }
23
24 long long ll[]; // expected-warning {{tentative array definition}} expected-note {{declared here}} addr16-note {{declared here}} addr32-note {{declared here}}
25
f2(void)26 void f2(void) {
27 ++ll[3];
28 ++ll[2705843009213693952];
29 // addr16-warning@-1 {{array index 2705843009213693952 refers past the last possible element for an array in 16-bit address space containing 64-bit (8-byte) elements (max possible 8192 elements)}}
30 // addr32-warning@-2 {{array index 2705843009213693952 refers past the last possible element for an array in 32-bit address space containing 64-bit (8-byte) elements (max possible 536870912 elements)}}
31 // addr64-warning@-3 {{array index 2705843009213693952 refers past the last possible element for an array in 64-bit address space containing 64-bit (8-byte) elements (max possible 2305843009213693952 elements)}}
32 ++ll[847073650];
33 // addr16-warning@-1 {{array index 847073650 refers past the last possible element for an array in 16-bit address space containing 64-bit (8-byte) elements (max possible 8192 elements)}}
34 // addr32-warning@-2 {{array index 847073650 refers past the last possible element for an array in 32-bit address space containing 64-bit (8-byte) elements (max possible 536870912 elements)}}
35 }
36
f3(struct S p[])37 void f3(struct S p[]) { // expected-note {{declared here}} addr16-note {{declared here}}
38 ++p[3].a;
39 ++p[7073650413200313099].b;
40 // addr16-warning@-1 {{array index 7073650413200313099 refers past the last possible element for an array in 16-bit address space containing 160-bit (20-byte) elements (max possible 3276 elements)}}
41 // addr32-warning@-2 {{array index 7073650413200313099 refers past the last possible element for an array in 32-bit address space containing 192-bit (24-byte) elements (max possible 178956970 elements)}}
42 // addr64-warning@-3 {{array index 7073650413200313099 refers past the last possible element for an array in 64-bit address space containing 256-bit (32-byte) elements (max possible 576460752303423488 elements)}}
43 ++p[7073650].c;
44 // addr16-warning@-1 {{array index 7073650 refers past the last possible element for an array in 16-bit address space containing 160-bit (20-byte) elements (max possible 3276 elements)}}
45 }
46
f4(struct S * p)47 void f4(struct S *p) { // expected-note {{declared here}} addr16-note {{declared here}}
48 p += 3;
49 p += 7073650413200313099;
50 // addr16-warning@-1 {{the pointer incremented by 7073650413200313099 refers past the last possible element for an array in 16-bit address space containing 160-bit (20-byte) elements (max possible 3276 elements)}}
51 // addr32-warning@-2 {{the pointer incremented by 7073650413200313099 refers past the last possible element for an array in 32-bit address space containing 192-bit (24-byte) elements (max possible 178956970 elements)}}
52 // addr64-warning@-3 {{the pointer incremented by 7073650413200313099 refers past the last possible element for an array in 64-bit address space containing 256-bit (32-byte) elements (max possible 576460752303423488 elements)}}
53 p += 7073650;
54 // addr16-warning@-1 {{the pointer incremented by 7073650 refers past the last possible element for an array in 16-bit address space containing 160-bit (20-byte) elements (max possible 3276 elements)}}
55 }
56
57 struct BQ {
58 struct S bigblock[3276];
59 };
60
61 struct BQ bq[]; // expected-warning {{tentative array definition}} addr16-note {{declared here}}
62
f5(void)63 void f5(void) {
64 ++bq[0].bigblock[0].a;
65 ++bq[1].bigblock[0].a;
66 // addr16-warning@-1 {{array index 1 refers past the last possible element for an array in 16-bit address space containing 524160-bit (65520-byte) elements (max possible 1 element)}}
67 }
68
f6(void)69 void f6(void) {
70 int ints[] = {1, 3, 5, 7, 8, 6, 4, 5, 9};
71 int const n_ints = sizeof(ints) / sizeof(int);
72 unsigned long long const N = 3;
73
74 int *middle = &ints[0] + n_ints / 2;
75 // Should NOT produce a warning.
76 *(middle + 5 - N) = 22;
77 }
78
pr50741(void)79 void pr50741(void) {
80 (void *)0 + 0xdead000000000000UL;
81 // no array-bounds warning, and no crash
82 }
83
func()84 void func() {
85 func + 0xdead000000000000UL; // no crash
86 }
87