From 6dd5a77e6f107b5f83d82405a2f4346498228e73 Mon Sep 17 00:00:00 2001 From: Vinay Deshmukh <32487576+vinay-deshmukh@users.noreply.github.com> Date: Sat, 15 Mar 2025 22:01:35 -0400 Subject: [PATCH 01/28] `-Wglobal-constructors` --- libc/cmake/modules/LLVMLibCTestRules.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake index 45a36abd8ce1b..fef670885229c 100644 --- a/libc/cmake/modules/LLVMLibCTestRules.cmake +++ b/libc/cmake/modules/LLVMLibCTestRules.cmake @@ -57,7 +57,7 @@ function(_get_common_test_compile_options output_var c_test flags) list(APPEND compile_options "-Wnewline-eof") list(APPEND compile_options "-Wnonportable-system-include-path") list(APPEND compile_options "-Wthread-safety") - # list(APPEND compile_options "-Wglobal-constructors") + list(APPEND compile_options "-Wglobal-constructors") endif() endif() set(${output_var} ${compile_options} PARENT_SCOPE) From a142b5be42a18cc1cd06040af671ac6e92a0b2e6 Mon Sep 17 00:00:00 2001 From: Vinay Deshmukh <32487576+vinay-deshmukh@users.noreply.github.com> Date: Sat, 15 Mar 2025 22:09:31 -0400 Subject: [PATCH 02/28] Werror to break pipeline --- libc/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt index ad39ff6fbcb1e..15cbda1df7ded 100644 --- a/libc/CMakeLists.txt +++ b/libc/CMakeLists.txt @@ -34,6 +34,7 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug") add_definitions("-D_DEBUG") endif() +add_compile_options("-Werror") # Default to C++17 set(CMAKE_CXX_STANDARD 17) From 6b558fb81bfc129455e06d408b6adc03a42aa7be Mon Sep 17 00:00:00 2001 From: Vinay Deshmukh <32487576+vinay-deshmukh@users.noreply.github.com> Date: Mon, 17 Mar 2025 20:41:38 -0400 Subject: [PATCH 03/28] Use static member instances --- libc/test/UnitTest/LibcTest.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libc/test/UnitTest/LibcTest.h b/libc/test/UnitTest/LibcTest.h index fbeafd0bacb75..2c53a4127becf 100644 --- a/libc/test/UnitTest/LibcTest.h +++ b/libc/test/UnitTest/LibcTest.h @@ -350,9 +350,9 @@ CString libc_make_test_file_path_func(const char *file_name); } \ void Run() override; \ const char *getName() const override { return name; } \ - }; \ - TypeList::Tests::type \ + static TypeList::Tests::type \ SuiteName##_##TestName##_Instance; \ + }; \ template void SuiteName##_##TestName::Run() #define TYPED_TEST_F(SuiteClass, TestName, TypeList) \ @@ -370,9 +370,9 @@ CString libc_make_test_file_path_func(const char *file_name); } \ void Run() override; \ const char *getName() const override { return name; } \ - }; \ - TypeList::Tests::type \ + static TypeList::Tests::type \ SuiteClass##_##TestName##_Instance; \ + }; \ template void SuiteClass##_##TestName::Run() #define TEST(SuiteName, TestName) \ @@ -383,8 +383,8 @@ CString libc_make_test_file_path_func(const char *file_name); SuiteName##_##TestName() { addTest(this); } \ void Run() override; \ const char *getName() const override { return #SuiteName "." #TestName; } \ + static SuiteName##_##TestName SuiteName##_##TestName##_Instance; \ }; \ - SuiteName##_##TestName SuiteName##_##TestName##_Instance; \ void SuiteName##_##TestName::Run() #define TEST_F(SuiteClass, TestName) \ @@ -396,8 +396,8 @@ CString libc_make_test_file_path_func(const char *file_name); SuiteClass##_##TestName() { addTest(this); } \ void Run() override; \ const char *getName() const override { return #SuiteClass "." #TestName; } \ + static SuiteClass##_##TestName SuiteClass##_##TestName##_Instance; \ }; \ - SuiteClass##_##TestName SuiteClass##_##TestName##_Instance; \ void SuiteClass##_##TestName::Run() // Helper to trick the compiler into ignoring lack of braces on the else From 168dc9dfdd19f3d33f16971d38f365f7ac25cca0 Mon Sep 17 00:00:00 2001 From: Vinay Deshmukh <32487576+vinay-deshmukh@users.noreply.github.com> Date: Wed, 19 Mar 2025 20:20:53 -0400 Subject: [PATCH 04/28] cf --- libc/test/UnitTest/LibcTest.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libc/test/UnitTest/LibcTest.h b/libc/test/UnitTest/LibcTest.h index 2c53a4127becf..ed75e230218ca 100644 --- a/libc/test/UnitTest/LibcTest.h +++ b/libc/test/UnitTest/LibcTest.h @@ -351,7 +351,7 @@ CString libc_make_test_file_path_func(const char *file_name); void Run() override; \ const char *getName() const override { return name; } \ static TypeList::Tests::type \ - SuiteName##_##TestName##_Instance; \ + SuiteName##_##TestName##_Instance; \ }; \ template void SuiteName##_##TestName::Run() @@ -371,7 +371,7 @@ CString libc_make_test_file_path_func(const char *file_name); void Run() override; \ const char *getName() const override { return name; } \ static TypeList::Tests::type \ - SuiteClass##_##TestName##_Instance; \ + SuiteClass##_##TestName##_Instance; \ }; \ template void SuiteClass##_##TestName::Run() From 70ba2f96202ea8cf43fb6914afcadd4d5f765a19 Mon Sep 17 00:00:00 2001 From: Vinay Deshmukh <32487576+vinay-deshmukh@users.noreply.github.com> Date: Thu, 20 Mar 2025 18:31:53 -0400 Subject: [PATCH 05/28] try to isolate warning --- libc/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt index 15cbda1df7ded..b86eefc05e782 100644 --- a/libc/CMakeLists.txt +++ b/libc/CMakeLists.txt @@ -34,7 +34,7 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug") add_definitions("-D_DEBUG") endif() -add_compile_options("-Werror") +add_compile_options("-Werror=global-constructors") # Default to C++17 set(CMAKE_CXX_STANDARD 17) From 9bb0c5b4e417700ad5f87cf0173bc1203f054d7a Mon Sep 17 00:00:00 2001 From: Vinay Deshmukh <32487576+vinay-deshmukh@users.noreply.github.com> Date: Sun, 23 Mar 2025 15:16:20 -0400 Subject: [PATCH 06/28] constexpr ctor --- libc/test/UnitTest/LibcTest.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libc/test/UnitTest/LibcTest.h b/libc/test/UnitTest/LibcTest.h index ed75e230218ca..3da119cc070b4 100644 --- a/libc/test/UnitTest/LibcTest.h +++ b/libc/test/UnitTest/LibcTest.h @@ -343,7 +343,7 @@ CString libc_make_test_file_path_func(const char *file_name); public: \ using ParamType = T; \ char name[256]; \ - SuiteName##_##TestName() { \ + constexpr SuiteName##_##TestName() { \ addTest(this); \ LIBC_NAMESPACE::testing::internal::GenerateName( \ name, sizeof(name), #SuiteName "." #TestName); \ @@ -363,7 +363,7 @@ CString libc_make_test_file_path_func(const char *file_name); public: \ using ParamType = T; \ char name[256]; \ - SuiteClass##_##TestName() { \ + constexpr SuiteClass##_##TestName() { \ SuiteClass::addTest(this); \ LIBC_NAMESPACE::testing::internal::GenerateName( \ name, sizeof(name), #SuiteClass "." #TestName); \ @@ -380,7 +380,7 @@ CString libc_make_test_file_path_func(const char *file_name); "All LLVM-libc TEST suite names must start with 'LlvmLibc'."); \ class SuiteName##_##TestName : public LIBC_NAMESPACE::testing::Test { \ public: \ - SuiteName##_##TestName() { addTest(this); } \ + constexpr SuiteName##_##TestName() { addTest(this); } \ void Run() override; \ const char *getName() const override { return #SuiteName "." #TestName; } \ static SuiteName##_##TestName SuiteName##_##TestName##_Instance; \ @@ -393,7 +393,7 @@ CString libc_make_test_file_path_func(const char *file_name); "All LLVM-libc TEST_F suite class names must start with 'LlvmLibc'."); \ class SuiteClass##_##TestName : public SuiteClass { \ public: \ - SuiteClass##_##TestName() { addTest(this); } \ + constexpr SuiteClass##_##TestName() { addTest(this); } \ void Run() override; \ const char *getName() const override { return #SuiteClass "." #TestName; } \ static SuiteClass##_##TestName SuiteClass##_##TestName##_Instance; \ From ca587e0b135038f15bc5e16cb33e8878a299fc2c Mon Sep 17 00:00:00 2001 From: Vinay Deshmukh <32487576+vinay-deshmukh@users.noreply.github.com> Date: Sun, 23 Mar 2025 15:58:17 -0400 Subject: [PATCH 07/28] instance is constexpr --- libc/test/UnitTest/LibcTest.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libc/test/UnitTest/LibcTest.h b/libc/test/UnitTest/LibcTest.h index 3da119cc070b4..5e6149f88b4ba 100644 --- a/libc/test/UnitTest/LibcTest.h +++ b/libc/test/UnitTest/LibcTest.h @@ -350,7 +350,7 @@ CString libc_make_test_file_path_func(const char *file_name); } \ void Run() override; \ const char *getName() const override { return name; } \ - static TypeList::Tests::type \ + static constexpr TypeList::Tests::type \ SuiteName##_##TestName##_Instance; \ }; \ template void SuiteName##_##TestName::Run() @@ -370,7 +370,7 @@ CString libc_make_test_file_path_func(const char *file_name); } \ void Run() override; \ const char *getName() const override { return name; } \ - static TypeList::Tests::type \ + static constexpr TypeList::Tests::type \ SuiteClass##_##TestName##_Instance; \ }; \ template void SuiteClass##_##TestName::Run() @@ -383,7 +383,7 @@ CString libc_make_test_file_path_func(const char *file_name); constexpr SuiteName##_##TestName() { addTest(this); } \ void Run() override; \ const char *getName() const override { return #SuiteName "." #TestName; } \ - static SuiteName##_##TestName SuiteName##_##TestName##_Instance; \ + static constexpr SuiteName##_##TestName SuiteName##_##TestName##_Instance; \ }; \ void SuiteName##_##TestName::Run() @@ -396,7 +396,8 @@ CString libc_make_test_file_path_func(const char *file_name); constexpr SuiteClass##_##TestName() { addTest(this); } \ void Run() override; \ const char *getName() const override { return #SuiteClass "." #TestName; } \ - static SuiteClass##_##TestName SuiteClass##_##TestName##_Instance; \ + static constexpr SuiteClass##_##TestName \ + SuiteClass##_##TestName##_Instance; \ }; \ void SuiteClass##_##TestName::Run() From 82a84bb1d485089827fbe4378b9ce526145c00c2 Mon Sep 17 00:00:00 2001 From: Vinay Deshmukh <32487576+vinay-deshmukh@users.noreply.github.com> Date: Sun, 23 Mar 2025 16:09:51 -0400 Subject: [PATCH 08/28] default constexpr for Test --- libc/test/UnitTest/LibcTest.h | 1 + 1 file changed, 1 insertion(+) diff --git a/libc/test/UnitTest/LibcTest.h b/libc/test/UnitTest/LibcTest.h index 5e6149f88b4ba..5d5555b611a47 100644 --- a/libc/test/UnitTest/LibcTest.h +++ b/libc/test/UnitTest/LibcTest.h @@ -120,6 +120,7 @@ class Test { static int getNumTests(); public: + constexpr Test() = default; virtual ~Test() {} virtual void SetUp() {} virtual void TearDown() {} From 05733f7a628c6e2549bd7618a7759d5ad62a7ee6 Mon Sep 17 00:00:00 2001 From: Vinay Deshmukh <32487576+vinay-deshmukh@users.noreply.github.com> Date: Sun, 23 Mar 2025 16:17:42 -0400 Subject: [PATCH 09/28] outside --- libc/test/UnitTest/LibcTest.h | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/libc/test/UnitTest/LibcTest.h b/libc/test/UnitTest/LibcTest.h index 5d5555b611a47..2dc9306bad46e 100644 --- a/libc/test/UnitTest/LibcTest.h +++ b/libc/test/UnitTest/LibcTest.h @@ -351,9 +351,9 @@ CString libc_make_test_file_path_func(const char *file_name); } \ void Run() override; \ const char *getName() const override { return name; } \ - static constexpr TypeList::Tests::type \ - SuiteName##_##TestName##_Instance; \ }; \ + constexpr TypeList::Tests::type \ + SuiteName##_##TestName##_Instance; \ template void SuiteName##_##TestName::Run() #define TYPED_TEST_F(SuiteClass, TestName, TypeList) \ @@ -371,9 +371,9 @@ CString libc_make_test_file_path_func(const char *file_name); } \ void Run() override; \ const char *getName() const override { return name; } \ - static constexpr TypeList::Tests::type \ - SuiteClass##_##TestName##_Instance; \ }; \ + static constexpr TypeList::Tests::type \ + SuiteClass##_##TestName##_Instance; \ template void SuiteClass##_##TestName::Run() #define TEST(SuiteName, TestName) \ @@ -384,8 +384,8 @@ CString libc_make_test_file_path_func(const char *file_name); constexpr SuiteName##_##TestName() { addTest(this); } \ void Run() override; \ const char *getName() const override { return #SuiteName "." #TestName; } \ - static constexpr SuiteName##_##TestName SuiteName##_##TestName##_Instance; \ }; \ + static constexpr SuiteName##_##TestName SuiteName##_##TestName##_Instance; \ void SuiteName##_##TestName::Run() #define TEST_F(SuiteClass, TestName) \ @@ -397,9 +397,8 @@ CString libc_make_test_file_path_func(const char *file_name); constexpr SuiteClass##_##TestName() { addTest(this); } \ void Run() override; \ const char *getName() const override { return #SuiteClass "." #TestName; } \ - static constexpr SuiteClass##_##TestName \ - SuiteClass##_##TestName##_Instance; \ }; \ + static constexpr SuiteClass##_##TestName SuiteClass##_##TestName##_Instance; \ void SuiteClass##_##TestName::Run() // Helper to trick the compiler into ignoring lack of braces on the else From 928e5c16e88f3acd857961ddfbed564eefaf36c1 Mon Sep 17 00:00:00 2001 From: Vinay Deshmukh <32487576+vinay-deshmukh@users.noreply.github.com> Date: Sun, 23 Mar 2025 16:27:46 -0400 Subject: [PATCH 10/28] remove virtual dtor --- libc/test/UnitTest/LibcTest.h | 1 - 1 file changed, 1 deletion(-) diff --git a/libc/test/UnitTest/LibcTest.h b/libc/test/UnitTest/LibcTest.h index 2dc9306bad46e..e5cfc05e4e368 100644 --- a/libc/test/UnitTest/LibcTest.h +++ b/libc/test/UnitTest/LibcTest.h @@ -121,7 +121,6 @@ class Test { public: constexpr Test() = default; - virtual ~Test() {} virtual void SetUp() {} virtual void TearDown() {} From 0ab296549a59d8aac3c4ef6326924959d65cef01 Mon Sep 17 00:00:00 2001 From: Vinay Deshmukh <32487576+vinay-deshmukh@users.noreply.github.com> Date: Sun, 23 Mar 2025 16:39:39 -0400 Subject: [PATCH 11/28] note: non-constexpr function addTest cannot be used in a constant expression --- libc/test/UnitTest/LibcTest.cpp | 11 ----------- libc/test/UnitTest/LibcTest.h | 13 ++++++++++++- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/libc/test/UnitTest/LibcTest.cpp b/libc/test/UnitTest/LibcTest.cpp index fec45982f3e63..e1033240d3550 100644 --- a/libc/test/UnitTest/LibcTest.cpp +++ b/libc/test/UnitTest/LibcTest.cpp @@ -116,17 +116,6 @@ char **envp = nullptr; using internal::RunContext; -void Test::addTest(Test *T) { - if (End == nullptr) { - Start = T; - End = T; - return; - } - - End->Next = T; - End = T; -} - int Test::getNumTests() { int N = 0; for (Test *T = Start; T; T = T->Next, ++N) diff --git a/libc/test/UnitTest/LibcTest.h b/libc/test/UnitTest/LibcTest.h index e5cfc05e4e368..49937bf84114d 100644 --- a/libc/test/UnitTest/LibcTest.h +++ b/libc/test/UnitTest/LibcTest.h @@ -127,7 +127,18 @@ class Test { static int runTests(const TestOptions &Options); protected: - static void addTest(Test *T); + constexpr static void *addTest(Test *T) { + if (End == nullptr) { + Start = T; + End = T; + // read of constexpr + return nullptr; + } + + End->Next = T; + End = T; + return nullptr; + } // We make use of a template function, with |LHS| and |RHS| as explicit // parameters, for enhanced type checking. Other gtest like unittest From ec4be668567ce300ef857c2e96bfba94777b6663 Mon Sep 17 00:00:00 2001 From: Vinay Deshmukh <32487576+vinay-deshmukh@users.noreply.github.com> Date: Sun, 23 Mar 2025 16:59:07 -0400 Subject: [PATCH 12/28] restore to original --- libc/test/UnitTest/LibcTest.cpp | 11 +++++++++++ libc/test/UnitTest/LibcTest.h | 31 ++++++++++--------------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/libc/test/UnitTest/LibcTest.cpp b/libc/test/UnitTest/LibcTest.cpp index e1033240d3550..fec45982f3e63 100644 --- a/libc/test/UnitTest/LibcTest.cpp +++ b/libc/test/UnitTest/LibcTest.cpp @@ -116,6 +116,17 @@ char **envp = nullptr; using internal::RunContext; +void Test::addTest(Test *T) { + if (End == nullptr) { + Start = T; + End = T; + return; + } + + End->Next = T; + End = T; +} + int Test::getNumTests() { int N = 0; for (Test *T = Start; T; T = T->Next, ++N) diff --git a/libc/test/UnitTest/LibcTest.h b/libc/test/UnitTest/LibcTest.h index 49937bf84114d..fbeafd0bacb75 100644 --- a/libc/test/UnitTest/LibcTest.h +++ b/libc/test/UnitTest/LibcTest.h @@ -120,25 +120,14 @@ class Test { static int getNumTests(); public: - constexpr Test() = default; + virtual ~Test() {} virtual void SetUp() {} virtual void TearDown() {} static int runTests(const TestOptions &Options); protected: - constexpr static void *addTest(Test *T) { - if (End == nullptr) { - Start = T; - End = T; - // read of constexpr - return nullptr; - } - - End->Next = T; - End = T; - return nullptr; - } + static void addTest(Test *T); // We make use of a template function, with |LHS| and |RHS| as explicit // parameters, for enhanced type checking. Other gtest like unittest @@ -354,7 +343,7 @@ CString libc_make_test_file_path_func(const char *file_name); public: \ using ParamType = T; \ char name[256]; \ - constexpr SuiteName##_##TestName() { \ + SuiteName##_##TestName() { \ addTest(this); \ LIBC_NAMESPACE::testing::internal::GenerateName( \ name, sizeof(name), #SuiteName "." #TestName); \ @@ -362,7 +351,7 @@ CString libc_make_test_file_path_func(const char *file_name); void Run() override; \ const char *getName() const override { return name; } \ }; \ - constexpr TypeList::Tests::type \ + TypeList::Tests::type \ SuiteName##_##TestName##_Instance; \ template void SuiteName##_##TestName::Run() @@ -374,7 +363,7 @@ CString libc_make_test_file_path_func(const char *file_name); public: \ using ParamType = T; \ char name[256]; \ - constexpr SuiteClass##_##TestName() { \ + SuiteClass##_##TestName() { \ SuiteClass::addTest(this); \ LIBC_NAMESPACE::testing::internal::GenerateName( \ name, sizeof(name), #SuiteClass "." #TestName); \ @@ -382,7 +371,7 @@ CString libc_make_test_file_path_func(const char *file_name); void Run() override; \ const char *getName() const override { return name; } \ }; \ - static constexpr TypeList::Tests::type \ + TypeList::Tests::type \ SuiteClass##_##TestName##_Instance; \ template void SuiteClass##_##TestName::Run() @@ -391,11 +380,11 @@ CString libc_make_test_file_path_func(const char *file_name); "All LLVM-libc TEST suite names must start with 'LlvmLibc'."); \ class SuiteName##_##TestName : public LIBC_NAMESPACE::testing::Test { \ public: \ - constexpr SuiteName##_##TestName() { addTest(this); } \ + SuiteName##_##TestName() { addTest(this); } \ void Run() override; \ const char *getName() const override { return #SuiteName "." #TestName; } \ }; \ - static constexpr SuiteName##_##TestName SuiteName##_##TestName##_Instance; \ + SuiteName##_##TestName SuiteName##_##TestName##_Instance; \ void SuiteName##_##TestName::Run() #define TEST_F(SuiteClass, TestName) \ @@ -404,11 +393,11 @@ CString libc_make_test_file_path_func(const char *file_name); "All LLVM-libc TEST_F suite class names must start with 'LlvmLibc'."); \ class SuiteClass##_##TestName : public SuiteClass { \ public: \ - constexpr SuiteClass##_##TestName() { addTest(this); } \ + SuiteClass##_##TestName() { addTest(this); } \ void Run() override; \ const char *getName() const override { return #SuiteClass "." #TestName; } \ }; \ - static constexpr SuiteClass##_##TestName SuiteClass##_##TestName##_Instance; \ + SuiteClass##_##TestName SuiteClass##_##TestName##_Instance; \ void SuiteClass##_##TestName::Run() // Helper to trick the compiler into ignoring lack of braces on the else From 620bf4a5fd2045f3d39e72c387fb36104a8d5434 Mon Sep 17 00:00:00 2001 From: Vinay Deshmukh <32487576+vinay-deshmukh@users.noreply.github.com> Date: Sun, 23 Mar 2025 17:04:36 -0400 Subject: [PATCH 13/28] pragma wrap --- libc/test/UnitTest/LibcTest.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libc/test/UnitTest/LibcTest.h b/libc/test/UnitTest/LibcTest.h index fbeafd0bacb75..6f3357730697a 100644 --- a/libc/test/UnitTest/LibcTest.h +++ b/libc/test/UnitTest/LibcTest.h @@ -334,6 +334,9 @@ CString libc_make_test_file_path_func(const char *file_name); return "[ParamType = " #TYPE "]"; \ } +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wglobal-constructors" + #define TYPED_TEST(SuiteName, TestName, TypeList) \ static_assert( \ LIBC_NAMESPACE::testing::internal::valid_prefix(#SuiteName), \ @@ -400,6 +403,8 @@ CString libc_make_test_file_path_func(const char *file_name); SuiteClass##_##TestName SuiteClass##_##TestName##_Instance; \ void SuiteClass##_##TestName::Run() +#pragma GCC diagnostic pop + // Helper to trick the compiler into ignoring lack of braces on the else // branch. We cannot introduce braces at this point, since it would prevent // using `<< ...` after the test macro for additional failure output. From e8be0531188144630cb2230d7f5091da328d7344 Mon Sep 17 00:00:00 2001 From: Vinay Deshmukh <32487576+vinay-deshmukh@users.noreply.github.com> Date: Sun, 23 Mar 2025 17:14:19 -0400 Subject: [PATCH 14/28] pragma wrap --- libc/test/UnitTest/LibcTest.h | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/libc/test/UnitTest/LibcTest.h b/libc/test/UnitTest/LibcTest.h index 6f3357730697a..e62f5313eda44 100644 --- a/libc/test/UnitTest/LibcTest.h +++ b/libc/test/UnitTest/LibcTest.h @@ -334,8 +334,11 @@ CString libc_make_test_file_path_func(const char *file_name); return "[ParamType = " #TYPE "]"; \ } -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wglobal-constructors" +#define DO_PRAGMA_BEGIN #pragma GCC diagnostic push + +#define DO_PRAGMA #pragma GCC diagnostic ignored "-Wglobal-constructors" + +#define DO_PRAGMA_END #pragma GCC diagnostic pop #define TYPED_TEST(SuiteName, TestName, TypeList) \ static_assert( \ @@ -354,8 +357,11 @@ CString libc_make_test_file_path_func(const char *file_name); void Run() override; \ const char *getName() const override { return name; } \ }; \ + DO_PRAGMA_BEGIN \ + DO_PRAGMA \ TypeList::Tests::type \ SuiteName##_##TestName##_Instance; \ + DO_PRAGMA_END \ template void SuiteName##_##TestName::Run() #define TYPED_TEST_F(SuiteClass, TestName, TypeList) \ @@ -374,8 +380,11 @@ CString libc_make_test_file_path_func(const char *file_name); void Run() override; \ const char *getName() const override { return name; } \ }; \ + DO_PRAGMA_BEGIN \ + DO_PRAGMA \ TypeList::Tests::type \ SuiteClass##_##TestName##_Instance; \ + DO_PRAGMA_END \ template void SuiteClass##_##TestName::Run() #define TEST(SuiteName, TestName) \ @@ -387,7 +396,10 @@ CString libc_make_test_file_path_func(const char *file_name); void Run() override; \ const char *getName() const override { return #SuiteName "." #TestName; } \ }; \ + DO_PRAGMA_BEGIN \ + DO_PRAGMA \ SuiteName##_##TestName SuiteName##_##TestName##_Instance; \ + DO_PRAGMA_END \ void SuiteName##_##TestName::Run() #define TEST_F(SuiteClass, TestName) \ @@ -400,11 +412,12 @@ CString libc_make_test_file_path_func(const char *file_name); void Run() override; \ const char *getName() const override { return #SuiteClass "." #TestName; } \ }; \ + DO_PRAGMA_BEGIN \ + DO_PRAGMA \ SuiteClass##_##TestName SuiteClass##_##TestName##_Instance; \ + DO_PRAGMA_END \ void SuiteClass##_##TestName::Run() -#pragma GCC diagnostic pop - // Helper to trick the compiler into ignoring lack of braces on the else // branch. We cannot introduce braces at this point, since it would prevent // using `<< ...` after the test macro for additional failure output. From 889c3ba2b9dd54b97b8bf37f6151fcd06251e596 Mon Sep 17 00:00:00 2001 From: Vinay Deshmukh <32487576+vinay-deshmukh@users.noreply.github.com> Date: Mon, 24 Mar 2025 19:21:41 -0400 Subject: [PATCH 15/28] undo pragma --- libc/CMakeLists.txt | 2 +- libc/test/UnitTest/LibcTest.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt index b86eefc05e782..b2a5b3ae246a3 100644 --- a/libc/CMakeLists.txt +++ b/libc/CMakeLists.txt @@ -34,7 +34,7 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug") add_definitions("-D_DEBUG") endif() -add_compile_options("-Werror=global-constructors") +# add_compile_options("-Werror=global-constructors") # Default to C++17 set(CMAKE_CXX_STANDARD 17) diff --git a/libc/test/UnitTest/LibcTest.h b/libc/test/UnitTest/LibcTest.h index e62f5313eda44..6299d43f52d0b 100644 --- a/libc/test/UnitTest/LibcTest.h +++ b/libc/test/UnitTest/LibcTest.h @@ -334,11 +334,11 @@ CString libc_make_test_file_path_func(const char *file_name); return "[ParamType = " #TYPE "]"; \ } -#define DO_PRAGMA_BEGIN #pragma GCC diagnostic push +#define DO_PRAGMA_BEGIN -#define DO_PRAGMA #pragma GCC diagnostic ignored "-Wglobal-constructors" +#define DO_PRAGMA -#define DO_PRAGMA_END #pragma GCC diagnostic pop +#define DO_PRAGMA_END #define TYPED_TEST(SuiteName, TestName, TypeList) \ static_assert( \ From 94a783bd797913834b2af8fb9b6dee46ba0b913d Mon Sep 17 00:00:00 2001 From: Vinay Deshmukh <32487576+vinay-deshmukh@users.noreply.github.com> Date: Sun, 30 Mar 2025 09:21:15 -0400 Subject: [PATCH 16/28] remove pragma attempt --- libc/test/UnitTest/LibcTest.h | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/libc/test/UnitTest/LibcTest.h b/libc/test/UnitTest/LibcTest.h index 6299d43f52d0b..ed75e230218ca 100644 --- a/libc/test/UnitTest/LibcTest.h +++ b/libc/test/UnitTest/LibcTest.h @@ -334,12 +334,6 @@ CString libc_make_test_file_path_func(const char *file_name); return "[ParamType = " #TYPE "]"; \ } -#define DO_PRAGMA_BEGIN - -#define DO_PRAGMA - -#define DO_PRAGMA_END - #define TYPED_TEST(SuiteName, TestName, TypeList) \ static_assert( \ LIBC_NAMESPACE::testing::internal::valid_prefix(#SuiteName), \ @@ -356,12 +350,9 @@ CString libc_make_test_file_path_func(const char *file_name); } \ void Run() override; \ const char *getName() const override { return name; } \ + static TypeList::Tests::type \ + SuiteName##_##TestName##_Instance; \ }; \ - DO_PRAGMA_BEGIN \ - DO_PRAGMA \ - TypeList::Tests::type \ - SuiteName##_##TestName##_Instance; \ - DO_PRAGMA_END \ template void SuiteName##_##TestName::Run() #define TYPED_TEST_F(SuiteClass, TestName, TypeList) \ @@ -379,12 +370,9 @@ CString libc_make_test_file_path_func(const char *file_name); } \ void Run() override; \ const char *getName() const override { return name; } \ + static TypeList::Tests::type \ + SuiteClass##_##TestName##_Instance; \ }; \ - DO_PRAGMA_BEGIN \ - DO_PRAGMA \ - TypeList::Tests::type \ - SuiteClass##_##TestName##_Instance; \ - DO_PRAGMA_END \ template void SuiteClass##_##TestName::Run() #define TEST(SuiteName, TestName) \ @@ -395,11 +383,8 @@ CString libc_make_test_file_path_func(const char *file_name); SuiteName##_##TestName() { addTest(this); } \ void Run() override; \ const char *getName() const override { return #SuiteName "." #TestName; } \ + static SuiteName##_##TestName SuiteName##_##TestName##_Instance; \ }; \ - DO_PRAGMA_BEGIN \ - DO_PRAGMA \ - SuiteName##_##TestName SuiteName##_##TestName##_Instance; \ - DO_PRAGMA_END \ void SuiteName##_##TestName::Run() #define TEST_F(SuiteClass, TestName) \ @@ -411,11 +396,8 @@ CString libc_make_test_file_path_func(const char *file_name); SuiteClass##_##TestName() { addTest(this); } \ void Run() override; \ const char *getName() const override { return #SuiteClass "." #TestName; } \ + static SuiteClass##_##TestName SuiteClass##_##TestName##_Instance; \ }; \ - DO_PRAGMA_BEGIN \ - DO_PRAGMA \ - SuiteClass##_##TestName SuiteClass##_##TestName##_Instance; \ - DO_PRAGMA_END \ void SuiteClass##_##TestName::Run() // Helper to trick the compiler into ignoring lack of braces on the else From f20b84d74b0dfd13b49a3ddd84076349f1916b6f Mon Sep 17 00:00:00 2001 From: Vinay Deshmukh <32487576+vinay-deshmukh@users.noreply.github.com> Date: Sun, 30 Mar 2025 09:48:55 -0400 Subject: [PATCH 17/28] Fix cmake failure --- libc/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt index b2a5b3ae246a3..b86eefc05e782 100644 --- a/libc/CMakeLists.txt +++ b/libc/CMakeLists.txt @@ -34,7 +34,7 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug") add_definitions("-D_DEBUG") endif() -# add_compile_options("-Werror=global-constructors") +add_compile_options("-Werror=global-constructors") # Default to C++17 set(CMAKE_CXX_STANDARD 17) From fbb0ca5473835f18e6ac3ead2a14a81298d59127 Mon Sep 17 00:00:00 2001 From: Vinay Deshmukh <32487576+vinay-deshmukh@users.noreply.github.com> Date: Sun, 30 Mar 2025 09:49:12 -0400 Subject: [PATCH 18/28] Use _Pragma correctly --- libc/test/UnitTest/LibcTest.h | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/libc/test/UnitTest/LibcTest.h b/libc/test/UnitTest/LibcTest.h index ed75e230218ca..f2d71c0e32647 100644 --- a/libc/test/UnitTest/LibcTest.h +++ b/libc/test/UnitTest/LibcTest.h @@ -334,6 +334,15 @@ CString libc_make_test_file_path_func(const char *file_name); return "[ParamType = " #TYPE "]"; \ } + +#define DO_PRAGMA(x) _Pragma (#x); + +#define DO_PRAGMA_BEGIN DO_PRAGMA(GCC diagnostic push) + +#define DO_PRAGMA_BODY DO_PRAGMA(GCC diagnostic ignored "-Wglobal-constructors") + +#define DO_PRAGMA_END DO_PRAGMA(GCC diagnostic pop) + #define TYPED_TEST(SuiteName, TestName, TypeList) \ static_assert( \ LIBC_NAMESPACE::testing::internal::valid_prefix(#SuiteName), \ @@ -350,9 +359,12 @@ CString libc_make_test_file_path_func(const char *file_name); } \ void Run() override; \ const char *getName() const override { return name; } \ - static TypeList::Tests::type \ - SuiteName##_##TestName##_Instance; \ }; \ + DO_PRAGMA_BEGIN \ + DO_PRAGMA_BODY \ + TypeList::Tests::type \ + SuiteName##_##TestName##_Instance; \ + DO_PRAGMA_END \ template void SuiteName##_##TestName::Run() #define TYPED_TEST_F(SuiteClass, TestName, TypeList) \ @@ -370,9 +382,12 @@ CString libc_make_test_file_path_func(const char *file_name); } \ void Run() override; \ const char *getName() const override { return name; } \ - static TypeList::Tests::type \ - SuiteClass##_##TestName##_Instance; \ }; \ + DO_PRAGMA_BEGIN \ + DO_PRAGMA_BODY \ + TypeList::Tests::type \ + SuiteClass##_##TestName##_Instance; \ + DO_PRAGMA_END \ template void SuiteClass##_##TestName::Run() #define TEST(SuiteName, TestName) \ @@ -383,8 +398,11 @@ CString libc_make_test_file_path_func(const char *file_name); SuiteName##_##TestName() { addTest(this); } \ void Run() override; \ const char *getName() const override { return #SuiteName "." #TestName; } \ - static SuiteName##_##TestName SuiteName##_##TestName##_Instance; \ }; \ + DO_PRAGMA_BEGIN \ + DO_PRAGMA_BODY \ + SuiteName##_##TestName SuiteName##_##TestName##_Instance; \ + DO_PRAGMA_END \ void SuiteName##_##TestName::Run() #define TEST_F(SuiteClass, TestName) \ @@ -396,8 +414,11 @@ CString libc_make_test_file_path_func(const char *file_name); SuiteClass##_##TestName() { addTest(this); } \ void Run() override; \ const char *getName() const override { return #SuiteClass "." #TestName; } \ - static SuiteClass##_##TestName SuiteClass##_##TestName##_Instance; \ }; \ + DO_PRAGMA_BEGIN \ + DO_PRAGMA_BODY \ + SuiteClass##_##TestName SuiteClass##_##TestName##_Instance; \ + DO_PRAGMA_END \ void SuiteClass##_##TestName::Run() // Helper to trick the compiler into ignoring lack of braces on the else From 009b11b923b98148aa5748b26cb0f9485e2c5be1 Mon Sep 17 00:00:00 2001 From: Vinay Deshmukh <32487576+vinay-deshmukh@users.noreply.github.com> Date: Sun, 30 Mar 2025 09:56:27 -0400 Subject: [PATCH 19/28] collisions --- libc/test/UnitTest/LibcTest.h | 37 +++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/libc/test/UnitTest/LibcTest.h b/libc/test/UnitTest/LibcTest.h index f2d71c0e32647..d3f8357267002 100644 --- a/libc/test/UnitTest/LibcTest.h +++ b/libc/test/UnitTest/LibcTest.h @@ -334,14 +334,17 @@ CString libc_make_test_file_path_func(const char *file_name); return "[ParamType = " #TYPE "]"; \ } +#define LIBC_TEST_GLOBAL_CTOR_DO_PRAGMA(x) _Pragma(#x); -#define DO_PRAGMA(x) _Pragma (#x); +#define LIBC_TEST_GLOBAL_CTOR_DO_PRAGMA_BEGIN \ + LIBC_TEST_GLOBAL_CTOR_DO_PRAGMA(GCC diagnostic push) -#define DO_PRAGMA_BEGIN DO_PRAGMA(GCC diagnostic push) +#define LIBC_TEST_GLOBAL_CTOR_DO_PRAGMA_BODY \ + LIBC_TEST_GLOBAL_CTOR_DO_PRAGMA(GCC diagnostic ignored \ + "-Wglobal-constructors") -#define DO_PRAGMA_BODY DO_PRAGMA(GCC diagnostic ignored "-Wglobal-constructors") - -#define DO_PRAGMA_END DO_PRAGMA(GCC diagnostic pop) +#define LIBC_TEST_GLOBAL_CTOR_DO_PRAGMA_END \ + LIBC_TEST_GLOBAL_CTOR_DO_PRAGMA(GCC diagnostic pop) #define TYPED_TEST(SuiteName, TestName, TypeList) \ static_assert( \ @@ -360,11 +363,11 @@ CString libc_make_test_file_path_func(const char *file_name); void Run() override; \ const char *getName() const override { return name; } \ }; \ - DO_PRAGMA_BEGIN \ - DO_PRAGMA_BODY \ + LIBC_TEST_GLOBAL_CTOR_DO_PRAGMA_BEGIN \ + LIBC_TEST_GLOBAL_CTOR_DO_PRAGMA_BODY \ TypeList::Tests::type \ SuiteName##_##TestName##_Instance; \ - DO_PRAGMA_END \ + LIBC_TEST_GLOBAL_CTOR_DO_PRAGMA_END \ template void SuiteName##_##TestName::Run() #define TYPED_TEST_F(SuiteClass, TestName, TypeList) \ @@ -383,11 +386,11 @@ CString libc_make_test_file_path_func(const char *file_name); void Run() override; \ const char *getName() const override { return name; } \ }; \ - DO_PRAGMA_BEGIN \ - DO_PRAGMA_BODY \ + LIBC_TEST_GLOBAL_CTOR_DO_PRAGMA_BEGIN \ + LIBC_TEST_GLOBAL_CTOR_DO_PRAGMA_BODY \ TypeList::Tests::type \ SuiteClass##_##TestName##_Instance; \ - DO_PRAGMA_END \ + LIBC_TEST_GLOBAL_CTOR_DO_PRAGMA_END \ template void SuiteClass##_##TestName::Run() #define TEST(SuiteName, TestName) \ @@ -399,10 +402,10 @@ CString libc_make_test_file_path_func(const char *file_name); void Run() override; \ const char *getName() const override { return #SuiteName "." #TestName; } \ }; \ - DO_PRAGMA_BEGIN \ - DO_PRAGMA_BODY \ + LIBC_TEST_GLOBAL_CTOR_DO_PRAGMA_BEGIN \ + LIBC_TEST_GLOBAL_CTOR_DO_PRAGMA_BODY \ SuiteName##_##TestName SuiteName##_##TestName##_Instance; \ - DO_PRAGMA_END \ + LIBC_TEST_GLOBAL_CTOR_DO_PRAGMA_END \ void SuiteName##_##TestName::Run() #define TEST_F(SuiteClass, TestName) \ @@ -415,10 +418,10 @@ CString libc_make_test_file_path_func(const char *file_name); void Run() override; \ const char *getName() const override { return #SuiteClass "." #TestName; } \ }; \ - DO_PRAGMA_BEGIN \ - DO_PRAGMA_BODY \ + LIBC_TEST_GLOBAL_CTOR_DO_PRAGMA_BEGIN \ + LIBC_TEST_GLOBAL_CTOR_DO_PRAGMA_BODY \ SuiteClass##_##TestName SuiteClass##_##TestName##_Instance; \ - DO_PRAGMA_END \ + LIBC_TEST_GLOBAL_CTOR_DO_PRAGMA_END \ void SuiteClass##_##TestName::Run() // Helper to trick the compiler into ignoring lack of braces on the else From 54b604a00089131dfd2b97b24f534e3c5ed7bb30 Mon Sep 17 00:00:00 2001 From: Vinay Deshmukh <32487576+vinay-deshmukh@users.noreply.github.com> Date: Sun, 30 Mar 2025 10:33:19 -0400 Subject: [PATCH 20/28] warning: extra ';' outside of a function is incompatible with C++98 [-Wc++98-compat-extra-semi] --- libc/test/UnitTest/LibcTest.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libc/test/UnitTest/LibcTest.h b/libc/test/UnitTest/LibcTest.h index d3f8357267002..54221de4da454 100644 --- a/libc/test/UnitTest/LibcTest.h +++ b/libc/test/UnitTest/LibcTest.h @@ -334,7 +334,7 @@ CString libc_make_test_file_path_func(const char *file_name); return "[ParamType = " #TYPE "]"; \ } -#define LIBC_TEST_GLOBAL_CTOR_DO_PRAGMA(x) _Pragma(#x); +#define LIBC_TEST_GLOBAL_CTOR_DO_PRAGMA(x) _Pragma(#x) #define LIBC_TEST_GLOBAL_CTOR_DO_PRAGMA_BEGIN \ LIBC_TEST_GLOBAL_CTOR_DO_PRAGMA(GCC diagnostic push) From ccf13f36962e89e19f0bb0a501e7e068e1dd2e74 Mon Sep 17 00:00:00 2001 From: Vinay Deshmukh <32487576+vinay-deshmukh@users.noreply.github.com> Date: Sun, 30 Mar 2025 10:52:28 -0400 Subject: [PATCH 21/28] Assume it's an intentional global --- libc/test/integration/startup/gpu/init_fini_array_test.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libc/test/integration/startup/gpu/init_fini_array_test.cpp b/libc/test/integration/startup/gpu/init_fini_array_test.cpp index ceedd5fc81358..52005ba627062 100644 --- a/libc/test/integration/startup/gpu/init_fini_array_test.cpp +++ b/libc/test/integration/startup/gpu/init_fini_array_test.cpp @@ -32,7 +32,10 @@ int GLOBAL_INDEX = 512; int INITVAL_INITIALIZER = 0x600D; int BEFORE_INITIALIZER = 0xFEED; +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wglobal-constructors" A global(GLOBAL_INDEX, INITVAL_INITIALIZER); +#pragma GCC diagnostic pop int initval = 0; int before = 0; From 9b0cff4c28099536f47ac8a2efb740f28b958535 Mon Sep 17 00:00:00 2001 From: Vinay Deshmukh <32487576+vinay-deshmukh@users.noreply.github.com> Date: Sun, 30 Mar 2025 11:08:53 -0400 Subject: [PATCH 22/28] another one --- libc/test/integration/startup/linux/init_fini_array_test.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libc/test/integration/startup/linux/init_fini_array_test.cpp b/libc/test/integration/startup/linux/init_fini_array_test.cpp index ed14e03a60c05..d2ee48c3428ff 100644 --- a/libc/test/integration/startup/linux/init_fini_array_test.cpp +++ b/libc/test/integration/startup/linux/init_fini_array_test.cpp @@ -31,7 +31,10 @@ class A { int GLOBAL_INDEX = 512; int INITVAL_INITIALIZER = 0x600D; +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wglobal-constructors" A global(GLOBAL_INDEX, INITVAL_INITIALIZER); +#pragma GCC diagnostic pop int initval = 0; int preinitval = 0; From ad8f2e73de986ea19ae3fcef8732ac22e99a3a90 Mon Sep 17 00:00:00 2001 From: Vinay Deshmukh <32487576+vinay-deshmukh@users.noreply.github.com> Date: Sun, 30 Mar 2025 11:19:30 -0400 Subject: [PATCH 23/28] thread_local --- libc/test/integration/src/pthread/pthread_exit_test.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libc/test/integration/src/pthread/pthread_exit_test.cpp b/libc/test/integration/src/pthread/pthread_exit_test.cpp index 48e6c81713a40..2667a02184b12 100644 --- a/libc/test/integration/src/pthread/pthread_exit_test.cpp +++ b/libc/test/integration/src/pthread/pthread_exit_test.cpp @@ -29,7 +29,10 @@ class A { } }; +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wglobal-constructors" thread_local A thread_local_a(123); +#pragma GCC diagnostic pop void *func(void *) { // Touch the thread local variable so that it gets initialized and a callback From 53bacd03bef43a5b49be6d8d45ed0fdb8957867b Mon Sep 17 00:00:00 2001 From: Vinay Deshmukh <32487576+vinay-deshmukh@users.noreply.github.com> Date: Sun, 30 Mar 2025 11:27:24 -0400 Subject: [PATCH 24/28] thread_local --- libc/test/integration/src/threads/thrd_exit_test.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libc/test/integration/src/threads/thrd_exit_test.cpp b/libc/test/integration/src/threads/thrd_exit_test.cpp index 0939a7621f443..a789fdd217418 100644 --- a/libc/test/integration/src/threads/thrd_exit_test.cpp +++ b/libc/test/integration/src/threads/thrd_exit_test.cpp @@ -29,7 +29,10 @@ class A { } }; +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wglobal-constructors" thread_local A thread_local_a(123); +#pragma GCC diagnostic pop int func(void *) { thread_local_a.set(321); From 8ed51cc0db341127025cc471b2e4c3e3d006e853 Mon Sep 17 00:00:00 2001 From: Vinay Deshmukh <32487576+vinay-deshmukh@users.noreply.github.com> Date: Mon, 14 Apr 2025 20:20:17 -0400 Subject: [PATCH 25/28] Undo code fixes --- libc/test/UnitTest/LibcTest.h | 24 ------------------- .../src/pthread/pthread_exit_test.cpp | 3 --- .../src/threads/thrd_exit_test.cpp | 3 --- .../startup/gpu/init_fini_array_test.cpp | 3 --- .../startup/linux/init_fini_array_test.cpp | 3 --- 5 files changed, 36 deletions(-) diff --git a/libc/test/UnitTest/LibcTest.h b/libc/test/UnitTest/LibcTest.h index 54221de4da454..fbeafd0bacb75 100644 --- a/libc/test/UnitTest/LibcTest.h +++ b/libc/test/UnitTest/LibcTest.h @@ -334,18 +334,6 @@ CString libc_make_test_file_path_func(const char *file_name); return "[ParamType = " #TYPE "]"; \ } -#define LIBC_TEST_GLOBAL_CTOR_DO_PRAGMA(x) _Pragma(#x) - -#define LIBC_TEST_GLOBAL_CTOR_DO_PRAGMA_BEGIN \ - LIBC_TEST_GLOBAL_CTOR_DO_PRAGMA(GCC diagnostic push) - -#define LIBC_TEST_GLOBAL_CTOR_DO_PRAGMA_BODY \ - LIBC_TEST_GLOBAL_CTOR_DO_PRAGMA(GCC diagnostic ignored \ - "-Wglobal-constructors") - -#define LIBC_TEST_GLOBAL_CTOR_DO_PRAGMA_END \ - LIBC_TEST_GLOBAL_CTOR_DO_PRAGMA(GCC diagnostic pop) - #define TYPED_TEST(SuiteName, TestName, TypeList) \ static_assert( \ LIBC_NAMESPACE::testing::internal::valid_prefix(#SuiteName), \ @@ -363,11 +351,8 @@ CString libc_make_test_file_path_func(const char *file_name); void Run() override; \ const char *getName() const override { return name; } \ }; \ - LIBC_TEST_GLOBAL_CTOR_DO_PRAGMA_BEGIN \ - LIBC_TEST_GLOBAL_CTOR_DO_PRAGMA_BODY \ TypeList::Tests::type \ SuiteName##_##TestName##_Instance; \ - LIBC_TEST_GLOBAL_CTOR_DO_PRAGMA_END \ template void SuiteName##_##TestName::Run() #define TYPED_TEST_F(SuiteClass, TestName, TypeList) \ @@ -386,11 +371,8 @@ CString libc_make_test_file_path_func(const char *file_name); void Run() override; \ const char *getName() const override { return name; } \ }; \ - LIBC_TEST_GLOBAL_CTOR_DO_PRAGMA_BEGIN \ - LIBC_TEST_GLOBAL_CTOR_DO_PRAGMA_BODY \ TypeList::Tests::type \ SuiteClass##_##TestName##_Instance; \ - LIBC_TEST_GLOBAL_CTOR_DO_PRAGMA_END \ template void SuiteClass##_##TestName::Run() #define TEST(SuiteName, TestName) \ @@ -402,10 +384,7 @@ CString libc_make_test_file_path_func(const char *file_name); void Run() override; \ const char *getName() const override { return #SuiteName "." #TestName; } \ }; \ - LIBC_TEST_GLOBAL_CTOR_DO_PRAGMA_BEGIN \ - LIBC_TEST_GLOBAL_CTOR_DO_PRAGMA_BODY \ SuiteName##_##TestName SuiteName##_##TestName##_Instance; \ - LIBC_TEST_GLOBAL_CTOR_DO_PRAGMA_END \ void SuiteName##_##TestName::Run() #define TEST_F(SuiteClass, TestName) \ @@ -418,10 +397,7 @@ CString libc_make_test_file_path_func(const char *file_name); void Run() override; \ const char *getName() const override { return #SuiteClass "." #TestName; } \ }; \ - LIBC_TEST_GLOBAL_CTOR_DO_PRAGMA_BEGIN \ - LIBC_TEST_GLOBAL_CTOR_DO_PRAGMA_BODY \ SuiteClass##_##TestName SuiteClass##_##TestName##_Instance; \ - LIBC_TEST_GLOBAL_CTOR_DO_PRAGMA_END \ void SuiteClass##_##TestName::Run() // Helper to trick the compiler into ignoring lack of braces on the else diff --git a/libc/test/integration/src/pthread/pthread_exit_test.cpp b/libc/test/integration/src/pthread/pthread_exit_test.cpp index 2667a02184b12..48e6c81713a40 100644 --- a/libc/test/integration/src/pthread/pthread_exit_test.cpp +++ b/libc/test/integration/src/pthread/pthread_exit_test.cpp @@ -29,10 +29,7 @@ class A { } }; -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wglobal-constructors" thread_local A thread_local_a(123); -#pragma GCC diagnostic pop void *func(void *) { // Touch the thread local variable so that it gets initialized and a callback diff --git a/libc/test/integration/src/threads/thrd_exit_test.cpp b/libc/test/integration/src/threads/thrd_exit_test.cpp index a789fdd217418..0939a7621f443 100644 --- a/libc/test/integration/src/threads/thrd_exit_test.cpp +++ b/libc/test/integration/src/threads/thrd_exit_test.cpp @@ -29,10 +29,7 @@ class A { } }; -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wglobal-constructors" thread_local A thread_local_a(123); -#pragma GCC diagnostic pop int func(void *) { thread_local_a.set(321); diff --git a/libc/test/integration/startup/gpu/init_fini_array_test.cpp b/libc/test/integration/startup/gpu/init_fini_array_test.cpp index 52005ba627062..ceedd5fc81358 100644 --- a/libc/test/integration/startup/gpu/init_fini_array_test.cpp +++ b/libc/test/integration/startup/gpu/init_fini_array_test.cpp @@ -32,10 +32,7 @@ int GLOBAL_INDEX = 512; int INITVAL_INITIALIZER = 0x600D; int BEFORE_INITIALIZER = 0xFEED; -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wglobal-constructors" A global(GLOBAL_INDEX, INITVAL_INITIALIZER); -#pragma GCC diagnostic pop int initval = 0; int before = 0; diff --git a/libc/test/integration/startup/linux/init_fini_array_test.cpp b/libc/test/integration/startup/linux/init_fini_array_test.cpp index d2ee48c3428ff..ed14e03a60c05 100644 --- a/libc/test/integration/startup/linux/init_fini_array_test.cpp +++ b/libc/test/integration/startup/linux/init_fini_array_test.cpp @@ -31,10 +31,7 @@ class A { int GLOBAL_INDEX = 512; int INITVAL_INITIALIZER = 0x600D; -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wglobal-constructors" A global(GLOBAL_INDEX, INITVAL_INITIALIZER); -#pragma GCC diagnostic pop int initval = 0; int preinitval = 0; From bb7b9a5eb0d6fea1073fd4f89e164abbd44fc5cf Mon Sep 17 00:00:00 2001 From: Vinay Deshmukh <32487576+vinay-deshmukh@users.noreply.github.com> Date: Mon, 14 Apr 2025 20:20:37 -0400 Subject: [PATCH 26/28] Werror no longer needed --- libc/CMakeLists.txt | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt index b86eefc05e782..47708c2267818 100644 --- a/libc/CMakeLists.txt +++ b/libc/CMakeLists.txt @@ -34,8 +34,6 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug") add_definitions("-D_DEBUG") endif() -add_compile_options("-Werror=global-constructors") - # Default to C++17 set(CMAKE_CXX_STANDARD 17) @@ -130,25 +128,20 @@ else() endif() endif() -# Defines LIBC_TARGET_ARCHITECTURE and associated macros. -set(LIBC_TARGET_TRIPLE "" CACHE STRING "The target triple for the libc build.") -include(LLVMLibCArchitectures) - -# Some targets can only support the full build. -set(default_to_full_build OFF) -if(LIBC_TARGET_OS_IS_GPU) - set(default_to_full_build ON) -endif() - -option(LLVM_LIBC_FULL_BUILD "Build and test LLVM libc as if it is the full libc" ${default_to_full_build}) +option(LLVM_LIBC_FULL_BUILD "Build and test LLVM libc as if it is the full libc" OFF) option(LLVM_LIBC_IMPLEMENTATION_DEFINED_TEST_BEHAVIOR "Build LLVM libc tests assuming our implementation-defined behavior" ON) option(LLVM_LIBC_ENABLE_LINTING "Enables linting of libc source files" OFF) +set(LIBC_TARGET_TRIPLE "" CACHE STRING "The target triple for the libc build.") + option(LIBC_CONFIG_PATH "The path to user provided folder that configures the build for the target system." OFF) set(LIBC_ENABLE_UNITTESTS ON) set(LIBC_ENABLE_HERMETIC_TESTS ${LLVM_LIBC_FULL_BUILD}) +# Defines LIBC_TARGET_ARCHITECTURE and associated macros. +include(LLVMLibCArchitectures) + set(LIBC_CONFIG_JSON_FILE_LIST "") if(NOT LIBC_CONFIG_PATH) From cc03d0e3752de8a0cb874c2a7a1e2b5824cb4fd2 Mon Sep 17 00:00:00 2001 From: Vinay Deshmukh <32487576+vinay-deshmukh@users.noreply.github.com> Date: Mon, 14 Apr 2025 20:21:31 -0400 Subject: [PATCH 27/28] Remove global constructors error in libc tests --- libc/cmake/modules/LLVMLibCTestRules.cmake | 1 - 1 file changed, 1 deletion(-) diff --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake index fef670885229c..711b94a8c4e5d 100644 --- a/libc/cmake/modules/LLVMLibCTestRules.cmake +++ b/libc/cmake/modules/LLVMLibCTestRules.cmake @@ -57,7 +57,6 @@ function(_get_common_test_compile_options output_var c_test flags) list(APPEND compile_options "-Wnewline-eof") list(APPEND compile_options "-Wnonportable-system-include-path") list(APPEND compile_options "-Wthread-safety") - list(APPEND compile_options "-Wglobal-constructors") endif() endif() set(${output_var} ${compile_options} PARENT_SCOPE) From db914c2b06ad26482c2b9002b4ce3e4a739729c7 Mon Sep 17 00:00:00 2001 From: Vinay Deshmukh <32487576+vinay-deshmukh@users.noreply.github.com> Date: Mon, 14 Apr 2025 20:24:41 -0400 Subject: [PATCH 28/28] Fix main's changes --- libc/CMakeLists.txt | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt index ce4e908f2b177..b264dcb4974c7 100644 --- a/libc/CMakeLists.txt +++ b/libc/CMakeLists.txt @@ -34,6 +34,7 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug") add_definitions("-D_DEBUG") endif() + # Default to C++17 set(CMAKE_CXX_STANDARD 17) @@ -121,20 +122,25 @@ else() endif() endif() -option(LLVM_LIBC_FULL_BUILD "Build and test LLVM libc as if it is the full libc" OFF) +# Defines LIBC_TARGET_ARCHITECTURE and associated macros. +set(LIBC_TARGET_TRIPLE "" CACHE STRING "The target triple for the libc build.") +include(LLVMLibCArchitectures) + +# Some targets can only support the full build. +set(default_to_full_build OFF) +if(LIBC_TARGET_OS_IS_GPU) + set(default_to_full_build ON) +endif() + +option(LLVM_LIBC_FULL_BUILD "Build and test LLVM libc as if it is the full libc" ${default_to_full_build}) option(LLVM_LIBC_IMPLEMENTATION_DEFINED_TEST_BEHAVIOR "Build LLVM libc tests assuming our implementation-defined behavior" ON) option(LLVM_LIBC_ENABLE_LINTING "Enables linting of libc source files" OFF) -set(LIBC_TARGET_TRIPLE "" CACHE STRING "The target triple for the libc build.") - option(LIBC_CONFIG_PATH "The path to user provided folder that configures the build for the target system." OFF) set(LIBC_ENABLE_UNITTESTS ON) set(LIBC_ENABLE_HERMETIC_TESTS ${LLVM_LIBC_FULL_BUILD}) -# Defines LIBC_TARGET_ARCHITECTURE and associated macros. -include(LLVMLibCArchitectures) - set(LIBC_CONFIG_JSON_FILE_LIST "") if(NOT LIBC_CONFIG_PATH)