Re: [PATCH] D22856: [analyzer] Change -analyze-function to accept qualified names.

2016-08-08 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL278018: [analyzer] Change -analyze-function to accept 
qualified names. (authored by dergachev).

Changed prior to commit:
  https://reviews.llvm.org/D22856?vs=66360=67180#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D22856

Files:
  cfe/trunk/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
  cfe/trunk/test/Analysis/analyzeOneFunction.m
  cfe/trunk/test/Analysis/analyze_display_progress.cpp
  cfe/trunk/test/Analysis/analyzer-display-progress.cpp
  cfe/trunk/test/Analysis/analyzer-display-progress.m

Index: cfe/trunk/test/Analysis/analyzer-display-progress.cpp
===
--- cfe/trunk/test/Analysis/analyzer-display-progress.cpp
+++ cfe/trunk/test/Analysis/analyzer-display-progress.cpp
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -analyze -analyzer-display-progress %s 2>&1 | FileCheck %s
+
+void f() {};
+void g() {};
+void h() {}
+
+struct SomeStruct {
+  void f() {}
+};
+
+struct SomeOtherStruct {
+  void f() {}
+};
+
+namespace ns {
+  struct SomeStruct {
+void f(int) {}
+void f(float, ::SomeStruct) {}
+void f(float, SomeStruct) {}
+  };
+}
+
+// CHECK: analyzer-display-progress.cpp f()
+// CHECK: analyzer-display-progress.cpp g()
+// CHECK: analyzer-display-progress.cpp h()
+// CHECK: analyzer-display-progress.cpp SomeStruct::f()
+// CHECK: analyzer-display-progress.cpp SomeOtherStruct::f()
+// CHECK: analyzer-display-progress.cpp ns::SomeStruct::f(int)
+// CHECK: analyzer-display-progress.cpp ns::SomeStruct::f(float, ::SomeStruct)
+// CHECK: analyzer-display-progress.cpp ns::SomeStruct::f(float, struct ns::SomeStruct)
Index: cfe/trunk/test/Analysis/analyzeOneFunction.m
===
--- cfe/trunk/test/Analysis/analyzeOneFunction.m
+++ cfe/trunk/test/Analysis/analyzeOneFunction.m
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -analyze -analyze-function="myMethodWithY:withX:" -analyzer-checker=core,osx.cocoa.RetainCount -analyzer-store=region -verify %s
+// RUN: %clang_cc1 -analyze -analyze-function="-[Test1 myMethodWithY:withX:]" -analyzer-checker=core,osx.cocoa.RetainCount -analyzer-store=region -verify %s
 
 typedef signed char BOOL;
 typedef unsigned int NSUInteger;
Index: cfe/trunk/test/Analysis/analyzer-display-progress.m
===
--- cfe/trunk/test/Analysis/analyzer-display-progress.m
+++ cfe/trunk/test/Analysis/analyzer-display-progress.m
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -fblocks -analyze -analyzer-display-progress %s 2>&1 | FileCheck %s
+
+#include "Inputs/system-header-simulator-objc.h"
+
+static void f() {}
+
+@interface I: NSObject
+-(void)instanceMethod:(int)arg1 with:(int)arg2;
++(void)classMethod;
+@end
+
+@implementation I
+-(void)instanceMethod:(int)arg1 with:(int)arg2 {}
++(void)classMethod {}
+@end
+
+void g(I *i, int x, int y) {
+  [I classMethod];
+  [i instanceMethod: x with: y];
+
+  void (^block)(void);
+  block = ^{};
+  block();
+}
+
+// CHECK: analyzer-display-progress.m f
+// CHECK: analyzer-display-progress.m -[I instanceMethod:with:]
+// CHECK: analyzer-display-progress.m +[I classMethod]
+// CHECK: analyzer-display-progress.m g
+// CHECK: analyzer-display-progress.m block (line: 22, col: 11)
Index: cfe/trunk/test/Analysis/analyze_display_progress.cpp
===
--- cfe/trunk/test/Analysis/analyze_display_progress.cpp
+++ cfe/trunk/test/Analysis/analyze_display_progress.cpp
@@ -1,26 +0,0 @@
-// RUN: %clang_cc1 -analyze -analyzer-display-progress %s 2>&1 | FileCheck %s
-
-void f() {};
-void g() {};
-void h() {}
-
-struct SomeStruct {
-  void f() {}
-};
-
-struct SomeOtherStruct {
-  void f() {}
-};
-
-namespace ns {
-  struct SomeStruct {
-void f() {}
-  };
-}
-
-// CHECK: analyze_display_progress.cpp f
-// CHECK: analyze_display_progress.cpp g
-// CHECK: analyze_display_progress.cpp h
-// CHECK: analyze_display_progress.cpp SomeStruct::f
-// CHECK: analyze_display_progress.cpp SomeOtherStruct::f
-// CHECK: analyze_display_progress.cpp ns::SomeStruct::f
Index: cfe/trunk/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
@@ -265,19 +265,8 @@
   else
 assert(Mode == (AM_Syntax | AM_Path) && "Unexpected mode!");
 
