Skip to content

Conversation

eugeneepshteyn
Copy link
Contributor

Added IsAlternateEntry() and modified IsExternalProcedureDefinition() to also check for alternate entries.

(IsExternalProcedureDefinition() is called from CheckHelper::CheckGlobalName(), which checks for duplicate global symbols.)

Fixes #62778

@eugeneepshteyn eugeneepshteyn marked this pull request as ready for review September 3, 2025 01:18
// point to its subprogram.
const Symbol *GetMainEntry(const Symbol *);

inline bool IsAlternateEntry(const Symbol *symbol) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be more clear to implement these in the opposite way, I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean have IsAlternateEntry(&symbol) be primary and IsAlternateEntry(*symbol) call it? I started it that way, but because GetMainEntry() returns a pointer, it looked somewhat less clean.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you only have one call site, then you don't need both APIs (yet).

I have been slowing converting tools like this -- ones with reasonable results for absent (null) pointer arguments -- into pointer-only forms, as I run across hem.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I only left IsAlternateEntry() that accepts the pointer, because it still looks cleaner to me.

@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Sep 3, 2025
@llvmbot
Copy link
Member

llvmbot commented Sep 3, 2025

@llvm/pr-subscribers-flang-semantics

Author: Eugene Epshteyn (eugeneepshteyn)

Changes

Added IsAlternateEntry() and modified IsExternalProcedureDefinition() to also check for alternate entries.

(IsExternalProcedureDefinition() is called from CheckHelper::CheckGlobalName(), which checks for duplicate global symbols.)

Fixes #62778


Full diff: https://github.com/llvm/llvm-project/pull/156563.diff

3 Files Affected:

  • (modified) flang/include/flang/Evaluate/tools.h (+6)
  • (modified) flang/lib/Semantics/check-declarations.cpp (+1-1)
  • (modified) flang/test/Semantics/bind-c01.f90 (+8)
diff --git a/flang/include/flang/Evaluate/tools.h b/flang/include/flang/Evaluate/tools.h
index 225e1a77f041b..5f2f199e778c7 100644
--- a/flang/include/flang/Evaluate/tools.h
+++ b/flang/include/flang/Evaluate/tools.h
@@ -1531,6 +1531,12 @@ class Scope;
 // point to its subprogram.
 const Symbol *GetMainEntry(const Symbol *);
 
+inline bool IsAlternateEntry(const Symbol *symbol) {
+  // If symbol is not alternate entry symbol, GetMainEntry() returns the same
+  // symbol.
+  return symbol && GetMainEntry(symbol) != symbol;
+}
+
 // These functions are used in Evaluate so they are defined here rather than in
 // Semantics to avoid a link-time dependency on Semantics.
 // All of these apply GetUltimate() or ResolveAssociations() to their arguments.
diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp
index b9f5737468ff8..84edcebc64973 100644
--- a/flang/lib/Semantics/check-declarations.cpp
+++ b/flang/lib/Semantics/check-declarations.cpp
@@ -2950,7 +2950,7 @@ static bool IsSubprogramDefinition(const Symbol &symbol) {
 
 static bool IsExternalProcedureDefinition(const Symbol &symbol) {
   return IsBlockData(symbol) ||
-      (IsSubprogramDefinition(symbol) &&
+      ((IsSubprogramDefinition(symbol) || IsAlternateEntry(&symbol)) &&
           (IsExternal(symbol) || symbol.GetBindName()));
 }
 
diff --git a/flang/test/Semantics/bind-c01.f90 b/flang/test/Semantics/bind-c01.f90
index f0546b3eb068c..79d53677abc9d 100644
--- a/flang/test/Semantics/bind-c01.f90
+++ b/flang/test/Semantics/bind-c01.f90
@@ -29,3 +29,11 @@ subroutine foo() bind(c, name="x6")
 end subroutine
 subroutine foo() bind(c, name="x7")
 end subroutine
+
+subroutine entries()
+
+entry e1() bind(C, name="e")
+
+!ERROR: Two entities have the same global name 'e'
+entry e2() bind(C, name="e")
+end subroutine

@eugeneepshteyn eugeneepshteyn merged commit a34b110 into llvm:main Sep 3, 2025
9 checks passed
@eugeneepshteyn eugeneepshteyn deleted the fix-bindc-name branch September 3, 2025 23:22
ckoparkar added a commit to ckoparkar/llvm-project that referenced this pull request Sep 4, 2025
* main: (1483 commits)
  [clang] fix error recovery for invalid nested name specifiers (llvm#156772)
  Revert "[lldb] Add count for errors of DWO files in statistics and combine DWO file count functions" (llvm#156777)
  AMDGPU: Add agpr variants of multi-data DS instructions (llvm#156420)
  [libc][NFC] disable localtime on aarch64/baremetal (llvm#156776)
  [win/asan] Improve SharedReAlloc with HEAP_REALLOC_IN_PLACE_ONLY. (llvm#132558)
  [LLDB] Make internal shell the default for running LLDB lit tests. (llvm#156729)
  [lldb][debugserver] Max response size for qSpeedTest (llvm#156099)
  [AMDGPU] Define 1024 VGPRs on gfx1250 (llvm#156765)
  [flang] Check for BIND(C) name conflicts with alternate entries (llvm#156563)
  [RISCV] Add exhausted_gprs_fprs test to calling-conv-half.ll. NFC (llvm#156586)
  [NFC] Remove trailing whitespaces from `clang/include/clang/Basic/AttrDocs.td`
  [lldb] Mark scripted frames as synthetic instead of artificial (llvm#153117)
  [docs] Refine some of the wording in the quality developer policy (llvm#156555)
  [MLIR] Apply clang-tidy fixes for readability-identifier-naming in TransformOps.cpp (NFC)
  [MLIR] Add LDBG() tracing to VectorTransferOpTransforms.cpp (NFC)
  [NFC] Apply clang-format to PPCInstrFutureMMA.td (llvm#156749)
  [libc] implement template functions for localtime (llvm#110363)
  [llvm-objcopy][COFF] Update .symidx values after stripping (llvm#153322)
  Add documentation on debugging LLVM.
  [lldb] Add count for errors of DWO files in statistics and combine DWO file count functions (llvm#155023)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flang:semantics flang Flang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[flang] crash with "cannot process subprogram that was already processed"

3 participants