libgccjit: Don't abort on fatal errors
diff --git a/gcc/diagnostic-core.h b/gcc/diagnostic-core.h
index fc32f48..0e63028 100644
--- a/gcc/diagnostic-core.h
+++ b/gcc/diagnostic-core.h
@@ -112,8 +112,7 @@
 extern void error_meta (rich_location *, const diagnostics::metadata &,
 			const char *, ...)
   ATTRIBUTE_GCC_DIAG(3,4);
-extern void fatal_error (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3)
-     ATTRIBUTE_NORETURN;
+extern void fatal_error (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
 /* Pass one of the OPT_W* from options.h as the second parameter.  */
 extern bool pedwarn (location_t,
 		     diagnostics::option_id,
diff --git a/gcc/diagnostic-global-context.cc b/gcc/diagnostic-global-context.cc
index 30fc190..7f4136d 100644
--- a/gcc/diagnostic-global-context.cc
+++ b/gcc/diagnostic-global-context.cc
@@ -766,7 +766,8 @@
 			      diagnostics::kind::fatal);
   va_end (ap);
 
-  gcc_unreachable ();
+  if (!global_dc->dont_abort_on_fatal_error ())
+    gcc_unreachable ();
 }
 
 /* An internal consistency check has failed.  We make no attempt to
diff --git a/gcc/diagnostics/context.cc b/gcc/diagnostics/context.cc
index cd14977..4ebfec6 100644
--- a/gcc/diagnostics/context.cc
+++ b/gcc/diagnostics/context.cc
@@ -1037,8 +1037,12 @@
       if (m_abort_on_error)
 	real_abort ();
       fnotice (stderr, "compilation terminated.\n");
-      finish ();
-      exit (FATAL_EXIT_CODE);
+      if (!m_dont_abort_on_fatal_error)
+      {
+        finish ();
+        exit (FATAL_EXIT_CODE);
+      }
+      break;
 
     default:
       gcc_unreachable ();
diff --git a/gcc/diagnostics/context.h b/gcc/diagnostics/context.h
index 7d7c872..06ff5f1 100644
--- a/gcc/diagnostics/context.h
+++ b/gcc/diagnostics/context.h
@@ -565,6 +565,18 @@
     m_abort_on_error = val;
   }
 
+  void
+  set_dont_abort_on_fatal_error (bool val)
+  {
+    m_dont_abort_on_fatal_error = val;
+  }
+
+  bool
+  dont_abort_on_fatal_error () const
+  {
+    return m_dont_abort_on_fatal_error;
+  }
+
   /* Accessor for use in serialization, e.g. by C++ modules.  */
   auto &
   get_classification_history ()
@@ -679,6 +691,9 @@
   /* True if we should raise a SIGABRT on errors.  */
   bool m_abort_on_error;
 
+  /* True if we should not abort on fatal errors. Mainly used for libgccjit.  */
+  bool m_dont_abort_on_fatal_error = false;
+
 public:
   /* True if we should show the column number on diagnostics.  */
   bool m_show_column;
diff --git a/gcc/jit/dummy-frontend.cc b/gcc/jit/dummy-frontend.cc
index d85597c..773e35a 100644
--- a/gcc/jit/dummy-frontend.cc
+++ b/gcc/jit/dummy-frontend.cc
@@ -1020,6 +1020,7 @@
   : diagnostics::text_sink (dc),
     m_playback_ctxt (playback_ctxt)
   {
+    dc.set_dont_abort_on_fatal_error (true);
   }
 
   void dump (FILE *out, int indent) const final override