PR target/34982

Jan Hubicka jh@suse.cz
Wed Jan 30 22:47:00 GMT 2008


Hi,
this testcase shows miscompilation of call caused by using forward
declaration in init_cumulative_args instead of real declaration in local
function call.  This prevents use of register calling conventions.

Note that audit trail contains one extra patch that prevents using of
backend data during parsing.  It make us slightly more strict on
handling regparm attribute; I am not sure if we ought to commit it now
to get programs diagnozed and fixed or wait for next release.  I am
happy with both.

Bootstrapped/regtested i686-linux and x86_64-linux and comitted.

Index: ChangeLog
===================================================================
*** ChangeLog	(revision 131965)
--- ChangeLog	(working copy)
***************
*** 1,3 ****
--- 1,9 ----
+ 2008-01-30  Jan Hubicka  <jh@suse.cz>
+ 
+ 	PR target/34982
+ 	* i386.c (init_cumulative_args): Use real function declaration when
+ 	calling locally.
+ 
  2008-01-30  Richard Sandiford  <rsandifo@nildram.co.uk>
  
  	PR rtl-optimization/34998
Index: testsuite/gcc.c-torture/execute/pr34982.c
===================================================================
*** testsuite/gcc.c-torture/execute/pr34982.c	(revision 0)
--- testsuite/gcc.c-torture/execute/pr34982.c	(revision 0)
***************
*** 0 ****
--- 1,14 ----
+ extern void abort (void);
+ 
+ static void something();
+ 
+ int main()
+ {
+   something(-1);
+ }
+ 
+ static void something(int i)
+ {
+   if (i != -1)
+     abort ();
+ }
Index: testsuite/ChangeLog
===================================================================
*** testsuite/ChangeLog	(revision 131965)
--- testsuite/ChangeLog	(working copy)
***************
*** 1,3 ****
--- 1,8 ----
+ 2008-01-30  Jan Hubicka  <jh@suse.cz>
+ 
+ 	PR target/34982
+ 	* gcc.c-torture/execute/pr34982.c: New testcase
+ 
  2008-01-30  Andreas Krebbel  <krebbel1@de.ibm.com>
  
  	* gcc.target/s390/tf_to_di-1.c: New testcase.
Index: config/i386/i386.c
===================================================================
*** config/i386/i386.c	(revision 131965)
--- config/i386/i386.c	(working copy)
*************** init_cumulative_args (CUMULATIVE_ARGS *c
*** 3432,3437 ****
--- 3432,3438 ----
  		      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 ****
--- 3443,3457 ----
      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);



More information about the Gcc-patches mailing list