builtins.def (BUILT_IN_CONJ, [...]): Define.

* builtins.def (BUILT_IN_CONJ, BUILT_IN_CREAL, BUILT_IN_CIMAG):
	Define.
	* builtins.c (expand_builtin): Abort on BUILT_IN_CONJ,
	BUILT_IN_CREAL and BUILT_IN_CIMAG.
	* c-common.c (c_common_nodes_and_builtins): Create builtin conjf,
	conj, conjl, crealf, creal, creall, cimagf, cimag and cimagl.
	(expand_tree_builtin): Handle BUILT_IN_CONJ, BUILT_IN_CREAL and
	BUILT_IN_CIMAG.
	* extend.texi: Document these builtins.

testsuite:
	* gcc.c-torture/execute/builtin-complex-1.c: New test.

From-SVN: r38716
This commit is contained in:
Joseph Myers 2001-01-05 18:24:08 +00:00 committed by Joseph Myers
parent 604bb87de9
commit 341e3d1169
7 changed files with 288 additions and 4 deletions

View File

@ -1,3 +1,15 @@
2001-01-05 Joseph S. Myers <jsm28@cam.ac.uk>
* builtins.def (BUILT_IN_CONJ, BUILT_IN_CREAL, BUILT_IN_CIMAG):
Define.
* builtins.c (expand_builtin): Abort on BUILT_IN_CONJ,
BUILT_IN_CREAL and BUILT_IN_CIMAG.
* c-common.c (c_common_nodes_and_builtins): Create builtin conjf,
conj, conjl, crealf, creal, creall, cimagf, cimag and cimagl.
(expand_tree_builtin): Handle BUILT_IN_CONJ, BUILT_IN_CREAL and
BUILT_IN_CIMAG.
* extend.texi: Document these builtins.
2001-01-05 Daniel Berlin <dberlin@redhat.com>
* c-common.c (lang_get_alias_set): Say we know nothing of

View File

@ -3299,6 +3299,13 @@ expand_builtin (exp, target, subtarget, mode, ignore)
/* build_function_call changes these into ABS_EXPR. */
abort ();
case BUILT_IN_CONJ:
case BUILT_IN_CREAL:
case BUILT_IN_CIMAG:
/* expand_tree_builtin changes these into CONJ_EXPR, REALPART_EXPR
and IMAGPART_EXPR. */
abort ();
case BUILT_IN_SIN:
case BUILT_IN_COS:
/* Treat these like sqrt, but only if the user asks for them. */

View File

@ -1,6 +1,6 @@
/* This file contains the definitions and documentation for the
builtins used in the GNU compiler.
Copyright (C) 2000 Free Software Foundation, Inc.
Copyright (C) 2000, 2001 Free Software Foundation, Inc.
This file is part of GNU CC.
@ -22,6 +22,9 @@ Boston, MA 02111-1307, USA. */
DEF_BUILTIN(BUILT_IN_ALLOCA)
DEF_BUILTIN(BUILT_IN_ABS)
DEF_BUILTIN(BUILT_IN_FABS)
DEF_BUILTIN(BUILT_IN_CONJ)
DEF_BUILTIN(BUILT_IN_CREAL)
DEF_BUILTIN(BUILT_IN_CIMAG)
DEF_BUILTIN(BUILT_IN_FFS)
DEF_BUILTIN(BUILT_IN_DIV)
DEF_BUILTIN(BUILT_IN_LDIV)

View File

