This revision was automatically updated to reflect the committed changes. Closed by commit rGc47f971694be: [Sema][SVE] Don't allow sizeless objects to be thrown (authored by rsandifo-arm).
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 @@ -7120,6 +7120,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>;
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 @@ -7120,6 +7120,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>;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits