Skip to content

Commit c8f25f7

Browse files
committed
[RISCV][NFC] Add Coverage For Symbol Operands
This adds assembly test coverage for the following operand types: - simm12 - uimm20_lui - uimm20_auipc - simm6 - simm6nonzero - simm5 - simm5_plus1 - simm20_li
1 parent 8cf3b98 commit c8f25f7

12 files changed

+193
-6
lines changed

llvm/test/MC/RISCV/rv32c-invalid.s

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ c.addi16sp t0, 16 # CHECK: :[[@LINE]]:13: error: register must be sp (x2)
3535

3636
# Out of range immediates
3737

38+
reldef:
39+
40+
.global undef
41+
3842
## uimmlog2xlennonzero
3943
c.slli t0, 64 # CHECK: :[[@LINE]]:12: error: immediate must be an integer in the range [1, 31]
4044
c.srli a0, 32 # CHECK: :[[@LINE]]:12: error: immediate must be an integer in the range [1, 31]
@@ -53,16 +57,23 @@ c.andi a0, %hi(foo) # CHECK: :[[@LINE]]:12: error: immediate must be an integer
5357
## simm6nonzero
5458
c.addi t0, -33 # CHECK: :[[@LINE]]:12: error: immediate must be non-zero in the range [-32, 31]
5559
c.addi t0, 32 # CHECK: :[[@LINE]]:12: error: immediate must be non-zero in the range [-32, 31]
56-
c.addi t0, foo # CHECK: :[[@LINE]]:12: error: immediate must be non-zero in the range [-32, 31]
5760
c.addi t0, %lo(foo) # CHECK: :[[@LINE]]:12: error: immediate must be non-zero in the range [-32, 31]
5861
c.addi t0, %hi(foo) # CHECK: :[[@LINE]]:12: error: immediate must be non-zero in the range [-32, 31]
62+
c.addi t0, reldef # CHECK: :[[@LINE]]:12: error: immediate must be non-zero in the range [-32, 31]
63+
c.addi t0, reldef-. # CHECK: :[[@LINE]]:12: error: immediate must be non-zero in the range [-32, 31]
64+
c.addi t0, undef # CHECK: :[[@LINE]]:12: error: immediate must be non-zero in the range [-32, 31]
65+
c.addi t0, latedef # CHECK: :[[@LINE]]:12: error: immediate must be non-zero in the range [-32, 31]
66+
5967

6068
## c_lui_imm
6169
c.lui t0, 0 # CHECK: :[[@LINE]]:11: error: immediate must be in [0xfffe0, 0xfffff] or [1, 31]
6270
c.lui t0, 32 # CHECK: :[[@LINE]]:11: error: immediate must be in [0xfffe0, 0xfffff] or [1, 31]
6371
c.lui t0, 0xffffdf # CHECK: :[[@LINE]]:11: error: immediate must be in [0xfffe0, 0xfffff] or [1, 31]
6472
c.lui t0, 0x1000000 # CHECK: :[[@LINE]]:11: error: immediate must be in [0xfffe0, 0xfffff] or [1, 31]
65-
c.lui t0, foo # CHECK: [[@LINE]]:11: error: immediate must be in [0xfffe0, 0xfffff] or [1, 31]
73+
c.lui t0, reldef # CHECK: :[[@LINE]]:11: error: immediate must be in [0xfffe0, 0xfffff] or [1, 31]
74+
c.lui t0, reldef-. # CHECK: :[[@LINE]]:11: error: immediate must be in [0xfffe0, 0xfffff] or [1, 31]
75+
c.lui t0, undef # CHECK: :[[@LINE]]:11: error: immediate must be in [0xfffe0, 0xfffff] or [1, 31]
76+
c.lui t0, latedef # CHECK: :[[@LINE]]:11: error: immediate must be in [0xfffe0, 0xfffff] or [1, 31]
6677

