Reordering instructions

I have a question about reordering legal instructions in C # /. NET

Let's start with this example. We have this method defined in some class, where _a, _b and _c are fields.

int _a;
int _b;
int _c;
void Foo()
{
   _a = 1; // Write 1
   _b = 1; // Write 2
   _c = 1; // Write 3
}

And our calling environment will look something like this.

//memory operations
ClassInstance.Foo();
//memory operations

I wonder what kind of legal team reorganization is possible when this method call is built in against the function call. In particular, I am wondering if / when it is legal to reorder memory operations inside Foo () with memory operations outside it (from our previous example, memory operations).

Also, a function call (no built-in), in a sense, "creates memory barriers." As in the case, memory operations that occur before or after a function call cannot be redirected to memory operations in a function call.

, - " ", ?

+4
2

# Language Specification . " " :

3.10

# , ..... # :

  • . , .

  • (Β§10.5.4 Β§10.5.5).

  • (Β§10.5.3).

( - , , , , ).

, " , ". . Coverity :

... CPU [ ] , . ...

, , , " "; - , , .

+4

, ( ) . Order Execution , , . .

, . . , ( .NET Framework, ) .

, , . ↑, ↓, . ↑ ↓. , . , , .

void Foo()
{
   ↑
   _a = 1; // Write 1
   ↑
   _b = 1; // Write 2
   ↑
   _c = 1; // Write 3
}

, , , . , , , Foo.

, , , , , .

+3

Source: https://habr.com/ru/post/1531894/


All Articles