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:
Christopher Bazley 2026-09-26 12:42:40 +01:00
parent 1f214e1390
commit 48f54e5969
3 changed files with 33 additions and 3 deletions

View File

@ -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()" */

View 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;
}