This is the mail archive of the gcc-prs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

optimization/463: Optimizer wrongly eliminates code block



>Number:         463
>Category:       optimization
>Synopsis:       Optimizer wrongly eliminates code block
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Thu Aug 10 16:46:00 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator:     Farrell McKay
>Release:        egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
>Organization:
>Environment:
Linux 2.2.14 #4 SMP Mon Jul 17 19:50:32 EST
Intel Pentium III dual CPU system
>Description:
Compiling and running the attached program without optimization works ok.  If I turn on any level of optimization, the if() statement is wrongly eliminated from the program.

Presumably the same problem will arise with the other maths
functions also.

>How-To-Repeat:
g++ optbug.cpp; ./a.out; correctly produces:
Success; got the expected error: rtn = nan errno = 33
rtn = nan  errno = 33

g++ -O optbug.cpp; ./a.out; wrongly produces:
rtn = nan  errno = 0


>Fix:
I need a programmatic hint or a compiler switch that
tells the optimizer about 'errno' side-effects.
Do you have any suggestions for a fix or work-around?
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="optbug.cpp"
Content-Disposition: inline; filename="optbug.cpp"

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <errno.h>

main()
{
	double rtn;

	errno = 0;
	rtn = acos(2.0);			// This should fail, and set errno to EDOM.
	if (errno != 0)
		printf("Success; got the expected error: rtn = %g errno = %d\n", rtn, errno);

	printf("rtn = %g  errno = %d\n", rtn, errno);
	return 0;
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]