Skip to content

Conversation

agozillon
Copy link
Contributor

In at least certain cases, notably when equivalence is used (at least for the example this showed up as a problem in) we currently miscategorize symbols as firstprivate when they may not be, as they can throw a false positive when a use symbol from a mod file is picked up.

The fix to this is to chase up the appropriate symbol to access the correct details.

…od file symbols

In at least certain cases, notably when equivalence is used (at least for the example
this showed up as a problem in) we currently miscategorize symbols as firstprivate
when they may not be, as they can throw a false positive when a yse symbol from a mod
file is picked up.

The fix to this is to chase up the appropriate symbol to access the correct details.
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:openmp flang:semantics labels Sep 5, 2025
@llvmbot
Copy link
Member

llvmbot commented Sep 5, 2025

@llvm/pr-subscribers-flang-fir-hlfir
@llvm/pr-subscribers-flang-semantics

@llvm/pr-subscribers-flang-openmp

Author: None (agozillon)

Changes

In at least certain cases, notably when equivalence is used (at least for the example this showed up as a problem in) we currently miscategorize symbols as firstprivate when they may not be, as they can throw a false positive when a use symbol from a mod file is picked up.

The fix to this is to chase up the appropriate symbol to access the correct details.


Full diff: https://github.com/llvm/llvm-project/pull/157009.diff

1 Files Affected:

  • (modified) flang/lib/Semantics/resolve-directives.cpp (+9-8)
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index a08e764ecf936..2eca768766887 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -2517,14 +2517,15 @@ static bool IsTargetCaptureImplicitlyFirstprivatizeable(const Symbol &symbol,
     return false;
   };
 
-  if (checkSymbol(symbol)) {
-    const auto *hostAssoc{symbol.detailsIf<HostAssocDetails>()};
-    if (hostAssoc) {
-      return checkSymbol(hostAssoc->symbol());
-    }
-    return true;
-  }
-  return false;
+  return common::visit(
+      common::visitors{
+          [&](const UseDetails &x) -> bool { return checkSymbol(x.symbol()); },
+          [&](const HostAssocDetails &x) -> bool {
+            return checkSymbol(x.symbol());
+          },
+          [&](const auto &) -> bool { return checkSymbol(symbol); },
+      },
+      symbol.details());
 }
 
 void OmpAttributeVisitor::CreateImplicitSymbols(const Symbol *symbol) {

@agozillon
Copy link
Contributor Author

If there's any suggestions for how best to create a test for this I'd be happy to add one, wasn't sure if there was a precedence in the Flang MLIR lit tests for having a two file test where one emits a mod file to use in the actual test file!

Otherwise, if there's any other similar edge cases like this that people know that might be possible I'd be happy to see about testing and addressing those! Still a lot of details about symbols that I'm missing :-)

@luporl
Copy link
Contributor

luporl commented Sep 5, 2025

Does the issue only occur when the module and its use are in separate files?
There are some tests that define a module and then use it in a program, but in the same file.
Another option could be using split-file, to have both parts in the same test file, like in flang/test/Lower/OpenMP/generic-loop-rewriting.f90.

In any case, a test or example would be good to help understand the issue.

@agozillon
Copy link
Contributor Author

Thank you I'll give them a try! I believe it only happens when it's in another file, it's when the symbol we initially "capture" emits something along the lines of "Use of symbol from *.mod"

@agozillon
Copy link
Contributor Author

Added a test that hopefully helps shed some light on things a bit better, thank you very much for the pointer to the example test! :-)

Copy link
Contributor

@luporl luporl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for adding a test.

@agozillon
Copy link
Contributor Author

Thank you very much for the help and the review!

@agozillon agozillon merged commit 262e994 into llvm:main Sep 8, 2025
10 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Sep 8, 2025

LLVM Buildbot has detected a new failure on builder openmp-offload-sles-build-only running on rocm-worker-hw-04-sles while building flang at step 7 "Add check check-flang".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/140/builds/30328

Here is the relevant piece of the build log for the reference
Step 7 (Add check check-flang) failure: test (failure)
******************** TEST 'Flang :: Lower/OpenMP/DelayedPrivatization/target-private-implicit-scalar-map-2.f90' FAILED ********************
Exit Code: 2

