This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[lto] Use num_parm_types and its friends in coerce_new_type.
- From: Kazu Hirata <kazu at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Fri, 4 Aug 2006 22:00:59 -0700
- Subject: [lto] Use num_parm_types and its friends in coerce_new_type.
Hi,
Tested on x86_64-pc-linux-gnu. Committed to the LTO branch as
obvious.
Kazu Hirata
2006-08-05 Kazu Hirata <kazu@codesourcery.com>
* decl2.c (coerce_new_type): Use num_parm_types and its
friends.
Index: cp/decl2.c
===================================================================
--- cp/decl2.c (revision 115941)
+++ cp/decl2.c (working copy)
@@ -1144,7 +1144,9 @@ tree
coerce_new_type (tree type)
{
int e = 0;
- tree args = TYPE_ARG_TYPES (type);
+ tree parm_types = TYPE_ARG_TYPES (type);
+ int len = num_parm_types (parm_types);
+ int skip = 0;
gcc_assert (TREE_CODE (type) == FUNCTION_TYPE);
@@ -1154,31 +1156,42 @@ coerce_new_type (tree type)
error ("%<operator new%> must return type %qT", ptr_type_node);
}
- if (!args
- || (TREE_VALUE (args) == void_type_node
- && TREE_CHAIN (args) == NULL_TREE)
- || !same_type_p (TREE_VALUE (args), size_type_node))
+ if (len == 0
+ || (len == 1 && nth_parm_type (parm_types, 0) == void_type_node)
+ || !same_type_p (nth_parm_type (parm_types, 0), size_type_node))
{
e = 2;
- if (args
- && (TREE_VALUE (args) != void_type_node
- || TREE_CHAIN (args) != NULL_TREE))
- args = TREE_CHAIN (args);
+ if (len != 0
+ && !(len == 1
+ && nth_parm_type (parm_types, 0) == void_type_node))
+ skip = 1;
pedwarn ("%<operator new%> takes type %<size_t%> (%qT) "
"as first parameter", size_type_node);
}
switch (e)
- {
+ {
case 2:
- args = tree_cons (NULL_TREE, size_type_node, args);
+ {
+ /* Prepend size_type_node to PARM_TYPES. */
+ tree new_parm_types = alloc_parm_types (len - skip + 1);
+ int i;
+
+ *(nth_parm_type_ptr (new_parm_types, 0)) = size_type_node;
+ for (i = 0; i < len - skip; i++)
+ {
+ *(nth_parm_type_ptr (new_parm_types, 1 + i)) =
+ nth_parm_type (parm_types, skip + i);
+ }
+ parm_types = new_parm_types;
+ }
/* Fall through. */
case 1:
type = build_exception_variant
- (build_function_type (ptr_type_node, args),
+ (build_function_type (ptr_type_node, parm_types),
TYPE_RAISES_EXCEPTIONS (type));
/* Fall through. */
default:;
- }
+ }
return type;
}