aboutsummaryrefslogtreecommitdiff
path: root/flang/lib/Semantics/mod-file.cpp
diff options
context:
space:
mode:
authorIƱaki Amatria Barral <140811900+inaki-amatria@users.noreply.github.com>2025-02-26 18:19:02 +0100
committerGitHub <noreply@github.com>2025-02-26 18:19:02 +0100
commit722c7c0b0f9a3f74cb6755fa40d9b88e77d79495 (patch)
treeaa7813047c656f5dab10a6a891131231e1345304 /flang/lib/Semantics/mod-file.cpp
parent7717a549e91c4fb554b78fce38e75b0147fb6cac (diff)
downloadllvm-722c7c0b0f9a3f74cb6755fa40d9b88e77d79495.zip
llvm-722c7c0b0f9a3f74cb6755fa40d9b88e77d79495.tar.gz
llvm-722c7c0b0f9a3f74cb6755fa40d9b88e77d79495.tar.bz2
[flang][Semantics] Ensure deterministic mod file output (#128655)
This PR adds a test to ensure deterministic ordering in `.mod` files. It also includes related changes to prevent non-deterministic symbol ordering caused by pointers outside the cooked source. This issue is particularly noticeable when using Flang as a library and compiling the same files multiple times.
Diffstat (limited to 'flang/lib/Semantics/mod-file.cpp')
-rw-r--r--flang/lib/Semantics/mod-file.cpp21
1 files changed, 2 insertions, 19 deletions
diff --git a/flang/lib/Semantics/mod-file.cpp b/flang/lib/Semantics/mod-file.cpp
index bef934b..82c43d9 100644
--- a/flang/lib/Semantics/mod-file.cpp
+++ b/flang/lib/Semantics/mod-file.cpp
@@ -836,18 +836,6 @@ void ModFileWriter::PutUseExtraAttr(
}
}
-static inline SourceName NameInModuleFile(const Symbol &symbol) {
- if (const auto *use{symbol.detailsIf<UseDetails>()}) {
- if (use->symbol().attrs().test(Attr::PRIVATE)) {
- // Avoid the use in sorting of names created to access private
- // specific procedures as a result of generic resolution;
- // they're not in the cooked source.
- return use->symbol().name();
- }
- }
- return symbol.name();
-}
-
// Collect the symbols of this scope sorted by their original order, not name.
// Generics and namelists are exceptions: they are sorted after other symbols.
void CollectSymbols(const Scope &scope, SymbolVector &sorted,
@@ -882,13 +870,8 @@ void CollectSymbols(const Scope &scope, SymbolVector &sorted,
sorted.push_back(symbol);
}
}
- // Sort most symbols by name: use of Symbol::ReplaceName ensures the source
- // location of a symbol's name is the first "real" use.
- auto sorter{[](SymbolRef x, SymbolRef y) {
- return NameInModuleFile(*x).begin() < NameInModuleFile(*y).begin();
- }};
- std::sort(sorted.begin(), sorted.end(), sorter);
- std::sort(generics.begin(), generics.end(), sorter);
+ std::sort(sorted.begin(), sorted.end(), SymbolSourcePositionCompare{});
+ std::sort(generics.begin(), generics.end(), SymbolSourcePositionCompare{});
sorted.insert(sorted.end(), generics.begin(), generics.end());
sorted.insert(sorted.end(), namelist.begin(), namelist.end());
for (const auto &pair : scope.commonBlocks()) {