aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/pointer-counted-by.c
blob: 0f18828ac113dce61de03e80449e738e340ee7b3 (plain)
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/* Testing the correct usage of attribute counted_by for pointer field.
   and also mixed pointer field and FMA field in the same structure.  */
/* { dg-do compile } */
/* { dg-options "-O0" } */

int size;
int *x __attribute__ ((counted_by (size))); /* { dg-error "attribute is not allowed for a non-field declaration" } */

struct pointer_array_0 {
  int count;
  int array __attribute__ ((counted_by (count))); /* { dg-error "attribute is not allowed for a non-array or non-pointer field" } */
  int other;
};

int count;
struct pointer_array_1 {
  int other;
  int *array_1 __attribute__ ((counted_by (count))); /* { dg-error "attribute is not a field declaration in the same structure as" } */
  int array_fam[] __attribute__ ((counted_by (count))); /* { dg-error "attribute is not a field declaration in the same structure as" } */
};

struct pointer_array_2 {
  float count1;
  float count2;
  int *array_2 __attribute__ ((counted_by (count1))); /* { dg-error "attribute is not a field declaration with an integer type" } */
  int array_fam[] __attribute__ ((counted_by (count2))); /* { dg-error "attribute is not a field declaration with an integer type" } */
}; 

struct pointer_array_3 {
  int count;
  int *array_3 __attribute__ ((counted_by (count))) __attribute__ ((counted_by (count)));
}; 

struct pointer_array_4 {
  int count1;
  int count2;
  int *array_4 __attribute__ ((counted_by (count1))) __attribute__ ((counted_by (count2))); /* { dg-error "conflicts with previous declaration" } */
  float array_fam[] __attribute__ ((counted_by (count2))) __attribute__ ((counted_by (count1))); /* { dg-error "conflicts with previous declaration" } */
}; 

struct pointer_array_5 {
  _Bool count;
  int *array_5 __attribute__ ((counted_by (count)));
}; 

enum week {Mon, Tue, Wed};
struct pointer_array_6 {
  enum week days;
  int *array_6 __attribute__ ((counted_by (days)));
}; 

struct pointer_array_7 {
  int count;
  void *array_7 __attribute__ ((counted_by (count))); /* { dg-error "attribute is not allowed for a pointer to void" } */
}; 

struct pointer_array_8 {
  int count;
  int (*fpr)(int,int) __attribute__ ((counted_by (count))); /* { dg-error "attribute is not allowed for a pointer to function" } */
}; 

struct item1 {
  int a;
  float b;
};

union item2 {
  char *a;
  int *b; 
};

typedef struct item3 Item3;
typedef union item4 Item4;

struct item5 {
  int a;
  float b[];
};

/* Incomplete structure and union are allowed.  */
struct pointer_array_9 {
  int count1;
  int count2;
  int count3;
  struct item1 *array_1 __attribute__ ((counted_by (count1)));
  union item2 *array_2 __attribute__ ((counted_by (count2)));
  Item3 *array_3 __attribute__ ((counted_by (count3))); 
  Item4 *array_4 __attribute__ ((counted_by (count4))); 
  int count4;
  int count5;
  /* structure with flexible array member is not allowed.  */
  struct item5 *array_5 __attribute__ ((counted_by (count5))); /* { dg-error "attribute is not allowed for a pointer to structure or union with flexible array member" } */
}; 

struct mixed_array {
  int count1;
  float *array_1 __attribute__ ((counted_by (count1)));
  float *array_2 __attribute__ ((counted_by (count1)));
  int count2;
  long *array_3 __attribute__ ((counted_by (count2)));
  long array_4[] __attribute__ ((counted_by (count2)));
};

struct mixed_array_2 {
  float *array_1 __attribute__ ((counted_by (count1)));
  int count1;
  float *array_2 __attribute__ ((counted_by (count1)));
  long *array_3 __attribute__ ((counted_by (count2)));
  int count2;
  long array_4[] __attribute__ ((counted_by (count2)));
};