1*78e87970SHeejin Ahn; RUN: llc < %s -verify-machineinstrs | FileCheck %s
2*78e87970SHeejin Ahn
3*78e87970SHeejin Ahn; Wasm does not currently support function addresses with offsets, so we
4*78e87970SHeejin Ahn; shouldn't try to create a folded SDNode like (function + offset). This is a
5*78e87970SHeejin Ahn; regression test for the folding bug and this should not crash in MCInstLower.
6*78e87970SHeejin Ahn
7*78e87970SHeejin Ahntarget triple = "wasm32-unknown-unknown"
8*78e87970SHeejin Ahn
9*78e87970SHeejin Ahn; 'hidden' here should be present to reproduce the bug
10*78e87970SHeejin Ahndeclare hidden void @ham(i8*)
11*78e87970SHeejin Ahn
12*78e87970SHeejin Ahndefine void @bar(i8* %ptr) {
13*78e87970SHeejin Ahnbb1:
14*78e87970SHeejin Ahn  br i1 undef, label %bb3, label %bb2
15*78e87970SHeejin Ahn
16*78e87970SHeejin Ahnbb2:
17*78e87970SHeejin Ahn  ; While lowering this switch, isel creates (@ham + 1) expression as a course
18*78e87970SHeejin Ahn  ; of range optimization for switch, and tries to fold the expression, but
19*78e87970SHeejin Ahn  ; wasm does not support with function addresses with offsets. This folding
20*78e87970SHeejin Ahn  ; should be disabled.
21*78e87970SHeejin Ahn  ; CHECK:      i32.const  ham
22*78e87970SHeejin Ahn  ; CHECK-NEXT: i32.const  1
23*78e87970SHeejin Ahn  ; CHECK-NEXT: i32.add
24*78e87970SHeejin Ahn  switch i32 ptrtoint (void (i8*)* @ham to i32), label %bb4 [
25*78e87970SHeejin Ahn    i32 -1, label %bb3
26*78e87970SHeejin Ahn    i32 0, label %bb3
27*78e87970SHeejin Ahn  ]
28*78e87970SHeejin Ahn
29*78e87970SHeejin Ahnbb3:
30*78e87970SHeejin Ahn  unreachable
31*78e87970SHeejin Ahn
32*78e87970SHeejin Ahnbb4:
33*78e87970SHeejin Ahn  %tmp = load i8, i8* %ptr
34*78e87970SHeejin Ahn  unreachable
35*78e87970SHeejin Ahn}
36