From: Ziemowit Laski Date: Sat, 13 Nov 2004 02:08:44 +0000 (+0000) Subject: varasm.c (output_addressed_constants): For CONST_DECLs, output the initializer if... X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2256aa1cff25a0ea9c5b699795a773a93f11f565;p=platform%2Fupstream%2Fgcc.git varasm.c (output_addressed_constants): For CONST_DECLs, output the initializer if present. [gcc/ChangeLog] 2004-11-12 Ziemowit Laski * varasm.c (output_addressed_constants): For CONST_DECLs, output the initializer if present. [gcc/testsuite/ChangeLog] 2004-11-12 Ziemowit Laski * objc.dg/const-str-8.m, objc.dg/const-str-9.m: New tests. From-SVN: r90569 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d7016a9..b26460b 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,10 @@ 2004-11-12 Ziemowit Laski + * varasm.c (output_addressed_constants): For CONST_DECLs, + output the initializer if present. + +2004-11-12 Ziemowit Laski + * config/rs6000/darwin.h: Fix confusing typo in comment. 2004-11-12 Devang Patel diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a2d6a24..a8ea52e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2004-11-12 Ziemowit Laski + + * objc.dg/const-str-8.m, objc.dg/const-str-9.m: + New tests. + 2004-11-12 Mark Mitchell * lib/gcc-dg.exp (dg-forbid-option): New function. diff --git a/gcc/testsuite/objc.dg/const-str-8.m b/gcc/testsuite/objc.dg/const-str-8.m new file mode 100644 index 0000000..60abcbd --- /dev/null +++ b/gcc/testsuite/objc.dg/const-str-8.m @@ -0,0 +1,39 @@ +/* Test for assigning compile-time constant-string objects to static variables. */ +/* Contributed by Ziemowit Laski */ + +/* { dg-options "-fnext-runtime -fconstant-string-class=Foo -lobjc" } */ +/* { dg-do run { target *-*-darwin* } } */ + + +#include +#include + +@interface Foo: Object { + char *cString; + unsigned int len; +} +@end + +struct objc_class _FooClassReference; + +@implementation Foo : Object +- (char *)customString { + return cString; +} +@end + +static const Foo *appKey = @"MyApp"; +static int CFPreferencesSynchronize (const Foo *ref) { + return ref == appKey; +} + +static void PrefsSynchronize(void) +{ + if(!CFPreferencesSynchronize(appKey)) + abort(); +} + +int main () { + PrefsSynchronize(); + return 0; +} diff --git a/gcc/testsuite/objc.dg/const-str-9.m b/gcc/testsuite/objc.dg/const-str-9.m new file mode 100644 index 0000000..0333374 --- /dev/null +++ b/gcc/testsuite/objc.dg/const-str-9.m @@ -0,0 +1,20 @@ +/* Test if ObjC constant strings get placed in the correct section. */ +/* Contributed by Ziemowit Laski */ + +/* { dg-options "-fnext-runtime" } */ +/* { dg-do compile { target *-*-darwin* } } */ + +#include + +@interface NSConstantString: Object { + char *cString; + unsigned int len; +} +@end + +extern struct objc_class _NSConstantStringClassReference; + +static const NSConstantString *appKey = @"MyApp"; + +/* { dg-final { scan-assembler ".section __OBJC, __cstring_object" } } */ +/* { dg-final { scan-assembler ".long\t__NSConstantStringClassReference\n\t.long\t.*\n\t.long\t5\n\t.data" } } */ diff --git a/gcc/varasm.c b/gcc/varasm.c index a92abb4..6019b5a 100644 --- a/gcc/varasm.c +++ b/gcc/varasm.c @@ -3385,6 +3385,10 @@ output_addressed_constants (tree exp) tem = TREE_OPERAND (tem, 0)) ; + /* If we have an initialized CONST_DECL, retrieve the initializer. */ + if (TREE_CODE (tem) == CONST_DECL && DECL_INITIAL (tem)) + tem = DECL_INITIAL (tem); + if (CONSTANT_CLASS_P (tem) || TREE_CODE (tem) == CONSTRUCTOR) output_constant_def (tem, 0); break;