[cfe-commits] r154612 - in /cfe/trunk: lib/CodeGen/CGExpr.cpp lib/CodeGen/CodeGenTypes.cpp lib/Sema/SemaExprCXX.cpp test/CodeGenCXX/atomicinit.cpp

Douglas Gregor dgregor at apple.com
Thu Apr 12 13:42:30 PDT 2012


Author: dgregor
Date: Thu Apr 12 15:42:30 2012
New Revision: 154612

URL: http://llvm.org/viewvc/llvm-project?rev=154612&view=rev
Log:
Fix some i1/i8 confusion within _Atomic(bool) in IR generation, both
in general (such an atomic has boolean representation) and
specifically for IR generation of __c11_atomic_init. The latter also
means actually using initialization semantics for this initialization,
rather than just creating a store.

On a related note, make sure we actually put in non-atomic-to-atomic
conversions when performing an implicit conversion sequence. IR
generation is far too kind here, but we still want the ASTs to make
sense.


Modified:
    cfe/trunk/lib/CodeGen/CGExpr.cpp
    cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
    cfe/trunk/lib/Sema/SemaExprCXX.cpp
    cfe/trunk/test/CodeGenCXX/atomicinit.cpp

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=154612&r1=154611&r2=154612&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Thu Apr 12 15:42:30 2012
@@ -867,6 +867,9 @@
   if (const EnumType *ET = Ty->getAs<EnumType>())
     return ET->getDecl()->getIntegerType()->isBooleanType();
 
+  if (const AtomicType *AT = Ty->getAs<AtomicType>())
+    return hasBooleanRepresentation(AT->getValueType());
+
   return false;
 }
 
@@ -1227,7 +1230,7 @@
   // Get the source value, truncated to the width of the bit-field.
   llvm::Value *SrcVal = Src.getScalarVal();
 
-  if (Dst.getType()->isBooleanType())
+  if (hasBooleanRepresentation(Dst.getType()))
     SrcVal = Builder.CreateIntCast(SrcVal, ResLTy, /*IsSigned=*/false);
 
   SrcVal = Builder.CreateAnd(SrcVal, llvm::APInt::getLowBitsSet(ResSizeInBits,
@@ -2843,10 +2846,11 @@
   if (E->getOp() == AtomicExpr::AO__c11_atomic_init) {
     assert(!Dest && "Init does not return a value");
     if (!hasAggregateLLVMType(E->getVal1()->getType())) {
-      llvm::StoreInst *Store =
-        Builder.CreateStore(EmitScalarExpr(E->getVal1()), Ptr);
-      Store->setAlignment(Size);
-      Store->setVolatile(E->isVolatile());
+      QualType PointeeType
+        = E->getPtr()->getType()->getAs<PointerType>()->getPointeeType();
+      EmitScalarInit(EmitScalarExpr(E->getVal1()),
+                     LValue::MakeAddr(Ptr, PointeeType, alignChars,
+                                      getContext()));
     } else if (E->getType()->isAnyComplexType()) {
       EmitComplexExprIntoAddr(E->getVal1(), Ptr, E->isVolatile());
     } else {

Modified: cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenTypes.cpp?rev=154612&r1=154611&r2=154612&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenTypes.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenTypes.cpp Thu Apr 12 15:42:30 2012
@@ -556,7 +556,7 @@
   }
 
   case Type::Atomic: {
-    ResultType = ConvertTypeForMem(cast<AtomicType>(Ty)->getValueType());
+    ResultType = ConvertType(cast<AtomicType>(Ty)->getValueType());
     break;
   }
   }

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=154612&r1=154611&r2=154612&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Thu Apr 12 15:42:30 2012
@@ -2765,6 +2765,13 @@
     llvm_unreachable("Improper third standard conversion");
   }
 
+  // If this conversion sequence involved a scalar -> atomic conversion, perform
+  // that conversion now.
+  if (const AtomicType *ToAtomic = ToType->getAs<AtomicType>())
+    if (Context.hasSameType(ToAtomic->getValueType(), From->getType()))
+      From = ImpCastExprToType(From, ToType, CK_NonAtomicToAtomic, VK_RValue, 0,
+                               CCK).take();
+      
   return Owned(From);
 }
 

Modified: cfe/trunk/test/CodeGenCXX/atomicinit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/atomicinit.cpp?rev=154612&r1=154611&r2=154612&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/atomicinit.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/atomicinit.cpp Thu Apr 12 15:42:30 2012
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -emit-llvm -o - -triple=i686-apple-darwin9 | FileCheck %s
+// RUN: %clang_cc1 %s -emit-llvm -O1 -o - -triple=i686-apple-darwin9 | FileCheck %s
 struct A {
   _Atomic(int) i;
   A(int j);
@@ -21,5 +21,28 @@
 // CHECK: define void @_Z11atomic_initR1Ai
 void atomic_init(A& a, int i) {
   // CHECK-NOT: atomic
+  // CHECK: tail call void @_ZN1BC1Ei
   __c11_atomic_init(&b, B(i));
+  // CHECK-NEXT: ret void
 }
+
+// CHECK: define void @_Z16atomic_init_boolPU7_Atomicbb
+void atomic_init_bool(_Atomic(bool) *ab, bool b) {
+  // CHECK-NOT: atomic
+  // CHECK: {{zext i1.*to i8}}
+  // CHECK-NEXT: store i8
+  __c11_atomic_init(ab, b);
+  // CHECK-NEXT: ret void
+}
+
+struct AtomicBoolMember {
+  _Atomic(bool) ab;
+  AtomicBoolMember(bool b);
+};
+
+// CHECK: define void @_ZN16AtomicBoolMemberC2Eb
+// CHECK: {{zext i1.*to i8}}
+// CHECK-NEXT: store i8
+// CHECK-NEXT: ret void
+AtomicBoolMember::AtomicBoolMember(bool b) : ab(b) { }
+





More information about the cfe-commits mailing list