Bug 228521 - c++ code crashes
c++ code crashes
Status: CLOSED UPSTREAM
Product: Fedora
Classification: Fedora
Component: gcc (Show other bugs)
6
athlon Linux
medium Severity urgent
: ---
: ---
Assigned To: Jakub Jelinek
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2007-02-13 10:49 EST by Tianlin Wang
Modified: 2007-11-30 17:11 EST (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2007-02-14 06:22:50 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)


External Trackers
Tracker ID Priority Status Summary Last Updated
GNU Compiler Collection 30787 None None None Never

  None (edit)
Description Tianlin Wang 2007-02-13 10:49:38 EST
Description of problem:
A c++ code generates 'Segmentation' message when it is complied with 
-O2. It works fine with other optimization levels such as -O,-O3.

Version-Release number of selected component (if applicable):
I only observed this bug in FC6. My machine is Atholon64

How reproducible:

/** The following code will end with 'Segmentation' if compiled with -O2 **/
/** It works fine with other optimization levels such -O, -O3 **/

/************ BEGIN OF CODE ***********/
#include <string>
#include <cstddef>

struct AA {
  int def;
};

struct BB {
  AA *alltype;
};

void compute(int n,BB *grand=NULL);


int main(int argc, char *argv[])
{
   compute(1);
   return 0;
}

void compute(int n,BB *grand)
{
  int t;
   for (t=0; t<n; t++) {
      if (grand) grand->alltype[t].def += 1;
   }
   return;
}

/********* END OF CODE **********/


Steps to Reproduce:
1. Compile the sample code with -O2
2. run it
3. you will see the 'Segmentation' on the screen
  
Actual results:
Segmentation

Expected results:


Additional info:
Comment 1 Jakub Jelinek 2007-02-13 11:11:48 EST
Simplified C testcase:
struct S
{
  int *s;
};

void
test (int x, struct S *y)
{
  int i;
  for (i = 0; i < x; i++)
    {
      if (y)
        y->s[i] += 1;
    }
}

int
main ()
{
  test (1, (void *) 0);
  return 0;
}

This seems to be a RTL strength reduction bug, present also on vanilla
gcc-4_1-branch.  -O2 -fno-strength-reduce cures this.
Comment 2 Jakub Jelinek 2007-02-14 06:22:50 EST
Tracking upstream.

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