[all-commits] [llvm/llvm-project] 011e4a: [X86][MC][bugfix] Report error for mismatched modi...

KanRobert via All-commits all-commits at lists.llvm.org
Wed Feb 1 18:09:10 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 011e4abb498098aed2f8447dd4117d5c4e09c0f0
      https://github.com/llvm/llvm-project/commit/011e4abb498098aed2f8447dd4117d5c4e09c0f0
  Author: Shengchen Kan <shengchen.kan at intel.com>
  Date:   2023-02-02 (Thu, 02 Feb 2023)

  Changed paths:
    M llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
    M llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp
    M llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.h
    M llvm/lib/Target/X86/X86AsmPrinter.cpp
    M llvm/lib/Target/X86/X86FixupBWInsts.cpp
    M llvm/lib/Target/X86/X86FrameLowering.cpp
    M llvm/lib/Target/X86/X86ISelLowering.cpp
    M llvm/lib/Target/X86/X86InstrInfo.cpp
    M llvm/lib/Target/X86/X86MCInstLower.cpp
    A llvm/test/CodeGen/X86/asm-modifier-error.ll

  Log Message:
  -----------
  [X86][MC][bugfix] Report error for mismatched modifier in inline asm and remove function getX86SubSuperRegisterOrZero

```
MCRegister getX86SubSuperRegister*(MCRegister Reg, unsigned Size,
                                  bool High = false);
```
A strange behavior of the functions `getX86SubSuperRegister*` was
introduced by llvm-svn:145579: The returned register may not
match the parameters when a 8-bit high register is required.

And llvm-svn: 175762 refined the code and dropped the comments, then we
knew nothing happened there from the code :-(

These two functions are only called with `Size=8` and `High=true` in two places.
One is in `X86FixupBWInsts.cpp` for liveness of registers and the other is in
`X86AsmPrinter.cpp` for inline asm.

For the first one, we provide an alternative in this patch.
For the second one, the strange behaviour caused a bug that an erorr was not reported for mismatched modifier.

```
void f() {
  char x;
  asm volatile ("mov %%ah, %h0" :"=r"(x)::"%eax", "%ebx", "%ecx", "%edx", "edi", "esi");
}
```

```
$ gcc -S test.c

error: extended registers have no high halves
```

```
$ clang -S test.c

no error
```

so we fix the bug in this patch.

`getX86SubSuperRegister` is just a wrapper of `getX86SubSuperRegisterOrZero` with a `assert`.
I belive we should remove the latter.

Reviewed By: pengfei

Differential Revision: https://reviews.llvm.org/D142834




More information about the All-commits mailing list