EPICS Math tests failing on Windows with MSVC
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
EPICS Base |
Confirmed
|
Low
|
mdavidsaver |
Bug Description
Some epics base tests involving NaN and Inf have been failing for most windows MSVC builds, I have written a small test program https:/
The general summary is that:
VS2010, VS2017 and VS2019 are OK in all configurations
For other Visual studio versions:
Debug builds are often OK
All release builds fail.
The failure mode is as follows (Inf shown here but applies to NaN too):
Inf – Inf is evaluated correctly
Inf + -Inf is evaluated incorrectly
Inf + (-Inf) is evaluated correctly on VS 11.0 and 12.0, but not 14.0
The test code is using expressions like “a + -a” with a = Inf, if it instead tests “a + -b” with a = b = Inf then release mode works in all cases. So it looks like the repeated variable name is causing an undesired optimisation. I feel expressions of the form “a + -b” rather than “a + -a” are a better reflection of what is likely in practice, if that change is acceptable then I would be happy to submit a PR to use different variable names within binary operation tests
Regards,
Freddie
Related branches
- Andrew Johnson: Needs Fixing
-
Diff: 127 lines (+28/-40)2 files modifiedmodules/libcom/test/epicsCalcTest.cpp (+13/-14)
modules/libcom/test/epicsMathTest.c (+15/-26)
Taking a step back. I ask myself, what is epicsMathTest actually testing? To me it's about runtime behavior. "Inf + - Inf" is nonsense which wouldn't be found in a real source file, so the fact that the MSVC optimizer gets it wrong is interesting, but ultimately a distraction.
While not the best solution. Absent fine grained control of the optimizer, maybe the path forward is to disable optimizations (only) in epicsMathTest.c and/or epicsCalcTest.c ? Or at least around the NaN and Inf tests?
> #if defined(_MSC_VER)
> # pragma optimize("g", off)
> #endif