Fix the UBSan inexpensive call sanitization 57/94857/5
authorSlava Barinov <v.barinov@samsung.com>
Fri, 30 Sep 2016 09:36:36 +0000 (12:36 +0300)
committerDongkyun Son <dongkyun.s@samsung.com>
Wed, 16 Nov 2016 04:34:49 +0000 (20:34 -0800)
The change imported in order to fix false positive -Wmaybe-uninitialized
in several packages in UBSan builds.

* gimple.c: Include builtins.h
(gimple_inexpensive_call_p): New function.
* gimple.h (gimple_inexpensive_call_p): Declare.
* tree-ssa-loop-ch.c (should_duplicate_loop_header_p): Use it.
* tree-ssa-loop-ivcanon.c (tree_estimate_loop_size): Likewise;
fix formatting.

upstream hash: f18de397b1e0523fd840800399ec6ea21ec04af8
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@237172 138bc75d-0d04-0410-961f-82ee72b054a4

Authored-by: hubicka
Change-Id: Ia58f6110f777f444c3679631f5406376e9e9925f
Signed-off-by: Slava Barinov <v.barinov@samsung.com>
gcc/gimple.c
gcc/gimple.h
gcc/tree-ssa-loop-ch.c
gcc/tree-ssa-loop-ivcanon.c

index 86b4ab3..69d2f9d 100644 (file)
@@ -47,6 +47,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "demangle.h"
 #include "langhooks.h"
 #include "bitmap.h"
+#include "builtins.h"
 
 
 /* All the tuples have their operand vector (if present) at the very bottom
@@ -2812,3 +2813,16 @@ gimple_seq_set_location (gimple_seq seq, location_t loc)
   for (gimple_stmt_iterator i = gsi_start (seq); !gsi_end_p (i); gsi_next (&i))
     gimple_set_location (gsi_stmt (i), loc);
 }
+
+/* Return false if STMT will likely expand to real function call.  */
+
+bool
+gimple_inexpensive_call_p (gimple stmt)
+{
+  if (gimple_call_internal_p (stmt))
+    return true;
+  tree decl = gimple_call_fndecl (stmt);
+  if (decl && is_inexpensive_builtin (decl))
+    return true;
+  return false;
+}
index 50a5a86..4340f86 100644 (file)
@@ -1268,6 +1268,7 @@ extern bool infer_nonnull_range (gimple, tree, bool, bool);
 extern void sort_case_labels (vec<tree> );
 extern void preprocess_case_label_vec_for_gimple (vec<tree> , tree, tree *);
 extern void gimple_seq_set_location (gimple_seq , location_t);
+extern bool gimple_inexpensive_call_p (gimple);
 
 /* Formal (expression) temporary table handling: multiple occurrences of
    the same scalar expression are evaluated into the same temporary.  */
index 0a6b1c1..56aba7f 100644 (file)
@@ -95,7 +95,8 @@ should_duplicate_loop_header_p (basic_block header, struct loop *loop,
       if (is_gimple_debug (last))
        continue;
 
-      if (is_gimple_call (last))
+      if (gimple_code (last) == GIMPLE_CALL
+         && !gimple_inexpensive_call_p (last))
        return false;
 
       *limit -= estimate_num_insns (last, &eni_size_weights);
index b475b06..b497f32 100644 (file)
@@ -336,22 +336,20 @@ tree_estimate_loop_size (struct loop *loop, edge exit, edge edge_to_cancel, stru
       for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
        {
          gimple stmt = gsi_stmt (gsi);
-         if (gimple_code (stmt) == GIMPLE_CALL)
+         if (gimple_code (stmt) == GIMPLE_CALL
+             && !gimple_inexpensive_call_p (stmt))
            {
              int flags = gimple_call_flags (stmt);
-             tree decl = gimple_call_fndecl (stmt);
-
-             if (decl && DECL_IS_BUILTIN (decl)
-                 && is_inexpensive_builtin (decl))
-               ;
-             else if (flags & (ECF_PURE | ECF_CONST))
+             if (flags & (ECF_PURE | ECF_CONST))
                size->num_pure_calls_on_hot_path++;
              else
                size->num_non_pure_calls_on_hot_path++;
              size->num_branches_on_hot_path ++;
            }
-         else if (gimple_code (stmt) != GIMPLE_CALL
-                  && gimple_code (stmt) != GIMPLE_DEBUG)
+         /* Count inexpensive calls as non-calls, because they will likely
+            expand inline.  */
+
+         else if (gimple_code (stmt) != GIMPLE_DEBUG)
            size->non_call_stmts_on_hot_path++;
          if (((gimple_code (stmt) == GIMPLE_COND
                && (!constant_after_peeling (gimple_cond_lhs (stmt), stmt, loop)