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 libstdc++/12496] New: wrong result for __atomic_add(&value, -1) when using -o0


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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

           Summary: wrong result for __atomic_add(&value, -1) when using -o0
           Product: gcc
           Version: 3.2.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: patrick dot frants at quintiq dot com
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: sparc-sun-solaris2.8
  GCC host triplet: sparc-sun-solaris2.8
GCC target triplet: sparc-sun-solaris2.8

First of all I don't know wether it is a library or code generation problem, as 
I don't know wether the inline assembler in atomicity.h *should* produce 
correct code.

With -o0 __atomic_add with -1 as the second argument results in 4294967305. 
With all other optimization levels it results in the right value.

The output of the program below is:

bash-2.03$ g++ -m64 atomic_add_bug.cpp 
bash-2.03$ a.out
__atomic_add(10,  1) = 11
__atomic_add(10, -1) = 4294967305


/* Compile this on Sparc:
 * "g++ -o0 -m64 atomic_add_bug.cpp"
 * Execute a.out and see that the output for adding -1 is incorrect!
 *
 * Repeating the same procedure for -o1, -o2, -o3 shows that those
 * optimization levels produce expected output.
 */

#include <iostream>
using namespace std;

#include <bits/atomicity.h>

int main(int argc, char** argv)
{
  _Atomic_word inc_result = 10;
  _Atomic_word dec_result = 10;

  __atomic_add(&inc_result, 1);
  __atomic_add(&dec_result, -1);

  cout << "__atomic_add(10,  1) = " << inc_result << endl;
  cout << "__atomic_add(10, -1) = " << dec_result << endl;
  return 0;
}


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