summaryrefslogtreecommitdiffstats
path: root/contrib/gcc/cp/decl2.c
diff options
context:
space:
mode:
authorpfg <pfg@FreeBSD.org>2014-01-05 00:43:28 +0000
committerpfg <pfg@FreeBSD.org>2014-01-05 00:43:28 +0000
commit9c8bbe68490d277cf64459b3390cf48e2a09ddf6 (patch)
treefffd69b9133b091a53ee14b3de5fd5006d53f92a /contrib/gcc/cp/decl2.c
parentc5e9a8143da358a2c480a64c9782d5eedda3b002 (diff)
downloadFreeBSD-src-9c8bbe68490d277cf64459b3390cf48e2a09ddf6.zip
FreeBSD-src-9c8bbe68490d277cf64459b3390cf48e2a09ddf6.tar.gz
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 that __block is not actually a keyword, but a macro. There will be workaround for this issue in a near 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. Reference: [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 MFC after: 3 weeks
Diffstat (limited to 'contrib/gcc/cp/decl2.c')
-rw-r--r--contrib/gcc/cp/decl2.c129
1 files changed, 96 insertions, 33 deletions
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 ();
OpenPOWER on IntegriCloud