public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c/7527: gcc 2.95.3 and gcc 3.0.4 generate incorrect code
@ 2002-08-08 3:16 Stian
0 siblings, 0 replies; 3+ messages in thread
From: Stian @ 2002-08-08 3:16 UTC (permalink / raw)
To: nobody; +Cc: gcc-prs
The following reply was made to PR c/7527; it has been noted by GNATS.
From: Stian <stian@knowledge-network.no>
To: gcc-gnats@gcc.gnu.org
Cc: gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org, nobody@gcc.gnu.org,
tomdean@asus.tddhome
Subject: Re: c/7527: gcc 2.95.3 and gcc 3.0.4 generate incorrect code
Date: 08 Aug 2002 12:08:55 +0200
The second conditional makes more sense if you use () at the right places
if(!(_io_ports[0x39]&0x80))
If you don't add them, your statement is the same as
if((!_io_ports[0x39])&0x80)
That always come out false, then ! makes the result of the io-read either 0 or 1.
Stian
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: c/7527: gcc 2.95.3 and gcc 3.0.4 generate incorrect code
@ 2002-08-07 11:46 rth
0 siblings, 0 replies; 3+ messages in thread
From: rth @ 2002-08-07 11:46 UTC (permalink / raw)
To: gcc-bugs, gcc-prs, nobody, tomdean
Synopsis: gcc 2.95.3 and gcc 3.0.4 generate incorrect code
State-Changed-From-To: open->closed
State-Changed-By: rth
State-Changed-When: Wed Aug 7 11:16:27 2002
State-Changed-Why:
Not a bug. You are confused about operator precedence.
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=7527
^ permalink raw reply [flat|nested] 3+ messages in thread
* c/7527: gcc 2.95.3 and gcc 3.0.4 generate incorrect code
@ 2002-08-07 10:36 Thomas D. Dean
0 siblings, 0 replies; 3+ messages in thread
From: Thomas D. Dean @ 2002-08-07 10:36 UTC (permalink / raw)
To: gcc-gnats
>Number: 7527
>Category: c
>Synopsis: gcc 2.95.3 and gcc 3.0.4 generate incorrect code
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Wed Aug 07 10:26:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: Thomas D. Dean
>Release: 3.0.4 m68hc1x-20020616
>Organization:
>Environment:
System: FreeBSD asus 4.6-STABLE FreeBSD 4.6-STABLE #7: Mon Jul 22 14:18:44 PDT 2002 root@asus:/usr/src/sys/compile/ASUS i386
host: i386-unknown-freebsd4.6
build: i386-unknown-freebsd4.6
target: m6811-unknown-none
configured with: ./configure --target=m6811-elf --program-prefix=m6811-elf- --enable-languages=c,c++
>Description:
Compiling the simple 10 statement c-source, below, causes incorrect
code to be generated. The 40 lines of comments in the code explain
details.
The statement 'if(!_io_ports[0x59]&0x80) {...}' is compiled incorrectly.
The problem was first noticed with
# m6811-elf-gcc -v
Reading specs from /usr/local/lib/gcc-lib/m6811-elf/3.0.4/specs
Configured with: ./configure --target=m6811-elf --program-prefix=m6811-elf- \
--enable-languages=c,c++
Thread model: single
gcc version 3.0.4 m68hc1x-20020616
and reproduced with
# gcc -v
Using builtin specs.
gcc version 2.95.3 20010315 (release) [FreeBSD]
tomdean
/*
* example to generate incorrect code.
*
* compiled with `gcc -Wall -o f f.c
*/
volatile unsigned char *_io_ports = (unsigned char *)0x7500;
int main() {
/*
* produces correct code
*/
if(!(_io_ports[0x39]&0x80)) {
_io_ports[0x29] = 0xff;
}
/*
* produces incorrect code - accesses _io_ports[0x59], but,
* the if() is ignored. There is no value testing or conditional
* branch in the elf file. The above code is the preferred syntax,
* but, the below code should do something with the value.
*
* at 8048485 in the output of objdump, below, _io_ports[0x59] is
* accessed as 0x59(%eax). The next line, 8048488, is the start of
* 'return 0'. There should be some form of conditional between.
*
*/
if(!_io_ports[0x59]&0x80) {
_io_ports[0x49] = 0;
}
return 0;
}
/*
* objdump -d f shows
* ...
*
* 0804846c <main>:
* 804846c: 55 push %ebp
* 804846d: 89 e5 mov %esp,%ebp
* 804846f: 8b 15 d8 94 04 08 mov 0x80494d8,%edx
* 8048475: 8a 42 39 mov 0x39(%edx),%al
* 8048478: 84 c0 test %al,%al
* 804847a: 7c 04 jl 8048480 <main+0x14>
* 804847c: c6 42 29 ff movb $0xff,0x29(%edx)
* 8048480: a1 d8 94 04 08 mov 0x80494d8,%eax
* 8048485: 8a 40 59 mov 0x59(%eax),%al
* 8048488: 31 c0 xor %eax,%eax
* 804848a: c9 leave
* 804848b: c3 ret
*
* ...
*/
>How-To-Repeat:
Compile the source code above
>Fix:
The first conditional, 'if(!(_io_ports[0x39]&0x80))' generates correct code.
The 2nd conditional, 'if(!_io_ports[0x39]&0x80)' generates incorrect code.
>Release-Note:
>Audit-Trail:
>Unformatted:
medium
wrong-code
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2002-08-08 10:16 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-08-08 3:16 c/7527: gcc 2.95.3 and gcc 3.0.4 generate incorrect code Stian
-- strict thread matches above, loose matches on Subject: below --
2002-08-07 11:46 rth
2002-08-07 10:36 Thomas D. Dean
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).