Debian Codegraph @

gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-9.c

raw
1 /* { dg-additional-options "-fdiagnostics-text-art-charset=unicode" } */
2
3 #include <stdint.h>
4
5 struct st
6 {
7 char buf[16];
8 int32_t x;
9 int32_t y;
10 };
11
12 struct st arr[10];
13
14 int32_t struct_arr_read_x_element_before_start_far(void)
15 {
16 return arr[-100].x; /* { dg-warning "buffer under-read" "warning" } */
17 /* { dg-message "out-of-bounds read from byte -2384 till byte -2381 but 'arr' starts at byte 0" "final event" { target *-*-* } .-1 } */
18 /* { dg-message "valid subscripts for 'arr' are '\\\[0\\\]' to '\\\[9\\\]'" "valid subscript note" { target *-*-* } .-2 } */
19 }
20
21 // TODO: show index of accessed element
22 // TODO: show field of accessed element
23 /* { dg-begin-multiline-output "" }
24
25 ┌───────────────────────────┐
26 │read of 'int32_t' (4 bytes)│
27 └───────────────────────────┘
28 ^
29 │
30 │
31 ┌───────────────────────────┐ ┌─────────┬─────────┬─────────┐
32 │ │ │ [0] │ ... │ [9] │
33 │ before valid range │ ├─────────┴─────────┴─────────┤
34 │ │ │'arr' (type: 'struct st[10]')│
35 └───────────────────────────┘ └─────────────────────────────┘
36 ├─────────────┬─────────────┤├────┬─────┤├──────────────┬──────────────┤
37 │ │ │
38 ╭──────────┴──────────╮ ╭─────┴────╮ ╭───────┴───────╮
39 │under-read of 4 bytes│ │2380 bytes│ │size: 240 bytes│
40 ╰─────────────────────╯ ╰──────────╯ ╰───────────────╯
41
42 { dg-end-multiline-output "" } */