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