]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/testsuite/gcc.dg/attr-alloc_size-11.c
Update copyright years.
[thirdparty/gcc.git] / gcc / testsuite / gcc.dg / attr-alloc_size-11.c
CommitLineData
c16880ef
MS
1/* Verify that -Walloc-size-greater-than doesn't cause false positives
2 for anti-ranges. Note that not all of the statements below result
3 in the argument being represented as an anti-range.
4
5 { dg-do compile }
6 { dg-options "-O2 -Walloc-size-larger-than=12 -ftrack-macro-expansion=0" } */
7
8#define SCHAR_MAX __SCHAR_MAX__
9#define SCHAR_MIN (-SCHAR_MAX - 1)
10#define UCHAR_MAX (SCHAR_MAX * 2 + 1)
11
12#define SHRT_MAX __SHRT_MAX__
13#define SHRT_MIN (-SHRT_MAX - 1)
d0cb4057 14#define USHRT_MAX (SHRT_MAX * 2U + 1)
c16880ef
MS
15
16#define INT_MAX __INT_MAX__
17#define INT_MIN (-INT_MAX - 1)
18#define UINT_MAX (INT_MAX * 2U + 1)
19
20#define LONG_MAX __LONG_MAX__
21#define LONG_MIN (-LONG_MAX - 1)
22#define ULONG_MAX (LONG_MAX * 2LU + 1)
23
24#define PTRDIFF_MAX __PTRDIFF_MAX__
25#define PTRDIFF_MIN (-PTRDIFF_MAX - 1)
26#define SIZE_MAX __SIZE_MAX__
27
28#define ALLOC_MAX 12
29
30typedef __PTRDIFF_TYPE__ ptrdiff_t;
31typedef __SIZE_TYPE__ size_t;
32
33#define CONCAT(a, b) a ## b
34#define CAT(a, b) CONCAT (a, b)
35
36/* Macro to generate a unique function to test the anti-range
37 ~[MIN, MAX] for type T. */
38#define TEST(T, min, max) \
39 void* CAT (test_anti_range_, __LINE__)(T n) \
40 { \
41 extern void* CAT (alloc_anti_range_, __LINE__)(T) \
42 __attribute__ ((alloc_size (1))); \
43 if (min <= n && n <= max) \
44 n = min - 1; \
45 return CAT (alloc_anti_range_, __LINE__)(n); \
46 } typedef void dummy /* Require a semicolon. */
47
730e6e46
SB
48/* The following tests fail because of missing range information. The xfail
49 exclusions are PR79356. */
49451c5e
TV
50TEST (signed char, SCHAR_MIN + 2, ALLOC_MAX); /* { dg-warning "argument 1 range \\\[13, \[0-9\]+\\\] exceeds maximum object size 12" "missing range info for signed char" { xfail { ! { aarch64*-*-* arm*-*-* avr-*-* alpha*-*-* ia64-*-* mips*-*-* or1k*-*-* pdp11*-*-* powerpc*-*-* sparc*-*-* s390*-*-* visium-*-* msp430-*-* nvptx*-*-*} } } } */
51TEST (short, SHRT_MIN + 2, ALLOC_MAX); /* { dg-warning "argument 1 range \\\[13, \[0-9\]+\\\] exceeds maximum object size 12" "missing range info for short" { xfail { ! { aarch64*-*-* arm*-*-* alpha*-*-* avr-*-* ia64-*-* mips*-*-* or1k*-*-* pdp11*-*-* powerpc*-*-* sparc*-*-* s390x-*-* visium-*-* msp430-*-* nvptx*-*-* } } } } */
c16880ef
MS
52TEST (int, INT_MIN + 2, ALLOC_MAX); /* { dg-warning "argument 1 range \\\[13, \[0-9\]+\\\] exceeds maximum object size 12" } */
53TEST (int, -3, ALLOC_MAX); /* { dg-warning "argument 1 range \\\[13, \[0-9\]+\\\] exceeds maximum object size 12" } */
54TEST (int, -2, ALLOC_MAX); /* { dg-warning "argument 1 range \\\[13, \[0-9\]+\\\] exceeds maximum object size 12" } */
55TEST (int, -1, ALLOC_MAX); /* { dg-warning "argument 1 range \\\[13, \[0-9\]+\\\] exceeds maximum object size 12" } */
56TEST (int, 0, ALLOC_MAX); /* { dg-warning "argument 1 range \\\[13, \[0-9\]+\\\] exceeds maximum object size 12" } */
57TEST (int, 1, ALLOC_MAX); /* { dg-warning "argument 1 range \\\[13, \[0-9\]+\\\] exceeds maximum object size 12" } */
58TEST (int, 1, INT_MAX - 1); /* { dg-warning "argument 1 range \\\[\[0-9\]+, \[0-9\]+\\\] exceeds maximum object size 12" } */
59
60/* The following two aren't necessarily anti-ranges. */
61TEST (int, 1, INT_MAX); /* { dg-warning "argument 1 range \\\[-\[0-9\]+, 0\\\] is negative" } */
62TEST (int, 0, INT_MAX); /* { dg-warning "argument 1 range \\\[-\[0-9\]+, -1\\\] is negative" } */
63
64TEST (long, LONG_MIN + 2, ALLOC_MAX); /* { dg-warning "argument 1 range \\\[13, \[0-9\]+\\\] exceeds maximum object size 12" } */
65TEST (ptrdiff_t, PTRDIFF_MIN + 2, ALLOC_MAX); /* { dg-warning "argument 1 range \\\[13, \[0-9\]+\\\] exceeds maximum object size 12" } */
66
67TEST (unsigned, 0, ALLOC_MAX); /* { dg-warning "argument 1 range \\\[13, \[0-9\]+\\\] exceeds maximum object size 12" } */
68TEST (unsigned long, 0, ALLOC_MAX); /* { dg-warning "argument 1 range \\\[13, \[0-9\]+\\\] exceeds maximum object size 12" } */
69TEST (size_t, 0, ALLOC_MAX); /* { dg-warning "argument 1 range \\\[13, \[0-9\]+\\\] exceeds maximum object size 12" } */