diff options
author | Bernd Edlinger <bernd.edlinger@hotmail.de> | 2018-11-09 20:38:07 +0000 |
---|---|---|
committer | Bernd Edlinger <edlinger@gcc.gnu.org> | 2018-11-09 20:38:07 +0000 |
commit | ab386758ef41dad695ccf25f975ebf12b4afe8c4 (patch) | |
tree | b4e750d78e5710a9c0ddaf5743b86c604eedd376 /gcc/expr.c | |
parent | 340e0dd66466091ea2bbd160592c017eb67dc47d (diff) | |
download | gcc-ab386758ef41dad695ccf25f975ebf12b4afe8c4.zip gcc-ab386758ef41dad695ccf25f975ebf12b4afe8c4.tar.gz gcc-ab386758ef41dad695ccf25f975ebf12b4afe8c4.tar.bz2 |
re PR tree-optimization/87940 (FAIL: gcc.dg/warn-strlen-no-nul.c)
2018-11-09 Bernd Edlinger <bernd.edlinger@hotmail.de>
PR tree-optimization/87940
* expr.c (string_constant): Don't strip NOPS in subexpressions.
Fold PLUS_EXPR correctly.
From-SVN: r265992
Diffstat (limited to 'gcc/expr.c')
-rw-r--r-- | gcc/expr.c | 25 |
1 files changed, 12 insertions, 13 deletions
@@ -11358,18 +11358,15 @@ string_constant (tree arg, tree *ptr_offset, tree *mem_size, tree *decl) tree arg0 = TREE_OPERAND (arg, 0); tree arg1 = TREE_OPERAND (arg, 1); - STRIP_NOPS (arg0); - STRIP_NOPS (arg1); - - if (TREE_CODE (arg0) == ADDR_EXPR) - ; /* Do nothing. */ - else if (TREE_CODE (arg1) == ADDR_EXPR) - std::swap (arg0, arg1); - else - return NULL_TREE; - tree offset; - if (tree str = string_constant (arg0, &offset, mem_size, decl)) + tree str = string_constant (arg0, &offset, mem_size, decl); + if (!str) + { + str = string_constant (arg1, &offset, mem_size, decl); + arg1 = arg0; + } + + if (str) { /* Avoid pointers to arrays (see bug 86622). */ if (POINTER_TYPE_P (TREE_TYPE (arg)) @@ -11380,7 +11377,8 @@ string_constant (tree arg, tree *ptr_offset, tree *mem_size, tree *decl) && tree_int_cst_equal (*mem_size, DECL_SIZE_UNIT (*decl)))) return NULL_TREE; - tree type = TREE_TYPE (arg1); + tree type = TREE_TYPE (offset); + arg1 = fold_convert (type, arg1); *ptr_offset = fold_build2 (PLUS_EXPR, type, offset, arg1); return str; } @@ -11412,7 +11410,8 @@ string_constant (tree arg, tree *ptr_offset, tree *mem_size, tree *decl) return NULL_TREE; tree rhs2 = gimple_assign_rhs2 (stmt); - tree type = TREE_TYPE (rhs2); + tree type = TREE_TYPE (offset); + rhs2 = fold_convert (type, rhs2); *ptr_offset = fold_build2 (PLUS_EXPR, type, offset, rhs2); return str; } |