In gcc/:
authornicola <nicola@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 27 Sep 2010 18:04:09 +0000 (18:04 +0000)
committernicola <nicola@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 27 Sep 2010 18:04:09 +0000 (18:04 +0000)
2010-09-27  Nicola Pero  <nicola.pero@meta-innovation.com>

        Merge from 'apple/trunk' branch on FSF servers.  Removed small
        change in build_conditional_expr that had been added when fixing
        PR objc/27377 and which did the same check in a less complete way.

        2005-12-15  Fariborz Jahanian <fjahanian@apple.com>

        Radar 4229905
        * c-typeck.c (build_conditional_expr): Call objc_have_common_type when
        looking for objective-c common pointer types.

        2005-06-22  Ziemowit Laski  <zlaski@apple.com>

        Radar 4154928
        * c-typeck.c (build_conditional_expr): For two ObjC pointer types,
        use their ObjC common type.

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

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

        2005-12-15  Fariborz Jahanian <fjahanian@apple.com>

        Radar 4229905
        * c-common.h (objc_have_common_type): New declaration.
        * stub-objc.c (objc_have_common_type): New stub.

        2005-06-22  Ziemowit Laski  <zlaski@apple.com>

        Radar 4154928
        * c-common.h (objc_common_type): New prototype.
        * stub-objc.c (objc_common_type): New stub.

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

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

        2005-12-15  Fariborz Jahanian <fjahanian@apple.com>

        Radar 4229905
        * objc-act.c (objc_have_common_types): New function.

        2005-06-22  Ziemowit Laski  <zlaski@apple.com>

        Radar 4154928
        * objc-act.c (objc_common_type): New function.

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

        Merge from apple/trunk branch on FSF servers:

        2005-12-15  Fariborz Jahanian <fjahanian@apple.com>

        Radar 4229905
        * typeck.c (composite_pointer_type): Call objc_have_common_type
        when comparing two objective-c pointer types.

        2005-06-22  Ziemowit Laski  <zlaski@apple.com>

        Radar 4154928
        * call.c (standard_conversion): Allow for a pointer conversion
        between any two ObjC pointer types.
        * typeck.c (composite_pointer_type): Determine common type
        for two ObjC pointer types.

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

        Merge from 'apple/trunk' branch on FSF servers.  Renamed
        const-str-12.m to constr-str-12b.m to avoid conflicts.

        2005-12-15  Fariborz Jahanian <fjahanian@apple.com>

        Radar 4229905
        * obj-c++.dg/warn5.mm: New

        2005-06-22  Ziemowit Laski  <zlaski@apple.com>

        Radar 4154928
        * obj-c++.dg/const-str-12.mm: New.
        * objc.dg/const-str-12.m: New.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@164655 138bc75d-0d04-0410-961f-82ee72b054a4

14 files changed:
gcc/ChangeLog
gcc/c-family/ChangeLog
gcc/c-family/c-common.h
gcc/c-family/stub-objc.c
gcc/c-typeck.c
gcc/cp/ChangeLog
gcc/cp/call.c
gcc/cp/typeck.c
gcc/objc/ChangeLog
gcc/objc/objc-act.c
gcc/testsuite/ChangeLog
gcc/testsuite/obj-c++.dg/const-str-12.mm [new file with mode: 0644]
gcc/testsuite/obj-c++.dg/warn5.mm [new file with mode: 0644]
gcc/testsuite/objc.dg/const-str-12b.m [new file with mode: 0644]

index 712dfaa..7954df7 100644 (file)
@@ -1,3 +1,21 @@
+2010-09-27  Nicola Pero  <nicola.pero@meta-innovation.com>
+
+       Merge from 'apple/trunk' branch on FSF servers.  Removed small
+       change in build_conditional_expr that had been added when fixing
+       PR objc/27377 and which did the same check in a less complete way.
+
+       2005-12-15  Fariborz Jahanian <fjahanian@apple.com>
+
+       Radar 4229905
+       * c-typeck.c (build_conditional_expr): Call objc_have_common_type when
+       looking for objective-c common pointer types.
+       
+       2005-06-22  Ziemowit Laski  <zlaski@apple.com>
+
+       Radar 4154928
+       * c-typeck.c (build_conditional_expr): For two ObjC pointer types,
+       use their ObjC common type.
+
 2010-09-27  Richard Guenther  <rguenther@suse.de>
 
        * dbxout.c (dbxout_symbol): Use DECL_FILE_SCOPE_P.
