aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Chisnall <csdavec@swan.ac.uk>2012-04-11 15:29:15 +0000
committerDavid Chisnall <csdavec@swan.ac.uk>2012-04-11 15:29:15 +0000
commit3a3c9b26ded46cb9055564adb2f48911eef84ace (patch)
tree58de576d39c82684136e9b9fac49cc97a776c870
parent93848e08a512a9487485dc4a94d03a66529be703 (diff)
Allow c++ initialisers to initialise _Atomic fields.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@154499 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaOverload.cpp7
-rw-r--r--test/CodeGenCXX/atomicinit.cpp12
2 files changed, 19 insertions, 0 deletions
diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp
index e4c6fdfb59..4ba25c4eeb 100644
--- a/lib/Sema/SemaOverload.cpp
+++ b/lib/Sema/SemaOverload.cpp
@@ -1316,6 +1316,13 @@ static bool IsStandardConversion(Sema &S, Expr* From, QualType ToType,
SCS.setFromType(FromType);
SCS.CopyConstructor = 0;
+ // Allow conversion to _Atomic types. These are C11 and are provided as an
+ // extension in C++ mode.
+ if (const AtomicType *ToAtomicType = ToType->getAs<AtomicType>()) {
+ if (ToAtomicType->getValueType() == FromType)
+ return true;
+ }
+
// There are no standard conversions for class types in C++, so
// abort early. When overloading in C, however, we do permit
if (FromType->isRecordType() || ToType->isRecordType()) {
diff --git a/test/CodeGenCXX/atomicinit.cpp b/test/CodeGenCXX/atomicinit.cpp
new file mode 100644
index 0000000000..17c5b62a3a
--- /dev/null
+++ b/test/CodeGenCXX/atomicinit.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 %s -emit-llvm -o - -triple=i686-apple-darwin9 | FileCheck %s
+struct A {
+ _Atomic(int) i;
+ A(int j);
+ void v(int j);
+};
+// Storing to atomic values should be atomic
+// CHECK: store atomic i32
+void A::v(int j) { i = j; }
+// Initialising atomic values should not be atomic
+// CHECK-NOT: store atomic
+A::A(int j) : i(j) {}