1 /* PR c/83656 - missing -Wbuiltin-declaration-mismatch on declaration
4 { dg-options "-Wbuiltin-declaration-mismatch" } */
6 typedef __PTRDIFF_TYPE__
ptrdiff_t;
7 typedef __SIZE_TYPE__
size_t;
20 typedef size_t SizeType
;
32 /* Verify warnings for undefined calls to built-ins expecting integer
35 int abs (); /* { dg-message "built-in .abs. declared here" } */
37 void test_integer_conversion_abs (void)
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 } } */
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
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" } */
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
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
);
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
86 __builtin_memset (d
, 0.0, 4.0);
90 /* Verify warnings for undefined calls to built-ins expecting floating
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. */
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)
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" } */