------- Comment #9 from hubicka at ucw dot cz  2008-01-27 19:24 -------
Subject: Re:  [4.3 regression] calling a function with undefined parameters
causes segmentation fault at -O1 or higher

However the failure here is not early calling of cgraph_local_info (it
is ugly, but harmless, we are just looking for target promoting rules
that we don't change). 

The problem is good old type system broken scenario: the forward
declaration has no prorotype and thus might be vararg and thus it is not
regparmized, however the definition is correct. When expanding the call
we use type of the call, so the wrong type.

I am testing the attached patch. My type merging code fixes this too and
obvioiusly we should work harder on maybe_vaarg rule for local
functions, this should make lot of difference on K&R code (I wonder if
any is still around in usual distro)

Honza

Index: config/i386/i386.c
===================================================================
*** config/i386/i386.c  (revision 131882)
--- config/i386/i386.c  (working copy)
*************** init_cumulative_args (CUMULATIVE_ARGS *c
*** 3432,3437 ****
--- 3449,3455 ----
                      rtx libname,      /* SYMBOL_REF of library name or 0 */
                      tree fndecl)
  {
+   struct cgraph_local_info *i = fndecl ? cgraph_local_info (fndecl) : NULL;
    memset (cum, 0, sizeof (*cum));

    /* Set up the number of registers to use for passing arguments.  */
*************** init_cumulative_args (CUMULATIVE_ARGS *c
*** 3442,3447 ****
--- 3460,3474 ----
      cum->mmx_nregs = MMX_REGPARM_MAX;
    cum->warn_sse = true;
    cum->warn_mmx = true;
+ 
+   /* Because type might mismatch in between caller and callee, we need to
+      use actual type of function for local calls.
+      FIXME: cgraph_analyze can be told to actually record if function uses
+      va_start so for local functions maybe_vaarg can be made aggressive
+      helping K&R code.
+      FIXME: once typesytem is fixed, we won't need this code anymore.  */
+   if (i && i->local)
+     fntype = TREE_TYPE (fndecl);
    cum->maybe_vaarg = (fntype
                      ? (!prototype_p (fntype) || stdarg_p (fntype))
                      : !libname);


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34982

Reply via email to