From patchwork Tue Sep 27 18:16:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 675764 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 3sk8Dr73Kmz9s3v for ; Wed, 28 Sep 2016 04:17:00 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=xe+md/rK; dkim-atps=neutral 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:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=pUUBcK8AwOvu+NjNM a18R45ErC79CwJlYjT4urOHMomSw8Fl70CtrThVcWJUn560iB1nFP6LMeJ5T+5pj enKNYdKVEdC1pkTA3EQ4geZeTliYG1JgkcHi2cg9Rfzi1gzgh+aFjr5ta1V9SBh8 uq5NGqc0uBw6WOW/MNa1BQUaCQ= 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:references:mime-version :content-type:in-reply-to; s=default; bh=N4AY2Cc6lHEskd9ca7m6HKd qln8=; b=xe+md/rKM3xZhzYy7poVGh9pmvOBCS8LjIgce1dy0z8tFk4IDPlYg3q j1lrb5xF2rAqgLd0gT+SxhMyvAV5uyr9ysDSJGnWxRX/NviSR44bQr25LDmxE+us yWtqsnBJnTlQIP90r/kBJpkGjuXv9ba/zllDY8yXydszwUNn1DGo= Received: (qmail 75397 invoked by alias); 27 Sep 2016 18:16:50 -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 75387 invoked by uid 89); 27 Sep 2016 18:16:50 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.9 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS 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; Tue, 27 Sep 2016 18:16:48 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1E982497 for ; Tue, 27 Sep 2016 18:16:47 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-204-43.brq.redhat.com [10.40.204.43]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u8RIGj0o017424 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 27 Sep 2016 14:16:46 -0400 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id u8RIGi1L019778; Tue, 27 Sep 2016 20:16:44 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id u8RIGhrH019777; Tue, 27 Sep 2016 20:16:43 +0200 Date: Tue, 27 Sep 2016 20:16:43 +0200 From: Jakub Jelinek To: Jason Merrill Cc: Marek Polacek , gcc-patches List Subject: Re: [C++ PATCH] Fix -fsanitize=return on small functions (PR c++/77722) Message-ID: <20160927181643.GB7282@tucnak.redhat.com> Reply-To: Jakub Jelinek References: <20160927075729.GH7282@tucnak.redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-IsSubscribed: yes On Tue, Sep 27, 2016 at 10:56:51AM -0400, Jason Merrill wrote: > On Tue, Sep 27, 2016 at 3:57 AM, Jakub Jelinek wrote: > > @@ -1570,14 +1570,22 @@ cp_ubsan_maybe_instrument_return (tree f > > + if (TREE_CODE (*p) == STATEMENT_LIST) > > { > > + tree_stmt_iterator i = tsi_last (*p); > > tsi_link_after (&i, t, TSI_NEW_STMT); > > } > > + else > > + { > > + tree list = NULL_TREE; > > + append_to_statement_list_force (*p, &list); > > + append_to_statement_list (t, &list); > > + *p = list; > > + } > > Can't you replace all of this with > > append_to_statement_list (t, p); > > ? > > OK either way. That works too and is cleaner, thanks. Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk. 2016-09-27 Jakub Jelinek PR c++/77722 * cp-gimplify.c (cp_ubsan_maybe_instrument_return): Instrument also functions that have just a STATEMENT_LIST instead of BIND_EXPR, or BIND_EXPR with some statement rather than STATEMENT_LIST as body. * g++.dg/ubsan/return-4.C: New test. * g++.dg/ubsan/return-5.C: New test. * g++.dg/ubsan/return-6.C: New test. Jakub --- gcc/cp/cp-gimplify.c.jj 2016-09-26 12:06:36.060910355 +0200 +++ gcc/cp/cp-gimplify.c 2016-09-27 18:06:50.780686666 +0200 @@ -1570,14 +1570,11 @@ cp_ubsan_maybe_instrument_return (tree f } if (t == NULL_TREE) return; - t = DECL_SAVED_TREE (fndecl); - if (TREE_CODE (t) == BIND_EXPR - && TREE_CODE (BIND_EXPR_BODY (t)) == STATEMENT_LIST) - { - tree_stmt_iterator i = tsi_last (BIND_EXPR_BODY (t)); - t = ubsan_instrument_return (DECL_SOURCE_LOCATION (fndecl)); - tsi_link_after (&i, t, TSI_NEW_STMT); - } + tree *p = &DECL_SAVED_TREE (fndecl); + if (TREE_CODE (*p) == BIND_EXPR) + p = &BIND_EXPR_BODY (*p); + t = ubsan_instrument_return (DECL_SOURCE_LOCATION (fndecl)); + append_to_statement_list (t, p); } void --- gcc/testsuite/g++.dg/ubsan/return-5.C.jj 2016-09-27 18:05:37.138615332 +0200 +++ gcc/testsuite/g++.dg/ubsan/return-5.C 2016-09-27 18:05:37.138615332 +0200 @@ -0,0 +1,19 @@ +// PR c++/77722 +// { dg-do run } +// { dg-options "-fsanitize=return -w" } +// { dg-shouldfail "ubsan" } + +int +foo () +{ + int a = 5; +} + +int +main () +{ + foo (); + return 0; +} + +// { dg-output "execution reached the end of a value-returning function without returning a value" } --- gcc/testsuite/g++.dg/ubsan/return-4.C.jj 2016-09-27 18:05:37.137615345 +0200 +++ gcc/testsuite/g++.dg/ubsan/return-4.C 2016-09-27 18:05:37.137615345 +0200 @@ -0,0 +1,18 @@ +// PR c++/77722 +// { dg-do run } +// { dg-options "-fsanitize=return -w" } +// { dg-shouldfail "ubsan" } + +int +foo () +{ +} + +int +main () +{ + foo (); + return 0; +} + +// { dg-output "execution reached the end of a value-returning function without returning a value" } --- gcc/testsuite/g++.dg/ubsan/return-6.C.jj 2016-09-27 18:05:37.138615332 +0200 +++ gcc/testsuite/g++.dg/ubsan/return-6.C 2016-09-27 18:05:37.138615332 +0200 @@ -0,0 +1,20 @@ +// PR c++/77722 +// { dg-do run } +// { dg-options "-fsanitize=return -w" } +// { dg-shouldfail "ubsan" } + +int +foo () +{ + int a = 5; + int b = 5; +} + +int +main () +{ + foo (); + return 0; +} + +// { dg-output "execution reached the end of a value-returning function without returning a value" }