Sema: Don't crash converting to bool from _Atomic
authorDavid Majnemer <david.majnemer@gmail.com>
Tue, 16 Dec 2014 06:31:17 +0000 (06:31 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Tue, 16 Dec 2014 06:31:17 +0000 (06:31 +0000)
Turning our _Atomic L-value into an R-value removes its _Atomic-ness.
However, we didn't update our 'FromType' which made
ScalarTypeToBooleanCastKind think we were trying to pass it a
non-scalar.

This fixes PR21836.

llvm-svn: 224322

clang/lib/Sema/SemaExprCXX.cpp
clang/test/SemaCXX/atomic-type.cpp

index 1f9c1ea..2227721 100644 (file)
@@ -2754,10 +2754,10 @@ Sema::PerformImplicitConversion(Expr *From, QualType ToType,
 
   case ICK_Lvalue_To_Rvalue: {
     assert(From->getObjectKind() != OK_ObjCProperty);
-    FromType = FromType.getUnqualifiedType();
     ExprResult FromRes = DefaultLvalueConversion(From);
     assert(!FromRes.isInvalid() && "Can't perform deduced conversion?!");
     From = FromRes.get();
+    FromType = From->getType();
     break;
   }
 
index ae18eab..779b067 100644 (file)
@@ -83,3 +83,7 @@ namespace copy_init {
   // allows extraneous braces around initializers.
   Y y3 = { { X(0) }, { 4 } }; // expected-error 2{{illegal initializer type}}
 }
+
+bool PR21836(_Atomic(int) *x) {
+    return *x;
+}