6778
## uimm8_lsb00
6879
c.lwsp ra, 256(sp) # CHECK: :[[@LINE]]:13: error: immediate must be a multiple of 4 bytes in the range [0, 252]
@@ -87,3 +98,5 @@ c.addi4spn a0, sp, 1024 # CHECK: :[[@LINE]]:21: error: immediate must be a mult
8798
c.addi16sp sp, -528 # CHECK: :[[@LINE]]:17: error: immediate must be a multiple of 16 bytes and non-zero in the range [-512, 496]
8899
c.addi16sp sp, 512 # CHECK: :[[@LINE]]:17: error: immediate must be a multiple of 16 bytes and non-zero in the range [-512, 496]
89100
c.addi16sp sp, 0 # CHECK: :[[@LINE]]:17: error: immediate must be a multiple of 16 bytes and non-zero in the range [-512, 496]
101+
102+
.set latedef, 1

llvm/test/MC/RISCV/rv64c-invalid.s

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,32 @@ c.ldsp zero, 4(sp) # CHECK: :[[@LINE]]:9: error: register must be a GPR excludi
1313

1414
# Out of range immediates
1515

16+
reldef:
17+
.global undef
18+
1619
## uimmlog2xlennonzero
1720
c.slli t0, 64 # CHECK: :[[@LINE]]:12: error: immediate must be an integer in the range [1, 63]
1821
c.srli a0, -1 # CHECK: :[[@LINE]]:12: error: immediate must be an integer in the range [1, 63]
1922
c.srai a0, 0 # CHECK: :[[@LINE]]:12: error: immediate must be an integer in the range [1, 63]
23+
c.slli t0, reldef # CHECK: :[[@LINE]]:12: error: immediate must be an integer in the range [1, 63]
24+
c.srli a0, reldef-. # CHECK: :[[@LINE]]:12: error: immediate must be an integer in the range [1, 63]
25+
c.srai a0, undef # CHECK: :[[@LINE]]:12: error: immediate must be an integer in the range [1, 63]
2026

2127
## simm6
2228
c.addiw t0, -33 # CHECK: :[[@LINE]]:13: error: immediate must be an integer in the range [-32, 31]
2329
c.addiw t0, 32 # CHECK: :[[@LINE]]:13: error: immediate must be an integer in the range [-32, 31]
24-
c.addiw t0, foo # CHECK: :[[@LINE]]:13: error: immediate must be an integer in the range [-32, 31]
2530
c.addiw t0, %lo(foo) # CHECK: :[[@LINE]]:13: error: immediate must be an integer in the range [-32, 31]
2631
c.addiw t0, %hi(foo) # CHECK: :[[@LINE]]:13: error: immediate must be an integer in the range [-32, 31]
32+
c.addiw t0, reldef # CHECK: :[[@LINE]]:13: error: immediate must be an integer in the range [-32, 31]
33+
c.addiw t0, reldef-. # CHECK: :[[@LINE]]:13: error: immediate must be an integer in the range [-32, 31]
34+
c.addiw t0, undef # CHECK: :[[@LINE]]:13: error: immediate must be an integer in the range [-32, 31]
35+
c.addiw t0, latedef # CHECK: :[[@LINE]]:13: error: immediate must be an integer in the range [-32, 31]
2736

2837
## uimm9_lsb000
2938
c.ldsp ra, 512(sp) # CHECK: :[[@LINE]]:13: error: immediate must be a multiple of 8 bytes in the range [0, 504]
3039
c.sdsp ra, -8(sp) # CHECK: :[[@LINE]]:13: error: immediate must be a multiple of 8 bytes in the range [0, 504]
3140
## uimm8_lsb000
3241
c.ld s0, -8(sp) # CHECK: :[[@LINE]]:11: error: immediate must be a multiple of 8 bytes in the range [0, 248]
3342
c.sd s0, 256(sp) # CHECK: :[[@LINE]]:11: error: immediate must be a multiple of 8 bytes in the range [0, 248]
43+
44+
.set latedef, 1

