Currently the assembler will happily assemble, e.g. ldr r0, [s0, #12] and similar.
This patch add checks that only general-purpose registers are used in address operands, shifted registers, and shift amounts.
The check are done in the various AsmOperandClass predicates, which seems simple and as the right place to do it, but
the error messages aren't that good as in the alternative patch here: https://reviews.llvm.org/D39909
Details
Diff Detail
Event Timeline
Having said that, I still tried this approach to a few asm operand classes and the results look promising.
Anyway, I suggest separating the correctness check for general-purpose registers from a set of follow-up of patches, which
just improve the error message "invalid operand for instruction".
It looks like there are a lot of inaccuracies here still with regards to accepting r13/sp and r15/pc. Rejecting non-GPRs is obviously an improvement, but I don't think we should be adding diagnostics which give wrong information to the user.
Maybe the best course of action here would be to commit just the part restricting registers to GPR now, leaving the diagnostics as "invalid operand". We can then fix the operand classes precisely a few at a time, adding predicate functions and diagnostics that match.
lib/Target/ARM/ARMInstrInfo.td | ||
---|---|---|
608 ↗ | (On Diff #123317) | I've been trying to standardise the grammar of these messages on "operand must be a <type> ..." rather than "<type> operand must be ...", see D36689. |
609 ↗ | (On Diff #123317) | Neither register can be r15, at least for ADD on v7A and v8A. |
939 ↗ | (On Diff #123317) | The index register can't be r15 (at least for ARM LDR on v7A). |
lib/Target/ARM/AsmParser/ARMAsmParser.cpp | ||
1157 | There is no code here checking for anything more specific than GPR (other than the TBB/TBH operands), but there are lots of instructions that cannot use sp or pc. |
lib/Target/ARM/ARMInstrInfo.td | ||
---|---|---|
608 ↗ | (On Diff #123317) | The reason for this phrasing is that it makes the diagnostic more clear, for example, when assembling add r3, r0, s1, lsl r6 the error message is like addr.s:17:17: note: shifted register operand must use two registers in the range [r0, r15] add r3, r0, s1, lsl r6 ^ with the caret pointing to the shift amount, whereas it's the s1 register that needs to be fixed. |
lib/Target/ARM/AsmParser/ARMAsmParser.cpp | ||
1157 | Right. So, I have to draw the line somewhere and currently it's at not allowing non-GPRs in address and shifted register operands, and updating the diagnostics to match the code (in that sense, I probably shouldn't have made the changes for TBB/TBH). Perhaps we would like to reject syntaxes, which generate an encoding with unpredictable behavior, or perhaps it's not worth the trouble. To me it seems like a subject for further discussion and a follow-up patch(es). |
I think this change goes against the recent trend of printing multiple diagnostics, instead of a huge dump that will certainly be inaccurate at least some times.
I agree with @olista01 that terse messages are better than wrong messages. If there is inaccuracies, let's fix them, but this patch is way beyond that.
This patch doesn't have full context (git diff -U999999), please use that in future as it makes reviewing easier.
test/MC/ARM/arm-reg-addr-errors.s | ||
---|---|---|
2 | The previous version of this patch also tested Thumb, and FP/SIMD loads and stores. The code change looks like it should still affect those (except for the diagnostic strings), so could those tests also be kept? |
The preceding version contained more tests as they were covering each affected AsmOperandClass. Without the error messages, the tests just cover the changed functions, i.e. adding a test for vld4.32 {d0[], d1[], d2[], d3[]}, [s7:64]
won't test more than the already tested isMem().
I'll re-upload the diff with more context.
Just as an FYI, Phab won't send an email to let folks know about this unless you actually write something in the comment box.
When marking patches as approved, try to always write "LGTM" or something in the message.
chandlerc, thanks. I got all the emails, and was well aware about the status of the review at all time, just wasn't sure what is the proper way to proceed when having conflicting reviews.
There is no code here checking for anything more specific than GPR (other than the TBB/TBH operands), but there are lots of instructions that cannot use sp or pc.