From patchwork Thu Jun 10 18:30:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 1490619 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+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=KvN5eDSY; 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 4G1CGj0rSkz9sxS for ; Fri, 11 Jun 2021 04:31:07 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2F38E398B17A for ; Thu, 10 Jun 2021 18:31:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2F38E398B17A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1623349864; bh=AmcDnoGr8Uhd9ak/EgjnjmoRqbvab1mZ6yl/n0GUof0=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=KvN5eDSYWC/fSZGqYcNKUXaIbnU4ywTJWnTjNuOmDNve2VYXtEjq6qs4AtkImmjFE 1FavAxyr9WguohrnDU3mP8dvbRbKJLAK47GikXxQJQ2dERFLEBZCTyG8/+uIvc4TAz jv1sv6grK1GwZmJNv4UPeW5QwJEiiyudS+BqIWVw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) by sourceware.org (Postfix) with ESMTPS id 7B38E385783A for ; Thu, 10 Jun 2021 18:30:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7B38E385783A Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:105:465:1:2:0]) (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-201.mailbox.org (Postfix) with ESMTPS id 4G1CG852ZVzQjPh; Thu, 10 Jun 2021 20:30:40 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by spamfilter01.heinlein-hosting.de (spamfilter01.heinlein-hosting.de [80.241.56.115]) (amavisd-new, port 10030) with ESMTP id Xda1W_8FfLuB; Thu, 10 Jun 2021 20:30:37 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [committed] d: Fix ICE in TypeInfoDeclaration, at dmd/declaration.c (PR100967) Date: Thu, 10 Jun 2021 20:30:35 +0200 Message-Id: <20210610183035.3275691-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 X-MBO-SPAM-Probability: X-Rspamd-Score: -0.20 / 15.00 / 15.00 X-Rspamd-Queue-Id: 776FB1811 X-Rspamd-UID: 990408 X-Spam-Status: No, score=-15.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi, This patch fixes an ICE in the constructor of TypeInfoDeclaration from within the D language front-end. Generates a stub TypeInfo class even if the root Object class is missing. The front-end will take care of issuing an error and abort the compilation when running semantic on constructed TypeInfo objects. The errors issued by the code generation pass relating to missing or disabled RTTI has been consolidated into a single function, so that a meaningful error will be emitted before the front-end terminates. Bootstrapped and regression tested on x86_64-linux-gnu/-m32/-mx32, committed to mainline, and backported to the gcc-9, gcc-10, and gcc-11 release branches. Regards, Iain --- gcc/d/ChangeLog: PR d/100967 * d-frontend.cc (getTypeInfoType): Move TypeInfo checks to check_typeinfo_type and call new function. * d-tree.h (check_typeinfo_type): Declare. * typeinfo.cc: Include dmd/scope.h. (create_frontend_tinfo_types): Generate front-end types even if Object is missing. (build_typeinfo): Move TypeInfo checks to check_typeinfo_type and call new function. (check_typeinfo_type): New function. gcc/testsuite/ChangeLog: PR d/100967 * gdc.dg/pr100967.d: New test. --- gcc/d/d-frontend.cc | 33 +--------------------------- gcc/d/d-tree.h | 1 + gcc/d/typeinfo.cc | 38 +++++++++++++++++++++++++++------ gcc/testsuite/gdc.dg/pr100967.d | 11 ++++++++++ 4 files changed, 45 insertions(+), 38 deletions(-) create mode 100644 gcc/testsuite/gdc.dg/pr100967.d diff --git a/gcc/d/d-frontend.cc b/gcc/d/d-frontend.cc index 84c70f8ee6a..30fc6d435d0 100644 --- a/gcc/d/d-frontend.cc +++ b/gcc/d/d-frontend.cc @@ -185,39 +185,8 @@ eval_builtin (Loc loc, FuncDeclaration *fd, Expressions *arguments) Type * getTypeInfoType (Loc loc, Type *type, Scope *sc) { - if (!global.params.useTypeInfo) - { - /* Even when compiling without RTTI we should still be able to evaluate - TypeInfo at compile-time, just not at run-time. */ - if (!sc || !(sc->flags & SCOPEctfe)) - { - static int warned = 0; - - if (!warned) - { - error_at (make_location_t (loc), - "% cannot be used with %<-fno-rtti%>"); - warned = 1; - } - } - } - - if (Type::dtypeinfo == NULL - || (Type::dtypeinfo->storage_class & STCtemp)) - { - /* If TypeInfo has not been declared, warn about each location once. */ - static Loc warnloc; - - if (!loc.equals (warnloc)) - { - error_at (make_location_t (loc), - "% could not be found, " - "but is implicitly used"); - warnloc = loc; - } - } - gcc_assert (type->ty != Terror); + check_typeinfo_type (loc, sc); create_typeinfo (type, sc ? sc->_module->importedFrom : NULL); return type->vtinfo->type; } diff --git a/gcc/d/d-tree.h b/gcc/d/d-tree.h index bb731a60541..6ef9af2a991 100644 --- a/gcc/d/d-tree.h +++ b/gcc/d/d-tree.h @@ -670,6 +670,7 @@ extern tree layout_classinfo (ClassDeclaration *); extern unsigned base_vtable_offset (ClassDeclaration *, BaseClass *); extern tree get_typeinfo_decl (TypeInfoDeclaration *); extern tree get_classinfo_decl (ClassDeclaration *); +extern void check_typeinfo_type (const Loc &, Scope *); extern tree build_typeinfo (const Loc &, Type *); extern void create_typeinfo (Type *, Module *); extern void create_tinfo_types (Module *); diff --git a/gcc/d/typeinfo.cc b/gcc/d/typeinfo.cc index 503480b491d..9d6464deb07 100644 --- a/gcc/d/typeinfo.cc +++ b/gcc/d/typeinfo.cc @@ -27,6 +27,7 @@ along with GCC; see the file COPYING3. If not see #include "dmd/identifier.h" #include "dmd/module.h" #include "dmd/mtype.h" +#include "dmd/scope.h" #include "dmd/template.h" #include "dmd/target.h" @@ -244,8 +245,8 @@ create_tinfo_types (Module *mod) static void create_frontend_tinfo_types (void) { - /* If there's no Object class defined, then neither can TypeInfo be. */ - if (object_module == NULL || ClassDeclaration::object == NULL) + /* If there's no object module, then neither can there be TypeInfo. */ + if (object_module == NULL) return; /* Create all frontend TypeInfo classes declarations. We rely on all @@ -1373,16 +1374,19 @@ get_classinfo_decl (ClassDeclaration *decl) return decl->csym; } -/* Returns typeinfo reference for TYPE. */ +/* Performs sanity checks on the `object.TypeInfo' type, raising an error if + RTTI is disabled, or the type is missing. */ -tree -build_typeinfo (const Loc &loc, Type *type) +void +check_typeinfo_type (const Loc &loc, Scope *sc) { if (!global.params.useTypeInfo) { static int warned = 0; - if (!warned) + /* Even when compiling without RTTI we should still be able to evaluate + TypeInfo at compile-time, just not at run-time. */ + if (!warned && (!sc || !(sc->flags & SCOPEctfe))) { error_at (make_location_t (loc), "% cannot be used with %<-fno-rtti%>"); @@ -1390,7 +1394,29 @@ build_typeinfo (const Loc &loc, Type *type) } } + if (Type::dtypeinfo == NULL + || (Type::dtypeinfo->storage_class & STCtemp)) + { + /* If TypeInfo has not been declared, warn about each location once. */ + static Loc warnloc; + + if (!warnloc.equals (loc)) + { + error_at (make_location_t (loc), + "% could not be found, " + "but is implicitly used"); + warnloc = loc; + } + } +} + +/* Returns typeinfo reference for TYPE. */ + +tree +build_typeinfo (const Loc &loc, Type *type) +{ gcc_assert (type->ty != Terror); + check_typeinfo_type (loc, NULL); create_typeinfo (type, NULL); return build_address (get_typeinfo_decl (type->vtinfo)); } diff --git a/gcc/testsuite/gdc.dg/pr100967.d b/gcc/testsuite/gdc.dg/pr100967.d new file mode 100644 index 00000000000..582ad582676 --- /dev/null +++ b/gcc/testsuite/gdc.dg/pr100967.d @@ -0,0 +1,11 @@ +// 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" } + +extern(C) int main() +{ + int[int] aa; + aa[0] = 1; // { dg-error ".object.TypeInfo. could not be found, but is implicitly used" } + return 0; +}