Skip analyzer strndup test on hppa*-*-hpux*
[official-gcc.git] / gcc / testsuite / gcc.dg / Wbuiltin-declaration-mismatch-4.c
blobe845b43c0736bf16774dabec484a3e9f5ac102ae
1 /* PR c/83656 - missing -Wbuiltin-declaration-mismatch on declaration
2 without prototype
3 { dg-do compile }
4 { dg-options "-Wbuiltin-declaration-mismatch" } */
6 typedef __PTRDIFF_TYPE__ ptrdiff_t;
7 typedef __SIZE_TYPE__ size_t;
9 char c;
10 signed char sc;
11 unsigned char uc;
12 short si;
13 unsigned short usi;
14 int i;
15 unsigned ui;
16 long li;
17 unsigned long uli;
19 size_t szi;
20 typedef size_t SizeType;
21 SizeType szti;
23 ptrdiff_t diffi;
25 enum E { e0 } e;
27 float f;
28 double d;
29 long double ld;
32 /* Verify warnings for undefined calls to built-ins expecting integer
33 arguments. */
35 int abs (); /* { dg-message "built-in .abs. declared here" } */
37 void test_integer_conversion_abs (void)
39 i = abs (c);
40 i = abs (sc);
41 i = abs (uc);
43 i = abs (si);
44 i = abs (usi); /* { dg-warning ".abs. argument 1 promotes to .unsigned int. where .int. is expected in a call to built-in function declared without prototype" "" { target short_eq_int } } */
46 i = abs (i);
47 i = abs (ui); /* { dg-warning ".abs. argument 1 type is .unsigned int. where .int. is expected in a call to built-in function declared without prototype" } */
49 /* Verify that the same call as above but to the built-in doesn't
50 trigger a warning. */
51 i = __builtin_abs (ui);
53 i = abs (li); /* { dg-warning ".abs. argument 1 type is .long int. where .int. is expected in a call to built-in function declared without prototype" } */
54 i = abs (uli); /* { dg-warning ".abs. argument 1 type is .long unsigned int. where .int. is expected in a call to built-in function declared without prototype" } */
56 i = abs (e0);
57 i = abs (e);
59 i = abs (-1.0); /* { dg-warning ".abs. argument 1 type is .double. where .int. is expected in a call to built-in function declared without prototype" } */
60 i = abs (f); /* { dg-warning ".abs. argument 1 promotes to .double. where .int. is expected in a call to built-in function declared without prototype" } */
61 i = abs (ld); /* { dg-warning ".abs. argument 1 type is .long double. where .int. is expected in a call to built-in function declared without prototype" } */
63 /* Verify that the same call as above but to the built-in doesn't
64 trigger a warning. */
65 i = __builtin_abs (ld);
69 extern void* memset ();
71 void test_integer_conversion_memset (void *d)
73 memset (d, 0, sizeof (int));
74 memset (d, '\0', szi);
75 memset (d, i, szti);
77 /* Passing a ptrdiff_t where size_t is expected may not be unsafe
78 but because GCC may emits suboptimal code for such calls warning
79 for them helps improve efficiency. */
80 memset (d, 0, diffi); /* { dg-warning ".memset. argument 3 promotes to .ptrdiff_t. {aka .\(long \)?\(int\)?\(__int20\)?.} where .\(long \)?\(__int20 \)?unsigned\( int\)?. is expected" } */
82 memset (d, 0, 2.0); /* { dg-warning ".memset. argument 3 type is .double. where '\(long \)?\(__int20 \)?unsigned\( int\)?' is expected" } */
84 /* Verify that the same call as above but to the built-in doesn't
85 trigger a warning. */
86 __builtin_memset (d, 0.0, 4.0);
90 /* Verify warnings for undefined calls to built-ins expecting floating
91 arguments. */
93 double fabs (); /* { dg-message "built-in .fabs. declared here" } */
95 /* Expect a warning for fabsf below because even a float argument promotes
96 to double. Unfortunately, invalid calls to fabsf() are not diagnosed. */
97 float fabsf (); /* { dg-warning "conflicting types for built-in function .fabsf.; expected .float\\\(float\\\)." } */
98 long double fabsl (); /* { dg-message "built-in .fabsl. declared here" } */
100 void test_real_conversion_fabs (void)
102 d = fabs (c); /* { dg-warning ".fabs. argument 1 promotes to .int. where .double. is expected in a call to built-in function declared without prototype" } */
104 d = fabs (i); /* { dg-warning ".fabs. argument 1 type is .int. where .double. is expected in a call to built-in function declared without prototype" } */
106 d = fabs (li); /* { dg-warning ".fabs. argument 1 type is .long int. where .double. is expected in a call to built-in function declared without prototype" } */
108 /* In C, the type of an enumeration constant is int. */
109 d = fabs (e0); /* { dg-warning ".fabs. argument 1 type is .int. where .double. is expected in a call to built-in function declared without prototype" } */
111 d = fabs (e); /* { dg-warning ".fabs. argument 1 type is .enum E. where .double. is expected in a call to built-in function declared without prototype" "ordinary enum" { target { ! short_enums } } } */
112 /* { dg-warning ".fabs. argument 1 promotes to .int. where .double. is expected in a call to built-in function declared without prototype" "size 1 enum" { target short_enums } .-1 } */
114 /* No warning here since float is promoted to double. */
115 d = fabs (f);
117 d = fabs (ld); /* { dg-warning ".fabs. argument 1 type is .long double. where .double. is expected in a call to built-in function declared without prototype" } */
119 d = fabsf (c); /* { dg-warning ".fabsf. argument 1 promotes to .int. where .float. is expected in a call to built-in function declared without prototype" "pr87890" { xfail *-*-* } } */
121 d = fabsl (c); /* { dg-warning ".fabsl. argument 1 promotes to .int. where .long double. is expected in a call to built-in function declared without prototype" } */
123 d = fabsl (f); /* { dg-warning ".fabsl. argument 1 promotes to .double. where .long double. is expected in a call to built-in function declared without prototype" } */
125 /* Verify that the same call as above but to the built-in doesn't
126 trigger a warning. */
127 d = __builtin_fabsl (f);
130 /* Verify warnings for calls to a two-argument real function. */
132 double pow (); /* { dg-message "built-in .pow. declared here" } */
134 void test_real_conversion_pow (void)
136 d = pow (2.0, 2.0);
137 d = pow (d, 3.0);
138 d = pow (d, d);
140 d = pow (2, 3.0); /* { dg-warning ".pow. argument 1 type is .int. where .double. is expected in a call to built-in function declared without prototype" } */
141 d = pow (3.0, 2); /* { dg-warning ".pow. argument 2 type is .int. where .double. is expected in a call to built-in function declared without prototype" } */
145 /* Verify warnings for calls that discard qualifiers. */
147 extern void* memcpy ();
149 void test_qual_conversion_memcpy (void *d, const void *s)
151 memcpy (d, s, sizeof (int));
152 memcpy (s, d, sizeof (int)); /* { dg-warning "passing argument 1 of .memcpy. discards 'const' qualifier from pointer target type" } */