re PR objc/17923 (const-str-[34].m fails on the mainline (next runtime))
authorAndrew Pinski <pinskia@physics.uc.edu>
Thu, 21 Oct 2004 16:29:58 +0000 (16:29 +0000)
committerAndrew Pinski <pinskia@gcc.gnu.org>
Thu, 21 Oct 2004 16:29:58 +0000 (09:29 -0700)
2004-10-21  Andrew Pinski  <pinskia@physics.uc.edu>

        PR objc/17923
        * tree.c (staticp): A CONST_DECL has static storage if either
        TREE_STATIC or DECL_EXTERNAL is set.
        * c-decl.c (pushdecl_top_level): Accept CONST_DECLs which can
        have null names.

2004-10-21  Andrew Pinski  <pinskia@physics.uc.edu>

        PR objc/17923
        * objc-act.c (objc_build_string_object): Create a CONST_DECL
        for the NeXT runtime case.

2004-10-21  Andrew Pinski  <pinskia@physics.uc.edu>

        PR objc/17923
        * objc.dg/const-str-7.m: New test.

From-SVN: r89384

gcc/ChangeLog
gcc/c-decl.c
gcc/objc/ChangeLog
gcc/objc/objc-act.c
gcc/testsuite/ChangeLog
gcc/testsuite/objc.dg/const-str-7.m [new file with mode: 0644]
gcc/tree.c

index 95774e2f2766832845d4a60c09a657009cf5eea1..ba84e868f7d554c0c1c79045e35cead32831b94c 100644 (file)
@@ -1,3 +1,11 @@
+2004-10-21  Andrew Pinski  <pinskia@physics.uc.edu>
+
+       PR objc/17923
+       * tree.c (staticp): A CONST_DECL has static storage if either
+       TREE_STATIC or DECL_EXTERNAL is set.
+       * c-decl.c (pushdecl_top_level): Accept CONST_DECLs which can
+       have null names.
+
 2004-10-21  Kazu Hirata  <kazu@cs.umass.edu>
 
        * expr.c (store_expr): Remove dont_store_target.
index 9e9813d7f78416f014330aec087906438c25b95a..a2443ec6c19e8419fc9bb0e2eb0000b05b2581f3 100644 (file)
@@ -2128,12 +2128,11 @@ pushdecl_top_level (tree x)
 {
   tree name;
   bool nested = false;
-
-  gcc_assert (TREE_CODE (x) == VAR_DECL);
+  gcc_assert (TREE_CODE (x) == VAR_DECL || TREE_CODE (x) == CONST_DECL);
 
   name = DECL_NAME (x);
 
 gcc_assert (!I_SYMBOL_BINDING (name));
gcc_assert (TREE_CODE (x) == CONST_DECL || !I_SYMBOL_BINDING (name));
 
   if (TREE_PUBLIC (x))
     {
index 734f74d6bf98c548cd0e60567d280800e36735b8..b904fa0ee5e736a1e341ba713c3855951e71affa 100644 (file)
@@ -1,3 +1,9 @@
+2004-10-21  Andrew Pinski  <pinskia@physics.uc.edu>
+
+       PR objc/17923
+       * objc-act.c (objc_build_string_object): Create a CONST_DECL
+       for the NeXT runtime case.
+
 2004-10-02  Kazu Hirata  <kazu@cs.umass.edu>
 
        * objc-act.c: Fix comment typos.
index e530f2c1dff4cab70d3e8740c4f3c56e50b9dc19..34550959482910706b04c29d2a7b9c9eb3406d25 100644 (file)
@@ -1661,6 +1661,7 @@ objc_build_string_object (tree string)
 
   if (!desc)
     {
+      tree var;
       *loc = desc = ggc_alloc (sizeof (*desc));
       desc->literal = string;
 
@@ -1685,14 +1686,18 @@ objc_build_string_object (tree string)
       if (!flag_next_runtime)
        constructor
          = objc_add_static_instance (constructor, constant_string_type);
-
+      else
+        {
+         var = build_decl (CONST_DECL, NULL, TREE_TYPE (constructor));
+         DECL_INITIAL (var) = constructor;
+         TREE_STATIC (var) = 1;
+         pushdecl_top_level (var);
+         constructor = var;
+       }
       desc->constructor = constructor;
     }
 
   addr = build_unary_op (ADDR_EXPR, desc->constructor, 1);
-  TREE_CONSTANT (addr) = true;
-  TREE_INVARIANT (addr) = true;
-  TREE_STATIC (addr) = true;
 
   return addr;
 }
index 83838ee8c8c37dda3aca43ce50cc8527b7a186c5..b7f25ddf4dde71d7e34cc158ba62dc1df5ee9070 100644 (file)
@@ -1,3 +1,8 @@
+2004-10-21  Andrew Pinski  <pinskia@physics.uc.edu>
+
+       PR objc/17923
+       * objc.dg/const-str-7.m: New test.
+
 2004-10-20  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>
 
        * g++.dg/template/memfriend11.C: Fix comment typo.
diff --git a/gcc/testsuite/objc.dg/const-str-7.m b/gcc/testsuite/objc.dg/const-str-7.m
new file mode 100644 (file)
index 0000000..3691579
--- /dev/null
@@ -0,0 +1,46 @@
+/* Test to make sure that the const objc strings are the same across
+   scopes.  */
+/* Developed by Andrew Pinski <pinskia@physics.uc.edu> */
+
+
+/* { dg-options "-fnext-runtime -fconstant-string-class=Foo -lobjc" } */
+/* { dg-do run { target *-*-darwin* } } */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <memory.h>
+#include <objc/objc.h>
+#include <objc/Object.h>
+
+
+@interface Foo: Object {
+  char *cString;
+  unsigned int len;
+}
+- (char *)customString;
+@end
+
+struct objc_class _FooClassReference;
+
+
+@implementation Foo : Object
+- (char *)customString {
+  return cString;
+}
+@end
+
+
+int main () {
+  Foo *string = @"bla";
+  {
+    Foo *string2 = @"bla";
+
+
+    if(string != string2)
+      abort();
+    printf("Strings are being uniqued properly\n");
+   }
+  return 0;
+}
+
index e07bd4799087f269cfa3785f6bd88a36815e3d47..b132571b5f397839c334b8fd9cc045d9d401d9c1 100644 (file)
@@ -1489,6 +1489,10 @@ staticp (tree arg)
              && ! DECL_NON_ADDR_CONST_P (arg)
              ? arg : NULL);
 
+    case CONST_DECL:
+      return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
+             ? arg : NULL);
+
     case CONSTRUCTOR:
       return TREE_STATIC (arg) ? arg : NULL;