-  llvm::errs() << ": " << Loc.getFilename();
-  if (isa(D) || isa(D)) {
-const NamedDecl *ND = cast(D);
-llvm::errs() << ' ' << ND->getQualifiedNameAsString() << '\n';
-  }
-  else if (isa(D)) {
-llvm::errs() << ' ' << "block(line:" << Loc.getLine() << ",col:"
- << Loc.getColumn() << '\n';
-  }
-  else if (const ObjCMethodDecl *MD = dyn_cast(D)) {
-Selector S = 

Re: [PATCH] D22856: [analyzer] Change -analyze-function to accept qualified names.

2016-08-01 Thread Artem Dergachev via cfe-commits
NoQ updated this revision to Diff 66360.
NoQ added a comment.

Copy-paste the code from CGDebugInfo.cpp to support Objective-C instance and 
class methods. Add more tests. Move the `analyze_display_progress.cpp` because 
most tests use dashes in names.


https://reviews.llvm.org/D22856

Files:
  lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
  test/Analysis/analyzeOneFunction.m
  test/Analysis/analyze_display_progress.cpp
  test/Analysis/analyzer-display-progress.cpp
  test/Analysis/analyzer-display-progress.m

Index: test/Analysis/analyzer-display-progress.m
===
--- /dev/null
+++ test/Analysis/analyzer-display-progress.m
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -fblocks -analyze -analyzer-display-progress %s 2>&1 | FileCheck %s
+
+#include "Inputs/system-header-simulator-objc.h"
+
+static void f() {}
+
+@interface I: NSObject
+-(void)instanceMethod:(int)arg1 with:(int)arg2;
++(void)classMethod;
+@end
+
+@implementation I
+-(void)instanceMethod:(int)arg1 with:(int)arg2 {}
++(void)classMethod {}
+@end
+
+void g(I *i, int x, int y) {
+  [I classMethod];
+  [i instanceMethod: x with: y];
+
+  void (^block)(void);
+  block = ^{};
+  block();
+}
+
+// CHECK: analyzer-display-progress.m f
+// CHECK: analyzer-display-progress.m -[I instanceMethod:with:]
+// CHECK: analyzer-display-progress.m +[I classMethod]
+// CHECK: analyzer-display-progress.m g
+// CHECK: analyzer-display-progress.m block (line: 22, col: 11)
Index: test/Analysis/analyzer-display-progress.cpp
===
--- /dev/null
+++ test/Analysis/analyzer-display-progress.cpp
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -analyze -analyzer-display-progress %s 2>&1 | FileCheck %s
+
+void f() {};
+void g() {};
+void h() {}
+
+struct SomeStruct {
+  void f() {}
+};
+
+struct SomeOtherStruct {
+  void f() {}
+};
+
+namespace ns {
+  struct SomeStruct {
+void f(int) {}
+void f(float, ::SomeStruct) {}
+void f(float, SomeStruct) {}
+  };
+}
+
+// CHECK: analyzer-display-progress.cpp f()
+// CHECK: analyzer-display-progress.cpp g()
+// CHECK: analyzer-display-progress.cpp h()
+// CHECK: analyzer-display-progress.cpp SomeStruct::f()
+// CHECK: analyzer-display-progress.cpp SomeOtherStruct::f()
+// CHECK: analyzer-display-progress.cpp ns::SomeStruct::f(int)
+// CHECK: analyzer-display-progress.cpp ns::SomeStruct::f(float, ::SomeStruct)
+// CHECK: analyzer-display-progress.cpp ns::SomeStruct::f(float, struct ns::SomeStruct)
Index: test/Analysis/analyze_display_progress.cpp
===
--- test/Analysis/analyze_display_progress.cpp
+++ /dev/null
@@ -1,26 +0,0 @@
-// RUN: %clang_cc1 -analyze -analyzer-display-progress %s 2>&1 | FileCheck %s
-
-void f() {};
-void g() {};
-void h() {}
-
-struct SomeStruct {
-  void f() {}
-};
-
-struct SomeOtherStruct {
-  void f() {}
-};
-
-namespace ns {
-  struct SomeStruct {
-void f() {}
-  };
-}
-
-// CHECK: analyze_display_progress.cpp f
-// CHECK: analyze_display_progress.cpp g
-// CHECK: analyze_display_progress.cpp h
-// CHECK: analyze_display_progress.cpp SomeStruct::f
-// CHECK: analyze_display_progress.cpp SomeOtherStruct::f
-// CHECK: analyze_display_progress.cpp ns::SomeStruct::f
Index: test/Analysis/analyzeOneFunction.m
===
--- test/Analysis/analyzeOneFunction.m
+++ test/Analysis/analyzeOneFunction.m
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -analyze -analyze-function="myMethodWithY:withX:" -analyzer-checker=core,osx.cocoa.RetainCount -analyzer-store=region -verify %s
+// RUN: %clang_cc1 -analyze -analyze-function="-[Test1 myMethodWithY:withX:]" -analyzer-checker=core,osx.cocoa.RetainCount -analyzer-store=region -verify %s
 
 typedef signed char BOOL;
 typedef unsigned int NSUInteger;
Index: lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
===
--- lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
+++ lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
@@ -265,19 +265,8 @@
   else
 assert(Mode == (AM_Syntax | AM_Path) && "Unexpected mode!");
 
-  llvm::errs() << ": " << Loc.getFilename();
-  if (isa(D) || isa(D)) {
-const NamedDecl *ND = cast(D);
-llvm::errs() << ' ' << ND->getQualifiedNameAsString() << '\n';
-  }
-  else if (isa(D)) {
-llvm::errs() << ' ' << "block(line:" << Loc.getLine() << ",col:"
- << Loc.getColumn() << '\n';
-  }
-  else if (const ObjCMethodDecl *MD = dyn_cast(D)) {
-Selector S = MD->getSelector();
-llvm::errs() << ' ' << S.getAsString();
-  }
+  llvm::errs() << ": " << Loc.getFilename() << ' '
+   << getFunctionName(D) << '\n';
 }
   }
 
