1// RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
2// RUN: %clangxx_asan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
3// RUN: %clangxx_asan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s
4// RUN: %clangxx_asan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s
5
6#include <string.h>
7
8char kString[] = "foo";
9
10int main(int argc, char **argv) {
11  char *copy = strdup(kString);
12  int x = copy[4 + argc];  // BOOM
13  // CHECK: AddressSanitizer: heap-buffer-overflow
14  // CHECK: #0 {{.*}}main {{.*}}strdup_oob_test.cc:[[@LINE-2]]
15  // CHECK-LABEL: allocated by thread T{{.*}} here:
16  // CHECK: #{{[01]}} {{.*}}strdup
17  // CHECK-LABEL: SUMMARY
18  // CHECK: strdup_oob_test.cc:[[@LINE-6]]
19  return x;
20}
21