[cfe-commits] r133323 - in /cfe/trunk: include/clang/ARCMigrate/ARCMTActions.h include/clang/Frontend/FrontendAction.h lib/ARCMigrate/ARCMT.cpp lib/ARCMigrate/ARCMTActions.cpp lib/ARCMigrate/Internals.h lib/Frontend/FrontendAction.cpp test/ARCMT/alloc-with-zone-check.m test/ARCMT/atautorelease-check.m test/ARCMT/checking.m test/ARCMT/cxx-checking.mm test/ARCMT/nonobjc-to-objc-cast-2.m test/ARCMT/releases-driver.m test/ARCMT/releases-driver.m.result tools/arcmt-test/arcmt-test.cpp
Argyrios Kyrtzidis
akyrtzi at gmail.com
Fri Jun 17 17:53:41 PDT 2011
Author: akirtzidis
Date: Fri Jun 17 19:53:41 2011
New Revision: 133323
URL: http://llvm.org/viewvc/llvm-project?rev=133323&view=rev
Log:
[arcmt] Fix the ARC migrator. -arcmt-modify requires running before the initialization of SourceManager
because it is going to modify the input file.
Added:
cfe/trunk/test/ARCMT/releases-driver.m
cfe/trunk/test/ARCMT/releases-driver.m.result
Modified:
cfe/trunk/include/clang/ARCMigrate/ARCMTActions.h
cfe/trunk/include/clang/Frontend/FrontendAction.h
cfe/trunk/lib/ARCMigrate/ARCMT.cpp
cfe/trunk/lib/ARCMigrate/ARCMTActions.cpp
cfe/trunk/lib/ARCMigrate/Internals.h
cfe/trunk/lib/Frontend/FrontendAction.cpp
cfe/trunk/test/ARCMT/alloc-with-zone-check.m
cfe/trunk/test/ARCMT/atautorelease-check.m
cfe/trunk/test/ARCMT/checking.m
cfe/trunk/test/ARCMT/cxx-checking.mm
cfe/trunk/test/ARCMT/nonobjc-to-objc-cast-2.m
cfe/trunk/tools/arcmt-test/arcmt-test.cpp
Modified: cfe/trunk/include/clang/ARCMigrate/ARCMTActions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ARCMigrate/ARCMTActions.h?rev=133323&r1=133322&r2=133323&view=diff
==============================================================================
--- cfe/trunk/include/clang/ARCMigrate/ARCMTActions.h (original)
+++ cfe/trunk/include/clang/ARCMigrate/ARCMTActions.h Fri Jun 17 19:53:41 2011
@@ -18,7 +18,7 @@
class CheckAction : public WrapperFrontendAction {
protected:
- virtual void ExecuteAction();
+ virtual bool BeginInvocation(CompilerInstance &CI);
public:
CheckAction(FrontendAction *WrappedAction);
@@ -26,7 +26,7 @@
class TransformationAction : public WrapperFrontendAction {
protected:
- virtual void ExecuteAction();
+ virtual bool BeginInvocation(CompilerInstance &CI);
public:
TransformationAction(FrontendAction *WrappedAction);
Modified: cfe/trunk/include/clang/Frontend/FrontendAction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/FrontendAction.h?rev=133323&r1=133322&r2=133323&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/FrontendAction.h (original)
+++ cfe/trunk/include/clang/Frontend/FrontendAction.h Fri Jun 17 19:53:41 2011
@@ -78,6 +78,14 @@
virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
llvm::StringRef InFile) = 0;
+ /// \brief Callback before starting processing a single input, giving the
+ /// opportunity to modify the CompilerInvocation or do some other action
+ /// before BeginSourceFileAction is called.
+ ///
+ /// \return True on success; on failure \see BeginSourceFileAction() and
+ /// ExecutionAction() and EndSourceFileAction() will not be called.
+ virtual bool BeginInvocation(CompilerInstance &CI) { return true; }
+
/// BeginSourceFileAction - Callback at the start of processing a single
/// input.
///
@@ -265,6 +273,7 @@
protected:
virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
llvm::StringRef InFile);
+ virtual bool BeginInvocation(CompilerInstance &CI);
virtual bool BeginSourceFileAction(CompilerInstance &CI,
llvm::StringRef Filename);
virtual void ExecuteAction();
Modified: cfe/trunk/lib/ARCMigrate/ARCMT.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/ARCMT.cpp?rev=133323&r1=133322&r2=133323&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/ARCMT.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/ARCMT.cpp Fri Jun 17 19:53:41 2011
@@ -79,6 +79,14 @@
Diags.Report(*I);
}
+bool CapturedDiagList::hasErrors() const {
+ for (ListTy::const_iterator I = List.begin(), E = List.end(); I != E; ++I)
+ if (I->getLevel() >= Diagnostic::Error)
+ return true;
+
+ return false;
+}
+
namespace {
class CaptureDiagnosticClient : public DiagnosticClient {
@@ -236,7 +244,7 @@
DiagClient->EndSourceFile();
- return Diags->getClient()->getNumErrors() > 0;
+ return capturedDiags.hasErrors();
}
//===----------------------------------------------------------------------===//
Modified: cfe/trunk/lib/ARCMigrate/ARCMTActions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/ARCMTActions.cpp?rev=133323&r1=133322&r2=133323&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/ARCMTActions.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/ARCMTActions.cpp Fri Jun 17 19:53:41 2011
@@ -14,29 +14,24 @@
using namespace clang;
using namespace arcmt;
-void CheckAction::ExecuteAction() {
- CompilerInstance &CI = getCompilerInstance();
+bool CheckAction::BeginInvocation(CompilerInstance &CI) {
if (arcmt::checkForManualIssues(CI.getInvocation(), getCurrentFile(),
getCurrentFileKind(),
CI.getDiagnostics().getClient()))
- return;
+ return false; // errors, stop the action.
// We only want to see warnings reported from arcmt::checkForManualIssues.
CI.getDiagnostics().setIgnoreAllWarnings(true);
- WrapperFrontendAction::ExecuteAction();
+ return true;
}
CheckAction::CheckAction(FrontendAction *WrappedAction)
: WrapperFrontendAction(WrappedAction) {}
-void TransformationAction::ExecuteAction() {
- CompilerInstance &CI = getCompilerInstance();
- if (arcmt::applyTransformations(CI.getInvocation(), getCurrentFile(),
+bool TransformationAction::BeginInvocation(CompilerInstance &CI) {
+ return !arcmt::applyTransformations(CI.getInvocation(), getCurrentFile(),
getCurrentFileKind(),
- CI.getDiagnostics().getClient()))
- return;
-
- WrapperFrontendAction::ExecuteAction();
+ CI.getDiagnostics().getClient());
}
TransformationAction::TransformationAction(FrontendAction *WrappedAction)
Modified: cfe/trunk/lib/ARCMigrate/Internals.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/Internals.h?rev=133323&r1=133322&r2=133323&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/Internals.h (original)
+++ cfe/trunk/lib/ARCMigrate/Internals.h Fri Jun 17 19:53:41 2011
@@ -30,6 +30,8 @@
bool hasDiagnostic(llvm::ArrayRef<unsigned> IDs, SourceRange range) const;
void reportDiagnostics(Diagnostic &diags) const;
+
+ bool hasErrors() const;
};
class TransformActions {
Modified: cfe/trunk/lib/Frontend/FrontendAction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendAction.cpp?rev=133323&r1=133322&r2=133323&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/FrontendAction.cpp (original)
+++ cfe/trunk/lib/Frontend/FrontendAction.cpp Fri Jun 17 19:53:41 2011
@@ -130,6 +130,9 @@
setCurrentFile(Filename, InputKind);
setCompilerInstance(&CI);
+ if (!BeginInvocation(CI))
+ goto failure;
+
// AST files follow a very different path, since they share objects via the
// AST unit.
if (InputKind == IK_AST) {
@@ -386,8 +389,13 @@
llvm::StringRef InFile) {
return WrappedAction->CreateASTConsumer(CI, InFile);
}
+bool WrapperFrontendAction::BeginInvocation(CompilerInstance &CI) {
+ return WrappedAction->BeginInvocation(CI);
+}
bool WrapperFrontendAction::BeginSourceFileAction(CompilerInstance &CI,
llvm::StringRef Filename) {
+ WrappedAction->setCurrentFile(getCurrentFile(), getCurrentFileKind());
+ WrappedAction->setCompilerInstance(&CI);
return WrappedAction->BeginSourceFileAction(CI, Filename);
}
void WrapperFrontendAction::ExecuteAction() {
Modified: cfe/trunk/test/ARCMT/alloc-with-zone-check.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/alloc-with-zone-check.m?rev=133323&r1=133322&r2=133323&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/alloc-with-zone-check.m (original)
+++ cfe/trunk/test/ARCMT/alloc-with-zone-check.m Fri Jun 17 19:53:41 2011
@@ -1,4 +1,4 @@
-// RUN: arcmt-test -check-only -verify --args %s
+// RUN: %clang_cc1 -arcmt-check -verify -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi %s
#if __has_feature(objc_arr)
#define NS_AUTOMATED_REFCOUNT_UNAVAILABLE __attribute__((unavailable("not available in automatic reference counting mode")))
Modified: cfe/trunk/test/ARCMT/atautorelease-check.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/atautorelease-check.m?rev=133323&r1=133322&r2=133323&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/atautorelease-check.m (original)
+++ cfe/trunk/test/ARCMT/atautorelease-check.m Fri Jun 17 19:53:41 2011
@@ -1,4 +1,4 @@
-// RUN: arcmt-test -check-only -verify --args %s
+// RUN: %clang_cc1 -arcmt-check -verify -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi %s
#if __has_feature(objc_arr)
#define NS_AUTOMATED_REFCOUNT_UNAVAILABLE __attribute__((unavailable("not available in automatic reference counting mode")))
Modified: cfe/trunk/test/ARCMT/checking.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/checking.m?rev=133323&r1=133322&r2=133323&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/checking.m (original)
+++ cfe/trunk/test/ARCMT/checking.m Fri Jun 17 19:53:41 2011
@@ -1,4 +1,4 @@
-// RUN: arcmt-test -check-only -verify --args %s
+// RUN: %clang_cc1 -arcmt-check -verify -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi %s
#include "Common.h"
Modified: cfe/trunk/test/ARCMT/cxx-checking.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/cxx-checking.mm?rev=133323&r1=133322&r2=133323&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/cxx-checking.mm (original)
+++ cfe/trunk/test/ARCMT/cxx-checking.mm Fri Jun 17 19:53:41 2011
@@ -1,4 +1,4 @@
-// RUN: arcmt-test -check-only -verify --args -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -fblocks -Warc-abi %s
+// RUN: %clang_cc1 -arcmt-check -verify -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -fblocks -Warc-abi %s
// Classes that have an Objective-C object pointer.
struct HasObjectMember0 { // expected-warning{{'HasObjectMember0' cannot be shared between ARC and non-ARC code; add a copy constructor, a copy assignment operator, and a destructor to make it ABI-compatible}}
Modified: cfe/trunk/test/ARCMT/nonobjc-to-objc-cast-2.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/nonobjc-to-objc-cast-2.m?rev=133323&r1=133322&r2=133323&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/nonobjc-to-objc-cast-2.m (original)
+++ cfe/trunk/test/ARCMT/nonobjc-to-objc-cast-2.m Fri Jun 17 19:53:41 2011
@@ -1,4 +1,4 @@
-// RUN: arcmt-test -check-only -verify --args %s
+// RUN: %clang_cc1 -arcmt-check -verify -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi %s
typedef int BOOL;
typedef const struct __CFString * CFStringRef;
Added: cfe/trunk/test/ARCMT/releases-driver.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/releases-driver.m?rev=133323&view=auto
==============================================================================
--- cfe/trunk/test/ARCMT/releases-driver.m (added)
+++ cfe/trunk/test/ARCMT/releases-driver.m Fri Jun 17 19:53:41 2011
@@ -0,0 +1,68 @@
+// RUN: %clang_cc1 -fobjc-nonfragile-abi -fblocks -fsyntax-only -fobjc-arc -x objective-c %s.result
+// RUN: cp %s %t
+// RUN: %clang_cc1 -arcmt-modify -triple x86_64-apple-macosx10.6 -fobjc-nonfragile-abi -x objective-c %t
+// RUN: diff %t %s.result
+// RUN: rm %t
+
+typedef int BOOL;
+
+id IhaveSideEffect();
+
+ at protocol NSObject
+- (BOOL)isEqual:(id)object;
+- (id)retain;
+- (oneway void)release;
+ at end
+
+ at interface NSObject <NSObject> {}
+ at end
+
+ at interface Foo : NSObject {
+ id bar;
+}
+ at property (retain) id bar;
+-(void)test:(id)obj;
+ at end
+
+ at implementation Foo
+
+ at synthesize bar;
+
+-(void)test:(id)obj {
+ id x = self.bar;
+ [x retain];
+ self.bar = obj;
+ // do stuff with x;
+ [x release];
+
+ [IhaveSideEffect() release];
+
+ [x release], x = 0;
+}
+
+ at end
+
+void func(Foo *p) {
+ [p release];
+ (([p release]));
+}
+
+ at interface Baz {
+ id <NSObject> _foo;
+}
+ at end
+
+ at implementation Baz
+- dealloc {
+ [_foo release];
+ return 0;
+}
+ at end
+
+#define RELEASE_MACRO(x) [x release]
+#define RELEASE_MACRO2(x) RELEASE_MACRO(x)
+
+void test2(id p) {
+ RELEASE_MACRO(p);
+ RELEASE_MACRO2(p);
+}
Added: cfe/trunk/test/ARCMT/releases-driver.m.result
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/releases-driver.m.result?rev=133323&view=auto
==============================================================================
--- cfe/trunk/test/ARCMT/releases-driver.m.result (added)
+++ cfe/trunk/test/ARCMT/releases-driver.m.result Fri Jun 17 19:53:41 2011
@@ -0,0 +1,61 @@
+// RUN: %clang_cc1 -fobjc-nonfragile-abi -fblocks -fsyntax-only -fobjc-arc -x objective-c %s.result
+// RUN: cp %s %t
+// RUN: %clang_cc1 -arcmt-modify -triple x86_64-apple-macosx10.6 -fobjc-nonfragile-abi -x objective-c %t
+// RUN: diff %t %s.result
+// RUN: rm %t
+
+typedef int BOOL;
+
+id IhaveSideEffect();
+
+ at protocol NSObject
+- (BOOL)isEqual:(id)object;
+- (id)retain;
+- (oneway void)release;
+ at end
+
+ at interface NSObject <NSObject> {}
+ at end
+
+ at interface Foo : NSObject {
+ id bar;
+}
+ at property (retain) id bar;
+-(void)test:(id)obj;
+ at end
+
+ at implementation Foo
+
+ at synthesize bar;
+
+-(void)test:(id)obj {
+ id x = self.bar;
+ self.bar = obj;
+ // do stuff with x;
+
+ IhaveSideEffect();
+
+ x = 0;
+}
+
+ at end
+
+void func(Foo *p) {
+}
+
+ at interface Baz {
+ id <NSObject> _foo;
+}
+ at end
+
+ at implementation Baz
+- dealloc {
+ return 0;
+}
+ at end
+
+#define RELEASE_MACRO(x) [x release]
+#define RELEASE_MACRO2(x) RELEASE_MACRO(x)
+
+void test2(id p) {
+}
Modified: cfe/trunk/tools/arcmt-test/arcmt-test.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/arcmt-test/arcmt-test.cpp?rev=133323&r1=133322&r2=133323&view=diff
==============================================================================
--- cfe/trunk/tools/arcmt-test/arcmt-test.cpp (original)
+++ cfe/trunk/tools/arcmt-test/arcmt-test.cpp Fri Jun 17 19:53:41 2011
@@ -111,10 +111,11 @@
if (!CI.getLangOpts().ObjC1)
return false;
- return arcmt::checkForManualIssues(CI,
- CI.getFrontendOpts().Inputs[0].second,
- CI.getFrontendOpts().Inputs[0].first,
- Diags->getClient());
+ arcmt::checkForManualIssues(CI,
+ CI.getFrontendOpts().Inputs[0].second,
+ CI.getFrontendOpts().Inputs[0].first,
+ Diags->getClient());
+ return Diags->getClient()->getNumErrors() > 0;
}
static void printResult(FileRemapper &remapper, llvm::raw_ostream &OS) {
More information about the cfe-commits
mailing list