Skip to content

Commit

Permalink
[flang] Make -fget-symbols-sources output deterministic
Browse files Browse the repository at this point in the history
The DumpSymbolsSources() routine ordered its output by the addresses
of the names of the symbols, and was susceptible to variation across
environments.  Fixed by using a multimap using the values of the names.

Differential Revision: https://reviews.llvm.org/D87035
  • Loading branch information
klausler committed Sep 2, 2020
1 parent 4f57a12 commit f80866b
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions flang/lib/Semantics/semantics.cpp
Expand Up @@ -45,17 +45,17 @@

namespace Fortran::semantics {

using NameToSymbolMap = std::map<const char *, SymbolRef>;
using NameToSymbolMap = std::multimap<parser::CharBlock, SymbolRef>;
static void DoDumpSymbols(llvm::raw_ostream &, const Scope &, int indent = 0);
static void PutIndent(llvm::raw_ostream &, int indent);

static void GetSymbolNames(const Scope &scope, NameToSymbolMap &symbols) {
// Finds all symbol names in the scope without collecting duplicates.
for (const auto &pair : scope) {
symbols.emplace(pair.second->name().begin(), *pair.second);
symbols.emplace(pair.second->name(), *pair.second);
}
for (const auto &pair : scope.commonBlocks()) {
symbols.emplace(pair.second->name().begin(), *pair.second);
symbols.emplace(pair.second->name(), *pair.second);
}
for (const auto &child : scope.children()) {
GetSymbolNames(child, symbols);
Expand Down
6 changes: 3 additions & 3 deletions flang/test/Semantics/getsymbols01.f90
Expand Up @@ -16,10 +16,10 @@ recursive pure function f() result(x)
end module

! RUN: %f18 -fget-symbols-sources -fparse-only %s 2>&1 | FileCheck %s
! CHECK-COUNT-1:f:{{.*}}getsymbols01.f90, 12, 26-27
! CHECK-COUNT-1:mm1:{{.*}}getsymbols01.f90, 2, 8-11
! CHECK-COUNT-1:s:{{.*}}getsymbols01.f90, 5, 18-19
! CHECK-COUNT-1:x:{{.*}}getsymbols01.f90, 5, 21-22
! CHECK-COUNT-1:y:{{.*}}getsymbols01.f90, 5, 24-25
! CHECK-COUNT-1:ss:{{.*}}getsymbols01.f90, 9, 19-21
! CHECK-COUNT-1:f:{{.*}}getsymbols01.f90, 12, 26-27
! CHECK-COUNT-1:x:{{.*}}getsymbols01.f90, 5, 21-22
! CHECK-COUNT-1:x:{{.*}}getsymbols01.f90, 13, 24-25
! CHECK-COUNT-1:y:{{.*}}getsymbols01.f90, 5, 24-25
2 changes: 1 addition & 1 deletion flang/test/Semantics/getsymbols02.f90
Expand Up @@ -10,5 +10,5 @@ PROGRAM helloworld
! RUN: %f18 -fparse-only %S/Inputs/getsymbols02-a.f90
! RUN: %f18 -fparse-only %S/Inputs/getsymbols02-b.f90
! RUN: %f18 -fget-symbols-sources -fparse-only %s 2>&1 | FileCheck %s
! CHECK: get5: mm2a
! CHECK: callget5: mm2b
! CHECK: get5: mm2a
2 changes: 1 addition & 1 deletion flang/test/Semantics/getsymbols03-a.f90
Expand Up @@ -8,7 +8,7 @@ program main
end program

! RUN: %f18 -fget-symbols-sources -fparse-only %s 2>&1 | FileCheck %s
! CHECK:mm3:{{.*}}getsymbols03-b.f90, 1, 8-11
! CHECK:f:{{.*}}getsymbols03-b.f90, 2, 12-13
! CHECK:main:{{.*}}getsymbols03-a.f90, 4, 9-13
! CHECK:mm3:{{.*}}getsymbols03-b.f90, 1, 8-11
! CHECK:x:{{.*}}getsymbols03-a.f90, 6, 13-14
2 changes: 1 addition & 1 deletion flang/test/Semantics/getsymbols04.f90
Expand Up @@ -8,5 +8,5 @@ program main

! RUN: %f18 -fget-symbols-sources -fparse-only %s 2>&1 | FileCheck %s
! CHECK:x:{{.*}}getsymbols04.f90, 3, 14-15
! CHECK:y:{{.*}}getsymbols04.f90, 4, 14-15
! CHECK:x:{{.*}}getsymbols04.f90, 5, 11-12
! CHECK:y:{{.*}}getsymbols04.f90, 4, 14-15
2 changes: 1 addition & 1 deletion flang/test/Semantics/getsymbols05.f90
Expand Up @@ -11,5 +11,5 @@ program main

! RUN: %f18 -fget-symbols-sources -fparse-only %s 2>&1 | FileCheck %s
! CHECK:x:{{.*}}getsymbols05.f90, 3, 14-15
! CHECK:y:{{.*}}getsymbols05.f90, 4, 14-15
! CHECK:x:{{.*}}getsymbols05.f90, 6, 16-17
! CHECK:y:{{.*}}getsymbols05.f90, 4, 14-15

0 comments on commit f80866b

Please sign in to comment.