Skip to content

Conversation

@llvmbot
Copy link
Member

@llvmbot llvmbot commented Apr 29, 2025

Backport b99dab2

Requested by: @tstellar

@llvmbot
Copy link
Member Author

llvmbot commented Apr 29, 2025

@eugeneepshteyn What do you think about merging this PR to the release branch?

@github-project-automation github-project-automation bot moved this to Needs Triage in LLVM Release Status Apr 29, 2025
@llvmbot llvmbot requested a review from eugeneepshteyn April 29, 2025 04:24
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Apr 29, 2025
@llvmbot
Copy link
Member Author

llvmbot commented Apr 29, 2025

@llvm/pr-subscribers-flang-semantics

Author: None (llvmbot)

Changes

Backport b99dab2

Requested by: @tstellar


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

2 Files Affected:

  • (modified) flang/lib/Semantics/check-declarations.cpp (+4-1)
  • (modified) flang/test/Semantics/call10.f90 (+4)
diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp
index 5c26469b9fa24..8da9252133bdc 100644
--- a/flang/lib/Semantics/check-declarations.cpp
+++ b/flang/lib/Semantics/check-declarations.cpp
@@ -359,7 +359,10 @@ void CheckHelper::Check(const Symbol &symbol) {
       // are not pertinent to the characteristics of the procedure.
       // Restrictions on entities in pure procedure interfaces don't need
       // enforcement.
-    } else if (!FindCommonBlockContaining(symbol) && IsSaved(symbol)) {
+    } else if (symbol.has<AssocEntityDetails>() ||
+        FindCommonBlockContaining(symbol)) {
+      // can look like they have SAVE but are fine in PURE
+    } else if (IsSaved(symbol)) {
       if (IsInitialized(symbol)) {
         messages_.Say(
             "A pure subprogram may not initialize a variable"_err_en_US);
diff --git a/flang/test/Semantics/call10.f90 b/flang/test/Semantics/call10.f90
index 2d2f57934cd8a..1e186f7b4048a 100644
--- a/flang/test/Semantics/call10.f90
+++ b/flang/test/Semantics/call10.f90
@@ -36,6 +36,8 @@ pure subroutine s05a
     end subroutine
   end interface
 
+  real :: moduleVar = 1.
+
  contains
 
   subroutine impure(x)
@@ -117,6 +119,8 @@ pure subroutine s05 ! C1589
     !ERROR: A pure subprogram may not initialize a variable
       real :: v6 = 0.
     end block
+    associate (x => moduleVar) ! ok
+    end associate
   end subroutine
   pure subroutine s06 ! C1589
     !ERROR: A pure subprogram may not have a variable with the VOLATILE attribute

@eugeneepshteyn
Copy link
Contributor

I have no opinion. If you need it there and it works, go a head and merge...

@github-project-automation github-project-automation bot moved this from Needs Triage to Needs Merge in LLVM Release Status Apr 30, 2025
A PURE subprogram can't have a local variable with the SAVE attribute.
An ASSOCIATE or SELECT TYPE construct entity whose selector is a
variable will return true from IsSave(); exclude them from the local
variable check.

Fixes llvm#131356.

(cherry picked from commit b99dab2)
@tstellar tstellar merged commit 8272e45 into llvm:release/20.x May 9, 2025
7 of 9 checks passed
@github-project-automation github-project-automation bot moved this from Needs Merge to Done in LLVM Release Status May 9, 2025
@github-actions
Copy link

github-actions bot commented May 9, 2025

@tstellar (or anyone else). If you would like to add a note about this fix in the release notes (completely optional). Please reply to this comment with a one or two sentence description of the fix. When you are done, please add the release:note label to this PR.

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

Labels

flang:semantics flang Flang issues not falling into any other category

Projects

Development

Successfully merging this pull request may close these issues.

4 participants