From patchwork Sun Apr 21 07:17:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 1088445 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-499517-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=quarantine dis=none) header.from=gdcproject.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="SdzWwtxV"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44n1J52Rr9z9s3l for ; Sun, 21 Apr 2019 17:17:41 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; q= dns; s=default; b=YW7IkTxq5j+kMktFKk64QgX7Peesj2h5lwE6dtUwUZ8xIM EPskuZdob0HeYGzNY/+j+c4nxURFE6rvQ4E+uoA3KE9/OTz8HQTbXf5YuI6cWlmJ phtJJDGW8ntnUqTLJn8UeXYioKf6ik9/PDt4iPsYdZPJdiMC43U7ZdGlhJsb0= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; s= default; bh=WaejY9gJS2wQgTtg4QECcZc8cKg=; b=SdzWwtxVBsasPX4i3Sq5 n0t60o1AyCA8YgIdUGa7jPcRgG+hrcjegf0BWiGhgJfCMeRnIcp60/3T3Q39S7gG 3xcxCm1BfZ0MpwzS5IIu//pRRzv0GCKL+ubbdyijkv74bCqix03zsz+5bGN277wu DByovfqAg0NLn8vJFDnC0D4= Received: (qmail 72600 invoked by alias); 21 Apr 2019 07:17:34 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 72591 invoked by uid 89); 21 Apr 2019 07:17:34 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-19.2 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=visitor, back-end, decl_initial, DECL_INITIAL X-HELO: mail-qt1-f171.google.com Received: from mail-qt1-f171.google.com (HELO mail-qt1-f171.google.com) (209.85.160.171) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 21 Apr 2019 07:17:33 +0000 Received: by mail-qt1-f171.google.com with SMTP id p20so9290369qtc.9 for ; Sun, 21 Apr 2019 00:17:32 -0700 (PDT) MIME-Version: 1.0 From: Iain Buclaw Date: Sun, 21 Apr 2019 09:17:19 +0200 Message-ID: Subject: [PATCH, d] Committed use guard to prevent declaration pass from running multiple times To: gcc-patches X-IsSubscribed: yes Hi, This patch adds checks for semanticRun in the Declaration visitor passes. While it shouldn't happen during normal traversal of the AST provided from the front-end, there are some cases where declarations need to be visited out of order, such as what is being done in PR d/89017, it then becomes necessary to guard against this. Regression tested on x86_64-linux-gnu. Committed to trunk as r270478. diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc index fffed97727f..84c17ab36f7 100644 --- a/gcc/d/decl.cc +++ b/gcc/d/decl.cc @@ -147,6 +147,9 @@ public: void visit (Import *d) { + if (d->semanticRun >= PASSobj) + return; + /* Implements import declarations by telling the debug back-end we are importing the NAMESPACE_DECL of the module or IMPORTED_DECL of the declaration into the current lexical scope CONTEXT. NAME is set if @@ -188,6 +191,8 @@ public: debug_hooks->imported_module_or_decl (decl, name, context, false, false); } + + d->semanticRun = PASSobj; } /* Expand any local variables found in tuples. */ @@ -325,6 +330,9 @@ public: void visit (StructDeclaration *d) { + if (d->semanticRun >= PASSobj) + return; + if (d->type->ty == Terror) { error_at (make_location_t (d->loc), @@ -376,6 +384,8 @@ public: if (d->xhash) d->xhash->accept (this); + + d->semanticRun = PASSobj; } /* Finish semantic analysis of functions in vtbl for class CD. */ @@ -453,6 +463,9 @@ public: void visit (ClassDeclaration *d) { + if (d->semanticRun >= PASSobj) + return; + if (d->type->ty == Terror) { error_at (make_location_t (d->loc), @@ -518,6 +531,8 @@ public: tree ctype = TREE_TYPE (build_ctype (d->type)); if (TYPE_NAME (ctype)) d_pushdecl (TYPE_NAME (ctype)); + + d->semanticRun = PASSobj; } /* Write out compiler generated TypeInfo and vtables for the given interface @@ -525,6 +540,9 @@ public: void visit (InterfaceDeclaration *d) { + if (d->semanticRun >= PASSobj) + return; + if (d->type->ty == Terror) { error_at (make_location_t (d->loc), @@ -557,6 +575,8 @@ public: tree ctype = TREE_TYPE (build_ctype (d->type)); if (TYPE_NAME (ctype)) d_pushdecl (TYPE_NAME (ctype)); + + d->semanticRun = PASSobj; } /* Write out compiler generated TypeInfo and initializer for the given @@ -606,6 +626,9 @@ public: void visit (VarDeclaration *d) { + if (d->semanticRun >= PASSobj) + return; + if (d->type->ty == Terror) { error_at (make_location_t (d->loc), @@ -731,6 +754,8 @@ public: } } } + + d->semanticRun = PASSobj; } /* Generate and compile a static TypeInfo declaration, but only if it is @@ -738,12 +763,16 @@ public: void visit (TypeInfoDeclaration *d) { + if (d->semanticRun >= PASSobj) + return; + if (speculative_type_p (d->tinfo)) return; tree t = get_typeinfo_decl (d); DECL_INITIAL (t) = layout_typeinfo (d); d_finish_decl (t); + d->semanticRun = PASSobj; } /* Finish up a function declaration and compile it all the way