[clang] [APINotes] Fix a few accidental refactoring artifacts (PR #83057)
Egor Zhdan via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 26 12:51:55 PST 2024
https://github.com/egorzhdan created https://github.com/llvm/llvm-project/pull/83057
This fixes a few breakages introduced during upstreaming – please see each commit for details.
>From dae96657bee753a96bc41e8cde3ca81e082d82cb Mon Sep 17 00:00:00 2001
From: Egor Zhdan <e_zhdan at apple.com>
Date: Mon, 26 Feb 2024 20:46:39 +0000
Subject: [PATCH 1/4] [APINotes] Fix accidental refactoring artifact
The assertion needs to happen after the read operation.
---
clang/lib/APINotes/APINotesReader.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/lib/APINotes/APINotesReader.cpp b/clang/lib/APINotes/APINotesReader.cpp
index ff9b95d9bf75e3..36f5c2931b7d9f 100644
--- a/clang/lib/APINotes/APINotesReader.cpp
+++ b/clang/lib/APINotes/APINotesReader.cpp
@@ -81,9 +81,9 @@ class VersionedTableInfo {
auto version = ReadVersionTuple(Data);
const auto *DataBefore = Data;
(void)DataBefore;
+ auto UnversionedData = Derived::readUnversioned(Key, Data);
assert(Data != DataBefore &&
"Unversioned data reader didn't move pointer");
- auto UnversionedData = Derived::readUnversioned(Key, Data);
Result.push_back({version, UnversionedData});
}
return Result;
>From c08b72c3534310b3ddaefddccfc5a64f0829ee6e Mon Sep 17 00:00:00 2001
From: Egor Zhdan <e_zhdan at apple.com>
Date: Mon, 26 Feb 2024 20:47:43 +0000
Subject: [PATCH 2/4] [APINotes] Fix hashing of a string
`llvm::hash_value` of a `StringRef` hashes the pointer, not the string.
---
clang/lib/APINotes/APINotesReader.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/lib/APINotes/APINotesReader.cpp b/clang/lib/APINotes/APINotesReader.cpp
index 36f5c2931b7d9f..1364dc5acd3706 100644
--- a/clang/lib/APINotes/APINotesReader.cpp
+++ b/clang/lib/APINotes/APINotesReader.cpp
@@ -148,7 +148,7 @@ class IdentifierTableInfo {
external_key_type GetExternalKey(internal_key_type Key) { return Key; }
hash_value_type ComputeHash(internal_key_type Key) {
- return llvm::hash_value(Key);
+ return llvm::djbHash(Key);
}
static bool EqualKey(internal_key_type LHS, internal_key_type RHS) {
>From e8ee95ab96e437f73a1557dcface7760d5a697e5 Mon Sep 17 00:00:00 2001
From: Egor Zhdan <e_zhdan at apple.com>
Date: Mon, 26 Feb 2024 20:48:57 +0000
Subject: [PATCH 3/4] [APINotes] Do not use a moved-from value
`Results` was being moved and then used.
---
clang/lib/APINotes/APINotesReader.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/clang/lib/APINotes/APINotesReader.cpp b/clang/lib/APINotes/APINotesReader.cpp
index 1364dc5acd3706..55ea4bae81e6e8 100644
--- a/clang/lib/APINotes/APINotesReader.cpp
+++ b/clang/lib/APINotes/APINotesReader.cpp
@@ -1797,8 +1797,8 @@ APINotesReader::Create(std::unique_ptr<llvm::MemoryBuffer> InputBuffer,
template <typename T>
APINotesReader::VersionedInfo<T>::VersionedInfo(
llvm::VersionTuple Version,
- llvm::SmallVector<std::pair<llvm::VersionTuple, T>, 1> Results)
- : Results(std::move(Results)) {
+ llvm::SmallVector<std::pair<llvm::VersionTuple, T>, 1> R)
+ : Results(std::move(R)) {
assert(!Results.empty());
assert(std::is_sorted(
>From 76098becdbda1c1903592c160dbb0fc505ed31e3 Mon Sep 17 00:00:00 2001
From: Egor Zhdan <e_zhdan at apple.com>
Date: Mon, 26 Feb 2024 20:50:01 +0000
Subject: [PATCH 4/4] [APINotes] Populate `StoredObjCSelector` properly
---
clang/lib/APINotes/APINotesWriter.cpp | 1 +
1 file changed, 1 insertion(+)
diff --git a/clang/lib/APINotes/APINotesWriter.cpp b/clang/lib/APINotes/APINotesWriter.cpp
index 62a2ab1799913a..76fd24ccfae984 100644
--- a/clang/lib/APINotes/APINotesWriter.cpp
+++ b/clang/lib/APINotes/APINotesWriter.cpp
@@ -128,6 +128,7 @@ class APINotesWriter::Implementation {
SelectorID getSelector(ObjCSelectorRef SelectorRef) {
// Translate the selector reference into a stored selector.
StoredObjCSelector Selector;
+ Selector.NumArgs = SelectorRef.NumArgs;
Selector.Identifiers.reserve(SelectorRef.Identifiers.size());
for (auto piece : SelectorRef.Identifiers)
Selector.Identifiers.push_back(getIdentifier(piece));
More information about the cfe-commits
mailing list