Patchwork ObjC/ObjC++ - another small merge from apple/trunk

login
register
mail settings
Submitter Nicola Pero
Date Oct. 17, 2010, 9:53 p.m.
Message ID <1287352380.510922717@192.168.2.228>
Download mbox | patch
Permalink /patch/68096/
State New
Headers show

Comments

Nicola Pero - Oct. 17, 2010, 9:53 p.m.
This improves the error message when accessing ObjC/ObjC++ private instance variables.

Committed to trunk (preapproved by Mike)

Thanks

In gcc/:
2010-10-17  Nicola Pero  <nicola.pero@meta-innovation.com>

        Merge from 'apple/trunk' branch on FSF servers.

        2006-03-27 Fariborz Jahanian <fjahanian@apple.com>

        Radar 4133425
        * c-decl.c (undeclared_variable): Issue diagnostic on
        private 'ivar' access.

In gcc/c-family/:
2010-10-17  Nicola Pero  <nicola.pero@meta-innovation.com>

        Merge from 'apple/trunk' branch on FSF servers.

        2006-03-27 Fariborz Jahanian <fjahanian@apple.com>

        Radar 4133425
        * c-common.h (objc_diagnose_private_ivar): New decl.
        * stub-objc.c (objc_diagnose_private_ivar): New stub.

In gcc/cp/:
2010-10-17  Nicola Pero  <nicola.pero@meta-innovation.com>

        Merge from apple/trunk branch on FSF servers.

        2006-03-27 Fariborz Jahanian <fjahanian@apple.com>

        Radar 4133425
        * lex.c (unqualified_name_lookup_error): Issue diagnostic
        for private 'ivar' access.

In gcc/objc/:
2010-10-17  Nicola Pero  <nicola.pero@meta-innovation.com>

        Merge from 'apple/trunk' branch on FSF servers.

        2006-03-27 Fariborz Jahanian <fjahanian@apple.com>

        Radar 4133425
        * objc-act.c (objc_diagnose_private_ivar): New.

In gcc/testsuite/:
2010-10-17  Nicola Pero  <nicola.pero@meta-innovation.com>

        Merge from 'apple/trunk' branch on FSF servers.

        2006-03-27 Fariborz Jahanian <fjahanian@apple.com>

        Radar 4133425
        * objc.dg/private-1.m: Test modified.
        * obj-c++.dg/private-1.mm: Test modified.

Patch

Index: gcc/c-family/ChangeLog
===================================================================
--- gcc/c-family/ChangeLog	(revision 165600)
+++ gcc/c-family/ChangeLog	(working copy)
@@ -1,3 +1,13 @@ 
+2010-10-17  Nicola Pero  <nicola.pero@meta-innovation.com>
+
+	Merge from 'apple/trunk' branch on FSF servers.		
+
+	2006-03-27 Fariborz Jahanian <fjahanian@apple.com>
+
+        Radar 4133425
+	* c-common.h (objc_diagnose_private_ivar): New decl.
+	* stub-objc.c (objc_diagnose_private_ivar): New stub.	
+
 2010-10-17  Iain Sandoe  <iains@gcc.gnu.org>
 
 	* c-common.c (c_common_reswords): Add package, RID_AT_PACKAGE.
Index: gcc/c-family/c-common.h
===================================================================
--- gcc/c-family/c-common.h	(revision 165600)
+++ gcc/c-family/c-common.h	(working copy)
@@ -987,6 +987,7 @@  extern void objc_check_global_decl (tree);
 extern tree objc_common_type (tree, tree);
 extern bool objc_compare_types (tree, tree, int, tree);
 extern bool objc_have_common_type (tree, tree, int, tree);
+extern bool objc_diagnose_private_ivar (tree);
 extern void objc_volatilize_decl (tree);
 extern bool objc_type_quals_match (tree, tree);
 extern tree objc_rewrite_function_call (tree, tree);
Index: gcc/c-family/stub-objc.c
===================================================================
--- gcc/c-family/stub-objc.c	(revision 165600)
+++ gcc/c-family/stub-objc.c	(working copy)
@@ -44,6 +44,11 @@  objc_is_object_ptr (tree ARG_UNUSED (arg))
   return 0;
 }
 
+bool objc_diagnose_private_ivar (tree ARG_UNUSED (arg))
+{
+  return false;
+}
+
 tree
 objc_lookup_ivar (tree other, tree ARG_UNUSED (arg))
 {
Index: gcc/objc/objc-act.c
===================================================================
--- gcc/objc/objc-act.c	(revision 165600)
+++ gcc/objc/objc-act.c	(working copy)
@@ -10821,6 +10821,25 @@  generate_objc_image_info (void)
   finish_var_decl (decl, objc_build_constructor (TREE_TYPE (decl), v));
 }
 
+/* Routine is called to issue diagnostic when reference to a private 
+   ivar is made and no other variable with same name is found in 
+   current scope.  */
+bool
+objc_diagnose_private_ivar (tree id)
+{
+  tree ivar;
+  if (!objc_method_context)
+    return false;
+  ivar = is_ivar (objc_ivar_chain, id);
+  if (ivar && is_private (ivar))
+    {
+      error ("instance variable %qs is declared private", 
+	     IDENTIFIER_POINTER (id));
+      return true;
+    }
+  return false;
+}
+
 /* Look up ID as an instance variable.  OTHER contains the result of
    the C or C++ lookup, which we may want to use instead.  */
 /* Also handle use of property as setter/getter. */
