[PATCH] D76088: [Sema][SVE] Don't allow sizeless objects to be thrown
Richard Sandiford via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 12 15:12:13 PDT 2020
rsandifo-arm updated this revision to Diff 250066.
rsandifo-arm added a comment.
Allow pointers to sizeless types to be thrown.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D76088/new/
https://reviews.llvm.org/D76088
Files:
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaExprCXX.cpp
clang/test/SemaCXX/sizeless-1.cpp
Index: clang/test/SemaCXX/sizeless-1.cpp
===================================================================
--- clang/test/SemaCXX/sizeless-1.cpp
+++ clang/test/SemaCXX/sizeless-1.cpp
@@ -395,6 +395,9 @@
local_int16 = static_cast<svint16_t>(local_int8); // expected-error {{static_cast from 'svint8_t' (aka '__SVInt8_t') to 'svint16_t' (aka '__SVInt16_t') is not allowed}}
sel = static_cast<int>(local_int8); // expected-error {{static_cast from 'svint8_t' (aka '__SVInt8_t') to 'int' is not allowed}}
+ throw local_int8; // expected-error {{cannot throw object of sizeless type 'svint8_t'}}
+ throw global_int8_ptr;
+
local_int8.~__SVInt8_t(); // expected-error {{object expression of non-scalar type 'svint8_t' (aka '__SVInt8_t') cannot be used in a pseudo-destructor expression}}
(void)svint8_t();
Index: clang/lib/Sema/SemaExprCXX.cpp
===================================================================
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -956,6 +956,11 @@
E->getSourceRange()))
return true;
+ if (!isPointer && Ty->isSizelessType()) {
+ Diag(ThrowLoc, diag::err_throw_sizeless) << Ty << E->getSourceRange();
+ return true;
+ }
+
if (RequireNonAbstractType(ThrowLoc, ExceptionObjectTy,
diag::err_throw_abstract_type, E))
return true;
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7117,6 +7117,8 @@
"cannot throw object of incomplete type %0">;
def err_throw_incomplete_ptr : Error<
"cannot throw pointer to object of incomplete type %0">;
+def err_throw_sizeless : Error<
+ "cannot throw object of sizeless type %0">;
def warn_throw_underaligned_obj : Warning<
"underaligned exception object thrown">,
InGroup<UnderalignedExceptionObject>;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76088.250066.patch
Type: text/x-patch
Size: 2015 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200312/c178058b/attachment.bin>
More information about the cfe-commits
mailing list