llvm/test/MC/RISCV/rv64c-valid.s

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,10 @@ c.srli a3, 63
7272
# CHECK-ASM: encoding: [0x7d,0x96]
7373
# CHECK-NO-EXT: error: instruction requires the following: 'C' (Compressed Instructions) or 'Zca' (part of the C extension, excluding compressed floating point loads/stores){{$}}
7474
c.srai a2, 63
75+
76+
.set absdef, 1
77+
78+
# CHECK-ASM-AND-OBJ: c.addiw a0, 1
79+
# CHECK-ASM: encoding: [0x05,0x25]
80+
# CHECK-NO-EXT: error: instruction requires the following: 'C' (Compressed Instructions) or 'Zca' (part of the C extension, excluding compressed floating point loads/stores){{$}}
81+
c.addiw a0, absdef

llvm/test/MC/RISCV/rvc-invalid.s

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# RUN: not llvm-mc %s -triple=riscv32 2>&1 | FileCheck %s
2+
# RUN: not llvm-mc %s -triple=riscv64 2>&1 | FileCheck %s
3+
4+
reldef:
5+
6+
.global undef
7+
8+
c.addi a0, reldef # CHECK: :[[@LINE]]:12: error: invalid operand for instruction
9+
c.addi a0, reldef-. # CHECK: :[[@LINE]]:12: error: invalid operand for instruction
10+
c.addi a0, undef # CHECK: :[[@LINE]]:12: error: invalid operand for instruction
11+
c.addi a0, latedef # CHECK: :[[@LINE]]:12: error: invalid operand for instruction
12+
13+
c.li a0, reldef # CHECK: :[[@LINE]]:10: error: invalid operand for instruction
14+
c.li a0, reldef-. # CHECK: :[[@LINE]]:10: error: invalid operand for instruction
15+
c.li a0, undef # CHECK: :[[@LINE]]:10: error: invalid operand for instruction
16+
c.li a0, latedef # CHECK: :[[@LINE]]:10: error: invalid operand for instruction
17+
18+
c.andi a0, reldef # CHECK: :[[@LINE]]:12: error: invalid operand for instruction
19+
c.andi a0, reldef-. # CHECK: :[[@LINE]]:12: error: invalid operand for instruction
20+
c.andi a0, undef # CHECK: :[[@LINE]]:12: error: invalid operand for instruction
21+
c.andi a0, latedef # CHECK: :[[@LINE]]:12: error: invalid operand for instruction
22+
23+
.set latedef, 1

llvm/test/MC/RISCV/rvc-valid.s

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,20 @@ c.lui s0, 0xfffff
175175
# CHECK-ASM: encoding: [0x00,0x00]
176176
# CHECK-NO-EXT: error: instruction requires the following: 'C' (Compressed Instructions) or 'Zca' (part of the C extension, excluding compressed floating point loads/stores){{$}}
177177
c.unimp
178+
179+
.set absdef, 1
180+
181+
c.addi a0, absdef
182+
# CHECK-ASM-AND-OBJ: c.addi a0, 1
183+
# CHECK-ASM: encoding: [0x05,0x05]
184+
# CHECK-NO-EXT: error: instruction requires the following: 'C' (Compressed Instructions) or 'Zca' (part of the C extension, excluding compressed floating point loads/stores){{$}}
185+
186+
c.li a0, absdef
187+
# CHECK-ASM-AND-OBJ: c.li a0, 1
188+
# CHECK-ASM: encoding: [0x05,0x45]
189+
# CHECK-NO-EXT: error: instruction requires the following: 'C' (Compressed Instructions) or 'Zca' (part of the C extension, excluding compressed floating point loads/stores){{$}}
190+
191+
c.andi a0, absdef
192+
# CHECK-ASM-AND-OBJ: c.andi a0, 1
193+
# CHECK-ASM: encoding: [0x05,0x89]
194+
# CHECK-NO-EXT: error: instruction requires the following: 'C' (Compressed Instructions) or 'Zca' (part of the C extension, excluding compressed floating point loads/stores){{$}}

