mirror of
https://github.com/neovim/neovim.git
synced 2025-01-01 17:23:36 -07:00
build: Fix -Wconversion warnings for fpclassify et al
closes #8274 - Instead of #undef and re-#define, define "xfoo" wrappers to avoid include-order sensitivity. - The warnings are bogus, caused by bad interaction between glibc and clang 6+. - https://bugs.llvm.org/show_bug.cgi?id=35268 - https://bugs.llvm.org/show_bug.cgi?id=39738 - https://bugzilla.redhat.com/show_bug.cgi?id=1472437
This commit is contained in:
parent
53c0f0bba5
commit
c6a039d087
@ -258,6 +258,19 @@ int main(void)
|
||||
}
|
||||
" HAVE_BUILTIN_ADD_OVERFLOW)
|
||||
|
||||
set(CMAKE_REQUIRED_LIBRARIES m)
|
||||
check_c_source_compiles("
|
||||
#include <math.h>
|
||||
int main(void)
|
||||
{
|
||||
double d = 1.0;
|
||||
int ok = (FP_NORMAL == __fpclassify(d) && !__isnan(d) && !__isinf(d));
|
||||
return ok ? 0 : 1;
|
||||
}
|
||||
" HAVE___FPCLASSIFY)
|
||||
unset(CMAKE_REQUIRED_LIBRARIES)
|
||||
|
||||
|
||||
if(MSVC)
|
||||
# XXX: /W4 gives too many warnings. #3241
|
||||
add_definitions(/W3 -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE)
|
||||
|
@ -71,5 +71,6 @@
|
||||
|
||||
#cmakedefine HAVE_EXECINFO_BACKTRACE
|
||||
#cmakedefine HAVE_BUILTIN_ADD_OVERFLOW
|
||||
#cmakedefine HAVE___FPCLASSIFY
|
||||
|
||||
#endif // AUTO_CONFIG_H
|
||||
|
@ -28,11 +28,6 @@
|
||||
#include "nvim/lib/kvec.h"
|
||||
#include "nvim/eval/typval_encode.h"
|
||||
|
||||
#ifdef __MINGW32__
|
||||
# undef fpclassify
|
||||
# define fpclassify __fpclassify
|
||||
#endif
|
||||
|
||||
#define ga_concat(a, b) ga_concat(a, (char_u *)b)
|
||||
#define utf_ptr2char(b) utf_ptr2char((char_u *)b)
|
||||
#define utf_ptr2len(b) ((size_t)utf_ptr2len((char_u *)b))
|
||||
@ -327,7 +322,7 @@ int encode_read_from_list(ListReaderState *const state, char *const buf,
|
||||
#define TYPVAL_ENCODE_CONV_FLOAT(tv, flt) \
|
||||
do { \
|
||||
const float_T flt_ = (flt); \
|
||||
switch (fpclassify(flt_)) { \
|
||||
switch (xfpclassify(flt_)) { \
|
||||
case FP_NAN: { \
|
||||
ga_concat(gap, (char_u *) "str2float('nan')"); \
|
||||
break; \
|
||||
@ -531,7 +526,7 @@ int encode_read_from_list(ListReaderState *const state, char *const buf,
|
||||
#define TYPVAL_ENCODE_CONV_FLOAT(tv, flt) \
|
||||
do { \
|
||||
const float_T flt_ = (flt); \
|
||||
switch (fpclassify(flt_)) { \
|
||||
switch (xfpclassify(flt_)) { \
|
||||
case FP_NAN: { \
|
||||
EMSG(_("E474: Unable to represent NaN value in JSON")); \
|
||||
return FAIL; \
|
||||
|
@ -1,6 +1,10 @@
|
||||
#ifndef NVIM_MACROS_H
|
||||
#define NVIM_MACROS_H
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "auto/config.h"
|
||||
|
||||
// EXTERN is only defined in main.c. That's where global variables are
|
||||
// actually defined and initialized.
|
||||
#ifndef EXTERN
|
||||
@ -19,6 +23,23 @@
|
||||
# define MAX(X, Y) ((X) > (Y) ? (X) : (Y))
|
||||
#endif
|
||||
|
||||
#if defined(__clang__) && __clang__ == 1 && __clang_major__ >= 6 \
|
||||
&& defined(HAVE___FPCLASSIFY)
|
||||
// Workaround glibc + Clang 6+ bug. #8274
|
||||
// https://bugzilla.redhat.com/show_bug.cgi?id=1472437
|
||||
# define xfpclassify __fpclassify
|
||||
# define xisnan __isnan
|
||||
# define xisinf __isinf
|
||||
#elif defined(__MINGW32__)
|
||||
// Workaround mingw warning. #7863
|
||||
# define xfpclassify __fpclassify
|
||||
# define xisnan _isnan
|
||||
#else
|
||||
# define xfpclassify fpclassify
|
||||
# define xisnan isnan
|
||||
# define xisinf isinf
|
||||
#endif
|
||||
|
||||
/// String with length
|
||||
///
|
||||
/// For use in functions which accept (char *s, size_t len) pair in arguments.
|
||||
|
@ -50,16 +50,7 @@
|
||||
#include "nvim/os/shell.h"
|
||||
#include "nvim/eval/encode.h"
|
||||
|
||||
#ifdef __MINGW32__
|
||||
# undef fpclassify
|
||||
# define fpclassify __fpclassify
|
||||
# undef isnan
|
||||
# define isnan _isnan
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Copy "string" into newly allocated memory.
|
||||
*/
|
||||
/// Copy "string" into newly allocated memory.
|
||||
char_u *vim_strsave(const char_u *string)
|
||||
FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL
|
||||
{
|
||||
@ -1214,14 +1205,14 @@ int vim_vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap,
|
||||
remove_trailing_zeroes = true;
|
||||
}
|
||||
|
||||
if (isinf(f)
|
||||
if (xisinf(f)
|
||||
|| (strchr("fF", fmt_spec) != NULL && abs_f > 1.0e307)) {
|
||||
xstrlcpy(tmp, infinity_str(f > 0.0, fmt_spec,
|
||||
force_sign, space_for_positive),
|
||||
sizeof(tmp));
|
||||
str_arg_l = strlen(tmp);
|
||||
zero_padding = 0;
|
||||
} else if (isnan(f)) {
|
||||
} else if (xisnan(f)) {
|
||||
// Not a number: nan or NAN
|
||||
memmove(tmp, ASCII_ISUPPER(fmt_spec) ? "NAN" : "nan", 4);
|
||||
str_arg_l = 3;
|
||||
|
Loading…
Reference in New Issue
Block a user