Skip to content

Commit

Permalink
[AIX][TOC] -mtocdata/-mno-tocdata fix non deterministic iteration ord…
Browse files Browse the repository at this point in the history
…er (#86840)

Failure with testcase toc-conf.c observed when building with
LLVM_REVERSE_ITERATION=ON.
Changing from using llvm::StringSet to std::set<llvm:StringRef> to
ensure iteration order is deterministic. Note: the functionality of the
feature does not require a specific iteration order, however, this will
allow testing to be consistent.
From llvm docs:
The advantages of std::set are that its iterators are stable (deleting
or inserting an element from the set does not affect iterators or
pointers to other elements) and that iteration over the set is
guaranteed to be in sorted order.
  • Loading branch information
syzaara committed Mar 28, 2024
1 parent a042fcb commit 4ddd4ed
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions clang/lib/Driver/ToolChains/AIX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ static void addTocDataOptions(const llvm::opt::ArgList &Args,
// the global setting of tocdata in TOCDataGloballyinEffect.
// Those that have the opposite setting to TOCDataGloballyinEffect, are added
// to ExplicitlySpecifiedGlobals.
llvm::StringSet<> ExplicitlySpecifiedGlobals;
std::set<llvm::StringRef> ExplicitlySpecifiedGlobals;
for (const auto Arg :
Args.filtered(options::OPT_mtocdata_EQ, options::OPT_mno_tocdata_EQ)) {
TOCDataSetting ArgTocDataSetting =
Expand All @@ -486,7 +486,7 @@ static void addTocDataOptions(const llvm::opt::ArgList &Args,
ExplicitlySpecifiedGlobals.erase(Val);
}

auto buildExceptionList = [](const llvm::StringSet<> &ExplicitValues,
auto buildExceptionList = [](const std::set<llvm::StringRef> &ExplicitValues,
const char *OptionSpelling) {
std::string Option(OptionSpelling);
bool IsFirst = true;
Expand All @@ -495,7 +495,7 @@ static void addTocDataOptions(const llvm::opt::ArgList &Args,
Option += ",";

IsFirst = false;
Option += E.first();
Option += E.str();
}
return Option;
};
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Driver/toc-conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void func() {

// CHECK-CONF1-NOT: warning:
// CHECK-CONF1: "-cc1"{{.*}}" "-mno-tocdata"
// CHECK-CONF1: "-mtocdata=g2,g1"
// CHECK-CONF1: "-mtocdata=g1,g2"

// CHECK-CONF2-NOT: warning:
// CHECK-CONF2: "-cc1"{{.*}}" "-mtocdata"
Expand Down

0 comments on commit 4ddd4ed

Please sign in to comment.