Re: [PATCH] D22513: [clang-tidy] add check cppcoreguidelines-special-member-functions

2016-08-01 Thread Alexander Kornienko via cfe-commits
alexfh added a comment.

Thanks for the new check! Looks awesome! A couple of late comments inline.



Comment at: 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp:91
@@ +90,3 @@
+
+  std::initializer_list>
+  Matchers = {{"dtor", SpecialMemberFunctionKind::Destructor},

Is the explicit use of the initializer_list needed to pacify MSVC? I wonder 
whether std::string can be replaced with a `StringRef`?


Comment at: 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-special-member-functions-cxx-03.cpp:6
@@ +5,3 @@
+};
+// CHECK-MESSAGES: [[@LINE-3]]:7: warning: class 'DefinesDestructor' defines a 
destructor but does not define a copy constructor or a copy assignment operator 
[cppcoreguidelines-special-member-functions]
+

Native speakers can correct me, but "does not define X or Y" reads as if 
defining either X or Y is enough to fix the issue, while in fact we're 
expecting all special members to be defined. I'm not sure what the best wording 
would be, maybe "class 'C' defines X and Y, but does not define all other 
special members: T, U, V"?


Repository:
  rL LLVM

https://reviews.llvm.org/D22513



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


[PATCH] D23004: [ASTMatchers] Add matchers canReferToDecl() and hasUnderlyingDecl()

2016-08-01 Thread Martin Böhme via cfe-commits
mboehme created this revision.
mboehme added reviewers: aaron.ballman, sbenza.
mboehme added a subscriber: cfe-commits.
Herald added a subscriber: klimek.

Required for D0

https://reviews.llvm.org/D23004

