+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.
+
2018-11-09 Ilya Leoshkevich <iii@linux.ibm.com>
PR target/87762
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))
&& 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;
}
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;
}