1// Test the blacklist functionality of ASan
2
3// RUN: echo "fun:*brokenFunction*" > %tmp
4// RUN: echo "global:*badGlobal*" >> %tmp
5// RUN: echo "src:*blacklist-extra.cc" >> %tmp
6// RUN: %clangxx_asan -fsanitize-blacklist=%tmp -O0 %s -o %t \
7// RUN: %p/Helpers/blacklist-extra.cc && %run %t 2>&1
8// RUN: %clangxx_asan -fsanitize-blacklist=%tmp -O1 %s -o %t \
9// RUN: %p/Helpers/blacklist-extra.cc && %run %t 2>&1
10// RUN: %clangxx_asan -fsanitize-blacklist=%tmp -O2 %s -o %t \
11// RUN: %p/Helpers/blacklist-extra.cc && %run %t 2>&1
12// RUN: %clangxx_asan -fsanitize-blacklist=%tmp -O3 %s -o %t \
13// RUN: %p/Helpers/blacklist-extra.cc && %run %t 2>&1
14
15// badGlobal is accessed improperly, but we blacklisted it. Align
16// it to make sure memory past the end of badGlobal will be in
17// the same page.
18__attribute__((aligned(16))) int badGlobal;
19int readBadGlobal() {
20  return (&badGlobal)[1];
21}
22
23// A function which is broken, but excluded in the blacklist.
24int brokenFunction(int argc) {
25  char x[10] = {0};
26  return x[argc * 10];  // BOOM
27}
28
29// This function is defined in Helpers/blacklist-extra.cc, a source file which
30// is blacklisted by name
31int externalBrokenFunction(int x);
32
33int main(int argc, char **argv) {
34  brokenFunction(argc);
35  int x = readBadGlobal();
36  externalBrokenFunction(argc);
37  return 0;
38}
39