index 7d3e3dd..25603f9 100644 (file)
@@ -1,3 +1,19 @@
+2010-09-27  Nicola Pero  <nicola.pero@meta-innovation.com>
+
+       Merge from 'apple/trunk' branch on FSF servers. 
+
+       2005-12-15  Fariborz Jahanian <fjahanian@apple.com>
+
+       Radar 4229905   
+       * c-common.h (objc_have_common_type): New declaration.
+       * stub-objc.c (objc_have_common_type): New stub.
+
+       2005-06-22  Ziemowit Laski  <zlaski@apple.com>
+
+       Radar 4154928
+       * c-common.h (objc_common_type): New prototype.
+       * stub-objc.c (objc_common_type): New stub.     
+
 2010-09-24  Jan Hubicka  <jh@suse.cz>
 
        * c-common.c (handle_leaf_attribute): New function.
index de72c19..296f690 100644 (file)
@@ -941,7 +941,9 @@ extern tree objc_is_class_name (tree);
 extern tree objc_is_object_ptr (tree);
 extern void objc_check_decl (tree);
 extern int objc_is_reserved_word (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 void objc_volatilize_decl (tree);
 extern bool objc_type_quals_match (tree, tree);
 extern tree objc_rewrite_function_call (tree, tree);
index 0ce1fef..0384b48 100644 (file)
@@ -62,6 +62,12 @@ objc_is_reserved_word (tree ARG_UNUSED (ident))
   return 0;
 }
 
+tree
+objc_common_type (tree ARG_UNUSED (type1), tree ARG_UNUSED (type2))
+{
+  return 0;
+}
+
 bool
 objc_compare_types (tree ARG_UNUSED (ltyp), tree ARG_UNUSED (rtyp),
                    int ARG_UNUSED (argno), tree ARG_UNUSED (callee))
@@ -69,6 +75,13 @@ objc_compare_types (tree ARG_UNUSED (ltyp), tree ARG_UNUSED (rtyp),
   return false;
 }
 
