gpt4 book ai didi

MSVC compiled code hits debug assert when using _Atomic float(使用原子浮点时,MSVC编译代码命中调试断言)

转载 作者:bug小助手 更新时间:2023-10-25 13:07:18 26 4
gpt4 key购买 nike



I have the following code:

我有以下代码:


static _Atomic float testf;
void func() {
testf=1.0f;
float f=testf;
printf("%f\n", f);
}

Running it causes the program to hit a Debug Assert, Invalid memory order, at vcruntime_c11_atomic_support.h:417. (MSVC version 19.37.32822.0).

运行它会导致程序在vcruntime_c11_tom_support.h:417遇到调试断言,内存顺序无效。(MSVC版本19.37.32822.0)。


I'm not that familiar with x64 calling conventions, but it looks like the generated assembly isn't calling either one of _Atomic_store32 or _Atomic_load32 correctly:

我不太熟悉x64调用约定,但看起来生成的程序集没有正确调用_ATOM_STORY32或_ATOM_LOAD32之一:


inline void _Atomic_store32(volatile int* _Ptr, int _Desired, int _Order);
inline int _Atomic_load32(const volatile int* _Ptr, int _Order);

; 41   :     testf=1.0f;

mov r8d, 5 ; !!This seems to be _Order, corresponding to _Atomic_memory_order_seq_cst
movss xmm1, DWORD PTR __real@3f800000
lea rcx, OFFSET FLAT:testf
call _Atomic_store32 ; !!Where is EDX? That should contain _Desired.

; 42 : float f=testf;

movss xmm1, DWORD PTR __real@40a00000
lea rcx, OFFSET FLAT:testf
call _Atomic_load32 ; !!EDX should have _Order.
movss DWORD PTR f$[rsp], xmm0

Is MSVC atomic support bugged, or am I doing something wrong?

是MSVC原子支持被窃听了,还是我做错了什么?


更多回答
优秀答案推荐

Looks like a compiler bug from that asm output.

看起来像是来自ASM输出的编译器错误。


It's like the compiler wants to call _Atomic_store32(void*, float) since it's passing the second arg in XMM1. But that's the same function it uses for integers, I assume, so yeah the actual arg needs to be in EDX. Treating it like a variadic function would work for the Win x64 calling convention, since those functions need XMM args to be copied to the corresponding integer reg.

这就像编译器想要调用_ATOM_STORE32(空*,浮点),因为它传递的是XMM1中的第二个arg。但这是它对整数使用的相同函数,我假设,所以是的,实际的arg需要在edX中。将其视为变量函数将适用于Win x64调用约定,因为这些函数需要将XMM参数复制到相应的整数reg。


For the load, movss xmm1, DWORD PTR __real@40a00000 is loading a float constant with bit-pattern 0x40a00000 into the second arg-passing register (for FP args). That bit-pattern represents 5.0f, so MSVC has got itself very confused about something, doing _Atomic_load32(&testf, (float)memory_order_seq_cst) with those arg types.

对于LOAD,movss xmm1,DWORD PTR__REAL@40a00000正在将位模式为0x40a00000的浮点常量加载到第二个参数传递寄存器(用于FP参数)。该位模式表示5.0f,因此MSVC对某些事情感到非常困惑,使用这些arg类型执行_ATOM_LOAD32(&Testf,(Float)Memory_Order_seq_cst)。


Emitting code like that is definitely a sign of a compiler bug. (And nice job constructing a minimal test-case and showing the relevant asm. You could submit this exact example to MS's compiler team and they'd very quickly see the symptoms of something being wrong.)

发出这样的代码绝对是编译器错误的迹象。(构建一个最小的测试用例并显示相关的ASM非常好。您可以将这个确切的示例提交给MS的编译器团队,他们很快就会发现有问题的症状。)


更多回答

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com