llvm/test/MC/RISCV/rvi-invalid.s

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# RUN: not llvm-mc -triple=riscv32 < %s 2>&1 | FileCheck %s
2+
# RUN: not llvm-mc -triple=riscv64 < %s 2>&1 | FileCheck %s
3+
4+
reldef:
5+
6+
.global undef
7+
8+
## simm12
9+
addi a0, a1, reldef # CHECK: :[[@LINE]]:14: error: operand must be a symbol with %lo/%pcrel_lo/%tprel_lo specifier or an integer in the range [-2048, 2047]
10+
addi a0, a1, reldef-. # CHECK: :[[@LINE]]:14: error: operand must be a symbol with %lo/%pcrel_lo/%tprel_lo specifier or an integer in the range [-2048, 2047]
11+
addi a0, a1, undef # CHECK: :[[@LINE]]:14: error: operand must be a symbol with %lo/%pcrel_lo/%tprel_lo specifier or an integer in the range [-2048, 2047]
12+
addi a0, a1, latedef # CHECK: :[[@LINE]]:14: error: operand must be a symbol with %lo/%pcrel_lo/%tprel_lo specifier or an integer in the range [-2048, 2047]
13+
14+
15+
lui a0, reldef # CHECK: :[[@LINE]]:9: error: operand must be a symbol with %hi/%tprel_hi specifier or an integer in the range [0, 1048575]
16+
lui a0, reldef-. # CHECK: :[[@LINE]]:9: error: operand must be a symbol with %hi/%tprel_hi specifier or an integer in the range [0, 1048575]
17+
lui a0, undef # CHECK: :[[@LINE]]:9: error: operand must be a symbol with %hi/%tprel_hi specifier or an integer in the range [0, 1048575]
18+
lui a0, latedef # CHECK: :[[@LINE]]:9: error: operand must be a symbol with %hi/%tprel_hi specifier or an integer in the range [0, 1048575]
19+
20+
auipc a0, reldef # CHECK: :[[@LINE]]:11: error: operand must be a symbol with a %pcrel_hi/%got_pcrel_hi/%tls_ie_pcrel_hi/%tls_gd_pcrel_hi specifier or an integer in the range [0, 1048575]
21+
auipc a0, reldef-. # CHECK: :[[@LINE]]:11: error: operand must be a symbol with a %pcrel_hi/%got_pcrel_hi/%tls_ie_pcrel_hi/%tls_gd_pcrel_hi specifier or an integer in the range [0, 1048575]
22+
auipc a0, undef # CHECK: :[[@LINE]]:11: error: operand must be a symbol with a %pcrel_hi/%got_pcrel_hi/%tls_ie_pcrel_hi/%tls_gd_pcrel_hi specifier or an integer in the range [0, 1048575]
23+
auipc a0, latedef # CHECK: :[[@LINE]]:11: error: operand must be a symbol with a %pcrel_hi/%got_pcrel_hi/%tls_ie_pcrel_hi/%tls_gd_pcrel_hi specifier or an integer in the range [0, 1048575]
24+
25+
.set latedef, 1
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# RUN: not llvm-mc --triple=riscv64 -mattr=+v < %s 2>&1 | FileCheck %s
2+
3+
reldef:
4+
5+
.global undef
6+
7+
## simm5_plus1
8+
vmsgeu.vi v3, v4, reldef, v0.t # CHECK: :[[@LINE]]:19: error: immediate must be in the range [-15, 16]
9+
vmsgeu.vi v3, v4, reldef-., v0.t # CHECK: :[[@LINE]]:19: error: immediate must be in the range [-15, 16]
10+
vmsgeu.vi v3, v4, undef, v0.t # CHECK: :[[@LINE]]:19: error: immediate must be in the range [-15, 16]
11+
vmsgeu.vi v3, v4, latedef, v0.t # CHECK: :[[@LINE]]:19: error: immediate must be in the range [-15, 16]
12+
13+
14+
## simm5
15+
vadd.vi v4, v5, reldef, v0.t # CHECK: :[[@LINE]]:17: error: immediate must be an integer in the range [-16, 15]
16+
vadd.vi v4, v5, reldef-., v0.t # CHECK: :[[@LINE]]:17: error: immediate must be an integer in the range [-16, 15]
17+
vadd.vi v4, v5, undef, v0.t # CHECK: :[[@LINE]]:17: error: immediate must be an integer in the range [-16, 15]
18+
vadd.vi v4, v5, latedef, v0.t # CHECK: :[[@LINE]]:17: error: immediate must be an integer in the range [-16, 15]
19+
20+
.set latedef, 1

