From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 99462 invoked by alias); 30 Sep 2019 13:05:53 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 99448 invoked by uid 89); 30 Sep 2019 13:05:52 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-9.0 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_2,GIT_PATCH_3,KAM_ASCII_DIVIDERS,SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: foss.arm.com Received: from foss.arm.com (HELO foss.arm.com) (217.140.110.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 30 Sep 2019 13:05:50 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7DA5C1570; Mon, 30 Sep 2019 06:05:49 -0700 (PDT) Received: from localhost (e121540-lin.manchester.arm.com [10.32.98.126]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A85A93F706; Mon, 30 Sep 2019 06:05:48 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org,dodji@redhat.com, dmalcolm@redhat.com, joseph@codesourcery.com, polacek@redhat.com, richard.sandiford@arm.com Cc: dodji@redhat.com, dmalcolm@redhat.com, joseph@codesourcery.com, polacek@redhat.com Subject: [C] Improve diagnostics for vector types Date: Mon, 30 Sep 2019 13:05:00 -0000 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-IsSubscribed: yes X-SW-Source: 2019-09/txt/msg01752.txt.bz2 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. Tested on aarch64-linux-gnu and x86_64-linux-gnu. OK to install? Richard 2019-09-30 Richard Sandiford 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. Index: gcc/c-family/c-pretty-print.c =================================================================== --- gcc/c-family/c-pretty-print.c 2019-09-30 13:54:18.387750214 +0100 +++ gcc/c-family/c-pretty-print.c 2019-09-30 14:01:05.904830151 +0100 @@ -470,6 +470,16 @@ pp_c_specifier_qualifier_list (c_pretty_ ? "_Complex" : "__complex__")); else if (code == VECTOR_TYPE) { + /* The syntax we print for vector types isn't real C or C++ syntax, + so it's better to print the type name if we have one. */ + tree name = TYPE_NAME (t); + if (!(pp->flags & pp_c_flag_gnu_v3) + && name + && TREE_CODE (name) == TYPE_DECL) + { + pp->id_expression (name); + break; + } pp_c_ws_string (pp, "__vector"); pp_c_left_paren (pp); pp_wide_integer (pp, TYPE_VECTOR_SUBPARTS (t)); Index: gcc/testsuite/gcc.dg/diag-aka-3.c =================================================================== --- /dev/null 2019-09-17 11:41:18.176664108 +0100 +++ gcc/testsuite/gcc.dg/diag-aka-3.c 2019-09-30 14:01:05.904830151 +0100 @@ -0,0 +1,9 @@ +typedef unsigned int myvec __attribute__((vector_size (16))); + +void f (float x) +{ + myvec y = x; /* { dg-error {incompatible types when initializing type 'myvec' {aka '__vector\([48]\) unsigned int'} using type 'float'} } */ + myvec *ptr = &x; /* { dg-error {initialization of 'myvec \*' {aka '__vector\([48]\) unsigned int \*'} from incompatible pointer type 'float \*'} } */ + const myvec *const_ptr = &x; /* { dg-error {initialization of 'const myvec \*' {aka 'const __vector\([48]\) unsigned int \*'} from incompatible pointer type 'float \*'} } */ + volatile myvec *volatile_ptr = &x; /* { dg-error {initialization of 'volatile myvec \*' {aka 'volatile __vector\([48]\) unsigned int \*'} from incompatible pointer type 'float \*'} } */ +} Index: gcc/testsuite/gcc.target/aarch64/diag_aka_1.c =================================================================== --- /dev/null 2019-09-17 11:41:18.176664108 +0100 +++ gcc/testsuite/gcc.target/aarch64/diag_aka_1.c 2019-09-30 14:01:05.908830119 +0100 @@ -0,0 +1,14 @@ +#include + +typedef int16x4_t myvec; + +void f (float x) +{ + __Int8x8_t y1 = x; /* { dg-error {incompatible types when initializing type '__Int8x8_t' using type 'float'} } */ + __Int8x8_t *ptr1 = &x; /* { dg-error {initialization of '__Int8x8_t \*' from incompatible pointer type 'float \*'} } */ + int8x8_t y2 = x; /* { dg-error {incompatible types when initializing type 'int8x8_t' using type 'float'} } */ + int8x8_t *ptr2 = &x; /* { dg-error {initialization of 'int8x8_t \*' from incompatible pointer type 'float \*'} } */ + /* ??? For these it would be better to print an aka for 'int16x4_t'. */ + myvec y3 = x; /* { dg-error {incompatible types when initializing type 'myvec' using type 'float'} } */ + myvec *ptr3 = &x; /* { dg-error {initialization of 'myvec \*' from incompatible pointer type 'float \*'} } */ +} Index: gcc/testsuite/g++.dg/diagnostic/aka4.C =================================================================== --- /dev/null 2019-09-17 11:41:18.176664108 +0100 +++ gcc/testsuite/g++.dg/diagnostic/aka4.C 2019-09-30 14:01:05.904830151 +0100 @@ -0,0 +1,9 @@ +typedef unsigned int myvec __attribute__((vector_size (16))); + +void f (float x) +{ + myvec y = x; // { dg-error {cannot convert 'float' to 'myvec' {aka '__vector\([48]\) unsigned int'} in initialization} } + myvec *ptr = &x; // { dg-error {cannot convert 'float\*' to 'myvec\*' {aka '__vector\([48]\) unsigned int\*'} in initialization} } + const myvec *const_ptr = &x; // { dg-error {cannot convert 'float\*' to 'const myvec\*' {aka 'const __vector\([48]\) unsigned int\*'} in initialization} } + volatile myvec *volatile_ptr = &x; // { dg-error {cannot convert 'float\*' to 'volatile myvec\*' {aka 'volatile __vector\([48]\) unsigned int\*'} in initialization} } +}