Commit 3d50a02
authored
[CIR][CIRGen] Fixes function calls with return values and cleanup stage (#1214)
#### The Problem
Let's take a look at the following code:
```
struct A {
~A() {}
};
int foo() { return 42; }
void bar() {
A a;
int b = foo();
}
```
The call to `foo` guarded by the synthetic `tryOp` looks approximately
like the following:
```
cir.try synthetic cleanup {
%2 = cir.call exception @_Z3foov() : () -> !s32i cleanup {
cir.call @_ZN1AD1Ev(%0) : (!cir.ptr<!ty_A>) -> () extra(#fn_attr1) // call to destructor of 'A'
cir.yield
}
cir.yield
} catch [#cir.unwind {
cir.resume
}]
cir.store %2, %1: !s32i, !cir.ptr<!s32i> // CIR verification error
```
The result of the `foo` call is in the `try` region - and is not
accessible from the outside, so the code generation fails with
`operand #0 does not dominate its use` .
#### Solution
So we have several options how to handle this properly.
1. We may intpoduce a new operation here, like `TryCall` but probably
more high level one, e.g. introduce the `InvokeOp`.
2. Also, we may add the result to `TryOp`.
3. The fast fix that is implemented in this PR is a temporary `alloca`
where we store the call result right in the try region. And the result
of the whole `emitCall` is a `load` from the temp `alloca`.
So this PR is both the request for changes and an open discussion as
well - how to handle this properly. So far I choose the third approach.
If it's ok - I will need to create one more PR with a similar fix for
the aggregated results or update this one.1 parent 0b9e8a0 commit 3d50a02
File tree
2 files changed
+54
-0
lines changed- clang
- lib/CIR/CodeGen
- test/CIR/CodeGen
2 files changed
+54
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
552 | 552 | | |
553 | 553 | | |
554 | 554 | | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
555 | 566 | | |
556 | 567 | | |
557 | 568 | | |
| |||
890 | 901 | | |
891 | 902 | | |
892 | 903 | | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
893 | 916 | | |
894 | 917 | | |
895 | 918 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
308 | 308 | | |
309 | 309 | | |
310 | 310 | | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
0 commit comments