From ed8776f96034b245b5418d4817d0ebda3db24198 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sat, 12 Feb 2022 23:29:19 +0900 Subject: [MSWin] Tentative measure for a bug of VS2022 [Misc #18362] Disable the use of `__assume()`, when combinations of `isnan()`, `isinf()` and `__assume()` will be wrongly optimized due to the bug of VS2022. --- win32/Makefile.sub | 2 ++ win32/setup.mak | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) (limited to 'win32') diff --git a/win32/Makefile.sub b/win32/Makefile.sub index 2b4bebac48..47a3dcfd5e 100644 --- a/win32/Makefile.sub +++ b/win32/Makefile.sub @@ -702,7 +702,9 @@ $(CONFIG_H): $(MKFILES) $(srcdir)/win32/Makefile.sub $(win_srcdir)/Makefile.sub #define ALWAYS_INLINE(x) __forceinline x #define WARN_UNUSED_RESULT(x) x #define MAYBE_UNUSED(x) x +!if !defined(VS2022_FP_BUG) #define HAVE___ASSUME 1 +!endif #define FUNC_STDCALL(x) __stdcall x #define FUNC_CDECL(x) __cdecl x #define FUNC_FASTCALL(x) __fastcall x diff --git a/win32/setup.mak b/win32/setup.mak index 4ed112294d..466c1ef515 100644 --- a/win32/setup.mak +++ b/win32/setup.mak @@ -123,6 +123,55 @@ int main(void) {FILE *volatile f = stdin; return 0;} -headers-: nul +-headers-: vs2022-fp-bug + +# Check the bug reported at: +# https://developercommunity.visualstudio.com/t/With-__assume-isnan-after-isinf/1515649 +# https://developercommunity.visualstudio.com/t/Prev-Issue---with-__assume-isnan-/1597317 +vs2022-fp-bug: + @echo checking for $(@:-= ) + @echo <<$@.c > NUL +/* compile with -O2 */ +#include +#include + +#define value_finite(d) 'f' +#define value_infinity() 'i' +#define value_nan() 'n' + +#ifdef NO_ASSUME +# define ASSUME_TRUE() (void)0 +#else +# define ASSUME_TRUE() __assume(1) +#endif + +static int +check_value(double value) +{ + if (isinf(value)) { + return value_infinity(); + } + else if (isnan(value)) { + return value_nan(); + } + + ASSUME_TRUE(); + return value_finite(value); +} + +int +main(void) +{ + int c = check_value(nan("")); + printf("NaN=>%c\n", c); + return c != value_nan(); +} +<< + @( \ + ($(CC) -O2 -DNO_ASSUME $@.c && .\$@ && $(CC) -O2 $@.c) && \ + (.\$@ || echo>>$(MAKEFILE) VS2022_FP_BUG=1) \ + ) & $(WIN32DIR:/=\)\rm.bat $@.* + -version-: nul verconf.mk verconf.mk: nul -- cgit v1.2.3