Sema: Permit an atomic type to be initialized by the same atomic type
authorDavid Majnemer <david.majnemer@gmail.com>
Sun, 28 Dec 2014 21:47:31 +0000 (21:47 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Sun, 28 Dec 2014 21:47:31 +0000 (21:47 +0000)
We forgot a conversion step when initializing an atomic type with an
rvalue of the same type.

This fixes PR22043.

llvm-svn: 224902

clang/lib/Sema/SemaExprCXX.cpp
clang/test/CodeGenCXX/atomicinit.cpp

index d3a1fa8..1e692eb 100644 (file)
@@ -2759,7 +2759,11 @@ Sema::PerformImplicitConversion(Expr *From, QualType ToType,
   // Perform the first implicit conversion.
   switch (SCS.First) {
   case ICK_Identity:
-    // Nothing to do.
+    if (const AtomicType *FromAtomic = FromType->getAs<AtomicType>()) {
+      FromType = FromAtomic->getValueType().getUnqualifiedType();
+      From = ImplicitCastExpr::Create(Context, FromType, CK_AtomicToNonAtomic,
+                                      From, /*BasePath=*/nullptr, VK_RValue);
+    }
     break;
 
   case ICK_Lvalue_To_Rvalue: {
index 91b990b..982396e 100644 (file)
@@ -1,5 +1,9 @@
 // RUN: %clang_cc1 %s -emit-llvm -O1 -o - -triple=i686-apple-darwin9 -std=c++11 | FileCheck %s
 
+// CHECK-DAG: @PR22043 = global i32 0, align 4
+typedef _Atomic(int) AtomicInt;
+AtomicInt PR22043 = AtomicInt();
+
 // CHECK-DAG: @_ZN7PR180978constant1aE = global { i16, i8 } { i16 1, i8 6 }, align 4
 // CHECK-DAG: @_ZN7PR180978constant1bE = global { i16, i8 } { i16 2, i8 6 }, align 4
 // CHECK-DAG: @_ZN7PR180978constant1cE = global { i16, i8 } { i16 3, i8 6 }, align 4