From patchwork Wed Jan 17 20:10:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 862587 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-471523-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="dGtBthRI"; 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 3zMJB66rmfz9t6C for ; Thu, 18 Jan 2018 07:10:54 +1100 (AEDT) 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:cc:subject:message-id:reply-to:mime-version :content-type; q=dns; s=default; b=fBb7Vavbs7mBd+4oAG2CCB/uLHfEz XDBThHfZt9FXpon7e0kZHP4HoO1oPG1dEaq7WUqdHJynzKSxHf1yK4TaueYY6trF zi4iOctnYHh21xzGLvmrd8G50S6flks/tnQBHyISfxMoAkA1bF3HKFxsigWnnczA C0zyGSg6rky1Ac= 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:cc:subject:message-id:reply-to:mime-version :content-type; s=default; bh=IrPw7EPQCDGPcKmz5qGia/jKjTY=; b=dGt BthRIiIf8lqCv58yJlWiL3D8ewszR0eBAgVb/hDAAM/LYLlRSkluED71+avKT810 KXofICXOECrOj2JMThvnK9bcvZM0oi4KFg7v+rn1hgenJ+MkjhJlSzDrbc6wVFTt ymxyDODTAhb7lfclq7xP7ipuRt89ub7cVlEuk+uw= Received: (qmail 33494 invoked by alias); 17 Jan 2018 20:10:47 -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 33453 invoked by uid 89); 17 Jan 2018 20:10:46 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.9 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 17 Jan 2018 20:10:45 +0000 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D203F78540; Wed, 17 Jan 2018 20:10:43 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-117-22.ams2.redhat.com [10.36.117.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6206518102; Wed, 17 Jan 2018 20:10:43 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id w0HKAfol020190; Wed, 17 Jan 2018 21:10:41 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id w0HKAeZD019259; Wed, 17 Jan 2018 21:10:40 +0100 Date: Wed, 17 Jan 2018 21:10:40 +0100 From: Jakub Jelinek To: Jason Merrill , Nathan Sidwell Cc: gcc-patches@gcc.gnu.org Subject: [C++ PATCH] Avoid appending a useless __builtin_unreachable in functions which do return (PR c++/83897) Message-ID: <20180117201040.GY2063@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.1 (2017-09-22) X-IsSubscribed: yes Hi! I've noticed several testcases recently that have a dead __builtin_unreachable call in functions right after return stmt. They are optimized away after a while (typically in the cfg pass), but we don't really need to generate them when there is the return. The reason we don't find it is because it is wrapped in some cases in CLEANUP_POINT_EXPR. That doesn't change anything on the function actually ending with a return. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2018-01-17 Jakub Jelinek PR c++/83897 * cp-gimplify.c (cp_maybe_instrument_return): Handle CLEANUP_POINT_EXPR. * g++.dg/cpp0x/pr83897.C: New test. Jakub --- gcc/cp/cp-gimplify.c.jj 2018-01-11 18:58:48.348391787 +0100 +++ gcc/cp/cp-gimplify.c 2018-01-16 17:24:41.087336680 +0100 @@ -1581,6 +1581,7 @@ cp_maybe_instrument_return (tree fndecl) t = BIND_EXPR_BODY (t); continue; case TRY_FINALLY_EXPR: + case CLEANUP_POINT_EXPR: t = TREE_OPERAND (t, 0); continue; case STATEMENT_LIST: --- gcc/testsuite/g++.dg/cpp0x/pr83897.C.jj 2018-01-16 17:41:54.723256147 +0100 +++ gcc/testsuite/g++.dg/cpp0x/pr83897.C 2018-01-16 17:41:34.274257947 +0100 @@ -0,0 +1,13 @@ +// PR c++/83897 +// { dg-do compile { target c++11 } } +// { dg-options "-O2 -fdump-tree-gimple" } +// { dg-final { scan-tree-dump-not "__builtin_unreachable" "gimple" } } + +struct A {}; +struct B { int a; int b = 5; }; + +A +bar (B) +{ + return {}; +}