Skip to content

[libc][math] Fix incorrect logic in fputil::generic::add_or_sub #116129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 18, 2025

Conversation

overmighty
Copy link
Member

@overmighty overmighty commented Nov 14, 2024

Fixes incorrect logic that went unnoticed until the function was tested
with output and input types that have the same underlying floating-point
format.

@overmighty overmighty requested a review from lntue November 14, 2024 00:27
@llvmbot llvmbot added the libc label Nov 14, 2024
@llvmbot
Copy link
Member

llvmbot commented Nov 14, 2024

@llvm/pr-subscribers-libc

Author: OverMighty (overmighty)

Changes

Fixes incorrect logic that went unnoticed until the function was tested
with output and input types having the same underlying floating-point
format. The resulting DyadicFloat's exponent was off by one when adding
two subnormal numbers, and the minimum operand's mantissa was misaligned
by one bit when adding a normal number with a subnormal number.


Full diff: https://github.com/llvm/llvm-project/pull/116129.diff

2 Files Affected:

  • (modified) libc/src/__support/FPUtil/generic/add_sub.h (+8-7)
  • (modified) libc/test/src/math/smoke/AddTest.h (+12-1)
diff --git a/libc/src/__support/FPUtil/generic/add_sub.h b/libc/src/__support/FPUtil/generic/add_sub.h
index 6bc9dcd23bafad..5c503e752c8ecb 100644
--- a/libc/src/__support/FPUtil/generic/add_sub.h
+++ b/libc/src/__support/FPUtil/generic/add_sub.h
@@ -160,20 +160,21 @@ add_or_sub(InType x, InType y) {
   } else {
     InStorageType max_mant = max_bits.get_explicit_mantissa() << GUARD_BITS_LEN;
     InStorageType min_mant = min_bits.get_explicit_mantissa() << GUARD_BITS_LEN;
-    int alignment =
-        max_bits.get_biased_exponent() - min_bits.get_biased_exponent();
+
+    int alignment = (max_bits.get_biased_exponent() - max_bits.is_normal()) -
+                    (min_bits.get_biased_exponent() - min_bits.is_normal());
 
     InStorageType aligned_min_mant =
         min_mant >> cpp::min(alignment, RESULT_MANTISSA_LEN);
     bool aligned_min_mant_sticky;
 
-    if (alignment <= 3)
+    if (alignment <= GUARD_BITS_LEN)
       aligned_min_mant_sticky = false;
-    else if (alignment <= InFPBits::FRACTION_LEN + 3)
+    else if (alignment > InFPBits::FRACTION_LEN + GUARD_BITS_LEN)
+      aligned_min_mant_sticky = true;
+    else
       aligned_min_mant_sticky =
           (min_mant << (InFPBits::STORAGE_LEN - alignment)) != 0;
-    else
-      aligned_min_mant_sticky = true;
 
     InStorageType min_mant_sticky(static_cast<int>(aligned_min_mant_sticky));
 
@@ -183,7 +184,7 @@ add_or_sub(InType x, InType y) {
       result_mant = max_mant - (aligned_min_mant | min_mant_sticky);
   }
 
-  int result_exp = max_bits.get_exponent() - RESULT_FRACTION_LEN;
+  int result_exp = max_bits.get_explicit_exponent() - RESULT_FRACTION_LEN;
   DyadicFloat result(result_sign, result_exp, result_mant);
   return result.template as<OutType, /*ShouldSignalExceptions=*/true>();
 }
diff --git a/libc/test/src/math/smoke/AddTest.h b/libc/test/src/math/smoke/AddTest.h
index 66b188f4fa7b31..26efff4efaf948 100644
--- a/libc/test/src/math/smoke/AddTest.h
+++ b/libc/test/src/math/smoke/AddTest.h
@@ -136,6 +136,16 @@ class AddTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
     func(InType(1.0), in.min_denormal);
     EXPECT_FP_EXCEPTION(FE_INEXACT);
   }
+
+  void test_mixed_normality(AddFunc func) {
+    if (LIBC_NAMESPACE::fputil::get_fp_type<OutType>() !=
+        LIBC_NAMESPACE::fputil::get_fp_type<InType>())
+      return;
+
+    EXPECT_FP_EQ(FPBits::create_value(Sign::POS, 2U, 0b1U).get_val(),
+                 func(InFPBits::create_value(Sign::POS, 2U, 0U).get_val(),
+                      InFPBits::create_value(Sign::POS, 2U, 0b10U).get_val()));
+  }
 };
 
 #define LIST_ADD_TESTS(OutType, InType, func)                                  \
@@ -145,6 +155,7 @@ class AddTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
     test_invalid_operations(&func);                                            \
   }                                                                            \
   TEST_F(LlvmLibcAddTest, RangeErrors) { test_range_errors(&func); }           \
