From patchwork Tue Jun 16 21:59:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 1310729 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=iHAQGmaU; 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 49mhwB47kCz9sRk for ; Wed, 17 Jun 2020 08:00:42 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 96E7D388C037; Tue, 16 Jun 2020 22:00:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 96E7D388C037 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1592344827; bh=P8vuVgKGDj35cq8UThdMuyr4xw2X1qOg/8JFszVRQUw=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=iHAQGmaUolzZmb5Ogk+NDSOAFCIvKxj5GWVSPj+EOf65I2kd/HKpCuatIY31CWUMA MG4/kyuv8/+MCZkj1MNKse93QARN0CWZnhslXeTxMRXov23pnsS4eLI9namTxNakwx fSmbPtXd/8dJ4JZx0477zXSh2QHF0Q8oiZ5fvz7o= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [IPv6:2001:67c:2050::465:101]) by sourceware.org (Postfix) with ESMTPS id 7AFAE388A80D for ; Tue, 16 Jun 2020 22:00:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 7AFAE388A80D Received: from smtp2.mailbox.org (smtp2.mailbox.org [80.241.60.241]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 49mhvp3g1vzKmt6; Wed, 17 Jun 2020 00:00:22 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by spamfilter03.heinlein-hosting.de (spamfilter03.heinlein-hosting.de [80.241.56.117]) (amavisd-new, port 10030) with ESMTP id fs7A9TxO63qz; Wed, 17 Jun 2020 00:00:19 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [committed] d: Use toTypeFunction instead of explicit cast Date: Tue, 16 Jun 2020 23:59:33 +0200 Message-Id: <20200616215933.3858164-10-ibuclaw@gdcproject.org> In-Reply-To: <20200616215933.3858164-1-ibuclaw@gdcproject.org> References: <20200616215933.3858164-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 655FB1731 X-Rspamd-Score: 1.79 / 15.00 / 15.00 X-Spam-Status: No, score=-16.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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@gcc.gnu.org Sender: "Gcc-patches" Hi, This patch replaces uses of casting to TypeFunction with toTypeFunction, which takes care of asserting that `ty' is a `Tfunction'. Bootstrapped and regression tested on x86_64-linux-gnu, and committed to master. Regards Iain gcc/d/ChangeLog: * d-frontend.cc (eval_builtin): Use toTypeFunction instead of cast. * decl.cc (DeclVisitor::visit): Likewise. * toir.cc (IRVisitor::visit): Likewise. * typeinfo.cc (TypeInfoVisitor::visit): Likewise. --- gcc/d/d-frontend.cc | 2 +- gcc/d/decl.cc | 28 ++++++++-------------------- gcc/d/toir.cc | 2 +- gcc/d/typeinfo.cc | 3 +-- 4 files changed, 11 insertions(+), 24 deletions(-) diff --git a/gcc/d/d-frontend.cc b/gcc/d/d-frontend.cc index 5415d471ef4..7434819d644 100644 --- a/gcc/d/d-frontend.cc +++ b/gcc/d/d-frontend.cc @@ -177,7 +177,7 @@ eval_builtin (Loc loc, FuncDeclaration *fd, Expressions *arguments) gcc_assert (fndecl_built_in_p (decl) || DECL_INTRINSIC_CODE (decl) != INTRINSIC_NONE); - TypeFunction *tf = (TypeFunction *) fd->type; + TypeFunction *tf = fd->type->toTypeFunction (); Expression *e = NULL; input_location = make_location_t (loc); diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc index 05868631eed..a6144f7c269 100644 --- a/gcc/d/decl.cc +++ b/gcc/d/decl.cc @@ -449,26 +449,14 @@ public: if (fd->leastAsSpecialized (fd2) || fd2->leastAsSpecialized (fd)) { - TypeFunction *tf = (TypeFunction *) fd->type; - if (tf->ty == Tfunction) - { - error_at (make_location_t (fd->loc), "use of %qs", - fd->toPrettyChars ()); - inform (make_location_t (fd2->loc), "is hidden by %qs", - fd2->toPrettyChars ()); - inform (make_location_t (d->loc), - "use % to introduce base class " - "overload set", fd->toChars (), - fd->parent->toChars (), fd->toChars ()); - } - else - { - error_at (make_location_t (fd->loc), "use of %qs", - fd->toPrettyChars ()); - inform (make_location_t (fd2->loc), "is hidden by %qs", - fd2->toPrettyChars ()); - } - + error_at (make_location_t (fd->loc), "use of %qs", + fd->toPrettyChars ()); + inform (make_location_t (fd2->loc), "is hidden by %qs", + fd2->toPrettyChars ()); + inform (make_location_t (d->loc), + "use % to introduce base class " + "overload set", fd->toChars (), + fd->parent->toChars (), fd->toChars ()); has_errors = true; break; } diff --git a/gcc/d/toir.cc b/gcc/d/toir.cc index 92d0ecdb0a0..d8a14efd667 100644 --- a/gcc/d/toir.cc +++ b/gcc/d/toir.cc @@ -1006,7 +1006,7 @@ public: return; } - TypeFunction *tf = (TypeFunction *)this->func_->type; + TypeFunction *tf = this->func_->type->toTypeFunction (); Type *type = this->func_->tintro != NULL ? this->func_->tintro->nextOf () : tf->nextOf (); diff --git a/gcc/d/typeinfo.cc b/gcc/d/typeinfo.cc index 73443eaed50..f3051d3e122 100644 --- a/gcc/d/typeinfo.cc +++ b/gcc/d/typeinfo.cc @@ -1045,8 +1045,7 @@ public: if (sd->xhash) { - TypeFunction *tf = (TypeFunction *) sd->xhash->type; - gcc_assert (tf->ty == Tfunction); + TypeFunction *tf = sd->xhash->type->toTypeFunction (); if (!tf->isnothrow || tf->trust == TRUSTsystem) { warning (sd->xhash->loc, "toHash() must be declared as "