[flang-commits] [flang] 2985d56 - [flang] Improve error message (initialized variable in pure subprogram)

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Wed Jan 19 17:27:38 PST 2022


Author: Peter Klausler
Date: 2022-01-19T17:27:31-08:00
New Revision: 2985d5623c88f760d5c594d19558cd5c57ff3f45

URL: https://github.com/llvm/llvm-project/commit/2985d5623c88f760d5c594d19558cd5c57ff3f45
DIFF: https://github.com/llvm/llvm-project/commit/2985d5623c88f760d5c594d19558cd5c57ff3f45.diff

LOG: [flang] Improve error message (initialized variable in pure subprogram)

When variable with the SAVE attribute appears in a pure subprogram,
emit a more specialized error message if the SAVE attribute was acquired
from static initialization.

Differential Revision: https://reviews.llvm.org/D117699

Added: 
    

Modified: 
    flang/lib/Semantics/check-declarations.cpp
    flang/test/Semantics/call10.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp
index d5c677af3bc6e..dcb8cd3834039 100644
--- a/flang/lib/Semantics/check-declarations.cpp
+++ b/flang/lib/Semantics/check-declarations.cpp
@@ -237,8 +237,13 @@ void CheckHelper::Check(const Symbol &symbol) {
   }
   if (InPure()) {
     if (IsSaved(symbol)) {
-      messages_.Say(
-          "A pure subprogram may not have a variable with the SAVE attribute"_err_en_US);
+      if (IsInitialized(symbol)) {
+        messages_.Say(
+            "A pure subprogram may not initialize a variable"_err_en_US);
+      } else {
+        messages_.Say(
+            "A pure subprogram may not have a variable with the SAVE attribute"_err_en_US);
+      }
     }
     if (symbol.attrs().test(Attr::VOLATILE)) {
       messages_.Say(

diff  --git a/flang/test/Semantics/call10.f90 b/flang/test/Semantics/call10.f90
index fabadad32f1a1..0074668753089 100644
--- a/flang/test/Semantics/call10.f90
+++ b/flang/test/Semantics/call10.f90
@@ -85,9 +85,9 @@ pure subroutine s04(a) ! C1588
   pure subroutine s05 ! C1589
     !ERROR: A pure subprogram may not have a variable with the SAVE attribute
     real, save :: v1
-    !ERROR: A pure subprogram may not have a variable with the SAVE attribute
+    !ERROR: A pure subprogram may not initialize a variable
     real :: v2 = 0.
-    !ERROR: A pure subprogram may not have a variable with the SAVE attribute
+    !ERROR: A pure subprogram may not initialize a variable
     real :: v3
     data v3/0./
     !ERROR: A pure subprogram may not have a variable with the SAVE attribute
@@ -97,7 +97,7 @@ pure subroutine s05 ! C1589
     block
     !ERROR: A pure subprogram may not have a variable with the SAVE attribute
       real, save :: v5
-    !ERROR: A pure subprogram may not have a variable with the SAVE attribute
+    !ERROR: A pure subprogram may not initialize a variable
       real :: v6 = 0.
     end block
   end subroutine


        


More information about the flang-commits mailing list