[clang] 506406c - [Sema][SVE] Reject "new" with sizeless types
Richard Sandiford via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 17 05:24:21 PDT 2020
Author: Richard Sandiford
Date: 2020-03-17T12:23:46Z
New Revision: 506406c4d59267497d4ac358b49e32b4d2f72119
URL: https://github.com/llvm/llvm-project/commit/506406c4d59267497d4ac358b49e32b4d2f72119
DIFF: https://github.com/llvm/llvm-project/commit/506406c4d59267497d4ac358b49e32b4d2f72119.diff
LOG: [Sema][SVE] Reject "new" 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.
Differential Revision: https://reviews.llvm.org/D76218
Added:
Modified:
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaExprCXX.cpp
clang/test/SemaCXX/sizeless-1.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 3e0591bc2cf0..77df05fbaf05 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6897,8 +6897,8 @@ def err_array_new_needs_size : Error<
"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<
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 5969b5abd399..f50e5ea02c86 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -2340,7 +2340,8 @@ bool Sema::CheckAllocatedType(QualType AllocType, SourceLocation Loc,
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))
diff --git a/clang/test/SemaCXX/sizeless-1.cpp b/clang/test/SemaCXX/sizeless-1.cpp
index 3b0b73a26eed..40fa436dd1de 100644
--- a/clang/test/SemaCXX/sizeless-1.cpp
+++ b/clang/test/SemaCXX/sizeless-1.cpp
@@ -411,6 +411,15 @@ void cxx_only(int sel) {
} 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();
More information about the cfe-commits
mailing list