Skip to content
Commit 011e4abb authored by Shengchen Kan's avatar Shengchen Kan
Browse files

[X86][MC][bugfix] Report error for mismatched modifier in inline asm and...

[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
parent f35a09da
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment