Dear TCC developers,
Earlier this month I posted about two bugs that I had found while
prototyping support for the _Optional qualifier in TCC:
- the operands of conditional expressions involving pointers to
differently-qualified array types were not recognized by TCC as
compatible, and
- when determining the result type of the ternary operator, TCC
combined only qualifiers stored on the outer array nodes.
Since no objections (or replies) were received on the mailing list, I
have since pushed fixes for those bugs to the mob branch.
I'd now like to fix another type-related bug: TCC wrongly discards the
const and volatile qualifiers from parameter types when adjusting
them. This is trivial to demonstrate using an example such as the
following:
void foo(int const c)
{
c = 0; // constraint violation
}
Of GCC, Clang, SDCC and TCC, only TCC fails to diagnose the constraint
violation: see https://godbolt.org/z/n64nPEPaT
The same bug can also be observed in the case of a volatile-qualified
parameter when _Generic is used to inspect its adjusted type.
I propose to push a fix for this bug, along with regression tests, to
mob shortly:
- convert_parameter_type() will no longer remove the const and
volatile qualifiers from a CType.
- a new function, convert_expression_type(), will remove the const and
volatile qualifiers before tail-calling convert_parameter_type().
- unary() and gexpr() will call convert_expression_type() instead of
convert_parameter_type() to ensure that expression semantics are
unchanged.
To ensure that qualifiers within an array-style parameter declaration
(e.g. int [const 2] are also handled correctly, post_type() also needs
to be modified to collect qualifiers and OR them into the t member of
CType. I'll probably push that as a separate commit.
(In case anyone is wondering about 'restrict', I have a later patch
that defines an alias for all three standard qualifiers such that they
are always treated consistently, as they should be.)
Best regards,
Christopher
_______________________________________________
Tinycc-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel