There's currently ongoing discussion on the dev lists about how to handle related cases with isnan() / isinf(), but I don't think the problem addressed by this patch is controversial:
If the compile specified loose FP math because special values like NaN / Inf / -0.0 are not expected, then we should warn if the code contains an obvious occurrence of any of those values.
My understanding of clang isn't good though. Is this the right place to detect the unexpected values? I commented in the test file that I don't see the expected warnings in all cases before CodeGen. But if we run through to IR creation, then I sometimes see duplicate warnings for the same line of code.
For example, I see duplicate 3 warnings on this program based on https://llvm.org/PR51775 :
% cat 51775.c #include <math.h> #include <stdlib.h> int main() { const double d = strtod("1E+1000000", NULL); return d == HUGE_VAL; }
% clang -O1 -ffast-math 51775.c -S -o - 51775.c:5:17: warning: floating-point infinity may be optimized out of computation or comparison [-Wliteral-range] return d == HUGE_VAL; ^ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/math.h:57:28: note: expanded from macro 'HUGE_VAL' # define HUGE_VAL __builtin_huge_val() ^ 51775.c:5:17: warning: floating-point infinity may be optimized out of computation or comparison [-Wliteral-range] /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/math.h:57:28: note: expanded from macro 'HUGE_VAL' # define HUGE_VAL __builtin_huge_val() ^ 51775.c:5:17: warning: floating-point infinity may be optimized out of computation or comparison [-Wliteral-range] /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/math.h:57:28: note: expanded from macro 'HUGE_VAL' # define HUGE_VAL __builtin_huge_val() ...
-ffast-math does not prohibit using negative zero, it only treat it identically to positive zero.