[clang] [APINotes] Match function-like Where.Parameters in Sema (PR #205307)
Gábor Horváth via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 6 03:27:08 PDT 2026
================
@@ -993,6 +993,119 @@ UnwindTagContext(TagDecl *DC, api_notes::APINotesManager &APINotes) {
return std::nullopt;
}
+static void stripAPINotesParameterNullability(QualType &ParamType) {
+ while (true) {
+ if (!AttributedType::stripOuterNullability(ParamType))
+ return;
+ }
+}
+
+struct APINotesParameterSelector {
+ SmallVector<std::string, 4> Parameters;
+
+ SmallVector<StringRef, 4> getParameterRefs() const {
+ SmallVector<StringRef, 4> Refs;
+ Refs.reserve(Parameters.size());
+ for (const std::string &Parameter : Parameters)
+ Refs.push_back(Parameter);
+ return Refs;
+ }
+
+ bool operator==(const APINotesParameterSelector &Other) const {
+ return Parameters == Other.Parameters;
+ }
+};
+
+struct APINotesParameterSelectorCandidates {
+ APINotesParameterSelector Source;
+ std::optional<APINotesParameterSelector> Desugared;
+};
+
+static PrintingPolicy
+getAPINotesParameterSelectorPrintingPolicy(const ASTContext &Context) {
+ PrintingPolicy Policy(Context.getLangOpts());
+ Policy.PrintAsCanonical = false;
+ Policy.FullyQualifiedName = false;
+ Policy.SuppressScope = false;
+ Policy.UsePreferredNames = false;
+ Policy.MSVCFormatting = false;
+ Policy.SplitTemplateClosers = false;
+ Policy.IncludeNewlines = false;
+ return Policy;
+}
+
+// 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);
----------------
Xazax-hun wrote:
Do we need to do the stripping twice or could this be:
```
if (Desugar)
ParamType = ParamType.getDesugaredType(Context);
ParamType.removeLocalConst();
stripAPINotesParameterNullability(ParamType);
```
https://github.com/llvm/llvm-project/pull/205307
More information about the cfe-commits
mailing list