mirror of
git://repo.or.cz/tinycc.git
synced 2026-11-04 21:26:36 +08:00
tccgen: Remove volatile qualifier from function return types
Modify post_type() such that the volatile qualifier is removed from function return types, as required by ISO C. Previously, only the const qualifier was removed. Added tests for all three standard qualifiers, although the new test for restrict only passes because TCC ignores that keyword.
This commit is contained in:
parent
1f214e1390
commit
48f54e5969
6
tccgen.c
6
tccgen.c
@ -5119,9 +5119,9 @@ static int post_type(CType *type, AttributeDef *ad, int storage, int td)
|
||||
/* if no parameters, then old type prototype */
|
||||
l = FUNC_OLD;
|
||||
skip(')');
|
||||
/* NOTE: const is ignored in returned type as it has a special
|
||||
meaning in gcc / C++ */
|
||||
type->t &= ~VT_CONSTANT;
|
||||
/* A function return value has the unqualified version of its
|
||||
declared type. */
|
||||
type->t &= ~(VT_CONSTANT | VT_VOLATILE);
|
||||
/* some ancient pre-K&R C allows a function to return an array
|
||||
and the array brackets to be put after the arguments, such
|
||||
that "int c()[]" means something like "int[] c()" */
|
||||
|
||||
30
tests/tests2/150_return_qualifiers.c
Normal file
30
tests/tests2/150_return_qualifiers.c
Normal file
@ -0,0 +1,30 @@
|
||||
const int const_return(void);
|
||||
volatile int volatile_return(void);
|
||||
int *restrict restrict_return(void);
|
||||
|
||||
_Static_assert(__builtin_types_compatible_p(__typeof__(const_return()) *, int *),
|
||||
"const is removed from a return type");
|
||||
_Static_assert(__builtin_types_compatible_p(__typeof__(volatile_return()) *, int *),
|
||||
"volatile is removed from a return type");
|
||||
_Static_assert(__builtin_types_compatible_p(__typeof__(restrict_return()) *, int **),
|
||||
"restrict is removed from a return type");
|
||||
|
||||
int const_return(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int volatile_return(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int *restrict_return(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
0
tests/tests2/150_return_qualifiers.expect
Normal file
0
tests/tests2/150_return_qualifiers.expect
Normal file
Loading…
Reference in New Issue
Block a user