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]

PATCH: gcc/varasm.c: Constant String Pointer Subtraction


2000-12-28  Jeffrey Oldham  <oldham@codesourcery.com>

	* varasm.c (initializer_constant_valid_p): Indicate subtraction of
	pointers to the same string constant is absolute.

The third line of gcc.c-torture/compile/20001116-1.c involves
subtraction of pointers to a string constant.  Since gcc implements
all occurrences of the same ?static? string constants using the same
memory, pointer subtraction is permitted.

Tested on: i686-pc-linux-gnu and mips-sgi-irix6.5
Approved by: Mark Mitchell (mark@codesourcery.com)

Thanks,
Jeffrey D. Oldham
oldham@codesourcery.com
Index: varasm.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/varasm.c,v
retrieving revision 1.148
diff -c -p -r1.148 varasm.c
*** varasm.c	2000/12/22 12:27:36	1.148
--- varasm.c	2000/12/27 00:45:05
*************** initializer_constant_valid_p (value, end
*** 4252,4257 ****
--- 4252,4265 ----
  	     Then the value is absolute.  */
  	  if (valid0 == valid1 && valid0 != 0)
  	    return null_pointer_node;
+ 
+ 	  /* Since GCC guarantees that string constants are unique in the
+ 	     generated code, a subtraction between two copies of the same
+ 	     constant string is absolute.  */
+ 	  if (valid0 && TREE_CODE (valid0) == STRING_CST &&
+ 	      valid1 && TREE_CODE (valid1) == STRING_CST &&
+ 	      TREE_STRING_POINTER (valid0) == TREE_STRING_POINTER (valid1))
+ 	    return null_pointer_node;
  	}
  
        /* Support differences between labels.  */

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