annotate clang/test/Sema/warn-bad-function-cast.c @ 207:2e18cbf3894f

LLVM12
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 08 Jun 2021 06:07:14 +0900
parents 1d019706d866
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1 // RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wbad-function-cast -ffixed-point -triple x86_64-unknown-unknown -verify
150
anatofuz
parents:
diff changeset
2 // rdar://9103192
anatofuz
parents:
diff changeset
3
anatofuz
parents:
diff changeset
4 void vf(void);
anatofuz
parents:
diff changeset
5 int if1(void);
anatofuz
parents:
diff changeset
6 char if2(void);
anatofuz
parents:
diff changeset
7 long if3(void);
anatofuz
parents:
diff changeset
8 float rf1(void);
anatofuz
parents:
diff changeset
9 double rf2(void);
anatofuz
parents:
diff changeset
10 _Complex double cf(void);
anatofuz
parents:
diff changeset
11 enum e { E1 } ef(void);
anatofuz
parents:
diff changeset
12 _Bool bf(void);
anatofuz
parents:
diff changeset
13 char *pf1(void);
anatofuz
parents:
diff changeset
14 int *pf2(void);
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
15 _Fract ff1(void);
150
anatofuz
parents:
diff changeset
16
anatofuz
parents:
diff changeset
17 void
anatofuz
parents:
diff changeset
18 foo(void)
anatofuz
parents:
diff changeset
19 {
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
20
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
21 /* default, no cast, should always be ok */
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
22 ff1();
150
anatofuz
parents:
diff changeset
23 /* Casts to void types are always OK. */
anatofuz
parents:
diff changeset
24 (void)vf();
anatofuz
parents:
diff changeset
25 (void)if1();
anatofuz
parents:
diff changeset
26 (void)cf();
anatofuz
parents:
diff changeset
27 (const void)bf();
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
28 (void)ff1();
150
anatofuz
parents:
diff changeset
29 /* Casts to the same type or similar types are OK. */
anatofuz
parents:
diff changeset
30 (int)if1();
anatofuz
parents:
diff changeset
31 (long)if2();
anatofuz
parents:
diff changeset
32 (char)if3();
anatofuz
parents:
diff changeset
33 (float)rf1();
anatofuz
parents:
diff changeset
34 (long double)rf2();
anatofuz
parents:
diff changeset
35 (_Complex float)cf();
anatofuz
parents:
diff changeset
36 (enum f { F1 })ef();
anatofuz
parents:
diff changeset
37 (_Bool)bf();
anatofuz
parents:
diff changeset
38 (void *)pf1();
anatofuz
parents:
diff changeset
39 (char *)pf2();
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
40 (_Fract) ff1();
150
anatofuz
parents:
diff changeset
41 /* All following casts issue warning */
anatofuz
parents:
diff changeset
42 (float)if1(); /* expected-warning {{cast from function call of type 'int' to non-matching type 'float'}} */
anatofuz
parents:
diff changeset
43 (double)if2(); /* expected-warning {{cast from function call of type 'char' to non-matching type 'double'}} */
anatofuz
parents:
diff changeset
44 (_Bool)if3(); /* expected-warning {{cast from function call of type 'long' to non-matching type '_Bool'}} */
anatofuz
parents:
diff changeset
45 (int)rf1(); /* expected-warning {{cast from function call of type 'float' to non-matching type 'int'}} */
anatofuz
parents:
diff changeset
46 (long)rf2(); /* expected-warning {{cast from function call of type 'double' to non-matching type 'long'}} */
anatofuz
parents:
diff changeset
47 (double)cf(); /* expected-warning {{cast from function call of type '_Complex double' to non-matching type 'double'}} */
anatofuz
parents:
diff changeset
48 (int)ef(); /* expected-warning {{cast from function call of type 'enum e' to non-matching type 'int'}} */
anatofuz
parents:
diff changeset
49 (int)bf(); /* expected-warning {{cast from function call of type '_Bool' to non-matching type 'int'}} */
anatofuz
parents:
diff changeset
50 (__SIZE_TYPE__)pf1(); /* expected-warning {{cast from function call of type 'char *' to non-matching type 'unsigned long'}} */
anatofuz
parents:
diff changeset
51 (__PTRDIFF_TYPE__)pf2(); /* expected-warning {{cast from function call of type 'int *' to non-matching type 'long'}} */
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
52 (_Fract) if1(); /* expected-warning{{cast from function call of type 'int' to non-matching type '_Fract'}} */
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
53 (int)ff1(); /* expected-warning{{cast from function call of type '_Fract' to non-matching type 'int'}} */
150
anatofuz
parents:
diff changeset
54 }
anatofuz
parents:
diff changeset
55