Skip to content

Commit afb0501

Browse files
committed
[clang] Register all LLVM targets in AllClangUnitTest main
Addresses feedback in llvm#134196 (comment) Makes the tests less sensitive to target registration from unrelated test fixtures by registering everything up front.
1 parent 0058272 commit afb0501

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

clang/unittests/AllClangUnitTests.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//===- clang/unittests/AllClangUnitTests.cpp ------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "gtest/gtest.h"
10+
#include "llvm/Support/CommandLine.h"
11+
#include "llvm/Support/TargetSelect.h"
12+
13+
// This custom main entry point for the AllClangUnitTests binary registers all
14+
// tests on startup, so the tests don't become sensitive to target registration
15+
// within the test suite.
16+
int main(int argc, char **argv) {
17+
::testing::InitGoogleTest(&argc, argv);
18+
llvm::cl::ParseCommandLineOptions(argc, argv);
19+
20+
llvm::InitializeAllTargets();
21+
llvm::InitializeAllTargetMCs();
22+
23+
return RUN_ALL_TESTS();
24+
}

clang/unittests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ get_property(LINK_LIBS GLOBAL PROPERTY CLANG_UNITTEST_LINK_LIBS)
117117
get_property(LLVM_COMPONENTS GLOBAL PROPERTY CLANG_UNITTEST_LLVM_COMPONENTS)
118118
add_distinct_clang_unittest(AllClangUnitTests
119119
${SRCS}
120+
AllClangUnitTests.cpp
120121
CLANG_LIBS
121122
${CLANG_LIBS}
122123
LINK_LIBS

0 commit comments

Comments
 (0)