[flang-commits] [flang] [flang][OpenMP] Support run-time user conditions in DECLARE VARIANT (PR #216781)

via flang-commits flang-commits at lists.llvm.org
Mon Aug 17 10:26:33 PDT 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 cpp,h -- flang/include/flang/Lower/OpenMP.h flang/lib/Lower/ConvertCall.cpp flang/lib/Lower/OpenMP/Utils.cpp flang/lib/Lower/OpenMP/Utils.h flang/lib/Semantics/check-omp-structure.h flang/lib/Semantics/check-omp-variant.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/include/flang/Lower/OpenMP.h b/flang/include/flang/Lower/OpenMP.h
index f2794400d..7261950e2 100644
--- a/flang/include/flang/Lower/OpenMP.h
+++ b/flang/include/flang/Lower/OpenMP.h
@@ -115,13 +115,13 @@ const Fortran::semantics::Symbol *
 resolveDeclareVariantCallee(const Fortran::semantics::Symbol &base,
                             AbstractConverter &converter);
 
-/// Lower a direct call to \p base (which carries OpenMP DECLARE VARIANT entries)
-/// as a run-time if/else cascade when a variant is guarded by a run-time user
-/// condition. \p emitCall is invoked to emit one call with the already-lowered
-/// arguments at the current insertion point: with the chosen variant symbol for
-/// a guarded branch, or with nullptr for the base fallback. Returns true if a
-/// cascade was emitted; false if no run-time condition applies and the caller
-/// should emit the normal single call. Subroutines only.
+/// Lower a direct call to \p base (which carries OpenMP DECLARE VARIANT
+/// entries) as a run-time if/else cascade when a variant is guarded by a
+/// run-time user condition. \p emitCall is invoked to emit one call with the
+/// already-lowered arguments at the current insertion point: with the chosen
+/// variant symbol for a guarded branch, or with nullptr for the base fallback.
+/// Returns true if a cascade was emitted; false if no run-time condition
+/// applies and the caller should emit the normal single call. Subroutines only.
 bool genDeclareVariantCall(
     AbstractConverter &converter, mlir::Location loc,
     const Fortran::semantics::Symbol &base,
diff --git a/flang/lib/Lower/OpenMP/Utils.cpp b/flang/lib/Lower/OpenMP/Utils.cpp
index 47557253a..0b9519633 100644
--- a/flang/lib/Lower/OpenMP/Utils.cpp
+++ b/flang/lib/Lower/OpenMP/Utils.cpp
@@ -1392,9 +1392,8 @@ void collectEnclosingConstructTraits(
   std::reverse(constructTraits.begin(), constructTraits.end());
 }
 
-DeclareVariantResolution
-resolveDeclareVariant(const semantics::Symbol &base,
-                      AbstractConverter &converter) {
+DeclareVariantResolution resolveDeclareVariant(const semantics::Symbol &base,
+                                               AbstractConverter &converter) {
   DeclareVariantResolution result;
   const semantics::Symbol &ultimate{base.GetUltimate()};
 
@@ -1429,8 +1428,8 @@ resolveDeclareVariant(const semantics::Symbol &base,
     // parser/semantics otherwise accept; reject them before building the match
     // info (MakeVariantMatchInfo asserts none are present). This mirrors how
     // METADIRECTIVE lowering rejects the same features.
-    switch (semantics::omp::FindUnsupportedSelectorFeature(
-        *entry.matchSelector, semaCtx)) {
+    switch (semantics::omp::FindUnsupportedSelectorFeature(*entry.matchSelector,
+                                                           semaCtx)) {
     case semantics::omp::UnsupportedSelectorFeature::TargetDevice:
       TODO(converter.getCurrentLocation(),
            "target_device selector in DECLARE VARIANT");
@@ -1510,8 +1509,8 @@ resolveDeclareVariantCallee(const semantics::Symbol &base,
                             AbstractConverter &converter) {
   DeclareVariantResolution resolution{resolveDeclareVariant(base, converter)};
   // Static fast path: return the single best variant when no run-time condition
-  // is involved. When a candidate carries a run-time condition, fall back to the
-  // base here; the call site lowers the choice as an if/else cascade.
+  // is involved. When a candidate carries a run-time condition, fall back to
+  // the base here; the call site lowers the choice as an if/else cascade.
   if (resolution.candidates.empty() || resolution.hasDynamicCondition)
     return nullptr;
   return resolution.candidates.front().variant;

``````````

</details>


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


More information about the flang-commits mailing list