[flang-commits] [PATCH] D117699: [flang] Improve error message (initialized variable in pure subprogram)

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


This revision was automatically updated to reflect the committed changes.
Closed by commit rG2985d5623c88: [flang] Improve error message (initialized variable in pure subprogram) (authored by klausler).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D117699/new/

https://reviews.llvm.org/D117699

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


Index: flang/test/Semantics/call10.f90
===================================================================
--- flang/test/Semantics/call10.f90
+++ flang/test/Semantics/call10.f90
@@ -85,9 +85,9 @@
   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 @@
     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
Index: flang/lib/Semantics/check-declarations.cpp
===================================================================
--- flang/lib/Semantics/check-declarations.cpp
+++ flang/lib/Semantics/check-declarations.cpp
@@ -237,8 +237,13 @@
   }
   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(


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117699.401455.patch
Type: text/x-patch
Size: 1822 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220120/6ecae211/attachment.bin>


More information about the flang-commits mailing list