@@ -377,6 +366,7 @@
 
 private:
   void storeTopLevelDecls(DeclGroupRef DG);
+  std::string getFunctionName(const Decl *D);
 
   /// \brief 

Re: [PATCH] D22856: [analyzer] Change -analyze-function to accept qualified names.

2016-07-29 Thread Anna Zaks via cfe-commits
zaks.anna accepted this revision.
zaks.anna added a comment.
This revision is now accepted and ready to land.

Since this is an improvement, it looks good to me. (Improving printing of ObjC 
methods is a good add on, but not blocking..)


https://reviews.llvm.org/D22856



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D22856: [analyzer] Change -analyze-function to accept qualified names.

2016-07-27 Thread Anna Zaks via cfe-commits
zaks.anna added a comment.

We'd definitely want the same routine in both: printing the name in 
-analyzer-display-progress and be accepted by -analyze-function.

Looks like what ND->getQualifiedNameAsString() returns is not proper ObjC 
syntax, but maybe it's fine for the debug feature? Even though it is not very 
readable...


https://reviews.llvm.org/D22856



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D22856: [analyzer] Change -analyze-function to accept qualified names.

2016-07-27 Thread Devin Coughlin via cfe-commits
dcoughlin added a comment.

In https://reviews.llvm.org/D22856#497796, @NoQ wrote:

> > I think it would be better for fully-qualified Objective-C methods to be 
> > specified with their Objective-C-style names. For example: "-[Test1 
> > myMethodWithY:withX:]".
>
>
> Uhm, need to know more about those. So i just print "`-[`", then 
> fully-qualified class name, then selector identifier, then "`]`"?


Instance methods get "-" and class methods (which are similar to static methods 
in Java) get the "+" prefix. See CGDebugInfo::getObjCMethodName() in 
CGDebugInfo.cpp for the gory details.


https://reviews.llvm.org/D22856



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D22856: [analyzer] Change -analyze-function to accept qualified names.

2016-07-27 Thread Artem Dergachev via cfe-commits
NoQ added a comment.

> I think it would be better for fully-qualified Objective-C methods to be 
> specified with their Objective-C-style names. For example: "-[Test1 
> myMethodWithY:withX:]".


Uhm, need to know more about those. So i just print "`-[`", then 
fully-qualified class name, then selector identifier, then "`]`"?

> Does this approach work for C++ when there are multiple overloads of methods 
> with the same name?


Nope, unfortunately not. I'm open to suggestions on how to make this work. We 
may either dump types of arguments, or do something like "`foo~1`", "`foo~2`", 
etc.


https://reviews.llvm.org/D22856



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D22856: [analyzer] Change -analyze-function to accept qualified names.

2016-07-27 Thread Devin Coughlin via cfe-commits
dcoughlin added a comment.

I think it would be better for fully-qualified Objective-C methods to be 
specified with their Objective-C-style names. For example:  "-[Test1 
myMethodWithY:withX:]". This would also remove the ambiguity when there are 
class and instance methods with the same selector.

Does this approach work for C++ when there are multiple overloads of methods 
with the same name?


https://reviews.llvm.org/D22856



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits