Bug 100270 - [10 Backport] _Generic can't distinguish VLS SVE vectors and GNU vectors
Summary: [10 Backport] _Generic can't distinguish VLS SVE vectors and GNU vectors
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 10.3.1
: P3 normal
Target Milestone: 11.2
Assignee: Richard Sandiford
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2021-04-26 15:33 UTC by Richard Sandiford
Modified: 2023-07-07 09:38 UTC (History)
0 users

See Also:
Host:
Target: aarch64*-*-*
Build:
Known to work:
Known to fail: 10.5.0
Last reconfirmed: 2021-04-26 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Sandiford 2021-04-26 15:33:02 UTC
Compiling the following test with -march=armv8.2-a+sve -msve-vector-bits=256:

---------------------------------------------------------------------------
#include <arm_sve.h>

typedef svint32_t vls_svint32_t __attribute__((arm_sve_vector_bits(256)));
typedef int32_t gnu_svint32_t __attribute__((vector_size(32)));

int
f (vls_svint32_t x)
{
  return _Generic(x, vls_svint32_t: 1, gnu_svint32_t: 2, default: -1);
}
---------------------------------------------------------------------------

gives:

a.c: In function ‘f’:
a.c:9:40: error: ‘_Generic’ specifies two compatible types
    9 |   return _Generic(x, vls_svint32_t: 1, gnu_svint32_t: 2, default: -1);
      |                                        ^~~~~~~~~~~~~
a.c:9:22: note: compatible type is here
    9 |   return _Generic(x, vls_svint32_t: 1, gnu_svint32_t: 2, default: -1);
      |                      ^~~~~~~~~~~~~
a.c:9:40: error: ‘_Generic’ selector matches multiple associations
    9 |   return _Generic(x, vls_svint32_t: 1, gnu_svint32_t: 2, default: -1);
      |                                        ^~~~~~~~~~~~~
a.c:9:22: note: other match is here
    9 |   return _Generic(x, vls_svint32_t: 1, gnu_svint32_t: 2, default: -1);
      |                      ^~~~~~~~~~~~~

This is because aarch64_comp_type_attributes needs to return
false for this combination of types.
Comment 1 Richard Sandiford 2021-04-26 15:33:25 UTC
Working on a patch.
Comment 2 GCC Commits 2021-04-27 11:18:25 UTC
The master branch has been updated by Richard Sandiford <rsandifo@gcc.gnu.org>:

https://gcc.gnu.org/g:4cea5b8cb715e40e10174e6de405f26202fa3d6a

commit r12-147-g4cea5b8cb715e40e10174e6de405f26202fa3d6a
Author: Richard Sandiford <richard.sandiford@arm.com>
Date:   Tue Apr 27 12:18:03 2021 +0100

    aarch64: Handle SVE attributes in comp_type_attributes [PR100270]
    
    Even though "SVE type" and "SVE sizeless type" are marked as
    affecting type identity, the middle end doesn't truly believe
    it unless we also handle them in comp_type_attributes.
    
    gcc/
            PR target/100270
            * config/aarch64/aarch64.c (aarch64_comp_type_attributes): Handle
            SVE attributes.
    
    gcc/testsuite/
            PR target/100270
            * gcc.target/aarch64/sve/acle/general-c/pr100270_1.c: New test.
            * gcc.target/aarch64/sve/acle/general-c/sizeless-2.c: Change
            expected error message when subtracting pointers to different
            vector types.  Expect warnings when mixing them elsewhere.
            * gcc.target/aarch64/sve/acle/general/attributes_7.c: Remove
            XFAILs.  Tweak error messages for some cases.
Comment 3 GCC Commits 2021-04-29 08:28:12 UTC
The releases/gcc-11 branch has been updated by Richard Sandiford <rsandifo@gcc.gnu.org>:

https://gcc.gnu.org/g:dfaa29b5441689ce05e3c09012d3afe269770e94

commit r11-8322-gdfaa29b5441689ce05e3c09012d3afe269770e94
Author: Richard Sandiford <richard.sandiford@arm.com>
Date:   Thu Apr 29 09:27:51 2021 +0100

    aarch64: Handle SVE attributes in comp_type_attributes [PR100270]
    
    Even though "SVE type" and "SVE sizeless type" are marked as
    affecting type identity, the middle end doesn't truly believe
    it unless we also handle them in comp_type_attributes.
    
    gcc/
            PR target/100270
            * config/aarch64/aarch64.c (aarch64_comp_type_attributes): Handle
            SVE attributes.
    
    gcc/testsuite/
            PR target/100270
            * gcc.target/aarch64/sve/acle/general-c/pr100270_1.c: New test.
            * gcc.target/aarch64/sve/acle/general-c/sizeless-2.c: Change
            expected error message when subtracting pointers to different
            vector types.  Expect warnings when mixing them elsewhere.
            * gcc.target/aarch64/sve/acle/general/attributes_7.c: Remove
            XFAILs.  Tweak error messages for some cases.
    
    (cherry picked from commit 4cea5b8cb715e40e10174e6de405f26202fa3d6a)
Comment 4 Jakub Jelinek 2022-06-28 10:44:42 UTC
GCC 10.4 is being released, retargeting bugs to GCC 10.5.
Comment 5 Richard Biener 2023-07-07 09:38:42 UTC
Fixed in GCC 11.