This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug optimization/14272] [tree-ssa] miscompilation of __exchange_and_add (atomicity.h)


------- Additional Comments From steven at gcc dot gnu dot org  2004-02-25 13:32 -------
This is a bug in the "How can this ever have worked" class. 
 
Here's the .optimized tree dump: 
---------------------------------------------------------- 
;; Function int __exchange_and_add(volatile int*, int) 
(_Z18__exchange_and_addPVii) 
 
 
CFG Statistics for int __exchange_and_add(volatile int*, int) 
 
--------------------------------------------------------- 
                                Number of        Memory 
                                instances         used  
--------------------------------------------------------- 
Basic blocks                              1         92b 
Edges                                     1         40b 
Basic block annotations                   1         20b 
--------------------------------------------------------- 
Total memory used by CFG data                      152b 
--------------------------------------------------------- 
 
Coalesced label blocks: 0 (Max so far: 0) 
 
int __exchange_and_add(volatile int*, int) (__mem, __val) 
{ 
  int __tmp; 
  int __result; 
  int T.1; 
  volatile int T.0; 
 
  # BLOCK 0 
  # PRED: ENTRY [100.0%]  (fallthru,exec) 
  __result_2 = *__mem_1; 
  T.0_3 = *__mem_1; 
  T.1_5 = T.0_3 + __val_4; 
  *__mem_1 = T.1_5; 
  return __result_2; 
  # SUCC: EXIT [100.0%]  
 
} 
 
 
 
Partition map  
 
 
After Coalescing: 
 
Partition map  
 
Partition 0 (__mem_1 - 1 ) 
Partition 1 (__result_2 - 2 ) 
Partition 2 (T.0_3 - 3 ) 
Partition 3 (__val_4 - 4 ) 
Partition 4 (T.1_5 - 5 ) 
Partition 5 (<retval>_6 - 6 ) 
 
 
Replacing Expressions 
__result_2 replace with --> *__mem_1 
T.0_3 replace with --> *__mem_1 
T.1_5 replace with --> T.0_3 + __val_4 
 
<retval>_6  --> <retval> 
T.1_5  --> T.1 
__val_4  --> __val 
T.0_3  --> T.0 
__result_2  --> __result 
__mem_1  --> __mem 
After Root variable replacement: 
 
Partition map  
 
Partition 0 (__mem - 1 ) 
Partition 1 (__result - 2 ) 
Partition 2 (T.0 - 3 ) 
Partition 3 (__val - 4 ) 
Partition 4 (T.1 - 5 ) 
Partition 5 (<retval> - 6 ) 
 
 
CFG Statistics for int __exchange_and_add(volatile int*, int) 
 
--------------------------------------------------------- 
                                Number of        Memory 
                                instances         used  
--------------------------------------------------------- 
Basic blocks                              1         92b 
Edges                                     1         40b 
Basic block annotations                   1         20b 
--------------------------------------------------------- 
Total memory used by CFG data                      152b 
--------------------------------------------------------- 
 
Coalesced label blocks: 0 (Max so far: 0) 
 
int __exchange_and_add(volatile int*, int) (__mem, __val) 
{ 
  int __tmp; 
  int __result; 
  int T.1; 
  volatile int T.0; 
 
  # BLOCK 0 
  # PRED: ENTRY [100.0%]  (fallthru,exec) 
  *__mem = *__mem + __val; 
  return *__mem; 
  # SUCC: EXIT [100.0%]  
 
} 
 
 
int __exchange_and_add(volatile int*, int) (__mem, __val) 
{ 
  int __tmp; 
  int __result; 
  int T.1; 
  volatile int T.0; 
 
  # BLOCK 0 
  # PRED: ENTRY [100.0%]  (fallthru,exec) 
  *__mem<D1463> = *__mem<D1463> + __val<D1464>; 
  return *__mem<D1463>; 
  # SUCC: EXIT [100.0%]  
 
} 
---------------------------------------------------------- 
 
Look how the original function returns *__mem with the value 
that it enters the function with, and the second returns with 
*__mem + __val:  *__mem is redefined between the point of the 
load to the function result and the return statement. 
 
This is a really nasty bug... 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dnovillo at redhat dot com
   Last reconfirmed|2004-02-24 14:26:13         |2004-02-25 13:32:06
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14272


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]