diff options
author | Erik Pilkington <erik.pilkington@gmail.com> | 2019-08-12 18:31:27 +0000 |
---|---|---|
committer | Erik Pilkington <erik.pilkington@gmail.com> | 2019-08-12 18:31:27 +0000 |
commit | 0a223d981e6d57a051c77a65cdee9f7024e1bc35 (patch) | |
tree | f837ce87f925bc9a43774ba8126428b262a1af57 | |
parent | 1308011e1b5c5382281a63dd4191a1784f8d2295 (diff) | |
download | bcm5719-llvm-0a223d981e6d57a051c77a65cdee9f7024e1bc35.tar.gz bcm5719-llvm-0a223d981e6d57a051c77a65cdee9f7024e1bc35.zip |
[Sema] Require a complete type for __builtin_bit_cast operands
Fixes llvm.org/PR42936
llvm-svn: 368600
-rw-r--r-- | clang/lib/Sema/SemaCast.cpp | 8 | ||||
-rw-r--r-- | clang/test/SemaCXX/builtin-bit-cast.cpp | 9 |
2 files changed, 17 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp index f184eda2f27..7a1d52ad4ea 100644 --- a/clang/lib/Sema/SemaCast.cpp +++ b/clang/lib/Sema/SemaCast.cpp @@ -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)) { + SrcExpr = ExprError(); + return; + } + CharUnits DestSize = Self.Context.getTypeSizeInChars(DestType); CharUnits SourceSize = Self.Context.getTypeSizeInChars(SrcType); if (DestSize != SourceSize) { diff --git a/clang/test/SemaCXX/builtin-bit-cast.cpp b/clang/test/SemaCXX/builtin-bit-cast.cpp index 3dddadc5617..87919d9d9d2 100644 --- a/clang/test/SemaCXX/builtin-bit-cast.cpp +++ b/clang/test/SemaCXX/builtin-bit-cast.cpp @@ -37,3 +37,12 @@ constexpr unsigned long ul = __builtin_bit_cast(unsigned long, not_trivially_cop // expected-error@+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); +} |