tested on x86_64-linux, darwin, i686-darwin, pushed to trunk,
thanks
Iain
--- 8< ---
This is preparation for the main part of the fix of the PR, in this we
make sure to build decls with language-specific data when the compiler
is Objective-c++. This is because Objective-C metadata are extern "C"
and that needs the lang-specific-data to record it.
PR objc/124260
gcc/objc/ChangeLog:
* objc-act.cc (objc_create_temporary_var, objc_build_struct,
synth_module_prologue, objc_build_internal_const_str_type,
objc_begin_catch_clause, objc_push_parm, synth_self_and_ucmd_args,
start_method_def, objc_start_function,
get_super_receiver): Use build_lang_decl for Objective-C++.
* objc-act.h (objc_build_decl): New.
* objc-gnu-runtime-abi-01.cc (gnu_runtime_01_initialize,
objc_add_static_instance, handle_class_ref): use build_lang_decl
for Objective-C++.
* objc-next-runtime-abi-01.cc (next_runtime_01_initialize,
next_runtime_abi_01_build_const_string_constructor): Likewise.
* objc-next-runtime-abi-02.cc (next_runtime_02_initialize,
next_runtime_abi_02_build_const_string_constructor): Likewise.
* objc-runtime-shared-support.cc (create_field_decl,
start_var_decl): Likewise.
Signed-off-by: Iain Sandoe <[email protected]>
---
gcc/objc/objc-act.cc | 34 ++++++++++++-------------
gcc/objc/objc-act.h | 14 ++++++++++
gcc/objc/objc-gnu-runtime-abi-01.cc | 12 ++++-----
gcc/objc/objc-next-runtime-abi-01.cc | 6 ++---
gcc/objc/objc-next-runtime-abi-02.cc | 4 +--
gcc/objc/objc-runtime-shared-support.cc | 4 +--
6 files changed, 44 insertions(+), 30 deletions(-)
diff --git a/gcc/objc/objc-act.cc b/gcc/objc/objc-act.cc
index f656037f4d7..f41a8b42b6d 100644
--- a/gcc/objc/objc-act.cc
+++ b/gcc/objc/objc-act.cc
@@ -272,12 +272,12 @@ objc_create_temporary_var (tree type, const char *name)
if (name != NULL)
{
- decl = build_decl (input_location,
+ decl = objc_build_decl (input_location,
VAR_DECL, get_identifier (name), type);
}
else
{
- decl = build_decl (input_location,
+ decl = objc_build_decl (input_location,
VAR_DECL, NULL_TREE, type);
}
TREE_USED (decl) = 1;
@@ -2230,7 +2230,7 @@ objc_build_struct (tree klass, tree fields, tree
super_name)
{
/* Prepend a packed variant of the base class into the layout. This
is necessary to preserve ObjC ABI compatibility. */
- tree base = build_decl (input_location,
+ tree base = objc_build_decl (input_location,
FIELD_DECL, NULL_TREE, super);
tree field = TYPE_FIELDS (super);
@@ -3110,19 +3110,19 @@ synth_module_prologue (void)
objc_selector_name = get_identifier (SEL_TYPEDEF_NAME);
/* Declare the 'id', 'instancetype' and 'Class' typedefs. */
- type = lang_hooks.decls.pushdecl (build_decl (input_location,
+ type = lang_hooks.decls.pushdecl (objc_build_decl (input_location,
TYPE_DECL,
objc_object_name,
objc_object_type));
suppress_warning (type);
- type = lang_hooks.decls.pushdecl (build_decl (input_location,
+ type = lang_hooks.decls.pushdecl (objc_build_decl (input_location,
TYPE_DECL,
objc_instancetype_name,
objc_instancetype_type));
suppress_warning (type);
- type = lang_hooks.decls.pushdecl (build_decl (input_location,
+ type = lang_hooks.decls.pushdecl (objc_build_decl (input_location,
TYPE_DECL,
objc_class_name,
objc_class_type));
@@ -3234,13 +3234,13 @@ static tree
objc_build_internal_const_str_type (void)
{
tree type = (*lang_hooks.types.make_type) (RECORD_TYPE);
- tree fields = build_decl (input_location,
+ tree fields = objc_build_decl (input_location,
FIELD_DECL, NULL_TREE, ptr_type_node);
- tree field = build_decl (input_location,
+ tree field = objc_build_decl (input_location,
FIELD_DECL, NULL_TREE, ptr_type_node);
DECL_CHAIN (field) = fields; fields = field;
- field = build_decl (input_location,
+ field = objc_build_decl (input_location,
FIELD_DECL, NULL_TREE, unsigned_type_node);
DECL_CHAIN (field) = fields; fields = field;
/* NB: The finish_builtin_struct() routine expects FIELD_DECLs in
@@ -4345,7 +4345,7 @@ objc_begin_catch_clause (tree decl)
else
{
/* The parser passed in a PARM_DECL, but what we really want is a
VAR_DECL. */
- decl = build_decl (input_location,
+ decl = objc_build_decl (input_location,
VAR_DECL, DECL_NAME (decl), TREE_TYPE (decl));
}
lang_hooks.decls.pushdecl (decl);
@@ -8455,7 +8455,7 @@ objc_push_parm (tree parm)
/* If the parameter type has been decayed, a new PARM_DECL needs to be
built as well. */
if (type != TREE_TYPE (parm))
- parm = build_decl (input_location, PARM_DECL, DECL_NAME (parm), type);
+ parm = objc_build_decl (input_location, PARM_DECL, DECL_NAME (parm), type);
DECL_ARG_TYPE (parm)
= lang_hooks.types.type_promotes_to (TREE_TYPE (parm));
@@ -8527,11 +8527,11 @@ synth_self_and_ucmd_args (void)
self_type = objc_object_type;
/* id self; */
- objc_push_parm (build_decl (input_location,
+ objc_push_parm (objc_build_decl (input_location,
PARM_DECL, self_id, self_type));
/* SEL _cmd; */
- objc_push_parm (build_decl (input_location,
+ objc_push_parm (objc_build_decl (input_location,
PARM_DECL, ucmd_id, objc_selector_type));
}
@@ -8576,7 +8576,7 @@ start_method_def (tree method, tree expr)
tree type = TREE_VALUE (TREE_TYPE (parmlist));
tree parm;
- parm = build_decl (input_location,
+ parm = objc_build_decl (input_location,
PARM_DECL, KEYWORD_ARG_NAME (parmlist), type);
decl_attributes (&parm, DECL_ATTRIBUTES (parmlist), 0);
objc_push_parm (parm);
@@ -8813,7 +8813,7 @@ objc_start_function (tree name, tree type, tree attrs,
#endif
)
{
- tree fndecl = build_decl (input_location,
+ tree fndecl = objc_build_decl (input_location,
FUNCTION_DECL, name, type);
#ifdef OBJCPLUS
@@ -8836,7 +8836,7 @@ objc_start_function (tree name, tree type, tree attrs,
push_scope ();
declare_parm_level ();
DECL_RESULT (current_function_decl)
- = build_decl (input_location,
+ = objc_build_decl (input_location,
RESULT_DECL, NULL_TREE,
TREE_TYPE (TREE_TYPE (current_function_decl)));
DECL_ARTIFICIAL (DECL_RESULT (current_function_decl)) = 1;
@@ -8993,7 +8993,7 @@ get_super_receiver (void)
bool inst_meth;
if (!UOBJC_SUPER_decl)
{
- UOBJC_SUPER_decl = build_decl (input_location,
+ UOBJC_SUPER_decl = objc_build_decl (input_location,
VAR_DECL, get_identifier (TAG_SUPER),
objc_super_template);
/* This prevents `unused variable' warnings when compiling with -Wall.
*/
diff --git a/gcc/objc/objc-act.h b/gcc/objc/objc-act.h
index 39cdf6847e1..6bcd9ff4b1f 100644
--- a/gcc/objc/objc-act.h
+++ b/gcc/objc/objc-act.h
@@ -778,4 +778,18 @@ is_ivar (tree decl_chain, tree ident)
return NULL_TREE;
}
+
+#ifdef OBJCPLUS
+inline tree
+objc_build_decl (location_t l, enum tree_code c, tree n, tree t)
+{
+ return build_lang_decl_loc (l, c, n, t);
+}
+#else
+inline tree
+objc_build_decl (location_t l, enum tree_code c, tree n, tree t)
+{
+ return build_decl (l, c, n, t);
+}
+#endif
#endif /* GCC_OBJC_ACT_H */
diff --git a/gcc/objc/objc-gnu-runtime-abi-01.cc
b/gcc/objc/objc-gnu-runtime-abi-01.cc
index 1f75c6d2dd7..333882d1344 100644
--- a/gcc/objc/objc-gnu-runtime-abi-01.cc
+++ b/gcc/objc/objc-gnu-runtime-abi-01.cc
@@ -209,7 +209,7 @@ static void gnu_runtime_01_initialize (void)
objc_selector_type = build_pointer_type (type);
/* SEL typedef. */
- type = lang_hooks.decls.pushdecl (build_decl (input_location,
+ type = lang_hooks.decls.pushdecl (objc_build_decl (input_location,
TYPE_DECL,
objc_selector_name,
objc_selector_type));
@@ -890,7 +890,7 @@ objc_add_static_instance (tree constructor, tree class_decl)
}
snprintf (buf, BUFSIZE, "_OBJC_INSTANCE_%d", num_static_inst++);
- decl = build_decl (input_location,
+ decl = objc_build_decl (input_location,
VAR_DECL, get_identifier (buf), class_decl);
TREE_STATIC (decl) = 1;
DECL_ARTIFICIAL (decl) = 1;
@@ -953,7 +953,7 @@ build_module_initializer_routine (void)
push_lang_context (lang_name_c); /* extern "C" */
#endif
- objc_push_parm (build_decl (input_location,
+ objc_push_parm (objc_build_decl (input_location,
PARM_DECL, NULL_TREE, void_type_node));
#ifdef OBJCPLUS
objc_start_function (get_identifier (TAG_GNUINIT),
@@ -1757,9 +1757,9 @@ handle_class_ref (tree chain)
sprintf (string, "__objc_class_name_%s", name);
- /* Make a decl for this name, so we can use its address in a tree. */
- decl = build_decl (input_location,
- VAR_DECL, get_identifier (string), TREE_TYPE
(integer_zero_node));
+ /* Make a forward declaration for this name, so we can use its address. */
+ decl = objc_build_decl (input_location, VAR_DECL,
+ get_identifier (string), integer_type_node);
DECL_EXTERNAL (decl) = 1;
TREE_PUBLIC (decl) = 1;
DECL_CONTEXT (decl) = NULL_TREE;
diff --git a/gcc/objc/objc-next-runtime-abi-01.cc
b/gcc/objc/objc-next-runtime-abi-01.cc
index 15cbcc10aaa..de115694ead 100644
--- a/gcc/objc/objc-next-runtime-abi-01.cc
+++ b/gcc/objc/objc-next-runtime-abi-01.cc
@@ -272,7 +272,7 @@ static void next_runtime_01_initialize (void)
get_identifier (TAG_SELECTOR)));
/* SEL typedef. */
- type = lang_hooks.decls.pushdecl (build_decl (input_location,
+ type = lang_hooks.decls.pushdecl (objc_build_decl (input_location,
TYPE_DECL,
objc_selector_name,
objc_selector_type));
@@ -1011,7 +1011,7 @@ static tree
next_runtime_abi_01_build_const_string_constructor (location_t loc, tree
string,
int length)
{
- tree constructor, fields, var;
+ tree constructor, fields;
vec<constructor_elt, va_gc> *v = NULL;
/* NeXT: (NSConstantString *) & ((__builtin_ObjCString) { isa, string,
length }) */
@@ -1028,7 +1028,7 @@ next_runtime_abi_01_build_const_string_constructor
(location_t loc, tree string,
CONSTRUCTOR_APPEND_ELT (v, fields, build_int_cst (NULL_TREE, length));
constructor = objc_build_constructor (internal_const_str_type, v);
- var = build_decl (input_location, CONST_DECL, NULL, TREE_TYPE (constructor));
+ tree var = objc_build_decl (loc, CONST_DECL, NULL, TREE_TYPE (constructor));
DECL_INITIAL (var) = constructor;
TREE_STATIC (var) = 1;
DECL_CONTEXT (var) = NULL;
diff --git a/gcc/objc/objc-next-runtime-abi-02.cc
b/gcc/objc/objc-next-runtime-abi-02.cc
index ab295d281f8..0ca1d86311c 100644
--- a/gcc/objc/objc-next-runtime-abi-02.cc
+++ b/gcc/objc/objc-next-runtime-abi-02.cc
@@ -374,7 +374,7 @@ static void next_runtime_02_initialize (void)
get_identifier (TAG_SELECTOR)));
/* SEL typedef. */
- type = lang_hooks.decls.pushdecl (build_decl (input_location,
+ type = lang_hooks.decls.pushdecl (objc_build_decl (input_location,
TYPE_DECL,
objc_selector_name,
objc_selector_type));
@@ -1940,7 +1940,7 @@ next_runtime_abi_02_build_const_string_constructor
(location_t loc, tree string,
CONSTRUCTOR_APPEND_ELT (v, fields, build_int_cst (NULL_TREE, length));
constructor = objc_build_constructor (internal_const_str_type, v);
- var = build_decl (input_location, CONST_DECL, NULL, TREE_TYPE (constructor));
+ var = objc_build_decl (input_location, CONST_DECL, NULL, TREE_TYPE
(constructor));
DECL_INITIAL (var) = constructor;
TREE_STATIC (var) = 1;
DECL_CONTEXT (var) = NULL;
diff --git a/gcc/objc/objc-runtime-shared-support.cc
b/gcc/objc/objc-runtime-shared-support.cc
index 994c341f4a7..d75b21c98d7 100644
--- a/gcc/objc/objc-runtime-shared-support.cc
+++ b/gcc/objc/objc-runtime-shared-support.cc
@@ -90,7 +90,7 @@ build_sized_array_type (tree base_type, int size)
static tree
create_field_decl (tree type, const char *name)
{
- return build_decl (input_location,
+ return objc_build_decl (input_location,
FIELD_DECL, get_identifier (name), type);
}
@@ -113,7 +113,7 @@ tree
start_var_decl (tree type, const char *name)
{
tree name_id = get_identifier (name);
- tree var = build_decl (input_location, VAR_DECL, name_id, type);
+ tree var = objc_build_decl (input_location, VAR_DECL, name_id, type);
DECL_INITIAL (var) = error_mark_node; /* A real initializer is coming... */
TREE_STATIC (var) = 1;
DECL_IGNORED_P (var) = 1;
--
2.50.1 (Apple Git-155)