[flang-commits] [flang] dc057e3 - [flang, unittest] Initialize targets before creating a CompilerInstance. NFC (#233117)
via flang-commits
flang-commits at lists.llvm.org
Sat Oct 17 10:34:14 PDT 2026
Author: Fangrui Song
Date: 2026-10-17T10:34:09-07:00
New Revision: dc057e33a1be7af3e8c08b237a796c526e6a471e
URL: https://github.com/llvm/llvm-project/commit/dc057e33a1be7af3e8c08b237a796c526e6a471e
DIFF: https://github.com/llvm/llvm-project/commit/dc057e33a1be7af3e8c08b237a796c526e6a471e.diff
LOG: [flang,unittest] Initialize targets before creating a CompilerInstance. NFC (#233117)
Initialize targets first to register library options before creating a
CompilerInstance.
Added:
Modified:
flang/unittests/Frontend/CompilerInstanceTest.cpp
flang/unittests/Frontend/FrontendActionTest.cpp
flang/unittests/Semantics/OpenMPUtils.cpp
Removed:
################################################################################
diff --git a/flang/unittests/Frontend/CompilerInstanceTest.cpp b/flang/unittests/Frontend/CompilerInstanceTest.cpp
index 60ef29c53c28d6..5f95d2f3edeb7f 100644
--- a/flang/unittests/Frontend/CompilerInstanceTest.cpp
+++ b/flang/unittests/Frontend/CompilerInstanceTest.cpp
@@ -101,14 +101,14 @@ TEST(CompilerInstance, AllowDiagnosticLogWithUnownedDiagnosticConsumer) {
TEST(CompilerInstance,
OpenAccDefaultNoneScalarsStrictDisableOptionUsesDriverTable) {
+ llvm::InitializeAllTargets();
+ llvm::InitializeAllTargetMCs();
+
CompilerInstance compInst;
compInst.createDiagnostics();
compInst.getInvocation().getTargetOpts().triple =
llvm::Triple::normalize(llvm::sys::getDefaultTargetTriple());
- llvm::InitializeAllTargets();
- llvm::InitializeAllTargetMCs();
-
ASSERT_TRUE(compInst.setUpTargetMachine());
auto &context = compInst.createNewSemanticsContext();
diff --git a/flang/unittests/Frontend/FrontendActionTest.cpp b/flang/unittests/Frontend/FrontendActionTest.cpp
index ec9682e27b3121..10211c5ea2fae0 100644
--- a/flang/unittests/Frontend/FrontendActionTest.cpp
+++ b/flang/unittests/Frontend/FrontendActionTest.cpp
@@ -39,6 +39,13 @@ class FrontendActionTest : public ::testing::Test {
CompilerInstance compInst;
+ // Targets register their library options, which compInst holds from its
+ // construction.
+ static void SetUpTestSuite() {
+ llvm::InitializeAllTargets();
+ llvm::InitializeAllTargetMCs();
+ }
+
void SetUp() override {
// Generate a unique test file name.
const testing::TestInfo *const testInfo =
@@ -59,12 +66,10 @@ class FrontendActionTest : public ::testing::Test {
inputFilePath = cwd.c_str();
inputFilePath += "/" + inputFileName;
- // Set-up default target triple and initialize LLVM Targets so that the
- // target data layout can be passed to the frontend.
+ // Set-up default target triple so that the target data layout can be
+ // passed to the frontend.
compInst.getInvocation().getTargetOpts().triple =
llvm::Triple::normalize(llvm::sys::getDefaultTargetTriple());
- llvm::InitializeAllTargets();
- llvm::InitializeAllTargetMCs();
compInst.createDiagnostics();
compInst.getFrontendOpts().inputs.push_back(
diff --git a/flang/unittests/Semantics/OpenMPUtils.cpp b/flang/unittests/Semantics/OpenMPUtils.cpp
index 3bdbb7f3f6f030..45197f48a9859a 100644
--- a/flang/unittests/Semantics/OpenMPUtils.cpp
+++ b/flang/unittests/Semantics/OpenMPUtils.cpp
@@ -47,6 +47,13 @@ class OpenMPUtilsTest : public ::testing::Test {
CompilerInstance compInst;
+ // Targets register their library options, which compInst holds from its
+ // construction.
+ static void SetUpTestSuite() {
+ llvm::InitializeAllTargets();
+ llvm::InitializeAllTargetMCs();
+ }
+
void SetUp() override {
// Generate a unique test file name.
const testing::TestInfo *const testInfo =
@@ -67,13 +74,11 @@ class OpenMPUtilsTest : public ::testing::Test {
inputFilePath = cwd.c_str();
inputFilePath += "/" + inputFileName;
- // Set-up default target triple and initialize LLVM Targets so that the
- // target data layout can be passed to the frontend.
+ // Set-up default target triple so that the target data layout can be
+ // passed to the frontend.
compInst.getInvocation().getTargetOpts().triple =
llvm::Triple::normalize(llvm::sys::getDefaultTargetTriple());
compInst.getInvocation().getLangOpts().OpenMPVersion = 60;
- llvm::InitializeAllTargets();
- llvm::InitializeAllTargetMCs();
compInst.createDiagnostics();
compInst.getFrontendOpts().inputs.push_back(
More information about the flang-commits
mailing list