1*f4a2713aSLionel Sambuc // RUN: cp %s %t
2*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -fixit %t
3*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -E -o - %t | FileCheck %s
4*f4a2713aSLionel Sambuc
5*f4a2713aSLionel Sambuc /* This is a test of the various code modification hints that are
6*f4a2713aSLionel Sambuc provided as part of warning or extension diagnostics. Only
7*f4a2713aSLionel Sambuc warnings for format strings within the function call will be
8*f4a2713aSLionel Sambuc fixed by -fixit. Other format strings will be left alone. */
9*f4a2713aSLionel Sambuc
10*f4a2713aSLionel Sambuc int printf(char const *, ...);
11*f4a2713aSLionel Sambuc int scanf(char const *, ...);
12*f4a2713aSLionel Sambuc
pr9751()13*f4a2713aSLionel Sambuc void pr9751() {
14*f4a2713aSLionel Sambuc const char kFormat1[] = "%s";
15*f4a2713aSLionel Sambuc printf(kFormat1, 5);
16*f4a2713aSLionel Sambuc printf("%s", 5);
17*f4a2713aSLionel Sambuc
18*f4a2713aSLionel Sambuc const char kFormat2[] = "%.3p";
19*f4a2713aSLionel Sambuc void *p;
20*f4a2713aSLionel Sambuc printf(kFormat2, p);
21*f4a2713aSLionel Sambuc printf("%.3p", p);
22*f4a2713aSLionel Sambuc
23*f4a2713aSLionel Sambuc const char kFormat3[] = "%0s";
24*f4a2713aSLionel Sambuc printf(kFormat3, "a");
25*f4a2713aSLionel Sambuc printf("%0s", "a");
26*f4a2713aSLionel Sambuc
27*f4a2713aSLionel Sambuc const char kFormat4[] = "%hhs";
28*f4a2713aSLionel Sambuc printf(kFormat4, "a");
29*f4a2713aSLionel Sambuc printf("%hhs", "a");
30*f4a2713aSLionel Sambuc
31*f4a2713aSLionel Sambuc const char kFormat5[] = "%-0d";
32*f4a2713aSLionel Sambuc printf(kFormat5, 5);
33*f4a2713aSLionel Sambuc printf("%-0d", 5);
34*f4a2713aSLionel Sambuc
35*f4a2713aSLionel Sambuc const char kFormat6[] = "%00d";
36*f4a2713aSLionel Sambuc int *i;
37*f4a2713aSLionel Sambuc scanf(kFormat6, i);
38*f4a2713aSLionel Sambuc scanf("%00d", i);
39*f4a2713aSLionel Sambuc }
40*f4a2713aSLionel Sambuc
41*f4a2713aSLionel Sambuc // CHECK: const char kFormat1[] = "%s";
42*f4a2713aSLionel Sambuc // CHECK: printf(kFormat1, 5);
43*f4a2713aSLionel Sambuc // CHECK: printf("%d", 5);
44*f4a2713aSLionel Sambuc
45*f4a2713aSLionel Sambuc // CHECK: const char kFormat2[] = "%.3p";
46*f4a2713aSLionel Sambuc // CHECK: void *p;
47*f4a2713aSLionel Sambuc // CHECK: printf(kFormat2, p);
48*f4a2713aSLionel Sambuc // CHECK: printf("%p", p);
49*f4a2713aSLionel Sambuc
50*f4a2713aSLionel Sambuc // CHECK: const char kFormat3[] = "%0s";
51*f4a2713aSLionel Sambuc // CHECK: printf(kFormat3, "a");
52*f4a2713aSLionel Sambuc // CHECK: printf("%s", "a");
53*f4a2713aSLionel Sambuc
54*f4a2713aSLionel Sambuc // CHECK: const char kFormat4[] = "%hhs";
55*f4a2713aSLionel Sambuc // CHECK: printf(kFormat4, "a");
56*f4a2713aSLionel Sambuc // CHECK: printf("%s", "a");
57*f4a2713aSLionel Sambuc
58*f4a2713aSLionel Sambuc // CHECK: const char kFormat5[] = "%-0d";
59*f4a2713aSLionel Sambuc // CHECK: printf(kFormat5, 5);
60*f4a2713aSLionel Sambuc // CHECK: printf("%-d", 5);
61*f4a2713aSLionel Sambuc
62*f4a2713aSLionel Sambuc // CHECK: const char kFormat6[] = "%00d";
63*f4a2713aSLionel Sambuc // CHECK: int *i;
64*f4a2713aSLionel Sambuc // CHECK: scanf(kFormat6, i);
65*f4a2713aSLionel Sambuc // CHECK: scanf("%d", i);
66