[flang-commits] [flang] [flang] Silence bogus error (PR #160173)
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Mon Sep 22 11:47:00 PDT 2025
https://github.com/klausler created https://github.com/llvm/llvm-project/pull/160173
One of the checks for implicitly-typed names under IMPLICIT NONE has a false positive case for USE-associated items in COMMON blocks.
Fixes https://github.com/llvm/llvm-project/issues/159977.
>From 5c549d9879e2f6d8ea97926cfbb4fba8e5dacbde Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Mon, 22 Sep 2025 10:46:15 -0700
Subject: [PATCH] [flang] Silence bogus error
One of the checks for implicitly-typed names under IMPLICIT NONE
has a false positive case for USE-associated items in COMMON blocks.
Fixes https://github.com/llvm/llvm-project/issues/159977.
---
flang/lib/Semantics/resolve-names.cpp | 3 ++-
flang/test/Semantics/bug159977.f90 | 11 +++++++++++
2 files changed, 13 insertions(+), 1 deletion(-)
create mode 100644 flang/test/Semantics/bug159977.f90
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index e97f0bf02a515..93fbbb58b06fd 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -3376,7 +3376,8 @@ bool ScopeHandler::CheckPossibleBadForwardRef(const Symbol &symbol) {
context().SetError(symbol);
return true;
}
- if ((IsDummy(symbol) || FindCommonBlockContaining(symbol)) &&
+ if ((IsDummy(symbol) ||
+ (!symbol.has<UseDetails>() && FindCommonBlockContaining(symbol))) &&
isImplicitNoneType() && symbol.test(Symbol::Flag::Implicit) &&
!context().HasError(symbol)) {
// Dummy or COMMON was implicitly typed despite IMPLICIT NONE(TYPE) in
diff --git a/flang/test/Semantics/bug159977.f90 b/flang/test/Semantics/bug159977.f90
new file mode 100644
index 0000000000000..ee731c9fb170e
--- /dev/null
+++ b/flang/test/Semantics/bug159977.f90
@@ -0,0 +1,11 @@
+! RUN: %flang_fc1 -fsyntax-only -pedantic %s 2>&1 | FileCheck %s --allow-empty
+! Ensure no bogus "no explicit type for ..." error on USE-associated
+! implicitly-typed COMMON block object in scope with IMPLICIT NONE.
+! CHECK-NOT: error:
+module m
+ common /block/ var
+end
+subroutine test
+ use m
+ implicit none
+end
More information about the flang-commits
mailing list