From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2100) id B8893388E828; Sat, 22 Aug 2020 21:48:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B8893388E828 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1598132917; bh=aTx2+dVKCIGIHWKpNtJH9M7pvd2+d8q+g5Xyop+XOcg=; h=From:To:Subject:Date:From; b=S4RJXWuCB1K/6IA2fQhOEFa1IQyr9TYpX258XS5PDfjR50Zdd5uYpaqfgoAs10E2C DWXY7KB5s37cMzNn/2+9cPPD/i7Q+Zkw+6EVNUNhMfIyQZcpUueI2p77VyBmKxgsSt P0gTqQIkbDo1fxtLWzWh8TVHUPAvyZAEpvIfVUII= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Giuliano Belinassi To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/autopar_devel] d: Fix segfault in build_frontend_type on alpha-*-* X-Act-Checkin: gcc X-Git-Author: Iain Buclaw X-Git-Refname: refs/heads/devel/autopar_devel X-Git-Oldrev: cd7a56becacbe878820d1ca3c1d407378a022b12 X-Git-Newrev: f865d9fb85187eccf10472258e93804838a089ac Message-Id: <20200822214837.B8893388E828@sourceware.org> Date: Sat, 22 Aug 2020 21:48:37 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 22 Aug 2020 21:48:37 -0000 https://gcc.gnu.org/g:f865d9fb85187eccf10472258e93804838a089ac commit f865d9fb85187eccf10472258e93804838a089ac Author: Iain Buclaw Date: Mon Jun 1 13:27:06 2020 +0200 d: Fix segfault in build_frontend_type on alpha-*-* 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. 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. Diff: --- 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);