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]
Other format: [Raw text]

stop some constant folding of readonly arrays


Don't do it if we're not guaranteed to be reading from *this* array.

A test case that shows the problem, at least in assembly, is

	const int __attribute__((weak)) T[4] = { 1, 2, 3, 4 };
	int foo()
	{
	  return T[2];
	}

We should *not* fold T[2] to 3.  I have no idea how to make this
into a reliable test case.  Ideally this would be a two-part test,
with the second copy of T being strong and having a different set
of data within.

On tree-ssa branch, a patch that I'm working on cleaned up C++ array
accesses enough that we are suddenly able to look through vtable
initializers.  Which sounds cool, except that the symbol that we read
from the vtable is not exported from libstdc++.so.  Oops.

Applied to mainline.


r~


        * expr.c (expand_expr): Don't look through constant arrays if
        they don't bind locally.

Index: expr.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/expr.c,v
retrieving revision 1.601
diff -u -p -r1.601 expr.c
--- expr.c	18 Nov 2003 02:05:29 -0000	1.601
+++ expr.c	18 Nov 2003 08:32:53 -0000
@@ -6955,7 +6955,8 @@ expand_expr (tree exp, rtx target, enum 
 		 && modifier != EXPAND_MEMORY
 		 && TREE_READONLY (array) && ! TREE_SIDE_EFFECTS (array)
 		 && TREE_CODE (array) == VAR_DECL && DECL_INITIAL (array)
-		 && TREE_CODE (DECL_INITIAL (array)) != ERROR_MARK)
+		 && TREE_CODE (DECL_INITIAL (array)) != ERROR_MARK
+		 && targetm.binds_local_p (array))
 	  {
 	    if (TREE_CODE (index) == INTEGER_CST)
 	      {


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