Alexey Samsonov | 00cd273 | 2014-01-21 11:58:33 +0000 | [diff] [blame] | 1 | // RUN: %clang_asan -O2 %s -o %t |
Reid Kleckner | 85220d0 | 2015-08-12 23:50:12 +0000 | [diff] [blame^] | 2 | // RUN: %env_asan_opts=check_printf=1 %run %t 2>&1 | FileCheck %s |
| 3 | // RUN: %env_asan_opts=check_printf=0 %run %t 2>&1 | FileCheck %s |
Greg Fitzgerald | b8aae54 | 2014-04-30 21:34:17 +0000 | [diff] [blame] | 4 | // RUN: %run %t 2>&1 | FileCheck %s |
Alexey Samsonov | 00cd273 | 2014-01-21 11:58:33 +0000 | [diff] [blame] | 5 | |
| 6 | #include <stdio.h> |
Timur Iskhodzhanov | 7f29181 | 2014-05-28 13:06:14 +0000 | [diff] [blame] | 7 | #if defined(_WIN32) |
| 8 | # define snprintf _snprintf |
| 9 | #endif |
| 10 | |
Alexey Samsonov | 00cd273 | 2014-01-21 11:58:33 +0000 | [diff] [blame] | 11 | int main() { |
| 12 | volatile char c = '0'; |
| 13 | volatile int x = 12; |
| 14 | volatile float f = 1.239; |
| 15 | volatile char s[] = "34"; |
Alexey Samsonov | 00cd273 | 2014-01-21 11:58:33 +0000 | [diff] [blame] | 16 | // Check that printf works fine under Asan. |
Alexey Samsonov | 1d028b8 | 2014-01-23 15:09:38 +0000 | [diff] [blame] | 17 | printf("%c %d %.3f %s\n", c, x, f, s); |
Alexey Samsonov | 00cd273 | 2014-01-21 11:58:33 +0000 | [diff] [blame] | 18 | // CHECK: 0 12 1.239 34 |
Alexey Samsonov | 1d028b8 | 2014-01-23 15:09:38 +0000 | [diff] [blame] | 19 | // Check that snprintf works fine under Asan. |
| 20 | char buf[4]; |
| 21 | snprintf(buf, 1000, "qwe"); |
| 22 | printf("%s\n", buf); |
| 23 | // CHECK: qwe |
| 24 | return 0; |
Alexey Samsonov | 00cd273 | 2014-01-21 11:58:33 +0000 | [diff] [blame] | 25 | } |