aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorRichard Sandiford <richard.sandiford@arm.com>2019-09-27 08:39:16 +0000
committerRichard Sandiford <rsandifo@gcc.gnu.org>2019-09-27 08:39:16 +0000
commitc6447c2014b76b5c077a07712a7f0b0aaa2e14d4 (patch)
tree9921a7089999908bc2646d4e3529ed4eeef6495a /gcc/cp
parent18908a56e18f15f84a91a4529923dd0878b2294f (diff)
downloadgcc-c6447c2014b76b5c077a07712a7f0b0aaa2e14d4.zip
gcc-c6447c2014b76b5c077a07712a7f0b0aaa2e14d4.tar.gz
gcc-c6447c2014b76b5c077a07712a7f0b0aaa2e14d4.tar.bz2
[C][C++] Allow targets to check calls to BUILT_IN_MD functions
For SVE, we'd like the frontends to check calls to target-specific built-in functions in the same way that they already do for "normal" builtins. This patch adds a target hook for that and extends check_builtin_function_arguments accordingly. A slight complication is that when TARGET_RESOLVE_OVERLOADED_BUILTIN has resolved an overload, it can use build_function_call_vec to build the call to the underlying non-overloaded function decl. This in turn coerces the arguments to the function type and then calls check_builtin_function_arguments to check the final call. If the target does find a problem in this final call, it can be useful to refer to the original overloaded function decl in diagnostics, since that's what the user wrote. The patch therefore passes the original decl as a final optional parameter to build_function_call_vec. 2019-09-27 Richard Sandiford <richard.sandiford@arm.com> gcc/ * target.def (check_builtin_call): New target hook. * doc/tm.texi.in (TARGET_CHECK_BUILTIN_CALL): New @hook. * doc/tm.texi: Regenerate. gcc/c-family/ * c-common.h (build_function_call_vec): Take the original function decl as an optional final parameter. (check_builtin_function_arguments): Take the original function decl. * c-common.c (check_builtin_function_arguments): Likewise. Handle all built-in functions, not just BUILT_IN_NORMAL ones. Use targetm.check_builtin_call to check BUILT_IN_MD functions. gcc/c/ * c-typeck.c (build_function_call_vec): Take the original function decl as an optional final parameter. Pass all built-in calls to check_builtin_function_arguments. gcc/cp/ * cp-tree.h (build_cxx_call): Take the original function decl as an optional final parameter. (cp_build_function_call_vec): Likewise. * call.c (build_cxx_call): Likewise. Pass all built-in calls to check_builtin_function_arguments. * typeck.c (build_function_call_vec): Take the original function decl as an optional final parameter and pass it to cp_build_function_call_vec. (cp_build_function_call_vec): Take the original function decl as an optional final parameter and pass it to build_cxx_call. From-SVN: r276176
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/ChangeLog13
-rw-r--r--gcc/cp/call.c10
-rw-r--r--gcc/cp/cp-tree.h6
-rw-r--r--gcc/cp/typeck.c16
4 files changed, 33 insertions, 12 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 1d30cef..3a3ef9e 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,16 @@
+2019-09-27 Richard Sandiford <richard.sandiford@arm.com>
+
+ * cp-tree.h (build_cxx_call): Take the original function decl
+ as an optional final parameter.
+ (cp_build_function_call_vec): Likewise.
+ * call.c (build_cxx_call): Likewise. Pass all built-in calls to
+ check_builtin_function_arguments.
+ * typeck.c (build_function_call_vec): Take the original function
+ decl as an optional final parameter and pass it to
+ cp_build_function_call_vec.
+ (cp_build_function_call_vec): Take the original function
+ decl as an optional final parameter and pass it to build_cxx_call.
+
2019-09-25 Marek Polacek <polacek@redhat.com>
PR c++/91877 - ICE with converting member of packed struct.
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 45b984e..5ccf3b8 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -9105,12 +9105,14 @@ maybe_warn_class_memaccess (location_t loc, tree fndecl,
}
/* Build and return a call to FN, using NARGS arguments in ARGARRAY.
+ If FN is the result of resolving an overloaded target built-in,
+ ORIG_FNDECL is the original function decl, otherwise it is null.
This function performs no overload resolution, conversion, or other
high-level operations. */
tree
build_cxx_call (tree fn, int nargs, tree *argarray,
- tsubst_flags_t complain)
+ tsubst_flags_t complain, tree orig_fndecl)
{
tree fndecl;
@@ -9120,11 +9122,13 @@ build_cxx_call (tree fn, int nargs, tree *argarray,
SET_EXPR_LOCATION (fn, loc);
fndecl = get_callee_fndecl (fn);
+ if (!orig_fndecl)
+ orig_fndecl = fndecl;
/* Check that arguments to builtin functions match the expectations. */
if (fndecl
&& !processing_template_decl
- && fndecl_built_in_p (fndecl, BUILT_IN_NORMAL))
+ && fndecl_built_in_p (fndecl))
{
int i;
@@ -9134,7 +9138,7 @@ build_cxx_call (tree fn, int nargs, tree *argarray,
argarray[i] = maybe_constant_value (argarray[i]);
if (!check_builtin_function_arguments (EXPR_LOCATION (fn), vNULL, fndecl,
- nargs, argarray))
+ orig_fndecl, nargs, argarray))
return error_mark_node;
}
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 9c0f394..8fc3fc1 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -6257,7 +6257,8 @@ extern tree perform_direct_initialization_if_possible (tree, tree, bool,
tsubst_flags_t);
extern tree in_charge_arg_for_name (tree);
extern tree build_cxx_call (tree, int, tree *,
- tsubst_flags_t);
+ tsubst_flags_t,
+ tree = NULL_TREE);
extern bool is_std_init_list (tree);
extern bool is_list_ctor (tree);
extern void validate_conversion_obstack (void);
@@ -7391,7 +7392,8 @@ extern tree get_member_function_from_ptrfunc (tree *, tree, tsubst_flags_t);
extern tree cp_build_function_call_nary (tree, tsubst_flags_t, ...)
ATTRIBUTE_SENTINEL;
extern tree cp_build_function_call_vec (tree, vec<tree, va_gc> **,
- tsubst_flags_t);
+ tsubst_flags_t,
+ tree = NULL_TREE);
extern tree build_x_binary_op (const op_location_t &,
enum tree_code, tree,
enum tree_code, tree,
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index f427c4f..d549450 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -3773,11 +3773,11 @@ build_function_call (location_t /*loc*/,
tree
build_function_call_vec (location_t /*loc*/, vec<location_t> /*arg_loc*/,
tree function, vec<tree, va_gc> *params,
- vec<tree, va_gc> * /*origtypes*/)
+ vec<tree, va_gc> * /*origtypes*/, tree orig_function)
{
vec<tree, va_gc> *orig_params = params;
tree ret = cp_build_function_call_vec (function, &params,
- tf_warning_or_error);
+ tf_warning_or_error, orig_function);
/* cp_build_function_call_vec can reallocate PARAMS by adding
default arguments. That should never happen here. Verify
@@ -3818,13 +3818,15 @@ cp_build_function_call_nary (tree function, tsubst_flags_t complain, ...)
return ret;
}
-/* Build a function call using a vector of arguments. PARAMS may be
- NULL if there are no parameters. This changes the contents of
- PARAMS. */
+/* Build a function call using a vector of arguments.
+ If FUNCTION is the result of resolving an overloaded target built-in,
+ ORIG_FNDECL is the original function decl, otherwise it is null.
+ PARAMS may be NULL if there are no parameters. This changes the
+ contents of PARAMS. */
tree
cp_build_function_call_vec (tree function, vec<tree, va_gc> **params,
- tsubst_flags_t complain)
+ tsubst_flags_t complain, tree orig_fndecl)
{
tree fntype, fndecl;
int is_method;
@@ -3949,7 +3951,7 @@ cp_build_function_call_vec (tree function, vec<tree, va_gc> **params,
bool warned_p = check_function_arguments (input_location, fndecl, fntype,
nargs, argarray, NULL);
- ret = build_cxx_call (function, nargs, argarray, complain);
+ ret = build_cxx_call (function, nargs, argarray, complain, orig_fndecl);
if (warned_p)
{