On Oct 4, 2004, at 3:26 PM, Ziemowit Laski wrote:
Hey Andrew,
One nit:
-
+ else
+ {
+ var = build_decl (CONST_DECL, NULL, TREE_TYPE (constructor));
+ DECL_INITIAL (var) = constructor;
+ if (global_bindings_p ())
+ TREE_STATIC (var) = 1;
+ pushdecl (var);
+ constructor = var;
+ }
I think you want to use 'pushdecl_top_level' so that each CONST_DECL
can get
referenced from anywhere in the file. You'll probably need to
perform a
song and dance similar to build_objc_string_decl()'s. :-)
Here is the new patch which fixes so the CONST_DECL go on file scope
instead of just in the current scope which was wrong.
I had to change pushdecl_top_level to accept the CONST_DECL and
not to crash because the name of the CONST_DECL is null.
OK? Again tested on powerpc-apple-darwin with no regressions.
Thanks,
Andrew Pinski
Here is another testcase to make sure that we are constant objc
strings are the same across scopes:
/* 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;
}
* 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.
objc/ChangeLog:
* objc-act.c (objc_build_string_object): Create a CONST_DECL
for the NeXT runtime case.
Index: c-decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-decl.c,v
retrieving revision 1.595
diff -u -p -r1.595 c-decl.c
--- c-decl.c 4 Oct 2004 00:10:07 -0000 1.595
+++ c-decl.c 4 Oct 2004 20:19:20 -0000
@@ -2127,12 +2127,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: tree.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.c,v
retrieving revision 1.437
diff -u -p -r1.437 tree.c
--- tree.c 29 Sep 2004 13:07:44 -0000 1.437
+++ tree.c 4 Oct 2004 20:19:21 -0000
@@ -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;
Index: objc/objc-act.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/objc/objc-act.c,v
retrieving revision 1.249
diff -u -p -r1.249 objc-act.c
--- objc/objc-act.c 2 Oct 2004 15:56:06 -0000 1.249
+++ objc/objc-act.c 4 Oct 2004 20:19:21 -0000
@@ -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;
}