This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Fix cacos bug introduced last November (was: ICE in compiling complex/cacos.c for arm/thumb)


(Well, it was early November when the patch was committed.)

> Date: Sat, 09 Oct 2010 10:35:52 +0200
> From: Ralf Corsepius <ralf.corsepius@rtems.org>

> Though this definitely is a compiler bug, I found reordering the code in 
> complex/cacos.c lets building succeed.
> 
> I am going to add this patch to RTEMS newlib patches and would 
> appreciate if it was considered for inclusion in newlib.

How was this tested?

Ever since this was checked in, my gcc autotester has rightly
refused to update its newlib.  In testing for an update, it
notices the bug as a regression in the gcc testcase
gfortran.dg/complex_intrinsic_5.f90, which calls cacos
0.0+0.76159415595576i and expects it to be 1.5707963267948966
-.70239670712987479i, with the bug causing it to be
1.5707963267948966+0i (well "obviously" the bug causes all
return values to have a zero imaginary part).  While the target
was cris-elf, I believe it should be visible on all newlib
platforms.  You could even use an ARM-based one but not use
-mthumb or use a gcc snapshot where the bug is fixed (or on PR
inspection, isn't exposed).

Speaking of the gcc bug, is this gcc PR47540?  Perhaps you could
make atonement by pinging Ian's gcc-patch, after testing? ;-)

Tested by running the gcc testsuite and noting the regression
gone.  Also spot-checked that I didn't get an ICE with arm-elf
and -O2 -g -mthumb -fno-builtin for the fixed code using r175559
of the 4.6 branch but then again that didn't happen for the
original code either (though the test-case in PR47540 ICEs).

Ok to commit?

	* libm/complex/cacos.c: Use temporaries and correct sequencing
	error in previous reordering change.

Index: newlib/libm/complex/cacos.c
===================================================================
RCS file: /cvs/src/src/newlib/libm/complex/cacos.c,v
retrieving revision 1.3
diff -u -p -r1.3 cacos.c
--- newlib/libm/complex/cacos.c	4 Nov 2010 18:27:13 -0000	1.3
+++ newlib/libm/complex/cacos.c	11 Jul 2011 08:28:39 -0000
@@ -80,10 +80,10 @@ QUICKREF
 double complex
 cacos(double complex z)
 {
-	double complex w;
+	double complex w, tmp0, tmp1;
 
-	w = casin(z);
-	w = M_PI_2 - creal(w);
-	w -= (cimag(w) * I);
+	tmp0 = casin(z);
+	tmp1 = M_PI_2 - creal(tmp0);
+	w = tmp1 - (cimag(tmp0) * I);
 	return w;
 }

brgds, H-P


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