This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[LTO][PATCH] Fix for LTO ICEs for mixed PIC and optimization compilations
- From: simonb at google dot com (Simon Baldwin)
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 26 Jan 2009 16:07:05 +0000 (GMT)
- Subject: [LTO][PATCH] Fix for LTO ICEs for mixed PIC and optimization compilations
This patch fixes a couple of compiler ICEs that can occur where either
optimization or PIC options do not match across compilation and link.
The wider issue of how to merge flags, where different, across translation
units that use whole program optimization remains open for the moment.
gcc/ChangeLog.lto
2009-01-26 Simon Baldwin <simonb@google.com>
* ipa-reference.c (write_node_summary_p): Add get_reference_vars_info
to items verified before writing.
(read_summary): Avoid reading where no input block is available.
* ipa-pure-const.c (write_summary): Confirm that function state is
present before writing a summary.
(read_summary): Avoid reading where no input block is available.
gcc/testsuite/ChangeLog.lto
2009-01-26 Simon Baldwin <simonb@google.com>
* gcc/testsuite/gcc.dg/lto/20090126-1_0.c: New.
* gcc/testsuite/gcc.dg/lto/20090126-2_0.c: New.
Index: gcc/ipa-reference.c
===================================================================
--- gcc/ipa-reference.c (revision 143674)
+++ gcc/ipa-reference.c (working copy)
@@ -1005,7 +1005,8 @@ write_node_summary_p (struct cgraph_node
&& node->global.inlined_to == NULL
&& (cgraph_is_master_clone (node, true)
|| (cgraph_function_body_availability (node)
- == AVAIL_OVERWRITABLE)));
+ == AVAIL_OVERWRITABLE))
+ && get_reference_vars_info (node) != NULL);
}
/* Serialize the ipa info for lto. */
@@ -1072,49 +1073,53 @@ read_summary (void)
while ((file_data = file_data_vec[j++]))
{
- unsigned int f_count;
- unsigned int i;
const char *data;
size_t len;
struct lto_input_block *ib
= lto_create_simple_input_block (file_data,
LTO_section_ipa_reference,
&data, &len);
-
- f_count = lto_input_uleb128 (ib);
- for (i = 0; i < f_count; i++)
- {
- unsigned int fn_index = lto_input_uleb128 (ib);
- tree fn_decl = lto_file_decl_data_get_fn_decl (file_data, fn_index);
- unsigned int j;
- struct cgraph_node *node = cgraph_node (fn_decl);
- ipa_reference_local_vars_info_t l = init_function_info (node);
-
- /* Set the statics read. */
- unsigned int v_count = lto_input_uleb128 (ib);
- for (j = 0; j < v_count; j++)
- {
- unsigned int var_index = lto_input_uleb128 (ib);
- tree v_decl = lto_file_decl_data_get_var_decl (file_data,
- var_index);
- add_static_var (v_decl);
- bitmap_set_bit (l->statics_read, DECL_UID (v_decl));
- }
-
- /* Set the statics written. */
- v_count = lto_input_uleb128 (ib);
- for (j = 0; j < v_count; j++)
+ if (ib)
+ {
+ unsigned int i;
+ unsigned int f_count = lto_input_uleb128 (ib);
+
+ for (i = 0; i < f_count; i++)
{
- unsigned int var_index = lto_input_uleb128 (ib);
- tree v_decl = lto_file_decl_data_get_var_decl (file_data,
- var_index);
- add_static_var (v_decl);
- bitmap_set_bit (l->statics_written, DECL_UID (v_decl));
- }
- }
- lto_destroy_simple_input_block (file_data,
- LTO_section_ipa_reference,
- ib, data, len);
+ unsigned int fn_index = lto_input_uleb128 (ib);
+ tree fn_decl = lto_file_decl_data_get_fn_decl (file_data,
+ fn_index);
+ unsigned int j;
+ struct cgraph_node *node = cgraph_node (fn_decl);
+ ipa_reference_local_vars_info_t l = init_function_info (node);
+
+ /* Set the statics read. */
+ unsigned int v_count = lto_input_uleb128 (ib);
+ for (j = 0; j < v_count; j++)
+ {
+ unsigned int var_index = lto_input_uleb128 (ib);
+ tree v_decl = lto_file_decl_data_get_var_decl (file_data,
+ var_index);
+ add_static_var (v_decl);
+ bitmap_set_bit (l->statics_read, DECL_UID (v_decl));
+ }
+
+ /* Set the statics written. */
+ v_count = lto_input_uleb128 (ib);
+ for (j = 0; j < v_count; j++)
+ {
+ unsigned int var_index = lto_input_uleb128 (ib);
+ tree v_decl = lto_file_decl_data_get_var_decl (file_data,
+ var_index);
+ add_static_var (v_decl);
+ bitmap_set_bit (l->statics_written, DECL_UID (v_decl));
+ }
+ }
+
+ lto_destroy_simple_input_block (file_data,
+ LTO_section_ipa_reference,
+ ib, data, len);
+ }
}
}
Index: gcc/testsuite/gcc.dg/lto/20090126-1_0.c
===================================================================
--- gcc/testsuite/gcc.dg/lto/20090126-1_0.c (revision 0)
+++ gcc/testsuite/gcc.dg/lto/20090126-1_0.c (revision 0)
@@ -0,0 +1,7 @@
+/* { dg-do link } */
+/* { dg-options "{-O0 -fwhopr}" } */
+/* { dg-extra-ld-options {-shared -O2 -fwhopr} } */
+
+int main(int argc, char **argv) {
+ return 0;
+}
Index: gcc/testsuite/gcc.dg/lto/20090126-2_0.c
===================================================================
--- gcc/testsuite/gcc.dg/lto/20090126-2_0.c (revision 0)
+++ gcc/testsuite/gcc.dg/lto/20090126-2_0.c (revision 0)
@@ -0,0 +1,7 @@
+/* { dg-do link } */
+/* { dg-options "{-fPIC -O2 -fwhopr}" } */
+/* { dg-extra-ld-options {-fno-PIC -shared -O2 -fwhopr} } */
+
+int main(int argc, char **argv) {
+ return 0;
+}
Index: gcc/ipa-pure-const.c
===================================================================
--- gcc/ipa-pure-const.c (revision 143674)
+++ gcc/ipa-pure-const.c (working copy)
@@ -750,7 +750,8 @@ write_summary (cgraph_node_set set)
for (csi = csi_start (set); !csi_end_p (csi); csi_next (&csi))
{
node = csi_node (csi);
- if (node->analyzed && cgraph_is_master_clone (node, true))
+ if (node->analyzed && cgraph_is_master_clone (node, true)
+ && get_function_state (node) != NULL)
count++;
}
@@ -760,11 +761,11 @@ write_summary (cgraph_node_set set)
for (csi = csi_start (set); !csi_end_p (csi); csi_next (&csi))
{
node = csi_node (csi);
- if (node->analyzed && cgraph_is_master_clone (node, true))
+ if (node->analyzed && cgraph_is_master_clone (node, true)
+ && get_function_state (node) != NULL)
{
unsigned HOST_WIDEST_INT flags = 0;
funct_state fs = get_function_state (node);
- gcc_assert (fs);
lto_output_fn_decl_index (ob->decl_state, ob->main_stream,
node->decl);
@@ -792,32 +793,34 @@ read_summary (void)
while ((file_data = file_data_vec[j++]))
{
- unsigned int count;
- unsigned int i;
const char *data;
size_t len;
struct lto_input_block *ib
= lto_create_simple_input_block (file_data,
LTO_section_ipa_pure_const,
&data, &len);
-
- count = lto_input_uleb128 (ib);
- for (i = 0; i < count; i++)
+ if (ib)
{
- unsigned int index = lto_input_uleb128 (ib);
- tree fn_decl = lto_file_decl_data_get_fn_decl (file_data, index);
- unsigned HOST_WIDEST_INT flags = lto_input_uleb128 (ib);
- funct_state fs = XCNEW (struct funct_state_d);
-
- set_function_state (cgraph_node (fn_decl), fs);
- fs->state_set_in_source = lto_get_flag (&flags);
- fs->looping = lto_get_flag (&flags);
- fs->pure_const_state = lto_get_flags (&flags, 2);
+ unsigned int i;
+ unsigned int count = lto_input_uleb128 (ib);
+
+ for (i = 0; i < count; i++)
+ {
+ unsigned int index = lto_input_uleb128 (ib);
+ tree fn_decl = lto_file_decl_data_get_fn_decl (file_data, index);
+ unsigned HOST_WIDEST_INT flags = lto_input_uleb128 (ib);
+ funct_state fs = XCNEW (struct funct_state_d);
+
+ set_function_state (cgraph_node (fn_decl), fs);
+ fs->state_set_in_source = lto_get_flag (&flags);
+ fs->looping = lto_get_flag (&flags);
+ fs->pure_const_state = lto_get_flags (&flags, 2);
+ }
+
+ lto_destroy_simple_input_block (file_data,
+ LTO_section_ipa_pure_const,
+ ib, data, len);
}
-
- lto_destroy_simple_input_block (file_data,
- LTO_section_ipa_pure_const,
- ib, data, len);
}
}