[flang-commits] [flang] [flang] Main program symbol no longer conflicts with the other symbols (PR #149169)

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Wed Jul 16 12:49:21 PDT 2025


================
@@ -489,15 +489,32 @@ class ParseTreeAnalyzer {
 
   // C1401
   void Post(const parser::MainProgram &mainProgram) {
-    if (const parser::CharBlock *
-        endName{GetStmtName(std::get<parser::Statement<parser::EndProgramStmt>>(
-            mainProgram.t))}) {
-      if (const auto &program{
-              std::get<std::optional<parser::Statement<parser::ProgramStmt>>>(
-                  mainProgram.t)}) {
-        if (*endName != program->statement.v.source) {
+    // Uppercase the name of the main program, so that its symbol name
+    // would be unique from similarly named non-main-program symbols.
+    auto upperCaseCharBlock = [](const parser::CharBlock &cb) {
+      char *ch = const_cast<char *>(cb.begin());
+      char *endCh = ch + cb.size();
+      while (ch != endCh) {
+        *ch++ = parser::ToUpperCaseLetter(*ch);
+      }
+    };
+    const parser::CharBlock *progName{nullptr};
+    if (const auto &program{
+            std::get<std::optional<parser::Statement<parser::ProgramStmt>>>(
+                mainProgram.t)}) {
+      progName = &program->statement.v.source;
+    }
+    if (progName) {
+      upperCaseCharBlock(*progName);
+    }
+    const parser::CharBlock *endName{GetStmtName(
+        std::get<parser::Statement<parser::EndProgramStmt>>(mainProgram.t))};
+    if (endName) {
----------------
klausler wrote:

these two `if` statements could each be combined with the preceding local variable declarations.

https://github.com/llvm/llvm-project/pull/149169


More information about the flang-commits mailing list