This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH: PR8332 and PR8493
- From: Mark Mitchell <mark at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sun, 1 Dec 2002 09:43:56 -0800
- Subject: C++ PATCH: PR8332 and PR8493
- Reply-to: mark at codesourcery dot com
This patch fixes these two PRs. The underlying problem was that the
builtin strlen was returning the (internal) type "sizetype" rather
than C type "size_t". This kind of problem has shown up before;
middle-end hackers should be aware that these two types are not the
same.
Bootstrapped and tested on i686-pc-linux-gnu, applied on the mainline
and on the branch.
--
Mark Mitchell mark@codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com
2002-12-01 Mark Mitchell <mark@codesourcery.com>
PR c++/8332
PR c++/8493
* decl.c (cxx_init_decl_processing): Use size_type_node, not
c_size_type_node.
* decl2.c (coerce_new_type): Likewise.
* except.c (do_allocate_exception): Likewise.
2002-12-01 Mark Mitchell <mark@codesourcery.com>
* builtin-types.def (BT_SIZE): Use size_type_node.
* builtins.c (fold_builtin): Make the builtin strlen returns a
size_t, not a sizetype.
* c-common.c (c_sizeof_or_alignof_type): Use size_type_node, not
c_size_type_node.
(c_alignof_expr): Likewise.
(c_common_nodes_and_builtins): Likewise.
* c-common.h (CTI_C_SIZE_TYPE): Remove.
(c_size_type_node): Likewise.
* c-format.c (T_ST): Use size_type_node, not c_size_type_node.
* tree.h (TI_SIZE_TYPE): New enumeral.
(size_type_node): Likewise.
2002-11-30 Mark Mitchell <mark@codesourcery.com>
PR c++/8332
PR c++/8493
* g++.dg/template/strlen1.C: New test.
Index: builtin-types.def
===================================================================
RCS file: /cvs/gcc/gcc/gcc/builtin-types.def,v
retrieving revision 1.9
diff -c -p -r1.9 builtin-types.def
*** builtin-types.def 17 Sep 2002 01:28:47 -0000 1.9
--- builtin-types.def 1 Dec 2002 17:43:10 -0000
***************
*** 1,4 ****
! /* Copyright (C) 2001 Free Software Foundation, Inc.
This file is part of GCC.
--- 1,4 ----
! /* Copyright (C) 2001, 2002 Free Software Foundation, Inc.
This file is part of GCC.
*************** DEF_PRIMITIVE_TYPE (BT_COMPLEX_LONG_DOUB
*** 74,80 ****
DEF_PRIMITIVE_TYPE (BT_PTR, ptr_type_node)
DEF_PRIMITIVE_TYPE (BT_CONST_PTR, const_ptr_type_node)
DEF_PRIMITIVE_TYPE (BT_PTRMODE, (*lang_hooks.types.type_for_mode)(ptr_mode, 0))
! DEF_PRIMITIVE_TYPE (BT_SIZE, c_size_type_node)
DEF_PRIMITIVE_TYPE (BT_STRING, string_type_node)
DEF_PRIMITIVE_TYPE (BT_CONST_STRING, const_string_type_node)
--- 74,80 ----
DEF_PRIMITIVE_TYPE (BT_PTR, ptr_type_node)
DEF_PRIMITIVE_TYPE (BT_CONST_PTR, const_ptr_type_node)
DEF_PRIMITIVE_TYPE (BT_PTRMODE, (*lang_hooks.types.type_for_mode)(ptr_mode, 0))
! DEF_PRIMITIVE_TYPE (BT_SIZE, size_type_node)
DEF_PRIMITIVE_TYPE (BT_STRING, string_type_node)
DEF_PRIMITIVE_TYPE (BT_CONST_STRING, const_string_type_node)
Index: builtins.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/builtins.c,v
retrieving revision 1.164
diff -c -p -r1.164 builtins.c
*** builtins.c 17 Nov 2002 14:47:07 -0000 1.164
--- builtins.c 1 Dec 2002 17:43:10 -0000
*************** fold_builtin (exp)
*** 4198,4205 ****
if (validate_arglist (arglist, POINTER_TYPE, VOID_TYPE))
{
tree len = c_strlen (TREE_VALUE (arglist));
! if (len != 0)
! return len;
}
break;
--- 4198,4210 ----
if (validate_arglist (arglist, POINTER_TYPE, VOID_TYPE))
{
tree len = c_strlen (TREE_VALUE (arglist));
! if (len)
! {
! /* Convert from the internal "sizetype" type to "size_t". */
! if (size_type_node)
! len = convert (size_type_node, len);
! return len;
! }
}
break;
Index: c-common.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.c,v
retrieving revision 1.391
diff -c -p -r1.391 c-common.c
*** c-common.c 27 Nov 2002 06:13:21 -0000 1.391
--- c-common.c 1 Dec 2002 17:43:11 -0000
*************** c_sizeof_or_alignof_type (type, op, comp
*** 3090,3096 ****
TYPE_IS_SIZETYPE means that certain things (like overflow) will
never happen. However, this node should really have type
`size_t', which is just a typedef for an ordinary integer type. */
! value = fold (build1 (NOP_EXPR, c_size_type_node, value));
my_friendly_assert (!TYPE_IS_SIZETYPE (TREE_TYPE (value)), 20001021);
return value;
--- 3090,3096 ----
TYPE_IS_SIZETYPE means that certain things (like overflow) will
never happen. However, this node should really have type
`size_t', which is just a typedef for an ordinary integer type. */
! value = fold (build1 (NOP_EXPR, size_type_node, value));
my_friendly_assert (!TYPE_IS_SIZETYPE (TREE_TYPE (value)), 20001021);
return value;
*************** c_alignof_expr (expr)
*** 3141,3147 ****
else
return c_alignof (TREE_TYPE (expr));
! return fold (build1 (NOP_EXPR, c_size_type_node, t));
}
/* Handle C and C++ default attributes. */
--- 3141,3147 ----
else
return c_alignof (TREE_TYPE (expr));
! return fold (build1 (NOP_EXPR, size_type_node, t));
}
/* Handle C and C++ default attributes. */
*************** c_common_nodes_and_builtins ()
*** 3284,3293 ****
/* `unsigned long' is the standard type for sizeof.
Note that stddef.h uses `unsigned long',
and this must agree, even if long and int are the same size. */
! c_size_type_node =
TREE_TYPE (identifier_global_value (get_identifier (SIZE_TYPE)));
! signed_size_type_node = c_common_signed_type (c_size_type_node);
! set_sizetype (c_size_type_node);
build_common_tree_nodes_2 (flag_short_double);
--- 3284,3293 ----
/* `unsigned long' is the standard type for sizeof.
Note that stddef.h uses `unsigned long',
and this must agree, even if long and int are the same size. */
! size_type_node =
TREE_TYPE (identifier_global_value (get_identifier (SIZE_TYPE)));
! signed_size_type_node = c_common_signed_type (size_type_node);
! set_sizetype (size_type_node);
build_common_tree_nodes_2 (flag_short_double);
Index: c-common.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.h,v
retrieving revision 1.163
diff -c -p -r1.163 c-common.h
*** c-common.h 26 Sep 2002 22:25:12 -0000 1.163
--- c-common.h 1 Dec 2002 17:43:12 -0000
*************** enum c_tree_index
*** 131,140 ****
CTI_SIGNED_WCHAR_TYPE,
CTI_UNSIGNED_WCHAR_TYPE,
CTI_WINT_TYPE,
- CTI_C_SIZE_TYPE, /* The type used for the size_t typedef and the
- result type of sizeof (an ordinary type without
- TYPE_IS_SIZETYPE set, unlike the internal
- sizetype). */
CTI_SIGNED_SIZE_TYPE, /* For format checking only. */
CTI_UNSIGNED_PTRDIFF_TYPE, /* For format checking only. */
CTI_INTMAX_TYPE,
--- 131,136 ----
*************** struct c_common_identifier GTY(())
*** 188,194 ****
#define signed_wchar_type_node c_global_trees[CTI_SIGNED_WCHAR_TYPE]
#define unsigned_wchar_type_node c_global_trees[CTI_UNSIGNED_WCHAR_TYPE]
#define wint_type_node c_global_trees[CTI_WINT_TYPE]
- #define c_size_type_node c_global_trees[CTI_C_SIZE_TYPE]
#define signed_size_type_node c_global_trees[CTI_SIGNED_SIZE_TYPE]
#define unsigned_ptrdiff_type_node c_global_trees[CTI_UNSIGNED_PTRDIFF_TYPE]
#define intmax_type_node c_global_trees[CTI_INTMAX_TYPE]
--- 184,189 ----
Index: c-format.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-format.c,v
retrieving revision 1.29
diff -c -p -r1.29 c-format.c
*** c-format.c 22 Sep 2002 02:03:15 -0000 1.29
--- c-format.c 1 Dec 2002 17:43:13 -0000
*************** static const format_flag_pair strfmon_fl
*** 729,735 ****
#define T_WI &wint_type_node
#define T94_WI { STD_C94, "wint_t", T_WI }
#define TEX_WI { STD_EXT, "wint_t", T_WI }
! #define T_ST &c_size_type_node
#define T99_ST { STD_C99, "size_t", T_ST }
#define T_SST &signed_size_type_node
#define T99_SST { STD_C99, "signed size_t", T_SST }
--- 729,735 ----
#define T_WI &wint_type_node
#define T94_WI { STD_C94, "wint_t", T_WI }
#define TEX_WI { STD_EXT, "wint_t", T_WI }
! #define T_ST &size_type_node
#define T99_ST { STD_C99, "size_t", T_ST }
#define T_SST &signed_size_type_node
#define T99_SST { STD_C99, "signed size_t", T_SST }
Index: tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.h,v
retrieving revision 1.364
diff -c -p -r1.364 tree.h
*** tree.h 27 Nov 2002 06:13:22 -0000 1.364
--- tree.h 1 Dec 2002 17:43:14 -0000
*************** enum tree_index
*** 1971,1976 ****
--- 1971,1977 ----
TI_VOID_TYPE,
TI_PTR_TYPE,
TI_CONST_PTR_TYPE,
+ TI_SIZE_TYPE,
TI_PTRDIFF_TYPE,
TI_VA_LIST_TYPE,
*************** extern GTY(()) tree global_trees[TI_MAX]
*** 2048,2053 ****
--- 2049,2056 ----
#define ptr_type_node global_trees[TI_PTR_TYPE]
/* The C type `const void *'. */
#define const_ptr_type_node global_trees[TI_CONST_PTR_TYPE]
+ /* The C type `size_t'. */
+ #define size_type_node global_trees[TI_SIZE_TYPE]
#define ptrdiff_type_node global_trees[TI_PTRDIFF_TYPE]
#define va_list_type_node global_trees[TI_VA_LIST_TYPE]
Index: cp/decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.960
diff -c -p -r1.960 decl.c
*** cp/decl.c 27 Nov 2002 01:59:42 -0000 1.960
--- cp/decl.c 1 Dec 2002 17:43:20 -0000
*************** cxx_init_decl_processing ()
*** 6656,6662 ****
ptr_ftype_sizetype
= build_function_type (ptr_type_node,
tree_cons (NULL_TREE,
! c_size_type_node,
void_list_node));
newtype = build_exception_variant
(ptr_ftype_sizetype, add_exception_specifier
--- 6656,6662 ----
ptr_ftype_sizetype
= build_function_type (ptr_type_node,
tree_cons (NULL_TREE,
! size_type_node,
void_list_node));
newtype = build_exception_variant
(ptr_ftype_sizetype, add_exception_specifier
Index: cp/decl2.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl2.c,v
retrieving revision 1.573
diff -c -p -r1.573 decl2.c
*** cp/decl2.c 15 Nov 2002 05:46:34 -0000 1.573
--- cp/decl2.c 1 Dec 2002 17:43:21 -0000
*************** coerce_new_type (type)
*** 1468,1484 ****
e = 1, error ("`operator new' must return type `%T'", ptr_type_node);
if (!args || args == void_list_node
! || !same_type_p (TREE_VALUE (args), c_size_type_node))
{
e = 2;
if (args && args != void_list_node)
args = TREE_CHAIN (args);
! pedwarn ("`operator new' takes type `size_t' (`%T') as first parameter", c_size_type_node);
}
switch (e)
{
case 2:
! args = tree_cons (NULL_TREE, c_size_type_node, args);
/* FALLTHROUGH */
case 1:
type = build_exception_variant
--- 1468,1484 ----
e = 1, error ("`operator new' must return type `%T'", ptr_type_node);
if (!args || args == void_list_node
! || !same_type_p (TREE_VALUE (args), size_type_node))
{
e = 2;
if (args && args != void_list_node)
args = TREE_CHAIN (args);
! pedwarn ("`operator new' takes type `size_t' (`%T') as first parameter", size_type_node);
}
switch (e)
{
case 2:
! args = tree_cons (NULL_TREE, size_type_node, args);
/* FALLTHROUGH */
case 1:
type = build_exception_variant
Index: cp/except.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/except.c,v
retrieving revision 1.147
diff -c -p -r1.147 except.c
*** cp/except.c 31 Oct 2002 21:38:39 -0000 1.147
--- cp/except.c 1 Dec 2002 17:43:21 -0000
*************** do_allocate_exception (type)
*** 503,509 ****
else
{
/* Declare void *__cxa_allocate_exception(size_t). */
! tree tmp = tree_cons (NULL_TREE, c_size_type_node, void_list_node);
fn = push_library_fn (fn, build_function_type (ptr_type_node, tmp));
}
--- 503,509 ----
else
{
/* Declare void *__cxa_allocate_exception(size_t). */
! tree tmp = tree_cons (NULL_TREE, size_type_node, void_list_node);
fn = push_library_fn (fn, build_function_type (ptr_type_node, tmp));
}
Index: testsuite/g++.dg/template/strlen1.C
===================================================================
RCS file: testsuite/g++.dg/template/strlen1.C
diff -N testsuite/g++.dg/template/strlen1.C
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/template/strlen1.C 1 Dec 2002 17:43:24 -0000
***************
*** 0 ****
--- 1,9 ----
+ template <typename A1>
+ void monk2 (A1) {}
+
+ unsigned int strlen (const char*);
+
+ void monk ()
+ {
+ monk2 (strlen (""));
+ }