Commit 2c972fb
Carolyn Zech
Add support for anonymous nested statics (#3953)
rust-lang/rust#121644 added support for
anonymous nested allocations to statics. This PR adds support for such
statics to Kani.
The idea is to treat an anonymous `GlobalAlloc::Static` the same as we
would treat a `GlobalAlloc::Memory`, since an anonymous static is a
nested memory allocation. To frame this change in terms of the tests:
`pointer_to_const_alloc.rs` contains a test for the
`GlobalAlloc::Memory` case, which we could already handle prior to this
PR. The MIR looks like:
```
alloc3 (size: 4, align: 4) {
2a 00 00 00 │ *...
}
alloc1 (static: FOO, size: 16, align: 8) {
╾─────alloc3<imm>─────╼ 01 00 00 00 00 00 00 00 │ ╾──────╼........
}
```
meaning that `FOO` contains a pointer to the *immutable* allocation
alloc3 (note the `alloc3<imm>`, imm standing for "immutable").
`anon_static.rs` tests the code introduced in this PR. The MIR from
`example_1` looks almost identical:
```
alloc2 (static: FOO::{constant#0}, size: 4, align: 4) {
2a 00 00 00 │ *...
}
alloc1 (static: FOO, size: 16, align: 8) {
╾───────alloc2────────╼ 01 00 00 00 00 00 00 00 │ ╾──────╼........
}
```
Note, however, that `alloc2` is mutable, and is thus an anonymous nested
static rather than a constant allocation.
But we can just call `codegen_const_allocation` anyway, since it ends up
checking if the allocation is indeed constant before declaring the
global variable in the symbol table:
https://github.com/model-checking/kani/blob/319040b8cd2cb72ec0603653fad7a8d934857d57/kani-compiler/src/codegen_cprover_gotoc/codegen/operand.rs#L556
Resolves #3904
By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 and MIT licenses.1 parent 319040b commit 2c972fb
File tree
5 files changed
+153
-23
lines changed- kani-compiler/src
- codegen_cprover_gotoc/codegen
- kani_middle
- tests/kani/Static
5 files changed
+153
-23
lines changedLines changed: 23 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
372 | 373 | | |
373 | 374 | | |
374 | 375 | | |
375 | | - | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
376 | 385 | | |
377 | 386 | | |
378 | 387 | | |
| |||
490 | 499 | | |
491 | 500 | | |
492 | 501 | | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
493 | 515 | | |
494 | 516 | | |
495 | 517 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | 12 | | |
14 | 13 | | |
15 | 14 | | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
149 | 158 | | |
150 | 159 | | |
151 | 160 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
| |||
219 | 220 | | |
220 | 221 | | |
221 | 222 | | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
227 | 231 | | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
236 | 242 | | |
237 | 243 | | |
238 | 244 | | |
| |||
331 | 337 | | |
332 | 338 | | |
333 | 339 | | |
334 | | - | |
| 340 | + | |
335 | 341 | | |
336 | 342 | | |
337 | 343 | | |
| |||
520 | 526 | | |
521 | 527 | | |
522 | 528 | | |
523 | | - | |
| 529 | + | |
524 | 530 | | |
525 | 531 | | |
526 | 532 | | |
527 | 533 | | |
528 | | - | |
529 | | - | |
530 | | - | |
531 | | - | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
532 | 549 | | |
533 | 550 | | |
534 | 551 | | |
535 | 552 | | |
536 | 553 | | |
537 | 554 | | |
538 | | - | |
| 555 | + | |
539 | 556 | | |
540 | 557 | | |
541 | 558 | | |
542 | 559 | | |
543 | | - | |
| 560 | + | |
544 | 561 | | |
545 | 562 | | |
546 | 563 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
0 commit comments