-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang] Register all LLVM targets in AllClangUnitTest main #144428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
afb0501
f5accc3
1f57ce2
5d9b647
893096a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
kadircet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
llvm::InitializeAllTargetMCs(); | ||
llvm::InitializeAllAsmPrinters(); | ||
llvm::InitializeAllAsmParsers(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think we're still linking against There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I spot checked two other unit tests that have custom mains, and they don't do anything special: I think archive semantics are pretty portable between platforms, so I think this just works. The sources used to build the unit test executable override the main provided by the gtest library. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i don't feel great about relying on linking order and linker not loading llvm_gtest_main solely because it wasn't referenced, but I guess that's a theoretical concern that won't matter much in practice (since but can we at least leave a comment here, mentioning that we're also linking against There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, on second thought, there's a lot more going on in UnitTestMain than I thought. I rewrote this to use a dynamic initializer to register the targets instead. Those will reliably run before test fixtures. The only risk here is that we encounter intialization-order-fiasco issues, but I spot-checked x86, and it seems to be resilient to that... I will test with ASan locally to build confidence, but PTAL at the new approach. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks a lot, this is really neat! and yeah i think initialization-order-fiasco should be less of a concern here. |
||
CLANG_LIBS | ||
${CLANG_LIBS} | ||
LINK_LIBS | ||
|
Uh oh!
There was an error while loading. Please reload this page.