llvm/test/MC/RISCV/rvv/symbol-valid.s

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# RUN: llvm-mc --triple=riscv64 -mattr=+v < %s | FileCheck %s --check-prefix=ASM
2+
# RUN: llvm-mc --triple=riscv64 -mattr=+v < %s -filetype=obj -o - \
3+
# RUN: | llvm-objdump -d --mattr=+v - \
4+
# RUN: | FileCheck %s --check-prefix=OBJ
5+
6+
7+
.set absdef, 1
8+
9+
## simm5_plus1
10+
# ASM: vmsgtu.vi v3, v4, 0, v0.t
11+
# OBJ: vmsgtu.vi v3, v4, 0x0, v0.t
12+
vmsgeu.vi v3, v4, absdef, v0.t
13+
14+
## simm5
15+
# ASM: vadd.vi v4, v5, 1, v0.t
16+
# OBJ: vadd.vi v4, v5, 0x1, v0.t
17+
vadd.vi v4, v5, absdef, v0.t
18+

llvm/test/MC/RISCV/xqcibi-relocations.s

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,20 @@ qc.bnei t3, 14, same_section
8484
# OBJ-NEXT: qc.e.bgeui s2, 0x18, 0x28 <same_section>
8585
qc.e.bgeui s2, 24, same_section
8686

87-
.option norelax
87+
## Enable compression/relaxation to check how symbols are handled.
88+
.option noexact
89+
90+
# ASM: qc.bnei t1, 10, undef
91+
# OBJ: qc.beqi t1, 0xa, 0x42 <same_section_extern+0x16>
92+
# OBJ-NEXT: j 0x3e <same_section_extern+0x12>
93+
# OBJ-NEXT: R_RISCV_JAL undef{{$}}
94+
qc.bnei t1, 10, undef
95+
96+
# ASM: qc.e.bgeui s0, 40, undef
97+
# OBJ-NEXT: qc.e.bltui s0, 0x28, 0x4c <same_section_extern+0x20>
98+
# OBJ-NEXT: j 0x48 <same_section_extern+0x1c>
99+
# OBJ-NEXT: R_RISCV_JAL undef{{$}}
100+
qc.e.bgeui s0, 40, undef
88101

89102
.section .text.second, "ax", @progbits
90103

llvm/test/MC/RISCV/xqcilb-relocations.s

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,22 @@ qc.e.j same_section
9292
# OBJ-NEXT: R_RISCV_RELAX
9393
qc.e.jal same_section
9494

95-
.option norelax
95+
## Enable compression/relaxation to check how symbols are handled.
96+
.option noexact
97+
98+
qc.e.j undef
99+
# ASM: j undef
100+
# OBJ: qc.e.j 0x44 <same_section_extern+0x10>
101+
# OBJ-NEXT: R_RISCV_VENDOR QUALCOMM{{$}}
102+
# OBJ-NEXT: R_RISCV_CUSTOM195 undef{{$}}
103+
# OBJ-NEXT: R_RISCV_RELAX
104+
105+
qc.e.jal undef
106+
# ASM: jal undef
107+
# OBJ: qc.e.jal 0x4a <same_section_extern+0x16>
108+
# OBJ-NEXT: R_RISCV_VENDOR QUALCOMM{{$}}
109+
# OBJ-NEXT: R_RISCV_CUSTOM195 undef{{$}}
110+
# OBJ-NEXT: R_RISCV_RELAX
96111

97112
.section .text.other, "ax", @progbits
98113

0 commit comments

Comments
 (0)