varasm.c (initializer_constant_valid_p): Indicate subtraction of pointers to the...
authorJeffrey Oldham <oldham@codesourcery.com>
Thu, 28 Dec 2000 19:35:56 +0000 (19:35 +0000)
committerJeffrey D. Oldham <oldham@gcc.gnu.org>
Thu, 28 Dec 2000 19:35:56 +0000 (19:35 +0000)
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.

From-SVN: r38514

gcc/ChangeLog
gcc/varasm.c

index e826e1cf91bb4d11c28e511353198425e6c0368f..3230e138815cafbc2e1b15e1b093c995565ca0d4 100644 (file)
@@ -1,3 +1,8 @@
+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.
+
 2000-12-28  Joseph S. Myers  <jsm28@cam.ac.uk>
 
        * c-common.c (enum format_type): Add strfmon_format_type.
index b2c283e13b7d25e82d1aa305b30a99224e3adf61..8f76f45f7192eee94f3444c3362476eea4029129 100644 (file)
@@ -4252,6 +4252,14 @@ initializer_constant_valid_p (value, endtype)
             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.  */