Testing abort with tm_pure

Testing abort with tm_pure

Hi I ma using the Intel STM C compiler version 2.0,

Ihave the following code bellow. when compiled

$icc -Qtm_enable test test.c

the value of "b" is 1 but is expected 0. It works for -O0 specified explicitly. Found it useful to share since users may waste quite a time understanding why getting wired variables when not compiling with -O0.

1 #include
2 #include
3 #include
4
5 int abort_counter = 0;
6
7 __attribute__((tm_pure))
8 void increment_abort_counter()
9 {
10 abort_counter++;
11 }
12
13
14 int main()
15 {
16 int a = 0;
17 int b = 0;
18
19 __tm_atomic
20 {
21 a++;
22
23 increment_abort_counter();
24
25 __tm_atomic
26 {
27 b++;
28 increment_abort_counter();
29
30 if (abort_counter == 2)
31 {
32 __tm_abort;
33 }
34 }
35 }
36
37 printf("abort_counter, expected 2, actual: %d\n", abort_counter);
38 printf("a, expected 1, actual: %d\n", a);
39 printf("b, expected 0, actual: %d\n", b);
40 return 0;
41 }

publicaciones de 2 / 0 nuevos
Último envío
Para obtener más información sobre las optimizaciones del compilador, consulte el aviso sobre la optimización.
Best Reply

Quoting - feradz

Hi I ma using the Intel STM C compiler version 2.0,

Ihave the following code bellow. when compiled

$icc -Qtm_enable test test.c

the value of "b" is 1 but is expected 0. It works for -O0 specified explicitly. Found it useful to share since users may waste quite a time understanding why getting wired variables when not compiling with -O0.

1 #include
2 #include
3 #include
4
5 int abort_counter = 0;
6
7 __attribute__((tm_pure))
8 void increment_abort_counter()
9 {
10 abort_counter++;
11 }
12
13
14 int main()
15 {
16 int a = 0;
17 int b = 0;
18
19 __tm_atomic
20 {
21 a++;
22
23 increment_abort_counter();
24
25 __tm_atomic
26 {
27 b++;
28 increment_abort_counter();
29
30 if (abort_counter == 2)
31 {
32 __tm_abort;
33 }
34 }
35 }
36
37 printf("abort_counter, expected 2, actual: %dn", abort_counter);
38 printf("a, expected 1, actual: %dn", a);
39 printf("b, expected 0, actual: %dn", b);
40 return 0;
41 }

Yes the value of b should be 0. This is a bug in the compiler,when optimization is enabled we incorrectly propagate the value b++ to the print statement.Next update should address this problem.

Deje un comentario

Por favor inicie sesión para agregar un comentario. ¿No es socio? Únase ya