forked from OSchip/llvm-project
[Sema][SVE] Don't allow sizeless objects to be thrown
Summary: The same rules for throwing and catching incomplete types also apply to sizeless types. This patch enforces that for throw statements. It also make sure that we use "sizeless type" rather "incomplete type" in the associated message. (Both are correct, but "sizeless type" is more specific and hopefully more user-friendly.) The SVE ACLE simply extends the rule for incomplete types to sizeless types. However, throwing pointers to sizeless types should not pose any real difficulty, so as an extension, the clang implementation allows that. Reviewers: sdesmalen, efriedma, rovka, rjmccall Subscribers: tschuett, rkruppe, psnobl, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D76088
This commit is contained in:
parent
f5e0f8b10a
commit
c47f971694
|
@ -7120,6 +7120,8 @@ def err_throw_incomplete : Error<
|
|||
"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>;
|
||||
|
|
|
@ -956,6 +956,11 @@ bool Sema::CheckCXXThrowOperand(SourceLocation ThrowLoc,
|
|||
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;
|
||||
|
|
|
@ -395,6 +395,9 @@ void cxx_only(int sel) {
|
|||
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();
|
||||
|
|
Loading…
Reference in New Issue