[clang] [APINotes] Diagnose invalid Where.Parameters selectors (PR #209408)

via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 22 02:13:19 PDT 2026


================
@@ -893,6 +911,80 @@ APINotesReader::Implementation::getIdentifier(llvm::StringRef Str) {
   return *Known;
 }
 
+std::optional<llvm::StringRef>
+APINotesReader::Implementation::getIdentifierString(IdentifierID ID) {
+  if (!IdentifierTable)
+    return std::nullopt;
+
+  if (ID == IdentifierID(0))
+    return llvm::StringRef();
+
+  if (!IdentifierStringsInitialized) {
+    IdentifierStringsInitialized = true;
+    // keys() and data() iterate over the same serialized entries in lockstep,
+    // so build the reverse cache without doing a lookup for each key.
+    auto Identifiers = IdentifierTable->keys();
+    auto IDs = IdentifierTable->data();
+    auto Identifier = Identifiers.begin();
+    auto KnownID = IDs.begin();
+    auto IdentifierEnd = Identifiers.end();
+    auto KnownIDEnd = IDs.end();
+    for (; Identifier != IdentifierEnd && KnownID != KnownIDEnd;
+         ++Identifier, ++KnownID) {
+      unsigned Index = static_cast<unsigned>(*KnownID);
+      if (IdentifierStrings.size() <= Index)
+        IdentifierStrings.resize(Index + 1);
+      IdentifierStrings[Index] = *Identifier;
+    }
+  }
+
+  unsigned Index = static_cast<unsigned>(ID);
+  if (Index >= IdentifierStrings.size())
+    return std::nullopt;
+  return IdentifierStrings[Index];
+}
+
+static APINotesFunctionSelectorKey
----------------
StoeckOverflow wrote:

Agreed, this would be a nicer shape if `FunctionTableKey` is the selector key we want to share across the reader/Sema boundary. I kept `FunctionTableKey` local to `APINotesFormat.h` because it currently reads as the private binary table key, and introduced `APINotesFunctionSelectorKey` as the smaller reader-facing
diagnostic identity.

But I agree that duplicating the fields is not ideal. If you think
`FunctionTableKey` should be promoted to the shared APINotes selector-key type, I can make that change and wrap it here as suggested.

https://github.com/llvm/llvm-project/pull/209408


More information about the cfe-commits mailing list