Skip to content

Commit cd301a3

Browse files
committed
[AArch64][MC] Improve isSImm Diagnostic Fidelity
With the change in #126653, it became clear that there was an implicit coercion from DiagnosticPredicate bool in `isSimm`, which is then undone in the TableGen'd code that uses the predicate, converting from a bool back to a DiagnosticPredicate. This roundtrip conversion loses information - if `isSImmScaled` returns `DiagnosticPredicate::NoMatch` then it is converted to `DiagnosticPredicate::NearMatch`, which both will cause an error, but have different behaviour for which diagnostic is used. This change removes the boolean conversions and directly returns the DiagnosticPredicate. This causes some changes to error messages, most of which are that when a register provided but a specific immediate was expected, now the error is "invalid operand for instruction" and not an indication that the immediate was out of range. The only change not like this is to LDR (Register), which seems to just choose a different immediate-related diagnostic when a 64-bit register is used - which was equally inaccurate as the previous error. This is because there are many other places in the parser that do not (yet?) use DiagnosticPredicate, in this case the issue seems to be `isUImm12Offset`, which still returns a `bool`.
1 parent 4b3c644 commit cd301a3

File tree

9 files changed

+11
-11
lines changed

9 files changed

+11
-11
lines changed

llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -814,8 +814,8 @@ class AArch64Operand : public MCParsedAsmOperand {
814814
return (Val >= 0 && Val < 64);
815815
}
816816

817-
template <int Width> bool isSImm() const {
818-
return bool(isSImmScaled<Width, 1>());
817+
template <int Width> DiagnosticPredicate isSImm() const {
818+
return isSImmScaled<Width, 1>();
819819
}
820820

821821
template <int Bits, int Scale> DiagnosticPredicate isSImmScaled() const {

llvm/test/MC/AArch64/SME/addspl-diagnostics.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ addspl x19, x14, #32
88

99
// addspl requires an immediate, not a register.
1010
addspl x19, x14, x15
11-
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: index must be an integer in range [-32, 31].
11+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid operand for instruction
1212
// CHECK-NEXT: addspl x19, x14, x15
1313
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:

llvm/test/MC/AArch64/SME/addsvl-diagnostics.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ addsvl x3, x5, #32
88

99
// addsvl requires an immediate, not a register.
1010
addsvl x3, x5, x6
11-
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: index must be an integer in range [-32, 31].
11+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid operand for instruction
1212
// CHECK-NEXT: addsvl x3, x5, x6
1313
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:

llvm/test/MC/AArch64/SME/rdsvl-diagnostics.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ rdsvl x9, #32
88

99
// rdsvl requires an immediate, not a register.
1010
rdsvl x9, x10
11-
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: index must be an integer in range [-32, 31].
11+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid operand for instruction
1212
// CHECK-NEXT: rdsvl x9, x10
1313
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:

llvm/test/MC/AArch64/SVE/addpl-diagnostics.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ addpl x19, x14, #32
88

99
// addpl requires an immediate, not a register.
1010
addpl x19, x14, x15
11-
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: index must be an integer in range [-32, 31].
11+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid operand for instruction
1212
// CHECK-NEXT: addpl x19, x14, x15
1313
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:

llvm/test/MC/AArch64/SVE/addvl-diagnostics.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ addvl x3, x5, #32
88

99
// addvl requires an immediate, not a register.
1010
addvl x3, x5, x6
11-
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: index must be an integer in range [-32, 31].
11+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid operand for instruction
1212
// CHECK-NEXT: addvl x3, x5, x6
1313
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:

llvm/test/MC/AArch64/SVE/index-diagnostics.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ index z17.d, x9, #16
4848
// Invalid register
4949

5050
index z17.s, x9, w7
51-
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: index must be an integer in range [-16, 15].
51+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid operand for instruction
5252
// CHECK-NEXT: index z17.s, x9, w7
5353
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
5454

5555
index z17.d, w9, w7
56-
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: index must be an integer in range [-16, 15].
56+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid operand for instruction
5757
// CHECK-NEXT: index z17.d, w9, w7
5858
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
5959

llvm/test/MC/AArch64/SVE/rdvl-diagnostics.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ rdvl x9, #32
88

99
// rdvl requires an immediate, not a register.
1010
rdvl x9, x10
11-
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: index must be an integer in range [-32, 31].
11+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid operand for instruction
1212
// CHECK-NEXT: rdvl x9, x10
1313
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:

llvm/test/MC/AArch64/arm64-diags.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ ldr q1, [x3, w3, sxtw #1]
121121
; CHECK-ERRORS: error: expected 'uxtw' or 'sxtw' with optional shift of #0 or #3
122122
; CHECK-ERRORS: str d1, [x3, w3, sxtx #3]
123123
; CHECK-ERRORS: ^
124-
; CHECK-ERRORS: error: index must be an integer in range [-256, 255].
124+
; CHECK-ERRORS: error: index must be a multiple of 4 in range [0, 16380].
125125
; CHECK-ERRORS: ldr s1, [x3, d3, sxtx #2]
126126
; CHECK-ERRORS: ^
127127

0 commit comments

Comments
 (0)