Commit d9e17d3
authored
[CIR][FlattenCFG] Fix use after free when flattening terminator (#843)
Per the operation walking documentation [1]:
> A callback on a block or operation is allowed to erase that block or
> operation if either:
> * the walk is in post-order, or
> * the walk is in pre-order and the walk is skipped after the erasure.
We were doing neither when erasing terminator operations and replacing
them with a branch, leading to a use after free and ASAN errors. This
fixes the following tests with ASAN:
```
Clang :: CIR/CodeGen/switch-gnurange.cpp
Clang :: CIR/Lowering/atomic-runtime.cpp
Clang :: CIR/Lowering/loop.cir
Clang :: CIR/Lowering/loops-with-break.cir
Clang :: CIR/Lowering/loops-with-continue.cir
Clang :: CIR/Lowering/switch.cir
Clang :: CIR/Transforms/Target/x86_64/x86_64-call-conv-lowering-pass.cpp
Clang :: CIR/Transforms/loop.cir
Clang :: CIR/Transforms/switch.cir
```
These two tests still fail with ASAN after this, which I'm looking into:
```
Clang :: CIR/CodeGen/pointer-arith-ext.c
Clang :: CIR/Transforms/Target/x86_64/x86_64-call-conv-lowering-pass.cpp
```
`CIR/CodeGen/global-new.cpp` is failing even on a non-ASAN Release build
for me on the parent commit, so it's unrelated.
[1]
https://github.com/llvm/llvm-project/blob/0c55ad11ab3857056bb3917fdf087c4aa811b790/mlir/include/mlir/IR/Operation.h#L767-L7701 parent ba8c248 commit d9e17d3
File tree
2 files changed
+21
-13
lines changed- clang
- include/clang/CIR/Interfaces
- lib/CIR/Dialect/Transforms
2 files changed
+21
-13
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
74 | | - | |
| 74 | + | |
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
81 | | - | |
| 80 | + | |
82 | 81 | | |
83 | 82 | | |
84 | 83 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
40 | | - | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
44 | | - | |
45 | | - | |
| 45 | + | |
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| |||
541 | 541 | | |
542 | 542 | | |
543 | 543 | | |
544 | | - | |
545 | | - | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
546 | 549 | | |
547 | 550 | | |
548 | 551 | | |
549 | 552 | | |
550 | 553 | | |
551 | | - | |
552 | | - | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
553 | 559 | | |
554 | 560 | | |
555 | 561 | | |
| |||
705 | 711 | | |
706 | 712 | | |
707 | 713 | | |
708 | | - | |
709 | | - | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
710 | 719 | | |
711 | 720 | | |
712 | 721 | | |
| |||
0 commit comments