[flang-commits] [flang] [flang] Foil attempts to put automatic objects in COMMON (PR #66228)

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Wed Sep 13 14:11:30 PDT 2023


https://github.com/klausler updated https://github.com/llvm/llvm-project/pull/66228:

>From a7947592a4634ddde09874342512a72d65afe0db Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Tue, 29 Aug 2023 15:50:22 -0700
Subject: [PATCH] [flang] Foil attempts to put automatic objects in COMMON

We were catching automatic objects in modules and SAVE, but
not in COMMON blocks.

Fixes https://github.com/llvm/llvm-project/issues/65003.

Pull request: https://github.com/llvm/llvm-project/pull/66228
---
 flang/lib/Semantics/check-declarations.cpp | 15 ++++++++++-----
 flang/test/Semantics/resolve77.f90         | 10 ++++++++--
 2 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp
index e7e091ed024c48d..612abc471c5c61f 100644
--- a/flang/lib/Semantics/check-declarations.cpp
+++ b/flang/lib/Semantics/check-declarations.cpp
@@ -419,11 +419,16 @@ void CheckHelper::Check(const Symbol &symbol) {
     }
     CheckBindCFunctionResult(symbol);
   }
-  if (symbol.owner().IsModule() && IsAutomatic(symbol)) {
-    messages_.Say(
-        "Automatic data object '%s' may not appear in the specification part"
-        " of a module"_err_en_US,
-        symbol.name());
+  if (IsAutomatic(symbol)) {
+    if (const Symbol * common{FindCommonBlockContaining(symbol)}) {
+      messages_.Say(
+          "Automatic data object '%s' may not appear in COMMON block /%s/"_err_en_US,
+          symbol.name(), common->name());
+    } else if (symbol.owner().IsModule()) {
+      messages_.Say(
+          "Automatic data object '%s' may not appear in a module"_err_en_US,
+          symbol.name());
+    }
   }
   if (IsProcedure(symbol) && !symbol.HasExplicitInterface()) {
     if (IsAllocatable(symbol)) {
diff --git a/flang/test/Semantics/resolve77.f90 b/flang/test/Semantics/resolve77.f90
index 1a76e700908161d..ffee10271d51bfa 100644
--- a/flang/test/Semantics/resolve77.f90
+++ b/flang/test/Semantics/resolve77.f90
@@ -8,10 +8,16 @@ module m
   interface ifn3
     module procedure if3
   end interface
-  !ERROR: Automatic data object 'a' may not appear in the specification part of a module
+  !ERROR: Automatic data object 'a' may not appear in a module
   real :: a(if1(1))
-  !ERROR: Automatic data object 'b' may not appear in the specification part of a module
+  !ERROR: Automatic data object 'b' may not appear in a module
   real :: b(ifn2(1))
+  !ERROR: Automatic data object 'c' may not appear in COMMON block /blk/
+  real :: c(if1(1))
+  !ERROR: Automatic data object 'd' may not appear in COMMON block //
+  real :: d(ifn2(1))
+  common /blk/c
+  common d
  contains
   subroutine t1(n)
     integer :: iarr(if1(n))



More information about the flang-commits mailing list