[flang-commits] [flang] ca3bb96 - [flang][OpenMP] Set the target in bbc's semantics context (#233976)
via flang-commits
flang-commits at lists.llvm.org
Wed Oct 21 08:51:16 PDT 2026
Author: Chi-Chun, Chen
Date: 2026-10-21T10:40:54-05:00
New Revision: ca3bb96b7948c774ab3dc71fb116f97b65a97879
URL: https://github.com/llvm/llvm-project/commit/ca3bb96b7948c774ab3dc71fb116f97b65a97879
DIFF: https://github.com/llvm/llvm-project/commit/ca3bb96b7948c774ab3dc71fb116f97b65a97879.diff
LOG: [flang][OpenMP] Set the target in bbc's semantics context (#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)
Added:
flang/test/Driver/bbc-openmp-target-context.f90
Modified:
flang/tools/bbc/bbc.cpp
Removed:
################################################################################
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 6ab05058b05a1..c7904ba3560c2 100644
--- a/flang/tools/bbc/bbc.cpp
+++ b/flang/tools/bbc/bbc.cpp
@@ -797,6 +797,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