Skip to content

Commit 930e03c

Browse files
rnkrlavaee
authored andcommitted
[clang] Register all LLVM targets in AllClangUnitTest main (llvm#144428)
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 17f4a0b commit 930e03c

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

clang/unittests/AllClangUnitTests.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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 "llvm/Support/TargetSelect.h"
10+
11+
namespace {
12+
struct RegisterAllLLVMTargets {
13+
RegisterAllLLVMTargets();
14+
} gv;
15+
} // namespace
16+
17+
// This dynamic initializer initializes all layers (TargetInfo, MC, CodeGen,
18+
// AsmPrinter, etc) of all LLVM targets. This matches what cc1_main does on
19+
// startup, and prevents tests from initializing some of the Target layers,
20+
// which can interfere with tests that assume that lower target layers are
21+
// registered if the TargetInfo is registered.
22+
RegisterAllLLVMTargets::RegisterAllLLVMTargets() {
23+
llvm::InitializeAllTargetInfos();
24+
llvm::InitializeAllTargets();
25+
llvm::InitializeAllTargetMCs();
26+
llvm::InitializeAllAsmPrinters();
27+
llvm::InitializeAllAsmParsers();
28+
}

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)