summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-07-14 23:32:04 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-07-14 23:32:04 +0000
commitf2a27f40d658446fd544f6f4f226b1e1ea6bb1c4 (patch)
treee58045dfa2deb96db5438de9daa70abbb4eb5254
parent4771159f9fed25993673f4fd321a24a643d6b790 (diff)
downloadbcm5719-llvm-f2a27f40d658446fd544f6f4f226b1e1ea6bb1c4.tar.gz
bcm5719-llvm-f2a27f40d658446fd544f6f4f226b1e1ea6bb1c4.zip
[arcmt] Don't remove retains/releases on a global variable, flag them with errors. rdar://9402555.
llvm-svn: 135213
-rw-r--r--clang/lib/ARCMigrate/TransRetainReleaseDealloc.cpp9
-rw-r--r--clang/lib/ARCMigrate/TransUnbridgedCasts.cpp11
-rw-r--r--clang/lib/ARCMigrate/Transforms.cpp11
-rw-r--r--clang/lib/ARCMigrate/Transforms.h2
-rw-r--r--clang/test/ARCMT/checking.m6
5 files changed, 28 insertions, 11 deletions
diff --git a/clang/lib/ARCMigrate/TransRetainReleaseDealloc.cpp b/clang/lib/ARCMigrate/TransRetainReleaseDealloc.cpp
index 4eeb47437e3..c72312b2600 100644
--- a/clang/lib/ARCMigrate/TransRetainReleaseDealloc.cpp
+++ b/clang/lib/ARCMigrate/TransRetainReleaseDealloc.cpp
@@ -78,6 +78,15 @@ public:
Pass.TA.reportError(err, rec->getLocStart());
return true;
}
+
+ if (isGlobalVar(rec) &&
+ (E->getMethodFamily() != OMF_retain || isRemovable(E))) {
+ std::string err = "it is not safe to remove '";
+ err += E->getSelector().getAsString() + "' message on "
+ "a global variable";
+ Pass.TA.reportError(err, rec->getLocStart());
+ return true;
+ }
}
case OMF_dealloc:
break;
diff --git a/clang/lib/ARCMigrate/TransUnbridgedCasts.cpp b/clang/lib/ARCMigrate/TransUnbridgedCasts.cpp
index 6513d98c929..1cacd6d84e6 100644
--- a/clang/lib/ARCMigrate/TransUnbridgedCasts.cpp
+++ b/clang/lib/ARCMigrate/TransUnbridgedCasts.cpp
@@ -193,17 +193,6 @@ private:
return true;
return false;
}
-
- static bool isGlobalVar(Expr *E) {
- E = E->IgnoreParenCasts();
- if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E))
- return DRE->getDecl()->getDeclContext()->isFileContext();
- if (ConditionalOperator *condOp = dyn_cast<ConditionalOperator>(E))
- return isGlobalVar(condOp->getTrueExpr()) &&
- isGlobalVar(condOp->getFalseExpr());
-
- return false;
- }
};
} // end anonymous namespace
diff --git a/clang/lib/ARCMigrate/Transforms.cpp b/clang/lib/ARCMigrate/Transforms.cpp
index 7a439d95e3a..7bd95e54bc2 100644
--- a/clang/lib/ARCMigrate/Transforms.cpp
+++ b/clang/lib/ARCMigrate/Transforms.cpp
@@ -152,6 +152,17 @@ bool trans::hasSideEffects(Expr *E, ASTContext &Ctx) {
return true;
}
+bool trans::isGlobalVar(Expr *E) {
+ E = E->IgnoreParenCasts();
+ if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E))
+ return DRE->getDecl()->getDeclContext()->isFileContext();
+ if (ConditionalOperator *condOp = dyn_cast<ConditionalOperator>(E))
+ return isGlobalVar(condOp->getTrueExpr()) &&
+ isGlobalVar(condOp->getFalseExpr());
+
+ return false;
+}
+
namespace {
class ReferenceClear : public RecursiveASTVisitor<ReferenceClear> {
diff --git a/clang/lib/ARCMigrate/Transforms.h b/clang/lib/ARCMigrate/Transforms.h
index 00ff733f47e..b47d6d8e9b8 100644
--- a/clang/lib/ARCMigrate/Transforms.h
+++ b/clang/lib/ARCMigrate/Transforms.h
@@ -54,6 +54,8 @@ bool canApplyWeak(ASTContext &Ctx, QualType type);
SourceLocation findLocationAfterSemi(SourceLocation loc, ASTContext &Ctx);
bool hasSideEffects(Expr *E, ASTContext &Ctx);
+bool isGlobalVar(Expr *E);
+
template <typename BODY_TRANS>
class BodyTransform : public RecursiveASTVisitor<BodyTransform<BODY_TRANS> > {
diff --git a/clang/test/ARCMT/checking.m b/clang/test/ARCMT/checking.m
index 7ab54ceb05d..2e4ec122d64 100644
--- a/clang/test/ARCMT/checking.m
+++ b/clang/test/ARCMT/checking.m
@@ -36,10 +36,16 @@ struct UnsafeS {
- (oneway void)release { } // expected-error {{ARC forbids implementation}}
@end
+id global_foo;
+
void test1(A *a, BOOL b, struct UnsafeS *unsafeS) {
[unsafeS->unsafeObj retain]; // expected-error {{it is not safe to remove 'retain' message on an __unsafe_unretained type}} \
// expected-error {{ARC forbids explicit message send}}
id foo = [unsafeS->unsafeObj retain]; // no warning.
+ [global_foo retain]; // expected-error {{it is not safe to remove 'retain' message on a global variable}} \
+ // expected-error {{ARC forbids explicit message send}}
+ [global_foo release]; // expected-error {{it is not safe to remove 'release' message on a global variable}} \
+ // expected-error {{ARC forbids explicit message send}}
[a dealloc];
[a retain];
[a retainCount]; // expected-error {{ARC forbids explicit message send of 'retainCount'}}
OpenPOWER on IntegriCloud