From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 70929 invoked by alias); 2 Dec 2017 07:54:08 -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 70919 invoked by uid 89); 2 Dec 2017 07:54:08 -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; Sat, 02 Dec 2017 07:54:06 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id BA622ADD8; Sat, 2 Dec 2017 07:54:04 +0000 (UTC) Date: Sat, 02 Dec 2017 07:54:00 -0000 User-Agent: K-9 Mail for Android In-Reply-To: <20171202001410.GE2353@tucnak> References: <20171202001410.GE2353@tucnak> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PATCH] Fix -Wreturn-type with -fsanitize=return (PR c++/81212) To: Jakub Jelinek CC: gcc-patches@gcc.gnu.org From: Richard Biener Message-ID: <3E04EF0D-5DA2-442A-99AB-F94BEF52610C@suse.de> X-SW-Source: 2017-12/txt/msg00092.txt.bz2 On December 2, 2017 1:14:10 AM GMT+01:00, Jakub Jelinek = wrote: >Hi! > >With -fsanitize=3Dreturn, 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? OK.=20 Richard.=20 >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) =3D=3D 0) > { > gimple *last =3D last_stmt (bb); >+ const enum built_in_function ubsan_missing_ret >+ =3D BUILT_IN_UBSAN_HANDLE_MISSING_RETURN; > if (last >- && (LOCATION_LOCUS (gimple_location (last)) >- =3D=3D BUILTINS_LOCATION) >- && gimple_call_builtin_p (last, BUILT_IN_UNREACHABLE)) >+ && ((LOCATION_LOCUS (gimple_location (last)) >+ =3D=3D BUILTINS_LOCATION >+ && gimple_call_builtin_p (last, BUILT_IN_UNREACHABLE)) >+ || gimple_call_builtin_p (last, ubsan_missing_ret))) > { > gimple_stmt_iterator gsi =3D 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=3Dreturn" } >+ >+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=3Dreturn" } >+// { dg-options "-fsanitize=3Dreturn -Wno-return-type" } > // { dg-shouldfail "ubsan" } >=20 > 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=3Dreturn -fno-sanitize-recover=3Dreturn" } >+// { dg-options "-fsanitize=3Dreturn -fno-sanitize-recover=3Dreturn >-Wno-return-type" } >=20 > struct S { S (); ~S (); }; >=20 >--- 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=3Dundefined" } >+// { dg-options "-fsanitize=3Dundefined -Wno-return-type" } > // { dg-shouldfail "ubsan" } >=20 > struct S { S (); ~S (); }; > > Jakub