Skip to content

Commit 45c296d

Browse files
authored
fpcmp: Allow decimal numbers ending with a period (#251)
After 8a84a50, fpcmp requires at least one post-decimal digit when period present. This leads to incorrect comparison results for 628.pop2_s of SPEC2017 because this program outputs `65.` when the Fortran compiler is flang while the reference output is `65.0`.
1 parent 9faf63c commit 45c296d

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

tools/fpcmp.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,13 @@ static const char *AdvanceNumber(const char *StartPos, const char *End) {
6767
// Decimal separator
6868
if (Pos < End && *Pos == '.') {
6969
++Pos;
70+
EndOfNumber = Pos;
7071

71-
// Post-decimal digits (require at least one when period present)
72-
bool HasPostDecimalDigit = false;
72+
// Post-decimal digits (optional)
7373
while (Pos < End && isDigitChar(*Pos)) {
74-
HasPostDecimalDigit = true;
75-
7674
++Pos;
7775
EndOfNumber = Pos;
7876
}
79-
if (!HasPostDecimalDigit)
80-
return EndOfNumber;
8177
}
8278

8379
// Require a valid number before the exponent.

tools/test/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
# without the source directory.
33
configure_file(test_not.py test_not.py
44
COPYONLY)
5+
configure_file(fpcmp-input1 fpcmp-input1
6+
COPYONLY)
7+
configure_file(fpcmp-input2 fpcmp-input2
8+
COPYONLY)
59

610
llvm_test_executable_no_test(ret1 ret1.c)
711
add_dependencies(ret1 not)
@@ -25,3 +29,7 @@ llvm_test_executable_no_test(check_env check_env.c)
2529
add_dependencies(check_env not)
2630
llvm_test_run(EXECUTABLE ${Python_EXECUTABLE} "%b/test/test_not.py" "$<TARGET_FILE:not>" "$<TARGET_FILE:check_env>")
2731
llvm_add_test_For_target(check_env)
32+
33+
# Check that fpcmp can handle decimal numbers ending with a period correctly.
34+
llvm_test_run(EXECUTABLE "$<TARGET_FILE:fpcmp-target>" "-a" "0.03" "-r" "0.03" "-i" "%b/test/fpcmp-input1" "%b/test/fpcmp-input2")
35+
llvm_add_test_for_target(fpcmp-target)

tools/test/fpcmp-input1

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
65.
2+
3.E+02
3+
-------
4+
45000
5+
7E+03
6+
-------
7+
.9
8+
.6E+04

tools/test/fpcmp-input2

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
65.0
2+
300.0
3+
-------
4+
45000.0
5+
7000.0
6+
-------
7+
0.9
8+
6000

0 commit comments

Comments
 (0)