+bool
+objc_have_common_type (tree ARG_UNUSED (ltyp), tree ARG_UNUSED (rtyp),
+                      int ARG_UNUSED (argno), tree ARG_UNUSED (callee))
+{
+  return false;
+}
+
 void
 objc_volatilize_decl (tree ARG_UNUSED (decl))
 {
index 065e9b8..e20c234 100644 (file)
@@ -4051,7 +4051,6 @@ build_conditional_expr (location_t colon_loc, tree ifexp, bool ifexp_bcp,
   bool int_const, op1_int_operands, op2_int_operands, int_operands;
   bool ifexp_int_operands;
   tree ret;
-  bool objc_ok;
 
   op1_int_operands = EXPR_INT_CONST_OPERANDS (orig_op1);
   if (op1_int_operands)
@@ -4088,8 +4087,6 @@ build_conditional_expr (location_t colon_loc, tree ifexp, bool ifexp_bcp,
       return error_mark_node;
     }
 
-  objc_ok = objc_compare_types (type1, type2, -3, NULL_TREE);
-
   if ((TREE_CODE (op1) == EXCESS_PRECISION_EXPR
        || TREE_CODE (op2) == EXCESS_PRECISION_EXPR)
       && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
@@ -4255,13 +4252,15 @@ build_conditional_expr (location_t colon_loc, tree ifexp, bool ifexp_bcp,
          result_type = build_pointer_type (qualify_type (TREE_TYPE (type2),
                                                          TREE_TYPE (type1)));
        }
+      /* Objective-C pointer comparisons are a bit more lenient.  */
+      else if (objc_have_common_type (type1, type2, -3, NULL_TREE))
+       result_type = objc_common_type (type1, type2);
       else
        {
          int qual = ENCODE_QUAL_ADDR_SPACE (as_common);
 
-         if (!objc_ok)
-           pedwarn (colon_loc, 0,
-                    "pointer type mismatch in conditional expression");
+         pedwarn (colon_loc, 0,
+                  "pointer type mismatch in conditional expression");
          result_type = build_pointer_type
                          (build_qualified_type (void_type_node, qual));
        }
index 4b6eb74..f600800 100644 (file)
@@ -1,3 +1,21 @@
+2010-09-27  Nicola Pero  <nicola.pero@meta-innovation.com>
+
+       Merge from apple/trunk branch on FSF servers:
+       
+       2005-12-15  Fariborz Jahanian <fjahanian@apple.com>
+
+       Radar 4229905
+       * typeck.c (composite_pointer_type): Call objc_have_common_type
+       when comparing two objective-c pointer types.
+
+       2005-06-22  Ziemowit Laski  <zlaski@apple.com>
+
+       Radar 4154928
+       * call.c (standard_conversion): Allow for a pointer conversion
+       between any two ObjC pointer types.
+       * typeck.c (composite_pointer_type): Determine common type
+       for two ObjC pointer types.
+       
 2010-09-24  Jan Hubicka  <jh@suse.cz>
 
        * decl.c (finish_function): Use decl_replaceable_p
index 89ab757..c3a5799 100644 (file)
@@ -900,6 +900,11 @@ standard_conversion (tree to, tree from, tree expr, bool c_cast_p,
       else if (expr && string_conv_p (to, expr, 0))
        /* converting from string constant to char *.  */
        conv = build_conv (ck_qual, to, conv);
+      /* Allow conversions among compatible ObjC pointer types (base
+        conversions have been already handled above).  */
+      else if (c_dialect_objc ()
+              && objc_compare_types (to, from, -4, NULL_TREE))
+       conv = build_conv (ck_ptr, to, conv);
       else if (ptr_reasonably_similar (to_pointee, from_pointee))
        {
          conv = build_conv (ck_ptr, to, conv);
index 019c51e..9959e40 100644 (file)
@@ -632,8 +632,8 @@ composite_pointer_type (tree t1, tree t2, tree arg1, tree arg2,
   if (c_dialect_objc () && TREE_CODE (t1) == POINTER_TYPE
       && TREE_CODE (t2) == POINTER_TYPE)
     {
-      if (objc_compare_types (t1, t2, -3, NULL_TREE))
-       return t1;
+      if (objc_have_common_type (t1, t2, -3, NULL_TREE))
+       return objc_common_type (t1, t2);
     }
 
   /* [expr.eq] permits the application of a pointer conversion to
index 9a2e46b..8e70e20 100644 (file)
@@ -1,3 +1,17 @@
+2010-09-27  Nicola Pero  <nicola.pero@meta-innovation.com>
+
+       Merge from 'apple/trunk' branch on FSF servers.
+
+       2005-12-15  Fariborz Jahanian <fjahanian@apple.com>
+
+       Radar 4229905
+       * objc-act.c (objc_have_common_types): New function.
+       
+       2005-06-22  Ziemowit Laski  <zlaski@apple.com>
+
+       Radar 4154928
+       * objc-act.c (objc_common_type): New function.
+       
 2010-09-27  Richard Guenther  <rguenther@suse.de>
 
        * objc-act.c (objc_get_class_reference): Use CP_TYPE_CONTEXT.
index e4483da..5d76596 100644 (file)
@@ -1100,6 +1100,35 @@ objc_compare_protocols (tree lcls, tree ltyp, tree rcls, tree rtyp, bool warn)
   return have_lproto || (rcls != NULL_TREE);
 }
 
+/* Given two types TYPE1 and TYPE2, return their least common ancestor.
+   Both TYPE1 and TYPE2 must be pointers, and already determined to be
+   compatible by objc_compare_types() below.  */
+
+tree
+objc_common_type (tree type1, tree type2)
+{
+  tree inner1 = TREE_TYPE (type1), inner2 = TREE_TYPE (type2);
+
+  while (POINTER_TYPE_P (inner1))
+    {
+      inner1 = TREE_TYPE (inner1);
+      inner2 = TREE_TYPE (inner2);
+    }
+
+  /* If one type is derived from another, return the base type.  */
+  if (DERIVED_FROM_P (inner1, inner2))
+    return type1;
+  else if (DERIVED_FROM_P (inner2, inner1))
+    return type2;
+
+  /* If both types are 'Class', return 'Class'.  */
+  if (objc_is_class_id (inner1) && objc_is_class_id (inner2))
+    return objc_class_type;
+
+  /* Otherwise, return 'id'.  */
+  return objc_object_type;
+}
+
 /* Determine if it is permissible to assign (if ARGNO is greater than -3)
    an instance of RTYP to an instance of LTYP or to compare the two
    (if ARGNO is equal to -3), per ObjC type system rules.  Before
@@ -1273,6 +1302,28 @@ objc_compare_types (tree ltyp, tree rtyp, int argno, tree callee)
   return true;
 }
 
+/* This routine is similar to objc_compare_types except that function-pointers are
+   excluded. This is because, caller assumes that common types are of (id, Object*)
+   variety and calls objc_common_type to obtain a common type. There is no commonolty
+   between two function-pointers in this regard. */
+
+bool 
+objc_have_common_type (tree ltyp, tree rtyp, int argno, tree callee)
+{
+  if (objc_compare_types (ltyp, rtyp, argno, callee))
+    {
+      /* exclude function-pointer types. */
+      do
+        {
+          ltyp = TREE_TYPE (ltyp);  /* Remove indirections.  */
+          rtyp = TREE_TYPE (rtyp);
+        }
+      while (POINTER_TYPE_P (ltyp) && POINTER_TYPE_P (rtyp));
+      return !(TREE_CODE (ltyp) == FUNCTION_TYPE && TREE_CODE (rtyp) == FUNCTION_TYPE);
+    }
+  return false;
+}
+
 /* Check if LTYP and RTYP have the same type qualifiers.  If either type
    lives in the volatilized hash table, ignore the 'volatile' bit when
    making the comparison.  */
index dc21e64..24f0c17 100644 (file)
@@ -1,3 +1,19 @@
+2010-09-27  Nicola Pero  <nicola.pero@meta-innovation.com>
+
+       Merge from 'apple/trunk' branch on FSF servers.  Renamed
+       const-str-12.m to constr-str-12b.m to avoid conflicts.
+       
+       2005-12-15  Fariborz Jahanian <fjahanian@apple.com>
+
+       Radar 4229905
+       * obj-c++.dg/warn5.mm: New
+       
+       2005-06-22  Ziemowit Laski  <zlaski@apple.com>
+
+       Radar 4154928
+       * obj-c++.dg/const-str-12.mm: New.
+       * objc.dg/const-str-12.m: New.
+
 2010-09-27  Tobias Burnus  <burnus@net-b.de>
 
        PR fortran/40569
diff --git a/gcc/testsuite/obj-c++.dg/const-str-12.mm b/gcc/testsuite/obj-c++.dg/const-str-12.mm
new file mode 100644 (file)
index 0000000..d6bb1be
--- /dev/null
@@ -0,0 +1,26 @@
+/* Test if ObjC types play nice in conditional expressions.  */
+/* Author: Ziemowit Laski  */
+
+/* { dg-options "-fconstant-string-class=Foo" } */
+/* { dg-do compile } */
+
+#include "../objc-obj-c++-shared/Object1.h"
+
+@interface Foo: Object {
+  char *cString;
+  unsigned int len;
+}
++ (id)description;
+@end
+
+@interface Bar: Object
++ (Foo *) getString: (int) which;
+@end
+
+struct objc_class _FooClassReference;
+
+@implementation Bar
++ (Foo *) getString: (int) which {
+  return which? [Foo description]: @"Hello";
+}
+@end
diff --git a/gcc/testsuite/obj-c++.dg/warn5.mm b/gcc/testsuite/obj-c++.dg/warn5.mm
new file mode 100644 (file)
index 0000000..b46daed
--- /dev/null
@@ -0,0 +1,25 @@
+/* Check to make sure that a c++ program compiled in objective-c++ mode
+   has no trace of meta-data specific diagnosis coming out of compiling it.
+   This is replicate of warn5.C.
+*/
+// { dg-do assemble  }
+// { dg-options "-Wpointer-arith" }
+
+double X(const double x) { return x; }
+double Y() { return 1.0; }
+double Z() { return 2.0; }
+
+struct A {
+  void bar() { }
+  void foo() { }
+};
+
+typedef void (A::*pmf)();
+
+static int mememe = &A::foo - &A::bar;  // { dg-warning "" } 
+pmf b = &A::foo-1;      // { dg-warning "" } 
+
+int main() {
+    double y;
+    y=X(Y-Z);   // { dg-warning "" } 
+}
diff --git a/gcc/testsuite/objc.dg/const-str-12b.m b/gcc/testsuite/objc.dg/const-str-12b.m
new file mode 100644 (file)
index 0000000..d6bb1be
--- /dev/null
@@ -0,0 +1,26 @@
+/* Test if ObjC types play nice in conditional expressions.  */
+/* Author: Ziemowit Laski  */
+
+/* { dg-options "-fconstant-string-class=Foo" } */
+/* { dg-do compile } */
+
+#include "../objc-obj-c++-shared/Object1.h"
+
+@interface Foo: Object {
+  char *cString;
+  unsigned int len;
+}
++ (id)description;
+@end
+
+@interface Bar: Object
++ (Foo *) getString: (int) which;
+@end
+
+struct objc_class _FooClassReference;
+
+@implementation Bar
++ (Foo *) getString: (int) which {
+  return which? [Foo description]: @"Hello";
+}
+@end