Files:
  docs/LibASTMatchersReference.html
  include/clang/ASTMatchers/ASTMatchers.h
  lib/ASTMatchers/Dynamic/Registry.cpp
  unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Index: unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -241,6 +241,17 @@
 hasDeclaration(namedDecl(hasName("A";
 }
 
+TEST(HasUnderlyingDecl, Matches) {
+  EXPECT_TRUE(matches("class A{};"),
+  cxxRecordDecl(hasName("A"), hasUnderlyingDecl(hasName("A";
+  EXPECT_TRUE(matches("class A{}; typedef A B;"),
+  typedefDecl(hasName("B"), hasUnderlyingDecl(hasName("A";
+  EXPECT_TRUE(matches("class A{}; typedef A B; typedef B C;"),
+  typedefDecl(hasName("C"), hasUnderlyingDecl(hasName("A";
+  EXPECT_TRUE(notMatches("class A{}; class B{}; typedef B C;"),
+  typedefDecl(hasName("C"), hasUnderlyingDecl(hasName("A";
+}
+
 TEST(HasType, TakesQualTypeMatcherAndMatchesExpr) {
   TypeMatcher ClassX = hasDeclaration(recordDecl(hasName("X")));
   EXPECT_TRUE(
@@ -2051,5 +2062,24 @@
   EXPECT_TRUE(notMatches(Code2, ForEachOverriddenInClass("A1")));
 }
 
+TEST(Matcher, CanReferToDecl) {
+  std::string Fragment = "void foo(int p1);"
+ "void foo(int *p2);"
+ "void bar(int p3);"
+ "template  void baz(T t) { foo(t); }";
+
+  EXPECT_TRUE(
+  matches(Fragment, unresolvedLookupExpr(canReferToDecl(functionDecl(
+hasParameter(0, parmVarDecl(hasName("p1";
+  EXPECT_TRUE(
+  matches(Fragment, unresolvedLookupExpr(canReferToDecl(functionDecl(
+hasParameter(0, parmVarDecl(hasName("p2";
+  EXPECT_TRUE(
+  notMatches(Fragment, unresolvedLookupExpr(canReferToDecl(functionDecl(
+   hasParameter(0, parmVarDecl(hasName("p3";
+  EXPECT_TRUE(notMatches(Fragment, unresolvedLookupExpr(canReferToDecl(
+   functionDecl(hasName("bar"));
+}
+
 } // namespace ast_matchers
 } // namespace clang
Index: lib/ASTMatchers/Dynamic/Registry.cpp
===
--- lib/ASTMatchers/Dynamic/Registry.cpp
+++ lib/ASTMatchers/Dynamic/Registry.cpp
@@ -115,6 +115,7 @@
   REGISTER_MATCHER(breakStmt);
   REGISTER_MATCHER(builtinType);
   REGISTER_MATCHER(callExpr);
+  REGISTER_MATCHER(canReferToDecl);
   REGISTER_MATCHER(caseStmt);
   REGISTER_MATCHER(castExpr);
   REGISTER_MATCHER(characterLiteral);
@@ -265,6 +266,7 @@
   REGISTER_MATCHER(hasTypeLoc);
   REGISTER_MATCHER(hasUnaryOperand);
   REGISTER_MATCHER(hasUnarySelector);
+  REGISTER_MATCHER(hasUnderlyingDecl);
   REGISTER_MATCHER(hasValueType);
   REGISTER_MATCHER(ifStmt);
   REGISTER_MATCHER(ignoringImplicit);
Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -2422,6 +2422,24 @@
   void(internal::HasDeclarationSupportedTypes)>(InnerMatcher);
 }
 
+/// \brief Matches a \c NamedDecl whose underlying declaration matches the given
+/// matcher.
+///
+/// Given
+/// \code
+///   class X {};
+///   typedef X Y;
+/// \endcode
+/// \c namedDecl(hasUnderlyingDecl(hasName("X")))
+///   matches both \c X and \c Y .
+AST_MATCHER_P(NamedDecl, hasUnderlyingDecl, internal::Matcher,
+  InnerMatcher) {
+  const NamedDecl *UnderlyingDecl = Node.getUnderlyingDecl();
+
+  return (UnderlyingDecl != nullptr &&
+  InnerMatcher.matches(*UnderlyingDecl, Finder, Builder));
+}
+
 /// \brief Matches on the implicit object argument of a member call expression.
 ///
 /// Example matches y.x()
@@ -2777,6 +2795,22 @@
   return false;
 }
 
+/// \brief Matches any \c Decl of an \c OverloadExpr that matches the given
+/// matcher.
+///
+/// Given
+/// \code
+///   void foo(int);
+///   template  void bar(T t) { foo(t); }
+/// \endcode
+/// unresolvedLookupExpr(canReferToDecl(functionDecl()))
+///   matches \c foo in \c foo(t);
+AST_MATCHER_P(OverloadExpr, canReferToDecl, internal::Matcher,
+  InnerMatcher) {
+  return matchesFirstInPointerRange(InnerMatcher, Node.decls_begin(),
+Node.decls_end(), Finder, Builder);
+}
+
 /// \brief Matches the Decl of a DeclStmt which has a single declaration.
 ///
 /// Given
Index: docs/LibASTMatchersReference.html
===
--- docs/LibASTMatchersReference.html
+++ docs/LibASTMatchersReference.html

Re: [PATCH] D22220: [clang-tidy] Add check 'misc-move-forwarding-reference'

2016-08-01 Thread Martin Böhme via cfe-commits
mboehme updated this revision to Diff 66284.
mboehme marked 3 inline comments as done.

https://reviews.llvm.org/D0

Files:
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/MiscTidyModule.cpp
  clang-tidy/misc/MoveForwardingReferenceCheck.cpp
  clang-tidy/misc/MoveForwardingReferenceCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-move-forwarding-reference.rst
  test/clang-tidy/misc-move-forwarding-reference.cpp

Index: test/clang-tidy/misc-move-forwarding-reference.cpp
===
--- /dev/null
+++ test/clang-tidy/misc-move-forwarding-reference.cpp
@@ -0,0 +1,117 @@
+// RUN: %check_clang_tidy %s misc-move-forwarding-reference %t
+
+namespace std {
+template  struct remove_reference;
+
+template  struct remove_reference { typedef _Tp type; };
+
+template  struct remove_reference<_Tp &> { typedef _Tp type; };
+
+template  struct remove_reference<_Tp &&> { typedef _Tp type; };
+
+template 
+constexpr typename std::remove_reference<_Tp>::type &&move(_Tp &&__t);
+
+} // namespace std
+
+// Standard case.
+template  void f1(U &&SomeU) {
+  T SomeT(std::move(SomeU));
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: forwarding reference passed to
+  // CHECK-FIXES: T SomeT(std::forward(SomeU));
+}
+
+// Ignore parentheses around the argument to std::move().
+template  void f2(U &&SomeU) {
+  T SomeT(std::move((SomeU)));
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: forwarding reference passed to
+  // CHECK-FIXES: T SomeT(std::forward((SomeU)));
+}
+
+// Handle the case correctly where std::move() is being used through a using
+// declaration.
+template  void f3(U &&SomeU) {
+  using std::move;
+  T SomeT(move(SomeU));
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: forwarding reference passed to
+  // CHECK-FIXES: T SomeT(std::forward(SomeU));
+}
+
+// Handle the case correctly where a global specifier is prepended to
+// std::move().
+template  void f4(U &&SomeU) {
+  T SomeT(::std::move(SomeU));
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: forwarding reference passed to
+  // CHECK-FIXES: T SomeT(::std::forward(SomeU));
+}
+
+// Create a correct fix if there are spaces around the overload resolution
+// operator.
+template  void f5(U &&SomeU) {
+  {
+T SomeT(::std::move(SomeU));
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: forwarding reference passed to
+// CHECK-FIXES: T SomeT(::std::forward(SomeU));
+  }
+  {
+T SomeT(std::move(SomeU));
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: forwarding reference passed to
+// CHECK-FIXES: T SomeT(std::forward(SomeU));
+  }
+}
+
+// Ignore const rvalue reference parameters.
+template  void f6(const U &&SomeU) {
+  T SomeT(std::move(SomeU));
+}
+
+// Ignore the case where the argument to std::move() is a lambda parameter (and
+// thus not actually a parameter of the function template).
+template  void f7() {
+  [](U &&SomeU) { T SomeT(std::move(SomeU)); };
+}
+
+// Ignore the case where the argument is a lvalue reference.
+template  void f8(U &SomeU) {
+  T SomeT(std::move(SomeU));
+}
+
+// Ignore the case where the template parameter is a class template parameter
+// (i.e. no template argument deduction is taking place).
+template  class SomeClass {
+  void f(U &&SomeU) { T SomeT(std::move(SomeU)); }
+};
+
+// Ignore the case where the function parameter in the template isn't an rvalue
+// reference but the template argument is explicitly set to be an rvalue
+// reference.
+class A {};
+template  void foo(T);
+void f8() {
+  A a;
+  foo(std::move(a));
+}
+
+// A warning is output, but no fix is suggested, if a macro is used to rename
+// std::move.
+#define MOVE(x) std::move((x))
+template  void f9(U &&SomeU) {
+  T SomeT(MOVE(SomeU));
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: forwarding reference passed to
+}
+
+// Same result if the argument is passed outside of the macro.
+#undef MOVE
+#define MOVE std::move
+template  void f10(U &&SomeU) {
+  T SomeT(MOVE(SomeU));
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: forwarding reference passed to
+}
+
+// Same result if the macro does not include the "std" namespace.
+#undef MOVE
+#define MOVE move
+template  void f11(U &&SomeU) {
+  T SomeT(std::MOVE(SomeU));
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: forwarding reference passed to
+}
Index: docs/clang-tidy/checks/misc-move-forwarding-reference.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/misc-move-forwarding-reference.rst
@@ -0,0 +1,60 @@
+.. title:: clang-tidy - misc-move-forwarding-reference
+
+misc-move-forwarding-reference
+==
+
+Warns if ``std::move`` is called on a forwarding reference, for example:
+
+  .. code-block:: c++
+
+template 
+void foo(T&& t) {
+  bar(std::move(t));
+}
+
+`Forwarding references
+`_ should
+typically be passed to 

r277328 - scan-build: Add an option to show the description in the list of defect

2016-08-01 Thread Sylvestre Ledru via cfe-commits
Author: sylvestre
Date: Mon Aug  1 03:04:45 2016
New Revision: 277328

URL: http://llvm.org/viewvc/llvm-project?rev=277328&view=rev
Log:
scan-build: Add an option to show the description in the list of defect

Summary:
This patch adds an option //--show-description// to add the defect description 
to the list of defect. This helps to get a better understanding of the defect 
without opening the page.

For example, this is used for Firefox:
https://people.mozilla.org/~sledru/reports/fx-scan-build/

Reviewers: rizsotto.mailinglist, zaks.anna

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D22810

Modified:
cfe/trunk/tools/scan-build/bin/scan-build

Modified: cfe/trunk/tools/scan-build/bin/scan-build
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build/bin/scan-build?rev=277328&r1=277327&r2=277328&view=diff
==
--- cfe/trunk/tools/scan-build/bin/scan-build (original)
+++ cfe/trunk/tools/scan-build/bin/scan-build Mon Aug  1 03:04:45 2016
@@ -53,6 +53,7 @@ my %Options = (
   IgnoreErrors => 0, # Ignore build errors.
   ViewResults => 0,  # View results when the build terminates.
   ExitStatusFoundBugs => 0,  # Exit status reflects whether bugs were found
+  ShowDescription => 0,  # Display the description of the defect in the 
list
   KeepEmpty => 0,# Don't remove output directory even with 0 
results.
   EnableCheckers => {},
   DisableCheckers => {},
@@ -453,6 +454,10 @@ sub ScanFile {
 
   push @$Index,[ $FName, $BugCategory, $BugType, $BugFile, $BugFunction, 
$BugLine,
  $BugPathLength ];
+
+  if ($Options{ShowDescription}) {
+  push @{ $Index->[-1] }, $BugDescription
+  }
 }
 
 
####
@@ -746,6 +751,15 @@ print OUT [1];
+  print OUT $row->[1]; # $BugCategory
   print OUT "";
   print OUT "";
-  print OUT $row->[2];
+  print OUT $row->[2]; # $BugType
   print OUT "";
 
   # Update the file prefix.
@@ -802,11 +816,11 @@ ENDTEXT
   print OUT "";
 
   print OUT "";
-  print OUT $row->[4];
+  print OUT $row->[4]; # Function
   print OUT "";
 
   # Print out the quantities.
-  for my $j ( 5 .. 6 ) {
+  for my $j ( 5 .. 6 ) { # Line & Path length
 print OUT "$row->[$j]";
   }
 
@@ -1150,6 +1164,10 @@ OPTIONS:
Specify the title used on generated HTML pages. If not specified, a default
title will be used.
 
+ --show-description
+
+   Display the description of defects in the list
+
  -plist
 
By default the output of scan-build is a set of HTML files. This option
@@ -1586,6 +1604,12 @@ sub ProcessArgs {
   next;
 }
 
+if ($arg eq "--show-description") {
+  shift @$Args;
+  $Options{ShowDescription} = 1;
+  next;
+}
+
 if ($arg eq "-store") {
   shift @$Args;
   $Options{StoreModel} = shift @$Args;


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


Re: [PATCH] D22208: [clang-tidy] Fixes to modernize-use-emplace

2016-08-01 Thread Alexander Kornienko via cfe-commits
alexfh added inline comments.


Comment at: clang-tidy/modernize/UseEmplaceCheck.cpp:115
@@ -95,1 +114,3 @@
+  auto CtorCallSourceRange = CharSourceRange::getTokenRange(
+  InnerCtorCall->getExprLoc(), CallParensRange.getBegin());
 

Prazek wrote:
> alexfh wrote:
> > This doesn't seem to be an issue, since expression 
> > `v.push_back(obj.member())` won't trigger this check: it expects that the 
> > argument of the `push_back` call is a `cxxConstructExpr` or a 
> > `cxxFunctionalCastExpr`.
> what about the implicit conversion? What if obj.member would return object 
> that is different from the one that v stores, but it is convertible to it?
Sounds almost like a recipe for a test case ;) Have you tried to construct it 
this way?


https://reviews.llvm.org/D22208



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


Re: [PATCH] D22220: [clang-tidy] Add check 'misc-move-forwarding-reference'

2016-08-01 Thread Martin Böhme via cfe-commits
mboehme marked 7 inline comments as done.


Comment at: clang-tidy/misc/MoveForwardingReferenceCheck.cpp:93
@@ +92,3 @@
+   hasArgument(0, ignoringParenImpCasts(declRefExpr(
+  to(ForwardingReferenceParmMatcher)
+  .bind("call-move"),

sbenza wrote:
> aaron.ballman wrote:
> > I wonder if there's a reason for this behavior, or if it's simple a matter 
> > of not being needed previously and so it was never implemented. @sbenza or 
> > @klimek may know. I think we should be fixing the RecursiveASTVisitor, 
> > unless there is a valid reason not to (which there may be), though that 
> > would be a separate patch (and can happen after we land this one).
> Even if the nodes are not visited through the recursive visitor, you can 
> always have a matcher for it.
> Eg: `hasAnyConstructorInitializer` / `cxxCtorInitializer`.
> 
> But what node are you trying to visit here?
> The only node I see is `NamingClass`, which is not really a child node.
> Like the referred `Decl` in a `DeclRefExpr` is not a child either. You can't 
> use `has()` there, you have to use `to()`.
I've now reworked this to use new matchers (in review in D23004). Thanks for 
the comments, which finally got me on the right track!

> But what node are you trying to visit here?

I'm trying to visit the decls() in an OverloadExpr (this happened in 
isStdMove(), which is now deleted).

As you note, these intentionally aren't children of the OverloadExpr (so it 
doesn't make sense for the RecursiveASTMatcher to visit them), but it still 
makes sense to have a matchers for them -- which I've now added.


Comment at: clang-tidy/misc/MoveForwardingReferenceCheck.cpp:45-55
@@ +44,13 @@
+  // We still conservatively put a "std::" in front of the forward because
+  // we don't know whether the code also had a "using std::forward;".
+  Diag << FixItHint::CreateReplacement(CallRange, "std::" + ForwardName);
+} else if (const NamespaceDecl *Namespace = NNS->getAsNamespace()) {
+  if (Namespace->getName() == "std") {
+if (!NNS->getPrefix()) {
+  // Called as "std::move".
+  Diag << FixItHint::CreateReplacement(CallRange,
+   "std::" + ForwardName);
+} else if (NNS->getPrefix()->getKind() == NestedNameSpecifier::Global) 
{
+  // Called as "::std::move".
+  Diag << FixItHint::CreateReplacement(CallRange,
+   "::std::" + ForwardName);

I've changed the code to look at the NestedNameSpecifiers instead of looking at 
the original source text.

> But, at the same time, the check should be bomb proof for ugly cases like 
> [snip]

Apologies, I misunderstood -- I thought you were saying it should be bomb proof 
in the sense that it shouldn't suggest any replacement (and that's why I marked 
your comment done). Having read aaron.ballman's comment, I now realize what you 
meant is that the check should be bomb proof in the sense that it should create 
a correct fix even for such "ugly" cases.


https://reviews.llvm.org/D0



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


Re: [PATCH] D23004: [ASTMatchers] Add matchers canReferToDecl() and hasUnderlyingDecl()

2016-08-01 Thread Martin Böhme via cfe-commits
mboehme added a comment.

Retracting from review for the moment. Tests fail to compile (embarrasingly 
enough, I ran the wrong test suite -- apologies).


https://reviews.llvm.org/D23004



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


Re: [PATCH] D22514: CloneDetection now respects statement specific data when searching for clones.

2016-08-01 Thread Artem Dergachev via cfe-commits
NoQ added a comment.

Congrats on the fantastic hack that nobody else noticed! I've a feeling we 
cannot add tests for that, because any test would quickly break if we change 
the hash, though demonstrating that we fixed the problem would still be cool 
(eg. take two unsupported expressions of different kind but same type, and show 
that they're no longer reported).

One more minor comment.



Comment at: lib/Analysis/CloneDetection.cpp:127
@@ +126,3 @@
+// Initialize the last bytes that are maybe not fully overwritten.
+CollectedData.back() = 0;
+

I think `resize()` zero-initializes the whole new data(?)


Comment at: lib/Analysis/CloneDetection.cpp:142
@@ +141,3 @@
+CODE;  
\
+ConstStmtVisitor::Visit##CLASS(S);  
\
+  }

This is... Beautiful... oo
/Approves.


https://reviews.llvm.org/D22514



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


Re: [PATCH] D22729: MPIBufferDerefCheck for Clang-Tidy

2016-08-01 Thread Haojian Wu via cfe-commits
hokein added a comment.

Looks like the dependency of this patch https://reviews.llvm.org/D21962 got 
reverted by some reasons.



Comment at: clang-tidy/mpi/BufferDerefCheck.cpp:63
@@ +62,3 @@
+if (FuncClassifier.isReduceType(Identifier)) {
+  addBuffer(0);
+  addBuffer(1);

Could you add some comments to describe what these statements do? It's confused 
when reading the magic number parameter. The same below.


Comment at: clang-tidy/mpi/BufferDerefCheck.cpp:109
@@ +108,3 @@
+  std::string IndirectionDesc;
+  for (int i = Indirections.size() - 1; i >= 0; --i) {
+if (Indirections[i] == IndirectionType::Pointer) {

size_t


https://reviews.llvm.org/D22729



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


Re: [PATCH] D22940: [OpenCL] Handle -cl-fp32-correctly-rounded-divide-sqrt

2016-08-01 Thread Nikolay Haustov via cfe-commits
nhaustov accepted this revision.
nhaustov added a comment.
This revision is now accepted and ready to land.

Ok.


https://reviews.llvm.org/D22940



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


[PATCH] D23006: [clang-rename] add basic Emacs integration

2016-08-01 Thread Kirill Bobyrev via cfe-commits
omtcyfz created this revision.
omtcyfz added reviewers: bkramer, alexfh, klimek.
omtcyfz added a subscriber: cfe-commits.

This patch aims to add very basic Emacs integration. My experience with Emacs 
is limited to few days, so I'm not sure whether I've done things correctly.

https://reviews.llvm.org/D23006

Files:
  clang-rename/tool/clang-rename.el

Index: clang-rename/tool/clang-rename.el
===
--- /dev/null
+++ clang-rename/tool/clang-rename.el
@@ -0,0 +1,46 @@
+;;; clang-rename.el --- Renames every occurrence of a symbol found at .
+
+;; Keywords: tools, c
+
+;;; Commentary:
+
+;; This package allows to filter code through clang-format to fix its 
formatting.
+;; clang-format is a tool that formats C/C++/Obj-C code according to a set of
+;; style options, see 
.
+;; Note that clang-format 3.4 or newer is required.
+
+;; To install clang-rename.el make sure the directory of this file is in your
+;; 'load-path' and add
+;;
+;;   (require 'clang-rename)
+;;
+;; to your .emacs configureation.
+
+;;; Code:
+
+(defvar clang-rename-binary "clang-rename")
+
+(defun clang-rename (new-name)
+  "Rename all instances of the symbol at the point using clang-rename"
+  (interactive "sEnter a new name: ")
+  (let (;; Emacs offset is 1-based.
+(offset (- (point) 1))
+(orig-buf (current-buffer))
+(file-name (buffer-file-name)))
+
+(let ((rename-command
+  (format "bash -f -c '%s -offset=%s -new-name=%s -i %s'"
+   clang-rename-binary offset new-name file-name)))
+  (message (format "Running clang-rename command %s" rename-command))
+  ;; Run clang-rename via bash.
+  (shell-command rename-command)
+  ;; Reload buffer.
+  (interactive)
+  (revert-buffer t t)
+)
+  )
+)
+
+(provide 'clang-rename)
+
+;;; clang-rename.el ends here


Index: clang-rename/tool/clang-rename.el
===
--- /dev/null
+++ clang-rename/tool/clang-rename.el
@@ -0,0 +1,46 @@
+;;; clang-rename.el --- Renames every occurrence of a symbol found at .
+
+;; Keywords: tools, c
+
+;;; Commentary:
+
+;; This package allows to filter code through clang-format to fix its formatting.
+;; clang-format is a tool that formats C/C++/Obj-C code according to a set of
+;; style options, see .
+;; Note that clang-format 3.4 or newer is required.
+
+;; To install clang-rename.el make sure the directory of this file is in your
+;; 'load-path' and add
+;;
+;;   (require 'clang-rename)
+;;
+;; to your .emacs configureation.
+
+;;; Code:
+
+(defvar clang-rename-binary "clang-rename")
+
+(defun clang-rename (new-name)
+  "Rename all instances of the symbol at the point using clang-rename"
+  (interactive "sEnter a new name: ")
+  (let (;; Emacs offset is 1-based.
+(offset (- (point) 1))
+(orig-buf (current-buffer))
+(file-name (buffer-file-name)))
+
+(let ((rename-command
+  (format "bash -f -c '%s -offset=%s -new-name=%s -i %s'"
+   clang-rename-binary offset new-name file-name)))
+  (message (format "Running clang-rename command %s" rename-command))
+  ;; Run clang-rename via bash.
+  (shell-command rename-command)
+  ;; Reload buffer.
+  (interactive)
+  (revert-buffer t t)
+)
+  )
+)
+
+(provide 'clang-rename)
+
+;;; clang-rename.el ends here
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D22982: [CloneDetector] No longer reporting clones that don't have a common referenced variable pattern.

2016-08-01 Thread Artem Dergachev via cfe-commits
NoQ added a comment.

Uhm. I've a feeling that now i realize how it should have been written from the 
start. That's a pretty bad feeling to have.

I wish we had a //series of passes//. Before the first pass, all statements are 
considered equivalent. After the first pass, they're split into smaller clone 
groups. The second pass would add further distinction between items in each 
clone group, producing more clone groups. Etc. Every subsequent pass would 
compute more performance-intensive properties of statement sequences (the first 
pass being very simple, eg. only statement kinds). Once all passes end, only 
true positives remain. Probably wrap up each pass into a class that conforms to 
some common interface, and we're done with a nicely structured and 
easy-to-extend copy-paste error detection framework. We could probably even 
allow the user to turn separate passes on and off through some kind of dynamic 
registry.

Never mind though, will have a look at what we have :)


https://reviews.llvm.org/D22982



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


Re: [PATCH] D23004: [ASTMatchers] Add matchers canReferToDecl() and hasUnderlyingDecl()

2016-08-01 Thread Martin Böhme via cfe-commits
mboehme added reviewers: sbenza, aaron.ballman.
mboehme updated this revision to Diff 66291.
mboehme added a comment.

Updated test and documentation for hasUnderlyingDecl() to use using 
declarations instead of typedefs. (I made the mistaken assumption that 
getUnderlyingDecl() would also work on a typdef and didn't catch the mistake 
because I ran the wrong tests.)


https://reviews.llvm.org/D23004

Files:
  docs/LibASTMatchersReference.html
  include/clang/ASTMatchers/ASTMatchers.h
  lib/ASTMatchers/Dynamic/Registry.cpp
  unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Index: unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -241,6 +241,21 @@
 hasDeclaration(namedDecl(hasName("A";
 }
 
+TEST(HasUnderlyingDecl, Matches) {
+  EXPECT_TRUE(matches("namespace N { template  void f(T t); }"
+  "template  void g() { using N::f; f(T()); }",
+  unresolvedLookupExpr(canReferToDecl(
+  namedDecl(hasUnderlyingDecl(hasName("::N::f")));
+  EXPECT_TRUE(matches(
+  "namespace N { template  void f(T t); }"
+  "template  void g() { N::f(T()); }",
+  unresolvedLookupExpr(canReferToDecl(namedDecl(hasName("::N::f"));
+  EXPECT_TRUE(notMatches(
+  "namespace N { template  void f(T t); }"
+  "template  void g() { using N::f; f(T()); }",
+  unresolvedLookupExpr(canReferToDecl(namedDecl(hasName("::N::f"));
+}
+
 TEST(HasType, TakesQualTypeMatcherAndMatchesExpr) {
   TypeMatcher ClassX = hasDeclaration(recordDecl(hasName("X")));
   EXPECT_TRUE(
@@ -2051,5 +2066,24 @@
   EXPECT_TRUE(notMatches(Code2, ForEachOverriddenInClass("A1")));
 }
 
+TEST(Matcher, CanReferToDecl) {
+  std::string Fragment = "void foo(int p1);"
+ "void foo(int *p2);"
+ "void bar(int p3);"
+ "template  void baz(T t) { foo(t); }";
+
+  EXPECT_TRUE(
+  matches(Fragment, unresolvedLookupExpr(canReferToDecl(functionDecl(
+hasParameter(0, parmVarDecl(hasName("p1";
+  EXPECT_TRUE(
+  matches(Fragment, unresolvedLookupExpr(canReferToDecl(functionDecl(
+hasParameter(0, parmVarDecl(hasName("p2";
+  EXPECT_TRUE(
+  notMatches(Fragment, unresolvedLookupExpr(canReferToDecl(functionDecl(
+   hasParameter(0, parmVarDecl(hasName("p3";
+  EXPECT_TRUE(notMatches(Fragment, unresolvedLookupExpr(canReferToDecl(
+   functionDecl(hasName("bar"));
+}
+
 } // namespace ast_matchers
 } // namespace clang
Index: lib/ASTMatchers/Dynamic/Registry.cpp
===
--- lib/ASTMatchers/Dynamic/Registry.cpp
+++ lib/ASTMatchers/Dynamic/Registry.cpp
@@ -115,6 +115,7 @@
   REGISTER_MATCHER(breakStmt);
   REGISTER_MATCHER(builtinType);
   REGISTER_MATCHER(callExpr);
+  REGISTER_MATCHER(canReferToDecl);
   REGISTER_MATCHER(caseStmt);
   REGISTER_MATCHER(castExpr);
   REGISTER_MATCHER(characterLiteral);
@@ -265,6 +266,7 @@
   REGISTER_MATCHER(hasTypeLoc);
   REGISTER_MATCHER(hasUnaryOperand);
   REGISTER_MATCHER(hasUnarySelector);
+  REGISTER_MATCHER(hasUnderlyingDecl);
   REGISTER_MATCHER(hasValueType);
   REGISTER_MATCHER(ifStmt);
   REGISTER_MATCHER(ignoringImplicit);
Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -2422,6 +2422,25 @@
   void(internal::HasDeclarationSupportedTypes)>(InnerMatcher);
 }
 
+/// \brief Matches a \c NamedDecl whose underlying declaration matches the given
+/// matcher.
+///
+/// Given
+/// \code
+///   namespace N { template void f(T t); }
+///   template  void g() { using N::f; f(T()); }
+/// \endcode
+/// \c unresolvedLookupExpr(canReferToDecl(
+/// namedDecl(hasUnderlyingDecl(hasName("::N::f")
+///   matches the use of \c f in \c g() .
+AST_MATCHER_P(NamedDecl, hasUnderlyingDecl, internal::Matcher,
+  InnerMatcher) {
+  const NamedDecl *UnderlyingDecl = Node.getUnderlyingDecl();
+
+  return (UnderlyingDecl != nullptr &&
+  InnerMatcher.matches(*UnderlyingDecl, Finder, Builder));
+}
+
 /// \brief Matches on the implicit object argument of a member call expression.
 ///
 /// Example matches y.x()
@@ -2777,6 +2796,22 @@
   return false;
 }
 
+/// \brief Matches any \c Decl of an \c OverloadExpr that matches the given
+/// matcher.
+///
+/// Given
+/// \code
+///   void foo(int);
+///   template  void bar(T t) { foo(t); }
+/// \endcode
+/// unresolvedLookupExpr(canReferToDecl(functionDecl()))
+///   matches \c foo in \c foo(t);
+AST_MATCHER_P(OverloadExpr, canReferToDecl, internal::Matche

Re: [PATCH] D23006: [clang-rename] add basic Emacs integration

2016-08-01 Thread Kirill Bobyrev via cfe-commits
omtcyfz updated this revision to Diff 66292.
omtcyfz added a comment.

Update docs by adding information about Emacs integration.


https://reviews.llvm.org/D23006

Files:
  clang-rename/tool/clang-rename.el
  docs/clang-rename.rst

Index: docs/clang-rename.rst
===
--- docs/clang-rename.rst
+++ docs/clang-rename.rst
@@ -28,7 +28,7 @@
 work with if you set up a compile command database for your project (for an
 example of how to do this see `How To Setup Tooling For LLVM
 `_). You can also
-specify compilation options on the command line after ``--``:
+specify compilation options on the command line after `--`:
 
 .. code-block:: console
 
@@ -47,7 +47,7 @@
 renaming actions in the future.
 
 :program:`clang-rename` also aims to be easily integrated into popular text
-editors, such as Vim, and improve the workflow of users.
+editors, such as Vim and Emacs, and improve the workflow of users.
 
 Although a command line interface exists, it is highly recommended to use the
 text editor interface instead for better experience.
@@ -96,7 +96,22 @@
 happen before running the tool**.
 
 Once installed, you can point your cursor to symbols you want to rename, press
-``cr`` and print new desired name. The
-[`` 
key``](http://vim.wikia.com/wiki/Mapping_keys_in_Vim_-_Tutorial_(Part_3)#Map_leader)
+`cr` and print new desired name. The
+[` key`]
+(http://vim.wikia.com/wiki/Mapping_keys_in_Vim_-_Tutorial_(Part_3)#Map_leader)
 is a reference to a specific key defined by the mapleader variable and is bound
 to backslash by default.
+
+clang-rename Emacs integration
+
+
+You can also use :program:`clang-rename` while using Emacs! To set up
+:program:`clang-rename` integration for Emacs see
+`clang-rename/tool/clang-rename.el
+`_.
+
+Once installed, you can point your cursor to symbols you want to rename, press
+`M-X`, print `clang-rename` and new desired name.
+
+Please note that **you have to save all buffers, in which the replacement will
+happen before running the tool**.
Index: clang-rename/tool/clang-rename.el
===
--- /dev/null
+++ clang-rename/tool/clang-rename.el
@@ -0,0 +1,46 @@
+;;; clang-rename.el --- Renames every occurrence of a symbol found at .
+
+;; Keywords: tools, c
+
+;;; Commentary:
+
+;; This package allows to filter code through clang-format to fix its 
formatting.
+;; clang-format is a tool that formats C/C++/Obj-C code according to a set of
+;; style options, see 
.
+;; Note that clang-format 3.4 or newer is required.
+
+;; To install clang-rename.el make sure the directory of this file is in your
+;; 'load-path' and add
+;;
+;;   (require 'clang-rename)
+;;
+;; to your .emacs configureation.
+
+;;; Code:
+
+(defvar clang-rename-binary "clang-rename")
+
+(defun clang-rename-upstream (new-name)
+  "Rename all instances of the symbol at the point using clang-rename"
+  (interactive "sEnter a new name: ")
+  (let (;; Emacs offset is 1-based.
+(offset (- (point) 1))
+(orig-buf (current-buffer))
+(file-name (buffer-file-name)))
+
+(let ((rename-command
+  (format "bash -f -c '%s -offset=%s -new-name=%s -i %s'"
+   clang-rename-binary offset new-name file-name)))
+  (message (format "Running clang-rename command %s" rename-command))
+  ;; Run clang-rename via bash.
+  (shell-command rename-command)
+  ;; Reload buffer.
+  (interactive)
+  (revert-buffer t t)
+)
+  )
+)
+
+(provide 'clang-rename-upstream)
+
+;;; clang-rename.el ends here


Index: docs/clang-rename.rst
===
--- docs/clang-rename.rst
+++ docs/clang-rename.rst
@@ -28,7 +28,7 @@
 work with if you set up a compile command database for your project (for an
 example of how to do this see `How To Setup Tooling For LLVM
 `_). You can also
-specify compilation options on the command line after ``--``:
+specify compilation options on the command line after `--`:
 
 .. code-block:: console
 
@@ -47,7 +47,7 @@
 renaming actions in the future.
 
 :program:`clang-rename` also aims to be easily integrated into popular text
-editors, such as Vim, and improve the workflow of users.
+editors, such as Vim and Emacs, and improve the workflow of users.
 
 Although a command line interface exists, it is highly recommended to use the
 text editor interface instead for better experience.
@@ -96,7 +96,22 @@
 happen before running the tool**.
 
 Once installed, you can point your cursor to symbols you want to rename, press
-``cr`` and print new desired name. The
-[`` key

Re: [PATCH] D22513: [clang-tidy] add check cppcoreguidelines-special-member-functions

2016-08-01 Thread Eric Lemanissier via cfe-commits
ericLemanissier added a comment.

I have an segfault on all the source files of my project when I enable this 
check (it works ok when I disable this check). Sorry I don't have time to post 
a minimal source file producing the segfault. I will maybe tomorrow, or in two 
weeks.


Repository:
  rL LLVM

https://reviews.llvm.org/D22513



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


Re: [PATCH] D23006: [clang-rename] add basic Emacs integration

2016-08-01 Thread Manuel Klimek via cfe-commits
klimek added inline comments.


Comment at: clang-rename/tool/clang-rename.el:7
@@ +6,3 @@
+
+;; This package allows to filter code through clang-format to fix its 
formatting.
+;; clang-format is a tool that formats C/C++/Obj-C code according to a set of

s/clang-format/clang-rename/, and fix docs in general :)


Comment at: clang-rename/tool/clang-rename.el:17
@@ +16,3 @@
+;;
+;; to your .emacs configureation.
+

Typo.


https://reviews.llvm.org/D23006



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


Re: [PATCH] D21749: Changes related to new implementation of tooling::Replacements as class.

2016-08-01 Thread Eric Liu via cfe-commits
ioeric updated this revision to Diff 66295.
ioeric added a comment.

- merged with origin/master


https://reviews.llvm.org/D21749

Files:
  
clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h
  clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
  clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
  clang-rename/RenamingAction.cpp
  clang-rename/RenamingAction.h
  clang-rename/tool/ClangRename.cpp
  clang-tidy/ClangTidyDiagnosticConsumer.cpp
  include-fixer/IncludeFixer.cpp
  include-fixer/tool/ClangIncludeFixer.cpp
  tool-template/ToolTemplate.cpp
  unittests/clang-tidy/ClangTidyTest.h

Index: unittests/clang-tidy/ClangTidyTest.h
===
--- unittests/clang-tidy/ClangTidyTest.h
+++ unittests/clang-tidy/ClangTidyTest.h
@@ -119,7 +119,14 @@
   DiagConsumer.finish();
   tooling::Replacements Fixes;
   for (const ClangTidyError &Error : Context.getErrors())
-Fixes.insert(Error.Fix.begin(), Error.Fix.end());
+for (const auto &Fix : Error.Fix) {
+  auto Err = Fixes.add(Fix);
+  // FIXME: better error handling. Keep the behavior for now.
+  if (Err) {
+llvm::errs() << llvm::toString(std::move(Err)) << "\n";
+return "";
+  }
+}
   if (Errors)
 *Errors = Context.getErrors();
   auto Result = tooling::applyAllReplacements(Code, Fixes);
Index: tool-template/ToolTemplate.cpp
===
--- tool-template/ToolTemplate.cpp
+++ tool-template/ToolTemplate.cpp
@@ -53,18 +53,20 @@
 
 namespace {
 class ToolTemplateCallback : public MatchFinder::MatchCallback {
- public:
-  ToolTemplateCallback(Replacements *Replace) : Replace(Replace) {}
+public:
+  ToolTemplateCallback(std::map *Replace)
+  : Replace(Replace) {}
 
   void run(const MatchFinder::MatchResult &Result) override {
-// TODO: This routine will get called for each thing that the matchers find.
+// TODO: This routine will get called for each thing that the matchers
+// find.
 // At this point, you can examine the match, and do whatever you want,
 // including replacing the matched text with other text
 (void)Replace; // This to prevent an "unused member variable" warning;
   }
 
- private:
-  Replacements *Replace;
+private:
+  std::map *Replace;
 };
 } // end anonymous namespace
 
Index: include-fixer/tool/ClangIncludeFixer.cpp
===
--- include-fixer/tool/ClangIncludeFixer.cpp
+++ include-fixer/tool/ClangIncludeFixer.cpp
@@ -350,8 +350,8 @@
   }
 
   if (!Quiet)
-errs() << "Added #include " << Context.getHeaderInfos().front().Header
-   << '\n';
+llvm::errs() << "Added #include " << Context.getHeaderInfos().front().Header
+ << "\n";
 
   // Set up a new source manager for applying the resulting replacements.
   IntrusiveRefCntPtr DiagOpts(new DiagnosticOptions);
Index: include-fixer/IncludeFixer.cpp
===
--- include-fixer/IncludeFixer.cpp
+++ include-fixer/IncludeFixer.cpp
@@ -352,23 +352,36 @@
   std::string IncludeName =
   "#include " + Context.getHeaderInfos().front().Header + "\n";
   // Create replacements for the new header.
-  clang::tooling::Replacements Insertions = {
-  tooling::Replacement(FilePath, UINT_MAX, 0, IncludeName)};
+  clang::tooling::Replacements Insertions;
+  auto Err =
+  Insertions.add(tooling::Replacement(FilePath, UINT_MAX, 0, IncludeName));
+  if (Err)
+return std::move(Err);
 
   auto CleanReplaces = cleanupAroundReplacements(Code, Insertions, Style);
   if (!CleanReplaces)
 return CleanReplaces;
 
+  auto Replaces = std::move(*CleanReplaces);
   if (AddQualifiers) {
 for (const auto &Info : Context.getQuerySymbolInfos()) {
   // Ignore the empty range.
-  if (Info.Range.getLength() > 0)
-CleanReplaces->insert({FilePath, Info.Range.getOffset(),
-   Info.Range.getLength(),
-   Context.getHeaderInfos().front().QualifiedName});
+  if (Info.Range.getLength() > 0) {
+auto R = tooling::Replacement(
+{FilePath, Info.Range.getOffset(), Info.Range.getLength(),
+ Context.getHeaderInfos().front().QualifiedName});
+auto Err = Replaces.add(R);
+if (Err) {
+  llvm::consumeError(std::move(Err));
+  R = tooling::Replacement(
+  R.getFilePath(), Replaces.getShiftedCodePosition(R.getOffset()),
+  R.getLength(), R.getReplacementText());
+  Replaces = Replaces.merge(tooling::Replacements(R));
+}
+  }
 }
   }
-  return formatReplacements(Code, *CleanReplaces, Style);
+  return formatReplacements(Code, Replaces, Style);
 }
 
 } // namespace include_fixer
Index: clang-tidy/ClangTidyDiagnosticConsumer.cpp
===

Re: [PATCH] D21748: Implement tooling::Replacements as a class.

2016-08-01 Thread Eric Liu via cfe-commits
ioeric updated this revision to Diff 66294.
ioeric added a comment.

- Merge branch 'master' of http://llvm.org/git/clang into replace


https://reviews.llvm.org/D21748

Files:
  include/clang/Tooling/Core/Replacement.h
  include/clang/Tooling/Refactoring.h
  lib/Format/Format.cpp
  lib/Format/SortJavaScriptImports.cpp
  lib/Format/TokenAnalyzer.cpp
  lib/Format/WhitespaceManager.cpp
  lib/Tooling/Core/Replacement.cpp
  lib/Tooling/Refactoring.cpp
  lib/Tooling/RefactoringCallbacks.cpp
  tools/clang-format/ClangFormat.cpp
  unittests/Format/CleanupTest.cpp
  unittests/Format/FormatTest.cpp
  unittests/Tooling/RefactoringTest.cpp
  unittests/Tooling/ReplacementTest.h
  unittests/Tooling/RewriterTest.cpp

Index: unittests/Tooling/RewriterTest.cpp
===
--- unittests/Tooling/RewriterTest.cpp
+++ unittests/Tooling/RewriterTest.cpp
@@ -39,8 +39,11 @@
 
 TEST(Rewriter, AdjacentInsertAndDelete) {
   Replacements Replaces;
-  Replaces.insert(Replacement("", 6, 6, ""));
-  Replaces.insert(Replacement("", 6, 0, "replaced\n"));
+  auto Err = Replaces.add(Replacement("", 6, 6, ""));
+  EXPECT_TRUE(!Err);
+  Replaces =
+  Replaces.merge(Replacements(Replacement("", 6, 0, "replaced\n")));
+
   auto Rewritten = applyAllReplacements("line1\nline2\nline3\nline4", Replaces);
   EXPECT_TRUE(static_cast(Rewritten));
   EXPECT_EQ("line1\nreplaced\nline3\nline4", *Rewritten);
Index: unittests/Tooling/ReplacementTest.h
===
--- /dev/null
+++ unittests/Tooling/ReplacementTest.h
@@ -0,0 +1,56 @@
+//===- unittest/Tooling/ReplacementTest.h - Replacements related test--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+//  This file defines utility class and function for Replacement related tests.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_UNITTESTS_TOOLING_REPLACEMENTTESTBASE_H
+#define LLVM_CLANG_UNITTESTS_TOOLING_REPLACEMENTTESTBASE_H
+
+#include "RewriterTestContext.h"
+#include "clang/Tooling/Core/Replacement.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace tooling {
+
+/// \brief Converts a set of replacements to Replacements class.
+/// \return A Replacements class containing \p Replaces on success; otherwise,
+/// an empty Replacements is returned.
+static tooling::Replacements
+toReplacements(const std::set &Replaces) {
+  tooling::Replacements Result;
+  for (const auto &R : Replaces) {
+auto Err = Result.add(R);
+EXPECT_TRUE(!Err);
+if (Err) {
+  llvm::errs() << llvm::toString(std::move(Err)) << "\n";
+  return tooling::Replacements();
+}
+  }
+  return Result;
+}
+
+/// \brief A utility class for replacement related tests.
+class ReplacementTest : public ::testing::Test {
+protected:
+  tooling::Replacement createReplacement(SourceLocation Start, unsigned Length,
+ llvm::StringRef ReplacementText) {
+return tooling::Replacement(Context.Sources, Start, Length,
+ReplacementText);
+  }
+
+  RewriterTestContext Context;
+};
+
+} // namespace tooling
+} // namespace clang
+
+#endif // LLVM_CLANG_UNITTESTS_TOOLING_REPLACEMENTTESTBASE_H
Index: unittests/Tooling/RefactoringTest.cpp
===
--- unittests/Tooling/RefactoringTest.cpp
+++ unittests/Tooling/RefactoringTest.cpp
@@ -7,6 +7,7 @@
 //
 //===--===//
 
+#include "ReplacementTest.h"
 #include "RewriterTestContext.h"
 #include "clang/AST/ASTConsumer.h"
 #include "clang/AST/ASTContext.h"
@@ -31,16 +32,6 @@
 namespace clang {
 namespace tooling {
 
-class ReplacementTest : public ::testing::Test {
- protected:
-  Replacement createReplacement(SourceLocation Start, unsigned Length,
-llvm::StringRef ReplacementText) {
-return Replacement(Context.Sources, Start, Length, ReplacementText);
-  }
-
-  RewriterTestContext Context;
-};
-
 TEST_F(ReplacementTest, CanDeleteAllText) {
   FileID ID = Context.createInMemoryFile("input.cpp", "text");
   SourceLocation Location = Context.getLocation(ID, 1, 1);
@@ -108,62 +99,59 @@
   EXPECT_TRUE(Replace2.getFilePath().empty());
 }
 
-TEST_F(ReplacementTest, CanApplyReplacements) {
-  FileID ID = Context.createInMemoryFile("input.cpp",
- "line1\nline2\nline3\nline4");
+TEST_F(ReplacementTest, FailAddReplacements) {
   Replacements Replaces;
-  Replaces.insert(Replacement(Context.Sources, Context.getLocation(ID, 2, 1),
-  5, "replaced"));
-  Replaces.insert(Replacement(Context.Sources, Contex

Re: [PATCH] D22903: [clang-tidy] Prepare modernize-loop-convert for upcoming changes in D22566

2016-08-01 Thread Manuel Klimek via cfe-commits
klimek accepted this revision.
klimek added a comment.
This revision is now accepted and ready to land.

lg


https://reviews.llvm.org/D22903



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


Re: [PATCH] D23006: [clang-rename] add basic Emacs integration

2016-08-01 Thread Kirill Bobyrev via cfe-commits
omtcyfz added inline comments.


Comment at: clang-rename/tool/clang-rename.el:7
@@ +6,3 @@
+
+;; This package allows to filter code through clang-format to fix its 
formatting.
+;; clang-format is a tool that formats C/C++/Obj-C code according to a set of

klimek wrote:
> s/clang-format/clang-rename/, and fix docs in general :)
Aw, yeah. This block was just copied :D


https://reviews.llvm.org/D23006



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


Re: [PATCH] D23006: [clang-rename] add basic Emacs integration

2016-08-01 Thread Kirill Bobyrev via cfe-commits
omtcyfz updated this revision to Diff 66296.
omtcyfz marked 2 inline comments as done.

https://reviews.llvm.org/D23006

Files:
  clang-rename/tool/clang-rename.el
  docs/clang-rename.rst

Index: docs/clang-rename.rst
===
--- docs/clang-rename.rst
+++ docs/clang-rename.rst
@@ -28,7 +28,7 @@
 work with if you set up a compile command database for your project (for an
 example of how to do this see `How To Setup Tooling For LLVM
 `_). You can also
-specify compilation options on the command line after ``--``:
+specify compilation options on the command line after `--`:
 
 .. code-block:: console
 
@@ -47,7 +47,7 @@
 renaming actions in the future.
 
 :program:`clang-rename` also aims to be easily integrated into popular text
-editors, such as Vim, and improve the workflow of users.
+editors, such as Vim and Emacs, and improve the workflow of users.
 
 Although a command line interface exists, it is highly recommended to use the
 text editor interface instead for better experience.
@@ -96,7 +96,22 @@
 happen before running the tool**.
 
 Once installed, you can point your cursor to symbols you want to rename, press
-``cr`` and print new desired name. The
-[`` 
key``](http://vim.wikia.com/wiki/Mapping_keys_in_Vim_-_Tutorial_(Part_3)#Map_leader)
+`cr` and print new desired name. The
+[` key`]
+(http://vim.wikia.com/wiki/Mapping_keys_in_Vim_-_Tutorial_(Part_3)#Map_leader)
 is a reference to a specific key defined by the mapleader variable and is bound
 to backslash by default.
+
+clang-rename Emacs integration
+
+
+You can also use :program:`clang-rename` while using Emacs! To set up
+:program:`clang-rename` integration for Emacs see
+`clang-rename/tool/clang-rename.el
+`_.
+
+Once installed, you can point your cursor to symbols you want to rename, press
+`M-X`, print `clang-rename` and new desired name.
+
+Please note that **you have to save all buffers, in which the replacement will
+happen before running the tool**.
Index: clang-rename/tool/clang-rename.el
===
--- /dev/null
+++ clang-rename/tool/clang-rename.el
@@ -0,0 +1,41 @@
+;;; clang-rename.el --- Renames every occurrence of a symbol found at .
+
+;; Keywords: tools, c
+
+;;; Commentary:
+
+;; To install clang-rename.el make sure the directory of this file is in your
+;; 'load-path' and add
+;;
+;;   (require 'clang-rename)
+;;
+;; to your .emacs configuration.
+
+;;; Code:
+
+(defvar clang-rename-binary "clang-rename")
+
+(defun clang-rename-upstream (new-name)
+  "Rename all instances of the symbol at the point using clang-rename"
+  (interactive "sEnter a new name: ")
+  (let (;; Emacs offset is 1-based.
+(offset (- (point) 1))
+(orig-buf (current-buffer))
+(file-name (buffer-file-name)))
+
+(let ((rename-command
+  (format "bash -f -c '%s -offset=%s -new-name=%s -i %s'"
+   clang-rename-binary offset new-name file-name)))
+  (message (format "Running clang-rename command %s" rename-command))
+  ;; Run clang-rename via bash.
+  (shell-command rename-command)
+  ;; Reload buffer.
+  (interactive)
+  (revert-buffer t t)
+)
+  )
+)
+
+(provide 'clang-rename-upstream)
+
+;;; clang-rename.el ends here


Index: docs/clang-rename.rst
===
--- docs/clang-rename.rst
+++ docs/clang-rename.rst
@@ -28,7 +28,7 @@
 work with if you set up a compile command database for your project (for an
 example of how to do this see `How To Setup Tooling For LLVM
 `_). You can also
-specify compilation options on the command line after ``--``:
+specify compilation options on the command line after `--`:
 
 .. code-block:: console
 
@@ -47,7 +47,7 @@
 renaming actions in the future.
 
 :program:`clang-rename` also aims to be easily integrated into popular text
-editors, such as Vim, and improve the workflow of users.
+editors, such as Vim and Emacs, and improve the workflow of users.
 
 Although a command line interface exists, it is highly recommended to use the
 text editor interface instead for better experience.
@@ -96,7 +96,22 @@
 happen before running the tool**.
 
 Once installed, you can point your cursor to symbols you want to rename, press
-``cr`` and print new desired name. The
-[`` key``](http://vim.wikia.com/wiki/Mapping_keys_in_Vim_-_Tutorial_(Part_3)#Map_leader)
+`cr` and print new desired name. The
+[` key`]
+(http://vim.wikia.com/wiki/Mapping_keys_in_Vim_-_Tutorial_(Part_3)#Map_leader)
 is a reference to a specific key defined by the mapleader variable and is bound
 to backslash by default.
+
+clang-rename Emacs integra

r277334 - Allow .exe extension to ld to fix test with mingw.

2016-08-01 Thread Yaron Keren via cfe-commits
Author: yrnkrn
Date: Mon Aug  1 05:14:54 2016
New Revision: 277334

URL: http://llvm.org/viewvc/llvm-project?rev=277334&view=rev
Log:
Allow .exe extension to ld to fix test with mingw.


Modified:
cfe/trunk/test/Driver/offloading-interoperability.c

Modified: cfe/trunk/test/Driver/offloading-interoperability.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/offloading-interoperability.c?rev=277334&r1=277333&r2=277334&view=diff
==
--- cfe/trunk/test/Driver/offloading-interoperability.c (original)
+++ cfe/trunk/test/Driver/offloading-interoperability.c Mon Aug  1 05:14:54 2016
@@ -14,4 +14,4 @@
 // NO-OPENMP-FLAGS-FOR-CUDA-DEVICE-NEXT: fatbinary" "--cuda" "-64"
 // NO-OPENMP-FLAGS-FOR-CUDA-DEVICE-NEXT: clang{{.*}}" "-cc1" "-triple" 
"powerpc64le--linux-gnu"
 // NO-OPENMP-FLAGS-FOR-CUDA-DEVICE:  -fopenmp
-// NO-OPENMP-FLAGS-FOR-CUDA-DEVICE-NEXT: ld" {{.*}}"-m" "elf64lppc"
+// NO-OPENMP-FLAGS-FOR-CUDA-DEVICE-NEXT: {{ld(.exe)?"}} {{.*}}"-m" "elf64lppc"


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


r277335 - Implement tooling::Replacements as a class.

2016-08-01 Thread Eric Liu via cfe-commits
Author: ioeric
Date: Mon Aug  1 05:16:37 2016
New Revision: 277335

URL: http://llvm.org/viewvc/llvm-project?rev=277335&view=rev
Log:
Implement tooling::Replacements as a class.

Summary:
- Implement clang::tooling::Replacements as a class to provide interfaces to
  control how replacements for a single file are combined and provide guarantee
  on the order of replacements being applied.
- tooling::Replacements only contains replacements for the same file now.
  Use std::map to represent multi-file
  replacements.
- Error handling for the interface change will be improved in followup patches.

Reviewers: djasper, klimek

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D21748

Added:
cfe/trunk/unittests/Tooling/ReplacementTest.h
Modified:
cfe/trunk/include/clang/Tooling/Core/Replacement.h
cfe/trunk/include/clang/Tooling/Refactoring.h
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/lib/Format/SortJavaScriptImports.cpp
cfe/trunk/lib/Format/TokenAnalyzer.cpp
cfe/trunk/lib/Format/WhitespaceManager.cpp
cfe/trunk/lib/Tooling/Core/Replacement.cpp
cfe/trunk/lib/Tooling/Refactoring.cpp
cfe/trunk/lib/Tooling/RefactoringCallbacks.cpp
cfe/trunk/tools/clang-format/ClangFormat.cpp
cfe/trunk/unittests/Format/CleanupTest.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
cfe/trunk/unittests/Tooling/RefactoringTest.cpp
cfe/trunk/unittests/Tooling/RewriterTest.cpp

Modified: cfe/trunk/include/clang/Tooling/Core/Replacement.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Core/Replacement.h?rev=277335&r1=277334&r2=277335&view=diff
==
--- cfe/trunk/include/clang/Tooling/Core/Replacement.h (original)
+++ cfe/trunk/include/clang/Tooling/Core/Replacement.h Mon Aug  1 05:16:37 2016
@@ -123,14 +123,13 @@ public:
   /// \brief Returns a human readable string representation.
   std::string toString() const;
 
- private:
-   void setFromSourceLocation(const SourceManager &Sources,
-  SourceLocation Start, unsigned Length,
-  StringRef ReplacementText);
-   void setFromSourceRange(const SourceManager &Sources,
-   const CharSourceRange &Range,
-   StringRef ReplacementText,
-   const LangOptions &LangOpts);
+private:
+  void setFromSourceLocation(const SourceManager &Sources, SourceLocation 
Start,
+ unsigned Length, StringRef ReplacementText);
+  void setFromSourceRange(const SourceManager &Sources,
+  const CharSourceRange &Range,
+  StringRef ReplacementText,
+  const LangOptions &LangOpts);
 
   std::string FilePath;
   Range ReplacementRange;
@@ -143,17 +142,70 @@ bool operator<(const Replacement &LHS, c
 /// \brief Equal-to operator between two Replacements.
 bool operator==(const Replacement &LHS, const Replacement &RHS);
 
-/// \brief A set of Replacements.
-/// FIXME: Change to a vector and deduplicate in the RefactoringTool.
-typedef std::set Replacements;
+/// \brief Maintains a set of replacements that are conflict-free.
+/// Two replacements are considered conflicts if they overlap or have the same
+/// offset (i.e. order-dependent).
+class Replacements {
+ private:
+   typedef std::set ReplacementsImpl;
 
-/// \brief Apply all replacements in \p Replaces to the Rewriter \p Rewrite.
-///
-/// Replacement applications happen independently of the success of
-/// other applications.
-///
-/// \returns true if all replacements apply. false otherwise.
-bool applyAllReplacements(const Replacements &Replaces, Rewriter &Rewrite);
+ public:
+  typedef ReplacementsImpl::const_iterator const_iterator;
+
+  Replacements() = default;
+
+  explicit Replacements(const Replacement &R) { Replaces.insert(R); }
+
+  /// \brief Adds a new replacement \p R to the current set of replacements.
+  /// \p R must have the same file path as all existing replacements.
+  /// Returns true if the replacement is successfully inserted; otherwise,
+  /// it returns an llvm::Error, i.e. there is a conflict between R and the
+  /// existing replacements or R's file path is different from the filepath of
+  /// existing replacements. Callers must explicitly check the Error returned.
+  /// This prevents users from adding order-dependent replacements. To control
+  /// the order in which order-dependent replacements are applied, use
+  /// merge({R}) with R referring to the changed code after applying all
+  /// existing replacements.
+  /// Replacements with offset UINT_MAX are special - we do not detect 
conflicts
+  /// for such replacements since users may add them intentionally as a special
+  /// category of replacements.
+  llvm::Error add(const Replacement &R);
+
+  /// \brief Merges \p Replaces into the current replacements. \p Replaces
+  /// refers t

[clang-tools-extra] r277336 - Changes related to new implementation of tooling::Replacements as class.

2016-08-01 Thread Eric Liu via cfe-commits
Author: ioeric
Date: Mon Aug  1 05:16:39 2016
New Revision: 277336

URL: http://llvm.org/viewvc/llvm-project?rev=277336&view=rev
Log:
Changes related to new implementation of tooling::Replacements as class.

Summary: See http://reviews.llvm.org/D21748 for details.

Reviewers: djasper, klimek

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D21749

Modified:

clang-tools-extra/trunk/clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h

clang-tools-extra/trunk/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp

clang-tools-extra/trunk/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
clang-tools-extra/trunk/clang-rename/RenamingAction.cpp
clang-tools-extra/trunk/clang-rename/RenamingAction.h
clang-tools-extra/trunk/clang-rename/tool/ClangRename.cpp
clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
clang-tools-extra/trunk/include-fixer/IncludeFixer.cpp
clang-tools-extra/trunk/include-fixer/tool/ClangIncludeFixer.cpp
clang-tools-extra/trunk/tool-template/ToolTemplate.cpp
clang-tools-extra/trunk/unittests/clang-tidy/ClangTidyTest.h

Modified: 
clang-tools-extra/trunk/clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h?rev=277336&r1=277335&r2=277336&view=diff
==
--- 
clang-tools-extra/trunk/clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h
 (original)
+++ 
clang-tools-extra/trunk/clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h
 Mon Aug  1 05:16:39 2016
@@ -91,6 +91,11 @@ bool mergeAndDeduplicate(const TUReplace
  FileToReplacementsMap &GroupedReplacements,
  clang::SourceManager &SM);
 
+// FIXME: Remove this function after changing clang-apply-replacements to use
+// Replacements class.
+bool applyAllReplacements(const std::vector &Replaces,
+  Rewriter &Rewrite);
+
 /// \brief Apply all replacements in \c GroupedReplacements.
 ///
 /// \param[in] GroupedReplacements Deduplicated and conflict free Replacements

Modified: 
clang-tools-extra/trunk/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp?rev=277336&r1=277335&r2=277336&view=diff
==
--- 
clang-tools-extra/trunk/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
 (original)
+++ 
clang-tools-extra/trunk/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
 Mon Aug  1 05:16:39 2016
@@ -122,6 +122,81 @@ static void reportConflict(
   }
 }
 
+// FIXME: Remove this function after changing clang-apply-replacements to use
+// Replacements class.
+bool applyAllReplacements(const std::vector &Replaces,
+  Rewriter &Rewrite) {
+  bool Result = true;
+  for (std::vector::const_iterator I = Replaces.begin(),
+E = Replaces.end();
+   I != E; ++I) {
+if (I->isApplicable()) {
+  Result = I->apply(Rewrite) && Result;
+} else {
+  Result = false;
+}
+  }
+  return Result;
+}
+
+
+// FIXME: moved from libToolingCore. remove this when std::vector
+// is replaced with tooling::Replacements class.
+static void deduplicate(std::vector &Replaces,
+ std::vector &Conflicts) {
+  if (Replaces.empty())
+return;
+
+  auto LessNoPath = [](const tooling::Replacement &LHS,
+   const tooling::Replacement &RHS) {
+if (LHS.getOffset() != RHS.getOffset())
+  return LHS.getOffset() < RHS.getOffset();
+if (LHS.getLength() != RHS.getLength())
+  return LHS.getLength() < RHS.getLength();
+return LHS.getReplacementText() < RHS.getReplacementText();
+  };
+
+  auto EqualNoPath = [](const tooling::Replacement &LHS,
+const tooling::Replacement &RHS) {
+return LHS.getOffset() == RHS.getOffset() &&
+   LHS.getLength() == RHS.getLength() &&
+   LHS.getReplacementText() == RHS.getReplacementText();
+  };
+
+  // Deduplicate. We don't want to deduplicate based on the path as we assume
+  // that all replacements refer to the same file (or are symlinks).
+  std::sort(Replaces.begin(), Replaces.end(), LessNoPath);
+  Replaces.erase(std::unique(Replaces.begin(), Replaces.end(), EqualNoPath),
+ Replaces.end());
+
+  // Detect conflicts
+  tooling::Range ConflictRange(Replaces.front().getOffset(),
+   Replaces.front().getLength());
+  unsigned ConflictStart = 0;
+  unsigned ConflictLength = 1;
+  for (unsigned i =

Re: [PATCH] D21749: Changes related to new implementation of tooling::Replacements as class.

2016-08-01 Thread Eric Liu via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL277336: Changes related to new implementation of 
tooling::Replacements as class. (authored by ioeric).

Changed prior to commit:
  https://reviews.llvm.org/D21749?vs=66295&id=66298#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D21749

Files:
  
clang-tools-extra/trunk/clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h
  
clang-tools-extra/trunk/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
  
clang-tools-extra/trunk/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
  clang-tools-extra/trunk/clang-rename/RenamingAction.cpp
  clang-tools-extra/trunk/clang-rename/RenamingAction.h
  clang-tools-extra/trunk/clang-rename/tool/ClangRename.cpp
  clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/trunk/include-fixer/IncludeFixer.cpp
  clang-tools-extra/trunk/include-fixer/tool/ClangIncludeFixer.cpp
  clang-tools-extra/trunk/tool-template/ToolTemplate.cpp
  clang-tools-extra/trunk/unittests/clang-tidy/ClangTidyTest.h

Index: clang-tools-extra/trunk/unittests/clang-tidy/ClangTidyTest.h
===
--- clang-tools-extra/trunk/unittests/clang-tidy/ClangTidyTest.h
+++ clang-tools-extra/trunk/unittests/clang-tidy/ClangTidyTest.h
@@ -119,7 +119,14 @@
   DiagConsumer.finish();
   tooling::Replacements Fixes;
   for (const ClangTidyError &Error : Context.getErrors())
-Fixes.insert(Error.Fix.begin(), Error.Fix.end());
+for (const auto &Fix : Error.Fix) {
+  auto Err = Fixes.add(Fix);
+  // FIXME: better error handling. Keep the behavior for now.
+  if (Err) {
+llvm::errs() << llvm::toString(std::move(Err)) << "\n";
+return "";
+  }
+}
   if (Errors)
 *Errors = Context.getErrors();
   auto Result = tooling::applyAllReplacements(Code, Fixes);
Index: clang-tools-extra/trunk/include-fixer/tool/ClangIncludeFixer.cpp
===
--- clang-tools-extra/trunk/include-fixer/tool/ClangIncludeFixer.cpp
+++ clang-tools-extra/trunk/include-fixer/tool/ClangIncludeFixer.cpp
@@ -350,8 +350,8 @@
   }
 
   if (!Quiet)
-errs() << "Added #include " << Context.getHeaderInfos().front().Header
-   << '\n';
+llvm::errs() << "Added #include " << Context.getHeaderInfos().front().Header
+ << "\n";
 
   // Set up a new source manager for applying the resulting replacements.
   IntrusiveRefCntPtr DiagOpts(new DiagnosticOptions);
Index: clang-tools-extra/trunk/include-fixer/IncludeFixer.cpp
===
--- clang-tools-extra/trunk/include-fixer/IncludeFixer.cpp
+++ clang-tools-extra/trunk/include-fixer/IncludeFixer.cpp
@@ -352,23 +352,36 @@
   std::string IncludeName =
   "#include " + Context.getHeaderInfos().front().Header + "\n";
   // Create replacements for the new header.
-  clang::tooling::Replacements Insertions = {
-  tooling::Replacement(FilePath, UINT_MAX, 0, IncludeName)};
+  clang::tooling::Replacements Insertions;
+  auto Err =
+  Insertions.add(tooling::Replacement(FilePath, UINT_MAX, 0, IncludeName));
+  if (Err)
+return std::move(Err);
 
   auto CleanReplaces = cleanupAroundReplacements(Code, Insertions, Style);
   if (!CleanReplaces)
 return CleanReplaces;
 
+  auto Replaces = std::move(*CleanReplaces);
   if (AddQualifiers) {
 for (const auto &Info : Context.getQuerySymbolInfos()) {
   // Ignore the empty range.
-  if (Info.Range.getLength() > 0)
-CleanReplaces->insert({FilePath, Info.Range.getOffset(),
-   Info.Range.getLength(),
-   Context.getHeaderInfos().front().QualifiedName});
+  if (Info.Range.getLength() > 0) {
+auto R = tooling::Replacement(
+{FilePath, Info.Range.getOffset(), Info.Range.getLength(),
+ Context.getHeaderInfos().front().QualifiedName});
+auto Err = Replaces.add(R);
+if (Err) {
+  llvm::consumeError(std::move(Err));
+  R = tooling::Replacement(
+  R.getFilePath(), Replaces.getShiftedCodePosition(R.getOffset()),
+  R.getLength(), R.getReplacementText());
+  Replaces = Replaces.merge(tooling::Replacements(R));
+}
+  }
 }
   }
-  return formatReplacements(Code, *CleanReplaces, Style);
+  return formatReplacements(Code, Replaces, Style);
 }
 
 } // namespace include_fixer
Index: clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
===
--- clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -77,7 +77,14 @@
   assert(Range.getBegin().isFileID() && Range.getEnd().isFileID() &&
  "Only file location

Re: [PATCH] D21748: Implement tooling::Replacements as a class.

2016-08-01 Thread Eric Liu via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL277335: Implement tooling::Replacements as a class. 
(authored by ioeric).

Changed prior to commit:
  https://reviews.llvm.org/D21748?vs=66294&id=66297#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D21748

Files:
  cfe/trunk/include/clang/Tooling/Core/Replacement.h
  cfe/trunk/include/clang/Tooling/Refactoring.h
  cfe/trunk/lib/Format/Format.cpp
  cfe/trunk/lib/Format/SortJavaScriptImports.cpp
  cfe/trunk/lib/Format/TokenAnalyzer.cpp
  cfe/trunk/lib/Format/WhitespaceManager.cpp
  cfe/trunk/lib/Tooling/Core/Replacement.cpp
  cfe/trunk/lib/Tooling/Refactoring.cpp
  cfe/trunk/lib/Tooling/RefactoringCallbacks.cpp
  cfe/trunk/tools/clang-format/ClangFormat.cpp
  cfe/trunk/unittests/Format/CleanupTest.cpp
  cfe/trunk/unittests/Format/FormatTest.cpp
  cfe/trunk/unittests/Tooling/RefactoringTest.cpp
  cfe/trunk/unittests/Tooling/ReplacementTest.h
  cfe/trunk/unittests/Tooling/RewriterTest.cpp

Index: cfe/trunk/lib/Tooling/Core/Replacement.cpp
===
--- cfe/trunk/lib/Tooling/Core/Replacement.cpp
+++ cfe/trunk/lib/Tooling/Core/Replacement.cpp
@@ -137,200 +137,30 @@
 ReplacementText);
 }
 
-template 
-unsigned shiftedCodePositionInternal(const T &Replaces, unsigned Position) {
-  unsigned Offset = 0;
-  for (const auto& R : Replaces) {
-if (R.getOffset() + R.getLength() <= Position) {
-  Offset += R.getReplacementText().size() - R.getLength();
-  continue;
-}
-if (R.getOffset() < Position &&
-R.getOffset() + R.getReplacementText().size() <= Position) {
-  Position = R.getOffset() + R.getReplacementText().size() - 1;
-}
-break;
-  }
-  return Position + Offset;
-}
-
-unsigned shiftedCodePosition(const Replacements &Replaces, unsigned Position) {
-  return shiftedCodePositionInternal(Replaces, Position);
-}
-
-// FIXME: Remove this function when Replacements is implemented as std::vector
-// instead of std::set.
-unsigned shiftedCodePosition(const std::vector &Replaces,
- unsigned Position) {
-  return shiftedCodePositionInternal(Replaces, Position);
-}
-
-void deduplicate(std::vector &Replaces,
- std::vector &Conflicts) {
-  if (Replaces.empty())
-return;
-
-  auto LessNoPath = [](const Replacement &LHS, const Replacement &RHS) {
-if (LHS.getOffset() != RHS.getOffset())
-  return LHS.getOffset() < RHS.getOffset();
-if (LHS.getLength() != RHS.getLength())
-  return LHS.getLength() < RHS.getLength();
-return LHS.getReplacementText() < RHS.getReplacementText();
-  };
-
-  auto EqualNoPath = [](const Replacement &LHS, const Replacement &RHS) {
-return LHS.getOffset() == RHS.getOffset() &&
-   LHS.getLength() == RHS.getLength() &&
-   LHS.getReplacementText() == RHS.getReplacementText();
-  };
-
-  // Deduplicate. We don't want to deduplicate based on the path as we assume
-  // that all replacements refer to the same file (or are symlinks).
-  std::sort(Replaces.begin(), Replaces.end(), LessNoPath);
-  Replaces.erase(std::unique(Replaces.begin(), Replaces.end(), EqualNoPath),
- Replaces.end());
-
-  // Detect conflicts
-  Range ConflictRange(Replaces.front().getOffset(),
-  Replaces.front().getLength());
-  unsigned ConflictStart = 0;
-  unsigned ConflictLength = 1;
-  for (unsigned i = 1; i < Replaces.size(); ++i) {
-Range Current(Replaces[i].getOffset(), Replaces[i].getLength());
-if (ConflictRange.overlapsWith(Current)) {
-  // Extend conflicted range
-  ConflictRange = Range(ConflictRange.getOffset(),
-std::max(ConflictRange.getLength(),
- Current.getOffset() + Current.getLength() -
- ConflictRange.getOffset()));
-  ++ConflictLength;
-} else {
-  if (ConflictLength > 1)
-Conflicts.push_back(Range(ConflictStart, ConflictLength));
-  ConflictRange = Current;
-  ConflictStart = i;
-  ConflictLength = 1;
-}
-  }
-
-  if (ConflictLength > 1)
-Conflicts.push_back(Range(ConflictStart, ConflictLength));
-}
-
-bool applyAllReplacements(const Replacements &Replaces, Rewriter &Rewrite) {
-  bool Result = true;
-  for (Replacements::const_iterator I = Replaces.begin(),
-E = Replaces.end();
-   I != E; ++I) {
-if (I->isApplicable()) {
-  Result = I->apply(Rewrite) && Result;
-} else {
-  Result = false;
-}
-  }
-  return Result;
-}
-
-// FIXME: Remove this function when Replacements is implemented as std::vector
-// instead of std::set.
-bool applyAllReplacements(const std::vector &Replaces,
-  Rewriter &Rewrite) {
-  bool Result = true;
-  for (std::vector::const_iterator I = Replaces.begin(),
-E = 

Re: [PATCH] D22982: [CloneDetector] No longer reporting clones that don't have a common referenced variable pattern.

2016-08-01 Thread Artem Dergachev via cfe-commits
NoQ added a comment.

Looks good, minor comments :)



Comment at: lib/Analysis/CloneDetection.cpp:99
@@ +98,3 @@
+  /// Every item in this list is unique.
+  std::vector Variables;
+

I've a feeling this is essentially a `map`, because 
that harmonizes with our access patterns (lookup number by variable, insert the 
new value `Variables.size()` if not found). So i think a map would express the 
intention more clearly.


Comment at: lib/Analysis/CloneDetection.cpp:168
@@ +167,3 @@
+assert(Other.Occurences.size() == Occurences.size());
+for (unsigned i = 0; i < Occurences.size(); ++i) {
+  if (Occurences[i].KindID != Other.Occurences[i].KindID) {

Because your code uses a lot of fancy C++11, i'd probably suggest to make it 
even prettier with `std::all_of()`.


https://reviews.llvm.org/D22982



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


Re: [PATCH] D22513: [clang-tidy] add check cppcoreguidelines-special-member-functions

2016-08-01 Thread Jonathan Coe via cfe-commits
Thanks for reporting this.

I can reproduce the segfault and have a fix. Is it ok to commit and have
review done later?

regards,

Jon

On 1 August 2016 at 11:06, Eric Lemanissier 
wrote:

> ericLemanissier added a comment.
>
> I have an segfault on all the source files of my project when I enable
> this check (it works ok when I disable this check). Sorry I don't have time
> to post a minimal source file producing the segfault. I will maybe
> tomorrow, or in two weeks.
>
>
> Repository:
>   rL LLVM
>
> https://reviews.llvm.org/D22513
>
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D22969: [analyzer] Fix execution permissions for scan-build-py.

2016-08-01 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL277338: [analyzer] Fix execution permissions for the 
scan-build-py scripts. (authored by dergachev).

Changed prior to commit:
  https://reviews.llvm.org/D22969?vs=66159&id=66300#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D22969

Files:
  cfe/trunk/tools/scan-build-py/bin/analyze-build
  cfe/trunk/tools/scan-build-py/bin/analyze-c++
  cfe/trunk/tools/scan-build-py/bin/analyze-cc
  cfe/trunk/tools/scan-build-py/bin/intercept-build
  cfe/trunk/tools/scan-build-py/bin/intercept-c++
  cfe/trunk/tools/scan-build-py/bin/intercept-cc
  cfe/trunk/tools/scan-build-py/bin/scan-build



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


Re: [PATCH] D22513: [clang-tidy] add check cppcoreguidelines-special-member-functions

2016-08-01 Thread Jonathan Coe via cfe-commits
Patch posted to Phabricator as https://reviews.llvm.org/D23008

regards,

Jon

On 1 August 2016 at 11:48, Jonathan Coe  wrote:

> Thanks for reporting this.
>
> I can reproduce the segfault and have a fix. Is it ok to commit and have
> review done later?
>
> regards,
>
> Jon
>
> On 1 August 2016 at 11:06, Eric Lemanissier 
> wrote:
>
>> ericLemanissier added a comment.
>>
>> I have an segfault on all the source files of my project when I enable
>> this check (it works ok when I disable this check). Sorry I don't have time
>> to post a minimal source file producing the segfault. I will maybe
>> tomorrow, or in two weeks.
>>
>>
>> Repository:
>>   rL LLVM
>>
>> https://reviews.llvm.org/D22513
>>
>>
>>
>>
>>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D22774: [MSVC] Add ARM support to intrin.h for MSVC compatibility

2016-08-01 Thread Renato Golin via cfe-commits
rengolin added a reviewer: compnerd.
rengolin added a subscriber: compnerd.
rengolin added a comment.

Can you add a test on test/Headers, like the others, please?

I'm not well versed on Windows. @compnerd?



Comment at: lib/Headers/armintr.h:1
@@ +1,2 @@
+/*=== armintr.h - ARM intrinsics ---===
+ *

Maybe a hint that this is "ARM Windows Intrinsics"?


Comment at: lib/Headers/armintr.h:27
@@ +26,3 @@
+
+typedef enum
+{

Maybe an ifdef Windows wrapper, to make sure not to mess up *nix environments?


https://reviews.llvm.org/D22774



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


Re: [PATCH] D22774: [MSVC] Add ARM support to intrin.h for MSVC compatibility

2016-08-01 Thread Martin Storsjö via cfe-commits
mstorsjo added a comment.

In https://reviews.llvm.org/D22774#501993, @rengolin wrote:

> Can you add a test on test/Headers, like the others, please?


Sure, there seems to be a good spot for that in ms-intrin.cpp.



Comment at: lib/Headers/armintr.h:1
@@ +1,2 @@
+/*=== armintr.h - ARM intrinsics ---===
+ *

rengolin wrote:
> Maybe a hint that this is "ARM Windows Intrinsics"?
Sure


Comment at: lib/Headers/armintr.h:27
@@ +26,3 @@
+
+typedef enum
+{

rengolin wrote:
> Maybe an ifdef Windows wrapper, to make sure not to mess up *nix environments?
I can add the same as at the top of intrin.h, i.e. this:


```
/* Only include this if we're compiling for the windows platform. */
#ifndef _MSC_VER
#include_next 
#else
```


https://reviews.llvm.org/D22774



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


Re: [PATCH] D22903: [clang-tidy] Prepare modernize-loop-convert for upcoming changes in D22566

2016-08-01 Thread Martin Böhme via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL277339: [clang-tidy] Prepare modernize-loop-convert for 
upcoming changes in D22566 (authored by mboehme).

Changed prior to commit:
  https://reviews.llvm.org/D22903?vs=65877&id=66303#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D22903

Files:
  clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp

Index: clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp
===
--- clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp
+++ clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp
@@ -805,6 +805,18 @@
 }
 
 bool ForLoopIndexUseVisitor::TraverseStmt(Stmt *S) {
+  // If this is an initialization expression for a lambda capture, prune the
+  // traversal so that we don't end up diagnosing the contained DeclRefExpr as
+  // inconsistent usage. No need to record the usage here -- this is done in
+  // TraverseLambdaCapture().
+  if (const auto *LE = dyn_cast_or_null(NextStmtParent)) {
+// Any child of a LambdaExpr that isn't the body is an initialization
+// expression.
+if (S != LE->getBody()) {
+  return true;
+}
+  }
+
   // All this pointer swapping is a mechanism for tracking immediate parentage
   // of Stmts.
   const Stmt *OldNextParent = NextStmtParent;


Index: clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp
===
--- clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp
+++ clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp
@@ -805,6 +805,18 @@
 }
 
 bool ForLoopIndexUseVisitor::TraverseStmt(Stmt *S) {
+  // If this is an initialization expression for a lambda capture, prune the
+  // traversal so that we don't end up diagnosing the contained DeclRefExpr as
+  // inconsistent usage. No need to record the usage here -- this is done in
+  // TraverseLambdaCapture().
+  if (const auto *LE = dyn_cast_or_null(NextStmtParent)) {
+// Any child of a LambdaExpr that isn't the body is an initialization
+// expression.
+if (S != LE->getBody()) {
+  return true;
+}
+  }
+
   // All this pointer swapping is a mechanism for tracking immediate parentage
   // of Stmts.
   const Stmt *OldNextParent = NextStmtParent;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r277339 - [clang-tidy] Prepare modernize-loop-convert for upcoming changes in D22566

2016-08-01 Thread Martin Bohme via cfe-commits
Author: mboehme
Date: Mon Aug  1 06:29:17 2016
New Revision: 277339

URL: http://llvm.org/viewvc/llvm-project?rev=277339&view=rev
Log:
[clang-tidy] Prepare modernize-loop-convert for upcoming changes in D22566

Summary:
D22566 will change RecursiveASTVisitor so that it descends into the 
initialization expressions for lambda captures.

modernize-loop-convert needs to be prepared for this so that it does not 
interpret these initialization expressions as invalid uses of the loop 
variable. The change has no ill effects without D22566 in place, i.e. the 
change does not depend on D22566.

Reviewers: klimek

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D22903

Modified:
clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp?rev=277339&r1=277338&r2=277339&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp Mon Aug  
1 06:29:17 2016
@@ -805,6 +805,18 @@ bool ForLoopIndexUseVisitor::VisitDeclSt
 }
 
 bool ForLoopIndexUseVisitor::TraverseStmt(Stmt *S) {
+  // If this is an initialization expression for a lambda capture, prune the
+  // traversal so that we don't end up diagnosing the contained DeclRefExpr as
+  // inconsistent usage. No need to record the usage here -- this is done in
+  // TraverseLambdaCapture().
+  if (const auto *LE = dyn_cast_or_null(NextStmtParent)) {
+// Any child of a LambdaExpr that isn't the body is an initialization
+// expression.
+if (S != LE->getBody()) {
+  return true;
+}
+  }
+
   // All this pointer swapping is a mechanism for tracking immediate parentage
   // of Stmts.
   const Stmt *OldNextParent = NextStmtParent;


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


[PATCH] D23009: [clang-rename] handle overridden functions correctly

2016-08-01 Thread Kirill Bobyrev via cfe-commits
omtcyfz created this revision.
omtcyfz added reviewers: alexfh, klimek.
omtcyfz added a subscriber: cfe-commits.

1. Renaming overridden functions only works for two levels of "overriding 
hierarchy". `clang-rename` should recursively add overridden methods.
2. Make use of `forEachOverridden` AST Matcher.

https://reviews.llvm.org/D23009

Files:
  clang-rename/USRFindingAction.cpp
  test/clang-rename/FunctionOverride.cpp

Index: test/clang-rename/FunctionOverride.cpp
===
--- /dev/null
+++ test/clang-rename/FunctionOverride.cpp
@@ -0,0 +1,8 @@
+// RUN: clang-rename -offset=93 -new-name=boo %s -- | FileCheck %s
+
+class A { virtual void foo(); };// CHECK: class A { virtual void boo(); };
+class B : public A { void foo(); }; // CHECK: class B : public A { void boo(); 
};
+class C : public B { void foo(); }; // CHECK: class C : public B { void boo(); 
};
+
+// Use grep -FUbo 'Foo'  to get the correct offset of Foo when changing
+// this file.
Index: clang-rename/USRFindingAction.cpp
===
--- clang-rename/USRFindingAction.cpp
+++ clang-rename/USRFindingAction.cpp
@@ -54,21 +54,25 @@
 
   void Find() {
 USRSet.insert(getUSRForDecl(FoundDecl));
-addUSRsFromOverrideSetsAndCtorDtors();
+if (const auto *MethodDecl = dyn_cast(FoundDecl)) {
+  addUSRsFromOverrideSets(MethodDecl);
+}
+if (const auto *RecordDecl = dyn_cast(FoundDecl)) {
+  addUSRsOfCtorDtors(RecordDecl);
+}
 addMatchers();
 Finder.matchAST(Context);
 USRs->insert(USRs->end(), USRSet.begin(), USRSet.end());
   }
 
 private:
   void addMatchers() {
 const auto CXXMethodDeclMatcher =
-cxxMethodDecl(isVirtual()).bind("cxxMethodDecl");
+
cxxMethodDecl(forEachOverridden(cxxMethodDecl().bind("cxxMethodDecl")));
 Finder.addMatcher(CXXMethodDeclMatcher, this);
   }
 
-  // FIXME: Implement hasOverriddenMethod and matchesUSR matchers to make
-  // lookups more efficient.
+  // FIXME: Implement matchesUSR matchers to make lookups more efficient.
   virtual void run(const MatchFinder::MatchResult &Result) {
 const auto *VirtualMethod =
 Result.Nodes.getNodeAs("cxxMethodDecl");
@@ -83,20 +87,19 @@
 }
   }
 
-  void addUSRsFromOverrideSetsAndCtorDtors() {
-// If D is CXXRecordDecl we should add all USRs of its constructors.
-if (const auto *RecordDecl = dyn_cast(FoundDecl)) {
-  RecordDecl = RecordDecl->getDefinition();
-  for (const auto *CtorDecl : RecordDecl->ctors()) {
-USRSet.insert(getUSRForDecl(CtorDecl));
-  }
-  USRSet.insert(getUSRForDecl(RecordDecl->getDestructor()));
+  void addUSRsOfCtorDtors(const CXXRecordDecl *RecordDecl) {
+RecordDecl = RecordDecl->getDefinition();
+for (const auto *CtorDecl : RecordDecl->ctors()) {
+  USRSet.insert(getUSRForDecl(CtorDecl));
 }
-// If D is CXXMethodDecl we should add all USRs of its overriden methods.
-if (const auto *MethodDecl = dyn_cast(FoundDecl)) {
-  for (auto &OverriddenMethod : MethodDecl->overridden_methods()) {
-USRSet.insert(getUSRForDecl(OverriddenMethod));
-  }
+USRSet.insert(getUSRForDecl(RecordDecl->getDestructor()));
+  }
+
+  void addUSRsFromOverrideSets(const CXXMethodDecl *MethodDecl) {
+USRSet.insert(getUSRForDecl(MethodDecl));
+for (auto &OverriddenMethod : MethodDecl->overridden_methods()) {
+  // Recursively visit each OverridenMethod.
+  addUSRsFromOverrideSets(OverriddenMethod);
 }
   }
 


Index: test/clang-rename/FunctionOverride.cpp
===
--- /dev/null
+++ test/clang-rename/FunctionOverride.cpp
@@ -0,0 +1,8 @@
+// RUN: clang-rename -offset=93 -new-name=boo %s -- | FileCheck %s
+
+class A { virtual void foo(); };// CHECK: class A { virtual void boo(); };
+class B : public A { void foo(); }; // CHECK: class B : public A { void boo(); };
+class C : public B { void foo(); }; // CHECK: class C : public B { void boo(); };
+
+// Use grep -FUbo 'Foo'  to get the correct offset of Foo when changing
+// this file.
Index: clang-rename/USRFindingAction.cpp
===
--- clang-rename/USRFindingAction.cpp
+++ clang-rename/USRFindingAction.cpp
@@ -54,21 +54,25 @@
 
   void Find() {
 USRSet.insert(getUSRForDecl(FoundDecl));
-addUSRsFromOverrideSetsAndCtorDtors();
+if (const auto *MethodDecl = dyn_cast(FoundDecl)) {
+  addUSRsFromOverrideSets(MethodDecl);
+}
+if (const auto *RecordDecl = dyn_cast(FoundDecl)) {
+  addUSRsOfCtorDtors(RecordDecl);
+}
 addMatchers();
 Finder.matchAST(Context);
 USRs->insert(USRs->end(), USRSet.begin(), USRSet.end());
   }
 
 private:
   void addMatchers() {
 const auto CXXMethodDeclMatcher =
-cxxMethodDecl(isVirtual()).bind("cxxMethodDecl");
+cxxMethodDecl(forEachOverridden(cxxMethodDecl

Re: [PATCH] D22774: [MSVC] Add ARM support to intrin.h for MSVC compatibility

2016-08-01 Thread Renato Golin via cfe-commits
rengolin added inline comments.


Comment at: lib/Headers/armintr.h:27
@@ +26,3 @@
+
+typedef enum
+{

mstorsjo wrote:
> rengolin wrote:
> > Maybe an ifdef Windows wrapper, to make sure not to mess up *nix 
> > environments?
> I can add the same as at the top of intrin.h, i.e. this:
> 
> 
> ```
> /* Only include this if we're compiling for the windows platform. */
> #ifndef _MSC_VER
> #include_next 
> #else
> ```
Could be. I know you have that on the including header, but nothing stops 
people from including this one too by accident. Also, it makes it more clear 
where it should work and where it shouldn't.


https://reviews.llvm.org/D22774



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


Re: [PATCH] D22774: [MSVC] Add ARM support to intrin.h for MSVC compatibility

2016-08-01 Thread Martin Storsjö via cfe-commits
mstorsjo added inline comments.


Comment at: lib/Headers/armintr.h:27
@@ +26,3 @@
+
+typedef enum
+{

rengolin wrote:
> mstorsjo wrote:
> > rengolin wrote:
> > > Maybe an ifdef Windows wrapper, to make sure not to mess up *nix 
> > > environments?
> > I can add the same as at the top of intrin.h, i.e. this:
> > 
> > 
> > ```
> > /* Only include this if we're compiling for the windows platform. */
> > #ifndef _MSC_VER
> > #include_next 
> > #else
> > ```
> Could be. I know you have that on the including header, but nothing stops 
> people from including this one too by accident. Also, it makes it more clear 
> where it should work and where it shouldn't.
No, I meant just like you want, but instead of `#ifdef _WIN32` use `#ifndef 
_MSC_VER`, and use `#include_next ` for when not working in MSVC 
mode, i.e. behave as if our header didn't exist at all.

So I agree that it's useful to have on this individual header as well, not only 
rely on this guard in the intrin.h.


https://reviews.llvm.org/D22774



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


Re: [PATCH] D22729: MPIBufferDerefCheck for Clang-Tidy

2016-08-01 Thread Alexander Droste via cfe-commits
Alexander_Droste added a comment.

Hi, thanks for having a look!



Comment at: clang-tidy/mpi/BufferDerefCheck.cpp:63
@@ +62,3 @@
+if (FuncClassifier.isReduceType(Identifier)) {
+  addBuffer(0);
+  addBuffer(1);

hokein wrote:
> Could you add some comments to describe what these statements do? It's 
> confused when reading the magic number parameter. The same below.
Sure, I'll extend the comment.


Comment at: clang-tidy/mpi/BufferDerefCheck.cpp:109
@@ +108,3 @@
+  std::string IndirectionDesc;
+  for (int i = Indirections.size() - 1; i >= 0; --i) {
+if (Indirections[i] == IndirectionType::Pointer) {

hokein wrote:
> size_t
Hmm, this loop iterates the indirections in reverse order and exits the loop if 
`i` gets smaller than 0. `size_t` would therefore not work. I think it's safe 
to assume that the number of indirections will not exceed `INT_MAX`. How about 
an explicit cast? I can't use `rbegin` and `rend`, as the current index is 
needed for:

```
if (i > 0) {
  IndirectionDesc += "->";
}
```


https://reviews.llvm.org/D22729



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


Re: [PATCH] D21814: clang-rename: split existing options into two new subcommands

2016-08-01 Thread Miklos Vajna via cfe-commits
vmiklos updated this revision to Diff 66304.

https://reviews.llvm.org/D21814

Files:
  clang-rename/RenamingAction.cpp
  clang-rename/RenamingAction.h
  clang-rename/tool/ClangRename.cpp
  docs/clang-rename.rst
  test/clang-rename/ClassFindByName.cpp
  test/clang-rename/ClassTestMulti.cpp
  test/clang-rename/ClassTestMultiByName.cpp
  test/clang-rename/FunctionWithClassFindByName.cpp
  test/clang-rename/NoNewName.cpp

Index: test/clang-rename/NoNewName.cpp
===
--- test/clang-rename/NoNewName.cpp
+++ test/clang-rename/NoNewName.cpp
@@ -1,4 +1,4 @@
 // Check for an error while -new-name argument has not been passed to
 // clang-rename.
 // RUN: not clang-rename -offset=133 %s 2>&1 | FileCheck %s
-// CHECK: ERROR: no new name provided.
+// CHECK: clang-rename: for the -new-name option: must be specified
Index: test/clang-rename/FunctionWithClassFindByName.cpp
===
--- test/clang-rename/FunctionWithClassFindByName.cpp
+++ test/clang-rename/FunctionWithClassFindByName.cpp
@@ -1,4 +1,4 @@
-// RUN: clang-rename -old-name=Foo -new-name=Bar %s -- | FileCheck %s
+// RUN: clang-rename rename-all -old-name=Foo -new-name=Bar %s -- | FileCheck %s
 
 void foo() {
 }
Index: test/clang-rename/ClassTestMultiByName.cpp
===
--- /dev/null
+++ test/clang-rename/ClassTestMultiByName.cpp
@@ -0,0 +1,6 @@
+// RUN: clang-rename rename-all -old-name=Foo1 -new-name=Bar1 -old-name=Foo2 -new-name=Bar2 %s -- | FileCheck %s
+class Foo1 { // CHECK: class Bar1
+};
+
+class Foo2 { // CHECK: class Bar2
+};
Index: test/clang-rename/ClassTestMulti.cpp
===
--- /dev/null
+++ test/clang-rename/ClassTestMulti.cpp
@@ -0,0 +1,6 @@
+// RUN: clang-rename rename-all -offset=113 -new-name=Bar1 -offset=151 -new-name=Bar2 %s -- | FileCheck %s
+class Foo1 { // CHECK: class Bar1
+};
+
+class Foo2 { // CHECK: class Bar2
+};
Index: test/clang-rename/ClassFindByName.cpp
===
--- test/clang-rename/ClassFindByName.cpp
+++ test/clang-rename/ClassFindByName.cpp
@@ -1,4 +1,4 @@
-// RUN: clang-rename -old-name=Foo -new-name=Bar %s -- | FileCheck %s
+// RUN: clang-rename rename-all -old-name=Foo -new-name=Bar %s -- | FileCheck %s
 
 class Foo { // CHECK: class Bar
 };
Index: docs/clang-rename.rst
===
--- docs/clang-rename.rst
+++ docs/clang-rename.rst
@@ -42,6 +42,14 @@
   $ grep -FUbo 'foo' file.cpp
 
 
+You can also identify one or more symbols to be renamed by giving the fully qualified
+name:
+
+.. code-block:: console
+
+  $ clang-rename rename-all -old-name=foo -new-name=bar test.cpp
+
+
 The tool currently supports renaming actions inside a single Translation Unit
 only. It is planned to extend the tool's functionality to support multi-TU
 renaming actions in the future.
@@ -55,34 +63,73 @@
 .. code-block:: console
 
   $ clang-rename -help
+  Usage: clang-rename {rename-at|rename-all} [OPTION]...
+
+  A tool to rename symbols in C/C++ code.
+
+  Subcommands:
+rename-at:  Perform rename off of a location in a file. (This is the default.)
+rename-all: Perform rename of all symbols matching one or more fully qualified names.
+
+
+.. code-block:: console
+
+  $ clang-rename rename-at -help
   OVERVIEW: A tool to rename symbols in C/C++ code.
   clang-rename renames every occurrence of a symbol found at  in
   . If -i is specified, the edited files are overwritten to disk.
   Otherwise, the results are written to stdout.
-
-  USAGE: clang-rename [subcommand] [options]  [... ]
-
+  
+  USAGE: clang-rename rename-at [subcommand] [options]  [... ]
+  
   OPTIONS:
+  
+  Generic Options:
+  
+-help  - Display available options (-help-hidden for more)
+-help-list - Display list of available options (-help-list-hidden for more)
+-version   - Display the version of this program
 
-  Clang-rename options:
+  clang-rename rename-at options:
 
 -export-fixes=   - YAML file to store suggested fixes in.
 -extra-arg=- Additional argument to append to the compiler command line
 -extra-arg-before= - Additional argument to prepend to the compiler command line
 -i - Overwrite edited s.
 -new-name= - The new name to change the symbol to.
 -offset= - Locates the symbol by offset as opposed to :.
--old-name= - The fully qualified name of the symbol, if -offset is not used.
 -p=- Build path
 -pl- Print the locations affected by renaming to stderr.
 -pn- Print the found symbol's name prior to renaming to stderr.
 
+
+.. code-block:: console
+
+  $ ~/git/llvm/workdir/bin/c

Re: [PATCH] D21814: clang-rename: split existing options into two new subcommands

2016-08-01 Thread Miklos Vajna via cfe-commits
vmiklos added a comment.

Rebased on top of r277339 and resolved conflicts.


https://reviews.llvm.org/D21814



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


Re: [PATCH] D22774: [MSVC] Add ARM support to intrin.h for MSVC compatibility

2016-08-01 Thread Renato Golin via cfe-commits
rengolin added inline comments.


Comment at: lib/Headers/armintr.h:27
@@ +26,3 @@
+
+typedef enum
+{

mstorsjo wrote:
> rengolin wrote:
> > mstorsjo wrote:
> > > rengolin wrote:
> > > > Maybe an ifdef Windows wrapper, to make sure not to mess up *nix 
> > > > environments?
> > > I can add the same as at the top of intrin.h, i.e. this:
> > > 
> > > 
> > > ```
> > > /* Only include this if we're compiling for the windows platform. */
> > > #ifndef _MSC_VER
> > > #include_next 
> > > #else
> > > ```
> > Could be. I know you have that on the including header, but nothing stops 
> > people from including this one too by accident. Also, it makes it more 
> > clear where it should work and where it shouldn't.
> No, I meant just like you want, but instead of `#ifdef _WIN32` use `#ifndef 
> _MSC_VER`, and use `#include_next ` for when not working in MSVC 
> mode, i.e. behave as if our header didn't exist at all.
> 
> So I agree that it's useful to have on this individual header as well, not 
> only rely on this guard in the intrin.h.
Sounds good.


https://reviews.llvm.org/D22774



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


Re: [PATCH] D23006: [clang-rename] add basic Emacs integration

2016-08-01 Thread Kirill Bobyrev via cfe-commits
omtcyfz added a comment.

Manuel, any other comments? Jens seems to be missing and I don't know about 
anyone else who is familiar with Emacs :(


https://reviews.llvm.org/D23006



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


[clang-tools-extra] r277340 - [clang-tidy] remove trailing whitespaces and retab

2016-08-01 Thread Kirill Bobyrev via cfe-commits
Author: omtcyfz
Date: Mon Aug  1 07:06:18 2016
New Revision: 277340

URL: http://llvm.org/viewvc/llvm-project?rev=277340&view=rev
Log:
[clang-tidy] remove trailing whitespaces and retab

Modified:
clang-tools-extra/trunk/clang-tidy/cert/LICENSE.TXT
clang-tools-extra/trunk/clang-tidy/cert/StrToNumCheck.cpp

clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.h

clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeConstCastCheck.cpp
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeConstCastCheck.h

clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeStaticCastDowncastCheck.cpp

clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeStaticCastDowncastCheck.h

clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.h
clang-tools-extra/trunk/clang-tidy/misc/MacroParenthesesCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/misc/MoveConstructorInitCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/SizeofContainerCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/StaticAssertCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/StaticAssertCheck.h
clang-tools-extra/trunk/clang-tidy/misc/StringIntegerAssignmentCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/StringIntegerAssignmentCheck.h
clang-tools-extra/trunk/clang-tidy/misc/SuspiciousMissingCommaCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/SuspiciousMissingCommaCheck.h
clang-tools-extra/trunk/clang-tidy/misc/SwappedArgumentsCheck.cpp

clang-tools-extra/trunk/clang-tidy/misc/ThrowByValueCatchByReferenceCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/UnusedAliasDeclsCheck.h
clang-tools-extra/trunk/clang-tidy/misc/UnusedParametersCheck.h
clang-tools-extra/trunk/clang-tidy/modernize/PassByValueCheck.cpp

clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-slicing.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-emplace.rst

Modified: clang-tools-extra/trunk/clang-tidy/cert/LICENSE.TXT
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cert/LICENSE.TXT?rev=277340&r1=277339&r2=277340&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/cert/LICENSE.TXT (original)
+++ clang-tools-extra/trunk/clang-tidy/cert/LICENSE.TXT Mon Aug  1 07:06:18 2016
@@ -7,7 +7,7 @@ additions:
 Any file referencing a CERT Secure Coding guideline:
 Please allow this letter to serve as confirmation that open source projects on
 http://llvm.org are permitted to link via hypertext to the CERT(R) secure 
coding
-guidelines available at https://www.securecoding.cert.org.   
+guidelines available at https://www.securecoding.cert.org.
 
 The foregoing is permitted by the Terms of Use as follows:
 "Linking to the Service

Modified: clang-tools-extra/trunk/clang-tidy/cert/StrToNumCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cert/StrToNumCheck.cpp?rev=277340&r1=277339&r2=277340&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/cert/StrToNumCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/cert/StrToNumCheck.cpp Mon Aug  1 
07:06:18 2016
@@ -127,7 +127,7 @@ ConversionKind ClassifyFormatString(Stri
 
   Handler H;
   analyze_format_string::ParseScanfString(H, Fmt.begin(), Fmt.end(), LO, TI);
-  
+
   return H.get();
 }
 

Modified: 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.h?rev=277340&r1=277339&r2=277340&view=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.h
 (original)
+++ 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.h
 Mon Aug  1 07:06:18 2016
@@ -15,7 +15,7 @@
 namespace clang {
 namespace tidy {
 namespace cppcoreguidelines {
-   
+
 /// This check flags all array to pointer decays
 ///
 /// For the user-facing documentation see:

Modified: 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeConstCastCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeConstCastCheck.cpp?rev=277340&r1=277339&r2=277340&view=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeConstCastCheck.cpp 
(original)
+++ 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeConstCastCheck.cpp 
Mon Aug  1 07:06:18 2016
@@ -16,7 +16,7 @@ u

Re: [PATCH] D15227: [analyzer] Valist checkers.

2016-08-01 Thread Gábor Horváth via cfe-commits
xazax.hun marked 10 inline comments as done.
xazax.hun added a comment.

https://reviews.llvm.org/D15227



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


Re: [PATCH] D22729: MPIBufferDerefCheck for Clang-Tidy

2016-08-01 Thread Alexander Droste via cfe-commits
Alexander_Droste added a comment.

> Looks like the dependency of this patch https://reviews.llvm.org/D21962 got 
> reverted by some reasons.


I know, I updated the patch after that, in order to fix the problem.


https://reviews.llvm.org/D22729



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


Re: [PATCH] D22513: [clang-tidy] add check cppcoreguidelines-special-member-functions

2016-08-01 Thread Aaron Ballman via cfe-commits
On Mon, Aug 1, 2016 at 6:48 AM, Jonathan Coe  wrote:
> Thanks for reporting this.
>
> I can reproduce the segfault and have a fix. Is it ok to commit and have
> review done later?

Yes, this sort of thing is typical to handle post-commit (along with
other feedback that comes in post-commit).

~Aaron

>
> regards,
>
> Jon
>
> On 1 August 2016 at 11:06, Eric Lemanissier 
> wrote:
>>
>> ericLemanissier added a comment.
>>
>> I have an segfault on all the source files of my project when I enable
>> this check (it works ok when I disable this check). Sorry I don't have time
>> to post a minimal source file producing the segfault. I will maybe tomorrow,
>> or in two weeks.
>>
>>
>> Repository:
>>   rL LLVM
>>
>> https://reviews.llvm.org/D22513
>>
>>
>>
>>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r277342 - Make RecursiveASTVisitor visit lambda capture initialization expressions

2016-08-01 Thread Martin Bohme via cfe-commits
Author: mboehme
Date: Mon Aug  1 07:15:46 2016
New Revision: 277342

URL: http://llvm.org/viewvc/llvm-project?rev=277342&view=rev
Log:
Make RecursiveASTVisitor visit lambda capture initialization expressions

Summary:
Lambda capture initializations are part of the explicit source code and
therefore should be visited by default but, so far, RecursiveASTVisitor does not
visit them.

This appears to be an oversight. Because the lambda body needs custom handling
(calling TraverseLambdaBody()), the DEF_TRAVERSE_STMT for LambdaExpr sets
ShouldVisitChildren to false but then neglects to visit the lambda capture
initializations. This patch adds code to visit the expressions associated with
lambda capture initializations.

Reviewers: klimek

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D22566

Modified:
cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
cfe/trunk/unittests/Tooling/RecursiveASTVisitorTestExprVisitor.cpp

Modified: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecursiveASTVisitor.h?rev=277342&r1=277341&r2=277342&view=diff
==
--- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h (original)
+++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h Mon Aug  1 07:15:46 2016
@@ -2266,6 +2266,9 @@ DEF_TRAVERSE_STMT(LambdaExpr, {
C != CEnd; ++C) {
 TRY_TO(TraverseLambdaCapture(S, C));
   }
+  for (Expr *Init : S->capture_inits()) {
+TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(Init);
+  }
 
   TypeLoc TL = S->getCallOperator()->getTypeSourceInfo()->getTypeLoc();
   FunctionProtoTypeLoc Proto = TL.castAs();

Modified: cfe/trunk/unittests/Tooling/RecursiveASTVisitorTestExprVisitor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/RecursiveASTVisitorTestExprVisitor.cpp?rev=277342&r1=277341&r2=277342&view=diff
==
--- cfe/trunk/unittests/Tooling/RecursiveASTVisitorTestExprVisitor.cpp 
(original)
+++ cfe/trunk/unittests/Tooling/RecursiveASTVisitorTestExprVisitor.cpp Mon Aug  
1 07:15:46 2016
@@ -191,6 +191,14 @@ TEST(RecursiveASTVisitor, VisitsCallExpr
 "void x(); void y() { x(); }"));
 }
 
+TEST(RecursiveASTVisitor, VisitsLambdaCaptureInit) {
+  DeclRefExprVisitor Visitor;
+  Visitor.ExpectMatch("i", 1, 20);
+  EXPECT_TRUE(Visitor.runOver(
+"void f() { int i; [i]{}; };",
+DeclRefExprVisitor::Lang_CXX11));
+}
+
 /* FIXME: According to Richard Smith this is a bug in the AST.
 TEST(RecursiveASTVisitor, VisitsBaseClassTemplateArgumentsInInstantiation) {
   DeclRefExprVisitor Visitor;


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


Re: [PATCH] D21959: [X86] Add xgetbv xsetbv intrinsics

2016-08-01 Thread Guy Blank via cfe-commits
guyblank added a comment.

ping


https://reviews.llvm.org/D21959



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


r277338 - [analyzer] Fix execution permissions for the scan-build-py scripts.

2016-08-01 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Mon Aug  1 05:55:59 2016
New Revision: 277338

URL: http://llvm.org/viewvc/llvm-project?rev=277338&view=rev
Log:
[analyzer] Fix execution permissions for the scan-build-py scripts.

Differential Revision: https://reviews.llvm.org/D22969

Modified:
cfe/trunk/tools/scan-build-py/bin/analyze-build   (props changed)
cfe/trunk/tools/scan-build-py/bin/analyze-c++   (props changed)
cfe/trunk/tools/scan-build-py/bin/analyze-cc   (props changed)
cfe/trunk/tools/scan-build-py/bin/intercept-build   (props changed)
cfe/trunk/tools/scan-build-py/bin/intercept-c++   (props changed)
cfe/trunk/tools/scan-build-py/bin/intercept-cc   (props changed)
cfe/trunk/tools/scan-build-py/bin/scan-build   (props changed)

Propchange: cfe/trunk/tools/scan-build-py/bin/analyze-build
--
svn:executable = *

Propchange: cfe/trunk/tools/scan-build-py/bin/analyze-c++
--
svn:executable = *

Propchange: cfe/trunk/tools/scan-build-py/bin/analyze-cc
--
svn:executable = *

Propchange: cfe/trunk/tools/scan-build-py/bin/intercept-build
--
svn:executable = *

Propchange: cfe/trunk/tools/scan-build-py/bin/intercept-c++
--
svn:executable = *

Propchange: cfe/trunk/tools/scan-build-py/bin/intercept-cc
--
svn:executable = *

Propchange: cfe/trunk/tools/scan-build-py/bin/scan-build
--
svn:executable = *


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


Re: [PATCH] D22774: [MSVC] Add ARM support to intrin.h for MSVC compatibility

2016-08-01 Thread Martin Storsjö via cfe-commits
mstorsjo updated this revision to Diff 66306.
mstorsjo added a comment.

Added a test, added "windows" to the header title line, added an `#ifndef 
_MSC_VER #include_next` to the header.


https://reviews.llvm.org/D22774

Files:
  lib/Headers/CMakeLists.txt
  lib/Headers/armintr.h
  lib/Headers/intrin.h
  test/Headers/ms-intrin.cpp

Index: test/Headers/ms-intrin.cpp
===
--- test/Headers/ms-intrin.cpp
+++ test/Headers/ms-intrin.cpp
@@ -60,4 +60,8 @@
   __readcr3();
   __writecr3(0);
 #endif
+
+#ifdef _M_ARM
+  __dmb(_ARM_BARRIER_ISHST);
+#endif
 }
Index: lib/Headers/intrin.h
===
--- lib/Headers/intrin.h
+++ lib/Headers/intrin.h
@@ -34,6 +34,10 @@
 #include 
 #endif
 
+#if defined(__arm__)
+#include 
+#endif
+
 /* For the definition of jmp_buf. */
 #if __STDC_HOSTED__
 #include 
Index: lib/Headers/armintr.h
===
--- /dev/null
+++ lib/Headers/armintr.h
@@ -0,0 +1,45 @@
+/*=== armintr.h - ARM Windows intrinsics ---===
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ *===---===
+ */
+
+/* Only include this if we're compiling for the windows platform. */
+#ifndef _MSC_VER
+#include_next 
+#else
+
+#ifndef __ARMINTR_H
+#define __ARMINTR_H
+
+typedef enum
+{
+  _ARM_BARRIER_SY= 0xF,
+  _ARM_BARRIER_ST= 0xE,
+  _ARM_BARRIER_ISH   = 0xB,
+  _ARM_BARRIER_ISHST = 0xA,
+  _ARM_BARRIER_NSH   = 0x7,
+  _ARM_BARRIER_NSHST = 0x6,
+  _ARM_BARRIER_OSH   = 0x3,
+  _ARM_BARRIER_OSHST = 0x2
+} _ARMINTR_BARRIER_TYPE;
+
+#endif /* __ARMINTR_H */
+#endif /* _MSC_VER */
Index: lib/Headers/CMakeLists.txt
===
--- lib/Headers/CMakeLists.txt
+++ lib/Headers/CMakeLists.txt
@@ -3,6 +3,7 @@
   altivec.h
   ammintrin.h
   arm_acle.h
+  armintr.h
   avx2intrin.h
   avx512bwintrin.h
   avx512cdintrin.h


Index: test/Headers/ms-intrin.cpp
===
--- test/Headers/ms-intrin.cpp
+++ test/Headers/ms-intrin.cpp
@@ -60,4 +60,8 @@
   __readcr3();
   __writecr3(0);
 #endif
+
+#ifdef _M_ARM
+  __dmb(_ARM_BARRIER_ISHST);
+#endif
 }
Index: lib/Headers/intrin.h
===
--- lib/Headers/intrin.h
+++ lib/Headers/intrin.h
@@ -34,6 +34,10 @@
 #include 
 #endif
 
+#if defined(__arm__)
+#include 
+#endif
+
 /* For the definition of jmp_buf. */
 #if __STDC_HOSTED__
 #include 
Index: lib/Headers/armintr.h
===
--- /dev/null
+++ lib/Headers/armintr.h
@@ -0,0 +1,45 @@
+/*=== armintr.h - ARM Windows intrinsics ---===
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALING

Re: [PATCH] D22514: CloneDetection now respects statement specific data when searching for clones.

2016-08-01 Thread Raphael Isemann via cfe-commits
teemperor updated this revision to Diff 66308.
teemperor added a comment.

- No longer re-initialize memory created from resize().
- Added test for checking that StmtDataCollector visits all parent classes.


https://reviews.llvm.org/D22514

Files:
  include/clang/Analysis/CloneDetection.h
  lib/Analysis/CloneDetection.cpp
  test/Analysis/copypaste/asm.cpp
  test/Analysis/copypaste/attributes.cpp
  test/Analysis/copypaste/call.cpp
  test/Analysis/copypaste/catch.cpp
  test/Analysis/copypaste/delete.cpp
  test/Analysis/copypaste/dependent-exist.cpp
  test/Analysis/copypaste/expr-types.cpp
  test/Analysis/copypaste/false-positives.cpp
  test/Analysis/copypaste/fold.cpp
  test/Analysis/copypaste/function-try-block.cpp
  test/Analysis/copypaste/functions.cpp
  test/Analysis/copypaste/generic.c
  test/Analysis/copypaste/labels.cpp
  test/Analysis/copypaste/lambda.cpp

Index: test/Analysis/copypaste/lambda.cpp
===
--- /dev/null
+++ test/Analysis/copypaste/lambda.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -analyze -std=c++11 -analyzer-checker=alpha.clone.CloneChecker -verify %s
+
+// expected-no-diagnostics
+
+void foo1(int a, long b) {
+  auto l = [a, b](){};
+}
+
+void foo2(int a, long b) {
+  auto l = [&a, b](){};
+}
+
+void foo3(int a, long b) {
+  auto l = [a](){};
+}
+
+void foo4(int a, long b) {
+  auto l = [=](){};
+}
+
+void foo5(int a, long b) {
+  auto l = [&](){};
+}
+
Index: test/Analysis/copypaste/labels.cpp
===
--- /dev/null
+++ test/Analysis/copypaste/labels.cpp
@@ -0,0 +1,51 @@
+// RUN: %clang_cc1 -analyze -std=gnu++11 -analyzer-checker=alpha.clone.CloneChecker -verify %s
+
+// expected-no-diagnostics
+
+
+bool foo1(int x) {
+  start:
+  if (x != 3) {
+++x;
+void *ptr = &&start;
+goto start;
+  }
+  end:
+  return false;
+}
+
+// Targeting a different label with the address-of-label operator.
+bool foo2(int x) {
+  start:
+  if (x != 3) {
+++x;
+void *ptr = &&end;
+goto start;
+  }
+  end:
+  return false;
+}
+
+// Different target label in goto
+bool foo3(int x) {
+  start:
+  if (x != 3) {
+++x;
+void *ptr = &&start;
+goto end;
+  }
+  end:
+  return false;
+}
+
+// FIXME: Can't detect same algorithm as in foo1 but with different label names.
+bool foo4(int x) {
+  foo:
+  if (x != 3) {
+++x;
+void *ptr = &&foo;
+goto foo;
+  }
+  end:
+  return false;
+}
Index: test/Analysis/copypaste/generic.c
===
--- /dev/null
+++ test/Analysis/copypaste/generic.c
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -analyze -std=c11 -analyzer-checker=alpha.clone.CloneChecker -verify %s
+
+// expected-no-diagnostics
+
+int global;
+
+int foo1() {
+  if (global > 0)
+return 0;
+  else if (global < 0)
+return _Generic(global, double: 1, float: 2, default: 3);
+  return 1;
+}
+
+// Different associated type (int instead of float)
+int foo2() {
+  if (global > 0)
+return 0;
+  else if (global < 0)
+return _Generic(global, double: 1, int: 2, default: 4);
+  return 1;
+}
+
+// Different number of associated types.
+int foo3() {
+  if (global > 0)
+return 0;
+  else if (global < 0)
+return _Generic(global, double: 1, default: 4);
+  return 1;
+}
Index: test/Analysis/copypaste/functions.cpp
===
--- test/Analysis/copypaste/functions.cpp
+++ test/Analysis/copypaste/functions.cpp
@@ -20,6 +20,31 @@
 
 // Functions below are not clones and should not be reported.
 
+// The next two functions test that statement classes are still respected when
+// checking for clones in expressions. This will show that the statement
+// specific data of all super classes is collected, and not just the data of the
+// first super class.
+int testSuperClass(int a, int b) { // no-warning
+  log();
+  if (a > b)
+return true ? a : b;
+  return b;
+}
+int testSuperClass2(int a, int b) { // no-warning
+  log();
+  if (a > b)
+return __builtin_choose_expr(true, a, b);
+  return b;
+}
+
+
+int min1(int a, int b) { // no-warning
+  log();
+  if (a < b)
+return a;
+  return b;
+}
+
 int foo(int a, int b) { // no-warning
   return a + b;
 }
Index: test/Analysis/copypaste/function-try-block.cpp
===
--- /dev/null
+++ test/Analysis/copypaste/function-try-block.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -analyze -fcxx-exceptions -std=c++1z -analyzer-checker=alpha.clone.CloneChecker -verify %s
+
+// Tests if function try blocks are correctly handled.
+
+void nonCompoundStmt1(int& x)
+  try { x += 1; } catch(...) { x -= 1; } // expected-warning{{Detected code clone.}}
+
+void nonCompoundStmt2(int& x)
+  try { x += 1; } catch(...) { x -= 1; } // expected-note{{Related code clone is here.}}
Index: test/Analysis/copypaste/fold.cpp
==

Re: [PATCH] D22774: [MSVC] Add ARM support to intrin.h for MSVC compatibility

2016-08-01 Thread Renato Golin via cfe-commits
rengolin accepted this revision.
rengolin added a reviewer: rengolin.
rengolin added a comment.
This revision is now accepted and ready to land.

LGTM. Thanks!


https://reviews.llvm.org/D22774



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


Re: [PATCH] D22514: CloneDetection now respects statement specific data when searching for clones.

2016-08-01 Thread Raphael Isemann via cfe-commits
teemperor updated this revision to Diff 66309.
teemperor added a comment.

- s/super class/base class/g


https://reviews.llvm.org/D22514

Files:
  include/clang/Analysis/CloneDetection.h
  lib/Analysis/CloneDetection.cpp
  test/Analysis/copypaste/asm.cpp
  test/Analysis/copypaste/attributes.cpp
  test/Analysis/copypaste/call.cpp
  test/Analysis/copypaste/catch.cpp
  test/Analysis/copypaste/delete.cpp
  test/Analysis/copypaste/dependent-exist.cpp
  test/Analysis/copypaste/expr-types.cpp
  test/Analysis/copypaste/false-positives.cpp
  test/Analysis/copypaste/fold.cpp
  test/Analysis/copypaste/function-try-block.cpp
  test/Analysis/copypaste/functions.cpp
  test/Analysis/copypaste/generic.c
  test/Analysis/copypaste/labels.cpp
  test/Analysis/copypaste/lambda.cpp

Index: test/Analysis/copypaste/lambda.cpp
===
--- /dev/null
+++ test/Analysis/copypaste/lambda.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -analyze -std=c++11 -analyzer-checker=alpha.clone.CloneChecker -verify %s
+
+// expected-no-diagnostics
+
+void foo1(int a, long b) {
+  auto l = [a, b](){};
+}
+
+void foo2(int a, long b) {
+  auto l = [&a, b](){};
+}
+
+void foo3(int a, long b) {
+  auto l = [a](){};
+}
+
+void foo4(int a, long b) {
+  auto l = [=](){};
+}
+
+void foo5(int a, long b) {
+  auto l = [&](){};
+}
+
Index: test/Analysis/copypaste/labels.cpp
===
--- /dev/null
+++ test/Analysis/copypaste/labels.cpp
@@ -0,0 +1,51 @@
+// RUN: %clang_cc1 -analyze -std=gnu++11 -analyzer-checker=alpha.clone.CloneChecker -verify %s
+
+// expected-no-diagnostics
+
+
+bool foo1(int x) {
+  start:
+  if (x != 3) {
+++x;
+void *ptr = &&start;
+goto start;
+  }
+  end:
+  return false;
+}
+
+// Targeting a different label with the address-of-label operator.
+bool foo2(int x) {
+  start:
+  if (x != 3) {
+++x;
+void *ptr = &&end;
+goto start;
+  }
+  end:
+  return false;
+}
+
+// Different target label in goto
+bool foo3(int x) {
+  start:
+  if (x != 3) {
+++x;
+void *ptr = &&start;
+goto end;
+  }
+  end:
+  return false;
+}
+
+// FIXME: Can't detect same algorithm as in foo1 but with different label names.
+bool foo4(int x) {
+  foo:
+  if (x != 3) {
+++x;
+void *ptr = &&foo;
+goto foo;
+  }
+  end:
+  return false;
+}
Index: test/Analysis/copypaste/generic.c
===
--- /dev/null
+++ test/Analysis/copypaste/generic.c
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -analyze -std=c11 -analyzer-checker=alpha.clone.CloneChecker -verify %s
+
+// expected-no-diagnostics
+
+int global;
+
+int foo1() {
+  if (global > 0)
+return 0;
+  else if (global < 0)
+return _Generic(global, double: 1, float: 2, default: 3);
+  return 1;
+}
+
+// Different associated type (int instead of float)
+int foo2() {
+  if (global > 0)
+return 0;
+  else if (global < 0)
+return _Generic(global, double: 1, int: 2, default: 4);
+  return 1;
+}
+
+// Different number of associated types.
+int foo3() {
+  if (global > 0)
+return 0;
+  else if (global < 0)
+return _Generic(global, double: 1, default: 4);
+  return 1;
+}
Index: test/Analysis/copypaste/functions.cpp
===
--- test/Analysis/copypaste/functions.cpp
+++ test/Analysis/copypaste/functions.cpp
@@ -20,6 +20,31 @@
 
 // Functions below are not clones and should not be reported.
 
+// The next two functions test that statement classes are still respected when
+// checking for clones in expressions. This will show that the statement
+// specific data of all base classes is collected, and not just the data of the
+// first base class.
+int testBaseClass(int a, int b) { // no-warning
+  log();
+  if (a > b)
+return true ? a : b;
+  return b;
+}
+int testBaseClass2(int a, int b) { // no-warning
+  log();
+  if (a > b)
+return __builtin_choose_expr(true, a, b);
+  return b;
+}
+
+
+int min1(int a, int b) { // no-warning
+  log();
+  if (a < b)
+return a;
+  return b;
+}
+
 int foo(int a, int b) { // no-warning
   return a + b;
 }
Index: test/Analysis/copypaste/function-try-block.cpp
===
--- /dev/null
+++ test/Analysis/copypaste/function-try-block.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -analyze -fcxx-exceptions -std=c++1z -analyzer-checker=alpha.clone.CloneChecker -verify %s
+
+// Tests if function try blocks are correctly handled.
+
+void nonCompoundStmt1(int& x)
+  try { x += 1; } catch(...) { x -= 1; } // expected-warning{{Detected code clone.}}
+
+void nonCompoundStmt2(int& x)
+  try { x += 1; } catch(...) { x -= 1; } // expected-note{{Related code clone is here.}}
Index: test/Analysis/copypaste/fold.cpp
===
--- /dev/null
+++ test/Analysis/copypaste/fold.cpp
@@ -0,0 +1,35 @@
+// RUN: %clang_cc1 -

[PATCH] D23014: [analyzer] Model base to derived casts more precisely.

2016-08-01 Thread Gábor Horváth via cfe-commits
xazax.hun created this revision.
xazax.hun added reviewers: zaks.anna, dcoughlin, dergachev.a, a.sidorin.
xazax.hun added a subscriber: cfe-commits.

Dynamic casts are handled relatively well by the static analyzer. BaseToDerived 
casts however are handled conservatively. This can cause some false positives 
with the NewDeleteLeaks checker.

This patch alters the behavior of BaseToDerived casts. In case a dynamic cast 
would succeed use the same semantics. Otherwise fall back to the conservative 
approach.

A slightly related question: in case a cast on a pointer can not be modelled 
precisely, maybe that should be handled as a pointer escape to avoid false 
positives in some cases?

https://reviews.llvm.org/D23014

Files:
  lib/StaticAnalyzer/Core/ExprEngineC.cpp
  test/Analysis/NewDelete-checker-test.cpp

Index: test/Analysis/NewDelete-checker-test.cpp
===
--- test/Analysis/NewDelete-checker-test.cpp
+++ test/Analysis/NewDelete-checker-test.cpp
@@ -377,3 +377,19 @@
   delete foo;
   delete foo;  // expected-warning {{Attempt to delete released memory}}
 }
+
+struct Base {
+  virtual ~Base() {}
+};
+
+struct Derived : Base {
+};
+
+Base *allocate() {
+  return new Derived;
+}
+
+void shouldNotReportLeak() {
+  Derived *p = (Derived *)allocate();
+  delete p;
+}
Index: lib/StaticAnalyzer/Core/ExprEngineC.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngineC.cpp
+++ lib/StaticAnalyzer/Core/ExprEngineC.cpp
@@ -412,6 +412,28 @@
 Bldr.generateNode(CastE, Pred, state);
 continue;
   }
+  case CK_BaseToDerived: {
+SVal val = state->getSVal(Ex, LCtx);
+QualType resultType = CastE->getType();
+if (CastE->isGLValue())
+  resultType = getContext().getPointerType(resultType);
+
+bool Failed = false;
+
+if (!val.isZeroConstant()) {
+  val = getStoreManager().evalDynamicCast(val, T, Failed);
+}
+
+// Failed to cast or the result is unknown, fall back to conservative.
+if (Failed || val.isUnknown()) {
+  val =
+svalBuilder.conjureSymbolVal(nullptr, CastE, LCtx, resultType,
+ currBldrCtx->blockCount());
+}
+state = state->BindExpr(CastE, LCtx, val);
+Bldr.generateNode(CastE, Pred, state);
+continue;
+  }
   case CK_NullToMemberPointer: {
 // FIXME: For now, member pointers are represented by void *.
 SVal V = svalBuilder.makeNull();
@@ -421,7 +443,6 @@
   }
   // Various C++ casts that are not handled yet.
   case CK_ToUnion:
-  case CK_BaseToDerived:
   case CK_BaseToDerivedMemberPointer:
   case CK_DerivedToBaseMemberPointer:
   case CK_ReinterpretMemberPointer:


Index: test/Analysis/NewDelete-checker-test.cpp
===
--- test/Analysis/NewDelete-checker-test.cpp
+++ test/Analysis/NewDelete-checker-test.cpp
@@ -377,3 +377,19 @@
   delete foo;
   delete foo;  // expected-warning {{Attempt to delete released memory}}
 }
+
+struct Base {
+  virtual ~Base() {}
+};
+
+struct Derived : Base {
+};
+
+Base *allocate() {
+  return new Derived;
+}
+
+void shouldNotReportLeak() {
+  Derived *p = (Derived *)allocate();
+  delete p;
+}
Index: lib/StaticAnalyzer/Core/ExprEngineC.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngineC.cpp
+++ lib/StaticAnalyzer/Core/ExprEngineC.cpp
@@ -412,6 +412,28 @@
 Bldr.generateNode(CastE, Pred, state);
 continue;
   }
+  case CK_BaseToDerived: {
+SVal val = state->getSVal(Ex, LCtx);
+QualType resultType = CastE->getType();
+if (CastE->isGLValue())
+  resultType = getContext().getPointerType(resultType);
+
+bool Failed = false;
+
+if (!val.isZeroConstant()) {
+  val = getStoreManager().evalDynamicCast(val, T, Failed);
+}
+
+// Failed to cast or the result is unknown, fall back to conservative.
+if (Failed || val.isUnknown()) {
+  val =
+svalBuilder.conjureSymbolVal(nullptr, CastE, LCtx, resultType,
+ currBldrCtx->blockCount());
+}
+state = state->BindExpr(CastE, LCtx, val);
+Bldr.generateNode(CastE, Pred, state);
+continue;
+  }
   case CK_NullToMemberPointer: {
 // FIXME: For now, member pointers are represented by void *.
 SVal V = svalBuilder.makeNull();
@@ -421,7 +443,6 @@
   }
   // Various C++ casts that are not handled yet.
   case CK_ToUnion:
-  case CK_BaseToDerived:
   case CK_BaseToDerivedMemberPointer:
   case CK_DerivedToBaseMemberPointer:
   case CK_ReinterpretMemberPointer:
___
cfe-commits mailing list
cfe-commits@lis

Re: [PATCH] D23014: [analyzer] Model base to derived casts more precisely.

2016-08-01 Thread Gábor Horváth via cfe-commits
xazax.hun added inline comments.


Comment at: test/Analysis/NewDelete-checker-test.cpp:394
@@ +393,3 @@
+  Derived *p = (Derived *)allocate();
+  delete p;
+}

Before the modification the analyzer reports a leak here, since the symbol 
returned by the BaseToDerived cast is independent of the original symbol.


https://reviews.llvm.org/D23014



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


[PATCH] D23016: Enhance treatment of function specializations in friend declarations

2016-08-01 Thread Serge Pavlov via cfe-commits
sepavloff created this revision.
sepavloff added a subscriber: cfe-commits.

Function specializations used in friend declarations in class templates, like:
```
template class C1 {
friend void func<>(int);
```
previously were processed incorrectly: class instantiation made them ordinary
functions and they were not placed into redeclaration chains correctly. This
change repairs specialization treatment.

This change fixes PR12994.

https://reviews.llvm.org/D23016

Files:
  lib/AST/DeclTemplate.cpp
  lib/Sema/SemaAccess.cpp
  lib/Sema/SemaTemplateInstantiateDecl.cpp
  test/SemaCXX/friend-spec.cpp

Index: test/SemaCXX/friend-spec.cpp
===
--- /dev/null
+++ test/SemaCXX/friend-spec.cpp
@@ -0,0 +1,96 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -DCHECK_DIAGS %s
+// RUN: %clang_cc1 -triple i386-pc-linux-gnu -emit-llvm %s
+
+// Tests for befriended function specializations
+
+
+#ifdef CHECK_DIAGS
+
+namespace test1 {
+  template
+  void func_01(T);
+
+  template
+  class C1 {
+static void private_func();
+friend void func_01<>(int);
+  };
+
+  template
+  void func_01(T) {
+C1::private_func();
+  }
+
+  template void func_01<>(int);
+}
+
+namespace test2 {
+  template
+  void func_01(T);
+
+  template
+  class C1 {
+static void private_func();  // expected-note{{implicitly declared private here}}
+friend void func_01<>(int);
+  };
+
+  template
+  void func_01(T) {
+C1::private_func();  // expected-error{{'private_func' is a private member of 'test2::C1'}}
+  }
+
+  template void func_01<>(int*);  // expected-note{{in instantiation of function template specialization 'test2::func_01' requested here}}
+}
+
+namespace test3 {
+  template
+  void func_01(T, int);
+  template
+  void func_01(T, char);
+
+  template
+  class C1 {
+static void private_func();  // expected-note{{implicitly declared private here}}
+friend void func_01<>(int, T);
+  };
+
+  template
+  void func_01(T, int) {
+C1::private_func();
+  }
+
+  template
+  void func_01(T, char) {
+C1::private_func();  // expected-error{{'private_func' is a private member of 'test3::C1'}}
+  }
+
+  template void func_01<>(int, int);
+  template void func_01<>(int, char);  // expected-note{{in instantiation of function template specialization 'test3::func_01' requested here}}
+}
+
+#endif
+
+namespace pr12994 {
+  template
+  void PrintThis(cls &obj);
+
+  class Xxx;
+
+  template
+  class Test {
+friend void PrintThis<>(Xxx&);
+void printme() {}
+  };
+
+  class Aimpl {};
+
+  class Xxx : public Test {};
+
+  template
+  void PrintThis(cls &obj) {
+obj.printme();
+  }
+
+  template void PrintThis(Xxx&);
+}
+
Index: lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -1617,13 +1617,21 @@
  Innermost),
 /*InsertPos=*/nullptr);
   } else if (isFriend) {
-// Note, we need this connection even if the friend doesn't have a body.
-// Its body may exist but not have been attached yet due to deferred
-// parsing.
-// FIXME: It might be cleaner to set this when attaching the body to the
-// friend function declaration, however that would require finding all the
-// instantiations and modifying them.
-Function->setInstantiationOfMemberFunction(D, TSK_ImplicitInstantiation);
+if (const FunctionTemplateSpecializationInfo *FTSI =
+   D->getTemplateSpecializationInfo()) {
+  Function->setFunctionTemplateSpecialization(FTSI->getTemplate(),
+   TemplateArgumentList::CreateCopy(SemaRef.Context,
+FTSI->TemplateArguments->asArray()),
+  /*InsertPos=*/nullptr);
+} else {
+  // Note, we need this connection even if the friend doesn't have a body.
+  // Its body may exist but not have been attached yet due to deferred
+  // parsing.
+  // FIXME: It might be cleaner to set this when attaching the body to the
+  // friend function declaration, however that would require finding all the
+  // instantiations and modifying them.
+  Function->setInstantiationOfMemberFunction(D, TSK_ImplicitInstantiation);
+}
   }
 
   if (InitFunctionInstantiation(Function, D))
@@ -1668,6 +1676,13 @@
 
 isExplicitSpecialization = true;
 
+  } else  if (const FunctionTemplateSpecializationInfo *FTSI =
+   D->getTemplateSpecializationInfo()) {
+void *InsertPos = nullptr;
+FunctionDecl *Prev = FTSI->getTemplate()->findSpecialization(
+ FTSI->TemplateArguments->asArray(), InsertPos);
+if (Prev)
+  Function->setPreviousDeclaration(Prev);

Re: [PATCH] D23006: [clang-rename] add basic Emacs integration

2016-08-01 Thread Haojian Wu via cfe-commits
hokein added inline comments.


Comment at: clang-rename/tool/clang-rename.el:16
@@ +15,3 @@
+
+(defvar clang-rename-binary "clang-rename")
+

I think we should make `clang-rename` binary path configurable by making it a 
custom variable (using `defcustom`).


Comment at: clang-rename/tool/clang-rename.el:20
@@ +19,3 @@
+  "Rename all instances of the symbol at the point using clang-rename"
+  (interactive "sEnter a new name: ")
+  (let (;; Emacs offset is 1-based.

`s` is an extra character here?


Comment at: clang-rename/tool/clang-rename.el:27
@@ +26,3 @@
+(let ((rename-command
+  (format "bash -f -c '%s -offset=%s -new-name=%s -i %s'"
+   clang-rename-binary offset new-name file-name)))

Any reason why not use `call-process-region`?


Comment at: docs/clang-rename.rst:106
@@ +105,3 @@
+clang-rename Emacs integration
+
+

missing two "=".


Comment at: docs/clang-rename.rst:114
@@ +113,3 @@
+Once installed, you can point your cursor to symbols you want to rename, press
+`M-X`, print `clang-rename` and new desired name.
+

`print` doesn't make sense here? I think user should type `clang-rename` and 
new name.


https://reviews.llvm.org/D23006



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


Re: [PATCH] D23006: [clang-rename] add basic Emacs integration

2016-08-01 Thread Alexander Kornienko via cfe-commits
alexfh added inline comments.


Comment at: clang-rename/tool/clang-rename.el:18
@@ +17,3 @@
+
+(defun clang-rename-upstream (new-name)
+  "Rename all instances of the symbol at the point using clang-rename"

The name should be just "clang-rename".


Comment at: docs/clang-rename.rst:100
@@ +99,3 @@
+`cr` and print new desired name. The
+[` key`]
+(http://vim.wikia.com/wiki/Mapping_keys_in_Vim_-_Tutorial_(Part_3)#Map_leader)

Remove the linebreak after "The".


Comment at: docs/clang-rename.rst:114
@@ +113,3 @@
+Once installed, you can point your cursor to symbols you want to rename, press
+`M-X`, print `clang-rename` and new desired name.
+

hokein wrote:
> `print` doesn't make sense here? I think user should type `clang-rename` and 
> new name.
Yep, just s/print/type/.


https://reviews.llvm.org/D23006



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


Re: [PATCH] D22803: [clang-tidy] Fix an unused-using-decl false positive about template arguments infunction call expression.

2016-08-01 Thread Alexander Kornienko via cfe-commits
alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

LG


https://reviews.llvm.org/D22803



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


Re: [PATCH] D23006: [clang-rename] add basic Emacs integration

2016-08-01 Thread Kirill Bobyrev via cfe-commits
omtcyfz added inline comments.


Comment at: clang-rename/tool/clang-rename.el:20
@@ +19,3 @@
+  "Rename all instances of the symbol at the point using clang-rename"
+  (interactive "sEnter a new name: ")
+  (let (;; Emacs offset is 1-based.

hokein wrote:
> `s` is an extra character here?
No, it tells Emacs to read a string.


Comment at: clang-rename/tool/clang-rename.el:27
@@ +26,3 @@
+(let ((rename-command
+  (format "bash -f -c '%s -offset=%s -new-name=%s -i %s'"
+   clang-rename-binary offset new-name file-name)))

hokein wrote:
> Any reason why not use `call-process-region`?
/* discussed */


https://reviews.llvm.org/D23006



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


Re: [PATCH] D23006: [clang-rename] add basic Emacs integration

2016-08-01 Thread Kirill Bobyrev via cfe-commits
omtcyfz updated this revision to Diff 66328.
omtcyfz marked 8 inline comments as done.

https://reviews.llvm.org/D23006

Files:
  clang-rename/tool/clang-rename.el
  docs/clang-rename.rst

Index: docs/clang-rename.rst
===
--- docs/clang-rename.rst
+++ docs/clang-rename.rst
@@ -28,7 +28,7 @@
 work with if you set up a compile command database for your project (for an
 example of how to do this see `How To Setup Tooling For LLVM
 `_). You can also
-specify compilation options on the command line after ``--``:
+specify compilation options on the command line after `--`:
 
 .. code-block:: console
 
@@ -47,7 +47,7 @@
 renaming actions in the future.
 
 :program:`clang-rename` also aims to be easily integrated into popular text
-editors, such as Vim, and improve the workflow of users.
+editors, such as Vim and Emacs, and improve the workflow of users.
 
 Although a command line interface exists, it is highly recommended to use the
 text editor interface instead for better experience.
@@ -96,7 +96,21 @@
 happen before running the tool**.
 
 Once installed, you can point your cursor to symbols you want to rename, press
-``cr`` and print new desired name. The
-[`` 
key``](http://vim.wikia.com/wiki/Mapping_keys_in_Vim_-_Tutorial_(Part_3)#Map_leader)
+`cr` and print new desired name. The [` key`]
+(http://vim.wikia.com/wiki/Mapping_keys_in_Vim_-_Tutorial_(Part_3)#Map_leader)
 is a reference to a specific key defined by the mapleader variable and is bound
 to backslash by default.
+
+clang-rename Emacs integration
+==
+
+You can also use :program:`clang-rename` while using Emacs! To set up
+:program:`clang-rename` integration for Emacs see
+`clang-rename/tool/clang-rename.el
+`_.
+
+Once installed, you can point your cursor to symbols you want to rename, press
+`M-X`, type `clang-rename` and new desired name.
+
+Please note that **you have to save all buffers, in which the replacement will
+happen before running the tool**.
Index: clang-rename/tool/clang-rename.el
===
--- /dev/null
+++ clang-rename/tool/clang-rename.el
@@ -0,0 +1,45 @@
+;;; clang-rename.el --- Renames every occurrence of a symbol found at .
+
+;; Keywords: tools, c
+
+;;; Commentary:
+
+;; To install clang-rename.el make sure the directory of this file is in your
+;; 'load-path' and add
+;;
+;;   (require 'clang-rename)
+;;
+;; to your .emacs configuration.
+
+;;; Code:
+
+(defcustom clang-rename-binary "clang-rename"
+  "Path to clang-rename executable."
+  :type 'hook
+  :options '(turn-on-auto-fill flyspell-mode)
+  :group 'wp)
+
+(defun clang-rename (new-name)
+  "Rename all instances of the symbol at the point using clang-rename"
+  (interactive "sEnter a new name: ")
+  (let (;; Emacs offset is 1-based.
+(offset (- (point) 1))
+(orig-buf (current-buffer))
+(file-name (buffer-file-name)))
+
+(let ((rename-command
+  (format "bash -f -c '%s -offset=%s -new-name=%s -i %s'"
+   clang-rename-binary offset new-name file-name)))
+  (message (format "Running clang-rename command %s" rename-command))
+  ;; Run clang-rename via bash.
+  (shell-command rename-command)
+  ;; Reload buffer.
+  (interactive)
+  (revert-buffer t t)
+)
+  )
+)
+
+(provide 'clang-rename)
+
+;;; clang-rename.el ends here


Index: docs/clang-rename.rst
===
--- docs/clang-rename.rst
+++ docs/clang-rename.rst
@@ -28,7 +28,7 @@
 work with if you set up a compile command database for your project (for an
 example of how to do this see `How To Setup Tooling For LLVM
 `_). You can also
-specify compilation options on the command line after ``--``:
+specify compilation options on the command line after `--`:
 
 .. code-block:: console
 
@@ -47,7 +47,7 @@
 renaming actions in the future.
 
 :program:`clang-rename` also aims to be easily integrated into popular text
-editors, such as Vim, and improve the workflow of users.
+editors, such as Vim and Emacs, and improve the workflow of users.
 
 Although a command line interface exists, it is highly recommended to use the
 text editor interface instead for better experience.
@@ -96,7 +96,21 @@
 happen before running the tool**.
 
 Once installed, you can point your cursor to symbols you want to rename, press
-``cr`` and print new desired name. The
-[`` key``](http://vim.wikia.com/wiki/Mapping_keys_in_Vim_-_Tutorial_(Part_3)#Map_leader)
+`cr` and print new desired name. The [` key`]
+(http://vim.wikia.com/wiki/Mapping_keys_in_Vim_-_Tutorial_(Part_3)#Map_leader)
 is a reference to a specific key defi

Re: [PATCH] D22943: [Driver] Add FIXME's where we can't use effective triples (NFC)

2016-08-01 Thread Vedant Kumar via cfe-commits

> On Jul 30, 2016, at 12:59 PM, Joerg Sonnenberger via cfe-commits 
>  wrote:
> 
> On Thu, Jul 28, 2016 at 10:11:05PM +, Vedant Kumar wrote:
>>  - test/Driver/netbsd.c
>> 
>>We see -mcpu=arm1022e instead of arm926ej-s in a single run.
> 
> Which one exactly?

Here is the test (test/Driver/netbsd.c @ Line 175):

> // ARM: clang{{.*}}" "-cc1" "-triple" "armv5e--netbsd-eabi"
> // ARM: as{{.*}}" "-mcpu=arm926ej-s" "-o"
> // ARM: ld{{.*}}" "--eh-frame-hdr" "-dynamic-linker" "/libexec/ld.elf_so"
> // ARM: "-m" "armelf_nbsd_eabi"
> // ARM: "-o" "a.out" "{{.*}}/usr/lib{{/|}}crt0.o"
> // ARM: "{{.*}}/usr/lib{{/|}}eabi{{/|}}crti.o"
> // ARM: "{{.*}}/usr/lib{{/|}}crtbegin.o" "{{.*}}.o" "-lc"
> // ARM: "{{.*}}/usr/lib{{/|}}crtend.o" "{{.*}}/usr/lib{{/|}}crtn.o"

And here is the test output:

> /Users/vk/Desktop/llvm/tools/clang/test/Driver/netbsd.c:175:9: error: 
> expected string not found in input
> // ARM: as{{.*}}" "-mcpu=arm926ej-s" "-o"
> ^
> :5:81: note: scanning from here
>  "/Users/vk/Desktop/llvm/DA/./bin/clang" "-cc1" "-triple" 
> "armv5e--netbsd-eabi" "-S" "-disable-free" "-main-file-name" "netbsd.c" 
> "-mrelocation-model" "static" "-mthread-model" "posix" "-mdisable-fp-elim" 
> "-masm-verbose" "-no-integrated-as" "-mconstructor-aliases" "-munwind-tables" 
> "-target-cpu" "arm1022e" "-target-feature" "+soft-float-abi" 
> "-target-feature" "+strict-align" "-target-abi" "aapcs" "-mfloat-abi" "soft" 
> "-target-linker-version" "272" "-dwarf-column-info" "-debugger-tuning=gdb" 
> "-resource-dir" "/Users/vk/Desktop/llvm/DA/./bin/../lib/clang/4.0.0" 
> "-isysroot" 
> "/Users/vk/Desktop/llvm/tools/clang/test/Driver/Inputs/basic_netbsd_tree" 
> "-fno-dwarf-directory-asm" "-fdebug-compilation-dir" 
> "/Users/vk/Desktop/llvm/build/tools/clang/test/Driver" "-ferror-limit" "19" 
> "-fmessage-length" "0" "-fallow-half-arguments-and-returns" 
> "-fno-signed-char" "-fobjc-runtime=gnustep" "-fdiagnostics-show-option" "-o" 
> "/var/folders/j5/4k_dcg5j5kl7z4fd3gp1pjp4gn/T/netbsd-0d4ff3.s" "-x" "c" 
> "/Users/vk/Desktop/llvm/tools/clang/test/Driver/netbsd.c"
>   
>   ^
> :6:6: note: possible intended match here
>  "/usr/bin/as" "-mcpu=arm1022e" "-o" 
> "/var/folders/j5/4k_dcg5j5kl7z4fd3gp1pjp4gn/T/netbsd-82d94c.o" 
> "/var/folders/j5/4k_dcg5j5kl7z4fd3gp1pjp4gn/T/netbsd-0d4ff3.s"

For context, the inconsistency arises when the driver uses
ToolChain::ComputeLLVMTriple() instead of the default toolchain triple.

Thanks for taking a look!

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


Re: [PATCH] D23006: [clang-rename] add basic Emacs integration

2016-08-01 Thread Kirill Bobyrev via cfe-commits
omtcyfz added a comment.

All the comments seem to be addressed.


https://reviews.llvm.org/D23006



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


Re: [PATCH] D23009: [clang-rename] handle overridden functions correctly

2016-08-01 Thread Alexander Kornienko via cfe-commits
alexfh requested changes to this revision.
This revision now requires changes to proceed.


Comment at: test/clang-rename/FunctionOverride.cpp:3
@@ +2,3 @@
+
+class A { virtual void foo(); };// CHECK: class A { virtual void boo(); };
+class B : public A { void foo(); }; // CHECK: class B : public A { void boo(); 
};

I guess, this test will pass even if clang-rename doesn't do any changes, since 
the pattern in the CHECK line will match with itself. There are multiple ways 
to fix this. For instance, you can anchor the pattern to the start of line (`// 
CHECK: {{ˆ}}class A ...`) or add `| sed 's,//.*,//'` to the pipeline before `| 
FileCheck %s`.


https://reviews.llvm.org/D23009



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


Re: [PATCH] D22900: Revert r244207 - Mark calls in thunk functions as tail-call optimization

2016-08-01 Thread David Majnemer via cfe-commits
On Sun, Jul 31, 2016 at 10:32 PM, Gerolf Hoflehner 
wrote:

>
> > On Jul 31, 2016, at 1:46 AM, Amjad Aboud  wrote:
> >
> > aaboud added a comment.
> >
> >> ISTM that the DWARF spec intended such thunks to be encoded as
> `DW_AT_trampoline`.  That seems more appropriate than relying on codegen
> emitting a tailcall.  This way the debugger can make the policy decision of
> whether or not thunks should show up in the backtrace.
> >
> >>
> >
> >> In any case, correctness must always trump all else.  Reverting to
> green should take precedence over a QoI bug like PR24235.
> >
> >
> > I agree to the revert, though I am not sure about the new test, it looks
> too complected, especially the command line.
>
> An app crashed somewhere because it loaded a garbage value from the stack.
> To show that problem the test is.a little longer than it would be if we
> only wanted to check " no tail + byval “.
>

It is frowned upon to have tests which rely on LLVM's optimizers, it makes
the resulting test susceptible to changes in code unrelated to clang.  I'd
recommend we change the test to check for no tail + byval.


> > I will let David decide on accepting that test or ask for improvement.
> >
> > Regards,
> > Amjad
> >
> >
> > https://reviews.llvm.org/D22900
> >
> >
> >
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [clang-tools-extra] r276836 - test: simplify commands, NFC

2016-08-01 Thread Alexander Kornienko via cfe-commits
On Wed, Jul 27, 2016 at 6:43 AM, Saleem Abdulrasool via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: compnerd
> Date: Tue Jul 26 23:43:15 2016
> New Revision: 276836
>
> URL: http://llvm.org/viewvc/llvm-project?rev=276836&view=rev
> Log:
> test: simplify commands, NFC
>
> Rather than copying the file and then doing an in-place edit, perform the
> replacements to stdout and pass the output to FileCheck directly.  Avoids
> unnecessary copying and seds.
>
> Modified:
>
> clang-tools-extra/trunk/test/clang-rename/ClassAsTemplateArgumentFindByClass.cpp
>
> clang-tools-extra/trunk/test/clang-rename/ClassAsTemplateArgumentFindByTemplateArgument.cpp
> clang-tools-extra/trunk/test/clang-rename/ClassFindByName.cpp
>
> clang-tools-extra/trunk/test/clang-rename/ClassNameInFunctionDefenition.cpp
> clang-tools-extra/trunk/test/clang-rename/ClassSimpleRenaming.cpp
> clang-tools-extra/trunk/test/clang-rename/ComplicatedClassType.cpp
> clang-tools-extra/trunk/test/clang-rename/ConstCastExpr.cpp
> clang-tools-extra/trunk/test/clang-rename/ConstructExpr.cpp
> clang-tools-extra/trunk/test/clang-rename/CtorFindByDeclaration.cpp
> clang-tools-extra/trunk/test/clang-rename/CtorFindByDefinition.cpp
> clang-tools-extra/trunk/test/clang-rename/CtorInitializer.cpp
> clang-tools-extra/trunk/test/clang-rename/DeclRefExpr.cpp
> clang-tools-extra/trunk/test/clang-rename/DtorDeclaration.cpp
> clang-tools-extra/trunk/test/clang-rename/DtorDefinition.cpp
> clang-tools-extra/trunk/test/clang-rename/DynamicCastExpr.cpp
> clang-tools-extra/trunk/test/clang-rename/Field.cpp
> clang-tools-extra/trunk/test/clang-rename/FunctionMacro.cpp
> clang-tools-extra/trunk/test/clang-rename/MemberExprMacro.cpp
> clang-tools-extra/trunk/test/clang-rename/Namespace.cpp
> clang-tools-extra/trunk/test/clang-rename/ReinterpretCastExpr.cpp
> clang-tools-extra/trunk/test/clang-rename/StaticCastExpr.cpp
>
> clang-tools-extra/trunk/test/clang-rename/TemplateFunctionFindByDeclaration.cpp
> clang-tools-extra/trunk/test/clang-rename/TemplateFunctionFindByUse.cpp
>
> clang-tools-extra/trunk/test/clang-rename/TemplateTypenameFindByTypeInside.cpp
>
> clang-tools-extra/trunk/test/clang-rename/UserDefinedConversionFindByTypeDeclaration.cpp
> clang-tools-extra/trunk/test/clang-rename/Variable.cpp
> clang-tools-extra/trunk/test/clang-rename/VariableMacro.cpp
>
> Modified:
> clang-tools-extra/trunk/test/clang-rename/ClassAsTemplateArgumentFindByClass.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-rename/ClassAsTemplateArgumentFindByClass.cpp?rev=276836&r1=276835&r2=276836&view=diff
>
> ==
> ---
> clang-tools-extra/trunk/test/clang-rename/ClassAsTemplateArgumentFindByClass.cpp
> (original)
> +++
> clang-tools-extra/trunk/test/clang-rename/ClassAsTemplateArgumentFindByClass.cpp
> Tue Jul 26 23:43:15 2016
> @@ -1,6 +1,4 @@
> -// RUN: cat %s > %t.cpp
> -// RUN: clang-rename -offset=136 -new-name=Bar %t.cpp -i --
> -// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s
> +// RUN: clang-rename -offset=74 -new-name=Bar %s -- | FileCheck %s
>

This patch changes behavior of the tests. Namely, it makes most tests pass
even if clang-rename doesn't do anything. The reason is that the CHECK
patterns that don't contain regular expressions will match with themselves
(previously, `sed 's,//.*,,` would remove them).

Please revert or fix (or better revert and then post another patch for
review).


>
>  class Foo {};   // CHECK: class Bar {};
>
>
> Modified:
> clang-tools-extra/trunk/test/clang-rename/ClassAsTemplateArgumentFindByTemplateArgument.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-rename/ClassAsTemplateArgumentFindByTemplateArgument.cpp?rev=276836&r1=276835&r2=276836&view=diff
>
> ==
> ---
> clang-tools-extra/trunk/test/clang-rename/ClassAsTemplateArgumentFindByTemplateArgument.cpp
> (original)
> +++
> clang-tools-extra/trunk/test/clang-rename/ClassAsTemplateArgumentFindByTemplateArgument.cpp
> Tue Jul 26 23:43:15 2016
> @@ -1,6 +1,4 @@
> -// RUN: cat %s > %t.cpp
> -// RUN: clang-rename -offset=304 -new-name=Bar %t.cpp -i --
> -// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s
> +// RUN: clang-rename -offset=243 -new-name=Bar %s -- | FileCheck %s
>
>  class Foo {};   // CHECK: class Bar {};
>
>
> Modified: clang-tools-extra/trunk/test/clang-rename/ClassFindByName.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-rename/ClassFindByName.cpp?rev=276836&r1=276835&r2=276836&view=diff
>
> ==
> --- clang-tools-extra/trunk/test/clang-rename/ClassFindByName.cpp
> (original)
> +++ clang-tools-extra/trunk/test/clang-rename/ClassFindByName.cpp Tue Jul
> 26 23:43:15 2016
> @@ -1,6

r277352 - [Parse] Let declarations follow labels in -fms-extensions mode

2016-08-01 Thread David Majnemer via cfe-commits
Author: majnemer
Date: Mon Aug  1 11:39:29 2016
New Revision: 277352

URL: http://llvm.org/viewvc/llvm-project?rev=277352&view=rev
Log:
[Parse] Let declarations follow labels in -fms-extensions mode

MSVC permits declarations in these places as conforming extension (it is
a constraint violation otherwise).

This fixes PR28782.

Modified:
cfe/trunk/lib/Parse/ParseStmt.cpp
cfe/trunk/test/Parser/MicrosoftExtensions.c

Modified: cfe/trunk/lib/Parse/ParseStmt.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseStmt.cpp?rev=277352&r1=277351&r2=277352&view=diff
==
--- cfe/trunk/lib/Parse/ParseStmt.cpp (original)
+++ cfe/trunk/lib/Parse/ParseStmt.cpp Mon Aug  1 11:39:29 2016
@@ -206,7 +206,8 @@ Retry:
   }
 
   default: {
-if ((getLangOpts().CPlusPlus || Allowed == ACK_Any) &&
+if ((getLangOpts().CPlusPlus || getLangOpts().MicrosoftExt ||
+ Allowed == ACK_Any) &&
 isDeclarationStatement()) {
   SourceLocation DeclStart = Tok.getLocation(), DeclEnd;
   DeclGroupPtrTy Decl = ParseDeclaration(Declarator::BlockContext,

Modified: cfe/trunk/test/Parser/MicrosoftExtensions.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/MicrosoftExtensions.c?rev=277352&r1=277351&r2=277352&view=diff
==
--- cfe/trunk/test/Parser/MicrosoftExtensions.c (original)
+++ cfe/trunk/test/Parser/MicrosoftExtensions.c Mon Aug  1 11:39:29 2016
@@ -106,3 +106,12 @@ __declspec(align(16)) struct align_befor
 _Static_assert(__alignof(struct align_before_key1) == 16, "");
 _Static_assert(__alignof(struct align_before_key2) == 16, "");
 _Static_assert(__alignof(struct align_before_key3) == 16, "");
+
+void PR28782(int i) {
+foo:
+  int n;
+  switch (i) {
+  case 0:
+int m;
+  }
+}


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


[clang-tools-extra] r277354 - [clang-rename] revert r276836

2016-08-01 Thread Kirill Bobyrev via cfe-commits
Author: omtcyfz
Date: Mon Aug  1 11:48:33 2016
New Revision: 277354

URL: http://llvm.org/viewvc/llvm-project?rev=277354&view=rev
Log:
[clang-rename] revert r276836

Revert r276836, which resulted in tests passing regardless of the actual tool
replacements.


Modified:

clang-tools-extra/trunk/test/clang-rename/ClassAsTemplateArgumentFindByClass.cpp

clang-tools-extra/trunk/test/clang-rename/ClassAsTemplateArgumentFindByTemplateArgument.cpp
clang-tools-extra/trunk/test/clang-rename/ClassFindByName.cpp
clang-tools-extra/trunk/test/clang-rename/ClassNameInFunctionDefinition.cpp
clang-tools-extra/trunk/test/clang-rename/ClassSimpleRenaming.cpp
clang-tools-extra/trunk/test/clang-rename/ComplicatedClassType.cpp
clang-tools-extra/trunk/test/clang-rename/ConstCastExpr.cpp
clang-tools-extra/trunk/test/clang-rename/ConstructExpr.cpp
clang-tools-extra/trunk/test/clang-rename/CtorFindByDeclaration.cpp
clang-tools-extra/trunk/test/clang-rename/CtorFindByDefinition.cpp
clang-tools-extra/trunk/test/clang-rename/CtorInitializer.cpp
clang-tools-extra/trunk/test/clang-rename/DeclRefExpr.cpp
clang-tools-extra/trunk/test/clang-rename/DtorDeclaration.cpp
clang-tools-extra/trunk/test/clang-rename/DtorDefinition.cpp
clang-tools-extra/trunk/test/clang-rename/DynamicCastExpr.cpp
clang-tools-extra/trunk/test/clang-rename/Field.cpp
clang-tools-extra/trunk/test/clang-rename/FunctionMacro.cpp
clang-tools-extra/trunk/test/clang-rename/MemberExprMacro.cpp
clang-tools-extra/trunk/test/clang-rename/Namespace.cpp
clang-tools-extra/trunk/test/clang-rename/ReinterpretCastExpr.cpp
clang-tools-extra/trunk/test/clang-rename/StaticCastExpr.cpp

clang-tools-extra/trunk/test/clang-rename/TemplateFunctionFindByDeclaration.cpp
clang-tools-extra/trunk/test/clang-rename/TemplateFunctionFindByUse.cpp

clang-tools-extra/trunk/test/clang-rename/TemplateTypenameFindByTypeInside.cpp

clang-tools-extra/trunk/test/clang-rename/UserDefinedConversionFindByTypeDeclaration.cpp
clang-tools-extra/trunk/test/clang-rename/Variable.cpp
clang-tools-extra/trunk/test/clang-rename/VariableMacro.cpp

Modified: 
clang-tools-extra/trunk/test/clang-rename/ClassAsTemplateArgumentFindByClass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-rename/ClassAsTemplateArgumentFindByClass.cpp?rev=277354&r1=277353&r2=277354&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-rename/ClassAsTemplateArgumentFindByClass.cpp
 (original)
+++ 
clang-tools-extra/trunk/test/clang-rename/ClassAsTemplateArgumentFindByClass.cpp
 Mon Aug  1 11:48:33 2016
@@ -1,4 +1,6 @@
-// RUN: clang-rename -offset=74 -new-name=Bar %s -- | FileCheck %s
+// RUN: cat %s > %t.cpp
+// RUN: clang-rename -offset=136 -new-name=Bar %t.cpp -i --
+// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s
 
 class Foo {};   // CHECK: class Bar {};
 

Modified: 
clang-tools-extra/trunk/test/clang-rename/ClassAsTemplateArgumentFindByTemplateArgument.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-rename/ClassAsTemplateArgumentFindByTemplateArgument.cpp?rev=277354&r1=277353&r2=277354&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-rename/ClassAsTemplateArgumentFindByTemplateArgument.cpp
 (original)
+++ 
clang-tools-extra/trunk/test/clang-rename/ClassAsTemplateArgumentFindByTemplateArgument.cpp
 Mon Aug  1 11:48:33 2016
@@ -1,4 +1,6 @@
-// RUN: clang-rename -offset=243 -new-name=Bar %s -- | FileCheck %s
+// RUN: cat %s > %t.cpp
+// RUN: clang-rename -offset=304 -new-name=Bar %t.cpp -i --
+// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s
 
 class Foo {};   // CHECK: class Bar {};
 

Modified: clang-tools-extra/trunk/test/clang-rename/ClassFindByName.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-rename/ClassFindByName.cpp?rev=277354&r1=277353&r2=277354&view=diff
==
--- clang-tools-extra/trunk/test/clang-rename/ClassFindByName.cpp (original)
+++ clang-tools-extra/trunk/test/clang-rename/ClassFindByName.cpp Mon Aug  1 
11:48:33 2016
@@ -1,4 +1,6 @@
-// RUN: clang-rename -old-name=Foo -new-name=Bar %s -- | FileCheck %s
+// RUN: cat %s > %t.cpp
+// RUN: clang-rename -old-name=Foo -new-name=Bar %t.cpp -i --
+// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s
 
 class Foo { // CHECK: class Bar
 };

Modified: 
clang-tools-extra/trunk/test/clang-rename/ClassNameInFunctionDefinition.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-rename/ClassNameInFunctionDefinition.cpp?rev=277354&r1=277353&r2=277354&view=diff
==
--- clang-tools-extra/trunk/test/clang-rename/ClassNameInFunctionDefinition.cpp 
(original)
+++ clang

Re: [PATCH] D23009: [clang-rename] handle overridden functions correctly

2016-08-01 Thread Kirill Bobyrev via cfe-commits
omtcyfz updated this revision to Diff 66338.
omtcyfz marked an inline comment as done.

https://reviews.llvm.org/D23009

Files:
  clang-rename/USRFindingAction.cpp
  test/clang-rename/FunctionOverride.cpp

Index: test/clang-rename/FunctionOverride.cpp
===
--- /dev/null
+++ test/clang-rename/FunctionOverride.cpp
@@ -0,0 +1,10 @@
+// RUN: cat %s > %t.cpp
+// RUN: clang-rename -offset=318 -new-name=bar %t.cpp -i --
+// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s
+
+class A { virtual void foo(); };// CHECK: class A { virtual void bar(); };
+class B : public A { void foo(); }; // CHECK: class B : public A { void bar(); 
};
+class C : public B { void foo(); }; // CHECK: class C : public B { void bar(); 
};
+
+// Use grep -FUbo 'Foo'  to get the correct offset of Foo when changing
+// this file.
Index: clang-rename/USRFindingAction.cpp
===
--- clang-rename/USRFindingAction.cpp
+++ clang-rename/USRFindingAction.cpp
@@ -54,21 +54,25 @@
 
   void Find() {
 USRSet.insert(getUSRForDecl(FoundDecl));
-addUSRsFromOverrideSetsAndCtorDtors();
+if (const auto *MethodDecl = dyn_cast(FoundDecl)) {
+  addUSRsFromOverrideSets(MethodDecl);
+}
+if (const auto *RecordDecl = dyn_cast(FoundDecl)) {
+  addUSRsOfCtorDtors(RecordDecl);
+}
 addMatchers();
 Finder.matchAST(Context);
 USRs->insert(USRs->end(), USRSet.begin(), USRSet.end());
   }
 
 private:
   void addMatchers() {
 const auto CXXMethodDeclMatcher =
-cxxMethodDecl(isVirtual()).bind("cxxMethodDecl");
+
cxxMethodDecl(forEachOverridden(cxxMethodDecl().bind("cxxMethodDecl")));
 Finder.addMatcher(CXXMethodDeclMatcher, this);
   }
 
-  // FIXME: Implement hasOverriddenMethod and matchesUSR matchers to make
-  // lookups more efficient.
+  // FIXME: Implement matchesUSR matchers to make lookups more efficient.
   virtual void run(const MatchFinder::MatchResult &Result) {
 const auto *VirtualMethod =
 Result.Nodes.getNodeAs("cxxMethodDecl");
@@ -83,20 +87,19 @@
 }
   }
 
-  void addUSRsFromOverrideSetsAndCtorDtors() {
-// If D is CXXRecordDecl we should add all USRs of its constructors.
-if (const auto *RecordDecl = dyn_cast(FoundDecl)) {
-  RecordDecl = RecordDecl->getDefinition();
-  for (const auto *CtorDecl : RecordDecl->ctors()) {
-USRSet.insert(getUSRForDecl(CtorDecl));
-  }
-  USRSet.insert(getUSRForDecl(RecordDecl->getDestructor()));
+  void addUSRsOfCtorDtors(const CXXRecordDecl *RecordDecl) {
+RecordDecl = RecordDecl->getDefinition();
+for (const auto *CtorDecl : RecordDecl->ctors()) {
+  USRSet.insert(getUSRForDecl(CtorDecl));
 }
-// If D is CXXMethodDecl we should add all USRs of its overriden methods.
-if (const auto *MethodDecl = dyn_cast(FoundDecl)) {
-  for (auto &OverriddenMethod : MethodDecl->overridden_methods()) {
-USRSet.insert(getUSRForDecl(OverriddenMethod));
-  }
+USRSet.insert(getUSRForDecl(RecordDecl->getDestructor()));
+  }
+
+  void addUSRsFromOverrideSets(const CXXMethodDecl *MethodDecl) {
+USRSet.insert(getUSRForDecl(MethodDecl));
+for (auto &OverriddenMethod : MethodDecl->overridden_methods()) {
+  // Recursively visit each OverridenMethod.
+  addUSRsFromOverrideSets(OverriddenMethod);
 }
   }
 


Index: test/clang-rename/FunctionOverride.cpp
===
--- /dev/null
+++ test/clang-rename/FunctionOverride.cpp
@@ -0,0 +1,10 @@
+// RUN: cat %s > %t.cpp
+// RUN: clang-rename -offset=318 -new-name=bar %t.cpp -i --
+// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s
+
+class A { virtual void foo(); };// CHECK: class A { virtual void bar(); };
+class B : public A { void foo(); }; // CHECK: class B : public A { void bar(); };
+class C : public B { void foo(); }; // CHECK: class C : public B { void bar(); };
+
+// Use grep -FUbo 'Foo'  to get the correct offset of Foo when changing
+// this file.
Index: clang-rename/USRFindingAction.cpp
===
--- clang-rename/USRFindingAction.cpp
+++ clang-rename/USRFindingAction.cpp
@@ -54,21 +54,25 @@
 
   void Find() {
 USRSet.insert(getUSRForDecl(FoundDecl));
-addUSRsFromOverrideSetsAndCtorDtors();
+if (const auto *MethodDecl = dyn_cast(FoundDecl)) {
+  addUSRsFromOverrideSets(MethodDecl);
+}
+if (const auto *RecordDecl = dyn_cast(FoundDecl)) {
+  addUSRsOfCtorDtors(RecordDecl);
+}
 addMatchers();
 Finder.matchAST(Context);
 USRs->insert(USRs->end(), USRSet.begin(), USRSet.end());
   }
 
 private:
   void addMatchers() {
 const auto CXXMethodDeclMatcher =
-cxxMethodDecl(isVirtual()).bind("cxxMethodDecl");
+cxxMethodDecl(forEachOverridden(cxxMethodDecl().bind("cxxMethodDecl")));
 Finder.addMatcher(CXXMethodDeclMatcher, this);
   }
 
-  

Re: [PATCH] D23004: [ASTMatchers] Add matchers canReferToDecl() and hasUnderlyingDecl()

2016-08-01 Thread Alexander Kornienko via cfe-commits
alexfh added a subscriber: alexfh.


Comment at: include/clang/ASTMatchers/ASTMatchers.h:2440
@@ +2439,3 @@
+
+  return (UnderlyingDecl != nullptr &&
+  InnerMatcher.matches(*UnderlyingDecl, Finder, Builder));

nit: Parentheses are superfluous here.


Comment at: include/clang/ASTMatchers/ASTMatchers.h:2807
@@ +2806,3 @@
+/// \endcode
+/// unresolvedLookupExpr(canReferToDecl(functionDecl()))
+///   matches \c foo in \c foo(t);

Please add an `unresolvedLookupExpr` that this matcher doesn't match (maybe 
change the matcher to make it easier).


https://reviews.llvm.org/D23004



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


Re: [PATCH] D23009: [clang-rename] handle overridden functions correctly

2016-08-01 Thread Alexander Kornienko via cfe-commits
alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

LG


https://reviews.llvm.org/D23009



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


Re: [PATCH] D22853: [clang-rename] add support for template parameter renaming

2016-08-01 Thread Alexander Kornienko via cfe-commits
alexfh requested changes to this revision.
This revision now requires changes to proceed.


Comment at: clang-rename/USRFinder.cpp:80
@@ -79,1 +79,3 @@
 TypeBeginLoc, 0, Context.getSourceManager(), Context.getLangOpts());
+if (const auto *TemplateTypeParm = 
dyn_cast(Loc.getType())) {
+  return setResult(TemplateTypeParm->getDecl(), TypeBeginLoc, TypeEndLoc);

It's not common to use braces around single-line `if` bodies in LLVM/Clang code.


Comment at: clang-rename/USRLocFinder.cpp:104
@@ -103,1 +103,3 @@
 }
+if (const auto TemplateTypeParm = 
dyn_cast(Loc.getType())) {
+  if (getUSRForDecl(TemplateTypeParm->getDecl()) == USR) {

nit: `const auto *`


Comment at: test/clang-rename/TemplateTypenameFindByTemplateParam.cpp:1
@@ -1,8 +1,2 @@
-// RUN: cat %s > %t.cpp
-// RUN: clang-rename -offset=270 -new-name=U %t.cpp -i --
-// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s
-
-// Currently unsupported test.
-// FIXME: clang-rename should be able to rename template parameters correctly.
-// XFAIL: *
+// RUN: clang-rename -offset=87 -new-name=Bar %s -- | FileCheck %s
 

As noted elsewhere, this way of testing is wrong.


Comment at: test/clang-rename/TemplateTypenameFindByTypeInside.cpp:1
@@ -1,6 +1,2 @@
-// RUN: clang-rename -offset=289 -new-name=U %s -- | FileCheck %s
-
-// Currently unsupported test.
-// FIXME: clang-rename should be able to rename template parameters correctly.
-// XFAIL: *
+// RUN: clang-rename -offset=153 -new-name=Bar %s -- | FileCheck %s
 

ditto


https://reviews.llvm.org/D22853



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


Re: [PATCH] D23006: [clang-rename] add basic Emacs integration

2016-08-01 Thread Alexander Kornienko via cfe-commits
alexfh added inline comments.


Comment at: clang-rename/tool/clang-rename.el:28
@@ +27,3 @@
+(orig-buf (current-buffer))
+(file-name (buffer-file-name)))
+

For posterity, please add a short summary of the offline discussion.


Comment at: docs/clang-rename.rst:104
@@ +103,3 @@
+
+clang-rename Emacs integration
+==

Either `Clang-rename Emacs integration` or just `Emacs integration`.


https://reviews.llvm.org/D23006



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


Re: [PATCH] D23009: [clang-rename] handle overridden functions correctly

2016-08-01 Thread Kirill Bobyrev via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL277356: [clang-rename] handle overridden functions correctly 
(authored by omtcyfz).

Changed prior to commit:
  https://reviews.llvm.org/D23009?vs=66338&id=66340#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D23009

Files:
  clang-tools-extra/trunk/clang-rename/USRFindingAction.cpp
  clang-tools-extra/trunk/test/clang-rename/FunctionOverride.cpp
  clang-tools-extra/trunk/test/clang-rename/FunctionWithClassFindByName.cpp
  clang-tools-extra/trunk/test/clang-rename/UserDefinedConversion.cpp

Index: clang-tools-extra/trunk/clang-rename/USRFindingAction.cpp
===
--- clang-tools-extra/trunk/clang-rename/USRFindingAction.cpp
+++ clang-tools-extra/trunk/clang-rename/USRFindingAction.cpp
@@ -54,21 +54,25 @@
 
   void Find() {
 USRSet.insert(getUSRForDecl(FoundDecl));
-addUSRsFromOverrideSetsAndCtorDtors();
+if (const auto *MethodDecl = dyn_cast(FoundDecl)) {
+  addUSRsFromOverrideSets(MethodDecl);
+}
+if (const auto *RecordDecl = dyn_cast(FoundDecl)) {
+  addUSRsOfCtorDtors(RecordDecl);
+}
 addMatchers();
 Finder.matchAST(Context);
 USRs->insert(USRs->end(), USRSet.begin(), USRSet.end());
   }
 
 private:
   void addMatchers() {
 const auto CXXMethodDeclMatcher =
-cxxMethodDecl(isVirtual()).bind("cxxMethodDecl");
+cxxMethodDecl(forEachOverridden(cxxMethodDecl().bind("cxxMethodDecl")));
 Finder.addMatcher(CXXMethodDeclMatcher, this);
   }
 
-  // FIXME: Implement hasOverriddenMethod and matchesUSR matchers to make
-  // lookups more efficient.
+  // FIXME: Implement matchesUSR matchers to make lookups more efficient.
   virtual void run(const MatchFinder::MatchResult &Result) {
 const auto *VirtualMethod =
 Result.Nodes.getNodeAs("cxxMethodDecl");
@@ -83,20 +87,19 @@
 }
   }
 
-  void addUSRsFromOverrideSetsAndCtorDtors() {
-// If D is CXXRecordDecl we should add all USRs of its constructors.
-if (const auto *RecordDecl = dyn_cast(FoundDecl)) {
-  RecordDecl = RecordDecl->getDefinition();
-  for (const auto *CtorDecl : RecordDecl->ctors()) {
-USRSet.insert(getUSRForDecl(CtorDecl));
-  }
-  USRSet.insert(getUSRForDecl(RecordDecl->getDestructor()));
+  void addUSRsOfCtorDtors(const CXXRecordDecl *RecordDecl) {
+RecordDecl = RecordDecl->getDefinition();
+for (const auto *CtorDecl : RecordDecl->ctors()) {
+  USRSet.insert(getUSRForDecl(CtorDecl));
 }
-// If D is CXXMethodDecl we should add all USRs of its overriden methods.
-if (const auto *MethodDecl = dyn_cast(FoundDecl)) {
-  for (auto &OverriddenMethod : MethodDecl->overridden_methods()) {
-USRSet.insert(getUSRForDecl(OverriddenMethod));
-  }
+USRSet.insert(getUSRForDecl(RecordDecl->getDestructor()));
+  }
+
+  void addUSRsFromOverrideSets(const CXXMethodDecl *MethodDecl) {
+USRSet.insert(getUSRForDecl(MethodDecl));
+for (auto &OverriddenMethod : MethodDecl->overridden_methods()) {
+  // Recursively visit each OverridenMethod.
+  addUSRsFromOverrideSets(OverriddenMethod);
 }
   }
 
Index: clang-tools-extra/trunk/test/clang-rename/UserDefinedConversion.cpp
===
--- clang-tools-extra/trunk/test/clang-rename/UserDefinedConversion.cpp
+++ clang-tools-extra/trunk/test/clang-rename/UserDefinedConversion.cpp
@@ -1,4 +1,6 @@
-// RUN: clang-rename -offset=143 -new-name=Bar %s -- | FileCheck %s
+// RUN: cat %s > %t.cpp
+// RUN: clang-rename -offset=205 -new-name=Bar %t.cpp -i --
+// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s
 
 class Foo {}; // CHECK: class Bar {};
 
Index: clang-tools-extra/trunk/test/clang-rename/FunctionOverride.cpp
===
--- clang-tools-extra/trunk/test/clang-rename/FunctionOverride.cpp
+++ clang-tools-extra/trunk/test/clang-rename/FunctionOverride.cpp
@@ -0,0 +1,10 @@
+// RUN: cat %s > %t.cpp
+// RUN: clang-rename -offset=318 -new-name=bar %t.cpp -i --
+// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s
+
+class A { virtual void foo(); };// CHECK: class A { virtual void bar(); };
+class B : public A { void foo(); }; // CHECK: class B : public A { void bar(); };
+class C : public B { void foo(); }; // CHECK: class C : public B { void bar(); };
+
+// Use grep -FUbo 'Foo'  to get the correct offset of Foo when changing
+// this file.
Index: clang-tools-extra/trunk/test/clang-rename/FunctionWithClassFindByName.cpp
===
--- clang-tools-extra/trunk/test/clang-rename/FunctionWithClassFindByName.cpp
+++ clang-tools-extra/trunk/test/clang-rename/FunctionWithClassFindByName.cpp
@@ -1,4 +1,6 @@
-// RUN: clang-rename -old-name=Foo -new-name=Bar %s -- | FileCheck %s
+// RUN: cat %s > %t.cpp
+// RUN: clang-rename -old-name=Foo -new-name

Re: [PATCH] D23006: [clang-rename] add basic Emacs integration

2016-08-01 Thread Kirill Bobyrev via cfe-commits
omtcyfz updated this revision to Diff 66341.

https://reviews.llvm.org/D23006

Files:
  clang-rename/tool/clang-rename.el
  docs/clang-rename.rst

Index: docs/clang-rename.rst
===
--- docs/clang-rename.rst
+++ docs/clang-rename.rst
@@ -20,15 +20,15 @@
 project. If you have any ideas or suggestions, you might want to put a feature
 request there.
 
-Using clang-rename
+Using Clang-Rename
 ==
 
 :program:`clang-rename` is a `LibTooling
 `_-based tool, and it's easier to
 work with if you set up a compile command database for your project (for an
 example of how to do this see `How To Setup Tooling For LLVM
 `_). You can also
-specify compilation options on the command line after ``--``:
+specify compilation options on the command line after `--`:
 
 .. code-block:: console
 
@@ -47,7 +47,7 @@
 renaming actions in the future.
 
 :program:`clang-rename` also aims to be easily integrated into popular text
-editors, such as Vim, and improve the workflow of users.
+editors, such as Vim and Emacs, and improve the workflow of users.
 
 Although a command line interface exists, it is highly recommended to use the
 text editor interface instead for better experience.
@@ -84,8 +84,8 @@
 -version   - Display the version of this program
 
 
-clang-rename Vim integration
-
+Vim Integration
+===
 
 You can call :program:`clang-rename` directly from Vim! To set up
 :program:`clang-rename` integration for Vim see
@@ -96,7 +96,21 @@
 happen before running the tool**.
 
 Once installed, you can point your cursor to symbols you want to rename, press
-``cr`` and print new desired name. The
-[`` key``](http://vim.wikia.com/wiki/Mapping_keys_in_Vim_-_Tutorial_(Part_3)#Map_leader)
+`cr` and print new desired name. The [` key`]
+(http://vim.wikia.com/wiki/Mapping_keys_in_Vim_-_Tutorial_(Part_3)#Map_leader)
 is a reference to a specific key defined by the mapleader variable and is bound
 to backslash by default.
+
+Emacs Integration
+=
+
+You can also use :program:`clang-rename` while using Emacs! To set up
+:program:`clang-rename` integration for Emacs see
+`clang-rename/tool/clang-rename.el
+`_.
+
+Once installed, you can point your cursor to symbols you want to rename, press
+`M-X`, type `clang-rename` and new desired name.
+
+Please note that **you have to save all buffers, in which the replacement will
+happen before running the tool**.
Index: clang-rename/tool/clang-rename.el
===
--- /dev/null
+++ clang-rename/tool/clang-rename.el
@@ -0,0 +1,45 @@
+;;; clang-rename.el --- Renames every occurrence of a symbol found at .
+
+;; Keywords: tools, c
+
+;;; Commentary:
+
+;; To install clang-rename.el make sure the directory of this file is in your
+;; 'load-path' and add
+;;
+;;   (require 'clang-rename)
+;;
+;; to your .emacs configuration.
+
+;;; Code:
+
+(defcustom clang-rename-binary "clang-rename"
+  "Path to clang-rename executable."
+  :type 'hook
+  :options '(turn-on-auto-fill flyspell-mode)
+  :group 'wp)
+
+(defun clang-rename (new-name)
+  "Rename all instances of the symbol at the point using clang-rename"
+  (interactive "sEnter a new name: ")
+  (let (;; Emacs offset is 1-based.
+(offset (- (point) 1))
+(orig-buf (current-buffer))
+(file-name (buffer-file-name)))
+
+(let ((rename-command
+  (format "bash -f -c '%s -offset=%s -new-name=%s -i %s'"
+   clang-rename-binary offset new-name file-name)))
+  (message (format "Running clang-rename command %s" rename-command))
+  ;; Run clang-rename via bash.
+  (shell-command rename-command)
+  ;; Reload buffer.
+  (interactive)
+  (revert-buffer t t)
+)
+  )
+)
+
+(provide 'clang-rename)
+
+;;; clang-rename.el ends here
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D23006: [clang-rename] add basic Emacs integration

2016-08-01 Thread Kirill Bobyrev via cfe-commits
omtcyfz marked 2 inline comments as done.


Comment at: clang-rename/tool/clang-rename.el:28
@@ +27,3 @@
+(orig-buf (current-buffer))
+(file-name (buffer-file-name)))
+

alexfh wrote:
> For posterity, please add a short summary of the offline discussion.
`call-process-region` is used while contents of current buffer are to be 
replaced, but in case of `clang-rename` changes might affect all buffers, which 
doesn't make sense to take care of one buffer only.


https://reviews.llvm.org/D23006



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


[clang-tools-extra] r277356 - [clang-rename] handle overridden functions correctly

2016-08-01 Thread Kirill Bobyrev via cfe-commits
Author: omtcyfz
Date: Mon Aug  1 12:15:57 2016
New Revision: 277356

URL: http://llvm.org/viewvc/llvm-project?rev=277356&view=rev
Log:
[clang-rename] handle overridden functions correctly

1. Renaming overridden functions only works for two levels of "overriding
   hierarchy". clang-rename should recursively add overridden methods.
2. Make use of forEachOverridden AST Matcher.
3. Fix two tests.

Reviewers: alexfh

Differential Revision: https://reviews.llvm.org/D23009


Added:
clang-tools-extra/trunk/test/clang-rename/FunctionOverride.cpp
Modified:
clang-tools-extra/trunk/clang-rename/USRFindingAction.cpp
clang-tools-extra/trunk/test/clang-rename/FunctionWithClassFindByName.cpp
clang-tools-extra/trunk/test/clang-rename/UserDefinedConversion.cpp

Modified: clang-tools-extra/trunk/clang-rename/USRFindingAction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-rename/USRFindingAction.cpp?rev=277356&r1=277355&r2=277356&view=diff
==
--- clang-tools-extra/trunk/clang-rename/USRFindingAction.cpp (original)
+++ clang-tools-extra/trunk/clang-rename/USRFindingAction.cpp Mon Aug  1 
12:15:57 2016
@@ -54,7 +54,12 @@ public:
 
   void Find() {
 USRSet.insert(getUSRForDecl(FoundDecl));
-addUSRsFromOverrideSetsAndCtorDtors();
+if (const auto *MethodDecl = dyn_cast(FoundDecl)) {
+  addUSRsFromOverrideSets(MethodDecl);
+}
+if (const auto *RecordDecl = dyn_cast(FoundDecl)) {
+  addUSRsOfCtorDtors(RecordDecl);
+}
 addMatchers();
 Finder.matchAST(Context);
 USRs->insert(USRs->end(), USRSet.begin(), USRSet.end());
@@ -63,12 +68,11 @@ public:
 private:
   void addMatchers() {
 const auto CXXMethodDeclMatcher =
-cxxMethodDecl(isVirtual()).bind("cxxMethodDecl");
+
cxxMethodDecl(forEachOverridden(cxxMethodDecl().bind("cxxMethodDecl")));
 Finder.addMatcher(CXXMethodDeclMatcher, this);
   }
 
-  // FIXME: Implement hasOverriddenMethod and matchesUSR matchers to make
-  // lookups more efficient.
+  // FIXME: Implement matchesUSR matchers to make lookups more efficient.
   virtual void run(const MatchFinder::MatchResult &Result) {
 const auto *VirtualMethod =
 Result.Nodes.getNodeAs("cxxMethodDecl");
@@ -83,20 +87,19 @@ private:
 }
   }
 
-  void addUSRsFromOverrideSetsAndCtorDtors() {
-// If D is CXXRecordDecl we should add all USRs of its constructors.
-if (const auto *RecordDecl = dyn_cast(FoundDecl)) {
-  RecordDecl = RecordDecl->getDefinition();
-  for (const auto *CtorDecl : RecordDecl->ctors()) {
-USRSet.insert(getUSRForDecl(CtorDecl));
-  }
-  USRSet.insert(getUSRForDecl(RecordDecl->getDestructor()));
+  void addUSRsOfCtorDtors(const CXXRecordDecl *RecordDecl) {
+RecordDecl = RecordDecl->getDefinition();
+for (const auto *CtorDecl : RecordDecl->ctors()) {
+  USRSet.insert(getUSRForDecl(CtorDecl));
 }
-// If D is CXXMethodDecl we should add all USRs of its overriden methods.
-if (const auto *MethodDecl = dyn_cast(FoundDecl)) {
-  for (auto &OverriddenMethod : MethodDecl->overridden_methods()) {
-USRSet.insert(getUSRForDecl(OverriddenMethod));
-  }
+USRSet.insert(getUSRForDecl(RecordDecl->getDestructor()));
+  }
+
+  void addUSRsFromOverrideSets(const CXXMethodDecl *MethodDecl) {
+USRSet.insert(getUSRForDecl(MethodDecl));
+for (auto &OverriddenMethod : MethodDecl->overridden_methods()) {
+  // Recursively visit each OverridenMethod.
+  addUSRsFromOverrideSets(OverriddenMethod);
 }
   }
 

Added: clang-tools-extra/trunk/test/clang-rename/FunctionOverride.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-rename/FunctionOverride.cpp?rev=277356&view=auto
==
--- clang-tools-extra/trunk/test/clang-rename/FunctionOverride.cpp (added)
+++ clang-tools-extra/trunk/test/clang-rename/FunctionOverride.cpp Mon Aug  1 
12:15:57 2016
@@ -0,0 +1,10 @@
+// RUN: cat %s > %t.cpp
+// RUN: clang-rename -offset=318 -new-name=bar %t.cpp -i --
+// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s
+
+class A { virtual void foo(); };// CHECK: class A { virtual void bar(); };
+class B : public A { void foo(); }; // CHECK: class B : public A { void bar(); 
};
+class C : public B { void foo(); }; // CHECK: class C : public B { void bar(); 
};
+
+// Use grep -FUbo 'Foo'  to get the correct offset of Foo when changing
+// this file.

Modified: 
clang-tools-extra/trunk/test/clang-rename/FunctionWithClassFindByName.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-rename/FunctionWithClassFindByName.cpp?rev=277356&r1=277355&r2=277356&view=diff
==
--- clang-tools-extra/trunk/test/clang-rename/FunctionWithClassFindByName.cpp 
(original)
+++ clang-tools-extra/trunk/t

Re: [PATCH] D22853: [clang-rename] add support for template parameter renaming

2016-08-01 Thread Kirill Bobyrev via cfe-commits
omtcyfz added inline comments.


Comment at: clang-rename/USRFinder.cpp:80
@@ -79,1 +79,3 @@
 TypeBeginLoc, 0, Context.getSourceManager(), Context.getLangOpts());
+if (const auto *TemplateTypeParm = 
dyn_cast(Loc.getType())) {
+  return setResult(TemplateTypeParm->getDecl(), TypeBeginLoc, TypeEndLoc);

alexfh wrote:
> It's not common to use braces around single-line `if` bodies in LLVM/Clang 
> code.
I do that literally everywhere :D LLVM Code Style isn't against it and I thinks 
it is good in terms of readability.


https://reviews.llvm.org/D22853



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


Re: [PATCH] D22470: [libcxx] Improve shared_ptr dtor performance

2016-08-01 Thread Ben Craig via cfe-commits
bcraig added a comment.

I am going to submit the code changes and the tests independently.  I'm having 
trouble getting cmake to use the right compiler for the libcxx-benchmarks 
target.


https://reviews.llvm.org/D22470



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


Re: r277175 - Reapply r277058: "[ObjC] Consider availability of context when emitting availability warnings"

2016-08-01 Thread Nico Weber via cfe-commits
Hi Erik,

with this change clangs warns on this program:

$ cat test.mm
#import 
@interface AXPlatformNodeCocoa : NSObject
@end
@implementation AXPlatformNodeCocoa
- (NSArray*)accessibilityAttributeNames {
  NSArray* const kTextfieldAttributes = @[
NSAccessibilityPlaceholderValueAttribute,
  ];
  return kTextfieldAttributes;
}
@end

$ bin/clang -c test.mm -isysroot $(xcrun -show-sdk-path)
-Wpartial-availability -mmacosx-version-min=10.7
test.mm:9:5: warning: 'NSAccessibilityPlaceholderValueAttribute' is
partial: introduced in macOS 10.6 [-Wpartial-availability]
NSAccessibilityPlaceholderValueAttribute,
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/AppKit.framework/Headers/NSAccessibilityConstants.h:85:31:
note:
  'NSAccessibilityPlaceholderValueAttribute' has been explicitly marked
partial here

Given that I'm building with -mmacosx-version-min=10.7 it seems strange to
warn about something introduced in 10.6. This is probably not doing what it
should?

Thanks,
Nico


On Fri, Jul 29, 2016 at 1:37 PM, Erik Pilkington via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: epilk
> Date: Fri Jul 29 12:37:38 2016
> New Revision: 277175
>
> URL: http://llvm.org/viewvc/llvm-project?rev=277175&view=rev
> Log:
> Reapply r277058: "[ObjC] Consider availability of context when emitting
> availability warnings"
>
> Modified:
> cfe/trunk/include/clang/AST/DeclBase.h
> cfe/trunk/include/clang/Sema/Sema.h
> cfe/trunk/lib/AST/DeclBase.cpp
> cfe/trunk/lib/Sema/SemaDeclAttr.cpp
> cfe/trunk/lib/Sema/SemaExpr.cpp
> cfe/trunk/test/SemaObjC/attr-availability.m
>
> Modified: cfe/trunk/include/clang/AST/DeclBase.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=277175&r1=277174&r2=277175&view=diff
>
> ==
> --- cfe/trunk/include/clang/AST/DeclBase.h (original)
> +++ cfe/trunk/include/clang/AST/DeclBase.h Fri Jul 29 12:37:38 2016
> @@ -17,6 +17,7 @@
>  #include "clang/AST/AttrIterator.h"
>  #include "clang/AST/DeclarationName.h"
>  #include "clang/Basic/Specifiers.h"
> +#include "clang/Basic/VersionTuple.h"
>  #include "llvm/ADT/PointerUnion.h"
>  #include "llvm/ADT/iterator.h"
>  #include "llvm/ADT/iterator_range.h"
> @@ -603,7 +604,12 @@ public:
>/// AR_Available, will be set to a (possibly empty) message
>/// describing why the declaration has not been introduced, is
>/// deprecated, or is unavailable.
> -  AvailabilityResult getAvailability(std::string *Message = nullptr)
> const;
> +  ///
> +  /// \param EnclosingVersion The version to compare with. If empty,
> assume the
> +  /// deployment target version.
> +  AvailabilityResult
> +  getAvailability(std::string *Message = nullptr,
> +  VersionTuple EnclosingVersion = VersionTuple()) const;
>
>/// \brief Determine whether this declaration is marked 'deprecated'.
>///
>
> Modified: cfe/trunk/include/clang/Sema/Sema.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=277175&r1=277174&r2=277175&view=diff
>
> ==
> --- cfe/trunk/include/clang/Sema/Sema.h (original)
> +++ cfe/trunk/include/clang/Sema/Sema.h Fri Jul 29 12:37:38 2016
> @@ -9596,7 +9596,12 @@ public:
>}
>
>AvailabilityResult getCurContextAvailability() const;
> -
> +
> +  /// \brief Get the verison that this context implies.
> +  /// For instance, a method in an interface that is annotated with an
> +  /// availability attribuite effectively has the availability of the
> interface.
> +  VersionTuple getVersionForDecl(const Decl *Ctx) const;
> +
>const DeclContext *getCurObjCLexicalContext() const {
>  const DeclContext *DC = getCurLexicalContext();
>  // A category implicitly has the attribute of the interface.
>
> Modified: cfe/trunk/lib/AST/DeclBase.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclBase.cpp?rev=277175&r1=277174&r2=277175&view=diff
>
> ==
> --- cfe/trunk/lib/AST/DeclBase.cpp (original)
> +++ cfe/trunk/lib/AST/DeclBase.cpp Fri Jul 29 12:37:38 2016
> @@ -400,11 +400,12 @@ const Attr *Decl::getDefiningAttr() cons
>  /// diagnostics.
>  static AvailabilityResult CheckAvailability(ASTContext &Context,
>  const AvailabilityAttr *A,
> -std::string *Message) {
> -  VersionTuple TargetMinVersion =
> -Context.getTargetInfo().getPlatformMinVersion();
> +std::string *Message,
> +VersionTuple
> EnclosingVersion) {
> +  if (EnclosingVersion.empty())
> +EnclosingVersion = Context.getTargetInfo().getPlatformMinVersion();
>
> -  if (Targ

Re: [PATCH] D22900: Revert r244207 - Mark calls in thunk functions as tail-call optimization

2016-08-01 Thread Reid Kleckner via cfe-commits
rnk added a comment.

I think the correctness problem is in DSE. It should be safe for clang to put 
'tail' here. The tail call does not capture the address of any local variables, 
but it does load from them via 'byval'.


https://reviews.llvm.org/D22900



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


Re: [PATCH] D22900: Revert r244207 - Mark calls in thunk functions as tail-call optimization

2016-08-01 Thread Reid Kleckner via cfe-commits
rnk added a comment.

I think Nick was responsible for adding this DSE optimization *years* ago.


https://reviews.llvm.org/D22900



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


[libcxx] r277357 - Improve shared_ptr dtor performance

2016-08-01 Thread Ben Craig via cfe-commits
Author: bcraig
Date: Mon Aug  1 12:51:26 2016
New Revision: 277357

URL: http://llvm.org/viewvc/llvm-project?rev=277357&view=rev
Log:
Improve shared_ptr dtor performance

If the last destruction is uncontended, skip the atomic store on
__shared_weak_owners_. This shifts some costs from normal
shared_ptr usage to weak_ptr uses.

https://reviews.llvm.org/D22470

Modified:
libcxx/trunk/src/memory.cpp

Modified: libcxx/trunk/src/memory.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/memory.cpp?rev=277357&r1=277356&r2=277357&view=diff
==
--- libcxx/trunk/src/memory.cpp (original)
+++ libcxx/trunk/src/memory.cpp Mon Aug  1 12:51:26 2016
@@ -96,7 +96,35 @@ __shared_weak_count::__release_shared()
 void
 __shared_weak_count::__release_weak() _NOEXCEPT
 {
-if (decrement(__shared_weak_owners_) == -1)
+// NOTE: The acquire load here is an optimization of the very
+// common case where a shared pointer is being destructed while
+// having no other contended references.
+//
+// BENEFIT: We avoid expensive atomic stores like XADD and STREX
+// in a common case.  Those instructions are slow and do nasty
+// things to caches.
+//
+// IS THIS SAFE?  Yes.  During weak destruction, if we see that we
+// are the last reference, we know that no-one else is accessing
+// us. If someone were accessing us, then they would be doing so
+// while the last shared / weak_ptr was being destructed, and
+// that's undefined anyway.
+//
+// If we see anything other than a 0, then we have possible
+// contention, and need to use an atomicrmw primitive.
+// The same arguments don't apply for increment, where it is legal
+// (though inadvisable) to share shared_ptr references between
+// threads, and have them all get copied at once.  The argument
+// also doesn't apply for __release_shared, because an outstanding
+// weak_ptr::lock() could read / modify the shared count.
+if (__libcpp_atomic_load(&__shared_weak_owners_, _AO_Aquire) == 0)
+{
+// no need to do this store, because we are about
+// to destroy everything.
+//__libcpp_atomic_store(&__shared_weak_owners_, -1, _AO_Release);
+__on_zero_shared_weak();
+}
+else if (decrement(__shared_weak_owners_) == -1)
 __on_zero_shared_weak();
 }
 


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


Re: [PATCH] D22470: [libcxx] Improve shared_ptr dtor performance

2016-08-01 Thread Ben Craig via cfe-commits
bcraig closed this revision.
bcraig added a comment.

committed https://reviews.llvm.org/rL277357: Improve shared_ptr dtor 
performance.


https://reviews.llvm.org/D22470



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


Re: [PATCH] D22505: clang-format Access Modifier Use Normal Indent

2016-08-01 Thread Loki Astari via cfe-commits
LokiAstari added a comment.

@djasper@klimek

Just want to bring this to the top of your queue again :-)
Any further thoughts on the processes?

Loki


https://reviews.llvm.org/D22505



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


RE: [PATCH] D20979: [OpenCL] Use function metadata to represent kernel attributes

2016-08-01 Thread Anastasia Stulova via cfe-commits
Hi Xiuli,

Could you please elaborate what do you think it broken exactly?

Because we haven't actually removed opencl.kernels metadata but just changed 
the format of it. 

Basically, we are using function metadata instead of generic metadata as it was 
before.

Thanks,
Anastasia

-Original Message-
From: Pan Xiuli [mailto:xiuli...@outlook.com] 
Sent: 01 August 2016 05:54
To: reviews+d20979+public+e2872c9c869f1...@reviews.llvm.org; Anastasia Stulova; 
alexey.ba...@intel.com
Cc: thomas.stell...@amd.com; cfe-commits@lists.llvm.org
Subject: RE: [PATCH] D20979: [OpenCL] Use function metadata to represent kernel 
attributes

Hi Sam,

I am now using llvm39 to enable our opencl driver, but I found this patch broke 
the spir target as well.
The opencl.kernels metadata is required by spir spec. I think we should keep 
the old code for spir target.

Thanks
Xiuli

-Original Message-
From: Yaxun Liu [mailto:yaxun@amd.com] 
Sent: Wednesday, June 22, 2016 11:04 PM
To: yaxun@amd.com; xiuli...@outlook.com; anastasia.stul...@arm.com; 
alexey.ba...@intel.com
Cc: thomas.stell...@amd.com; cfe-commits@lists.llvm.org
Subject: Re: [PATCH] D20979: [OpenCL] Use function metadata to represent kernel 
attributes

This revision was automatically updated to reflect the committed changes.
Closed by commit rL273425: [OpenCL] Use function metadata to represent kernel 
attributes (authored by yaxunl).

Changed prior to commit:
  http://reviews.llvm.org/D20979?vs=60545&id=61555#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D20979

Files:
  cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
  cfe/trunk/test/CodeGenOpenCL/kernel-arg-info.cl
  cfe/trunk/test/CodeGenOpenCL/kernel-attributes.cl
  cfe/trunk/test/CodeGenOpenCL/kernel-metadata.cl

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


Re: [PATCH] D22073: libc++: test lock-free atomic alignment

2016-08-01 Thread JF Bastien via cfe-commits
jfb updated this revision to Diff 66342.
jfb added a comment.

- Move atomics.align to libcxx-specific
- Give names to anonymous structs
- Rename test, use REQUIRES / RUN commands


https://reviews.llvm.org/D22073

Files:
  test/libcxx/atomics/atomics.align/align.pass.sh.cpp

Index: test/libcxx/atomics/atomics.align/align.pass.sh.cpp
===
--- /dev/null
+++ test/libcxx/atomics/atomics.align/align.pass.sh.cpp
@@ -0,0 +1,89 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// UNSUPPORTED: libcpp-has-no-threads, c++98, c++03
+// REQUIRES: libatomic
+// RUN: %build -latomic
+// RUN: %run
+
+// 
+
+// Verify that the content of atomic is properly aligned if the type is
+// lock-free. This can't be observed through the atomic API. It is
+// nonetheless required for correctness of the implementation: lock-free 
implies
+// that ISA instructions are used, and these instructions assume "suitable
+// alignment". Supported architectures all require natural alignment for
+// lock-freedom (e.g. load-linked / store-conditional, or cmpxchg).
+
+#include 
+#include 
+
+template  struct atomic_test : public std::__atomic_base {
+  atomic_test() {
+if (this->is_lock_free())
+  assert(alignof(this->__a_) >= sizeof(this->__a_) &&
+ "expected natural alignment for lock-free type");
+  }
+};
+
+int main() {
+
+// structs and unions can't be defined in the template invocation.
+// Work around this with a typedef.
+#define CHECK_ALIGNMENT(T) 
\
+  do { 
\
+typedef T type;
\
+atomic_test t;   
\
+  } while (0)
+
+  CHECK_ALIGNMENT(bool);
+  CHECK_ALIGNMENT(char);
+  CHECK_ALIGNMENT(signed char);
+  CHECK_ALIGNMENT(unsigned char);
+  CHECK_ALIGNMENT(char16_t);
+  CHECK_ALIGNMENT(char32_t);
+  CHECK_ALIGNMENT(wchar_t);
+  CHECK_ALIGNMENT(short);
+  CHECK_ALIGNMENT(unsigned short);
+  CHECK_ALIGNMENT(int);
+  CHECK_ALIGNMENT(unsigned int);
+  CHECK_ALIGNMENT(long);
+  CHECK_ALIGNMENT(unsigned long);
+  CHECK_ALIGNMENT(long long);
+  CHECK_ALIGNMENT(unsigned long long);
+  CHECK_ALIGNMENT(std::nullptr_t);
+  CHECK_ALIGNMENT(void *);
+  CHECK_ALIGNMENT(float);
+  CHECK_ALIGNMENT(double);
+  CHECK_ALIGNMENT(long double);
+  CHECK_ALIGNMENT(int __attribute__((vector_size(1 * sizeof(int);
+  CHECK_ALIGNMENT(int __attribute__((vector_size(2 * sizeof(int);
+  CHECK_ALIGNMENT(int __attribute__((vector_size(4 * sizeof(int);
+  CHECK_ALIGNMENT(int __attribute__((vector_size(16 * sizeof(int);
+  CHECK_ALIGNMENT(int __attribute__((vector_size(32 * sizeof(int);
+  CHECK_ALIGNMENT(float __attribute__((vector_size(1 * sizeof(float);
+  CHECK_ALIGNMENT(float __attribute__((vector_size(2 * sizeof(float);
+  CHECK_ALIGNMENT(float __attribute__((vector_size(4 * sizeof(float);
+  CHECK_ALIGNMENT(float __attribute__((vector_size(16 * sizeof(float);
+  CHECK_ALIGNMENT(float __attribute__((vector_size(32 * sizeof(float);
+  CHECK_ALIGNMENT(double __attribute__((vector_size(1 * sizeof(double);
+  CHECK_ALIGNMENT(double __attribute__((vector_size(2 * sizeof(double);
+  CHECK_ALIGNMENT(double __attribute__((vector_size(4 * sizeof(double);
+  CHECK_ALIGNMENT(double __attribute__((vector_size(16 * sizeof(double);
+  CHECK_ALIGNMENT(double __attribute__((vector_size(32 * sizeof(double);
+  CHECK_ALIGNMENT(struct Empty {});
+  CHECK_ALIGNMENT(struct OneInt { int i; });
+  CHECK_ALIGNMENT(struct IntArr2 { int i[2]; });
+  CHECK_ALIGNMENT(struct LLIArr2 { long long int i[2]; });
+  CHECK_ALIGNMENT(struct LLIArr4 { long long int i[4]; });
+  CHECK_ALIGNMENT(struct LLIArr8 { long long int i[8]; });
+  CHECK_ALIGNMENT(struct LLIArr16 { long long int i[16]; });
+  CHECK_ALIGNMENT(struct Padding { char c; /* padding */ long long int i; });
+  CHECK_ALIGNMENT(union IntFloat { int i; float f; });
+}


Index: test/libcxx/atomics/atomics.align/align.pass.sh.cpp
===
--- /dev/null
+++ test/libcxx/atomics/atomics.align/align.pass.sh.cpp
@@ -0,0 +1,89 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// U

Re: [PATCH] D22073: libc++: test lock-free atomic alignment

2016-08-01 Thread JF Bastien via cfe-commits
jfb added a comment.

In https://reviews.llvm.org/D22073#486636, @EricWF wrote:

> OK, IMO the way to handle this test is to have it manually link `-latomic`. 
> This can be done by renaming the test to `.sh.cpp` and adding the 
> following lines:
>
>   // REQUIRES: libatomic
>   // RUN: %build -latomic
>   // RUN: %run
>
>
> After that this LGTM.


Sorry for the delay in getting back to this. It's now done :)
Will land after lunch (so I'm not AFK).


https://reviews.llvm.org/D22073



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


Re: [PATCH] D22927: [OpenCL] Fix size of image type

2016-08-01 Thread Anastasia Stulova via cfe-commits
Anastasia accepted this revision.
Anastasia added a comment.
This revision is now accepted and ready to land.

LGTM!


https://reviews.llvm.org/D22927



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


[PATCH] D23023: [include-fixer] Correct nested class search for identifiers with scoped information

2016-08-01 Thread Haojian Wu via cfe-commits
hokein created this revision.
hokein added a reviewer: bkramer.
hokein added a subscriber: cfe-commits.

include-fixer will firstly try to use scoped namespace context information to
search identifier. However, in some cases, it's unsafe to do nested class
search, because it might treat the identifier as a nested class of scoped
namespace.

Given the following code, and the symbol database only has two classes: "foo" 
and
"b::Bar".

namespace foo { Bar t; }

Before getting fixing, include-fixer will never search "Bar" symbol.
Because it firstly tries to search "foo::Bar", there is no "Bar" in foo 
namespace,
then it finds "foo" in database finally. So it treats "Bar" is a nested class
of "foo".

https://reviews.llvm.org/D23023

Files:
  include-fixer/IncludeFixer.cpp
  include-fixer/IncludeFixerContext.cpp
  include-fixer/SymbolIndexManager.cpp
  include-fixer/SymbolIndexManager.h
  unittests/include-fixer/IncludeFixerTest.cpp

Index: unittests/include-fixer/IncludeFixerTest.cpp
===
--- unittests/include-fixer/IncludeFixerTest.cpp
+++ unittests/include-fixer/IncludeFixerTest.cpp
@@ -77,6 +77,12 @@
   SymbolInfo("Vector", SymbolInfo::SymbolKind::Class, "\"Vector.h\"", 2,
  {{SymbolInfo::ContextType::Namespace, "a"}},
  /*num_occurrences=*/1),
+  SymbolInfo("StrCat", SymbolInfo::SymbolKind::Class, "\"strcat.h\"",
+ 1, {{SymbolInfo::ContextType::Namespace, "str"}}),
+  SymbolInfo("str", SymbolInfo::SymbolKind::Class, "\"str.h\"",
+ 1, {}),
+  SymbolInfo("foo2", SymbolInfo::SymbolKind::Class, "\"foo2.h\"",
+ 1, {}),
   };
   auto SymbolIndexMgr = llvm::make_unique();
   SymbolIndexMgr->addSymbolIndex(
@@ -189,6 +195,16 @@
   // full match.
   EXPECT_EQ("#include \"bar.h\"\nnamespace A {\na::b::bar b;\n}",
 runIncludeFixer("namespace A {\nb::bar b;\n}"));
+
+  // Finds candidates for "str::StrCat".
+  EXPECT_EQ("#include \"strcat.h\"\nnamespace foo2 {\nstr::StrCat b;\n}",
+runIncludeFixer("namespace foo2 {\nstr::StrCat b;\n}"));
+  // str::StrCat2 doesn't exist.
+  // In these two cases, StrCat2 is a nested class of class str.
+  EXPECT_EQ("#include \"str.h\"\nnamespace foo2 {\nstr::StrCat2 b;\n}",
+runIncludeFixer("namespace foo2 {\nstr::StrCat2 b;\n}"));
+  EXPECT_EQ("#include \"str.h\"\nnamespace ns {\nstr::StrCat2 b;\n}",
+runIncludeFixer("namespace ns {\nstr::StrCat2 b;\n}"));
 }
 
 TEST(IncludeFixer, EnumConstantSymbols) {
@@ -253,7 +269,7 @@
   // Test nested classes.
   EXPECT_EQ("#include \"bar.h\"\nnamespace d {\na::b::bar::t b;\n}\n",
 runIncludeFixer("namespace d {\nbar::t b;\n}\n"));
-  EXPECT_EQ("#include \"bar2.h\"\nnamespace c {\na::c::bar::t b;\n}\n",
+  EXPECT_EQ("#include \"bar.h\"\nnamespace c {\na::b::bar::t b;\n}\n",
 runIncludeFixer("namespace c {\nbar::t b;\n}\n"));
   EXPECT_EQ("#include \"bar.h\"\nnamespace a {\nb::bar::t b;\n}\n",
 runIncludeFixer("namespace a {\nbar::t b;\n}\n"));
Index: include-fixer/SymbolIndexManager.h
===
--- include-fixer/SymbolIndexManager.h
+++ include-fixer/SymbolIndexManager.h
@@ -28,12 +28,15 @@
   /// Search for header files to be included for an identifier.
   /// \param Identifier The identifier being searched for. May or may not be
   ///   fully qualified.
-  /// \returns A list of inclusion candidates, in a format ready for being
-  ///  pasted after an #include token.
-  // FIXME: Move mapping from SymbolInfo to headers out of
-  // SymbolIndexManager::search and return SymbolInfos instead of header paths.
+  /// \param IsNestedSearch Whether searching nested classes. If true, the
+  ///method tries to stripping identifier name parts from the end until
+  ///it finds the corresponding candidates in database (e.g for
+  ///identifier "b::foo", the method will try to find "b" if it fails on
+  ///finding "b::foo").
+  ///
+  /// \returns A list of symbol candidates.
   std::vector
-  search(llvm::StringRef Identifier) const;
+  search(llvm::StringRef Identifier, bool IsNestedSearch = true) const;
 
 private:
   std::vector> SymbolIndices;
Index: include-fixer/SymbolIndexManager.cpp
===
--- include-fixer/SymbolIndexManager.cpp
+++ include-fixer/SymbolIndexManager.cpp
@@ -42,7 +42,8 @@
 }
 
 std::vector
-SymbolIndexManager::search(llvm::StringRef Identifier) const {
+SymbolIndexManager::search(llvm::StringRef Identifier,
+   bool IsNestedSearch) const {
   // The identifier may be fully qualified, so split it and get all the context
   // names.
   llvm::SmallVector Names;
@@ -60,7 +61,7 @@
   // either) and can report that result.
   bool TookPrefix = false;
   std::vector MatchedSymbols;
-  while (Matched

r277365 - [AArch64] Add support for Samsung Exynos M2 (NFC).

2016-08-01 Thread Evandro Menezes via cfe-commits
Author: evandro
Date: Mon Aug  1 13:39:55 2016
New Revision: 277365

URL: http://llvm.org/viewvc/llvm-project?rev=277365&view=rev
Log:
[AArch64] Add support for Samsung Exynos M2 (NFC).

Modified:
cfe/trunk/test/CodeGen/arm-target-features.c
cfe/trunk/test/Driver/aarch64-cpus.c
cfe/trunk/test/Driver/arm-cortex-cpus.c
cfe/trunk/test/Preprocessor/aarch64-target-features.c

Modified: cfe/trunk/test/CodeGen/arm-target-features.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/arm-target-features.c?rev=277365&r1=277364&r2=277365&view=diff
==
--- cfe/trunk/test/CodeGen/arm-target-features.c (original)
+++ cfe/trunk/test/CodeGen/arm-target-features.c Mon Aug  1 13:39:55 2016
@@ -29,6 +29,7 @@
 // RUN: %clang_cc1 -triple thumbv8-linux-gnueabihf -target-cpu cortex-a72 
-emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-BASIC-V8
 // RUN: %clang_cc1 -triple thumbv8-linux-gnueabihf -target-cpu cortex-a73 
-emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-BASIC-V8
 // RUN: %clang_cc1 -triple thumbv8-linux-gnueabihf -target-cpu exynos-m1 
-emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-BASIC-V8
+// RUN: %clang_cc1 -triple thumbv8-linux-gnueabihf -target-cpu exynos-m2 
-emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-BASIC-V8
 // CHECK-BASIC-V8: 
"target-features"="+crc,+crypto,+dsp,+fp-armv8,+hwdiv,+hwdiv-arm,+neon"
 
 

Modified: cfe/trunk/test/Driver/aarch64-cpus.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/aarch64-cpus.c?rev=277365&r1=277364&r2=277365&view=diff
==
--- cfe/trunk/test/Driver/aarch64-cpus.c (original)
+++ cfe/trunk/test/Driver/aarch64-cpus.c Mon Aug  1 13:39:55 2016
@@ -96,12 +96,26 @@
 // RUN: %clang -target aarch64_be -mlittle-endian -mtune=exynos-m1 -### -c %s 
2>&1 | FileCheck -check-prefix=M1 %s
 // M1: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "exynos-m1"
 
+// RUN: %clang -target aarch64 -mcpu=exynos-m2 -### -c %s 2>&1 | FileCheck 
-check-prefix=M2 %s
+// RUN: %clang -target aarch64 -mlittle-endian -mcpu=exynos-m2 -### -c %s 2>&1 
| FileCheck -check-prefix=M2 %s
+// RUN: %clang -target aarch64_be -mlittle-endian -mcpu=exynos-m2 -### -c %s 
2>&1 | FileCheck -check-prefix=M2 %s
+// RUN: %clang -target aarch64 -mtune=exynos-m2 -### -c %s 2>&1 | FileCheck 
-check-prefix=M2 %s
+// RUN: %clang -target aarch64 -mlittle-endian -mtune=exynos-m2 -### -c %s 
2>&1 | FileCheck -check-prefix=M2 %s
+// RUN: %clang -target aarch64_be -mlittle-endian -mtune=exynos-m2 -### -c %s 
2>&1 | FileCheck -check-prefix=M2 %s
+// M2: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "exynos-m2"
+
 // RUN: %clang -target arm64 -mcpu=exynos-m1 -### -c %s 2>&1 | FileCheck 
-check-prefix=ARM64-M1 %s
 // RUN: %clang -target arm64 -mlittle-endian -mcpu=exynos-m1 -### -c %s 2>&1 | 
FileCheck -check-prefix=ARM64-M1 %s
 // RUN: %clang -target arm64 -mtune=exynos-m1 -### -c %s 2>&1 | FileCheck 
-check-prefix=ARM64-M1 %s
 // RUN: %clang -target arm64 -mlittle-endian -mtune=exynos-m1 -### -c %s 2>&1 
| FileCheck -check-prefix=ARM64-M1 %s
 // ARM64-M1: "-cc1"{{.*}} "-triple" "arm64{{.*}}" "-target-cpu" "exynos-m1"
 
+// RUN: %clang -target arm64 -mcpu=exynos-m2 -### -c %s 2>&1 | FileCheck 
-check-prefix=ARM64-M2 %s
+// RUN: %clang -target arm64 -mlittle-endian -mcpu=exynos-m2 -### -c %s 2>&1 | 
FileCheck -check-prefix=ARM64-M2 %s
+// RUN: %clang -target arm64 -mtune=exynos-m2 -### -c %s 2>&1 | FileCheck 
-check-prefix=ARM64-M2 %s
+// RUN: %clang -target arm64 -mlittle-endian -mtune=exynos-m2 -### -c %s 2>&1 
| FileCheck -check-prefix=ARM64-M2 %s
+// ARM64-M2: "-cc1"{{.*}} "-triple" "arm64{{.*}}" "-target-cpu" "exynos-m2"
+
 // RUN: %clang -target aarch64 -mcpu=kryo -### -c %s 2>&1 | FileCheck 
-check-prefix=KRYO %s
 // RUN: %clang -target aarch64 -mlittle-endian -mcpu=kryo -### -c %s 2>&1 | 
FileCheck -check-prefix=KRYO %s
 // RUN: %clang -target aarch64 -mtune=kryo -### -c %s 2>&1 | FileCheck 
-check-prefix=KRYO %s
@@ -181,6 +195,14 @@
 // RUN: %clang -target aarch64_be -mbig-endian -mtune=exynos-m1 -### -c %s 
2>&1 | FileCheck -check-prefix=M1-BE %s
 // M1-BE: "-cc1"{{.*}} "-triple" "aarch64_be{{.*}}" "-target-cpu" "exynos-m1"
 
+// RUN: %clang -target aarch64_be -mcpu=exynos-m2 -### -c %s 2>&1 | FileCheck 
-check-prefix=M2-BE %s
+// RUN: %clang -target aarch64 -mbig-endian -mcpu=exynos-m2 -### -c %s 2>&1 | 
FileCheck -check-prefix=M2-BE %s
+// RUN: %clang -target aarch64_be -mbig-endian -mcpu=exynos-m2 -### -c %s 2>&1 
| FileCheck -check-prefix=M2-BE %s
+// RUN: %clang -target aarch64_be -mtune=exynos-m2 -### -c %s 2>&1 | FileCheck 
-check-prefix=M2-BE %s
+// RUN: %clang -target aarch64 -mbig-endian -mtune=exynos-m2 -### -c %s 2>&1 | 
FileCheck -check-prefix=M2-BE %s
+// RUN: %clang -target aarch64_be -mbig-endian -mtune=exynos-m2 -### -c %s 
2>&1 | FileCheck -check-prefix=M2-BE %s
+// M2-BE: "-c

Re: [PATCH] D22725: [clang-tidy] Add check 'modernize-use-algorithm'

2016-08-01 Thread Jonas Devlieghere via cfe-commits
JDevlieghere updated this revision to Diff 66350.
JDevlieghere added a comment.

Addressed comments from Piotr Padlewski


Repository:
  rL LLVM

https://reviews.llvm.org/D22725

Files:
  clang-tidy/modernize/CMakeLists.txt
  clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tidy/modernize/UseAlgorithmCheck.cpp
  clang-tidy/modernize/UseAlgorithmCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/modernize-use-algorithm.rst
  test/clang-tidy/modernize-use-algorithm.cpp

Index: test/clang-tidy/modernize-use-algorithm.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-use-algorithm.cpp
@@ -0,0 +1,50 @@
+// RUN: %check_clang_tidy %s modernize-use-algorithm %t
+
+// CHECK-FIXES: #include 
+
+namespace std {
+typedef unsigned int size_t;
+void *memcpy(void *dest, const void *src, std::size_t count);
+void *memset(void *dest, int ch, std::size_t count);
+
+template 
+OutputIt copy(InputIt first, InputIt last, OutputIt d_first);
+
+template 
+OutputIt move(InputIt first, InputIt last, OutputIt d_first);
+
+template 
+void fill(ForwardIt first, ForwardIt last, const T &value);
+}
+
+void a() {
+  char foo[] = "foo", bar[3];
+  std::memcpy(bar, foo, sizeof bar);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Use std::copy instead of memcpy [modernize-use-algorithm]
+  // CHECK-FIXES: std::copy(foo, foo + sizeof bar, bar);
+
+  void* baz = bar;
+  std::memcpy(baz, foo, sizeof bar);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Use std::copy instead of memcpy [modernize-use-algorithm]
+
+  std::copy(foo, foo + sizeof bar, bar);
+}
+
+void b() {
+  char foo[] = "foobar";
+  std::memset(foo, 'a', 3);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Use std::fill instead of memset [modernize-use-algorithm]
+  // CHECK-FIXES: std::fill(foo, foo + 3, 'a');
+
+  std::memset(foo, 1, 3);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Use std::fill instead of memset [modernize-use-algorithm]
+
+  std::fill(foo, foo + 2, 'a');
+}
+
+#define MEMCPY(dest, src) std::memcpy((dest), (src), sizeof(dest))
+void c() {
+  char foo[] = "foo", bar[3];
+  MEMCPY(bar, foo);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Use std::copy instead of memcpy [modernize-use-algorithm]
+}
Index: docs/clang-tidy/checks/modernize-use-algorithm.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/modernize-use-algorithm.rst
@@ -0,0 +1,37 @@
+.. title:: clang-tidy - modernize-use-algorithm
+
+modernize-use-algorithm
+===
+
+Replaces calls to ``memcpy`` and ``memset`` with ``std::copy``, and
+``std::fill`` respectively. The advantages of using these algorithm functions
+is that they are at least as efficient, more general and type-aware.
+
+Furthermore, by using the algorithms the types remain intact as opposed to
+being discarded by the C-style functions. This allows the implementation to
+make use use of type information to further optimize. One example of such
+optimization is taking advantage of 64-bit alignment when copying an array of
+``std::uint64_t``.
+
+memcpy
+--
+
+.. code:: c++
+
+std::memcpy(dest, source, sizeof dest);
+
+// transforms to:
+
+std::copy(source, source + sizeof dest, dest);
+
+memset
+--
+
+.. code:: c++
+
+std::memset(dest, ch, count);
+
+// transforms to:
+
+std::fill(dest, dest + count, ch)
+
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -105,6 +105,7 @@
modernize-shrink-to-fit
modernize-use-auto
modernize-use-bool-literals
+   modernize-use-algorithm
modernize-use-default
modernize-use-emplace
modernize-use-nullptr
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -69,6 +69,12 @@
 
   Flags classes where some, but not all, special member functions are user-defined.
 
+- New `modernize-use-algorithm
+  `_ check
+
+  Replaces calls to ``memcpy`` and ``memset`` with their respective algorithm
+  counterparts ``std::copy`` and ``std::fill``.
+
 Improvements to include-fixer
 -
 
Index: clang-tidy/modernize/UseAlgorithmCheck.h
===
--- /dev/null
+++ clang-tidy/modernize/UseAlgorithmCheck.h
@@ -0,0 +1,42 @@
+//===--- UseAlgorithmCheck.h - clang-tidy-*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLAN

[PATCH] D23024: [ObjC Availability] Fix false positive of -Wpartial-availability introduced in r277058

2016-08-01 Thread Erik Pilkington via cfe-commits
erik.pilkington created this revision.
erik.pilkington added reviewers: manmanren, thakis.
erik.pilkington added a subscriber: cfe-commits.

As of r277058, Clang would incorrectly emit -Wpartial-availability for the 
following (when compiled with -mmacosx-verison-min=10.6):
```
int fn_10_5() __attribute__((availablity(macos, introduced=10.5)));
int use() __attribute__((availability(macos, introduced=10.4))) {
  return fn_10_5(); // incorrect warning: fn_10_5 is partial
}
```
The problem is that I didn't consider the base deployment target when getting 
the context version, so the availability of the context of the call to 
`fn_10_5` was `10.4` (from the function), not `10.6` (from the deployment 
target). Therefore, a warning was emitted.

Thanks Nico Weber for pointing this out!

https://reviews.llvm.org/D23024

Files:
  lib/Sema/SemaDeclAttr.cpp
  test/SemaObjC/attr-availability.m

Index: test/SemaObjC/attr-availability.m
===
--- test/SemaObjC/attr-availability.m
+++ test/SemaObjC/attr-availability.m
@@ -297,6 +297,7 @@
 
 #if defined(WARN_PARTIAL)
 
+int fn_10_0() __attribute__((availability(macosx, introduced=10.0)));
 int fn_10_7() __attribute__((availability(macosx, introduced=10.7))); // 
expected-note{{marked partial here}}
 int fn_10_8() __attribute__((availability(macosx, introduced=10.8))) { // 
expected-note{{marked partial here}}
   return fn_10_7();
@@ -324,4 +325,8 @@
 -(void)method4 { fn_10_8(); }
 @end
 
+int old_func() __attribute__((availability(macos, introduced=10.4))) {
+  fn_10_0();
+}
+
 #endif
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -6505,5 +6505,5 @@
 DeclVersion = AA->getIntroduced();
   }
 
-  return DeclVersion;
+  return std::max(DeclVersion, 
Context.getTargetInfo().getPlatformMinVersion());
 }


Index: test/SemaObjC/attr-availability.m
===
--- test/SemaObjC/attr-availability.m
+++ test/SemaObjC/attr-availability.m
@@ -297,6 +297,7 @@
 
 #if defined(WARN_PARTIAL)
 
+int fn_10_0() __attribute__((availability(macosx, introduced=10.0)));
 int fn_10_7() __attribute__((availability(macosx, introduced=10.7))); // expected-note{{marked partial here}}
 int fn_10_8() __attribute__((availability(macosx, introduced=10.8))) { // expected-note{{marked partial here}}
   return fn_10_7();
@@ -324,4 +325,8 @@
 -(void)method4 { fn_10_8(); }
 @end
 
+int old_func() __attribute__((availability(macos, introduced=10.4))) {
+  fn_10_0();
+}
+
 #endif
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -6505,5 +6505,5 @@
 DeclVersion = AA->getIntroduced();
   }
 
-  return DeclVersion;
+  return std::max(DeclVersion, Context.getTargetInfo().getPlatformMinVersion());
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D23024: [ObjC Availability] Fix false positive of -Wpartial-availability introduced in r277058

2016-08-01 Thread Nico Weber via cfe-commits
thakis accepted this revision.
thakis added a comment.
This revision is now accepted and ready to land.

Thanks for the quick fix!


https://reviews.llvm.org/D23024



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


r277367 - [codeview] Skip injected class names in nested record emission

2016-08-01 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Mon Aug  1 13:56:13 2016
New Revision: 277367

URL: http://llvm.org/viewvc/llvm-project?rev=277367&view=rev
Log:
[codeview] Skip injected class names in nested record emission

We were already trying to do this, but our check wasn't quite right.

Fixes PR28790

Added:
cfe/trunk/test/CodeGenCXX/debug-info-codeview-injected-class.cpp
Modified:
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=277367&r1=277366&r2=277367&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Mon Aug  1 13:56:13 2016
@@ -1092,6 +1092,9 @@ void CGDebugInfo::CollectRecordNormalFie
 void CGDebugInfo::CollectRecordNestedRecord(
 const RecordDecl *RD, SmallVectorImpl &elements) {
   QualType Ty = CGM.getContext().getTypeDeclType(RD);
+  // Injected class names are not considered nested records.
+  if (isa(Ty))
+return;
   SourceLocation Loc = RD->getLocation();
   llvm::DIType *nestedType = getOrCreateType(Ty, getOrCreateFile(Loc));
   elements.push_back(nestedType);

Added: cfe/trunk/test/CodeGenCXX/debug-info-codeview-injected-class.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-codeview-injected-class.cpp?rev=277367&view=auto
==
--- cfe/trunk/test/CodeGenCXX/debug-info-codeview-injected-class.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/debug-info-codeview-injected-class.cpp Mon Aug  1 
13:56:13 2016
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 %s -std=c++11 -triple=i686-pc-windows-msvc 
-debug-info-kind=limited -gcodeview -emit-llvm -o - | FileCheck %s
+
+// The injected class names in this test were accidentally making it into our
+// nested class record debug info. Make sure they don't appear there.
+
+// PR28790
+
+struct A {
+  const char *m_fn1();
+  template  class B;
+  template  class C;
+  template  class C>;
+};
+const char *A::m_fn1() { return nullptr; }
+
+// CHECK: ![[A:[^ ]*]] = distinct !DICompositeType(tag: DW_TAG_structure_type, 
name: "A",
+// CHECK-SAME: elements: ![[elements:[0-9]+]]
+
+// CHECK: ![[elements]] = !{![[m_fn1:[0-9]+]]}
+
+// CHECK: ![[m_fn1]] = !DISubprogram(name: "m_fn1",


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


Re: [PATCH] D18073: Add memory allocating functions

2016-08-01 Thread Alexander Riccio via cfe-commits
ariccio added a comment.

Bump?


https://reviews.llvm.org/D18073



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


[libcxx] r277368 - libc++: test lock-free atomic alignment

2016-08-01 Thread JF Bastien via cfe-commits
Author: jfb
Date: Mon Aug  1 14:27:08 2016
New Revision: 277368

URL: http://llvm.org/viewvc/llvm-project?rev=277368&view=rev
Log:
libc++: test lock-free atomic alignment

Summary:
libc++ implements std::atomic<_Tp> using __atomic_base<_Tp> with
`mutable _Atomic(_Tp) __a_`. That member must be suitably aligned on
relevant ISAs for instructions such as cmpxchg to work properly, but
this alignment isn't checked anywhere. __atomic_base's implementation
relies on _Atomic doing "the right thing" since it's under the
compiler's control, and only the compiler knows about lock-freedom and
instruction generation. This test makes sure that the compiler isn't
breaking libc++'s expectations.

I'm looking at a few odd things in the C++ standard, and will have a few
other fixes around this area in the future.

This requires building with `-DLIBCXX_HAS_ATOMIC_LIB=True`, the test
marks the dependency as REQUIRES and won't be run without.

Reviewers: cfe-commits

Subscribers: EricWF, mclow.lists

Differential Revision: http://reviews.llvm.org/D22073

Added:
libcxx/trunk/test/libcxx/atomics/atomics.align/
libcxx/trunk/test/libcxx/atomics/atomics.align/align.pass.sh.cpp

Added: libcxx/trunk/test/libcxx/atomics/atomics.align/align.pass.sh.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/atomics/atomics.align/align.pass.sh.cpp?rev=277368&view=auto
==
--- libcxx/trunk/test/libcxx/atomics/atomics.align/align.pass.sh.cpp (added)
+++ libcxx/trunk/test/libcxx/atomics/atomics.align/align.pass.sh.cpp Mon Aug  1 
14:27:08 2016
@@ -0,0 +1,89 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// UNSUPPORTED: libcpp-has-no-threads, c++98, c++03
+// REQUIRES: libatomic
+// RUN: %build -latomic
+// RUN: %run
+
+// 
+
+// Verify that the content of atomic is properly aligned if the type is
+// lock-free. This can't be observed through the atomic API. It is
+// nonetheless required for correctness of the implementation: lock-free 
implies
+// that ISA instructions are used, and these instructions assume "suitable
+// alignment". Supported architectures all require natural alignment for
+// lock-freedom (e.g. load-linked / store-conditional, or cmpxchg).
+
+#include 
+#include 
+
+template  struct atomic_test : public std::__atomic_base {
+  atomic_test() {
+if (this->is_lock_free())
+  assert(alignof(this->__a_) >= sizeof(this->__a_) &&
+ "expected natural alignment for lock-free type");
+  }
+};
+
+int main() {
+
+// structs and unions can't be defined in the template invocation.
+// Work around this with a typedef.
+#define CHECK_ALIGNMENT(T) 
\
+  do { 
\
+typedef T type;
\
+atomic_test t;   
\
+  } while (0)
+
+  CHECK_ALIGNMENT(bool);
+  CHECK_ALIGNMENT(char);
+  CHECK_ALIGNMENT(signed char);
+  CHECK_ALIGNMENT(unsigned char);
+  CHECK_ALIGNMENT(char16_t);
+  CHECK_ALIGNMENT(char32_t);
+  CHECK_ALIGNMENT(wchar_t);
+  CHECK_ALIGNMENT(short);
+  CHECK_ALIGNMENT(unsigned short);
+  CHECK_ALIGNMENT(int);
+  CHECK_ALIGNMENT(unsigned int);
+  CHECK_ALIGNMENT(long);
+  CHECK_ALIGNMENT(unsigned long);
+  CHECK_ALIGNMENT(long long);
+  CHECK_ALIGNMENT(unsigned long long);
+  CHECK_ALIGNMENT(std::nullptr_t);
+  CHECK_ALIGNMENT(void *);
+  CHECK_ALIGNMENT(float);
+  CHECK_ALIGNMENT(double);
+  CHECK_ALIGNMENT(long double);
+  CHECK_ALIGNMENT(int __attribute__((vector_size(1 * sizeof(int);
+  CHECK_ALIGNMENT(int __attribute__((vector_size(2 * sizeof(int);
+  CHECK_ALIGNMENT(int __attribute__((vector_size(4 * sizeof(int);
+  CHECK_ALIGNMENT(int __attribute__((vector_size(16 * sizeof(int);
+  CHECK_ALIGNMENT(int __attribute__((vector_size(32 * sizeof(int);
+  CHECK_ALIGNMENT(float __attribute__((vector_size(1 * sizeof(float);
+  CHECK_ALIGNMENT(float __attribute__((vector_size(2 * sizeof(float);
+  CHECK_ALIGNMENT(float __attribute__((vector_size(4 * sizeof(float);
+  CHECK_ALIGNMENT(float __attribute__((vector_size(16 * sizeof(float);
+  CHECK_ALIGNMENT(float __attribute__((vector_size(32 * sizeof(float);
+  CHECK_ALIGNMENT(double __attribute__((vector_size(1 * sizeof(double);
+  CHECK_ALIGNMENT(double __attribute__((vector_size(2 * sizeof(double);
+  CHECK_ALIGNMENT(double __attribute__((vector_size(4 * sizeof(double);
+  CHECK_ALIGNMENT(double __attribute__((vector_size(16 * sizeof(double);
+  CHECK_ALIGNMENT(doubl

Re: [PATCH] D22073: libc++: test lock-free atomic alignment

2016-08-01 Thread JF Bastien via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL277368: libc++: test lock-free atomic alignment (authored by 
jfb).

Changed prior to commit:
  https://reviews.llvm.org/D22073?vs=66342&id=66356#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D22073

Files:
  libcxx/trunk/test/libcxx/atomics/atomics.align/align.pass.sh.cpp

Index: libcxx/trunk/test/libcxx/atomics/atomics.align/align.pass.sh.cpp
===
--- libcxx/trunk/test/libcxx/atomics/atomics.align/align.pass.sh.cpp
+++ libcxx/trunk/test/libcxx/atomics/atomics.align/align.pass.sh.cpp
@@ -0,0 +1,89 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// UNSUPPORTED: libcpp-has-no-threads, c++98, c++03
+// REQUIRES: libatomic
+// RUN: %build -latomic
+// RUN: %run
+
+// 
+
+// Verify that the content of atomic is properly aligned if the type is
+// lock-free. This can't be observed through the atomic API. It is
+// nonetheless required for correctness of the implementation: lock-free 
implies
+// that ISA instructions are used, and these instructions assume "suitable
+// alignment". Supported architectures all require natural alignment for
+// lock-freedom (e.g. load-linked / store-conditional, or cmpxchg).
+
+#include 
+#include 
+
+template  struct atomic_test : public std::__atomic_base {
+  atomic_test() {
+if (this->is_lock_free())
+  assert(alignof(this->__a_) >= sizeof(this->__a_) &&
+ "expected natural alignment for lock-free type");
+  }
+};
+
+int main() {
+
+// structs and unions can't be defined in the template invocation.
+// Work around this with a typedef.
+#define CHECK_ALIGNMENT(T) 
\
+  do { 
\
+typedef T type;
\
+atomic_test t;   
\
+  } while (0)
+
+  CHECK_ALIGNMENT(bool);
+  CHECK_ALIGNMENT(char);
+  CHECK_ALIGNMENT(signed char);
+  CHECK_ALIGNMENT(unsigned char);
+  CHECK_ALIGNMENT(char16_t);
+  CHECK_ALIGNMENT(char32_t);
+  CHECK_ALIGNMENT(wchar_t);
+  CHECK_ALIGNMENT(short);
+  CHECK_ALIGNMENT(unsigned short);
+  CHECK_ALIGNMENT(int);
+  CHECK_ALIGNMENT(unsigned int);
+  CHECK_ALIGNMENT(long);
+  CHECK_ALIGNMENT(unsigned long);
+  CHECK_ALIGNMENT(long long);
+  CHECK_ALIGNMENT(unsigned long long);
+  CHECK_ALIGNMENT(std::nullptr_t);
+  CHECK_ALIGNMENT(void *);
+  CHECK_ALIGNMENT(float);
+  CHECK_ALIGNMENT(double);
+  CHECK_ALIGNMENT(long double);
+  CHECK_ALIGNMENT(int __attribute__((vector_size(1 * sizeof(int);
+  CHECK_ALIGNMENT(int __attribute__((vector_size(2 * sizeof(int);
+  CHECK_ALIGNMENT(int __attribute__((vector_size(4 * sizeof(int);
+  CHECK_ALIGNMENT(int __attribute__((vector_size(16 * sizeof(int);
+  CHECK_ALIGNMENT(int __attribute__((vector_size(32 * sizeof(int);
+  CHECK_ALIGNMENT(float __attribute__((vector_size(1 * sizeof(float);
+  CHECK_ALIGNMENT(float __attribute__((vector_size(2 * sizeof(float);
+  CHECK_ALIGNMENT(float __attribute__((vector_size(4 * sizeof(float);
+  CHECK_ALIGNMENT(float __attribute__((vector_size(16 * sizeof(float);
+  CHECK_ALIGNMENT(float __attribute__((vector_size(32 * sizeof(float);
+  CHECK_ALIGNMENT(double __attribute__((vector_size(1 * sizeof(double);
+  CHECK_ALIGNMENT(double __attribute__((vector_size(2 * sizeof(double);
+  CHECK_ALIGNMENT(double __attribute__((vector_size(4 * sizeof(double);
+  CHECK_ALIGNMENT(double __attribute__((vector_size(16 * sizeof(double);
+  CHECK_ALIGNMENT(double __attribute__((vector_size(32 * sizeof(double);
+  CHECK_ALIGNMENT(struct Empty {});
+  CHECK_ALIGNMENT(struct OneInt { int i; });
+  CHECK_ALIGNMENT(struct IntArr2 { int i[2]; });
+  CHECK_ALIGNMENT(struct LLIArr2 { long long int i[2]; });
+  CHECK_ALIGNMENT(struct LLIArr4 { long long int i[4]; });
+  CHECK_ALIGNMENT(struct LLIArr8 { long long int i[8]; });
+  CHECK_ALIGNMENT(struct LLIArr16 { long long int i[16]; });
+  CHECK_ALIGNMENT(struct Padding { char c; /* padding */ long long int i; });
+  CHECK_ALIGNMENT(union IntFloat { int i; float f; });
+}


Index: libcxx/trunk/test/libcxx/atomics/atomics.align/align.pass.sh.cpp
===
--- libcxx/trunk/test/libcxx/atomics/atomics.align/align.pass.sh.cpp
+++ libcxx/trunk/test/libcxx/atomics/atomics.align/align.pass.sh.cpp
@@ -0,0 +1,89 @@
+//===--===//
+//
+// The

Re: [PATCH] D22725: [clang-tidy] Add check 'modernize-use-algorithm'

2016-08-01 Thread Piotr Padlewski via cfe-commits
Prazek added a comment.

In https://reviews.llvm.org/D22725#502374, @JDevlieghere wrote:

> Addressed comments from Piotr Padlewski
>
> LLVM compiles with the latest version of this check, however some tests are 
> failing. I'll investigate the cause of this and update this check if it can 
> be prevented.


That's weird. I wonder what happen, because the transformations looks legit.


Repository:
  rL LLVM

https://reviews.llvm.org/D22725



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


Re: [PATCH] D22900: Revert r244207 - Mark calls in thunk functions as tail-call optimization

2016-08-01 Thread Gerolf Hoflehner via cfe-commits
I forwarded your the thread for the DSE path. Even my original intent for was a 
short-term bandage and by no means a long term fix. 

> On Aug 1, 2016, at 10:53 AM, Reid Kleckner  wrote:
> 
> rnk added a comment.
> 
> I think the correctness problem is in DSE. It should be safe for clang to put 
> 'tail' here. The tail call does not capture the address of any local 
> variables, but it does load from them via 'byval'.
> 
> 
> https://reviews.llvm.org/D22900
> 
> 
> 

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


  1   2   >