aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/Wstringop-overflow-71.c
blob: 74311ecf7ff47c7fab4ca610c544d236d32da3ce (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
111
112
113
114
/* PR tree-optimization/97027 - missing warning on buffer overflow storing
   a larger scalar into a smaller array
   Verify warnings for overflow by stores of results of built-in functions.
   { dg-do compile }
   { dg-options "-O2" }
   { dg-require-effective-target alloca } */

typedef __INT16_TYPE__ int16_t;
typedef __SIZE_TYPE__  size_t;

extern int abs (int);

extern void* alloca (size_t);

extern double nan (const char *);

#ifdef __DEC32_MAX__
  _Decimal32 nand32 (const char *);
#else
/* _Decimal32 is supported only conditionally and not available on all
   targets.  */
#  define _Decimal32  double
#  define nand32(s)   nan (s)
#endif

extern size_t strlen (const char *);
extern char* strcpy (char *, const char *);


extern unsigned char ax[], a1[1], a2[2], a8[8];


void nowarn_abs (int i)
{
  *(int *)ax = abs (i);
  *(char *)a1 = abs (i);
}

void warn_abs (int i)
{
  *(int *)a1 = abs (i);         // { dg-warning "\\\[-Wstringop-overflow" }
}


void nowarn_alloca (size_t n)
{
  *(void **)ax = alloca (n);
}

void warn_alloca (size_t n)
{
  *(void **)a1 = alloca (n);    // { dg-warning "\\\[-Wstringop-overflow" }
}


void nowarn_complex (double x, double i)
{
  *(_Complex double *)ax = __builtin_complex (x, i);
}

void warn_complex (double x, double i)
{
  _Complex double *p = (_Complex double *)a1;
  *p = __builtin_complex (x, i);  // { dg-warning "\\\[-Wstringop-overflow" "pr101455" { xfail *-*-* } }
}


__attribute__ ((noipa)) void nowarn_nan (const char *s)
{
  *(double *)ax = nan (s);
}

__attribute__ ((noipa)) void warn_nan (const char *s)
{
  *(double *)a1 = nan (s);      // { dg-warning "\\\[-Wstringop-overflow" }
}


__attribute__ ((noipa)) void nowarn_nand32 (const char *s)
{
  *(_Decimal32 *)ax = nand32 (s);
}

__attribute__ ((noipa)) void warn_nand32 (const char *s)
{
  *(_Decimal32 *)a1 = nand32 (s); // { dg-warning "\\\[-Wstringop-overflow" }
}


void nowarn_strlen (const char *s1, const char *s2, const char *s3)
{
  *(char *)ax = strlen (s1);
  *(char *)a1 = strlen (s2);
  *(size_t *)a8 = strlen (s3);
}

void warn_strlen (const char *s1, const char *s2)
{
  *(int16_t *)a1 = strlen (s1); // { dg-warning "\\\[-Wstringop-overflow" }
  *(size_t *)a2 = strlen (s2);  // { dg-warning "\\\[-Wstringop-overflow" "!ptr_eq_short" { target { ! ptr_eq_short } } }
}


void nowarn_strcpy (char *s1, char *s2, const char *s3)
{
  *(char **)ax = strcpy (s1, s2);
  *(char **)a8 = strcpy (s2, s3);
}

void warn_strcpy (char *s1, char *s2, const char *s3)
{
  *(char **)a1 = strcpy (s1, s2);   // { dg-warning "\\\[-Wstringop-overflow" }
  *(char **)a2 = strcpy (s2, s3);   // { dg-warning "\\\[-Wstringop-overflow" "!ptr_eq_short" { target { ! ptr_eq_short } } }
}