@ -5134,6 +5134,8 @@ c_common_nodes_and_builtins ()
tree void_ftype_any, void_ftype_int, int_ftype_any;
tree double_ftype_double, double_ftype_double_double;
tree float_ftype_float, ldouble_ftype_ldouble;
tree cfloat_ftype_cfloat, cdouble_ftype_cdouble, cldouble_ftype_cldouble;
tree float_ftype_cfloat, double_ftype_cdouble, ldouble_ftype_cldouble;
tree int_ftype_cptr_cptr_sizet, sizet_ftype_cstring_cstring;
tree int_ftype_cstring_cstring, string_ftype_string_cstring;
tree string_ftype_cstring_int, string_ftype_cstring_cstring;
@ -5358,6 +5360,32 @@ c_common_nodes_and_builtins ()
tree_cons (NULL_TREE, double_type_node,
double_endlink));
cfloat_ftype_cfloat
= build_function_type (complex_float_type_node,
tree_cons (NULL_TREE, complex_float_type_node,
endlink));
cdouble_ftype_cdouble
= build_function_type (complex_double_type_node,
tree_cons (NULL_TREE, complex_double_type_node,
endlink));
cldouble_ftype_cldouble
= build_function_type (complex_long_double_type_node,
tree_cons (NULL_TREE, complex_long_double_type_node,
endlink));
float_ftype_cfloat
= build_function_type (float_type_node,
tree_cons (NULL_TREE, complex_float_type_node,
endlink));
double_ftype_cdouble
= build_function_type (double_type_node,
tree_cons (NULL_TREE, complex_double_type_node,
endlink));
ldouble_ftype_cldouble
= build_function_type (long_double_type_node,
tree_cons (NULL_TREE, complex_long_double_type_node,
endlink));
int_ftype_int
= build_function_type (integer_type_node, int_endlink);
@ -5748,6 +5776,36 @@ c_common_nodes_and_builtins ()
builtin_function_2 ("__builtin_cosl", "cosl",
ldouble_ftype_ldouble, ldouble_ftype_ldouble,
BUILT_IN_COS, BUILT_IN_NORMAL, 1, 0, 0);
/* ISO C99 complex arithmetic functions. */
builtin_function_2 ("__builtin_conjf", "conjf",
cfloat_ftype_cfloat, cfloat_ftype_cfloat,
BUILT_IN_CONJ, BUILT_IN_NORMAL, 0, !flag_isoc99, 0);
builtin_function_2 ("__builtin_conj", "conj",
cdouble_ftype_cdouble, cdouble_ftype_cdouble,
BUILT_IN_CONJ, BUILT_IN_NORMAL, 0, !flag_isoc99, 0);
builtin_function_2 ("__builtin_conjl", "conjl",
cldouble_ftype_cldouble, cldouble_ftype_cldouble,
BUILT_IN_CONJ, BUILT_IN_NORMAL, 0, !flag_isoc99, 0);
builtin_function_2 ("__builtin_crealf", "crealf",
float_ftype_cfloat, float_ftype_cfloat,
BUILT_IN_CREAL, BUILT_IN_NORMAL, 0, !flag_isoc99, 0);
builtin_function_2 ("__builtin_creal", "creal",
double_ftype_cdouble, double_ftype_cdouble,
BUILT_IN_CREAL, BUILT_IN_NORMAL, 0, !flag_isoc99, 0);
builtin_function_2 ("__builtin_creall", "creall",
ldouble_ftype_cldouble, ldouble_ftype_cldouble,
BUILT_IN_CREAL, BUILT_IN_NORMAL, 0, !flag_isoc99, 0);
builtin_function_2 ("__builtin_cimagf", "cimagf",
float_ftype_cfloat, float_ftype_cfloat,
BUILT_IN_CIMAG, BUILT_IN_NORMAL, 0, !flag_isoc99, 0);
builtin_function_2 ("__builtin_cimag", "cimag",
double_ftype_cdouble, double_ftype_cdouble,
BUILT_IN_CIMAG, BUILT_IN_NORMAL, 0, !flag_isoc99, 0);
builtin_function_2 ("__builtin_cimagl", "cimagl",
ldouble_ftype_cldouble, ldouble_ftype_cldouble,
BUILT_IN_CIMAG, BUILT_IN_NORMAL, 0, !flag_isoc99, 0);
built_in_decls[BUILT_IN_PUTCHAR] =
builtin_function ("__builtin_putchar", int_ftype_int,
BUILT_IN_PUTCHAR, BUILT_IN_NORMAL, "putchar");
@ -5967,6 +6025,21 @@ expand_tree_builtin (function, params, coerced_params)
return integer_zero_node;
return build_unary_op (ABS_EXPR, TREE_VALUE (coerced_params), 0);
case BUILT_IN_CONJ:
if (coerced_params == 0)
return integer_zero_node;
return build_unary_op (CONJ_EXPR, TREE_VALUE (coerced_params), 0);
case BUILT_IN_CREAL:
if (coerced_params == 0)
return integer_zero_node;
return build_unary_op (REALPART_EXPR, TREE_VALUE (coerced_params), 0);
case BUILT_IN_CIMAG:
if (coerced_params == 0)
return integer_zero_node;
return build_unary_op (IMAGPART_EXPR, TREE_VALUE (coerced_params), 0);
case BUILT_IN_ISGREATER:
if (TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT)
code = UNLE_EXPR;

View File

@ -3357,9 +3357,18 @@ function as well.
@findex alloca
@findex bcmp
@findex bzero
@findex cimag
@findex cimagf
@findex cimagl
@findex conj
@findex conjf
@findex conjl
@findex cos
@findex cosf
@findex cosl
@findex creal
@findex crealf
@findex creall
@findex exit
@findex _exit
@findex fabs
@ -3424,9 +3433,10 @@ as builtins. Corresponding versions @code{__builtin_alloca},
@code{__builtin_rindex} and @code{__builtin_ffs} are also recognized in
strict ISO C mode.
The ISO C99 functions @code{llabs} and @code{imaxabs}
are handled as builtins except in
strict ISO C89 mode. There are also builtin versions of the ISO C99
The ISO C99 functions @code{conj}, @code{conjf}, @code{conjl},
@code{creal}, @code{crealf}, @code{creall}, @code{cimag}, @code{cimagf},
@code{cimagl}, @code{llabs} and @code{imaxabs} are handled as builtins
except in strict ISO C89 mode. There are also builtin versions of the ISO C99
functions @code{cosf}, @code{cosl}, @code{fabsf}, @code{fabsl},
@code{sinf}, @code{sinl}, @code{sqrtf}, and @code{sqrtl}, that are
recognized in any mode since ISO C89 reserves these names for the

View File

