[C] Improve diagnostics for vector types
authorRichard Sandiford <richard.sandiford@arm.com>
Tue, 1 Oct 2019 08:56:12 +0000 (08:56 +0000)
committerRichard Sandiford <rsandifo@gcc.gnu.org>
Tue, 1 Oct 2019 08:56:12 +0000 (08:56 +0000)
commit8209db250f305cc79fd751c3ed056fb9ff551a83
tree4eb7f756c70754535630e314469467e44a31413f
parent17d184e5c4896264c27c27d125a6c1f8462d9d37
[C] Improve diagnostics for vector types

Given the following invalid arm_neon.h-based code:

  float x;
  int8x8_t y = x;

the error message we emit is pretty good:

  incompatible types when initializing type 'int8x8_t' using type 'float'

But convert the types to pointers:

  int8x8_t *ptr = &x;

and the message becomes:

  initialization of '__vector(8) signed char *' from incompatible pointer type 'float *'

Although it's reasonably obvious what '__vector(8) signed char *' means,
it isn't valid C or C++ syntax and is quite far from what the user wrote,
so using 'int8x8_t *' would be better.

This patch therefore prints the type name of vectors that have one.
It's still OK to print the __vector syntax as an "aka", although I have
a follow-on patch to tweak this slightly for types defined in system
header files.  The follow-on patch also addresses the ??? in
gcc.target/aarch64/diag_aka_1.c.

The C++ test already passed, but it seemed worth including for
consistency.

2019-10-01  Richard Sandiford  <richard.sandiford@arm.com>

gcc/c-family/
* c-pretty-print.c (pp_c_specifier_qualifier_list): If a vector type
has a type name, use it in preference to the __vector syntax.

gcc/testsuite/
* gcc.dg/diag-aka-3.c: New test.
* gcc.target/aarch64/diag_aka_1.c: New test.
* g++.dg/diagnostic/aka4.C: New test.

From-SVN: r276394
gcc/c-family/ChangeLog
gcc/c-family/c-pretty-print.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/diagnostic/aka4.C [new file with mode: 0644]
gcc/testsuite/gcc.dg/diag-aka-3.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/diag_aka_1.c [new file with mode: 0644]