From patchwork Tue Jun 2 07:45:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 1302152 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=8.43.85.97; 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=t5kvI+MI; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (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 49bkcJ6qvGz9sSn for ; Tue, 2 Jun 2020 17:45:51 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8C04A3870858; Tue, 2 Jun 2020 07:45:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8C04A3870858 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1591083948; bh=oazIFl2q4/7Z2r5tT1DCglHeK/2HPMeopxw7PyXC/dA=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=t5kvI+MI0bJ8BMwC7yUNMcTuGRhuKuWCgmXiIYqAOHYYEqvXNiWik5FfD5kchGbYm Lixk22qYyJLBRf/8KDtF1QPZ0cvKXThiRpVXJp4RVf9lLnGExjfyk91JPLTXFaah6O s5H61OS6G928ih65nVpIVL+ZBbvHGetklJ5QCW84= 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 [80.241.56.151]) by sourceware.org (Postfix) with ESMTPS id 7DD4B3870850 for ; Tue, 2 Jun 2020 07:45:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 7DD4B3870850 Received: from smtp1.mailbox.org (smtp1.mailbox.org [80.241.60.240]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 49bkc772kYzKmrv; Tue, 2 Jun 2020 09:45:43 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp1.mailbox.org ([80.241.60.240]) by gerste.heinlein-support.de (gerste.heinlein-support.de [91.198.250.173]) (amavisd-new, port 10030) with ESMTP id EkvnkXAwL0Wk; Tue, 2 Jun 2020 09:45:40 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [committed] d: Fix segfault in build_frontend_type on alpha-*-* Date: Tue, 2 Jun 2020 09:45:26 +0200 Message-Id: <20200602074526.5859-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 03FB517EE X-Rspamd-Score: 1.29 / 15.00 / 15.00 X-Spam-Status: No, score=-18.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, 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, The va_list type for Alpha includes a nameless dummy field for alignment purposes. To transpose this into D, a field named "__pad%d" is inserted into the struct definition. It was also noticed that in the D front-end AST copy of the backend type, all offsets for fields generated by build_frontend_type were set to zero due to a wrong assumption that DECL_FIELD_OFFSET would have a non-zero value. This has been fixed to use byte_position instead. Bootstrapped and regression tested on x86_64-linux-gnu, and committed to both mainline and backported to the gcc-10 release branch. Regards Iain. gcc/d/ChangeLog: * d-builtins.cc (build_frontend_type): Handle struct fields with NULL DECL_NAME. Use byte_position to get the real field offset. --- gcc/d/d-builtins.cc | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/gcc/d/d-builtins.cc b/gcc/d/d-builtins.cc index a5654a66bf5..1cb5407f8a9 100644 --- a/gcc/d/d-builtins.cc +++ b/gcc/d/d-builtins.cc @@ -238,6 +238,9 @@ build_frontend_type (tree type) sdecl->type->ctype = type; sdecl->type->merge2 (); + /* Add both named and anonymous fields as members of the struct. + Anonymous fields still need a name in D, so call them "__pad%d". */ + int anonfield_id = 0; sdecl->members = new Dsymbols; for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field)) @@ -249,12 +252,19 @@ build_frontend_type (tree type) return NULL; } - Identifier *fident - = Identifier::idPool (IDENTIFIER_POINTER (DECL_NAME (field))); + Identifier *fident; + if (DECL_NAME (field) == NULL_TREE) + fident = Identifier::generateId ("__pad", anonfield_id++); + else + { + const char *name = IDENTIFIER_POINTER (DECL_NAME (field)); + fident = Identifier::idPool (name); + } + VarDeclaration *vd = VarDeclaration::create (Loc (), ftype, fident, NULL); vd->parent = sdecl; - vd->offset = tree_to_uhwi (DECL_FIELD_OFFSET (field)); + vd->offset = tree_to_uhwi (byte_position (field)); vd->semanticRun = PASSsemanticdone; vd->csym = field; sdecl->members->push (vd);