1 /* { dg-options "-fdiagnostics-show-caret -Wpointer-sign" }  */
2 
3 /* A collection of calls where argument 2 is of the wrong type.  */
4 
5 /* decl, with argname.  */
6 
7 extern int callee_1 (int one, const char *two, float three); /* { dg-line callee_1 } */
8 
test_1(int first,int second,float third)9 int test_1 (int first, int second, float third)
10 {
11   return callee_1 (first, second, third); /* { dg-warning "passing argument 2 of 'callee_1' makes pointer from integer without a cast" }  */
12   /* { dg-begin-multiline-output "" }
13    return callee_1 (first, second, third);
14                            ^~~~~~
15                            |
16                            int
17      { dg-end-multiline-output "" } */
18   /* { dg-message "expected 'const char \\*' but argument is of type 'int'" "" { target *-*-* } callee_1 } */
19   /* { dg-begin-multiline-output "" }
20  extern int callee_1 (int one, const char *two, float three);
21                                ~~~~~~~~~~~~^~~
22      { dg-end-multiline-output "" } */
23 }
24 
25 /* decl, without argname.  */
26 
27 extern int callee_2 (int, const char *, float); /* { dg-line callee_2 } */
28 
test_2(int first,int second,float third)29 int test_2 (int first, int second, float third)
30 {
31   return callee_2 (first, second, third); /* { dg-warning "passing argument 2 of 'callee_2' makes pointer from integer without a cast" } */
32   /* { dg-begin-multiline-output "" }
33    return callee_2 (first, second, third);
34                            ^~~~~~
35                            |
36                            int
37      { dg-end-multiline-output "" } */
38   /* { dg-message "expected 'const char \\*' but argument is of type 'int'" "" { target *-*-* } callee_2 } */
39   /* { dg-begin-multiline-output "" }
40  extern int callee_2 (int, const char *, float);
41                            ^~~~~~~~~~~~
42      { dg-end-multiline-output "" } */
43 }
44 
45 /* defn, with argname.  */
46 
callee_3(int one,const char * two,float three)47 static int callee_3 (int one, const char *two, float three) /* { dg-line callee_3 } */
48 {
49   return callee_2 (one, two, three);
50 }
51 
test_3(int first,int second,float third)52 int test_3 (int first, int second, float third)
53 {
54   return callee_3 (first, second, third); // { dg-warning "passing argument 2 of 'callee_3' makes pointer from integer without a cast" }
55   /* { dg-begin-multiline-output "" }
56    return callee_3 (first, second, third);
57                            ^~~~~~
58                            |
59                            int
60      { dg-end-multiline-output "" } */
61   /* { dg-message "expected 'const char \\*' but argument is of type 'int'" "" { target *-*-* } callee_3 } */
62   /* { dg-begin-multiline-output "" }
63  static int callee_3 (int one, const char *two, float three)
64                                ~~~~~~~~~~~~^~~
65      { dg-end-multiline-output "" } */
66 }
67 
68 /* Trivial decl, with argname.  */
69 
70 extern int callee_4 (int one, float two, float three); /* { dg-line callee_4 } */
71 
test_4(int first,const char * second,float third)72 int test_4 (int first, const char *second, float third)
73 {
74   return callee_4 (first, second, third); /* { dg-error "incompatible type for argument 2 of 'callee_4'" }  */
75   /* { dg-begin-multiline-output "" }
76    return callee_4 (first, second, third);
77                            ^~~~~~
78                            |
79                            const char *
80      { dg-end-multiline-output "" } */
81   /* { dg-message "expected 'float' but argument is of type 'const char \\*'" "" { target *-*-* } callee_4 } */
82   /* { dg-begin-multiline-output "" }
83  extern int callee_4 (int one, float two, float three);
84                                ~~~~~~^~~
85      { dg-end-multiline-output "" } */
86 }
87 
88 /* Trivial decl, without argname.  */
89 
90 extern int callee_5 (int, float, float); /* { dg-line callee_5 } */
91 
test_5(int first,const char * second,float third)92 int test_5 (int first, const char *second, float third)
93 {
94   return callee_5 (first, second, third); /* { dg-error "incompatible type for argument 2 of 'callee_5'" }  */
95   /* { dg-begin-multiline-output "" }
96    return callee_5 (first, second, third);
97                            ^~~~~~
98                            |
99                            const char *
100      { dg-end-multiline-output "" } */
101   /* { dg-message "expected 'float' but argument is of type 'const char \\*'" "" { target *-*-* } callee_5 } */
102   /* { dg-begin-multiline-output "" }
103  extern int callee_5 (int, float, float);
104                            ^~~~~
105      { dg-end-multiline-output "" } */
106 }
107 
108 /* Callback with name.  */
109 
110 extern int callee_6 (int one, int (*two)(int, int), float three); /* { dg-line callee_6 } */
111 
test_6(int first,int second,float third)112 int test_6 (int first, int second, float third)
113 {
114   return callee_6 (first, second, third); /* { dg-warning "passing argument 2 of 'callee_6' makes pointer from integer without a cast" } */
115   /* { dg-begin-multiline-output "" }
116    return callee_6 (first, second, third);
117                            ^~~~~~
118                            |
119                            int
120      { dg-end-multiline-output "" } */
121   /* { dg-message " expected 'int \\(\\*\\)\\(int,  int\\)' but argument is of type 'int'" "" { target *-*-* } callee_6 } */
122   /* { dg-begin-multiline-output "" }
123  extern int callee_6 (int one, int (*two)(int, int), float three);
124                                ~~~~~~^~~~~~~~~~~~~~
125      { dg-end-multiline-output "" } */
126 }
127 
128 /* Callback without name.  */
129 
130 extern int callee_7 (int one, int (*)(int, int), float three); /* { dg-line callee_7 } */
131 
test_7(int first,int second,float third)132 int test_7 (int first, int second, float third)
133 {
134   return callee_7 (first, second, third); /* { dg-warning "passing argument 2 of 'callee_7' makes pointer from integer without a cast" } */
135   /* { dg-begin-multiline-output "" }
136    return callee_7 (first, second, third);
137                            ^~~~~~
138                            |
139                            int
140      { dg-end-multiline-output "" } */
141   /* { dg-message " expected 'int \\(\\*\\)\\(int,  int\\)' but argument is of type 'int'" "" { target *-*-* } callee_7 } */
142   /* { dg-begin-multiline-output "" }
143  extern int callee_7 (int one, int (*)(int, int), float three);
144                                ^~~~~~~~~~~~~~~~~
145      { dg-end-multiline-output "" } */
146 }
147 
148 /* -Wincompatible-pointer-types for a parameter.  */
149 
150 extern int callee_8 (int one, float *two, float (three)); /* { dg-line callee_8 } */
151 
test_8(int first,int * second,float third)152 int test_8 (int first, int *second, float third)
153 {
154   return callee_8 (first, second, third); /* { dg-warning "passing argument 2 of 'callee_8' from incompatible pointer type" } */
155   /* { dg-begin-multiline-output "" }
156    return callee_8 (first, second, third);
157                            ^~~~~~
158                            |
159                            int *
160      { dg-end-multiline-output "" } */
161   /* { dg-message "expected 'float \\*' but argument is of type 'int \\*'" "" { target *-*-* } callee_8 } */
162   /* { dg-begin-multiline-output "" }
163  extern int callee_8 (int one, float *two, float (three));
164                                ~~~~~~~^~~
165      { dg-end-multiline-output "" } */
166 }
167 
168 /* -Wpointer-sign for a parameter.  */
169 
170 extern int callee_9 (int one, int *two, float (three)); /* { dg-line callee_9 } */
171 
test_9(int first,unsigned int * second,float third)172 int test_9 (int first, unsigned int *second, float third)
173 {
174   return callee_9 (first, second, third); /* { dg-warning "pointer targets in passing argument 2 of 'callee_9' differ in signedness" } */
175   /* { dg-begin-multiline-output "" }
176    return callee_9 (first, second, third);
177                            ^~~~~~
178                            |
179                            unsigned int *
180      { dg-end-multiline-output "" } */
181   /* { dg-message "expected 'int \\*' but argument is of type 'unsigned int \\*'" "" { target *-*-* } callee_9 } */
182   /* { dg-begin-multiline-output "" }
183  extern int callee_9 (int one, int *two, float (three));
184                                ~~~~~^~~
185      { dg-end-multiline-output "" } */
186 }
187