]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libgccjit: Fix GGC segfault when using -flto
authorAntoni Boucher <bouanto@zoho.com>
Wed, 10 Jan 2024 22:13:20 +0000 (17:13 -0500)
committerDavid Malcolm <dmalcolm@redhat.com>
Wed, 10 Jan 2024 22:13:20 +0000 (17:13 -0500)
gcc/ChangeLog:
PR jit/111396
* ipa-fnsummary.cc (ipa_fnsummary_cc_finalize): Call
ipa_free_size_summary.
* ipa-icf.cc (ipa_icf_cc_finalize): New function.
* ipa-profile.cc (ipa_profile_cc_finalize): New function.
* ipa-prop.cc (ipa_prop_cc_finalize): New function.
* ipa-prop.h (ipa_prop_cc_finalize): New function.
* ipa-sra.cc (ipa_sra_cc_finalize): New function.
* ipa-utils.h (ipa_profile_cc_finalize, ipa_icf_cc_finalize,
ipa_sra_cc_finalize): New functions.
* toplev.cc (toplev::finalize): Call ipa_icf_cc_finalize,
ipa_prop_cc_finalize, ipa_profile_cc_finalize and
ipa_sra_cc_finalize
Include ipa-utils.h.

gcc/testsuite/ChangeLog:
PR jit/111396
* jit.dg/all-non-failing-tests.h: Add note about test-ggc-bugfix.
* jit.dg/test-ggc-bugfix.c: New test.

gcc/ipa-fnsummary.cc
gcc/ipa-icf.cc
gcc/ipa-profile.cc
gcc/ipa-prop.cc
gcc/ipa-prop.h
gcc/ipa-sra.cc
gcc/ipa-utils.h
gcc/testsuite/jit.dg/all-non-failing-tests.h
gcc/testsuite/jit.dg/test-ggc-bugfix.c [new file with mode: 0644]
gcc/toplev.cc

index ba1a2d819e85c9d3d40802e46ddb06bdf7fe340c..74c9b4e1d1e5676f33162dee373a104fc11b5887 100644 (file)
@@ -5090,4 +5090,5 @@ void
 ipa_fnsummary_cc_finalize (void)
 {
   ipa_free_fn_summary ();
+  ipa_free_size_summary ();
 }
index 3d62d7b6791d7a6195bb5d00a1b1f5d830d1a640..29ed1f1e4c1399c0602ede04b4a94b00ce946fa3 100644 (file)
@@ -3663,3 +3663,12 @@ make_pass_ipa_icf (gcc::context *ctxt)
 {
   return new ipa_icf::pass_ipa_icf (ctxt);
 }
+
+/* Reset all state within ipa-icf.cc so that we can rerun the compiler
+   within the same process.  For use by toplev::finalize.  */
+
+void
+ipa_icf_cc_finalize (void)
+{
+  ipa_icf::optimizer = NULL;
+}
index 8880e86d189c168cc43fdd44c23fada59509e9e3..5e89f677c3e6fcbb7801612b08264bc1cdfe3bb7 100644 (file)
@@ -1065,3 +1065,13 @@ make_pass_ipa_profile (gcc::context *ctxt)
 {
   return new pass_ipa_profile (ctxt);
 }
+
+/* Reset all state within ipa-profile.cc so that we can rerun the compiler
+   within the same process.  For use by toplev::finalize.  */
+
+void
+ipa_profile_cc_finalize (void)
+{
+  delete call_sums;
+  call_sums = NULL;
+}
index 12a2cab9f512b4dda0d99774d48f40202d77800f..bec0ebd210cfd4a3686dcce1edfd575c4f3681ab 100644 (file)
@@ -5988,5 +5988,23 @@ ipa_return_value_range (Value_Range &range, tree decl)
   return true;
 }
 
+/* Reset all state within ipa-prop.cc so that we can rerun the compiler
+   within the same process.  For use by toplev::finalize.  */
+
+void
+ipa_prop_cc_finalize (void)
+{
+  if (function_insertion_hook_holder)
+    symtab->remove_cgraph_insertion_hook (function_insertion_hook_holder);
+  function_insertion_hook_holder = NULL;
+
+  if (ipa_edge_args_sum)
+    ggc_delete (ipa_edge_args_sum);
+  ipa_edge_args_sum = NULL;
+
+  if (ipa_node_params_sum)
+    ggc_delete (ipa_node_params_sum);
+  ipa_node_params_sum = NULL;
+}
 
 #include "gt-ipa-prop.h"
