c: Fix bogus vector initialisation error [PR96377]
authorRichard Sandiford <richard.sandiford@arm.com>
Sat, 1 Aug 2020 11:41:28 +0000 (12:41 +0100)
committerRichard Sandiford <richard.sandiford@arm.com>
Sat, 1 Aug 2020 11:41:28 +0000 (12:41 +0100)
commit7d599ad27b9bcf5165f87710f1abc64bbabd06ae
tree78482380b2a17a1775290b757897bdf39bbbbaef
parent197f1e8c14306fc97ff91f9fb4262e70f45eedef
c: Fix bogus vector initialisation error [PR96377]

One of the problems in this PR was that if we had:

  vector_type1 array[] = { vector_value1 };

process_init_element would only treat vector_value1 as initialising
a vector_type1 if they had the same TYPE_MAIN_VARIANT.  This has
several problems:

(1) It gives confusing error messages if the vector types are
    incompatible.  (Tested by gcc.dg/pr96377-1.c.)

(2) It means that we reject code that should be valid with
    -flax-vector-conversions.  (Tested by gcc.dg/pr96377-2.c.)

(3) On arm and aarch64 targets, it means that we reject some
    initializers that mix Advanced SIMD and standard GNU vectors.
    These vectors have traditionally had different TYPE_MAIN_VARIANTs
    because they have different mangling schemes.  (Tested by
    gcc.dg/pr96377-[3-6].c.)

(4) It means that we reject SVE initializers that should be valid.
    (Tested by gcc.target/aarch64/sve/gnu_vectors_[34].c.)

(5) After r11-1741-g:31427b974ed7b7dd54e2 we reject:

      arm_neon_type1 array[] = { k ^ arm_neon_value1 };

    because applying the binary operator to arm_neon_value1 strips
    the "Advanced SIMD type" attributes that were added in that patch.
    Stripping the attributes is problematic for other reasons though,
    so that still needs to be fixed separately.

g++.target/aarch64/sve/gnu_vectors_[34].C already pass.

gcc/c/
PR c/96377
* c-typeck.c (process_init_element): Split test for whether to
recurse into a record, union or array into...
(initialize_elementwise_p): ...this new function.  Don't recurse
into a vector type if the initialization value is also a vector.

gcc/testsuite/
PR c/96377
* gcc.dg/pr96377-1.c: New test.
* gcc.dg/pr96377-2.c: Likewise.
* gcc.dg/pr96377-3.c: Likewise.
* gcc.dg/pr96377-4.c: Likewise.
* gcc.dg/pr96377-5.c: Likewise.
* gcc.dg/pr96377-6.c: Likewise.
* gcc.target/aarch64/pr96377-1.c: Likewise.
* gcc.target/aarch64/sve/acle/general-c/gnu_vectors_3.c: Likewise.
* gcc.target/aarch64/sve/acle/general-c/gnu_vectors_4.c: Likewise.
* g++.target/aarch64/sve/acle/general-c++/gnu_vectors_3.C: Likewise.
* g++.target/aarch64/sve/acle/general-c++/gnu_vectors_4.C: Likewise.
12 files changed:
gcc/c/c-typeck.c
gcc/testsuite/g++.target/aarch64/sve/acle/general-c++/gnu_vectors_3.C [new file with mode: 0644]
gcc/testsuite/g++.target/aarch64/sve/acle/general-c++/gnu_vectors_4.C [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr96377-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr96377-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr96377-3.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr96377-4.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr96377-5.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr96377-6.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/pr96377-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/gnu_vectors_3.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/gnu_vectors_4.c [new file with mode: 0644]