summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
authorDavid Chisnall <csdavec@swan.ac.uk>2012-01-16 17:27:18 +0000
committerDavid Chisnall <csdavec@swan.ac.uk>2012-01-16 17:27:18 +0000
commitfa35df628a4ab331347dc448ccde573d6a7fa81d (patch)
treebfd08bb857ccb2b66b87541d23e8a439ab0b336e /clang/test
parent44a2895a0369ba2149f6ed4dc5f90197e854b5be (diff)
downloadbcm5719-llvm-fa35df628a4ab331347dc448ccde573d6a7fa81d.tar.gz
bcm5719-llvm-fa35df628a4ab331347dc448ccde573d6a7fa81d.zip
Some improvements to the handling of C11 atomic types:
- Add atomic-to/from-nonatomic cast types - Emit atomic operations for arithmetic on atomic types - Emit non-atomic stores for initialisation of atomic types, but atomic stores and loads for every other store / load - Add a __atomic_init() intrinsic which does a non-atomic store to an _Atomic() type. This is needed for the corresponding C11 stdatomic.h function. - Enables the relevant __has_feature() checks. The feature isn't 100% complete yet, but it's done enough that we want people testing it. Still to do: - Make the arithmetic operations on atomic types (e.g. Atomic(int) foo = 1; foo++;) use the correct LLVM intrinsic if one exists, not a loop with a cmpxchg. - Add a signal fence builtin - Properly set the fenv state in atomic operations on floating point values - Correctly handle things like _Atomic(_Complex double) which are too large for an atomic cmpxchg on some platforms (this requires working out what 'correctly' means in this context) - Fix the many remaining corner cases llvm-svn: 148242
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/CodeGen/atomic_init.c14
-rw-r--r--clang/test/CodeGen/atomic_ops.c14
-rw-r--r--clang/test/Lexer/has_feature_c1x.c9
-rw-r--r--clang/test/Lexer/has_feature_cxx0x.cpp9
4 files changed, 46 insertions, 0 deletions
diff --git a/clang/test/CodeGen/atomic_init.c b/clang/test/CodeGen/atomic_init.c
new file mode 100644
index 00000000000..243eb602cb1
--- /dev/null
+++ b/clang/test/CodeGen/atomic_init.c
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s
+
+// Check that no atomic operations are used in any initialisation of _Atomic
+// types.
+
+_Atomic(int) i = 42;
+
+void foo()
+{
+ _Atomic(int) j = 12; // CHECK: store
+ // CHECK-NOT: atomic
+ __atomic_init(&j, 42); // CHECK: store
+ // CHECK-NOT: atomic
+}
diff --git a/clang/test/CodeGen/atomic_ops.c b/clang/test/CodeGen/atomic_ops.c
new file mode 100644
index 00000000000..9a18c9e9449
--- /dev/null
+++ b/clang/test/CodeGen/atomic_ops.c
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s
+
+void foo(void)
+{
+ _Atomic(int) i = 0;
+ // Check that multiply / divides on atomics produce a cmpxchg loop
+ i *= 2; // CHECK: cmpxchg
+ i /= 2; // CHECK: cmpxchg
+ // These should be emitting atomicrmw instructions, but they aren't yet
+ i += 2; // CHECK: cmpxchg
+ i -= 2; // CHECK: cmpxchg
+ i++; // CHECK: cmpxchg
+ i--; // CHECK: cmpxchg
+}
diff --git a/clang/test/Lexer/has_feature_c1x.c b/clang/test/Lexer/has_feature_c1x.c
index a502f16ce3f..c9a5f56ddf3 100644
--- a/clang/test/Lexer/has_feature_c1x.c
+++ b/clang/test/Lexer/has_feature_c1x.c
@@ -1,6 +1,15 @@
// RUN: %clang_cc1 -E -std=c1x %s -o - | FileCheck --check-prefix=CHECK-1X %s
// RUN: %clang_cc1 -E %s -o - | FileCheck --check-prefix=CHECK-NO-1X %s
+#if __has_feature(c_atomic)
+int has_atomic();
+#else
+int no_atomic();
+#endif
+
+// CHECK-1X: has_atomic
+// CHECK-NO-1X: no_atomic
+
#if __has_feature(c_static_assert)
int has_static_assert();
#else
diff --git a/clang/test/Lexer/has_feature_cxx0x.cpp b/clang/test/Lexer/has_feature_cxx0x.cpp
index a22cf64c205..f02f1031add 100644
--- a/clang/test/Lexer/has_feature_cxx0x.cpp
+++ b/clang/test/Lexer/has_feature_cxx0x.cpp
@@ -1,6 +1,15 @@
// RUN: %clang_cc1 -E -std=c++11 %s -o - | FileCheck --check-prefix=CHECK-0X %s
// RUN: %clang_cc1 -E %s -o - | FileCheck --check-prefix=CHECK-NO-0X %s
+#if __has_feature(cxx_atomic)
+int has_atomic();
+#else
+int no_atomic();
+#endif
+
+// CHECK-0X: has_atomic
+// CHECK-NO-0X: no_atomic
+
#if __has_feature(cxx_lambdas)
int has_lambdas();
#else
OpenPOWER on IntegriCloud