summaryrefslogtreecommitdiffstats
path: root/contrib/gcc/cp
diff options
context:
space:
mode:
authorpfg <pfg@FreeBSD.org>2014-01-26 19:49:54 +0000
committerpfg <pfg@FreeBSD.org>2014-01-26 19:49:54 +0000
commitfe288f1b72a13316f613e06cd07d4d777cd59b99 (patch)
tree388002273457e1ebeee9510b9908dc299e3748f1 /contrib/gcc/cp
parent5c96f061e7bff64c2387d5fd90ff095b71ce59b2 (diff)
downloadFreeBSD-src-fe288f1b72a13316f613e06cd07d4d777cd59b99.zip
FreeBSD-src-fe288f1b72a13316f613e06cd07d4d777cd59b99.tar.gz
MFC r260311, r260831:
gcc: Add support for Apple's Block extension Block objects [1] are a C-level syntactic and runtime feature. They are similar to standard C functions, but in addition to executable code they may also contain variable bindings to automatic (stack) or managed (heap) memory. A block can therefore maintain a set of state (data) that it can use to impact behavior when executed. This port is based on Apple's GCC 5646 with some bugfixes from Apple GCC 5666.3. It has some small differences with the support in clang, which remains the recommended compiler. Perhaps the most notable difference is that in GCC __block is not actually a keyword, but a macro. There may be workaround for this issue in the future. Other issues can be consulted in the clang documentation [2] For better compatiblity with Apple's GCC and llvm-gcc, some related fixes and features from Apple have been included. Support for the non-standard nested functions in GCC is now off by default. No effort was made to update the ObjC support since FreeBSD doesn't carry ObjC in the base system but some of the code crept in and was more difficult to remove than to adjust. References: [1] https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Blocks/Articles/00_Introduction.html [2] http://clang.llvm.org/compatibility.html#block-variable-initialization Obtained from: Apple GCC 4.2
Diffstat (limited to 'contrib/gcc/cp')
-rw-r--r--contrib/gcc/cp/ChangeLog.apple643
-rw-r--r--contrib/gcc/cp/call.c32
-rw-r--r--contrib/gcc/cp/class.c31
-rw-r--r--contrib/gcc/cp/cp-gimplify.c25
-rw-r--r--contrib/gcc/cp/cp-objcp-common.c32
-rw-r--r--contrib/gcc/cp/cp-objcp-common.h6
-rw-r--r--contrib/gcc/cp/cp-tree.h44
-rw-r--r--contrib/gcc/cp/decl.c585
-rw-r--r--contrib/gcc/cp/decl.h6
-rw-r--r--contrib/gcc/cp/decl2.c129
-rw-r--r--contrib/gcc/cp/error.c11
-rw-r--r--contrib/gcc/cp/init.c14
-rw-r--r--contrib/gcc/cp/mangle.c7
-rw-r--r--contrib/gcc/cp/name-lookup.c6
-rw-r--r--contrib/gcc/cp/name-lookup.h2
-rw-r--r--contrib/gcc/cp/parser.c2449
-rw-r--r--contrib/gcc/cp/pt.c5
-rw-r--r--contrib/gcc/cp/semantics.c179
-rw-r--r--contrib/gcc/cp/tree.c9
-rw-r--r--contrib/gcc/cp/typeck.c299
20 files changed, 4361 insertions, 153 deletions
diff --git a/contrib/gcc/cp/ChangeLog.apple b/contrib/gcc/cp/ChangeLog.apple
index a3eb812..a2cecaa 100644
--- a/contrib/gcc/cp/ChangeLog.apple
+++ b/contrib/gcc/cp/ChangeLog.apple
@@ -1,9 +1,652 @@
+2008-11-07 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 5847976
+ * decl.c (synth_block_byref_id_object_copy_func): Takes new 'flag' argument
+ and produces the new much simplified API.
+ (synth_block_byref_id_object_dispose_func): Ditto.
+ (new_block_byref_decl): Turn off -fobjc-gc so we don't get
+ bogus warning on field declared as __weak.
+ (init_byref_decl): Takes a new 'flag' argument and passes
+ it down to synth_block_byref_id_object_copy_func and
+ synth_block_byref_id_object_dispose_func.
+ (cp_finish_decl): Calculates the flag for the block
+ variable declaration and passes it down to init_byref_decl.
+ * parser.c (build_block_struct_initlist): Removes call to
+ copy_in_object (not needed).
+ (synth_copy_helper_block_func): Produce the new, simplified
+ API.
+ (synth_destroy_helper_block_func): Ditto.
+ (build_block_byref_decl): Copy over COPYABLE_WEAK_BLOCK flag.
+
+2008-10-31 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 6175959
+ * parser.c (synth_copy_helper_block_func): Use the new API
+ _Block_object_assign for ObjC object copying.
+ (block_object_dispose): New
+ (synth_destroy_helper_block_func): Call block_object_dispose
+ to use new _Block_object_dispose API for ObjC object release.
+
+2008-10-27 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 6231433
+ * typeck.c (objc_compare_types, objc_have_common_type):
+ Take an extra argument for better diagnostics.
+ * call.c: Ditto
+
+2010-03-16 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 7760213
+ * semantics.c (get_final_block_variable): Diagnose
+ access of __block array.
+
+2010-03-12 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 7735196
+ * cp/parser.c (build_block_struct_initlist):
+ Set BLOCK_USE_STRET flag in block descriptor for
+ blocks which return their aggregate value in memory.
+
+2010-03-05 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 7721728
+ * semantics.c (get_final_block_variable): Diagnose
+ importation of copied-in variables.
+
+2009-02-11 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 6573923
+ * decl.c (synth_block_byref_id_object_copy_func,
+ synth_block_byref_id_object_dispose_func): Set BLOCK_BYREF_CALLER
+ flag in call to copy/dispose helper functions.
+
+2009-02-11 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 6545782
+ * semantics.c (get_final_block_variable): New
+ (finish_id_expression): Call get_final_block_variable.
+
+2008-10-27 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 6302949
+ * parser.c (objc_cp_parser_at_property): Warn on missing
+ ',' separator for property attribute list.
+
+2008-10-24 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 6305545
+ * semantics.c (expand_or_defer_fn): Lower nested function
+ of the structors.
+
+2008-10-24 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 5847213 (minor tweak)
+ * parser.c (build_block_descriptor_type):
+ Make descriptor_ptr_type and descriptor_ptr_type_with_copydispose
+ visible to pch.
+
+2008-10-17 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 6289031
+ * decl.c: Removed all code related to
+ radar 6083129 (byref escapes).
+
+2008-10-15 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 6271728
+ * parser.c (cp_parser_objc_method_definition_list): Method
+ definition always start with '{', or it is error.
+
+2008-10-14 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 6275956
+ * semantics.c (finish_this_expr): Reference to "this" in a block
+ must be looked up.
+
+2008-10-10 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 5847213 - New Block ABI
+
+ * typeck.c (build_block_call): New code gen for block call.
+ * parser.c (build_descriptor_block_decl) New
+ (build_block_struct_type): New block literal type.
+ (build_block_struct_initlist): New block literal initializers.
+ (build_block_literal_tmp): New block literal variable initialization.
+ (synth_copy_helper_block_func): Fixed a minor bug (unrelated to this radar).
+ (build_block_internal_types): Removed.
+ (build_block_descriptor_type): New routine to build build descriptor type.
+ (make_block_pointer_declarator): Unnecessary code is removed.
+
+2008-10-02 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 6246527
+ * parser.c (cp_parser_block_literal_expr): Call to do the delta
+ on printf attribute.
+
+2008-09-30 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 6230297
+ * c-parser.c (build_block_struct_initlist): 'trivial'
+ block temporary can be static as well.
+ (build_block_literal_tmp): Accomodate 'trivial' block
+ literal temporary variable as static.
+
+2008-09-30 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 6230297
+ * parser.c (build_block_struct_initlist): 'trivial'
+ block temporary can be static as well.
+ (build_block_literal_tmp): Accomodate 'trivial' block
+ literal temporary variable as static.
+
+2008-09-30 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 6225809
+ * parser.c (build_block_byref_decl): Add __block vaiables
+ to intervening blocks.
+
+2008-09-29 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 6154598
+ tree.c (maybe_dummy_object): Build expression for
+ copied in "this" in the block.
+
+2008-09-26 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 6243400
+ * parser.c (build_block_struct_type): Mostly rewritten
+ to use C++'s API for building block's main struct so structors
+ for those data members requiring them are synthesized and
+ used.
+
+2008-09-25 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 6244520
+ * decl.c (new_block_byref_decl): New field added to
+ struct __Block_byref_x.
+ (init_byref_decl): Above field initialized to NULL.
+
+2008-09-25 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 6237713
+ * parser.c (cp_parser_block_literal_expr): Parse
+ and set attribute on block literals.
+
+2008-09-16 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 6214617
+ * parser.c (cp_block_requires_copying): New
+ (build_block_struct_type): Set BlockImportsCxxObjects flag.
+ (build_block_struct_initlist): Set BLOCK_HAS_CXX_OBJ if need be.
+ (synth_copy_helper_block_func): Call copy ctor if copied in object has one.
+ (synth_destroy_helper_block_func): Call dtor on cxx object.
+
+2008-09-12 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 6212722 (tweak)
+ * parser.c (build_block_ref_decl): Use decay_conversion.
+
+2008-09-09 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 6169580
+ * decl.c (synth_block_byref_id_object_copy_func): Pass new flag
+ to finish_function.
+ (synth_block_byref_id_object_): Ditto.
+ (finish_function): Don't pop the nested class when synthesizing
+ block helpers.
+ * semantics.c (finish_id_expression): Added logic to attach
+ copied-in "this" to stand-alone field reference in a block.
+ * parser.c (synth_copy_helper_block_func, synth_destroy_helper_block_func):
+ Pass new flag to finish_function.
+ (cp_parser_block_literal_expr): When block is in non-static member
+ function, need to import "this" as a read-only copied in variable.
+
+2008-09-05 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 6169527
+ * parser.c (build_block_struct_type): Set CLASSTYPE_AS_BASE.
+ (build_block_internal_types): Ditto.
+ (build_block_struct_initlist): Rewritten.
+ (build_block_literal_tmp): Rewritten.
+ (build_block_ref_decl): Just add copied-in variable to
+ the scope.
+ (declare_block_prologue_local_vars): Rewritten.
+ (declare_block_prologue_local_byref_vars): New
+ (block_build_prologue): Call declare_block_prologue_local_byref_vars
+ for byref variables.
+
+2008-09-03 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 6185344
+ * typeck.c (check_return_expr): Added extra check
+ for return type checking.
+ * parser.c (cp_parser_direct_declarator): Added
+ extra check for type used as block return type.
+ (cp_parser_block_literal_expr): Parse and handle
+ user provided block return type syntax.
+
+2008-08-28 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 6160536
+ * parser.c (cp_parser_block_literal_expr): Call build_block_helper_name
+ to get pretty name for block helper function.
+
+2008-08-28 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 6180456
+ * decl.c (synth_block_byref_id_object_copy_func): Use different
+ API when copying __block object in c language.
+ (synth_block_byref_id_object_dispose_func): Use different
+ API when releasing a __block object in c.
+ * parser.c (synth_copy_helper_block_func): Refactored to
+ call build_block_byref_assign_copy_decl().
+
+2008-08-27 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 6087117
+ * typeck.c (convert_arguments): Takes an extra argument
+ for distiguinsing block call to function calls.
+ (build_function_call): Tell convert_arguments if we
+ are calling a block.
+
+2008-08-24 Caroline Tice <ctice@apple.com.
+
+ Radar 6144664
+ * parser.c (build_block_byref_decl): Assign the
+ source location for each byref decl to the source
+ location of the helper function decl.
+ (build_block_ref_decl): Ditto for ref decls.
+
+2008-07-21 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 6029624
+ * call.c (objcp_reference_related_p): New
+ * cp-tree.h (objcp_reference_related_p): New decl.
+
+2008-06-05 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 5982990
+ * parser.c (cp_parser_compound_statement): Take a new
+ argument which is used to call objc_mark_locals_volatile.
+ (cp_parser_primary_expression, cp_parser_statement,
+ etc.): add extra argument in calling cp_parser_compound_statement.
+ (cp_parser_objc_synchronized_statement): Passes
+ flag_objc_sjlj_exceptions as last argument in calling
+ cp_parser_compound_statement.
+
+2008-03-20 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 5802025
+ * typeck.c (finish_class_member_access_expr): Generate getter call
+ from an OBJC_PROPERTY_REFERENCE_EXPR.
+
+2008-03-19 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 5733674
+ * decl.c (expand_static_init): Generate write barrier for
+ static initialization in objective-c++ mode.
+
+2008-02-20 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 5732232 - code gen part 2.
+ * cp-lang.c (c_finish_return): Defined these
+ templates to get a clean compile.
+
+2007-08-22 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 4947311
+ * parser.c (cp_parser_objc_protocol_declaration): Takes attribute list
+ as extra argument and passes it down to
+ objc_declare_protocols/objc_start_protocol.
+ (cp_parser_objc_class_interface): Now receives attribute list as input.
+ (cp_parser_objc_declaration): Parses attribute list and passes it down
+ to cp_parser_objc_class_interface/cp_parser_objc_protocol_declaration.
+
+2007-07-13 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 5277239
+ * parser.c (cp_parser_objc_reference_expression): New routine to
+ build a property reference expression.
+ (cp_objc_property_reference_prefix): New routine to recognize a
+ property dot syntax.
+ (cp_parser_primary_expression): Build a property reference expression
+ when a property dot-syntax is recognized.
+ (cp_parser_type_name): Exclude property dot-syntax from being recognized
+ as a type name.
+ (cp_parser_class_name): Exclude property dot-syntax from being recognized
+ as a class name.
+
+2007-07-10 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 5285911
+ * typeck.c (finish_class_member_access_expr): Call
+ objc_build_property_reference_expr instead of objc_build_getter_call.
+
+2007-06-29 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 5276085
+ * typeck.c (build_modify_expr): Call objc_weak_reference_expr
+ instead of objc_remove_weak_read.
+ * parser.c (cp_parser_cast_expression): Call
+ objc_build_weak_reference_tree instead of objc_generate_weak_read.
+ (cp_parser_cast_expression): Ditto.
+
+2007-05-18 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 5202926
+ * mangle.c (write_mangled_name): Removed suppression in last patch.
+
+2007-04-20 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 5130983
+ * c-common.h (enum lvalue_use): New enumerator lv_foreach
+ added.
+ * c-common.c (lvalue_error): Diagnose on lv_foreach.
+
+2007-04-20 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 5130983
+ * parser.c (cp_parser_parse_foreach_stmt): Parse selector expression
+ as an expression.
+ (objc_foreach_stmt): Issue diagnostic on non-lavlue selector
+ expression.
+
+2007-03-29 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 4947014 - objc atomic property
+ * lex.c (RID_NONATOMIC): Add
+ * parser.c (objc_cp_parser_at_property): Recognize 'nonatomic' as
+ new property attribute.
+
+2007-03-29 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 4564694
+ * lex.c (RID_AT_PACKAGE): Add
+ * parser.c (cp_lexer_get_preprocessor_token): Parse @package.
+
+2006-12-14 Fariborz Jahanian <fjahania@apple.com>
+
+ Radar 4854605
+ * parser.c (objc_foreach_stmt): Set iterator
+ to nil.
+
+2006-09-01 Fariborz Jahanian <fjahania@apple.com>
+
+ Radar 4712269
+ * typeck.c (build_unary_op): Call objc_build_incr_decr_setter_call
+ for potential ince/decr pre/post expressions involving properties.
+
+2006-07-21 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 4631818
+ * parser.c (cp_parser_parse_foreach_stmt): New.
+ (cp_parser_iteration_statement): Remove old code.
+ Replace it with call to cp_parser_parse_foreach_stmt.
+ (cp_parser_simple_declaration): Remove old code.
+ (cp_parser_init_declarator): Remove old code.
+
+2006-08-31 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 4697411
+ * typeck.c (build_class_member_access_expr): Call
+ objc_volatilize_component_ref.
+
+2006-07-18 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 4592503
+ * class.c (layout_class_type): Check on illegal use of __weak
+ on struct fields.
+ * decl.c (start_decl): Check on illegal use of __weak on
+ variable declarations.
+
+2006-07-14 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 4621020
+ * lex.c (reswords): Added entry for 'weak' attribute keyword.
+ * parser.c (objc_cp_parser_at_property): Recorgnize 'weak'attribute.
+
+2006-06-26 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 4591909
+ * lex.c (reswords): New entry for 'dynamic' attribute.
+ * parser.c (objc_cp_parser_at_property): Change to parse new
+ attribute syntax.
+
+2006-05-18 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 4548636 (objc attributes on class)
+ * parser.c (objc_attr_follwed_by_at_keyword): New routine to disambiguate
+ attribute before a type and attribute before an @interface declaration..
+ (cp_parser_declaration): Handle case of attribute list which can be
+ followed by an @interface.
+ (cp_parser_objc_class_interface): Parse possible attribute list before
+ parsing @interface.
+ (cp_parser_objc_declaration): Recognize 'attribute' as a valid token which
+ can start an @interface declaration.
+
+2006-05-16 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 4547045
+ * parser.c (objc_foreach_stmt): Fix a thinko.
+
+2006-04-12 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 4507230
+ * parser.c (objc_foreach_stmt): Check for valid objc
+ objects in foreach header.
+
+2006-04-06 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 4436866
+ (Missing copies attribute)
+ * lex.c (reswords): New keyword 'copies' added.
+ * parser.c (objc_cp_parser_at_property): Parse 'copies'
+ attribute.
+
2006-02-15 Fariborz Jahanian <fjahanian@apple.com>
Radar 4445586
* semantics.c (begin_do_stmt): DO_STMT nodes take an
extra argument to build.
+2005-11-08 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 4330422
+
+ * typeck.c (comp_ptr_ttypes_real): Remove the hack. un-volatize the
+ artificially 'volatized' type before doing pointer comparison.
+
+2005-08-15 Ziemowit Laski <zlaski@apple.com>
+
+ Radar 4093475
+ * parser.c (cp_parser_objc_interstitial_code): Catch stray
+ '{' and '}' tokens and issue appropriate errors.
+ (cp_parser_objc_method_prototype_list,
+ cp_parser_objc_method_definition_list): Bail out if end-of-file
+ is seen; issue error if trailing '@end' is not seen.
+
+2008-08-06 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 6040305 - work in progress.
+ * parser.c (clean_and_exit): Clean up if inside
+ a function.
+ (cp_parser_block_literal_expr): Set DECL_NO_STATIC_CHAIN
+ if inside a function.
+
+2008-08-05 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 6040305 - work in progress.
+ * decl.c (init_byref_decl): Generate c-style helper
+ functions for compose/dispose helpers.
+
+2008-08-04 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 6040305 - work in progress.
+ * decl.c (synth_block_byref_id_object_copy_func,
+ synth_block_byref_id_object_dispose_func,
+ block_start_struct, block_finish_struct,
+ new_block_byref_decl, init_byref_decl): New routines.
+ (cp_finish_decl): Build the APIed version of
+ a __byref local vriable.
+ * semantics.c (finish_id_expression): Add a __byref
+ variable to the list of such variables for current
+ block.
+ * parser.c (build_component_ref): Fix to make it work.
+ (cp_parser_block_literal_expr): Push/pop language-c,
+ set context of the helper function.
+ (declare_block_prologue_local_vars): Mend tree for
+ the built-in local variables in the helper prologue.
+
+2008-07-30 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 6040305
+ * call.c (standard_conversion): Allow conversion of 'id'
+ type to a block pointer.
+
+2008-07-30 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 6040305
+ * typeck.c (build_block_call): New
+ (build_function_call): Call build_block_call
+ for block calls.
+ * call.c (standard_conversion): Remove "void *" to
+ block pointer conversion.
+
+2008-07-29 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 6040305
+ * call.c (standard_conversion): Allow assignment of
+ "void *" to block pointer object.
+
+2008-07-28 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 6040305
+ * typeck.c (comptypes): block-pointer types'
+ return type get special treatment.
+
+2008-07-16 Eugene Marinelli <marinelli@apple.com>
+
+ Radar 5559195
+ * decl.c (cxx_maybe_build_cleanup): When considering whether to
+ build a cleanup for a class type, use
+ CLASSTYPE_HAS_NONTRIVIAL_DESTRUCTOR_BODY and
+ CLASSTYPE_DESTRUCTOR_NONTRIVIAL_BECAUSE_OF_BASE instead of
+ TYPE_HAS_NONTRIVIAL_DESTRUCTOR to determine whether it must be
+ output.
+
+2008-07-15 Eugene Marinelli <marinelli@apple.com>
+
+ Radar 5559195
+ * cp-tree.h (struct lang_type_class): Add destructor_triviality_final
+ flag to mark when has_nontrivial_destructor_body and
+ destructor_nontrivial_because_of_base are final. Add accessor for
+ this flag.
+ * parser.c (cp_parser_statement_seq_opt): Use
+ CLASSTYPE_DESTRUCTOR_TRIVIALITY_FINAL to determine if
+ destructor should be checked for being empty, and set it if
+ CLASSTYPE_HAS_NONTRIVIAL_DESTRUCTOR_BODY is changed.
+
+2008-07-10 Eugene Marinelli <marinelli@apple.com>
+
+ Radar 5559195
+ * init.c (push_base_cleanups): Check flags indicating whether
+ destructor of base class has a nontrivial body, has a base destructor
+ that must be called, or is private to determine whether it should be
+ called by the derived class. Set
+ CLASSTYPE_DESTRUCTOR_NONTRIVIAL_BECAUSE_OF_BASE to 1 if it has
+ members that must be deleted.
+ * class.c (check_bases, finish_struct_bits,
+ add_implicitly_declared_members): Set
+ CLASSTYPE_DESTRUCTOR_NONTRIVIAL_BECAUSE_OF_BASE and
+ CLASSTYPE_HAS_NONTRIVIAL_DESTRUCTOR_BODY based on base classes.
+ (check_methods): Set CLASSTYPE_HAS_NONTRIVIAL_DESTRUCTOR_BODY to 1
+ whenever a user-declared destructor is seen as a conservative
+ assumption.
+ * cp-tree.h (struct lang_type_class): Add
+ has_nontrivial_destructor_body and
+ destructor_nontrivial_because_of_base flags. Decrement remaining
+ dummy bits. Add accessors for these flags.
+ * parser.c (cp_parser_statement_seq_opt): Unmark
+ CLASSTYPE_HAS_NONTRIVIAL_DESTRUCTOR_BODY and then set it again only if
+ a statement is parsed.
+
+2007-05-07 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 4157812
+ * parser.c (cp_parser_objc_method_keyword_params): Recognize optional
+ method argument attribute.
+
+2007-03-21 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 2848255
+ * except.c (do_begin_catch): Take a new argument to decide
+ to call objc_begin_catch for objc exceptions.
+ (objcp_build_eh_type_type): New.
+ (do_end_catch): Call objc_end_catch for objc type
+ exceptions.
+ (expand_start_catch_block): Add new argument to do_begin_catch call.
+ (build_throw): Call objc_throw_exception for throwing objc type objects.
+ * cp-tree.h (objc2_valid_objc_catch_type, objcp_build_eh_type_type):
+ New extern decl.
+ * parser.c (cp_parser_objc_try_catch_finally_stateme): Add syntax for
+ @catch(...).
+
+2006-04-26 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 3803157 (method attributes)
+ * parser.c (cp_parser_objc_maybe_attributes): New.
+ (cp_parser_objc_method_keyword_params): Parse attributes at end
+ of method declaration.
+ (cp_parser_objc_method_tail_params_opt): Parse attributes after
+ '...'.
+ (cp_parser_objc_method_signature): Retreive method attribute for
+ the caller.
+ (cp_parser_objc_method_prototype_list): Pass new arg. to
+ cp_parser_objc_method_signature and pass attributes to
+ objc_add_method_declaration.
+ (cp_parser_objc_method_definition_list): Pass new arg. to
+ cp_parser_objc_method_signature and pass attributes to
+ objc_start_method_definition.
+
+2006-03-27 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 4133425
+ * lex.c (unqualified_name_lookup_error): Issue diagnostic
+ for private 'ivar' access.
+
+2006-02-02 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 4426814
+ * typeck.c (build_modify_expr): Undo call to objc_read_weak
+ on LHS of the assignment.
+ * parser.c (cp_parser_cast_expression): Central place to add
+ objc_read_weak call on expressions of __weak objects.
+
+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-10-17 Fariborz Jahanian <fjahanian@apple.com>
+
+ Radar 4290840
+
+ * parser.c (cp_parser_objc_method_keyword_params): Check for valid
+ method parameters and issue error.
+ (cp_parser_objc_method_definition_list): Check for invalid tokens
+ which cannot start a function definition.
+
+2005-08-02 Ziemowit Laski <zlaski@apple.com>
+
+ Radar 4185810
+ * parser.c (cp_parser_compound_statement): Continue
+ parsing even if the initial '{' is missing; an error
+ message is already being produced.
+ (cp_parser_statement_seq_opt): In addition to '}' and
+ end-of-file, a statement sequence may also be terminated
+ by a stray 'else' or '@end'.
+
# APPLE LOCAL begin for-fsf-4_4 3274130 5295549
2007-08-03 Geoffrey Keating <geoffk@apple.com>
diff --git a/contrib/gcc/cp/call.c b/contrib/gcc/cp/call.c
index 24b5d1f..1de6a47 100644
--- a/contrib/gcc/cp/call.c
+++ b/contrib/gcc/cp/call.c
@@ -281,7 +281,8 @@ build_call (tree function, tree parms)
function = build_addr_func (function);
- gcc_assert (TYPE_PTR_P (TREE_TYPE (function)));
+ /* APPLE LOCAL blocks 6040305 */
+ gcc_assert (TYPE_PTR_P (TREE_TYPE (function)) || TREE_CODE (TREE_TYPE (function)) == BLOCK_POINTER_TYPE);
fntype = TREE_TYPE (TREE_TYPE (function));
gcc_assert (TREE_CODE (fntype) == FUNCTION_TYPE
|| TREE_CODE (fntype) == METHOD_TYPE);
@@ -657,7 +658,8 @@ standard_conversion (tree to, tree from, tree expr, bool c_cast_p,
if (same_type_p (from, to))
return conv;
- if ((tcode == POINTER_TYPE || TYPE_PTR_TO_MEMBER_P (to))
+ /* APPLE LOCAL blocks 6040305 (ck) */
+ if ((tcode == POINTER_TYPE || tcode == BLOCK_POINTER_TYPE || TYPE_PTR_TO_MEMBER_P (to))
&& expr && null_ptr_cst_p (expr))
conv = build_conv (ck_std, to, conv);
else if ((tcode == INTEGER_TYPE && fcode == POINTER_TYPE)
@@ -810,6 +812,8 @@ standard_conversion (tree to, tree from, tree expr, bool c_cast_p,
if (ARITHMETIC_TYPE_P (from)
|| fcode == ENUMERAL_TYPE
|| fcode == POINTER_TYPE
+ /* APPLE LOCAL blocks 6040305 (cl) */
+ || fcode == BLOCK_POINTER_TYPE
|| TYPE_PTR_TO_MEMBER_P (from))
{
conv = build_conv (ck_std, to, conv);
@@ -877,6 +881,15 @@ reference_related_p (tree t1, tree t2)
&& DERIVED_FROM_P (t1, t2)));
}
+/* APPLE LOCAL begin radar 6029624 */
+/* Used in objective-c++, same as reference_related_p */
+bool
+objcp_reference_related_p (tree t1, tree t2)
+{
+ return reference_related_p (t1, t2);
+}
+/* APPLE LOCAL end radar 6029624 */
+
/* Returns nonzero if T1 is reference-compatible with T2. */
static bool
@@ -3520,10 +3533,19 @@ build_conditional_expr (tree arg1, tree arg2, tree arg3)
cv-qualification of either the second or the third operand.
The result is of the common type. */
else if ((null_ptr_cst_p (arg2)
- && (TYPE_PTR_P (arg3_type) || TYPE_PTR_TO_MEMBER_P (arg3_type)))
+ /* APPLE LOCAL begin blocks 6040305 (co) */
+ && (TYPE_PTR_P (arg3_type) || TYPE_PTR_TO_MEMBER_P (arg3_type)
+ || TREE_CODE (arg3_type) == BLOCK_POINTER_TYPE))
+ /* APPLE LOCAL end blocks 6040305 (co) */
|| (null_ptr_cst_p (arg3)
- && (TYPE_PTR_P (arg2_type) || TYPE_PTR_TO_MEMBER_P (arg2_type)))
- || (TYPE_PTR_P (arg2_type) && TYPE_PTR_P (arg3_type))
+ /* APPLE LOCAL begin blocks 6040305 (co) */
+ && (TYPE_PTR_P (arg2_type) || TYPE_PTR_TO_MEMBER_P (arg2_type)
+ || TREE_CODE (arg2_type) == BLOCK_POINTER_TYPE))
+ || ((TYPE_PTR_P (arg2_type)
+ || TREE_CODE (arg2_type) == BLOCK_POINTER_TYPE)
+ && (TYPE_PTR_P (arg3_type)
+ || TREE_CODE (arg3_type) == BLOCK_POINTER_TYPE))
+ /* APPLE LOCAL end blocks 6040305 (co) */
|| (TYPE_PTRMEM_P (arg2_type) && TYPE_PTRMEM_P (arg3_type))
|| (TYPE_PTRMEMFUNC_P (arg2_type) && TYPE_PTRMEMFUNC_P (arg3_type)))
{
diff --git a/contrib/gcc/cp/class.c b/contrib/gcc/cp/class.c
index 1f30524..047ce17 100644
--- a/contrib/gcc/cp/class.c
+++ b/contrib/gcc/cp/class.c
@@ -1282,6 +1282,12 @@ check_bases (tree t,
TYPE_NEEDS_CONSTRUCTING (t) |= TYPE_NEEDS_CONSTRUCTING (basetype);
TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
|= TYPE_HAS_NONTRIVIAL_DESTRUCTOR (basetype);
+ /* APPLE LOCAL begin omit calls to empty destructors 5559195 */
+ if (CLASSTYPE_HAS_NONTRIVIAL_DESTRUCTOR_BODY (basetype)
+ || CLASSTYPE_DESTRUCTOR_NONTRIVIAL_BECAUSE_OF_BASE (basetype))
+ CLASSTYPE_DESTRUCTOR_NONTRIVIAL_BECAUSE_OF_BASE (t) = 1;
+ /* APPLE LOCAL end omit calls to empty destructors 5559195 */
+
TYPE_HAS_COMPLEX_ASSIGN_REF (t)
|= TYPE_HAS_COMPLEX_ASSIGN_REF (basetype);
TYPE_HAS_COMPLEX_INIT_REF (t) |= TYPE_HAS_COMPLEX_INIT_REF (basetype);
@@ -1440,6 +1446,13 @@ finish_struct_bits (tree t)
TYPE_HAS_NONTRIVIAL_DESTRUCTOR (variants)
= TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t);
+ /* APPLE LOCAL begin omit calls to empty destructors 5559195 */
+ CLASSTYPE_HAS_NONTRIVIAL_DESTRUCTOR_BODY (variants) =
+ CLASSTYPE_HAS_NONTRIVIAL_DESTRUCTOR_BODY (t);
+ CLASSTYPE_DESTRUCTOR_NONTRIVIAL_BECAUSE_OF_BASE (variants) =
+ CLASSTYPE_DESTRUCTOR_NONTRIVIAL_BECAUSE_OF_BASE (t);
+ /* APPLE LOCAL end omit calls to empty destructors 5559195 */
+
TYPE_POLYMORPHIC_P (variants) = TYPE_POLYMORPHIC_P (t);
TYPE_BINFO (variants) = TYPE_BINFO (t);
@@ -2540,6 +2553,13 @@ add_implicitly_declared_members (tree t,
{
bool lazy_p = true;
+ /* APPLE LOCAL begin omit calls to empty destructors 5559195 */
+ /* Since this is an empty destructor, it can only be nontrivial
+ because one of its base classes has a destructor that must be
+ called. */
+ CLASSTYPE_DESTRUCTOR_NONTRIVIAL_BECAUSE_OF_BASE (t) = 1;
+ /* APPLE LOCAL end omit calls to empty destructors 5559195 */
+
if (TYPE_FOR_JAVA (t))
/* If this a Java class, any non-trivial destructor is
invalid, even if compiler-generated. Therefore, if the
@@ -3729,7 +3749,16 @@ check_methods (tree t)
}
/* All user-declared destructors are non-trivial. */
if (DECL_DESTRUCTOR_P (x))
- TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t) = 1;
+ /* APPLE LOCAL begin omit calls to empty destructors 5559195 */
+ {
+ TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t) = 1;
+
+ /* Conservatively assume that destructor body is nontrivial. Will
+ be unmarked during parsing of function body if it happens to be
+ trivial. */
+ CLASSTYPE_HAS_NONTRIVIAL_DESTRUCTOR_BODY (t) = 1;
+ }
+ /* APPLE LOCAL end omit calls to empty destructors 5559195 */
}
}
diff --git a/contrib/gcc/cp/cp-gimplify.c b/contrib/gcc/cp/cp-gimplify.c
index 08d4ca0..879356a 100644
--- a/contrib/gcc/cp/cp-gimplify.c
+++ b/contrib/gcc/cp/cp-gimplify.c
@@ -200,8 +200,20 @@ gimplify_cp_loop (tree cond, tree body, tree incr, tree attrs,
stmt_list = NULL_TREE;
entry = NULL_TREE;
- break_block = begin_bc_block (bc_break);
- cont_block = begin_bc_block (bc_continue);
+ /* APPLE LOCAL begin C* language */
+ /* Order of label addition to stack is important for objc's foreach-stmt. */
+ /* APPLE LOCAL radar 4667060 */
+ if (inner_foreach == integer_zero_node)
+ {
+ cont_block = begin_bc_block (bc_continue);
+ break_block = begin_bc_block (bc_break);
+ }
+ else
+ {
+ break_block = begin_bc_block (bc_break);
+ cont_block = begin_bc_block (bc_continue);
+ }
+ /* APPLE LOCAL end C* language */
/* If condition is zero don't generate a loop construct. */
if (cond && integer_zerop (cond))
@@ -252,10 +264,19 @@ gimplify_cp_loop (tree cond, tree body, tree incr, tree attrs,
}
}
+ /* APPLE LOCAL begin radar 4547045 */
+ /* Pop foreach's inner loop break label so outer loop's
+ break label becomes target of inner loop body's break statements.
+ */
+ t = NULL_TREE;
gimplify_stmt (&body);
gimplify_stmt (&incr);
body = finish_bc_block (bc_continue, cont_block, body);
+ /* APPLE LOCAL begin radar 4547045 */
+ /* Push back inner loop's own 'break' label so rest
+ of code works seemlessly. */
+ /* APPLE LOCAL radar 4667060 */
append_to_statement_list (top, &stmt_list);
append_to_statement_list (body, &stmt_list);
diff --git a/contrib/gcc/cp/cp-objcp-common.c b/contrib/gcc/cp/cp-objcp-common.c
index f40be96..d42a735 100644
--- a/contrib/gcc/cp/cp-objcp-common.c
+++ b/contrib/gcc/cp/cp-objcp-common.c
@@ -259,5 +259,37 @@ init_shadowed_var_for_decl (void)
tree_map_eq, 0);
}
+/* APPLE LOCAL begin radar 5741070 */
+/* Given an IDENTIFIER tree for a class interface, find (if possible) and
+ return the record type for the class interface. */
+
+tree
+c_return_interface_record_type (tree typename)
+{
+ enum tree_code_class class;
+ enum tree_code code;
+ tree retval = NULL;
+
+ if (typename == NULL)
+ return retval;
+
+ code = TREE_CODE (typename);
+ class = TREE_CODE_CLASS (code);
+
+ if (code != IDENTIFIER_NODE
+ || class != tcc_exceptional)
+ return retval;
+
+ if (TREE_TYPE (typename)
+ && TREE_CODE (TREE_TYPE (typename)) == RECORD_TYPE)
+ retval = TREE_TYPE (typename);
+
+ if (retval
+ && TREE_CODE (retval) != RECORD_TYPE)
+ retval = NULL;
+
+ return retval;
+}
+/* APPLE LOCAL end radar 5741070 */
#include "gt-cp-cp-objcp-common.h"
diff --git a/contrib/gcc/cp/cp-objcp-common.h b/contrib/gcc/cp/cp-objcp-common.h
index f420d93..5800d34 100644
--- a/contrib/gcc/cp/cp-objcp-common.h
+++ b/contrib/gcc/cp/cp-objcp-common.h
@@ -166,4 +166,10 @@ extern tree objcp_tsubst_copy_and_build (tree, tree, tsubst_flags_t,
#undef LANG_HOOKS_OMP_PRIVATIZE_BY_REFERENCE
#define LANG_HOOKS_OMP_PRIVATIZE_BY_REFERENCE cxx_omp_privatize_by_reference
+/* APPLE LOCAL begin radar 6353006 */
+#undef LANG_HOOKS_BUILD_GENERIC_BLOCK_STRUCT_TYPE
+#define LANG_HOOKS_BUILD_GENERIC_BLOCK_STRUCT_TYPE \
+ c_build_generic_block_struct_type
+/* APPLE LOCAL end radar 6353006 */
+
#endif /* GCC_CP_OBJCP_COMMON */
diff --git a/contrib/gcc/cp/cp-tree.h b/contrib/gcc/cp/cp-tree.h
index 6593832..1dafeb9 100644
--- a/contrib/gcc/cp/cp-tree.h
+++ b/contrib/gcc/cp/cp-tree.h
@@ -1052,6 +1052,13 @@ struct lang_type_class GTY(())
unsigned has_complex_assign_ref : 1;
unsigned non_aggregate : 1;
+ /* APPLE LOCAL begin omit calls to empty destructors 5559195 */
+ unsigned has_nontrivial_destructor_body : 1;
+ unsigned destructor_nontrivial_because_of_base : 1;
+ unsigned destructor_triviality_final : 1;
+ /* APPLE LOCAL end omit calls to empty destructors 5559195 */
+
+
/* When adding a flag here, consider whether or not it ought to
apply to a template instance if it applies to the template. If
so, make sure to copy it in instantiate_class_template! */
@@ -1059,7 +1066,9 @@ struct lang_type_class GTY(())
/* There are some bits left to fill out a 32-bit word. Keep track
of this by updating the size of this bitfield whenever you add or
remove a flag. */
- unsigned dummy : 12;
+ /* APPLE LOCAL begin omit calls to empty destructors 5559195 */
+ unsigned dummy : 10;
+ /* APPLE LOCAL end omit calls to empty destructors 5559195 */
tree primary_base;
VEC(tree_pair_s,gc) *vcall_indices;
@@ -2439,6 +2448,8 @@ extern void decl_shadowed_for_var_insert (tree, tree);
|| TREE_CODE (TYPE) == ENUMERAL_TYPE \
|| ARITHMETIC_TYPE_P (TYPE) \
|| TYPE_PTR_P (TYPE) \
+ /* APPLE LOCAL blocks 6040305 */ \
+ || TREE_CODE (TYPE) == BLOCK_POINTER_TYPE \
|| TYPE_PTRMEMFUNC_P (TYPE))
/* [dcl.init.aggr]
@@ -2520,6 +2531,20 @@ extern void decl_shadowed_for_var_insert (tree, tree);
#define TYPE_HAS_NONTRIVIAL_DESTRUCTOR(NODE) \
(TYPE_LANG_FLAG_4 (NODE))
+/* APPLE LOCAL begin omit calls to empty destructors 5559195 */
+/* One if the body of the destructor of class type NODE has been shown to do
+ nothing, else zero. */
+#define CLASSTYPE_HAS_NONTRIVIAL_DESTRUCTOR_BODY(NODE) (LANG_TYPE_CLASS_CHECK (NODE)->has_nontrivial_destructor_body)
+
+/* One if destructor of this type must be called by its base classes because
+ one of its base classes' destructors must be called. */
+#define CLASSTYPE_DESTRUCTOR_NONTRIVIAL_BECAUSE_OF_BASE(NODE) (LANG_TYPE_CLASS_CHECK (NODE)->destructor_nontrivial_because_of_base)
+
+/* One if the values of CLASSTYPE_DESTRUCTOR_NONTRIVIAL_BECAUSE_OF_BASE
+ and CLASSTYPE_HAS_NONTRIVIAL_DESTRUCTOR_BODY are final. */
+#define CLASSTYPE_DESTRUCTOR_TRIVIALITY_FINAL(NODE) (LANG_TYPE_CLASS_CHECK (NODE)->destructor_triviality_final)
+/* APPLE LOCAL end omit calls to empty destructors 5559195 */
+
/* Nonzero for class type means that copy initialization of this type can use
a bitwise copy. */
#define TYPE_HAS_TRIVIAL_INIT_REF(NODE) \
@@ -3704,6 +3729,8 @@ typedef enum cp_declarator_kind {
cdk_pointer,
cdk_reference,
cdk_ptrmem,
+ /* APPLE LOCAL blocks 6040305 (ch) */
+ cdk_block_pointer,
cdk_error
} cp_declarator_kind;
@@ -3772,6 +3799,13 @@ struct cp_declarator {
/* For cdk_ptrmem, the class type containing the member. */
tree class_type;
} pointer;
+ /* APPLE LOCAL begin blocks 6040305 (ch) */
+ /* For cdk_block_pointer. */
+ struct {
+ /* The cv-qualifiers for the pointer. */
+ cp_cv_quals qualifiers;
+ } block_pointer;
+ /* APPLE LOCAL end blocks 6040305 (ch) */
} u;
};
@@ -3922,6 +3956,8 @@ extern tree push_throw_library_fn (tree, tree);
extern tree check_tag_decl (cp_decl_specifier_seq *);
extern tree shadow_tag (cp_decl_specifier_seq *);
extern tree groktypename (cp_decl_specifier_seq *, const cp_declarator *);
+/* APPLE LOCAL 6339747 */
+extern tree grokblockdecl (cp_decl_specifier_seq *, const cp_declarator *);
extern tree start_decl (const cp_declarator *, cp_decl_specifier_seq *, int, tree, tree, tree *);
extern void start_decl_1 (tree, bool);
extern void cp_finish_decl (tree, tree, bool, tree, int);
@@ -4600,5 +4636,11 @@ extern void cp_genericize (tree);
extern void cp_cpp_error (cpp_reader *, int,
const char *, va_list *)
ATTRIBUTE_GCC_CXXDIAG(3,0);
+/* APPLE LOCAL radar 5741070 */
+extern tree c_return_interface_record_type (tree);
+/* APPLE LOCAL begin blocks 6040305 (cg) */
+extern cp_declarator* make_block_pointer_declarator (tree, cp_cv_quals,
+ cp_declarator *);
+/* APPLE LOCAL end blocks 6040305 (cg) */
#endif /* ! GCC_CP_TREE_H */
diff --git a/contrib/gcc/cp/decl.c b/contrib/gcc/cp/decl.c
index d716ac7..9a58994 100644
--- a/contrib/gcc/cp/decl.c
+++ b/contrib/gcc/cp/decl.c
@@ -52,7 +52,8 @@ Boston, MA 02110-1301, USA. */
#include "timevar.h"
#include "tree-flow.h"
-static tree grokparms (cp_parameter_declarator *, tree *);
+/* APPLE LOCAL blocks 6040305 (ce) */
+tree grokparms (cp_parameter_declarator *, tree *);
static const char *redeclaration_error_message (tree, tree);
static int decl_jump_unsafe (tree);
@@ -3800,7 +3801,26 @@ shadow_tag (cp_decl_specifier_seq *declspecs)
return t;
}
-
+
+/* APPLE LOCAL begin blocks 6339747 */
+/* Decode a block literal type, such as "int **", returning a ...FUNCTION_DECL node. */
+
+tree
+grokblockdecl (cp_decl_specifier_seq *type_specifiers,
+ const cp_declarator *declarator)
+{
+ tree decl;
+ tree attrs = type_specifiers->attributes;
+
+ type_specifiers->attributes = NULL_TREE;
+
+ decl = grokdeclarator (declarator, type_specifiers, BLOCKDEF, 0, &attrs);
+ if (attrs)
+ cplus_decl_attributes (&decl, attrs, 0);
+ return decl;
+}
+/* APPLE LOCAL end blocks 6339747 */
+
/* Decode a "typename", such as "int **", returning a ..._TYPE node. */
tree
@@ -5002,10 +5022,15 @@ make_rtl_for_nonlocal_decl (tree decl, tree init, const char* asmspec)
if (DECL_LANG_SPECIFIC (decl) && DECL_IN_AGGR_P (decl))
{
gcc_assert (TREE_STATIC (decl));
+ /* APPLE LOCAL begin templated static data 6298605 */
/* An in-class declaration of a static data member should be
- external; it is only a declaration, and not a definition. */
- if (init == NULL_TREE)
- gcc_assert (DECL_EXTERNAL (decl) || !TREE_PUBLIC (decl));
+ external if the decl is accessible from outside this
+ translation unit (eg something not in an anonymous
+ namespace); it is only a declaration, and not a
+ definition. */
+ if (init == NULL_TREE && TREE_PUBLIC (decl))
+ gcc_assert (DECL_EXTERNAL (decl));
+ /* APPLE LOCAL end templated static data 6298605 */
}
/* We don't create any RTL for local variables. */
@@ -5160,6 +5185,367 @@ value_dependent_init_p (tree init)
return false;
}
+/* APPLE LOCAL begin blocks 6040305 (cr) */
+#define BLOCK_ALIGN_MAX 18
+static tree block_byref_id_object_copy[BLOCK_BYREF_CURRENT_MAX*(BLOCK_ALIGN_MAX+1)];
+static tree block_byref_id_object_dispose[BLOCK_BYREF_CURRENT_MAX*(BLOCK_ALIGN_MAX+1)];
+
+/**
+ This routine builds:
+
+ void __Block_byref_id_object_copy(struct Block_byref_id_object *dst,
+ struct Block_byref_id_object *src) {
+ _Block_object_assign (&_dest->object, _src->object, BLOCK_FIELD_IS_OBJECT[|BLOCK_FIELD_IS_WEAK]) // objects
+ _Block_object_assign(&_dest->object, _src->object, BLOCK_FIELD_IS_BLOCK[|BLOCK_FIELD_IS_WEAK]) // blocks
+ } */
+static void
+synth_block_byref_id_object_copy_func (int flag, int kind)
+{
+ tree stmt;
+ tree dst_arg, src_arg;
+ tree dst_obj, src_obj;
+ tree call_exp;
+
+ gcc_assert (block_byref_id_object_copy[kind]);
+ /* Set up: (void* _dest, void*_src) parameters. */
+ dst_arg = build_decl (PARM_DECL, get_identifier ("_dst"),
+ ptr_type_node);
+ TREE_USED (dst_arg) = 1;
+ DECL_ARG_TYPE (dst_arg) = ptr_type_node;
+ src_arg = build_decl (PARM_DECL, get_identifier ("_src"),
+ ptr_type_node);
+ TREE_USED (src_arg) = 1;
+ DECL_ARG_TYPE (src_arg) = ptr_type_node;
+ /* arg_info = xcalloc (1, sizeof (struct c_arg_info)); */
+ TREE_CHAIN (dst_arg) = src_arg;
+ /* arg_info->parms = dst_arg; */
+ /* arg_info->types = tree_cons (NULL_TREE, ptr_type_node,
+ tree_cons (NULL_TREE,
+ ptr_type_node,
+ NULL_TREE)); */
+ DECL_ARGUMENTS (block_byref_id_object_copy[kind]) = dst_arg;
+ /* function header synthesis. */
+ push_function_context ();
+ /* start_block_helper_function (block_byref_id_object_copy[kind], true); */
+ /* store_parm_decls_from (arg_info); */
+ start_preparsed_function (block_byref_id_object_copy[kind],
+ /*attrs*/NULL_TREE,
+ SF_PRE_PARSED);
+
+ /* Body of the function. */
+ stmt = begin_compound_stmt (BCS_FN_BODY);
+ /* Build dst->object */
+ dst_obj = build_indirect_object_id_exp (dst_arg);
+
+
+ /* src_obj is: _src->object. */
+ src_obj = build_indirect_object_id_exp (src_arg);
+ /* APPLE LOCAL begin radar 6180456 */
+ /* _Block_object_assign (&_dest->object, _src->object, BLOCK_FIELD_IS_OBJECT) or:
+ _Block_object_assign (&_dest->object, _src->object, BLOCK_FIELD_IS_BLOCK) */
+ /* APPLE LOCAL begin radar 6573923 */
+ /* Also add the new flag when calling _Block_object_dispose
+ from byref dispose helper. */
+ flag |= BLOCK_BYREF_CALLER;
+ /* APPLE LOCAL end radar 6573923 */
+ call_exp = build_block_object_assign_call_exp (build_fold_addr_expr (dst_obj), src_obj, flag);
+ add_stmt (call_exp);
+ /* APPLE LOCAL end radar 6180456 */
+
+ finish_compound_stmt (stmt);
+ /* APPLE LOCAL radar 6169580 */
+ finish_function (4);
+ pop_function_context ();
+}
+
+/**
+ This routine builds:
+
+ void __Block_byref_id_object_dispose(struct Block_byref_id_object *_src) {
+ _Block_object_dispose(_src->object, BLOCK_FIELD_IS_OBJECT[|BLOCK_FIELD_IS_WEAK]) // objects
+ _Block_object_dispose(_src->object, BLOCK_FIELD_IS_BLOCK[|BLOCK_FIELD_IS_WEAK]) // blocks
+ } */
+static void synth_block_byref_id_object_dispose_func (int flag, int kind)
+{
+ tree stmt;
+ tree src_arg, src_obj, rel_exp;
+
+ gcc_assert (block_byref_id_object_dispose[kind]);
+ /* Set up: (void *_src) parameter. */
+ src_arg = build_decl (PARM_DECL, get_identifier ("_src"),
+ ptr_type_node);
+ TREE_USED (src_arg) = 1;
+ DECL_ARG_TYPE (src_arg) = ptr_type_node;
+ /* arg_info = xcalloc (1, sizeof (struct c_arg_info));
+ arg_info->parms = src_arg;
+ arg_info->types = tree_cons (NULL_TREE, ptr_type_node,
+ NULL_TREE); */
+ DECL_ARGUMENTS (block_byref_id_object_dispose[kind]) = src_arg;
+ /* function header synthesis. */
+ push_function_context ();
+ /* start_block_helper_function (block_byref_id_object_dispose[kind], true); */
+ /* store_parm_decls_from (arg_info); */
+ start_preparsed_function (block_byref_id_object_dispose[kind],
+ /*attrs*/NULL_TREE,
+ SF_PRE_PARSED);
+
+ /* Body of the function. */
+ stmt = begin_compound_stmt (BCS_FN_BODY);
+ src_obj = build_indirect_object_id_exp (src_arg);
+
+ /* APPLE LOCAL begin radar 6180456 */
+ /* _Block_object_dispose(_src->object, BLOCK_FIELD_IS_OBJECT) or:
+ _Block_object_dispose(_src->object, BLOCK_FIELD_IS_BLOCK) */
+ /* APPLE LOCAL begin radar 6573923 */
+ /* Also add the new flag when calling _Block_object_dispose
+ from byref dispose helper. */
+ flag |= BLOCK_BYREF_CALLER;
+ /* APPLE LOCAL end radar 6573923 */
+ rel_exp = build_block_object_dispose_call_exp (src_obj, flag);
+ /* APPLE LOCAL end radar 6180456 */
+ add_stmt (rel_exp);
+
+ finish_compound_stmt (stmt);
+ /* APPLE LOCAL radar 6169580 */
+ finish_function (4);
+ pop_function_context ();
+}
+
+static tree
+block_start_struct (tree name)
+{
+ tree s;
+ /* The idea here is to mimic the actions that the C++ parser takes when
+ constructing 'extern "C" struct NAME {'. */
+ push_lang_context (lang_name_c);
+
+ s = xref_tag (record_type, name, ts_global, 0);
+ CLASSTYPE_DECLARED_CLASS (s) = 0; /* this is a 'struct', not a 'class'. */
+ xref_basetypes (s, NULL_TREE); /* no base classes here! */
+
+ return begin_class_definition (s, NULL_TREE);
+}
+
+static tree
+block_finish_struct (tree t, tree fieldlist)
+{
+ tree field, next_field;
+
+ for (field = fieldlist; field; field = next_field)
+ {
+ next_field = TREE_CHAIN (field); /* insert one field at a time; */
+ TREE_CHAIN (field) = NULL_TREE; /* otherwise, grokfield croaks. */
+ finish_member_declaration (field);
+ }
+ t = finish_struct (t, NULL);
+ pop_lang_context ();
+
+ return t;
+}
+
+/* new_block_byref_decl - This routine changes a 'typex x' declared variable into:
+
+ struct __Block_byref_x {
+ // APPLE LOCAL radar 6244520
+ void *__isa; // NULL for everything except __weak pointers
+ struct Block_byref_x *__forwarding;
+ int32_t __flags;
+ int32_t __size;
+ void *__ByrefKeepFuncPtr; // Only if variable is __block ObjC object
+ void *__ByrefDestroyFuncPtr; // Only if variable is __block ObjC object
+ typex x;
+ } x;
+*/
+
+static tree
+new_block_byref_decl (tree decl)
+{
+ static int unique_count;
+ /* APPLE LOCAL radar 5847976 */
+ int save_flag_objc_gc;
+ tree Block_byref_type;
+ tree fields = NULL_TREE, field;
+ const char *prefix = "__Block_byref_";
+ char *string = (char*)alloca (strlen (IDENTIFIER_POINTER (DECL_NAME (decl))) +
+ strlen (prefix) + 8 /* to hold the count */);
+
+ sprintf (string, "%s%d_%s", prefix, ++unique_count,
+ IDENTIFIER_POINTER (DECL_NAME (decl)));
+
+ push_to_top_level ();
+
+ /* Block_byref_type = start_struct (RECORD_TYPE, get_identifier (string)); */
+ Block_byref_type = block_start_struct (get_identifier (string));
+
+ /* APPLE LOCAL begin radar 6244520 */
+ /* void *__isa; */
+ field = build_decl (FIELD_DECL, get_identifier ("__isa"), ptr_type_node);
+ fields = field;
+ /* APPLE LOCAL end radar 6244520 */
+
+ /* struct Block_byref_x *__forwarding; */
+ field = build_decl (FIELD_DECL, get_identifier ("__forwarding"),
+ build_pointer_type (Block_byref_type));
+ /* APPLE LOCAL radar 6244520 */
+ chainon (fields, field);
+
+ /* int32_t __flags; */
+ field = build_decl (FIELD_DECL, get_identifier ("__flags"),
+ unsigned_type_node);
+ chainon (fields, field);
+
+ /* int32_t __size; */
+ field = build_decl (FIELD_DECL, get_identifier ("__size"),
+ unsigned_type_node);
+ chainon (fields, field);
+
+ if (COPYABLE_BYREF_LOCAL_NONPOD (decl))
+ {
+ /* void *__ByrefKeepFuncPtr; */
+ field = build_decl (FIELD_DECL, get_identifier ("__ByrefKeepFuncPtr"),
+ ptr_type_node);
+ chainon (fields, field);
+
+ /* void *__ByrefDestroyFuncPtr; */
+ field = build_decl (FIELD_DECL, get_identifier ("__ByrefDestroyFuncPtr"),
+ ptr_type_node);
+ chainon (fields, field);
+ }
+
+ /* typex x; */
+ field = build_decl (FIELD_DECL, DECL_NAME (decl), TREE_TYPE (decl));
+ chainon (fields, field);
+
+ /* APPLE LOCAL begin radar 5847976 */
+ /* Hack so we don't issue warning on a field_decl having __weak attribute */
+ save_flag_objc_gc = flag_objc_gc;
+ flag_objc_gc = 0;
+ /* finish_struct (Block_byref_type, field_decl_chain, NULL_TREE); */
+ block_finish_struct (Block_byref_type, fields);
+ flag_objc_gc = save_flag_objc_gc;
+ /* APPLE LOCAL end radar 5847976 */
+ pop_from_top_level ();
+
+ TREE_TYPE (decl) = Block_byref_type;
+ /* Force layout_decl to recompute these fields. */
+ DECL_SIZE (decl) = DECL_SIZE_UNIT (decl) = 0;
+ layout_decl (decl, 0);
+ return decl;
+}
+
+/* init_byref_decl - This routine builds the initializer for the __Block_byref_x
+ type in the form of:
+ { NULL, &x, 0, sizeof(struct __Block_byref_x), initializer-expr};
+
+ or:
+ { NULL, &x, 0, sizeof(struct __Block_byref_x)};
+ when INIT is NULL_TREE
+
+ For __block ObjC objects, it also adds "byref_keep" and "byref_destroy"
+ Funtion pointers. So the most general initializers would be:
+
+ { NULL, &x, 0, sizeof(struct __Block_byref_x), &byref_keep, &byref_destroy,
+ &initializer-expr};
+ */
+static tree
+init_byref_decl (tree decl, tree init, int flag)
+{
+ tree initlist;
+ tree block_byref_type = TREE_TYPE (decl);
+ int size = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (block_byref_type));
+ unsigned flags = 0;
+ tree fields;
+
+ if (COPYABLE_BYREF_LOCAL_NONPOD (decl))
+ flags = BLOCK_HAS_COPY_DISPOSE;
+
+ fields = TYPE_FIELDS (block_byref_type);
+ /* APPLE LOCAL begin radar 6244520 */
+ initlist = tree_cons (fields, fold_convert (ptr_type_node, ((flag & BLOCK_FIELD_IS_WEAK) != 0) ? integer_one_node
+ : integer_zero_node),
+ 0);
+ fields = TREE_CHAIN (fields);
+
+ initlist = tree_cons (fields,
+ build_unary_op (ADDR_EXPR, decl, 0), initlist);
+ /* APPLE LOCAL end radar 6244520 */
+ fields = TREE_CHAIN (fields);
+
+ initlist = tree_cons (fields, build_int_cst (TREE_TYPE (fields), flags),
+ initlist);
+ fields = TREE_CHAIN (fields);
+ initlist = tree_cons (fields, build_int_cst (TREE_TYPE (fields), size),
+ initlist);
+ fields = TREE_CHAIN (fields);
+
+ if (COPYABLE_BYREF_LOCAL_NONPOD (decl))
+ {
+ char name[64];
+ int align = exact_log2 ((DECL_ALIGN (decl)+TYPE_ALIGN (ptr_type_node)-1) / TYPE_ALIGN (ptr_type_node));
+ int kind;
+ if (align == -1 || align > BLOCK_ALIGN_MAX) {
+ error ("invalid alignment for __block variable");
+ kind = 0;
+ } else
+ kind = align*BLOCK_BYREF_CURRENT_MAX + flag;
+ /* Add &__Block_byref_id_object_copy, &__Block_byref_id_object_dispose
+ initializers. */
+ if (!block_byref_id_object_copy[kind])
+ {
+ tree func_type;
+ push_lang_context (lang_name_c);
+ /* Build a void __Block_byref_id_object_copy(void*, void*) type. */
+ func_type =
+ build_function_type (void_type_node,
+ tree_cons (NULL_TREE, ptr_type_node,
+ tree_cons (NULL_TREE, ptr_type_node,
+ void_list_node)));
+ sprintf (name, "__Block_byref_id_object_copy%d", kind);
+ block_byref_id_object_copy[kind] = build_helper_func_decl (get_identifier (name),
+ func_type);
+ DECL_CONTEXT (block_byref_id_object_copy[kind]) = current_function_decl;
+ /* Synthesize function definition. */
+ synth_block_byref_id_object_copy_func (flag, kind);
+ pop_lang_context ();
+ }
+ initlist = tree_cons (fields,
+ build_fold_addr_expr (block_byref_id_object_copy[kind]),
+ initlist);
+ fields = TREE_CHAIN (fields);
+
+ if (!block_byref_id_object_dispose[kind])
+ {
+ tree func_type;
+ push_lang_context (lang_name_c);
+ /* Synthesize void __Block_byref_id_object_dispose (void*) and
+ build &__Block_byref_id_object_dispose. */
+ func_type =
+ build_function_type (void_type_node,
+ tree_cons (NULL_TREE, ptr_type_node, void_list_node));
+ sprintf (name, "__Block_byref_id_object_dispose%d", kind);
+ block_byref_id_object_dispose[kind] = build_helper_func_decl (get_identifier (name),
+ func_type);
+ DECL_CONTEXT (block_byref_id_object_dispose[kind]) = current_function_decl;
+ /* Synthesize function definition. */
+ synth_block_byref_id_object_dispose_func (flag, kind);
+ pop_lang_context ();
+ }
+ initlist = tree_cons (fields,
+ build_fold_addr_expr (block_byref_id_object_dispose[kind]),
+ initlist);
+ fields = TREE_CHAIN (fields);
+ }
+
+ if (init)
+ {
+ init = digest_init (TREE_TYPE (fields), init);
+ initlist = tree_cons (fields, init, initlist);
+ }
+ init = build_constructor_from_list (block_byref_type, nreverse (initlist));
+ return init;
+}
+/* APPLE LOCAL end blocks 6040305 (cr) */
+
/* Finish processing of a declaration;
install its line number and initial value.
If the length of an array type is not known before,
@@ -5295,6 +5681,17 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
if (DECL_THREAD_LOCAL_P (decl) && !pod_type_p (TREE_TYPE (decl)))
error ("%qD cannot be thread-local because it has non-POD type %qT",
decl, TREE_TYPE (decl));
+ /* APPLE LOCAL begin blocks 6040305 (cq) */
+ if (COPYABLE_BYREF_LOCAL_VAR (decl)) {
+ if (DECL_EXTERNAL (decl) || TREE_STATIC (decl))
+ {
+ error ("__block attribute on %q+D not allowed, only allowed on local variables", decl);
+ COPYABLE_BYREF_LOCAL_VAR (decl) = 0;
+ COPYABLE_BYREF_LOCAL_NONPOD (decl) = 0;
+ }
+ }
+ /* APPLE LOCAL end blocks 6040305 (cq) */
+
/* If this is a local variable that will need a mangled name,
register it now. We must do this before processing the
initializer for the variable, since the initialization might
@@ -5760,6 +6157,16 @@ expand_static_init (tree decl, tree init)
&& TYPE_HAS_TRIVIAL_DESTRUCTOR (TREE_TYPE (decl)))
return;
+ /* APPLE LOCAL begin radar 5733674 */
+ if (c_dialect_objc () && flag_objc_gc && init && TREE_CODE (init) == INIT_EXPR)
+ {
+ tree result = objc_generate_write_barrier (TREE_OPERAND (init, 0),
+ INIT_EXPR, TREE_OPERAND (init, 1));
+ if (result)
+ init = result;
+ }
+ /* APPLE LOCAL end radar 5733674 */
+
if (DECL_FUNCTION_SCOPE_P (decl))
{
/* Emit code to perform this initialization but once. */
@@ -7235,6 +7642,8 @@ grokdeclarator (const cp_declarator *declarator,
case cdk_pointer:
case cdk_reference:
case cdk_ptrmem:
+ /* APPLE LOCAL blocks 6040305 */
+ case cdk_block_pointer:
break;
case cdk_error:
@@ -7930,6 +8339,33 @@ grokdeclarator (const cp_declarator *declarator,
ctype = NULL_TREE;
break;
+ /* APPLE LOCAL begin blocks 6040305 (cj) */
+ case cdk_block_pointer:
+ if (TREE_CODE (type) != FUNCTION_TYPE)
+ {
+ error ("block pointer to non-function type is invalid");
+ type = error_mark_node;
+ }
+ else
+ {
+ /* We now know that the TYPE_QUALS don't apply to the decl,
+ but to the target of the pointer. */
+ type_quals = TYPE_UNQUALIFIED;
+
+ type = build_block_pointer_type (type);
+
+ if (declarator->u.pointer.qualifiers)
+ {
+ type
+ = cp_build_qualified_type (type,
+ declarator->u.pointer.qualifiers);
+ type_quals = cp_type_quals (type);
+ }
+ }
+ ctype = NULL_TREE;
+ break;
+ /* APPLE LOCAL end blocks 6040305 (cj) */
+
case cdk_error:
break;
@@ -8121,6 +8557,38 @@ grokdeclarator (const cp_declarator *declarator,
}
}
+ /* APPLE LOCAL begin blocks 6339747 */
+ if (decl_context == BLOCKDEF)
+ {
+ tree decl;
+
+ if (type == error_mark_node)
+ return error_mark_node;
+
+ if (TREE_CODE (type) != FUNCTION_TYPE)
+ {
+ tree t = make_node (FUNCTION_TYPE);
+
+ if (TREE_CODE (type) == ARRAY_TYPE)
+ {
+ error ("block declared as returning an array");
+ return error_mark_node;
+ }
+
+ TYPE_ARG_TYPES (t) = void_list_node;
+ TREE_TYPE (t) = type;
+ type = t;
+ parms = NULL_TREE;
+ }
+
+ if (raises)
+ type = build_exception_variant (type, raises);
+ decl = build_lang_decl (FUNCTION_DECL, NULL_TREE, type);
+ DECL_ARGUMENTS (decl) = parms;
+ return decl;
+ }
+ /* APPLE LOCAL end blocks 6339747 */
+
/* If this is declaring a typedef name, return a TYPE_DECL. */
if (declspecs->specs[(int)ds_typedef] && decl_context != TYPENAME)
{
@@ -8973,7 +9441,8 @@ check_default_argument (tree decl, tree arg)
*PARMS is set to the chain of PARM_DECLs created. */
-static tree
+/* APPLE LOCAL blocks 6040305 (ce) */
+tree
grokparms (cp_parameter_declarator *first_parm, tree *parms)
{
tree result = NULL_TREE;
@@ -10915,6 +11384,82 @@ start_preparsed_function (tree decl1, tree attrs, int flags)
}
+/* APPLE LOCAL begin warn missing prototype 6261539 */
+static bool
+fn_previously_found (tree decl, tree olddecl)
+{
+ int types_match;
+
+ if (olddecl == 0)
+ return false;
+
+ if (TREE_CODE (olddecl) == OVERLOAD)
+ {
+ if (OVL_CHAIN (olddecl) == NULL_TREE)
+ olddecl = OVL_CURRENT (olddecl);
+ else
+ {
+ tree match;
+ for (match = olddecl; match; match = OVL_NEXT (match))
+ {
+ if (fn_previously_found (decl, OVL_CURRENT (match)))
+ return true;
+ }
+ return false;
+ }
+ }
+
+ /* Don't warn about previously erroneous things that have the same
+ name. */
+ if (TREE_TYPE (olddecl) == error_mark_node)
+ return true;
+
+ /* Internally defined things still need a prototype to escape the
+ warning. */
+ if (DECL_ARTIFICIAL (olddecl))
+ return false;
+
+ if (TREE_CODE (olddecl) != FUNCTION_DECL)
+ return false;
+
+ /* These will match or error, don't also spew prototype warnings. */
+ if (DECL_EXTERN_C_P (olddecl)
+ && DECL_EXTERN_C_P (decl))
+ return true;
+
+ /* These will match or error, don't also spew prototype warnings. */
+ if (compparms (TYPE_ARG_TYPES (TREE_TYPE (decl)),
+ TYPE_ARG_TYPES (TREE_TYPE (olddecl))))
+ return true;
+
+ types_match = decls_match (decl, olddecl);
+
+ if (types_match)
+ return true;
+
+ return false;
+}
+
+inline static void
+check_missing_prototype (tree decl)
+{
+ if (warn_missing_prototypes
+ && namespace_bindings_p ()
+ && TREE_PUBLIC (decl)
+ && !DECL_MAIN_P (decl)
+ && DECL_NON_THUNK_FUNCTION_P (decl)
+ && ! DECL_FUNCTION_MEMBER_P (decl)
+ && DECL_NAMESPACE_SCOPE_P (decl)
+ && ! decl_anon_ns_mem_p (decl)
+ && ! DECL_DECLARED_INLINE_P (decl))
+ {
+ tree olddecl = namespace_binding (DECL_NAME (decl), DECL_CONTEXT (decl));
+ if (!fn_previously_found (decl, olddecl))
+ warning (OPT_Wmissing_prototypes, "no previous prototype for %q+D", decl);
+ }
+}
+/* APPLE LOCAL end warn missing prototype 6261539 */
+
/* Like start_preparsed_function, except that instead of a
FUNCTION_DECL, this function takes DECLSPECS and DECLARATOR.
@@ -11259,6 +11804,8 @@ finish_function (int flags)
tree fndecl = current_function_decl;
tree fntype, ctype = NULL_TREE;
int inclass_inline = (flags & 2) != 0;
+ /* APPLE LOCAL radar 6169580 */
+ int in_blocks_helper_function = (flags & 4) != 0;
int nested;
/* When we get some parse errors, we can end up without a
@@ -11452,7 +11999,8 @@ finish_function (int flags)
maybe_end_member_template_processing ();
/* Leave the scope of the class. */
- if (ctype)
+ /* APPLE LOCAL radar 6169580 */
+ if (ctype && !in_blocks_helper_function)
pop_nested_class ();
--function_depth;
@@ -11678,13 +12226,32 @@ cxx_maybe_build_cleanup (tree decl)
{
tree type = TREE_TYPE (decl);
- if (type != error_mark_node && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
+ /* APPLE LOCAL begin omit calls to empty destructors 5559195 */
+ tree dtor = NULL_TREE;
+ bool build_cleanup = false;
+
+ if (TREE_CODE (type) == RECORD_TYPE)
+ dtor = CLASSTYPE_DESTRUCTORS (type);
+
+ if (type != error_mark_node)
{
+ if (TREE_CODE (type) == RECORD_TYPE)
+ /* For RECORD_TYPEs, we can refer to more precise flags than
+ TYPE_HAS_NONTRIVIAL_DESTRUCTOR. */
+ build_cleanup = (dtor && TREE_PRIVATE (dtor))
+ || CLASSTYPE_HAS_NONTRIVIAL_DESTRUCTOR_BODY (type)
+ || CLASSTYPE_DESTRUCTOR_NONTRIVIAL_BECAUSE_OF_BASE (type);
+ else
+ build_cleanup = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type);
+ }
+
+ if (build_cleanup)
+ {
+ /* APPLE LOCAL end omit calls to empty destructors 5559195 */
int flags = LOOKUP_NORMAL|LOOKUP_DESTRUCTOR;
tree rval;
bool has_vbases = (TREE_CODE (type) == RECORD_TYPE
&& CLASSTYPE_VBASECLASSES (type));
-
if (TREE_CODE (type) == ARRAY_TYPE)
rval = decl;
else
diff --git a/contrib/gcc/cp/decl.h b/contrib/gcc/cp/decl.h
index dd2357a..179d8a86 100644
--- a/contrib/gcc/cp/decl.h
+++ b/contrib/gcc/cp/decl.h
@@ -27,6 +27,8 @@ enum decl_context
FIELD, /* Declaration inside struct or union */
BITFIELD, /* Likewise but with specified width */
TYPENAME, /* Typename (inside cast or sizeof) */
+ /* APPLE LOCAL blocks 6339747 */
+ BLOCKDEF, /* Declaratin of block literal */
MEMFUNCDEF /* Member function definition */
};
@@ -34,3 +36,7 @@ enum decl_context
extern tree grokdeclarator (const cp_declarator *,
const cp_decl_specifier_seq *,
enum decl_context, int, tree*);
+/* APPLE LOCAL radar 4721858 */
+extern void emit_instantiate_pending_templates (location_t *);
+/* APPLE LOCAL blocks 6040305 (ce) */
+extern tree grokparms (cp_parameter_declarator *first_parm, tree *parms);
diff --git a/contrib/gcc/cp/decl2.c b/contrib/gcc/cp/decl2.c
index 69cdb99..8c31bb9 100644
--- a/contrib/gcc/cp/decl2.c
+++ b/contrib/gcc/cp/decl2.c
@@ -1904,6 +1904,27 @@ constrain_class_visibility (tree type)
}
}
+/* APPLE LOCAL begin weak types 5954418 */
+static bool
+typeinfo_comdat (tree type)
+{
+ tree binfo, base_binfo;
+ int j;
+
+ if (lookup_attribute ("weak", TYPE_ATTRIBUTES (type)))
+ return true;
+
+ for (binfo = TYPE_BINFO (type), j = 0;
+ BINFO_BASE_ITERATE (binfo, j, base_binfo); ++j)
+ {
+ if (typeinfo_comdat (BINFO_TYPE (base_binfo)))
+ return true;
+ }
+
+ return false;
+}
+/* APPLE LOCAL end weak types 5954418 */
+
/* DECL is a FUNCTION_DECL or VAR_DECL. If the object file linkage
for DECL has not already been determined, do so now by setting
DECL_EXTERNAL, DECL_COMDAT and other related flags. Until this
@@ -2100,7 +2121,10 @@ import_export_decl (tree decl)
{
comdat_p = (targetm.cxx.class_data_always_comdat ()
|| (CLASSTYPE_KEY_METHOD (type)
- && DECL_DECLARED_INLINE_P (CLASSTYPE_KEY_METHOD (type))));
+ /* APPLE LOCAL begin weak types 5954418 */
+ && DECL_DECLARED_INLINE_P (CLASSTYPE_KEY_METHOD (type)))
+ || typeinfo_comdat (type));
+ /* APPLE LOCAL end weak types 5954418 */
mark_needed (decl);
if (!flag_weak)
{
@@ -3043,6 +3067,10 @@ build_java_method_aliases (void)
}
}
+/* APPLE LOCAL begin radar 4721858 */
+static void emit_deferred (location_t *);
+/* APPLE LOCAL end radar 4721858 */
+
/* This routine is called from the last rule in yyparse ().
Its job is to create all the code needed to initialize and
destroy the global aggregates. We do the destruction
@@ -3051,14 +3079,10 @@ build_java_method_aliases (void)
void
cp_finish_file (void)
{
- tree vars;
- bool reconsider;
- size_t i;
+ /* APPLE LOCAL begin radar 4721858 */
location_t locus;
- unsigned ssdf_count = 0;
- int retries = 0;
- tree decl;
-
+ /* APPLE LOCAL end radar 4721858 */
+
locus = input_location;
at_eof = 1;
@@ -3066,8 +3090,8 @@ cp_finish_file (void)
if (! global_bindings_p () || current_class_type || decl_namespace_list)
return;
- if (pch_file)
- c_common_write_pch ();
+ /* APPLE LOCAL radar 4874613 */
+ /* dump of pch file moved to c_parse_file (). */
#ifdef USE_MAPPED_LOCATION
/* FIXME - huh? */
@@ -3097,6 +3121,29 @@ cp_finish_file (void)
emit_support_tinfos ();
+ /* APPLE LOCAL begin radar 4721858 */
+ emit_instantiate_pending_templates (&locus);
+
+ emit_deferred (&locus);
+}
+
+/* This routine emits pending functions and instatiates pending templates
+ as more opportunities arises. */
+
+void
+emit_instantiate_pending_templates (location_t *locusp)
+{
+ tree vars;
+ bool reconsider;
+ size_t i;
+ unsigned ssdf_count = 0;
+ int retries = 0;
+
+ /* APPLE LOCAL radar 4874626 */
+ /* initialization removed. */
+ at_eof = 1;
+/* APPLE LOCAL end radar 4721858 */
+
do
{
tree t;
@@ -3174,7 +3221,8 @@ cp_finish_file (void)
/* Set the line and file, so that it is obviously not from
the source file. */
- input_location = locus;
+ /* APPLE LOCAL radar 4721858 */
+ input_location = *locusp;
ssdf_body = start_static_storage_duration_function (ssdf_count);
/* Make sure the back end knows about all the variables. */
@@ -3200,7 +3248,8 @@ cp_finish_file (void)
/* Finish up the static storage duration function for this
round. */
- input_location = locus;
+ /* APPLE LOCAL radar 4721858 */
+ input_location = *locusp;
finish_static_storage_duration_function (ssdf_body);
/* All those initializations and finalizations might cause
@@ -3211,7 +3260,8 @@ cp_finish_file (void)
#ifdef USE_MAPPED_LOCATION
/* ??? */
#else
- locus.line++;
+ /* APPLE LOCAL radar 4721858 */
+ locusp->line++;
#endif
}
@@ -3309,27 +3359,36 @@ cp_finish_file (void)
retries++;
}
while (reconsider);
+/* APPLE LOCAL begin radar 4721858 */
+}
+static void
+emit_deferred (location_t *locusp)
+{
+ size_t i;
+ tree decl;
+ bool reconsider = false;
+ /* APPLE LOCAL end radar 4721858 */
/* All used inline functions must have a definition at this point. */
for (i = 0; VEC_iterate (tree, deferred_fns, i, decl); ++i)
{
if (/* Check online inline functions that were actually used. */
- TREE_USED (decl) && DECL_DECLARED_INLINE_P (decl)
- /* If the definition actually was available here, then the
- fact that the function was not defined merely represents
- that for some reason (use of a template repository,
- #pragma interface, etc.) we decided not to emit the
- definition here. */
- && !DECL_INITIAL (decl)
- /* An explicit instantiation can be used to specify
- that the body is in another unit. It will have
- already verified there was a definition. */
- && !DECL_EXPLICIT_INSTANTIATION (decl))
- {
- warning (0, "inline function %q+D used but never defined", decl);
- /* Avoid a duplicate warning from check_global_declaration_1. */
- TREE_NO_WARNING (decl) = 1;
- }
+ TREE_USED (decl) && DECL_DECLARED_INLINE_P (decl)
+ /* If the definition actually was available here, then the
+ fact that the function was not defined merely represents
+ that for some reason (use of a template repository,
+ #pragma interface, etc.) we decided not to emit the
+ definition here. */
+ && !DECL_INITIAL (decl)
+ /* An explicit instantiation can be used to specify
+ that the body is in another unit. It will have
+ already verified there was a definition. */
+ && !DECL_EXPLICIT_INSTANTIATION (decl))
+ {
+ warning (0, "inline function %q+D used but never defined", decl);
+ /* Avoid a duplicate warning from check_global_declaration_1. */
+ TREE_NO_WARNING (decl) = 1;
+ }
}
/* We give C linkage to static constructors and destructors. */
@@ -3340,17 +3399,20 @@ cp_finish_file (void)
if (priority_info_map)
splay_tree_foreach (priority_info_map,
generate_ctor_and_dtor_functions_for_priority,
- /*data=*/&locus);
+ /* APPLE LOCAL radar 4721858 */
+ /*data=*/locusp);
else
{
/* If we have a ctor or this is obj-c++ and we need a static init,
call generate_ctor_or_dtor_function. */
if (static_ctors || (c_dialect_objc () && objc_static_init_needed_p ()))
generate_ctor_or_dtor_function (/*constructor_p=*/true,
- DEFAULT_INIT_PRIORITY, &locus);
+ /* APPLE LOCAL radar 4721858 */
+ DEFAULT_INIT_PRIORITY, locusp);
if (static_dtors)
generate_ctor_or_dtor_function (/*constructor_p=*/false,
- DEFAULT_INIT_PRIORITY, &locus);
+ /* APPLE LOCAL radar 4721858 */
+ DEFAULT_INIT_PRIORITY, locusp);
}
/* We're done with the splay-tree now. */
@@ -3403,7 +3465,8 @@ cp_finish_file (void)
dump_tree_statistics ();
dump_time_statistics ();
}
- input_location = locus;
+ /* APPLE LOCAL radar 4721858 */
+ input_location = *locusp;
#ifdef ENABLE_CHECKING
validate_conversion_obstack ();
diff --git a/contrib/gcc/cp/error.c b/contrib/gcc/cp/error.c
index c169cab..f90096a 100644
--- a/contrib/gcc/cp/error.c
+++ b/contrib/gcc/cp/error.c
@@ -342,6 +342,8 @@ dump_type (tree t, int flags)
reduces code size. */
case ARRAY_TYPE:
case POINTER_TYPE:
+ /* APPLE LOCAL blocks 6040305 */
+ case BLOCK_POINTER_TYPE:
case REFERENCE_TYPE:
case OFFSET_TYPE:
offset_type:
@@ -497,6 +499,8 @@ dump_type_prefix (tree t, int flags)
switch (TREE_CODE (t))
{
case POINTER_TYPE:
+ /* APPLE LOCAL blocks 6040305 */
+ case BLOCK_POINTER_TYPE:
case REFERENCE_TYPE:
{
tree sub = TREE_TYPE (t);
@@ -507,7 +511,10 @@ dump_type_prefix (tree t, int flags)
pp_cxx_whitespace (cxx_pp);
pp_cxx_left_paren (cxx_pp);
}
- pp_character (cxx_pp, "&*"[TREE_CODE (t) == POINTER_TYPE]);
+ /* APPLE LOCAL begin blocks 6040305 */
+ pp_character (cxx_pp, "&*^"[(TREE_CODE (t) == POINTER_TYPE)
+ + (TREE_CODE (t) == BLOCK_POINTER_TYPE)*2]);
+ /* APPLE LOCAL end blocks 6040305 */
pp_base (cxx_pp)->padding = pp_before;
pp_cxx_cv_qualifier_seq (cxx_pp, t);
}
@@ -593,6 +600,8 @@ dump_type_suffix (tree t, int flags)
switch (TREE_CODE (t))
{
case POINTER_TYPE:
+ /* APPLE LOCAL blocks 6040305 */
+ case BLOCK_POINTER_TYPE:
case REFERENCE_TYPE:
case OFFSET_TYPE:
if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
diff --git a/contrib/gcc/cp/init.c b/contrib/gcc/cp/init.c
index fbdd609..0d67fef 100644
--- a/contrib/gcc/cp/init.c
+++ b/contrib/gcc/cp/init.c
@@ -2905,7 +2905,13 @@ push_base_cleanups (void)
for (binfo = TYPE_BINFO (current_class_type), i = 0;
BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
{
- if (TYPE_HAS_TRIVIAL_DESTRUCTOR (BINFO_TYPE (base_binfo))
+ /* APPLE LOCAL begin omit calls to empty destructors 5559195 */
+ tree dtor = CLASSTYPE_DESTRUCTORS (BINFO_TYPE (base_binfo));
+
+ if ((!CLASSTYPE_DESTRUCTOR_NONTRIVIAL_BECAUSE_OF_BASE (BINFO_TYPE (base_binfo))
+ && !CLASSTYPE_HAS_NONTRIVIAL_DESTRUCTOR_BODY (BINFO_TYPE (base_binfo))
+ && !(dtor && (TREE_PRIVATE (dtor))))
+ /* APPLE LOCAL end omit calls to empty destructors 5559195 */
|| BINFO_VIRTUAL_P (base_binfo))
continue;
@@ -2935,6 +2941,12 @@ push_base_cleanups (void)
LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR|LOOKUP_NORMAL,
0);
finish_decl_cleanup (NULL_TREE, expr);
+
+ /* APPLE LOCAL begin omit calls to empty destructors 5559195 */
+ /* Even if body of current class's destructor was found to be empty,
+ it must now be called because it must delete its members. */
+ CLASSTYPE_DESTRUCTOR_NONTRIVIAL_BECAUSE_OF_BASE (current_class_type) = 1;
+ /* APPLE LOCAL end omit calls to empty destructors 5559195 */
}
}
}
diff --git a/contrib/gcc/cp/mangle.c b/contrib/gcc/cp/mangle.c
index 8bfdc20..c6147f7 100644
--- a/contrib/gcc/cp/mangle.c
+++ b/contrib/gcc/cp/mangle.c
@@ -1634,6 +1634,13 @@ write_type (tree type)
write_type (TREE_TYPE (type));
break;
+ /* APPLE LOCAL begin blocks 6040305 */
+ case BLOCK_POINTER_TYPE:
+ write_string ("U13block_pointer");
+ write_type (TREE_TYPE (type));
+ break;
+ /* APPLE LOCAL end blocks 6040305 */
+
case REFERENCE_TYPE:
write_char ('R');
write_type (TREE_TYPE (type));
diff --git a/contrib/gcc/cp/name-lookup.c b/contrib/gcc/cp/name-lookup.c
index e18794f..fa7ae5c 100644
--- a/contrib/gcc/cp/name-lookup.c
+++ b/contrib/gcc/cp/name-lookup.c
@@ -363,6 +363,8 @@ push_binding (tree id, tree decl, cxx_scope* level)
{
binding = cxx_binding_make (decl, NULL_TREE);
binding->scope = level;
+ /* APPLE LOCAL blocks 6040305 (ch) */
+ binding->declared_in_block = cur_block != 0;
}
else
binding = new_class_binding (id, decl, /*type=*/NULL_TREE, level);
@@ -1821,6 +1823,8 @@ binding_for_name (cxx_scope *scope, tree name)
result->scope = scope;
result->is_local = false;
result->value_is_inherited = false;
+ /* APPLE LOCAL blocks 6040305 (ch) */
+ result->declared_in_block = 0;
IDENTIFIER_NAMESPACE_BINDINGS (name) = result;
return result;
}
@@ -4597,6 +4601,8 @@ arg_assoc_type (struct arg_lookup *k, tree type)
return arg_assoc_type (k, TYPE_PTRMEMFUNC_FN_TYPE (type));
return arg_assoc_class (k, type);
case POINTER_TYPE:
+ /* APPLE LOCAL blocks 6040305 */
+ case BLOCK_POINTER_TYPE:
case REFERENCE_TYPE:
case ARRAY_TYPE:
return arg_assoc_type (k, TREE_TYPE (type));
diff --git a/contrib/gcc/cp/name-lookup.h b/contrib/gcc/cp/name-lookup.h
index 0d99f9b..f604f87 100644
--- a/contrib/gcc/cp/name-lookup.h
+++ b/contrib/gcc/cp/name-lookup.h
@@ -76,6 +76,8 @@ struct cxx_binding GTY(())
cxx_scope *scope;
unsigned value_is_inherited : 1;
unsigned is_local : 1;
+ /* APPLE LOCAL blocks 6040305 (ch) */
+ unsigned declared_in_block : 1;
};
/* Datatype used to temporarily save C++ bindings (for implicit
diff --git a/contrib/gcc/cp/parser.c b/contrib/gcc/cp/parser.c
index fded0fd..25cc225 100644
--- a/contrib/gcc/cp/parser.c
+++ b/contrib/gcc/cp/parser.c
@@ -38,6 +38,8 @@
#include "target.h"
#include "cgraph.h"
#include "c-common.h"
+/* APPLE LOCAL C* language */
+#include "tree-iterator.h"
/* The lexer. */
@@ -1120,6 +1122,10 @@ typedef enum cp_parser_flags
typedef enum cp_parser_declarator_kind
{
+ /* APPLE LOCAL begin blocks 6339747 */
+ /* We want a block declarator. */
+ CP_PARSER_DECLARATOR_BLOCK,
+ /* APPLE LOCAL end blocks 6339747 */
/* We want an abstract declarator. */
CP_PARSER_DECLARATOR_ABSTRACT,
/* We want a named declarator. */
@@ -1539,6 +1545,23 @@ static tree cp_parser_constant_expression
(cp_parser *, bool, bool *);
static tree cp_parser_builtin_offsetof
(cp_parser *);
+/* APPLE LOCAL begin blocks 6040305 (ca) */
+static tree cp_parser_block_literal_expr (cp_parser *);
+/* APPLE LOCAL end blocks 6040305 (ca) */
+/* APPLE LOCAL begin C* language */
+static void objc_foreach_stmt
+ (cp_parser *, tree);
+/* APPLE LOCAL end C* language */
+/* APPLE LOCAL begin C* property (Radar 4436866) */
+static void objc_cp_parser_at_property
+ (cp_parser *);
+static void objc_cp_parse_property_decl
+ (cp_parser *);
+/* APPLE LOCAL end C* property (Radar 4436866) */
+/* APPLE LOCAL begin radar 4548636 */
+static bool objc_attr_follwed_by_at_keyword
+ (cp_parser *);
+/* APPLE LOCAL end radar 4548636 */
/* Statements [gram.stmt.stmt] */
@@ -1549,7 +1572,8 @@ static void cp_parser_label_for_labeled_statement
static tree cp_parser_expression_statement
(cp_parser *, tree);
static tree cp_parser_compound_statement
- (cp_parser *, tree, bool);
+ /* APPLE LOCAL radar 5982990 */
+ (cp_parser *, tree, bool, bool);
static void cp_parser_statement_seq_opt
(cp_parser *, tree);
static tree cp_parser_selection_statement
@@ -1777,6 +1801,10 @@ static tree cp_parser_objc_message_args
(cp_parser *);
static tree cp_parser_objc_message_expression
(cp_parser *);
+/* APPLE LOCAL begin radar 5277239 */
+static tree cp_parser_objc_reference_expression
+ (cp_parser *, tree);
+/* APPLE LOCAL end radar 5277239 */
static tree cp_parser_objc_encode_expression
(cp_parser *);
static tree cp_parser_objc_defs_expression
@@ -1791,6 +1819,12 @@ static bool cp_parser_objc_selector_p
(enum cpp_ttype);
static tree cp_parser_objc_selector
(cp_parser *);
+/* APPLE LOCAL begin radar 3803157 - objc attribute */
+static void cp_parser_objc_maybe_attributes
+(cp_parser *, tree *);
+static tree cp_parser_objc_identifier_list
+(cp_parser *);
+/* APPLE LOCAL end radar 3803157 - objc attribute */
static tree cp_parser_objc_protocol_refs_opt
(cp_parser *);
static void cp_parser_objc_declaration
@@ -2443,6 +2477,141 @@ cp_parser_skip_to_end_of_statement (cp_parser* parser)
}
}
+/* APPLE LOCAL begin radar 5277239 */
+/* This routine checks that type_decl is a class or class object followed by a '.'
+ which is an alternative syntax to class-method messaging [class-name class-method]
+ */
+
+static bool
+cp_objc_property_reference_prefix (cp_parser *parser, tree type)
+{
+ return c_dialect_objc () && cp_lexer_peek_token (parser->lexer)->type == CPP_DOT
+ && (objc_is_id (type) || objc_is_class_name (type));
+}
+/* APPLE LOCAL end radar 5277239 */
+/* APPLE LOCAL begin C* property (Radar 4436866, 4591909) */
+/* This routine parses the propery declarations. */
+
+static void
+objc_cp_parse_property_decl (cp_parser *parser)
+{
+ int declares_class_or_enum;
+ cp_decl_specifier_seq declspecs;
+
+ cp_parser_decl_specifier_seq (parser,
+ CP_PARSER_FLAGS_NONE,
+ &declspecs,
+ &declares_class_or_enum);
+ /* Keep going until we hit the `;' at the end of the declaration. */
+ while (cp_lexer_next_token_is_not (parser->lexer, CPP_SEMICOLON))
+ {
+ tree property;
+ cp_token *token;
+ cp_declarator *declarator
+ = cp_parser_declarator (parser, CP_PARSER_DECLARATOR_NAMED,
+ NULL, NULL, false);
+ property = grokdeclarator (declarator, &declspecs, NORMAL,0, NULL);
+ /* Revover from any kind of error in property declaration. */
+ if (property == error_mark_node || property == NULL_TREE)
+ return;
+ /* Add to property list. */
+ objc_add_property_variable (copy_node (property));
+ if (token->type == CPP_COMMA)
+ {
+ cp_lexer_consume_token (parser->lexer); /* Eat ','. */
+ continue;
+ }
+ else if (token->type == CPP_EOF)
+ return;
+ }
+ cp_lexer_consume_token (parser->lexer); /* Eat ';'. */
+}
+
+/* This function parses a @property declaration inside an objective class
+ or its implementation. */
+
+static void
+objc_cp_parser_at_property (cp_parser *parser)
+{
+ cp_token *token;
+
+ objc_set_property_attr (0, NULL_TREE);
+ /* Consume @property */
+ cp_lexer_consume_token (parser->lexer);
+ token = cp_lexer_peek_token (parser->lexer);
+ if (token->type == CPP_OPEN_PAREN)
+ {
+ cp_lexer_consume_token (parser->lexer);
+ while (token->type != CPP_CLOSE_PAREN && token->type != CPP_EOF)
+ {
+ tree node;
+ /* property has attribute list. */
+ /* Consume '(' */
+ node = cp_parser_identifier (parser);
+ if (node == ridpointers [(int) RID_READONLY])
+ {
+ /* Do the readyonly thing. */
+ objc_set_property_attr (1, NULL_TREE);
+ }
+ else if (node == ridpointers [(int) RID_GETTER]
+ || node == ridpointers [(int) RID_SETTER])
+ {
+ /* Do the getter/setter attribute. */
+ token = cp_lexer_consume_token (parser->lexer);
+ if (token->type == CPP_EQ)
+ {
+ /* APPLE LOCAL radar 4675792 */
+ tree attr_ident = cp_parser_objc_selector (parser);
+ int num;
+ if (node == ridpointers [(int) RID_GETTER])
+ num = 2;
+ else
+ {
+ num = 3;
+ /* Consume the ':' which must always follow the setter name. */
+ if (cp_lexer_next_token_is (parser->lexer, CPP_COLON))
+ cp_lexer_consume_token (parser->lexer);
+ }
+ objc_set_property_attr (num, attr_ident);
+ }
+ else
+ {
+ error ("getter/setter attribute must be followed by '='");
+ break;
+ }
+ }
+ /* APPLE LOCAL begin radar 4947014 - objc atomic property */
+ else if (node == ridpointers [(int) RID_NONATOMIC])
+ {
+ objc_set_property_attr (13, NULL_TREE);
+ }
+ /* APPLE LOCAL end radar 4947014 - objc atomic property */
+ else
+ {
+ error ("unknown property attribute");
+ break;
+ }
+ /* APPLE LOCAL begin radar 6302949 */
+ if (cp_lexer_next_token_is_not (parser->lexer, CPP_COMMA)
+ && cp_lexer_next_token_is_not (parser->lexer, CPP_CLOSE_PAREN)
+ && cp_lexer_next_token_is_not (parser->lexer, CPP_EOF))
+ warning (0, "property attributes must be separated by a comma");
+ /* APPLE LOCAL end radar 6302949 */
+ if (cp_lexer_next_token_is (parser->lexer, CPP_COMMA))
+ cp_lexer_consume_token (parser->lexer);
+ token = cp_lexer_peek_token (parser->lexer);
+ }
+ if (token->type != CPP_CLOSE_PAREN)
+ {
+ error ("syntax error in @property's attribute declaration");
+ }
+ /* Consume ')' */
+ cp_lexer_consume_token (parser->lexer);
+ }
+ objc_cp_parse_property_decl (parser);
+}
+/* APPLE LOCAL end C* property (Radar 4436866, 4591909) */
+
/* This function is called at the end of a statement or declaration.
If the next token is a semicolon, it is consumed; otherwise, error
recovery is attempted. */
@@ -2901,6 +3070,8 @@ cp_parser_translation_unit (cp_parser* parser)
( compound-statement )
__builtin_va_arg ( assignment-expression , type-id )
__builtin_offsetof ( type-id , offsetof-expression )
+ APPLE LOCAL blocks 6040305 (cf)
+ block-literal-expr
Objective-C++ Extension:
@@ -2934,6 +3105,16 @@ cp_parser_primary_expression (cp_parser *parser,
token = cp_lexer_peek_token (parser->lexer);
switch (token->type)
{
+ /* APPLE LOCAL begin blocks 6040305 (cf) */
+ case CPP_XOR:
+ if (flag_blocks)
+ {
+ tree expr = cp_parser_block_literal_expr (parser);
+ return expr;
+ }
+ cp_parser_error (parser, "expected primary-expression");
+ return error_mark_node;
+ /* APPLE LOCAL end blocks 6040305 (cf) */
/* literal:
integer-literal
character-literal
@@ -3027,7 +3208,8 @@ cp_parser_primary_expression (cp_parser *parser,
/* Start the statement-expression. */
expr = begin_stmt_expr ();
/* Parse the compound-statement. */
- cp_parser_compound_statement (parser, expr, false);
+ /* APPLE LOCAL radar 5982990 */
+ cp_parser_compound_statement (parser, expr, false, false);
/* Finish up. */
expr = finish_stmt_expr (expr, false);
}
@@ -3197,6 +3379,11 @@ cp_parser_primary_expression (cp_parser *parser,
if (ambiguous_decls)
return error_mark_node;
+ /* APPLE LOCAL begin radar 5277239 */
+ if (TREE_CODE (decl) == TYPE_DECL
+ && cp_objc_property_reference_prefix (parser, TREE_TYPE (decl)))
+ return cp_parser_objc_reference_expression (parser, decl);
+ /* APPLE LOCAL end radar 5277239 */
/* In Objective-C++, an instance variable (ivar) may be preferred
to whatever cp_parser_lookup_name() found. */
decl = objc_lookup_ivar (decl, id_expression);
@@ -6329,7 +6516,8 @@ cp_parser_statement (cp_parser* parser, tree in_statement_expr,
}
/* Anything that starts with a `{' must be a compound-statement. */
else if (token->type == CPP_OPEN_BRACE)
- statement = cp_parser_compound_statement (parser, NULL, false);
+ /* APPLE LOCAL radar 5982990 */
+ statement = cp_parser_compound_statement (parser, NULL, false, false);
/* CPP_PRAGMA is a #pragma inside a function body, which constitutes
a statement all its own. */
else if (token->type == CPP_PRAGMA)
@@ -6503,7 +6691,8 @@ cp_parser_expression_statement (cp_parser* parser, tree in_statement_expr)
static tree
cp_parser_compound_statement (cp_parser *parser, tree in_statement_expr,
- bool in_try)
+ /* APPLE LOCAL radar 5982990 */
+ bool in_try, bool objc_sjlj_exceptions)
{
tree compound_stmt;
@@ -6514,6 +6703,10 @@ cp_parser_compound_statement (cp_parser *parser, tree in_statement_expr,
compound_stmt = begin_compound_stmt (in_try ? BCS_TRY_BLOCK : 0);
/* Parse an (optional) statement-seq. */
cp_parser_statement_seq_opt (parser, in_statement_expr);
+ /* APPLE LOCAL begin radar 5982990 */
+ if (objc_sjlj_exceptions)
+ objc_mark_locals_volatile (NULL);
+ /* APPLE LOCAL end radar 5982990 */
/* Finish the compound-statement. */
finish_compound_stmt (compound_stmt);
/* Consume the `}'. */
@@ -6531,17 +6724,45 @@ cp_parser_compound_statement (cp_parser *parser, tree in_statement_expr,
static void
cp_parser_statement_seq_opt (cp_parser* parser, tree in_statement_expr)
{
+ /* APPLE LOCAL begin omit calls to empty destructors 5559195 */
+ tree class_type = DECL_CONTEXT (current_function_decl);
+
+ bool determine_destructor_triviality =
+ DECL_DESTRUCTOR_P (current_function_decl) && class_type != NULL_TREE
+ && !CLASSTYPE_DESTRUCTOR_TRIVIALITY_FINAL (class_type);
+
+ /* Assume that the destructor is trivial at first, and mark nontrivial if
+ any statement is parsed. */
+ if (determine_destructor_triviality)
+ {
+ CLASSTYPE_HAS_NONTRIVIAL_DESTRUCTOR_BODY (class_type) = 0;
+ CLASSTYPE_DESTRUCTOR_TRIVIALITY_FINAL (class_type) = 1;
+ }
+ /* APPLE LOCAL end omit calls to empty destructors 5559195 */
+
/* Scan statements until there aren't any more. */
while (true)
{
cp_token *token = cp_lexer_peek_token (parser->lexer);
- /* If we're looking at a `}', then we've run out of statements. */
+ /* APPLE LOCAL begin ObjC++ 4185810 */
+ /* If we're looking at a `}', then we've run out of
+ statements; the same is true if we have reached the end
+ of file, or have stumbled upon a stray 'else' or '@end'. */
if (token->type == CPP_CLOSE_BRACE
|| token->type == CPP_EOF
- || token->type == CPP_PRAGMA_EOL)
+ || token->type == CPP_PRAGMA_EOL
+ || (token->type == CPP_KEYWORD
+ && (token->keyword == RID_ELSE
+ || token->keyword == RID_AT_END)))
+ /* APPLE LOCAL end ObjC++ 4185810 */
break;
+ /* APPLE LOCAL begin omit calls to empty destructors 5559195 */
+ if (determine_destructor_triviality)
+ CLASSTYPE_HAS_NONTRIVIAL_DESTRUCTOR_BODY (class_type) = 1;
+ /* APPLE LOCAL end omit calls to empty destructors 5559195 */
+
/* Parse the statement. */
cp_parser_statement (parser, in_statement_expr, true, NULL);
}
@@ -6779,11 +7000,119 @@ cp_parser_condition (cp_parser* parser)
return cp_parser_expression (parser, /*cast_p=*/false);
}
+/* APPLE LOCAL begin radar 4631818 */
+/* This routine looks for objective-c++'s foreach statement by scanning for-loop
+ header looking for either 1) 'for (type selector in...)' or 2) 'for (selector in...)'
+ where selector is already declared in outer scope. If it failed, it undoes the lexical
+ look-ahead and returns false. If it succeeded, it adds the 'selector' to the statement
+ list and returns true. At success, lexer points to token following the 'in' keyword.
+*/
+
+static bool
+cp_parser_parse_foreach_stmt (cp_parser *parser)
+{
+ int decl_spec_declares_class_or_enum;
+ bool is_cv_qualifier;
+ tree type_spec;
+ cp_decl_specifier_seq decl_specs;
+ tree node;
+ cp_token *token;
+ bool is_legit_foreach = false;
+ cp_declarator *declarator;
+
+ /* Exclude class/struct/enum type definition in for-loop header, which is
+ aparently legal in c++. Otherwise, it causes side-effect (type is enterred
+ in function's scope) when type is re-parsed. */
+ token = cp_lexer_peek_token (parser->lexer);
+ if (cp_parser_token_is_class_key (token) || token->keyword == RID_ENUM)
+ return false;
+
+ cp_parser_parse_tentatively (parser);
+ clear_decl_specs (&decl_specs);
+ type_spec
+ = cp_parser_type_specifier (parser, CP_PARSER_FLAGS_OPTIONAL,
+ &decl_specs,
+ /*is_declaration=*/true,
+ &decl_spec_declares_class_or_enum,
+ &is_cv_qualifier);
+ declarator
+ = cp_parser_declarator (parser, CP_PARSER_DECLARATOR_NAMED,
+ NULL,
+ /*parenthesized_p=*/NULL,
+ /*member_p=*/false);
+ if (declarator == cp_error_declarator)
+ {
+ cp_parser_abort_tentative_parse (parser);
+ return false;
+ }
+
+ token = cp_lexer_peek_token (parser->lexer);
+
+ node = token->u.value;
+ if (node && TREE_CODE (node) == IDENTIFIER_NODE
+ && node == ridpointers [(int) RID_IN])
+ {
+ enum cpp_ttype nt = cp_lexer_peek_nth_token (parser->lexer, 2)->type;
+ switch (nt)
+ {
+ case CPP_NAME:
+ case CPP_OPEN_PAREN:
+ case CPP_MULT:
+ case CPP_PLUS: case CPP_PLUS_PLUS:
+ case CPP_MINUS: case CPP_MINUS_MINUS:
+ case CPP_OPEN_SQUARE:
+ is_legit_foreach = true;
+ default:
+ break;
+ }
+ }
+ if (is_legit_foreach)
+ {
+ tree pushed_scope = NULL;
+ tree decl;
+ if (type_spec)
+ {
+ /* we have: 'for (type selector in...)' */
+ cp_parser_commit_to_tentative_parse (parser);
+ decl = start_decl (declarator, &decl_specs,
+ false /*is_initialized*/,
+ NULL_TREE /*attributes*/,
+ NULL_TREE /*prefix_attributes*/,
+ &pushed_scope);
+ /* APPLE LOCAL begin radar 5130983 */
+ if (!decl || decl == error_mark_node)
+ {
+ error ("selector is undeclared");
+ is_legit_foreach = false;
+ }
+ else
+ cp_finish_decl (decl,
+ NULL_TREE /*initializer*/,
+ false /*init_const_expr_p=*/,
+ NULL_TREE /*asm_specification*/,
+ 0 /*flags */);
+ }
+ else {
+ tree statement;
+ /* we have: 'for (selector in...)' */
+ /* Parse it as an expression. */
+ cp_parser_abort_tentative_parse (parser);
+ statement = cp_parser_expression (parser, /*cast_p=*/false);
+ add_stmt (statement);
+ }
+ /* APPLE LOCAL end radar 5130983 */
+ /* Consume the 'in' token */
+ cp_lexer_consume_token (parser->lexer);
+ }
+ else
+ cp_parser_abort_tentative_parse (parser);
+ return is_legit_foreach;
+}
+/* APPLE LOCAL end radar 4631818 */
+
/* Parse an iteration-statement.
iteration-statement:
- while ( condition ) statement
- do statement while ( expression ) ;
for ( for-init-statement condition [opt] ; expression [opt] )
statement
@@ -7050,6 +7379,10 @@ cp_parser_jump_statement (cp_parser* parser)
break;
case RID_GOTO:
+ /* APPLE LOCAL begin blocks 6040305 (cb) */
+ if (cur_block)
+ error ("goto not allowed in block literal");
+ /* APPLE LOCAL end blocks 6040305 (cb) */
/* Create the goto-statement. */
if (cp_lexer_next_token_is (parser->lexer, CPP_MULT))
{
@@ -7130,7 +7463,8 @@ cp_parser_implicitly_scoped_statement (cp_parser* parser, bool *if_p)
}
/* if a compound is opened, we simply parse the statement directly. */
else if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE))
- statement = cp_parser_compound_statement (parser, NULL, false);
+ /* APPLE LOCAL radar 5982990 */
+ statement = cp_parser_compound_statement (parser, NULL, false, false);
/* If the token is not a `{', then we must take special action. */
else
{
@@ -11459,6 +11793,37 @@ cp_parser_init_declarator (cp_parser* parser,
return decl;
}
+/* APPLE LOCAL begin blocks 6040305 (cc) */
+static cp_cv_quals
+cp_parser_cv_qualifier_or_attribute_seq_opt (cp_parser *parser, tree *attrs_p)
+{
+ cp_cv_quals quals = TYPE_UNQUALIFIED;
+ cp_cv_quals q;
+ cp_token *token;
+
+ *attrs_p = NULL_TREE;
+ while (true)
+ {
+ /* Peek at the next token. */
+ token = cp_lexer_peek_token (parser->lexer);
+ /* Handle attributes. */
+ if (token->keyword == RID_ATTRIBUTE)
+ {
+ /* Parse the attributes. */
+ *attrs_p = chainon (*attrs_p,
+ cp_parser_attributes_opt (parser));
+ continue;
+ }
+
+ q = cp_parser_cv_qualifier_seq_opt (parser);
+ if (q == TYPE_UNQUALIFIED)
+ break;
+ quals |= q;
+ }
+ return quals;
+}
+/* APPLE LOCAL end blocks 6040305 (cc) */
+
/* Parse a declarator.
declarator:
@@ -11479,6 +11844,12 @@ cp_parser_init_declarator (cp_parser* parser,
attributes [opt] ptr-operator abstract-declarator [opt]
attributes [opt] direct-abstract-declarator
+ APPLE LOCAL begin blocks 6339747
+ block-declarator:
+ attributes [opt] ptr-operator block-declarator [opt]
+ attributes [opt] direct-block-declarator
+ APPLE LOCAL end blocks 6339747
+
If CTOR_DTOR_OR_CONV_P is not NULL, *CTOR_DTOR_OR_CONV_P is used to
detect constructor, destructor or conversion operators. It is set
to -1 if the declarator is a name, and +1 if it is a
@@ -11523,6 +11894,28 @@ cp_parser_declarator (cp_parser* parser,
/* Peek at the next token. */
token = cp_lexer_peek_token (parser->lexer);
+ /* APPLE LOCAL begin blocks 6040305 (cc) */
+ if (flag_blocks && token->type == CPP_XOR)
+ {
+ cp_cv_quals quals;
+ cp_declarator *inner;
+ tree attrs;
+
+ cp_lexer_consume_token (parser->lexer);
+
+ /* cp_parse_declspecs (parser, quals_attrs, false, false, true); */
+ quals = cp_parser_cv_qualifier_or_attribute_seq_opt (parser, &attrs);
+
+ inner = cp_parser_declarator (parser, CP_PARSER_DECLARATOR_EITHER,
+ /*ctor_dtor_or_conv_p=*/NULL,
+ /*parenthesized_p=*/NULL,
+ /*member_p=*/false);
+ if (inner == cp_error_declarator)
+ return inner;
+ return make_block_pointer_declarator (attrs, quals, inner);
+ }
+ /* APPLE LOCAL end blocks 6040305 (cc) */
+
/* Check for the ptr-operator production. */
cp_parser_parse_tentatively (parser);
/* Parse the ptr-operator. */
@@ -11598,6 +11991,17 @@ cp_parser_declarator (cp_parser* parser,
direct-abstract-declarator [opt] [ constant-expression [opt] ]
( abstract-declarator )
+ APPLE LOCAL begin blocks 6339747
+ GNU Extensions:
+
+ direct-block-declarator:
+ direct-block-declarator [opt]
+ ( parameter-declaration-clause ) [opt]
+ exception-specification [opt]
+ direct-block-declarator [opt] [ constant-expression [opt] ]
+ ( block-declarator )
+ APPLE LOCAL end blocks 6339747
+
Returns a representation of the declarator. DCL_KIND is
CP_PARSER_DECLARATOR_ABSTRACT, if we are parsing a
direct-abstract-declarator. It is CP_PARSER_DECLARATOR_NAMED, if
@@ -11714,8 +12118,16 @@ cp_parser_direct_declarator (cp_parser* parser,
/* Consume the `)'. */
cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
- /* Parse the cv-qualifier-seq. */
- cv_quals = cp_parser_cv_qualifier_seq_opt (parser);
+ /* APPLE LOCAL begin blocks 6339747 */
+ if (dcl_kind != BLOCKDEF)
+ {
+ /* Parse the cv-qualifier-seq. */
+ cv_quals = cp_parser_cv_qualifier_seq_opt (parser);
+ }
+ else
+ cv_quals = TYPE_UNQUALIFIED;
+ /* APPLE LOCAL end blocks 6339747 */
+
/* And the exception-specification. */
exception_specification
= cp_parser_exception_specification_opt (parser);
@@ -11815,7 +12227,10 @@ cp_parser_direct_declarator (cp_parser* parser,
declarator = make_array_declarator (declarator, bounds);
}
- else if (first && dcl_kind != CP_PARSER_DECLARATOR_ABSTRACT)
+ /* APPLE LOCAL begin blocks 6339747 */
+ else if (first && (dcl_kind == CP_PARSER_DECLARATOR_NAMED
+ || dcl_kind == CP_PARSER_DECLARATOR_EITHER))
+ /* APPLE LOCAL end blocks 6339747 */
{
tree qualifying_scope;
tree unqualified_name;
@@ -11976,7 +12391,8 @@ cp_parser_direct_declarator (cp_parser* parser,
/* For an abstract declarator, we might wind up with nothing at this
point. That's an error; the declarator is not optional. */
- if (!declarator)
+ /* APPLE LOCAL blocks 6339747 */
+ if (!declarator && dcl_kind != CP_PARSER_DECLARATOR_BLOCK)
cp_parser_error (parser, "expected declarator");
/* If we entered a scope, we must exit it now. */
@@ -12000,6 +12416,8 @@ cp_parser_direct_declarator (cp_parser* parser,
ptr-operator:
& cv-qualifier-seq [opt]
+ APPLE LOCAL blocks 6040305 (cc)
+ ^
Returns INDIRECT_REF if a pointer, or pointer-to-member, was used.
Returns ADDR_EXPR if a reference was used. In the case of a
@@ -12782,7 +13200,8 @@ cp_parser_parameter_declaration (cp_parser *parser,
static void
cp_parser_function_body (cp_parser *parser)
{
- cp_parser_compound_statement (parser, NULL, false);
+ /* APPLE LOCAL radar 5982990 */
+ cp_parser_compound_statement (parser, NULL, false, false);
}
/* Parse a ctor-initializer-opt followed by a function-body. Return
@@ -14539,7 +14958,8 @@ cp_parser_try_block (cp_parser* parser)
cp_parser_require_keyword (parser, RID_TRY, "`try'");
try_block = begin_try_block ();
- cp_parser_compound_statement (parser, NULL, true);
+ /* APPLE LOCAL radar 5982990 */
+ cp_parser_compound_statement (parser, NULL, true, false);
finish_try_block (try_block);
cp_parser_handler_seq (parser);
finish_handler_sequence (try_block);
@@ -14616,7 +15036,8 @@ cp_parser_handler (cp_parser* parser)
declaration = cp_parser_exception_declaration (parser);
finish_handler_parms (declaration, handler);
cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
- cp_parser_compound_statement (parser, NULL, false);
+ /* APPLE LOCAL radar 5982990 */
+ cp_parser_compound_statement (parser, NULL, false, false);
finish_handler (handler);
}
@@ -15401,6 +15822,8 @@ cp_parser_check_declarator_template_parameters (cp_parser* parser,
case cdk_pointer:
case cdk_reference:
case cdk_ptrmem:
+ /* APPLE LOCAL blocks 6040305 */
+ case cdk_block_pointer:
return (cp_parser_check_declarator_template_parameters
(parser, declarator->declarator));
@@ -17109,6 +17532,25 @@ cp_parser_objc_message_expression (cp_parser* parser)
return objc_build_message_expr (build_tree_list (receiver, messageargs));
}
+/* APPLE LOCAL begin radar 5277239 */
+/* Parse an Objective-C dot-syntax class expression.
+
+ objc-message-expression:
+ class-name '.' class-method-name
+
+ Returns an objc_property_reference expression. */
+
+static tree
+cp_parser_objc_reference_expression (cp_parser* parser, tree type_decl)
+{
+ tree receiver, component;
+ receiver = objc_get_class_reference (TREE_TYPE (type_decl));
+ cp_lexer_consume_token (parser->lexer); /* Eact '.' */
+ component = cp_parser_objc_message_args (parser);
+ return objc_build_property_reference_expr (receiver, TREE_PURPOSE (component));
+}
+/* APPLE LOCAL end radar 5277239 */
+
/* Parse an objc-message-receiver.
objc-message-receiver:
@@ -17560,10 +18002,25 @@ cp_parser_objc_selector (cp_parser* parser)
}
}
+/* APPLE LOCAL begin radar 3803157 - objc attribute */
+static void
+cp_parser_objc_maybe_attributes (cp_parser* parser, tree* attributes)
+{
+ cp_token *token = cp_lexer_peek_token (parser->lexer);
+ if (*attributes != NULL_TREE)
+ {
+ error ("method attributes must be specified at the end only");
+ *attributes = NULL_TREE;
+ }
+ if (token->keyword == RID_ATTRIBUTE)
+ *attributes = cp_parser_attributes_opt (parser);
+}
+
/* Parse an Objective-C params list. */
static tree
-cp_parser_objc_method_keyword_params (cp_parser* parser)
+cp_parser_objc_method_keyword_params (cp_parser* parser, tree* attributes)
+/* APPLE LOCAL end radar 3803157 - objc attribute */
{
tree params = NULL_TREE;
bool maybe_unary_selector_p = true;
@@ -17572,36 +18029,58 @@ cp_parser_objc_method_keyword_params (cp_parser* parser)
while (cp_parser_objc_selector_p (token->type) || token->type == CPP_COLON)
{
tree selector = NULL_TREE, typename, identifier;
+ /* APPLE LOCAL radar 4157812 */
+ tree attr = NULL_TREE;
if (token->type != CPP_COLON)
selector = cp_parser_objc_selector (parser);
/* Detect if we have a unary selector. */
if (maybe_unary_selector_p
- && cp_lexer_next_token_is_not (parser->lexer, CPP_COLON))
- return selector;
+ && cp_lexer_next_token_is_not (parser->lexer, CPP_COLON))
+ /* APPLE LOCAL begin radar 3803157 - objc attribute */
+ {
+ cp_parser_objc_maybe_attributes (parser, attributes);
+ if (cp_lexer_next_token_is_not (parser->lexer, CPP_COLON))
+ return selector;
+ }
+ /* APPLE LOCAL end radar 3803157 - objc attribute */
maybe_unary_selector_p = false;
cp_parser_require (parser, CPP_COLON, "`:'");
typename = cp_parser_objc_typename (parser);
+ /* APPLE LOCAL radar 4157812 */
+ cp_parser_objc_maybe_attributes (parser, &attr);
identifier = cp_parser_identifier (parser);
+ /* APPLE LOCAL radar 3803157 - objc attribute */
+ cp_parser_objc_maybe_attributes (parser, attributes);
params
= chainon (params,
objc_build_keyword_decl (selector,
typename,
- identifier));
+ /* APPLE LOCAL radar 4157812 */
+ identifier, attr));
token = cp_lexer_peek_token (parser->lexer);
}
+ /* APPLE LOCAL begin radar 4290840 */
+ if (params == NULL_TREE)
+ {
+ cp_parser_error (parser, "objective-c++ method declaration is expected");
+ return error_mark_node;
+ }
+ /* APPLE LOCAL end radar 4290840 */
+
return params;
}
/* Parse the non-keyword Objective-C params. */
static tree
-cp_parser_objc_method_tail_params_opt (cp_parser* parser, bool *ellipsisp)
+/* APPLE LOCAL radar 3803157 - objc attribute */
+cp_parser_objc_method_tail_params_opt (cp_parser* parser, bool *ellipsisp, tree* attributes)
{
tree params = make_node (TREE_LIST);
cp_token *token = cp_lexer_peek_token (parser->lexer);
@@ -17616,11 +18095,13 @@ cp_parser_objc_method_tail_params_opt (cp_parser* parser, bool *ellipsisp)
token = cp_lexer_peek_token (parser->lexer);
if (token->type == CPP_ELLIPSIS)
- {
- cp_lexer_consume_token (parser->lexer); /* Eat '...'. */
- *ellipsisp = true;
- break;
- }
+ {
+ cp_lexer_consume_token (parser->lexer); /* Eat '...'. */
+ *ellipsisp = true;
+ /* APPLE LOCAL radar 3803157 - objc attribute */
+ cp_parser_objc_maybe_attributes (parser, attributes);
+ break;
+ }
parmdecl = cp_parser_parameter_declaration (parser, false, NULL);
parm = grokdeclarator (parmdecl->declarator,
@@ -17661,15 +18142,19 @@ cp_parser_objc_interstitial_code (cp_parser* parser)
/* Parse a method signature. */
static tree
-cp_parser_objc_method_signature (cp_parser* parser)
+/* APPLE LOCAL radar 3803157 - objc attribute */
+cp_parser_objc_method_signature (cp_parser* parser, tree* attributes)
{
tree rettype, kwdparms, optparms;
bool ellipsis = false;
cp_parser_objc_method_type (parser);
rettype = cp_parser_objc_typename (parser);
- kwdparms = cp_parser_objc_method_keyword_params (parser);
- optparms = cp_parser_objc_method_tail_params_opt (parser, &ellipsis);
+ /* APPLE LOCAL begin radar 3803157 - objc attribute */
+ *attributes = NULL_TREE;
+ kwdparms = cp_parser_objc_method_keyword_params (parser, attributes);
+ optparms = cp_parser_objc_method_tail_params_opt (parser, &ellipsis, attributes);
+ /* APPLE LOCAL end radar 3803157 - objc attribute */
return objc_build_method_signature (rettype, kwdparms, optparms, ellipsis);
}
@@ -17681,22 +18166,31 @@ cp_parser_objc_method_prototype_list (cp_parser* parser)
{
cp_token *token = cp_lexer_peek_token (parser->lexer);
- while (token->keyword != RID_AT_END)
+ /* APPLE LOCAL 4093475 */
+ while (token->keyword != RID_AT_END && token->type != CPP_EOF)
{
if (token->type == CPP_PLUS || token->type == CPP_MINUS)
- {
- objc_add_method_declaration
- (cp_parser_objc_method_signature (parser));
- cp_parser_consume_semicolon_at_end_of_statement (parser);
- }
+ {
+ /* APPLE LOCAL begin radar 3803157 - objc attribute */
+ tree attributes, sig;
+ sig = cp_parser_objc_method_signature (parser, &attributes);
+ objc_add_method_declaration (sig, attributes);
+ /* APPLE LOCAL end radar 3803157 - objc attribute */
+ cp_parser_consume_semicolon_at_end_of_statement (parser);
+ }
+ /* APPLE LOCAL begin C* interface */
+ else if (token->keyword == RID_AT_PROPERTY)
+ objc_cp_parser_at_property (parser);
+ /* APPLE LOCAL end C* interface */
else
- /* Allow for interspersed non-ObjC++ code. */
+ /* Allow for interspersed non-ObjC++ code. */
cp_parser_objc_interstitial_code (parser);
token = cp_lexer_peek_token (parser->lexer);
}
- cp_lexer_consume_token (parser->lexer); /* Eat '@end'. */
+ /* APPLE LOCAL 4093475 */
+ cp_parser_require_keyword (parser, RID_AT_END, "`@end'");
objc_finish_interface ();
}
@@ -17707,27 +18201,49 @@ cp_parser_objc_method_definition_list (cp_parser* parser)
{
cp_token *token = cp_lexer_peek_token (parser->lexer);
- while (token->keyword != RID_AT_END)
+ /* APPLE LOCAL 4093475 */
+ while (token->keyword != RID_AT_END && token->type != CPP_EOF)
{
tree meth;
if (token->type == CPP_PLUS || token->type == CPP_MINUS)
- {
- push_deferring_access_checks (dk_deferred);
- objc_start_method_definition
- (cp_parser_objc_method_signature (parser));
+ {
+ /* APPLE LOCAL radar 4290840 */
+ cp_token *ptk;
+ /* APPLE LOCAL begin radar 3803157 - objc attribute */
+ tree sig, attribute;
+ push_deferring_access_checks (dk_deferred);
+ sig = cp_parser_objc_method_signature (parser, &attribute);
+ objc_start_method_definition (sig, attribute);
+ /* APPLE LOCAL end radar 3803157 - objc attribute */
/* For historical reasons, we accept an optional semicolon. */
if (cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON))
cp_lexer_consume_token (parser->lexer);
- perform_deferred_access_checks ();
- stop_deferring_access_checks ();
- meth = cp_parser_function_definition_after_declarator (parser,
- false);
- pop_deferring_access_checks ();
- objc_finish_method_definition (meth);
+ /* APPLE LOCAL begin radar 4290840 */
+ /* Check for all possibilities of illegal lookahead tokens. */
+ ptk = cp_lexer_peek_token (parser->lexer);
+ /* APPLE LOCAL radar 6271728 */
+ if (ptk->type == CPP_OPEN_BRACE)
+ {
+ perform_deferred_access_checks ();
+ stop_deferring_access_checks ();
+ meth = cp_parser_function_definition_after_declarator (parser,
+ false);
+ pop_deferring_access_checks ();
+ objc_finish_method_definition (meth);
}
+ /* APPLE LOCAL begin radar 6271728 */
+ else
+ cp_parser_require (parser, CPP_OPEN_BRACE, "`{'");
+ /* APPLE LOCAL end radar 6271728 */
+ /* APPLE LOCAL end radar 4290840 */
+ }
+ /* APPLE LOCAL begin C* interface */
+ else if (token->keyword == RID_AT_PROPERTY)
+ objc_cp_parser_at_property (parser);
+ /* APPLE LOCAL end C* interface */
else
/* Allow for interspersed non-ObjC++ code. */
cp_parser_objc_interstitial_code (parser);
@@ -17735,7 +18251,8 @@ cp_parser_objc_method_definition_list (cp_parser* parser)
token = cp_lexer_peek_token (parser->lexer);
}
- cp_lexer_consume_token (parser->lexer); /* Eat '@end'. */
+ /* APPLE LOCAL 4093475 */
+ cp_parser_require_keyword (parser, RID_AT_END, "`@end'");
objc_finish_implementation ();
}
@@ -17861,7 +18378,8 @@ cp_parser_objc_class_ivars (cp_parser* parser)
/* Parse an Objective-C protocol declaration. */
static void
-cp_parser_objc_protocol_declaration (cp_parser* parser)
+/* APPLE LOCAL radar 4947311 */
+cp_parser_objc_protocol_declaration (cp_parser* parser, tree attributes)
{
tree proto, protorefs;
cp_token *tok;
@@ -17879,8 +18397,9 @@ cp_parser_objc_protocol_declaration (cp_parser* parser)
/* Try a forward declaration first. */
if (tok->type == CPP_COMMA || tok->type == CPP_SEMICOLON)
{
- objc_declare_protocols (cp_parser_objc_identifier_list (parser));
- finish:
+ /* APPLE LOCAL radar 4947311 */
+ objc_declare_protocols (cp_parser_objc_identifier_list (parser), attributes);
+ finish:
cp_parser_consume_semicolon_at_end_of_statement (parser);
}
@@ -17889,20 +18408,23 @@ cp_parser_objc_protocol_declaration (cp_parser* parser)
{
proto = cp_parser_identifier (parser);
protorefs = cp_parser_objc_protocol_refs_opt (parser);
- objc_start_protocol (proto, protorefs);
+ /* APPLE LOCAL radar 4947311 */
+ objc_start_protocol (proto, protorefs, attributes);
cp_parser_objc_method_prototype_list (parser);
}
}
/* Parse an Objective-C superclass or category. */
+/* APPLE LOCAL begin radar 4965989 */
static void
cp_parser_objc_superclass_or_category (cp_parser *parser, tree *super,
- tree *categ)
+ tree *categ, bool *is_category)
{
cp_token *next = cp_lexer_peek_token (parser->lexer);
*super = *categ = NULL_TREE;
+ *is_category = false;
if (next->type == CPP_COLON)
{
cp_lexer_consume_token (parser->lexer); /* Eat ':'. */
@@ -17911,29 +18433,47 @@ cp_parser_objc_superclass_or_category (cp_parser *parser, tree *super,
else if (next->type == CPP_OPEN_PAREN)
{
cp_lexer_consume_token (parser->lexer); /* Eat '('. */
- *categ = cp_parser_identifier (parser);
+ /* APPLE LOCAL begin radar 4965989 */
+ next = cp_lexer_peek_token (parser->lexer);
+ *categ = (next->type == CPP_CLOSE_PAREN) ? NULL_TREE : cp_parser_identifier (parser);
+ *is_category = true;
+ /* APPLE LOCAL end radar 4965989 */
cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
}
}
+/* APPLE LOCAL end radar 4965989 */
/* Parse an Objective-C class interface. */
static void
-cp_parser_objc_class_interface (cp_parser* parser)
+/* APPLE LOCAL radar 4947311 */
+cp_parser_objc_class_interface (cp_parser* parser, tree attributes)
{
tree name, super, categ, protos;
-
+ /* APPLE LOCAL radar 4965989 */
+ bool is_categ;
+ /* APPLE LOCAL radar 4947311 */
+ /* Code for radar 4548636 removed. */
cp_lexer_consume_token (parser->lexer); /* Eat '@interface'. */
name = cp_parser_identifier (parser);
- cp_parser_objc_superclass_or_category (parser, &super, &categ);
+ /* APPLE LOCAL radar 4965989 */
+ cp_parser_objc_superclass_or_category (parser, &super, &categ, &is_categ);
protos = cp_parser_objc_protocol_refs_opt (parser);
-
+
/* We have either a class or a category on our hands. */
- if (categ)
- objc_start_category_interface (name, categ, protos);
+ /* APPLE LOCAL radar 4965989 */
+ if (is_categ)
+ /* APPLE LOCAL begin radar 4548636 */
+ {
+ if (attributes)
+ error ("attributes may not be specified on a category");
+ objc_start_category_interface (name, categ, protos);
+ }
+ /* APPLE LOCAL end radar 4548636 */
else
{
- objc_start_class_interface (name, super, protos);
+ /* APPLE LOCAL radar 4548636 */
+ objc_start_class_interface (name, super, protos, attributes);
/* Handle instance variable declarations, if any. */
cp_parser_objc_class_ivars (parser);
objc_continue_interface ();
@@ -17948,14 +18488,25 @@ static void
cp_parser_objc_class_implementation (cp_parser* parser)
{
tree name, super, categ;
-
+ /* APPLE LOCAL radar 4965989 */
+ bool is_categ;
cp_lexer_consume_token (parser->lexer); /* Eat '@implementation'. */
name = cp_parser_identifier (parser);
- cp_parser_objc_superclass_or_category (parser, &super, &categ);
+ /* APPLE LOCAL radar 4965989 */
+ cp_parser_objc_superclass_or_category (parser, &super, &categ, &is_categ);
/* We have either a class or a category on our hands. */
- if (categ)
- objc_start_category_implementation (name, categ);
+ /* APPLE LOCAL begin radar 4965989 */
+ if (is_categ)
+ {
+ if (categ == NULL_TREE)
+ {
+ error ("cannot implement anonymous category");
+ return;
+ }
+ objc_start_category_implementation (name, categ);
+ }
+ /* APPLE LOCAL end radar 4965989 */
else
{
objc_start_class_implementation (name, super);
@@ -17993,10 +18544,24 @@ cp_parser_objc_declaration (cp_parser* parser)
cp_parser_objc_class_declaration (parser);
break;
case RID_AT_PROTOCOL:
- cp_parser_objc_protocol_declaration (parser);
+ /* APPLE LOCAL radar 4947311 */
+ cp_parser_objc_protocol_declaration (parser, NULL_TREE);
break;
+ /* APPLE LOCAL begin radar 4548636 - radar 4947311 */
+ case RID_ATTRIBUTE:
+ {
+ tree attributes = NULL_TREE;
+ cp_parser_objc_maybe_attributes (parser, &attributes);
+ if (cp_lexer_peek_token (parser->lexer)->keyword == RID_AT_INTERFACE)
+ cp_parser_objc_class_interface (parser, attributes);
+ else if (cp_lexer_peek_token (parser->lexer)->keyword == RID_AT_PROTOCOL)
+ cp_parser_objc_protocol_declaration (parser, attributes);
+ break;
+ }
+ /* APPLE LOCAL end radar 4548636 - radar 4947311 */
case RID_AT_INTERFACE:
- cp_parser_objc_class_interface (parser);
+ /* APPLE LOCAL radar 4947311 */
+ cp_parser_objc_class_interface (parser, NULL_TREE);
break;
case RID_AT_IMPLEMENTATION:
cp_parser_objc_class_implementation (parser);
@@ -18037,7 +18602,8 @@ cp_parser_objc_try_catch_finally_statement (cp_parser *parser) {
/* NB: The @try block needs to be wrapped in its own STATEMENT_LIST
node, lest it get absorbed into the surrounding block. */
stmt = push_stmt_list ();
- cp_parser_compound_statement (parser, NULL, false);
+ /* APPLE LOCAL radar 5982990 */
+ cp_parser_compound_statement (parser, NULL, false, false);
objc_begin_try_stmt (location, pop_stmt_list (stmt));
while (cp_lexer_next_token_is_keyword (parser->lexer, RID_AT_CATCH))
@@ -18047,14 +18613,10 @@ cp_parser_objc_try_catch_finally_statement (cp_parser *parser) {
cp_lexer_consume_token (parser->lexer);
cp_parser_require (parser, CPP_OPEN_PAREN, "`('");
- parmdecl = cp_parser_parameter_declaration (parser, false, NULL);
- parm = grokdeclarator (parmdecl->declarator,
- &parmdecl->decl_specifiers,
- PARM, /*initialized=*/0,
- /*attrlist=*/NULL);
cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
objc_begin_catch_clause (parm);
- cp_parser_compound_statement (parser, NULL, false);
+ /* APPLE LOCAL radar 5982990 */
+ cp_parser_compound_statement (parser, NULL, false, false);
objc_finish_catch_clause ();
}
@@ -18065,7 +18627,8 @@ cp_parser_objc_try_catch_finally_statement (cp_parser *parser) {
/* NB: The @finally block needs to be wrapped in its own STATEMENT_LIST
node, lest it get absorbed into the surrounding block. */
stmt = push_stmt_list ();
- cp_parser_compound_statement (parser, NULL, false);
+ /* APPLE LOCAL radar 5982990 */
+ cp_parser_compound_statement (parser, NULL, false, false);
objc_build_finally_clause (location, pop_stmt_list (stmt));
}
@@ -18094,7 +18657,8 @@ cp_parser_objc_synchronized_statement (cp_parser *parser) {
/* NB: The @synchronized block needs to be wrapped in its own STATEMENT_LIST
node, lest it get absorbed into the surrounding block. */
stmt = push_stmt_list ();
- cp_parser_compound_statement (parser, NULL, false);
+ /* APPLE LOCAL radar 5982990 */
+ cp_parser_compound_statement (parser, NULL, false, flag_objc_sjlj_exceptions);
return objc_build_synchronized (location, lock, pop_stmt_list (stmt));
}
@@ -18142,7 +18706,1735 @@ cp_parser_objc_statement (cp_parser * parser) {
return error_mark_node;
}
-
+
+/* APPLE LOCAL begin C* language */
+/* Routine closes up the C*'s foreach statement.
+*/
+
+static void
+objc_finish_foreach_stmt (tree for_stmt)
+{
+ if (flag_new_for_scope > 0)
+ {
+ tree scope = TREE_CHAIN (for_stmt);
+ TREE_CHAIN (for_stmt) = NULL;
+ add_stmt (do_poplevel (scope));
+ }
+
+ finish_stmt ();
+}
+
+/*
+ Synthesizer routine for C*'s feareach statement.
+
+ It synthesizes:
+ for ( type elem in collection) { stmts; }
+
+ Into:
+ {
+ type elem;
+ __objcFastEnumerationState enumState = { 0 };
+ id items[16];
+
+ unsigned long limit = [collection countByEnumeratingWithState:&enumState objects:items count:16];
+ if (limit) {
+ unsigned long startMutations = *enumState.mutationsPtr;
+ do {
+ unsigned long counter = 0;
+ do {
+ if (startMutations != *enumState.mutationsPtr) objc_enumerationMutation(collection);
+ elem = enumState.itemsPtr[counter++];
+ stmts;
+ } while (counter < limit);
+ } while (limit = [collection countByEnumeratingWithState:&enumState objects:items count:16]);
+ }
+ else
+ elem = nil; radar 4854605, 5128402
+
+*/
+
+static void
+objc_foreach_stmt (cp_parser* parser, tree statement)
+{
+ unsigned char in_statement;
+ tree enumerationMutation_call_exp;
+ tree countByEnumeratingWithState;
+ tree receiver;
+ tree exp, bind;
+ tree enumState_decl, items_decl;
+ tree limit_decl, limit_decl_assign_expr;
+ tree outer_if_stmt, inner_if_stmt, if_condition, startMutations_decl;
+ tree outer_do_stmt, inner_do_stmt, do_condition;
+ tree counter_decl;
+ tree_stmt_iterator i = tsi_start (TREE_CHAIN (statement));
+ tree t = tsi_stmt (i);
+ /* APPLE LOCAL radar 5130983 */
+ tree elem_decl = TREE_CODE (t) == DECL_EXPR ? DECL_EXPR_DECL (t) : t;
+
+ receiver = cp_parser_condition (parser);
+ cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
+
+ /* APPLE LOCAL begin radar 4507230 */
+ if (!objc_type_valid_for_messaging (TREE_TYPE (elem_decl)))
+ {
+ error ("selector element does not have a valid object type");
+ return;
+ }
+
+ if (!objc_type_valid_for_messaging (TREE_TYPE (receiver)))
+ {
+ error ("expression does not have a valid object type");
+ return;
+ }
+ /* APPLE LOCAL end radar 4507230 */
+
+ enumerationMutation_call_exp = objc_build_foreach_components (receiver, &enumState_decl,
+ &items_decl, &limit_decl,
+ &startMutations_decl, &counter_decl,
+ &countByEnumeratingWithState);
+
+ /* __objcFastEnumerationState enumState = { 0 }; */
+ exp = build_stmt (DECL_EXPR, enumState_decl);
+ bind = build3 (BIND_EXPR, void_type_node, enumState_decl, exp, NULL);
+ TREE_SIDE_EFFECTS (bind) = 1;
+ add_stmt (bind);
+
+ /* id items[16]; */
+ bind = build3 (BIND_EXPR, void_type_node, items_decl, NULL, NULL);
+ TREE_SIDE_EFFECTS (bind) = 1;
+ add_stmt (bind);
+
+ /* Generate this statement and add it to the list. */
+ /* limit = [collection countByEnumeratingWithState:&enumState objects:items count:16] */
+ limit_decl_assign_expr = build2 (MODIFY_EXPR, TREE_TYPE (limit_decl), limit_decl,
+ countByEnumeratingWithState);
+ bind = build3 (BIND_EXPR, void_type_node, limit_decl, NULL, NULL);
+ TREE_SIDE_EFFECTS (bind) = 1;
+ add_stmt (bind);
+
+ /* if (limit) { */
+ outer_if_stmt = begin_if_stmt ();
+ /* APPLE LOCAL radar 4547045 */
+ if_condition = build_binary_op (NE_EXPR, limit_decl_assign_expr,
+ fold_convert (TREE_TYPE (limit_decl), integer_zero_node),
+ 1);
+
+ finish_if_stmt_cond (if_condition, outer_if_stmt);
+
+ /* unsigned long startMutations = *enumState.mutationsPtr; */
+ exp = objc_build_component_ref (enumState_decl, get_identifier("mutationsPtr"));
+ exp = build_indirect_ref (exp, "unary *");
+ exp = build2 (MODIFY_EXPR, void_type_node, startMutations_decl, exp);
+ bind = build3 (BIND_EXPR, void_type_node, startMutations_decl, exp, NULL);
+ TREE_SIDE_EFFECTS (bind) = 1;
+ add_stmt (bind);
+
+ /* do { */
+/* APPLE LOCAL begin for-fsf-4_4 3274130 5295549 */ \
+ outer_do_stmt = begin_do_stmt (NULL_TREE);
+
+/* APPLE LOCAL end for-fsf-4_4 3274130 5295549 */ \
+ /* Body of the outer do-while loop */
+ /* unsigned int counter = 0; */
+ exp = build2 (MODIFY_EXPR, void_type_node, counter_decl,
+ fold_convert (TREE_TYPE (counter_decl), integer_zero_node));
+ bind = build3 (BIND_EXPR, void_type_node, counter_decl, exp, NULL);
+ TREE_SIDE_EFFECTS (bind) = 1;
+ add_stmt (bind);
+
+ /* do { */
+/* APPLE LOCAL begin for-fsf-4_4 3274130 5295549 */ \
+ inner_do_stmt = begin_do_stmt (NULL_TREE);
+
+/* APPLE LOCAL end for-fsf-4_4 3274130 5295549 */ \
+ /* Body of the inner do-while loop */
+
+ /* if (startMutations != *enumState.mutationsPtr) objc_enumerationMutation (collection); */
+ inner_if_stmt = begin_if_stmt ();
+ exp = objc_build_component_ref (enumState_decl, get_identifier("mutationsPtr"));
+ exp = build_indirect_ref (exp, "unary *");
+ if_condition = build_binary_op (NE_EXPR, startMutations_decl, exp, 1);
+ finish_if_stmt_cond (if_condition, inner_if_stmt);
+
+ add_stmt (enumerationMutation_call_exp);
+ finish_then_clause (inner_if_stmt);
+ finish_if_stmt (inner_if_stmt);
+
+ /* elem = enumState.itemsPtr [counter]; */
+ exp = objc_build_component_ref (enumState_decl, get_identifier("itemsPtr"));
+ exp = build_array_ref (exp, counter_decl);
+ add_stmt (build2 (MODIFY_EXPR, void_type_node, elem_decl, exp));
+ /* APPLE LOCAL radar 4538105 */
+ TREE_USED (elem_decl) = 1;
+
+ /* counter++; */
+ exp = build2 (PLUS_EXPR, TREE_TYPE (counter_decl), counter_decl,
+ build_int_cst (NULL_TREE, 1));
+ add_stmt (build2 (MODIFY_EXPR, void_type_node, counter_decl, exp));
+
+ /* ADD << stmts >> from the foreach loop. */
+ /* Parse the body of the for-statement. */
+ in_statement = parser->in_statement;
+ parser->in_statement = IN_ITERATION_STMT;
+ cp_parser_already_scoped_statement (parser);
+ parser->in_statement = in_statement;
+
+ finish_do_body (inner_do_stmt);
+
+ /* } while (counter < limit ); */
+ do_condition = build_binary_op (LT_EXPR, counter_decl, limit_decl, 1);
+ finish_do_stmt (do_condition, inner_do_stmt);
+ DO_FOREACH (inner_do_stmt) = integer_zero_node;
+ /* APPLE LOCAL radar 4667060 */
+ DO_FOREACH (outer_do_stmt) = elem_decl;
+
+ finish_do_body (outer_do_stmt);
+
+ /* } while (limit = [collection countByEnumeratingWithState:&enumState objects:items count:16]); */
+
+ exp = unshare_expr (limit_decl_assign_expr);
+ do_condition = build_binary_op (NE_EXPR, exp,
+ fold_convert (TREE_TYPE (limit_decl), integer_zero_node),
+ 1);
+ finish_do_stmt (do_condition, outer_do_stmt);
+
+
+ finish_then_clause (outer_if_stmt);
+
+ /* } */
+ /* APPLE LOCAL begin radar 4854605 - radar 5128402 */
+ begin_else_clause (outer_if_stmt);
+ add_stmt (build2 (MODIFY_EXPR, void_type_node, elem_decl,
+ fold_convert (TREE_TYPE (elem_decl), integer_zero_node)));
+ finish_else_clause (outer_if_stmt);
+ /* APPLE LOCAL end radar 4854605 - radar 5128402 */
+
+ finish_if_stmt (outer_if_stmt);
+
+ objc_finish_foreach_stmt (statement);
+}
+/* APPLE LOCAL end C* language */
+/* APPLE LOCAL begin blocks 6040305 (ce) */
+#define I_SYMBOL_BINDING(t) IDENTIFIER_BINDING(t)
+
+tree build_component_ref (tree e, tree member);
+tree
+build_component_ref (tree e, tree member)
+{
+ if (!DECL_P (member))
+ member = lookup_member (TREE_TYPE (e), member, 0, 0);
+ if (processing_template_decl)
+ return build3 (COMPONENT_REF, TREE_TYPE (member), e, DECL_NAME (member), NULL_TREE);
+ return build_class_member_access_expr (e, member,
+ NULL_TREE, false);
+}
+
+/* APPLE LOCAL begin radar 6214617 */
+static bool
+cp_block_requires_copying (tree exp)
+{
+ return (block_requires_copying (exp)
+ || TYPE_HAS_CONSTRUCTOR (TREE_TYPE (exp))
+ || TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (exp)));
+}
+/* APPLE LOCAL end radar 6214617 */
+
+/* APPLE LOCAL begin radar 5847213 - radar 6329245 */
+/** build_descriptor_block_decl -
+ This routine builds a static block_descriptior variable of type:
+ struct __block_descriptor; and initializes it to:
+ {0, sizeof(struct literal_block_n),
+ copy_helper_block_1, // only if block BLOCK_HAS_COPY_DISPOSE
+ destroy_helper_block_1, // only if block BLOCK_HAS_COPY_DISPOSE
+ }
+ */
+static tree
+build_descriptor_block_decl (tree block_struct_type, struct block_sema_info *block_impl)
+{
+ extern tree create_tmp_var_raw (tree, const char *);
+ static int desc_unique_count;
+ int size;
+ tree helper_addr;
+ tree decl, constructor;
+ char name [32];
+ VEC(constructor_elt,gc) *impl_v = NULL;
+ tree descriptor_type =
+ TREE_TYPE (build_block_descriptor_type (block_impl->BlockHasCopyDispose));
+
+ sprintf (name, "__block_descriptor_tmp_%d", ++desc_unique_count);
+ decl = create_tmp_var_raw (descriptor_type, name);
+ DECL_CONTEXT (decl) = NULL_TREE;
+
+ /* Initialize "reserved" field to 0 for now. */
+ CONSTRUCTOR_APPEND_ELT(impl_v, NULL_TREE, build_int_cst (long_unsigned_type_node, 0));
+
+ /* Initialize "Size" field. */
+ size = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (block_struct_type));
+ CONSTRUCTOR_APPEND_ELT(impl_v, NULL_TREE, build_int_cst (long_unsigned_type_node, size));
+
+ if (block_impl->BlockHasCopyDispose)
+ {
+ /* Initialize "CopyFuncPtr" and "DestroyFuncPtr" fields. */
+ /* Helpers were previously generated completeley as a nested
+ function (and context was required for code gen.) But they are not,
+ so context must be set to NULL so initialization logic does not complain. */
+ DECL_CONTEXT (block_impl->copy_helper_func_decl) = NULL_TREE;
+ helper_addr = build_fold_addr_expr (block_impl->copy_helper_func_decl);
+ helper_addr = convert (ptr_type_node, helper_addr);
+ CONSTRUCTOR_APPEND_ELT(impl_v, NULL_TREE, helper_addr);
+
+ DECL_CONTEXT (block_impl->destroy_helper_func_decl) = NULL_TREE;
+ helper_addr = build_fold_addr_expr (block_impl->destroy_helper_func_decl);
+ helper_addr = convert (ptr_type_node, helper_addr);
+ CONSTRUCTOR_APPEND_ELT(impl_v, NULL_TREE, helper_addr);
+ }
+ /* Create a CONSTRUCTOR to represent the braced-initializer. */
+ constructor = make_node (CONSTRUCTOR);
+ CONSTRUCTOR_ELTS (constructor) = impl_v;
+ TREE_PUBLIC (decl) = 0;
+ TREE_STATIC (decl) = 1;
+ cp_finish_decl (decl, constructor, 0, 0, LOOKUP_ONLYCONVERTING);
+ return decl;
+}
+
+/* APPLE LOCAL begin radar 6300081 */
+/* This function builds a "generic" block struct type, to be passed
+ into the debug information for blocks pointers, to allow gdb to
+ find the actual function pointer for the block. Any time the Blocks
+ structure layout changes, this may also need to change.
+
+ Currently a block pointer is a pointer to a __block_literal_n struct,
+ the third field of which is a pointer to a __block_descriptor struct,
+ whose third field is the function pointer. There are other fields as
+ well, but these are the ones gdb needs to know about to find the
+ function pointer. Therefore a generic block struct currently looks
+ like this:
+
+ struct __block_literal_generic
+ {
+ void * __isa;
+ int __flags;
+ int __reserved;
+ void *__FuncPtr;
+ struct __block_descriptor
+ {
+ unsigned long int reserved;
+ unsigned long int Size;
+ } *__descriptor;
+ };
+
+ IF AT ANY TIME THE STRUCTURE OF A __BLOCK_LITERAL_N CHANGES, THIS
+ MUST BE CHANGED ALSO!!
+
+ */
+
+tree
+/* APPLE LOCAL radar 6353006 */
+c_build_generic_block_struct_type (void)
+{
+ tree fields = NULL_TREE;
+ tree field;
+ tree block_struct_type;
+
+ push_to_top_level ();
+ block_struct_type = xref_tag (record_type,
+ get_identifier ("__block_literal_generic"),
+ ts_current, false);
+ xref_basetypes (block_struct_type, NULL_TREE);
+ CLASSTYPE_DECLARED_CLASS (block_struct_type) = 0;
+ pushclass (block_struct_type);
+
+ field = build_decl (FIELD_DECL, get_identifier ("__isa"), ptr_type_node);
+ TREE_CHAIN (field) = fields;
+ fields = field;
+
+ field = build_decl (FIELD_DECL, get_identifier ("__flags"),
+ integer_type_node);
+ TREE_CHAIN (field) = fields;
+ fields = field;
+
+ field = build_decl (FIELD_DECL, get_identifier ("__reserved"),
+ integer_type_node);
+ TREE_CHAIN (field) = fields;
+ fields = field;
+
+ field = build_decl (FIELD_DECL, get_identifier ("__FuncPtr"),
+ ptr_type_node);
+ TREE_CHAIN (field) = fields;
+ fields = field;
+
+ field = build_decl (FIELD_DECL, get_identifier ("__descriptor"),
+ build_block_descriptor_type (false));
+ TREE_CHAIN (field) = fields;
+ fields = field;
+
+ TYPE_FIELDS (block_struct_type) = fields;
+ TYPE_NAME (block_struct_type) = build_decl (TYPE_DECL,
+ get_identifier ("__block_literal_generic"),
+ block_struct_type);
+ TYPE_STUB_DECL (block_struct_type) = TYPE_NAME (block_struct_type);
+ TYPE_BLOCK_IMPL_STRUCT (block_struct_type) = 1;
+ finish_struct (block_struct_type, NULL_TREE);
+ pop_from_top_level ();
+
+ return block_struct_type;
+}
+/* APPLE LOCAL end radar 6300081 */
+
+/** build_block_struct_type -
+ struct __block_literal_n {
+ void *__isa; // initialized to &_NSConcreteStackBlock or &_NSConcreteGlobalBlock
+ int __flags;
+ int __reserved;
+ void *__FuncPtr;
+
+ struct __block_descriptor {
+ unsigned long int reserved; // NULL
+ unsigned long int Size; // sizeof(struct __block_literal_n)
+
+ // optional helper functions
+ void *CopyFuncPtr; // When BLOCK_HAS_COPY_DISPOSE
+ void *DestroyFuncPtr; // When BLOCK_HAS_COPY_DISPOSE
+ } *__descriptor;
+
+ // imported variables
+ int x; // ref variable list ...
+ int *y; // byref variable list
+ };
+ */
+static tree
+build_block_struct_type (struct block_sema_info * block_impl)
+{
+ tree fields = NULL_TREE, field, chain;
+ char buffer[32];
+ static int unique_count;
+ tree block_struct_type;
+
+ /* Check and see if this block is required to have a Copy/Dispose
+ helper function. If yes, set BlockHasCopyDispose to TRUE. */
+ for (chain = block_impl->block_ref_decl_list; chain;
+ chain = TREE_CHAIN (chain))
+ /* APPLE LOCAL begin radar 6214617 */
+ if (cp_block_requires_copying (TREE_VALUE (chain)))
+ {
+ tree type = TREE_TYPE (TREE_VALUE (chain));
+ block_impl->BlockHasCopyDispose = TRUE;
+ if (TYPE_HAS_CONSTRUCTOR (type) || TYPE_NEEDS_CONSTRUCTING (type))
+ {
+ block_impl->BlockImportsCxxObjects = TRUE;
+ break;
+ }
+ /* APPLE LOCAL end radar 6214617 */
+ }
+
+ /* Further check to see that we have __block variables which require
+ Copy/Dispose helpers. */
+ for (chain = block_impl->block_byref_decl_list; chain;
+ chain = TREE_CHAIN (chain))
+ if (COPYABLE_BYREF_LOCAL_VAR (TREE_VALUE (chain)))
+ {
+ block_impl->BlockHasCopyDispose = TRUE;
+ break;
+ }
+
+ sprintf(buffer, "__block_literal_%d", ++unique_count);
+ push_to_top_level ();
+ /* APPLE LOCAL begin radar 6243400 */
+ block_struct_type = xref_tag (record_type, get_identifier (buffer), ts_current, false);
+ xref_basetypes (block_struct_type, NULL_TREE);
+ CLASSTYPE_DECLARED_CLASS (block_struct_type) = 0;
+ pushclass (block_struct_type);
+ /* APPLE LOCAL end radar 6243400 */
+ /* void * __isa; */
+ field = build_decl (FIELD_DECL, get_identifier ("__isa"), ptr_type_node);
+ TREE_CHAIN (field) = fields;
+ fields = field;
+
+ /* int __flags. */
+ field = build_decl (FIELD_DECL, get_identifier ("__flags"), integer_type_node);
+ TREE_CHAIN (field) = fields;
+ fields = field;
+
+ /* int __reserved. */
+ field = build_decl (FIELD_DECL, get_identifier ("__reserved"), integer_type_node);
+ TREE_CHAIN (field) = fields;
+ fields = field;
+
+ /* void *__FuncPtr. */
+ field = build_decl (FIELD_DECL, get_identifier ("__FuncPtr"),
+ ptr_type_node);
+ TREE_CHAIN (field) = fields;
+ fields = field;
+
+ /* struct __block_descriptor *__descriptor */
+ field = build_decl (FIELD_DECL, get_identifier ("__descriptor"),
+ build_block_descriptor_type (block_impl->BlockHasCopyDispose));
+ TREE_CHAIN (field) = fields;
+ fields = field;
+
+ if (block_impl->BlockHasCopyDispose)
+ {
+ /* If inner block of a nested block has BlockHasCopyDispose, so
+ does its outer block. */
+ if (block_impl->prev_block_info)
+ block_impl->prev_block_info->BlockHasCopyDispose = TRUE;
+ }
+
+ /* int x; // ref variable list ... */
+ for (chain = block_impl->block_ref_decl_list; chain; chain = TREE_CHAIN (chain))
+ {
+ tree p = TREE_VALUE (chain);
+ /* Note! const-ness of copied in variable must not be carried over to the
+ type of the synthesized struct field. It prevents to assign to this
+ field when copy constructor is synthesized. */
+ field = build_decl (FIELD_DECL, DECL_NAME (p),
+ c_build_qualified_type (TREE_TYPE (p),
+ TYPE_UNQUALIFIED));
+ TREE_CHAIN (field) = fields;
+ fields = field;
+ }
+
+ /* int *y; // byref variable list */
+ for (chain = block_impl->block_byref_decl_list; chain; chain = TREE_CHAIN (chain))
+ {
+ tree p = TREE_VALUE (chain);
+ field = build_decl (FIELD_DECL, DECL_NAME (p),
+ TREE_TYPE (p));
+ TREE_CHAIN (field) = fields;
+ fields = field;
+ }
+
+ /* APPLE LOCAL begin radar 6243400 */
+ TYPE_FIELDS (block_struct_type) = fields;
+ TYPE_NAME (block_struct_type) =
+ build_decl (TYPE_DECL, get_identifier (buffer), block_struct_type);
+ TYPE_STUB_DECL (block_struct_type) = TYPE_NAME (block_struct_type);
+ finish_struct (block_struct_type, NULL_TREE);
+ pop_from_top_level ();
+ /* APPLE LOCAL end radar 6243400 */
+ return block_struct_type;
+}
+
+/**
+ build_block_struct_initlist - builds the initializer list:
+ { &_NSConcreteStackBlock or &_NSConcreteGlobalBlock // __isa,
+ BLOCK_USE_STRET | BLOCK_HAS_COPY_DISPOSE | BLOCK_IS_GLOBAL // __flags,
+ 0, // __reserved,
+ &helper_1, // __FuncPtr,
+ &static_descriptor_variable // __descriptor,
+ x, // user variables.
+ &y
+ ...
+ }
+*/
+/* APPLE LOCAL begin radar 6169527 */
+/* This routine is entirely rewritten as we now have to deal with full-blown
+ c++ classes with fields which may require construction. */
+static VEC(constructor_elt,gc) *
+build_block_struct_initlist (tree block_struct_type,
+ struct block_sema_info *block_impl)
+{
+ tree expr, chain, helper_addr;
+ /* APPLE LOCAL radar 7735196 */
+ unsigned flags = 0;
+ static tree NSConcreteStackBlock_decl = NULL_TREE;
+ static tree NSConcreteGlobalBlock_decl = NULL_TREE;
+ VEC(constructor_elt,gc) *impl_v = NULL;
+ tree descriptor_block_decl = build_descriptor_block_decl (block_struct_type, block_impl);
+
+ if (block_impl->BlockHasCopyDispose)
+ /* Note! setting of this flag merely indicates to the runtime that
+ we have destroy_helper_block/copy_helper_block helper
+ routines. */
+ flags |= BLOCK_HAS_COPY_DISPOSE;
+ /* APPLE LOCAL begin radar 6214617 */
+ /* Set BLOCK_HAS_CXX_OBJ if block is importing a cxx object. */
+ if (block_impl->BlockImportsCxxObjects)
+ flags |= BLOCK_HAS_CXX_OBJ;
+ /* APPLE LOCAL end radar 6214617 */
+/* APPLE LOCAL begin radar 7735196 */
+ if (block_impl->return_type && aggregate_value_p(block_impl->return_type, 0))
+ flags |= BLOCK_USE_STRET;
+ /* APPLE LOCAL end 7735196 */
+ /* APPLE LOCAL begin radar 6230297 */
+ if (!current_function_decl ||
+ (block_impl->block_ref_decl_list == NULL_TREE &&
+ block_impl->block_byref_decl_list == NULL_TREE))
+ /* APPLE LOCAL end radar 6230297 */
+ {
+ /* This is a global block. */
+ /* Find an existing declaration for _NSConcreteGlobalBlock or declare
+ extern void *_NSConcreteGlobalBlock; */
+ if (NSConcreteGlobalBlock_decl == NULL_TREE)
+ {
+ tree name_id = get_identifier("_NSConcreteGlobalBlock");
+ NSConcreteGlobalBlock_decl = lookup_name (name_id);
+ if (!NSConcreteGlobalBlock_decl)
+ {
+ NSConcreteGlobalBlock_decl = build_decl (VAR_DECL, name_id, ptr_type_node);
+ DECL_EXTERNAL (NSConcreteGlobalBlock_decl) = 1;
+ TREE_PUBLIC (NSConcreteGlobalBlock_decl) = 1;
+ pushdecl_top_level (NSConcreteGlobalBlock_decl);
+ rest_of_decl_compilation (NSConcreteGlobalBlock_decl, 0, 0);
+ }
+ }
+ /* APPLE LOCAL begin radar 6457359 */
+ CONSTRUCTOR_APPEND_ELT(impl_v, NULL_TREE,
+ convert (ptr_type_node,
+ build_fold_addr_expr (NSConcreteGlobalBlock_decl)));
+ /* APPLE LOCAL end radar 6457359 */
+ flags |= BLOCK_IS_GLOBAL;
+ }
+ else
+ {
+ /* Find an existing declaration for _NSConcreteStackBlock or declare
+ extern void *_NSConcreteStackBlock; */
+ if (NSConcreteStackBlock_decl == NULL_TREE)
+ {
+ tree name_id = get_identifier("_NSConcreteStackBlock");
+ NSConcreteStackBlock_decl = lookup_name (name_id);
+ if (!NSConcreteStackBlock_decl)
+ {
+ NSConcreteStackBlock_decl = build_decl (VAR_DECL, name_id, ptr_type_node);
+ DECL_EXTERNAL (NSConcreteStackBlock_decl) = 1;
+ TREE_PUBLIC (NSConcreteStackBlock_decl) = 1;
+ pushdecl_top_level (NSConcreteStackBlock_decl);
+ rest_of_decl_compilation (NSConcreteStackBlock_decl, 0, 0);
+ }
+ }
+ /* APPLE LOCAL begin radar 6457359 */
+ CONSTRUCTOR_APPEND_ELT(impl_v, NULL_TREE,
+ convert (ptr_type_node,
+ build_fold_addr_expr (NSConcreteStackBlock_decl)));
+ /* APPLE LOCAL end radar 6457359 */
+ }
+
+ /* __flags */
+ CONSTRUCTOR_APPEND_ELT(impl_v, NULL_TREE, build_int_cst (integer_type_node, flags));
+ /* __reserved */
+ CONSTRUCTOR_APPEND_ELT(impl_v, NULL_TREE, build_int_cst (integer_type_node, 0));
+ /* __FuncPtr */
+ helper_addr = build_fold_addr_expr (block_impl->helper_func_decl);
+ helper_addr = convert (ptr_type_node, helper_addr);
+ CONSTRUCTOR_APPEND_ELT(impl_v, NULL_TREE, helper_addr);
+
+ /* &static_descriptor_variable initializer */
+ expr = build_fold_addr_expr (descriptor_block_decl);
+ CONSTRUCTOR_APPEND_ELT(impl_v, NULL_TREE, expr);
+
+ for (chain = block_impl->block_original_ref_decl_list; chain;
+ chain = TREE_CHAIN (chain))
+ {
+ tree y = TREE_VALUE (chain);
+ TREE_USED (y) = 1;
+ CONSTRUCTOR_APPEND_ELT(impl_v, NULL_TREE, y);
+ }
+ for (chain = block_impl->block_byref_decl_list; chain;
+ chain = TREE_CHAIN (chain))
+ {
+ tree y = lookup_name (DECL_NAME (TREE_VALUE (chain)));
+ tree forwarding_expr;
+ gcc_assert (y);
+ TREE_USED (y) = 1;
+ if (COPYABLE_BYREF_LOCAL_VAR (y))
+ {
+ /* For variables declared __block, either the original one
+ at the point of declaration or the imported version (which is
+ initialized in the helper function's prologue) is used to
+ initilize the byref variable field in the temporary. */
+ if (TREE_CODE (TREE_TYPE (y)) != RECORD_TYPE)
+ y = build_indirect_ref (y, "unary *");
+ /* We will be using the __block_struct_variable.__forwarding as the
+ initializer. */
+ forwarding_expr = build_component_ref (y, get_identifier ("__forwarding"));
+ }
+ else
+ /* Global variable is always assumed passed by its address. */
+ forwarding_expr = build_fold_addr_expr (y);
+
+ CONSTRUCTOR_APPEND_ELT(impl_v, NULL_TREE, forwarding_expr);
+ }
+ return impl_v;
+}
+/* APPLE LOCAL end radar 6169527 */
+/* APPLE LOCAL end radar 5847213 - radar 6329245 */
+
+/**
+ build_block_literal_tmp - This routine:
+
+ 1) builds block type:
+ struct __block_literal_n {
+ void *__isa; // initialized to &_NSConcreteStackBlock or &_NSConcreteGlobalBlock
+ int __flags;
+ int __reserved;
+ void *__FuncPtr;
+
+ struct __block_descriptor {
+ unsigned long int reserved; // NULL
+ unsigned long int Size; // sizeof(struct Block_literal_1)
+
+ // optional helper functions
+ void *CopyFuncPtr; // When BLOCK_HAS_COPY_DISPOSE
+ void *DestroyFuncPtr; // When BLOCK_HAS_COPY_DISPOSE
+ } *__descriptor;
+
+ // imported variables
+ int x; // ref variable list ...
+ int *y; // byref variable list
+ };
+
+ 2) build function prototype:
+ double helper_1(struct block_1 *ii, int z);
+
+ 3) build the temporary initialization:
+ struct block_1 I = {
+ { &_NSConcreteStackBlock or &_NSConcreteGlobalBlock // isa,
+ BLOCK_HAS_CXX_OBJ | BLOCK_HAS_COPY_DISPOSE | BLOCK_IS_GLOBAL // flags,
+ 0, // reserved,
+ &helper_1,
+ &{
+ NULL,
+ sizeof(struct block_1),
+ copy_helper_block_1, // only if block BLOCK_HAS_COPY_DISPOSE
+ destroy_helper_block_1, // only if block BLOCK_HAS_COPY_DISPOSE
+ },
+ x,
+ &y
+};
+
+It return the temporary.
+*/
+/* APPLE LOCAL begin radar 6169527 */
+static tree
+build_block_literal_tmp (const char *name,
+ struct block_sema_info * block_impl)
+{
+ extern tree create_tmp_var_raw (tree, const char *);
+ tree block_holder_tmp_decl;
+ tree constructor;
+ tree block_struct_type = TREE_TYPE (block_impl->block_arg_ptr_type);
+ /* APPLE LOCAL begin radar 6230297 */
+ bool staticBlockTmp = (block_impl->block_ref_decl_list == NULL_TREE &&
+ block_impl->block_byref_decl_list == NULL_TREE);
+
+ block_holder_tmp_decl = create_tmp_var_raw (block_struct_type, name);
+ /* Context will not be known until when the literal is synthesized.
+ This is more so in the case of nested block literal blocks. */
+ maybe_push_decl (block_holder_tmp_decl);
+ DECL_CONTEXT (block_holder_tmp_decl) = staticBlockTmp ? NULL_TREE
+ : current_function_decl;
+ if (staticBlockTmp)
+ DECL_CONTEXT (block_impl->helper_func_decl) = NULL_TREE;
+ /* APPLE LOCAL end radar 6230297 */
+ DECL_ARTIFICIAL (block_holder_tmp_decl) = 1;
+
+ /* Create a CONSTRUCTOR to represent the braced-initializer. */
+ constructor = make_node (CONSTRUCTOR);
+
+ CONSTRUCTOR_ELTS (constructor) = build_block_struct_initlist (block_struct_type,
+ block_impl);
+ /* Temporary representing a global block is made global static. */
+ /* APPLE LOCAL radar 6230297 */
+ if (staticBlockTmp || global_bindings_p ()) {
+ TREE_PUBLIC (block_holder_tmp_decl) = 0;
+ TREE_STATIC (block_holder_tmp_decl) = 1;
+ }
+ cp_finish_decl (block_holder_tmp_decl, constructor, 0, 0, LOOKUP_ONLYCONVERTING);
+ return block_holder_tmp_decl;
+}
+/* APPLE LOCAL end radar 6169527 */
+
+static tree
+clean_and_exit (tree block)
+{
+ pop_function_context ();
+ pop_lang_context ();
+ if (current_function_decl)
+ free (finish_block (block));
+ return error_mark_node;
+}
+
+/** synth_copy_helper_block_func - This function synthesizes
+ void copy_helper_block (struct block* _dest, struct block *_src) function.
+ */
+
+static void
+synth_copy_helper_block_func (struct block_sema_info * block_impl)
+{
+ tree stmt, chain;
+ tree dst_arg, src_arg;
+ /* struct c_arg_info * arg_info; */
+ /* Set up: (struct block* _dest, struct block *_src) parameters. */
+ dst_arg = build_decl (PARM_DECL, get_identifier ("_dst"),
+ block_impl->block_arg_ptr_type);
+ DECL_CONTEXT (dst_arg) = cur_block->copy_helper_func_decl;
+ TREE_USED (dst_arg) = 1;
+ DECL_ARG_TYPE (dst_arg) = block_impl->block_arg_ptr_type;
+ src_arg = build_decl (PARM_DECL, get_identifier ("_src"),
+ block_impl->block_arg_ptr_type);
+ DECL_CONTEXT (src_arg) = cur_block->copy_helper_func_decl;
+ TREE_USED (src_arg) = 1;
+ DECL_ARG_TYPE (src_arg) = block_impl->block_arg_ptr_type;
+ /* arg_info = xcalloc (1, sizeof (struct c_arg_info)); */
+ TREE_CHAIN (dst_arg) = src_arg;
+
+ pushdecl (cur_block->copy_helper_func_decl);
+ /* arg_info->parms = dst_arg; */
+ /* arg_info->types = tree_cons (NULL_TREE, block_impl->block_arg_ptr_type,
+ tree_cons (NULL_TREE,
+ block_impl->block_arg_ptr_type,
+ NULL_TREE)); */
+ DECL_ARGUMENTS (cur_block->copy_helper_func_decl) = dst_arg;
+ /* function header synthesis. */
+ push_function_context ();
+ /* start_block_helper_function (cur_block->copy_helper_func_decl, true); */
+ /* store_parm_decls (arg_info); */
+ start_preparsed_function (cur_block->copy_helper_func_decl,
+ /*attrs*/NULL_TREE,
+ SF_PRE_PARSED);
+
+ /* Body of the function. */
+ stmt = begin_compound_stmt (BCS_FN_BODY);
+ for (chain = block_impl->block_ref_decl_list; chain;
+ chain = TREE_CHAIN (chain))
+ /* APPLE LOCAL radar 6214617 */
+ if (cp_block_requires_copying (TREE_VALUE (chain)))
+ {
+ /* APPLE LOCAL begin radar 6175959 */
+ int flag = 0;
+ tree p = TREE_VALUE (chain);
+ tree dst_block_component, src_block_component;
+ dst_block_component = build_component_ref (build_indirect_ref (dst_arg, "->"),
+ DECL_NAME (p));
+ src_block_component = build_component_ref (build_indirect_ref (src_arg, "->"),
+ DECL_NAME (p));
+
+ if (TREE_CODE (TREE_TYPE (p)) == BLOCK_POINTER_TYPE)
+ /* _Block_object_assign(&_dest->myImportedBlock, _src->myImportedClosure, BLOCK_FIELD_IS_BLOCK) */
+ flag = BLOCK_FIELD_IS_BLOCK;
+ /* APPLE LOCAL begin radar 6214617 */
+ else if (TYPE_HAS_CONSTRUCTOR (TREE_TYPE (p))
+ || TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (p)))
+ {
+ tree call_exp = build_aggr_init (dst_block_component, src_block_component,
+ LOOKUP_ONLYCONVERTING);
+ add_stmt (call_exp);
+ }
+ /* APPLE LOCAL end radar 6214617 */
+ else
+ /* _Block_object_assign(&_dest->myImportedBlock, _src->myImportedClosure, BLOCK_FIELD_IS_OBJECT) */
+ flag = BLOCK_FIELD_IS_OBJECT;
+ if (flag)
+ {
+ tree call_exp;
+ dst_block_component = build_fold_addr_expr (dst_block_component);
+ call_exp = build_block_object_assign_call_exp (dst_block_component, src_block_component, flag);
+ add_stmt (call_exp);
+ }
+ /* APPLE LOCAL end radar 6175959 */
+ }
+
+ /* For each __block declared variable used in |...| Must generate call to:
+ _Block_object_assign(&_dest->myImportedBlock, _src->myImportedBlock, BLOCK_FIELD_IS_BYREF [|BLOCK_FIELD_IS_WEAK])
+ */
+ for (chain = block_impl->block_byref_decl_list; chain;
+ chain = TREE_CHAIN (chain))
+ if (COPYABLE_BYREF_LOCAL_VAR (TREE_VALUE (chain)))
+ {
+ int flag = BLOCK_FIELD_IS_BYREF;
+ tree call_exp;
+ tree p = TREE_VALUE (chain);
+ tree dst_block_component, src_block_component;
+ dst_block_component = build_component_ref (build_indirect_ref (dst_arg, "->"),
+ DECL_NAME (p));
+ src_block_component = build_component_ref (build_indirect_ref (src_arg, "->"),
+ DECL_NAME (p));
+
+ /* _Block_object_assign(&_dest->myImportedClosure, _src->myImportedClosure, BLOCK_FIELD_IS_BYREF [|BLOCK_FIELD_IS_WEAK]) */
+ if (COPYABLE_WEAK_BLOCK (p))
+ flag |= BLOCK_FIELD_IS_WEAK;
+
+ dst_block_component = build_fold_addr_expr (dst_block_component);
+ call_exp = build_block_object_assign_call_exp (dst_block_component, src_block_component, flag);
+ add_stmt (call_exp);
+ }
+
+ finish_compound_stmt (stmt);
+ /* APPLE LOCAL radar 6169580 */
+ finish_function (4);
+ /* Hum, would be nice if someone else did this for us. */
+ if (global_bindings_p ())
+ cgraph_finalize_function (block_impl->copy_helper_func_decl, false);
+ pop_function_context ();
+ /* free (arg_info); */
+}
+
+static void
+synth_destroy_helper_block_func (struct block_sema_info * block_impl)
+{
+ tree stmt, chain;
+ tree src_arg;
+ /* struct c_arg_info * arg_info; */
+ /* Set up: (struct block *_src) parameter. */
+ src_arg = build_decl (PARM_DECL, get_identifier ("_src"),
+ block_impl->block_arg_ptr_type);
+ DECL_CONTEXT (src_arg) = cur_block->destroy_helper_func_decl;
+ TREE_USED (src_arg) = 1;
+ DECL_ARG_TYPE (src_arg) = block_impl->block_arg_ptr_type;
+ /* arg_info = xcalloc (1, sizeof (struct c_arg_info)); */
+
+ pushdecl (cur_block->destroy_helper_func_decl);
+ /* arg_info->parms = src_arg; */
+ /* arg_info->types = tree_cons (NULL_TREE, block_impl->block_arg_ptr_type,
+ NULL_TREE); */
+ DECL_ARGUMENTS (cur_block->destroy_helper_func_decl) = src_arg;
+
+ /* function header synthesis. */
+ push_function_context ();
+ /* start_block_helper_function (cur_block->destroy_helper_func_decl, true); */
+ /* store_parm_decls_from (arg_info); */
+ start_preparsed_function (cur_block->destroy_helper_func_decl,
+ /*attrs*/NULL_TREE,
+ SF_PRE_PARSED);
+
+ /* Body of the function. */
+ stmt = begin_compound_stmt (BCS_FN_BODY);
+ for (chain = block_impl->block_ref_decl_list; chain;
+ chain = TREE_CHAIN (chain))
+ /* APPLE LOCAL begin radar 6214617 */
+ if (block_requires_copying (TREE_VALUE (chain))
+ || (TREE_CODE (TREE_TYPE (TREE_VALUE (chain))) == RECORD_TYPE
+ && CLASSTYPE_DESTRUCTORS (TREE_TYPE (TREE_VALUE (chain)))))
+ /* APPLE LOCAL end radar 6214617 */
+ {
+ int flag = 0;
+ tree rel_exp;
+ tree p = TREE_VALUE (chain);
+ tree src_block_component;
+ src_block_component = build_component_ref (build_indirect_ref (src_arg, "->"),
+ DECL_NAME (p));
+
+ if (TREE_CODE (TREE_TYPE (p)) == BLOCK_POINTER_TYPE)
+ /* _Block_object_dispose(_src->imported_object_0, BLOCK_FIELD_IS_BLOCK); */
+ flag = BLOCK_FIELD_IS_BLOCK;
+ /* APPLE LOCAL begin radar 6214617 */
+ else if (TREE_CODE (TREE_TYPE (p)) == RECORD_TYPE
+ && CLASSTYPE_DESTRUCTORS (TREE_TYPE (p)))
+ {
+ tree call_exp = cxx_maybe_build_cleanup (src_block_component);
+ gcc_assert (call_exp);
+ add_stmt (call_exp);
+ }
+ /* APPLE LOCAL end radar 6214617 */
+ else
+ /* _Block_object_dispose(_src->imported_object_0, BLOCK_FIELD_IS_OBJECT); */
+ flag = BLOCK_FIELD_IS_OBJECT;
+ if (flag)
+ {
+ rel_exp = build_block_object_dispose_call_exp (src_block_component, flag);
+ add_stmt (rel_exp);
+ }
+ }
+
+ /* For each __block declared variable used in |...| Must generate call to:
+ _Block_object_dispose(_src->myImportedClosure, BLOCK_FIELD_IS_BYREF[|BLOCK_FIELD_IS_WEAK])
+ */
+ for (chain = block_impl->block_byref_decl_list; chain;
+ chain = TREE_CHAIN (chain))
+ if (COPYABLE_BYREF_LOCAL_VAR (TREE_VALUE (chain)))
+ {
+ tree call_exp;
+ int flag = BLOCK_FIELD_IS_BYREF;
+ tree p = TREE_VALUE (chain);
+ tree src_block_component;
+
+ src_block_component = build_component_ref (build_indirect_ref (src_arg, "->"),
+ DECL_NAME (p));
+ if (COPYABLE_WEAK_BLOCK (p))
+ flag |= BLOCK_FIELD_IS_WEAK;
+ /* _Block_object_dispose(_src->myImportedClosure, BLOCK_FIELD_IS_BYREF[|BLOCK_FIELD_IS_WEAK]) */
+ call_exp = build_block_object_dispose_call_exp (src_block_component, flag);
+ add_stmt (call_exp);
+ }
+
+ finish_compound_stmt (stmt);
+ /* APPLE LOCAL radar 6169580 */
+ finish_function (4);
+ /* Hum, would be nice if someone else did this for us. */
+ if (global_bindings_p ())
+ cgraph_finalize_function (block_impl->destroy_helper_func_decl, false);
+ pop_function_context ();
+}
+
+/* Parse a block-id.
+
+ GNU Extension:
+
+ block-id:
+ type-specifier-seq block-declarator
+
+ Returns the DECL specified or implied. */
+
+static tree
+cp_parser_block_id (cp_parser* parser)
+{
+ cp_decl_specifier_seq type_specifier_seq;
+ cp_declarator *declarator;
+
+ /* Parse the type-specifier-seq. */
+ cp_parser_type_specifier_seq (parser, /*is_condition=*/false,
+ &type_specifier_seq);
+ if (type_specifier_seq.type == error_mark_node)
+ return error_mark_node;
+
+ /* Look for the block-declarator. */
+ declarator
+ = cp_parser_declarator (parser, CP_PARSER_DECLARATOR_BLOCK, NULL,
+ /*parenthesized_p=*/NULL,
+ /*member_p=*/false);
+
+ return grokblockdecl (&type_specifier_seq, declarator);
+}
+
+/* Parse a block-literal-expr.
+
+ GNU Extension:
+
+ block-literal-expr:
+ ^ parameter-declation-clause exception-specification [opt] compound-statement
+ ^ block-id compound-statement
+
+ It synthesizes the helper function for later generation and builds
+ the necessary data to represent the block literal where it is
+ declared. */
+static tree
+cp_parser_block_literal_expr (cp_parser* parser)
+{
+ char name [32];
+ static int global_unique_count;
+ int unique_count = ++global_unique_count;
+ tree block_helper_function_decl;
+ tree expr, type, arglist = NULL_TREE, ftype;
+ tree self_arg, stmt;
+ /* struct c_arg_info *args = NULL; */
+ cp_parameter_declarator *args = NULL;
+ tree arg_type = void_list_node;
+ struct block_sema_info *block_impl;
+ tree tmp;
+ tree restype;
+ tree typelist;
+ tree helper_function_type;
+ tree block;
+ /* APPLE LOCAL radar 6185344 */
+ tree declared_block_return_type = NULL_TREE;
+ /* APPLE LOCAL radar 6237713 */
+ tree attributes = NULL_TREE;
+ /* APPLE LOCAL radar 6169580 */
+ int context_is_nonstatic_method;
+ tree raises = NULL_TREE;
+
+ cp_lexer_consume_token (parser->lexer); /* eat '^' */
+
+ /* APPLE LOCAL begin radar 6237713 */
+ if (cp_lexer_peek_token (parser->lexer)->keyword == RID_ATTRIBUTE)
+ attributes = cp_parser_attributes_opt (parser);
+ /* APPLE LOCAL end radar 6237713 */
+
+ if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN))
+ {
+ /* Parse the optional argument list */
+ cp_lexer_consume_token (parser->lexer);
+ /* Open the scope to collect parameter decls */
+ /* push_scope (); */
+ /* args = c_parser_parms_declarator (parser, true, NULL_TREE); */
+ /* Parse the parameter-declaration-clause. */
+ args = cp_parser_parameter_declaration_clause (parser);
+ cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
+ arg_type = grokparms (args, &arglist);
+ /* Check for args as it might be NULL due to error. */
+ if (! args)
+ {
+ return error_mark_node;
+ }
+ raises = cp_parser_exception_specification_opt (parser);
+ }
+ /* APPLE LOCAL begin radar 6185344 */
+ else if (cp_lexer_next_token_is_not (parser->lexer, CPP_OPEN_BRACE))
+ {
+ /* Parse user declared return type. */
+ tree decl;
+
+ /* APPLE LOCAL begin radar 6237713 */
+ if (attributes)
+ {
+ warning (0, "attributes before block type are ignored");
+ attributes = NULL_TREE;
+ }
+ /* APPLE LOCAL end radar 6237713 */
+
+ decl = cp_parser_block_id (parser);
+
+ if (decl && decl != error_mark_node)
+ {
+ arg_type = TYPE_ARG_TYPES (TREE_TYPE (decl));
+ arglist = DECL_ARGUMENTS (decl);
+ raises = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (decl));
+ declared_block_return_type = TREE_TYPE (TREE_TYPE (decl));
+ }
+ }
+ /* APPLE LOCAL end radar 6185344 */
+
+ block = begin_block ();
+ /* APPLE LOCAL begin radar 6169580 */
+ context_is_nonstatic_method = (current_function_decl
+ && DECL_NONSTATIC_MEMBER_FUNCTION_P (current_function_decl));
+ /* APPLE LOCAL end radar 6169580 */
+
+ /* cur_block->arg_info = NULL; */
+ /* APPLE LOCAL begin radar 6185344 */
+ if (declared_block_return_type)
+ {
+ cur_block->return_type = TYPE_MAIN_VARIANT (declared_block_return_type);
+ cur_block->block_has_return_type = true;
+ }
+ else
+ cur_block->return_type = NULL_TREE;
+ /* APPLE LOCAL end radar 6185344 */
+
+ /* Must also build hidden parameter .block_descriptor added to the helper
+ function, even though we do not know its type yet. */
+ /* APPLE LOCAL radar 6404979 */
+ self_arg = build_artificial_parm (get_identifier (".block_descriptor"), ptr_type_node);
+
+ /* TREE_CHAIN (self_arg) = cur_block->arg_info->parms; */
+ TREE_CHAIN (self_arg) = arglist;
+ arg_type = tree_cons (NULL_TREE, ptr_type_node, arg_type);
+ arglist = self_arg;
+
+ /* APPLE LOCAL begin radar 6185344 */
+ /* Build the declaration of the helper function (if we do not know its result
+ type yet, assume it is 'void'. If user provided it, use it).
+ Treat this as a nested function and use nested function infrastructure for
+ its generation. */
+
+ push_lang_context (lang_name_c);
+
+ ftype = build_function_type ((!cur_block->block_has_return_type
+ ? void_type_node : cur_block->return_type),
+ arg_type);
+ /* APPLE LOCAL end radar 6185344 */
+ if (raises)
+ ftype = build_exception_variant (ftype, raises);
+ /* APPLE LOCAL radar 6160536 */
+ block_helper_function_decl = build_helper_func_decl (build_block_helper_name (unique_count),
+ ftype);
+ DECL_CONTEXT (block_helper_function_decl) = current_function_decl;
+ cur_block->helper_func_decl = block_helper_function_decl;
+
+ DECL_ARGUMENTS (block_helper_function_decl) = arglist;
+
+ push_function_context ();
+ /* start_block_helper_function (cur_block->helper_func_decl, false); */
+ /* Enter parameter list to the scope of the helper function. */
+ /* store_parm_decls_from (cur_block->arg_info); */
+ start_preparsed_function (cur_block->helper_func_decl,
+ /*attrs*/NULL_TREE,
+ SF_PRE_PARSED);
+ /* APPLE LOCAL begin radar 6237713 */
+ if (cp_lexer_peek_token (parser->lexer)->keyword == RID_ATTRIBUTE)
+ attributes = cp_parser_attributes_opt (parser);
+ /* APPLE LOCAL radar 6246527 */
+ any_recognized_block_attribute (attributes);
+ decl_attributes (&cur_block->helper_func_decl, attributes, 0);
+ /* APPLE LOCAL end radar 6237713 */
+
+ /* Start parsing body or expression part of the block literal. */
+ {
+ unsigned save = parser->in_statement;
+ /* Indicate no valid break/continue context. We'll notice and
+ emit the proper error message in c_finish_bc_stmt. */
+ parser->in_statement = 0;
+ stmt = begin_compound_stmt (BCS_FN_BODY);
+ /* Set block's scope to the scope of the helper function's main body.
+ This is primarily used when nested blocks are declared. */
+ cur_block->cp_the_scope = current_binding_level;
+ /* APPLE LOCAL begin radar 6169580 */
+ if (context_is_nonstatic_method)
+ {
+ tree this_decl = lookup_name (this_identifier);
+ gcc_assert (this_decl);
+ build_block_ref_decl (this_identifier, this_decl);
+ }
+ /* APPLE LOCAL end radar 6169580 */
+ cp_parser_compound_statement (parser, NULL, false, false);
+ parser->in_statement = save;
+ }
+
+ cur_block->block_arg_ptr_type =
+ build_pointer_type (build_block_struct_type (cur_block));
+
+ restype = !cur_block->return_type ? void_type_node
+ : cur_block->return_type;
+ if (restype == error_mark_node)
+ return clean_and_exit (block);
+
+ /* Now that we know type of the hidden .block_descriptor argument, fix its type. */
+ TREE_TYPE (self_arg) = cur_block->block_arg_ptr_type;
+ DECL_ARG_TYPE (self_arg) = cur_block->block_arg_ptr_type;
+
+ /* The DECL_RESULT should already have the correct type by now. */
+ gcc_assert (TREE_TYPE (DECL_RESULT (current_function_decl))
+ == restype);
+
+ cur_block->block_body = stmt;
+ block_build_prologue (cur_block);
+
+ finish_compound_stmt (stmt);
+ /* add_stmt (fnbody); */
+
+ /* We are done parsing of the block body. Return type of block is now known.
+ We also know all we need to know about the helper function. So, fix its
+ type here. */
+ /* We moved this here because for global blocks, helper function body is
+ not nested and is gimplified in call to finish_function() and return type
+ of the function must be correct. */
+ ftype = build_function_type (restype, TREE_CHAIN (arg_type));
+ if (raises)
+ ftype = build_exception_variant (ftype, raises);
+ /* Declare helper function; as in:
+ double helper_1(struct block_1 *ii, int z); */
+ typelist = TYPE_ARG_TYPES (ftype);
+ /* (struct block_1 *ii, int z, ...) */
+ typelist = tree_cons (NULL_TREE, cur_block->block_arg_ptr_type,
+ typelist);
+ helper_function_type = build_function_type (TREE_TYPE (ftype), typelist);
+ if (raises)
+ helper_function_type = build_exception_variant (helper_function_type, raises);
+ TREE_TYPE (cur_block->helper_func_decl) = helper_function_type;
+ finish_function (4);
+ pop_function_context ();
+ /* Hum, would be nice if someone else did this for us. */
+ if (global_bindings_p ())
+ cgraph_finalize_function (cur_block->helper_func_decl, false);
+ pop_lang_context ();
+
+ /* Build the declaration for copy_helper_block and destroy_helper_block
+ helper functions for later use. */
+
+ if (cur_block->BlockHasCopyDispose)
+ {
+ tree s_ftype;
+
+ push_lang_context (lang_name_c);
+ /* void copy_helper_block (struct block*, struct block *); */
+ s_ftype = build_function_type (void_type_node,
+ tree_cons (NULL_TREE, cur_block->block_arg_ptr_type,
+ tree_cons (NULL_TREE,
+ cur_block->block_arg_ptr_type,
+ void_list_node)));
+ sprintf (name, "__copy_helper_block_%d", unique_count);
+ cur_block->copy_helper_func_decl =
+ build_helper_func_decl (get_identifier (name), s_ftype);
+ DECL_CONTEXT (cur_block->copy_helper_func_decl) = current_function_decl;
+ synth_copy_helper_block_func (cur_block);
+
+ /* void destroy_helper_block (struct block*); */
+ s_ftype = build_function_type (void_type_node,
+ tree_cons (NULL_TREE,
+ cur_block->block_arg_ptr_type, void_list_node));
+ sprintf (name, "__destroy_helper_block_%d", unique_count);
+ cur_block->destroy_helper_func_decl =
+ build_helper_func_decl (get_identifier (name), s_ftype);
+ DECL_CONTEXT (cur_block->destroy_helper_func_decl) = current_function_decl;
+ synth_destroy_helper_block_func (cur_block);
+ pop_lang_context ();
+ }
+
+ block_impl = finish_block (block);
+
+ /* Build unqiue name of the temporary used in code gen. */
+ sprintf (name, "__block_holder_tmp_%d", unique_count);
+ tmp = build_block_literal_tmp (name, block_impl);
+ tmp = build_fold_addr_expr (tmp);
+ type = build_block_pointer_type (ftype);
+ expr = convert (type, convert (ptr_type_node, tmp));
+ free (block_impl);
+ return expr;
+}
+/* APPLE LOCAL end blocks 6040305 (ce) */
+
+/* APPLE LOCAL begin blocks 6040305 (ch) */
+/* build_byref_local_var_access - converts EXPR to:
+ EXPR.__forwarding-><decl-name>.
+ */
+tree
+build_byref_local_var_access (tree expr, tree decl_name)
+{
+ tree exp = build_component_ref (expr, get_identifier ("__forwarding"));
+ exp = build_indirect_ref (exp, "unary *");
+ exp = build_component_ref (exp, decl_name);
+ return exp;
+}
+
+#define BINDING_VALUE(b) ((b)->value)
+
+/**
+ build_block_byref_decl - This routine inserts a variable declared as a
+ 'byref' variable using the |...| syntax in helper function's outer-most scope.
+ */
+tree
+build_block_byref_decl (tree name, tree decl, tree exp)
+{
+ tree ptr_type, byref_decl;
+ /* APPLE LOCAL begin radar 6225809 */
+ if (cur_block->prev_block_info) {
+ /* Traverse enclosing blocks. Insert a __block variable in
+ each enclosing block which has no declaration of this
+ variable. This is to ensure that the current (inner) block
+ gets the __block version of the variable; */
+ struct block_sema_info *cb = cur_block->prev_block_info;
+ while (cb) {
+ struct cxx_binding *b = I_SYMBOL_BINDING (name);
+ gcc_assert (b);
+ gcc_assert (BINDING_VALUE (b));
+ gcc_assert (TREE_CODE (BINDING_VALUE (b)) == VAR_DECL
+ || TREE_CODE (BINDING_VALUE (b)) == PARM_DECL);
+ /* Find the first declaration not in current block. */
+ while (b && BINDING_VALUE (b)
+ && (TREE_CODE (BINDING_VALUE (b)) == VAR_DECL
+ || TREE_CODE (BINDING_VALUE (b)) == PARM_DECL)
+ && DECL_CONTEXT (BINDING_VALUE (b)) == cur_block->helper_func_decl)
+ {
+ /* FIXME: This can't happen?! */
+ abort ();
+ /* b = b->previous; */
+ }
+
+ gcc_assert (b);
+ gcc_assert (BINDING_VALUE (b));
+ gcc_assert (TREE_CODE (BINDING_VALUE (b)) == VAR_DECL
+ || TREE_CODE (BINDING_VALUE (b)) == PARM_DECL);
+
+ /* Is the next declaration not in the enclosing block? */
+ if (b && BINDING_VALUE (b)
+ && (TREE_CODE (BINDING_VALUE (b)) == VAR_DECL
+ || TREE_CODE (BINDING_VALUE (b)) == PARM_DECL)
+ && DECL_CONTEXT (BINDING_VALUE (b)) != cb->helper_func_decl)
+ {
+ /* No declaration of variable seen in the block. Must insert one. */
+ /* FIXME: does this push enough? scope? */
+ struct cp_binding_level *save_scope = current_binding_level;
+ struct block_sema_info *save_current_block = cur_block;
+ tree save_current_function_decl = current_function_decl;
+ current_binding_level = cb->cp_the_scope;
+ cur_block = cb;
+ current_function_decl = cb->helper_func_decl;
+ decl = build_block_byref_decl (name, decl, exp);
+ cur_block = save_current_block;
+ current_binding_level = save_scope;
+ current_function_decl = save_current_function_decl;
+ }
+ cb = cb->prev_block_info;
+ }
+ }
+ /* APPLE LOCAL end radar 6225809 */
+
+ /* If it is already a byref declaration, do not add the pointer type
+ because such declarations already have the pointer type
+ added. This happens when we have two nested byref declarations in
+ nested blocks. */
+ ptr_type = (TREE_CODE (decl) == VAR_DECL && BLOCK_DECL_BYREF (decl))
+ ? TREE_TYPE (decl) : build_pointer_type (TREE_TYPE (decl));
+ byref_decl = build_decl (VAR_DECL, name, ptr_type);
+ DECL_CONTEXT (byref_decl) = current_function_decl;
+ BLOCK_DECL_BYREF (byref_decl) = 1;
+
+ if (TREE_CODE (decl) == VAR_DECL && COPYABLE_BYREF_LOCAL_VAR (decl))
+ {
+ COPYABLE_BYREF_LOCAL_VAR (byref_decl) = 1;
+ COPYABLE_BYREF_LOCAL_NONPOD (byref_decl) = COPYABLE_BYREF_LOCAL_NONPOD (decl);
+ /* APPLE LOCAL radar 5847976 */
+ COPYABLE_WEAK_BLOCK (byref_decl) = COPYABLE_WEAK_BLOCK (decl);
+ }
+
+ /* Current scope must be that of the main function body. */
+ /* FIXME gcc_assert (current_scope->function_body);*/
+ pushdecl (byref_decl);
+ mark_used (byref_decl);
+ /* APPLE LOCAL begin radar 6083129 - byref escapes (cp) */
+ /* FIXME: finish this off, ensure the decl is scoped appropriately
+ for when we want the cleanup to run. */
+ /* APPLE LOCAL end radar 6083129 - byref escapes (cp) */
+ cur_block->block_byref_decl_list =
+ tree_cons (NULL_TREE, byref_decl, cur_block->block_byref_decl_list);
+ /* APPLE LOCAL radar 5847213 */
+ /* build of block_original_byref_decl_list us removed. */
+ /* APPLE LOCAL begin radar 6144664 */
+ DECL_SOURCE_LOCATION (byref_decl)
+ = DECL_SOURCE_LOCATION (cur_block->helper_func_decl);
+ /* APPLE LOCAL end radar 6144664 */
+ return byref_decl;
+}
+
+/**
+ build_block_ref_decl - This routine inserts a copied-in variable (a variable
+ referenced in the block but whose scope is outside the block) in helper
+ function's outer-most scope. It also sets its type to 'const' as such
+ variables are read-only.
+ */
+tree
+build_block_ref_decl (tree name, tree decl)
+{
+ /* FIXME - Broken, should be found via objc runtime testcases. */
+ /* FIXME - Don't use DECL_CONTEXT on any helpers */
+ tree ref_decl;
+ /* APPLE LOCAL radar 6212722 */
+ tree type, exp;
+ /* 'decl' was previously declared as __block. Simply, copy the value
+ embedded in the above variable. */
+ if (TREE_CODE (decl) == VAR_DECL && COPYABLE_BYREF_LOCAL_VAR (decl))
+ decl = build_byref_local_var_access (decl, DECL_NAME (decl));
+ else {
+ if (cur_block->prev_block_info) {
+ /* Traverse enclosing blocks. Insert a copied-in variable in
+ each enclosing block which has no declaration of this
+ variable. This is to ensure that the current (inner) block
+ has the 'frozen' value of the copied-in variable; which means
+ the value of the copied in variable is at the point of the
+ block declaration and *not* when the inner block is
+ invoked. */
+ struct block_sema_info *cb = cur_block->prev_block_info;
+ while (cb) {
+ struct cxx_binding *b = I_SYMBOL_BINDING (name);
+ gcc_assert (b);
+ gcc_assert (BINDING_VALUE (b));
+ gcc_assert (TREE_CODE (BINDING_VALUE (b)) == VAR_DECL
+ || TREE_CODE (BINDING_VALUE (b)) == PARM_DECL);
+ /* Find the first declaration not in current block. */
+ while (b && BINDING_VALUE (b)
+ && (TREE_CODE (BINDING_VALUE (b)) == VAR_DECL
+ || TREE_CODE (BINDING_VALUE (b)) == PARM_DECL)
+ && DECL_CONTEXT (BINDING_VALUE (b)) == cur_block->helper_func_decl)
+ {
+ /* FIXME: This can't happen?! */
+ abort ();
+ /* b = b->previous; */
+ }
+
+ gcc_assert (b);
+ gcc_assert (BINDING_VALUE (b));
+ gcc_assert (TREE_CODE (BINDING_VALUE (b)) == VAR_DECL
+ || TREE_CODE (BINDING_VALUE (b)) == PARM_DECL);
+
+ /* Is the next declaration not in the enclosing block? */
+ if (b && BINDING_VALUE (b)
+ && (TREE_CODE (BINDING_VALUE (b)) == VAR_DECL
+ || TREE_CODE (BINDING_VALUE (b)) == PARM_DECL)
+ && DECL_CONTEXT (BINDING_VALUE (b)) != cb->helper_func_decl)
+ {
+ /* No declaration of variable seen in the block. Must
+ insert one, so it 'freezes' the variable in this
+ block. */
+ /* FIXME: does this push enough? scope? */
+ struct cp_binding_level *save_scope = current_binding_level;
+ struct block_sema_info *save_current_block = cur_block;
+ tree save_current_function_decl = current_function_decl;
+ current_binding_level = cb->cp_the_scope;
+ cur_block = cb;
+ current_function_decl = cb->helper_func_decl;
+ decl = build_block_ref_decl (name, decl);
+ cur_block = save_current_block;
+ current_binding_level = save_scope;
+ current_function_decl = save_current_function_decl;
+ }
+ cb = cb->prev_block_info;
+ }
+ }
+ }
+ /* APPLE LOCAL begin radar 6212722 */
+ exp = decl;
+ type = TREE_TYPE (exp);
+ if (TREE_CODE (type) == ARRAY_TYPE || TREE_CODE (type) == FUNCTION_TYPE) {
+ exp = decay_conversion (exp);
+ type = TREE_TYPE (exp);
+ }
+ ref_decl = build_decl (VAR_DECL, name,
+ build_qualified_type (type, TYPE_QUAL_CONST));
+ /* APPLE LOCAL end radar 6212722 */
+ /* APPLE LOCAL begin radar 6144664 */
+ DECL_SOURCE_LOCATION (ref_decl) = DECL_SOURCE_LOCATION
+ (cur_block->helper_func_decl);
+ /* APPLE LOCAL end radar 6144664 */
+ DECL_CONTEXT (ref_decl) = current_function_decl;
+ DECL_INITIAL (ref_decl) = error_mark_node;
+ c_apply_type_quals_to_decl (TYPE_QUAL_CONST, ref_decl);
+ BLOCK_DECL_COPIED (ref_decl) = 1;
+
+ /* Find the scope for function body (outer-most scope) and insert
+ this variable in that scope. This is to avoid duplicate
+ declaration of the save variable. */
+ {
+ struct cp_binding_level *b = current_binding_level;
+ while (b->level_chain->kind != sk_function_parms)
+ b = b->level_chain;
+ pushdecl_with_scope (ref_decl, b, /*is_friend=*/false);
+ /* APPLE LOCAL radar 6169527 */
+ add_decl_expr (ref_decl);
+ }
+ cur_block->block_ref_decl_list =
+ tree_cons (NULL_TREE, ref_decl, cur_block->block_ref_decl_list);
+ cur_block->block_original_ref_decl_list =
+ /* APPLE LOCAL radar 6212722 */
+ tree_cons (NULL_TREE, exp, cur_block->block_original_ref_decl_list);
+ return ref_decl;
+}
+
+/* APPLE LOCAL begin radar 5847213 - radar 6329245 */
+static GTY (()) tree descriptor_ptr_type;
+static GTY (()) tree descriptor_ptr_type_with_copydispose;
+/** build_block_descriptor_type - This routine builds following internal type:
+ struct __block_descriptor {
+ unsigned long int reserved; // NULL
+ unsigned long int Size; // sizeof(struct Block_literal_1)
+
+ // optional helper functions
+ void *CopyFuncPtr; // When BLOCK_HAS_COPY_DISPOSE is set (withCopyDispose true)
+ void *DestroyFuncPtr; // When BLOCK_HAS_COPY_DISPOSE is set (withCopyDispose true)
+ } *descriptor_ptr_type;
+
+ Objects of this type will always be static. This is one main component of abi change.
+ */
+tree
+build_block_descriptor_type (bool withCopyDispose)
+{
+ tree field_decl_chain = NULL_TREE, field_decl;
+ tree main_type;
+
+ if (withCopyDispose && descriptor_ptr_type_with_copydispose)
+ return descriptor_ptr_type_with_copydispose;
+ if (!withCopyDispose && descriptor_ptr_type)
+ return descriptor_ptr_type;
+
+ main_type = make_aggr_type (RECORD_TYPE);
+ xref_basetypes (main_type, NULL_TREE);
+
+ /* unsigned long int reserved; */
+ field_decl = build_decl (FIELD_DECL, get_identifier ("reserved"), long_unsigned_type_node);
+ TREE_CHAIN (field_decl) = field_decl_chain;
+ field_decl_chain = field_decl;
+
+ /* unsigned long int Size; */
+ field_decl = build_decl (FIELD_DECL, get_identifier ("Size"), long_unsigned_type_node);
+ TREE_CHAIN (field_decl) = field_decl_chain;
+ field_decl_chain = field_decl;
+
+ if (withCopyDispose)
+ {
+ /* void *CopyFuncPtr; */
+ field_decl = build_decl (FIELD_DECL, get_identifier ("CopyFuncPtr"), ptr_type_node);
+ TREE_CHAIN (field_decl) = field_decl_chain;
+ field_decl_chain = field_decl;
+ /* void *DestroyFuncPtr; */
+ field_decl = build_decl (FIELD_DECL, get_identifier ("DestroyFuncPtr"), ptr_type_node);
+ TREE_CHAIN (field_decl) = field_decl_chain;
+ field_decl_chain = field_decl;
+ }
+
+ /* Mark this struct as being a block struct rather than a 'normal'
+ struct. */
+ TYPE_BLOCK_IMPL_STRUCT (main_type) = 1;
+ if (withCopyDispose)
+ finish_builtin_struct (main_type, "__block_descriptor_withcopydispose", field_decl_chain, NULL_TREE);
+ else
+ finish_builtin_struct (main_type, "__block_descriptor", field_decl_chain, NULL_TREE);
+ CLASSTYPE_AS_BASE (main_type) = main_type;
+
+ main_type = build_pointer_type (main_type);
+ if (withCopyDispose)
+ descriptor_ptr_type_with_copydispose = main_type;
+ else
+ descriptor_ptr_type = main_type;
+ return main_type;
+}
+/* APPLE LOCAL end radar 5847213 - radar 6329245 */
+
+cp_declarator *
+make_block_pointer_declarator (tree attributes,
+ cp_cv_quals quals,
+ cp_declarator *target)
+{
+ struct cp_declarator *itarget = target;
+ struct cp_declarator *ret = make_declarator (cdk_block_pointer);
+
+ /* APPLE LOCAL radar 5847213 */
+ /* code removed */
+
+
+ ret->attributes = attributes;
+ ret->declarator = itarget;
+ ret->u.block_pointer.qualifiers = quals;
+ return ret;
+}
+
+/* This routine returns 'true' if 'name' has a declaration inside the
+ current block, 'false' otherwise. If 'name' has no declaration in
+ the current block, it returns in DECL the user declaration for
+ 'name' found in the enclosing scope. Note that if it is declared
+ in current declaration, it can be either a user declaration or a
+ byref/copied-in declaration added in current block's scope by the
+ compiler. */
+bool
+lookup_name_in_block (tree name, tree *decl)
+{
+ /* FIXME - Broken, should be found via objc runtime testcases. */
+ /* FIXME - Don't use DECL_CONTEXT on any helpers */
+ cxx_binding *b = I_SYMBOL_BINDING (name);
+ if (b && b->declared_in_block
+ && DECL_CONTEXT (BINDING_VALUE (b)) == current_function_decl)
+ return true;
+
+ /* Check for variables only, as we may have parameters, such as
+ 'self' */
+ /* Note that if a copied-in variable (BLOCK_DECL_COPIED) in the
+ enclosing block is found, it must be returned as this is
+ where the variable in current (nested block) will have to get
+ its value. */
+ while (b
+ && TREE_CODE (BINDING_VALUE (b)) == VAR_DECL
+ && (BLOCK_DECL_BYREF (BINDING_VALUE (b))))
+ b = b->previous;
+ if (b)
+ *decl = BINDING_VALUE (b);
+ return false;
+}
+
+/**
+ build_helper_func_decl - This routine builds a FUNCTION_DECL for
+ a block helper function.
+ */
+tree
+build_helper_func_decl (tree ident, tree type)
+{
+ tree func_decl = build_decl (FUNCTION_DECL, ident, type);
+ DECL_EXTERNAL (func_decl) = 0;
+ TREE_PUBLIC (func_decl) = 0;
+ TREE_USED (func_decl) = 1;
+ TREE_NOTHROW (func_decl) = 0;
+ /* APPLE LOCAL radar 6172148 */
+ BLOCK_SYNTHESIZED_FUNC (func_decl) = 1;
+ retrofit_lang_decl (func_decl);
+ if (current_function_decl)
+ DECL_NO_STATIC_CHAIN (current_function_decl) = 0;
+ return func_decl;
+}
+
+/**
+ declare_block_prologue_local_vars - utility routine to do the actual
+ declaration and initialization for each referecned block variable.
+ */
+/* APPLE LOCAL begin radar 6169527 */
+/* This routine is mostly rewritten for c++ because initialization of variables
+ may involve copy construction. */
+static void
+declare_block_prologue_local_vars (tree self_parm, tree component,
+ tree stmt)
+{
+ tree decl, block_component;
+ tree_stmt_iterator i;
+ tree initialization_stmt;
+ /* APPLE LOCAL radar 6163705 */
+ int save_line = LOCATION_LINE (input_location);
+
+ decl = component;
+ block_component = build_component_ref (build_indirect_ref (self_parm, "->"),
+ DECL_NAME (component));
+ gcc_assert (block_component);
+ /* APPLE LOCAL radar 6163705 */
+ LOCATION_LINE (input_location) = DECL_SOURCE_LINE (decl) - 1;
+ DECL_EXTERNAL (decl) = 0;
+ TREE_STATIC (decl) = 0;
+ TREE_USED (decl) = 1;
+ DECL_CONTEXT (decl) = current_function_decl;
+ DECL_ARTIFICIAL (decl) = 1;
+ initialization_stmt = push_stmt_list();
+ cp_finish_decl (decl, block_component, 0, 0, LOOKUP_ONLYCONVERTING);
+ initialization_stmt = pop_stmt_list (initialization_stmt);
+ /* APPLE LOCAL radar 6163705 */
+ LOCATION_LINE (input_location) = save_line;
+ /* Prepend a initialization_stmt statement to the statement list. */
+ i = tsi_start (stmt);
+ tsi_link_before (&i, initialization_stmt, TSI_SAME_STMT);
+}
+
+/**
+ declare_block_prologue_local_byref_vars - utility routine to do the actual
+ declaration and initialization for each __block referenced block variable.
+ */
+static void
+declare_block_prologue_local_byref_vars (tree self_parm, tree component,
+ tree stmt)
+{
+ tree decl, block_component;
+ tree_stmt_iterator i;
+ tree decl_stmt;
+
+ decl = component;
+ block_component = build_component_ref (build_indirect_ref (self_parm, "->"),
+ DECL_NAME (component));
+ gcc_assert (block_component);
+ DECL_EXTERNAL (decl) = 0;
+ TREE_STATIC (decl) = 0;
+ TREE_USED (decl) = 1;
+ DECL_CONTEXT (decl) = current_function_decl;
+ DECL_ARTIFICIAL (decl) = 1;
+ DECL_INITIAL (decl) = block_component;
+ /* Prepend a DECL_EXPR statement to the statement list. */
+ i = tsi_start (stmt);
+ decl_stmt = build_stmt (DECL_EXPR, decl);
+ SET_EXPR_LOCATION (decl_stmt, DECL_SOURCE_LOCATION (decl));
+ /* APPLE LOCAL begin radar 6163705, Blocks prologues */
+ /* Give the prologue statements a line number of one before the beginning of
+ the function, to make them easily identifiable later. */
+ EXPR_LINENO (decl_stmt) = DECL_SOURCE_LINE (decl) - 1;
+ /* APPLE LOCAL end radar 6163705, Blocks prologues */
+ decl_stmt = build3 (BIND_EXPR, void_type_node, decl, decl_stmt, NULL);
+ TREE_SIDE_EFFECTS (decl_stmt) = 1;
+
+ tsi_link_before (&i, decl_stmt, TSI_SAME_STMT);
+}
+/* APPLE LOCAL end radar 6169527 */
+
+/**
+ block_build_prologue
+ - This routine builds the declarations for the
+ variables referenced in the block; as in:
+ int *y = .block_descriptor->y;
+ int x = .block_descriptor->x;
+
+ The decl_expr declaration for each initialization is enterred at the
+ beginning of the helper function's statement-list which is passed
+ in block_impl->block_body.
+ */
+void
+block_build_prologue (struct block_sema_info *block_impl)
+{
+ tree chain;
+ tree self_parm = lookup_name (get_identifier (".block_descriptor"));
+ gcc_assert (self_parm);
+
+ for (chain = block_impl->block_ref_decl_list; chain;
+ chain = TREE_CHAIN (chain))
+ declare_block_prologue_local_vars (self_parm, TREE_VALUE (chain),
+ block_impl->block_body);
+ /* APPLE LOCAL begin radar 6169527 */
+ for (chain = block_impl->block_byref_decl_list; chain;
+ chain = TREE_CHAIN (chain))
+ declare_block_prologue_local_byref_vars (self_parm, TREE_VALUE (chain),
+ block_impl->block_body);
+ /* APPLE LOCAL end radar 6169527 */
+}
+/* APPLE LOCAL end blocks 6040305 (ch) */
+
/* OpenMP 2.5 parsing routines. */
/* All OpenMP clauses. OpenMP 2.5. */
@@ -18881,6 +21173,7 @@ cp_parser_omp_critical (cp_parser *parser, cp_token *pragma_tok)
return c_finish_omp_critical (stmt, name);
}
+
/* OpenMP 2.5:
# pragma omp flush flush-vars[opt] new-line
diff --git a/contrib/gcc/cp/pt.c b/contrib/gcc/cp/pt.c
index 008f8f9..38a8219 100644
--- a/contrib/gcc/cp/pt.c
+++ b/contrib/gcc/cp/pt.c
@@ -7835,6 +7835,11 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl)
complain);
}
+ /* APPLE LOCAL begin blocks 6204446 */
+ case BLOCK_POINTER_TYPE:
+ return t;
+ /* APPLE LOCAL end blocks 6204446 */
+
default:
sorry ("use of %qs in template",
tree_code_name [(int) TREE_CODE (t)]);
diff --git a/contrib/gcc/cp/semantics.c b/contrib/gcc/cp/semantics.c
index c234e25..d377ad7 100644
--- a/contrib/gcc/cp/semantics.c
+++ b/contrib/gcc/cp/semantics.c
@@ -1943,6 +1943,18 @@ finish_this_expr (void)
error ("%<this%> is unavailable for static member functions");
result = error_mark_node;
}
+ /* APPLE LOCAL begin radar 6275956 */
+ else if (cur_block && current_function_decl
+ && BLOCK_SYNTHESIZED_FUNC (current_function_decl))
+ {
+ result = lookup_name (this_identifier);
+ if (!result)
+ {
+ error ("invalid use of %<this%> in a block");
+ result = error_mark_node;
+ }
+ }
+ /* APPLE LOCAL end radar 6275956 */
else
{
if (current_function_decl)
@@ -2470,6 +2482,82 @@ baselink_for_fns (tree fns)
return build_baselink (cl, cl, fns, /*optype=*/NULL_TREE);
}
+/* APPLE LOCAL begin blocks 6040305 */
+static bool
+block_var_ok_for_context (tree context)
+{
+ /* FIXME - local classes inside blocks, templates, etc */
+ struct block_sema_info *b = cur_block;
+ tree decl = current_function_decl;
+
+ /* If in a block helper, only variables from the context of the helper
+ are ok. */
+ while (b && b->helper_func_decl == decl)
+ {
+ if (context == DECL_CONTEXT (decl))
+ return true;
+ decl = DECL_CONTEXT (decl);
+ b = b->prev_block_info;
+ }
+
+ return false;
+}
+
+/* APPLE LOCAL begin radar 6545782 */
+/** This routine does all the work on use of variables in a block. */
+static tree get_final_block_variable (tree name, tree var) {
+ tree decl = var;
+
+ if (cur_block
+ && (TREE_CODE (decl) == VAR_DECL
+ || TREE_CODE (decl) == PARM_DECL)
+ && !lookup_name_in_block (name, &decl))
+ {
+ bool gdecl;
+ /* We are referencing a variable inside a block whose
+ declaration is outside. */
+ gcc_assert (decl &&
+ (TREE_CODE (decl) == VAR_DECL
+ || TREE_CODE (decl) == PARM_DECL));
+ gdecl = (TREE_CODE (decl) == VAR_DECL &&
+ (DECL_EXTERNAL (decl) || TREE_STATIC (decl)));
+ /* Treat all 'global' variables as 'byref' by default. */
+ if (gdecl
+ || (TREE_CODE (decl) == VAR_DECL && COPYABLE_BYREF_LOCAL_VAR (decl)))
+ {
+ /* byref globals are directly accessed. */
+ /* APPLE LOCAL begin radar 7760213 */
+ if (!gdecl) {
+ if (HasByrefArray(TREE_TYPE (decl)))
+ error ("cannot access __block variable of array type inside block");
+ /* build a decl for the byref variable. */
+ decl = build_block_byref_decl (name, decl, decl);
+ }
+ /* APPLE LOCAL end radar 7760213 */
+ else
+ add_block_global_byref_list (decl);
+ }
+ else
+ {
+ /* 'byref' globals are never copied-in. So, do not add
+ them to the copied-in list. */
+ if (!in_block_global_byref_list (decl)) {
+ /* APPLE LOCAL begin radar 7721728 */
+ if (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
+ error ("cannot access copied-in variable of array type inside block");
+ /* APPLE LOCAL end radar 7721728 */
+ /* build a new decl node. set its type to 'const' type
+ of the old decl. */
+ decl = build_block_ref_decl (name, decl);
+ }
+ }
+ }
+ return decl;
+}
+/* APPLE LOCAL end radar 6545782 */
+
+/* APPLE LOCAL end blocks 6040305 */
+
/* ID_EXPRESSION is a representation of parsed, but unprocessed,
id-expression. (See cp_parser_id_expression for details.) SCOPE,
if non-NULL, is the type or namespace used to explicitly qualify
@@ -2536,6 +2624,7 @@ finish_id_expression (tree id_expression,
if (decl == error_mark_node)
{
/* Name lookup failed. */
+
if (scope
&& (!TYPE_P (scope)
|| (!dependent_type_p (scope)
@@ -2576,7 +2665,10 @@ finish_id_expression (tree id_expression,
{
tree context = decl_function_context (decl);
if (context != NULL_TREE && context != current_function_decl
- && ! TREE_STATIC (decl))
+ /* APPLE LOCAL begin blocks 6040305 */
+ && ! TREE_STATIC (decl)
+ && !block_var_ok_for_context (context))
+ /* APPLE LOCAL end blocks 6040305 */
{
error (TREE_CODE (decl) == VAR_DECL
? "use of %<auto%> variable from containing function"
@@ -2852,8 +2944,21 @@ finish_id_expression (tree id_expression,
Access checking has been performed during name lookup
already. Turn off checking to avoid duplicate errors. */
push_deferring_access_checks (dk_no_check);
- decl = finish_non_static_data_member (decl, current_class_ref,
- /*qualifying_scope=*/NULL_TREE);
+ /* APPLE LOCAL begin radar 6169580 */
+ if (cur_block)
+ {
+ tree exp;
+ tree this_copiedin_var = lookup_name (this_identifier);
+ gcc_assert (!current_class_ref);
+ gcc_assert (this_copiedin_var);
+ exp = build_x_arrow (this_copiedin_var);
+ decl = build_class_member_access_expr (exp, decl, TREE_TYPE (exp),
+ /*preserve_reference=*/false);
+ }
+ else
+ decl = finish_non_static_data_member (decl, current_class_ref,
+ /*qualifying_scope=*/NULL_TREE);
+ /* APPLE LOCAL end radar 6169580 */
pop_deferring_access_checks ();
}
else if (is_overloaded_fn (decl))
@@ -2894,7 +2999,8 @@ finish_id_expression (tree id_expression,
path = currently_open_derived_class (DECL_CONTEXT (decl));
perform_or_defer_access_check (TYPE_BINFO (path), decl, decl);
}
-
+ /* APPLE LOCAL radar 6545782 */
+ decl = get_final_block_variable (id_expression, decl);
decl = convert_from_reference (decl);
}
}
@@ -2902,6 +3008,30 @@ finish_id_expression (tree id_expression,
if (TREE_DEPRECATED (decl))
warn_deprecated_use (decl);
+ /* APPLE LOCAL begin blocks 6040305 (cd) */
+ if (TREE_CODE (decl) == VAR_DECL)
+ {
+ if (BLOCK_DECL_BYREF (decl))
+ {
+ tree orig_decl = decl;
+ decl = build_indirect_ref (decl, "unary *");
+ if (COPYABLE_BYREF_LOCAL_VAR (orig_decl))
+ {
+ /* What we have is an expression which is of type
+ struct __Block_byref_X. Must get to the value of the variable
+ embedded in this structure. It is at:
+ __Block_byref_X.__forwarding->x */
+ decl = build_byref_local_var_access (decl,
+ DECL_NAME (orig_decl));
+ }
+ }
+ else
+ if (COPYABLE_BYREF_LOCAL_VAR (decl))
+ decl = build_byref_local_var_access (decl,
+ DECL_NAME (decl));
+ }
+ /* APPLE LOCAL end blocks 6040305 (cd) */
+
return decl;
}
@@ -3173,6 +3303,11 @@ expand_or_defer_fn (tree fn)
it. */
if (maybe_clone_body (fn))
{
+ /* APPLE LOCAL begin radar 6305545 */
+ /* Must lower the nested functions which could be, among other
+ things, block helper functions. */
+ lower_if_nested_functions (fn);
+ /* APPLE LOCAL end radar 6305545 */
/* We don't want to process FN again, so pretend we've written
it out, even though we haven't. */
TREE_ASM_WRITTEN (fn) = 1;
@@ -3965,6 +4100,42 @@ cxx_omp_predetermined_sharing (tree decl)
return OMP_CLAUSE_DEFAULT_UNSPECIFIED;
}
+
+/* APPLE LOCAL begin blocks 6040305 (ch) */
+tree
+begin_block (void)
+{
+ struct block_sema_info *csi;
+ tree block;
+ /* push_scope (); */
+ current_stmt_tree ()->stmts_are_full_exprs_p = 1;
+#if 0
+ block = do_pushlevel (sk_block);
+#else
+ block = NULL_TREE;
+#endif
+ csi = (struct block_sema_info*)xcalloc (1, sizeof (struct block_sema_info));
+ csi->prev_block_info = cur_block;
+ cur_block = csi;
+ return block;
+}
+
+struct block_sema_info *
+finish_block (tree block)
+{
+ struct block_sema_info *csi = cur_block;
+ cur_block = cur_block->prev_block_info;
+ /* pop_scope (); */
+#if 0
+ if (block)
+ do_poplevel (block);
+#else
+ block = 0;
+#endif
+ return csi;
+}
+/* APPLE LOCAL end blocks 6040305 (ch) */
+
void
init_cp_semantics (void)
diff --git a/contrib/gcc/cp/tree.c b/contrib/gcc/cp/tree.c
index eee9151..5575097 100644
--- a/contrib/gcc/cp/tree.c
+++ b/contrib/gcc/cp/tree.c
@@ -1717,6 +1717,15 @@ maybe_dummy_object (tree type, tree* binfop)
&& same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (current_class_ref)),
current_class_type))
decl = current_class_ref;
+ /* APPLE LOCAL begin radar 6154598 */
+ else if (cur_block)
+ {
+ tree this_copiedin_var = lookup_name (this_identifier);
+ gcc_assert (!current_class_ref);
+ gcc_assert (this_copiedin_var);
+ decl = build_x_arrow (this_copiedin_var);
+ }
+ /* APPLE LOCAL end radar 6154598 */
else
decl = build_dummy_object (context);
diff --git a/contrib/gcc/cp/typeck.c b/contrib/gcc/cp/typeck.c
index 925511b..c184a1f 100644
--- a/contrib/gcc/cp/typeck.c
+++ b/contrib/gcc/cp/typeck.c
@@ -57,7 +57,8 @@ static void casts_away_constness_r (tree *, tree *);
static bool casts_away_constness (tree, tree);
static void maybe_warn_about_returning_address_of_local (tree);
static tree lookup_destructor (tree, tree, tree);
-static tree convert_arguments (tree, tree, tree, int);
+/* APPLE LOCAL radar 6087117 */
+static tree convert_arguments (tree, tree, tree, int, int);
/* Do `exp = require_complete_type (exp);' to make sure exp
does not have an incomplete type. (That includes void types.)
@@ -406,7 +407,8 @@ composite_pointer_type_r (tree t1, tree t2, const char* location)
tree attributes;
/* Determine the types pointed to by T1 and T2. */
- if (TREE_CODE (t1) == POINTER_TYPE)
+ /* APPLE LOCAL blocks 6040305 */
+ if (TREE_CODE (t1) == POINTER_TYPE || TREE_CODE (t1) == BLOCK_POINTER_TYPE)
{
pointee1 = TREE_TYPE (t1);
pointee2 = TREE_TYPE (t2);
@@ -453,8 +455,13 @@ composite_pointer_type_r (tree t1, tree t2, const char* location)
result_type = build_ptrmem_type (TYPE_PTRMEM_CLASS_TYPE (t1),
result_type);
}
+ /* APPLE LOCAL begin blocks 6065211 */
+ else if (TREE_CODE (t1) == BLOCK_POINTER_TYPE
+ && result_type != void_type_node)
+ result_type = build_block_pointer_type (result_type);
else
result_type = build_pointer_type (result_type);
+ /* APPLE LOCAL end blocks 6065211 */
/* Merge the attributes. */
attributes = (*targetm.merge_type_attributes) (t1, t2);
@@ -524,8 +531,10 @@ 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;
+ /* APPLE LOCAL radar 4229905 - radar 6231433 */
+ if (objc_have_common_type (t1, t2, -3, NULL_TREE, location))
+ /* APPLE LOCAL 4154928 */
+ return objc_common_type (t1, t2);
}
/* [expr.eq] permits the application of a pointer conversion to
@@ -572,6 +581,14 @@ composite_pointer_type (tree t1, tree t2, tree arg1, tree arg2,
return error_mark_node;
}
}
+ /* APPLE LOCAL begin blocks 6065211 */
+ else if (TREE_CODE (t1) != TREE_CODE (t2))
+ {
+ error ("%s between distinct pointer types %qT and %qT "
+ "lacks a cast", location, t1, t2);
+ return error_mark_node;
+ }
+ /* APPLE LOCAL end blocks 6065211 */
return composite_pointer_type_r (t1, t2, location);
}
@@ -1039,6 +1056,21 @@ comptypes (tree t1, tree t2, int strict)
return false;
break;
+ /* APPLE LOCAL begin blocks 6040305 */
+ case BLOCK_POINTER_TYPE:
+ if (TREE_CODE (t2) == BLOCK_POINTER_TYPE)
+ {
+ tree pt1 = TREE_TYPE (t1);
+ tree pt2 = TREE_TYPE (t2);
+ if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (pt1),
+ TREE_TYPE (pt2)))
+ return false;
+ if (!compparms (TYPE_ARG_TYPES (pt1), TYPE_ARG_TYPES (pt2)))
+ return false;
+ break;
+ }
+ /* APPLE LOCAL end blocks 6040305 */
+
case POINTER_TYPE:
case REFERENCE_TYPE:
if (TYPE_MODE (t1) != TYPE_MODE (t2)
@@ -2662,6 +2694,53 @@ get_member_function_from_ptrfunc (tree *instance_ptrptr, tree function)
return function;
}
+/* APPLE LOCAL begin blocks 6040305 (cm) */
+/* APPLE LOCAL begin radar 5847213 - radar 6329245 */
+/**
+ build_block_call - Routine to build a block call; as in:
+ ((double(*)(void *, int))(BLOCK_PTR_EXP->__FuncPtr))(I, 42);
+ FNTYPE is the original function type derived from the syntax.
+ BLOCK_PTR_EXP is the block pointer variable.
+ PARAMS is the parameter list.
+*/
+static tree
+build_block_call (tree fntype, tree block_ptr_exp, tree params)
+{
+ tree function_ptr_exp;
+ tree typelist;
+ tree result;
+ /* APPLE LOCAL radar 6396238 */
+ bool block_ptr_exp_side_effect = TREE_SIDE_EFFECTS (block_ptr_exp);
+
+ /* First convert it to 'void *'. */
+ block_ptr_exp = convert (ptr_type_node, block_ptr_exp);
+ gcc_assert (generic_block_literal_struct_type);
+ block_ptr_exp = convert (build_pointer_type (generic_block_literal_struct_type),
+ block_ptr_exp);
+ if (block_ptr_exp_side_effect)
+ block_ptr_exp = save_expr (block_ptr_exp);
+
+ /* BLOCK_PTR_VAR->__FuncPtr */
+ function_ptr_exp =
+ finish_class_member_access_expr (build_indirect_ref (block_ptr_exp, "->"),
+ get_identifier ("__FuncPtr"), false);
+ gcc_assert (function_ptr_exp);
+
+ /* Build: result_type(*)(void *, function-arg-type-list) */
+ typelist = TYPE_ARG_TYPES (fntype);
+ typelist = tree_cons (NULL_TREE, ptr_type_node, typelist);
+ fntype = build_function_type (TREE_TYPE (fntype), typelist);
+ function_ptr_exp = convert (build_pointer_type (fntype), function_ptr_exp);
+ params = tree_cons (NULL_TREE, block_ptr_exp, params);
+ result = build3 (CALL_EXPR, TREE_TYPE (fntype),
+ function_ptr_exp, params, NULL_TREE);
+ /* FIXME: should do more from build_cxx_call */
+ result = convert_from_reference (result);
+ return result;
+}
+/* APPLE LOCAL end radar 5847213 - radar 6329245 */
+/* APPLE LOCAL end blocks 6040305 (cm) */
+
tree
build_function_call (tree function, tree params)
{
@@ -2724,7 +2803,8 @@ build_function_call (tree function, tree params)
is_method = (TREE_CODE (fntype) == POINTER_TYPE
&& TREE_CODE (TREE_TYPE (fntype)) == METHOD_TYPE);
- if (!((TREE_CODE (fntype) == POINTER_TYPE
+ /* APPLE LOCAL blocks 6040305 */
+ if (!(((TREE_CODE (fntype) == POINTER_TYPE || TREE_CODE (fntype) == BLOCK_POINTER_TYPE)
&& TREE_CODE (TREE_TYPE (fntype)) == FUNCTION_TYPE)
|| is_method
|| TREE_CODE (function) == TEMPLATE_ID_EXPR))
@@ -2739,8 +2819,11 @@ build_function_call (tree function, tree params)
/* Convert the parameters to the types declared in the
function prototype, or apply default promotions. */
+ /* APPLE LOCAL begin radar 6087117 */
coerced_params = convert_arguments (TYPE_ARG_TYPES (fntype),
- params, fndecl, LOOKUP_NORMAL);
+ params, fndecl, LOOKUP_NORMAL,
+ (TREE_CODE (TREE_TYPE (function)) == BLOCK_POINTER_TYPE));
+ /* APPLE LOCAL end radar 6087117 */
if (coerced_params == error_mark_node)
return error_mark_node;
@@ -2749,10 +2832,14 @@ build_function_call (tree function, tree params)
check_function_arguments (TYPE_ATTRIBUTES (fntype), coerced_params,
TYPE_ARG_TYPES (fntype));
+ /* APPLE LOCAL begin blocks 6040305 */
+ if (TREE_CODE (TREE_TYPE (function)) == BLOCK_POINTER_TYPE)
+ return build_block_call (fntype, function, coerced_params);
+ /* APPLE LOCAL end blocks 6040305 */
return build_cxx_call (function, coerced_params);
}
-
+
/* Convert the actual parameter expressions in the list VALUES
to the types in the list TYPELIST.
If parmdecls is exhausted, or when an element has NULL as its type,
@@ -2771,7 +2858,8 @@ build_function_call (tree function, tree params)
default arguments, if such were specified. Do so here. */
static tree
-convert_arguments (tree typelist, tree values, tree fndecl, int flags)
+/* APPLE LOCAL radar 6087117 */
+convert_arguments (tree typelist, tree values, tree fndecl, int flags, int block_call)
{
tree typetail, valtail;
tree result = NULL_TREE;
@@ -2813,7 +2901,8 @@ convert_arguments (tree typelist, tree values, tree fndecl, int flags)
error ("at this point in file");
}
else
- error ("too many arguments to function");
+ /* APPLE LOCAL radar 6087117 */
+ error ("too many arguments to %s", (block_call ? "block call" : "function"));
/* In case anybody wants to know if this argument
list is valid. */
if (result)
@@ -2915,7 +3004,8 @@ convert_arguments (tree typelist, tree values, tree fndecl, int flags)
error ("at this point in file");
}
else
- error ("too few arguments to function");
+ /* APPLE LOCAL radar 6087117 */
+ error ("too few arguments to %s", (block_call ? "block call" : "function"));
return error_mark_node;
}
}
@@ -3314,22 +3404,29 @@ build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
&& (code1 == INTEGER_TYPE || code1 == REAL_TYPE
|| code1 == COMPLEX_TYPE))
short_compare = 1;
- else if ((code0 == POINTER_TYPE && code1 == POINTER_TYPE)
+ /* APPLE LOCAL begin blocks 6040305 */
+ else if (((code0 == POINTER_TYPE || code0 == BLOCK_POINTER_TYPE)
+ && (code1 == POINTER_TYPE || code1 == BLOCK_POINTER_TYPE))
|| (TYPE_PTRMEM_P (type0) && TYPE_PTRMEM_P (type1)))
+ /* APPLE LOCAL end blocks 6040305 */
result_type = composite_pointer_type (type0, type1, op0, op1,
"comparison");
- else if ((code0 == POINTER_TYPE || TYPE_PTRMEM_P (type0))
+ /* APPLE LOCAL blocks 6040305 (cl) */
+ else if ((code0 == POINTER_TYPE || code0 == BLOCK_POINTER_TYPE || TYPE_PTRMEM_P (type0))
&& null_ptr_cst_p (op1))
result_type = type0;
- else if ((code1 == POINTER_TYPE || TYPE_PTRMEM_P (type1))
+ /* APPLE LOCAL blocks 6040305 (cl) */
+ else if ((code1 == POINTER_TYPE || code1 == BLOCK_POINTER_TYPE || TYPE_PTRMEM_P (type1))
&& null_ptr_cst_p (op0))
result_type = type1;
- else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
+ /* APPLE LOCAL blocks 6040305 (cl) */
+ else if ((code0 == POINTER_TYPE || code0 == BLOCK_POINTER_TYPE) && code1 == INTEGER_TYPE)
{
result_type = type0;
error ("ISO C++ forbids comparison between pointer and integer");
}
- else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE)
+ /* APPLE LOCAL blocks 6040305 (cl) */
+ else if (code0 == INTEGER_TYPE && (code1 == POINTER_TYPE || code1 == BLOCK_POINTER_TYPE))
{
result_type = type1;
error ("ISO C++ forbids comparison between pointer and integer");
@@ -5247,6 +5344,30 @@ build_reinterpret_cast_1 (tree type, tree expr, bool c_cast_p,
else if (TYPE_PTR_P (type) && INTEGRAL_OR_ENUMERATION_TYPE_P (intype))
/* OK */
;
+ /* APPLE LOCAL begin blocks 6040305 (ck) */
+ else if (TREE_CODE (type) == INTEGER_TYPE && TREE_CODE (intype) == BLOCK_POINTER_TYPE)
+ {
+ if (TYPE_PRECISION (type) < TYPE_PRECISION (intype))
+ pedwarn ("cast from %qT to %qT loses precision",
+ intype, type);
+ }
+ else if (TREE_CODE (type) == BLOCK_POINTER_TYPE && TREE_CODE (intype) == INTEGER_TYPE)
+ /* OK */
+ ;
+ else if (TREE_CODE (type) == BLOCK_POINTER_TYPE && TREE_CODE (intype) == BLOCK_POINTER_TYPE)
+ /* OK */
+ ;
+ else if (TREE_CODE (intype) == BLOCK_POINTER_TYPE
+ && (objc_is_id (type)
+ || (TREE_CODE (type) == POINTER_TYPE && VOID_TYPE_P (TREE_TYPE (type)))))
+ /* OK */
+ ;
+ else if (TREE_CODE (type) == BLOCK_POINTER_TYPE
+ && TREE_CODE (intype) == POINTER_TYPE
+ && (objc_is_id (intype) || VOID_TYPE_P (TREE_TYPE (intype))))
+ /* OK */
+ ;
+ /* APPLE LOCAL end blocks 6040305 (ck) */
else if ((TYPE_PTRFN_P (type) && TYPE_PTRFN_P (intype))
|| (TYPE_PTRMEMFUNC_P (type) && TYPE_PTRMEMFUNC_P (intype)))
return fold_if_not_in_template (build_nop (type, expr));
@@ -5300,6 +5421,14 @@ build_reinterpret_cast_1 (tree type, tree expr, bool c_cast_p,
return error_mark_node;
}
+ /* APPLE LOCAL begin don't sign-extend pointers cast to integers */
+ if (TREE_CODE (type) == INTEGER_TYPE
+ && TREE_CODE (intype) == POINTER_TYPE
+ && TYPE_PRECISION (type) > TYPE_PRECISION (intype)
+ && TYPE_UNSIGNED (type))
+ expr = cp_convert (c_common_type_for_size (POINTER_SIZE, 1), expr);
+ /* APPLE LOCAL end don't sign-extend pointers cast to integers */
+
return cp_convert (type, expr);
}
@@ -5725,6 +5854,19 @@ build_modify_expr (tree lhs, enum tree_code modifycode, tree rhs)
return error_mark_node;
return result;
}
+ /* APPLE LOCAL end C* property (Radar 4436866) */
+ /* `operator=' is not an inheritable operator. */
+ if (! IS_AGGR_TYPE (lhstype))
+ /* Do the default thing. */;
+ else
+ {
+ result = build_new_op (MODIFY_EXPR, LOOKUP_NORMAL,
+ lhs, rhs, make_node (NOP_EXPR),
+ /*overloaded_p=*/NULL);
+ if (result == NULL_TREE)
+ return error_mark_node;
+ return result;
+ }
lhstype = olhstype;
}
else
@@ -5745,6 +5887,7 @@ build_modify_expr (tree lhs, enum tree_code modifycode, tree rhs)
/* Now it looks like a plain assignment. */
modifycode = NOP_EXPR;
+ lhstype = olhstype;
}
gcc_assert (TREE_CODE (lhstype) != REFERENCE_TYPE);
gcc_assert (TREE_CODE (TREE_TYPE (newrhs)) != REFERENCE_TYPE);
@@ -5898,10 +6041,47 @@ build_modify_expr (tree lhs, enum tree_code modifycode, tree rhs)
tree
build_x_modify_expr (tree lhs, enum tree_code modifycode, tree rhs)
{
+ /* APPLE LOCAL __block assign sequence point 6639533 */
+ bool insert_sequence_point = false;
+
if (processing_template_decl)
return build_min_nt (MODOP_EXPR, lhs,
build_min_nt (modifycode, NULL_TREE, NULL_TREE), rhs);
+ /* APPLE LOCAL begin __block assign sequence point 6639533 */
+ /* For byref = x;, we have to transform this into ({ typeof(x) x' =
+ x; byref = x`; )} to ensure there is a sequence point before the
+ evaluation of the byref, inorder to ensure that the access
+ expression for byref doesn't start running before x is evaluated,
+ as it will access the __forwarding pointer and that must be done
+ after x is evaluated. */
+ /* First we check to see if lhs is a byref... byrefs look like:
+ __Block_byref_X.__forwarding->x */
+ if (TREE_CODE (lhs) == COMPONENT_REF)
+ {
+ tree inner = TREE_OPERAND (lhs, 0);
+ /* now check for -> */
+ if (TREE_CODE (inner) == INDIRECT_REF)
+ {
+ inner = TREE_OPERAND (inner, 0);
+ if (TREE_CODE (inner) == COMPONENT_REF)
+ {
+ inner = TREE_OPERAND (inner, 0);
+ if (TREE_CODE (inner) == VAR_DECL
+ && COPYABLE_BYREF_LOCAL_VAR (inner))
+ {
+ tree old_rhs = rhs;
+ /* then we save the rhs. */
+ rhs = save_expr (rhs);
+ if (rhs != old_rhs)
+ /* And arrange for the sequence point to be inserted. */
+ insert_sequence_point = true;
+ }
+ }
+ }
+ }
+ /* APPLE LOCAL end __block assign sequence point 6639533 */
+
if (modifycode != NOP_EXPR)
{
tree rval = build_new_op (MODIFY_EXPR, LOOKUP_NORMAL, lhs, rhs,
@@ -5909,11 +6089,20 @@ build_x_modify_expr (tree lhs, enum tree_code modifycode, tree rhs)
/*overloaded_p=*/NULL);
if (rval)
{
+ /* APPLE LOCAL begin __block assign sequence point 6639533 */
+ if (insert_sequence_point)
+ rval = build2 (COMPOUND_EXPR, TREE_TYPE (rval), rhs, rval);
+ /* APPLE LOCAL end __block assign sequence point 6639533 */
TREE_NO_WARNING (rval) = 1;
return rval;
}
}
- return build_modify_expr (lhs, modifycode, rhs);
+ lhs = build_modify_expr (lhs, modifycode, rhs);
+ /* APPLE LOCAL begin __block assign sequence point 6639533 */
+ if (insert_sequence_point)
+ lhs = build2 (COMPOUND_EXPR, TREE_TYPE (lhs), rhs, lhs);
+ /* APPLE LOCAL end __block assign sequence point 6639533 */
+ return lhs;
}
@@ -6220,6 +6409,8 @@ convert_for_assignment (tree type, tree rhs,
{
tree rhstype;
enum tree_code coder;
+ /* APPLE LOCAL radar 4874632 */
+ tree new_rhs = NULL_TREE;
/* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
if (TREE_CODE (rhs) == NON_LVALUE_EXPR)
@@ -6270,8 +6461,10 @@ convert_for_assignment (tree type, tree rhs,
}
}
- if (objc_compare_types (type, rhstype, parmno, rname))
- return convert (type, rhs);
+ /* APPLE LOCAL file radar 6231433 */
+ if (objc_compare_types (type, rhstype, parmno, rname, "comparison"))
+ /* APPLE LOCAL radar 4874632 */
+ new_rhs = convert (type, rhs);
}
/* [expr.ass]
@@ -6477,6 +6670,10 @@ maybe_warn_about_returning_address_of_local (tree retval)
if (TREE_CODE (valtype) == REFERENCE_TYPE)
warning (0, "reference to local variable %q+D returned",
whats_returned);
+ /* APPLE LOCAL begin blocks 6040305 (cn) */
+ else if (TREE_CODE (valtype) == BLOCK_POINTER_TYPE)
+ error ("returning block that lives on the local stack");
+ /* APPLE LOCAL end blocks 6040305 (cn) */
else
warning (0, "address of local variable %q+D returned",
whats_returned);
@@ -6484,6 +6681,14 @@ maybe_warn_about_returning_address_of_local (tree retval)
}
}
+/* APPLE LOCAL begin blocks 6040305 (cm) */
+static bool
+types_are_block_compatible (tree t1, tree t2)
+{
+ return comptypes (t1, t2, COMPARE_STRICT);
+}
+/* APPLE LOCAL end blocks 6040305 (cm) */
+
/* Check that returning RETVAL from the current function is valid.
Return an expression explicitly showing all conversions required to
change RETVAL into the function return type, and to assign it to
@@ -6527,6 +6732,64 @@ check_return_expr (tree retval, bool *no_warning)
return NULL_TREE;
}
+ /* APPLE LOCAL begin blocks 6040305 (cm) */
+ /* APPLE LOCAL radar 6185344 */
+ if (cur_block && !cur_block->block_has_return_type)
+ {
+ /* If this is the first return we've seen in the block, infer the type of
+ the block from it. */
+ if (cur_block->return_type == NULL_TREE)
+ {
+ if (retval)
+ {
+ tree restype;
+ retval = decay_conversion (retval);
+ restype = TYPE_MAIN_VARIANT (TREE_TYPE (retval));
+ TREE_TYPE (current_function_decl)
+ = build_function_type (restype,
+ TYPE_ARG_TYPES (TREE_TYPE (current_function_decl)));
+ TREE_TYPE (DECL_RESULT (current_function_decl)) = restype;
+ relayout_decl (DECL_RESULT (current_function_decl));
+ cur_block->return_type = restype;
+ }
+ else
+ cur_block->return_type = void_type_node;
+ }
+
+ /* Verify that this result type matches the previous one. We
+ are pickier with blocks than for normal functions because
+ this is a new feature and we set the rules. */
+ if (TREE_CODE (cur_block->return_type) == VOID_TYPE)
+ {
+ if (retval)
+ {
+ error ("void block should not return a value");
+ return error_mark_node;
+ }
+ }
+ else if (!retval)
+ {
+ error ("non-void block should return a value");
+ return error_mark_node;
+ }
+
+ if (retval)
+ {
+ /* We have a non-void block with an expression, continue checking. */
+ valtype = TREE_TYPE (retval);
+
+ /* For now, restrict multiple return statements in a block to have
+ strict compatible types only. */
+ if (!types_are_block_compatible (cur_block->return_type, valtype))
+ {
+ error ("incompatible type returning %qT, expected %qT",
+ valtype, cur_block->return_type);
+ return error_mark_node;
+ }
+ }
+ }
+ /* APPLE LOCAL end blocks 6040305 (cm) */
+
if (processing_template_decl)
{
current_function_returns_value = 1;
OpenPOWER on IntegriCloud