[Sema] Check __builtin_bit_cast operand for completeness before materializing it.
authorErik Pilkington <erik.pilkington@gmail.com>
Mon, 12 Aug 2019 19:29:43 +0000 (19:29 +0000)
committerErik Pilkington <erik.pilkington@gmail.com>
Mon, 12 Aug 2019 19:29:43 +0000 (19:29 +0000)
This shouldn't be observable, but it doesn't make sense to materialize an
incomplete type.

llvm-svn: 368610

clang/lib/Sema/SemaCast.cpp

index 7a1d52a..71e5e8e 100644 (file)
@@ -2799,9 +2799,6 @@ void CastOperation::CheckCStyleCast() {
 
 void CastOperation::CheckBuiltinBitCast() {
   QualType SrcType = SrcExpr.get()->getType();
-  if (SrcExpr.get()->isRValue())
-    SrcExpr = Self.CreateMaterializeTemporaryExpr(SrcType, SrcExpr.get(),
-                                                  /*IsLValueReference=*/false);
 
   if (Self.RequireCompleteType(OpRange.getBegin(), DestType,
                                diag::err_typecheck_cast_to_incomplete) ||
@@ -2811,6 +2808,10 @@ void CastOperation::CheckBuiltinBitCast() {
     return;
   }
 
+  if (SrcExpr.get()->isRValue())
+    SrcExpr = Self.CreateMaterializeTemporaryExpr(SrcType, SrcExpr.get(),
+                                                  /*IsLValueReference=*/false);
+
   CharUnits DestSize = Self.Context.getTypeSizeInChars(DestType);
   CharUnits SourceSize = Self.Context.getTypeSizeInChars(SrcType);
   if (DestSize != SourceSize) {