diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-11-07 18:40:29 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-11-07 18:40:29 +0000 |
commit | e80d4f228c8d0d42cd9a85d461f01d96c14f4137 (patch) | |
tree | f1844530f923dc0debbc78a73fa51190e7212b17 /clang/lib/ARCMigrate/TransGCAttrs.cpp | |
parent | fed29142bad78baf6034e01d1843c16e89cdbc1a (diff) | |
download | bcm5719-llvm-e80d4f228c8d0d42cd9a85d461f01d96c14f4137.tar.gz bcm5719-llvm-e80d4f228c8d0d42cd9a85d461f01d96c14f4137.zip |
[arcmt] In GC, change '__weak' -> '__unsafe_unretained' when applied
to objects of classes that don't support ARC weak
llvm-svn: 143976
Diffstat (limited to 'clang/lib/ARCMigrate/TransGCAttrs.cpp')
-rw-r--r-- | clang/lib/ARCMigrate/TransGCAttrs.cpp | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/clang/lib/ARCMigrate/TransGCAttrs.cpp b/clang/lib/ARCMigrate/TransGCAttrs.cpp index 79dc0538b69..94eb8781dfe 100644 --- a/clang/lib/ARCMigrate/TransGCAttrs.cpp +++ b/clang/lib/ARCMigrate/TransGCAttrs.cpp @@ -12,6 +12,7 @@ #include "clang/Lex/Lexer.h" #include "clang/Basic/SourceManager.h" #include "clang/Analysis/Support/SaveAndRestore.h" +#include "clang/Sema/SemaDiagnostic.h" using namespace clang; using namespace arcmt; @@ -81,6 +82,8 @@ public: ASTContext &Ctx = MigrateCtx.Pass.Ctx; SourceManager &SM = Ctx.getSourceManager(); + if (Loc.isMacroID()) + Loc = SM.getImmediateExpansionRange(Loc).first; llvm::SmallString<32> Buf; bool Invalid = false; StringRef Spell = Lexer::getSpelling( @@ -101,7 +104,7 @@ public: MigrationContext::GCAttrOccurrence &Attr = MigrateCtx.GCAttrs.back(); Attr.Kind = Kind; - Attr.Loc = SM.getImmediateExpansionRange(Loc).first; + Attr.Loc = Loc; Attr.ModifiedType = TL.getModifiedLoc().getType(); Attr.Dcl = D; Attr.FullyMigratable = FullyMigratable; @@ -202,12 +205,35 @@ static void errorForGCAttrsOnNonObjC(MigrationContext &MigrateCtx) { } } +static void checkWeakGCAttrs(MigrationContext &MigrateCtx) { + TransformActions &TA = MigrateCtx.Pass.TA; + + for (unsigned i = 0, e = MigrateCtx.GCAttrs.size(); i != e; ++i) { + MigrationContext::GCAttrOccurrence &Attr = MigrateCtx.GCAttrs[i]; + if (Attr.Kind == MigrationContext::GCAttrOccurrence::Weak && + Attr.FullyMigratable) { + if (Attr.ModifiedType.isNull() || + !Attr.ModifiedType->isObjCRetainableType()) + continue; + if (!canApplyWeak(MigrateCtx.Pass.Ctx, Attr.ModifiedType, + /*AllowOnUnknownClass=*/true)) { + Transaction Trans(TA); + TA.replaceText(Attr.Loc, "__weak", "__unsafe_unretained"); + TA.clearDiagnostic(diag::err_arc_weak_no_runtime, + diag::err_arc_unsupported_weak_class, + Attr.Loc); + } + } + } +} + void GCAttrsTraverser::traverseTU(MigrationContext &MigrateCtx) { GCAttrsCollector(MigrateCtx).TraverseDecl( MigrateCtx.Pass.Ctx.getTranslationUnitDecl()); clearRedundantStrongs(MigrateCtx); errorForGCAttrsOnNonObjC(MigrateCtx); + checkWeakGCAttrs(MigrateCtx); } void MigrationContext::dumpGCAttrs() { |