Thanks to visit codestin.com
Credit goes to github.com

Skip to content

release/20.x: [flang] Exempt construct entities from SAVE check for PURE (#131383) #137752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: release/20.x
Choose a base branch
from

Conversation

llvmbot
Copy link
Member

@llvmbot llvmbot commented Apr 29, 2025

Backport b99dab2

Requested by: @tstellar

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)
@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
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
Status: Needs Merge
Development

Successfully merging this pull request may close these issues.

3 participants