Skip to content

Commit 2105cb4

Browse files
committed
fpcmp: Allow decimal numbers ending with a period
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 460eedc commit 2105cb4

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-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)
@@ -19,6 +23,10 @@ add_dependencies(abrt not)
1923
llvm_test_run(EXECUTABLE "$<TARGET_FILE:not>" "--crash" "$<TARGET_FILE:abrt>")
2024
llvm_add_test_for_target(abrt)
2125

26+
# Check that fpcmp can handle decimal numbers ending with a period correctly.
27+
llvm_test_run(EXECUTABLE "$<TARGET_FILE:fpcmp-target>" "-a" "0.03" "-r" "0.03" "-i" "%b/test/fpcmp-input1" "%b/test/fpcmp-input2")
28+
llvm_add_test_for_target(fpcmp-target)
29+
2230
# Check that not passes environment variables to the called executable.
2331
find_package(Python COMPONENTS Interpreter)
2432
llvm_test_executable_no_test(check_env check_env.c)

tools/test/fpcmp-input1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
65.
2+
3.E-02

tools/test/fpcmp-input2

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
65.0
2+
3.0E-02

0 commit comments

Comments
 (0)