Mercurial > hg > CbC > CbC_gcc
comparison gcc/testsuite/gcc.dg/attr-alloc_size-3.c @ 131:84e7813d76e9
gcc-8.2
author | mir3636 |
---|---|
date | Thu, 25 Oct 2018 07:37:49 +0900 |
parents | 04ced10e8804 |
children | 1830386684a0 |
comparison
equal
deleted
inserted
replaced
111:04ced10e8804 | 131:84e7813d76e9 |
---|---|
3 PR c/78284 - warn on malloc with very large arguments | 3 PR c/78284 - warn on malloc with very large arguments |
4 Test exercising the ability to detect and diagnose calls to allocation | 4 Test exercising the ability to detect and diagnose calls to allocation |
5 functions decorated with attribute alloc_size that either overflow or | 5 functions decorated with attribute alloc_size that either overflow or |
6 exceed the default maximum object size (with -Walloc-size-larger-than | 6 exceed the default maximum object size (with -Walloc-size-larger-than |
7 not explicitly specified). */ | 7 not explicitly specified). */ |
8 /* { dg-do compile } */ | 8 /* { dg-do compile { target size32plus } } */ |
9 /* { dg-options "-O2 -Wall" } */ | 9 /* { dg-options "-O2 -Wall" } */ |
10 | 10 |
11 #define SCHAR_MAX __SCHAR_MAX__ | 11 #define SCHAR_MAX __SCHAR_MAX__ |
12 #define SCHAR_MIN (-SCHAR_MAX - 1) | 12 #define SCHAR_MIN (-SCHAR_MAX - 1) |
13 #define UCHAR_MAX (SCHAR_MAX * 2 + 1) | 13 #define UCHAR_MAX (SCHAR_MAX * 2 + 1) |
63 void* f_llong_2 (long long, long long) ALLOC_SIZE (1, 2); | 63 void* f_llong_2 (long long, long long) ALLOC_SIZE (1, 2); |
64 | 64 |
65 void* f_size_1 (size_t) ALLOC_SIZE (1); | 65 void* f_size_1 (size_t) ALLOC_SIZE (1); |
66 void* f_size_2 (size_t, size_t) ALLOC_SIZE (1, 2); | 66 void* f_size_2 (size_t, size_t) ALLOC_SIZE (1, 2); |
67 | 67 |
68 size_t | 68 static size_t |
69 unsigned_range (size_t min, size_t max) | 69 unsigned_range (size_t min, size_t max) |
70 { | 70 { |
71 extern size_t random_unsigned_value (void); | 71 extern size_t random_unsigned_value (void); |
72 size_t val = random_unsigned_value (); | 72 size_t val = random_unsigned_value (); |
73 if (val < min || max < val) val = min; | 73 if (val < min || max < val) val = min; |
74 return val; | 74 return val; |
75 } | 75 } |
76 | 76 |
77 long long | 77 static long long |
78 signed_range (long long min, long long max) | 78 signed_range (long long min, long long max) |
79 { | 79 { |
80 extern long long random_signed_value (void); | 80 extern long long random_signed_value (void); |
81 long long val = random_signed_value (); | 81 long long val = random_signed_value (); |
82 if (val < min || max < val) val = min; | 82 if (val < min || max < val) val = min; |
83 return val; | 83 return val; |
84 } | 84 } |
85 | 85 |
86 size_t | 86 static size_t |
87 unsigned_anti_range (size_t min, size_t max) | 87 unsigned_anti_range (size_t min, size_t max) |
88 { | 88 { |
89 extern size_t random_unsigned_value (void); | 89 extern size_t random_unsigned_value (void); |
90 size_t val = random_unsigned_value (); | 90 size_t val = random_unsigned_value (); |
91 if (min <= val && val <= max) | |
92 val = min - 1; | |
93 return val; | |
94 } | |
95 | |
96 long long | |
97 signed_anti_range (long long min, long long max) | |
98 { | |
99 extern long long random_signed_value (void); | |
100 long long val = random_signed_value (); | |
101 if (min <= val && val <= max) | 91 if (min <= val && val <= max) |
102 val = min - 1; | 92 val = min - 1; |
103 return val; | 93 return val; |
104 } | 94 } |
105 | 95 |