-  TEST_F(LlvmLibcAddTest, InexactResults) { test_inexact_results(&func); }
+  TEST_F(LlvmLibcAddTest, InexactResults) { test_inexact_results(&func); }     \
+  TEST_F(LlvmLibcAddTest, MixedNormality) { test_mixed_normality(&func); }
 
 #endif // LLVM_LIBC_TEST_SRC_MATH_SMOKE_ADDTEST_H

Comment on lines +164 to +160
int alignment = (max_bits.get_biased_exponent() - max_bits.is_normal()) -
(min_bits.get_biased_exponent() - min_bits.is_normal());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The formula given in section 9.2.3.2 of Handbook of Floating-Point Arithmetic is $\delta = (E_x - n_x) - (E_y - n_y)$. When I implemented fputil::generic::add_or_sub, I asked myself why it wasn't just $\delta = E_x - E_y$, and ended up using that instead of the formula given in the book. Today I remembered asking myself that question, so I thought about it again and now it's obvious.

Fixes incorrect logic that went unnoticed until the function was tested
with output and input types having the same underlying floating-point
format. The resulting DyadicFloat's exponent was off by one when adding
two subnormal numbers, and the minimum operand's mantissa was misaligned
by one bit when adding a normal number with a subnormal number.
@overmighty overmighty requested a review from lntue March 18, 2025 10:28
@overmighty overmighty merged commit 1bb8b65 into llvm:main Mar 18, 2025
16 checks passed
@overmighty overmighty deleted the libc-math-fix-add branch March 18, 2025 14:04
@llvm-ci
Copy link
Collaborator

llvm-ci commented Mar 18, 2025

LLVM Buildbot has detected a new failure on builder libc-aarch64-ubuntu-dbg running on libc-aarch64-ubuntu while building libc at step 4 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/104/builds/18422

