]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ubsan.c (do_ubsan_in_current_function): New.
authorJason Merrill <jason@redhat.com>
Thu, 8 Jan 2015 21:27:22 +0000 (16:27 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Thu, 8 Jan 2015 21:27:22 +0000 (16:27 -0500)
gcc/
* ubsan.c (do_ubsan_in_current_function): New.
(pass_ubsan::gate): Use it.
* ubsan.h: Declare it.
* convert.c (convert_to_integer): Use it.
gcc/c-family/
* c-ubsan.c (ubsan_maybe_instrument_array_ref): Use
do_ubsan_in_current_function.
(ubsan_maybe_instrument_reference_or_call): Likewise.
* c-ubsan.h: Declare it.
gcc/cp/
* cp-gimplify.c (cp_genericize): Use do_ubsan_in_current_function.
* decl.c (compute_array_index_type): Likewise.
* init.c (build_vec_init): Likewise.
* typeck.c (cp_build_binary_op): Likewise.

From-SVN: r219360

12 files changed:
gcc/ChangeLog
gcc/c-family/ChangeLog
gcc/c-family/c-ubsan.c
gcc/c-family/c-ubsan.h
gcc/convert.c
gcc/cp/ChangeLog
gcc/cp/cp-gimplify.c
gcc/cp/decl.c
gcc/cp/init.c
gcc/cp/typeck.c
gcc/ubsan.c
gcc/ubsan.h

index ff6abddfe508cd0479e9730d434ce23543101e2a..f3db7fdfb3c79f9d0c6935933475582c052620f2 100644 (file)
@@ -1,3 +1,10 @@
+2015-01-08  Jason Merrill  <jason@redhat.com>
+
+       * ubsan.c (do_ubsan_in_current_function): New.
+       (pass_ubsan::gate): Use it.
+       * ubsan.h: Declare it.
+       * convert.c (convert_to_integer): Use it.
+
 2015-01-08  Jakub Jelinek  <jakub@redhat.com>
 
        PR target/64338
index d6f09dcf0441ec8c3418497b7eab6462a95f6635..acbe684ada14c20c5b7bab4ad0047d6b0d5c334a 100644 (file)
@@ -1,3 +1,10 @@
+2015-01-08  Jason Merrill  <jason@redhat.com>
+
+       * c-ubsan.c (ubsan_maybe_instrument_array_ref): Use
+       do_ubsan_in_current_function.
+       (ubsan_maybe_instrument_reference_or_call): Likewise.
+       * c-ubsan.h: Declare it.
+
 2015-01-08  Mike Stump  <mikestump@comcast.net>
 
        * c-common.c (c_common_attribute_table): Add no_sanitize_thread.
index f2db4942db4385e6eb5044562ea272220152c849..c195c7ff763bed43beb26037d96c23cf390f7639 100644 (file)
@@ -364,9 +364,7 @@ void
 ubsan_maybe_instrument_array_ref (tree *expr_p, bool ignore_off_by_one)
 {
   if (!ubsan_array_ref_instrumented_p (*expr_p)
-      && current_function_decl != NULL_TREE
-      && !lookup_attribute ("no_sanitize_undefined",
-                           DECL_ATTRIBUTES (current_function_decl)))
+      && do_ubsan_in_current_function ())
     {
       tree op0 = TREE_OPERAND (*expr_p, 0);
       tree op1 = TREE_OPERAND (*expr_p, 1);
@@ -386,9 +384,7 @@ static tree
 ubsan_maybe_instrument_reference_or_call (location_t loc, tree op, tree ptype,
                                          enum ubsan_null_ckind ckind)
 {
-  if (current_function_decl == NULL_TREE
-      || lookup_attribute ("no_sanitize_undefined",
-                          DECL_ATTRIBUTES (current_function_decl)))
+  if (!do_ubsan_in_current_function ())
     return NULL_TREE;
 
   tree type = TREE_TYPE (ptype);
index b1fe5f1d820edcb4cf574fab7b4e85020fb43196..fb379c83c1564ef31cb44d327a17fdff470905c3 100644 (file)
@@ -31,4 +31,7 @@ extern void ubsan_maybe_instrument_array_ref (tree *, bool);
 extern void ubsan_maybe_instrument_reference (tree);
 extern void ubsan_maybe_instrument_member_call (tree, bool);
 
+/* Declare this here as well as in ubsan.h. */
+extern bool do_ubsan_in_current_function (void);
+
 #endif  /* GCC_C_UBSAN_H  */
index 0491986bd1e375969d48a70a7b71edec01af288d..fc1b93c225b62e297db77cfd19633f69fa97581d 100644 (file)
@@ -885,9 +885,7 @@ convert_to_integer (tree type, tree expr)
 
     case REAL_TYPE:
       if (flag_sanitize & SANITIZE_FLOAT_CAST
-         && current_function_decl != NULL_TREE
-         && !lookup_attribute ("no_sanitize_undefined",
-                               DECL_ATTRIBUTES (current_function_decl)))
+         && do_ubsan_in_current_function ())
        {
          expr = save_expr (expr);
          tree check = ubsan_instrument_float_cast (loc, type, expr, expr);
index 46d795705d9c553eb9b4a05d0ca547282bb9e542..8afaafa6b840b3b674d3d2e7528c18229fdaff76 100644 (file)
@@ -1,3 +1,10 @@
+2015-01-08  Jason Merrill  <jason@redhat.com>
+
+       * cp-gimplify.c (cp_genericize): Use do_ubsan_in_current_function.
+       * decl.c (compute_array_index_type): Likewise.
+       * init.c (build_vec_init): Likewise.
+       * typeck.c (cp_build_binary_op): Likewise.
+
 2015-01-08  Jason Merrill  <jason@redhat.com>
 
        * init.c (build_vec_init): Call ubsan_instrument_bounds to check
index a23076f6c36524d219ec358b2709a8a8e14a5d2f..33dce296433d8f5eaac6c3ec471dcef53956a307 100644 (file)
@@ -1350,9 +1350,7 @@ cp_genericize (tree fndecl)
   cp_genericize_tree (&DECL_SAVED_TREE (fndecl));
 
   if (flag_sanitize & SANITIZE_RETURN
-      && current_function_decl != NULL_TREE
-      && !lookup_attribute ("no_sanitize_undefined",
-                           DECL_ATTRIBUTES (current_function_decl)))
+      && do_ubsan_in_current_function ())
     cp_ubsan_maybe_instrument_return (fndecl);
 
   /* Do everything else.  */
index 65ccf7745d273793fd9c21de0195ad15ea2641dc..dd000c39cb11582c8c4e6d4f8666469c93be7c90 100644 (file)
@@ -8595,10 +8595,7 @@ compute_array_index_type (tree name, tree size, tsubst_flags_t complain)
          stabilize_vla_size (itype);
 
          if (flag_sanitize & SANITIZE_VLA
-             && current_function_decl != NULL_TREE
-             && !lookup_attribute ("no_sanitize_undefined",
-                                   DECL_ATTRIBUTES
-                                   (current_function_decl)))
+             && do_ubsan_in_current_function ())
            {
              /* We have to add 1 -- in the ubsan routine we generate
                 LE_EXPR rather than LT_EXPR.  */
index 6f324926aefaf6d2f6d432c7e87a73694bbdd2c3..3bd470b986a1bcf8451d51cb62cce866b6fd5146 100644 (file)
@@ -3575,10 +3575,7 @@ build_vec_init (tree base, tree maxindex, tree init,
              /* Don't check an array new when -fno-exceptions.  */
            }
          else if (flag_sanitize & SANITIZE_BOUNDS
-                  && current_function_decl
-                  && !lookup_attribute ("no_sanitize_undefined",
-                                        DECL_ATTRIBUTES
-                                        (current_function_decl)))
+                  && do_ubsan_in_current_function ())
            {
              /* Make sure the last element of the initializer is in bounds. */
              finish_expr_stmt
index b4af8b0d073cd0c9d69262a0ae390282be20a391..fb0ffd1438d151c5cdffe3a700298d197bb93165 100644 (file)
@@ -4973,9 +4973,7 @@ cp_build_binary_op (location_t location,
   if ((flag_sanitize & (SANITIZE_SHIFT | SANITIZE_DIVIDE
                        | SANITIZE_FLOAT_DIVIDE))
       && !processing_template_decl
-      && current_function_decl != 0
-      && !lookup_attribute ("no_sanitize_undefined",
-                           DECL_ATTRIBUTES (current_function_decl))
+      && do_ubsan_in_current_function ()
       && (doing_div_or_mod || doing_shift))
     {
       /* OP0 and/or OP1 might have side-effects.  */
index 5c9355aacb821fcfa33e4ba84474f7891686c783..7dae9670338d5577d996d9c9e99b933ad42b9185 100644 (file)
@@ -1648,6 +1648,16 @@ instrument_object_size (gimple_stmt_iterator *gsi, bool is_lhs)
   gsi_insert_before (gsi, g, GSI_SAME_STMT);
 }
 
+/* True if we want to play UBSan games in the current function.  */
+
+bool
+do_ubsan_in_current_function ()
+{
+  return (current_function_decl != NULL_TREE
+         && !lookup_attribute ("no_sanitize_undefined",
+                               DECL_ATTRIBUTES (current_function_decl)));
+}
+
 namespace {
 
 const pass_data pass_data_ubsan =
@@ -1679,9 +1689,7 @@ public:
                              | SANITIZE_NONNULL_ATTRIBUTE
                              | SANITIZE_RETURNS_NONNULL_ATTRIBUTE
                              | SANITIZE_OBJECT_SIZE)
-            && current_function_decl != NULL_TREE
-            && !lookup_attribute ("no_sanitize_undefined",
-                                  DECL_ATTRIBUTES (current_function_decl));
+       && do_ubsan_in_current_function ();
     }
 
   virtual unsigned int execute (function *);
index 5d9d90933a262e7131daedb6610f46827e961a31..9b8a59b6c84d84096113afb5a260ed50b8a8fd24 100644 (file)
@@ -38,6 +38,7 @@ enum ubsan_print_style {
   UBSAN_PRINT_ARRAY
 };
 
+extern bool do_ubsan_in_current_function (void);
 extern bool ubsan_expand_bounds_ifn (gimple_stmt_iterator *);
 extern bool ubsan_expand_null_ifn (gimple_stmt_iterator *);
 extern bool ubsan_expand_objsize_ifn (gimple_stmt_iterator *);