From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1873) id BB8A339B3C3E; Thu, 29 Jul 2021 15:13:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BB8A339B3C3E MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Iain Buclaw To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-2599] d: Generate Object class if it doesn't exist during TypeInfo emission (PR101672) X-Act-Checkin: gcc X-Git-Author: Iain Buclaw X-Git-Refname: refs/heads/master X-Git-Oldrev: 7616ed6307c90b5bbf1bf53550d33cc674ab4b6f X-Git-Newrev: 3c13cf479ba81c4d29b202e9b8c6a7f0031a8b20 Message-Id: <20210729151304.BB8A339B3C3E@sourceware.org> Date: Thu, 29 Jul 2021 15:13:04 +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: Thu, 29 Jul 2021 15:13:04 -0000 https://gcc.gnu.org/g:3c13cf479ba81c4d29b202e9b8c6a7f0031a8b20 commit r12-2599-g3c13cf479ba81c4d29b202e9b8c6a7f0031a8b20 Author: Iain Buclaw Date: Mon Jul 26 20:01:29 2021 +0200 d: Generate Object class if it doesn't exist during TypeInfo emission (PR101672) 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. PR d/101672 gcc/d/ChangeLog: * 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: * gdc.dg/pr100967.d: Update test. * gdc.dg/pr101672.d: New test. Diff: --- 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(-) 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; +}