This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: __builtin_constant_p broken


Jeffrey A Law <law@cygnus.com> writes:

|>   In message <vyzg1daui6d.fsf@issan.informatik.uni-dortmund.de>you write:
|>   > __builtin_constant_p is supposed to expand to true only for arguments that
|>   > are compile-time constants.
|>   > 
|>   > 
|>   > 1998-09-29  Andreas Schwab  <schwab@issan.informatik.uni-dortmund.de>
|>   > 
|>   > 	* expr.c (expand_builtin, case BUILT_IN_CONSTANT_P): Return true
|>   > 	only for compile-time constants.
|>   > 	* cse.c (fold_rtx): Check that the argument of CONSTANT_P_RTX is a
|>   > 	compile-time constant.
|>   > 
|>   > --- egcs-2.92/gcc/cse.c.~1~	Tue Sep  8 14:20:28 1998
|>   > +++ egcs-2.92/gcc/cse.c	Tue Sep 29 22:10:01 1998
|>   > @@ -5749,7 +5749,12 @@
|>   >      case 'x':
|>   >        /* Always eliminate CONSTANT_P_RTX at this stage. */
|>   >        if (code == CONSTANT_P_RTX)
|>   > -	return (const_arg0 ? const1_rtx : const0_rtx);
|>   > +	return ((const_arg0
|>   > +		 && (GET_CODE (const_arg0) == CONST_INT
|>   > +		     || GET_CODE (const_arg0) == CONST_DOUBLE
|>   > +		     || (GET_CODE (const_arg0) == SYMBOL_REF
|>   > +			 && CONSTANT_POOL_ADDRESS_P (const_arg0))))
|>   > +		? const1_rtx : const0_rtx);
|>   >        break;
|> Shouldn't the check just be CONSTANT_P?   What specifically is appearing in
|> const_arg0 which isn't a compile-time constant?

A SYMBOL_REF that is not a reference to the constant pool.
Here is an example:

char foo[10], bar[10];

#define strcpy(a,b) \
  (__builtin_constant_p (b)
   ? (char *) memcpy (a, b, strlen (b) + 1)
   : strcpy (a, b))

int main ()
{
  strcpy (foo, bar);
  return 0;
}

__builtin_constant_p (bar) returns true, but strlen (bar) does not expand
to a constant.  This makes __builtin_constant_p useless.

Andreas.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]