[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:
Reid Kleckner 2025-06-24 19:40:13 -06:00 committed by GitHub
parent 3140333872
commit dbb3e7d116
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 0 deletions

View 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();
}

View File

@ -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