This is an archive of the discontinued LLVM Phabricator instance.

[M68k][AsmParser] Fix invalid register name parsing logics
ClosedPublic

Authored by myhsu on May 2 2021, 3:01 PM.

Details

Summary

Adjust sanity check in register parsing function to allow register name with more than 2 characters (e.g. ccr).

Diff Detail

Event Timeline

myhsu created this revision.May 2 2021, 3:01 PM
myhsu requested review of this revision.May 2 2021, 3:01 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 2 2021, 3:01 PM
ricky26 added inline comments.May 2 2021, 3:12 PM
llvm/lib/Target/M68k/AsmParser/M68kAsmParser.cpp
489

It might be simpler to pull out CCR for now. Otherwise this will cause some invalid register names to be parsed as valid %a0q for example would be parsed as A0 (the third character would be ignored).

A better solution might be to remove this check and in the switch cases check the name length.

I recognise this is due to my error!

myhsu updated this revision to Diff 342285.May 2 2021, 3:12 PM

Removing corresponding legacy test in the test/CodeGen/M68k/Encoding folder

myhsu added inline comments.May 2 2021, 3:21 PM
llvm/lib/Target/M68k/AsmParser/M68kAsmParser.cpp
489

Good point. Will do.
Although when we're going to support register with size suffix (e.g. %a0.l) we still need to handle more general cases (because AsmLexer will lex "a0.l" as a single identifier albeit there is a AsmToken::Dot token) but I think it's trivial to change.

myhsu updated this revision to Diff 342287.May 2 2021, 3:28 PM
myhsu marked an inline comment as done.

Handle CCR register's name as special case

ricky26 accepted this revision.May 2 2021, 4:23 PM

LGTM

llvm/lib/Target/M68k/AsmParser/M68kAsmParser.cpp
489

Agreed. I expected some changes to the register name parsing to be necessary. 😄

This revision is now accepted and ready to land.May 2 2021, 4:23 PM
This revision was landed with ongoing or failed builds.May 5 2021, 5:15 PM
This revision was automatically updated to reflect the committed changes.
jrtc27 added a subscriber: jrtc27.May 5 2021, 5:42 PM
jrtc27 added inline comments.
llvm/test/MC/M68k/Data/Classes/MxMoveCCR.s
1–16

Keep your tests minimal please, no unnecessary crud

myhsu marked an inline comment as done.May 5 2021, 5:51 PM
myhsu added inline comments.
llvm/test/MC/M68k/Data/Classes/MxMoveCCR.s
1–16
llvm/lib/Target/M68k/AsmParser/M68kAsmParser.cpp