From 0ee293e4bffd6094304a34097dc480578f542124 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9=20Draszik?= <adraszik@tycoint.com>
Date: Wed, 24 Aug 2016 20:58:59 +0100
Subject: [PATCH] execution_monitor: fix soft float issues
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
gcc.compile.c++ <builddir>/boost/bin.v2/libs/test/build/gcc-4.3.1/release/threading-multi/execution_monitor.o
"mipsel-poky-linux-musl-g++" "-mel" "-mabi=32" "-msoft-float" "-march=mips32r2" "-mips16" "-minterlink-compressed" "-mtune=24kec" "-mdsp" "-Wl,-O1" "-Wl,--as-needed" "-fstack-protector-strong" "-Wl,-z,relro,-z,now" "--sysroot=<sysroot>" -ftemplate-depth-128 -O2 -pipe -g -feliminate-unused-debug-types -fdebug-prefix-map=<srcdir>=/usr/src/debug/boost/1.61.0-r0 -fdebug-prefix-map=<sysroot_host>= -fdebug-prefix-map=<sysroot>= -fstack-protector-strong -pie -fpie -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security -fvisibility-inlines-hidden -O3 -finline-functions -Wno-inline -Wall -pedantic -pthread -fPIC -Wno-variadic-macros -DBOOST_ALL_NO_LIB=1 -DBOOST_CHRONO_DYN_LINK=1 -DBOOST_SYSTEM_DYN_LINK=1 -DBOOST_SYSTEM_NO_DEPRECATED -DBOOST_TEST_DYN_LINK=1 -DBOOST_TIMER_DYN_LINK=1 -DNDEBUG -I"." -c -o "<builddir>/boost/bin.v2/libs/test/build/gcc-4.3.1/release/threading-multi/execution_monitor.o" "libs/test/src/execution_monitor.cpp"
In file included from ./boost/test/impl/execution_monitor.ipp:31:0,
from libs/test/src/execution_monitor.cpp:16:
./boost/test/execution_monitor.hpp:491:27: error: 'FE_DIVBYZERO' was not declared in this scope
BOOST_FPE_DIVBYZERO = FE_DIVBYZERO,
^~~~~~~~~~~~
./boost/test/execution_monitor.hpp:492:27: error: 'FE_INEXACT' was not declared in this scope
BOOST_FPE_INEXACT = FE_INEXACT,
^~~~~~~~~~
./boost/test/execution_monitor.hpp:493:27: error: 'FE_INVALID' was not declared in this scope
BOOST_FPE_INVALID = FE_INVALID,
^~~~~~~~~~
./boost/test/execution_monitor.hpp:494:27: error: 'FE_OVERFLOW' was not declared in this scope
BOOST_FPE_OVERFLOW = FE_OVERFLOW,
^~~~~~~~~~~
./boost/test/execution_monitor.hpp:495:27: error: 'FE_UNDERFLOW' was not declared in this scope
BOOST_FPE_UNDERFLOW = FE_UNDERFLOW,
^~~~~~~~~~~~
The reason is that some (notably FPU-less) architectures,
including mips*-nf, don't define/implement some of the
floating point constants, even though fenv.h is
available.
The key point is:
A fully standards conforming fenv.h does not have to
define any FE_* macros, and if it does define them,
then it defines macros only for the FP exceptions it
actually supports.
So correct usage requires a triple check:
1) Check BOOST_NO_FENV_H to see if the header is supported.
2) Include the header and then check FE_ALL_EXCEPT to see
if any FP exceptions are supported.
3) Before using the individual FE_* macros, you need to
check for their existence too as not all may be
supported.
https://svn.boost.org/trac/boost/ticket/11756
Other projects have similar issues, e.g. pixman, and
apply similar work-arounds:
https://lists.freedesktop.org/archives/pixman/2014-February/003172.html
Architectures are notably also allowed to define FE_ALL_EXCEPT to 0!
Keeping this in mind, and knowing that the compiler will eliminate
code that can't be executed, we can change BOOST_FPE_ALL to be 0 for
the case of compiling using Clang and/or fenv.h being unavailable
as well, which allows simplification of the #ifdef's in
execution_monitor.ipp a bit.
Signed-off-by: André Draszik <adraszik@tycoint.com>
---
include/boost/test/execution_monitor.hpp | 26 +++++++++++++++++++++++++-
include/boost/test/impl/execution_monitor.ipp | 10 ++++++++--
2 files changed, 33 insertions(+), 3 deletions(-)
diff --git a/include/boost/test/execution_monitor.hpp b/include/boost/test/execution_monitor.hpp
index 3a203d1..4a028ab 100644
a
|
b
|
enum masks {
|
498 | 498 | |
499 | 499 | BOOST_FPE_ALL = MCW_EM, |
500 | 500 | #elif defined(BOOST_NO_FENV_H) || defined(BOOST_CLANG) |
501 | | BOOST_FPE_ALL = 1, |
| 501 | BOOST_FPE_ALL = 0, |
502 | 502 | #else |
| 503 | #if defined(FE_DIVBYZERO) |
503 | 504 | BOOST_FPE_DIVBYZERO = FE_DIVBYZERO, |
| 505 | #else |
| 506 | BOOST_FPE_DIVBYZERO = 0, |
| 507 | #endif |
| 508 | #if defined(FE_INEXACT) |
504 | 509 | BOOST_FPE_INEXACT = FE_INEXACT, |
| 510 | #else |
| 511 | BOOST_FPE_INEXACT = 0, |
| 512 | #endif |
| 513 | #if defined(FE_INVALID) |
505 | 514 | BOOST_FPE_INVALID = FE_INVALID, |
| 515 | #else |
| 516 | BOOST_FPE_INVALID = 0, |
| 517 | #endif |
| 518 | #if defined(FE_OVERFLOW) |
506 | 519 | BOOST_FPE_OVERFLOW = FE_OVERFLOW, |
| 520 | #else |
| 521 | BOOST_FPE_OVERFLOW = 0, |
| 522 | #endif |
| 523 | #if defined(FE_UNDERFLOW) |
507 | 524 | BOOST_FPE_UNDERFLOW = FE_UNDERFLOW, |
| 525 | #else |
| 526 | BOOST_FPE_UNDERFLOW = 0, |
| 527 | #endif |
508 | 528 | |
| 529 | #if defined(FE_ALL_EXCEPT) |
509 | 530 | BOOST_FPE_ALL = FE_ALL_EXCEPT, |
| 531 | #else |
| 532 | BOOST_FPE_ALL = 0, |
| 533 | #endif |
510 | 534 | #endif |
511 | 535 | BOOST_FPE_INV = BOOST_FPE_ALL+1 |
512 | 536 | }; |
diff --git a/include/boost/test/impl/execution_monitor.ipp b/include/boost/test/impl/execution_monitor.ipp
index ce6c6c7..47dd005 100644
a
|
b
|
enable( unsigned mask )
|
1378 | 1378 | #endif |
1379 | 1379 | |
1380 | 1380 | return ~old_cw & BOOST_FPE_ALL; |
1381 | | #elif defined(__GLIBC__) && defined(__USE_GNU) && !defined(BOOST_CLANG) && !defined(BOOST_NO_FENV_H) |
| 1381 | #elif defined(__GLIBC__) && defined(__USE_GNU) |
| 1382 | if (BOOST_FPE_ALL == 0) |
| 1383 | /* Not Implemented */ |
| 1384 | return 0; |
1382 | 1385 | feclearexcept(BOOST_FPE_ALL); |
1383 | 1386 | int res = feenableexcept( mask ); |
1384 | 1387 | return res == -1 ? (unsigned)BOOST_FPE_INV : (unsigned)res; |
… |
… |
disable( unsigned mask )
|
1415 | 1418 | #endif |
1416 | 1419 | |
1417 | 1420 | return ~old_cw & BOOST_FPE_ALL; |
1418 | | #elif defined(__GLIBC__) && defined(__USE_GNU) && !defined(BOOST_CLANG) && !defined(BOOST_NO_FENV_H) |
| 1421 | #elif defined(__GLIBC__) && defined(__USE_GNU) |
| 1422 | if (BOOST_FPE_ALL == 0) |
| 1423 | /* Not Implemented */ |
| 1424 | return BOOST_FPE_INV; |
1419 | 1425 | feclearexcept(BOOST_FPE_ALL); |
1420 | 1426 | int res = fedisableexcept( mask ); |
1421 | 1427 | return res == -1 ? (unsigned)BOOST_FPE_INV : (unsigned)res; |