diff options
-rw-r--r-- | gcc/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/c-decl.c | 5 | ||||
-rw-r--r-- | gcc/objc/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/objc/objc-act.c | 13 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/objc.dg/const-str-7.m | 46 | ||||
-rw-r--r-- | gcc/tree.c | 4 |
7 files changed, 80 insertions, 7 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 95774e2f276..ba84e868f7d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -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. diff --git a/gcc/c-decl.c b/gcc/c-decl.c index 9e9813d7f78..a2443ec6c19 100644 --- a/gcc/c-decl.c +++ b/gcc/c-decl.c @@ -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)) { diff --git a/gcc/objc/ChangeLog b/gcc/objc/ChangeLog index 734f74d6bf9..b904fa0ee5e 100644 --- a/gcc/objc/ChangeLog +++ b/gcc/objc/ChangeLog @@ -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. diff --git a/gcc/objc/objc-act.c b/gcc/objc/objc-act.c index e530f2c1dff..34550959482 100644 --- a/gcc/objc/objc-act.c +++ b/gcc/objc/objc-act.c @@ -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; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 83838ee8c8c..b7f25ddf4dd 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -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 index 00000000000..3691579381d --- /dev/null +++ b/gcc/testsuite/objc.dg/const-str-7.m @@ -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; +} + diff --git a/gcc/tree.c b/gcc/tree.c index e07bd479908..b132571b5f3 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -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; |