Index: gcc/objc/ChangeLog
===================================================================
--- gcc/objc/ChangeLog	(revision 165600)
+++ gcc/objc/ChangeLog	(working copy)
@@ -1,3 +1,12 @@ 
+2010-10-17  Nicola Pero  <nicola.pero@meta-innovation.com>
+
+	Merge from 'apple/trunk' branch on FSF servers.
+	
+	2006-03-27 Fariborz Jahanian <fjahanian@apple.com>
+
+	Radar 4133425
+	* objc-act.c (objc_diagnose_private_ivar): New.
+
 2010-10-17  Iain Sandoe  <iains@gcc.gnu.org>
 
 	* objc-act.c: Rename 'objc_public_flag' to  objc_ivar_visibility and
Index: gcc/ChangeLog
===================================================================
--- gcc/ChangeLog	(revision 165600)
+++ gcc/ChangeLog	(working copy)
@@ -1,3 +1,13 @@ 
+2010-10-17  Nicola Pero  <nicola.pero@meta-innovation.com>
+
+	Merge from 'apple/trunk' branch on FSF servers.
+	
+	2006-03-27 Fariborz Jahanian <fjahanian@apple.com>
+
+        Radar 4133425
+	* c-decl.c (undeclared_variable): Issue diagnostic on
+	private 'ivar' access.
+	
 2010-10-17  Uros Bizjak  <ubizjak@gmail.com>
 
 	PR target/46051
Index: gcc/testsuite/ChangeLog
===================================================================
--- gcc/testsuite/ChangeLog	(revision 165600)
+++ gcc/testsuite/ChangeLog	(working copy)
@@ -1,3 +1,13 @@ 
+2010-10-17  Nicola Pero  <nicola.pero@meta-innovation.com>
+	
+	Merge from 'apple/trunk' branch on FSF servers.
+
+	2006-03-27 Fariborz Jahanian <fjahanian@apple.com>
+
+	Radar 4133425
+	* objc.dg/private-1.m: Test modified.
+	* obj-c++.dg/private-1.mm: Test modified.
+	
 2010-10-17  Uros Bizjak  <ubizjak@gmail.com>
 
 	PR testsuite/45987
Index: gcc/testsuite/objc.dg/private-1.m
===================================================================
--- gcc/testsuite/objc.dg/private-1.m	(revision 165600)
+++ gcc/testsuite/objc.dg/private-1.m	(working copy)
@@ -34,7 +34,7 @@ 
 - (void) test
 {
   /* Private variables simply don't exist in the subclass.  */
-  private = 12;/* { dg-error "undeclared" } */
+  private = 12;  /* { dg-error "instance variable" } */
   /* { dg-message "function it appears in" "" { target *-*-* } { 37 } } */
 
   protected = 12; /* Ok  */
Index: gcc/testsuite/obj-c++.dg/private-1.mm
===================================================================
--- gcc/testsuite/obj-c++.dg/private-1.mm	(revision 165600)
+++ gcc/testsuite/obj-c++.dg/private-1.mm	(working copy)
@@ -1,8 +1,6 @@ 
 /* Test errors for accessing @private and @protected variables.  */
 /* Based on work by: Nicola Pero <nicola@brainstorm.co.uk>.  */
-
 /* { dg-do compile } */
-
 #include <objc/objc.h>
 
 @interface MySuperClass
@@ -36,7 +34,7 @@ 
 - (void) test
 {
   /* Private variables simply don't exist in the subclass.  */
-  _private = 12; /* { dg-error "._private. was not declared in this scope" } */
+  _private = 12; /* { dg-error "instance variable \\'_private\\' is declared private" } */
 
   _protected = 12; /* Ok  */
   _public = 12;    /* Ok  */
Index: gcc/cp/ChangeLog
===================================================================
--- gcc/cp/ChangeLog	(revision 165600)
+++ gcc/cp/ChangeLog	(working copy)
@@ -1,3 +1,13 @@ 
+2010-10-17  Nicola Pero  <nicola.pero@meta-innovation.com>
+	
+	Merge from apple/trunk branch on FSF servers.
+	
+	2006-03-27 Fariborz Jahanian <fjahanian@apple.com>
+
+        Radar 4133425
+	* lex.c (unqualified_name_lookup_error): Issue diagnostic
+	for private 'ivar' access.
+	
 2010-10-17  Iain Sandoe  <iains@gcc.gnu.org>
 
 	* parser.c (cp_parser_objc_visibility_spec): Update to use visibility 
Index: gcc/cp/lex.c
===================================================================
--- gcc/cp/lex.c	(revision 165600)
+++ gcc/cp/lex.c	(working copy)
@@ -449,7 +449,8 @@  unqualified_name_lookup_error (tree name)
     }
   else
     {
-      error ("%qD was not declared in this scope", name);
+      if (!objc_diagnose_private_ivar (name))
+        error ("%qD was not declared in this scope", name);
       /* Prevent repeated error messages by creating a VAR_DECL with
 	 this NAME in the innermost block scope.  */
       if (current_function_decl)
Index: gcc/c-decl.c
===================================================================
--- gcc/c-decl.c	(revision 165600)
+++ gcc/c-decl.c	(working copy)
@@ -2961,7 +2961,8 @@  undeclared_variable (location_t loc, tree id)
     }
   else
     {
-      error_at (loc, "%qE undeclared (first use in this function)", id);
+      if (!objc_diagnose_private_ivar (id))
+        error_at (loc, "%qE undeclared (first use in this function)", id);
       if (!already)
 	{
           inform (loc, "each undeclared identifier is reported only"