public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix unreachable-2.c testcase (PR sanitizer/83219)
@ 2017-11-30 22:55 Jakub Jelinek
  2017-12-01  7:00 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2017-11-30 22:55 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches

Hi!

As mentioned in the PR, when -fsanitize=unreachable (part of
-fsanitize=undefined), we don't want optimizers to optimize away
conditional branches to __builtin_unreachable or switch cases
that branch go __builtin_unreachable.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?

2017-11-30  Jakub Jelinek  <jakub@redhat.com>

	PR sanitizer/83219
	* tree-cfg.c: Include asan.h.
	(gimple_seq_unreachable_p): Return false for -fsanitize=unreachable.

--- gcc/tree-cfg.c.jj	2017-11-23 21:13:30.000000000 +0100
+++ gcc/tree-cfg.c	2017-11-30 11:40:38.334930487 +0100
@@ -61,6 +61,7 @@ along with GCC; see the file COPYING3.
 #include "attribs.h"
 #include "selftest.h"
 #include "opts.h"
+#include "asan.h"
 
 /* This file contains functions for building the Control Flow Graph (CFG)
    for a function tree.  */
@@ -469,7 +470,12 @@ computed_goto_p (gimple *t)
 bool
 gimple_seq_unreachable_p (gimple_seq stmts)
 {
-  if (stmts == NULL)
+  if (stmts == NULL
+      /* Return false if -fsanitize=unreachable, we don't want to
+	 optimize away those calls, but rather turn them into
+	 __ubsan_handle_builtin_unreachable () or __builtin_trap ()
+	 later.  */
+      || sanitize_flags_p (SANITIZE_UNREACHABLE))
     return false;
 
   gimple_stmt_iterator gsi = gsi_last (stmts);

	Jakub

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Fix unreachable-2.c testcase (PR sanitizer/83219)
  2017-11-30 22:55 [PATCH] Fix unreachable-2.c testcase (PR sanitizer/83219) Jakub Jelinek
@ 2017-12-01  7:00 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2017-12-01  7:00 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

On November 30, 2017 11:51:09 PM GMT+01:00, Jakub Jelinek <jakub@redhat.com> wrote:
>Hi!
>
>As mentioned in the PR, when -fsanitize=unreachable (part of
>-fsanitize=undefined), we don't want optimizers to optimize away
>conditional branches to __builtin_unreachable or switch cases
>that branch go __builtin_unreachable.
>
>Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok
>for
>trunk?

OK. 

Richard. 

>2017-11-30  Jakub Jelinek  <jakub@redhat.com>
>
>	PR sanitizer/83219
>	* tree-cfg.c: Include asan.h.
>	(gimple_seq_unreachable_p): Return false for -fsanitize=unreachable.
>
>--- gcc/tree-cfg.c.jj	2017-11-23 21:13:30.000000000 +0100
>+++ gcc/tree-cfg.c	2017-11-30 11:40:38.334930487 +0100
>@@ -61,6 +61,7 @@ along with GCC; see the file COPYING3.
> #include "attribs.h"
> #include "selftest.h"
> #include "opts.h"
>+#include "asan.h"
> 
>/* This file contains functions for building the Control Flow Graph
>(CFG)
>    for a function tree.  */
>@@ -469,7 +470,12 @@ computed_goto_p (gimple *t)
> bool
> gimple_seq_unreachable_p (gimple_seq stmts)
> {
>-  if (stmts == NULL)
>+  if (stmts == NULL
>+      /* Return false if -fsanitize=unreachable, we don't want to
>+	 optimize away those calls, but rather turn them into
>+	 __ubsan_handle_builtin_unreachable () or __builtin_trap ()
>+	 later.  */
>+      || sanitize_flags_p (SANITIZE_UNREACHABLE))
>     return false;
> 
>   gimple_stmt_iterator gsi = gsi_last (stmts);
>
>	Jakub

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-12-01  7:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-30 22:55 [PATCH] Fix unreachable-2.c testcase (PR sanitizer/83219) Jakub Jelinek
2017-12-01  7:00 ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).