From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 118935 invoked by alias); 2 Dec 2017 00:14:16 -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 118879 invoked by uid 89); 2 Dec 2017 00:14:16 -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_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; Sat, 02 Dec 2017 00:14:14 +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 84AA181DE5; Sat, 2 Dec 2017 00:14:13 +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 2A60E60C90; Sat, 2 Dec 2017 00:14:13 +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 vB20EA7w027542; Sat, 2 Dec 2017 01:14:11 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id vB20EAxs027541; Sat, 2 Dec 2017 01:14:10 +0100 Date: Sat, 02 Dec 2017 00:14:00 -0000 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix -Wreturn-type with -fsanitize=return (PR c++/81212) Message-ID: <20171202001410.GE2353@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-12/txt/msg00084.txt.bz2 Hi! With -fsanitize=return, we add __builtin_ubsan_handle_missing_return instead of __builtin_unreachable with BUILTINS_LOCATION locus, the following patch teaches warn function return pass to handle that too. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2017-12-01 Jakub Jelinek PR c++/81212 * tree-cfg.c (pass_warn_function_return::execute): Handle __builtin_ubsan_handle_missing_return like __builtin_unreachable with BUILTINS_LOCATION. * g++.dg/ubsan/pr81212.C: New test. * g++.dg/ubsan/return-1.C: Add -Wno-return-type to dg-options. * g++.dg/ubsan/return-2.C: Add -Wno-return-type to dg-options. * g++.dg/ubsan/return-7.C: Add -Wno-return-type to dg-options. --- gcc/tree-cfg.c.jj 2017-12-01 09:10:12.000000000 +0100 +++ gcc/tree-cfg.c 2017-12-01 19:38:21.933049446 +0100 @@ -9151,10 +9151,13 @@ pass_warn_function_return::execute (func if (EDGE_COUNT (bb->succs) == 0) { gimple *last = last_stmt (bb); + const enum built_in_function ubsan_missing_ret + = BUILT_IN_UBSAN_HANDLE_MISSING_RETURN; if (last - && (LOCATION_LOCUS (gimple_location (last)) - == BUILTINS_LOCATION) - && gimple_call_builtin_p (last, BUILT_IN_UNREACHABLE)) + && ((LOCATION_LOCUS (gimple_location (last)) + == BUILTINS_LOCATION + && gimple_call_builtin_p (last, BUILT_IN_UNREACHABLE)) + || gimple_call_builtin_p (last, ubsan_missing_ret))) { gimple_stmt_iterator gsi = gsi_for_stmt (last); gsi_prev_nondebug (&gsi); --- gcc/testsuite/g++.dg/ubsan/pr81212.C.jj 2017-12-01 19:30:43.251747933 +0100 +++ gcc/testsuite/g++.dg/ubsan/pr81212.C 2017-12-01 19:30:25.000000000 +0100 @@ -0,0 +1,16 @@ +// PR c++/81212 +// { dg-do compile } +// { dg-options "-Wreturn-type -fsanitize=return" } + +struct S +{ + S (void *); + void *s; +}; + +S +foo (bool x, void *y) +{ + if (x) + return S (y); +} // { dg-warning "control reaches end of non-void function" } --- gcc/testsuite/g++.dg/ubsan/return-1.C.jj 2013-11-22 21:05:59.000000000 +0100 +++ gcc/testsuite/g++.dg/ubsan/return-1.C 2017-12-01 22:23:17.053866660 +0100 @@ -1,5 +1,5 @@ // { dg-do run } -// { dg-options "-fsanitize=return" } +// { dg-options "-fsanitize=return -Wno-return-type" } // { dg-shouldfail "ubsan" } struct S { S (); ~S (); }; --- gcc/testsuite/g++.dg/ubsan/return-2.C.jj 2014-10-22 15:52:16.000000000 +0200 +++ gcc/testsuite/g++.dg/ubsan/return-2.C 2017-12-01 22:23:32.059679081 +0100 @@ -1,5 +1,5 @@ // { dg-do run } -// { dg-options "-fsanitize=return -fno-sanitize-recover=return" } +// { dg-options "-fsanitize=return -fno-sanitize-recover=return -Wno-return-type" } struct S { S (); ~S (); }; --- gcc/testsuite/g++.dg/ubsan/return-7.C.jj 2016-11-23 20:50:51.000000000 +0100 +++ gcc/testsuite/g++.dg/ubsan/return-7.C 2017-12-01 22:24:03.894281135 +0100 @@ -1,5 +1,5 @@ // { dg-do run } -// { dg-options "-fsanitize=undefined" } +// { dg-options "-fsanitize=undefined -Wno-return-type" } // { dg-shouldfail "ubsan" } struct S { S (); ~S (); }; Jakub