Skip to content

Conversation

@agozillon
Copy link
Contributor

Currently we're picking up and complaining about builtin (and procedure) symbols like null() when defaultmap(none) is set, so I've relaxed the restriction a bit to allow for procedures and named constants to bypass the restriction. It might be the case that we want to tighten it up again in certain aspects in the future.

Currently we're picking up and complaining about builtin symbols like
Null() when defaultmap(none) is set, so I've relaxed the restriction a
bit to allow for procedures and named constants to bypass the
restriction. It might be the case that we want to tighten it up again
in certain aspects in the future.
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:openmp flang:semantics labels Nov 13, 2025
@llvmbot
Copy link
Member

llvmbot commented Nov 13, 2025

@llvm/pr-subscribers-flang-openmp

@llvm/pr-subscribers-flang-semantics

Author: None (agozillon)

Changes

Currently we're picking up and complaining about builtin (and procedure) symbols like null() when defaultmap(none) is set, so I've relaxed the restriction a bit to allow for procedures and named constants to bypass the restriction. It might be the case that we want to tighten it up again in certain aspects in the future.


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

2 Files Affected:

  • (modified) flang/lib/Semantics/resolve-directives.cpp (+7-2)
  • (modified) flang/test/Semantics/OpenMP/defaultmap-clause-none.f90 (+37)
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index 224c69163b85e..71665355aed1a 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -3070,8 +3070,13 @@ void OmpAttributeVisitor::Post(const parser::Name &name) {
       // place for the types specified.
       if (Symbol * found{currScope().FindSymbol(name.source)}) {
         // If the variable has declare target applied to it (enter or link) it
-        // is exempt from defaultmap(none) restrictions
-        if (!symbol->GetUltimate().test(Symbol::Flag::OmpDeclareTarget)) {
+        // is exempt from defaultmap(none) restrictions.
+        // We also exempt procedures and named constants from defaultmap(none)
+        // checking.
+        if (!symbol->GetUltimate().test(Symbol::Flag::OmpDeclareTarget) &&
+            !(IsProcedure(*symbol) &&
+                !semantics::IsProcedurePointer(*symbol)) &&
+            !IsNamedConstant(*symbol)) {
           auto &dMap = GetContext().defaultMap;
           for (auto defaults : dMap) {
             if (defaults.second ==
diff --git a/flang/test/Semantics/OpenMP/defaultmap-clause-none.f90 b/flang/test/Semantics/OpenMP/defaultmap-clause-none.f90
index 08e8ebc995097..0b74e3412e472 100644
--- a/flang/test/Semantics/OpenMP/defaultmap-clause-none.f90
+++ b/flang/test/Semantics/OpenMP/defaultmap-clause-none.f90
@@ -94,3 +94,40 @@ subroutine defaultmap_aggregate_none
         end do
     !$omp end target
 end subroutine defaultmap_aggregate_none
+
+! Verify we do not catch null in defaultmap(none)
+subroutine defaultmap_builtin_none
+    implicit none
+    integer,  pointer :: ptr(:)
+
+    !$omp target defaultmap(none) map(ptr)
+!CHECK-NOT: The DEFAULTMAP(NONE) clause requires that 'null' must be listed in a data-sharing attribute, data-mapping attribute, or is_device_ptr clause
+            ptr => null()
+    !$omp end target
+end subroutine defaultmap_builtin_none
+
+module pro
+ implicit none
+contains
+
+ function test_procedure() result(ret)
+    integer :: ret
+    ret = 1
+ end function test_procedure
+
+! Verify we do not catch a function symbol in defaultmap(none)
+! but do catch procedure pointers
+subroutine defaultmap_func_and_procedure_pointer()
+    implicit none
+    procedure(test_procedure), pointer :: f1
+    integer :: i
+
+    f1 => test_procedure
+
+    !$omp target defaultmap(none) map(i)
+!ERROR: The DEFAULTMAP(NONE) clause requires that 'f1' must be listed in a data-sharing attribute, data-mapping attribute, or is_device_ptr clause
+        i = f1()
+        i = test_procedure()
+    !$omp end target
+end subroutine defaultmap_func_and_procedure_pointer
+end module

@agozillon agozillon requested a review from mjklemm November 14, 2025 13:34
@agozillon
Copy link
Contributor Author

Small ping for a review on this if possible please!

Copy link
Contributor

@mjklemm mjklemm left a comment

Choose a reason for hiding this comment

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

LGTM

@agozillon
Copy link
Contributor Author

thank you very much for the quick review @mjklemm

@agozillon agozillon merged commit 739a5a4 into llvm:main Nov 14, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

3 participants