This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/65759] New: atomic_is_lock_free inconsistency between C and C++
- From: "msebor at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 14 Apr 2015 03:29:31 +0000
- Subject: [Bug c/65759] New: atomic_is_lock_free inconsistency between C and C++
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65759
Bug ID: 65759
Summary: atomic_is_lock_free inconsistency between C and C++
Product: gcc
Version: 5.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: msebor at gcc dot gnu.org
The C11 atomic_is_lock_free generic function returns a result that's
inconsistent with the result of the corresponding C++ 11 function for structs
of some small sizes such as 3, 5, 9, or 15. I'm not aware of a requirement
either in the C or the C++ standard that the functions return the same result
but if atomic operations on a type are lock-free in one language, it seems that
they must be implemented that way in other languages as well.
I found a report of similar inconsistency in bug 65033 which has been fixed.
$ cat ~/tmp/lock_free-0.c && (for n in 1 2 3 4 5 8 9 15 16 17; do echo "#
struct { char a[$n]; }" && printf "C " && gcc/xgcc -Bgcc -DNELEMS=$n
-I./gcc/include -L ./powerpc64le-unknown-linux-gnu/libatomic/.libs -latomic
~/tmp/lock_free-0.c && ./a.out && printf "C++ " && gcc/xg++ -Bgcc -DNELEMS=$n
-I./powerpc64le-unknown-linux-gnu/libstdc++-v3/include
-I./powerpc64le-unknown-linux-gnu/libstdc++-v3/include/powerpc64le-unknown-linux-gnu
-std=c++11 -L./powerpc64le-unknown-linux-gnu/libatomic/.libs -L
./powerpc64le-unknown-linux-gnu/libstdc++-v3/src/.libs -latomic
~/tmp/lock_free-0.c && ./a.out; done)
#include <stdio.h>
struct A { char c[NELEMS]; };
#if __cplusplus
# include <atomic>
std::atomic<A> a;
#else
# include <stdatomic.h>
_Atomic struct A a;
#endif
int main (void) {
printf ("%i\n", atomic_is_lock_free (&a));
}
# struct { char a[1]; }
C 1
C++ 1
# struct { char a[2]; }
C 1
C++ 1
# struct { char a[3]; }
C 1
C++ 0
# struct { char a[4]; }
C 1
C++ 1
# struct { char a[5]; }
C 1
C++ 0
# struct { char a[8]; }
C 1
C++ 1
# struct { char a[9]; }
C 0
C++ 0
# struct { char a[15]; }
C 0
C++ 0
# struct { char a[16]; }
C 1
C++ 0
# struct { char a[17]; }
C 0
C++ 0