From patchwork Fri Mar 20 16:29:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 1259058 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=HpYzBcjA; 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 48kTkr6WDqz9sRf for ; Sat, 21 Mar 2020 03:29:39 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 577B23948827; Fri, 20 Mar 2020 16:29:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 577B23948827 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1584721776; bh=E57CJUpyV8g7flyJH+J6tmmEluNHaYe7XUOnAxZQfiQ=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=HpYzBcjA9UVG+RUg5lK+O3mzjZJF93UZ26+DgFio9RD3hBDuomyAhKcXAU8/TDg2H pDQ6BQpVaNdGzG6lRnzDWtQbpYGQUz5k+RL8FOnuSI4Rzmnzo1iNfo3gKi9QmcoOeZ MIxbqyQWlnCkPX+LL9b1Dakcy8N+TL7hXC0HGcog= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout-u-204.mailbox.org (mout-u-204.mailbox.org [IPv6:2001:67c:2050:1::465:204]) by sourceware.org (Postfix) with ESMTPS id 2AE98387703A for ; Fri, 20 Mar 2020 16:29:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2AE98387703A Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:105:465:1:2:0]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mout-u-204.mailbox.org (Postfix) with ESMTPS id 48kTkg6r63zQjy1; Fri, 20 Mar 2020 17:29:31 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by spamfilter02.heinlein-hosting.de (spamfilter02.heinlein-hosting.de [80.241.56.116]) (amavisd-new, port 10030) with ESMTP id ec4-9VJt4K5c; Fri, 20 Mar 2020 17:29:29 +0100 (CET) To: gcc-patches@gcc.gnu.org Subject: [PATCH lto/91027][D] Committed fix for SEGV in hash_table::find_slot_with_hash Date: Fri, 20 Mar 2020 17:29:12 +0100 Message-Id: <20200320162912.1237-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 X-Spam-Status: No, score=-27.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_NONE, SPF_PASS 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: "Li, Pan2 via Gcc-patches" Reply-To: Iain Buclaw Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi, This patch fixes LTO bug with the D front-end. As DECL_ASSEMBLER_NAME is set on the TYPE_DECL, so TYPE_CXX_ODR_P must also be set on the type. The addition of merge_aggregate_types is not strictly needed now, but it fixes a problem introduced in newer versions of the dmd front-end where templated types could be sent more than once to the D code generator. Bootstrapped and tested on x86_64-linux-gnu, and committed to trunk. Regards Iain --- gcc/d/ChangeLog: 2020-03-20 Iain Buclaw PR lto/91027 * d-tree.h (struct GTY): Add daggregate field. (IDENTIFIER_DAGGREGATE): Define. (d_mangle_decl): Add declaration. * decl.cc (mangle_decl): Remove static linkage, rename to... (d_mangle_decl): ...this, update all callers. * types.cc (merge_aggregate_types): New function. (TypeVisitor::visit (TypeStruct *)): Call merge_aggregate_types, set IDENTIFIER_DAGGREGATE and TYPE_CXX_ODR_P. (TypeVisitor::visit (TypeClass *)): Likewise. --- gcc/d/d-tree.h | 5 +++++ gcc/d/decl.cc | 10 +++++----- gcc/d/types.cc | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 5 deletions(-) diff --git a/gcc/d/d-tree.h b/gcc/d/d-tree.h index 4e9c0b7395e..0f831c754c0 100644 --- a/gcc/d/d-tree.h +++ b/gcc/d/d-tree.h @@ -204,6 +204,7 @@ struct GTY(()) lang_identifier /* The frontend Declaration associated with this identifier. */ Declaration * GTY((skip)) dsymbol; + AggregateDeclaration * GTY((skip)) daggregate; }; #define IDENTIFIER_LANG_SPECIFIC(NODE) \ @@ -218,6 +219,9 @@ struct GTY(()) lang_identifier #define IDENTIFIER_DSYMBOL(NODE) \ (IDENTIFIER_LANG_SPECIFIC (NODE)->dsymbol) +#define IDENTIFIER_DAGGREGATE(NODE) \ + (IDENTIFIER_LANG_SPECIFIC (NODE)->daggregate) + /* Global state pertinent to the current function. */ struct GTY(()) language_function @@ -600,6 +604,7 @@ extern tree d_signed_type (tree); extern void d_keep (tree); /* In decl.cc. */ +extern const char *d_mangle_decl (Dsymbol *); extern tree mangle_internal_decl (Dsymbol *, const char *, const char *); extern void build_decl_tree (Dsymbol *); extern tree get_symbol_decl (Declaration *); diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc index 7afb1aa0292..053d5537f4e 100644 --- a/gcc/d/decl.cc +++ b/gcc/d/decl.cc @@ -59,8 +59,8 @@ along with GCC; see the file COPYING3. If not see /* Return identifier for the external mangled name of DECL. */ -static const char * -mangle_decl (Dsymbol *decl) +const char * +d_mangle_decl (Dsymbol *decl) { if (decl->isFuncDeclaration ()) return mangleExact ((FuncDeclaration *)decl); @@ -78,7 +78,7 @@ mangle_decl (Dsymbol *decl) tree mangle_internal_decl (Dsymbol *decl, const char *name, const char *suffix) { - const char *prefix = mangle_decl (decl); + const char *prefix = d_mangle_decl (decl); unsigned namelen = strlen (name); unsigned buflen = (2 + strlen (prefix) + namelen + strlen (suffix)) * 2; char *buf = (char *) alloca (buflen); @@ -1145,7 +1145,7 @@ get_symbol_decl (Declaration *decl) if (decl->mangleOverride) mangled_name = get_identifier (decl->mangleOverride); else - mangled_name = get_identifier (mangle_decl (decl)); + mangled_name = get_identifier (d_mangle_decl (decl)); mangled_name = targetm.mangle_decl_assembler_name (decl->csym, mangled_name); @@ -2333,7 +2333,7 @@ build_type_decl (tree type, Dsymbol *dsym) tree decl = build_decl (make_location_t (dsym->loc), TYPE_DECL, get_identifier (name), type); - SET_DECL_ASSEMBLER_NAME (decl, get_identifier (mangle_decl (dsym))); + 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); diff --git a/gcc/d/types.cc b/gcc/d/types.cc index 866da965b40..025285205eb 100644 --- a/gcc/d/types.cc +++ b/gcc/d/types.cc @@ -498,6 +498,40 @@ finish_aggregate_type (unsigned structsize, unsigned alignsize, } } +/* Returns true if the class or struct type TYPE has already been layed out by + the lowering of another front-end AST type. In which case, there will either + be a reuse of the back-end type, or a multiple definition error. + DECO is the uniquely mangled decoration for the type. */ + +static bool +merge_aggregate_types (Type *type, tree deco) +{ + AggregateDeclaration *sym; + + if (type->ty == Tstruct) + sym = ((TypeStruct *) type)->sym; + else if (type->ty == Tclass) + sym = ((TypeClass *) type)->sym; + else + gcc_unreachable (); + + if (IDENTIFIER_DAGGREGATE (deco)) + { + AggregateDeclaration *ad = IDENTIFIER_DAGGREGATE (deco); + /* There should never be a class/struct mismatch in mangled names. */ + gcc_assert ((sym->isStructDeclaration () && ad->isStructDeclaration ()) + || (sym->isClassDeclaration () && ad->isClassDeclaration ())); + + /* Non-templated variables shouldn't be defined twice. */ + if (!sym->isInstantiated ()) + ScopeDsymbol::multiplyDefined (sym->loc, sym, ad); + + type->ctype = build_ctype (ad->type); + return true; + } + + return false; +} /* Implements the visitor interface to build the GCC trees of all Type AST classes emitted from the D Front-end, where CTYPE holds @@ -857,12 +891,19 @@ public: void visit (TypeStruct *t) { + /* Merge types in the back-end if the front-end did not itself do so. */ + tree deco = get_identifier (d_mangle_decl (t->sym)); + if (merge_aggregate_types (t, deco)) + return; + /* Need to set this right away in case of self-references. */ t->ctype = make_node (t->sym->isUnionDeclaration () ? UNION_TYPE : RECORD_TYPE); d_keep (t->ctype); + IDENTIFIER_DAGGREGATE (deco) = t->sym; TYPE_LANG_SPECIFIC (t->ctype) = build_lang_type (t); + TYPE_CXX_ODR_P (t->ctype) = 1; if (t->sym->members) { @@ -903,17 +944,24 @@ public: void visit (TypeClass *t) { + /* Merge types in the back-end if the front-end did not itself do so. */ + tree deco = get_identifier (d_mangle_decl (t->sym)); + if (merge_aggregate_types (t, deco)) + return; + /* Need to set ctype right away in case of self-references to the type during this call. */ tree basetype = make_node (RECORD_TYPE); t->ctype = build_pointer_type (basetype); d_keep (t->ctype); + IDENTIFIER_DAGGREGATE (deco) = t->sym; /* Note that lang_specific data is assigned to both the reference and the underlying record type. */ TYPE_LANG_SPECIFIC (t->ctype) = build_lang_type (t); TYPE_LANG_SPECIFIC (basetype) = TYPE_LANG_SPECIFIC (t->ctype); CLASS_TYPE_P (basetype) = 1; + TYPE_CXX_ODR_P (basetype) = 1; /* Put out all fields, including from each base class. */ layout_aggregate_type (t->sym, basetype, t->sym);