Skip to content

[flang] Spurious error with ASSOCIATE in a PURE procedure #131356

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

Closed
kcooley-cvd opened this issue Mar 14, 2025 · 5 comments · Fixed by #131383
Closed

[flang] Spurious error with ASSOCIATE in a PURE procedure #131356

kcooley-cvd opened this issue Mar 14, 2025 · 5 comments · Fixed by #131383

Comments

@kcooley-cvd
Copy link

When given the following code:

MODULE test_m
   REAL :: module_var
CONTAINS
   PURE SUBROUTINE test()
      ASSOCIATE(var => module_var)
      END ASSOCIATE
   END SUBROUTINE test
END MODULE test_m

Flang wrongly announces an error:

./test.f90:14:17: error: A pure subprogram may not have a variable with the SAVE attribute
        ASSOCIATE(var => module_var)
                  ^^^

But test is a valid PURE subroutine since var is not assigned to. Version information:

flang version 20.1.0 (https://github.com/llvm/llvm-project.git 24a30daaa559829ad079f2ff7f73eb4e18095f88)
Target: x86_64-unknown-linux-gnu
Thread model: posix
@llvmbot llvmbot added the flang Flang issues not falling into any other category label Mar 14, 2025
@EugeneZelenko EugeneZelenko added flang:frontend and removed flang Flang issues not falling into any other category labels Mar 14, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 14, 2025

@llvm/issue-subscribers-flang-frontend

Author: None (kcooley-cvd)

When given the following code:
MODULE test_m
   REAL :: module_var
CONTAINS
   PURE SUBROUTINE test()
      ASSOCIATE(var => module_var)
      END ASSOCIATE
   END SUBROUTINE test
END MODULE test_m

Flang wrongly announces an error:

./test.f90:14:17: error: A pure subprogram may not have a variable with the SAVE attribute
        ASSOCIATE(var => module_var)
                  ^^^

But test is a valid PURE subroutine since var is not assigned to. Version information:

flang version 20.1.0 (https://github.com/llvm/llvm-project.git 24a30daaa559829ad079f2ff7f73eb4e18095f88)
Target: x86_64-unknown-linux-gnu
Thread model: posix

@klausler klausler self-assigned this Mar 14, 2025
@klausler
Copy link
Contributor

Thanks for the bug report and its short and clear example! Quick fix coming soon.

klausler added a commit to klausler/llvm-project that referenced this issue Mar 14, 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.
klausler added a commit that referenced this issue Mar 19, 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 #131356.
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this issue Mar 19, 2025
… (#131383)

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/llvm-project#131356.
@kcooley-cvd
Copy link
Author

What is the approximate timeline for this fix to make it into a release?

@tstellar
Copy link
Collaborator

/cherry-pick b99dab2

@llvmbot
Copy link
Member

llvmbot commented Apr 29, 2025

/pull-request #137752

swift-ci pushed a commit to swiftlang/llvm-project that referenced this issue May 9, 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 moved this from Needs Triage to Done in LLVM Release Status May 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging a pull request may close this issue.

5 participants