<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/55141>55141</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            longjmp intrinsic silently dropped on AArch64 compilations
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          ayazhafiz
      </td>
    </tr>
</table>

<pre>
    I have the following IR:

```llvm
target triple = "aarch64-darwin-macos"

@l_sjlj_buffer = global [40 x i8] zeroinitializer

; Function Attrs: nobuiltin nounwind
define void @l_panic(i8* nonnull %0, i32 %1) local_unnamed_addr {
entry:
  store i8* %0, i8** bitcast (i8* getelementptr inbounds ([40 x i8], [40 x i8]* @l_sjlj_buffer, i32 0, i64 24) to i8**), align 8
  call void @llvm.eh.sjlj.longjmp(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @l_sjlj_buffer, i32 0, i32 0))
  unreachable
}

; Function Attrs: noreturn nounwind
declare void @llvm.eh.sjlj.longjmp(i8*)
```

For which d42f222f9d6f01afe99d0d597c98b36eb205c5ec generates the following code (via llc, without error):

```s
        .section        __TEXT,__text,regular,pure_instructions
        .globl  _l_panic                        ; -- Begin function l_panic
        .p2align        2
_l_panic:                               ; @l_panic
        .cfi_startproc
; %bb.0:                                ; %entry
Lloh0:
        adrp    x8, _l_sjlj_buffer@PAGE
Lloh1:
        add     x8, x8, _l_sjlj_buffer@PAGEOFF
Lloh2:
        str     x0, [x8, #24]
        .loh AdrpAddStr Lloh0, Lloh1, Lloh2
        .cfi_endproc
                                        ; -- End function
        .globl  _l_sjlj_buffer                  ; @l_sjlj_buffer
.zerofill __DATA,__common,_l_sjlj_buffer,40,4
.subsections_via_symbols
```

Note that there is no branch after the store under `Lloh2`. I ran `llc -debug` on this code, which indicates that the AArch64 backend does not expand the `longjmp` intrinsic and instead the instruction is dropped in LegalizeDAG:

```
Type-legalized selection DAG: %bb.0 'l_panic:entry'
SelectionDAG has 9 nodes:
  t0: ch = EntryToken
      t2: i64,ch = CopyFromReg t0, Register:i64 %0
      t7: i64 = add nuw GlobalAddress:i64<[40 x i8]* @l_sjlj_buffer> 0, Constant:i64<24>
    t10: ch = store<(store (s64) into `i8** bitcast (i8* getelementptr inbounds ([40 x i8], [40 x i8]* @l_sjlj_buffer, i32 0, i64 24) to i8**)`)> t0, t2, t7, undef:i64
  t11: ch = EH_SJLJ_LONGJMP t10, GlobalAddress:i64<[40 x i8]* @l_sjlj_buffer> 0



Legalizing: t11: ch = EH_SJLJ_LONGJMP t10, GlobalAddress:i64<[40 x i8]* @l_sjlj_buffer> 0
Trying to expand node
Successfully expanded node
 ... replacing: t11: ch = EH_SJLJ_LONGJMP t10, GlobalAddress:i64<[40 x i8]* @l_sjlj_buffer> 0
     with:      t10: ch = store<(store (s64) into `i8** bitcast (i8* getelementptr inbounds ([40 x i8], [40 x i8]* @l_sjlj_buffer, i32 0, i64 24) to i8**)`)> t0, t2, t7, undef:i64
```

If the AArch64 backend does not support the intrinsic, can a failure be issued rather than dropping the instruction? Of note, `opt --verify` did not issue a warning here, and I see elsewhere that `clang` issues a failure if `__builtin_longjmp` is used in C code targeting AArch64.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzlV01v2zgQ_TX2hbAgU_KHDj44cZxNkW2LNofeBEqkLGZpUSCpJO6v3xlStuVskxZYoFhgDcOmJM7jcGbePKrQ_LC6IzV7EsTVglRaKf0smx25-zJK1qN4M4qPv_M4fJV62odbjpmdcMQZ2SpBRsmGjChlzJT1PJ1wZgBosmeltnD7AiqNVW4f1WNedFUljDfdKV0wRUazqzQmL0QuR7MN-S6Mlo10kikJ4wuQ5Ipsu6Z0Ujdk7Zyx4DBpdNFJ5WQDo64BB3iYzUUlG0GetOTEL9-yRpYjuoR1KJo1TadgdTqLR_SayITieDqiGVG6ZCrvmobtBc8Z5-Dv4irAis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