[llvm-branch-commits] [flang] [flang][OpenMP] Switch clause verification to descriptor-based (PR #229527)

Sairudra More via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Oct 19 02:31:03 PDT 2026


================
@@ -326,6 +352,251 @@ static ResultTy VerifyUltimate(
   return result;
 }
 
+bool OmpStructureChecker::VerifyClauseVersion(
+    parser::OmpDirectiveName dirName, const AppliedClauseInfo &info) {
+  llvm::omp::Version version{context_.langOptions().getOpenMPVersion()};
+  llvm::omp::Version maxVer{std::numeric_limits<int>::max()};
+  bool isCancel{dirName.v == llvm::omp::Directive::OMPD_cancel ||
+      dirName.v == llvm::omp::Directive::OMPD_cancellation_point};
+
+  auto result = VerifyVersions(info, dirName.v, version);
+
+  for (auto &[c, svr] : result) {
+    std::string cname{GetUpperName(c, version)};
+    std::string dname{GetUpperName(dirName.v, version)};
+    llvm::omp::Version since(svr.second.Min);
+    llvm::omp::Version until(svr.second.Max);
+
+    // Cancellation construct type clauses are directive names. They are
+    // only allowed on CANCEL and CANCELLATION_POINT directives. They may
+    // appear as byproducts of parsing an invalid directive name,
+    // e.g. SECTIONS PARALLEL, where SECTIONS will be the directive name,
+    // and PARALLEL will be a cancellation-construct-type clause.
+    // This may cause confusing error messages to be emitted, so deal with
+    // these cases separately.
+    if (!isCancel && c == llvm::omp::Clause::OMPC_cancellation_construct_type) {
+      context_.Say(svr.first, "%s cannot follow %s"_err_en_US,
+          parser::ToUpperCaseLetters(svr.first.ToString()), dname);
+      continue;
+    }
+
+    if (since == maxVer && until == 0u) {
+      context_.Say(svr.first,
+          "%s clause is not allowed on %s directive"_err_en_US, cname, dname);
+    } else if (since != maxVer && version < since) {
+      context_.Warn(common::UsageWarning::OpenMPFuture, svr.first,
+          "%s clause is not allowed on %s directive in %s, %s"_warn_en_US,
----------------
Saieiei wrote:

INITIALIZER on DECLARE REDUCTION now warns that it needs 5.0, so plain `flang -fopenmp -Werror` rejects it, although OpenMP 4.5 section 2.16 allows it. Adding a 4.5 entry for INITIALIZER and listing it in the 4.5 DECLARE REDUCTION entry removes the warning for me.

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


More information about the llvm-branch-commits mailing list