From patchwork Thu Jul 29 15:23:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 1511331 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+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) 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=We+7Jgh2; 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 4GbDt14mCwz9sRf for ; Fri, 30 Jul 2021 01:27:21 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DD73739B5D0D for ; Thu, 29 Jul 2021 15:27:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DD73739B5D0D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1627572438; bh=Wxv0okSa9Khr6YItv9cBHaMVa70F4toUBNVY03uGyDI=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=We+7Jgh2DtcixAN1bQM4aLfrzlFcDnw1T0v6JFs1NNU1xjwN0TExZADoVd3eEiZik OST3umsfPtxNx8kmmfvhNo+RvmcFTF5P9x256+dAH/Yvc+DMvZBM+PPX5X5E3X6dY2 oj4gdbDRrrO1pjXY8c9UguJZlwjtFYfZgFQponJE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by sourceware.org (Postfix) with ESMTPS id 9994A39CE1D5 for ; Thu, 29 Jul 2021 15:23:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9994A39CE1D5 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-202.mailbox.org (Postfix) with ESMTPS id 4GbDnR5L1VzQk1m; Thu, 29 Jul 2021 17:23:23 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by spamfilter06.heinlein-hosting.de (spamfilter06.heinlein-hosting.de [80.241.56.125]) (amavisd-new, port 10030) with ESMTP id Pk1p0tqJT2u1; Thu, 29 Jul 2021 17:23:20 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [committed] d: Generate Object class if it doesn't exist during TypeInfo emission (PR101672) Date: Thu, 29 Jul 2021 17:23:18 +0200 Message-Id: <20210729152318.273469-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 72C8B182F X-Rspamd-UID: d0dcdd X-Spam-Status: No, score=-15.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi, This patch adds a check to make_frontend_typeinfo to generate a stub Object class if one doesn't exist in the run-time library. Having a stub will prevent errors from occuring when compiling D code with an empty object.d. Though if it were to actually be used implicitly then an error should occur. Bootstrapped and regression tested on x86_64-linux-gnu/-mx32/-m32, and committed to mainline. Regards, Iain --- gcc/d/ChangeLog: PR d/101672 * typeinfo.cc (make_frontend_typeinfo): Generate Object class if it doesn't exist. (check_typeinfo_type): Don't warn if there's no location. gcc/testsuite/ChangeLog: PR d/101672 * gdc.dg/pr100967.d: Update test. * gdc.dg/pr101672.d: New test. --- gcc/d/typeinfo.cc | 23 +++++++++++++++++++++-- gcc/testsuite/gdc.dg/pr100967.d | 2 +- gcc/testsuite/gdc.dg/pr101672.d | 19 +++++++++++++++++++ 3 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gdc.dg/pr101672.d diff --git a/gcc/d/typeinfo.cc b/gcc/d/typeinfo.cc index 9d6464deb07..a1f0543d58e 100644 --- a/gcc/d/typeinfo.cc +++ b/gcc/d/typeinfo.cc @@ -205,12 +205,30 @@ make_frontend_typeinfo (Identifier *ident, ClassDeclaration *base = NULL) if (!object_module->_scope) object_module->importAll (NULL); + /* Object class doesn't exist, create a stub one that will cause an error if + used. */ + Loc loc = (object_module->md) ? object_module->md->loc : object_module->loc; + if (!base) + { + if (!ClassDeclaration::object) + { + ClassDeclaration *object + = ClassDeclaration::create (loc, Identifier::idPool ("Object"), + NULL, NULL, true); + object->parent = object_module; + object->members = new Dsymbols; + object->storage_class |= STCtemp; + } + + base = ClassDeclaration::object; + } + /* Assignment of global typeinfo variables is managed by the ClassDeclaration constructor, so only need to new the declaration here. */ - Loc loc = (object_module->md) ? object_module->md->loc : object_module->loc; ClassDeclaration *tinfo = ClassDeclaration::create (loc, ident, NULL, NULL, true); tinfo->parent = object_module; + tinfo->members = new Dsymbols; dsymbolSemantic (tinfo, object_module->_scope); tinfo->baseClass = base; /* This is a compiler generated class, and shouldn't be mistaken for being @@ -1316,6 +1334,7 @@ public: tree type = tinfo_types[get_typeinfo_kind (tid->tinfo)]; gcc_assert (type != NULL_TREE); + /* Built-in typeinfo will be referenced as one-only. */ tid->csym = declare_extern_var (ident, type); DECL_LANG_SPECIFIC (tid->csym) = build_lang_decl (tid); @@ -1400,7 +1419,7 @@ check_typeinfo_type (const Loc &loc, Scope *sc) /* If TypeInfo has not been declared, warn about each location once. */ static Loc warnloc; - if (!warnloc.equals (loc)) + if (loc.filename && !warnloc.equals (loc)) { error_at (make_location_t (loc), "% could not be found, " diff --git a/gcc/testsuite/gdc.dg/pr100967.d b/gcc/testsuite/gdc.dg/pr100967.d index 582ad582676..bb83c299ced 100644 --- a/gcc/testsuite/gdc.dg/pr100967.d +++ b/gcc/testsuite/gdc.dg/pr100967.d @@ -1,7 +1,7 @@ // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100967 // { dg-do compile } -module object; // { dg-error "class object.TypeInfo missing or corrupt object.d" } +module object; extern(C) int main() { diff --git a/gcc/testsuite/gdc.dg/pr101672.d b/gcc/testsuite/gdc.dg/pr101672.d new file mode 100644 index 00000000000..292fd761fb1 --- /dev/null +++ b/gcc/testsuite/gdc.dg/pr101672.d @@ -0,0 +1,19 @@ +// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101672 +// { dg-do compile } + +module object; + +interface I101672 +{ + static int i101672; +} + +class A101672 : I101672 // { dg-error "class object.A101672 missing or corrupt object.d" } +{ + static int a101672; +} + +class B101672 : A101672 +{ + static int b101672; +}