[libc-commits] [libc] 4497566 - [libc] Fix maybe unused warnings in Arm 32-bit no-FP baremetal builds (#237257)
via libc-commits
libc-commits at lists.llvm.org
Sun Nov 1 05:34:02 PST 2026
Author: Victor Campos
Date: 2026-11-01T13:33:57Z
New Revision: 4497566c7ca6b1d958fe27678f541308b948f6c2
URL: https://github.com/llvm/llvm-project/commit/4497566c7ca6b1d958fe27678f541308b948f6c2
DIFF: https://github.com/llvm/llvm-project/commit/4497566c7ca6b1d958fe27678f541308b948f6c2.diff
LOG: [libc] Fix maybe unused warnings in Arm 32-bit no-FP baremetal builds (#237257)
In configurations without floating-point, some variables end up not
used, hence warnings are shown because of this.
This patch adds `[[maybe_unused]]` to the definitions affected by this.
The ultimate goal is to re-enable `-Werror` in no-FP builds.
Added:
Modified:
libc/test/src/math/smoke/NearbyIntTest.h
libc/test/src/math/smoke/acosbf16_test.cpp
libc/test/src/stdfix/DiviFxTest.h
libc/test/src/stdfix/IdivFxTest.h
libc/test/src/time/asctime_r_test.cpp
libc/test/src/time/ctime_r_test.cpp
libc/test/src/time/gmtime_r_test.cpp
libc/test/src/time/localtime_r_test.cpp
Removed:
################################################################################
diff --git a/libc/test/src/math/smoke/NearbyIntTest.h b/libc/test/src/math/smoke/NearbyIntTest.h
index af7a7df3a068d3..faf727f1045a7f 100644
--- a/libc/test/src/math/smoke/NearbyIntTest.h
+++ b/libc/test/src/math/smoke/NearbyIntTest.h
@@ -60,18 +60,18 @@ class NearbyIntTestTemplate : public LIBC_NAMESPACE::testing::Test {
ASSERT_FP_EQ(func(-min_denormal), neg_zero);
}
- void testSubnormalTowardZero(NearbyIntFunc func) {
+ void testSubnormalTowardZero([[maybe_unused]] NearbyIntFunc func) {
EXPECT_FP_EQ_ROUNDING_TOWARD_ZERO(func(min_denormal), zero);
EXPECT_FP_EQ_ROUNDING_TOWARD_ZERO(func(-min_denormal), neg_zero);
}
- void testSubnormalToPosInf(NearbyIntFunc func) {
+ void testSubnormalToPosInf([[maybe_unused]] NearbyIntFunc func) {
EXPECT_FP_EQ_ROUNDING_UPWARD(func(min_denormal), FPBits::one().get_val());
EXPECT_FP_EQ_ROUNDING_UPWARD(func(-min_denormal), neg_zero);
}
- void testSubnormalToNegInf(NearbyIntFunc func) {
- T negative_one = FPBits::one(Sign::NEG).get_val();
+ void testSubnormalToNegInf([[maybe_unused]] NearbyIntFunc func) {
+ [[maybe_unused]] T negative_one = FPBits::one(Sign::NEG).get_val();
EXPECT_FP_EQ_ROUNDING_DOWNWARD(func(min_denormal), zero);
EXPECT_FP_EQ_ROUNDING_DOWNWARD(func(-min_denormal), negative_one);
}
diff --git a/libc/test/src/math/smoke/acosbf16_test.cpp b/libc/test/src/math/smoke/acosbf16_test.cpp
index a477a61c236185..a630d8997b6b01 100644
--- a/libc/test/src/math/smoke/acosbf16_test.cpp
+++ b/libc/test/src/math/smoke/acosbf16_test.cpp
@@ -65,7 +65,7 @@ TEST_F(LlvmLibcAcosBf16Test, SmallInputs) {
const uint16_t inputs[] = {0x0001, 0x007f, 0x0080, 0x209d,
0x397f, 0x3980, 0x3981};
const bfloat16 pi_2_lo = FPBits(uint16_t(0x3fc9)).get_val();
- const bfloat16 pi_2_hi = FPBits(uint16_t(0x3fca)).get_val();
+ [[maybe_unused]] const bfloat16 pi_2_hi = FPBits(uint16_t(0x3fca)).get_val();
for (uint16_t bits : inputs) {
bfloat16 x = FPBits(bits).get_val();
EXPECT_FP_EQ_ALL_ROUNDING(pi_2_lo, pi_2_hi, pi_2_lo, pi_2_lo,
diff --git a/libc/test/src/stdfix/DiviFxTest.h b/libc/test/src/stdfix/DiviFxTest.h
index 6bbfcd0f8e9fdc..c74285692e1083 100644
--- a/libc/test/src/stdfix/DiviFxTest.h
+++ b/libc/test/src/stdfix/DiviFxTest.h
@@ -151,7 +151,7 @@ class DiviFxTest : public LIBC_NAMESPACE::testing::Test {
}
}
- void testInvalidNumbers(DiviFxFunc func) {
+ void testInvalidNumbers([[maybe_unused]] DiviFxFunc func) {
EXPECT_DEATH([func] { func(1, zero); }, WITH_SIGNAL(-1));
if constexpr (has_integral) {
diff --git a/libc/test/src/stdfix/IdivFxTest.h b/libc/test/src/stdfix/IdivFxTest.h
index 1fe6e5706b7651..883669f0bf1c75 100644
--- a/libc/test/src/stdfix/IdivFxTest.h
+++ b/libc/test/src/stdfix/IdivFxTest.h
@@ -61,7 +61,7 @@ class IdivFxTest : public LIBC_NAMESPACE::testing::Test {
}
}
- void testInvalidNumbers(IdivFxFunc func) {
+ void testInvalidNumbers([[maybe_unused]] IdivFxFunc func) {
constexpr bool has_integral = (FXRep::INTEGRAL_LEN > 0);
EXPECT_DEATH([func] { func(0.5, 0.0); }, WITH_SIGNAL(-1));
diff --git a/libc/test/src/time/asctime_r_test.cpp b/libc/test/src/time/asctime_r_test.cpp
index 0183c2aab96870..123fcb092d2830 100644
--- a/libc/test/src/time/asctime_r_test.cpp
+++ b/libc/test/src/time/asctime_r_test.cpp
@@ -27,8 +27,9 @@ static inline char *call_asctime_r(struct tm *tm_data, int year, int month,
// asctime and asctime_r share the same code and thus didn't repeat all the
// tests from asctime. Added couple of validation tests.
TEST_F(LlvmLibcAsctimeR, Nullptr) {
- char buffer[LIBC_NAMESPACE::time_constants::ASCTIME_BUFFER_SIZE];
- struct tm tm_data;
+ [[maybe_unused]] char
+ buffer[LIBC_NAMESPACE::time_constants::ASCTIME_BUFFER_SIZE];
+ [[maybe_unused]] struct tm tm_data;
EXPECT_DEATH([] { LIBC_NAMESPACE::asctime_r(nullptr, nullptr); },
WITH_SIGNAL(-1));
EXPECT_DEATH([&] { LIBC_NAMESPACE::asctime_r(nullptr, buffer); },
diff --git a/libc/test/src/time/ctime_r_test.cpp b/libc/test/src/time/ctime_r_test.cpp
index 571bc310a1faf3..4d8432c9f6068b 100644
--- a/libc/test/src/time/ctime_r_test.cpp
+++ b/libc/test/src/time/ctime_r_test.cpp
@@ -17,8 +17,9 @@
using LlvmLibcCtimeR = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
TEST_F(LlvmLibcCtimeR, Nullptr) {
- char buffer[LIBC_NAMESPACE::time_constants::ASCTIME_BUFFER_SIZE];
- time_t t;
+ [[maybe_unused]] char
+ buffer[LIBC_NAMESPACE::time_constants::ASCTIME_BUFFER_SIZE];
+ [[maybe_unused]] time_t t;
EXPECT_DEATH([] { LIBC_NAMESPACE::ctime_r(nullptr, nullptr); },
WITH_SIGNAL(-1));
EXPECT_DEATH([&] { LIBC_NAMESPACE::ctime_r(nullptr, buffer); },
diff --git a/libc/test/src/time/gmtime_r_test.cpp b/libc/test/src/time/gmtime_r_test.cpp
index 1c5058b6654dbe..bd07263d0989f3 100644
--- a/libc/test/src/time/gmtime_r_test.cpp
+++ b/libc/test/src/time/gmtime_r_test.cpp
@@ -59,8 +59,8 @@ TEST_F(LlvmLibcGmTimeR, Max64BitYear) {
}
TEST_F(LlvmLibcGmTimeR, NullPtr) {
- struct tm tm_data;
- time_t seconds = 0;
+ [[maybe_unused]] struct tm tm_data;
+ [[maybe_unused]] time_t seconds = 0;
EXPECT_DEATH([] { LIBC_NAMESPACE::gmtime_r(nullptr, nullptr); },
WITH_SIGNAL(-1));
EXPECT_DEATH([&] { LIBC_NAMESPACE::gmtime_r(nullptr, &tm_data); },
diff --git a/libc/test/src/time/localtime_r_test.cpp b/libc/test/src/time/localtime_r_test.cpp
index bc71419d68c641..4df377ee030501 100644
--- a/libc/test/src/time/localtime_r_test.cpp
+++ b/libc/test/src/time/localtime_r_test.cpp
@@ -28,8 +28,8 @@ TEST(LlvmLibcLocaltimeR, ValidUnixTimestamp0) {
}
TEST(LlvmLibcLocaltimeR, NullPtr) {
- struct tm input;
- time_t timer = 0;
+ [[maybe_unused]] struct tm input;
+ [[maybe_unused]] time_t timer = 0;
EXPECT_DEATH([] { LIBC_NAMESPACE::localtime_r(nullptr, nullptr); },
WITH_SIGNAL(-1));
EXPECT_DEATH([&] { LIBC_NAMESPACE::localtime_r(nullptr, &input); },
More information about the libc-commits
mailing list