[PATCH] Fix ubsan non-call-exceptions ICE (PR tree-optimization/65984)
Jakub Jelinek
jakub@redhat.com
Mon May 4 18:16:00 GMT 2015
Hi!
The code I've added in r217755 was assuming that stmt_could_throw_p
memory read will always end a bb, but that is clearly not the case.
Thus, the following patch uses stmt_ends_bb_p instead.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk/5?
2015-05-04 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/65984
* ubsan.c: Include tree-cfg.h.
(instrument_bool_enum_load): Use stmt_ends_bb_p instead of
stmt_could_throw_p test, rename can_throw variable to ends_bb.
* c-c++-common/ubsan/pr65984.c: New test.
--- gcc/ubsan.c.jj 2015-04-09 21:49:59.000000000 +0200
+++ gcc/ubsan.c 2015-05-04 17:17:34.273661884 +0200
@@ -87,6 +87,7 @@ along with GCC; see the file COPYING3.
#include "builtins.h"
#include "tree-object-size.h"
#include "tree-eh.h"
+#include "tree-cfg.h"
/* Map from a tree to a VAR_DECL tree. */
@@ -1420,7 +1421,7 @@ instrument_bool_enum_load (gimple_stmt_i
|| TREE_CODE (gimple_assign_lhs (stmt)) != SSA_NAME)
return;
- bool can_throw = stmt_could_throw_p (stmt);
+ bool ends_bb = stmt_ends_bb_p (stmt);
location_t loc = gimple_location (stmt);
tree lhs = gimple_assign_lhs (stmt);
tree ptype = build_pointer_type (TREE_TYPE (rhs));
@@ -1432,7 +1433,7 @@ instrument_bool_enum_load (gimple_stmt_i
tree mem = build2 (MEM_REF, utype, gimple_assign_lhs (g),
build_int_cst (atype, 0));
tree urhs = make_ssa_name (utype);
- if (can_throw)
+ if (ends_bb)
{
gimple_assign_set_lhs (stmt, urhs);
g = gimple_build_assign (lhs, NOP_EXPR, urhs);
@@ -1469,7 +1470,7 @@ instrument_bool_enum_load (gimple_stmt_i
gimple_set_location (g, loc);
gsi_insert_after (gsi, g, GSI_NEW_STMT);
- if (!can_throw)
+ if (!ends_bb)
{
gimple_assign_set_rhs_with_ops (&gsi2, NOP_EXPR, urhs);
update_stmt (stmt);
--- gcc/testsuite/c-c++-common/ubsan/pr65984.c.jj 2015-05-04 14:16:59.655378975 +0200
+++ gcc/testsuite/c-c++-common/ubsan/pr65984.c 2015-05-04 17:19:55.875447821 +0200
@@ -0,0 +1,23 @@
+/* PR tree-optimization/65984 */
+/* { dg-do compile } */
+/* { dg-options "-fnon-call-exceptions -fsanitize=bool,enum" } */
+
+#ifndef __cplusplus
+#define bool _Bool
+#endif
+
+enum E { E0, E1, E2 };
+enum E e[2];
+bool *b;
+
+int
+foo (int i)
+{
+ return e[i];
+}
+
+int
+bar (int i)
+{
+ return b[i];
+}
Jakub
More information about the Gcc-patches
mailing list