[flang-commits] [flang] [flang] NameUniquer helper for detecting module-scope data (PR #192733)

Eugene Epshteyn via flang-commits flang-commits at lists.llvm.org
Sun Apr 19 08:01:01 PDT 2026


================
@@ -347,6 +347,29 @@ bool fir::NameUniquer::belongsToModule(llvm::StringRef uniquedName,
          result.second.modules[0] == moduleName;
 }
 
+/// Flang records the lexical module/submodule nesting of a symbol in the
----------------
eugeneepshteyn wrote:

AI reviewer suggested to add a unit test to `flang/unittests/Optimizer/InternalNamesTest.cpp`:
```
TEST(InternalNamesTest, isModuleScopeDataUniquedName) {
  // True cases: module-scope variable, constant, common block
  ASSERT_TRUE(NameUniquer::isModuleScopeDataUniquedName("_QMmodEintvar"));
  ASSERT_TRUE(NameUniquer::isModuleScopeDataUniquedName("_QMmodECpi"));
  ASSERT_TRUE(NameUniquer::isModuleScopeDataUniquedName("_QMmodSsubEvar"));

  // False cases: procedure inside module, derived type, non-uniqued name,
  //              unqualified common block (no module), and — the bug case —
  //              a saved local in a module procedure.
  ASSERT_FALSE(NameUniquer::isModuleScopeDataUniquedName("_QMmodPsub"));
  ASSERT_FALSE(NameUniquer::isModuleScopeDataUniquedName("_QMmodTmytype"));
  ASSERT_FALSE(NameUniquer::isModuleScopeDataUniquedName("_QCblk"));      // no module
  ASSERT_FALSE(NameUniquer::isModuleScopeDataUniquedName("someExternalName"));
  ASSERT_FALSE(NameUniquer::isModuleScopeDataUniquedName(""));
  ASSERT_FALSE(NameUniquer::isModuleScopeDataUniquedName("_QMmFfooEx"));  // saved local in module procedure
}
```

Question: what is this function supposed to return for `x`?
```
module m
contains
    subroutine foo()
      integer, save :: x ! <-- SAVE
    end subroutine
end
```

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


More information about the flang-commits mailing list