Move ASan lit-tests under test/asan
[blocksruntime.git] / test / asan / TestCases / printf-5.c
blob5e90e734fb0f705a679600d26f459fa4b2559a8e
1 // RUN: %clang_asan -O2 %s -o %t
2 // We need replace_intrin=0 to avoid reporting errors in memcpy.
3 // RUN: ASAN_OPTIONS=replace_intrin=0:check_printf=1 not %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s
4 // RUN: ASAN_OPTIONS=replace_intrin=0:check_printf=0 %t 2>&1 | FileCheck --check-prefix=CHECK-OFF %s
5 // RUN: ASAN_OPTIONS=replace_intrin=0 %t 2>&1 | FileCheck --check-prefix=CHECK-OFF %s
7 #include <stdio.h>
8 #include <string.h>
9 int main() {
10 volatile char c = '0';
11 volatile int x = 12;
12 volatile float f = 1.239;
13 volatile char s[] = "34";
14 volatile char fmt[2];
15 memcpy((char *)fmt, "%c %d %f %s\n", sizeof(fmt));
16 printf((char *)fmt, c, x, f, s);
17 return 0;
18 // Check that format string is sanitized.
19 // CHECK-ON: stack-buffer-overflow
20 // CHECK-ON-NOT: 0 12 1.239 34
21 // CHECK-OFF: 0