OSDN Git Service

Target Hook to issue diagnostics for AltiVec argument to funtion
authorfjahanian <fjahanian@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 8 Mar 2005 21:01:47 +0000 (21:01 +0000)
committerfjahanian <fjahanian@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 8 Mar 2005 21:01:47 +0000 (21:01 +0000)
with unknown prototype.
OKed by Mark Mitchel.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@96124 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/c-typeck.c
gcc/config/rs6000/rs6000.c
gcc/doc/tm.texi
gcc/target-def.h
gcc/target.h
gcc/targhooks.c
gcc/targhooks.h
gcc/testsuite/gcc.dg/altivec-21.c [new file with mode: 0644]

index 4999fa4..ddfe3a6 100644 (file)
@@ -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,
index 24bd079..9c94b03 100644 (file)
@@ -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);
index f668b12..9b9d3ae 100644 (file)
@@ -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"
index 81b664e..0a67353 100644 (file)
@@ -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
index 499d37f..01759db 100644 (file)
@@ -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                      \
    }
 
 
index 0a54c6f..914d6de 100644 (file)
@@ -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.  */
index 5607093..e31f857 100644 (file)
@@ -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;
+}
index 1965bbd..ae6cf53 100644 (file)
@@ -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 (file)
index 0000000..d81bb31
--- /dev/null
@@ -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__ */
+}
+