| 1 |
/* PR c/83656 - missing -Wbuiltin-declaration-mismatch on declaration |
| 2 |
without prototype |
| 3 |
{ dg-do compile } |
| 4 |
{ dg-options "-std=gnu17 -Wbuiltin-declaration-mismatch" } */ |
| 5 |
|
| 6 |
typedef __PTRDIFF_TYPE__ ptrdiff_t; |
| 7 |
typedef __SIZE_TYPE__ size_t; |
| 8 |
|
| 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; |
| 18 |
|
| 19 |
size_t szi; |
| 20 |
typedef size_t SizeType; |
| 21 |
SizeType szti; |
| 22 |
|
| 23 |
ptrdiff_t diffi; |
| 24 |
|
| 25 |
enum E { e0 } e; |
| 26 |
|
| 27 |
float f; |
| 28 |
double d; |
| 29 |
long double ld; |
| 30 |
|
| 31 |
|
| 32 |
/* Verify warnings for undefined calls to built-ins expecting integer |
| 33 |
arguments. */ |
| 34 |
|
| 35 |
int abs (); /* { dg-message "built-in .abs. declared here" } */ |
| 36 |
|
| 37 |
void test_integer_conversion_abs (void) |
| 38 |
{ |
| 39 |
i = abs (c); |
| 40 |
i = abs (sc); |
| 41 |
i = abs (uc); |
| 42 |
|
| 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 } } */ |
| 45 |
|
| 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" } */ |
| 48 |
|
| 49 |
/* Verify that the same call as above but to the built-in doesn't |
| 50 |
trigger a warning. */ |
| 51 |
i = __builtin_abs (ui); |
| 52 |
|
| 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" } */ |
| 55 |
|
| 56 |
i = abs (e0); |
| 57 |
i = abs (e); |
| 58 |
|
| 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" } */ |
| 62 |
|
| 63 |
/* Verify that the same call as above but to the built-in doesn't |
| 64 |
trigger a warning. */ |
| 65 |
i = __builtin_abs (ld); |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
extern void* memset (); |
| 70 |
|
| 71 |
void test_integer_conversion_memset (void *d) |
| 72 |
{ |
| 73 |
memset (d, 0, sizeof (int)); |
| 74 |
memset (d, '\0', szi); |
| 75 |
memset (d, i, szti); |
| 76 |
|
| 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" } */ |
| 81 |
|
| 82 |
memset (d, 0, 2.0); /* { dg-warning ".memset. argument 3 type is .double. where '\(long \)*\(__int20 \)?unsigned\( int\)?' is expected" } */ |
| 83 |
|
| 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); |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
/* Verify warnings for undefined calls to built-ins expecting floating |
| 91 |
arguments. */ |
| 92 |
|
| 93 |
double fabs (); /* { dg-message "built-in .fabs. declared here" } */ |
| 94 |
|
| 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" } */ |
| 99 |
|
| 100 |
void test_real_conversion_fabs (void) |
| 101 |
{ |
| 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" } */ |
| 103 |
|
| 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" } */ |
| 105 |
|
| 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" } */ |
| 107 |
|
| 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" } */ |
| 110 |
|
| 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 } */ |
| 113 |
|
| 114 |
/* No warning here since float is promoted to double. */ |
| 115 |
d = fabs (f); |
| 116 |
|
| 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" } */ |
| 118 |
|
| 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 *-*-* } } */ |
| 120 |
|
| 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" } */ |
| 122 |
|
| 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" } */ |
| 124 |
|
| 125 |
/* Verify that the same call as above but to the built-in doesn't |
| 126 |
trigger a warning. */ |
| 127 |
d = __builtin_fabsl (f); |
| 128 |
} |
| 129 |
|
| 130 |
/* Verify warnings for calls to a two-argument real function. */ |
| 131 |
|
| 132 |
double pow (); /* { dg-message "built-in .pow. declared here" } */ |
| 133 |
|
| 134 |
void test_real_conversion_pow (void) |
| 135 |
{ |
| 136 |
d = pow (2.0, 2.0); |
| 137 |
d = pow (d, 3.0); |
| 138 |
d = pow (d, d); |
| 139 |
|
| 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" } */ |
| 142 |
} |
| 143 |
|
| 144 |
|
| 145 |
/* Verify warnings for calls that discard qualifiers. */ |
| 146 |
|
| 147 |
extern void* memcpy (); |
| 148 |
|
| 149 |
void test_qual_conversion_memcpy (void *d, const void *s) |
| 150 |
{ |
| 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" } */ |
| 153 |
} |