Here is the relevant piece of the build log for the reference
Step 4 (annotate) failure: 'python ../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py ...' (failure)
...
[       OK ] LlvmLibcLdExpTest.NormalOperation (310 us)
Ran 6 tests.  PASS: 6  FAIL: 0
[129/1317] Running unit test libc.test.src.math.fmodf_test.__unit__
[==========] Running 2 tests from 1 test suite.
[ RUN      ] LlvmLibcFmodTest.SpecialNumbers
[       OK ] LlvmLibcFmodTest.SpecialNumbers (131 us)
[ RUN      ] LlvmLibcFmodTest.RegularExtreme
[       OK ] LlvmLibcFmodTest.RegularExtreme (12 us)
Ran 2 tests.  PASS: 2  FAIL: 0
[130/1317] Building CXX object libc/utils/MPFRWrapper/CMakeFiles/libcMPFRWrapper.dir/MPFRUtils.cpp.o
FAILED: libc/utils/MPFRWrapper/CMakeFiles/libcMPFRWrapper.dir/MPFRUtils.cpp.o 
/usr/bin/clang++ -DLIBC_NAMESPACE=__llvm_libc_20_0_0_git -D_DEBUG -I/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wstring-conversion -fdiagnostics-color -g -O3 -fpie -Wconversion -Wno-sign-conversion -Wimplicit-fallthrough -Wwrite-strings -Wno-c99-extensions -Wno-gnu-imaginary-constant -Wno-pedantic -Wstrict-prototypes -Wextra-semi -Wnewline-eof -Wnonportable-system-include-path -Wthread-safety -std=gnu++17 -MD -MT libc/utils/MPFRWrapper/CMakeFiles/libcMPFRWrapper.dir/MPFRUtils.cpp.o -MF libc/utils/MPFRWrapper/CMakeFiles/libcMPFRWrapper.dir/MPFRUtils.cpp.o.d -o libc/utils/MPFRWrapper/CMakeFiles/libcMPFRWrapper.dir/MPFRUtils.cpp.o -c /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/utils/MPFRWrapper/MPFRUtils.cpp
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/utils/MPFRWrapper/MPFRUtils.cpp:405:15: error: duplicate explicit instantiation of 'explain_binary_operation_one_output_error<long double, long double>'
template void explain_binary_operation_one_output_error(
              ^
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/utils/MPFRWrapper/MPFRUtils.cpp:390:1: note: previous explicit instantiation is here
explain_binary_operation_one_output_error(Operation,
^
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/utils/MPFRWrapper/MPFRUtils.cpp:633:15: error: duplicate explicit instantiation of 'compare_binary_operation_one_output<long double, long double>'
template bool compare_binary_operation_one_output(Operation,
              ^
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/utils/MPFRWrapper/MPFRUtils.cpp:609:1: note: previous explicit instantiation is here
compare_binary_operation_one_output(Operation, const BinaryInput<long double> &,
^
2 errors generated.
[131/1317] Running unit test libc.test.src.math.fdiml_test.__unit__
[==========] Running 5 tests from 1 test suite.
[ RUN      ] LlvmLibcFDimTest.NaNArg_fdiml
[       OK ] LlvmLibcFDimTest.NaNArg_fdiml (4 us)
[ RUN      ] LlvmLibcFDimTest.InfArg_fdiml
[       OK ] LlvmLibcFDimTest.InfArg_fdiml (3 us)
[ RUN      ] LlvmLibcFDimTest.NegInfArg_fdiml
[       OK ] LlvmLibcFDimTest.NegInfArg_fdiml (2 us)
[ RUN      ] LlvmLibcFDimTest.BothZero_fdiml
[       OK ] LlvmLibcFDimTest.BothZero_fdiml (1 us)
[ RUN      ] LlvmLibcFDimTest.InLongDoubleRange_fdiml
[       OK ] LlvmLibcFDimTest.InLongDoubleRange_fdiml (48 ms)
Ran 5 tests.  PASS: 5  FAIL: 0
[132/1317] Running unit test libc.test.src.math.modf_test.__unit__
[==========] Running 4 tests from 1 test suite.
[ RUN      ] LlvmLibcModfTest.SpecialNumbers
[       OK ] LlvmLibcModfTest.SpecialNumbers (4 us)
[ RUN      ] LlvmLibcModfTest.RoundedNubmers
[       OK ] LlvmLibcModfTest.RoundedNubmers (3 us)
[ RUN      ] LlvmLibcModfTest.Fractions
[       OK ] LlvmLibcModfTest.Fractions (3 us)
[ RUN      ] LlvmLibcModfTest.Range
[       OK ] LlvmLibcModfTest.Range (61 ms)
Ran 4 tests.  PASS: 4  FAIL: 0

@llvm-ci
Copy link
Collaborator

llvm-ci commented Mar 18, 2025

LLVM Buildbot has detected a new failure on builder libc-riscv64-debian-dbg running on libc-riscv64-debian while building libc at step 4 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/188/builds/11972

Here is the relevant piece of the build log for the reference
Step 4 (annotate) failure: 'python ../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py ...' (failure)
...
[ RUN      ] LlvmLibcFEnvTest.RaiseAndCrash
[       OK ] LlvmLibcFEnvTest.RaiseAndCrash (4 us)
Ran 1 tests.  PASS: 1  FAIL: 0
[106/1512] Running unit test libc.test.src.fenv.enabled_exceptions_test.__unit__
[==========] Running 1 test from 1 test suite.
[ RUN      ] LlvmLibcExceptionStatusTest.RaiseAndCrash
[       OK ] LlvmLibcExceptionStatusTest.RaiseAndCrash (5 us)
Ran 1 tests.  PASS: 1  FAIL: 0
[107/1512] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.fsubf128.__NO_FMA_OPT.dir/fsubf128.cpp.o
[108/1512] Building CXX object libc/utils/MPFRWrapper/CMakeFiles/libcMPFRWrapper.dir/MPFRUtils.cpp.o
FAILED: libc/utils/MPFRWrapper/CMakeFiles/libcMPFRWrapper.dir/MPFRUtils.cpp.o 
/usr/bin/clang++ -DLIBC_NAMESPACE=__llvm_libc_20_0_0_git -D_DEBUG -I/home/libc_worker/libc-riscv64-debian/libc-riscv64-debian-dbg/llvm-project/libc -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wstring-conversion -fdiagnostics-color -g -O3 -fpie -Wconversion -Wno-sign-conversion -Wimplicit-fallthrough -Wwrite-strings -Wno-c99-extensions -Wno-gnu-imaginary-constant -Wno-pedantic -Wstrict-prototypes -Wextra-semi -Wnewline-eof -Wnonportable-system-include-path -Wthread-safety -std=gnu++17 -MD -MT libc/utils/MPFRWrapper/CMakeFiles/libcMPFRWrapper.dir/MPFRUtils.cpp.o -MF libc/utils/MPFRWrapper/CMakeFiles/libcMPFRWrapper.dir/MPFRUtils.cpp.o.d -o libc/utils/MPFRWrapper/CMakeFiles/libcMPFRWrapper.dir/MPFRUtils.cpp.o -c /home/libc_worker/libc-riscv64-debian/libc-riscv64-debian-dbg/llvm-project/libc/utils/MPFRWrapper/MPFRUtils.cpp
/home/libc_worker/libc-riscv64-debian/libc-riscv64-debian-dbg/llvm-project/libc/utils/MPFRWrapper/MPFRUtils.cpp:405:15: error: duplicate explicit instantiation of 'explain_binary_operation_one_output_error<long double, long double>'
template void explain_binary_operation_one_output_error(
              ^
/home/libc_worker/libc-riscv64-debian/libc-riscv64-debian-dbg/llvm-project/libc/utils/MPFRWrapper/MPFRUtils.cpp:390:1: note: previous explicit instantiation is here
explain_binary_operation_one_output_error(Operation,
^
/home/libc_worker/libc-riscv64-debian/libc-riscv64-debian-dbg/llvm-project/libc/utils/MPFRWrapper/MPFRUtils.cpp:633:15: error: duplicate explicit instantiation of 'compare_binary_operation_one_output<long double, long double>'
template bool compare_binary_operation_one_output(Operation,
              ^
/home/libc_worker/libc-riscv64-debian/libc-riscv64-debian-dbg/llvm-project/libc/utils/MPFRWrapper/MPFRUtils.cpp:609:1: note: previous explicit instantiation is here
compare_binary_operation_one_output(Operation, const BinaryInput<long double> &,
^
2 errors generated.
[109/1512] Building CXX object libc/test/src/math/CMakeFiles/libc.test.src.math.daddl_test.__unit__.__build__.dir/daddl_test.cpp.o
[110/1512] Building CXX object libc/test/src/math/CMakeFiles/libc.test.src.math.daddl_test.__unit__.__NO_FMA_OPT.__build__.dir/daddl_test.cpp.o
[111/1512] Building CXX object libc/test/src/math/CMakeFiles/libc.test.src.math.fadd_test.__unit__.__build__.dir/fadd_test.cpp.o
[112/1512] Building CXX object libc/test/src/math/CMakeFiles/libc.test.src.math.fadd_test.__unit__.__NO_FMA_OPT.__build__.dir/fadd_test.cpp.o
[113/1512] Running unit test libc.test.src.__support.hash_test.__unit__
[==========] Running 4 tests from 1 test suite.
[ RUN      ] LlvmLibcHashTest.SanityCheck
[       OK ] LlvmLibcHashTest.SanityCheck (7 ms)
[ RUN      ] LlvmLibcHashTest.Avalanche
[       OK ] LlvmLibcHashTest.Avalanche (2634 ms)
[ RUN      ] LlvmLibcHashTest.UniformLSB
[       OK ] LlvmLibcHashTest.UniformLSB (1838 ms)
[ RUN      ] LlvmLibcHashTest.UniformMSB
[       OK ] LlvmLibcHashTest.UniformMSB (480 us)
Ran 4 tests.  PASS: 4  FAIL: 0
ninja: build stopped: subcommand failed.
['ninja', 'libc-unit-tests'] exited with return code 1.
The build step threw an exception...
Traceback (most recent call last):
  File "/home/libc_worker/libc-riscv64-debian/libc-riscv64-debian-dbg/build/../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py", line 164, in step
    yield
  File "/home/libc_worker/libc-riscv64-debian/libc-riscv64-debian-dbg/build/../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py", line 137, in main
    run_command(['ninja', 'libc-unit-tests'])
  File "/home/libc_worker/libc-riscv64-debian/libc-riscv64-debian-dbg/build/../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py", line 179, in run_command
Step 7 (libc-unit-tests) failure: libc-unit-tests (failure)
...
[ RUN      ] LlvmLibcFEnvTest.RaiseAndCrash
[       OK ] LlvmLibcFEnvTest.RaiseAndCrash (4 us)
Ran 1 tests.  PASS: 1  FAIL: 0
[106/1512] Running unit test libc.test.src.fenv.enabled_exceptions_test.__unit__
[==========] Running 1 test from 1 test suite.
[ RUN      ] LlvmLibcExceptionStatusTest.RaiseAndCrash
[       OK ] LlvmLibcExceptionStatusTest.RaiseAndCrash (5 us)
Ran 1 tests.  PASS: 1  FAIL: 0
[107/1512] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.fsubf128.__NO_FMA_OPT.dir/fsubf128.cpp.o
[108/1512] Building CXX object libc/utils/MPFRWrapper/CMakeFiles/libcMPFRWrapper.dir/MPFRUtils.cpp.o
FAILED: libc/utils/MPFRWrapper/CMakeFiles/libcMPFRWrapper.dir/MPFRUtils.cpp.o 
/usr/bin/clang++ -DLIBC_NAMESPACE=__llvm_libc_20_0_0_git -D_DEBUG -I/home/libc_worker/libc-riscv64-debian/libc-riscv64-debian-dbg/llvm-project/libc -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wstring-conversion -fdiagnostics-color -g -O3 -fpie -Wconversion -Wno-sign-conversion -Wimplicit-fallthrough -Wwrite-strings -Wno-c99-extensions -Wno-gnu-imaginary-constant -Wno-pedantic -Wstrict-prototypes -Wextra-semi -Wnewline-eof -Wnonportable-system-include-path -Wthread-safety -std=gnu++17 -MD -MT libc/utils/MPFRWrapper/CMakeFiles/libcMPFRWrapper.dir/MPFRUtils.cpp.o -MF libc/utils/MPFRWrapper/CMakeFiles/libcMPFRWrapper.dir/MPFRUtils.cpp.o.d -o libc/utils/MPFRWrapper/CMakeFiles/libcMPFRWrapper.dir/MPFRUtils.cpp.o -c /home/libc_worker/libc-riscv64-debian/libc-riscv64-debian-dbg/llvm-project/libc/utils/MPFRWrapper/MPFRUtils.cpp
/home/libc_worker/libc-riscv64-debian/libc-riscv64-debian-dbg/llvm-project/libc/utils/MPFRWrapper/MPFRUtils.cpp:405:15: error: duplicate explicit instantiation of 'explain_binary_operation_one_output_error<long double, long double>'
template void explain_binary_operation_one_output_error(
              ^
/home/libc_worker/libc-riscv64-debian/libc-riscv64-debian-dbg/llvm-project/libc/utils/MPFRWrapper/MPFRUtils.cpp:390:1: note: previous explicit instantiation is here
explain_binary_operation_one_output_error(Operation,
^
/home/libc_worker/libc-riscv64-debian/libc-riscv64-debian-dbg/llvm-project/libc/utils/MPFRWrapper/MPFRUtils.cpp:633:15: error: duplicate explicit instantiation of 'compare_binary_operation_one_output<long double, long double>'
template bool compare_binary_operation_one_output(Operation,
              ^
/home/libc_worker/libc-riscv64-debian/libc-riscv64-debian-dbg/llvm-project/libc/utils/MPFRWrapper/MPFRUtils.cpp:609:1: note: previous explicit instantiation is here
compare_binary_operation_one_output(Operation, const BinaryInput<long double> &,
^
2 errors generated.
[109/1512] Building CXX object libc/test/src/math/CMakeFiles/libc.test.src.math.daddl_test.__unit__.__build__.dir/daddl_test.cpp.o
[110/1512] Building CXX object libc/test/src/math/CMakeFiles/libc.test.src.math.daddl_test.__unit__.__NO_FMA_OPT.__build__.dir/daddl_test.cpp.o
[111/1512] Building CXX object libc/test/src/math/CMakeFiles/libc.test.src.math.fadd_test.__unit__.__build__.dir/fadd_test.cpp.o
[112/1512] Building CXX object libc/test/src/math/CMakeFiles/libc.test.src.math.fadd_test.__unit__.__NO_FMA_OPT.__build__.dir/fadd_test.cpp.o
[113/1512] Running unit test libc.test.src.__support.hash_test.__unit__
[==========] Running 4 tests from 1 test suite.
[ RUN      ] LlvmLibcHashTest.SanityCheck
[       OK ] LlvmLibcHashTest.SanityCheck (7 ms)
[ RUN      ] LlvmLibcHashTest.Avalanche
[       OK ] LlvmLibcHashTest.Avalanche (2634 ms)
[ RUN      ] LlvmLibcHashTest.UniformLSB
[       OK ] LlvmLibcHashTest.UniformLSB (1838 ms)
[ RUN      ] LlvmLibcHashTest.UniformMSB
[       OK ] LlvmLibcHashTest.UniformMSB (480 us)
Ran 4 tests.  PASS: 4  FAIL: 0
ninja: build stopped: subcommand failed.
['ninja', 'libc-unit-tests'] exited with return code 1.
The build step threw an exception...
Traceback (most recent call last):
  File "/home/libc_worker/libc-riscv64-debian/libc-riscv64-debian-dbg/build/../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py", line 164, in step
    yield
  File "/home/libc_worker/libc-riscv64-debian/libc-riscv64-debian-dbg/build/../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py", line 137, in main
    run_command(['ninja', 'libc-unit-tests'])
  File "/home/libc_worker/libc-riscv64-debian/libc-riscv64-debian-dbg/build/../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py", line 179, in run_command

@llvm-ci
Copy link
Collaborator

llvm-ci commented Mar 18, 2025

LLVM Buildbot has detected a new failure on builder libc-riscv32-qemu-yocto-fullbuild-dbg running on rv32gc-qemu-system while building libc at step 4 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/196/builds/6132

Here is the relevant piece of the build log for the reference
Step 4 (annotate) failure: 'python ../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py ...' (failure)
...
[15/1152] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.dsubf128.dir/dsubf128.cpp.o
[16/1152] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.fsubf128.dir/fsubf128.cpp.o
[17/1152] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.daddf128.__internal__.dir/daddf128.cpp.o
[18/1152] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.fsubf128.__internal__.dir/fsubf128.cpp.o
[19/1152] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.daddl.__internal__.dir/daddl.cpp.o
[20/1152] Building CXX object libc/test/src/math/CMakeFiles/libc.test.src.math.daddl_test.__unit__.__build__.dir/daddl_test.cpp.o
[21/1152] Building CXX object libc/test/src/math/CMakeFiles/libc.test.src.math.faddl_test.__unit__.__build__.dir/faddl_test.cpp.o
[22/1152] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.faddl.dir/faddl.cpp.o
[23/1152] Building CXX object libc/test/src/math/CMakeFiles/libc.test.src.math.dsubl_test.__unit__.__build__.dir/dsubl_test.cpp.o
[24/1152] Building CXX object libc/utils/MPFRWrapper/CMakeFiles/libcMPFRWrapper.dir/MPFRUtils.cpp.o
FAILED: libc/utils/MPFRWrapper/CMakeFiles/libcMPFRWrapper.dir/MPFRUtils.cpp.o 
/usr/local/bin/clang++ -DLIBC_NAMESPACE=__llvm_libc_20_0_0_git -D_DEBUG -I/home/libcrv32buildbot/gmp+mpfr/include -I/home/libcrv32buildbot/bbroot/libc-riscv32-qemu-yocto-fullbuild-dbg/llvm-project/libc -mabi=ilp32d -march=rv32imafdc --target=riscv32-unknown-linux-gnu --sysroot=/opt/riscv/sysroot --gcc-toolchain=/opt/riscv -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -g -std=gnu++17 -O3 --target=riscv32-unknown-linux-gnu -fpie -DLIBC_FULL_BUILD -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -ffixed-point -Wconversion -Wno-sign-conversion -Wimplicit-fallthrough -Wwrite-strings -Wno-c99-extensions -Wno-gnu-imaginary-constant -Wno-pedantic -Wstrict-prototypes -Wextra-semi -Wnewline-eof -Wnonportable-system-include-path -Wthread-safety -MD -MT libc/utils/MPFRWrapper/CMakeFiles/libcMPFRWrapper.dir/MPFRUtils.cpp.o -MF libc/utils/MPFRWrapper/CMakeFiles/libcMPFRWrapper.dir/MPFRUtils.cpp.o.d -o libc/utils/MPFRWrapper/CMakeFiles/libcMPFRWrapper.dir/MPFRUtils.cpp.o -c /home/libcrv32buildbot/bbroot/libc-riscv32-qemu-yocto-fullbuild-dbg/llvm-project/libc/utils/MPFRWrapper/MPFRUtils.cpp
/home/libcrv32buildbot/bbroot/libc-riscv32-qemu-yocto-fullbuild-dbg/llvm-project/libc/utils/MPFRWrapper/MPFRUtils.cpp:405:15: error: duplicate explicit instantiation of 'explain_binary_operation_one_output_error<long double, long double>'
  405 | template void explain_binary_operation_one_output_error(
      |               ^
/home/libcrv32buildbot/bbroot/libc-riscv32-qemu-yocto-fullbuild-dbg/llvm-project/libc/utils/MPFRWrapper/MPFRUtils.cpp:390:1: note: previous explicit instantiation is here
  390 | explain_binary_operation_one_output_error(Operation,
      | ^
/home/libcrv32buildbot/bbroot/libc-riscv32-qemu-yocto-fullbuild-dbg/llvm-project/libc/utils/MPFRWrapper/MPFRUtils.cpp:633:15: error: duplicate explicit instantiation of 'compare_binary_operation_one_output<long double, long double>'
  633 | template bool compare_binary_operation_one_output(Operation,
      |               ^
/home/libcrv32buildbot/bbroot/libc-riscv32-qemu-yocto-fullbuild-dbg/llvm-project/libc/utils/MPFRWrapper/MPFRUtils.cpp:609:1: note: previous explicit instantiation is here
  609 | compare_binary_operation_one_output(Operation, const BinaryInput<long double> &,
      | ^
2 errors generated.
[25/1152] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.faddf128.dir/faddf128.cpp.o
[26/1152] Building CXX object libc/test/src/math/CMakeFiles/libc.test.src.math.fadd_test.__unit__.__build__.dir/fadd_test.cpp.o
[27/1152] Building CXX object libc/test/src/math/CMakeFiles/libc.test.src.math.fsubl_test.__unit__.__build__.dir/fsubl_test.cpp.o
[28/1152] Building CXX object libc/test/src/math/smoke/CMakeFiles/libc.test.src.math.smoke.fadd_test.__unit__.__build__.dir/fadd_test.cpp.o
[29/1152] Building CXX object libc/test/src/math/smoke/CMakeFiles/libc.test.src.math.smoke.dsubf128_test.__unit__.__build__.dir/dsubf128_test.cpp.o
[30/1152] Building CXX object libc/test/src/math/smoke/CMakeFiles/libc.test.src.math.smoke.faddf128_test.__unit__.__build__.dir/faddf128_test.cpp.o
[31/1152] Building CXX object libc/test/src/math/smoke/CMakeFiles/libc.test.src.math.smoke.faddl_test.__unit__.__build__.dir/faddl_test.cpp.o
[32/1152] Building CXX object libc/test/src/math/smoke/CMakeFiles/libc.test.src.math.smoke.dsubl_test.__unit__.__build__.dir/dsubl_test.cpp.o
[33/1152] Building CXX object libc/test/src/math/CMakeFiles/libc.test.src.math.sub_same_type_test.__unit__.__build__.dir/sub_same_type_test.cpp.o
[34/1152] Building CXX object libc/test/src/math/smoke/CMakeFiles/libc.test.src.math.smoke.fsub_test.__unit__.__build__.dir/fsub_test.cpp.o
[35/1152] Building CXX object libc/test/src/math/smoke/CMakeFiles/libc.test.src.math.smoke.fsubl_test.__unit__.__build__.dir/fsubl_test.cpp.o
[36/1152] Building CXX object libc/test/src/math/smoke/CMakeFiles/libc.test.src.math.smoke.daddl_test.__unit__.__build__.dir/daddl_test.cpp.o
[37/1152] Building CXX object libc/test/src/math/CMakeFiles/libc.test.src.math.add_same_type_test.__unit__.__build__.dir/add_same_type_test.cpp.o
[38/1152] Building CXX object libc/test/src/math/smoke/CMakeFiles/libc.test.src.math.smoke.fsubf128_test.__unit__.__build__.dir/fsubf128_test.cpp.o
[39/1152] Building CXX object libc/test/src/math/smoke/CMakeFiles/libc.test.src.math.smoke.daddf128_test.__unit__.__build__.dir/daddf128_test.cpp.o
[40/1152] Building CXX object libc/test/src/math/smoke/CMakeFiles/libc.test.src.math.smoke.add_same_type_test.__unit__.__build__.dir/add_same_type_test.cpp.o
[41/1152] Building CXX object libc/test/src/math/smoke/CMakeFiles/libc.test.src.math.smoke.sub_same_type_test.__unit__.__build__.dir/sub_same_type_test.cpp.o
[42/1152] Running unit test libc.test.src.__support.freelist_test.__unit__
sh: line 1: /timer.2240: Permission denied
[==========] Running 1 test from 1 test suite.
[ RUN      ] LlvmLibcFreeList.FreeList
[       OK ] LlvmLibcFreeList.FreeList (2 ms)
Ran 1 tests.  PASS: 1  FAIL: 0
[43/1152] Running unit test libc.test.src.__support.fixedvector_test.__unit__
Step 8 (libc-unit-tests) failure: libc-unit-tests (failure)
...
[15/1152] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.dsubf128.dir/dsubf128.cpp.o
[16/1152] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.fsubf128.dir/fsubf128.cpp.o
[17/1152] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.daddf128.__internal__.dir/daddf128.cpp.o
[18/1152] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.fsubf128.__internal__.dir/fsubf128.cpp.o
[19/1152] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.daddl.__internal__.dir/daddl.cpp.o
[20/1152] Building CXX object libc/test/src/math/CMakeFiles/libc.test.src.math.daddl_test.__unit__.__build__.dir/daddl_test.cpp.o
[21/1152] Building CXX object libc/test/src/math/CMakeFiles/libc.test.src.math.faddl_test.__unit__.__build__.dir/faddl_test.cpp.o
[22/1152] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.faddl.dir/faddl.cpp.o
[23/1152] Building CXX object libc/test/src/math/CMakeFiles/libc.test.src.math.dsubl_test.__unit__.__build__.dir/dsubl_test.cpp.o
[24/1152] Building CXX object libc/utils/MPFRWrapper/CMakeFiles/libcMPFRWrapper.dir/MPFRUtils.cpp.o
FAILED: libc/utils/MPFRWrapper/CMakeFiles/libcMPFRWrapper.dir/MPFRUtils.cpp.o 
/usr/local/bin/clang++ -DLIBC_NAMESPACE=__llvm_libc_20_0_0_git -D_DEBUG -I/home/libcrv32buildbot/gmp+mpfr/include -I/home/libcrv32buildbot/bbroot/libc-riscv32-qemu-yocto-fullbuild-dbg/llvm-project/libc -mabi=ilp32d -march=rv32imafdc --target=riscv32-unknown-linux-gnu --sysroot=/opt/riscv/sysroot --gcc-toolchain=/opt/riscv -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -g -std=gnu++17 -O3 --target=riscv32-unknown-linux-gnu -fpie -DLIBC_FULL_BUILD -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -ffixed-point -Wconversion -Wno-sign-conversion -Wimplicit-fallthrough -Wwrite-strings -Wno-c99-extensions -Wno-gnu-imaginary-constant -Wno-pedantic -Wstrict-prototypes -Wextra-semi -Wnewline-eof -Wnonportable-system-include-path -Wthread-safety -MD -MT libc/utils/MPFRWrapper/CMakeFiles/libcMPFRWrapper.dir/MPFRUtils.cpp.o -MF libc/utils/MPFRWrapper/CMakeFiles/libcMPFRWrapper.dir/MPFRUtils.cpp.o.d -o libc/utils/MPFRWrapper/CMakeFiles/libcMPFRWrapper.dir/MPFRUtils.cpp.o -c /home/libcrv32buildbot/bbroot/libc-riscv32-qemu-yocto-fullbuild-dbg/llvm-project/libc/utils/MPFRWrapper/MPFRUtils.cpp
/home/libcrv32buildbot/bbroot/libc-riscv32-qemu-yocto-fullbuild-dbg/llvm-project/libc/utils/MPFRWrapper/MPFRUtils.cpp:405:15: error: duplicate explicit instantiation of 'explain_binary_operation_one_output_error<long double, long double>'
  405 | template void explain_binary_operation_one_output_error(
      |               ^
/home/libcrv32buildbot/bbroot/libc-riscv32-qemu-yocto-fullbuild-dbg/llvm-project/libc/utils/MPFRWrapper/MPFRUtils.cpp:390:1: note: previous explicit instantiation is here
  390 | explain_binary_operation_one_output_error(Operation,
      | ^
/home/libcrv32buildbot/bbroot/libc-riscv32-qemu-yocto-fullbuild-dbg/llvm-project/libc/utils/MPFRWrapper/MPFRUtils.cpp:633:15: error: duplicate explicit instantiation of 'compare_binary_operation_one_output<long double, long double>'
  633 | template bool compare_binary_operation_one_output(Operation,
      |               ^
/home/libcrv32buildbot/bbroot/libc-riscv32-qemu-yocto-fullbuild-dbg/llvm-project/libc/utils/MPFRWrapper/MPFRUtils.cpp:609:1: note: previous explicit instantiation is here
  609 | compare_binary_operation_one_output(Operation, const BinaryInput<long double> &,
      | ^
2 errors generated.
[25/1152] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.faddf128.dir/faddf128.cpp.o
[26/1152] Building CXX object libc/test/src/math/CMakeFiles/libc.test.src.math.fadd_test.__unit__.__build__.dir/fadd_test.cpp.o
[27/1152] Building CXX object libc/test/src/math/CMakeFiles/libc.test.src.math.fsubl_test.__unit__.__build__.dir/fsubl_test.cpp.o
[28/1152] Building CXX object libc/test/src/math/smoke/CMakeFiles/libc.test.src.math.smoke.fadd_test.__unit__.__build__.dir/fadd_test.cpp.o
[29/1152] Building CXX object libc/test/src/math/smoke/CMakeFiles/libc.test.src.math.smoke.dsubf128_test.__unit__.__build__.dir/dsubf128_test.cpp.o
[30/1152] Building CXX object libc/test/src/math/smoke/CMakeFiles/libc.test.src.math.smoke.faddf128_test.__unit__.__build__.dir/faddf128_test.cpp.o
[31/1152] Building CXX object libc/test/src/math/smoke/CMakeFiles/libc.test.src.math.smoke.faddl_test.__unit__.__build__.dir/faddl_test.cpp.o
[32/1152] Building CXX object libc/test/src/math/smoke/CMakeFiles/libc.test.src.math.smoke.dsubl_test.__unit__.__build__.dir/dsubl_test.cpp.o
[33/1152] Building CXX object libc/test/src/math/CMakeFiles/libc.test.src.math.sub_same_type_test.__unit__.__build__.dir/sub_same_type_test.cpp.o
[34/1152] Building CXX object libc/test/src/math/smoke/CMakeFiles/libc.test.src.math.smoke.fsub_test.__unit__.__build__.dir/fsub_test.cpp.o
[35/1152] Building CXX object libc/test/src/math/smoke/CMakeFiles/libc.test.src.math.smoke.fsubl_test.__unit__.__build__.dir/fsubl_test.cpp.o
[36/1152] Building CXX object libc/test/src/math/smoke/CMakeFiles/libc.test.src.math.smoke.daddl_test.__unit__.__build__.dir/daddl_test.cpp.o
[37/1152] Building CXX object libc/test/src/math/CMakeFiles/libc.test.src.math.add_same_type_test.__unit__.__build__.dir/add_same_type_test.cpp.o
[38/1152] Building CXX object libc/test/src/math/smoke/CMakeFiles/libc.test.src.math.smoke.fsubf128_test.__unit__.__build__.dir/fsubf128_test.cpp.o
[39/1152] Building CXX object libc/test/src/math/smoke/CMakeFiles/libc.test.src.math.smoke.daddf128_test.__unit__.__build__.dir/daddf128_test.cpp.o
[40/1152] Building CXX object libc/test/src/math/smoke/CMakeFiles/libc.test.src.math.smoke.add_same_type_test.__unit__.__build__.dir/add_same_type_test.cpp.o
[41/1152] Building CXX object libc/test/src/math/smoke/CMakeFiles/libc.test.src.math.smoke.sub_same_type_test.__unit__.__build__.dir/sub_same_type_test.cpp.o
[42/1152] Running unit test libc.test.src.__support.freelist_test.__unit__
sh: line 1: /timer.2240: Permission denied
[==========] Running 1 test from 1 test suite.
[ RUN      ] LlvmLibcFreeList.FreeList
[       OK ] LlvmLibcFreeList.FreeList (2 ms)
Ran 1 tests.  PASS: 1  FAIL: 0
[43/1152] Running unit test libc.test.src.__support.fixedvector_test.__unit__

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants