[clang] [CIR] Fix use-after-free when emitting ternary with a throw-expression arm (PR #208850)

Akshay K via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 10 15:55:23 PDT 2026


kumarak wrote:

@andykaylor @bcardosolopes @xlauko, it will be great to get your thoughts on the fix. It avoids adding an insert point for the noreturn expression and generates `cir.unreachable`.

This is the generated CIR for the throw I see:
```
int f(bool b, int x) { return b ? x : throw 2; }

...
  }, false {
      %6 = cir.alloc.exception 4 -> !cir.ptr<!s32i> loc(#loc1)
      %7 = cir.const #cir.int<2> : !s32i loc(#loc1)
      cir.store align(16) %7, %6 : !s32i, !cir.ptr<!s32i> loc(#loc11)
      cir.throw %6 : !cir.ptr<!s32i>, @_ZTIi loc(#loc18)
      cir.unreachable loc(#loc18)
    }) : (!cir.bool) -> !s32i loc(#loc17)
...
```



https://github.com/llvm/llvm-project/pull/208850


More information about the cfe-commits mailing list