aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2005-03-08 21:01:47 +0000
committerFariborz Jahanian <fjahanian@gcc.gnu.org>2005-03-08 21:01:47 +0000
commit4d3e6fae4dd35a70c3b63fad8e02b6d4b4b70002 (patch)
tree8e733d5b7a3ce8d9267f4f50ab0923c79cbd51f2
parent2470e6670af2f53985d726d89c4c3e52e8d7e0b2 (diff)
downloadgcc-4d3e6fae4dd35a70c3b63fad8e02b6d4b4b70002.zip
gcc-4d3e6fae4dd35a70c3b63fad8e02b6d4b4b70002.tar.gz
gcc-4d3e6fae4dd35a70c3b63fad8e02b6d4b4b70002.tar.bz2
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
-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 4999fa4..ddfe3a6 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 24bd079..9c94b03 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 f668b12..9b9d3ae 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 81b664e..0a67353 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 499d37f..01759db 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 0a54c6f..914d6de 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 5607093..e31f857 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 1965bbd..ae6cf53 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 0000000..d81bb31
--- /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__ */
+}
+