diff options
author | Joseph Myers <joseph@codesourcery.com> | 2017-08-22 17:55:42 +0000 |
---|---|---|
committer | Joseph Myers <joseph@codesourcery.com> | 2017-08-22 17:55:42 +0000 |
commit | d9bef9c0a41bc3ca4036542cbf2a7d2d0cf60237 (patch) | |
tree | da821dc6e3782dfeed9df3151577b492aaa2afa2 /iconvdata | |
parent | 988f991b5069f09d793c887618e84a196b100416 (diff) | |
download | glibc-d9bef9c0a41bc3ca4036542cbf2a7d2d0cf60237.tar glibc-d9bef9c0a41bc3ca4036542cbf2a7d2d0cf60237.tar.gz glibc-d9bef9c0a41bc3ca4036542cbf2a7d2d0cf60237.tar.bz2 glibc-d9bef9c0a41bc3ca4036542cbf2a7d2d0cf60237.zip |
Fix tgmath.h handling of complex integers (bug 21684).
The tgmath.h macros return a real type not a complex type when an
argument is of complex integer type (a GNU extension) and there are no
arguments of complex floating type. It seems clear that just as real
integers are mapped to double for tgmath.h, so complex integers should
be mapped to _Complex double.
This patch implements such a mapping. The main complication in fixing
this bug is that the tgmath.h macros expand their arguments a large
number of times, resulting in exponential blowup of the size of the
expansion when calls to tgmath.h macros are used in the arguments of
such macros; it would be unfortunate for fixing a bug with a fairly
obscure extension to make the macros expand their arguments even more
times. Thus, this patch optimizes the definitions of the relevant
macros. __tgmath_real_type previously expanded its argument 7 times
and now expands it 3 times. __tgmath_complex_type, used in place of
__tgmath_real_type only for functions that might return either real or
complex types, not for complex functions that always return real types
or always return complex types, expands its argument 5 times. So the
sizes of the macro expansions from nested macro calls are
correspondingly reduced (remembering that each tgmath.h macro expands
__tgmath_real_type, or sometimes now __tgmath_complex_type, several
times).
Sometimes the real return type resulted from calling a complex
function and converting the result to a real type; sometimes it
resulted from calling a real function, because the logic for
determining whether arguments were real or complex, based on sizeof,
was confused by integer promotions applying to e.g. short int but not
_Complex short int. The relevant tests are converted to use a new
macro __expr_is_real, which, by calling __builtin_classify_type rather
than comparing the results of two calls to sizeof, also reduces the
number of times macros expand their arguments.
Although there are reductions in the number of times macros expand
their arguments, I do not consider this to fix bug 21660, since a
proper fix means each macro expanding its arguments only once (via
using new compiler features designed for that purpose).
Tested for x86_64.
[BZ #21684]
* math/tgmath.h (__floating_type): Simplify definitions.
(__real_integer_type): New macro.
(__complex_integer_type): Likewise.
(__expr_is_real): Likewise.
(__tgmath_real_type_sub): Update comment to describe handling of
complex types.
(__tgmath_complex_type_sub): New macro.
(__tgmath_complex_type): Likewise.
[__HAVE_FLOAT128 && __GLIBC_USE (IEC_60559_TYPES_EXT)]
(__TGMATH_CF128): Use __expr_is_real.
(__TGMATH_UNARY_REAL_IMAG): Use __tgmath_complex_type and
__expr_is_real.
(__TGMATH_BINARY_REAL_IMAG): Likewise.
(__TGMATH_UNARY_REAL_IMAG_RET_REAL): Use __expr_is_real.
* math/gen-tgmath-tests.py (Type.create_type): Create complex
integer types.
Diffstat (limited to 'iconvdata')
0 files changed, 0 insertions, 0 deletions