Commit 8679f34
committed
internal: init: add escape hatch for referencing initialized fields
The initializer macro emits mutable references for already initialized
fields, which allows modifying or accessing them later in code blocks or
when initializing other fields. This behavior results in compiler errors
when combining with packed structs, since those do not permit creating
references to misaligned fields. For example:
TODO
This was requested by Janne Grunau [1] and will most certainly be used
by the kernel when we eventually end up with trying to initialize packed
structs.
Thus add an initializer attribute `#[disable_initialized_field_access]`
that does what the name suggests: do not generate references to already
initialized fields.
There is space for future work: add yet another attribute which can be
applied on fields of initializers that ask for said field to be made
accessible. We can add that when the need arises.
Wanted-by: Janne Grunau <j@jannau.net>
Link: https://lore.kernel.org/all/20251206170214.GE1097212@robin.jannau.net [1]
Signed-off-by: Benno Lossin <lossin@kernel.org>1 parent c0a57ec commit 8679f34
1 file changed
Lines changed: 52 additions & 23 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| 61 | + | |
61 | 62 | | |
62 | 63 | | |
63 | 64 | | |
| |||
80 | 81 | | |
81 | 82 | | |
82 | 83 | | |
83 | | - | |
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
| |||
142 | 142 | | |
143 | 143 | | |
144 | 144 | | |
145 | | - | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
146 | 154 | | |
147 | 155 | | |
148 | 156 | | |
| |||
225 | 233 | | |
226 | 234 | | |
227 | 235 | | |
| 236 | + | |
228 | 237 | | |
229 | 238 | | |
230 | 239 | | |
| |||
255 | 264 | | |
256 | 265 | | |
257 | 266 | | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
258 | 274 | | |
259 | 275 | | |
260 | 276 | | |
261 | 277 | | |
262 | 278 | | |
263 | 279 | | |
264 | 280 | | |
265 | | - | |
266 | | - | |
267 | | - | |
| 281 | + | |
268 | 282 | | |
269 | 283 | | |
270 | 284 | | |
271 | 285 | | |
272 | 286 | | |
273 | | - | |
| 287 | + | |
274 | 288 | | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
| 289 | + | |
| 290 | + | |
279 | 291 | | |
280 | 292 | | |
281 | 293 | | |
282 | 294 | | |
283 | 295 | | |
284 | 296 | | |
285 | | - | |
286 | | - | |
287 | | - | |
288 | | - | |
289 | | - | |
290 | | - | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
291 | 303 | | |
292 | | - | |
293 | | - | |
294 | | - | |
295 | | - | |
| 304 | + | |
| 305 | + | |
296 | 306 | | |
297 | 307 | | |
298 | 308 | | |
| |||
301 | 311 | | |
302 | 312 | | |
303 | 313 | | |
304 | | - | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
305 | 323 | | |
306 | | - | |
307 | 324 | | |
308 | | - | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
309 | 333 | | |
| 334 | + | |
310 | 335 | | |
311 | 336 | | |
312 | 337 | | |
| |||
436 | 461 | | |
437 | 462 | | |
438 | 463 | | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
439 | 468 | | |
440 | 469 | | |
441 | 470 | | |
| |||
0 commit comments