From: Erik Pilkington Date: Mon, 12 Aug 2019 19:29:43 +0000 (+0000) Subject: [Sema] Check __builtin_bit_cast operand for completeness before materializing it. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8cfecdf7b60541f2e90fec818a6d5504efc422e2;p=clang [Sema] Check __builtin_bit_cast operand for completeness before materializing it. This shouldn't be observable, but it doesn't make sense to materialize an incomplete type. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@368610 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaCast.cpp b/lib/Sema/SemaCast.cpp index 7a1d52ad4e..71e5e8e428 100644 --- a/lib/Sema/SemaCast.cpp +++ b/lib/Sema/SemaCast.cpp @@ -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) {