summaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorgeoffk <geoffk@138bc75d-0d04-0410-961f-82ee72b054a4>2007-07-13 06:12:51 +0000
committergeoffk <geoffk@138bc75d-0d04-0410-961f-82ee72b054a4>2007-07-13 06:12:51 +0000
commit50388ca3231d2219dd81d1b840dc1581671fe7cf (patch)
tree5725393fda59464c6afb4405cdb5de32243d799e /gcc
parentb47f1d9300e4bbe061b1b0f1662a7e7ae3937d0a (diff)
downloadgcc-50388ca3231d2219dd81d1b840dc1581671fe7cf.tar.gz
Index: gcc/ChangeLog
2007-07-12 Geoffrey Keating <geoffk@apple.com> * ginclude/tgmath.h: New. * config.gcc: Use GCC's tgmath.h on non-glibc systems. * doc/sourcebuild.texi (Headers): Document use_gcc_tgmath. * configure.ac (STMP_FIXPROTO): Honor use_gcc_tgmath. * configure: Regenerate. Index: gcc/testsuite/ChangeLog 2007-07-11 Geoffrey Keating <geoffk@apple.com> * gcc.dg/c99-tgmath-1.c: New. * gcc.dg/c99-tgmath-2.c: New. * gcc.dg/c99-tgmath-3.c: New. * gcc.dg/c99-tgmath-4.c: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@126613 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog8
-rw-r--r--gcc/config.gcc6
-rwxr-xr-xgcc/configure5
-rw-r--r--gcc/configure.ac5
-rw-r--r--gcc/doc/sourcebuild.texi3
-rw-r--r--gcc/ginclude/tgmath.h174
-rw-r--r--gcc/testsuite/ChangeLog7
-rw-r--r--gcc/testsuite/gcc.dg/c99-tgmath-1.c247
-rw-r--r--gcc/testsuite/gcc.dg/c99-tgmath-2.c14
-rw-r--r--gcc/testsuite/gcc.dg/c99-tgmath-3.c14
-rw-r--r--gcc/testsuite/gcc.dg/c99-tgmath-4.c14
11 files changed, 497 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 924fc03da57..462bbb0d0ab 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,11 @@
+2007-07-12 Geoffrey Keating <geoffk@apple.com>
+
+ * ginclude/tgmath.h: New.
+ * config.gcc: Use GCC's tgmath.h on non-glibc systems.
+ * doc/sourcebuild.texi (Headers): Document use_gcc_tgmath.
+ * configure.ac (STMP_FIXPROTO): Honor use_gcc_tgmath.
+ * configure: Regenerate.
+
2007-07-13 Kaz Kojima <kkojima@gcc.gnu.org>
* config/sh/linux-unwind.h (sh_fallback_frame_state): Use
diff --git a/gcc/config.gcc b/gcc/config.gcc
index 38ba1dfee88..085222e297f 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -98,6 +98,9 @@
# extra_headers List of used header files from the directory
# config/${cpu_type}.
#
+# use_gcc_tgmath If set, add tgmath.h to the list of used header
+# files.
+#
# extra_passes List of extra executables compiled for this target
# machine, used for compiling from source to object.
#
@@ -156,6 +159,7 @@
out_file=
tmake_file=
extra_headers=
+use_gcc_tgmath=yes
extra_passes=
extra_parts=
extra_programs=
@@ -493,6 +497,7 @@ case ${target} in
esac
# Assume that glibc or uClibc are being used and so __cxa_atexit is provided.
default_use_cxa_atexit=yes
+ use_gcc_tgmath=no
;;
*-*-gnu*)
# On the Hurd, the setup is just about the same on
@@ -516,6 +521,7 @@ case ${target} in
esac
# Assume that glibc is being used and so __cxa_atexit is provided.
default_use_cxa_atexit=yes
+ use_gcc_tgmath=no
;;
*-*-netbsd*)
tmake_file="t-slibgcc-elf-ver t-libc-ok t-netbsd t-libgcc-pic"
diff --git a/gcc/configure b/gcc/configure
index d317039a142..1b72cdb9442 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -13202,6 +13202,11 @@ for file in ${extra_headers} ; do
extra_headers_list="${extra_headers_list} \$(srcdir)/config/${cpu_type}/${file}"
done
+# If use_gcc_tgmath is set, append ginclude/tgmath.h.
+if test x"$use_gcc_tgmath" = xyes
+then extra_headers_list="${extra_headers_list} \$(srcdir)/ginclude/tgmath.h"
+fi
+
# Define collect2 in Makefile.
case $host_can_use_collect2 in
no) collect2= ;;
diff --git a/gcc/configure.ac b/gcc/configure.ac
index 5a65f894456..33d9518491e 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -1739,6 +1739,11 @@ for file in ${extra_headers} ; do
extra_headers_list="${extra_headers_list} \$(srcdir)/config/${cpu_type}/${file}"
done
+# If use_gcc_tgmath is set, append ginclude/tgmath.h.
+if test x"$use_gcc_tgmath" = xyes
+then extra_headers_list="${extra_headers_list} \$(srcdir)/ginclude/tgmath.h"
+fi
+
# Define collect2 in Makefile.
case $host_can_use_collect2 in
no) collect2= ;;
diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi
index 780653a6e89..fc564908efb 100644
--- a/gcc/doc/sourcebuild.texi
+++ b/gcc/doc/sourcebuild.texi
@@ -301,6 +301,9 @@ such as POSIX specify additional values to be defined in
@file{gsyslimits.h} if it does not need fixing to work with GCC; if it
needs fixing, @file{syslimits.h} is the fixed copy.
+GCC can also install @code{<tgmath.h>}. It will do this when
+@file{config.gcc} sets @code{use_gcc_tgmath} to @code{yes}.
+
@node Documentation
@subsection Building Documentation
diff --git a/gcc/ginclude/tgmath.h b/gcc/ginclude/tgmath.h
new file mode 100644
index 00000000000..2327556f1a6
--- /dev/null
+++ b/gcc/ginclude/tgmath.h
@@ -0,0 +1,174 @@
+/* Copyright (C) 2004, 2005 Free Software Foundation, Inc.
+ Contributed by Apple, Inc.
+
+This file is part of GCC.
+
+GCC 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.
+
+GCC 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 GCC; see the file COPYING. If not, write to
+the Free Software Foundation, 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA. */
+
+/* As a special exception, if you include this header file into source
+ files compiled by GCC, this header file does not by itself cause
+ the resulting executable to be covered by the GNU General Public
+ License. This exception does not however invalidate any other
+ reasons why the executable file might be covered by the GNU General
+ Public License. */
+
+/*
+ * ISO C Standard: 7.22 Type-generic math <tgmath.h>
+ */
+
+#ifndef _TGMATH_H
+#define _TGMATH_H
+
+#include <math.h>
+
+#ifndef __cplusplus
+#include <complex.h>
+
+/* Naming convention: generic macros are defining using
+ __TGMATH_CPLX*, __TGMATH_REAL*, and __TGMATH_CPLX_ONLY. _CPLX
+ means the generic argument(s) may be real or complex, _REAL means
+ real only, _CPLX means complex only. If there is no suffix, we are
+ defining a function of one generic argument. If the suffix is _n
+ it is a function of n generic arguments. If the suffix is _m_n it
+ is a function of n arguments, the first m of which are generic. We
+ only define these macros for values of n and/or m that are needed. */
+
+/* The general rules for generic macros are given in 7.22 paragraphs 1 and 2.
+ If any generic parameter is complex, we use a complex version. Otherwise
+ we use a real version. If the real part of any generic parameter is long
+ double, we use the long double version. Otherwise if the real part of any
+ generic paramter is double or of integer type, we use the double version.
+ Otherwise we use the float version. */
+
+#define __tg_cplx(expr) \
+ __builtin_classify_type(expr) == 9
+
+#define __tg_ldbl(expr) \
+ __builtin_types_compatible_p(__typeof__(expr), long double)
+
+#define __tg_dbl(expr) \
+ (__builtin_types_compatible_p(__typeof__(expr), double) \
+ || __builtin_classify_type(expr) == 1)
+
+#define __tg_choose(x,f,d,l) \
+ __builtin_choose_expr(__tg_ldbl(x), l, \
+ __builtin_choose_expr(__tg_dbl(x), d, \
+ f))
+
+#define __tg_choose_2(x,y,f,d,l) \
+ __builtin_choose_expr(__tg_ldbl(x) || __tg_ldbl(y), l, \
+ __builtin_choose_expr(__tg_dbl(x) || __tg_dbl(y), d, \
+ f))
+
+#define __tg_choose_3(x,y,z,f,d,l) \
+ __builtin_choose_expr(__tg_ldbl(x) || __tg_ldbl(y) || __tg_ldbl(z), l, \
+ __builtin_choose_expr(__tg_dbl(x) || __tg_dbl(y) \
+ || __tg_dbl(z), d, \
+ f))
+
+#define __TGMATH_CPLX(z,R,C) \
+ __builtin_choose_expr (__tg_cplx(z), \
+ __tg_choose (__real__(z), C##f(z), (C)(z), C##l(z)), \
+ __tg_choose (z, R##f(z), (R)(z), R##l(z)))
+
+#define __TGMATH_CPLX_2(z1,z2,R,C) \
+ __builtin_choose_expr (__tg_cplx(z1) || __tg_cplx(z2), \
+ __tg_choose_2 (__real__(z1), __real__(z2), \
+ C##f(z1,z2), (C)(z1,z2), C##l(z1,z2)), \
+ __tg_choose_2 (z1, z2, \
+ R##f(z1,z2), (R)(z1,z2), R##l(z1,z2)))
+
+#define __TGMATH_REAL(x,R) \
+ __tg_choose (x, R##f(x), (R)(x), R##l(x))
+#define __TGMATH_REAL_2(x,y,R) \
+ __tg_choose_2 (x, y, R##f(x,y), (R)(x,y), R##l(x,y))
+#define __TGMATH_REAL_3(x,y,z,R) \
+ __tg_choose_3 (x, y, z, R##f(x,y,z), (R)(x,y,z), R##l(x,y,z))
+#define __TGMATH_REAL_1_2(x,y,R) \
+ __tg_choose (x, R##f(x,y), (R)(x,y), R##l(x,y))
+#define __TGMATH_REAL_2_3(x,y,z,R) \
+ __tg_choose_2 (x, y, R##f(x,y,z), (R)(x,y,z), R##l(x,y,z))
+#define __TGMATH_CPLX_ONLY(z,C) \
+ __tg_choose (__real__(z), C##f(z), (C)(z), C##l(z))
+
+/* Functions defined in both <math.h> and <complex.h> (7.22p4) */
+#define acos(z) __TGMATH_CPLX(z, acos, cacos)
+#define asin(z) __TGMATH_CPLX(z, asin, casin)
+#define atan(z) __TGMATH_CPLX(z, atan, catan)
+#define acosh(z) __TGMATH_CPLX(z, acosh, cacosh)
+#define asinh(z) __TGMATH_CPLX(z, asinh, casinh)
+#define atanh(z) __TGMATH_CPLX(z, atanh, catanh)
+#define cos(z) __TGMATH_CPLX(z, cos, ccos)
+#define sin(z) __TGMATH_CPLX(z, sin, csin)
+#define tan(z) __TGMATH_CPLX(z, tan, ctan)
+#define cosh(z) __TGMATH_CPLX(z, cosh, ccosh)
+#define sinh(z) __TGMATH_CPLX(z, sinh, csinh)
+#define tanh(z) __TGMATH_CPLX(z, tanh, ctanh)
+#define exp(z) __TGMATH_CPLX(z, exp, cexp)
+#define log(z) __TGMATH_CPLX(z, log, clog)
+#define pow(z1,z2) __TGMATH_CPLX_2(z1, z2, pow, cpow)
+#define sqrt(z) __TGMATH_CPLX(z, sqrt, csqrt)
+#define fabs(z) __TGMATH_CPLX(z, fabs, cabs)
+
+/* Functions defined in <math.h> only (7.22p5) */
+#define atan2(x,y) __TGMATH_REAL_2(x, y, atan2)
+#define cbrt(x) __TGMATH_REAL(x, cbrt)
+#define ceil(x) __TGMATH_REAL(x, ceil)
+#define copysign(x,y) __TGMATH_REAL_2(x, y, copysign)
+#define erf(x) __TGMATH_REAL(x, erf)
+#define erfc(x) __TGMATH_REAL(x, erfc)
+#define exp2(x) __TGMATH_REAL(x, exp2)
+#define expm1(x) __TGMATH_REAL(x, expm1)
+#define fdim(x,y) __TGMATH_REAL_2(x, y, fdim)
+#define floor(x) __TGMATH_REAL(x, floor)
+#define fma(x,y,z) __TGMATH_REAL_3(x, y, z, fma)
+#define fmax(x,y) __TGMATH_REAL_2(x, y, fmax)
+#define fmin(x,y) __TGMATH_REAL_2(x, y, fmin)
+#define fmod(x,y) __TGMATH_REAL_2(x, y, fmod)
+#define frexp(x,y) __TGMATH_REAL_1_2(x, y, frexp)
+#define hypot(x,y) __TGMATH_REAL_2(x, y, hypot)
+#define ilogb(x) __TGMATH_REAL(x, ilogb)
+#define ldexp(x,y) __TGMATH_REAL_1_2(x, y, ldexp)
+#define lgamma(x) __TGMATH_REAL(x, lgamma)
+#define llrint(x) __TGMATH_REAL(x, llrint)
+#define llround(x) __TGMATH_REAL(x, llround)
+#define log10(x) __TGMATH_REAL(x, log10)
+#define log1p(x) __TGMATH_REAL(x, log1p)
+#define log2(x) __TGMATH_REAL(x, log2)
+#define logb(x) __TGMATH_REAL(x, logb)
+#define lrint(x) __TGMATH_REAL(x, lrint)
+#define lround(x) __TGMATH_REAL(x, lround)
+#define nearbyint(x) __TGMATH_REAL(x, nearbyint)
+#define nextafter(x,y) __TGMATH_REAL_2(x, y, nextafter)
+#define nexttoward(x,y) __TGMATH_REAL_1_2(x, y, nexttoward)
+#define remainder(x,y) __TGMATH_REAL_2(x, y, remainder)
+#define remquo(x,y,z) __TGMATH_REAL_2_3(x, y, z, remquo)
+#define rint(x) __TGMATH_REAL(x, rint)
+#define round(x) __TGMATH_REAL(x, round)
+#define scalbn(x,y) __TGMATH_REAL_1_2(x, y, scalbn)
+#define scalbln(x,y) __TGMATH_REAL_1_2(x, y, scalbln)
+#define tgamma(x) __TGMATH_REAL(x, tgamma)
+#define trunc(x) __TGMATH_REAL(x, trunc)
+
+/* Functions defined in <complex.h> only (7.22p6) */
+#define carg(z) __TGMATH_CPLX_ONLY(z, carg)
+#define cimag(z) __TGMATH_CPLX_ONLY(z, cimag)
+#define conj(z) __TGMATH_CPLX_ONLY(z, conj)
+#define cproj(z) __TGMATH_CPLX_ONLY(z, cproj)
+#define creal(z) __TGMATH_CPLX_ONLY(z, creal)
+
+#endif /* __cplusplus */
+#endif /* _TGMATH_H */
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index a6e15963d1b..e6a5cf411ab 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,10 @@
+2007-07-12 Geoffrey Keating <geoffk@apple.com>
+
+ * gcc.dg/c99-tgmath-1.c: New.
+ * gcc.dg/c99-tgmath-2.c: New.
+ * gcc.dg/c99-tgmath-3.c: New.
+ * gcc.dg/c99-tgmath-4.c: New.
+
2007-07-12 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
Janis Johnson <janis187@us.ibm.com>
diff --git a/gcc/testsuite/gcc.dg/c99-tgmath-1.c b/gcc/testsuite/gcc.dg/c99-tgmath-1.c
new file mode 100644
index 00000000000..bef6ab1b918
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c99-tgmath-1.c
@@ -0,0 +1,247 @@
+/* Test for <tgmath.h> in C99. */
+/* Origin: Matt Austern <austern@apple.com>
+/* { dg-do preprocess } */
+/* { dg-options "-std=iso9899:1999" } */
+
+/* Test that tgmath defines the macros it's supposed to. */
+#include <tgmath.h>
+
+#ifndef acos
+#error acos undefined
+#endif
+
+#ifndef asin
+#error asin undefined
+#endif
+
+#ifndef atan
+#error atan undefined
+#endif
+
+#ifndef acosh
+#error acosh undefined
+#endif
+
+#ifndef asinh
+#error asinh undefined
+#endif
+
+#ifndef atanh
+#error atanh undefined
+#endif
+
+#ifndef cos
+#error cos undefined
+#endif
+
+#ifndef sin
+#error sin undefined
+#endif
+
+#ifndef tan
+#error tan undefined
+#endif
+
+#ifndef cosh
+#error cosh undefined
+#endif
+
+#ifndef sinh
+#error sinh undefined
+#endif
+
+#ifndef tanh
+#error tanh undefined
+#endif
+
+#ifndef exp
+#error exp undefined
+#endif
+
+#ifndef log
+#error log undefined
+#endif
+
+#ifndef pow
+#error pow undefined
+#endif
+
+#ifndef sqrt
+#error sqrt undefined
+#endif
+
+#ifndef fabs
+#error fabs undefined
+#endif
+
+#ifndef atan2
+#error atan2 undefined
+#endif
+
+#ifndef cbrt
+#error cbrt undefined
+#endif
+
+#ifndef ceil
+#error ceil undefined
+#endif
+
+#ifndef copysign
+#error copysign undefined
+#endif
+
+#ifndef erf
+#error erf undefined
+#endif
+
+#ifndef erfc
+#error erfc undefined
+#endif
+
+#ifndef exp2
+#error exp2 undefined
+#endif
+
+#ifndef expm1
+#error expm1 undefined
+#endif
+
+#ifndef fdim
+#error fdim undefined
+#endif
+
+#ifndef floor
+#error floor undefined
+#endif
+
+#ifndef fma
+#error fma undefined
+#endif
+
+#ifndef fmax
+#error fmax undefined
+#endif
+
+#ifndef fmin
+#error fmin undefined
+#endif
+
+#ifndef fmod
+#error fmod undefined
+#endif
+
+#ifndef frexp
+#error frexp undefined
+#endif
+
+#ifndef hypot
+#error hypot undefined
+#endif
+
+#ifndef ilogb
+#error ilogb undefined
+#endif
+
+#ifndef ldexp
+#error ldexp undefined
+#endif
+
+#ifndef lgamma
+#error lgamma undefined
+#endif
+
+#ifndef llrint
+#error llrint undefined
+#endif
+
+#ifndef llround
+#error llround undefined
+#endif
+
+#ifndef log10
+#error log10 undefined
+#endif
+
+#ifndef log1p
+#error log1p undefined
+#endif
+
+#ifndef log2
+#error log2 undefined
+#endif
+
+#ifndef logb
+#error logb undefined
+#endif
+
+#ifndef lrint
+#error lrint undefined
+#endif
+
+#ifndef lround
+#error lround undefined
+#endif
+
+#ifndef nearbyint
+#error nearbyint undefined
+#endif
+
+#ifndef nextafter
+#error nextafter undefined
+#endif
+
+#ifndef nexttoward
+#error nexttoward undefined
+#endif
+
+#ifndef remainder
+#error remainder undefined
+#endif
+
+#ifndef remquo
+#error remquo undefined
+#endif
+
+#ifndef rint
+#error rint undefined
+#endif
+
+#ifndef round
+#error round undefined
+#endif
+
+#ifndef scalbn
+#error scalbn undefined
+#endif
+
+#ifndef scalbln
+#error scalbln undefined
+#endif
+
+#ifndef tgamma
+#error tgamma undefined
+#endif
+
+#ifndef trunc
+#error trunc undefined
+#endif
+
+#ifndef carg
+#error carg undefined
+#endif
+
+#ifndef cimag
+#error cimag undefined
+#endif
+
+#ifndef conj
+#error conj undefined
+#endif
+
+#ifndef cproj
+#error cproj undefined
+#endif
+
+#ifndef creal
+#error creal undefined
+#endif
diff --git a/gcc/testsuite/gcc.dg/c99-tgmath-2.c b/gcc/testsuite/gcc.dg/c99-tgmath-2.c
new file mode 100644
index 00000000000..d162d4ac9ad
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c99-tgmath-2.c
@@ -0,0 +1,14 @@
+/* Test for <tgmath.h> in C99. */
+/* Origin: Matt Austern <austern@apple.com>
+/* { dg-do compile } */
+/* { dg-options "-std=iso9899:1999" } */
+
+/* Test that invoking type-generic sin on a float invokes sinf. */
+#include <tgmath.h>
+
+float foo(float x)
+{
+ return sin(x);
+}
+
+/* {dg-final {scan-assembler "sinf" } } */
diff --git a/gcc/testsuite/gcc.dg/c99-tgmath-3.c b/gcc/testsuite/gcc.dg/c99-tgmath-3.c
new file mode 100644
index 00000000000..4d0de1ee56b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c99-tgmath-3.c
@@ -0,0 +1,14 @@
+/* Test for <tgmath.h> in C99. */
+/* Origin: Matt Austern <austern@apple.com>
+/* { dg-do compile } */
+/* { dg-options "-std=iso9899:1999" } */
+
+/* Test that invoking type-generic exp on a complex invokes cexp. */
+#include <tgmath.h>
+
+complex double foo(complex double x)
+{
+ return exp(x);
+}
+
+/* {dg-final {scan-assembler "cexp" } } */
diff --git a/gcc/testsuite/gcc.dg/c99-tgmath-4.c b/gcc/testsuite/gcc.dg/c99-tgmath-4.c
new file mode 100644
index 00000000000..e9e490bdec7
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c99-tgmath-4.c
@@ -0,0 +1,14 @@
+/* Test for <tgmath.h> in C99. */
+/* Origin: Matt Austern <austern@apple.com>
+/* { dg-do compile } */
+/* { dg-options "-std=iso9899:1999" } */
+
+/* Test that invoking type-generic pow on complex float invokes cpowf. */
+#include <tgmath.h>
+
+complex double foo(complex float x, float y)
+{
+ return pow(x, y);
+}
+
+/* {dg-final {scan-assembler "cpowf" } } */