<div dir="ltr"><div dir="ltr">On Mon, 12 Aug 2019 at 11:30, Erik Pilkington via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Author: epilk<br>
Date: Mon Aug 12 11:31:27 2019<br>
New Revision: 368600<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=368600&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=368600&view=rev</a><br>
Log:<br>
[Sema] Require a complete type for __builtin_bit_cast operands<br>
<br>
Fixes <a href="http://llvm.org/PR42936" rel="noreferrer" target="_blank">llvm.org/PR42936</a><br>
<br>
Modified:<br>
cfe/trunk/lib/Sema/SemaCast.cpp<br>
cfe/trunk/test/SemaCXX/builtin-bit-cast.cpp<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaCast.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCast.cpp?rev=368600&r1=368599&r2=368600&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCast.cpp?rev=368600&r1=368599&r2=368600&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaCast.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaCast.cpp Mon Aug 12 11:31:27 2019<br>
@@ -2803,6 +2803,14 @@ void CastOperation::CheckBuiltinBitCast(<br>
SrcExpr = Self.CreateMaterializeTemporaryExpr(SrcType, SrcExpr.get(),<br>
/*IsLValueReference=*/false);<br>
<br>
+ if (Self.RequireCompleteType(OpRange.getBegin(), DestType,<br>
+ diag::err_typecheck_cast_to_incomplete) ||<br>
+ Self.RequireCompleteType(OpRange.getBegin(), SrcType,<br>
+ diag::err_incomplete_type)) {<br></blockquote><div><br></div><div>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.</div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+ SrcExpr = ExprError();<br>
+ return;<br>
+ }<br>
+<br>
CharUnits DestSize = Self.Context.getTypeSizeInChars(DestType);<br>
CharUnits SourceSize = Self.Context.getTypeSizeInChars(SrcType);<br>
if (DestSize != SourceSize) {<br>
<br>
Modified: cfe/trunk/test/SemaCXX/builtin-bit-cast.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/builtin-bit-cast.cpp?rev=368600&r1=368599&r2=368600&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/builtin-bit-cast.cpp?rev=368600&r1=368599&r2=368600&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/SemaCXX/builtin-bit-cast.cpp (original)<br>
+++ cfe/trunk/test/SemaCXX/builtin-bit-cast.cpp Mon Aug 12 11:31:27 2019<br>
@@ -37,3 +37,12 @@ constexpr unsigned long ul = __builtin_b<br>
<br>
// expected-error@+1 {{__builtin_bit_cast destination type must be trivially copyable}}<br>
constexpr long us = __builtin_bit_cast(unsigned long &, 0L);<br>
+<br>
+namespace PR42936 {<br>
+template <class T> struct S { int m; };<br>
+<br>
+extern S<int> extern_decl;<br>
+<br>
+int x = __builtin_bit_cast(int, extern_decl);<br>
+S<char> y = __builtin_bit_cast(S<char>, 0);<br>
+}<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div></div>