[flang-commits] [flang] [flang] Silence spurious error (PR #106086)

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Mon Aug 26 08:02:56 PDT 2024


https://github.com/klausler created https://github.com/llvm/llvm-project/pull/106086

Don't attempt to give an object a default binding label when it shows up in a declaration after it has already been given an explicit binding label in an earlier declaration.

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

>From 71cc437a34df34fc74bba0a31f09dcc953249bc2 Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Mon, 26 Aug 2024 08:00:19 -0700
Subject: [PATCH] [flang] Silence spurious error

Don't attempt to give an object a default binding label
when it shows up in a declaration after it has already been
given an explicit binding label in an earlier declaration.

Fixes https://github.com/llvm/llvm-project/issues/106019.
---
 flang/lib/Semantics/resolve-names.cpp   | 3 +++
 flang/test/Semantics/declarations03.f90 | 3 +++
 2 files changed, 6 insertions(+)

diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index c0478fd4390076..ec8f854f64d103 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -1797,6 +1797,9 @@ void AttrsVisitor::SetBindNameOn(Symbol &symbol) {
     }
     auto last{label->find_last_not_of(" ")};
     label = label->substr(first, last - first + 1);
+  } else if (symbol.GetIsExplicitBindName()) {
+    // don't try to override explicit binding name with default
+    return;
   } else if (ClassifyProcedure(symbol) == ProcedureDefinitionClass::Internal) {
     // BIND(C) does not give an implicit binding label to internal procedures.
     return;
diff --git a/flang/test/Semantics/declarations03.f90 b/flang/test/Semantics/declarations03.f90
index 65b07e7d5c6567..8e6f0a4aaf6bd6 100644
--- a/flang/test/Semantics/declarations03.f90
+++ b/flang/test/Semantics/declarations03.f90
@@ -50,6 +50,9 @@ module m
   !ERROR: BIND_C attribute was already specified on 's5'
   integer, bind(c, name="ss2") :: s5
 
+  integer, bind(c, name="s6explicit") :: s6
+  dimension s6(10) ! caused spurious error
+
 end
 
 subroutine common1()



More information about the flang-commits mailing list