brintos

brintos / llvm-project-archived public Read only

0
0
Text · 7.3 KiB · 909286b Raw
117 lines · c
1// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fsyntax-only -Wno-unused -verify=addr64,expected %s2// RUN: %clang_cc1 -triple i386-pc-linux-gnu   -fsyntax-only -Wno-unused -verify=addr32,expected %s3// RUN: %clang_cc1 -triple avr-pc-linux-gnu    -fsyntax-only -Wno-unused -verify=addr16,expected %s4 5struct S {6  long long a;7  char b;8  long long c;9  short d;10};11 12struct S s[]; // expected-warning {{tentative array definition}} expected-note {{declared here}} addr16-note {{declared here}}13 14void f1(void) {15  ++s[3].a;16  ++s[7073650413200313099].b;17  // addr16-warning@-1 {{array index 7'073'650'413'200'313'099 refers past the last possible element for an array in 16-bit address space containing 152-bit (19-byte) elements (max possible 3'449 elements)}}18  // addr32-warning@-2 {{array index 7'073'650'413'200'313'099 refers past the last possible element for an array in 32-bit address space containing 192-bit (24-byte) elements (max possible 178'956'970 elements)}}19  // addr64-warning@-3 {{array index 7'073'650'413'200'313'099 refers past the last possible element for an array in 64-bit address space containing 256-bit (32-byte) elements (max possible 576'460'752'303'423'488 elements)}}20  ++s[7073650].c;21  // addr16-warning@-1 {{array index 7'073'650 refers past the last possible element for an array in 16-bit address space containing 152-bit (19-byte) elements (max possible 3'449 elements)}}22}23 24long long ll[]; // expected-warning {{tentative array definition}} expected-note {{declared here}} addr16-note {{declared here}} addr32-note {{declared here}}25 26void f2(void) {27  ++ll[3];28  ++ll[2705843009213693952];29  // addr16-warning@-1 {{array index 2'705'843'009'213'693'952 refers past the last possible element for an array in 16-bit address space containing 64-bit (8-byte) elements (max possible 8'192 elements)}}30  // addr32-warning@-2 {{array index 2'705'843'009'213'693'952 refers past the last possible element for an array in 32-bit address space containing 64-bit (8-byte) elements (max possible 536'870'912 elements)}}31  // addr64-warning@-3 {{array index 2'705'843'009'213'693'952 refers past the last possible element for an array in 64-bit address space containing 64-bit (8-byte) elements (max possible 2'305'843'009'213'693'952 elements)}}32  ++ll[847073650];33  // addr16-warning@-1 {{array index 847'073'650 refers past the last possible element for an array in 16-bit address space containing 64-bit (8-byte) elements (max possible 8'192 elements)}}34  // addr32-warning@-2 {{array index 847'073'650 refers past the last possible element for an array in 32-bit address space containing 64-bit (8-byte) elements (max possible 536'870'912 elements)}}35}36 37void 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 7'073'650'413'200'313'099 refers past the last possible element for an array in 16-bit address space containing 152-bit (19-byte) elements (max possible 3'449 elements)}}41  // addr32-warning@-2 {{array index 7'073'650'413'200'313'099 refers past the last possible element for an array in 32-bit address space containing 192-bit (24-byte) elements (max possible 178'956'970 elements)}}42  // addr64-warning@-3 {{array index 7'073'650'413'200'313'099 refers past the last possible element for an array in 64-bit address space containing 256-bit (32-byte) elements (max possible 576'460'752'303'423'488 elements)}}43  ++p[7073650].c;44  // addr16-warning@-1 {{array index 7'073'650 refers past the last possible element for an array in 16-bit address space containing 152-bit (19-byte) elements (max possible 3'449 elements)}}45}46 47void 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 7'073'650'413'200'313'099 refers past the last possible element for an array in 16-bit address space containing 152-bit (19-byte) elements (max possible 3'449 elements)}}51  // addr32-warning@-2 {{the pointer incremented by 7'073'650'413'200'313'099 refers past the last possible element for an array in 32-bit address space containing 192-bit (24-byte) elements (max possible 178'956'970 elements)}}52  // addr64-warning@-3 {{the pointer incremented by 7'073'650'413'200'313'099 refers past the last possible element for an array in 64-bit address space containing 256-bit (32-byte) elements (max possible 576'460'752'303'423'488 elements)}}53  p += 7073650;54  // addr16-warning@-1 {{the pointer incremented by 7'073'650 refers past the last possible element for an array in 16-bit address space containing 152-bit (19-byte) elements (max possible 3'449 elements)}}55}56 57struct BQ {58  struct S bigblock[3276];59};60 61struct BQ bq[]; // expected-warning {{tentative array definition}} addr16-note {{declared here}}62 63void 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 497952-bit (62'244-byte) elements (max possible 1 element)}}67}68 69void 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 79void pr50741(void) {80  (void *)0 + 0xdead000000000000UL;81  // no array-bounds warning, and no crash82}83 84void func() {85  func + 0xdead000000000000UL; // no crash86}87 88struct {89  int _;90  char tail[];  // addr16-note {{declared here}} addr32-note {{declared here}}91} fam;92 93struct {94  int _;95  char tail[0];  // addr16-note {{declared here}} addr32-note {{declared here}}96} fam0;97 98struct {99  int _;100  char tail[1];  // addr16-note {{declared here}} addr32-note {{declared here}}101} fam1;102 103void fam_ily() {104  ++fam.tail[7073650413200313099];105  // addr16-warning@-1 {{array index 7'073'650'413'200'313'099 refers past the last possible element for an array in 16-bit address space containing 8-bit (1-byte) elements (max possible 65'536 elements)}}106  // addr32-warning@-2 {{array index 7'073'650'413'200'313'099 refers past the last possible element for an array in 32-bit address space containing 8-bit (1-byte) elements (max possible 4'294'967'296 elements)}}107  // No warning for addr64 because the array index is inbound in that case.108  ++fam0.tail[7073650413200313099];109  // addr16-warning@-1 {{array index 7'073'650'413'200'313'099 refers past the last possible element for an array in 16-bit address space containing 8-bit (1-byte) elements (max possible 65'536 elements)}}110  // addr32-warning@-2 {{array index 7'073'650'413'200'313'099 refers past the last possible element for an array in 32-bit address space containing 8-bit (1-byte) elements (max possible 4'294'967'296 elements)}}111  // No warning for addr64 because the array index is inbound in that case.112  ++fam1.tail[7073650413200313099];113  // addr16-warning@-1 {{array index 7'073'650'413'200'313'099 refers past the last possible element for an array in 16-bit address space containing 8-bit (1-byte) elements (max possible 65'536 elements)}}114  // addr32-warning@-2 {{array index 7'073'650'413'200'313'099 refers past the last possible element for an array in 32-bit address space containing 8-bit (1-byte) elements (max possible 4'294'967'296 elements)}}115  // No warning for addr64 because the array index is inbound in that case.116}117