[clang] number labels in asm goto strings after tied inputs
I noticed that the following case would compile in Clang but not GCC: void *x(void) { void *p = &&foo; asm goto ("# %0\n\t# %l1":"+r"(p):::foo); foo:; return p; } Changing the output template above from %l2 would compile in GCC but not Clang. This demonstrates that when using tied outputs (say via the "+r" output constraint), the hidden inputs occur or are numbered BEFORE the labels, at least with GCC. In fact, GCC does denote this in its documentation: https://gcc.gnu.org/onlinedocs/gcc-11.2.0/gcc/Extended-Asm.html#Goto-Labels > Output operand with constraint modifier ‘+’ is counted as two operands > because it is considered as one output and one input operand. For the sake of compatibility, I think it's worthwhile to just make this change. It's better to use symbolic names for compatibility (especially now between released version of Clang that support asm goto with outputs). ie. %l1 from the above would be %l[foo]. The GCC docs also make this recommendation. Also, I cleaned up some cruft in GCCAsmStmt::getNamedOperand. AFAICT, NumPlusOperands was no longer used, though I couldn't find which commit didn't clean that up correctly. Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98096 Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103640 Link: https://gcc.gnu.org/onlinedocs/gcc-11.2.0/gcc/Extended-Asm.html#Goto-Labels Reviewed By: void Differential Revision: https://reviews.llvm.org/D115471
Loading
Please sign in to comment