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]

__builtin_constant_p broken


__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;
     }
 
--- egcs-2.92/gcc/expr.c.~1~	Tue Sep 29 21:55:25 1998
+++ egcs-2.92/gcc/expr.c	Tue Sep 29 21:55:40 1998
@@ -8828,8 +8828,12 @@
 	{
 	  tree arg = TREE_VALUE (arglist);
 
-	  STRIP_NOPS (arg);
-	  if (really_constant_p (arg)
+	  /* This is not quite the same as STRIP_NOPS.  It does more.  */
+	  while (TREE_CODE (arg) == NOP_EXPR
+		 || TREE_CODE (arg) == CONVERT_EXPR
+		 || TREE_CODE (arg) == NON_LVALUE_EXPR)
+	    arg = TREE_OPERAND (arg, 0);
+	  if (TREE_CODE_CLASS (TREE_CODE (arg)) == 'c'
 	      || (TREE_CODE (arg) == ADDR_EXPR
 		  && TREE_CODE (TREE_OPERAND (arg, 0)) == STRING_CST))
 	    return const1_rtx;

-- 
Andreas Schwab                                      "And now for something
schwab@issan.informatik.uni-dortmund.de              completely different"
schwab@gnu.org


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