[flang-commits] [flang] [flang][OpenMP]Add symbls omp_in, omp_out and omp_priv in DECLARE RED… (PR #129908)

Mats Petersson via flang-commits flang-commits at lists.llvm.org
Fri Mar 7 09:41:43 PST 2025


================
@@ -1761,11 +1770,26 @@ void OmpVisitor::ProcessReductionSpecifier(
   // Creating a new scope in case the combiner expression (or clauses) use
   // reerved identifiers, like "omp_in". This is a temporary solution until
   // we deal with these in a more thorough way.
-  PushScope(Scope::Kind::OtherConstruct, nullptr);
-  Walk(std::get<parser::OmpTypeNameList>(spec.t));
-  Walk(std::get<std::optional<parser::OmpReductionCombiner>>(spec.t));
-  Walk(clauses);
-  PopScope();
+  auto &typeList = std::get<parser::OmpTypeNameList>(spec.t);
+  for (auto &t : typeList.v) {
+    PushScope(Scope::Kind::OtherConstruct, nullptr);
+    BeginDeclTypeSpec();
+    // We need to walk t.u because Walk(t) does it's own BeginDeclTypeSpec.
+    Walk(t.u);
+
+    auto *typeSpec = GetDeclTypeSpec();
+    assert(typeSpec && "We should have a type here");
+    const parser::CharBlock ompVarNames[] = {
+        {"omp_in", 6}, {"omp_out", 7}, {"omp_priv", 8}};
----------------
Leporacanthicus wrote:

Well, they have names - that's what those CharBlock things are for. 

I'll add a comment, but the point is that inside the loop that iterates over the types, the assignment in the reduction specifier and the clauselist [whch is where the intializer is dealt with]  will need these symbols. It worked previously for basic types, because the semantic analysis accepts basic operations like `omp_out=omp_in+omp_out` by generating implicit symbols  [assuming `implicit none` isn't used].

Here's an example with `implicit none` that fails to compile: Comment out that one line and it will hit the "Not yet implemented" - of course, it would be WRONG, because omp_out is implicitly declared as a float, but it compiles...
https://godbolt.org/z/rM49GdjhY

The question is really how much effort we should put into avoiding generating symbols that aren't strictly required.

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


More information about the flang-commits mailing list