[{"id":1767664,"web_url":"http://patchwork.ozlabs.org/comment/1767664/","msgid":"<alpine.LSU.2.20.1709131011240.26836@zhemvz.fhfr.qr>","list_archive_url":null,"date":"2017-09-13T08:12:05","subject":"Re: [PATCH] Fix PR82128","submitter":{"id":4338,"url":"http://patchwork.ozlabs.org/api/people/4338/","name":"Richard Biener","email":"rguenther@suse.de"},"content":"On Tue, 12 Sep 2017, Richard Biener wrote:\n\n> \n> This is the one with the folding fix...\n\nAnd it didn't work out (the comment before the changed line even\nexplains...).  Thus I'll do the following.\n\nBootstrapped and tested on x86_64-unknown-linux-gnu, applied.\n\nRichard.\n\n2017-09-13  Richard Biener  <rguenther@suse.de>\n\n\tPR middle-end/82128\n\t* gimple-fold.c (gimple_fold_call): Update SSA name in-place to\n\tdefault-def to avoid breaking iterator update with the weird\n\tinteraction with cgraph_update_edges_for_call_stmt_node.\n\n\t* g++.dg/pr82128.C: New testcase.\n\nIndex: gcc/gimple-fold.c\n===================================================================\n--- gcc/gimple-fold.c\t(revision 252060)\n+++ gcc/gimple-fold.c\t(working copy)\n@@ -3862,24 +3862,18 @@ gimple_fold_call (gimple_stmt_iterator *\n \t\t  tree fndecl = builtin_decl_implicit (BUILT_IN_UNREACHABLE);\n \t\t  gimple *new_stmt = gimple_build_call (fndecl, 0);\n \t\t  gimple_set_location (new_stmt, gimple_location (stmt));\n+\t\t  /* If the call had a SSA name as lhs morph that into\n+\t\t     an uninitialized value.  */\n \t\t  if (lhs && TREE_CODE (lhs) == SSA_NAME)\n \t\t    {\n \t\t      tree var = create_tmp_var (TREE_TYPE (lhs));\n-\t\t      tree def = get_or_create_ssa_default_def (cfun, var);\n-\n-\t\t      /* To satisfy condition for\n-\t\t\t cgraph_update_edges_for_call_stmt_node,\n-\t\t\t we need to preserve GIMPLE_CALL statement\n-\t\t\t at position of GSI iterator.  */\n-\t\t      update_call_from_tree (gsi, def);\n-\t\t      gsi_insert_before (gsi, new_stmt, GSI_NEW_STMT);\n-\t\t    }\n-\t\t  else\n-\t\t    {\n-\t\t      gimple_set_vuse (new_stmt, gimple_vuse (stmt));\n-\t\t      gimple_set_vdef (new_stmt, gimple_vdef (stmt));\n-\t\t      gsi_replace (gsi, new_stmt, false);\n+\t\t      SET_SSA_NAME_VAR_OR_IDENTIFIER (lhs, var);\n+\t\t      SSA_NAME_DEF_STMT (lhs) = gimple_build_nop ();\n+\t\t      set_ssa_default_def (cfun, var, lhs);\n \t\t    }\n+\t\t  gimple_set_vuse (new_stmt, gimple_vuse (stmt));\n+\t\t  gimple_set_vdef (new_stmt, gimple_vdef (stmt));\n+\t\t  gsi_replace (gsi, new_stmt, false);\n \t\t  return true;\n \t\t}\n \t    }\nIndex: gcc/testsuite/g++.dg/pr82128.C\n===================================================================\n--- gcc/testsuite/g++.dg/pr82128.C\t(revision 0)\n+++ gcc/testsuite/g++.dg/pr82128.C\t(working copy)\n@@ -0,0 +1,20 @@\n+// { dg-do compile }\n+// { dg-options \"-O3 -fno-tree-forwprop\" }\n+\n+class A {\n+      virtual unsigned long m_fn1() const;\n+        virtual int &m_fn2(unsigned long) const;\n+};\n+class C : A {\n+public:\n+      int &m_fn2(unsigned long) const;\n+        unsigned long m_fn1() const;\n+};\n+class B {\n+      void m_fn3(const A &, const int &, const C &, int &) const;\n+};\n+void B::m_fn3(const A &, const int &, const C &, int &) const {\n+      C &a(a);\n+        for (long b = 0; a.m_fn1(); b++)\n+\t      a.m_fn2(0);\n+}","headers":{"Return-Path":"<gcc-patches-return-462001-incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","mailing list gcc-patches@gcc.gnu.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org\n\t(client-ip=209.132.180.131; helo=sourceware.org;\n\tenvelope-from=gcc-patches-return-462001-incoming=patchwork.ozlabs.org@gcc.gnu.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tunprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org\n\theader.b=\"Vdi+9q45\"; dkim-atps=neutral","sourceware.org; auth=none"],"Received":["from sourceware.org (server1.sourceware.org [209.132.180.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xsZCD6FJRz9sPm\n\tfor <incoming@patchwork.ozlabs.org>;\n\tWed, 13 Sep 2017 18:12:24 +1000 (AEST)","(qmail 91817 invoked by alias); 13 Sep 2017 08:12:15 -0000","(qmail 85340 invoked by uid 89); 13 Sep 2017 08:12:11 -0000","from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by\n\tsourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP;\n\tWed, 13 Sep 2017 08:12:08 +0000","from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254])\tby\n\tmx1.suse.de (Postfix) with ESMTP id 6FDEEABED\tfor\n\t<gcc-patches@gcc.gnu.org>; Wed, 13 Sep 2017 08:12:06 +0000 (UTC)"],"DomainKey-Signature":"a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender:date\n\t:from:to:subject:in-reply-to:message-id:references:mime-version\n\t:content-type; q=dns; s=default; b=nZGS6K4JjypedHwoV/cKJhMMKO5fP\n\tpjOjXM/gj677KUHtnMpgDCHhYuuDAaKHYcqLss+RZCJ/HyFUdE3U0YEpr540QutK\n\tMGtpK/ciykAyFWMzmvQ7I+cKZHxvMLFIGM/Ay/1rFLirnk99uRl5GHxEKxu6sRec\n\tNzCVjFHVGj+vmM=","DKIM-Signature":"v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender:date\n\t:from:to:subject:in-reply-to:message-id:references:mime-version\n\t:content-type; s=default; bh=PHn81OjnovfOuETvjcgTvzaHIJ4=; b=Vdi\n\t+9q45furXcOJBjliPfUEgcggpx095Jm+/ts8Tkr9QxNICVN2psdE+mp+uwBFfGGT\n\tBXzgIyE47zPUYyN3066qk9OHj/IyQuqAaN5IvODzuzSXAr+wAgQKkqSCCY3t1jxj\n\trITX6YA+n8WLXYnusD9mCID9NAQNbgk++Vlqjv88=","Mailing-List":"contact gcc-patches-help@gcc.gnu.org; run by ezmlm","Precedence":"bulk","List-Id":"<gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<mailto:gcc-patches-unsubscribe-incoming=patchwork.ozlabs.org@gcc.gnu.org>","List-Archive":"<http://gcc.gnu.org/ml/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-help@gcc.gnu.org>","Sender":"gcc-patches-owner@gcc.gnu.org","X-Virus-Found":"No","X-Spam-SWARE-Status":"No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_2,\n\tGIT_PATCH_3, KAM_ASCII_DIVIDERS, RP_MATCHES_RCVD,\n\tSPF_PASS autolearn=ham version=3.3.2 spammy=","X-HELO":"mx1.suse.de","Date":"Wed, 13 Sep 2017 10:12:05 +0200 (CEST)","From":"Richard Biener <rguenther@suse.de>","To":"gcc-patches@gcc.gnu.org","Subject":"Re: [PATCH] Fix PR82128","In-Reply-To":"<alpine.LSU.2.20.1709121548590.26836@zhemvz.fhfr.qr>","Message-ID":"<alpine.LSU.2.20.1709131011240.26836@zhemvz.fhfr.qr>","References":"<alpine.LSU.2.20.1709121548590.26836@zhemvz.fhfr.qr>","User-Agent":"Alpine 2.20 (LSU 67 2015-01-07)","MIME-Version":"1.0","Content-Type":"text/plain; charset=US-ASCII"}}]