Add __builtion_unreachable to vector::size(), vector::capacity()
[official-gcc.git] / gcc / testsuite / c-c++-common / analyzer / out-of-bounds-diagram-8.c
blobc8ff2fd1e64c808ae7ee1b520b2004f245a6bfff
1 /* { dg-additional-options "-fdiagnostics-text-art-charset=unicode" } */
2 /* { dg-skip-if "requires hosted libstdc++ for stdlib size_t" { ! hostedlib } } */
4 #include <stdlib.h>
5 #include <stdint.h>
7 /* Gap of 4, then an overflow of 4. */
9 void test2 (size_t size)
11 int32_t *buf = (int32_t *) __builtin_malloc (size * sizeof(int32_t)); /* { dg-message "\\(1\\) capacity: 'size \\* 4' bytes" "" { target c } } */
12 /* { dg-message "\\(1\\) capacity: '\\(size \\* 4\\)' bytes" "" { target c++ } .-1 } */
13 if (!buf) return;
15 buf[size + 1] = 42; /* { dg-warning "heap-based buffer overflow" } */
16 __builtin_free (buf);
19 /* { dg-begin-multiline-output "" }
21 ┌───────────────────┐
22 │write of '(int) 42'│
23 └───────────────────┘
24
25
27 ┌───────────────────────────────┐ ┌───────────────────┐
28 │buffer allocated on heap at (1)│ │ after valid range │
29 └───────────────────────────────┘ └───────────────────┘
30 ├───────────────┬───────────────┤├───────┬────────┤├─────────┬─────────┤
31 │ │ │
32 ╭─────────────┴────────────╮ ╭───┴───╮ ╭─────────┴─────────╮
33 │capacity: 'size * 4' bytes│ │4 bytes│ │overflow of 4 bytes│
34 ╰──────────────────────────╯ ╰───────╯ ╰───────────────────╯
36 { dg-end-multiline-output "" } */