aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/decl.c
diff options
context:
space:
mode:
authorRichard Sandiford <richard.sandiford@arm.com>2019-12-06 18:22:24 +0000
committerRichard Sandiford <rsandifo@gcc.gnu.org>2019-12-06 18:22:24 +0000
commit02a32ab4a6175f377a4b6f53159c6aae9a24a7cc (patch)
treeedbc148180bd6cb0282ec8b9b5fd5c124f0cdfd4 /gcc/cp/decl.c
parent1e8f5d49d791018310b9df540a3c19f7330351f6 (diff)
downloadgcc-02a32ab4a6175f377a4b6f53159c6aae9a24a7cc.zip
gcc-02a32ab4a6175f377a4b6f53159c6aae9a24a7cc.tar.gz
gcc-02a32ab4a6175f377a4b6f53159c6aae9a24a7cc.tar.bz2
[C++] Pass type uses through the verify_type_context hook
This patch makes the C++ frontend work with the verify_type_context hook. We need some new type contexts for features that don't exist in C, but otherwise the patch is very similar to the C one. TCTX_CAPTURE_BY_COPY could really be treated as an instance of TCTX_FIELD, but the error message is better if we split it out. 2019-12-06 Richard Sandiford <richard.sandiford@arm.com> gcc/ * target.h (TCTX_ALLOCATION, TCTX_DEALLOCATION, TCTX_EXCEPTIONS) (TCTX_CAPTURE_BY_COPY): New type_context_kinds. * config/aarch64/aarch64-sve-builtins.cc (verify_type_context): Handle them. gcc/cp/ * decl.c (start_decl_1): Use verify_type_context to check whether the target allows variables of a particular type to have static or thread-local storage duration. (check_array_initializer): Use verify_type_context to check whether the target allows a particular type to be used as an array element. (create_array_type_for_decl): Likewise. (cp_finish_decl): Use verify_type_context to check whether the target allows static member variables of a particular type. (grokdeclarator): Likewise. Also use verify_type_context to check whether the target allows non-static member variables of a particular type. * except.c: Include target.h. (is_admissible_throw_operand_or_catch_parameter): Use verify_type_context to check whether the target allows particular types to be thrown and caught. * typeck2.c (add_exception_specifier): Likewise. * init.c (build_new_1): Use verify_type_context to check whether the target allows particular types to be dynamically allocated. (build_vec_delete_1, build_delete): Use verify_type_context to check whether the target allows particular types to be deleted. * lambda.c (add_capture): Use verify_type_context to check whether the target allows particular types to be captured by copy. * pt.c: Include target.h. (instantiate_class_template_1): Use verify_type_context to check whether the target allows non-static member variables of a particular type. * typeck.c (cxx_alignof_expr): Use verify_type_context to check whether the target allows the alignment of a particular type to be measured. (pointer_diff, cp_build_unary_op): Use verify_type_context to check whether the target allows arithmetic involving pointers to particular types. gcc/testsuite/ * g++.dg/ext/sve-sizeless-1.C: New test. * g++.dg/ext/sve-sizeless-2.C: Likewise. From-SVN: r279058
Diffstat (limited to 'gcc/cp/decl.c')
-rw-r--r--gcc/cp/decl.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index a44f172..b5d689a 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -5470,6 +5470,13 @@ start_decl_1 (tree decl, bool initialized)
cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
}
+ if (is_global_var (decl))
+ {
+ type_context_kind context = (DECL_THREAD_LOCAL_P (decl)
+ ? TCTX_THREAD_STORAGE
+ : TCTX_STATIC_STORAGE);
+ verify_type_context (input_location, context, TREE_TYPE (decl));
+ }
if (initialized)
/* Is it valid for this decl to have an initializer at all? */
{
@@ -6535,6 +6542,11 @@ check_array_initializer (tree decl, tree type, tree init)
error ("elements of array %q#T have incomplete type", type);
return true;
}
+
+ location_t loc = (decl ? location_of (decl) : input_location);
+ if (!verify_type_context (loc, TCTX_ARRAY_ELEMENT, element_type))
+ return true;
+
/* A compound literal can't have variable size. */
if (init && !decl
&& ((COMPLETE_TYPE_P (type) && !TREE_CONSTANT (TYPE_SIZE (type)))
@@ -7482,6 +7494,8 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
if (VAR_P (decl)
&& DECL_CLASS_SCOPE_P (decl)
+ && verify_type_context (DECL_SOURCE_LOCATION (decl),
+ TCTX_STATIC_STORAGE, type)
&& DECL_INITIALIZED_IN_CLASS_P (decl))
check_static_variable_definition (decl, type);
@@ -10550,6 +10564,10 @@ create_array_type_for_decl (tree name, tree type, tree size, location_t loc)
break;
}
+ if (!verify_type_context (name ? loc : input_location,
+ TCTX_ARRAY_ELEMENT, type))
+ return error_mark_node;
+
/* [dcl.array]
The constant expressions that specify the bounds of the arrays
@@ -13254,6 +13272,14 @@ grokdeclarator (const cp_declarator *declarator,
decl = NULL_TREE;
}
}
+ else if (!verify_type_context (input_location,
+ staticp
+ ? TCTX_STATIC_STORAGE
+ : TCTX_FIELD, type))
+ {
+ type = error_mark_node;
+ decl = NULL_TREE;
+ }
else
{
if (friendp)