From patchwork Tue Jul 10 07:34:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 941841 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-481263-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="eP/6ryFc"; dkim-atps=neutral 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 41Pv9T41WJz9s00 for ; Tue, 10 Jul 2018 17:34:53 +1000 (AEST) 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:mime-version :content-type; q=dns; s=default; b=eAMbVBp5v25djd5+ga7/RpS+mD7R2 Hajs2Kp4Wkat1u+289rE18W5HK75BiG1ouZNQvw4CxXDmmDCK+GpyEfURSHCoD9i 7jBJODyflgO7OsM2omcC0/s4wWl5buySornCXXz7x5Ap+DRaQqfj0+xA3mZJwsbn gBikmLVq7JWduA= 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:mime-version :content-type; s=default; bh=8rLsWNlv0PSaLLqbcX6AvLHA1t4=; b=eP/ 6ryFcN/Hg85ksLdrkQ8z8PdcEQJUM8UFrZDjYcD01txlr1UWrh/2jzGS2Bhzkks7 bfSfmmle75vuD47rvaS5RrbvwiFova8OAAbSJFB4BOsWbPfclBx5uxhnXh5yT6Bo /Ul5q6qe7A2wUZOcRh0ejqrIJqApjD8kJEPxlCYc= Received: (qmail 66350 invoked by alias); 10 Jul 2018 07:34:13 -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 66238 invoked by uid 89); 10 Jul 2018 07:34:12 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:2046, HTo:U*aoliva 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, 10 Jul 2018 07:34:10 +0000 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EDC86308FB8A; Tue, 10 Jul 2018 07:34:08 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-117-71.ams2.redhat.com [10.36.117.71]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 903A22010CBA; Tue, 10 Jul 2018 07:34:08 +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 w6A7Y6nC027451; Tue, 10 Jul 2018 09:34:06 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id w6A7Y4Mx027450; Tue, 10 Jul 2018 09:34:04 +0200 Date: Tue, 10 Jul 2018 09:34:04 +0200 From: Jakub Jelinek To: Richard Biener , Alexandre Oliva Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix -fcompare-debug issue in cp_maybe_instrument_return (PR sanitizer/86406) Message-ID: <20180710073404.GD7166@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.2 (2017-12-15) X-IsSubscribed: yes Hi! cp_maybe_instrument_return is looking for a return stmt at the end of function to decide whether to omit -fsanitize=return instrumentation or __builtin_unreachable addition. If a STATEMENT_LIST has a return followed by DEBUG_BEGIN_STMT (or multiple of them), it doesn't find the return though. Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2018-07-10 Jakub Jelinek PR sanitizer/86406 * cp-gimplify.c (cp_maybe_instrument_return): Skip trailing DEBUG_BEGIN_STMTs. * g++.dg/ubsan/pr86406.C: New test. Jakub --- gcc/cp/cp-gimplify.c.jj 2018-07-05 11:41:51.687718588 +0200 +++ gcc/cp/cp-gimplify.c 2018-07-09 09:57:16.368775004 +0200 @@ -1621,6 +1621,13 @@ cp_maybe_instrument_return (tree fndecl) case STATEMENT_LIST: { tree_stmt_iterator i = tsi_last (t); + while (!tsi_end_p (i)) + { + tree p = tsi_stmt (i); + if (TREE_CODE (p) != DEBUG_BEGIN_STMT) + break; + tsi_prev (&i); + } if (!tsi_end_p (i)) { t = tsi_stmt (i); --- gcc/testsuite/g++.dg/ubsan/pr86406.C.jj 2018-07-09 09:58:57.362878125 +0200 +++ gcc/testsuite/g++.dg/ubsan/pr86406.C 2018-07-09 09:58:37.716858063 +0200 @@ -0,0 +1,33 @@ +// PR sanitizer/86406 +// { dg-do compile } +// { dg-options "-fcompare-debug -fsanitize=undefined -g -O1" } + +typedef enum { } cmd_status; +class ECell; +class ECell_const_ptr { }; +class ECell_ptr +{ + ECell *mp_element; + ECell *getPointer () const { return mp_element; } +public: + operator ECell_const_ptr () const { return ECell_const_ptr(); } +}; + +extern ECell_ptr NULL_CELL; +class VwUI_2DCellLayerView; +class view_cell_layoutImpl +{ + cmd_status handleChangeFlags (VwUI_2DCellLayerView * + p_ui_celllayerview, + ECell_const_ptr p_peekCell); + cmd_status openCellLayoutView (); +}; + +cmd_status +view_cell_layoutImpl::openCellLayoutView () +{ + ECell_const_ptr pcell = NULL_CELL; + VwUI_2DCellLayerView *p_user_interface; + return handleChangeFlags (p_user_interface, pcell); + ; +}