From patchwork Thu Jun 8 09:16:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 772926 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 3wk0D0159dz9s76 for ; Thu, 8 Jun 2017 19:16:31 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="eSWFyk2G"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=bNibYNS1PeZlS5fIKeTmZdEh9CH03vYWgFEpyKmzNSpAPaphsKxV+ 3f7lvYY0mSUnEE/hUGh5BdDq7KRdLFUf7EMa31536Rh317xdavLL0VDCBi2ejRTY sBIzIHE6IwO5Vr6w+G1OPuUGsa76e69De9pDHHMNFXBF4TBywgw5hg= 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:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=av/qck3fUtWjgw+RGojDyEb3rWg=; b=eSWFyk2GdbwqE8QwLs2t 3xLrkb06DKbEdRCwUyqviFeseqwLN2p5H/Ez1yve6wQikGyTHbWrsipZuFhIvjm5 uNYksK22UnVw8bsJgFijUtybSNkRiKpSgvZ/s1yYRe5tXBZflllasv2OZKdEuBbx PXht+BNKslNR6iAsasYfO74= Received: (qmail 97869 invoked by alias); 8 Jun 2017 09:16:07 -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 97511 invoked by uid 89); 8 Jun 2017 09:16:06 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 08 Jun 2017 09:16:05 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 56542AAB6 for ; Thu, 8 Jun 2017 09:16:07 +0000 (UTC) Date: Thu, 8 Jun 2017 11:16:07 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix PR81007 Message-ID: User-Agent: Alpine 2.20 (LSU 67 2015-01-07) MIME-Version: 1.0 Folding during gimplification can invoke the devirt machinery which doesn't deal with errorneous state. Thus avoid ICEing by not folding from gimplification in case we've seen errors. Similarly do not build cgraph edges in those cases as that invokes the devirt machinery as well (we stop compilation after lowering anyway in case errors were reported). The patch also fixes ordering of passes. Bootstrap and regtest running on x86_64-unknown-linux-gnu. Richard. 2017-06-08 Richard Biener PR middle-end/81007 * gimplify.c (maybe_fold_stmt): Do not fold after errors. * cgraphbuild.c: Include diagnostic-core.h. (pass_build_cgraph_edges::gate): Add, do not run after errors. * passes.def (all_lowering_passes): Run pass_build_cgraph_edges last again. * g++.dg/pr81007.C: New testcase. Index: gcc/gimplify.c =================================================================== --- gcc/gimplify.c (revision 249003) +++ gcc/gimplify.c (working copy) @@ -3067,6 +3067,10 @@ gimplify_arg (tree *arg_p, gimple_seq *p static bool maybe_fold_stmt (gimple_stmt_iterator *gsi) { + /* Do not fold if we may have invalid IL somewhere. */ + if (seen_error ()) + return false; + struct gimplify_omp_ctx *ctx; for (ctx = gimplify_omp_ctxp; ctx; ctx = ctx->outer_context) if ((ctx->region_type & (ORT_TARGET | ORT_PARALLEL | ORT_TASK)) != 0) Index: gcc/cgraphbuild.c =================================================================== --- gcc/cgraphbuild.c (revision 249003) +++ gcc/cgraphbuild.c (working copy) @@ -31,6 +31,7 @@ along with GCC; see the file COPYING3. #include "gimple-walk.h" #include "ipa-utils.h" #include "except.h" +#include "diagnostic-core.h" /* Context of record_reference. */ struct record_reference_ctx @@ -305,6 +306,7 @@ public: /* opt_pass methods: */ virtual unsigned int execute (function *); + virtual bool gate (function *) { return ! seen_error (); } }; // class pass_build_cgraph_edges unsigned int Index: gcc/passes.def =================================================================== --- gcc/passes.def (revision 249003) +++ gcc/passes.def (working copy) @@ -42,9 +42,9 @@ along with GCC; see the file COPYING3. NEXT_PASS (pass_build_cfg); NEXT_PASS (pass_warn_function_return); NEXT_PASS (pass_expand_omp); - NEXT_PASS (pass_build_cgraph_edges); NEXT_PASS (pass_sprintf_length, false); NEXT_PASS (pass_walloca, /*strict_mode_p=*/true); + NEXT_PASS (pass_build_cgraph_edges); TERMINATE_PASS_LIST (all_lowering_passes) /* Interprocedural optimization passes. */ Index: gcc/testsuite/g++.dg/pr81007.C =================================================================== --- gcc/testsuite/g++.dg/pr81007.C (nonexistent) +++ gcc/testsuite/g++.dg/pr81007.C (working copy) @@ -0,0 +1,14 @@ +// { dg-do compile } + +struct A +{ + A p; // { dg-error "incomplete" } + virtual void foo(); +}; + +struct B : A {}; + +void bar(B& b) +{ + b.foo(); +}