summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/Wstringop-overflow-8.c
blob: 513d6b1d332be3c5ed091b28cd2be762b59af2b0 (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
/* PR tree-optimization/79220 - missing -Wstringop-overflow= on a memcpy
   overflow with a small power-of-2 size
   { dg-do compile }
   { dg-options "-O2 -Wno-array-bounds -Wstringop-overflow" } */

extern void* memcpy (void*, const void*, __SIZE_TYPE__);
extern void* memmove (void*, const void*, __SIZE_TYPE__);
extern void* memset (void*, int, __SIZE_TYPE__);

char d[1];

void test_memcpy_lit_2 (void)
{
  memcpy (d, "01", 2);          /* { dg-warning "\\\[-Wstringop-overflow" } */
}

void test_memcpy_lit_4 (void)
{
  memcpy (d, "0123", 4);        /* { dg-warning "\\\[-Wstringop-overflow" } */
}

void test_memmove_lit_8 (void)
{
  memmove (d, "01234567", 8);   /* { dg-warning "\\\[-Wstringop-overflow" } */
}


void test_memcpy_ptr_2 (const void *s)
{
  memcpy (d, s, 2);             /* { dg-warning "\\\[-Wstringop-overflow" } */
}

void test_memcpy_ptr_4 (const void *s)
{
  memcpy (d, s, 4);             /* { dg-warning "\\\[-Wstringop-overflow" } */
}

void test_memcpy_ptr_8 (const void *s)
{
  memcpy (d, s, 8);             /* { dg-warning "\\\[-Wstringop-overflow" } */
}


void test_memmove_ptr (const void *s)
{
  memmove (d, s, 8);            /* { dg-warning "\\\[-Wstringop-overflow" } */
}

void test_memset_2 (void)
{
  memset (d, 0, 2);             /* { dg-warning "\\\[-Wstringop-overflow" } */
}

void test_memset_4 (void)
{
  memset (d, 0, 4);             /* { dg-warning "\\\[-Wstringop-overflow" } */
}

void test_memset_8 (void)
{
  memset (d, 0, 8);             /* { dg-warning "\\\[-Wstringop-overflow" } */
}