This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch] to i386winnt.c: Fix ICE on stdcall with incomplete type in parms


Hello
The following testcase produces ICE on mainline and all prior versions of gcc
that I have tested.

/* i386-stdcall-suffix.c */
/* Test that generation of stdcall suffix doesn't cause ICE
   with incomplete type */ 
/* { dg-do compile { target i?86-*-* } } */

struct _incomplete_t;
extern void __attribute__ ((__stdcall__))
foo (struct _incomplete_t);  /* { dg-warn "incomplete" } */

void bar(void)
{
  foo (0); /* { dg-error "incomplete" } */
}

\develop\bugs\gcc>gcc -Wall -c i386-stdcall-suffix.c 
i386-stdcall-suffix.c:8: warning: parameter has incomplete type
i386-stdcall-suffix.c: In function `bar':

i386-stdcall-suffix.c:12: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.

The problem arise when trying to generate a stdcall suffix
on windows targets (winnt.c:gen_stdcall_suffix).  This suffix is
calculated from the total size of the parameter list. 

The following patch fixes. I have just quit early when we hit an
incomplete type.  I don't think there is a need to do anything else
since convert_arguments will report a fatal error soon enough.

I have also added the above testcase to the testsuite, enabling it for
all i?86 targets.

Danny


ChangeLog

	2003-09-18  Danny Smith  <dannysmith@users.sourceforge.net>

	* config/i386/winnt.c (gen_stdcall_suffix): Quit summation of
	total parm size if a parm has incomplete type.
	(gen_fastcall_suffix): Likewise.

Testsuite

	* gcc-dg/i386-stdcall-suffix.c: New file.


Index: config/i386/winnt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/i386/winnt.c,v
retrieving revision 1.54
diff -c -3 -p -r1.54 winnt.c
*** config/i386/winnt.c	17 Aug 2003 10:00:02 -0000	1.54
--- config/i386/winnt.c	18 Sep 2003 00:17:46 -0000
*************** gen_fastcall_suffix (tree decl)
*** 420,426 ****
        {
  	tree formal_type = TYPE_ARG_TYPES (TREE_TYPE (decl));
  
! 	while (TREE_VALUE (formal_type) != void_type_node)
  	  {
  	    int parm_size
  	      = TREE_INT_CST_LOW (TYPE_SIZE (TREE_VALUE (formal_type)));
--- 420,429 ----
        {
  	tree formal_type = TYPE_ARG_TYPES (TREE_TYPE (decl));
  
! 	/* Quit if we hit an incomplete type.  Error is reported
! 	   by convert_arguments in c-typeck.c or cp/typeck.c.  */
! 	while (TREE_VALUE (formal_type) != void_type_node
! 	       && COMPLETE_TYPE_P (TREE_VALUE (formal_type)))	
  	  {
  	    int parm_size
  	      = TREE_INT_CST_LOW (TYPE_SIZE (TREE_VALUE (formal_type)));
*************** gen_stdcall_suffix (tree decl)
*** 458,464 ****
        {
  	tree formal_type = TYPE_ARG_TYPES (TREE_TYPE (decl));
  
! 	while (TREE_VALUE (formal_type) != void_type_node)
  	  {
  	    int parm_size
  	      = TREE_INT_CST_LOW (TYPE_SIZE (TREE_VALUE (formal_type)));
--- 461,470 ----
        {
  	tree formal_type = TYPE_ARG_TYPES (TREE_TYPE (decl));
  
! 	/* Quit if we hit an incomplete type.  Error is reported
! 	   by convert_arguments in c-typeck.c or cp/typeck.c.  */
! 	while (TREE_VALUE (formal_type) != void_type_node
! 	       && COMPLETE_TYPE_P (TREE_VALUE (formal_type)))	
  	  {
  	    int parm_size
  	      = TREE_INT_CST_LOW (TYPE_SIZE (TREE_VALUE (formal_type)));
*** /dev/null	Thu Sep 18 01:15:09 2003
--- testsuite/gcc.dg/i386-stdcall-suffix.c	Thu Sep 18 01:14:59 2003
***************
*** 0 ****
--- 1,14 ----
+ /* i386-stdcall-suffix.c */
+ /* Test that generation of stdcall suffix doesn't cause ICE
+    with incomplete type */ 
+ /* { dg-do compile { target i?86-*-* } } */
+ 
+ struct _incomplete_t;
+ 
+ extern void __attribute__ ((__stdcall__))
+ foo (struct _incomplete_t);  /* { dg-warn "incomplete" } */
+ 
+ void bar(void)
+ {
+   foo (0); /* { dg-error "incomplete" } */
+ }

http://search.yahoo.com.au - Yahoo! Search
- Looking for more? Try the new Yahoo! Search


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]