diff options
author | Egor Zhdan <e_zhdan@apple.com> | 2024-01-17 13:13:10 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-17 13:13:10 +0000 |
commit | 77d21e758ea9665631b211abc0e424d7a7c44989 (patch) | |
tree | ebdc29cd47dabfd609b594d509737c352af54acf /clang/lib/Sema/SemaDecl.cpp | |
parent | 9791e5414960f92396582b9e9ee503ac15799312 (diff) | |
download | llvm-77d21e758ea9665631b211abc0e424d7a7c44989.zip llvm-77d21e758ea9665631b211abc0e424d7a7c44989.tar.gz llvm-77d21e758ea9665631b211abc0e424d7a7c44989.tar.bz2 |
[APINotes] Upstream dependencies of Sema logic to apply API Notes to decls
This upstreams more of the Clang API Notes functionality that is
currently implemented in the Apple fork:
https://github.com/apple/llvm-project/tree/next/clang/lib/APINotes
This is the largest chunk of the API Notes functionality in the
upstreaming process. I will soon submit a follow-up patch to actually
enable usage of this functionality by having a Clang driver flag that
enables API Notes, along with tests.
Diffstat (limited to 'clang/lib/Sema/SemaDecl.cpp')
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index b74ff0b..9e6e4ab 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -15205,6 +15205,37 @@ void Sema::DiagnoseSizeOfParametersAndReturnValue( } } +QualType Sema::AdjustParameterTypeForObjCAutoRefCount(QualType T, + SourceLocation NameLoc, + TypeSourceInfo *TSInfo) { + // In ARC, infer a lifetime qualifier for appropriate parameter types. + if (!getLangOpts().ObjCAutoRefCount || + T.getObjCLifetime() != Qualifiers::OCL_None || !T->isObjCLifetimeType()) + return T; + + Qualifiers::ObjCLifetime Lifetime; + + // Special cases for arrays: + // - if it's const, use __unsafe_unretained + // - otherwise, it's an error + if (T->isArrayType()) { + if (!T.isConstQualified()) { + if (DelayedDiagnostics.shouldDelayDiagnostics()) + DelayedDiagnostics.add(sema::DelayedDiagnostic::makeForbiddenType( + NameLoc, diag::err_arc_array_param_no_ownership, T, false)); + else + Diag(NameLoc, diag::err_arc_array_param_no_ownership) + << TSInfo->getTypeLoc().getSourceRange(); + } + Lifetime = Qualifiers::OCL_ExplicitNone; + } else { + Lifetime = T->getObjCARCImplicitLifetime(); + } + T = Context.getLifetimeQualifiedType(T, Lifetime); + + return T; +} + ParmVarDecl *Sema::CheckParameter(DeclContext *DC, SourceLocation StartLoc, SourceLocation NameLoc, IdentifierInfo *Name, QualType T, TypeSourceInfo *TSInfo, |