===================================================================
@@ -1696,6 +1696,11 @@ set_mem_attributes_minus_bitpos (rtx ref
&& !TREE_THIS_VOLATILE (base))
MEM_READONLY_P (ref) = 1;
+ /* Mark static const strings readonly as well. */
+ if (base && TREE_CODE (base) == STRING_CST && TREE_READONLY (base)
+ && TREE_STATIC (base))
+ MEM_READONLY_P (ref) = 1;
+
/* If this expression uses it's parent's alias set, mark it such
that we won't change it. */
if (component_uses_parent_alias_set (t))
===================================================================
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-rtl-expand" } */
+
+void
+f1 (char *p)
+{
+ __builtin_memcpy (p, "123", 3);
+}
+
+/* { dg-final { scan-rtl-dump-times "mem/s/u" 3 "expand" { target mips*-*-* } } } */
+/* { dg-final { cleanup-rtl-dump "expand" } } */