Skip to content

Commit e8c5013

Browse files
committed
sarif-replay: fix off-by-one in handling of "endColumn" (§3.30.8) [PR118792]
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>
1 parent 0f8fd6b commit e8c5013

File tree

5 files changed

+29
-29
lines changed

5 files changed

+29
-29
lines changed

gcc/libsarifreplay.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1739,7 +1739,7 @@ handle_region_object (const json::object &region_obj,
17391739
/* SARIF's endColumn is 1 beyond the final column in the region,
17401740
whereas GCC's end columns are inclusive. */
17411741
end = m_output_mgr.new_location_from_file_line_column
1742-
(file, end_line, end_column_jnum->get ());
1742+
(file, end_line, end_column_jnum->get () - 1);
17431743
}
17441744
else
17451745
{

gcc/testsuite/sarif-replay.dg/2.1.0-valid/error-with-note.sarif

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626
/* { dg-begin-multiline-output "" }
2727
/this/does/not/exist/test.bas:2:8: error: 'GOTO' is considered harmful
2828
2 | GOTO label
29-
| ^~~~~~~~~~
29+
| ^~~~~~~~~~
3030
{ dg-end-multiline-output "" } */
3131
/* { dg-begin-multiline-output "" }
3232
/this/does/not/exist/test.bas:1:1: note: this is the target of the 'GOTO'
3333
1 | label: PRINT "hello world!"
34-
| ^~~~~~
34+
| ^~~~~
3535
{ dg-end-multiline-output "" } */
3636

3737
// TODO: trailing [error]

gcc/testsuite/sarif-replay.dg/2.1.0-valid/malloc-vs-local-4.c.sarif

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -339,37 +339,37 @@
339339
In function 'callee_1':
340340
/not/a/real/path/malloc-vs-local-4.c:5:3: warning: dereference of possibly-NULL ‘ptr’ [-Wanalyzer-possible-null-dereference]
341341
5 | *ptr = 42;
342-
| ^~~~~~~~~~
342+
| ^~~~~~~~~
343343
'test_1': events 1-5
344344
|
345345
| 8 | int test_1 (int i, int flag)
346-
| | ^~~~~~~
346+
| | ^~~~~~
347347
| | |
348348
| | (1) entry to ‘test_1’
349349
|......
350350
| 12 | if (flag)
351-
| | ~~
351+
| | ~
352352
| | |
353353
| | (2) following ‘true’ branch (when ‘flag != 0’)...
354354
| 13 | ptr = (int *)malloc (sizeof (int));
355-
| | ~~~~~~~~~~~~~~~~~~~~~~
355+
| | ~~~~~~~~~~~~~~~~~~~~~
356356
| | |
357357
| | (3) ...to here
358358
| | (4) this call could return NULL
359359
| 14 | callee_1 (ptr);
360-
| | ~~~~~~~~~~~~~~~
360+
| | ~~~~~~~~~~~~~~
361361
| | |
362362
| | (5) calling ‘callee_1’ from ‘test_1’
363363
|
364364
+--> 'callee_1': events 6-7
365365
|
366366
| 3 | void __attribute__((noinline)) callee_1 (int *ptr)
367-
| | ^~~~~~~~~
367+
| | ^~~~~~~~
368368
| | |
369369
| | (6) entry to ‘callee_1’
370370
| 4 | {
371371
| 5 | *ptr = 42;
372-
| | ~~~~~~~~~~
372+
| | ~~~~~~~~~
373373
| | |
374374
| | (7) ‘ptr’ could be NULL: unchecked value from (4)
375375
|
@@ -378,24 +378,24 @@ In function 'callee_1':
378378
In function 'test_2':
379379
/not/a/real/path/malloc-vs-local-4.c:38:7: warning: double-‘free’ of ‘ptr’ [-Wanalyzer-double-free]
380380
38 | free (ptr);
381-
| ^~~~~~~~~~~
381+
| ^~~~~~~~~~
382382
'test_2': events 1-5
383383
34 | if (!flag)
384-
| ^~
384+
| ^
385385
| |
386386
| (1) following ‘true’ branch (when ‘flag == 0’)...
387387
35 | {
388388
36 | void *ptr = malloc (16);
389-
| ~~~~~~~~~~~~
389+
| ~~~~~~~~~~~
390390
| |
391391
| (2) ...to here
392392
| (3) allocated here
393393
37 | free (ptr);
394-
| ~~~~~~~~~~~
394+
| ~~~~~~~~~~
395395
| |
396396
| (4) first ‘free’ here
397397
38 | free (ptr);
398-
| ~~~~~~~~~~~
398+
| ~~~~~~~~~~
399399
| |
400400
| (5) second ‘free’ here; first ‘free’ was at (4)
401401
{ dg-end-multiline-output "" } */

gcc/testsuite/sarif-replay.dg/2.1.0-valid/signal-1.c.moved.sarif

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,16 +170,16 @@
170170
In function 'custom_logger':
171171
signal-1.c:13:3: warning: call to ‘fprintf’ from within signal handler [-Wanalyzer-unsafe-call-within-signal-handler]
172172
13 | fprintf(stderr, "LOG: %s", msg);
173-
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
173+
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
174174
'main': events 1-2
175175
|
176176
| 21 | int main(int argc, const char *argv)
177-
| | ^~~~~
177+
| | ^~~~
178178
| | |
179179
| | (1) entry to ‘main’
180180
|......
181181
| 25 | signal(SIGINT, handler);
182-
| | ~~~~~~~~~~~~~~~~~~~~~~~~
182+
| | ~~~~~~~~~~~~~~~~~~~~~~~
183183
| | |
184184
| | (2) registering ‘handler’ as signal handler
185185
|
@@ -191,24 +191,24 @@ signal-1.c:13:3: warning: call to ‘fprintf’ from within signal handler [-Wan
191191
+--> 'handler': events 4-5
192192
|
193193
| 16 | static void handler(int signum)
194-
| | ^~~~~~~~
194+
| | ^~~~~~~
195195
| | |
196196
| | (4) entry to ‘handler’
197197
| 17 | {
198198
| 18 | custom_logger("got signal");
199-
| | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
199+
| | ~~~~~~~~~~~~~~~~~~~~~~~~~~~
200200
| | |
201201
| | (5) calling ‘custom_logger’ from ‘handler’
202202
|
203203
+--> 'custom_logger': events 6-7
204204
|
205205
| 11 | void custom_logger(const char *msg)
206-
| | ^~~~~~~~~~~~~~
206+
| | ^~~~~~~~~~~~~
207207
| | |
208208
| | (6) entry to ‘custom_logger’
209209
| 12 | {
210210
| 13 | fprintf(stderr, "LOG: %s", msg);
211-
| | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
211+
| | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
212212
| | |
213213
| | (7) call to ‘fprintf’ from within signal handler
214214
|

gcc/testsuite/sarif-replay.dg/2.1.0-valid/signal-1.c.sarif

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,16 +168,16 @@
168168
In function 'custom_logger':
169169
../../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]
170170
13 | fprintf(stderr, "LOG: %s", msg);
171-
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
171+
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
172172
'main': events 1-2
173173
|
174174
| 21 | int main(int argc, const char *argv)
175-
| | ^~~~~
175+
| | ^~~~
176176
| | |
177177
| | (1) entry to ‘main’
178178
|......
179179
| 25 | signal(SIGINT, handler);
180-
| | ~~~~~~~~~~~~~~~~~~~~~~~~
180+
| | ~~~~~~~~~~~~~~~~~~~~~~~
181181
| | |
182182
| | (2) registering ‘handler’ as signal handler
183183
|
@@ -189,24 +189,24 @@ In function 'custom_logger':
189189
+--> 'handler': events 4-5
190190
|
191191
| 16 | static void handler(int signum)
192-
| | ^~~~~~~~
192+
| | ^~~~~~~
193193
| | |
194194
| | (4) entry to ‘handler’
195195
| 17 | {
196196
| 18 | custom_logger("got signal");
197-
| | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
197+
| | ~~~~~~~~~~~~~~~~~~~~~~~~~~~
198198
| | |
199199
| | (5) calling ‘custom_logger’ from ‘handler’
200200
|
201201
+--> 'custom_logger': events 6-7
202202
|
203203
| 11 | void custom_logger(const char *msg)
204-
| | ^~~~~~~~~~~~~~
204+
| | ^~~~~~~~~~~~~
205205
| | |
206206
| | (6) entry to ‘custom_logger’
207207
| 12 | {
208208
| 13 | fprintf(stderr, "LOG: %s", msg);
209-
| | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
209+
| | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
210210
| | |
211211
| | (7) call to ‘fprintf’ from within signal handler
212212
|

0 commit comments

Comments
 (0)