Debian Codegraph @

gcc/testsuite/g++.dg/ext/attr-alloc_size.C

raw
1 /* PR c++/87541 - ICE using a constant decl as an attribute alloc_size argument
2 { dg-do compile }
3 { dg-options "-O2 -Wall -Wno-array-bounds" } */
4
5 #define ALLOC_SIZE(N) __attribute__ ((alloc_size (N)))
6
7 const int i1 = 1;
8 ALLOC_SIZE (i1) void* fcst (int);
9
10 void* call_fcst (void)
11 {
12 void *p = fcst (1);
13 __builtin___memset_chk (p, 0, 2, __builtin_object_size (p, 1)); // { dg-warning "\\\[-Wstringop-overflow=" }
14 return p;
15 }
16
17
18 enum { e1 = 1 };
19 ALLOC_SIZE (e1) void* fenum (int);
20
21 void* call_fenum (void)
22 {
23 void *p = fenum (1);
24 __builtin___memset_chk (p, 0, 2, __builtin_object_size (p, 1)); // { dg-warning "\\\[-Wstringop-overflow=" }
25 return p;
26 }
27
28
29 template <class T>
30 struct A
31 {
32 ALLOC_SIZE (T::N1) static void* ftemplarg_1 (int);
33 ALLOC_SIZE (T::N2) static void*
34 ftemplarg_2 (int); // { dg-warning "attribute argument value .2. exceeds the number of function parameters 1" }
35 };
36
37 struct B { static const int N1 = 1; static const int N2 = 1; };
38
39 void* call_ftemplarg_1 (A<B> *pa)
40 {
41 void *p = pa->ftemplarg_1 (1);
42 __builtin___memset_chk (p, 0, 2, __builtin_object_size (p, 1)); // { dg-warning "\\\[-Wstringop-overflow=" }
43 return p;
44 }
45
46 struct C { static const int N1 = 1; static const int N2 = 2; };
47
48 void* call_ftemplarg_2 (A<C> *pa)
49 {
50 void *p = pa->ftemplarg_2 (1);
51 __builtin___memset_chk (p, 0, 2, __builtin_object_size (p, 1));
52 return p;
53 }