build: Fix -Wconversion warnings for fpclassify et al

closes #8274

The parent commit tries a different approach, but that fails on Apple
Clang version:
    Apple LLVM version 10.0.0 (clang-1000.11.45.5)
    Target: x86_64-apple-darwin17.7.0
which somehow compiles the check_c_source_compiles() check, but then
complains during later compilation that __fpclassify is not defined
(regardless of "#include <math.h>").
This commit is contained in:
Justin M. Keyes 2019-01-21 00:19:15 +01:00
parent c6a039d087
commit 226352afcb
7 changed files with 51 additions and 35 deletions

View File

@ -258,19 +258,6 @@ int main(void)
} }
" HAVE_BUILTIN_ADD_OVERFLOW) " 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) if(MSVC)
# XXX: /W4 gives too many warnings. #3241 # XXX: /W4 gives too many warnings. #3241
add_definitions(/W3 -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE) add_definitions(/W3 -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE)

View File

@ -71,6 +71,5 @@
#cmakedefine HAVE_EXECINFO_BACKTRACE #cmakedefine HAVE_EXECINFO_BACKTRACE
#cmakedefine HAVE_BUILTIN_ADD_OVERFLOW #cmakedefine HAVE_BUILTIN_ADD_OVERFLOW
#cmakedefine HAVE___FPCLASSIFY
#endif // AUTO_CONFIG_H #endif // AUTO_CONFIG_H

View File

@ -19,6 +19,7 @@
#include "nvim/eval/typval.h" #include "nvim/eval/typval.h"
#include "nvim/garray.h" #include "nvim/garray.h"
#include "nvim/mbyte.h" #include "nvim/mbyte.h"
#include "nvim/math.h"
#include "nvim/message.h" #include "nvim/message.h"
#include "nvim/memory.h" #include "nvim/memory.h"
#include "nvim/charset.h" // vim_isprintc() #include "nvim/charset.h" // vim_isprintc()

View File

@ -1,10 +1,6 @@
#ifndef NVIM_MACROS_H #ifndef NVIM_MACROS_H
#define 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 // EXTERN is only defined in main.c. That's where global variables are
// actually defined and initialized. // actually defined and initialized.
#ifndef EXTERN #ifndef EXTERN
@ -23,23 +19,6 @@
# define MAX(X, Y) ((X) > (Y) ? (X) : (Y)) # define MAX(X, Y) ((X) > (Y) ? (X) : (Y))
#endif #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 /// String with length
/// ///
/// For use in functions which accept (char *s, size_t len) pair in arguments. /// For use in functions which accept (char *s, size_t len) pair in arguments.

42
src/nvim/math.c Normal file
View File

@ -0,0 +1,42 @@
// This is an open source non-commercial project. Dear PVS-Studio, please check
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include <math.h>
#include "nvim/math.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "math.c.generated.h"
#endif
#if defined(__clang__) && __clang__ == 1 && __clang_major__ >= 6
// Workaround glibc + Clang 6+ bug. #8274
// https://bugzilla.redhat.com/show_bug.cgi?id=1472437
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wconversion"
#endif
int xfpclassify(double d)
{
#if defined(__MINGW32__)
// Workaround mingw warning. #7863
return __fpclassify(d);
#else
return fpclassify(d);
#endif
}
int xisinf(double d)
{
return isinf(d);
}
int xisnan(double d)
{
#if defined(__MINGW32__)
// Workaround mingw warning. #7863
return _isnan(d);
#else
return isnan(d);
#endif
}
#if defined(__clang__) && __clang__ == 1 && __clang_major__ >= 6
# pragma clang diagnostic pop
#endif

7
src/nvim/math.h Normal file
View File

@ -0,0 +1,7 @@
#ifndef NVIM_MATH_H
#define NVIM_MATH_H
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "math.h.generated.h"
#endif
#endif // NVIM_MATH_H

View File

@ -27,6 +27,7 @@
#include "nvim/func_attr.h" #include "nvim/func_attr.h"
#include "nvim/getchar.h" #include "nvim/getchar.h"
#include "nvim/mark.h" #include "nvim/mark.h"
#include "nvim/math.h"
#include "nvim/mbyte.h" #include "nvim/mbyte.h"
#include "nvim/memfile.h" #include "nvim/memfile.h"
#include "nvim/memline.h" #include "nvim/memline.h"