diff --git a/clang/unittests/AllClangUnitTests.cpp b/clang/unittests/AllClangUnitTests.cpp new file mode 100644 index 0000000000000..6f33230a617c1 --- /dev/null +++ b/clang/unittests/AllClangUnitTests.cpp @@ -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(); +} 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