diff --git a/gcc/ipa-struct-reorg/ipa-struct-reorg.c b/gcc/ipa-struct-reorg/ipa-struct-reorg.c index 8d3da35400de0d468af69516d48d7e6d5ed43602..54c20ca3f33756409d31f935761dfe7331553373 100644 --- a/gcc/ipa-struct-reorg/ipa-struct-reorg.c +++ b/gcc/ipa-struct-reorg/ipa-struct-reorg.c @@ -104,6 +104,42 @@ along with GCC; see the file COPYING3. If not see #define VOID_POINTER_P(type) (POINTER_TYPE_P (type) && VOID_TYPE_P (TREE_TYPE (type))) +/* Check whether in C language or LTO with only C language. */ +bool +lang_c_p (void) +{ + const char *language_string = lang_hooks.name; + + if (!language_string) + { + return false; + } + + if (lang_GNU_C ()) + { + return true; + } + else if (strcmp (language_string, "GNU GIMPLE") == 0) // for LTO check + { + unsigned i = 0; + tree t = NULL_TREE; + + FOR_EACH_VEC_SAFE_ELT (all_translation_units, i, t) + { + language_string = TRANSLATION_UNIT_LANGUAGE (t); + if (language_string == NULL + || strncmp (language_string, "GNU C", 5) + || (language_string[5] != '\0' + && !(ISDIGIT (language_string[5])))) + { + return false; + } + } + return true; + } + return false; +} + namespace { using namespace struct_reorg; @@ -163,42 +199,6 @@ handled_type (tree type) return false; } -/* Check whether in C language or LTO with only C language. */ -bool -lang_c_p (void) -{ - const char *language_string = lang_hooks.name; - - if (!language_string) - { - return false; - } - - if (lang_GNU_C ()) - { - return true; - } - else if (strcmp (language_string, "GNU GIMPLE") == 0) // for LTO check - { - unsigned i = 0; - tree t = NULL_TREE; - - FOR_EACH_VEC_SAFE_ELT (all_translation_units, i, t) - { - language_string = TRANSLATION_UNIT_LANGUAGE (t); - if (language_string == NULL - || strncmp (language_string, "GNU C", 5) - || (language_string[5] != '\0' - && !(ISDIGIT (language_string[5])))) - { - return false; - } - } - return true; - } - return false; -} - /* Get the number of pointer layers. */ int diff --git a/gcc/tree.c b/gcc/tree.c index c2075d73586c0e69c3e8186847eecc4abfbc8d68..84a440b357671d0c6077075b65cd89b4d5b2f259 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -128,6 +128,9 @@ const char *const tree_code_class_strings[] = /* obstack.[ch] explicitly declined to prototype this. */ extern int _obstack_allocated_p (struct obstack *h, void *obj); +/* Check whether in C language or LTO with only C language. */ +extern bool lang_c_p (void); + /* Statistics-gathering stuff. */ static uint64_t tree_code_counts[MAX_TREE_CODES]; @@ -5219,7 +5222,10 @@ fld_simplified_type_name (tree type) /* Simplify type will cause that struct A and struct A within struct B are different type pointers, so skip it in structure optimizations. */ - if (flag_ipa_struct_layout || flag_ipa_struct_reorg) + if ((flag_ipa_struct_layout || flag_ipa_struct_reorg) + && lang_c_p () + && flag_lto_partition == LTO_PARTITION_ONE + && (in_lto_p || flag_whole_program)) return TYPE_NAME (type); if (!TYPE_NAME (type) || TREE_CODE (TYPE_NAME (type)) != TYPE_DECL) @@ -5463,7 +5469,10 @@ fld_simplified_type (tree t, class free_lang_data_d *fld) /* Simplify type will cause that struct A and struct A within struct B are different type pointers, so skip it in structure optimizations. */ - if (flag_ipa_struct_layout || flag_ipa_struct_reorg) + if ((flag_ipa_struct_layout || flag_ipa_struct_reorg) + && lang_c_p () + && flag_lto_partition == LTO_PARTITION_ONE + && (in_lto_p || flag_whole_program)) return t; if (POINTER_TYPE_P (t)) return fld_incomplete_type_of (t, fld);