xref: /aosp_15_r20/external/compiler-rt/test/asan/TestCases/global-overflow.cc (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot // RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
2*7c3d14c8STreehugger Robot // RUN: %clangxx_asan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
3*7c3d14c8STreehugger Robot // RUN: %clangxx_asan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s
4*7c3d14c8STreehugger Robot // RUN: %clangxx_asan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s
5*7c3d14c8STreehugger Robot 
6*7c3d14c8STreehugger Robot #include <string.h>
main(int argc,char ** argv)7*7c3d14c8STreehugger Robot int main(int argc, char **argv) {
8*7c3d14c8STreehugger Robot   static char XXX[10];
9*7c3d14c8STreehugger Robot   static char YYY[10];
10*7c3d14c8STreehugger Robot   static char ZZZ[10];
11*7c3d14c8STreehugger Robot   memset(XXX, 0, 10);
12*7c3d14c8STreehugger Robot   memset(YYY, 0, 10);
13*7c3d14c8STreehugger Robot   memset(ZZZ, 0, 10);
14*7c3d14c8STreehugger Robot   int res = YYY[argc * 10];  // BOOOM
15*7c3d14c8STreehugger Robot   // CHECK: {{READ of size 1 at 0x.* thread T0}}
16*7c3d14c8STreehugger Robot   // CHECK: {{    #0 0x.* in main .*global-overflow.cc:}}[[@LINE-2]]
17*7c3d14c8STreehugger Robot   // CHECK: {{0x.* is located 0 bytes to the right of global variable}}
18*7c3d14c8STreehugger Robot   // CHECK:   {{.*YYY.* of size 10}}
19*7c3d14c8STreehugger Robot   res += XXX[argc] + ZZZ[argc];
20*7c3d14c8STreehugger Robot   return res;
21*7c3d14c8STreehugger Robot }
22