[clang] Update ASM goto documentation to reflect how Clang differs from GCC

That said, we are planning to add this support in the near future.

Link: https://github.com/llvm/llvm-project/issues/53562

Differential Revision: https://reviews.llvm.org/D135818
This commit is contained in:
Bill Wendling 2022-10-12 14:43:38 -07:00
parent 02a543db66
commit 8c7b3461a5
1 changed files with 14 additions and 17 deletions

View File

@ -1546,28 +1546,25 @@ Query for this feature with ``__has_extension(blocks)``.
ASM Goto with Output Constraints ASM Goto with Output Constraints
================================ ================================
In addition to the functionality provided by `GCC's extended .. note::
assembly <https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html>`_, clang
supports output constraints with the `goto` form.
The goto form of GCC's extended assembly allows the programmer to branch to a C Clang's implementation of ASM goto differs from `GCC's
label from within an inline assembly block. Clang extends this behavior by implementation<https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html>`_ in
allowing the programmer to use output constraints: that Clang doesn't yet support outputs on the indirect branch. Use of an
output on the indirect branch may result in undefined behavior and should be
avoided. E.g., in the following `z` isn't valid when used and may have
different values depending on optimization levels. (Clang may not warn about
such constructs.)
.. code-block:: c++ .. code-block:: c++
int foo(int x) { int foo(int x) {
int y; int y, z;
asm goto("# %0 %1 %l2" : "=r"(y) : "r"(x) : : err); asm goto(... : "=r"(y), "=r"(z): "r"(x) : : err);
return y; return y;
err: err:
return -1; return z;
} }
It's important to note that outputs are valid only on the "fallthrough" branch.
Using outputs on an indirect branch may result in undefined behavior. For
example, in the function above, use of the value assigned to `y` in the `err`
block is undefined behavior.
When using tied-outputs (i.e. outputs that are inputs and outputs, not just When using tied-outputs (i.e. outputs that are inputs and outputs, not just
outputs) with the `+r` constraint, there is a hidden input that's created outputs) with the `+r` constraint, there is a hidden input that's created