blob: 3cedf06d25837885916507765a566ce53aa1e462 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
/* { dg-additional-options "-fdiagnostics-text-art-charset=unicode" } */
#include <stdint.h>
extern int32_t arr_0[0]; /* { dg-message "capacity: 0 bytes" } */
extern int32_t arr_1[1]; /* { dg-message "capacity: 4 bytes" } */
extern int32_t arr_2[2]; /* { dg-message "capacity: 8 bytes" } */
extern int32_t arr_3[3]; /* { dg-message "capacity: 12 bytes" } */
extern int32_t arr_4[4]; /* { dg-message "capacity: 16 bytes" } */
void test_immediately_after (int x)
{
arr_0[0] = x; /* { dg-warning "buffer overflow" } */
arr_1[1] = x; /* { dg-warning "buffer overflow" } */
arr_2[2] = x; /* { dg-warning "buffer overflow" } */
arr_3[3] = x; /* { dg-warning "buffer overflow" } */
arr_4[4] = x; /* { dg-warning "buffer overflow" } */
}
/* Expect no diagram for the arr_0 case: there's no valid region
to write to. */
/* The arr_1 case. */
/* { dg-begin-multiline-output "" }
┌──────────────────────────────────┐
│ write from 'x' (type: 'int') │
└──────────────────────────────────┘
│
│
v
┌──────────────────────────────────┐┌──────────────────────────────────┐
│ [0] ││ │
├──────────────────────────────────┤│ after valid range │
│ 'arr_1' (type: 'int32_t[1]') ││ │
└──────────────────────────────────┘└──────────────────────────────────┘
├────────────────┬─────────────────┤├────────────────┬─────────────────┤
│ │
╭────────┴────────╮ ╭─────────┴─────────╮
│capacity: 4 bytes│ │overflow of 4 bytes│
╰─────────────────╯ ╰───────────────────╯
{ dg-end-multiline-output "" } */
/* The arr_2 case. */
/* { dg-begin-multiline-output "" }
┌────────────────────────────┐
│write from 'x' (type: 'int')│
└────────────────────────────┘
│
│
v
┌────────────────────┬───────────────────┐┌────────────────────────────┐
│ [0] │ [1] ││ │
├────────────────────┴───────────────────┤│ after valid range │
│ 'arr_2' (type: 'int32_t[2]') ││ │
└────────────────────────────────────────┘└────────────────────────────┘
├───────────────────┬────────────────────┤├─────────────┬──────────────┤
│ │
╭────────┴────────╮ ╭─────────┴─────────╮
│capacity: 8 bytes│ │overflow of 4 bytes│
╰─────────────────╯ ╰───────────────────╯
{ dg-end-multiline-output "" } */
/* The arr_3 case. */
// Perhaps we should show [1] rather than ellipsize here.
/* { dg-begin-multiline-output "" }
┌────────────────────────────┐
│write from 'x' (type: 'int')│
└────────────────────────────┘
│
│
v
┌─────────────┬─────────────┬────────────┐┌────────────────────────────┐
│ [0] │ ... │ [2] ││ │
├─────────────┴─────────────┴────────────┤│ after valid range │
│ 'arr_3' (type: 'int32_t[3]') ││ │
└────────────────────────────────────────┘└────────────────────────────┘
├───────────────────┬────────────────────┤├─────────────┬──────────────┤
│ │
╭─────────┴────────╮ ╭─────────┴─────────╮
│capacity: 12 bytes│ │overflow of 4 bytes│
╰──────────────────╯ ╰───────────────────╯
{ dg-end-multiline-output "" } */
/* The arr_4 case. */
/* { dg-begin-multiline-output "" }
┌────────────────────────────┐
│write from 'x' (type: 'int')│
└────────────────────────────┘
│
│
v
┌──────────┬──────────────────┬──────────┐┌────────────────────────────┐
│ [0] │ ... │ [3] ││ │
├──────────┴──────────────────┴──────────┤│ after valid range │
│ 'arr_4' (type: 'int32_t[4]') ││ │
└────────────────────────────────────────┘└────────────────────────────┘
├───────────────────┬────────────────────┤├─────────────┬──────────────┤
│ │
╭─────────┴────────╮ ╭─────────┴─────────╮
│capacity: 16 bytes│ │overflow of 4 bytes│
╰──────────────────╯ ╰───────────────────╯
{ dg-end-multiline-output "" } */
|