https://github.com/rnk updated https://github.com/llvm/llvm-project/pull/144428
>From afb050103754e6b4656c68da8ddfb6b1a4e03e5d Mon Sep 17 00:00:00 2001 From: Reid Kleckner <[email protected]> Date: Mon, 16 Jun 2025 20:08:12 +0000 Subject: [PATCH 1/3] [clang] Register all LLVM targets in AllClangUnitTest main Addresses feedback in https://github.com/llvm/llvm-project/pull/134196#issuecomment-2970715875 Makes the tests less sensitive to target registration from unrelated test fixtures by registering everything up front. --- clang/unittests/AllClangUnitTests.cpp | 24 ++++++++++++++++++++++++ clang/unittests/CMakeLists.txt | 1 + 2 files changed, 25 insertions(+) create mode 100644 clang/unittests/AllClangUnitTests.cpp diff --git a/clang/unittests/AllClangUnitTests.cpp b/clang/unittests/AllClangUnitTests.cpp new file mode 100644 index 0000000000000..1726cabc8107c --- /dev/null +++ b/clang/unittests/AllClangUnitTests.cpp @@ -0,0 +1,24 @@ +//===- clang/unittests/AllClangUnitTests.cpp ------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "gtest/gtest.h" +#include "llvm/Support/CommandLine.h" +#include "llvm/Support/TargetSelect.h" + +// This custom main entry point for the AllClangUnitTests binary registers all +// tests on startup, so the tests don't become sensitive to target registration +// within the test suite. +int main(int argc, char **argv) { + ::testing::InitGoogleTest(&argc, argv); + llvm::cl::ParseCommandLineOptions(argc, argv); + + llvm::InitializeAllTargets(); + llvm::InitializeAllTargetMCs(); + + return RUN_ALL_TESTS(); +} diff --git a/clang/unittests/CMakeLists.txt b/clang/unittests/CMakeLists.txt index aef28f914b640..54c781a35c20c 100644 --- a/clang/unittests/CMakeLists.txt +++ b/clang/unittests/CMakeLists.txt @@ -117,6 +117,7 @@ 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} + AllClangUnitTests.cpp CLANG_LIBS ${CLANG_LIBS} LINK_LIBS >From f5accc33950191c2e6eebe8327e247e2a4177d3e Mon Sep 17 00:00:00 2001 From: Reid Kleckner <[email protected]> Date: Mon, 16 Jun 2025 20:15:11 +0000 Subject: [PATCH 2/3] reorder headers to pacify format checker --- clang/unittests/AllClangUnitTests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/unittests/AllClangUnitTests.cpp b/clang/unittests/AllClangUnitTests.cpp index 1726cabc8107c..d1c8da12d5c84 100644 --- a/clang/unittests/AllClangUnitTests.cpp +++ b/clang/unittests/AllClangUnitTests.cpp @@ -6,9 +6,9 @@ // //===----------------------------------------------------------------------===// -#include "gtest/gtest.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/TargetSelect.h" +#include "gtest/gtest.h" // This custom main entry point for the AllClangUnitTests binary registers all // tests on startup, so the tests don't become sensitive to target registration >From 1f57ce24f87a22a2975beb928892f4aa6b983f81 Mon Sep 17 00:00:00 2001 From: Reid Kleckner <[email protected]> Date: Tue, 17 Jun 2025 23:37:25 +0000 Subject: [PATCH 3/3] Add additional target registration hooks to match cc1 --- clang/unittests/AllClangUnitTests.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/clang/unittests/AllClangUnitTests.cpp b/clang/unittests/AllClangUnitTests.cpp index d1c8da12d5c84..279e51b41d5bf 100644 --- a/clang/unittests/AllClangUnitTests.cpp +++ b/clang/unittests/AllClangUnitTests.cpp @@ -17,8 +17,14 @@ int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); llvm::cl::ParseCommandLineOptions(argc, argv); + // Initialize all levels of target components. Keep this in sync with + // cc1_main. + llvm::InitializeAllTargetInfos(); llvm::InitializeAllTargets(); llvm::InitializeAllTargetMCs(); + llvm::InitializeAllAsmPrinters(); + llvm::InitializeAllAsmParsers(); + return RUN_ALL_TESTS(); } _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
