1// RUN: %clang_asan -Wno-excess-initializers -O2 %s -o %t
2// We need replace_intrin=0 to avoid reporting errors in memcpy.
3// RUN: %env_asan_opts=replace_intrin=0:check_printf=1 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s
4// RUN: %env_asan_opts=replace_intrin=0:check_printf=0 %run %t 2>&1 | FileCheck --check-prefix=CHECK-OFF %s
5// RUN: %env_asan_opts=replace_intrin=0 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s
6
7// FIXME: printf is not intercepted on Windows yet.
8// XFAIL: target={{.*windows-(msvc.*|gnu)}}
9
10#include <stdio.h>
11#include <string.h>
12int main() {
13 volatile char c = '0';
14 volatile int x = 12;
15 volatile float f = 1.239;
16 volatile char s[] = "34";
17 volatile char fmt[2] = "%c %d %f %s\n";
18 printf(format: (char *)fmt, c, x, f, s);
19 return 0;
20 // Check that format string is sanitized.
21 // CHECK-ON: stack-buffer-overflow
22 // CHECK-ON-NOT: 0 12 1.239 34
23 // CHECK-OFF: 0
24}
25

source code of compiler-rt/test/asan/TestCases/printf-5.c