OpenSolaris

Printable Version Enter a New Search
Bug ID 6549313
Synopsis /usr/sfw/bin/gcc needs a patched complex.h
State 1-Dispatched (Default State)
Category:Subcategory utility:gnu_compiler
Keywords opensolaris
Reported Against snv_62
Duplicate Of
Introduced In
Commit to Fix
Fixed In
Release Fixed
Related Bugs
Submit Date 23-April-2007
Last Update Date 26-April-2007
Description
Category
   sfw
Sub-Category
   sec508
Description
   /usr/sfw/bin/gcc needs a patched complex.h header.
_Complex_I is undeclared.
Problem with /opt/gcc/bin/gcc as well.
Frequency
   Always
Regression
   No
Steps to Reproduce
   Try to build guile-1.8.1.
It has a test for csqrt which fails, but would not if complex.h supported gcc.
See below for conftest.c
Expected Result
   gcc -o conftest conftest.c -lm
echo $status
0
./conftest
echo $status
0
Actual Result
   gcc -o conftest conftest.c -lm
conftest.c:6: error: `_Complex_I' undeclared here (not in a function)
echo $status
1
Error Message(s)
   conftest.c:6: error: `_Complex_I' undeclared here (not in a function)
Test Case
   /*
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
This file is part of GUILE
GUILE is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your
option) any later version.
GUILE is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GUILE; see the file COPYING.  If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <complex.h>
/*
 * "volatile" is meant to prevent gcc from calculating the sqrt as a
 * constant, we want to test libc.
 */
volatile complex double z = -_Complex_I;
int
main(void)
{
        z = csqrt(z);
        if (creal(z) > 0.0)
                return 0;       /* good */
        else
                return 1;       /* bad */
}
Workaround
   #!/bin/sh
cp -p /usr/include/complex.h /tmp/complex.h
gpatch /tmp/complex.h <<\EOF
--- /usr/include/complex.h      Mon Nov 27 18:53:43 2006
+++ /usr/sfw/lib/gcc/sparc-sun-solaris2.11/3.4.3/include/complex.h      Mon Feb 26 01:55:55 2007
@@ -34,13 +34,24 @@
  * Compilation environments for Solaris must provide the _Imaginary datatype
  * and the compiler intrinsics _Complex_I and _Imaginary_I
  */
-#define        _Complex_I      _Complex_I
+
+/* ISO C99 has types `float complex' and `double complex'.  */
 #define        complex         _Complex
-#define        _Imaginary_I    _Imaginary_I
-#define        imaginary       _Imaginary
+
+/* Use the smaller imaginary unit `float complex' constant  1.0fi,
+   instead of `double complex' constant 1.0i.  */
+#define        _Complex_I      (__extension__ 1.0fi)
+
+/* Another more descriptive name is `I'.  */
 #undef I
-#define        I               _Imaginary_I
+/* Once there is imaginary support in gcc, use it.  */
+#define        I               _Complex_I
+
+typedef        float _Complex  _Imaginary;
+#define        imaginary       _Imaginary
+#define        _Imaginary_I    (__extension__ 1.0fi)
+
 extern float cabsf(float complex);
 extern float cargf(float complex);
 extern float cimagf(float complex);
EOF
installf SUNWgcc /usr/sfw/lib/gcc/sparc-sun-solaris2.11/3.4.3/include/complex.h f 0644 root bin
cp -p /tmp/complex.h /usr/sfw/lib/gcc/sparc-sun-solaris2.11/3.4.3/include/complex.h
installf -f SUNWgcc
installf SUNW0gccfss /opt/gcc/lib/gcc/sparc-sun-solaris2.9/4.0.3/include/complex.h f 0644 root sys
installf SUNW0gccfss /opt/gcc/lib/gcc/sparc-sun-solaris2.10/4.0.3/include/complex.h f 0644 root sys
cp -p /tmp/complex.h /opt/gcc/lib/gcc/sparc-sun-solaris2.9/4.0.3/include/complex.h
cp -p /tmp/complex.h /opt/gcc/lib/gcc/sparc-sun-solaris2.10/4.0.3/include/complex.h
installf -f SUNW0gccfss
Submitter wants to work on bug
   No
Additional configuration information
   Packages SUNWgcc, SUNWgccruntime, SUNW0gccfss, and SUNWlibm are installed.
Work Around
N/A
Comments
N/A
  Add Yourself to the Interest List