误报:未定义或垃圾返回值呼叫者 [英] False positive: Undefined or garbage value returned to caller

查看:273
本文介绍了误报:未定义或垃圾返回值呼叫者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下code。使用内联汇编填充一个结果是:

The following code populates a result using inline assembly:

uint64_t Foo::f() {
    uint64_t result;

    asm volatile
    ("vldmia        %1, {q0-q1}     \n" // q0-1 = *this

     ⋮

     "vstmia        %0, {d0}        \n" // result = d0

     :: "r"(&result), "r"(this)
     : "q0", "q1");

    return result;
}

结果变量是在组装code无条件地确定,但X code'S分析似乎忽略这个(流量分析,从声明直线跳过到return语句),并抱怨:

The result variable is unconditionally set in the assembly code, but Xcode's Analyzer seems to ignore this (the flow analysis skips straight from the declaration to the return statement) and complains:

…/BitBoard.cpp:26:9: Undefined or garbage value returned to caller

有没有办法安抚分析仪不浪费周期初始化结果

编辑:我试图指定输出约束建议:

I've tried the suggestion to specify an output constraint:

: "=r"(&result) : "r"(this), "r"(&result)

但是编译器,在汇编输出无效的左值croaks。删除&安培; 编译,但回报看似随意的结果。更改 vstmia%0,{D0} VMOV%0,D0 也失败了,以为指令操作数无效

But the compiler croaks with "Invalid lvalue in asm output". Removing the & compiles but returns seemingly random results. Changing vstmia %0, {d0} to vmov %0, d0 also fails, with "Invalid operand for instruction".

我怀疑我必须标记结果作为输出,建议,并在不同的装配code填充它,但我找不到任何上了解的信息这样做。

I suspect that I have to mark result as an output, as suggested, and populate it differently in the assembly code, but I can't find any information on know to do so.

推荐答案

我怀疑这是由于缺乏的输出约束

I suspect this is due to the lack of an output constraint.

试试这个,

uint64_t Foo::f() {
    uint64_t result;

    asm /* volatile */
    ("vldmia        %1, {q0-q1}     \n" // q0-1 = *this

     ⋮

     "vstmia        %0, {d0}        \n" // result = d0

     : "=w"(result): "r"(this) : "q0", "q1");

    return result;
}

您必须使用的输出的约束,= W(结果),以告诉汇编器设置一个值的编译器。你可能如果你这样做不需要挥发性。至少,这是消除一个很好的问题。

You must use an output constraint, "=w"(result), to tell the compiler that the assembler is setting a value. You probably don't need the volatile if you do this. At least, this is a good issue to eliminate.

这篇关于误报:未定义或垃圾返回值呼叫者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