public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/15774] New: Conflicting function decls not diagnosed
@ 2004-06-02 10:54 dannysmith at users dot sourceforge dot net
  2004-06-02 10:59 ` [Bug c++/15774] " dannysmith at users dot sourceforge dot net
                   ` (5 more replies)
  0 siblings, 6 replies; 12+ messages in thread
From: dannysmith at users dot sourceforge dot net @ 2004-06-02 10:54 UTC (permalink / raw)
  To: gcc-bugs

The C++ frontend doesn't always call targetm.compare_type_attributes
when comparing function decls in decl.c: decls_match.  As a result
conflicting decls are not diagnosed.  Here is a testcase.

/* stdcall.c */
extern void foo(int);

void bar() { foo(1);}

void __attribute__((stdcall)) foo(int i) {};

This should casue fatal error because of type conflict between
declaration and definition of foo.

In C it does.

D:\develop\bugs>gcc -S -Wall stdcall.c 
> stdcall.c:5: error: conflicting types for 'foo'
> stdcall.c:1: error: previous declaration of 'foo' was here

In C++ it doesn't

D:\develop\bugs>gcc -xc++ -S -Wall stdcall.c
compiles without error.

But it produces bad code.  This is easier to spot on windows targets because
of the target specific stdcall decoration.

        .file        "stdcall.c"
        .text
        .align 4
        .align 2
.globl __Z3barv
        .def        __Z3barv;        .scl        2;        .type        
32;        .endef
__Z3barv:
        pushl        %ebp
        movl        %esp, %ebp
        subl        $8, %esp
        subl        $12, %esp
        pushl        $1
        call        __Z3fooi   <<< undefined
        addl        $16, %esp  <<< Should be $12.
        leave
        ret
        .align 2
.globl __Z3fooi@4
        .def        __Z3fooi@4;        .scl        2;        .type        
32;        .endef
__Z3fooi@4:
        pushl        %ebp
        movl        %esp, %ebp
        leave
        ret        $4
        .def        __Z3fooi;        .scl        3;        .type        
32;        .endef


The testcase fails in 3.4.0 and 3.5.0 on i386-i386-pc-mingw32


The following patch to cp/declc fixes the testcase.  I don't think it is right, 
but I'll run it throw bootstrap and regtest and  submit proper patch if it 
doesn't cause any other problems.

Danny

Index: decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.1212
diff -c -3 -p -r1.1212 decl.c
*** decl.c	28 May 2004 21:58:15 -0000	1.1212
--- decl.c	2 Jun 2004 10:35:33 -0000
*************** decls_match (tree newdecl, tree olddecl)
*** 1021,1027 ****
  	    }
  #endif
  	  else
! 	    types_match = compparms (p1, p2);
  	}
        else
  	types_match = 0;
--- 1021,1030 ----
  	    }
  #endif
  	  else
! 	    types_match = compparms (p1, p2)
! 			  && comptypes (TREE_TYPE (newdecl),
! 					 TREE_TYPE (olddecl),
! 					 COMPARE_REDECLARATION);
  	}
        else
  	types_match = 0;

-- 
           Summary: Conflicting function decls not diagnosed
           Product: gcc
           Version: 3.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: dannysmith at users dot sourceforge dot net
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i386-pc-mingw32
  GCC host triplet: i386-pc-mingw32
GCC target triplet: i386-pc-mingw32


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


^ permalink raw reply	[flat|nested] 12+ messages in thread
[parent not found: <bug-15774-4066@http.gcc.gnu.org/bugzilla/>]
[parent not found: <bug-15774-4@http.gcc.gnu.org/bugzilla/>]

end of thread, other threads:[~2011-02-19 21:26 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-06-02 10:54 [Bug c++/15774] New: Conflicting function decls not diagnosed dannysmith at users dot sourceforge dot net
2004-06-02 10:59 ` [Bug c++/15774] " dannysmith at users dot sourceforge dot net
2004-06-02 11:37 ` pinskia at gcc dot gnu dot org
2004-06-28  1:25 ` giovannibajo at libero dot it
2004-06-28  1:43 ` dannysmith at users dot sourceforge dot net
2004-06-28  7:50 ` giovannibajo at libero dot it
2004-06-29  3:31 ` jason at redhat dot com
     [not found] <bug-15774-4066@http.gcc.gnu.org/bugzilla/>
2006-06-30  3:10 ` dannysmith at users dot sourceforge dot net
2007-09-19 21:52 ` dannysmith at users dot sourceforge dot net
     [not found] <bug-15774-4@http.gcc.gnu.org/bugzilla/>
2010-12-25 10:41 ` ktietz at gcc dot gnu.org
2011-01-13 21:52 ` ktietz at gcc dot gnu.org
2011-02-19 22:06 ` ktietz at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).