Skip to content

Commit

Permalink
[MSWin] Tentative measure for a bug of VS2022 [Misc #18362]
Browse files Browse the repository at this point in the history
Disable the use of `__assume()`, when combinations of `isnan()`,
`isinf()` and `__assume()` will be wrongly optimized due to the
bug of VS2022.
  • Loading branch information
nobu committed Feb 20, 2022
1 parent 32af1a3 commit ed8776f
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
2 changes: 2 additions & 0 deletions win32/Makefile.sub
Expand Up @@ -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
Expand Down
49 changes: 49 additions & 0 deletions win32/setup.mak
Expand Up @@ -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 <math.h>
#include <float.h>

#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
Expand Down

0 comments on commit ed8776f

Please sign in to comment.