public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: p.van-hoof@qub.ac.uk
To: gcc-gnats@gcc.gnu.org
Cc: p.van-hoof@qub.ac.uk
Subject: optimization/10312: optimizer creates wrong code for loop
Date: Fri, 04 Apr 2003 18:56:00 -0000	[thread overview]
Message-ID: <200304041846.h34Ikxfo008166@scooby.star.fleet> (raw)


>Number:         10312
>Category:       optimization
>Synopsis:       optimizer creates wrong code for loop
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Fri Apr 04 18:56:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     Peter van Hoof
>Release:        3.4 20030403 (experimental)
>Organization:
Queen's University of Belfast
>Environment:
System: SunOS scooby 5.9 Generic_112233-04 sun4u sparc SUNW,Sun-Blade-100
Architecture: sun4

	
host: sparc-sun-solaris2.9
build: sparc-sun-solaris2.9
target: sparc-sun-solaris2.9
configured with: /scratch/gcc-repository/cvs/gcc/configure --prefix=/opt/local/gcc340 --enable-languages=c,c++,f77 --with-gnu-as --with-as=/opt/local/bin/gas
>Description:
The optimizer creates wrong code for the loop in the attached program.
When compiled with -O2, the resulting code will generate a segfault.
If the "double a" member of the struct is removed, the program will get
stuck in an infinite loop, rather than crash.

The program behaves correctly with gcc 3.2.2 and 3.3, so this is a regression.
>How-To-Repeat:
scooby> gcc -v -O2 c.c
Reading specs from /opt/local/gcc340/lib/gcc-lib/sparc-sun-solaris2.9/3.4/specs
Configured with: /scratch/gcc-repository/cvs/gcc/configure --prefix=/opt/local/gcc340 --enable-languages=c,c++,f77 --with-gnu-as --with-as=/opt/local/bin/gas
Thread model: posix
gcc version 3.4 20030403 (experimental)
 /opt/local/gcc340/lib/gcc-lib/sparc-sun-solaris2.9/3.4/cc1 -quiet -v -Dsparc -D__sparc__ -D__sparc -D__GCC_NEW_VARARGS__ -Acpu=sparc -Amachine=sparc c.c -quiet -dumpbase c.c -auxbase c -O2 -version -o /var/tmp//ccXLgTFq.s
ignoring nonexistent directory "/opt/local/gcc340/sparc-sun-solaris2.9/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /opt/local/gcc340/include
 /opt/local/gcc340/lib/gcc-lib/sparc-sun-solaris2.9/3.4/include
 /usr/include
End of search list.
GNU C version 3.4 20030403 (experimental) (sparc-sun-solaris2.9)
	compiled by GNU C version 3.4 20030403 (experimental).
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
 /opt/local/bin/gas -V -Qy -s -o /var/tmp//ccOfg7jT.o /var/tmp//ccXLgTFq.s
GNU assembler version 2.13.2.1 (sparc-sun-solaris2.9) using BFD version 2.13.2.1
 /opt/local/gcc340/lib/gcc-lib/sparc-sun-solaris2.9/3.4/collect2 -V -Y P,/usr/ccs/lib:/usr/lib -Qy /opt/local/gcc340/lib/gcc-lib/sparc-sun-solaris2.9/3.4/crt1.o /opt/local/gcc340/lib/gcc-lib/sparc-sun-solaris2.9/3.4/crti.o /usr/ccs/lib/values-Xa.o /opt/local/gcc340/lib/gcc-lib/sparc-sun-solaris2.9/3.4/crtbegin.o -L/opt/local/gcc340/lib/gcc-lib/sparc-sun-solaris2.9/3.4 -L/usr/ccs/bin -L/usr/ccs/lib -L/opt/local/gcc340/lib/gcc-lib/sparc-sun-solaris2.9/3.4/../../.. /var/tmp//ccOfg7jT.o -lgcc -lgcc_eh -lc -lgcc -lgcc_eh -lc /opt/local/gcc340/lib/gcc-lib/sparc-sun-solaris2.9/3.4/crtend.o /opt/local/gcc340/lib/gcc-lib/sparc-sun-solaris2.9/3.4/crtn.o
ld: Software Generation Utilities - Solaris Link Editors: 5.9-1.373

scooby>	a.out 
Segmentation fault

scooby>	cat c.c
struct {
	double a; 
	int n[2];
} g = { 0., { 1, 2 } };

int k = 0;

void b(int *j) {}

int main()
{
	int j;
	for( j=0; j < 2; j++ )
		k = ( k > g.n[j] ) ? k : g.n[j];
	k++;
	b(&j);
	return 0;
}
>Fix:
Workaround: use lower level of optimization.
>Release-Note:
>Audit-Trail:
>Unformatted:


             reply	other threads:[~2003-04-04 18:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-04-04 18:56 p.van-hoof [this message]
2003-04-04 19:03 ebotcazou
2003-04-04 19:16 Peter van Hoof
2003-04-04 22:06 Eric Botcazou

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200304041846.h34Ikxfo008166@scooby.star.fleet \
    --to=p.van-hoof@qub.ac.uk \
    --cc=gcc-gnats@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).