aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/ubsan.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc-4.9/gcc/ubsan.c')
-rw-r--r--gcc-4.9/gcc/ubsan.c37
1 files changed, 29 insertions, 8 deletions
diff --git a/gcc-4.9/gcc/ubsan.c b/gcc-4.9/gcc/ubsan.c
index ac40c85f5..25c2cde60 100644
--- a/gcc-4.9/gcc/ubsan.c
+++ b/gcc-4.9/gcc/ubsan.c
@@ -47,6 +47,7 @@ along with GCC; see the file COPYING3. If not see
#include "asan.h"
#include "gimplify-me.h"
#include "intl.h"
+#include "tree-eh.h"
/* Map from a tree to a VAR_DECL tree. */
@@ -528,9 +529,9 @@ ubsan_instrument_unreachable (location_t loc)
bool
is_ubsan_builtin_p (tree t)
{
- gcc_checking_assert (TREE_CODE (t) == FUNCTION_DECL);
- return strncmp (IDENTIFIER_POINTER (DECL_NAME (t)),
- "__builtin___ubsan_", 18) == 0;
+ return TREE_CODE (t) == FUNCTION_DECL
+ && strncmp (IDENTIFIER_POINTER (DECL_NAME (t)),
+ "__builtin___ubsan_", 18) == 0;
}
/* Expand UBSAN_NULL internal call. */
@@ -807,7 +808,9 @@ instrument_bool_enum_load (gimple_stmt_iterator *gsi)
|| TREE_CODE (gimple_assign_lhs (stmt)) != SSA_NAME)
return;
+ bool can_throw = stmt_could_throw_p (stmt);
location_t loc = gimple_location (stmt);
+ tree lhs = gimple_assign_lhs (stmt);
tree ptype = build_pointer_type (TREE_TYPE (rhs));
tree atype = reference_alias_ptr_type (rhs);
gimple g = gimple_build_assign (make_ssa_name (ptype, NULL),
@@ -817,9 +820,24 @@ instrument_bool_enum_load (gimple_stmt_iterator *gsi)
tree mem = build2 (MEM_REF, utype, gimple_assign_lhs (g),
build_int_cst (atype, 0));
tree urhs = make_ssa_name (utype, NULL);
- g = gimple_build_assign (urhs, mem);
- gimple_set_location (g, loc);
- gsi_insert_before (gsi, g, GSI_SAME_STMT);
+ if (can_throw)
+ {
+ gimple_assign_set_lhs (stmt, urhs);
+ g = gimple_build_assign_with_ops (NOP_EXPR, lhs, urhs, NULL_TREE);
+ gimple_set_location (g, loc);
+ edge e = find_fallthru_edge (gimple_bb (stmt)->succs);
+ gsi_insert_on_edge_immediate (e, g);
+ gimple_assign_set_rhs_from_tree (gsi, mem);
+ update_stmt (stmt);
+ *gsi = gsi_for_stmt (g);
+ g = stmt;
+ }
+ else
+ {
+ g = gimple_build_assign (urhs, mem);
+ gimple_set_location (g, loc);
+ gsi_insert_before (gsi, g, GSI_SAME_STMT);
+ }
minv = fold_convert (utype, minv);
maxv = fold_convert (utype, maxv);
if (!integer_zerop (minv))
@@ -841,8 +859,11 @@ instrument_bool_enum_load (gimple_stmt_iterator *gsi)
gimple_set_location (g, loc);
gsi_insert_after (gsi, g, GSI_NEW_STMT);
- gimple_assign_set_rhs_with_ops (&gsi2, NOP_EXPR, urhs, NULL_TREE);
- update_stmt (stmt);
+ if (!can_throw)
+ {
+ gimple_assign_set_rhs_with_ops (&gsi2, NOP_EXPR, urhs, NULL_TREE);
+ update_stmt (stmt);
+ }
tree data = ubsan_create_data ("__ubsan_invalid_value_data",
&loc, NULL,