GCC and existing codebases allow the use of integral values to be used
with this constraint. A recent change D133914 in this area started causing asserts.
Removing the assert is enough as the rest of the code works fine.
rdar://109675485
Differential D155023
Don't assert on a non-pointer value being used for a "p" inline asm constraint. aemerson on Jul 11 2023, 3:38 PM. Authored by
Details GCC and existing codebases allow the use of integral values to be used rdar://109675485
Diff Detail
Event TimelineComment Actions Do you have a C code? I want to see its original constraint. I'm not sure the problem is in IR's constraint or the FE that chooses p as constraint. From LangRef , p is described as An address operand. I would incline to a restricted and precise semantic for constraints in IR. Otherwise, we may face more backend crash. Comment Actions As I mentioned there is *already* code out in the wild that are relying on this to work. GCC also accepts this code, and so IMO it is the defacto semantics of this feature. In this case the IR semantics are wrong. As it currently stands clang with asserts will crash on code that it previously compiled cleanly. Comment Actions The be clear, the original c constraint was also p just like in the IR. I just used the output of -emit-llvm to write an IR test. Comment Actions It doesn't matter if it's invalid, the compiler shouldn't assert
Comment Actions My concern is removing assert don't solve the real problem. I think there are two problems here:
Comment Actions Sorry the inline assembly in the test isn't actually valid for ud1l, here's an example showing 'p' being used with an integer literal: https://godbolt.org/z/sPqqj5q8M void *test() { void *ret; asm ("movq %1, %0" : "=r" (ret) : "p" (256)); return ret; } You'll find that gcc happily accepts this. For non-standardized features like this, the semantics are defined by what the implementations *do*. If GCC has always rejected this as an error, I'm happy to do the same. But GCC doesn't, so we should match them instead of breaking existing users' code (that includes throwing an error in Sema). Now if you are convinced that this deletion of the assert is incorrect, then we can discuss a better fix. The other option is that we entirely back out the original change D133914 that introduced this regression. Comment Actions That isn't convincing much since GCC doesn't document the p constraint somewhere. https://gcc.gnu.org/onlinedocs/gcc-8.2.0/gcc/Machine-Constraints.html
The story started from D122220 rather than D133914. If there is a clear declaration for p constraint, I'd suggest to improve D133914, e.g., changing it to i for immediate value. Comment Actions https://gcc.gnu.org/onlinedocs/gcc/Simple-Constraints.html ?
I'm not exactly sure what you're suggesting. Ultimately: are we going to diverge from the canonical gcc behavior here for this feature? |
This is also assuming address space 0