| 1 |
/* { dg-do compile } */ |
| 2 |
/* { dg-require-effective-target analyzer } */ |
| 3 |
/* { dg-options "-fanalyzer -fdiagnostics-format=sarif-file" } */ |
| 4 |
|
| 5 |
/* Verify that SARIF output can capture chains of include files in |
| 6 |
diagnostic paths within result locations. |
| 7 |
|
| 8 |
Generate an analyzer warning with a path, using a chain of header files |
| 9 |
both for the warning and for the events within its esxecution path. |
| 10 |
In textual form, we'd expect something like: |
| 11 |
|
| 12 |
In file included from PATH/include-chain-2.c:28: |
| 13 |
PATH/include-chain-2.h: In function 'test': |
| 14 |
PATH/include-chain-2.h:6:3: warning: double-'free' of 'ptr' [CWE-415] [-Wanalyzer-double-free] |
| 15 |
6 | __builtin_free (ptr); |
| 16 |
| ^~~~~~~~~~~~~~~~~~~~ |
| 17 |
'test': events 1-2 |
| 18 |
5 | __builtin_free (ptr); |
| 19 |
| ^~~~~~~~~~~~~~~~~~~~ |
| 20 |
| | |
| 21 |
| (1) first 'free' here |
| 22 |
6 | __builtin_free (ptr); |
| 23 |
| ~~~~~~~~~~~~~~~~~~~~ |
| 24 |
| | |
| 25 |
| (2) second 'free' here; first 'free' was at (1) |
| 26 |
*/ |
| 27 |
|
| 28 |
#include "include-chain-2.h" |
| 29 |
|
| 30 |
/* Verify that some JSON was written to a file with the expected name: |
| 31 |
{ dg-final { verify-sarif-file } } */ |
| 32 |
|
| 33 |
/* Use a Python script to verify various properties about the generated |
| 34 |
.sarif file: |
| 35 |
{ dg-final { run-sarif-pytest include-chain-2.c "include-chain-2.py" } } */ |