[clang] Register all LLVM targets in AllClangUnitTest main (#144428)
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.
This commit is contained in:
parent
3140333872
commit
dbb3e7d116
28
clang/unittests/AllClangUnitTests.cpp
Normal file
28
clang/unittests/AllClangUnitTests.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
//===- 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 "llvm/Support/TargetSelect.h"
|
||||
|
||||
namespace {
|
||||
struct RegisterAllLLVMTargets {
|
||||
RegisterAllLLVMTargets();
|
||||
} gv;
|
||||
} // namespace
|
||||
|
||||
// This dynamic initializer initializes all layers (TargetInfo, MC, CodeGen,
|
||||
// AsmPrinter, etc) of all LLVM targets. This matches what cc1_main does on
|
||||
// startup, and prevents tests from initializing some of the Target layers,
|
||||
// which can interfere with tests that assume that lower target layers are
|
||||
// registered if the TargetInfo is registered.
|
||||
RegisterAllLLVMTargets::RegisterAllLLVMTargets() {
|
||||
llvm::InitializeAllTargetInfos();
|
||||
llvm::InitializeAllTargets();
|
||||
llvm::InitializeAllTargetMCs();
|
||||
llvm::InitializeAllAsmPrinters();
|
||||
llvm::InitializeAllAsmParsers();
|
||||
}
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user