https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103640

            Bug ID: 103640
           Summary: asm goto w/ outputs numbering with tied outputs
                    differs from clang
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ndesaulniers at google dot com
                CC: foom at fuhm dot net, segher at gcc dot gnu.org, vmakarov 
at redhat dot com
  Target Milestone: ---

Consider the following input:

void *x(void) {
  void *p = &&foo;
  asm goto ("# %0\n\t# %l1":"+r"(p):::foo);
  foo:;
  return p;
}

%0 refers to the 0th operand `p`.
%l1 refers to the 1st operand `foo`.

This code compiles in Clang, but not GCC.

If you change %l1 to %l2, that will compile in GCC but not clang.

Because +r constraint is being used, I suspect there's a hidden input being
tied to the output.

While we can change this in clang (https://reviews.llvm.org/D115471), I do
think it would be more ergonomic for developers if the order of operands for
the outputs templates matched the order of the asm operands.  Otherwise,
developers need to understand hidden inputs, or use symbolic names like:

asm goto ("# %0\n\t# %l[foo]":"+r"(p):::foo);

I suspect there's not enough users yet of asm goto w/ outputs to notice such a
change, either way.

Reply via email to