@ -1,3 +1,7 @@
2001-01-05 Joseph S. Myers <jsm28@cam.ac.uk>
* gcc.c-torture/execute/builtin-complex-1.c: New test.
2001-01-05 Nathan Sidwell <nathan@codesourcery.com>
* g++.old-deja/g++.pt/crash62.C: New test.

View File

@ -0,0 +1,175 @@
/* Test for builtin conj, creal, cimag. */
/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
extern float _Complex conjf (float _Complex);
extern double _Complex conj (double _Complex);
extern long double _Complex conjl (long double _Complex);
extern float crealf (float _Complex);
extern double creal (double _Complex);
extern long double creall (long double _Complex);
extern float cimagf (float _Complex);
extern double cimag (double _Complex);
extern long double cimagl (long double _Complex);
extern void abort (void);
extern void exit (int);
extern void link_failure (void);
int
main (void)
{
/* For each type, test both runtime and compile time (constant folding)
optimization. */
volatile float _Complex fc = 1.0F + 2.0iF;
volatile double _Complex dc = 1.0 + 2.0i;
volatile long double _Complex ldc = 1.0L + 2.0iL;
/* Test floats. */
if (conjf (fc) != 1.0F - 2.0iF)
abort ();
if (__builtin_conjf (fc) != 1.0F - 2.0iF)
abort ();
if (conjf (1.0F + 2.0iF) != 1.0F - 2.0iF)
link_failure ();
if (__builtin_conjf (1.0F + 2.0iF) != 1.0F - 2.0iF)
link_failure ();
if (crealf (fc) != 1.0F)
abort ();
if (__builtin_crealf (fc) != 1.0F)
abort ();
if (crealf (1.0F + 2.0iF) != 1.0F)
link_failure ();
if (__builtin_crealf (1.0F + 2.0iF) != 1.0F)
link_failure ();
if (cimagf (fc) != 2.0F)
abort ();
if (__builtin_cimagf (fc) != 2.0F)
abort ();
if (cimagf (1.0F + 2.0iF) != 2.0F)
link_failure ();
if (__builtin_cimagf (1.0F + 2.0iF) != 2.0F)
link_failure ();
/* Test doubles. */
if (conj (dc) != 1.0 - 2.0i)
abort ();
if (__builtin_conj (dc) != 1.0 - 2.0i)
abort ();
if (conj (1.0 + 2.0i) != 1.0 - 2.0i)
link_failure ();
if (__builtin_conj (1.0 + 2.0i) != 1.0 - 2.0i)
link_failure ();
if (creal (dc) != 1.0)
abort ();
if (__builtin_creal (dc) != 1.0)
abort ();
if (creal (1.0 + 2.0i) != 1.0)
link_failure ();
if (__builtin_creal (1.0 + 2.0i) != 1.0)
link_failure ();
if (cimag (dc) != 2.0)
abort ();
if (__builtin_cimag (dc) != 2.0)
abort ();
if (cimag (1.0 + 2.0i) != 2.0)
link_failure ();
if (__builtin_cimag (1.0 + 2.0i) != 2.0)
link_failure ();
/* Test long doubles. */
if (conjl (ldc) != 1.0L - 2.0iL)
abort ();
if (__builtin_conjl (ldc) != 1.0L - 2.0iL)
abort ();
if (conjl (1.0L + 2.0iL) != 1.0L - 2.0iL)
link_failure ();
if (__builtin_conjl (1.0L + 2.0iL) != 1.0L - 2.0iL)
link_failure ();
if (creall (ldc) != 1.0L)
abort ();
if (__builtin_creall (ldc) != 1.0L)
abort ();
if (creall (1.0L + 2.0iL) != 1.0L)
link_failure ();
if (__builtin_creall (1.0L + 2.0iL) != 1.0L)
link_failure ();
if (cimagl (ldc) != 2.0L)
abort ();
if (__builtin_cimagl (ldc) != 2.0L)
abort ();
if (cimagl (1.0L + 2.0iL) != 2.0L)
link_failure ();
if (__builtin_cimagl (1.0L + 2.0iL) != 2.0L)
link_failure ();
exit (0);
}
/* All the above cases should have been optimized to something else,
even if not optimizing (unless -fno-builtin was specified). So any
remaining calls to the original functions should abort. */
static float _Complex
conjf (float _Complex z)
{
abort ();
}
static double _Complex
conj (double _Complex z)
{
abort ();
}
static long double _Complex
conjl (long double _Complex z)
{
abort ();
}
static float
crealf (float _Complex z)
{
abort ();
}
static double
creal (double _Complex z)
{
abort ();
}
static long double
creall (long double _Complex z)
{
abort ();
}
static float
cimagf (float _Complex z)
{
abort ();
}
static double
cimag (double _Complex z)
{
abort ();
}
static long double
cimagl (long double _Complex z)
{
abort ();
}
/* When optimizing, all the constant cases should have been
constant folded, so no calls to link_failure should remain. In any case,
link_failure should not be called. */
#ifndef __OPTIMIZE__
void
link_failure (void)
{
abort ();
}
#endif