Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
Pushed to trunk as r15-7474-ge8c5013b6b7820.

gcc/ChangeLog:
        PR sarif-replay/118792
        * libsarifreplay.cc (sarif_replayer::handle_region_object): Fix
        off-by-one in handling of endColumn property so that the code
        matches the comment and the SARIF spec (§3.30.8).

gcc/testsuite/ChangeLog:
        PR sarif-replay/118792
        * sarif-replay.dg/2.1.0-valid/error-with-note.sarif: Update
        expected output to reflect fix to off-by-one error in handling of
        "endColumn" property.
        * sarif-replay.dg/2.1.0-valid/malloc-vs-local-4.c.sarif: Likewise.
        * sarif-replay.dg/2.1.0-valid/signal-1.c.moved.sarif: Likewise.
        * sarif-replay.dg/2.1.0-valid/signal-1.c.sarif: Likewise.

Signed-off-by: David Malcolm <dmalc...@redhat.com>
---
 gcc/libsarifreplay.cc                         |  2 +-
 .../2.1.0-valid/error-with-note.sarif         |  4 ++--
 .../2.1.0-valid/malloc-vs-local-4.c.sarif     | 24 +++++++++----------
 .../2.1.0-valid/signal-1.c.moved.sarif        | 14 +++++------
 .../2.1.0-valid/signal-1.c.sarif              | 14 +++++------
 5 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/gcc/libsarifreplay.cc b/gcc/libsarifreplay.cc
