On 4/14/2021 9:32 AM, Richard Sandiford via Gcc-patches wrote:
<arm_neon.h> types are distinct from GNU vector types in at least
their mangling.  However, there used to be nothing explicit in the
VECTOR_TYPE itself to indicate the difference: we simply treated them
as distinct TYPE_MAIN_VARIANTs.  This caused problems like the ones
reported in PR95726.

The fix for that PR was to add type attributes to the <arm_neon.h>
types, in order to maintain the distinction between them and GNU
vectors.  However, this in turn caused PR98852, where c_common_type
would unconditionally drop the attributes on the source types.
This meant that:

    <arm_neon.h> vector + <arm_neon.h> vector

had a GNU vector type rather than an <arm_neon.h> vector type.

See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96377#c2 for
Jakub's analysis of the history of this c_common_type code.
TBH I'm not sure which case the build_type_attribute_variant
code is handling, but I think we should at least avoid dropping
attributes that affect type identity.

I've tried to audit the C and target-specific attributes to look
for other types that might be affected by this, but I couldn't
see any.  We are only dealing with:

   gcc_assert (code1 == VECTOR_TYPE || code1 == COMPLEX_TYPE
              || code1 == FIXED_POINT_TYPE || code1 == REAL_TYPE
              || code1 == INTEGER_TYPE);

which excludes most affects_type_identity attributes.  The closest
was s390_vector_bool, but the handler for that attribute changes
the type node and drops the attribute itself (*no_add_attrs = true).

I put the main list handling into a separate function
(remove_attributes_matching) because a later patch will need it
for something else.

Tested on aarch64-linux-gnu, arm-linux-gnueabihf, armeb-eabi and
x86_64-linux-gnu.  OK for trunk?  The bug also occurs on GCC 10 branch,
but we'll need a slightly different fix there.

Thanks,
Richard


gcc/
        PR c/98852
        * attribs.h (affects_type_identity_attributes): Declare.
        * attribs.c (remove_attributes_matching): New function.
        (affects_type_identity_attributes): Likewise.

gcc/c/
        PR c/98852
        * c-typeck.c (c_common_type): Do not drop attributes that
        affect type identity.

gcc/testsuite/
        PR c/98852
        * gcc.target/aarch64/advsimd-intrinsics/pr98852.c: New test.

OK


Jeff

Reply via email to