Patch to add builtin strcat/strncat/strspn/strcspn

Kaveh R. Ghazi ghazi@caip.rutgers.edu
Thu Nov 30 05:52:00 GMT 2000


 > From: Jakub Jelinek <jakub@redhat.com>
 > 
 > strcpsn (s1, "a") could be also transformed into strlenM insn if the targets
 > have it (the pattern can have non-zero eoschar).

Okay thanks.  I'd like that to be handled separately.


 > > +static rtx
 > > +expand_builtin_strcat (arglist, target, mode)
 > ...
 > > +      tree dst = TREE_VALUE (arglist),
 > > +	src = TREE_VALUE (TREE_CHAIN (arglist)),
 > > +	slen = c_strlen (src);
 > > +
 > > +      /* If the string length is zero, return the dst parameter.  */
 > > +      if (slen && compare_tree_int (slen, 0) == 0)
 > 
 > Either you should check here for TREE_CODE (slen) == INTEGER_CST, or
 > alternatively use p = c_getstr (src) instead of c_strlen and check for
 > p[0] == '\0'.
 > 
 > > +static rtx
 > > +expand_builtin_strncat (arglist, target, mode)
 > ...
 > > +	slen = c_strlen (src),
 > > +	fn = built_in_decls[BUILT_IN_STRCAT];
 > > +
 > > +      /* If the requested length is zero, or the src parameter string
 > > +          length is zero, return the dst parameter.  */
 > > +      if ((TREE_CODE (len) == INTEGER_CST && compare_tree_int (len, 0) == 0)
 > > +	  || (slen && compare_tree_int (slen, 0) == 0))
 > 
 > Likewise.

Ok, I'll fix that.


 > IMHO the following two expand_exprs are not necessary, if TREE_CODE (len)
 > and TREE_CODE (slen) are INTEGER_CSTs, how can they have side-effects?
 > 
 > > +	  expand_expr (src, const0_rtx, VOIDmode, EXPAND_NORMAL);
 > > +	  expand_expr (len, const0_rtx, VOIDmode, EXPAND_NORMAL);
 > > +	  return expand_expr (dst, target, mode, EXPAND_NORMAL);
 > 	Jakub

The if condition is ||, not &&.  So either parameter (but not
necessarily both) could be INTEGER_CST.  E.g.:

If (strlen(src) == 0 || len == 0)
{
  expand both
  return dst
}

That way, if either one happens to NOT be constant (we don't care
which) it'll do the right thing WRT side effects.

		--Kaveh
--
Kaveh R. Ghazi			Engagement Manager / Project Services
ghazi@caip.rutgers.edu		Qwest Internet Solutions


More information about the Gcc-patches mailing list