summaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authornicola <nicola@138bc75d-0d04-0410-961f-82ee72b054a4>2010-09-21 18:51:34 +0000
committernicola <nicola@138bc75d-0d04-0410-961f-82ee72b054a4>2010-09-21 18:51:34 +0000
commite93ea189f714f1c8399f57d96a79fe2672807954 (patch)
tree897f0bbb69ee50c5f581e4a8d83c36076bdc3738 /gcc
parent2593b7b8135db4d43d62af403237e80b59ea9c9a (diff)
downloadgcc-e93ea189f714f1c8399f57d96a79fe2672807954.tar.gz
PR objc/25965
In gcc/objc/: * objc-act.c (objc_get_interface_ivars): New function. (objc_collecting_ivars): New variable. (continue_class): Set and reset objc_collecting_ivars for context. In gcc/: * c-decl.c (detect_field_duplicates): If compiling Objective-C, call objc_get_interface_ivars (). * c-family/c-common.h (objc_get_interface_ivars): New declaration. * c-family/stub-objc.c (objc_get_interface_ivars): New stub. In gcc/objcp/: * objcp-decl.c (objcp_finish_struct): Call objc_get_interface_ivars() and check for duplicate ivars. In gcc/testsuite/: Merge from 'apple/trunk' branch on FSF servers. 2005-10-11 Fariborz Jahanian <fjahanian@apple.com> Radar 4291785 objc.dg/naming-4.m: New objc.dg/naming-5.m: New obj-c++.dg/naming-1.mm: New obj-c++.dg/naming-2.mm: New git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@164491 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog8
-rw-r--r--gcc/c-decl.c11
-rw-r--r--gcc/c-family/c-common.h1
-rw-r--r--gcc/c-family/stub-objc.c6
-rw-r--r--gcc/objc/ChangeLog7
-rw-r--r--gcc/objc/objc-act.c19
-rw-r--r--gcc/objcp/ChangeLog6
-rw-r--r--gcc/objcp/objcp-decl.c34
-rw-r--r--gcc/testsuite/ChangeLog13
-rw-r--r--gcc/testsuite/obj-c++.dg/naming-1.mm26
-rw-r--r--gcc/testsuite/obj-c++.dg/naming-2.mm40
-rw-r--r--gcc/testsuite/objc.dg/naming-4.m27
-rw-r--r--gcc/testsuite/objc.dg/naming-5.m42
13 files changed, 240 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 07cea556aa2..eb4e36ab922 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,11 @@
+2010-09-21 Nicola Pero <nicola.pero@meta-innovation.com>
+
+ PR objc/25965
+ * c-decl.c (detect_field_duplicates): If compiling Objective-C,
+ call objc_get_interface_ivars ().
+ * c-family/c-common.h (objc_get_interface_ivars): New declaration.
+ * c-family/stub-objc.c (objc_get_interface_ivars): New stub.
+
2010-09-21 Kai Tietz <kai.tietz@onevision.com>
PR target/45694
diff --git a/gcc/c-decl.c b/gcc/c-decl.c
index 6c65b27e004..f8be06b479f 100644
--- a/gcc/c-decl.c
+++ b/gcc/c-decl.c
@@ -6718,6 +6718,17 @@ detect_field_duplicates (tree fieldlist)
tree x, y;
int timeout = 10;
+ /* If the struct is the list of instance variables of an Objective-C
+ class, then we need to add all the instance variables of
+ superclasses before checking for duplicates (since you can't have
+ an instance variable in a subclass with the same name as an
+ instance variable in a superclass). objc_get_interface_ivars()
+ leaves fieldlist unchanged if we are not in this case, so in that
+ case nothing changes compared to C.
+ */
+ if (c_dialect_objc ())
+ fieldlist = objc_get_interface_ivars (fieldlist);
+
/* First, see if there are more than "a few" fields.
This is trivially true if there are zero or one fields. */
if (!fieldlist)
diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index 378b68af217..ae31b7cf55f 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -962,6 +962,7 @@ extern tree objc_build_string_object (tree);
extern tree objc_get_protocol_qualified_type (tree, tree);
extern tree objc_get_class_reference (tree);
extern tree objc_get_class_ivars (tree);
+extern tree objc_get_interface_ivars (tree);
extern void objc_start_class_interface (tree, tree, tree);
extern void objc_start_category_interface (tree, tree, tree);
extern void objc_start_protocol (tree, tree);
diff --git a/gcc/c-family/stub-objc.c b/gcc/c-family/stub-objc.c
index b7748f79c6e..3cb45d0734a 100644
--- a/gcc/c-family/stub-objc.c
+++ b/gcc/c-family/stub-objc.c
@@ -248,6 +248,12 @@ objc_get_class_reference (tree ARG_UNUSED (name))
}
tree
+objc_get_interface_ivars (tree ARG_UNUSED (fieldlist))
+{
+ return 0;
+}
+
+tree
objc_get_protocol_qualified_type (tree ARG_UNUSED (name),
tree ARG_UNUSED (protos))
{
diff --git a/gcc/objc/ChangeLog b/gcc/objc/ChangeLog
index 132679ba132..87dcec853bf 100644
--- a/gcc/objc/ChangeLog
+++ b/gcc/objc/ChangeLog
@@ -1,3 +1,10 @@
+2010-09-21 Nicola Pero <nicola.pero@meta-innovation.com>
+
+ PR objc/25965
+ * objc-act.c (objc_get_interface_ivars): New function.
+ (objc_collecting_ivars): New variable.
+ (continue_class): Set and reset objc_collecting_ivars for context.
+
2010-09-15 Nicola Pero <nicola.pero@meta-innovation.com>
Merge from 'apple/trunk' branch on FSF servers.
diff --git a/gcc/objc/objc-act.c b/gcc/objc/objc-act.c
index d8fbe368a78..57942380934 100644
--- a/gcc/objc/objc-act.c
+++ b/gcc/objc/objc-act.c
@@ -371,6 +371,8 @@ int objc_public_flag;
/* Use to generate method labels. */
static int method_slot = 0;
+static int objc_collecting_ivars = 0;
+
#define BUFSIZE 1024
static char *errbuf; /* Buffer for error diagnostics */
@@ -3453,6 +3455,21 @@ objc_get_class_ivars (tree class_name)
return error_mark_node;
}
+/* Called when checking the variables in a struct. If we are not
+ doing the ivars list inside an @interface context, then returns
+ fieldlist unchanged. Else, returns the list of class ivars.
+*/
+tree
+objc_get_interface_ivars (tree fieldlist)
+{
+ if (!objc_collecting_ivars || !objc_interface_context
+ || TREE_CODE (objc_interface_context) != CLASS_INTERFACE_TYPE
+ || CLASS_SUPER_NAME (objc_interface_context) == NULL_TREE)
+ return fieldlist;
+
+ return get_class_ivars (objc_interface_context, true);
+}
+
/* Used by: build_private_template, continue_class,
and for @defs constructs. */
@@ -7714,7 +7731,9 @@ continue_class (tree klass)
push_lang_context (lang_name_c);
#endif /* OBJCPLUS */
+ objc_collecting_ivars = 1;
build_private_template (klass);
+ objc_collecting_ivars = 0;
#ifdef OBJCPLUS
pop_lang_context ();
diff --git a/gcc/objcp/ChangeLog b/gcc/objcp/ChangeLog
index 109d2327ed6..e7fe12bcf0b 100644
--- a/gcc/objcp/ChangeLog
+++ b/gcc/objcp/ChangeLog
@@ -1,3 +1,9 @@
+2010-09-21 Nicola Pero <nicola.pero@meta-innovation.com>
+
+ PR objc/25965
+ * objcp-decl.c (objcp_finish_struct): Call
+ objc_get_interface_ivars() and check for duplicate ivars.
+
2010-06-28 Steven Bosscher <steven@gcc.gnu.org>
* objcp-lang.c: Do not include except.h.
diff --git a/gcc/objcp/objcp-decl.c b/gcc/objcp/objcp-decl.c
index 8c688761098..af19a053823 100644
--- a/gcc/objcp/objcp-decl.c
+++ b/gcc/objcp/objcp-decl.c
@@ -25,6 +25,7 @@ along with GCC; see the file COPYING3. If not see
#include "tm.h"
#include "tree.h"
#include "cp-tree.h"
+#include "hashtab.h"
#include "objc-act.h"
#include "objcp-decl.h"
@@ -63,6 +64,39 @@ objcp_finish_struct (location_t loc ATTRIBUTE_UNUSED,
finish_member_declaration (field);
}
t = finish_struct (t, attributes);
+
+ /* If we are inside an @interface and are generating the list of
+ ivars, we need to check for duplicate ivars.
+ */
+ if (fieldlist)
+ {
+ tree original_fieldlist = fieldlist;
+ fieldlist = objc_get_interface_ivars (fieldlist);
+ if (fieldlist != original_fieldlist)
+ {
+ /* Minimal implementation of the equivalent of the C
+ front-end's detect_field_duplicates().
+ */
+ htab_t htab = htab_create (37, htab_hash_pointer, htab_eq_pointer, NULL);
+ tree x, y;
+ void **slot;
+
+ for (x = fieldlist; x ; x = DECL_CHAIN (x))
+ if ((y = DECL_NAME (x)) != 0)
+ {
+ slot = htab_find_slot (htab, y, INSERT);
+ if (*slot)
+ {
+ error ("duplicate member %q+D", x);
+ DECL_NAME (x) = NULL_TREE;
+ }
+ *slot = y;
+ }
+
+ htab_delete (htab);
+ }
+ }
+
pop_lang_context ();
return t;
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index fd14eab5918..b9ca99da59b 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,16 @@
+2010-09-21 Nicola Pero <nicola.pero@meta-innovation.com>
+
+ Merge from 'apple/trunk' branch on FSF servers.
+
+ 2005-10-11 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 4291785
+
+ objc.dg/naming-4.m: New
+ objc.dg/naming-5.m: New
+ obj-c++.dg/naming-1.mm: New
+ obj-c++.dg/naming-2.mm: New
+
2010-09-21 Jonathan Wakely <redi@gcc.gnu.org>
Jack Howarth <howarth@bromo.med.uc.edu>
diff --git a/gcc/testsuite/obj-c++.dg/naming-1.mm b/gcc/testsuite/obj-c++.dg/naming-1.mm
new file mode 100644
index 00000000000..aed2fd517af
--- /dev/null
+++ b/gcc/testsuite/obj-c++.dg/naming-1.mm
@@ -0,0 +1,26 @@
+/* Testing for detecting duplicate ivars. */
+/* { dg-do compile } */
+
+typedef struct S { int i; } NSDictionary;
+
+@interface A
+{
+ NSDictionary * _userInfo;
+}
+@end
+
+@interface B : A
+{
+ NSDictionary * _userInfo; /* { dg-error "duplicate member" } */
+}
+@end
+
+@interface C : A
+@end
+
+@interface D : C
+{
+ NSDictionary * _userInfo; /* { dg-error "duplicate member" } */
+}
+@end
+
diff --git a/gcc/testsuite/obj-c++.dg/naming-2.mm b/gcc/testsuite/obj-c++.dg/naming-2.mm
new file mode 100644
index 00000000000..4b7860e10dd
--- /dev/null
+++ b/gcc/testsuite/obj-c++.dg/naming-2.mm
@@ -0,0 +1,40 @@
+/* Testing for detecting duplicate ivars. */
+/* { dg-do compile } */
+
+typedef struct S { int i; } NSDictionary;
+
+@interface A
+{
+ NSDictionary * _userInfo;
+ int i1;
+ int i2;
+ int i3;
+ int i4;
+ int i5;
+ int i6;
+ int i7;
+}
+@end
+
+@interface B : A
+{
+ NSDictionary * _userInfo; /* { dg-error "duplicate member" } */
+ int ii1;
+ int ii2;
+ int ii3;
+ int ii4;
+ int ii5;
+ int ii6;
+ int ii7;
+}
+@end
+
+@interface C : A
+@end
+
+@interface D : C
+{
+ NSDictionary * _userInfo; /* { dg-error "duplicate member" } */
+}
+@end
+
diff --git a/gcc/testsuite/objc.dg/naming-4.m b/gcc/testsuite/objc.dg/naming-4.m
new file mode 100644
index 00000000000..9a85229f6a7
--- /dev/null
+++ b/gcc/testsuite/objc.dg/naming-4.m
@@ -0,0 +1,27 @@
+/* Testing for detecting duplicate ivars. */
+/* { dg-do compile } */
+
+typedef struct S { int i; } NSDictionary;
+
+@interface A
+{
+ NSDictionary * _userInfo;
+}
+@end
+
+@interface B : A
+{
+ NSDictionary * _userInfo; /* { dg-error "duplicate member" } */
+ NSDictionary * _userInfo; /* { dg-error "duplicate member" } */
+}
+@end
+
+@interface C : A
+@end
+
+@interface D : C
+{
+ NSDictionary * _userInfo; /* { dg-error "duplicate member" } */
+ NSDictionary * _userInfo; /* { dg-error "duplicate member" } */
+}
+@end
diff --git a/gcc/testsuite/objc.dg/naming-5.m b/gcc/testsuite/objc.dg/naming-5.m
new file mode 100644
index 00000000000..2e2786c41de
--- /dev/null
+++ b/gcc/testsuite/objc.dg/naming-5.m
@@ -0,0 +1,42 @@
+/* Testing for detecting duplicate ivars. */
+/* { dg-do compile } */
+
+typedef struct S { int i; } NSDictionary;
+
+@interface A
+{
+ NSDictionary * _userInfo;
+ int i1;
+ int i2;
+ int i3;
+ int i4;
+ int i5;
+ int i6;
+ int i7;
+}
+@end
+
+@interface B : A
+{
+ NSDictionary * _userInfo; /* { dg-error "duplicate member" } */
+ int ii1;
+ int ii2;
+ int ii3;
+ int ii4;
+ int ii5;
+ int ii6;
+ int ii7;
+ NSDictionary * _userInfo; /* { dg-error "duplicate member" } */
+}
+@end
+
+@interface C : A
+@end
+
+@interface D : C
+{
+ NSDictionary * _userInfo; /* { dg-error "duplicate member" } */
+ NSDictionary * _userInfo; /* { dg-error "duplicate member" } */
+}
+@end
+