[Mlir-commits] [flang] [mlir] [flang][OpenMP] Diagnose threadprivate accesses in target device code (PR #237949)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon Nov 2 04:51:20 PST 2026


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions h,cpp -- flang/lib/Optimizer/OpenMP/DeviceThreadprivateCheck.cpp flang/lib/Semantics/check-omp-device.cpp flang/lib/Semantics/check-omp-device.h flang/lib/Lower/OpenMP/OpenMP.cpp flang/lib/Optimizer/Passes/Pipelines.cpp flang/lib/Semantics/semantics.cpp mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp b/flang/lib/Lower/OpenMP/OpenMP.cpp
index 47e831521..aae41e9d7 100644
--- a/flang/lib/Lower/OpenMP/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP/OpenMP.cpp
@@ -5383,16 +5383,15 @@ static mlir::omp::DistributeOp genCompositeDistributeParallelDo(
       converter, loc, wsloopClauseOps, wsloopArgs);
   wsloopOp.setComposite(/*val=*/true);
 
-  genLoopNestOp(converter, symTable, semaCtx, eval, loc, queue, doItem,
-                loopNestClauseOps, iv,
-                {{distributeOp, distributeArgs}, {wsloopOp, wsloopArgs}},
-                llvm::omp::Directive::OMPD_distribute_parallel_do, dsp,
-                [&](mlir::Operation *loopNestOp) {
-                  // Threadprivate variables cannot be bound in the composite
-                  // omp.parallel, so do it at the start of the loop body.
-                  threadPrivatizeVars(converter, eval,
-                                      &loopNestOp->getRegion(0).front());
-                });
+  genLoopNestOp(
+      converter, symTable, semaCtx, eval, loc, queue, doItem, loopNestClauseOps,
+      iv, {{distributeOp, distributeArgs}, {wsloopOp, wsloopArgs}},
+      llvm::omp::Directive::OMPD_distribute_parallel_do, dsp,
+      [&](mlir::Operation *loopNestOp) {
+        // Threadprivate variables cannot be bound in the composite
+        // omp.parallel, so do it at the start of the loop body.
+        threadPrivatizeVars(converter, eval, &loopNestOp->getRegion(0).front());
+      });
 
   fir::FirOpBuilder &builder = converter.getFirOpBuilder();
   fir::FirOpBuilder::InsertionGuard guard(builder);
diff --git a/flang/lib/Optimizer/OpenMP/DeviceThreadprivateCheck.cpp b/flang/lib/Optimizer/OpenMP/DeviceThreadprivateCheck.cpp
index a559bd1ab..e02f83c0e 100644
--- a/flang/lib/Optimizer/OpenMP/DeviceThreadprivateCheck.cpp
+++ b/flang/lib/Optimizer/OpenMP/DeviceThreadprivateCheck.cpp
@@ -47,9 +47,9 @@ static bool isDeviceCode(Operation *op) {
 /// Operations that only compute an address or a descriptor from their operands
 /// without accessing the memory behind them.
 static bool isAddressComputation(Operation *op) {
-  return isa<fir::FortranVariableOpInterface, fir::CoordinateOp,
-             fir::ConvertOp, fir::EmboxOp, fir::ReboxOp, fir::BoxAddrOp,
-             fir::ArrayCoorOp, hlfir::DesignateOp>(op);
+  return isa<fir::FortranVariableOpInterface, fir::CoordinateOp, fir::ConvertOp,
+             fir::EmboxOp, fir::ReboxOp, fir::BoxAddrOp, fir::ArrayCoorOp,
+             hlfir::DesignateOp>(op);
 }
 
 /// Follow the uses of \p value through address computations, which are added
@@ -110,9 +110,9 @@ static std::string describeThreadprivate(fir::GlobalOp global) {
   }
 
   auto [kind, deconstructed] = fir::NameUniquer::deconstruct(symName);
-  llvm::StringRef name =
-      kind == fir::NameUniquer::NameKind::VARIABLE ? deconstructed.name
-                                                   : symName;
+  llvm::StringRef name = kind == fir::NameUniquer::NameKind::VARIABLE
+                             ? deconstructed.name
+                             : symName;
   return ("THREADPRIVATE variable '" + name + "'").str();
 }
 
@@ -156,8 +156,9 @@ class DeviceThreadprivateCheckPass
       llvm::SmallVector<Operation *> pending(addressOps.begin(),
                                              addressOps.end());
       while (!pending.empty()) {
-        auto *unused = llvm::find_if(
-            pending, [](Operation *addressOp) { return addressOp->use_empty(); });
+        auto *unused = llvm::find_if(pending, [](Operation *addressOp) {
+          return addressOp->use_empty();
+        });
         assert(unused != pending.end() && "expected an unused operation");
         (*unused)->erase();
         pending.erase(unused);

``````````

</details>


https://github.com/llvm/llvm-project/pull/237949


More information about the Mlir-commits mailing list