From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 39026 invoked by alias); 1 Dec 2017 07:06:33 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 39014 invoked by uid 89); 1 Dec 2017 07:06:32 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.7 required=5.0 tests=BAYES_00,GIT_PATCH_2,GIT_PATCH_3,KB_WAM_FROM_NAME_SINGLEWORD,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 01 Dec 2017 07:06:31 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 56624ADEA; Fri, 1 Dec 2017 07:06:28 +0000 (UTC) Date: Fri, 01 Dec 2017 07:06:00 -0000 User-Agent: K-9 Mail for Android In-Reply-To: <20171130225542.GP2353@tucnak> References: <20171130225542.GP2353@tucnak> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PATCH] Fix -Wreturn-type with switches (PR sanitizer/81275) To: Jakub Jelinek CC: gcc-patches@gcc.gnu.org From: Richard Biener Message-ID: X-SW-Source: 2017-12/txt/msg00021.txt.bz2 On November 30, 2017 11:55:42 PM GMT+01:00, Jakub Jelinek wrote: >Hi! > >Now that the C++ FE emits __builtin_unreachable with BUILTINS_LOCATION >for fallthrough into end of function without returning value, we need >to >see those in the warn_function_return pass which is right after >building >cfg. While GIMPLE_CONDs conditionally jumping to __builtin_unreachable >are >only optimized during evrp and later, GIMPLE_SWITCH cases that branch >to >__builtin_unreachable are unfortunately removed already during the cfg >cleanup in the cfg pass and thus the immediately following >warn_function_return pass can't warn. Fixed by postponing that, e.g. >the evrp pass does unconditional TODO_cleanup_cfg, so those will be >optimized away pretty early (often already during ccp1). > >Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? OK.=20 Richard.=20 >2017-11-30 Jakub Jelinek > > PR sanitizer/81275 > * tree-cfg.c (group_case_labels_stmt): Don't optimize away > C++ FE implicitly added __builtin_unreachable () until -Wreturn-type > is diagnosed. > > * c-c++-common/tsan/pr81275.c: New test. > >--- gcc/tree-cfg.c.jj 2017-11-30 11:40:38.000000000 +0100 >+++ gcc/tree-cfg.c 2017-11-30 12:01:39.496311219 +0100 >@@ -1750,7 +1750,14 @@ group_case_labels_stmt (gswitch *stmt) >=20 > /* Discard cases that have an unreachable destination block. */ > if (EDGE_COUNT (base_bb->succs) =3D=3D 0 >- && gimple_seq_unreachable_p (bb_seq (base_bb))) >+ && gimple_seq_unreachable_p (bb_seq (base_bb)) >+ /* Don't optimize this if __builtin_unreachable () is the >+ implicitly added one by the C++ FE too early, before >+ -Wreturn-type can be diagnosed. We'll optimize it later >+ during switchconv pass or any other cfg cleanup. */ >+ && (gimple_in_ssa_p (cfun) >+ || (LOCATION_LOCUS (gimple_location (last_stmt (base_bb))) >+ !=3D BUILTINS_LOCATION))) > { > edge base_edge =3D find_edge (gimple_bb (stmt), base_bb); > if (base_edge !=3D NULL) >--- gcc/testsuite/c-c++-common/tsan/pr81275.c.jj 2017-11-28 >22:23:34.000000000 +0100 >+++ gcc/testsuite/c-c++-common/tsan/pr81275.c 2017-11-30 >11:50:56.185274379 +0100 >@@ -1,7 +1,6 @@ > /* PR sanitizer/81275 */ > /* { dg-do compile } */ > /* { dg-options "-Wreturn-type -fsanitize=3Dthread" } */ >-/* { dg-skip-if "" { c++ } { "*" } { "-O0" } } */ >=20 > int > f1 (int a, int b) > > Jakub