From patchwork Wed Oct 19 11:39:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Li=C5=A1ka?= X-Patchwork-Id: 78226 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp200115qge; Wed, 19 Oct 2016 04:39:43 -0700 (PDT) X-Received: by 10.98.71.86 with SMTP id u83mr10424100pfa.180.1476877183773; Wed, 19 Oct 2016 04:39:43 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id a76si40185629pfc.86.2016.10.19.04.39.43 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Oct 2016 04:39:43 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-439010-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-439010-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-439010-patch=linaro.org@gcc.gnu.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=Mz4TSEQPsbwPL6NqWzVMhRtHg7RP/NndP+rYNOMLPk3qqg0CA9 HHxmJ0+AWykhwFW3EwxYS+UbsxZK7Zxq3zp0K93M6TN+EhbHGSs5YeHupg3bflrw 26iRA8P6ju2mkhE2fsAe/stOxW/jX9HhFgRgYSTGD3VN5VBvnMrGd3GC8= 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:to:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=PNUVAKn/OctjJG9EYn5Gn0+xWxs=; b=BIwOeJH/pvG1dQwUtqCr eH+6dEPpxJkrh14Yp/nrp9qZ92YG96xsms+VKdn+U09xzQ+k7ZjF4tylR/Ia4uEE kDWi8c58b7u23LRRDTQm2lX9Gpz3tcusDnaRD2ZDswMll0nXfCZmmVZe9r8MKZM/ K+qX5Crk1CuAdfElV/2e9Vk= Received: (qmail 100481 invoked by alias); 19 Oct 2016 11:39:30 -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 99592 invoked by uid 89); 19 Oct 2016 11:39:29 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00, SPF_PASS autolearn=ham version=3.3.2 spammy=*opts, gcc_options, sk:90e6186, UD:opts.c 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; Wed, 19 Oct 2016 11:39:19 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 47F60AD13; Wed, 19 Oct 2016 11:39:17 +0000 (UTC) To: GCC Patches Cc: Jakub Jelinek From: =?UTF-8?Q?Martin_Li=c5=a1ka?= Subject: [PATCH] Do not disable aggressive loop opts for, -fsanitize=unreachable or leak Message-ID: Date: Wed, 19 Oct 2016 13:39:16 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 X-IsSubscribed: yes Hello. This patch allows aggressive loop optimizations and strict overflow when -fsanitize=unreachabne or -fsanitize=leak is (are) enabled. That would help kernel people to have assumption that every functions should either end with jmp ret or by __builtin___ubsan_handle_builtin_unreachable. Patch can bootstrap on ppc64le-redhat-linux and survives regression tests. Ready to be installed? Martin >From 7f1648ef3480c6db856e567153cf9bb838c77d4f Mon Sep 17 00:00:00 2001 From: marxin Date: Mon, 17 Oct 2016 15:58:50 +0200 Subject: [PATCH] Do not disable aggressive loop opts for -fsanitize=unreachable or leak gcc/ChangeLog: 2016-10-17 Martin Liska PR sanitizer/77966 * opts.c (finish_options): Skip conditionally. gcc/testsuite/ChangeLog: 2016-10-17 Martin Liska PR sanitizer/77966 * c-c++-common/ubsan/unreachable-3.c: New test. --- gcc/opts.c | 2 +- gcc/testsuite/c-c++-common/ubsan/unreachable-3.c | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/c-c++-common/ubsan/unreachable-3.c diff --git a/gcc/opts.c b/gcc/opts.c index 90e6186..e909240 100644 --- a/gcc/opts.c +++ b/gcc/opts.c @@ -972,7 +972,7 @@ finish_options (struct gcc_options *opts, struct gcc_options *opts_set, opts->x_flag_delete_null_pointer_checks = 0; /* Aggressive compiler optimizations may cause false negatives. */ - if (opts->x_flag_sanitize) + if (opts->x_flag_sanitize & ~(SANITIZE_LEAK | SANITIZE_UNREACHABLE)) { opts->x_flag_aggressive_loop_optimizations = 0; opts->x_flag_strict_overflow = 0; diff --git a/gcc/testsuite/c-c++-common/ubsan/unreachable-3.c b/gcc/testsuite/c-c++-common/ubsan/unreachable-3.c new file mode 100644 index 0000000..b7a0d1a --- /dev/null +++ b/gcc/testsuite/c-c++-common/ubsan/unreachable-3.c @@ -0,0 +1,21 @@ +/* { dg-do compile } */ +/* { dg-options "-fsanitize=unreachable -O2 -fno-reorder-blocks -fsanitize-coverage=trace-pc -fdump-tree-optimized" } */ +/* { dg-skip-if "" { *-*-* } { "-flto" } } */ + +extern unsigned int ioread32(void *); +struct vnic_wq_ctrl { + unsigned int error_status; +}; +struct snic { + unsigned int wq_count; + struct vnic_wq_ctrl *wq[1]; + int wq_lock[1]; +}; +void snic_log_q_error(struct snic *snic) +{ + unsigned int i; + for (i = 0; i < snic->wq_count; i++) + ioread32(&snic->wq[i]->error_status); +} + +/* { dg-final { scan-tree-dump "__builtin___ubsan_handle_builtin_unreachable" "optimized" } } */ -- 2.10.1