From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 38520 invoked by alias); 30 Nov 2017 22:55:49 -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 38510 invoked by uid 89); 30 Nov 2017 22:55:48 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.7 required=5.0 tests=BAYES_00,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY,KB_WAM_FROM_NAME_SINGLEWORD,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; Thu, 30 Nov 2017 22:55:47 +0000 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 585DC6868E; Thu, 30 Nov 2017 22:55:46 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-77.ams2.redhat.com [10.36.116.77]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F107B5C550; Thu, 30 Nov 2017 22:55:45 +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 vAUMthTa028765; Thu, 30 Nov 2017 23:55:43 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id vAUMtggc028764; Thu, 30 Nov 2017 23:55:42 +0100 Date: Thu, 30 Nov 2017 23:01:00 -0000 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix -Wreturn-type with switches (PR sanitizer/81275) Message-ID: <20171130225542.GP2353@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.7.1 (2016-10-04) X-IsSubscribed: yes X-SW-Source: 2017-11/txt/msg02629.txt.bz2 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? 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) /* Discard cases that have an unreachable destination block. */ if (EDGE_COUNT (base_bb->succs) == 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))) + != BUILTINS_LOCATION))) { edge base_edge = find_edge (gimple_bb (stmt), base_bb); if (base_edge != 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=thread" } */ -/* { dg-skip-if "" { c++ } { "*" } { "-O0" } } */ int f1 (int a, int b) Jakub