r368600 - [Sema] Require a complete type for __builtin_bit_cast operands
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 12 11:39:30 PDT 2019
On Mon, 12 Aug 2019 at 11:30, Erik Pilkington via cfe-commits <
cfe-commits at lists.llvm.org> wrote:
> Author: epilk
> Date: Mon Aug 12 11:31:27 2019
> New Revision: 368600
>
> URL: http://llvm.org/viewvc/llvm-project?rev=368600&view=rev
> Log:
> [Sema] Require a complete type for __builtin_bit_cast operands
>
> Fixes llvm.org/PR42936
>
> Modified:
> cfe/trunk/lib/Sema/SemaCast.cpp
> cfe/trunk/test/SemaCXX/builtin-bit-cast.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaCast.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCast.cpp?rev=368600&r1=368599&r2=368600&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaCast.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaCast.cpp Mon Aug 12 11:31:27 2019
> @@ -2803,6 +2803,14 @@ void CastOperation::CheckBuiltinBitCast(
> SrcExpr = Self.CreateMaterializeTemporaryExpr(SrcType, SrcExpr.get(),
>
> /*IsLValueReference=*/false);
>
> + if (Self.RequireCompleteType(OpRange.getBegin(), DestType,
> + diag::err_typecheck_cast_to_incomplete) ||
> + Self.RequireCompleteType(OpRange.getBegin(), SrcType,
> + diag::err_incomplete_type)) {
>
Nit: we should check the source type for completeness before performing
temporary materialization conversion, as materializing a temporary only
makes sense for a complete type.
> + SrcExpr = ExprError();
> + return;
> + }
> +
> CharUnits DestSize = Self.Context.getTypeSizeInChars(DestType);
> CharUnits SourceSize = Self.Context.getTypeSizeInChars(SrcType);
> if (DestSize != SourceSize) {
>
> Modified: cfe/trunk/test/SemaCXX/builtin-bit-cast.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/builtin-bit-cast.cpp?rev=368600&r1=368599&r2=368600&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/SemaCXX/builtin-bit-cast.cpp (original)
> +++ cfe/trunk/test/SemaCXX/builtin-bit-cast.cpp Mon Aug 12 11:31:27 2019
> @@ -37,3 +37,12 @@ constexpr unsigned long ul = __builtin_b
>
> // expected-error at +1 {{__builtin_bit_cast destination type must be
> trivially copyable}}
> constexpr long us = __builtin_bit_cast(unsigned long &, 0L);
> +
> +namespace PR42936 {
> +template <class T> struct S { int m; };
> +
> +extern S<int> extern_decl;
> +
> +int x = __builtin_bit_cast(int, extern_decl);
> +S<char> y = __builtin_bit_cast(S<char>, 0);
> +}
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190812/4cc4c038/attachment.html>
More information about the cfe-commits
mailing list