[flang-commits] [flang] [flang][OpenMP] Use OmpDirectiveSpecification in DECLARE_VARIANT (PR #160371)
    Krzysztof Parzyszek via flang-commits 
    flang-commits at lists.llvm.org
       
    Thu Sep 25 07:04:51 PDT 2025
    
    
  
================
@@ -1370,9 +1365,50 @@ void OmpStructureChecker::Leave(const parser::OpenMPDeclareSimdConstruct &) {
 }
 
 void OmpStructureChecker::Enter(const parser::OmpDeclareVariantDirective &x) {
-  const auto &dir{std::get<parser::Verbatim>(x.t)};
-  PushContextAndClauseSets(
-      dir.source, llvm::omp::Directive::OMPD_declare_variant);
+  const parser::OmpDirectiveName &dirName{x.v.DirName()};
+  PushContextAndClauseSets(dirName.source, dirName.v);
+
+  const parser::OmpArgumentList &args{x.v.Arguments()};
+  if (args.v.size() != 1) {
+    context_.Say(args.source,
+        "DECLARE_VARIANT directive should have a single argument"_err_en_US);
+    return;
+  }
+
+  auto InvalidArgument{[&](parser::CharBlock source) {
+    context_.Say(source,
+        "The argument to the DECLARE_VARIANT directive should be [base-name:]variant-name"_err_en_US);
+  }};
+
+  auto CheckSymbol{[&](const Symbol *sym, parser::CharBlock source) {
+    if (sym) {
+      if (!IsProcedure(*sym) && !IsFunction(*sym)) {
+        context_.Say(source,
+            "The name '%s' should refer to a procedure"_err_en_US, sym->name());
+      }
+      if (sym->test(Symbol::Flag::Implicit)) {
+        context_.Say(source,
+            "The name '%s' has been implicitly declared"_err_en_US,
+            sym->name());
----------------
kparzysz wrote:
My reasoning was that the main problem is that the name should refer to a procedure, and that the message about implicit declaration explains why.  I've changed it a bit, so that the implicit declaration message is no longer an error on its own, but a note attached to the "should be a procedure" message.
In the "Use ODS in xyz" series of PRs I only added semantic checks that were needed because of the genericity of ODS, namely that the number of arguments is correct, and that their types are correct.  In this case (and some others) there are additional checks that are still needed, so the wording of the messages may need to be revised in the future.
https://github.com/llvm/llvm-project/pull/160371
    
    
More information about the flang-commits
mailing list