Skip to content

Commit f7cc4e8

Browse files
[flang] Attempt to address main program symbol conflicts
... by making main program symbol names upper case.
1 parent 1487084 commit f7cc4e8

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

flang/lib/Semantics/resolve-labels.cpp

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -489,15 +489,33 @@ class ParseTreeAnalyzer {
489489

490490
// C1401
491491
void Post(const parser::MainProgram &mainProgram) {
492-
if (const parser::CharBlock *
492+
// Uppercase the name of the main program, so that its symbol name
493+
// would be unique from similarly named non-main-program symbols.
494+
auto upperCaseCharBlock = [](const parser::CharBlock& cb) {
495+
char* ch = const_cast<char*>(cb.begin());
496+
char* endCh = ch + cb.size();
497+
while (ch != endCh) {
498+
*ch++ = parser::ToUpperCaseLetter(*ch);
499+
}
500+
};
501+
const parser::CharBlock *progName{nullptr};
502+
if (const auto &program{
503+
std::get<std::optional<parser::Statement<parser::ProgramStmt>>>(
504+
mainProgram.t)}) {
505+
progName = &program->statement.v.source;
506+
}
507+
if (progName) {
508+
upperCaseCharBlock(*progName);
509+
}
510+
const parser::CharBlock *
493511
endName{GetStmtName(std::get<parser::Statement<parser::EndProgramStmt>>(
494-
mainProgram.t))}) {
495-
if (const auto &program{
496-
std::get<std::optional<parser::Statement<parser::ProgramStmt>>>(
497-
mainProgram.t)}) {
498-
if (*endName != program->statement.v.source) {
512+
mainProgram.t))};
513+
if (endName) {
514+
upperCaseCharBlock(*endName);
515+
if (progName) {
516+
if (*endName != *progName) {
499517
context_.Say(*endName, "END PROGRAM name mismatch"_err_en_US)
500-
.Attach(program->statement.v.source, "should be"_en_US);
518+
.Attach(*progName, "should be"_en_US);
501519
}
502520
} else {
503521
context_.Say(*endName,

0 commit comments

Comments
 (0)