diff options
author | nicola <nicola@138bc75d-0d04-0410-961f-82ee72b054a4> | 2010-09-27 18:04:09 +0000 |
---|---|---|
committer | nicola <nicola@138bc75d-0d04-0410-961f-82ee72b054a4> | 2010-09-27 18:04:09 +0000 |
commit | 4abfc532e3ffc6353597404a1784013cfbeaef70 (patch) | |
tree | 52eceb4b49f0f2845bf998c477ea0bead40db6a6 /gcc | |
parent | 046cb05c5a1580ca187222781e6736aacf247173 (diff) | |
download | gcc-4abfc532e3ffc6353597404a1784013cfbeaef70.tar.gz |
In gcc/:
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
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 18 | ||||
-rw-r--r-- | gcc/c-family/ChangeLog | 16 | ||||
-rw-r--r-- | gcc/c-family/c-common.h | 2 | ||||
-rw-r--r-- | gcc/c-family/stub-objc.c | 13 | ||||
-rw-r--r-- | gcc/c-typeck.c | 11 | ||||
-rw-r--r-- | gcc/cp/ChangeLog | 18 | ||||
-rw-r--r-- | gcc/cp/call.c | 5 | ||||
-rw-r--r-- | gcc/cp/typeck.c | 4 | ||||
-rw-r--r-- | gcc/objc/ChangeLog | 14 | ||||
-rw-r--r-- | gcc/objc/objc-act.c | 51 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 16 | ||||
-rw-r--r-- | gcc/testsuite/obj-c++.dg/const-str-12.mm | 26 | ||||
-rw-r--r-- | gcc/testsuite/obj-c++.dg/warn5.mm | 25 | ||||
-rw-r--r-- | gcc/testsuite/objc.dg/const-str-12b.m | 26 |
14 files changed, 237 insertions, 8 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 712dfaab34a..7954df7805b 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -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. diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 7d3e3dddf7c..25603f90e25 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -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. diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index de72c192edf..296f69058e9 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -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); diff --git a/gcc/c-family/stub-objc.c b/gcc/c-family/stub-objc.c index 0ce1feffb41..0384b486fce 100644 --- a/gcc/c-family/stub-objc.c +++ b/gcc/c-family/stub-objc.c @@ -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)) { diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index 065e9b802c7..e20c234006b 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -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)); } diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 4b6eb74fe8d..f60080057bc 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -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 diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 89ab75723f4..c3a579929c3 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -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); diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 019c51eed85..9959e409f53 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -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 diff --git a/gcc/objc/ChangeLog b/gcc/objc/ChangeLog index 9a2e46b96ab..8e70e208bcd 100644 --- a/gcc/objc/ChangeLog +++ b/gcc/objc/ChangeLog @@ -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. diff --git a/gcc/objc/objc-act.c b/gcc/objc/objc-act.c index e4483da7adb..5d76596479c 100644 --- a/gcc/objc/objc-act.c +++ b/gcc/objc/objc-act.c @@ -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. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index dc21e6456d4..24f0c17c4bd 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -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 index 00000000000..d6bb1bead21 --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/const-str-12.mm @@ -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 index 00000000000..b46daed77fd --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/warn5.mm @@ -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 index 00000000000..d6bb1bead21 --- /dev/null +++ b/gcc/testsuite/objc.dg/const-str-12b.m @@ -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 |