diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 608c6204fe175e6b757c0e1c44a48f16ea1feffe..fbe708b45957f5f155fc56366476ec125e48c73c 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2018-09-11  Andrew Stubbs  <ams@codesourcery.com>
+
+	* diagnostic-core.h (sorry_at): New prototype.
+	* diagnostic.c (sorry_at): New function.
+
 2018-09-11  Aldy Hernandez  <aldyh@redhat.com>
 
 	* tree-vrp (extract_range_from_binary_expr_1): Treat all divisions
diff --git a/gcc/diagnostic-core.h b/gcc/diagnostic-core.h
index e4ebe005ede532b67e94387cf4dc4f8006230f96..80ff39541e6d581bd66c3dc47c178d339def7b6b 100644
--- a/gcc/diagnostic-core.h
+++ b/gcc/diagnostic-core.h
@@ -96,6 +96,7 @@ extern bool permerror (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
 extern bool permerror (rich_location *, const char *,
 				   ...) ATTRIBUTE_GCC_DIAG(2,3);
 extern void sorry (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2);
+extern void sorry_at (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
 extern void inform (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
 extern void inform (rich_location *, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
 extern void inform_n (location_t, unsigned HOST_WIDE_INT, const char *,
diff --git a/gcc/diagnostic.c b/gcc/diagnostic.c
index aae0934d21a66a6a336a995eb05ee4f54167ebb2..8575065069b5aa05285b6070c9e8328cdc211154 100644
--- a/gcc/diagnostic.c
+++ b/gcc/diagnostic.c
@@ -1443,6 +1443,18 @@ sorry (const char *gmsgid, ...)
   va_end (ap);
 }
 
+/* Same as above, but use location LOC instead of input_location.  */
+void
+sorry_at (location_t loc, const char *gmsgid, ...)
+{
+  auto_diagnostic_group d;
+  va_list ap;
+  va_start (ap, gmsgid);
+  rich_location richloc (line_table, loc);
+  diagnostic_impl (&richloc, -1, gmsgid, &ap, DK_SORRY);
+  va_end (ap);
+}
+
 /* Return true if an error or a "sorry" has been seen.  Various
    processing is disabled after errors.  */
 bool