From 6696da2f61946e7fdef18bd4ee96912120b8fc82 Mon Sep 17 00:00:00 2001 From: grischka Date: Sun, 23 Feb 2020 00:11:03 +0100 Subject: [PATCH] win32: long double as distinct C-type On windows. there is no long double really IOW it is the same as double. However setting the VT_LONG flag in combination with VT_DOUBLE allows to keep track of the original type for the purpose of '_Generic() or more accurate type warnings. --- tccgen.c | 5 +++-- tests/tests2/60_errors_and_warnings.c | 10 ++++++++++ tests/tests2/60_errors_and_warnings.expect | 3 +++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/tccgen.c b/tccgen.c index 18fbd6b8..efb37cfe 100644 --- a/tccgen.c +++ b/tccgen.c @@ -3244,7 +3244,8 @@ static void type_to_str(char *buf, int buf_size, goto add_tstr; case VT_DOUBLE: tstr = "double"; - goto add_tstr; + if (!(t & VT_LONG)) + goto add_tstr; case VT_LDOUBLE: tstr = "long double"; add_tstr: @@ -4589,7 +4590,7 @@ the_end: t |= LONG_SIZE == 8 ? VT_LLONG : VT_INT; #ifdef TCC_TARGET_PE if (bt == VT_LDOUBLE) - t = (t & ~(VT_BTYPE|VT_LONG)) | VT_DOUBLE; + t = (t & ~(VT_BTYPE|VT_LONG)) | (VT_DOUBLE|VT_LONG); #endif type->t = t; return type_found; diff --git a/tests/tests2/60_errors_and_warnings.c b/tests/tests2/60_errors_and_warnings.c index fcca6456..ac331ebb 100644 --- a/tests/tests2/60_errors_and_warnings.c +++ b/tests/tests2/60_errors_and_warnings.c @@ -308,5 +308,15 @@ void f2() { struct yyy y, *yy; struct zzz { int z; } z, *zz; +/******************************************************************/ +#elif defined test_long_double_type_for_win32 + +int main() +{ + double *a = 0; + long double *b = a; + int n = _Generic(*a, double:0, long double:1); +} + /******************************************************************/ #endif diff --git a/tests/tests2/60_errors_and_warnings.expect b/tests/tests2/60_errors_and_warnings.expect index dca874b6..838f6fcc 100644 --- a/tests/tests2/60_errors_and_warnings.expect +++ b/tests/tests2/60_errors_and_warnings.expect @@ -147,3 +147,6 @@ bar : 3 ; 3 60_errors_and_warnings.c:286: error: incompatible types for redefinition of 'xxx' [test_var_4] + +[test_long_double_type_for_win32] +60_errors_and_warnings.c:317: warning: assignment from incompatible pointer type