]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/3152 (g++-3.0 segfaults when compiling program using -g)
authorNathan Sidwell <nathan@codesourcery.com>
Thu, 26 Jul 2001 08:07:56 +0000 (08:07 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Thu, 26 Jul 2001 08:07:56 +0000 (08:07 +0000)
cp:
* decl.c (last_function_parm_tags): Remove.
(current_function_parm_tags): Remove.
(init_decl_processing): Adjust.
(start_function): Adjust.
(store_parm_decls): Adjust.

PR c++/3152
* decl.c (grokdeclarator): Detect when a function typedef is
declaring a function, and create last_function_parms correctly.
testsuite:
* g++.old-deja/g++.other/crash42.C: New test.

From-SVN: r44387

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.old-deja/g++.other/crash42.C [new file with mode: 0644]

index 050f437f6d7d7d19ff1e4699d9f6d5a5598b6147..70c9bd380bd5c43292edc1059a1e5b37b1e0cc31 100644 (file)
@@ -1,3 +1,15 @@
+2001-07-26  Nathan Sidwell  <nathan@codesourcery.com>
+
+       * decl.c (last_function_parm_tags): Remove.
+       (current_function_parm_tags): Remove.
+       (init_decl_processing): Adjust.
+       (start_function): Adjust.
+       (store_parm_decls): Adjust.
+
+       PR c++/3152
+       * decl.c (grokdeclarator): Detect when a function typedef is
+       declaring a function, and create last_function_parms correctly.
+
 2001-07-25  Jason Merrill  <jason_merrill@redhat.com>
        
        * call.c (joust): Only prefer a non-builtin candidate to a builtin
index 4bbf2e0f5d489474170d72dc26287fb6ae244c58..c9867da52099adecf5a71174a2e0360526680caf 100644 (file)
@@ -243,14 +243,8 @@ tree static_aggregates;
 
 tree integer_two_node, integer_three_node;
 
-/* Parsing a function declarator leaves here a chain of structure
-   and enum types declared in the parmlist.  */
-
-static tree last_function_parm_tags;
-
 /* Similar, for last_function_parm_tags.  */
 tree last_function_parms;
-static tree current_function_parm_tags;
 
 /* A list of all LABEL_DECLs in the function that have names.  Here so
    we can clear out their names' definitions at the end of the
@@ -6565,8 +6559,6 @@ init_decl_processing ()
   ggc_add_tree_root (&static_dtors, 1);
   ggc_add_tree_root (&lastiddecl, 1);
 
-  ggc_add_tree_root (&last_function_parm_tags, 1);
-  ggc_add_tree_root (&current_function_parm_tags, 1);
   ggc_add_tree_root (&last_function_parms, 1);
   ggc_add_tree_root (&error_mark_list, 1);
 
@@ -11101,6 +11093,26 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist)
       type = build_cplus_array_type (TREE_TYPE (type), TYPE_DOMAIN (type));
     }
 
+  /* Detect where we're using a typedef of function type to declare a
+     function. last_function_parms will not be set, so we must create
+     it now.  */
+  
+  if (type == typedef_type && TREE_CODE (type) == FUNCTION_TYPE)
+    {
+      tree decls = NULL_TREE;
+      tree args;
+
+      for (args = TYPE_ARG_TYPES (type); args; args = TREE_CHAIN (args))
+       {
+         tree decl = build_decl (PARM_DECL, NULL_TREE, TREE_VALUE (args));
+
+         TREE_CHAIN (decl) = decls;
+         decls = decl;
+       }
+      
+      last_function_parms = nreverse (decls);
+    }
+
   /* If this is a type name (such as, in a cast or sizeof),
      compute the type and return it now.  */
 
@@ -13296,7 +13308,6 @@ start_function (declspecs, declarator, attrs, flags)
        }
 
       last_function_parms = DECL_ARGUMENTS (decl1);
-      last_function_parm_tags = NULL_TREE;
     }
   else
     {
@@ -13403,7 +13414,6 @@ start_function (declspecs, declarator, attrs, flags)
   /* Save the parm names or decls from this function's declarator
      where store_parm_decls will find them.  */
   current_function_parms = last_function_parms;
-  current_function_parm_tags = last_function_parm_tags;
 
   /* Make sure the parameter and return types are reasonable.  When
      you declare a function, these types can be incomplete, but they
@@ -13630,9 +13640,6 @@ store_parm_decls (current_function_parms)
   int parms_have_cleanups = 0;
   tree cleanups = NULL_TREE;
 
-  /* This is a list of types declared among parms in a prototype.  */
-  tree parmtags = current_function_parm_tags;
-
   /* This is a chain of any other decls that came in among the parm
      declarations.  If a parm is declared with  enum {foo, bar} x;
      then CONST_DECLs for foo and bar are put here.  */
@@ -13690,7 +13697,7 @@ store_parm_decls (current_function_parms)
         function.  This is all and only the PARM_DECLs that were
         pushed into scope by the loop above.  */
       DECL_ARGUMENTS (fndecl) = getdecls ();
-      storetags (chainon (parmtags, gettags ()));
+      storetags (gettags ());
     }
   else
     DECL_ARGUMENTS (fndecl) = NULL_TREE;
index 805bbb5ebe66486476e4bba00f3e2668abbc9661..c06c779aa6ae6ade5232f8110e6a5f1ddd858a57 100644 (file)
@@ -1,3 +1,7 @@
+2001-07-26  Nathan Sidwell  <nathan@codesourcery.com>
+
+       * g++.old-deja/g++.other/crash42.C: New test.
+
 2001-07-26  Neil Booth  <neil@cat.daikokuya.demon.co.uk>
 
        * gcc.dg/cpp/extratokens.c: Fix.
diff --git a/gcc/testsuite/g++.old-deja/g++.other/crash42.C b/gcc/testsuite/g++.old-deja/g++.other/crash42.C
new file mode 100644 (file)
index 0000000..be316ac
--- /dev/null
@@ -0,0 +1,17 @@
+// Build don't link:
+// Special g++ Options: -g
+// 
+// Copyright (C) 2001 Free Software Foundation, Inc.
+// Contributed by Nathan Sidwell 25 Jul 2001 <nathan@codesourcery.com>
+
+// Bug 3152. Using a typedef to declare a function used an unset
+// global variable, last_function_parms.
+
+struct actor 
+{
+  typedef bool (operation)();
+
+  operation a;
+  operation b;
+  operation c;
+};