]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/8332 (strlen/template interaction causes ICE)
authorMark Mitchell <mark@codesourcery.com>
Sun, 1 Dec 2002 18:19:14 +0000 (18:19 +0000)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Sun, 1 Dec 2002 18:19:14 +0000 (18:19 +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.
* typeck.c (c_sizeof): Likewise.
(c_sizeof_nowarn): 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_alignof): 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: r59692

14 files changed:
gcc/ChangeLog
gcc/builtin-types.def
gcc/builtins.c
gcc/c-common.c
gcc/c-common.h
gcc/c-format.c
gcc/c-typeck.c
gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/cp/decl2.c
gcc/cp/except.c
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/tree.h

index 0c16f377eb796a6beddcf1c77d4358ae470251a4..d31f6cedd0b50835639fc473cf3b1f21d2f8ac56 100644 (file)
@@ -1,3 +1,17 @@
+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_alignof): 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-26  Neil Booth  <neil@daikokuya.co.uk>
 
        PR preprocessor/8524
index 6cefb322f204b761f07ba2242e6de6ccd6842cb9..c594bd2d12314b2324a692d6a0ab60ea97a3bcca 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.
 
@@ -76,7 +76,7 @@ DEF_PRIMITIVE_TYPE (BT_CONST_PTR, const_ptr_type_node)
 DEF_PRIMITIVE_TYPE (BT_TRAD_PTR, traditional_ptr_type_node)
 DEF_PRIMITIVE_TYPE (BT_TRAD_CONST_PTR, traditional_cptr_type_node)
 DEF_PRIMITIVE_TYPE (BT_PTRMODE, 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)
 DEF_PRIMITIVE_TYPE (BT_LEN, traditional_len_type_node)
index 7eb878f70386da0eefff59c1bac51e48e540bb79..d8874d6a1473b836a9b6501e8a2b3610bc7a1a58 100644 (file)
@@ -4068,8 +4068,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 647b7b7b8a4bce432564b1be927cc3f441b80878..3511f157d0e863272903e0af350bef49d9af531f 100644 (file)
@@ -2425,7 +2425,7 @@ c_alignof (type)
   else
     t = size_int (TYPE_ALIGN (type) / BITS_PER_UNIT);
 
-  return fold (build1 (NOP_EXPR, c_size_type_node, t));
+  return fold (build1 (NOP_EXPR, size_type_node, t));
 }
 
 /* Implement the __alignof keyword: Return the minimum required
@@ -2473,7 +2473,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
 /* Give the specifications for the format attributes, used by C and all
@@ -2601,12 +2601,12 @@ 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 = signed_type (c_size_type_node);
+  signed_size_type_node = signed_type (size_type_node);
   if (flag_traditional)
-    c_size_type_node = signed_size_type_node;
-  set_sizetype (c_size_type_node);
+    size_type_node = signed_size_type_node;
+  set_sizetype (size_type_node);
 
   build_common_tree_nodes_2 (flag_short_double);
 
index 61a7f107f324b1c26f620db96f0012e998b9732f..f5e46593b72682636120c2637a437ec1495a250b 100644 (file)
@@ -136,10 +136,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,
@@ -193,7 +189,6 @@ struct c_common_identifier
 #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 d52cfba7c70e3f73490436877a332c0603ac6c50..658ca30f29d201628975b0a3e57b54a2d4cfd673 100644 (file)
@@ -750,7 +750,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 6020862f4101ff7711e1dd9cb27c825a2a66aa76..8093135ef6cfa98fa0d32d7e8e1a19f22cd726ff 100644 (file)
@@ -752,7 +752,7 @@ c_sizeof (type)
      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.  */
-  return fold (build1 (NOP_EXPR, c_size_type_node, size));
+  return fold (build1 (NOP_EXPR, size_type_node, size));
 }
 
 tree
@@ -776,7 +776,7 @@ c_sizeof_nowarn (type)
      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.  */
-  return fold (build1 (NOP_EXPR, c_size_type_node, size));
+  return fold (build1 (NOP_EXPR, size_type_node, size));
 }
 
 /* Compute the size to increment a pointer by.  */
index 0af12ca3b5f4e2f495a4b963be8b33db62de1a5f..ea9463d584c13b26b535e1cd57791d8c0a203796 100644 (file)
@@ -1,3 +1,14 @@
+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.
+       * typeck.c (c_sizeof): Likewise.
+       (c_sizeof_nowarn): Likewise.
+
 2002-11-30  Mark Mitchell  <mark@codesourcery.com>
 
        PR c++/8214
index 06b081c2831dff13e8ca9a994c3c21a5a70c882a..b1981c0e1ffd610fa071636bfee8099c66c2a6f8 100644 (file)
@@ -6659,7 +6659,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 730bbfb55f000ab83ea91440c938ff9fb97ed3b5..be72010125c0e72ea894afb73a9abec39c08893f 100644 (file)
@@ -2062,17 +2062,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 3f3cdcfd3be8ae2eb17ceecf0b68e4c37b38c187..5de9f4c8956e89b741b7461ab248b4648e4c5eeb 100644 (file)
@@ -508,7 +508,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 a38305f29d1c0b38fb9e3d2fbbb68d863e0d1384..82867eba0b3bce4740a2463052b39888cb8624de 100644 (file)
@@ -1544,7 +1544,7 @@ c_sizeof (type)
      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.  */
-  size = fold (build1 (NOP_EXPR, c_size_type_node, size));
+  size = fold (build1 (NOP_EXPR, size_type_node, size));
   my_friendly_assert (!TYPE_IS_SIZETYPE (TREE_TYPE (size)), 
                      20001021);
   return size;
@@ -1613,7 +1613,7 @@ c_sizeof_nowarn (type)
      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.  */
-  size = fold (build1 (NOP_EXPR, c_size_type_node, size));
+  size = fold (build1 (NOP_EXPR, size_type_node, size));
   my_friendly_assert (!TYPE_IS_SIZETYPE (TREE_TYPE (size)), 
                      20001021);
   return size;
index 3041068c9f3225860078af921383fc05fb2d155b..554f55cd8a49b2d09708f38d15959861b7ebde58 100644 (file)
@@ -1,3 +1,9 @@
+2002-11-30  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/8332
+       PR c++/8493
+       * g++.dg/template/strlen1.C: New test.
+
 2002-11-30  Mark Mitchell  <mark@codesourcery.com>
 
        PR c++/8214
index 03724e1818a763da24d65b21020322367a8cae73..c59c53e75fe549f24b55579e432cded9b793fe29 100644 (file)
@@ -1915,6 +1915,7 @@ enum tree_index
   TI_VOID_TYPE,
   TI_PTR_TYPE,
   TI_CONST_PTR_TYPE,
+  TI_SIZE_TYPE,
   TI_PTRDIFF_TYPE,
   TI_VA_LIST_TYPE,
 
@@ -1985,6 +1986,8 @@ extern 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]