]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
sarif-replay: fix off-by-one in handling of "endColumn" (§3.30.8) [PR118792]
authorDavid Malcolm <dmalcolm@redhat.com>
Tue, 11 Feb 2025 13:54:15 +0000 (08:54 -0500)
committerDavid Malcolm <dmalcolm@redhat.com>
Tue, 11 Feb 2025 13:54:15 +0000 (08:54 -0500)
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 <dmalcolm@redhat.com>
gcc/libsarifreplay.cc
gcc/testsuite/sarif-replay.dg/2.1.0-valid/error-with-note.sarif
gcc/testsuite/sarif-replay.dg/2.1.0-valid/malloc-vs-local-4.c.sarif
gcc/testsuite/sarif-replay.dg/2.1.0-valid/signal-1.c.moved.sarif
gcc/testsuite/sarif-replay.dg/2.1.0-valid/signal-1.c.sarif

index 61d9565588ed6022fb519056fe517aa77526e4a6..71f807979261da6c86b6d5aee697d5ee54700fb1 100644 (file)
@@ -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
        {
index 0d75a693cdf8ae07007a395ce8e58a3d4e6e7ba7..77d5a4ee181455f096684b3ed2456e0342520ba6 100644 (file)
 /* { 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]
index 55c646bb5ad2f3419ceebb2e3bf86054131309df..947d65c6a7e45e7d1cf042ecc4cf14d42484a81d 100644 (file)
 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 "" } */
index f0026de12da43d25a2f79039519ec8c54d68e79f..b1760536bd2978b70fc258344ed57270638d0f87 100644 (file)
 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
                   |
index e2f316b972e9f49d34769b170f00308258cd1530..54fa0b83f1d8d4a07dfa299e1cbbcf710ef13489 100644 (file)
 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
                   |