re PR c++/8332 (strlen/template interaction causes ICE)
authorMark Mitchell <mark@codesourcery.com>
Sun, 1 Dec 2002 17:51:51 +0000 (17:51 +0000)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Sun, 1 Dec 2002 17:51:51 +0000 (17:51 +0000)
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.

* 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.

PR c++/8332
PR c++/8493
* g++.dg/template/strlen1.C: New test.

From-SVN: r59689

13 files changed:
gcc/ChangeLog
gcc/builtin-types.def
gcc/builtins.c
gcc/c-common.c
gcc/c-common.h
gcc/c-format.c
gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/cp/decl2.c
gcc/cp/except.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/template/strlen1.C [new file with mode: 0644]
gcc/tree.h

index 9fdba44187ddb99834bad867ab38bf2b70d92359..5717dea4ee3f076ff37f97a76f8c695156d90948 100644 (file)
@@ -1,3 +1,18 @@
+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  John David Anglin  <dave@hiauly1.hia.nrc.ca>
 
        * cfg.c (dump_flow_info): Use max_reg_num () to determine the largest
index be52392b49b43765c14777390d6a3c056085c325..23b4336c2b32c1e4ca285bf8bf61632599d4afbe 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001 Free Software Foundation, Inc.
+/* Copyright (C) 2001, 2002 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -74,7 +74,7 @@ DEF_PRIMITIVE_TYPE (BT_COMPLEX_LONG_DOUBLE, complex_long_double_type_node)
 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_SIZE, size_type_node)
 DEF_PRIMITIVE_TYPE (BT_STRING, string_type_node)
 DEF_PRIMITIVE_TYPE (BT_CONST_STRING, const_string_type_node)
 
index 7eea0365639a0c2dd2ba6417b6952edb2b579bc8..aa0cfaf8dd19819d877483a5b24b777d032aa5e9 100644 (file)
@@ -4198,8 +4198,13 @@ fold_builtin (exp)
       if (validate_arglist (arglist, POINTER_TYPE, VOID_TYPE))
        {
          tree len = c_strlen (TREE_VALUE (arglist));
-         if (len != 0)
-           return len;
+         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 f32456d455bd021c389056ed8c6c744fd7844e57..35adf760020e316b442f9d189e1f3886dd34062f 100644 (file)
@@ -3090,7 +3090,7 @@ c_sizeof_or_alignof_type (type, op, complain)
      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));
+  value = fold (build1 (NOP_EXPR, size_type_node, value));
   my_friendly_assert (!TYPE_IS_SIZETYPE (TREE_TYPE (value)), 20001021);
   
   return value;
@@ -3141,7 +3141,7 @@ c_alignof_expr (expr)
   else
     return c_alignof (TREE_TYPE (expr));
 
-  return fold (build1 (NOP_EXPR, c_size_type_node, t));
+  return fold (build1 (NOP_EXPR, size_type_node, t));
 }
 \f
 /* Handle C and C++ default attributes.  */
@@ -3284,10 +3284,10 @@ c_common_nodes_and_builtins ()
   /* `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 =
+  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);
+  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 ef04ca8b2e721ede0ca06efa11f64659d4d64c56..1f59ebd7d8292df0d20af7f11ef65babc7fc6e6e 100644 (file)
@@ -131,10 +131,6 @@ enum c_tree_index
     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,
@@ -188,7 +184,6 @@ struct c_common_identifier GTY(())
 #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]
index a8066df523571547073b697a3d816e795cb09094..083e91278f86cd871f79393fd3e63da6ce4b83e0 100644 (file)
@@ -729,7 +729,7 @@ static const format_flag_pair strfmon_flag_pairs[] =
 #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 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 aee593f470d4ee7f21485e900712bdec107a9569..f00d0fb0ff8ff9d6d2223d91b2e048657702ef56 100644 (file)
@@ -1,3 +1,12 @@
+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-11-30  Mark Mitchell  <mark@codesourcery.com>
 
        PR c++/8227
index dbb96eb6a28039334d0428d1ca3c3ea3fb2fcc91..f3ffbf10712a228dd13b22e9e56672005ae0b77e 100644 (file)
@@ -6656,7 +6656,7 @@ cxx_init_decl_processing ()
     ptr_ftype_sizetype 
       = build_function_type (ptr_type_node,
                             tree_cons (NULL_TREE,
-                                       c_size_type_node,
+                                       size_type_node,
                                        void_list_node));
     newtype = build_exception_variant
       (ptr_ftype_sizetype, add_exception_specifier
index 209a15bb2d9acba3a27a6e51ba8965701da92ae1..61efb5832ffc2e25baeac530d4ea22e9a2acfc29 100644 (file)
@@ -1468,17 +1468,17 @@ coerce_new_type (type)
     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))
+      || !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", c_size_type_node);
+      pedwarn ("`operator new' takes type `size_t' (`%T') as first parameter", size_type_node);
     }
   switch (e)
   {
     case 2:
-      args = tree_cons (NULL_TREE, c_size_type_node, args);
+      args = tree_cons (NULL_TREE, size_type_node, args);
       /* FALLTHROUGH */
     case 1:
       type = build_exception_variant
index 5e2ae89dff764b8067a4f3569555998b56934244..848ef512f7693124d61d109bbdcff9115efb18e6 100644 (file)
@@ -503,7 +503,7 @@ do_allocate_exception (type)
   else
     {
       /* Declare void *__cxa_allocate_exception(size_t).  */
-      tree tmp = tree_cons (NULL_TREE, c_size_type_node, void_list_node);
+      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 5574e17a54966c94c43308c5467eb312c9ef9c10..bad7921ffba2d075994d0d9dd2e5a1985a58134e 100644 (file)
@@ -1,5 +1,9 @@
 2002-11-30  Mark Mitchell  <mark@codesourcery.com>
 
+       PR c++/8332
+       PR c++/8493
+       * g++.dg/template/strlen1.C: New test.
+
        PR c++/8227
        * g++.dg/template/ctor2.C: New test.
 
diff --git a/gcc/testsuite/g++.dg/template/strlen1.C b/gcc/testsuite/g++.dg/template/strlen1.C
new file mode 100644 (file)
index 0000000..ddec51d
--- /dev/null
@@ -0,0 +1,9 @@
+template <typename A1>
+void monk2 (A1) {}
+
+unsigned int strlen (const char*);
+
+void monk ()
+{
+  monk2 (strlen (""));
+}
index abe070369ed46d3516b83060acabcb3bd8a6d2ba..a675851003bf1aee8647d88c9fcbf3d46a5004f8 100644 (file)
@@ -1971,6 +1971,7 @@ enum tree_index
   TI_VOID_TYPE,
   TI_PTR_TYPE,
   TI_CONST_PTR_TYPE,
+  TI_SIZE_TYPE,
   TI_PTRDIFF_TYPE,
   TI_VA_LIST_TYPE,
 
@@ -2048,6 +2049,8 @@ extern GTY(()) tree global_trees[TI_MAX];
 #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]