diff options
author | Jakub Jelinek <jakub@redhat.com> | 2017-09-04 10:11:44 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2017-09-04 10:11:44 +0200 |
commit | ca1150f0129abd2b0b52ad0c701a6bd7e0a1fc76 (patch) | |
tree | 5b5f269d8ebdc8d44079151eb4288310ab65b1c4 /gcc/gimple-fold.c | |
parent | 40008742c5f7c84ddd16f7da562bebca1a179d4b (diff) | |
download | gcc-ca1150f0129abd2b0b52ad0c701a6bd7e0a1fc76.zip gcc-ca1150f0129abd2b0b52ad0c701a6bd7e0a1fc76.tar.gz gcc-ca1150f0129abd2b0b52ad0c701a6bd7e0a1fc76.tar.bz2 |
re PR sanitizer/81981 (-fsanitize=undefined makes a -Wmaybe-uninitialized warning disappear)
PR sanitizer/81981
* gimple-fold.c (gimple_fold_call): Optimize away useless UBSAN_PTR
and UBSAN_BOUNDS internal calls. Clean up IFN_UBSAN_OBJECT_SIZE
handling. Use replace_call_with_value with NULL instead of
gsi_replace, unlink_stmt_vdef and release_defs.
* gcc.dg/ubsan/pr81981.c: New test.
From-SVN: r251641
Diffstat (limited to 'gcc/gimple-fold.c')
-rw-r--r-- | gcc/gimple-fold.c | 41 |
1 files changed, 33 insertions, 8 deletions
diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c index 367b35c..8366e4b 100644 --- a/gcc/gimple-fold.c +++ b/gcc/gimple-fold.c @@ -3936,18 +3936,43 @@ gimple_fold_call (gimple_stmt_iterator *gsi, bool inplace) gimple_call_arg (stmt, 2)); break; case IFN_UBSAN_OBJECT_SIZE: - if (integer_all_onesp (gimple_call_arg (stmt, 2)) - || (TREE_CODE (gimple_call_arg (stmt, 1)) == INTEGER_CST - && TREE_CODE (gimple_call_arg (stmt, 2)) == INTEGER_CST - && tree_int_cst_le (gimple_call_arg (stmt, 1), - gimple_call_arg (stmt, 2)))) + { + tree offset = gimple_call_arg (stmt, 1); + tree objsize = gimple_call_arg (stmt, 2); + if (integer_all_onesp (objsize) + || (TREE_CODE (offset) == INTEGER_CST + && TREE_CODE (objsize) == INTEGER_CST + && tree_int_cst_le (offset, objsize))) + { + replace_call_with_value (gsi, NULL_TREE); + return true; + } + } + break; + case IFN_UBSAN_PTR: + if (integer_zerop (gimple_call_arg (stmt, 1))) { - gsi_replace (gsi, gimple_build_nop (), false); - unlink_stmt_vdef (stmt); - release_defs (stmt); + replace_call_with_value (gsi, NULL_TREE); return true; } break; + case IFN_UBSAN_BOUNDS: + { + tree index = gimple_call_arg (stmt, 1); + tree bound = gimple_call_arg (stmt, 2); + if (TREE_CODE (index) == INTEGER_CST + && TREE_CODE (bound) == INTEGER_CST) + { + index = fold_convert (TREE_TYPE (bound), index); + if (TREE_CODE (index) == INTEGER_CST + && tree_int_cst_le (index, bound)) + { + replace_call_with_value (gsi, NULL_TREE); + return true; + } + } + } + break; case IFN_GOACC_DIM_SIZE: case IFN_GOACC_DIM_POS: result = fold_internal_goacc_dim (stmt); |