* gcc.dg/stack-check-5.c: Skip with -fstack-protector.
[official-gcc.git] / gcc / testsuite / gcc.dg / attr-alloc_size-11.c
blobfe6154a0d77752b315632b09399d73dc31cbc3a0
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.
5 { dg-do compile }
6 { dg-options "-O2 -Walloc-size-larger-than=12 -ftrack-macro-expansion=0" } */
8 #define SCHAR_MAX __SCHAR_MAX__
9 #define SCHAR_MIN (-SCHAR_MAX - 1)
10 #define UCHAR_MAX (SCHAR_MAX * 2 + 1)
12 #define SHRT_MAX __SHRT_MAX__
13 #define SHRT_MIN (-SHRT_MAX - 1)
14 #define USHRT_MAX (SHRT_MAX * 2 + 1)
16 #define INT_MAX __INT_MAX__
17 #define INT_MIN (-INT_MAX - 1)
18 #define UINT_MAX (INT_MAX * 2U + 1)
20 #define LONG_MAX __LONG_MAX__
21 #define LONG_MIN (-LONG_MAX - 1)
22 #define ULONG_MAX (LONG_MAX * 2LU + 1)
24 #define PTRDIFF_MAX __PTRDIFF_MAX__
25 #define PTRDIFF_MIN (-PTRDIFF_MAX - 1)
26 #define SIZE_MAX __SIZE_MAX__
28 #define ALLOC_MAX 12
30 typedef __PTRDIFF_TYPE__ ptrdiff_t;
31 typedef __SIZE_TYPE__ size_t;
33 #define CONCAT(a, b) a ## b
34 #define CAT(a, b) CONCAT (a, b)
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. */
48 /* The following tests fail because of missing range information. The xfail
49 exclusions are PR79356. */
50 TEST (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*-*-* alpha*-*-* ia64-*-* mips*-*-* powerpc*-*-* sparc*-*-* s390*-*-* } } } } */
51 TEST (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*-*-* ia64-*-* mips*-*-* powerpc*-*-* sparc*-*-* s390x-*-* } } } } */
52 TEST (int, INT_MIN + 2, ALLOC_MAX); /* { dg-warning "argument 1 range \\\[13, \[0-9\]+\\\] exceeds maximum object size 12" } */
53 TEST (int, -3, ALLOC_MAX); /* { dg-warning "argument 1 range \\\[13, \[0-9\]+\\\] exceeds maximum object size 12" } */
54 TEST (int, -2, ALLOC_MAX); /* { dg-warning "argument 1 range \\\[13, \[0-9\]+\\\] exceeds maximum object size 12" } */
55 TEST (int, -1, ALLOC_MAX); /* { dg-warning "argument 1 range \\\[13, \[0-9\]+\\\] exceeds maximum object size 12" } */
56 TEST (int, 0, ALLOC_MAX); /* { dg-warning "argument 1 range \\\[13, \[0-9\]+\\\] exceeds maximum object size 12" } */
57 TEST (int, 1, ALLOC_MAX); /* { dg-warning "argument 1 range \\\[13, \[0-9\]+\\\] exceeds maximum object size 12" } */
58 TEST (int, 1, INT_MAX - 1); /* { dg-warning "argument 1 range \\\[\[0-9\]+, \[0-9\]+\\\] exceeds maximum object size 12" } */
60 /* The following two aren't necessarily anti-ranges. */
61 TEST (int, 1, INT_MAX); /* { dg-warning "argument 1 range \\\[-\[0-9\]+, 0\\\] is negative" } */
62 TEST (int, 0, INT_MAX); /* { dg-warning "argument 1 range \\\[-\[0-9\]+, -1\\\] is negative" } */
64 TEST (long, LONG_MIN + 2, ALLOC_MAX); /* { dg-warning "argument 1 range \\\[13, \[0-9\]+\\\] exceeds maximum object size 12" } */
65 TEST (ptrdiff_t, PTRDIFF_MIN + 2, ALLOC_MAX); /* { dg-warning "argument 1 range \\\[13, \[0-9\]+\\\] exceeds maximum object size 12" } */
67 TEST (unsigned, 0, ALLOC_MAX); /* { dg-warning "argument 1 range \\\[13, \[0-9\]+\\\] exceeds maximum object size 12" } */
68 TEST (unsigned long, 0, ALLOC_MAX); /* { dg-warning "argument 1 range \\\[13, \[0-9\]+\\\] exceeds maximum object size 12" } */
69 TEST (size_t, 0, ALLOC_MAX); /* { dg-warning "argument 1 range \\\[13, \[0-9\]+\\\] exceeds maximum object size 12" } */