This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[tree-ssa] PATCH to simplify_builtin*
- From: Jason Merrill <jason at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Fri, 29 Aug 2003 18:26:55 -0400
- Subject: [tree-ssa] PATCH to simplify_builtin*
This patch fixes several type-correctess bugs in the simplify_builtin*
functions. All the COMPOUND_EXPRs had the wrong type, and we were often
returning a simplified form with a different type from the call.
Booted and tested powerpc-linux-gnu, applied to tree-ssa.
2003-08-29 Jason Merrill <jason@redhat.com>
* builtins.c (simplify_builtin): Make sure that the replacement
has the same type as the original expression.
(simplify_builtin_strpbrk): Fix type of COMPOUND_EXPR.
(simplify_builtin_strncpy, simplify_builtin_memcmp): Likewise.
(simplify_builtin_strncmp, simplify_builtin_strncat): Likewise.
(simplify_builtin_strspn, simplify_builtin_strcspn): Likewise.
(simplify_builtin_fputs, simplify_builtin_sprintf): Likewise.
*** builtins.c.~1~ 2003-08-29 11:04:22.000000000 -0400
--- builtins.c 2003-08-29 13:35:01.000000000 -0400
*************** simplify_builtin (tree exp, int ignore)
*** 6421,6469 ****
tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
tree arglist = TREE_OPERAND (exp, 1);
enum built_in_function fcode = DECL_FUNCTION_CODE (fndecl);
switch (fcode)
{
case BUILT_IN_FPUTS:
! return simplify_builtin_fputs (arglist, ignore, 0, NULL_TREE);
case BUILT_IN_FPUTS_UNLOCKED:
! return simplify_builtin_fputs (arglist, ignore, 1, NULL_TREE);
case BUILT_IN_STRSTR:
! return simplify_builtin_strstr (arglist);
case BUILT_IN_STRCAT:
! return simplify_builtin_strcat (arglist);
case BUILT_IN_STRNCAT:
! return simplify_builtin_strncat (arglist);
case BUILT_IN_STRSPN:
! return simplify_builtin_strspn (arglist);
case BUILT_IN_STRCSPN:
! return simplify_builtin_strcspn (arglist);
case BUILT_IN_STRCHR:
case BUILT_IN_INDEX:
! return simplify_builtin_strchr (arglist);
case BUILT_IN_STRRCHR:
case BUILT_IN_RINDEX:
! return simplify_builtin_strrchr (arglist);
case BUILT_IN_STRCPY:
! return simplify_builtin_strcpy (arglist);
case BUILT_IN_STRNCPY:
! return simplify_builtin_strncpy (arglist);
case BUILT_IN_STRCMP:
! return simplify_builtin_strcmp (arglist);
case BUILT_IN_STRNCMP:
! return simplify_builtin_strncmp (arglist);
case BUILT_IN_STRPBRK:
! return simplify_builtin_strpbrk (arglist);
case BUILT_IN_BCMP:
case BUILT_IN_MEMCMP:
! return simplify_builtin_memcmp (arglist);
case BUILT_IN_VA_START:
simplify_builtin_va_start (arglist);
! return NULL_TREE;
case BUILT_IN_SPRINTF:
! return simplify_builtin_sprintf (arglist, ignore);
default:
! return NULL_TREE;
}
}
/* Simplify a call to the strstr builtin.
--- 6421,6493 ----
tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
tree arglist = TREE_OPERAND (exp, 1);
enum built_in_function fcode = DECL_FUNCTION_CODE (fndecl);
+ tree val;
+
switch (fcode)
{
case BUILT_IN_FPUTS:
! val = simplify_builtin_fputs (arglist, ignore, 0, NULL_TREE);
! break;
case BUILT_IN_FPUTS_UNLOCKED:
! val = simplify_builtin_fputs (arglist, ignore, 1, NULL_TREE);
! break;
case BUILT_IN_STRSTR:
! val = simplify_builtin_strstr (arglist);
! break;
case BUILT_IN_STRCAT:
! val = simplify_builtin_strcat (arglist);
! break;
case BUILT_IN_STRNCAT:
! val = simplify_builtin_strncat (arglist);
! break;
case BUILT_IN_STRSPN:
! val = simplify_builtin_strspn (arglist);
! break;
case BUILT_IN_STRCSPN:
! val = simplify_builtin_strcspn (arglist);
! break;
case BUILT_IN_STRCHR:
case BUILT_IN_INDEX:
! val = simplify_builtin_strchr (arglist);
! break;
case BUILT_IN_STRRCHR:
case BUILT_IN_RINDEX:
! val = simplify_builtin_strrchr (arglist);
! break;
case BUILT_IN_STRCPY:
! val = simplify_builtin_strcpy (arglist);
! break;
case BUILT_IN_STRNCPY:
! val = simplify_builtin_strncpy (arglist);
! break;
case BUILT_IN_STRCMP:
! val = simplify_builtin_strcmp (arglist);
! break;
case BUILT_IN_STRNCMP:
! val = simplify_builtin_strncmp (arglist);
! break;
case BUILT_IN_STRPBRK:
! val = simplify_builtin_strpbrk (arglist);
! break;
case BUILT_IN_BCMP:
case BUILT_IN_MEMCMP:
! val = simplify_builtin_memcmp (arglist);
! break;
case BUILT_IN_VA_START:
simplify_builtin_va_start (arglist);
! val = NULL_TREE;
! break;
case BUILT_IN_SPRINTF:
! val = simplify_builtin_sprintf (arglist, ignore);
! break;
default:
! val = NULL_TREE;
! break;
}
+
+ if (val)
+ val = convert (TREE_TYPE (exp), val);
+ return val;
}
/* Simplify a call to the strstr builtin.
*************** simplify_builtin_strpbrk (tree arglist)
*** 6696,6702 ****
/* strpbrk(x, "") == NULL.
Evaluate and ignore the arguments in case they had
side-effects. */
! return build (COMPOUND_EXPR, void_type_node, s1, integer_zero_node);
}
if (p2[1] != '\0')
--- 6720,6727 ----
/* strpbrk(x, "") == NULL.
Evaluate and ignore the arguments in case they had
side-effects. */
! return build (COMPOUND_EXPR, integer_type_node, s1,
! integer_zero_node);
}
if (p2[1] != '\0')
*************** simplify_builtin_strncpy (tree arglist)
*** 6791,6797 ****
{
/* Evaluate and ignore the src argument in case it has
side-effects and return the dst parameter. */
! return build (COMPOUND_EXPR, void_type_node,
TREE_VALUE (TREE_CHAIN (arglist)),
TREE_VALUE (arglist));
}
--- 6816,6822 ----
{
/* Evaluate and ignore the src argument in case it has
side-effects and return the dst parameter. */
! return build (COMPOUND_EXPR, TREE_TYPE (TREE_VALUE (arglist)),
TREE_VALUE (TREE_CHAIN (arglist)),
TREE_VALUE (arglist));
}
*************** simplify_builtin_memcmp (tree arglist)
*** 6851,6858 ****
{
/* Evaluate and ignore arg1 and arg2 in case they have
side-effects. */
! return build (COMPOUND_EXPR, void_type_node, arg1,
! build (COMPOUND_EXPR, void_type_node,
arg2, integer_zero_node));
}
--- 6876,6883 ----
{
/* Evaluate and ignore arg1 and arg2 in case they have
side-effects. */
! return build (COMPOUND_EXPR, integer_type_node, arg1,
! build (COMPOUND_EXPR, integer_type_node,
arg2, integer_zero_node));
}
*************** simplify_builtin_strncmp (tree arglist)
*** 7030,7037 ****
{
/* Evaluate and ignore arg1 and arg2 in case they have
side-effects. */
! return build (COMPOUND_EXPR, void_type_node, arg1,
! build (COMPOUND_EXPR, void_type_node,
arg2, integer_zero_node));
}
--- 7055,7062 ----
{
/* Evaluate and ignore arg1 and arg2 in case they have
side-effects. */
! return build (COMPOUND_EXPR, integer_type_node, arg1,
! build (COMPOUND_EXPR, integer_type_node,
arg2, integer_zero_node));
}
*************** simplify_builtin_strncat (tree arglist)
*** 7165,7180 ****
return 0;
else
{
! tree dst = TREE_VALUE (arglist),
! src = TREE_VALUE (TREE_CHAIN (arglist)),
! len = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
const char *p = c_getstr (src);
/* If the requested length is zero, or the src parameter string
length is zero, return the dst parameter. */
if (integer_zerop (len) || (p && *p == '\0'))
! return build (COMPOUND_EXPR, void_type_node, src,
! build (COMPOUND_EXPR, void_type_node, len, dst));
/* If the requested len is greater than or equal to the string
length, call strcat. */
--- 7190,7205 ----
return 0;
else
{
! tree dst = TREE_VALUE (arglist);
! tree src = TREE_VALUE (TREE_CHAIN (arglist));
! tree len = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
const char *p = c_getstr (src);
/* If the requested length is zero, or the src parameter string
length is zero, return the dst parameter. */
if (integer_zerop (len) || (p && *p == '\0'))
! return build (COMPOUND_EXPR, TREE_TYPE (dst), src,
! build (COMPOUND_EXPR, integer_type_node, len, dst));
/* If the requested len is greater than or equal to the string
length, call strcat. */
*************** simplify_builtin_strspn (tree arglist)
*** 7235,7242 ****
{
/* Evaluate and ignore both arguments in case either one has
side-effects. */
! return build (COMPOUND_EXPR, void_type_node, s1,
! build (COMPOUND_EXPR, void_type_node,
s2, integer_zero_node));
}
return 0;
--- 7260,7267 ----
{
/* Evaluate and ignore both arguments in case either one has
side-effects. */
! return build (COMPOUND_EXPR, integer_type_node, s1,
! build (COMPOUND_EXPR, integer_type_node,
s2, integer_zero_node));
}
return 0;
*************** simplify_builtin_strcspn (tree arglist)
*** 7282,7288 ****
{
/* Evaluate and ignore argument s2 in case it has
side-effects. */
! return build (COMPOUND_EXPR, void_type_node,
s2, integer_zero_node);
}
--- 7307,7313 ----
{
/* Evaluate and ignore argument s2 in case it has
side-effects. */
! return build (COMPOUND_EXPR, integer_type_node,
s2, integer_zero_node);
}
*************** simplify_builtin_fputs (tree arglist, in
*** 7354,7360 ****
{
case -1: /* length is 0, delete the call entirely . */
{
! return build (COMPOUND_EXPR, void_type_node,
TREE_VALUE (TREE_CHAIN (arglist)), integer_zero_node);
}
case 0: /* length is 1, call fputc. */
--- 7379,7385 ----
{
case -1: /* length is 0, delete the call entirely . */
{
! return build (COMPOUND_EXPR, integer_type_node,
TREE_VALUE (TREE_CHAIN (arglist)), integer_zero_node);
}
case 0: /* length is 1, call fputc. */
*************** simplify_builtin_sprintf (tree arglist,
*** 7515,7524 ****
}
if (call && retval)
! return build (COMPOUND_EXPR,
! TREE_TYPE (implicit_built_in_decls[BUILT_IN_SPRINTF]),
! call,
! retval);
else
return call;
}
--- 7540,7551 ----
}
if (call && retval)
! {
! retval = convert
! (TREE_TYPE (TREE_TYPE (implicit_built_in_decls[BUILT_IN_SPRINTF])),
! retval);
! return build (COMPOUND_EXPR, TREE_TYPE (retval), call, retval);
! }
else
return call;
}