enum machine_mode));
static rtx expand_builtin_memcpy PARAMS ((tree, rtx,
enum machine_mode, int));
+static rtx expand_builtin_mempcpy PARAMS ((tree, rtx,
+ enum machine_mode));
static rtx expand_builtin_memmove PARAMS ((tree, rtx,
enum machine_mode));
static rtx expand_builtin_bcopy PARAMS ((tree));
}
}
+/* Expand a call to the mempcpy builtin, with arguments in ARGLIST.
+ Return 0 if we failed the caller should emit a normal call,
+ otherwise try to get the result in TARGET, if convenient (and in
+ mode MODE if that's convenient). */
+
+static rtx
+expand_builtin_mempcpy (arglist, target, mode)
+ tree arglist;
+ rtx target;
+ enum machine_mode mode;
+{
+ if (!validate_arglist (arglist,
+ POINTER_TYPE, POINTER_TYPE, INTEGER_TYPE, VOID_TYPE))
+ return 0;
+ else
+ {
+ /* If return value is ignored, transform mempcpy into memcpy. */
+ if (target == const0_rtx)
+ {
+ tree fn;
+ rtx ret = expand_builtin_memcpy (arglist, target, mode, /*endp=*/0);
+
+ if (ret)
+ return ret;
+
+ fn = implicit_built_in_decls[BUILT_IN_MEMCPY];
+ if (!fn)
+ return 0;
+
+ return expand_expr (build_function_call_expr (fn, arglist),
+ target, mode, EXPAND_NORMAL);
+ }
+
+ return expand_builtin_memcpy (arglist, target, mode, /*endp=*/1);
+ }
+}
+
/* Expand expression EXP, which is a call to the memmove builtin. Return 0
if we failed the caller should emit a normal call. */
else
{
tree newarglist;
- tree len = c_strlen (TREE_VALUE (TREE_CHAIN (arglist)));
+ tree len;
+
+ /* If return value is ignored, transform stpcpy into strcpy. */
+ if (target == const0_rtx)
+ {
+ tree fn;
+ rtx ret = expand_builtin_strcpy (arglist, target, mode);
+
+ if (ret)
+ return ret;
+
+ fn = implicit_built_in_decls[BUILT_IN_STRCPY];
+ if (!fn)
+ return 0;
+
+ return expand_expr (build_function_call_expr (fn, arglist),
+ target, mode, EXPAND_NORMAL);
+ }
+
+ len = c_strlen (TREE_VALUE (TREE_CHAIN (arglist)));
if (len == 0)
return 0;
break;
case BUILT_IN_MEMPCPY:
- target = expand_builtin_memcpy (arglist, target, mode, /*endp=*/1);
+ target = expand_builtin_mempcpy (arglist, target, mode);
if (target)
return target;
break;
const char s1[] = "123";
char p[32] = "";
+char *s2 = "defg";
+char *s3 = "FGH";
+size_t l1 = 1;
int main()
{
if (__builtin_mempcpy (p, "ABCDE", 6) != p + 6 || memcmp (p, "ABCDE", 6))
abort ();
+ /* If the result of stpcpy/mempcpy is ignored, gcc should use
+ strcpy/memcpy. */
+ stpcpy (p + 3, s2);
+ if (memcmp (p, "ABCdefg", 8))
+ abort ();
+ mempcpy (p + 5, s3, 1);
+ if (memcmp (p, "ABCdeFg", 8))
+ abort ();
+ mempcpy (p + 6, s3 + 1, l1);
+ if (memcmp (p, "ABCdeFG", 8))
+ abort ();
return 0;
}