[clang] [flang] [mlir] [Flang][OpenMP] Lower DECLARE TARGET INDIRECT clause (PR #208387)

via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 3 00:29:58 PST 2026


================
@@ -2702,15 +2702,40 @@ void OmpStructureChecker::Leave(const parser::OmpDeclareTargetDirective &x) {
       context_.Say(x.source,
           "If the DECLARE TARGET directive has a clause, it must contain at least one ENTER clause or LINK clause"_err_en_US);
     }
-    if (indirectClause && !enterClause) {
+    if (indirectClause && !enterClause && !toClause) {
       context_.Say(x.source,
-          "The INDIRECT clause cannot be used without the ENTER clause with the DECLARE TARGET directive."_err_en_US);
+          "The INDIRECT clause cannot be used without the ENTER or TO clause with the DECLARE TARGET directive."_err_en_US);
     }
     unsigned version{context_.langOptions().OpenMPVersion};
     if (toClause && version >= 52) {
       context_.Warn(common::UsageWarning::OpenMPUsage, toClause->source,
           "The usage of TO clause on DECLARE TARGET directive has been deprecated. Use ENTER clause instead."_warn_en_US);
     }
+    if (indirectClause) {
+      // The restriction applies only when the argument evaluates to true; an
+      // absent argument defaults to true.
+      bool isIndirect{true};
+      if (const auto &indirectExpr{
+              std::get<parser::OmpClause::Indirect>(indirectClause->u).v.v}) {
+        const auto &parserExpr{parser::UnwrapRef<parser::Expr>(*indirectExpr)};
+        if (auto &&expr{GetEvaluateExpr(parserExpr)})
+          isIndirect = GetLogicalValue(*expr).value_or(true);
----------------
blazie2004 wrote:

Agreed. Semantics now reports "The argument of the INDIRECT clause must be a constant scalar logical expression" and skips the DEVICE_TYPE check for that clause, so `indirect(flag) device_type(nohost)` gets only this error. [OpenMP 5.2 section 7.8.3](https://www.openmp.org/wp-content/uploads/OpenMP-API-Specification-5-2.pdf#page=229) gives invoked-by-fptr the constant property. The cases are in indirect03.f90, which now uses test_errors.py so each error is tied to its line.

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


More information about the cfe-commits mailing list