Message ID | 56951572-c9b4-af2d-0e8b-9d47b87ba313@codesourcery.com |
---|---|
State | New |
Headers |
Return-Path: <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C57F53858287 for <patchwork@sourceware.org>; Thu, 8 Sep 2022 15:29:34 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa3.mentor.iphmx.com (esa3.mentor.iphmx.com [68.232.137.180]) by sourceware.org (Postfix) with ESMTPS id 2EEDF3858421 for <gcc-patches@gcc.gnu.org>; Thu, 8 Sep 2022 15:29:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2EEDF3858421 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com X-IronPort-AV: E=Sophos;i="5.93,300,1654588800"; d="diff'?scan'208";a="82550583" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 08 Sep 2022 07:29:18 -0800 IronPort-SDR: 0YTgr5VWOXEoqAqyJlHQ8/Q747BI8vAVSkQE5dXeQiSmuD1hi9E+4R2gop75cvDt17eCJx8FSL Fl+AwJMmjjN0zLU/PHJaDbm+VTgrmG0aRVzO1/i3TIKnDmJUPGBB9qfE5icTRVlzqTsongliW9 7yKD4ANWLWMEVR5Z98PH6nRb3f+r7f0veCClQaB3XrfS8fxiCPuTPgzPj3tJkXQJMa8LVLmA9g FUFUSQxXkyHyqscunbuV7lPQxnpOtjffxLN7fzZ/qAKaZc5JnRG53W/wxLMSv3zGlcEAo9BgDi 0eo= Content-Type: multipart/mixed; boundary="------------1rEOE86nVYdDYuLDgPCE56q2" Message-ID: <56951572-c9b4-af2d-0e8b-9d47b87ba313@codesourcery.com> Date: Thu, 8 Sep 2022 23:29:12 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 Content-Language: en-US From: Chung-Lin Tang <cltang@codesourcery.com> To: gcc-patches <gcc-patches@gcc.gnu.org>, Joseph Myers <joseph@codesourcery.com> Subject: [PATCH] optc-save-gen.awk: adjust generated array compare X-ClientProxiedBy: SVR-ORW-MBX-07.mgc.mentorg.com (147.34.90.207) To svr-orw-mbx-10.mgc.mentorg.com (147.34.90.210) X-Spam-Status: No, score=-10.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_ASCII_DIVIDERS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> Cc: Sandra Loosemore <sandra@codesourcery.com> Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> |
Series |
optc-save-gen.awk: adjust generated array compare
|
|
Commit Message
Chung-Lin Tang
Sept. 8, 2022, 3:29 p.m. UTC
Hi Joseph, Jan-Benedict reported a build-bot error for the nios2 port under --enable-werror-always: options-save.cc: In function 'bool cl_target_option_eq(const cl_target_option*, const cl_target_option*)': options-save.cc:9291:38: error: comparison between two arrays [-Werror=array-compare] 9291 | if (ptr1->saved_custom_code_status != ptr2->saved_custom_code_status | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ options-save.cc:9291:38: note: use unary '+' which decays operands to pointers or '&'component_ref' not supported by dump_decl<declaration error>[0] != &'component_ref' not supported by dump_decl<declaration error>[0]' to compare the addresses options-save.cc:9294:37: error: comparison between two arrays [-Werror=array-compare] 9294 | if (ptr1->saved_custom_code_index != ptr2->saved_custom_code_index | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ... This is due to an array-typed TargetSave state in config/nios2/nios2.opt: ... TargetSave enum nios2_ccs_code saved_custom_code_status[256] TargetSave int saved_custom_code_index[256] ... This patch adjusts the generated array state compare from 'ptr1->array' into '&ptr1->array[0]' in gcc/optc-save-gen.awk, seems sufficient to pass the tougher checks. Tested by ensuring the compiler builds, which should be sufficient here. Okay to commit to mainline? Thanks, Chung-Lin * optc-save-gen.awk: Adjust array compare to use '&ptr->name[0]' instead of 'ptr->name'.
Comments
On 9/8/22 11:29, Chung-Lin Tang wrote: > Hi Joseph, > Jan-Benedict reported a build-bot error for the nios2 port under --enable-werror-always: > > options-save.cc: In function 'bool cl_target_option_eq(const cl_target_option*, const cl_target_option*)': > options-save.cc:9291:38: error: comparison between two arrays [-Werror=array-compare] > 9291 | if (ptr1->saved_custom_code_status != ptr2->saved_custom_code_status > | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > options-save.cc:9291:38: note: use unary '+' which decays operands to pointers or '&'component_ref' not supported by dump_decl<declaration error>[0] != &'component_ref' not supported by dump_decl<declaration error>[0]' to compare the addresses > options-save.cc:9294:37: error: comparison between two arrays [-Werror=array-compare] > 9294 | if (ptr1->saved_custom_code_index != ptr2->saved_custom_code_index > | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > ... > > This is due to an array-typed TargetSave state in config/nios2/nios2.opt: > ... > TargetSave > enum nios2_ccs_code saved_custom_code_status[256] > > TargetSave > int saved_custom_code_index[256] > ... > > > This patch adjusts the generated array state compare from 'ptr1->array' into '&ptr1->array[0]' in gcc/optc-save-gen.awk, > seems sufficient to pass the tougher checks. > > Tested by ensuring the compiler builds, which should be sufficient here. > Okay to commit to mainline? Martin added the array support in r219636, any thoughts? It seems to me that the warning is pointing out that comparing the address of the array is nonsensical, and we should remove it and just have the memcmp. > Thanks, > Chung-Lin > > * optc-save-gen.awk: Adjust array compare to use '&ptr->name[0]' > instead of 'ptr->name'.
On 9/8/22 18:23, Jason Merrill wrote:
> It seems to me that the warning is pointing out that comparing the address of the array is nonsensical, and we should remove it and just have the memcmp.
Yes, thanks for the pointer. We should always compare the array types with memcmp.
Ready to be installed?
Thanks,
Martin
On 9/8/22 14:01, Martin Liška wrote: > On 9/8/22 18:23, Jason Merrill wrote: >> It seems to me that the warning is pointing out that comparing the address of the array is nonsensical, and we should remove it and just have the memcmp. > > Yes, thanks for the pointer. We should always compare the array types with memcmp. > > Ready to be installed? OK.
diff --git a/gcc/optc-save-gen.awk b/gcc/optc-save-gen.awk index 233d1fbb637..27aabf2955e 100644 --- a/gcc/optc-save-gen.awk +++ b/gcc/optc-save-gen.awk @@ -1093,7 +1093,7 @@ for (i = 0; i < n_target_array; i++) { name = var_target_array[i] size = var_target_array_size[i] type = var_target_array_type[i] - print " if (ptr1->" name" != ptr2->" name ""; + print " if (&ptr1->" name"[0] != &ptr2->" name "[0]"; print " || memcmp (ptr1->" name ", ptr2->" name ", " size " * sizeof(" type ")))" print " return false;"; }