index 61d9565588e..71f80797926 100644
--- a/gcc/libsarifreplay.cc
+++ b/gcc/libsarifreplay.cc
@@ -1739,7 +1739,7 @@ handle_region_object (const json::object &region_obj,
          /* SARIF's endColumn is 1 beyond the final column in the region,
             whereas GCC's end columns are inclusive.  */
          end = m_output_mgr.new_location_from_file_line_column
-           (file, end_line, end_column_jnum->get ());
+           (file, end_line, end_column_jnum->get () - 1);
        }
       else
        {
diff --git a/gcc/testsuite/sarif-replay.dg/2.1.0-valid/error-with-note.sarif 
b/gcc/testsuite/sarif-replay.dg/2.1.0-valid/error-with-note.sarif
index 0d75a693cdf..77d5a4ee181 100644
--- a/gcc/testsuite/sarif-replay.dg/2.1.0-valid/error-with-note.sarif
+++ b/gcc/testsuite/sarif-replay.dg/2.1.0-valid/error-with-note.sarif
@@ -26,12 +26,12 @@
 /* { dg-begin-multiline-output "" }
 /this/does/not/exist/test.bas:2:8: error: 'GOTO' is considered harmful
     2 |        GOTO label
-      |        ^~~~~~~~~~  
+      |        ^~~~~~~~~~ 
    { dg-end-multiline-output "" } */
 /* { dg-begin-multiline-output "" }
 /this/does/not/exist/test.bas:1:1: note: this is the target of the 'GOTO'
     1 | label: PRINT "hello world!"
-      | ^~~~~~
+      | ^~~~~
    { dg-end-multiline-output "" } */
 
 // TODO: trailing [error]
diff --git 
a/gcc/testsuite/sarif-replay.dg/2.1.0-valid/malloc-vs-local-4.c.sarif 
b/gcc/testsuite/sarif-replay.dg/2.1.0-valid/malloc-vs-local-4.c.sarif
index 55c646bb5ad..947d65c6a7e 100644
--- a/gcc/testsuite/sarif-replay.dg/2.1.0-valid/malloc-vs-local-4.c.sarif
+++ b/gcc/testsuite/sarif-replay.dg/2.1.0-valid/malloc-vs-local-4.c.sarif
@@ -339,37 +339,37 @@
 In function 'callee_1':
 /not/a/real/path/malloc-vs-local-4.c:5:3: warning: dereference of 
possibly-NULL ‘ptr’ [-Wanalyzer-possible-null-dereference]
     5 |   *ptr = 42;
-      |   ^~~~~~~~~~
+      |   ^~~~~~~~~
   'test_1': events 1-5
     |
     |    8 | int test_1 (int i, int flag)
-    |      |     ^~~~~~~
+    |      |     ^~~~~~
     |      |     |
     |      |     (1) entry to ‘test_1’
     |......
     |   12 |   if (flag)
-    |      |      ~~
+    |      |      ~
     |      |      |
     |      |      (2) following ‘true’ branch (when ‘flag != 0’)...
     |   13 |     ptr = (int *)malloc (sizeof (int));
-    |      |                  ~~~~~~~~~~~~~~~~~~~~~~
+    |      |                  ~~~~~~~~~~~~~~~~~~~~~
     |      |                  |
     |      |                  (3) ...to here
     |      |                  (4) this call could return NULL
     |   14 |   callee_1 (ptr);
-    |      |   ~~~~~~~~~~~~~~~
+    |      |   ~~~~~~~~~~~~~~
     |      |   |
     |      |   (5) calling ‘callee_1’ from ‘test_1’
     |
     +--> 'callee_1': events 6-7
            |
            |    3 | void __attribute__((noinline)) callee_1 (int *ptr)
-           |      |                                ^~~~~~~~~
+           |      |                                ^~~~~~~~
            |      |                                |
            |      |                                (6) entry to ‘callee_1’
            |    4 | {
            |    5 |   *ptr = 42;
-           |      |   ~~~~~~~~~~                    
+           |      |   ~~~~~~~~~                     
            |      |   |
            |      |   (7) ‘ptr’ could be NULL: unchecked value from (4)
            |
@@ -378,24 +378,24 @@ In function 'callee_1':
 In function 'test_2':
 /not/a/real/path/malloc-vs-local-4.c:38:7: warning: double-‘free’ of ‘ptr’ 
[-Wanalyzer-double-free]
    38 |       free (ptr);
-      |       ^~~~~~~~~~~
+      |       ^~~~~~~~~~
   'test_2': events 1-5
    34 |   if (!flag)
-      |      ^~
+      |      ^
       |      |
       |      (1) following ‘true’ branch (when ‘flag == 0’)...
    35 |     {
    36 |       void *ptr = malloc (16);
-      |                   ~~~~~~~~~~~~
+      |                   ~~~~~~~~~~~
       |                   |
       |                   (2) ...to here
       |                   (3) allocated here
    37 |       free (ptr);
-      |       ~~~~~~~~~~~
+      |       ~~~~~~~~~~
       |       |
       |       (4) first ‘free’ here
    38 |       free (ptr);
-      |       ~~~~~~~~~~~
+      |       ~~~~~~~~~~
       |       |
       |       (5) second ‘free’ here; first ‘free’ was at (4)
    { dg-end-multiline-output "" } */
diff --git a/gcc/testsuite/sarif-replay.dg/2.1.0-valid/signal-1.c.moved.sarif 
b/gcc/testsuite/sarif-replay.dg/2.1.0-valid/signal-1.c.moved.sarif
index f0026de12da..b1760536bd2 100644
--- a/gcc/testsuite/sarif-replay.dg/2.1.0-valid/signal-1.c.moved.sarif
+++ b/gcc/testsuite/sarif-replay.dg/2.1.0-valid/signal-1.c.moved.sarif
@@ -170,16 +170,16 @@
 In function 'custom_logger':
 signal-1.c:13:3: warning: call to ‘fprintf’ from within signal handler 
[-Wanalyzer-unsafe-call-within-signal-handler]
    13 |   fprintf(stderr, "LOG: %s", msg);
-      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   'main': events 1-2
     |
     |   21 | int main(int argc, const char *argv)
-    |      |     ^~~~~
+    |      |     ^~~~
     |      |     |
     |      |     (1) entry to ‘main’
     |......
     |   25 |   signal(SIGINT, handler);
-    |      |   ~~~~~~~~~~~~~~~~~~~~~~~~
+    |      |   ~~~~~~~~~~~~~~~~~~~~~~~
     |      |   |
     |      |   (2) registering ‘handler’ as signal handler
     |
@@ -191,24 +191,24 @@ signal-1.c:13:3: warning: call to ‘fprintf’ from within 
signal handler [-Wan
     +--> 'handler': events 4-5
            |
            |   16 | static void handler(int signum)
-           |      |             ^~~~~~~~
+           |      |             ^~~~~~~
            |      |             |
            |      |             (4) entry to ‘handler’
            |   17 | {
            |   18 |   custom_logger("got signal");
-           |      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+           |      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~
            |      |   |
            |      |   (5) calling ‘custom_logger’ from ‘handler’
            |
            +--> 'custom_logger': events 6-7
                   |
                   |   11 | void custom_logger(const char *msg)
-                  |      |      ^~~~~~~~~~~~~~
+                  |      |      ^~~~~~~~~~~~~
                   |      |      |
                   |      |      (6) entry to ‘custom_logger’
                   |   12 | {
                   |   13 |   fprintf(stderr, "LOG: %s", msg);
-                  |      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+                  |      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                   |      |   |
                   |      |   (7) call to ‘fprintf’ from within signal handler
                   |
diff --git a/gcc/testsuite/sarif-replay.dg/2.1.0-valid/signal-1.c.sarif 
b/gcc/testsuite/sarif-replay.dg/2.1.0-valid/signal-1.c.sarif
index e2f316b972e..54fa0b83f1d 100644
--- a/gcc/testsuite/sarif-replay.dg/2.1.0-valid/signal-1.c.sarif
+++ b/gcc/testsuite/sarif-replay.dg/2.1.0-valid/signal-1.c.sarif
@@ -168,16 +168,16 @@
 In function 'custom_logger':
 ../../src/gcc/testsuite/gcc.dg/analyzer/signal-1.c:13:3: warning: call to 
‘fprintf’ from within signal handler 
[-Wanalyzer-unsafe-call-within-signal-handler]
    13 |   fprintf(stderr, "LOG: %s", msg);
-      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   'main': events 1-2
     |
     |   21 | int main(int argc, const char *argv)
-    |      |     ^~~~~
+    |      |     ^~~~
     |      |     |
     |      |     (1) entry to ‘main’
     |......
     |   25 |   signal(SIGINT, handler);
-    |      |   ~~~~~~~~~~~~~~~~~~~~~~~~
+    |      |   ~~~~~~~~~~~~~~~~~~~~~~~
     |      |   |
     |      |   (2) registering ‘handler’ as signal handler
     |
@@ -189,24 +189,24 @@ In function 'custom_logger':
     +--> 'handler': events 4-5
            |
            |   16 | static void handler(int signum)
-           |      |             ^~~~~~~~
+           |      |             ^~~~~~~
            |      |             |
            |      |             (4) entry to ‘handler’
            |   17 | {
            |   18 |   custom_logger("got signal");
-           |      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+           |      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~
            |      |   |
            |      |   (5) calling ‘custom_logger’ from ‘handler’
            |
            +--> 'custom_logger': events 6-7
                   |
                   |   11 | void custom_logger(const char *msg)
-                  |      |      ^~~~~~~~~~~~~~
+                  |      |      ^~~~~~~~~~~~~
                   |      |      |
                   |      |      (6) entry to ‘custom_logger’
                   |   12 | {
                   |   13 |   fprintf(stderr, "LOG: %s", msg);
-                  |      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+                  |      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                   |      |   |
                   |      |   (7) call to ‘fprintf’ from within signal handler
                   |
-- 
2.26.3

Reply via email to