diff options
author | Ivan Baravy <i.baravy@samsung.com> | 2017-02-27 11:44:27 +0300 |
---|---|---|
committer | Ivan Baravy <i.baravy@samsung.com> | 2017-02-27 16:45:00 +0300 |
commit | cccdb7369b2e4c65da334641884ab6f383497fc8 (patch) | |
tree | 0515511657fffdd74a7c9f8ccd8dfda11eb4e2d5 | |
parent | 6b3e63486ce3712ca2d6025785c50053326d8e10 (diff) | |
download | linaro-gcc-cccdb7369b2e4c65da334641884ab6f383497fc8.tar.gz linaro-gcc-cccdb7369b2e4c65da334641884ab6f383497fc8.tar.bz2 linaro-gcc-cccdb7369b2e4c65da334641884ab6f383497fc8.zip |
Fix the UBSan inexpensive call sanitization
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
-rw-r--r-- | gcc/gimple.c | 14 | ||||
-rw-r--r-- | gcc/gimple.h | 1 | ||||
-rw-r--r-- | gcc/tree-ssa-loop-ch.c | 3 | ||||
-rw-r--r-- | gcc/tree-ssa-loop-ivcanon.c | 16 |
4 files changed, 24 insertions, 10 deletions
diff --git a/gcc/gimple.c b/gcc/gimple.c index b06e62ce274..b874c9fdd3d 100644 --- a/gcc/gimple.c +++ b/gcc/gimple.c @@ -38,6 +38,7 @@ along with GCC; see the file COPYING3. If not see #include "gimple-walk.h" #include "gimplify.h" #include "target.h" +#include "builtins.h" /* All the tuples have their operand vector (if present) at the very bottom @@ -3007,3 +3008,16 @@ maybe_remove_unused_call_args (struct function *fn, gimple *stmt) update_stmt_fn (fn, stmt); } } + +/* 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; +} diff --git a/gcc/gimple.h b/gcc/gimple.h index 6d15dab5120..e0dfc3f8e74 100644 --- a/gcc/gimple.h +++ b/gcc/gimple.h @@ -1522,6 +1522,7 @@ extern bool infer_nonnull_range_by_attribute (gimple *, tree); 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 *); extern void gimple_seq_discard (gimple_seq); extern void maybe_remove_unused_call_args (struct function *, gimple *); diff --git a/gcc/tree-ssa-loop-ch.c b/gcc/tree-ssa-loop-ch.c index 907525627d0..64f784cdcc2 100644 --- a/gcc/tree-ssa-loop-ch.c +++ b/gcc/tree-ssa-loop-ch.c @@ -90,7 +90,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); diff --git a/gcc/tree-ssa-loop-ivcanon.c b/gcc/tree-ssa-loop-ivcanon.c index 9b59b4466c3..5d335e20e95 100644 --- a/gcc/tree-ssa-loop-ivcanon.c +++ b/gcc/tree-ssa-loop-ivcanon.c @@ -339,22 +339,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) |