[flang-commits] [flang] [flang][OpenMP] Set the target in bbc's semantics context (PR #233976)
via flang-commits
flang-commits at lists.llvm.org
Tue Oct 20 12:58:13 PDT 2026
https://github.com/chichunchen created https://github.com/llvm/llvm-project/pull/233976
bbc created a target machine but never passed its triple and features to the semantics context. Without a target triple, semantics treats device and implementation context selectors as possibly matching, so it checked METADIRECTIVE replacements that can never be selected for the target. For example, bbc reported a COLLAPSE error for the SIMD replacement of when(device={arch(nvptx64)}: simd collapse(2)) on x86-64, while flang accepts it.
Set the semantics target triple and features from the target machine, as the flang driver does.
Fixes https://github.com/llvm/llvm-project/issues/233027.
Assisted-by: GitHub Copilot (Claude Opus 5.5)
>From d6a3b84c4aa3cf10aadd345204a422047af99612 Mon Sep 17 00:00:00 2001
From: "Chi Chun, Chen" <chichun.chen at hpe.com>
Date: Fri, 16 Oct 2026 21:55:44 -0500
Subject: [PATCH] [flang][OpenMP] Set the target in bbc's semantics context
bbc created a target machine but never passed its triple and features to
the semantics context. Without a target triple, semantics treats device
and implementation context selectors as possibly matching, so it
checked METADIRECTIVE replacements that can never be selected for the
target. For example, bbc reported a COLLAPSE error for the SIMD
replacement of when(device={arch(nvptx64)}: simd collapse(2)) on
x86-64, while flang accepts it.
Set the semantics target triple and features from the target machine, as
the flang driver does.
Fixes https://github.com/llvm/llvm-project/issues/233027.
Assisted-by: GitHub Copilot (Claude Opus 5.5)
---
.../test/Driver/bbc-openmp-target-context.f90 | 20 +++++++++++++++++++
flang/tools/bbc/bbc.cpp | 2 ++
2 files changed, 22 insertions(+)
create mode 100644 flang/test/Driver/bbc-openmp-target-context.f90
diff --git a/flang/test/Driver/bbc-openmp-target-context.f90 b/flang/test/Driver/bbc-openmp-target-context.f90
new file mode 100644
index 0000000000000..6929ffd362a1b
--- /dev/null
+++ b/flang/test/Driver/bbc-openmp-target-context.f90
@@ -0,0 +1,20 @@
+! REQUIRES: x86-registered-target
+
+! RUN: bbc -target x86_64-unknown-linux-gnu -fopenmp -fopenmp-version=52 \
+! RUN: -emit-hlfir %s -o - 2>&1 | FileCheck %s
+
+! Semantics must use the bbc target: arch(nvptx64) does not match x86-64, so
+! the invalid SIMD replacement is never selected and must not be diagnosed.
+! CHECK-NOT: error
+! CHECK-LABEL: func.func @_QParch_mismatch(
+! CHECK-NOT: omp.simd
+! CHECK: fir.do_loop
+
+subroutine arch_mismatch(n, a)
+ integer :: n, a(n), i
+ !$omp metadirective when(device={arch(nvptx64)}: simd collapse(2)) &
+ !$omp& otherwise(nothing)
+ do i = 1, n
+ a(i) = i
+ end do
+end subroutine
diff --git a/flang/tools/bbc/bbc.cpp b/flang/tools/bbc/bbc.cpp
index 8fc902369f637..07e0e52fb228b 100644
--- a/flang/tools/bbc/bbc.cpp
+++ b/flang/tools/bbc/bbc.cpp
@@ -799,6 +799,8 @@ int main(int argc, char **argv) {
llvm::errs() << "failed to create target machine: " << error << "\n";
return mlir::failed(mlir::failure());
}
+ semanticsContext.set_targetTriple(targetMachine->getTargetTriple().str())
+ .set_targetFeatures(targetMachine->getTargetFeatureString().str());
std::string compilerVersion = Fortran::common::getFlangToolFullVersion("bbc");
std::string compilerOptions = "";
Fortran::tools::setUpTargetCharacteristics(
More information about the flang-commits
mailing list