Bug 65399 - Compiler produces wrong output.
Compiler produces wrong output.
Product: Red Hat Linux
Classification: Retired
Component: gcc (Show other bugs)
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
Brian Brock
Depends On:
  Show dependency treegraph
Reported: 2002-05-23 01:39 EDT by Kjartan Maraas
Modified: 2007-04-18 12:42 EDT (History)
2 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2002-12-15 15:35: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)
test case for compiler bug (559 bytes, patch)
2002-05-23 03:47 EDT, Kjartan Maraas
no flags Details | Diff

  None (edit)
Description Kjartan Maraas 2002-05-23 01:39:11 EDT
Description of Problem:

The attached testcase produces wrong output when compiled with -O2
Version-Release number of selected component (if applicable):

How Reproducible:
Every time

Steps to Reproduce:
1. Compile test.c with -O2
2. run

Actual Results:
[kmaraas@sevilla kmaraas]$ ./test
should be '/Documents':	/Documents
should be 'Documents':	Documents
should be 'Documents':	/Documents
should be 'Documents':	Documents

Expected Results:
Correct output

Additional Information:
Also get the same results with gcc3 (gcc3-3.0.4-1)
Comment 1 Jakub Jelinek 2002-05-23 03:42:04 EDT
No testcase attached...
Comment 2 Kjartan Maraas 2002-05-23 03:47:06 EDT
Created attachment 58266 [details]
test case for compiler bug
Comment 3 Kjartan Maraas 2002-05-23 03:47:29 EDT
Sorry about that :) Should be there now
Comment 4 Kjartan Maraas 2002-05-27 07:51:19 EDT
Any news on this? Would be nice to know if it actually is a bug in the compiler
or not. Sorry to be nagging about it, but I suddenly stopped trusting my
compiler after seeing this :)
Comment 5 Jakub Jelinek 2002-05-27 07:59:21 EDT
I've made a self contained testcase from it (bellow), verified the bug
in 2.96-RH and 3.0.x and found it is works just fine in 3.1.
As it works in 3.1, it is lower priority to me ATM.

typedef struct
  char *str;
  int len;
} A;

A *foo (void)
  static A x;
  x.str = "1234";
  x.len = 5;
  return &x;

int bar (const char *x)

char *baz (const char *x)
  return (char *) x;

main (int argc, char *argv[])
  char *s, *t;
  A *u;

  u = foo ();
  t = (*u->str == '\0') ? u->str : (u->str + 1);
  s = baz ((*u->str == '\0') ? u->str : (u->str + 1));
  bar (s);
  bar (t);
  if (*s != '2')
    abort ();
  return 0;
Comment 6 Kjartan Maraas 2002-05-27 08:52:27 EDT
I had someone test it on 3.1 sparc and he saw the problem there too. I'll try to
get the version from him.
Comment 7 Kjartan Maraas 2002-05-27 12:48:34 EDT
He used 3.1.0 from sunfreeware. Self compiled.
Comment 8 Kjartan Maraas 2002-08-24 17:42:36 EDT
Close this as fixed in the latest release?
Comment 9 Alan Cox 2002-12-15 15:35:17 EST
Confirmed ok in 8.0

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