[flang-commits] [flang] [llvm] [flang][OpenMP] Check that IF clause applies to at most one leaf (PR #205164)

via flang-commits flang-commits at lists.llvm.org
Tue Jun 23 13:00:31 PDT 2026


================
@@ -4334,39 +4345,90 @@ void OmpStructureChecker::Enter(const parser::OmpClause::If &x) {
     std::string modName{desc.name.str()};
 
     if (!isConstituent(dir, sub)) {
-      context_
-          .Say(modifierSource,
-              "%s is not a constituent of the %s directive"_err_en_US, subName,
-              dirName)
-          .Attach(
-              GetContext().directiveSource, "Cannot apply to directive"_en_US);
+      context_.Say(modifierSource,
+          "%s is not a constituent of the %s directive"_err_en_US, subName,
+          dirName);
     } else {
-      static llvm::omp::Directive valid45[]{
-          llvm::omp::OMPD_cancel, //
-          llvm::omp::OMPD_parallel, //
-          /* OMP 5.0+ also allows OMPD_simd */
-          llvm::omp::OMPD_target, //
-          llvm::omp::OMPD_target_data, //
-          llvm::omp::OMPD_target_enter_data, //
-          llvm::omp::OMPD_target_exit_data, //
-          llvm::omp::OMPD_target_update, //
-          llvm::omp::OMPD_task, //
-          llvm::omp::OMPD_taskloop, //
-          /* OMP 5.2+ also allows OMPD_teams */
+      static OmpDirectiveSet valid45{
+          llvm::omp::Directive::OMPD_cancel, //
+          llvm::omp::Directive::OMPD_parallel, //
+          llvm::omp::Directive::OMPD_target, //
+          llvm::omp::Directive::OMPD_target_data, //
+          llvm::omp::Directive::OMPD_target_enter_data, //
+          llvm::omp::Directive::OMPD_target_exit_data, //
+          llvm::omp::Directive::OMPD_target_update, //
+          llvm::omp::Directive::OMPD_task, //
+          llvm::omp::Directive::OMPD_taskloop, //
       };
-      if (version < 50 && sub == llvm::omp::OMPD_simd) {
+      static OmpDirectiveSet valid50{
+          valid45 | OmpDirectiveSet{llvm::omp::Directive::OMPD_simd}};
+      static OmpDirectiveSet valid52{
+          valid50 | OmpDirectiveSet{llvm::omp::Directive::OMPD_teams}};
+      static OmpDirectiveSet valid60{valid52 |
+          OmpDirectiveSet{llvm::omp::Directive::OMPD_taskgraph,
+              /*TODO llvm::omp::Directive::OMPD_task_iteration*/}};
+
+      static auto minVersion{[&](llvm::omp::Directive d) {
+        if (valid45.test(d)) {
+          return 45;
+        }
+        if (valid50.test(d)) {
+          return 50;
+        }
+        if (valid52.test(d)) {
+          return 52;
+        }
+        if (valid60.test(d)) {
+          return 60;
+        }
+        return 0;
+      }};
+      static auto suggest{[&](unsigned v) -> std::string {
+        if (v != 0) {
+          return ", " + TryVersion(v);
+        } else {
+          return "";
+        }
+      }};
+
+      if (version <= 45 && !valid45.test(sub)) {
+        context_.Say(modifierSource,
+            "%s is not allowed as '%s' in %s%s"_warn_en_US, subName, modName,
+            ThisVersion(version), suggest(minVersion(sub)));
+      } else if (version <= 51 && !valid50.test(sub)) {
----------------
kwyatt-ext wrote:

Intentional inclusion of 5.1 in the 5.0 messaging?

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


More information about the flang-commits mailing list