2014-11-24  Tobias Burnus  <burnus@net-b.de>

	* error.c: Update comments.
	(gfc_internal_error): Convert to common diagnostics.
	* interface.c (gfc_find_sym_in_symtree): Use %qs.
	* intrinsic.c (make_generic, gfc_check_intrinsic_standard,
	gfc_convert_type_warn): Ditto.
	* module.c (write_symbol): Ditto.
	* symbol.c (gfc_get_default_type): Ditto; use fatal instead
	of internal error.
	* trans-array.c (gfc_walk_subexpr): Replace internal_error by
	gfc_internal_error.
	* trans-decl.c (gfc_get_symbol_decl,
	(gfc_create_module_variable): Ditto. Use %qs.
	* trans-intrinsic.c (gfc_conv_intrinsic_lib_function): Ditto.
	* trans-io.c (transfer_expr): Ditto.
	* trans-openmp.c (gfc_trans_omp_workshare): Ditto.
	* trans.c (trans_code): Ditto.

diff --git a/gcc/fortran/error.c b/gcc/fortran/error.c
index 202dd88..a7d7e09 100644
--- a/gcc/fortran/error.c
+++ b/gcc/fortran/error.c
@@ -935,3 +935,4 @@ gfc_notify_std (int std, const char *gmsgid, ...)
 /* Immediate warning (i.e. do not buffer the warning).  */
-/* Use gfc_warning_now_2 instead, unless gmsgid contains a %L.  */
+/* Use gfc_warning_now_2 instead, except for scanner.c which might have an
+   invalid line buffer.  */
 
@@ -1096,3 +1097,4 @@ gfc_diagnostic_finalizer (diagnostic_context *context,
 /* Immediate warning (i.e. do not buffer the warning).  */
-/* This function uses the common diagnostics, but does not support %L, yet.  */
+/* This function uses the common diagnostics, but might not work for
+   scanner.c as it not always has a working line buffer.  */
 
@@ -1115,3 +1117,4 @@ gfc_warning_now_2 (int opt, const char *gmsgid, ...)
 /* Immediate warning (i.e. do not buffer the warning).  */
-/* This function uses the common diagnostics, but does not support %L, yet.  */
+/* This function uses the common diagnostics, but might not work for
+   scanner.c as it not always has a working line buffer.  */
 
@@ -1134,3 +1137,4 @@ gfc_warning_now_2 (const char *gmsgid, ...)
 /* Immediate error (i.e. do not buffer).  */
-/* This function uses the common diagnostics, but does not support %L, yet.  */
+/* This function uses the common diagnostics, but might not work for
+   scanner.c as it not always has a working line buffer.  */
 
@@ -1243,3 +1247,4 @@ warning:
 /* Immediate error.  */
-/* Use gfc_error_now_2 instead, unless gmsgid contains a %L.  */
+/* Use gfc_error_now_2 instead, except for scanner.c which might have an
+   invalid line buffer.  */
 
@@ -1276,17 +1281,13 @@ gfc_error_now (const char *gmsgid, ...)
 void
-gfc_internal_error (const char *format, ...)
+gfc_internal_error (const char *gmsgid, ...)
 {
   va_list argp;
+  diagnostic_info diagnostic;
 
-  buffer_flag = 0;
-
-  va_start (argp, format);
-
-  show_loci (&gfc_current_locus, NULL);
-  error_printf ("Internal Error at (1):");
-
-  error_print ("", format, argp);
+  va_start (argp, gmsgid);
+  diagnostic_set_info (&diagnostic, gmsgid, &argp, UNKNOWN_LOCATION, DK_ICE);
+  report_diagnostic (&diagnostic);
   va_end (argp);
 
-  exit (ICE_EXIT_CODE);
+  gcc_unreachable ();
 }
diff --git a/gcc/fortran/interface.c b/gcc/fortran/interface.c
index 1eb09ac..1980ddf 100644
--- a/gcc/fortran/interface.c
+++ b/gcc/fortran/interface.c
@@ -3544,3 +3544,3 @@ gfc_find_sym_in_symtree (gfc_symbol *sym)
     }
-  gfc_internal_error ("Unable to find symbol %s", sym->name);
+  gfc_internal_error ("Unable to find symbol %qs", sym->name);
   /* Not reached.  */
diff --git a/gcc/fortran/intrinsic.c b/gcc/fortran/intrinsic.c
index 9bc9b3c..38107e6 100644
--- a/gcc/fortran/intrinsic.c
+++ b/gcc/fortran/intrinsic.c
@@ -1089,3 +1089,3 @@ make_generic (const char *name, gfc_isym_id id, int standard ATTRIBUTE_UNUSED)
   if (g == NULL)
-    gfc_internal_error ("make_generic(): Can't find generic symbol '%s'",
+    gfc_internal_error ("make_generic(): Can't find generic symbol %qs",
 			name);
@@ -4310,3 +4310,3 @@ gfc_check_intrinsic_standard (const gfc_intrinsic_sym* isym,
     default:
-      gfc_internal_error ("Invalid standard code on intrinsic '%s' (%d)",
+      gfc_internal_error ("Invalid standard code on intrinsic %qs (%d)",
 			  isym->name, isym->standard);
@@ -4739,3 +4739,3 @@ bad:
 
-  gfc_internal_error ("Can't convert %s to %s at %L",
+  gfc_internal_error ("Can't convert %qs to %qs at %L",
 		      gfc_typename (&from_ts), gfc_typename (ts),
diff --git a/gcc/fortran/module.c b/gcc/fortran/module.c
index b88e669..f03aea6 100644
--- a/gcc/fortran/module.c
+++ b/gcc/fortran/module.c
@@ -5498,3 +5498,3 @@ write_symbol (int n, gfc_symbol *sym)
   if (sym->attr.flavor == FL_UNKNOWN || sym->attr.flavor == FL_LABEL)
-    gfc_internal_error ("write_symbol(): bad module symbol '%s'", sym->name);
+    gfc_internal_error ("write_symbol(): bad module symbol %qs", sym->name);
 
diff --git a/gcc/fortran/symbol.c b/gcc/fortran/symbol.c
index 3eb58f4..13bd6b3 100644
--- a/gcc/fortran/symbol.c
+++ b/gcc/fortran/symbol.c
@@ -223,8 +223,8 @@ gfc_get_default_type (const char *name, gfc_namespace *ns)
   if (gfc_option.flag_allow_leading_underscore && letter == '_')
-    gfc_internal_error ("Option -fallow-leading-underscore is for use only by "
-			"gfortran developers, and should not be used for "
-			"implicitly typed variables");
+    gfc_fatal_error ("Option %<-fallow-leading-underscore%> is for use only by "
+		     "gfortran developers, and should not be used for "
+		     "implicitly typed variables");
 
   if (letter < 'a' || letter > 'z')
-    gfc_internal_error ("gfc_get_default_type(): Bad symbol '%s'", name);
+    gfc_internal_error ("gfc_get_default_type(): Bad symbol %qs", name);
 
diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c
index 218d274..a70aa07 100644
--- a/gcc/fortran/trans-array.c
+++ b/gcc/fortran/trans-array.c
@@ -9095,3 +9095,3 @@ gfc_walk_subexpr (gfc_ss * ss, gfc_expr * expr)
     default:
-      internal_error ("bad expression type during walk (%d)",
+      gfc_internal_error ("bad expression type during walk (%d)",
 		      expr->expr_type);
diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c
index 07fefd9..eefd9bc 100644
--- a/gcc/fortran/trans-decl.c
+++ b/gcc/fortran/trans-decl.c
@@ -1437,3 +1437,3 @@ gfc_get_symbol_decl (gfc_symbol * sym)
   if (sym->attr.intrinsic)
-    internal_error ("intrinsic variable which isn't a procedure");
+    gfc_internal_error ("intrinsic variable which isn't a procedure");
 
@@ -4420,4 +4420,4 @@ gfc_create_module_variable (gfc_symbol * sym)
   if (sym->backend_decl && !sym->attr.vtab && !sym->attr.target)
-    internal_error ("backend decl for module variable %s already exists",
-		    sym->name);
+    gfc_internal_error ("backend decl for module variable %qs already exists",
+			sym->name);
 
diff --git a/gcc/fortran/trans-intrinsic.c b/gcc/fortran/trans-intrinsic.c
index 932bf79..6bf1f74 100644
--- a/gcc/fortran/trans-intrinsic.c
+++ b/gcc/fortran/trans-intrinsic.c
@@ -858,4 +858,4 @@ gfc_conv_intrinsic_lib_function (gfc_se * se, gfc_expr * expr)
     {
-      internal_error ("Intrinsic function %s(%d) not recognized",
-		      expr->value.function.name, id);
+      gfc_internal_error ("Intrinsic function %qs (%d) not recognized",
+			  expr->value.function.name, id);
     }
diff --git a/gcc/fortran/trans-io.c b/gcc/fortran/trans-io.c
index fbf7912..e1b7eb9 100644
--- a/gcc/fortran/trans-io.c
+++ b/gcc/fortran/trans-io.c
@@ -2194,3 +2194,3 @@ transfer_expr (gfc_se * se, gfc_typespec * ts, tree addr_expr, gfc_code * code)
     default:
-      internal_error ("Bad IO basetype (%d)", ts->type);
+      gfc_internal_error ("Bad IO basetype (%d)", ts->type);
     }
diff --git a/gcc/fortran/trans-openmp.c b/gcc/fortran/trans-openmp.c
index 038c3e9..a069771 100644
--- a/gcc/fortran/trans-openmp.c
+++ b/gcc/fortran/trans-openmp.c
@@ -3923,3 +3923,3 @@ gfc_trans_omp_workshare (gfc_code *code, gfc_omp_clauses *clauses)
 	default:
-	  internal_error ("gfc_trans_omp_workshare(): Bad statement code");
+	  gfc_internal_error ("gfc_trans_omp_workshare(): Bad statement code");
 	}
diff --git a/gcc/fortran/trans.c b/gcc/fortran/trans.c
index b707023..76fe7fd 100644
--- a/gcc/fortran/trans.c
+++ b/gcc/fortran/trans.c
@@ -1892,3 +1892,3 @@ trans_code (gfc_code * code, tree cond)
 	default:
-	  internal_error ("gfc_trans_code(): Bad statement code");
+	  gfc_internal_error ("gfc_trans_code(): Bad statement code");
 	}
