[flang-commits] [flang] [Flang][OpenMP] Add declare simd to all subprogram entries (PR #215777)

Sairudra More via flang-commits flang-commits at lists.llvm.org
Fri Aug 14 09:28:08 PDT 2026


================
@@ -6830,23 +5790,24 @@ genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
   // A `declare simd` directive may appear in the specification part of an
   // interface body. In that case the PFT records the directive as an
   // evaluation of the enclosing program unit rather than of the interface
-  // body's subprogram, and the clause operands (linear/aligned/uniform)
-  // reference dummy arguments that are local to the interface body and
-  // therefore have no address in the enclosing scope. Detect this by
-  // comparing the program unit lexically containing the directive with the
-  // procedure currently being lowered; if they differ, this evaluation is
-  // for a different procedure (the interface-body subprogram) and emitting
-  // an `omp.declare_simd` op here would create it with null operands. Skip
-  // emission: lowering for `declare simd` on an external procedure declared
-  // only via an interface body is not handled by this op-based form.
+  // body's subprogram. Detect this by comparing the program unit lexically
+  // containing the directive with the procedure currently being lowered; if
+  // they differ, the two options are:
+  //   1. It represents the described INTERFACE case, and emitting an
+  // `omp.declare_simd` op would be incorrect. These are lowered as external
+  // function declarations.
+  //   2. It represents an alternative ENTRY point to a subprogram, in which
+  // case we do need to emit the proper `omp.declare_simd` op.
   const semantics::Scope &progUnitScope =
       semantics::GetProgramUnitContaining(semaCtx.FindScope(beginSpec.source));
   lower::pft::FunctionLikeUnit *owningProc = eval.getOwningProcedure();
+  bool owningProcNotMainProgram = owningProc && !owningProc->isMainProgram();
   const semantics::Symbol *owningSym =
-      (owningProc && !owningProc->isMainProgram())
+      owningProcNotMainProgram
           ? &owningProc->getSubprogramSymbol()
           : (owningProc ? owningProc->getMainProgramSymbol() : nullptr);
-  if (progUnitScope.symbol() != owningSym)
+
+  if (!owningProcNotMainProgram && progUnitScope.symbol() != owningSym)
----------------
Saieiei wrote:

could we make the ENTRY allowance explicit instead of disabling the scope-mismatch check for every non-main procedure? As written, interface bodies inside subroutines/functions also bypass this guard, potentially recreating the unbound-operand case fixed by #197010/#192581. Could we distinguish actual ENTRY points from interface-body mismatches here and add a subprogram-interface regression?

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


More information about the flang-commits mailing list