diff --git a/clang/docs/LanguageExtensions.rst b/clang/docs/LanguageExtensions.rst --- a/clang/docs/LanguageExtensions.rst +++ b/clang/docs/LanguageExtensions.rst @@ -1546,28 +1546,25 @@ ASM Goto with Output Constraints ================================ -In addition to the functionality provided by `GCC's extended -assembly `_, clang -supports output constraints with the `goto` form. +.. note:: -The goto form of GCC's extended assembly allows the programmer to branch to a C -label from within an inline assembly block. Clang extends this behavior by -allowing the programmer to use output constraints: + Clang's implementation of ASM goto differs from `GCC's + implementation`_ in + 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 y; - asm goto("# %0 %1 %l2" : "=r"(y) : "r"(x) : : err); + int foo(int x) { + int y, z; + asm goto(... : "=r"(y), "=r"(z): "r"(x) : : err); return y; err: - return -1; - } - -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. + return z; + } 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