The assembler currently does not check the branch target for CBZ/CBNZ
instructions, which only permit branching forwards with a positive offset. This
adds validation for the branch target to ensure negative PC-relative offsets are
not encoded into the instruction, whether specified as a literal or as an
assembler symbol.
Details
- Reviewers
rengolin t.p.northover olista01 - Commits
- rG15ed7ec5aab8: [Thumb] Validate branch target for CBZ/CBNZ instructions.
rGa305a435a656: [Thumb] Validate branch target for CBZ/CBNZ instructions.
rL278788: [Thumb] Validate branch target for CBZ/CBNZ instructions.
rL278659: [Thumb] Validate branch target for CBZ/CBNZ instructions.
Diff Detail
Event Timeline
lib/Target/ARM/AsmParser/ARMAsmParser.cpp | ||
---|---|---|
6689 | These instructions accept a 6-bit immediate (shifted by one bit), not 5-bit. This should allow all even numbers in the range 0 to 126 (inclusive at both ends). | |
lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp | ||
582 | We should also be checking that the low bit is clear (and see my comment above about the immediate being 6 bits). | |
test/MC/ARM/thumb-diagnostics.s | ||
241 | It would be better to test as close to the bounds as possible, and add some tests for valid immediates close to the boundary. I think these should cover it: |
Why don't you use isUnsignedOffset, which would also check the upper limit and alignment?