1# RUN: llvm-mc -filetype=obj -triple riscv32 < %s --defsym RV32=1 | llvm-objdump -dr -M no-aliases - | FileCheck %s --check-prefixes=INST,RV32 2# RUN: llvm-mc -filetype=obj -triple riscv64 < %s | llvm-objdump -dr -M no-aliases - | FileCheck %s --check-prefixes=INST,RV64 3 4# RUN: not llvm-mc -triple riscv32 < %s --defsym RV32=1 --defsym ERR=1 2>&1 | FileCheck %s --check-prefixes=ERR 5# RUN: not llvm-mc -triple riscv64 < %s --defsym ERR=1 2>&1 | FileCheck %s --check-prefixes=ERR 6 7start: # @start 8# %bb.0: # %entry 9.Ltlsdesc_hi0: 10 auipc a0, %tlsdesc_hi(a-4) 11 # INST: auipc a0, 0x0 12 # INST-NEXT: R_RISCV_TLSDESC_HI20 a-0x4 13 auipc a0, %tlsdesc_hi(unspecified) 14 # INST-NEXT: auipc a0, 0x0 15 # INST-NEXT: R_RISCV_TLSDESC_HI20 unspecified 16.ifdef RV32 17 lw a1, %tlsdesc_load_lo(.Ltlsdesc_hi0)(a0) 18 # RV32: lw a1, 0x0(a0) 19 # RV32-NEXT: R_RISCV_TLSDESC_LOAD_LO12 .Ltlsdesc_hi0 20.else 21 ld a1, %tlsdesc_load_lo(.Ltlsdesc_hi0)(a0) 22 # RV64: ld a1, 0x0(a0) 23 # RV64-NEXT: R_RISCV_TLSDESC_LOAD_LO12 .Ltlsdesc_hi0 24.endif 25 addi a0, a0, %tlsdesc_add_lo(.Ltlsdesc_hi0) 26 # INST: addi a0, a0, 0x0 27 # INST-NEXT: R_RISCV_TLSDESC_ADD_LO12 .Ltlsdesc_hi0 28 jalr t0, 0(a1), %tlsdesc_call(.Ltlsdesc_hi0) 29 # INST-NEXT: jalr t0, 0x0(a1) 30 # INST-NEXT: R_RISCV_TLSDESC_CALL .Ltlsdesc_hi0 31 add a0, a0, tp 32 # INST-NEXT: add a0, a0, tp 33 ret 34 35## Check invalid usage 36.ifdef ERR 37 auipc x1, %tlsdesc_call(foo) # ERR: :[[#@LINE]]:12: error: operand must be a symbol with a %pcrel_hi/%got_pcrel_hi/%tls_ie_pcrel_hi/%tls_gd_pcrel_hi modifier or an integer in the range 38 auipc x1, %tlsdesc_call(1234) # ERR: :[[#@LINE]]:12: error: operand must be a symbol with a %pcrel_hi/%got_pcrel_hi/%tls_ie_pcrel_hi/%tls_gd_pcrel_hi modifier or an integer in the range 39 auipc a0, %tlsdesc_hi(a+b) # ERR: :[[#@LINE]]:12: error: operand must be a symbol with a %pcrel_hi/%got_pcrel_hi/%tls_ie_pcrel_hi/%tls_gd_pcrel_hi modifier or an integer in the range 40 41 lw a0, t0, %tlsdesc_load_lo(a_symbol) # ERR: :[[#@LINE]]:15: error: invalid operand for instruction 42 lw a0, t0, %tlsdesc_load_lo(a_symbol)(a4) # ERR: :[[#@LINE]]:15: error: invalid operand for instruction 43 44 addi a0, t0, %tlsdesc_add_lo(a_symbol)(a4) # ERR: :[[#@LINE]]:41: error: invalid operand for instruction 45 addi a0, %tlsdesc_add_lo(a_symbol) # ERR: :[[#@LINE]]:11: error: invalid operand for instruction 46 addi x1, %tlsdesc_load_lo(a_symbol)(a0) # ERR: :[[#@LINE]]:11: error: invalid operand for instruction 47 48 jalr x5, 0(a1), %tlsdesc_hi(a_symbol) # ERR: :[[#@LINE]]:18: error: operand must be a symbol with %tlsdesc_call modifier 49 jalr x1, 0(a1), %tlsdesc_call(a_symbol) # ERR: :[[#@LINE]]:13: error: the output operand must be t0/x5 when using %tlsdesc_call modifier 50.endif 51