简体   繁体   English

带有 goto 的扩展 asm,包括来自 gcc 文档的示例,无法编译

[英]Extended asm with goto, including an example from the gcc docs, fails to compile

Some extended assembly statements using the goto qualifier fail to compile with GCC 10.1.0.一些使用goto限定符的扩展汇编语句无法使用 GCC 10.1.0 编译。 Specifically,具体来说,

int foo(int count)
{
  asm goto ("dec %0; jb %l[stop]"
            : "+r" (count)
            :
            :
            : stop);
  return count;
stop:
  return 0;
}

(which is an example in the GCC extended asm docs ) fails to compile with the message expected ':' before string constant . (这是GCC 扩展 asm 文档中的一个示例)无法expected ':' before string constant进行编译。 Removing the "+r" (count) and the dec %0 allows it to compile successfully, but regardless of what I try whenever an output operand is supplied in the same asm statement as a goto label, it errors in this same way.删除"+r" (count)dec %0允许它成功编译,但无论我何时尝试在与 goto label 相同的 asm 语句中提供 output 操作数时,它都会以同样的方式出错。

It appears the current development GCC documentation which you are referencing applies to the latest trunk branches of GCC and doesn't apply to any of the official releases of GCC.您正在参考的当前开发GCC 文档似乎适用于 GCC 的最新主干分支,不适用于 Z32D8B233E3C58A262A0B7587229 的任何官方版本。 Official releases of GCC do not as of this time support asm goto with any output or input/output constraints. GCC 的官方版本目前不支持带有任何 output 或输入/输出约束的asm goto You can see this on godbolt .你可以在Godbolt上看到这个。 Latest trunk works but 10.2 and 10.1 don't.最新的主干有效,但 10.2 和 10.1 无效。 The fix is to wait for the next major release of GCC (version 11.x);修复方法是等待 GCC(版本 11.x)的下一个主要版本; download and compile the latest trunk release;下载并编译最新的主干版本; modify your inline assembly so that it doesn't rely on any output or output/input constraints.修改您的内联程序集,使其不依赖任何 output 或输出/输入约束。

Up until recently the documentation for GCC up to version 10.x had this to say:直到最近,GCC 版本 10.x 的文档都这样说:

An asm goto statement cannot have outputs . asm goto 语句不能有输出 This is due to an internal restriction of the compiler: control transfer instructions cannot have outputs.这是由于编译器的内部限制:控制转移指令不能有输出。 If the assembler code does modify anything, use the "memory" clobber to force the optimizers to flush all register values to memory and reload them if necessary after the asm statement.如果汇编程序代码确实修改了任何内容,请使用“内存”破坏程序强制优化器将所有寄存器值刷新到 memory 并在 asm 语句之后重新加载它们(如有必要)。

A list of all the documentation for the official releases and the current development documentation can be found at this URL .可以在此URL中找到正式版本的所有文档和当前开发文档的列表。 The current development documentation is at the bottom of the page.当前的开发文档位于页面底部。 Rule of thumb is that you should consult the documentation for your specific version of GCC.经验法则是您应该查阅 GCC 特定版本的文档。 I believe that all 10.x release documentation is the same as the latest 10.x version of the documentation on the GCC webpage.我相信所有 10.x 版本文档与 GCC 网页上的最新 10.x 版本文档相同。

Recent versions of CLANG/LLVM (11.0+) do support this feature but that is relatively recent addition as well.最新版本的 CLANG/LLVM (11.0+) 确实支持此功能,但这也是相对较新的添加。

asm goto doesn't allow output operands. asm goto 不允许 output 操作数。

It is a gnu decision.这是一个 gnu 决定。 in the function c_parser_for_statement from c-parser.c you can find:在来自 c-parser.c 的 function c_parser_for_statement 中,您可以找到:

/* For asm goto, we don't allow output operands, but reserve
the slot for a future extension that does allow them.  */

https://github.com/gcc-mirror/gcc/blob/releases/gcc-10/gcc/c/c-parser.c https://github.com/gcc-mirror/gcc/blob/releases/gcc-10/gcc/c/c-parser.c

However may be this situation will change since in the master branch this comment is not present anymore.然而,这种情况可能会改变,因为在主分支中,这条评论不再存在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM