-
Notifications
You must be signed in to change notification settings - Fork 14.8k
[flang] Check for BIND(C) name conflicts with alternate entries #156563
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Add a check for alternate entries to CheckHelper::CheckGlobalName(). Fixes llvm#62778
Instead, added IsAlternateEntry() and modified IsExternalProcedureDefinition().
// point to its subprogram. | ||
const Symbol *GetMainEntry(const Symbol *); | ||
|
||
inline bool IsAlternateEntry(const Symbol *symbol) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@llvm/pr-subscribers-flang-semantics Author: Eugene Epshteyn (eugeneepshteyn) ChangesAdded 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:
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
|
* 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) ...
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