Skip to content

[clang] Merge gtest binaries into AllClangUnitTests #134196

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 12 commits into from
Apr 29, 2025

Conversation

rnk
Copy link
Collaborator

@rnk rnk commented Apr 3, 2025

This reduces the size of the clang/unittests build directory by 64% and my overall build dir size by 5%. Static linking is the real driving factor here, but even if the default build configuration used shared libraries, I don't see why we should be building so many unit test binaries.

To make the project more approachable for new contributors, I'm attempting to make the build a bit less resource-intensive. Build directory size is a common complaint, and this is low-hanging fruit.

This reduces the size of the clang/unittests build directory by 64% and
my overall build dir size by 5%. Static linking is the real driving
factor here, but even if the default build configuration used shared
libraries, I don't see why we should be building so many unit test
binaries.

To make the project more approachable for new contributors, I'm
attempting to make the build a bit less resource-intensive. Build
directory size is a common complaint, and this is low-hanging fruit.
@rnk rnk requested a review from Copilot April 3, 2025 04:13
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR renames the gtest binary for unit tests to reduce build directory size and overall resource usage.

  • Renames a test case from ModuleCacheTest to DriverModuleCacheTest
  • Aligns unit test naming with the goal of merging binaries
Files not reviewed (3)
  • clang/unittests/CMakeLists.txt: Language not supported
  • clang/unittests/Interpreter/CMakeLists.txt: Language not supported
  • clang/unittests/Interpreter/ExceptionTests/CMakeLists.txt: Language not supported
Comments suppressed due to low confidence (1)

clang/unittests/Driver/ModuleCacheTest.cpp:20

  • [nitpick] The test case name 'DriverModuleCacheTest' is inconsistent with the file name 'ModuleCacheTest.cpp'. Consider renaming either the file or the test case for clarity.
