This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix unreachable-2.c testcase (PR sanitizer/83219)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Richard Biener <rguenther at suse dot de>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Thu, 30 Nov 2017 23:51:09 +0100
- Subject: [PATCH] Fix unreachable-2.c testcase (PR sanitizer/83219)
- Authentication-results: sourceware.org; auth=none
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
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