This is an archive of the discontinued LLVM Phabricator instance.

[X86] Ignore "short" even harder in Intel ASM.
ClosedPublic

Authored by dlj on May 15 2019, 9:09 PM.

Details

Summary

[X86] Ignore "short" even harder in Intel syntax ASM.

In Intel syntax, it's not uncommon to see a "short" modifier on Jcc conditional
jumps, which indicates the offset should be a "short jump" (8-bit immediate
offset from EIP, -128 to +127). This patch expands to all recognized Jcc
condition codes, and removes the inline restriction.

Clang already ignores "jmp short" in inline assembly. However, only "jmp" and a
couple of Jcc are actually checked, and only inline (i.e., not when using the
integrated assembler for asm sources). A quick search through asm-containing
libraries at hand shows a pretty broad range of Jcc conditions spelled with
"short."

Somewhat relatedly, this patch also renames the existing "ConditionCode"
variable to "ConditionPred"(icate), which better matches the verbiage in Intel
documentation. This should help avoid confusion between these two different
kinds of values, both of which are parsed from mnemonics.

GAS ignores the "short" modifier, and instead uses an encoding based on the
given immediate. MS inline seems to do the same, and I suspect MASM does, too.
NASM will yield an error if presented with an out-of-range immediate value.

Example of GCC 9.1 and MSVC v19.20, "jmp short" with offsets that do and do not
fit within 8 bits: https://gcc.godbolt.org/z/aFZmjY

Diff Detail

Repository
rL LLVM

Event Timeline

dlj created this revision.May 15 2019, 9:09 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 15 2019, 9:09 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
echristo accepted this revision.May 16 2019, 4:03 PM

Be nice to split the predicate change from the short change. No need to re-review though, they're both fine.

This revision is now accepted and ready to land.May 16 2019, 4:03 PM
This revision was automatically updated to reflect the committed changes.