[PATCH] D76218: [Sema][SVE] Reject "new" with sizeless types
Richard Sandiford via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 16 03:10:02 PDT 2020
rsandifo-arm created this revision.
rsandifo-arm added reviewers: sdesmalen, efriedma, rovka, rjmccall.
Herald added subscribers: cfe-commits, psnobl, rkruppe, tschuett.
Herald added a reviewer: rengolin.
Herald added a project: clang.
rsandifo-arm added a parent revision: D76090: [Sema][SVE] Don't allow sizeless types to be caught.
rsandifo-arm added a child revision: D76219: [Sema][SVE] Reject "delete" with sizeless types.
new-expressions for a type T require sizeof(T) to be computable,
so the SVE ACLE does not allow them for sizeless types. At the moment:
auto f() { return new __SVInt8_t; }
creates a call to operator new with a zero size:
%call = call noalias nonnull i8* @_Znwm(i64 0)
This patch reports an appropriate error instead.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D76218
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
@@ -411,6 +411,15 @@
} catch (svint8_t &) { // expected-error {{cannot catch reference to sizeless type 'svint8_t'}}
}
+ new svint8_t; // expected-error {{allocation of sizeless type 'svint8_t'}}
+ new svint8_t(); // expected-error {{allocation of sizeless type 'svint8_t'}}
+ new svint8_t[10]; // expected-error {{allocation of sizeless type 'svint8_t'}}
+ new svint8_t *;
+
+ new (global_int8_ptr) svint8_t; // expected-error {{allocation of sizeless type 'svint8_t'}}
+ new (global_int8_ptr) svint8_t(); // expected-error {{allocation of sizeless type 'svint8_t'}}
+ new (global_int8_ptr) svint8_t[10]; // expected-error {{allocation of sizeless type 'svint8_t'}}
+
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
@@ -2340,7 +2340,8 @@
return Diag(Loc, diag::err_bad_new_type)
<< AllocType << 1 << R;
else if (!AllocType->isDependentType() &&
- RequireCompleteType(Loc, AllocType, diag::err_new_incomplete_type,R))
+ RequireCompleteSizedType(
+ Loc, AllocType, diag::err_new_incomplete_or_sizeless_type, R))
return true;
else if (RequireNonAbstractType(Loc, AllocType,
diag::err_allocation_of_abstract_type))
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6897,8 +6897,8 @@
"array size must be specified in new expression with no initializer">;
def err_bad_new_type : Error<
"cannot allocate %select{function|reference}1 type %0 with new">;
-def err_new_incomplete_type : Error<
- "allocation of incomplete type %0">;
+def err_new_incomplete_or_sizeless_type : Error<
+ "allocation of %select{incomplete|sizeless}0 type %1">;
def err_new_array_nonconst : Error<
"only the first dimension of an allocated array may have dynamic size">;
def err_new_array_size_unknown_from_init : Error<
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76218.250500.patch
Type: text/x-patch
Size: 2511 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200316/d106f7e5/attachment.bin>
More information about the cfe-commits
mailing list