This is an archive of the discontinued LLVM Phabricator instance.

[ARM, Asm] Harden GNU LDRD/STRD aliases against invalid inputs
ClosedPublic

Authored by olista01 on Aug 15 2017, 4:01 AM.

Details

Summary

Previously, the code that implemented the GNU assembler aliases for the
LDRD and STRD instructions (where the second register is omitted)
assumed that the input was a valid instruction. This caused assertion
failures for every example in ldrd-strd-gnu-bad-inst.s.

This improves this code so that it bails out if the instruction is not
in the expected format, the check bails out, and the asm parser is run
on the unmodified instruction.

It also relaxes the alias on thumb targets, so that unaligned pairs of
registers can be used. The restriction that Rt must be even-numbered
only applies to the ARM versions of these instructions.

Diff Detail

Repository
rL LLVM

Event Timeline

olista01 created this revision.Aug 15 2017, 4:01 AM
rengolin added inline comments.Aug 15 2017, 4:21 AM
lib/Target/ARM/AsmParser/ARMAsmParser.cpp
5791

These were asserts, now they're returns... I wonder if that's going to allow some weird cases. The assembler is not straight forward enough to not have weird matches going through behind our backs, and a future commit can mix this one up.

test/MC/ARM/ldrd-strd-gnu-sp.s
11

No note that this is valid in v8?

test/MC/ARM/ldrd-strd-gnu-thumb-bad-regs.s
5

hum, I was expecting something a bit more explanatory here...

olista01 added inline comments.Aug 15 2017, 4:58 AM
lib/Target/ARM/AsmParser/ARMAsmParser.cpp
5791

The idea is that, if the instruction doesn't match what we expect, we just don't change it, and let the asm parser report whatever error it would for the instruction as written.

test/MC/ARM/ldrd-strd-gnu-sp.s
11

Since the instruction doesn't get transformed by fixupGNULDRDAlias, it has a missing operand compared to what the table-generated matcher expects, which isn't something we have a diagnostic for.

We could report a diagnostic from fixupGNULDRDAlias, but that would add a lot of complexity, because we'd want to report at least 2 notes: "requires V8", and "Rt must be in [r0,r11]". I'm not sure how commonly these aliases are used (I'm not sure why you'd want an instruction to implicitly read/write another register you didn't mention), so I didn't think that would be worth it.

What I would like to add (I've not tried this yet though) is different diagnostics for "unknown mnemonic" and "known mnemonic with invalid operands", which would at least give us something here.

test/MC/ARM/ldrd-strd-gnu-thumb-bad-regs.s
5

Same as above.

rengolin accepted this revision.Aug 15 2017, 5:04 AM

Ok, LGTM. Thanks!

lib/Target/ARM/AsmParser/ARMAsmParser.cpp
5791

Right, makes sense.

test/MC/ARM/ldrd-strd-gnu-sp.s
11

Right, I agree the mnemonic messages are a better way out of this mess.

This revision is now accepted and ready to land.Aug 15 2017, 5:04 AM
This revision was automatically updated to reflect the committed changes.