File: builtin-stringop-chk-7.c

package info (click to toggle)
gcc-arm-none-eabi 15%3A14.2.rel1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,099,328 kB
  • sloc: cpp: 3,627,108; ansic: 2,571,498; ada: 834,230; f90: 235,082; makefile: 79,231; asm: 74,984; xml: 51,692; exp: 39,736; sh: 33,298; objc: 15,629; python: 15,069; fortran: 14,429; pascal: 7,003; awk: 5,070; perl: 3,106; ml: 285; lisp: 253; lex: 204; haskell: 135
file content (72 lines) | stat: -rw-r--r-- 1,836 bytes parent folder | download | duplicates (2)
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
/* Verify that -Wstringop-overflow doesn't cause false positives for
   anti-ranges.  Note that not all of the statements below result in
   the memset argument being represented as an anti-range.

   { dg-do compile }
   { dg-options "-O2 -Wstringop-overflow" } */

#define SCHAR_MAX __SCHAR_MAX__
#define UCHAR_MAX (SCHAR_MAX * 2 + 1)

#define SHRT_MAX  __SHRT_MAX__
#define USHRT_MAX (SHRT_MAX * 2U + 1)

#define INT_MAX   __INT_MAX__
#define UINT_MAX  (INT_MAX * 2U + 1)

#define LONG_MAX __LONG_MAX__
#define ULONG_MAX (LONG_MAX * 2LU + 1)

#define PTRDIFF_MAX __PTRDIFF_MAX__
#define SIZE_MAX    __SIZE_MAX__

typedef __PTRDIFF_TYPE__ ptrdiff_t;
typedef __SIZE_TYPE__    size_t;

#define TEST_AR_1(T, prefix)			\
  void test_ar_1_ ## prefix (void *d, T n)	\
  {						\
    if (n == prefix ## _MAX - 1)		\
      n = prefix ## _MAX - 2;			\
    __builtin_memset (d, 0, n);			\
  } typedef void dummy

#define TEST_AR_2(T, prefix)					\
  void test_ar_2_ ## prefix (void *d, T n)			\
  {								\
    if (prefix ## _MAX - 2 <= n && n <= prefix ## _MAX - 1)	\
      n = prefix ## _MAX - 3;					\
    __builtin_memset (d, 0, n);					\
  } typedef void dummy

/* Verify antirange where MIN == MAX.  */
TEST_AR_1 (signed char, SCHAR);
TEST_AR_1 (unsigned char, UCHAR);

TEST_AR_1 (short, SHRT);
TEST_AR_1 (unsigned short, USHRT);

TEST_AR_1 (int, INT);
TEST_AR_1 (unsigned, UINT);

TEST_AR_1 (long, LONG);
TEST_AR_1 (unsigned long, ULONG);

TEST_AR_1 (ptrdiff_t, PTRDIFF);
TEST_AR_1 (size_t, SIZE);

/* Verify antirange where MIN < MAX.  */
TEST_AR_2 (signed char, SCHAR);
TEST_AR_2 (unsigned char, UCHAR);

TEST_AR_2 (short, SHRT);
TEST_AR_2 (unsigned short, USHRT);

TEST_AR_2 (int, INT);
TEST_AR_2 (unsigned, UINT);

TEST_AR_2 (long, LONG);
TEST_AR_2 (unsigned long, ULONG);

TEST_AR_2 (ptrdiff_t, PTRDIFF);
TEST_AR_2 (size_t, SIZE);