TEST(DriverModuleCacheTest, GetTargetAndMode) {

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' labels Apr 3, 2025
@llvmbot
Copy link
Member

llvmbot commented Apr 3, 2025

@llvm/pr-subscribers-clang-codegen

@llvm/pr-subscribers-clang-driver

Author: Reid Kleckner (rnk)

Changes

This reduces the size of the clang/unittests build directory by 64% and my overall build dir size by 5%. Static linking is the real driving factor here, but even if the default build configuration used shared libraries, I don't see why we should be building so many unit test binaries.

To make the project more approachable for new contributors, I'm attempting to make the build a bit less resource-intensive. Build directory size is a common complaint, and this is low-hanging fruit.


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

4 Files Affected:

  • (modified) clang/unittests/CMakeLists.txt (+51-2)
  • (modified) clang/unittests/Driver/ModuleCacheTest.cpp (+1-1)
  • (modified) clang/unittests/Interpreter/CMakeLists.txt (+1-1)
  • (modified) clang/unittests/Interpreter/ExceptionTests/CMakeLists.txt (+1-1)
diff --git a/clang/unittests/CMakeLists.txt b/clang/unittests/CMakeLists.txt
index f3823ba309420..8d4476761e03e 100644
--- a/clang/unittests/CMakeLists.txt
+++ b/clang/unittests/CMakeLists.txt
@@ -15,11 +15,11 @@ if(CLANG_BUILT_STANDALONE)
   endif()
 endif()
 
-# add_clang_unittest(test_name file1.cpp file2.cpp)
+# add_distinct_clang_unittest(test_name file1.cpp file2.cpp)
 #
 # Will compile the list of files together and link against the clang
 # Produces a binary named 'basename(test_name)'.
-function(add_clang_unittest test_name)
+function(add_distinct_clang_unittest test_name)
   cmake_parse_arguments(ARG
     ""
     ""
@@ -47,6 +47,33 @@ function(add_clang_unittest test_name)
   target_link_libraries(${test_name} PRIVATE ${ARG_LINK_LIBS})
 endfunction()
 
+define_property(GLOBAL PROPERTY CLANG_UNITTEST_SRCS)
+define_property(GLOBAL PROPERTY CLANG_UNITTEST_LLVM_COMPONENTS)
+define_property(GLOBAL PROPERTY CLANG_UNITTEST_CLANG_LIBS)
+define_property(GLOBAL PROPERTY CLANG_UNITTEST_LINK_LIBS)
+
+# add_clang_unittest(test_name file1.cpp file2.cpp)
+#
+# Adds unittests to the combined AllClangUnitTests binary. The unittest binary
+# is defined after adding all unittest subdirectories.
+function(add_clang_unittest test_name)
+  cmake_parse_arguments(ARG
+    ""
+    ""
+    "CLANG_LIBS;LINK_LIBS;LLVM_COMPONENTS"
+    ${ARGN})
+
+  file(RELATIVE_PATH src_prefix "${CMAKE_CURRENT_FUNCTION_LIST_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}")
+  set(srcs_prefixed)
+  foreach(src ${ARG_UNPARSED_ARGUMENTS})
+    set(srcs_prefixed ${srcs_prefixed} "${src_prefix}/${src}")
+  endforeach()
+  set_property(GLOBAL APPEND PROPERTY CLANG_UNITTEST_SRCS ${srcs_prefixed})
+  set_property(GLOBAL APPEND PROPERTY CLANG_UNITTEST_CLANG_LIBS ${ARG_CLANG_LIBS})
+  set_property(GLOBAL APPEND PROPERTY CLANG_UNITTEST_LINK_LIBS ${ARG_LINK_LIBS})
+  set_property(GLOBAL APPEND PROPERTY CLANG_UNITTEST_LLVM_COMPONENTS ${ARG_LLVM_COMPONENTS})
+endfunction()
+
 add_subdirectory(Basic)
 add_subdirectory(Lex)
 add_subdirectory(Parse)
@@ -77,3 +104,25 @@ add_subdirectory(Index)
 add_subdirectory(InstallAPI)
 add_subdirectory(Serialization)
 add_subdirectory(Support)
+
+
+# If we're doing a single merged clang unit test binary, add that target after
+# all the previous subdirectories have been processed.
+get_property(SRCS GLOBAL PROPERTY CLANG_UNITTEST_SRCS)
+get_property(CLANG_LIBS GLOBAL PROPERTY CLANG_UNITTEST_CLANG_LIBS)
+get_property(LINK_LIBS GLOBAL PROPERTY CLANG_UNITTEST_LINK_LIBS)
+get_property(LLVM_COMPONENTS GLOBAL PROPERTY CLANG_UNITTEST_LLVM_COMPONENTS)
+add_distinct_clang_unittest(AllClangUnitTests
+  ${SRCS}
+  CLANG_LIBS
+  ${CLANG_LIBS}
+  LINK_LIBS
+  ${LINK_LIBS}
+  LLVM_COMPONENTS
+  ${LLVM_COMPONENTS}
+)
+
+# The Tooling library has some internal headers. Make those work. If we like
+# the merged clang unit test binary, we can udpate the include paths and make
+# this the default.
+include_directories(Tooling)
diff --git a/clang/unittests/Driver/ModuleCacheTest.cpp b/clang/unittests/Driver/ModuleCacheTest.cpp
index 48744415647e6..7aa5047c59bd3 100644
--- a/clang/unittests/Driver/ModuleCacheTest.cpp
+++ b/clang/unittests/Driver/ModuleCacheTest.cpp
@@ -17,7 +17,7 @@ using namespace clang::driver;
 
 namespace {
 
-TEST(ModuleCacheTest, GetTargetAndMode) {
+TEST(DriverModuleCacheTest, GetTargetAndMode) {
   SmallString<128> Buf;
   Driver::getDefaultModuleCachePath(Buf);
   StringRef Path = Buf;
diff --git a/clang/unittests/Interpreter/CMakeLists.txt b/clang/unittests/Interpreter/CMakeLists.txt
index 9df1a4b03da47..1dda9024075a1 100644
--- a/clang/unittests/Interpreter/CMakeLists.txt
+++ b/clang/unittests/Interpreter/CMakeLists.txt
@@ -1,4 +1,4 @@
-add_clang_unittest(ClangReplInterpreterTests
+add_distinct_clang_unittest(ClangReplInterpreterTests
   IncrementalCompilerBuilderTest.cpp
   IncrementalProcessingTest.cpp
   InterpreterTest.cpp
diff --git a/clang/unittests/Interpreter/ExceptionTests/CMakeLists.txt b/clang/unittests/Interpreter/ExceptionTests/CMakeLists.txt
index eb366a860661c..dfd94d8e6442c 100644
--- a/clang/unittests/Interpreter/ExceptionTests/CMakeLists.txt
+++ b/clang/unittests/Interpreter/ExceptionTests/CMakeLists.txt
@@ -3,7 +3,7 @@
 set(LLVM_REQUIRES_EH ON)
 set(LLVM_REQUIRES_RTTI ON)
 
-add_clang_unittest(ClangReplInterpreterExceptionTests
+add_distinct_clang_unittest(ClangReplInterpreterExceptionTests
   InterpreterExceptionTest.cpp
   EXPORT_SYMBOLS
 

@llvmbot
Copy link
Member

llvmbot commented Apr 3, 2025

@llvm/pr-subscribers-clang

Author: Reid Kleckner (rnk)

Changes

This reduces the size of the clang/unittests build directory by 64% and my overall build dir size by 5%. Static linking is the real driving factor here, but even if the default build configuration used shared libraries, I don't see why we should be building so many unit test binaries.

To make the project more approachable for new contributors, I'm attempting to make the build a bit less resource-intensive. Build directory size is a common complaint, and this is low-hanging fruit.


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

4 Files Affected:

  • (modified) clang/unittests/CMakeLists.txt (+51-2)
  • (modified) clang/unittests/Driver/ModuleCacheTest.cpp (+1-1)
  • (modified) clang/unittests/Interpreter/CMakeLists.txt (+1-1)
  • (modified) clang/unittests/Interpreter/ExceptionTests/CMakeLists.txt (+1-1)
diff --git a/clang/unittests/CMakeLists.txt b/clang/unittests/CMakeLists.txt
index f3823ba309420..8d4476761e03e 100644
--- a/clang/unittests/CMakeLists.txt
+++ b/clang/unittests/CMakeLists.txt
@@ -15,11 +15,11 @@ if(CLANG_BUILT_STANDALONE)
   endif()
 endif()
 
-# add_clang_unittest(test_name file1.cpp file2.cpp)
+# add_distinct_clang_unittest(test_name file1.cpp file2.cpp)
 #
 # Will compile the list of files together and link against the clang
 # Produces a binary named 'basename(test_name)'.
-function(add_clang_unittest test_name)
+function(add_distinct_clang_unittest test_name)
   cmake_parse_arguments(ARG
     ""
     ""
@@ -47,6 +47,33 @@ function(add_clang_unittest test_name)
   target_link_libraries(${test_name} PRIVATE ${ARG_LINK_LIBS})
 endfunction()
 
+define_property(GLOBAL PROPERTY CLANG_UNITTEST_SRCS)
+define_property(GLOBAL PROPERTY CLANG_UNITTEST_LLVM_COMPONENTS)
+define_property(GLOBAL PROPERTY CLANG_UNITTEST_CLANG_LIBS)
+define_property(GLOBAL PROPERTY CLANG_UNITTEST_LINK_LIBS)
+
+# add_clang_unittest(test_name file1.cpp file2.cpp)
+#
+# Adds unittests to the combined AllClangUnitTests binary. The unittest binary
+# is defined after adding all unittest subdirectories.
+function(add_clang_unittest test_name)
+  cmake_parse_arguments(ARG
+    ""
+    ""
+    "CLANG_LIBS;LINK_LIBS;LLVM_COMPONENTS"
+    ${ARGN})
+
+  file(RELATIVE_PATH src_prefix "${CMAKE_CURRENT_FUNCTION_LIST_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}")
+  set(srcs_prefixed)
+  foreach(src ${ARG_UNPARSED_ARGUMENTS})
+    set(srcs_prefixed ${srcs_prefixed} "${src_prefix}/${src}")
+  endforeach()
+  set_property(GLOBAL APPEND PROPERTY CLANG_UNITTEST_SRCS ${srcs_prefixed})
+  set_property(GLOBAL APPEND PROPERTY CLANG_UNITTEST_CLANG_LIBS ${ARG_CLANG_LIBS})
+  set_property(GLOBAL APPEND PROPERTY CLANG_UNITTEST_LINK_LIBS ${ARG_LINK_LIBS})
+  set_property(GLOBAL APPEND PROPERTY CLANG_UNITTEST_LLVM_COMPONENTS ${ARG_LLVM_COMPONENTS})
+endfunction()
+
 add_subdirectory(Basic)
 add_subdirectory(Lex)
 add_subdirectory(Parse)
@@ -77,3 +104,25 @@ add_subdirectory(Index)
 add_subdirectory(InstallAPI)
 add_subdirectory(Serialization)
 add_subdirectory(Support)
+
+
+# If we're doing a single merged clang unit test binary, add that target after
+# all the previous subdirectories have been processed.
+get_property(SRCS GLOBAL PROPERTY CLANG_UNITTEST_SRCS)
+get_property(CLANG_LIBS GLOBAL PROPERTY CLANG_UNITTEST_CLANG_LIBS)
+get_property(LINK_LIBS GLOBAL PROPERTY CLANG_UNITTEST_LINK_LIBS)
+get_property(LLVM_COMPONENTS GLOBAL PROPERTY CLANG_UNITTEST_LLVM_COMPONENTS)
+add_distinct_clang_unittest(AllClangUnitTests
+  ${SRCS}
+  CLANG_LIBS
+  ${CLANG_LIBS}
+  LINK_LIBS
+  ${LINK_LIBS}
+  LLVM_COMPONENTS
+  ${LLVM_COMPONENTS}
+)
+
+# The Tooling library has some internal headers. Make those work. If we like
+# the merged clang unit test binary, we can udpate the include paths and make
+# this the default.
+include_directories(Tooling)
diff --git a/clang/unittests/Driver/ModuleCacheTest.cpp b/clang/unittests/Driver/ModuleCacheTest.cpp
index 48744415647e6..7aa5047c59bd3 100644
--- a/clang/unittests/Driver/ModuleCacheTest.cpp
+++ b/clang/unittests/Driver/ModuleCacheTest.cpp
@@ -17,7 +17,7 @@ using namespace clang::driver;
 
 namespace {
 
-TEST(ModuleCacheTest, GetTargetAndMode) {
+TEST(DriverModuleCacheTest, GetTargetAndMode) {
   SmallString<128> Buf;
   Driver::getDefaultModuleCachePath(Buf);
   StringRef Path = Buf;
diff --git a/clang/unittests/Interpreter/CMakeLists.txt b/clang/unittests/Interpreter/CMakeLists.txt
index 9df1a4b03da47..1dda9024075a1 100644
--- a/clang/unittests/Interpreter/CMakeLists.txt
+++ b/clang/unittests/Interpreter/CMakeLists.txt
@@ -1,4 +1,4 @@
-add_clang_unittest(ClangReplInterpreterTests
+add_distinct_clang_unittest(ClangReplInterpreterTests
   IncrementalCompilerBuilderTest.cpp
   IncrementalProcessingTest.cpp
   InterpreterTest.cpp
diff --git a/clang/unittests/Interpreter/ExceptionTests/CMakeLists.txt b/clang/unittests/Interpreter/ExceptionTests/CMakeLists.txt
index eb366a860661c..dfd94d8e6442c 100644
--- a/clang/unittests/Interpreter/ExceptionTests/CMakeLists.txt
+++ b/clang/unittests/Interpreter/ExceptionTests/CMakeLists.txt
@@ -3,7 +3,7 @@
 set(LLVM_REQUIRES_EH ON)
 set(LLVM_REQUIRES_RTTI ON)
 
-add_clang_unittest(ClangReplInterpreterExceptionTests
+add_distinct_clang_unittest(ClangReplInterpreterExceptionTests
   InterpreterExceptionTest.cpp
   EXPORT_SYMBOLS
 

@rnk rnk marked this pull request as draft April 3, 2025 04:53
@rnk rnk marked this pull request as ready for review April 10, 2025 14:42
@llvmbot llvmbot added the clang:codegen IR generation bugs: mangling, exceptions, etc. label Apr 10, 2025
Copy link

github-actions bot commented Apr 10, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@rnk
Copy link
Collaborator Author

rnk commented Apr 11, 2025

This is ready now, so please take a look. Apologies for all the push notifications. It took a lot of retries to get this to pass the premerge tests due to cmake environmental differences, which I guess shows the value of shared premerge testing.

@rnk
Copy link
Collaborator Author

rnk commented Apr 25, 2025

Ping, WDYT?

@@ -304,7 +304,7 @@ getCodeModel(const CodeGenOptions &CodeGenOpts) {
.Case("kernel", llvm::CodeModel::Kernel)
.Case("medium", llvm::CodeModel::Medium)
.Case("large", llvm::CodeModel::Large)
.Case("default", ~1u)
.Cases("default", "", ~1u)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you explain why this change is needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Basically, after my change, some Frontend tests now exercise this codepath without setting up a code model, and they hit the assert below. What changed is that now the target they are generating IR for is registered, so this codepath executes, when it didn't before my change. Interpreting "empty" as the default code model here seemed like the most sensible thing to do, rather than adding logic to those tests to explicitly set a code model.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was going to ask about this: Why do FrontendTests now have to call llvm::InitializeAllTargetMCs();? They used to not depend on llvm/lib/Target at all. Why is this needed now that that code gets linked into a bigger binary?

…, but not the TargetMachine

In this case, createTargetMachine may return null, which can happen in
some unit tests.
@rnk
Copy link
Collaborator Author

rnk commented Apr 29, 2025

If anyone is looking for stories about the value of premerge testing, I was all set to push this tonight, but I saw the linux premerge test failure. I debugged it, and it turns out to be a subtle interaction where if you run Clang codegen with registered targets but no registered TargetMachine classes, then one of our unittests will crash setting the large code model threshold 🙄 . Anyway, I pushed a fix and can land it tomorrow. Thanks for reviewing!

@rnk rnk merged commit db2315a into llvm:main Apr 29, 2025
11 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Apr 29, 2025

LLVM Buildbot has detected a new failure on builder llvm-clang-aarch64-darwin running on doug-worker-4 while building clang at step 6 "test-build-unified-tree-check-all".

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

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'Clang-Unit :: ./AllClangUnitTests/17/51' FAILED ********************
Script(shard):
--
GTEST_OUTPUT=json:/Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/unittests/./AllClangUnitTests-Clang-Unit-17005-17-51.json GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=51 GTEST_SHARD_INDEX=17 /Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/unittests/./AllClangUnitTests
--

Script:
--
/Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/unittests/./AllClangUnitTests --gtest_filter=LibclangParseTest.UninstallAbortingLLVMFatalErrorHandler
--
/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/unittests/libclang/CrashTests/LibclangCrashTest.cpp:36: Failure
Death test: clang_parseTranslationUnit(Index, Main.c_str(), nullptr, 0, nullptr, 0, TUFlags)
    Result: died but not with expected error.
  Expected: contains regular expression "ERROR"
Actual msg:
[  DEATH   ]  #0 0x00000001019cb4e4 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/unittests/AllClangUnitTests+0x10183f4e4)
[  DEATH   ]  #1 0x00000001019c97f4 llvm::sys::RunSignalHandlers() (/Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/unittests/AllClangUnitTests+0x10183d7f4)
[  DEATH   ]  #2 0x00000001019cbba0 SignalHandler(int, __siginfo*, void*) (/Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/unittests/AllClangUnitTests+0x10183fba0)
[  DEATH   ]  #3 0x00000001853ef584 (/usr/lib/system/libsystem_platform.dylib+0x18047b584)
[  DEATH   ]  #4 0x000000018510bee0 (/usr/lib/system/libsystem_trace.dylib+0x180197ee0)
[  DEATH   ]  #5 0x000000018510bc34 (/usr/lib/system/libsystem_trace.dylib+0x180197c34)
[  DEATH   ]  #6 0x000000011739e34c llvm::SignpostEmitter::SignpostEmitter() (/Users/buildbot/buildbot-root/aarch64-darwin/build/lib/libclang.dylib+0x19ba34c)
[  DEATH   ]  #7 0x00000001173b6a94 llvm::TimerGlobals::TimerGlobals() (/Users/buildbot/buildbot-root/aarch64-darwin/build/lib/libclang.dylib+0x19d2a94)
[  DEATH   ]  #8 0x00000001173917dc llvm::ManagedStaticBase::RegisterManagedStatic(void* (*)(), void (*)(void*)) const (/Users/buildbot/buildbot-root/aarch64-darwin/build/lib/libclang.dylib+0x19ad7dc)
[  DEATH   ]  #9 0x00000001173b4028 llvm::TimerGroup::constructForStatistics() (/Users/buildbot/buildbot-root/aarch64-darwin/build/lib/libclang.dylib+0x19d0028)
[  DEATH   ] #10 0x00000001173aa650 llvm::object_creator<(anonymous namespace)::StatisticInfo>::call() (/Users/buildbot/buildbot-root/aarch64-darwin/build/lib/libclang.dylib+0x19c6650)
[  DEATH   ] #11 0x00000001173917dc llvm::ManagedStaticBase::RegisterManagedStatic(void* (*)(), void (*)(void*)) const (/Users/buildbot/buildbot-root/aarch64-darwin/build/lib/libclang.dylib+0x19ad7dc)
[  DEATH   ] #12 0x00000001173a8954 llvm::TrackingStatistic::RegisterStatistic() (/Users/buildbot/buildbot-root/aarch64-darwin/build/lib/libclang.dylib+0x19c4954)
[  DEATH   ] #13 0x00000001160dd030 clang::SourceManager::createExpansionLocImpl(clang::SrcMgr::ExpansionInfo const&, unsigned int, int, unsigned int) (/Users/buildbot/buildbot-root/aarch64-darwin/build/lib/libclang.dylib+0x6f9030)
[  DEATH   ] #14 0x00000001160daac4 clang::SourceManager::clearIDTables() (/Users/buildbot/buildbot-root/aarch64-darwin/build/lib/libclang.dylib+0x6f6ac4)
[  DEATH   ] #15 0x00000001160da8fc clang::SourceManager::SourceManager(clang::DiagnosticsEngine&, clang::FileManager&, bool) (/Users/buildbot/buildbot-root/aarch64-darwin/build/lib/libclang.dylib+0x6f68fc)
[  DEATH   ] #16 0x00000001162f7cb8 clang::ASTUnit::Parse(std::__1::shared_ptr<clang::PCHContainerOperations>, std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) (/Users/buildbot/buildbot-root/aarch64-darwin/build/lib/libclang.dylib+0x913cb8)
[  DEATH   ] #17 0x00000001162faea4 clang::ASTUnit::LoadFromCompilerInvocation(std::__1::shared_ptr<clang::PCHContainerOperations>, unsigned int, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) (/Users/buildbot/buildbot-root/aarch64-darwin/build/lib/libclang.dylib+0x916ea4)
[  DEATH   ] #18 0x00000001162fb93c clang::ASTUnit::LoadFromCommandLine(char const**, char const**, std::__1::shared_ptr<clang::PCHContainerOperations>, llvm::IntrusiveRefCntPtr<clang::DiagnosticsEngine>, llvm::StringRef, bool, llvm::StringRef, bool, clang::CaptureDiagsKind, llvm::ArrayRef<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, llvm::MemoryBuffer*>>, bool, unsigned int, clang::TranslationUnitKind, bool, bool, bool, clang::SkipFunctionBodiesScope, bool, bool, bool, bool, std::__1::optional<llvm::StringRef>, std::__1::unique_ptr<clang::ASTUnit, std::__1::default_delete<clang::ASTUnit>>*, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) (/Users/buildbot/buildbot-root/aarch64-darwin/build/lib/libclang.dylib+0x91793c)
[  DEATH   ] #19 0x0000000115a0f180 void llvm::function_ref<void ()>::callback_fn<clang_parseTranslationUnit2FullArgv::$_1>(long) (/Users/buildbot/buildbot-root/aarch64-darwin/build/lib/libclang.dylib+0x2b180)
[  DEATH   ] #20 0x000000011736d5e4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/Users/buildbot/buildbot-root/aarch64-darwin/build/lib/libclang.dylib+0x19895e4)
[  DEATH   ] #21 0x000000011736d718 RunSafelyOnThread_Dispatch(void*) (/Users/buildbot/buildbot-root/aarch64-darwin/build/lib/libclang.dylib+0x1989718)
[  DEATH   ] #22 0x000000011736d82c void* llvm::thread::ThreadProxy<std::__1::tuple<void (*)(void*), (anonymous namespace)::RunSafelyOnThreadInfo*>>(void*) (/Users/buildbot/buildbot-root/aarch64-darwin/build/lib/libclang.dylib+0x198982c)
[  DEATH   ] #23 0x00000001853bef94 (/usr/lib/system/libsystem_pthread.dylib+0x18044af94)
[  DEATH   ] #24 0x00000001853b9d34 (/usr/lib/system/libsystem_pthread.dylib+0x180445d34)
[  DEATH   ] 


/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/unittests/libclang/CrashTests/LibclangCrashTest.cpp:36
Death test: clang_parseTranslationUnit(Index, Main.c_str(), nullptr, 0, nullptr, 0, TUFlags)
    Result: died but not with expected error.
  Expected: contains regular expression "ERROR"
Actual msg:
[  DEATH   ]  #0 0x00000001019cb4e4 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/unittests/AllClangUnitTests+0x10183f4e4)
[  DEATH   ]  #1 0x00000001019c97f4 llvm::sys::RunSignalHandlers() (/Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/unittests/AllClangUnitTests+0x10183d7f4)
...

@llvm-ci
Copy link
Collaborator

llvm-ci commented Apr 29, 2025

LLVM Buildbot has detected a new failure on builder sanitizer-x86_64-linux-fast running on sanitizer-buildbot4 while building clang at step 2 "annotate".

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

Here is the relevant piece of the build log for the reference
Step 2 (annotate) failure: 'python ../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py' (failure)
...
llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using lld-link: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/lld-link
llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using ld64.lld: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/ld64.lld
llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using wasm-ld: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/wasm-ld
llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using ld.lld: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/ld.lld
llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using lld-link: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/lld-link
llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using ld64.lld: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/ld64.lld
llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using wasm-ld: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/wasm-ld
llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/main.py:72: note: The test suite configuration requested an individual test timeout of 0 seconds but a timeout of 900 seconds was requested on the command line. Forcing timeout to be 900 seconds.
-- Testing: 89062 tests, 88 workers --
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.
FAIL: Clang :: Interpreter/global-dtor.cpp (36862 of 89062)
******************** TEST 'Clang :: Interpreter/global-dtor.cpp' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
cat /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/Interpreter/global-dtor.cpp | /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/clang-repl | /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/FileCheck /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/Interpreter/global-dtor.cpp # RUN: at line 6
+ /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/FileCheck /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/Interpreter/global-dtor.cpp
+ /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/clang-repl
+ cat /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/Interpreter/global-dtor.cpp
JIT session error: In graph incr_module_10-jitted-objectbuffer, section .text.startup: relocation target "__dso_handle" at address 0x7eea49b00000 is out of range of Delta32 fixup at 0x7aea4920d02f (<anonymous block> @ 0x7aea4920d010 + 0x1f)
error: Failed to materialize symbols: { (main, { DW.ref.__gxx_personality_v0, __clang_call_terminate, __orc_init_func.incr_module_10, $.incr_module_10.__inits.0, d, _ZN1DC2Ev, _ZN1DD2Ev }) }
error: Failed to materialize symbols: { (main, { __orc_init_func.incr_module_10 }) }
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/Interpreter/global-dtor.cpp:11:11: error: CHECK: expected string not found in input
// CHECK: D[f=1.000000, m=0x0]
          ^
<stdin>:1:1: note: scanning from here
clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> 
^
<stdin>:1:11: note: possible intended match here
clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> 
          ^

Input file: <stdin>
Check file: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/Interpreter/global-dtor.cpp

-dump-input=help explains the following input dump.

Input was:
<<<<<<
            1: clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl>  
check:11'0     X~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: no match found
check:11'1               ?                                                                                                                                                   possible intended match
>>>>>>

--

********************
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90..
Step 10 (stage2/asan_ubsan check) failure: stage2/asan_ubsan check (failure)
...
llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using lld-link: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/lld-link
llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using ld64.lld: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/ld64.lld
llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using wasm-ld: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/wasm-ld
llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using ld.lld: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/ld.lld
llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using lld-link: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/lld-link
llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using ld64.lld: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/ld64.lld
llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using wasm-ld: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/wasm-ld
llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/main.py:72: note: The test suite configuration requested an individual test timeout of 0 seconds but a timeout of 900 seconds was requested on the command line. Forcing timeout to be 900 seconds.
-- Testing: 89062 tests, 88 workers --
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.
FAIL: Clang :: Interpreter/global-dtor.cpp (36862 of 89062)
******************** TEST 'Clang :: Interpreter/global-dtor.cpp' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
cat /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/Interpreter/global-dtor.cpp | /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/clang-repl | /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/FileCheck /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/Interpreter/global-dtor.cpp # RUN: at line 6
+ /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/FileCheck /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/Interpreter/global-dtor.cpp
+ /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/clang-repl
+ cat /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/Interpreter/global-dtor.cpp
JIT session error: In graph incr_module_10-jitted-objectbuffer, section .text.startup: relocation target "__dso_handle" at address 0x7eea49b00000 is out of range of Delta32 fixup at 0x7aea4920d02f (<anonymous block> @ 0x7aea4920d010 + 0x1f)
error: Failed to materialize symbols: { (main, { DW.ref.__gxx_personality_v0, __clang_call_terminate, __orc_init_func.incr_module_10, $.incr_module_10.__inits.0, d, _ZN1DC2Ev, _ZN1DD2Ev }) }
error: Failed to materialize symbols: { (main, { __orc_init_func.incr_module_10 }) }
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/Interpreter/global-dtor.cpp:11:11: error: CHECK: expected string not found in input
// CHECK: D[f=1.000000, m=0x0]
          ^
<stdin>:1:1: note: scanning from here
clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> 
^
<stdin>:1:11: note: possible intended match here
clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> 
          ^

Input file: <stdin>
Check file: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/Interpreter/global-dtor.cpp

-dump-input=help explains the following input dump.

Input was:
<<<<<<
            1: clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl>  
check:11'0     X~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: no match found
check:11'1               ?                                                                                                                                                   possible intended match
>>>>>>

--

********************
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90..

@dyung
Copy link
Collaborator

dyung commented Apr 29, 2025

LLVM Buildbot has detected a new failure on builder llvm-clang-aarch64-darwin running on doug-worker-4 while building clang at step 6 "test-build-unified-tree-check-all".

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

Here is the relevant piece of the build log for the reference

@rnk not sure if you were notified or not, but the test you changed seems to be failing on MacOS. It seems to be consistently failing on my AArch64 MacOS bot, but only once randomly on my x86-64 MacOS bot (https://lab.llvm.org/buildbot/#/builders/23/builds/9847). Can you take a look?

@rnk
Copy link
Collaborator Author

rnk commented Apr 29, 2025

I attempted to repro on my macbook, but it doesn't reproduce. This test doesn't seem high value, and I thin kthe right next step is to disable it to green the bots before debugging it.

@rnk
Copy link
Collaborator Author

rnk commented Apr 29, 2025

I disabled the failing test in 743c32e.

@nico
Copy link
Contributor

nico commented Apr 30, 2025

BasicTests and FormatTests had fairly few deps (they didn't need Sema etc) and compiled much fewer files than they presumably now do. Does it make sense to keep those as distinct binaries?

nico added a commit that referenced this pull request Apr 30, 2025
The CMake build merged most clang unittests into a single binary.
The gn build doesn't (yet?) do this, but as part of that change,
FrontendTests somehow picked up a dependency on AllTargetsDescs,
see #134196 (comment)
@rnk
Copy link
Collaborator Author

rnk commented Apr 30, 2025

BasicTests and FormatTests had fairly few deps (they didn't need Sema etc) and compiled much fewer files than they presumably now do. Does it make sense to keep those as distinct binaries?

FormatTests has many clang dependencies, but after rebuilding, it looks like it's still quite small, so I sent a PR with my file size data:
#138021

You can see that the Interpreter tests are a much bigger target for optimization.

@owenca
Copy link
Contributor

owenca commented May 1, 2025

This patch caused an assertion failure for b8bb1cc on several build bots and my mac (M2, 15.4.1):

[ RUN      ] CodeGenTest.TestNonAlterTest
Assertion failed: (MRI && "Unable to create reg info"), function initAsmInfo, file CodeGenTargetMachineImpl.cpp, line 48.

It also made us lose the FormatTests build target:

$ ninja FormatTests
ninja: error: unknown target 'FormatTests'

Update:
Back to normal after afd738c.

@rnk
Copy link
Collaborator Author

rnk commented May 1, 2025

Are the CodeGenTest.TestNonAlterTest failures still an issue? I don't see that failure on any bots. I haven't gotten any reports.

@owenca
Copy link
Contributor

owenca commented May 2, 2025

@rnk see #137577 (comment) for some of the bots that got the assertion failure.

Update: Back to normal after afd738c.

I meant the assertion failure also disappeared after that commit.

@AaronBallman
Copy link
Collaborator

AaronBallman commented May 2, 2025

@rnk see #137577 (comment) for some of the bots that got the assertion failure.

Update: Back to normal after afd738c.

I meant the assertion failure also disappeared after that commit.

FWIW, I'm seeing the test failure on Windows x64 with a debug build of Clang's unit tests as of a fresh fetch of main this morning.

The failing test is:

TEST(CodeGenTest, CodeGenFromIRMemBuffer) {
  auto Invocation = std::make_shared<CompilerInvocation>();
  std::unique_ptr<MemoryBuffer> MemBuffer =
      MemoryBuffer::getMemBuffer("", "test.ll");
  Invocation->getFrontendOpts().Inputs.push_back(
      FrontendInputFile(*MemBuffer, Language::LLVM_IR));
  Invocation->getFrontendOpts().ProgramAction = frontend::EmitLLVMOnly;
  Invocation->getTargetOpts().Triple = "i386-unknown-linux-gnu";
  CompilerInstance Compiler(std::move(Invocation));
  Compiler.createDiagnostics(*llvm::vfs::getRealFileSystem());
  EXPECT_TRUE(Compiler.hasDiagnostics());

  EmitLLVMOnlyAction Action;
  bool Success = Compiler.ExecuteAction(Action);
  EXPECT_TRUE(Success);
}

and the failure is this assertion:

void CodeGenTargetMachineImpl::initAsmInfo() {
  MRI.reset(TheTarget.createMCRegInfo(getTargetTriple().str()));
  assert(MRI && "Unable to create reg info");
  ...

@rnk
Copy link
Collaborator Author

rnk commented May 2, 2025

FWIW, I'm seeing the test failure on Windows x64 with a debug build of Clang's unit tests as of a fresh fetch of main this morning.

Sorry about that! I leaned on the Windows premerge tests to find Windows issues (they did, that was useful), but I'm pretty sure it uses release, not debug, builds.

I won't be able to repro any windows build failures until Monday, and it's likely I'll be buried in other stuff.

If it's a singular test case, I would disable the test (rename it to add the DISABLED_ prefix to the test name as in 743c32e) to unblock work. Reverting and relanding will create new stale gtest executables in everyone's build directories.

If you want to go ahead and debug it, the next steps I would try are adding all the various LLVMInitializeAll* API calls to the gtest test case. I think what's going on here is that the TargetInfo classes are registered, but the MCTargetDesc or register info classes are not registered. This happens because some other gtest case running earlier registers the targets, and now the CodeGenTest links in the LLVM Target backends, when previously they were not present in the old gtest binary.

@dyung
Copy link
Collaborator

dyung commented May 2, 2025

I've been seeing intermittent failures of AllClangUnitTests/TimeProfilerTest/ConstantEvaluationCxx20 and AllClangUnitTests/TimeProfilerTest/ConstantEvaluationC99 on my MacOS bot, but I haven't had a chance to try and figure out if it might be related to your change or not.

ConstantEvaluationCxx20:

First instance of either failing: https://lab.llvm.org/buildbot/#/builders/190/builds/19216

@aeubanks
Copy link
Contributor

aeubanks commented May 3, 2025

I've also seen ConstantEvaluationC99 intermittently fail on our mac bots recently

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:codegen IR generation bugs: mangling, exceptions, etc. clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants