[flang-commits] [flang] 8db7571 - [flang][OpenMP] Simplify getLocation in FlangOmpReportVisitor, NFC (#155871)

via flang-commits flang-commits at lists.llvm.org
Thu Aug 28 10:08:17 PDT 2025


Author: Krzysztof Parzyszek
Date: 2025-08-28T12:08:13-05:00
New Revision: 8db7571179140c26f537aa329571aab3ebc58170

URL: https://github.com/llvm/llvm-project/commit/8db7571179140c26f537aa329571aab3ebc58170
DIFF: https://github.com/llvm/llvm-project/commit/8db7571179140c26f537aa329571aab3ebc58170.diff

LOG: [flang][OpenMP] Simplify getLocation in FlangOmpReportVisitor, NFC (#155871)

Use a utility function to get the construct source.

Added: 
    

Modified: 
    flang/examples/FlangOmpReport/FlangOmpReportVisitor.cpp

Removed: 
    


################################################################################
diff  --git a/flang/examples/FlangOmpReport/FlangOmpReportVisitor.cpp b/flang/examples/FlangOmpReport/FlangOmpReportVisitor.cpp
index cc058bf28329b..ab2e8fd8df58f 100644
--- a/flang/examples/FlangOmpReport/FlangOmpReportVisitor.cpp
+++ b/flang/examples/FlangOmpReport/FlangOmpReportVisitor.cpp
@@ -65,32 +65,9 @@ SourcePosition OpenMPCounterVisitor::getLocation(
       c.u);
 }
 SourcePosition OpenMPCounterVisitor::getLocation(const OpenMPConstruct &c) {
-  return std::visit(
-      Fortran::common::visitors{
-          [&](const OpenMPStandaloneConstruct &c) -> SourcePosition {
-            return parsing->allCooked().GetSourcePositionRange(c.source)->first;
-          },
-          // OpenMPSectionsConstruct, OpenMPLoopConstruct,
-          // OpenMPBlockConstruct, OpenMPCriticalConstruct Get the source from
-          // the directive field.
-          [&](const auto &c) -> SourcePosition {
-            const CharBlock &source{std::get<0>(c.t).source};
-            return parsing->allCooked().GetSourcePositionRange(source)->first;
-          },
-          [&](const OpenMPAtomicConstruct &c) -> SourcePosition {
-            const CharBlock &source{c.source};
-            return parsing->allCooked().GetSourcePositionRange(source)->first;
-          },
-          [&](const OpenMPSectionConstruct &c) -> SourcePosition {
-            const CharBlock &source{c.source};
-            return parsing->allCooked().GetSourcePositionRange(source)->first;
-          },
-          [&](const OpenMPUtilityConstruct &c) -> SourcePosition {
-            const CharBlock &source{c.source};
-            return parsing->allCooked().GetSourcePositionRange(source)->first;
-          },
-      },
-      c.u);
+  return parsing->allCooked()
+      .GetSourcePositionRange(omp::GetOmpDirectiveName(c).source)
+      ->first;
 }
 
 std::string OpenMPCounterVisitor::getName(const OmpWrapperType &w) {


        


More information about the flang-commits mailing list