aboutsummaryrefslogtreecommitdiff
path: root/flang/lib/Semantics/program-tree.cpp
diff options
context:
space:
mode:
authorPeter Klausler <pklausler@nvidia.com>2022-04-22 14:06:54 -0700
committerPeter Klausler <pklausler@nvidia.com>2022-04-25 09:25:44 -0700
commit72904a990c4d215a617ca77977babbeb45fc36dc (patch)
tree40d7efff2806aea7583e096cf5a08d11c983deda /flang/lib/Semantics/program-tree.cpp
parent149d3e4365325fdb9b79a4d0e3f88a2c84e0baaf (diff)
downloadllvm-72904a990c4d215a617ca77977babbeb45fc36dc.zip
llvm-72904a990c4d215a617ca77977babbeb45fc36dc.tar.gz
llvm-72904a990c4d215a617ca77977babbeb45fc36dc.tar.bz2
[flang] Avoid global name conflict when BIND(C,NAME=) is used
At the top level of program units in a source file, two subprograms are allowed to have the same name if at least one of them has a distinct interoperable binding name. F18's symbol table requires (most) symbols in a scope to have distinct names, though. Solve by using compiler-created names for the symbols of global scope subprograms that have interoperable binding names. Differential Revision: https://reviews.llvm.org/D124295
Diffstat (limited to 'flang/lib/Semantics/program-tree.cpp')
-rw-r--r--flang/lib/Semantics/program-tree.cpp22
1 files changed, 20 insertions, 2 deletions
diff --git a/flang/lib/Semantics/program-tree.cpp b/flang/lib/Semantics/program-tree.cpp
index e96a6c4..79b4738 100644
--- a/flang/lib/Semantics/program-tree.cpp
+++ b/flang/lib/Semantics/program-tree.cpp
@@ -137,14 +137,32 @@ ProgramTree ProgramTree::Build(const parser::FunctionSubprogram &x) {
const auto &stmt{std::get<parser::Statement<parser::FunctionStmt>>(x.t)};
const auto &end{std::get<parser::Statement<parser::EndFunctionStmt>>(x.t)};
const auto &name{std::get<parser::Name>(stmt.statement.t)};
- return BuildSubprogramTree(name, x).set_stmt(stmt).set_endStmt(end);
+ const parser::LanguageBindingSpec *bindingSpec{};
+ if (const auto &suffix{
+ std::get<std::optional<parser::Suffix>>(stmt.statement.t)}) {
+ if (suffix->binding) {
+ bindingSpec = &*suffix->binding;
+ }
+ }
+ return BuildSubprogramTree(name, x)
+ .set_stmt(stmt)
+ .set_endStmt(end)
+ .set_bindingSpec(bindingSpec);
}
ProgramTree ProgramTree::Build(const parser::SubroutineSubprogram &x) {
const auto &stmt{std::get<parser::Statement<parser::SubroutineStmt>>(x.t)};
const auto &end{std::get<parser::Statement<parser::EndSubroutineStmt>>(x.t)};
const auto &name{std::get<parser::Name>(stmt.statement.t)};
- return BuildSubprogramTree(name, x).set_stmt(stmt).set_endStmt(end);
+ const parser::LanguageBindingSpec *bindingSpec{};
+ if (const auto &binding{std::get<std::optional<parser::LanguageBindingSpec>>(
+ stmt.statement.t)}) {
+ bindingSpec = &*binding;
+ }
+ return BuildSubprogramTree(name, x)
+ .set_stmt(stmt)
+ .set_endStmt(end)
+ .set_bindingSpec(bindingSpec);
}
ProgramTree ProgramTree::Build(const parser::SeparateModuleSubprogram &x) {