The following msvc command line option suggests that memory fences are introduced using the option /volatile:ms
(default) but not when using /volatile:iso
. I have not been able to come up with any example code that does this.
For example one of my random attempts
https://godbolt.org/z/qrz18j3h9
volatile int A, B;
void foo()
{
A = B+1;
B = A+1;
}
generates the following asm
int volatile A DD 01H DUP (?) ; A
int volatile B DD 01H DUP (?) ; B
voltbl SEGMENT
_volmd DB 00H
DB 08H
DB 0eH
DB 016H
voltbl ENDS
void foo(void) PROC ; foo, COMDAT
mov eax, DWORD PTR int volatile B ; B
inc eax
mov DWORD PTR int volatile A, eax ; A
mov eax, DWORD PTR int volatile A ; A
inc eax
mov DWORD PTR int volatile B, eax ; B
ret 0
void foo(void) ENDP
irrespective of whether I use option /volatile:ms
or /volatile:iso
with Visual Studio 2019.
Can somebody provide an example where the above two options do make a difference to the output assembly code?