diff --git a/tools/fpcmp.c b/tools/fpcmp.c index a7b9a3a7b7..eccf5f4523 100644 --- a/tools/fpcmp.c +++ b/tools/fpcmp.c @@ -67,17 +67,13 @@ static const char *AdvanceNumber(const char *StartPos, const char *End) { // Decimal separator if (Pos < End && *Pos == '.') { ++Pos; + EndOfNumber = Pos; - // Post-decimal digits (require at least one when period present) - bool HasPostDecimalDigit = false; + // Post-decimal digits (optional) while (Pos < End && isDigitChar(*Pos)) { - HasPostDecimalDigit = true; - ++Pos; EndOfNumber = Pos; } - if (!HasPostDecimalDigit) - return EndOfNumber; } // Require a valid number before the exponent. diff --git a/tools/test/CMakeLists.txt b/tools/test/CMakeLists.txt index a724da14fe..9def857fd7 100644 --- a/tools/test/CMakeLists.txt +++ b/tools/test/CMakeLists.txt @@ -2,6 +2,10 @@ # without the source directory. configure_file(test_not.py test_not.py COPYONLY) +configure_file(fpcmp-input1 fpcmp-input1 + COPYONLY) +configure_file(fpcmp-input2 fpcmp-input2 + COPYONLY) llvm_test_executable_no_test(ret1 ret1.c) add_dependencies(ret1 not) @@ -25,3 +29,7 @@ llvm_test_executable_no_test(check_env check_env.c) add_dependencies(check_env not) llvm_test_run(EXECUTABLE ${Python_EXECUTABLE} "%b/test/test_not.py" "$" "$") llvm_add_test_For_target(check_env) + +# Check that fpcmp can handle decimal numbers ending with a period correctly. +llvm_test_run(EXECUTABLE "$" "-a" "0.03" "-r" "0.03" "-i" "%b/test/fpcmp-input1" "%b/test/fpcmp-input2") +llvm_add_test_for_target(fpcmp-target) diff --git a/tools/test/fpcmp-input1 b/tools/test/fpcmp-input1 new file mode 100644 index 0000000000..84726f0f29 --- /dev/null +++ b/tools/test/fpcmp-input1 @@ -0,0 +1,8 @@ +65. +3.E+02 +------- +45000 +7E+03 +------- +.9 +.6E+04 diff --git a/tools/test/fpcmp-input2 b/tools/test/fpcmp-input2 new file mode 100644 index 0000000000..3ea14d1e29 --- /dev/null +++ b/tools/test/fpcmp-input2 @@ -0,0 +1,8 @@ +65.0 +300.0 +------- +45000.0 +7000.0 +------- +0.9 +6000