This is the mail archive of the gcc@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]

[Tiny patch] builtin_constant_p improvement.


Hi,

The enclosed patch causes the following (recently posted) code to
return 1 when compiled as C code.  (It already does when compiled as
C++).  It removes an assumption that pointers can only be constant if
they are literals.

inline int f (const char *const s)
{
  if (__builtin_constant_p (s))
    return 1;
  else 
    return 0;
}

int g ()
{
  return f ("abc");
}

Ralph.
-------------------------------------
--- gcc/builtins.c~	Tue Jul  4 06:28:33 2000
+++ gcc/builtins.c	Thu Aug  3 20:38:49 2000
@@ -1167,12 +1167,11 @@
 
       /* If we aren't going to be running CSE or this expression
 	 has side effects, show we don't know it to be a constant.
-	 Likewise if it's a pointer or aggregate type since in those
-	 case we only want literals, since those are only optimized
+	 Likewise if it's an aggregate type, since in that
+	 case we only want literals, since that is only optimized
 	 when generating RTL, not later.  */
       if (TREE_SIDE_EFFECTS (arg) || cse_not_expected
-	  || AGGREGATE_TYPE_P (TREE_TYPE (arg))
-	  || POINTER_TYPE_P (TREE_TYPE (arg)))
+	  || AGGREGATE_TYPE_P (TREE_TYPE (arg)))
 	return const0_rtx;
 
       /* Otherwise, emit (constant_p_rtx (ARG)) and let CSE get a

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