summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfjahanian <fjahanian@138bc75d-0d04-0410-961f-82ee72b054a4>2005-03-08 21:01:47 +0000
committerfjahanian <fjahanian@138bc75d-0d04-0410-961f-82ee72b054a4>2005-03-08 21:01:47 +0000
commit10fda9eb3b1584ac33daaf1f7cdcc950f836adbf (patch)
tree8e733d5b7a3ce8d9267f4f50ab0923c79cbd51f2
parent90d092db65eb841cd897c8c1e59cd624e34b765c (diff)
downloadgcc-10fda9eb3b1584ac33daaf1f7cdcc950f836adbf.tar.gz
Target Hook to issue diagnostics for AltiVec argument to funtion
with unknown prototype. OKed by Mark Mitchel. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@96124 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog15
-rw-r--r--gcc/c-typeck.c7
-rw-r--r--gcc/config/rs6000/rs6000.c19
-rw-r--r--gcc/doc/tm.texi6
-rw-r--r--gcc/target-def.h7
-rw-r--r--gcc/target.h5
-rw-r--r--gcc/targhooks.c9
-rw-r--r--gcc/targhooks.h2
-rw-r--r--gcc/testsuite/gcc.dg/altivec-21.c17
9 files changed, 86 insertions, 1 deletions
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 <fjahanian@apple.com>
+
+ * 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 <kazu@cs.umass.edu>
* 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 <altivec.h>
+
+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__ */
+}
+