diff options
author | Tulio Magno Quites Machado Filho <tuliom@redhat.com> | 2023-11-24 09:17:21 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-24 09:17:21 -0300 |
commit | cf1bde33423da5eb9b7dc95daac4aada3167de3c (patch) | |
tree | 68ce5ea455446f6c971b173654cfcbdabfb39728 /clang/lib/Lex/ModuleMap.cpp | |
parent | a4ee55fe6ea088f55bf44236bd05f6a847a3de6c (diff) | |
download | llvm-cf1bde33423da5eb9b7dc95daac4aada3167de3c.zip llvm-cf1bde33423da5eb9b7dc95daac4aada3167de3c.tar.gz llvm-cf1bde33423da5eb9b7dc95daac4aada3167de3c.tar.bz2 |
[clang] Fix sorting module headers (#73146)
Struct Module::Header is not a POD type. As such, qsort() and
llvm::array_pod_sort() must not be used to sort it. This became an issue
with the new implementation of qsort() in glibc 2.39 that is not
guaranteed to be a stable sort, causing Headers to be re-ordered and
corrupted.
Replace the usage of llvm::array_pod_sort() with std::stable_sort() in
order to fix this issue. The signature of compareModuleHeaders() has to
be modified.
Fixes #73145.
Diffstat (limited to 'clang/lib/Lex/ModuleMap.cpp')
-rw-r--r-- | clang/lib/Lex/ModuleMap.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp index 00e13c9..1d67e27 100644 --- a/clang/lib/Lex/ModuleMap.cpp +++ b/clang/lib/Lex/ModuleMap.cpp @@ -2509,9 +2509,9 @@ void ModuleMapParser::parseHeaderDecl(MMToken::TokenKind LeadingToken, << FixItHint::CreateReplacement(CurrModuleDeclLoc, "framework module"); } -static int compareModuleHeaders(const Module::Header *A, - const Module::Header *B) { - return A->NameAsWritten.compare(B->NameAsWritten); +static bool compareModuleHeaders(const Module::Header &A, + const Module::Header &B) { + return A.NameAsWritten < B.NameAsWritten; } /// Parse an umbrella directory declaration. @@ -2574,7 +2574,7 @@ void ModuleMapParser::parseUmbrellaDirDecl(SourceLocation UmbrellaLoc) { } // Sort header paths so that the pcm doesn't depend on iteration order. - llvm::array_pod_sort(Headers.begin(), Headers.end(), compareModuleHeaders); + std::stable_sort(Headers.begin(), Headers.end(), compareModuleHeaders); for (auto &Header : Headers) Map.addHeader(ActiveModule, std::move(Header), ModuleMap::TextualHeader); |