index 3daf5ceeca7ef12d6deeecd86e625c25c7c90740..9c78dc9f486017748d426d888cac020e51d1a060 100644 (file)
@@ -1255,6 +1255,8 @@ tree ipcp_get_aggregate_const (struct function *func, tree parm, bool by_ref,
 bool unadjusted_ptr_and_unit_offset (tree op, tree *ret,
                                     poly_int64 *offset_ret);
 
+void ipa_prop_cc_finalize (void);
+
 /* From tree-sra.cc:  */
 tree build_ref_for_offset (location_t, tree, poly_int64, bool, tree,
                           gimple_stmt_iterator *, bool);
index 2fdc305c89cf7b9761f1399734096cf7baa71024..14c2a344e6d82606b52be0df2114c1f08c265782 100644 (file)
@@ -4707,5 +4707,17 @@ make_pass_ipa_sra (gcc::context *ctxt)
   return new pass_ipa_sra (ctxt);
 }
 
+/* Reset all state within ipa-sra.cc so that we can rerun the compiler
+   within the same process.  For use by toplev::finalize.  */
+
+void
+ipa_sra_cc_finalize (void)
+{
+  if (func_sums)
+    ggc_delete (func_sums);
+  func_sums = NULL;
+  delete call_sums;
+  call_sums = NULL;
+}
 
 #include "gt-ipa-sra.h"
index 0282de4582ad507f696cd342901aca864547dd69..d1da9c31e09ed6d7d29a60d8d4e172b902902141 100644 (file)
@@ -57,6 +57,13 @@ bool ipa_make_function_pure (cgraph_node *, bool, bool);
 
 /* In ipa-profile.cc  */
 bool ipa_propagate_frequency (struct cgraph_node *node);
+void ipa_profile_cc_finalize (void);
+
+/* In ipa-icf.cc  */
+void ipa_icf_cc_finalize (void);
+
+/* In ipa-sra.cc  */
+void ipa_sra_cc_finalize (void);
 
 /* In ipa-devirt.cc  */
 
index e762563f9bdba0bd53eb21ca5ea5cb9ccd9eb7d8..73ecd0329a09b789f0cb44ae382dd9629a2f8170 100644 (file)
 #undef create_code
 #undef verify_code
 
+/* test-ggc-bugfix.c: We don't use this once, since the use of
+   gcc_jit_context_add_command_line_option and
+   gcc_jit_context_add_driver_option affects the whole context.  */
+
 /* Now expose the individual testcases as instances of this struct.  */
 
 struct testcase
diff --git a/gcc/testsuite/jit.dg/test-ggc-bugfix.c b/gcc/testsuite/jit.dg/test-ggc-bugfix.c
new file mode 100644 (file)
index 0000000..59eb374
--- /dev/null
@@ -0,0 +1,34 @@
+/* { dg-do compile { target x86_64-*-* } } */
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "libgccjit.h"
+
+#include "harness.h"
+
+void
+create_code (gcc_jit_context *ctxt, void *user_data)
+{
+  gcc_jit_context_add_command_line_option (ctxt, "-flto");
+  gcc_jit_context_add_driver_option (ctxt, "-nostdlib");
+
+  gcc_jit_type *type_int = gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT);
+  gcc_jit_param *params_for_func_main[0] = {
+  };
+  gcc_jit_function *func_main =
+    gcc_jit_context_new_function (ctxt, NULL, GCC_JIT_FUNCTION_EXPORTED,
+                                  type_int, "main", 0, params_for_func_main,
+                                  0);
+  gcc_jit_block *block_start =
+    gcc_jit_function_new_block (func_main, "start");
+  gcc_jit_rvalue *rvalue__int_42 =
+    gcc_jit_context_new_rvalue_from_int (ctxt, type_int, 42);
+  gcc_jit_block_end_with_return (block_start, NULL, rvalue__int_42);
+}
+
+void
+verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
+{
+  CHECK_NON_NULL (result);
+}
index 0c2994e85a31e2abf22aa479f6c16dd7347cd4a6..55636ff6e809c01ae9cbc33e1e594b22360393a3 100644 (file)
@@ -75,6 +75,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "symbol-summary.h"
 #include "tree-vrp.h"
 #include "ipa-prop.h"
+#include "ipa-utils.h"
 #include "gcse.h"
 #include "omp-offload.h"
 #include "edit-context.h"
@@ -2359,7 +2360,11 @@ toplev::finalize (void)
   ipa_fnsummary_cc_finalize ();
   ipa_modref_cc_finalize ();
   ipa_edge_modifications_finalize ();
+  ipa_icf_cc_finalize ();
 
+  ipa_prop_cc_finalize ();
+  ipa_profile_cc_finalize ();
+  ipa_sra_cc_finalize ();
   cgraph_cc_finalize ();
   cgraphunit_cc_finalize ();
   symtab_thunks_cc_finalize ();