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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
/* PR middle-end/10138 - warn for uninitialized arrays passed as const arguments
Verify that -Wuninitialized and -Wmaybe-uninitialized trigger (or don't)
when passing uninitialized variables by reference to functions declared
with or without attribute access and with (or without) const qualified
arguments of array, VLA, or pointer types.
{ dg-do compile }
{ dg-options "-O2 -Wall -ftrack-macro-expansion=0" } */
#define NONE /* none */
#define RO(...) __attribute__ ((access (read_only, __VA_ARGS__)))
#define RW(...) __attribute__ ((access (read_write, __VA_ARGS__)))
#define WO(...) __attribute__ ((access (write_only, __VA_ARGS__)))
#define X(...) __attribute__ ((access (none, __VA_ARGS__)))
#define CONCAT(x, y) x ## y
#define CAT(x, y) CONCAT (x, y)
#define UNIQ(pfx) CAT (pfx, __LINE__)
extern void sink (void*);
#define T1(attr, name, type) \
void UNIQ (CAT (test_, name))(void) { \
extern attr void UNIQ (name)(type); \
int x; \
UNIQ (name)(&x); \
sink (&x); \
}
#define T2(attr, name, types) \
void UNIQ (CAT (test_, name))(void) { \
extern attr void UNIQ (name)(types); \
int x; \
UNIQ (name)(1, &x); \
sink (&x); \
}
typedef int IA_[];
typedef const int CIA_[];
T1 (NONE, fia_, IA_);
T1 (NONE, fcia_, CIA_); // { dg-warning "\\\[-Wmaybe-uninitialized" }
T1 (RO (1), froia_, IA_); // { dg-warning "\\\[-Wuninitialized" }
T1 (RW (1), frwia_, IA_); // { dg-warning "\\\[-Wmaybe-uninitialized" }
T1 (WO (1), fwoia_, IA_);
T1 (X (1), fxia_, IA_);
typedef int IA1[1];
typedef const int CIA1[1];
T1 (NONE, fia1, IA1);
T1 (NONE, fcia1, CIA1); // { dg-warning "\\\[-Wmaybe-uninitialized" }
T1 (RO (1), froia1, IA1); // { dg-warning "\\\[-Wuninitialized" }
T1 (RW (1), frwia1, IA1); // { dg-warning "\\\[-Wmaybe-uninitialized" }
T1 (WO (1), fwoia1, IA1);
T1 (X (1), fxia1, IA1);
#define IARS1 int[restrict static 1]
#define CIARS1 const int[restrict static 1]
T1 (NONE, fiars1, IARS1);
T1 (NONE, fciars1, CIARS1);// { dg-warning "\\\[-Wmaybe-uninitialized" }
T1 (RO (1), froiars1, IARS1); // { dg-warning "\\\[-Wuninitialized" }
T1 (RW (1), frwiars1, IARS1); // { dg-warning "\\\[-Wmaybe-uninitialized" }
T1 (WO (1), fwoiars1, IARS1);
T1 (X (1), fxiars1, IARS1);
#define IAS1 int[static 1]
#define CIAS1 const int[static 1]
T1 (NONE, fias1, IAS1);
T1 (NONE, fcias1, CIAS1); // { dg-warning "\\\[-Wmaybe-uninitialized" }
T1 (RO (1), froias1, IAS1); // { dg-warning "\\\[-Wuninitialized" }
T1 (RW (1), frwias1, IAS1); // { dg-warning "\\\[-Wmaybe-uninitialized" }
T1 (WO (1), fwoias1, IAS1);
T1 (X (1), fxias1, IAS1);
#define IAX int[*]
#define CIAX const int[*]
T1 (NONE, fiax, IAX);
T1 (NONE, fciax, CIAX); // { dg-warning "\\\[-Wmaybe-uninitialized" }
T1 (RO (1), froiax, IAX); // { dg-warning "\\\[-Wuninitialized" }
T1 (RW (1), frwiax, IAX); // { dg-warning "\\\[-Wmaybe-uninitialized" }
T1 (WO (1), fwoiax, IAX);
T1 (X (1), fxiax, IAX);
#define IAN int n, int[n]
#define CIAN int n, const int[n]
T2 (NONE, fian, IAN);
T2 (NONE, fcian, CIAN); // { dg-warning "\\\[-Wmaybe-uninitialized" }
T2 (RO (2, 1), froian, IAN); // { dg-warning "\\\[-Wuninitialized" }
T2 (RW (2, 1), frwian, IAN); // { dg-warning "\\\[-Wmaybe-uninitialized" }
T2 (WO (2, 1), fwoian, IAN);
T2 (X (2, 1), fxian, IAN);
typedef int* IP;
typedef const int* CIP;
T1 (NONE, fip, IP);
T1 (NONE, fcip, CIP); // { dg-warning "\\\[-Wmaybe-uninitialized" }
T1 (RO (1), froip, IP); // { dg-warning "\\\[-Wuninitialized" }
T1 (RW (1), frwip, IP); // { dg-warning "\\\[-Wmaybe-uninitialized" }
T1 (WO (1), fwoip, IP);
T1 (X (1), fxip, IP);
/* Verify that the notes printed after the warning mention attribute
access only when the attribute is explicitly used in the declaration
and not otherwise. */
void test_note_cst_restrict (void)
{
extern void
fccar (const char[restrict]); // { dg-message "by argument 1 of type 'const char\\\[restrict]' to 'fccar'" "note" }
char a[1]; // { dg-message "'a' declared here" "note" }
fccar (a); // { dg-warning "'a' may be used uninitialized" }
}
void test_note_vla (int n)
{
extern void
fccvla (const char[n]); // { dg-message "by argument 1 of type 'const char\\\[n]' to 'fccvla'" "note" }
char a[2]; // { dg-message "'a' declared here" "note" }
fccvla (a); // { dg-warning "'a' may be used uninitialized" }
}
void test_note_ro (void)
{
extern RO (1) void
frocar (char[restrict]); // { dg-message "in a call to 'frocar' declared with attribute 'access \\\(read_only, 1\\\)'" "note" }
char a[3]; // { dg-message "'a' declared here" "note" }
frocar (a); // { dg-warning "'a' is used uninitialized" }
}
void test_note_rw (void)
{
extern RW (1) void
frwcar (char[restrict]); // { dg-message "in a call to 'frwcar' declared with attribute 'access \\\(read_write, 1\\\)'" "note" }
char a[4]; // { dg-message "'a' declared here" "note" }
frwcar (a); // { dg-warning "'a' may be used uninitialized" }
}
|