From 4d3e6fae4dd35a70c3b63fad8e02b6d4b4b70002 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Tue, 8 Mar 2005 21:01:47 +0000 Subject: [PATCH] Target Hook to issue diagnostics for AltiVec argument to funtion with unknown prototype. Target Hook to issue diagnostics for AltiVec argument to funtion with unknown prototype. OKed by Mark Mitchel. From-SVN: r96124 --- gcc/ChangeLog | 15 +++++++++++++++ gcc/c-typeck.c | 7 +++++++ gcc/config/rs6000/rs6000.c | 19 +++++++++++++++++++ gcc/doc/tm.texi | 6 ++++++ gcc/target-def.h | 7 ++++++- gcc/target.h | 5 +++++ gcc/targhooks.c | 9 +++++++++ gcc/targhooks.h | 2 ++ gcc/testsuite/gcc.dg/altivec-21.c | 17 +++++++++++++++++ 9 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/altivec-21.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 4999fa4f75d..ddfe3a603cf 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,18 @@ +2005-03-08 Fariborz Jahanian + + * config/rs6000/rs6000.c (invalid_arg_for_unprototyped_fn): + Define the real function for ppc-darwin. + * c-typeck.c (convert_arguments): Check for target-specific + invalid argument call to unprototyped function. + * target-def.h (TARGET_INVALID_ARG_FOR_UNPROTOTYPED_FN): + New Macro. + * target.h (invalid_arg_for_unprototyped_fn): New field + in struct calls. + * targhooks.c (hook_invalid_arg_for_unprototyped_fn): New + default target hook. + * targhooks.h (hook_invalid_arg_for_unprototyped_fn): + Declare. + 2005-03-08 Kazu Hirata * c-typeck.c (constructor_stack, constructor_range_stack, diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index 24bd0794188..9c94b034b6a 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -2122,6 +2122,7 @@ convert_arguments (tree typelist, tree values, tree function, tree fundecl) tree val = TREE_VALUE (valtail); tree rname = function; int argnum = parmnum + 1; + const char *invalid_func_diag; if (type == void_type_node) { @@ -2273,6 +2274,12 @@ convert_arguments (tree typelist, tree values, tree function, tree fundecl) < TYPE_PRECISION (double_type_node))) /* Convert `float' to `double'. */ result = tree_cons (NULL_TREE, convert (double_type_node, val), result); + else if ((invalid_func_diag = + targetm.calls.invalid_arg_for_unprototyped_fn (typelist, fundecl, val))) + { + error (invalid_func_diag); + return error_mark_node; + } else /* Convert `short' and `char' to full-size `int'. */ result = tree_cons (NULL_TREE, default_conversion (val), result); diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c index f668b12bca0..9b9d3aee249 100644 --- a/gcc/config/rs6000/rs6000.c +++ b/gcc/config/rs6000/rs6000.c @@ -53,6 +53,7 @@ #include "cfglayout.h" #include "sched-int.h" #include "tree-gimple.h" +#include "intl.h" #if TARGET_XCOFF #include "xcoffout.h" /* get declarations of xcoff_*_section_name */ #endif @@ -757,6 +758,7 @@ static bool rs6000_pass_by_reference (CUMULATIVE_ARGS *, enum machine_mode, tree, bool); static int rs6000_arg_partial_bytes (CUMULATIVE_ARGS *, enum machine_mode, tree, bool); +static const char *invalid_arg_for_unprototyped_fn (tree, tree, tree); #if TARGET_MACHO static void macho_branch_islands (void); static void add_compiler_branch_island (tree, tree, int); @@ -1003,6 +1005,9 @@ static const char alt_reg_names[][8] = #undef TARGET_VECTOR_MODE_SUPPORTED_P #define TARGET_VECTOR_MODE_SUPPORTED_P rs6000_vector_mode_supported_p +#undef TARGET_INVALID_ARG_FOR_UNPROTOTYPED_FN +#define TARGET_INVALID_ARG_FOR_UNPROTOTYPED_FN invalid_arg_for_unprototyped_fn + /* MPC604EUM 3.5.2 Weak Consistency between Multiple Processors The PowerPC architecture requires only weak consistency among processors--that is, memory accesses between processors need not be @@ -17504,4 +17509,18 @@ rs6000_vector_mode_supported_p (enum machine_mode mode) return false; } +/* Target hook for invalid_arg_for_unprototyped_fn. */ +static const char * +invalid_arg_for_unprototyped_fn (tree typelist, tree funcdecl, tree val) +{ + return (!rs6000_darwin64_abi + && typelist == 0 + && TREE_CODE (TREE_TYPE (val)) == VECTOR_TYPE + && (funcdecl == NULL_TREE + || (TREE_CODE (funcdecl) == FUNCTION_DECL + && DECL_BUILT_IN_CLASS (funcdecl) != BUILT_IN_MD))) + ? N_("AltiVec argument passed to unprototyped function") + : NULL; +} + #include "gt-rs6000.h" diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index 81b664e1c9a..0a6735387ad 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -9587,6 +9587,12 @@ many recent processors which implement a policy of ``relaxed,'' and ia64. The default is @code{false}. @end deftypefn +@deftypefn {Target Hook} const char *TARGET_INVALID_ARG_FOR_UNPROTOTYPED_FN (tree @var{typelist}, tree @var{funcdecl}, tree @var{val}) +If defined, this macro returns the diagnostic message when it is +illegal to pass argument @var{val} to function @var{funcdecl} +with prototype @var{typelist}. +@end deftypefn + @defmac TARGET_USE_JCR_SECTION This macro determines whether to use the JCR section to register Java classes. By default, TARGET_USE_JCR_SECTION is defined to 1 if both diff --git a/gcc/target-def.h b/gcc/target-def.h index 499d37fb9f2..01759dbe160 100644 --- a/gcc/target-def.h +++ b/gcc/target-def.h @@ -356,6 +356,10 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define TARGET_ENCODE_SECTION_INFO default_encode_section_info #endif +#ifndef TARGET_INVALID_ARG_FOR_UNPROTOTYPED_FN +#define TARGET_INVALID_ARG_FOR_UNPROTOTYPED_FN hook_invalid_arg_for_unprototyped_fn +#endif + #define TARGET_FIXED_CONDITION_CODE_REGS hook_bool_uintp_uintp_false #define TARGET_CC_MODES_COMPATIBLE default_cc_modes_compatible @@ -416,7 +420,8 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. TARGET_SPLIT_COMPLEX_ARG, \ TARGET_MUST_PASS_IN_STACK, \ TARGET_CALLEE_COPIES, \ - TARGET_ARG_PARTIAL_BYTES \ + TARGET_ARG_PARTIAL_BYTES, \ + TARGET_INVALID_ARG_FOR_UNPROTOTYPED_FN \ } diff --git a/gcc/target.h b/gcc/target.h index 0a54c6f7bb4..914d6dee6f2 100644 --- a/gcc/target.h +++ b/gcc/target.h @@ -543,6 +543,11 @@ struct gcc_target in registers; the balance is therefore passed on the stack. */ int (* arg_partial_bytes) (CUMULATIVE_ARGS *ca, enum machine_mode mode, tree type, bool named); + + /* Return the diagnostic message string if function without a prototype + is not allowed for this 'val' argument; NULL otherwise. */ + const char *(*invalid_arg_for_unprototyped_fn) (tree typelist, + tree funcdecl, tree val); } calls; /* Functions specific to the C++ frontend. */ diff --git a/gcc/targhooks.c b/gcc/targhooks.c index 56070931e01..e31f857886c 100644 --- a/gcc/targhooks.c +++ b/gcc/targhooks.c @@ -288,3 +288,12 @@ hook_int_CUMULATIVE_ARGS_mode_tree_bool_0 ( { return 0; } + +const char * +hook_invalid_arg_for_unprototyped_fn ( + tree typelist ATTRIBUTE_UNUSED, + tree funcdecl ATTRIBUTE_UNUSED, + tree val ATTRIBUTE_UNUSED) +{ + return NULL; +} diff --git a/gcc/targhooks.h b/gcc/targhooks.h index 1965bbdb60c..ae6cf53c2a0 100644 --- a/gcc/targhooks.h +++ b/gcc/targhooks.h @@ -58,3 +58,5 @@ extern bool hook_bool_CUMULATIVE_ARGS_mode_tree_bool_true (CUMULATIVE_ARGS *, enum machine_mode, tree, bool); extern int hook_int_CUMULATIVE_ARGS_mode_tree_bool_0 (CUMULATIVE_ARGS *, enum machine_mode, tree, bool); +extern const char *hook_invalid_arg_for_unprototyped_fn + (tree, tree, tree); diff --git a/gcc/testsuite/gcc.dg/altivec-21.c b/gcc/testsuite/gcc.dg/altivec-21.c new file mode 100644 index 00000000000..d81bb310327 --- /dev/null +++ b/gcc/testsuite/gcc.dg/altivec-21.c @@ -0,0 +1,17 @@ +/* { dg-do compile { target powerpc*-*-* } } */ +/* { dg-options "-maltivec" } */ + +#include + +extern void preansi(); + +typedef void (*pvecfunc) (); + +void foo(pvecfunc pvf) { + vector int v = (vector int){1, 2, 3, 4}; +#ifndef __LP64__ + preansi (4, 4.0, v); /* { dg-error "AltiVec argument passed to unprototyped function" } */ + (*pvf) (4, 4.0, v); /* { dg-error "AltiVec argument passed to unprototyped function" } */ +#endif /* __LP64__ */ +} +