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

John Hui via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 23 18:50:18 PDT 2026


================
@@ -1072,6 +1073,69 @@ getAPINotesParameterSelectorCandidates(const Sema &S, const FunctionDecl *FD) {
   return Candidates;
 }
 
+static api_notes::APINotesFunctionSelectorKey
+getBroadAPINotesSelectorKey(api_notes::APINotesFunctionSelectorKey Key) {
+  Key.ParameterTypeIDs = std::nullopt;
+  return Key;
+}
+
+static APINotesSelectorDiagnosticReaderState &
+getAPINotesSelectorDiagnosticState(Sema &S, api_notes::APINotesReader *Reader) {
+  if (!S.APINotesSelectorDiagnostics)
+    S.APINotesSelectorDiagnostics =
+        std::make_unique<APINotesSelectorDiagnosticState>();
+  auto &State = S.APINotesSelectorDiagnostics->Readers[Reader];
+  if (State.Initialized)
+    return State;
+
+  State.Initialized = true;
----------------
j-hui wrote:

This seems unnecessary. If it's already in the `Readers` map, it should already be initialized, right?

Can you use something like `try_emplace` instead? That will return a `bool` that will tell you whether a new entry was created, means you need perform the initialization.

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


More information about the cfe-commits mailing list