Bug 116366 - gcc optimizer produces incorrect code
gcc optimizer produces incorrect code
Product: Red Hat Linux
Classification: Retired
Component: gcc (Show other bugs)
i686 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
David Lawrence
: 116372 (view as bug list)
Depends On:
  Show dependency treegraph
Reported: 2004-02-20 11:32 EST by Need Real Name
Modified: 2007-04-18 13:03 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2004-02-20 11:38:17 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Need Real Name 2004-02-20 11:32:01 EST
Description of problem:
gcc optimizer option -O2 produces incorrect code

Version-Release number of selected component (if applicable):
gcc-3.2.2-5 [gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)]

How reproducible:
Every time.

Steps to Reproduce:
1.compile and run test program with -O2 option

cat <<EOF > t.c
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main(int argc, char** argv)
    char *str;
    char *s;

    str = strdup("abc");
    s = str;
    printf("str is [%s], s is %c\n", str, *s);
    *s++ = toupper(*s);
    printf("str is [%s], s is %c\n", str, *s);
    return 0;
gcc -o t t.c
gcc -O2 -o t t.c
Actual results:
str is [abc], s is a
str is [Bbc], s is b

Expected results:
str is [abc], s is a
str is [Abc], s is b

Additional info:
Comment 1 Jakub Jelinek 2004-02-20 11:38:17 EST
That's not a bug, your code is broken.
There is no sequence point between s++ on the left side of = operator
and s use on the right side, so the actual result of the operation
is undefined.
See ISO C99 (or earlier standards) for details on sequence points.
Comment 2 Jakub Jelinek 2004-02-20 11:50:31 EST
*** Bug 116372 has been marked as a duplicate of this bug. ***

Note You need to log in before you can comment on or make changes to this bug.