aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/objc.dg/const-str-8.m39
-rw-r--r--gcc/testsuite/objc.dg/const-str-9.m20
-rw-r--r--gcc/varasm.c4
5 files changed, 73 insertions, 0 deletions
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 <zlaski@apple.com>
+ * varasm.c (output_addressed_constants): For CONST_DECLs,
+ output the initializer if present.
+
+2004-11-12 Ziemowit Laski <zlaski@apple.com>
+
* config/rs6000/darwin.h: Fix confusing typo in comment.
2004-11-12 Devang Patel <dpatel@apple.com>
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 <zlaski@apple.com>
+
+ * objc.dg/const-str-8.m, objc.dg/const-str-9.m:
+ New tests.
+
2004-11-12 Mark Mitchell <mark@codesourcery.com>
* 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 <zlaski@apple.com> */
+
+/* { dg-options "-fnext-runtime -fconstant-string-class=Foo -lobjc" } */
+/* { dg-do run { target *-*-darwin* } } */
+
+
+#include <stdlib.h>
+#include <objc/Object.h>
+
+@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 <zlaski@apple.com> */
+
+/* { dg-options "-fnext-runtime" } */
+/* { dg-do compile { target *-*-darwin* } } */
+
+#include <objc/Object.h>
+
+@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;