From patchwork Tue May 17 20:22:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 54113 Return-Path: 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 7AF693858C56 for ; Tue, 17 May 2022 20:23:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7AF693858C56 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1652818998; bh=cUHD1t2uiI2XQB5CMnP/JMGE7fKZrqB3sKvw+SQHMlM=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=EfJf5v7tNC/WPyeFb9WjCUlphTxHlnpbLTh1V4i5xs9zBoQM0LngksfZke2M+2+qs D+HCy6qEUKEn3lSaf4B1I5QSoESQo8cTz2q9+JHQIOe4QqrT0pJXXn0xq1gYA1ZqB6 s4FGMI7fegDFeio2vV18BMcsexkDXK5YpuHkYJCs= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id D73123858C53 for ; Tue, 17 May 2022 20:22:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D73123858C53 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-332-DCZz7sXWNtyeCsNsDGwLZQ-1; Tue, 17 May 2022 16:22:42 -0400 X-MC-Unique: DCZz7sXWNtyeCsNsDGwLZQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A0933185A794; Tue, 17 May 2022 20:22:42 +0000 (UTC) Received: from pdp-11.redhat.com (unknown [10.22.16.220]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2442F1121314; Tue, 17 May 2022 20:22:42 +0000 (UTC) To: GCC Patches , Joseph Myers Subject: [PATCH] c: use CONST_DECL for enumerators in TYPE_VALUES Date: Tue, 17 May 2022 16:22:33 -0400 Message-Id: <20220517202233.415333-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Marek Polacek via Gcc-patches From: Marek Polacek Reply-To: Marek Polacek Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" The C and C++ FEs differ in TYPE_VALUES for an enum type: an entry in the list in the C++ FE has a CONST_DECL in the TREE_VALUE, but the C FE has only the numerical value of the CONST_DECL there. This has caused me some trouble in my PR105497 patch. Using a CONST_DECL is preferable because a CONST_DECL can track more information (e.g., attributes), and you can always get the value simply by looking at its DECL_INITIAL. This turned out to be a trivial change. One place in godump.cc had to be adjusted. I'm not changing the CONST_DECL check in c_do_switch_warnings because I'll be changing it soon in my next patch. I didn't see any other checks that this patch makes redundant. Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? gcc/c/ChangeLog: * c-decl.cc (finish_enum): Store the CONST_DECL into TREE_VALUE, not its value. gcc/ChangeLog: * godump.cc (go_output_typedef): Use the DECL_INITIAL of the TREE_VALUE. --- gcc/c/c-decl.cc | 4 +++- gcc/godump.cc | 9 +++++---- 2 files changed, 8 insertions(+), 5 deletions(-) base-commit: b7501739f3b14ac7749aace93f636d021fd607f7 diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc index e49879ab286..83655548fc4 100644 --- a/gcc/c/c-decl.cc +++ b/gcc/c/c-decl.cc @@ -9253,7 +9253,9 @@ finish_enum (tree enumtype, tree values, tree attributes) DECL_INITIAL (enu) = ini; TREE_PURPOSE (pair) = DECL_NAME (enu); - TREE_VALUE (pair) = ini; + /* To match the C++ FE, store the CONST_DECL rather than just its + value. */ + TREE_VALUE (pair) = enu; } TYPE_VALUES (enumtype) = values; diff --git a/gcc/godump.cc b/gcc/godump.cc index 2ae0bcc9672..c0f52bbd0f2 100644 --- a/gcc/godump.cc +++ b/gcc/godump.cc @@ -1114,6 +1114,7 @@ go_output_typedef (class godump_container *container, tree decl) struct macro_hash_value *mhval; void **slot; char buf[WIDE_INT_PRINT_BUFFER_SIZE]; + tree value = DECL_INITIAL (TREE_VALUE (element)); name = IDENTIFIER_POINTER (TREE_PURPOSE (element)); @@ -1127,12 +1128,12 @@ go_output_typedef (class godump_container *container, tree decl) if (*slot != NULL) macro_hash_del (*slot); - if (tree_fits_shwi_p (TREE_VALUE (element))) + if (tree_fits_shwi_p (value)) snprintf (buf, sizeof buf, HOST_WIDE_INT_PRINT_DEC, - tree_to_shwi (TREE_VALUE (element))); - else if (tree_fits_uhwi_p (TREE_VALUE (element))) + tree_to_shwi (value)); + else if (tree_fits_uhwi_p (value)) snprintf (buf, sizeof buf, HOST_WIDE_INT_PRINT_UNSIGNED, - tree_to_uhwi (TREE_VALUE (element))); + tree_to_uhwi (value)); else print_hex (wi::to_wide (element), buf);