In patch https://gcc.gnu.org/ml/gcc-patches/2019-10/msg00092.html , I
increased the error column location by one to point to the actual error.
That works fine, except when the character is one before the end of the
line (= '\0') – as the PR 92072 shows.
This patch checks for this and only increases the location by one if
that's not the case. Cf. scanner.c's next_char().
Comitted as Rev. 276953 (+ 276955).
Cheers,
Tobias
commit 4940ee876372a906522c0f3ba35038f80e36f25c
Author: burnus <burnus@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Mon Oct 14 08:14:23 2019 +0000
[Fortran] PR 92072 – fix %C corner case
PR fortran/92072
* error.c (error_print, gfc_format_decoder): Fix %C column-
offset handling.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@276953 138bc75d-0d04-0410-961f-82ee72b054a4
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index 2892011b740..ad30ff2ceac 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,3 +1,9 @@
+2019-10-14 Tobias Burnus <tob...@codesourcery.com>
+
+ PR fortran/92072
+ * error.c (error_print, gfc_format_decoder): Fix %C column-
+ offset handling.
+
2019-10-13 Damian Rouson <dam...@sourceryinstitue.org>
PR fortran/91513
@@ -110,7 +116,8 @@
2019-10-04 Tobias Burnus <tob...@codesourcery.com>
- * error (error_print, gfc_format_decoder): Fix off-by one issue with %C.
+ * error.c (error_print, gfc_format_decoder): Fix off-by one issue
+ with %C.
2019-10-03 Steven G. Kargl <ka...@gcc.gnu.org>
diff --git a/gcc/fortran/error.c b/gcc/fortran/error.c
index 1019f17d73c..7962c93b108 100644
--- a/gcc/fortran/error.c
+++ b/gcc/fortran/error.c
@@ -1,3 +1,4 @@
+#pragma GCC optimize("O0")
/* Handle errors.
Copyright (C) 2000-2019 Free Software Foundation, Inc.
Contributed by Andy Vaught & Niels Kristian Bech Jensen
@@ -619,7 +620,7 @@ error_print (const char *type, const char *format0, va_list argp)
l2 = loc;
arg[pos].u.stringval = "(2)";
/* Point %C first offending character not the last good one. */
- if (arg[pos].type == TYPE_CURRENTLOC)
+ if (arg[pos].type == TYPE_CURRENTLOC && *l2->nextc != '\0')
l2->nextc++;
}
else
@@ -628,7 +629,7 @@ error_print (const char *type, const char *format0, va_list argp)
have_l1 = 1;
arg[pos].u.stringval = "(1)";
/* Point %C first offending character not the last good one. */
- if (arg[pos].type == TYPE_CURRENTLOC)
+ if (arg[pos].type == TYPE_CURRENTLOC && *l1->nextc != '\0')
l1->nextc++;
}
break;
@@ -969,7 +970,7 @@ gfc_format_decoder (pretty_printer *pp, text_info *text, const char *spec,
loc = va_arg (*text->args_ptr, locus *);
gcc_assert (loc->nextc - loc->lb->line >= 0);
unsigned int offset = loc->nextc - loc->lb->line;
- if (*spec == 'C')
+ if (*spec == 'C' && *loc->nextc != '\0')
/* Point %C first offending character not the last good one. */
offset++;
/* If location[0] != UNKNOWN_LOCATION means that we already
Index: gcc/fortran/ChangeLog
===================================================================
--- gcc/fortran/ChangeLog (revision 276953)
+++ gcc/fortran/ChangeLog (working copy)
@@ -1,5 +1,9 @@
2019-10-14 Tobias Burnus <tob...@codesourcery.com>
+ * error.c: Remove debug pragma added in previous commit.
+
+2019-10-14 Tobias Burnus <tob...@codesourcery.com>
+
PR fortran/92072
* error.c (error_print, gfc_format_decoder): Fix %C column-
offset handling.
Index: gcc/fortran/error.c
===================================================================
--- gcc/fortran/error.c (revision 276953)
+++ gcc/fortran/error.c (working copy)
@@ -1,4 +1,3 @@
-#pragma GCC optimize("O0")
/* Handle errors.
Copyright (C) 2000-2019 Free Software Foundation, Inc.
Contributed by Andy Vaught & Niels Kristian Bech Jensen