| Issue |
185343
|
| Summary |
In x86 assembly, references to `p` constraint probably should allow `a` modifiers
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
lhmouse
|
When using the `p` (pointer) constraint in inline assembly, GCC requires that references in the assembly template string have `a` modifiers like `%a0`, which makes sense, because the constraint is a pointer rather than a reference, and has to be dereferenced. Clang doesn't require `a` in this case; but on the contrary, Clang effects an error if it's specified.
This has become a maintenance burden since GCC and Clang reject each other's code.
For example:
```c
// gcc -O2 -Wall -Wextra -masm=intel
typedef __UINT32_TYPE__ uint32_t;
typedef __UINT64_TYPE__ uint64_t;
uint32_t
my_TlsGetValue(uint32_t index)
{
uint32_t value;
__asm__ ("gs mov %0, %a1"
: "=r"(value)
: "p"(0x1480 + index * 8)
: "memory");
return value;
}
```
This is accepted by GCC but rejected be clang (https://gcc.godbolt.org/z/dr9a8qTar):
```
<source>:10:14: error: invalid operand in inline asm: 'gs mov $0, ${1:a}'
__asm__ ("gs mov %0, %a1"
^
```
If we use `%1` without `a`, then this code is rejected by GCC instead (https://gcc.godbolt.org/z/sn9zo1vs7):
```
<source>: In function 'my_TlsGetValue':
<source>:10:5: error: invalid 'asm': invalid _expression_ as operand
10 | __asm__ ("gs mov %0, %1"
| ^~~~~~~
```
---
Suggestion: Clang may allow and ignore `a` for `p` constraints so it's compatible with both old and new code.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs