[Bug c/97702] comma operator does not drop qualifiers during lvalue conversion
joseph at codesourcery dot com
gcc-bugzilla@gcc.gnu.org
Tue Nov 3 18:16:43 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97702
--- Comment #1 from joseph at codesourcery dot com <joseph at codesourcery dot com> ---
The C front end doesn't have any kind of general lvalue-to-rvalue
conversion in the IR (other than for atomic lvalues where the code
required for such a conversion is more than a simple load, as handled by
convert_lvalue_to_rvalue) that tries to drop qualifiers; the DECL node is
used directly to represent a load of a variable, even when the rvalue
would have the unqualified type. The circumstances in which typeof
produces a qualified result type are underspecified. When a C standard
construct uses a type in a way that cares about qualifiers not being
present on rvalues (which I think only applies to _Generic), the removal
is handled at that point; see this code from c_parser_generic_selection:
selector = default_function_array_conversion (selector_loc, selector);
[...]
selector_type = TREE_TYPE (selector.value);
/* In ISO C terms, rvalues (including the controlling expression of
_Generic) do not have qualified types. */
if (TREE_CODE (selector_type) != ARRAY_TYPE)
selector_type = TYPE_MAIN_VARIANT (selector_type);
/* In ISO C terms, _Noreturn is not part of the type of expressions
such as &abort, but in GCC it is represented internally as a type
qualifier. */
if (FUNCTION_POINTER_TYPE_P (selector_type)
&& TYPE_QUALS (TREE_TYPE (selector_type)) != TYPE_UNQUALIFIED)
selector_type
= build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type)));
That said, the resolution of bug 45584 means casts always produce a result
with explicitly unqualified type (including casts to a qualified type, see
gcc.dg/pr13519-1.c). It would seem reasonable to do the same for the
comma operator. There will be other places as well that do not remove
qualifiers when constructing the internal representation for rvalues and
would need adjusting to make the constness of the IR more consistent.
One example is applying unary '+' to a const int variable; combine that
with typeof and it shows the result to be const at present.
More information about the Gcc-bugs
mailing list