Command Output (stdout):
--
# RUN: at line 4
split-file /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/flang/test/Lower/OpenMP/DelayedPrivatization/target-private-implicit-scalar-map-2.f90 /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/tools/flang/test/Lower/OpenMP/DelayedPrivatization/Output/target-private-implicit-scalar-map-2.f90.tmp
# executed command: split-file /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/flang/test/Lower/OpenMP/DelayedPrivatization/target-private-implicit-scalar-map-2.f90 /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/tools/flang/test/Lower/OpenMP/DelayedPrivatization/Output/target-private-implicit-scalar-map-2.f90.tmp
# RUN: at line 6
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/bin/flang -fc1 -emit-hlfir -fopenmp -mmlir --enable-delayed-privatization-staging -fopenmp-version=50 /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/tools/flang/test/Lower/OpenMP/DelayedPrivatization/Output/target-private-implicit-scalar-map-2.f90.tmp/imp_scalar_map_module.f90 -o -  | /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/bin/flang -fc1 -emit-hlfir -fopenmp -mmlir --enable-delayed-privatization-staging  -fopenmp-version=50 /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/tools/flang/test/Lower/OpenMP/DelayedPrivatization/Output/target-private-implicit-scalar-map-2.f90.tmp/imp_scalar_map_target.f90 -o -  | /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/bin/FileCheck /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/tools/flang/test/Lower/OpenMP/DelayedPrivatization/Output/target-private-implicit-scalar-map-2.f90.tmp/imp_scalar_map_target.f90
# executed command: /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/bin/flang -fc1 -emit-hlfir -fopenmp -mmlir --enable-delayed-privatization-staging -fopenmp-version=50 /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/tools/flang/test/Lower/OpenMP/DelayedPrivatization/Output/target-private-implicit-scalar-map-2.f90.tmp/imp_scalar_map_module.f90 -o -
# .---command stdout------------
# | module attributes {dlti.dl_spec = #dlti.dl_spec<!llvm.ptr<270> = dense<32> : vector<4xi64>, !llvm.ptr<271> = dense<32> : vector<4xi64>, !llvm.ptr<272> = dense<64> : vector<4xi64>, i64 = dense<64> : vector<2xi64>, i128 = dense<128> : vector<2xi64>, f80 = dense<128> : vector<2xi64>, !llvm.ptr = dense<64> : vector<4xi64>, i1 = dense<8> : vector<2xi64>, i8 = dense<8> : vector<2xi64>, i16 = dense<16> : vector<2xi64>, i32 = dense<32> : vector<2xi64>, f16 = dense<16> : vector<2xi64>, f64 = dense<64> : vector<2xi64>, f128 = dense<128> : vector<2xi64>, "dlti.endianness" = "little", "dlti.mangling_mode" = "e", "dlti.legal_int_widths" = array<i32: 8, 16, 32, 64>, "dlti.stack_alignment" = 128 : i64>, fir.defaultkind = "a1c4d8i4l4r4", fir.kindmap = "", llvm.data_layout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128", llvm.ident = "flang version 22.0.0 (https://github.com/llvm/llvm-project.git 262e994c8b1640a13819ca3d1de82dab300e1771)", llvm.target_triple = "x86_64-unknown-linux-gnu", omp.is_gpu = false, omp.is_target_device = false, omp.target_triples = [], omp.version = #omp.version<version = 50>} {
# |   fir.global @_QMtest_dataEj : !fir.array<200xi8> {
# |     %0 = fir.zero_bits !fir.array<200xi8>
# |     fir.has_value %0 : !fir.array<200xi8>
# |   }
# |   fir.global @_QMtest_dataEi : !fir.array<10x10xf32> {
# |     %0 = fir.zero_bits !fir.array<10x10xf32>
# |     fir.has_value %0 : !fir.array<10x10xf32>
# |   }
# |   fir.global @_QMtest_dataEz : i32 {
# |     %0 = fir.zero_bits i32
# |     fir.has_value %0 : i32
# |   }
# | }
# `-----------------------------
# .---command stderr------------
# | warning: OpenMP support for version 50 in flang is still incomplete
# `-----------------------------
# executed command: /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/bin/flang -fc1 -emit-hlfir -fopenmp -mmlir --enable-delayed-privatization-staging -fopenmp-version=50 /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/tools/flang/test/Lower/OpenMP/DelayedPrivatization/Output/target-private-implicit-scalar-map-2.f90.tmp/imp_scalar_map_target.f90 -o -
# .---command stderr------------
# | warning: OpenMP support for version 50 in flang is still incomplete
# | error: Semantic errors in /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/tools/flang/test/Lower/OpenMP/DelayedPrivatization/Output/target-private-implicit-scalar-map-2.f90.tmp/imp_scalar_map_target.f90
# | /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/tools/flang/test/Lower/OpenMP/DelayedPrivatization/Output/target-private-implicit-scalar-map-2.f90.tmp/imp_scalar_map_target.f90:2:9: error: Cannot parse module file for module 'test_data': Source file 'test_data.mod' was not found
# |       use test_data
# |           ^^^^^^^^^
# | /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/tools/flang/test/Lower/OpenMP/DelayedPrivatization/Output/target-private-implicit-scalar-map-2.f90.tmp/imp_scalar_map_target.f90:7:17: error: No explicit type declared for 'z'
# |           x = y + z + i(1,1) + j(1,1,1) + k(1,1)
# |                   ^
# | /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/tools/flang/test/Lower/OpenMP/DelayedPrivatization/Output/target-private-implicit-scalar-map-2.f90.tmp/imp_scalar_map_target.f90:7:21: error: No explicit type declared for 'i'
# |           x = y + z + i(1,1) + j(1,1,1) + k(1,1)
# |                       ^
# | /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/tools/flang/test/Lower/OpenMP/DelayedPrivatization/Output/target-private-implicit-scalar-map-2.f90.tmp/imp_scalar_map_target.f90:7:30: error: No explicit type declared for 'j'
# |           x = y + z + i(1,1) + j(1,1,1) + k(1,1)
# |                                ^
# | /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/tools/flang/test/Lower/OpenMP/DelayedPrivatization/Output/target-private-implicit-scalar-map-2.f90.tmp/imp_scalar_map_target.f90:7:41: error: No explicit type declared for 'k'
# |           x = y + z + i(1,1) + j(1,1,1) + k(1,1)
# |                                           ^
# `-----------------------------
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flang:fir-hlfir flang:openmp flang:semantics flang Flang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants