[flang-commits] [flang] 57197a0 - Revert "[Flang][OpenMP][Sema] Add OpenMP warning when mapping local descriptors to device on enter without a corresponding exit" (#203324)

via flang-commits flang-commits at lists.llvm.org
Thu Jun 11 09:16:43 PDT 2026


Author: dpalermo
Date: 2026-06-11T11:16:37-05:00
New Revision: 57197a0c7b9bb9c362e83e755f653c29996458b7

URL: https://github.com/llvm/llvm-project/commit/57197a0c7b9bb9c362e83e755f653c29996458b7
DIFF: https://github.com/llvm/llvm-project/commit/57197a0c7b9bb9c362e83e755f653c29996458b7.diff

LOG: Revert "[Flang][OpenMP][Sema] Add OpenMP warning when mapping local descriptors to device on enter without a corresponding exit" (#203324)

Reverts llvm/llvm-project#201060

Warning is actually reporting an error causing compilation to fail:
error: Semantic errors in OpenMPTargetStream.F90

Above error from Babelstream. Can be seen with either of the following
reproducers:
aomp/test/smoke-fort/milestone-3-babel-copy
aomp/test/smoke-fort-dev/milestone-3-babel

Added: 
    

Modified: 
    flang/include/flang/Semantics/openmp-utils.h
    flang/lib/Semantics/check-omp-structure.cpp
    flang/lib/Semantics/check-omp-structure.h
    flang/lib/Semantics/openmp-utils.cpp

Removed: 
    flang/test/Semantics/OpenMP/target-enter-data-temp-descriptor-omp61.f90
    flang/test/Semantics/OpenMP/target-enter-data-temp-descriptor.f90


################################################################################
diff  --git a/flang/include/flang/Semantics/openmp-utils.h b/flang/include/flang/Semantics/openmp-utils.h
index 754d14df9f07c..e0358eafe487c 100644
--- a/flang/include/flang/Semantics/openmp-utils.h
+++ b/flang/include/flang/Semantics/openmp-utils.h
@@ -119,12 +119,6 @@ const Symbol *GetHostSymbol(const Symbol &sym);
 bool IsMapEnteringType(parser::OmpMapType::Value type);
 bool IsMapExitingType(parser::OmpMapType::Value type);
 
-// Returns true if the symbol has a temporary stack-allocated descriptor.
-// This includes assumed-shape and assumed-rank dummy arguments that are
-// not allocatable or pointer. These descriptors are created on the caller's
-// stack and become invalid after the function returns.
-bool HasTemporaryStackDescriptor(const Symbol &symbol);
-
 MaybeExpr GetEvaluateExpr(const parser::Expr &parserExpr);
 template <typename T> MaybeExpr GetEvaluateExpr(const T &inp) {
   return GetEvaluateExpr(parser::UnwrapRef<parser::Expr>(inp));

diff  --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index 52b174fba7f21..046fc98c7d80c 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -142,27 +142,7 @@ void OmpStructureChecker::Enter(const parser::SubroutineStmt &x) {
   scopeStack_.push_back(sym->scope());
 }
 
-void OmpStructureChecker::CheckTempDescriptorMappings() {
-  unsigned version{context_.langOptions().OpenMPVersion};
-  for (const auto &[symbol, source] : tempDescriptorEnterMaps_) {
-    if (tempDescriptorExitMaps_.find(symbol) == tempDescriptorExitMaps_.end()) {
-      if (version >= 61) {
-        context_.Warn(common::UsageWarning::OpenMPUsage, source,
-            "The map of '%s' may include a descriptor that is created locally. Mapping this descriptor without an appropriate TARGET EXIT DATA in the same scope may result in the device retaining an invalid descriptor reference. To avoid mapping the descriptor utilize OpenMP's ref_ptee reference modifier to map just the data"_warn_en_US,
-            symbol->name());
-      } else {
-        context_.Warn(common::UsageWarning::OpenMPUsage, source,
-            "The map of '%s' may include a descriptor that is created locally. Mapping this descriptor without an appropriate TARGET EXIT DATA in the same scope may result in the device retaining an invalid descriptor reference"_warn_en_US,
-            symbol->name());
-      }
-    }
-  }
-  tempDescriptorEnterMaps_.clear();
-  tempDescriptorExitMaps_.clear();
-}
-
 void OmpStructureChecker::Enter(const parser::EndSubroutineStmt &x) {
-  CheckTempDescriptorMappings();
   scopeStack_.pop_back();
 }
 
@@ -172,7 +152,6 @@ void OmpStructureChecker::Enter(const parser::FunctionStmt &x) {
 }
 
 void OmpStructureChecker::Enter(const parser::EndFunctionStmt &x) {
-  CheckTempDescriptorMappings();
   scopeStack_.pop_back();
 }
 
@@ -182,7 +161,6 @@ void OmpStructureChecker::Enter(const parser::MpSubprogramStmt &x) {
 }
 
 void OmpStructureChecker::Enter(const parser::EndMpSubprogramStmt &x) {
-  CheckTempDescriptorMappings();
   scopeStack_.pop_back();
 }
 
@@ -4688,38 +4666,6 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Map &x) {
       }
     }
   }
-
-  // If we are an enter or exit map, iterate over the maps and add them to
-  // containers that track if the symbol has been referenced in both an
-  // enter/exit map in the current scope, if it falls into the category of
-  // having a temporary stack descriptor. If we have reference modifiers, we
-  // ignore the warning and trust that the user knows what they are doing
-  // already, as they are aware the type comes with a descriptor and pointer
-  // combination.
-  //
-  // We will utilise this information to emit a warning later if the neccesary
-  // conditions are met, where we have an enter map without a corresponding exit
-  // in the current scope.
-  bool hasRefModifier{
-      OmpGetUniqueModifier<parser::OmpRefModifier>(modifiers) != nullptr};
-  if (!hasRefModifier &&
-      (llvm::is_contained(leafs, Directive::OMPD_target_enter_data) ||
-          llvm::is_contained(leafs, Directive::OMPD_target_exit_data))) {
-    for (const parser::OmpObject &object : objects.v) {
-      if (const Symbol *sym{GetObjectSymbol(object, /*ultimate=*/true)}) {
-        if (HasTemporaryStackDescriptor(*sym)) {
-          auto maybeSource{GetObjectSource(object)};
-          parser::CharBlock source{
-              maybeSource.value_or(GetContext().clauseSource)};
-          if (llvm::is_contained(leafs, Directive::OMPD_target_enter_data)) {
-            tempDescriptorEnterMaps_.emplace(sym, source);
-          } else {
-            tempDescriptorExitMaps_.insert(sym);
-          }
-        }
-      }
-    }
-  }
 }
 
 void OmpStructureChecker::Enter(const parser::OmpClause::Schedule &x) {

diff  --git a/flang/lib/Semantics/check-omp-structure.h b/flang/lib/Semantics/check-omp-structure.h
index 6816f6dcc787c..66211d58e030c 100644
--- a/flang/lib/Semantics/check-omp-structure.h
+++ b/flang/lib/Semantics/check-omp-structure.h
@@ -403,7 +403,6 @@ class OmpStructureChecker : public OmpStructureCheckerBase {
       const parser::OmpClause &initClause);
   void CheckAllowedRequiresClause(llvm::omp::Clause clause);
   void AddEndDirectiveClauses(const parser::OmpClauseList &clauses);
-  void CheckTempDescriptorMappings();
 
   void EnterDirectiveNest(const int index) { directiveNest_[index]++; }
   void ExitDirectiveNest(const int index) { directiveNest_[index]--; }
@@ -426,12 +425,6 @@ class OmpStructureChecker : public OmpStructureCheckerBase {
   int allocateDirectiveLevel_{0};
   parser::CharBlock visitedAtomicSource_;
 
-  // Track symbols with temporary stack descriptors mapped in TARGET ENTER DATA
-  // and symbols mapped in TARGET EXIT DATA within the current function scope.
-  // Used to warn about potential issues with mapping temporary descriptors.
-  std::multimap<const Symbol *, parser::CharBlock> tempDescriptorEnterMaps_;
-  std::set<const Symbol *> tempDescriptorExitMaps_;
-
   // Stack of nested DO loops and OpenMP constructs.
   // This is used to verify DO loop nest for DOACROSS, and branches into
   // and out of OpenMP constructs.

diff  --git a/flang/lib/Semantics/openmp-utils.cpp b/flang/lib/Semantics/openmp-utils.cpp
index 1079537dc64e4..b02ef81176a63 100644
--- a/flang/lib/Semantics/openmp-utils.cpp
+++ b/flang/lib/Semantics/openmp-utils.cpp
@@ -312,29 +312,6 @@ bool IsMapExitingType(parser::OmpMapType::Value type) {
   }
 }
 
-// This function aims to return true when a symbol is going to result
-// in a temporary stack descriptor being allocated for it in the
-// lowering that may pose an issue for data mapping if left on
-// device accidentally.
-bool HasTemporaryStackDescriptor(const Symbol &symbol) {
-  const Symbol &ultimate(symbol.GetUltimate());
-  bool isDummy = IsDummy(ultimate);
-
-  if (IsAllocatableOrPointer(ultimate)) {
-    return !isDummy;
-  }
-
-  if (!isDummy) {
-    return false;
-  }
-
-  if (const auto *obj = ultimate.detailsIf<ObjectEntityDetails>()) {
-    return obj->IsAssumedShape() || obj->IsAssumedRank();
-  }
-
-  return false;
-}
-
 static MaybeExpr GetEvaluateExprFromTyped(const parser::TypedExpr &typedExpr) {
   // ForwardOwningPointer           typedExpr
   // `- GenericExprWrapper          ^.get()

diff  --git a/flang/test/Semantics/OpenMP/target-enter-data-temp-descriptor-omp61.f90 b/flang/test/Semantics/OpenMP/target-enter-data-temp-descriptor-omp61.f90
deleted file mode 100644
index e766b1b44d0fa..0000000000000
--- a/flang/test/Semantics/OpenMP/target-enter-data-temp-descriptor-omp61.f90
+++ /dev/null
@@ -1,97 +0,0 @@
-! RUN: %python %S/../test_errors.py %s %flang -fopenmp -fopenmp-version=61 -Werror -Wno-experimental-option
-
-! Check for OpenMP 6.1+ specific warning that includes ref_ptee suggestion
-! when mapping variables with temporary stack descriptors on TARGET ENTER DATA
-! without a corresponding TARGET EXIT DATA.
-
-subroutine test_assumed_shape_warning(arr)
-  integer, intent(inout), dimension(:,:) :: arr(:)
-  !WARNING: The map of 'arr' may include a descriptor that is created locally. Mapping this descriptor without an appropriate TARGET EXIT DATA in the same scope may result in the device retaining an invalid descriptor reference. To avoid mapping the descriptor utilize OpenMP's ref_ptee reference modifier to map just the data [-Wopenmp-usage]
-  !$omp target enter data map(to: arr)
-end subroutine
-
-subroutine test_assumed_rank_warning(arr)
-  integer, intent(inout) :: arr(..)
-  !WARNING: The map of 'arr' may include a descriptor that is created locally. Mapping this descriptor without an appropriate TARGET EXIT DATA in the same scope may result in the device retaining an invalid descriptor reference. To avoid mapping the descriptor utilize OpenMP's ref_ptee reference modifier to map just the data [-Wopenmp-usage]
-  !$omp target enter data map(to: arr)
-end subroutine
-
-subroutine test_local_allocatable_warning()
-  integer, allocatable :: local_arr(:)
-  allocate(local_arr(100))
-  !WARNING: The map of 'local_arr' may include a descriptor that is created locally. Mapping this descriptor without an appropriate TARGET EXIT DATA in the same scope may result in the device retaining an invalid descriptor reference. To avoid mapping the descriptor utilize OpenMP's ref_ptee reference modifier to map just the data [-Wopenmp-usage]
-  !$omp target enter data map(to: local_arr)
-  deallocate(local_arr)
-end subroutine
-
-subroutine test_local_pointer_warning()
-  integer, pointer :: local_ptr(:)
-  allocate(local_ptr(100))
-  !WARNING: The map of 'local_ptr' may include a descriptor that is created locally. Mapping this descriptor without an appropriate TARGET EXIT DATA in the same scope may result in the device retaining an invalid descriptor reference. To avoid mapping the descriptor utilize OpenMP's ref_ptee reference modifier to map just the data [-Wopenmp-usage]
-  !$omp target enter data map(to: local_ptr)
-  deallocate(local_ptr)
-end subroutine
-
-module test_module
-contains
-  subroutine test_module_procedure_warning(arr)
-    integer, intent(inout) :: arr(:)
-    !WARNING: The map of 'arr' may include a descriptor that is created locally. Mapping this descriptor without an appropriate TARGET EXIT DATA in the same scope may result in the device retaining an invalid descriptor reference. To avoid mapping the descriptor utilize OpenMP's ref_ptee reference modifier to map just the data [-Wopenmp-usage]
-    !$omp target enter data map(to: arr)
-  end subroutine
-
-  subroutine test_module_procedure_with_exit(arr)
-    integer, intent(inout) :: arr(:)
-    !$omp target enter data map(to: arr)
-    !$omp target exit data map(from: arr)
-  end subroutine
-end module
-
-! Test cases where warnings should not be emitted, the test_errors.py script
-! should fail if we emit errors for these that are not checked, so no need to
-! verify with an explicit check.
-
-subroutine test_ref_ptee_no_warning(arr)
-  integer, intent(inout) :: arr(:)
-  !$omp target enter data map(ref_ptee, to: arr)
-end subroutine
-
-subroutine test_ref_ptr_no_warning(arr)
-  integer, intent(inout) :: arr(:)
-  !$omp target enter data map(ref_ptr, to: arr)
-end subroutine
-
-subroutine test_ref_ptr_ptee_no_warning(arr)
-  integer, intent(inout) :: arr(:)
-  !$omp target enter data map(ref_ptr_ptee, to: arr)
-end subroutine
-
-subroutine test_with_exit_data(arr)
-  integer, intent(inout) :: arr(:)
-  !$omp target enter data map(to: arr)
-  !$omp target exit data map(from: arr)
-end subroutine
-
-subroutine test_explicit_shape_no_warning(arr, n)
-  integer, intent(in) :: n
-  integer, intent(inout) :: arr(n)
-  !$omp target enter data map(to: arr)
-end subroutine
-
-subroutine test_local_allocatable_with_exit()
-  integer, allocatable :: local_arr(:)
-  allocate(local_arr(100))
-  !$omp target enter data map(to: local_arr)
-  !$omp target exit data map(from: local_arr)
-  deallocate(local_arr)
-end subroutine
-
-subroutine test_allocatable_dummy_no_warning(arr)
-  integer, allocatable, intent(inout) :: arr(:)
-  !$omp target enter data map(to: arr)
-end subroutine
-
-subroutine test_pointer_dummy_no_warning(ptr)
-  integer, pointer, intent(inout) :: ptr(:)
-  !$omp target enter data map(to: ptr)
-end subroutine

diff  --git a/flang/test/Semantics/OpenMP/target-enter-data-temp-descriptor.f90 b/flang/test/Semantics/OpenMP/target-enter-data-temp-descriptor.f90
deleted file mode 100644
index bd1eb98ebec60..0000000000000
--- a/flang/test/Semantics/OpenMP/target-enter-data-temp-descriptor.f90
+++ /dev/null
@@ -1,93 +0,0 @@
-! RUN: %python %S/../test_errors.py %s %flang -fopenmp -Werror -fopenmp-version=52 -Wno-experimental-option
-
-! Check for warning when mapping variables with temporary stack descriptors
-! (assumed-shape, assumed-rank, local allocatables, local pointers) on
-! TARGET ENTER DATA without a corresponding TARGET EXIT DATA in the same scope.
-
-subroutine test_assumed_shape_warning(arr)
-  integer, intent(inout) :: arr(:)
-  !WARNING: The map of 'arr' may include a descriptor that is created locally. Mapping this descriptor without an appropriate TARGET EXIT DATA in the same scope may result in the device retaining an invalid descriptor reference [-Wopenmp-usage]
-  !$omp target enter data map(to: arr)
-end subroutine
-
-subroutine test_assumed_shape_2d_warning(arr)
-  integer, intent(inout) :: arr(:,:)
-  !WARNING: The map of 'arr' may include a descriptor that is created locally. Mapping this descriptor without an appropriate TARGET EXIT DATA in the same scope may result in the device retaining an invalid descriptor reference [-Wopenmp-usage]
-  !$omp target enter data map(to: arr)
-end subroutine
-
-subroutine test_assumed_rank_warning(arr)
-  integer, intent(inout) :: arr(..)
-  !WARNING: The map of 'arr' may include a descriptor that is created locally. Mapping this descriptor without an appropriate TARGET EXIT DATA in the same scope may result in the device retaining an invalid descriptor reference [-Wopenmp-usage]
-  !$omp target enter data map(to: arr)
-end subroutine
-
-subroutine test_local_pointer_warning()
-  integer, pointer :: local_ptr(:)
-  allocate(local_ptr(100))
-  !WARNING: The map of 'local_ptr' may include a descriptor that is created locally. Mapping this descriptor without an appropriate TARGET EXIT DATA in the same scope may result in the device retaining an invalid descriptor reference [-Wopenmp-usage]
-  !$omp target enter data map(to: local_ptr)
-  deallocate(local_ptr)
-end subroutine
-
-subroutine test_local_allocatable_warning()
-  integer, allocatable :: local_arr(:)
-  allocate(local_arr(100))
-  !WARNING: The map of 'local_arr' may include a descriptor that is created locally. Mapping this descriptor without an appropriate TARGET EXIT DATA in the same scope may result in the device retaining an invalid descriptor reference [-Wopenmp-usage]
-  !$omp target enter data map(to: local_arr)
-  deallocate(local_arr)
-end subroutine
-
-module test_module
-contains
-  subroutine test_module_procedure_warning(arr)
-    integer, intent(inout) :: arr(:)
-    !WARNING: The map of 'arr' may include a descriptor that is created locally. Mapping this descriptor without an appropriate TARGET EXIT DATA in the same scope may result in the device retaining an invalid descriptor reference [-Wopenmp-usage]
-    !$omp target enter data map(to: arr)
-  end subroutine
-
-  subroutine test_module_procedure_with_exit(arr)
-    integer, intent(inout) :: arr(:)
-    !$omp target enter data map(to: arr)
-    !$omp target exit data map(from: arr)
-  end subroutine
-end module
-
-! Test cases where warnings should not be emitted, the test_errors.py script
-! should fail if we emit errors for these that are not checked, so no need to
-! verify with an explicit check.
-
-subroutine test_pointer_dummy_no_warning(ptr)
-  integer, pointer, intent(inout) :: ptr(:)
-  !$omp target enter data map(to: ptr)
-end subroutine
-
-subroutine test_allocatable_dummy_no_warning(arr)
-  integer, allocatable, intent(inout) :: arr(:)
-  !$omp target enter data map(to: arr)
-end subroutine
-
-subroutine test_with_exit_data(arr)
-  integer, intent(inout) :: arr(:)
-  !$omp target enter data map(to: arr)
-  !$omp target exit data map(from: arr)
-end subroutine
-
-subroutine test_explicit_shape_no_warning(arr, n)
-  integer, intent(in) :: n
-  integer, intent(inout) :: arr(n)
-  !$omp target enter data map(to: arr)
-end subroutine
-
-subroutine test_assumed_size_no_warning(arr)
-  integer, intent(inout) :: arr(*)
-  !$omp target enter data map(to: arr(1:10))
-end subroutine
-
-subroutine test_local_allocatable_with_exit()
-  integer, allocatable :: local_arr(:)
-  allocate(local_arr(100))
-  !$omp target enter data map(to: local_arr)
-  !$omp target exit data map(from: local_arr)
-  deallocate(local_arr)
-end subroutine


        


More information about the flang-commits mailing list