| 1 |
// RUN: cp %s %t |
| 2 |
// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -Wformat -Wformat-signedness -fixit %t |
| 3 |
// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -fsyntax-only -Wformat -Wformat-signedness -Werror %t |
| 4 |
// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -E -o - %t | FileCheck %s |
| 5 |
|
| 6 |
#include <limits.h> |
| 7 |
|
| 8 |
int printf(const char *restrict format, ...); |
| 9 |
|
| 10 |
void test_printf_int(int x) |
| 11 |
{ |
| 12 |
printf("%u", x); |
| 13 |
} |
| 14 |
|
| 15 |
void test_printf_unsigned(unsigned x) |
| 16 |
{ |
| 17 |
printf("%d", x); |
| 18 |
} |
| 19 |
|
| 20 |
void test_printf_long(long x) |
| 21 |
{ |
| 22 |
printf("%lu", x); |
| 23 |
} |
| 24 |
|
| 25 |
void test_printf_unsigned_long(unsigned long x) |
| 26 |
{ |
| 27 |
printf("%ld", x); |
| 28 |
} |
| 29 |
|
| 30 |
void test_printf_long_long(long long x) |
| 31 |
{ |
| 32 |
printf("%llu", x); |
| 33 |
} |
| 34 |
|
| 35 |
void test_printf_unsigned_long_long(unsigned long long x) |
| 36 |
{ |
| 37 |
printf("%lld", x); |
| 38 |
} |
| 39 |
|
| 40 |
enum enum_int { |
| 41 |
minus_1 = -1 |
| 42 |
}; |
| 43 |
|
| 44 |
void test_printf_enum_int(enum enum_int x) |
| 45 |
{ |
| 46 |
printf("%u", x); |
| 47 |
} |
| 48 |
|
| 49 |
enum enum_unsigned { |
| 50 |
zero = 0 |
| 51 |
}; |
| 52 |
|
| 53 |
void test_printf_enum_unsigned(enum enum_unsigned x) |
| 54 |
{ |
| 55 |
printf("%d", x); |
| 56 |
} |
| 57 |
|
| 58 |
enum enum_long { |
| 59 |
minus_one = -1, |
| 60 |
int_val = INT_MAX, |
| 61 |
unsigned_val = (unsigned)INT_MIN |
| 62 |
}; |
| 63 |
|
| 64 |
void test_printf_enum_long(enum enum_long x) |
| 65 |
{ |
| 66 |
printf("%lu", x); |
| 67 |
} |
| 68 |
|
| 69 |
enum enum_unsigned_long { |
| 70 |
uint_max_plus = (unsigned long)UINT_MAX+1, |
| 71 |
}; |
| 72 |
|
| 73 |
void test_printf_enum_unsigned_long(enum enum_unsigned_long x) |
| 74 |
{ |
| 75 |
printf("%ld", x); |
| 76 |
} |
| 77 |
|
| 78 |
// Validate the fixes. |
| 79 |
// CHECK: void test_printf_int(int x) |
| 80 |
// CHECK: printf("%d", x); |
| 81 |
// CHECK: void test_printf_unsigned(unsigned x) |
| 82 |
// CHECK: printf("%u", x); |
| 83 |
// CHECK: void test_printf_long(long x) |
| 84 |
// CHECK: printf("%ld", x); |
| 85 |
// CHECK: void test_printf_unsigned_long(unsigned long x) |
| 86 |
// CHECK: printf("%lu", x); |
| 87 |
// CHECK: void test_printf_long_long(long long x) |
| 88 |
// CHECK: printf("%lld", x); |
| 89 |
// CHECK: void test_printf_unsigned_long_long(unsigned long long x) |
| 90 |
// CHECK: printf("%llu", x); |
| 91 |
// CHECK: void test_printf_enum_int(enum enum_int x) |
| 92 |
// CHECK: printf("%d", x); |
| 93 |
// CHECK: void test_printf_enum_unsigned(enum enum_unsigned x) |
| 94 |
// CHECK: printf("%u", x); |
| 95 |
// CHECK: void test_printf_enum_long(enum enum_long x) |
| 96 |
// CHECK: printf("%ld", x); |
| 97 |
// CHECK: void test_printf_enum_unsigned_long(enum enum_unsigned_long x) |
| 98 |
// CHECK: printf("%lu", x); |