From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 120459 invoked by alias); 15 Jul 2016 13:04:30 -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 120447 invoked by uid 89); 15 Jul 2016 13:04:30 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=BAYES_00,KAM_ASCII_DIVIDERS,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=UD:decl.c, declc, decl.c, surrounding X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 15 Jul 2016 13:04:28 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 23F1675F02; Fri, 15 Jul 2016 13:04:27 +0000 (UTC) Received: from localhost.localdomain (vpn1-7-10.ams2.redhat.com [10.36.7.10]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u6FD4O16021089; Fri, 15 Jul 2016 09:04:25 -0400 Subject: Re: C, C++: Fix PR 69733 (bad location for ignored qualifiers warning) To: Jeff Law , Joseph Myers References: <571A2697.4050208@t-online.de> <572A128B.4060800@redhat.com> <5493b5ce-7956-9619-0329-06cc30c81f25@redhat.com> Cc: GCC Patches , Jason Merrill From: Bernd Schmidt Message-ID: Date: Fri, 15 Jul 2016 13:04:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.0 MIME-Version: 1.0 In-Reply-To: <5493b5ce-7956-9619-0329-06cc30c81f25@redhat.com> Content-Type: multipart/mixed; boundary="------------E841AAB6A33827A89014702D" X-IsSubscribed: yes X-SW-Source: 2016-07/txt/msg00935.txt.bz2 This is a multi-part message in MIME format. --------------E841AAB6A33827A89014702D Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Content-length: 437 On 06/22/2016 05:37 AM, Jeff Law wrote: > It looks like this stalled... > > Anyway, it's fine for the trunk. Some of the surrounding code was changed a bit to produce different errors for different C standards, so I had to make an adjustment to the patch. While I was here, I added cdw_atomic to the list of qualifiers to look for, and added a C-specific testcase for that case. Retested as before. Ok for this version too? Bernd --------------E841AAB6A33827A89014702D Content-Type: text/x-patch; name="declspecs-v3.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="declspecs-v3.diff" Content-length: 6311 c/ PR c++/69733 * c-decl.c (smallest_type_quals_location): New static function. (grokdeclarator): Try to find the correct location for an ignored qualifier. cp/ PR c++/69733 * decl.c (grokdeclarator): Try to find the correct location for an ignored qualifier. testsuite/ PR c++/69733 * c-c++-common/pr69733.c: New test. * gcc.dg/pr69733.c: New test. * gcc.target/i386/pr69733.c: New test. Index: gcc/c/c-decl.c =================================================================== --- gcc/c/c-decl.c (revision 238040) +++ gcc/c/c-decl.c (working copy) @@ -5463,6 +5463,27 @@ warn_defaults_to (location_t location, i va_end (ap); } +/* Returns the smallest location != UNKNOWN_LOCATION in LOCATIONS, + considering only those c_declspec_words found in LIST, which + must be terminated by cdw_number_of_elements. */ + +static location_t +smallest_type_quals_location (const location_t *locations, + const c_declspec_word *list) +{ + location_t loc = UNKNOWN_LOCATION; + while (*list != cdw_number_of_elements) + { + location_t newloc = locations[*list]; + if (loc == UNKNOWN_LOCATION + || (newloc != UNKNOWN_LOCATION && newloc < loc)) + loc = newloc; + list++; + } + + return loc; +} + /* Given declspecs and a declarator, determine the name and type of the object declared and construct a ..._DECL node for it. @@ -6277,7 +6298,19 @@ grokdeclarator (const struct c_declarato qualify the return type, not the function type. */ if (type_quals) { - int quals_used = type_quals; + const enum c_declspec_word ignored_quals_list[] = + { + cdw_const, cdw_volatile, cdw_restrict, cdw_address_space, + cdw_atomic, cdw_number_of_elements + }; + location_t specs_loc + = smallest_type_quals_location (declspecs->locations, + ignored_quals_list); + if (specs_loc == UNKNOWN_LOCATION) + specs_loc = declspecs->locations[cdw_typedef]; + if (specs_loc == UNKNOWN_LOCATION) + specs_loc = loc; + /* Type qualifiers on a function return type are normally permitted by the standard but have no effect, so give a warning at -Wreturn-type. @@ -6287,13 +6320,14 @@ grokdeclarator (const struct c_declarato DR#423 means qualifiers (other than _Atomic) are actually removed from the return type when determining the function type. */ + int quals_used = type_quals; if (flag_isoc11) quals_used &= TYPE_QUAL_ATOMIC; if (quals_used && VOID_TYPE_P (type) && really_funcdef) - pedwarn (loc, 0, + pedwarn (specs_loc, 0, "function definition has qualified void return type"); else - warning_at (loc, OPT_Wignored_qualifiers, + warning_at (specs_loc, OPT_Wignored_qualifiers, "type qualifiers ignored on function return type"); /* Ensure an error for restrict on invalid types; the Index: gcc/cp/decl.c =================================================================== --- gcc/cp/decl.c (revision 238040) +++ gcc/cp/decl.c (working copy) @@ -10089,8 +10089,15 @@ grokdeclarator (const cp_declarator *dec if (type_quals != TYPE_UNQUALIFIED) { if (SCALAR_TYPE_P (type) || VOID_TYPE_P (type)) - warning (OPT_Wignored_qualifiers, - "type qualifiers ignored on function return type"); + { + location_t loc; + loc = smallest_type_quals_location (type_quals, + declspecs->locations); + if (loc == UNKNOWN_LOCATION) + loc = declspecs->locations[ds_type_spec]; + warning_at (loc, OPT_Wignored_qualifiers, "type " + "qualifiers ignored on function return type"); + } /* We now know that the TYPE_QUALS don't apply to the decl, but to its return type. */ type_quals = TYPE_UNQUALIFIED; Index: gcc/testsuite/c-c++-common/pr69733.c =================================================================== --- gcc/testsuite/c-c++-common/pr69733.c (revision 0) +++ gcc/testsuite/c-c++-common/pr69733.c (working copy) @@ -0,0 +1,24 @@ +/* { dg-do compile } */ +/* { dg-options "-W -fdiagnostics-show-caret" } */ + +typedef const double cd; +double val; + +const double val0() {return val;} /* { dg-warning "qualifiers ignored" } */ +/* { dg-begin-multiline-output "" } + const double val0() {return val;} + ^~~~~ +{ dg-end-multiline-output "" } */ + +volatile double val1() {return val;} /* { dg-warning "qualifiers ignored" } */ +/* { dg-begin-multiline-output "" } + volatile double val1() {return val;} + ^~~~~~~~ +{ dg-end-multiline-output "" } */ + +cd val2() {return val;} /* { dg-warning "qualifiers ignored" } */ +/* { dg-begin-multiline-output "" } + cd val2() {return val;} + ^~ +{ dg-end-multiline-output "" } */ + Index: gcc/testsuite/gcc.dg/pr69733.c =================================================================== --- gcc/testsuite/gcc.dg/pr69733.c (revision 0) +++ gcc/testsuite/gcc.dg/pr69733.c (working copy) @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-W -fdiagnostics-show-caret" } */ + +double val; + +_Atomic double val0() {return val;} /* { dg-warning "qualifiers ignored" } */ +/* { dg-begin-multiline-output "" } + _Atomic double val0() {return val;} + ^~~~~~~ +{ dg-end-multiline-output "" } */ + Index: gcc/testsuite/gcc.target/i386/pr69733.c =================================================================== --- gcc/testsuite/gcc.target/i386/pr69733.c (revision 0) +++ gcc/testsuite/gcc.target/i386/pr69733.c (working copy) @@ -0,0 +1,30 @@ +/* { dg-do compile } */ +/* { dg-options "-W -fdiagnostics-show-caret" } */ + +typedef const double cd; +double val; + +const double val0() {return val;} /* { dg-warning "qualifiers ignored" } */ +/* { dg-begin-multiline-output "" } + const double val0() {return val;} + ^~~~~ +{ dg-end-multiline-output "" } */ + +volatile double val1() {return val;} /* { dg-warning "qualifiers ignored" } */ +/* { dg-begin-multiline-output "" } + volatile double val1() {return val;} + ^~~~~~~~ +{ dg-end-multiline-output "" } */ + +cd val2() {return val;} /* { dg-warning "qualifiers ignored" } */ +/* { dg-begin-multiline-output "" } + cd val2() {return val;} + ^~ +{ dg-end-multiline-output "" } */ + +__seg_fs int val3() {return val;} /* { dg-warning "qualifiers ignored" } */ +/* { dg-begin-multiline-output "" } + __seg_fs int val3() {return val;} + ^~~~~~~~ +{ dg-end-multiline-output "" } */ + --------------E841AAB6A33827A89014702D--