[clang] [APINotes] Match function-like Where.Parameters in Sema (PR #205307)
John Hui via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 6 00:11:04 PDT 2026
================
@@ -993,6 +993,87 @@ UnwindTagContext(TagDecl *DC, api_notes::APINotesManager &APINotes) {
return std::nullopt;
}
+static void stripAPINotesParameterNullability(QualType &ParamType) {
+ while (true) {
+ if (!AttributedType::stripOuterNullability(ParamType))
+ return;
+ }
+}
+
+// Print the APINotes selector spelling for one parameter. The source-spelled
+// selector is tried first. The desugared spelling is only a permissive
+// fallback.
+static std::string getAPINotesParameterSelectorSpelling(
+ QualType ParamType, const ASTContext &Context, const PrintingPolicy &Policy,
+ bool Desugar) {
+ ParamType.removeLocalConst();
+ stripAPINotesParameterNullability(ParamType);
+
+ if (Desugar) {
+ ParamType = ParamType.getDesugaredType(Context);
+ ParamType.removeLocalConst();
+ stripAPINotesParameterNullability(ParamType);
+ }
+
+ return ParamType.getAsString(Policy);
+}
+
+static std::optional<SmallVector<SmallVector<std::string, 4>, 2>>
+getAPINotesParameterSelectorCandidates(const Sema &S, const FunctionDecl *FD) {
+ const auto *FPT = FD->getType()->getAs<FunctionProtoType>();
+ if (!FPT)
+ return std::nullopt;
+
+ SmallVector<std::string, 4> SourceParameters;
+ SmallVector<std::string, 4> DesugaredParameters;
+ SourceParameters.reserve(FPT->getNumParams());
+ DesugaredParameters.reserve(FPT->getNumParams());
+
+ const PrintingPolicy &Policy = S.Context.getPrintingPolicy();
----------------
j-hui wrote:
I'm fine with this being done on the basis of string comparisons for now!
We can talk more about whether we should be passing around strings vs `QualType`s when we meet next. Doing so may reduce the amount you have to copy around string vectors and perform (potentially fragile) string normalization, but that might not be a good trade-off if it comes at the cost of needing to repeatedly print a `QualType` into a string to do the comparison. The trade-off might not become clear until later, so no need to do any premature optimizations in this PR (:
https://github.com/llvm/llvm-project/pull/205307
More information about the cfe-commits
mailing list