public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/45265]  New: GCC has an intermittent bug when computing the address of function parameters
@ 2010-08-12 14:50 rogerio at rilhas dot com
  2010-08-12 14:52 ` [Bug c++/45265] " rogerio at rilhas dot com
                   ` (58 more replies)
  0 siblings, 59 replies; 60+ messages in thread
From: rogerio at rilhas dot com @ 2010-08-12 14:50 UTC (permalink / raw)
  To: gcc-bugs

The following code:

void bug_example_2(const char** format_address, int* ip) {
        char* p1=(char*)format_address;
        char* p2=(char*)ip;
        int dif=p2-p1;
        if (dif!=sizeof(char*)) {
                // crash
                char* p=0; *p=0;
        }
}

void bug_example(const char* strp, int i) {
        char buffer[1000]; buffer[0]=0;
        bug_example_2(&strp, &i);
}

int main(void) {
        bug_example("GCC has a bug", 10);
        return 0;
}

... is incorrectly compiled by GCC. As you can see there are no variable
parameters in this code, so there is nothing here out of the ordinary.

Possibility 1) GCC is not cdecl-ABI compliant, so the "dif" can have values
other than 4 on x86-32. In this case GCC should not claim to be
cdecl-compliant.

Possibility 2) GCC is not conformant to C99 but it is cdecl-ABI compliant. C99
states in section 6.5.3.2 paragraph 3 that "The unary & operator yields the
address of its operand.", but GCC is not doing that, as the "if" in
bug_example_2 is occasionally entered. Thus "dif" is not 4 (and with cdecl ABI
it should be 4 on x86-32).

If line "char buffer[1000]; buffer[0]=0;" GCC then compiles the code as
expected and "dif" will be 4.

This proves GCC is not conforming to C99 recommendations or that is not
cdecl-ABI compliant (or possibly both).

Don't bother trying to understand why I need the & operand to work as stated in
C99, or why I need the code to be cdecl compliant, that is too complicated for
you and it would just confuse you. For the purpose of this bug you may simply
consider that I'm performing conformity tests on GCC against C99 and cdecl, and
that GCC failed the test.

Next I will send you the preprocessed file and the compilation script.


-- 
           Summary: GCC has an intermittent bug when computing the address
                    of function parameters
           Product: gcc
           Version: 4.3.3
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: rogerio at rilhas dot com
 GCC build triplet: i686-virtualboxvm-ubuntu?
  GCC host triplet: i686-virtualboxvm-ubuntu?
GCC target triplet: i686-virtualboxvm-ubuntu?


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


^ permalink raw reply	[flat|nested] 60+ messages in thread

end of thread, other threads:[~2010-08-14 17:11 UTC | newest]

Thread overview: 60+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-12 14:50 [Bug c++/45265] New: GCC has an intermittent bug when computing the address of function parameters rogerio at rilhas dot com
2010-08-12 14:52 ` [Bug c++/45265] " rogerio at rilhas dot com
2010-08-12 14:52 ` rogerio at rilhas dot com
2010-08-12 14:54 ` rogerio at rilhas dot com
2010-08-12 15:09 ` jakub at gcc dot gnu dot org
2010-08-12 15:25 ` schwab at linux-m68k dot org
2010-08-12 15:33 ` rogerio at rilhas dot com
2010-08-12 15:34 ` rogerio at rilhas dot com
2010-08-12 15:52 ` redi at gcc dot gnu dot org
2010-08-12 15:52 ` schwab at linux-m68k dot org
2010-08-12 16:00 ` matz at gcc dot gnu dot org
2010-08-12 16:05 ` rogerio at rilhas dot com
2010-08-12 16:09 ` redi at gcc dot gnu dot org
2010-08-12 16:10 ` pinskia at gcc dot gnu dot org
2010-08-12 16:11 ` jakub at gcc dot gnu dot org
2010-08-12 16:15 ` rogerio at rilhas dot com
2010-08-12 16:17 ` redi at gcc dot gnu dot org
2010-08-12 16:18 ` rogerio at rilhas dot com
2010-08-12 16:19 ` rogerio at rilhas dot com
2010-08-12 16:20 ` redi at gcc dot gnu dot org
2010-08-12 16:58 ` dj at redhat dot com
2010-08-12 17:09 ` froydnj at gcc dot gnu dot org
2010-08-12 17:25 ` rogerio at rilhas dot com
2010-08-12 17:25 ` rogerio at rilhas dot com
2010-08-12 17:50 ` rogerio at rilhas dot com
2010-08-12 17:54 ` redi at gcc dot gnu dot org
2010-08-12 18:04 ` rogerio at rilhas dot com
2010-08-12 18:05 ` matz at gcc dot gnu dot org
2010-08-12 18:08 ` dj at redhat dot com
2010-08-12 18:24 ` rogerio at rilhas dot com
2010-08-12 18:28 ` pinskia at gcc dot gnu dot org
2010-08-12 18:32 ` rogerio at rilhas dot com
2010-08-12 18:39 ` rogerio at rilhas dot com
2010-08-12 18:56 ` matz at gcc dot gnu dot org
2010-08-13 12:14 ` rogerio at rilhas dot com
2010-08-13 13:00 ` matz at gcc dot gnu dot org
2010-08-13 13:14 ` matz at gcc dot gnu dot org
2010-08-13 13:32 ` paolo dot carlini at oracle dot com
2010-08-13 14:47 ` rogerio at rilhas dot com
2010-08-13 14:48 ` rogerio at rilhas dot com
2010-08-13 14:53 ` rogerio at rilhas dot com
2010-08-13 15:18 ` matz at gcc dot gnu dot org
2010-08-13 15:26 ` matz at gcc dot gnu dot org
2010-08-13 16:28 ` rogerio at rilhas dot com
2010-08-13 16:30 ` rogerio at rilhas dot com
2010-08-13 16:33 ` redi at gcc dot gnu dot org
2010-08-13 16:42 ` rogerio at rilhas dot com
2010-08-13 18:00 ` ubizjak at gmail dot com
2010-08-13 21:16 ` rogerio at rilhas dot com
2010-08-13 22:38 ` redi at gcc dot gnu dot org
2010-08-13 22:40 ` redi at gcc dot gnu dot org
2010-08-14  1:26 ` matz at gcc dot gnu dot org
2010-08-14 13:18 ` rogerio at rilhas dot com
2010-08-14 13:55 ` redi at gcc dot gnu dot org
2010-08-14 14:25 ` redi at gcc dot gnu dot org
2010-08-14 14:32 ` rogerio at rilhas dot com
2010-08-14 14:34 ` rogerio at rilhas dot com
2010-08-14 15:09 ` redi at gcc dot gnu dot org
2010-08-14 16:02 ` rogerio at rilhas dot com
2010-08-14 17:11 ` redi at gcc dot gnu dot 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).