From patchwork Sat Sep 12 19:44:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 1362907 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=j75M+41+; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BpjkY64YNz9sTC for ; Sun, 13 Sep 2020 05:44:36 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 305B7384A40A; Sat, 12 Sep 2020 19:44:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 305B7384A40A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1599939873; bh=5PHhGT+uLxBE+bdufjgpP7c5IbdfgHIOD4xP+ikYilg=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=j75M+41+RVseKjWo4OtqnVRnr1NpH1fA0L7NS32d5bm3S9GDpERXXYygzGo6SEANv 77Vg1kOk1yBImuombeJL8QGWBApu4fVB2FaEHt19R8c57g9mCFoAteUQMLz9GuooKF SWs4QXgWbO0CTVU8DUT/l0yjTXB6+L9VYuHTuGMM= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [IPv6:2001:67c:2050::465:101]) by sourceware.org (Postfix) with ESMTPS id 412323857C62 for ; Sat, 12 Sep 2020 19:44:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 412323857C62 Received: from smtp2.mailbox.org (smtp2.mailbox.org [80.241.60.241]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4BpjkN2Q5GzKmmy; Sat, 12 Sep 2020 21:44:28 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by spamfilter03.heinlein-hosting.de (spamfilter03.heinlein-hosting.de [80.241.56.117]) (amavisd-new, port 10030) with ESMTP id 95FhjxQjZ3iF; Sat, 12 Sep 2020 21:44:20 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [committed] d: Build TYPE_DECLs for non-numeric enum types. Date: Sat, 12 Sep 2020 21:44:13 +0200 Message-Id: <20200912194413.582366-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 X-MBO-SPAM-Probability: * X-Rspamd-Score: 1.18 / 15.00 / 15.00 X-Rspamd-Queue-Id: A0B76272 X-Rspamd-UID: ef5799 X-Spam-Status: No, score=-15.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Iain Buclaw via Gcc-patches From: Iain Buclaw Reply-To: Iain Buclaw Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi, This patch alters TYPE_DECL generation to also build one for enums whose member type is non-numeric. This is done so that the DWARF pass will emit a DW_TAG_typedef where the member type of an enum can't be represented in an ENUMERAL_TYPE. Bootstrapped and regression tested on x86_64-linux-gnu/0m32/-mx32. Committed to mainline. Regards Iain --- gcc/d/ChangeLog: * d-builtins.cc (d_build_d_type_nodes): Call build_ctype() on all basic front-end types. * decl.cc (DeclVisitor::visit (EnumDeclaration *)): Always add decl to current binding level. (build_type_decl): Build TYPE_DECL as a typedef if not for an enum or record type. * types.cc (TypeVisitor::visit (TypeEnum *)): Set underlying type for ENUMERAL_TYPEs. Build TYPE_DECL for non-numeric enums. --- gcc/d/d-builtins.cc | 8 ++++++++ gcc/d/decl.cc | 22 ++++++++++++---------- gcc/d/types.cc | 5 ++++- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/gcc/d/d-builtins.cc b/gcc/d/d-builtins.cc index e3d7adc2deb..72e2d3a7168 100644 --- a/gcc/d/d-builtins.cc +++ b/gcc/d/d-builtins.cc @@ -848,6 +848,14 @@ d_build_d_type_nodes (void) ireal_type_node = build_distinct_type_copy (long_double_type_node); TYPE_IMAGINARY_FLOAT (ireal_type_node) = 1; + /* Calling build_ctype() links the front-end Type to the GCC node, + and sets the TYPE_NAME to the D language type. */ + for (unsigned ty = 0; ty < TMAX; ty++) + { + if (Type::basic[ty] != NULL) + build_ctype (Type::basic[ty]); + } + /* Used for ModuleInfo, ClassInfo, and Interface decls. */ unknown_type_node = make_node (RECORD_TYPE); diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc index 59844bc8633..161a85a842b 100644 --- a/gcc/d/decl.cc +++ b/gcc/d/decl.cc @@ -618,13 +618,13 @@ public: d_linkonce_linkage (d->sinit); d_finish_decl (d->sinit); - - /* Add this decl to the current binding level. */ - tree ctype = build_ctype (d->type); - if (TREE_CODE (ctype) == ENUMERAL_TYPE && TYPE_NAME (ctype)) - d_pushdecl (TYPE_NAME (ctype)); } + /* Add this decl to the current binding level. */ + tree ctype = build_ctype (d->type); + if (TYPE_NAME (ctype)) + d_pushdecl (TYPE_NAME (ctype)); + d->semanticRun = PASSobj; } @@ -2270,8 +2270,6 @@ build_type_decl (tree type, Dsymbol *dsym) if (TYPE_STUB_DECL (type)) return; - gcc_assert (!POINTER_TYPE_P (type)); - /* If a templated type, use the template instance name, as that includes all template parameters. */ const char *name = dsym->parent->isTemplateInstance () @@ -2281,7 +2279,6 @@ build_type_decl (tree type, Dsymbol *dsym) get_identifier (name), type); SET_DECL_ASSEMBLER_NAME (decl, get_identifier (d_mangle_decl (dsym))); TREE_PUBLIC (decl) = 1; - DECL_ARTIFICIAL (decl) = 1; DECL_CONTEXT (decl) = d_decl_context (dsym); TYPE_CONTEXT (type) = DECL_CONTEXT (decl); @@ -2290,9 +2287,14 @@ build_type_decl (tree type, Dsymbol *dsym) /* Not sure if there is a need for separate TYPE_DECLs in TYPE_NAME and TYPE_STUB_DECL. */ if (TREE_CODE (type) == ENUMERAL_TYPE || RECORD_OR_UNION_TYPE_P (type)) - TYPE_STUB_DECL (type) = decl; + { + DECL_ARTIFICIAL (decl) = 1; + TYPE_STUB_DECL (type) = decl; + } + else if (type != TYPE_MAIN_VARIANT (type)) + DECL_ORIGINAL_TYPE (decl) = TYPE_MAIN_VARIANT (type); - rest_of_decl_compilation (decl, SCOPE_FILE_SCOPE_P (decl), 0); + rest_of_decl_compilation (decl, DECL_FILE_SCOPE_P (decl), 0); } /* Create a declaration for field NAME of a given TYPE, setting the flags diff --git a/gcc/d/types.cc b/gcc/d/types.cc index 994d0b9195b..6df1e78c074 100644 --- a/gcc/d/types.cc +++ b/gcc/d/types.cc @@ -859,14 +859,17 @@ public: For these, we simplify this a little by using the base type directly instead of building an ENUMERAL_TYPE. */ t->ctype = build_variant_type_copy (basetype); + build_type_decl (t->ctype, t->sym); } else { t->ctype = make_node (ENUMERAL_TYPE); - ENUM_IS_SCOPED (t->ctype) = 1; TYPE_LANG_SPECIFIC (t->ctype) = build_lang_type (t); d_keep (t->ctype); + ENUM_IS_SCOPED (t->ctype) = 1; + TREE_TYPE (t->ctype) = basetype; + if (flag_short_enums) TYPE_PACKED (t->ctype) = 1;