diff mbox

Do not disable aggressive loop opts for, -fsanitize=unreachable or leak

Message ID ebabe2dc-be5c-7754-8726-cfb0b2ef7caa@suse.cz
State New
Headers show

Commit Message

Martin Liška Oct. 19, 2016, 11:39 a.m. UTC
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

Comments

Jakub Jelinek Oct. 21, 2016, 1:55 p.m. UTC | #1
On Wed, Oct 19, 2016 at 01:39:16PM +0200, Martin Liška wrote:
> >From 7f1648ef3480c6db856e567153cf9bb838c77d4f Mon Sep 17 00:00:00 2001

> From: marxin <mliska@suse.cz>

> 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  <mliska@suse.cz>

> 

> 	PR sanitizer/77966

> 	* opts.c (finish_options): Skip conditionally.

> 

> gcc/testsuite/ChangeLog:

> 

> 2016-10-17  Martin Liska  <mliska@suse.cz>

> 

> 	PR sanitizer/77966

> 	* c-c++-common/ubsan/unreachable-3.c: New test.


Ok, thanks.

	Jakub
diff mbox

Patch

From 7f1648ef3480c6db856e567153cf9bb838c77d4f Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
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  <mliska@suse.cz>

	PR sanitizer/77966
	* opts.c (finish_options): Skip conditionally.

gcc/testsuite/ChangeLog:

2016-10-17  Martin Liska  <mliska@suse.cz>

	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