1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-12-24 17:51:17 +03:00

Fix tgmath.h for bit-fields (bug 21685).

The tgmath.h macros produce errors for bit-field arguments, because
they apply sizeof and typeof to the arguments.  This patch fixes them
to use unary + systematically before using sizeof or typeof on
arguments that might be bit-fields (note that __real__ of a bit-field
is still a bit-field for this purpose, since it's an lvalue).
gen-tgmath-tests.py is extended to add tests for this case.

Tested for x86_64.

	[BZ #21685]
	* math/tgmath.h (__tgmath_real_type): Use unary + on potentially
	bit-field expressions passed to sizeof or typeof.
	[__HAVE_FLOAT128 && __GLIBC_USE (IEC_60559_TYPES_EXT)]
	(__TGMATH_F128): Likewise.
	[__HAVE_FLOAT128 && __GLIBC_USE (IEC_60559_TYPES_EXT)]
	(__TGMATH_CF128): Likewise.
	(__TGMATH_UNARY_REAL_ONLY): Likewise.
	(__TGMATH_UNARY_REAL_RET_ONLY): Likewise.
	(__TGMATH_BINARY_FIRST_REAL_ONLY): Likewise.
	(__TGMATH_BINARY_FIRST_REAL_STD_ONLY): Likewise.
	(__TGMATH_BINARY_REAL_ONLY): Likewise.
	(__TGMATH_BINARY_REAL_STD_ONLY): Likewise.
	(__TGMATH_BINARY_REAL_RET_ONLY): Likewise.
	(__TGMATH_TERNARY_FIRST_SECOND_REAL_ONLY): Likewise.
	(__TGMATH_TERNARY_REAL_ONLY): Likewise.
	(__TGMATH_TERNARY_FIRST_REAL_RET_ONLY): Likewise.
	(__TGMATH_UNARY_REAL_IMAG): Likewise.
	(__TGMATH_UNARY_IMAG): Likewise.
	(__TGMATH_UNARY_REAL_IMAG_RET_REAL): Likewise.
	(__TGMATH_BINARY_REAL_IMAG): Likewise.
	* math/gen-tgmath-tests.py (Type.init_types): Create bit_field
	type.
	(define_vars_for_type): Handle bit_field type specially.
	(Tests.__init__): Declare structure with bit-field element.
This commit is contained in:
Joseph Myers
2017-08-02 16:09:01 +00:00
parent b358255f95
commit 2fee621de0
3 changed files with 98 additions and 60 deletions

View File

@@ -197,6 +197,7 @@ class Type(object):
Type.create_type('unsigned long long int', integer=True)
Type.create_type('enum e', integer=True, complex_ok=False)
Type.create_type('_Bool', integer=True, complex_ok=False)
Type.create_type('bit_field', integer=True, complex_ok=False)
# Internal types represent the combination of long double with
# _Float64 or _Float64x, for which the ordering depends on
# whether long double has the same format as double.
@@ -273,6 +274,11 @@ def vol_var_for_type(name):
def define_vars_for_type(name):
"""Return the definitions of variables with a given type (name)."""
if name == 'bit_field':
struct_vars = define_vars_for_type('struct s');
return '%s#define %s %s.bf\n' % (struct_vars,
vol_var_for_type(name),
vol_var_for_type('struct s'))
return ('%s %s __attribute__ ((unused));\n'
'%s volatile %s __attribute__ ((unused));\n'
% (name, var_for_type(name), name, vol_var_for_type(name)))
@@ -311,7 +317,11 @@ class Tests(object):
'int num_pass, num_fail;\n'
'volatile int called_mant_dig;\n'
'const char *volatile called_func_name;\n'
'enum e { E, F };\n']
'enum e { E, F };\n'
'struct s\n'
' {\n'
' int bf:2;\n'
' };\n']
float64_text = ('# if LDBL_MANT_DIG == DBL_MANT_DIG\n'
'typedef _Float64 long_double_Float64;\n'
'typedef __CFLOAT64 complex_long_double_Float64;\n'