This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Fix failure to parse parenthesized immediates
ClosedPublic

Authored by lewis-revill on Jan 28 2019, 3:05 AM.

Details

Summary

Since the parser attempts to parse an operand as a register with parentheses before parsing it as an immediate, immediates in parentheses should not be parsed by parseRegister. However in the case where the immediate does not start with an identifier, the LParen is not unlexed and so the RParen causes an unexpected token error.

This patch adds the missing UnLex, and modifies the existing UnLex to not use a buffered token, as it should always be unlexing an LParen.

Diff Detail

Repository
rL LLVM

Event Timeline

lewis-revill created this revision.Jan 28 2019, 3:05 AM
jrtc27 requested changes to this revision.Jan 28 2019, 4:54 AM

You should save the original AsmToken rather than reconstructing it, so as to retain the SMLoc, and Buf no longer needs to be at function scope. Also, I had some more exhaustive tests in mine; I think the important one is addi a1, a0, (1) to ensure that we can parse parenthesised immediate expressions when *not* part of a memory reference.

This revision now requires changes to proceed.Jan 28 2019, 4:54 AM

You should save the original AsmToken rather than reconstructing it, so as to retain the SMLoc, and Buf no longer needs to be at function scope. Also, I had some more exhaustive tests in mine; I think the important one is addi a1, a0, (1) to ensure that we can parse parenthesised immediate expressions when *not* part of a memory reference.

That sounds like a good approach. It really wasn't possible that LParen could ever be in the buffer given the way 'peekTokens' works.

Save the token for the parsed LParen rather than reconstructing one. Add some more tests.

lewis-revill edited the summary of this revision. (Show Details)

Rebased patch after addition of matchRegisterNameHelper

Herald added a project: Restricted Project. · View Herald TranscriptJun 13 2019, 6:44 AM
Herald added subscribers: Jim, benna, psnobl. · View Herald Transcript
asb accepted this revision.Jun 18 2019, 4:03 AM

This looks good to me, thanks!

lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
1002 ↗(On Diff #204521)

This (pre-existing) sentence is garbled and you might want to fix it as part of this patch.

This revision was not accepted when it landed; it landed in state Needs Review.Jun 19 2019, 3:10 AM
This revision was automatically updated to reflect the committed changes.