[PATCH] D41792: [AArch64] Add ARMv8.2-A FP16 scalar intrinsics

2018-01-17 Thread Sjoerd Meijer via Phabricator via cfe-commits
SjoerdMeijer accepted this revision.
SjoerdMeijer added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D41792



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


Re: r322350 - [ODRHash] Don't hash friend functions.

2018-01-17 Thread NAKAMURA Takumi via cfe-commits
That's good to hear. Thanks!

2018年1月17日(水) 13:51 Richard Trieu :

> I feel it's best to merge this change into the release branch instead of
> reverting the previous change.  I've filed a bug to request this revision,
> and a few others that fix the test case, to be merged.
> https://bugs.llvm.org/show_bug.cgi?id=35981
>
>
> On Tue, Jan 16, 2018 at 2:44 PM, NAKAMURA Takumi 
> wrote:
>
>> If r322350 is temporary fix, I suggest r321395 may be reverted in
>> release_60. Richard, how do you think?
>>
>> On Wed, Jan 17, 2018 at 4:27 AM Richard Trieu via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>> There was a different, possibly related, issue with templated methods
>>> that I just disabled checking for methods all together in r321396 until
>>> I can investigate further.
>>>
>>>
>>> On Mon, Jan 15, 2018 at 10:45 AM, David Blaikie 
>>> wrote:
>>>
 I'm surprised this problem is unique to friend functions with
 definitions inline and the friend declaration site - doesn't a similar
 issue occur with member functions of templates that are not instantiated in
 some (similar) contexts?

 Is there a common solution that could be used for both cases?


 On Thu, Jan 11, 2018 at 8:43 PM Richard Trieu via cfe-commits <
 cfe-commits@lists.llvm.org> wrote:

> Author: rtrieu
> Date: Thu Jan 11 20:42:27 2018
> New Revision: 322350
>
> URL: http://llvm.org/viewvc/llvm-project?rev=322350&view=rev
> Log:
> [ODRHash] Don't hash friend functions.
>
> In certain combinations of templated classes and friend functions, the
> body
> of friend functions does not get propagated along with function
> signature.
> Exclude friend functions for hashing to avoid this case.
>
> Added:
> cfe/trunk/test/Modules/Inputs/odr_hash-Friend/
> cfe/trunk/test/Modules/Inputs/odr_hash-Friend/Box.h
> cfe/trunk/test/Modules/Inputs/odr_hash-Friend/M1.h
> cfe/trunk/test/Modules/Inputs/odr_hash-Friend/M2.h
> cfe/trunk/test/Modules/Inputs/odr_hash-Friend/M3.h
> cfe/trunk/test/Modules/Inputs/odr_hash-Friend/module.modulemap
> cfe/trunk/test/Modules/odr_hash-Friend.cpp
> Modified:
> cfe/trunk/lib/AST/ODRHash.cpp
>
> Modified: cfe/trunk/lib/AST/ODRHash.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ODRHash.cpp?rev=322350&r1=322349&r2=322350&view=diff
>
> ==
> --- cfe/trunk/lib/AST/ODRHash.cpp (original)
> +++ cfe/trunk/lib/AST/ODRHash.cpp Thu Jan 11 20:42:27 2018
> @@ -478,6 +478,8 @@ void ODRHash::AddFunctionDecl(const Func
>
>// TODO: Fix hashing for class methods.
>if (isa(Function)) return;
> +  // And friend functions.
> +  if (Function->getFriendObjectKind()) return;
>
>// Skip functions that are specializations or in specialization
> context.
>const DeclContext *DC = Function;
>
> Added: cfe/trunk/test/Modules/Inputs/odr_hash-Friend/Box.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/odr_hash-Friend/Box.h?rev=322350&view=auto
>
> ==
> --- cfe/trunk/test/Modules/Inputs/odr_hash-Friend/Box.h (added)
> +++ cfe/trunk/test/Modules/Inputs/odr_hash-Friend/Box.h Thu Jan 11
> 20:42:27 2018
> @@ -0,0 +1,14 @@
> +template 
> +struct iterator {
> +  void Compare(const iterator &x) { }
> +  friend void Check(iterator) {}
> +};
> +
> +template  struct Box {
> +  iterator I;
> +
> +  void test() {
> +Check(I);
> +I.Compare(I);
> +  }
> +};
>
> Added: cfe/trunk/test/Modules/Inputs/odr_hash-Friend/M1.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/odr_hash-Friend/M1.h?rev=322350&view=auto
>
> ==
> --- cfe/trunk/test/Modules/Inputs/odr_hash-Friend/M1.h (added)
> +++ cfe/trunk/test/Modules/Inputs/odr_hash-Friend/M1.h Thu Jan 11
> 20:42:27 2018
> @@ -0,0 +1,6 @@
> +#include "Box.h"
> +
> +void Peek() {
> +  Box<> Gift;
> +  Gift.test();
> +}
>
> Added: cfe/trunk/test/Modules/Inputs/odr_hash-Friend/M2.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/odr_hash-Friend/M2.h?rev=322350&view=auto
>
> ==
> --- cfe/trunk/test/Modules/Inputs/odr_hash-Friend/M2.h (added)
> +++ cfe/trunk/test/Modules/Inputs/odr_hash-Friend/M2.h Thu Jan 11
> 20:42:27 2018
> @@ -0,0 +1,5 @@
> +#include "Box.h"
> +void x() {
> +  Box<> Unused;
> +  //Unused.test();
> +}
>
> Added: cfe/trunk/test/Modules/I

[PATCH] D32747: [Analyzer] Iterator Checker - Part 3: Invalidation check, first for (copy) assignments

2018-01-17 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware added a comment.

Thanks you for your comments! I have one question:




Comment at: lib/StaticAnalyzer/Checkers/IteratorChecker.cpp:1256
+if (Cond(Reg.second)) {
+  State = setIteratorPosition(State, Reg.first, Proc(Reg.second));
+}

a.sidorin wrote:
> Updating ProgramState is usually considered as an expensive operation. 
> Instead, we can update maps (RegionMap and SymbolMap) and then, if they have 
> any updates, create a state containing these maps. What do you think?
How to update ImmutableMap?


https://reviews.llvm.org/D32747



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


[PATCH] D32845: [Analyzer] Iterator Checker - Part 4: Mismatched iterator checker for function parameters

2018-01-17 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware marked an inline comment as done.
baloghadamsoftware added inline comments.



Comment at: lib/StaticAnalyzer/Checkers/IteratorChecker.cpp:382
 }
+  } else if (!isa(&Call)) {
+// The main purpose of iterators is to abstract away from different

a.sidorin wrote:
> The function becomes > 100 lines long. Should we refactor this check into a 
> separate function to improve readability?
Yes, I think so this would be a good idea. Should I do it now?



Comment at: lib/StaticAnalyzer/Checkers/IteratorChecker.cpp:388
+// template parameters for different containers. So we can safely
+// assume that passing iterators of different containers as arguments
+// whose type replaces the same template parameter is a bug.

a.sidorin wrote:
> While this assumption is sane and is true for  functions, user 
> code can have other design solutions. There is nothing that prevents users 
> from writing a function looking like:
> ```
> template 
> void f(IterTy FromBegin, IterTy FromEnd, IterTy ToBegin, IterTy ToEnd);
> ```
> and there is nothing wrong with it.
> One of  possible solutions is to restrict checker to check only functions 
> from std namespace. What do you think?
We can restrict, of course, but first we should measure how it performs on real 
code. With the restriction, we can get rid of some false positives but we may 
also loose some true positives.


https://reviews.llvm.org/D32845



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


[PATCH] D32747: [Analyzer] Iterator Checker - Part 3: Invalidation check, first for (copy) assignments

2018-01-17 Thread Aleksei Sidorin via Phabricator via cfe-commits
a.sidorin added inline comments.



Comment at: lib/StaticAnalyzer/Checkers/IteratorChecker.cpp:1256
+if (Cond(Reg.second)) {
+  State = setIteratorPosition(State, Reg.first, Proc(Reg.second));
+}

baloghadamsoftware wrote:
> a.sidorin wrote:
> > Updating ProgramState is usually considered as an expensive operation. 
> > Instead, we can update maps (RegionMap and SymbolMap) and then, if they 
> > have any updates, create a state containing these maps. What do you think?
> How to update ImmutableMap?
You can create a new Immutable map from existing with factory methods:
```
auto Factory = State->get_context();
auto Map = State->get();
Map = Factory.add(Map, Key, Value);
Map = Factory.add(Map, Key2, Value2);
State = State->set(Map);
```


https://reviews.llvm.org/D32747



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


[PATCH] D41815: [clang-tidy] implement check for goto

2018-01-17 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth updated this revision to Diff 130113.
JonasToth marked an inline comment as done.
JonasToth added a comment.

- [Misc] remove spurious format


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41815

Files:
  clang-tidy/cppcoreguidelines/AvoidGotoCheck.cpp
  clang-tidy/cppcoreguidelines/AvoidGotoCheck.h
  clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tidy/hicpp/HICPPTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/cppcoreguidelines-avoid-goto.rst
  docs/clang-tidy/checks/hicpp-avoid-goto.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/cppcoreguidelines-avoid-goto.cpp

Index: test/clang-tidy/cppcoreguidelines-avoid-goto.cpp
===
--- /dev/null
+++ test/clang-tidy/cppcoreguidelines-avoid-goto.cpp
@@ -0,0 +1,139 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-avoid-goto %t
+
+void noop() {}
+
+int main() {
+  noop();
+  goto jump_to_me;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: avoid using 'goto' for flow control
+  // CHECK-MESSAGES: [[@LINE+3]]:1: note: label defined here
+  noop();
+
+jump_to_me:;
+
+jump_backwards:;
+  noop();
+  goto jump_backwards;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: avoid using 'goto' for flow control
+  // CHECK-MESSAGES: [[@LINE-4]]:1: note: label defined here
+
+  goto jump_in_line;
+  ;
+jump_in_line:;
+  // CHECK-MESSAGES: [[@LINE-3]]:3: warning: avoid using 'goto' for flow control
+  // CHECK-MESSAGES: [[@LINE-2]]:1: note: label defined here
+
+  // Test the GNU extension https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html
+some_label:;
+  void *dynamic_label = &&some_label;
+
+  // FIXME: `IndirectGotoStmt` is not detected.
+  goto *dynamic_label;
+}
+
+void forward_jump_out_nested_loop() {
+  int array[] = {1, 2, 3, 4, 5};
+  for (int i = 0; i < 10; ++i) {
+noop();
+for (int j = 0; j < 10; ++j) {
+  noop();
+  if (i + j > 10)
+goto early_exit1;
+}
+noop();
+  }
+
+  for (int i = 0; i < 10; ++i) {
+noop();
+while (true) {
+  noop();
+  if (i > 5)
+goto early_exit1;
+}
+noop();
+  }
+
+  for (auto value : array) {
+noop();
+for (auto number : array) {
+  noop();
+  if (number == 5)
+goto early_exit1;
+}
+  }
+
+  do {
+noop();
+do {
+  noop();
+  goto early_exit1;
+} while (true);
+  } while (true);
+
+  do {
+for (auto number : array) {
+  noop();
+  if (number == 2)
+goto early_exit1;
+}
+  } while (true);
+
+  // Jumping further results in error, because the variable declaration would
+  // be skipped.
+early_exit1:;
+
+  int i = 0;
+  while (true) {
+noop();
+while (true) {
+  noop();
+  if (i > 5)
+goto early_exit2;
+  i++;
+}
+noop();
+  }
+
+  while (true) {
+noop();
+for (int j = 0; j < 10; ++j) {
+  noop();
+  if (j > 5)
+goto early_exit2;
+}
+noop();
+  }
+
+  while (true) {
+noop();
+for (auto number : array) {
+  if (number == 1)
+goto early_exit2;
+  noop();
+}
+  }
+
+  while (true) {
+noop();
+do {
+  noop();
+  goto early_exit2;
+} while (true);
+  }
+early_exit2:;
+}
+
+void jump_out_backwards() {
+
+before_the_loop:
+  noop();
+
+  for (int i = 0; i < 10; ++i) {
+for (int j = 0; j < 10; ++j) {
+  if (i * j > 80)
+goto before_the_loop;
+  // CHECK-MESSAGES: [[@LINE-1]]:9: warning: avoid using 'goto' for flow control
+  // CHECK-MESSAGES: [[@LINE-8]]:1: note: label defined here
+}
+  }
+}
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -52,6 +52,7 @@
cert-msc30-c (redirects to cert-msc50-cpp) 
cert-msc50-cpp
cert-oop11-cpp (redirects to performance-move-constructor-init) 
+   cppcoreguidelines-avoid-goto
cppcoreguidelines-c-copy-assignment-signature (redirects to misc-unconventional-assign-operator) 
cppcoreguidelines-interfaces-global-init
cppcoreguidelines-no-malloc
@@ -90,6 +91,7 @@
google-runtime-member-string-references
google-runtime-operator
google-runtime-references
+   hicpp-avoid-goto (redirects to cppcoreguidelines-avoid-goto) 
hicpp-braces-around-statements (redirects to readability-braces-around-statements) 
hicpp-deprecated-headers (redirects to modernize-deprecated-headers) 
hicpp-exception-baseclass
Index: docs/clang-tidy/checks/hicpp-avoid-goto.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/hicpp-avoid-goto.rst
@@ -0,0 +1,12 @@
+.. title:: clang-tidy - hicpp-avoid-goto
+
+hicpp-avoid-goto
+
+
+The `hicpp-avoid-goto` check is an alias to 
+`cppcoreguidelines-avoid-goto `_.
+Rule `6.3.1 High Integrity C++ 

[clang-tools-extra] r322624 - [clang-tidy] fix minor formatting issue

2018-01-17 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Wed Jan 17 02:23:50 2018
New Revision: 322624

URL: http://llvm.org/viewvc/llvm-project?rev=322624&view=rev
Log:
[clang-tidy] fix minor formatting issue

Modified:
clang-tools-extra/trunk/clang-tidy/hicpp/HICPPTidyModule.cpp

Modified: clang-tools-extra/trunk/clang-tidy/hicpp/HICPPTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/hicpp/HICPPTidyModule.cpp?rev=322624&r1=322623&r2=322624&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/hicpp/HICPPTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/hicpp/HICPPTidyModule.cpp Wed Jan 17 
02:23:50 2018
@@ -51,8 +51,7 @@ public:
 "hicpp-deprecated-headers");
 CheckFactories.registerCheck(
 "hicpp-exception-baseclass");
-CheckFactories.registerCheck(
-"hicpp-signed-bitwise");
+CheckFactories.registerCheck("hicpp-signed-bitwise");
 CheckFactories.registerCheck(
 "hicpp-explicit-conversions");
 CheckFactories.registerCheck(


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


[clang-tools-extra] r322626 - [clang-tidy] implement check for goto

2018-01-17 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Wed Jan 17 02:27:41 2018
New Revision: 322626

URL: http://llvm.org/viewvc/llvm-project?rev=322626&view=rev
Log:
[clang-tidy] implement check for goto

The usage of `goto` is discourage in C++ since forever. This check implements
a warning for every `goto`. Even though there are (rare) valid use cases for
`goto`, better high level constructs should be used.

`goto` is used sometimes in C programs to free resources at the end of 
functions in the case of errors. This pattern is better implemented with
RAII in C++.

Reviewers: aaron.ballman, alexfh, hokein

Reviewed By: aaron.ballman

Subscribers: lebedev.ri, jbcoe, Eugene.Zelenko, klimek, nemanjai, mgorny, 
xazax.hun, kbarton, cfe-commits

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

Added:
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/AvoidGotoCheck.cpp
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/AvoidGotoCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-avoid-goto.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/hicpp-avoid-goto.rst
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-avoid-goto.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CMakeLists.txt

clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/hicpp/HICPPTidyModule.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Added: clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/AvoidGotoCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/AvoidGotoCheck.cpp?rev=322626&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/AvoidGotoCheck.cpp 
(added)
+++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/AvoidGotoCheck.cpp Wed 
Jan 17 02:27:41 2018
@@ -0,0 +1,55 @@
+//===--- AvoidGotoCheck.cpp - 
clang-tidy---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "AvoidGotoCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace cppcoreguidelines {
+
+AST_MATCHER(GotoStmt, isForwardJumping) {
+  return Node.getLocStart() < Node.getLabel()->getLocStart();
+}
+
+void AvoidGotoCheck::registerMatchers(MatchFinder *Finder) {
+  if (!getLangOpts().CPlusPlus)
+return;
+
+  // TODO: This check does not recognize `IndirectGotoStmt` which is a
+  // GNU extension. These must be matched separately and an AST matcher
+  // is currently missing for them.
+
+  // Check if the 'goto' is used for control flow other than jumping
+  // out of a nested loop.
+  auto Loop = stmt(anyOf(forStmt(), cxxForRangeStmt(), whileStmt(), doStmt()));
+  auto NestedLoop =
+  stmt(anyOf(forStmt(hasAncestor(Loop)), 
cxxForRangeStmt(hasAncestor(Loop)),
+ whileStmt(hasAncestor(Loop)), doStmt(hasAncestor(Loop;
+
+  Finder->addMatcher(gotoStmt(anyOf(unless(hasAncestor(NestedLoop)),
+unless(isForwardJumping(
+ .bind("goto"),
+ this);
+}
+
+void AvoidGotoCheck::check(const MatchFinder::MatchResult &Result) {
+  const auto *Goto = Result.Nodes.getNodeAs("goto");
+
+  diag(Goto->getGotoLoc(), "avoid using 'goto' for flow control")
+  << Goto->getSourceRange();
+  diag(Goto->getLabel()->getLocStart(), "label defined here",
+   DiagnosticIDs::Note);
+}
+} // namespace cppcoreguidelines
+} // namespace tidy
+} // namespace clang

Added: clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/AvoidGotoCheck.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/AvoidGotoCheck.h?rev=322626&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/AvoidGotoCheck.h 
(added)
+++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/AvoidGotoCheck.h Wed 
Jan 17 02:27:41 2018
@@ -0,0 +1,36 @@
+//===--- AvoidGotoCheck.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_CLANG_TIDY_CPPCOREGUIDELINES_AVOIDGOTOCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_AVOIDGOTOCHECK_H
+
+#include "../ClangTidy.h"
+
+na

[PATCH] D41815: [clang-tidy] implement check for goto

2018-01-17 Thread Jonas Toth via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE322626: [clang-tidy] implement check for goto (authored by 
JonasToth, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D41815?vs=130113&id=130115#toc

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41815

Files:
  clang-tidy/cppcoreguidelines/AvoidGotoCheck.cpp
  clang-tidy/cppcoreguidelines/AvoidGotoCheck.h
  clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tidy/hicpp/HICPPTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/cppcoreguidelines-avoid-goto.rst
  docs/clang-tidy/checks/hicpp-avoid-goto.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/cppcoreguidelines-avoid-goto.cpp

Index: clang-tidy/cppcoreguidelines/AvoidGotoCheck.cpp
===
--- clang-tidy/cppcoreguidelines/AvoidGotoCheck.cpp
+++ clang-tidy/cppcoreguidelines/AvoidGotoCheck.cpp
@@ -0,0 +1,55 @@
+//===--- AvoidGotoCheck.cpp - clang-tidy---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "AvoidGotoCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace cppcoreguidelines {
+
+AST_MATCHER(GotoStmt, isForwardJumping) {
+  return Node.getLocStart() < Node.getLabel()->getLocStart();
+}
+
+void AvoidGotoCheck::registerMatchers(MatchFinder *Finder) {
+  if (!getLangOpts().CPlusPlus)
+return;
+
+  // TODO: This check does not recognize `IndirectGotoStmt` which is a
+  // GNU extension. These must be matched separately and an AST matcher
+  // is currently missing for them.
+
+  // Check if the 'goto' is used for control flow other than jumping
+  // out of a nested loop.
+  auto Loop = stmt(anyOf(forStmt(), cxxForRangeStmt(), whileStmt(), doStmt()));
+  auto NestedLoop =
+  stmt(anyOf(forStmt(hasAncestor(Loop)), cxxForRangeStmt(hasAncestor(Loop)),
+ whileStmt(hasAncestor(Loop)), doStmt(hasAncestor(Loop;
+
+  Finder->addMatcher(gotoStmt(anyOf(unless(hasAncestor(NestedLoop)),
+unless(isForwardJumping(
+ .bind("goto"),
+ this);
+}
+
+void AvoidGotoCheck::check(const MatchFinder::MatchResult &Result) {
+  const auto *Goto = Result.Nodes.getNodeAs("goto");
+
+  diag(Goto->getGotoLoc(), "avoid using 'goto' for flow control")
+  << Goto->getSourceRange();
+  diag(Goto->getLabel()->getLocStart(), "label defined here",
+   DiagnosticIDs::Note);
+}
+} // namespace cppcoreguidelines
+} // namespace tidy
+} // namespace clang
Index: clang-tidy/cppcoreguidelines/AvoidGotoCheck.h
===
--- clang-tidy/cppcoreguidelines/AvoidGotoCheck.h
+++ clang-tidy/cppcoreguidelines/AvoidGotoCheck.h
@@ -0,0 +1,36 @@
+//===--- AvoidGotoCheck.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_CLANG_TIDY_CPPCOREGUIDELINES_AVOIDGOTOCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_AVOIDGOTOCHECK_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace cppcoreguidelines {
+
+/// The usage of ``goto`` for control flow is error prone and should be replaced
+/// with looping constructs. Only forward jumps in nested loops are accepted.
+//
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines-avoid-goto.html
+class AvoidGotoCheck : public ClangTidyCheck {
+public:
+  AvoidGotoCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
+} // namespace cppcoreguidelines
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_AVOIDGOTOCHECK_H
Index: clang-tidy/cppcoreguidelines/CMakeLists.txt
===
--- clang-tidy/cppcoreguidelines/CMakeLists.txt
+++ clang-tidy/cppcoreguidelines/CMakeLists.txt
@@ -1,6 +1,7 @@
 set(LLVM_LINK_COMPONENTS support)
 
 add_clang_library(clangTidyCppCoreGuidelinesModule
+  AvoidGotoCheck.cpp
   CppCoreGuidelinesTidyModule.cpp
   Interf

[PATCH] D41788: [DeclPrinter] Fix two cases that crash clang -ast-print.

2018-01-17 Thread Benjamin Kramer via Phabricator via cfe-commits
bkramer accepted this revision.
bkramer added a comment.
This revision is now accepted and ready to land.

This should be fine.


https://reviews.llvm.org/D41788



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


[PATCH] D41708: [clang-tidy] Update fuchsia-overloaded-operator to check for valid loc

2018-01-17 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

In https://reviews.llvm.org/D41708#977000, @hans wrote:

> Alex, do you think the fix is still OK for the 6.0 branch? Let me know, and 
> I'll merge it.


Yes, please. Thank you!


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41708



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


[PATCH] D42071: [Sema] Add a callback in VisibleDeclConsumer allowing client to know which DeclContext is going to visit.

2018-01-17 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 130117.
hokein marked 2 inline comments as done.
hokein added a comment.
Herald added a subscriber: mgorny.

Refine the patch:

- expose visited contexts to client by adding `getVisitedContexts` in 
CodeCompleteContext.
- add unittest for sema code completion.


Repository:
  rC Clang

https://reviews.llvm.org/D42071

Files:
  include/clang/Sema/CodeCompleteConsumer.h
  include/clang/Sema/Lookup.h
  lib/Sema/SemaCodeComplete.cpp
  lib/Sema/SemaLookup.cpp
  unittests/Sema/CMakeLists.txt
  unittests/Sema/CodeCompleteTest.cpp

Index: unittests/Sema/CodeCompleteTest.cpp
===
--- /dev/null
+++ unittests/Sema/CodeCompleteTest.cpp
@@ -0,0 +1,135 @@
+//=== unittests/Sema/CodeCompleteTest.cpp - Code Complete tests ==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Parse/ParseAST.h"
+#include "clang/Sema/Sema.h"
+#include "clang/Sema/SemaDiagnostic.h"
+#include "clang/Tooling/Tooling.h"
+#include "gtest/gtest.h"
+#include "gmock/gmock.h"
+
+namespace {
+
+using namespace clang;
+using namespace clang::tooling;
+using ::testing::UnorderedElementsAre;
+
+const char TestCCName[] = "test.cc";
+using VisitedContextResults = std::vector;
+
+class VisitedContextFinder: public CodeCompleteConsumer {
+public:
+  VisitedContextFinder(VisitedContextResults &Results)
+  : CodeCompleteConsumer(/*CodeCompleteOpts=*/{},
+ /*CodeCompleteConsumer*/ false),
+VCResults(Results),
+CCTUInfo(std::make_shared()) {}
+
+  void ProcessCodeCompleteResults(Sema &S, CodeCompletionContext Context,
+  CodeCompletionResult *Results,
+  unsigned NumResults) override {
+VisitedContexts = Context.getVisitedContexts();
+VCResults = getVisitedNamespace();
+  }
+
+  CodeCompletionAllocator &getAllocator() override {
+return CCTUInfo.getAllocator();
+  }
+
+  CodeCompletionTUInfo &getCodeCompletionTUInfo() override { return CCTUInfo; }
+
+  std::vector getVisitedNamespace() const {
+std::vector NSNames;
+for (const auto *Context : VisitedContexts)
+  if (const auto *NS = llvm::dyn_cast(Context))
+NSNames.push_back(NS->getQualifiedNameAsString());
+return NSNames;
+  }
+
+private:
+  VisitedContextResults& VCResults;
+  CodeCompletionTUInfo CCTUInfo;
+  CodeCompletionContext::VisitedContextSet VisitedContexts;
+};
+
+class CodeCompleteAction : public SyntaxOnlyAction {
+public:
+  CodeCompleteAction(ParsedSourceLocation P, VisitedContextResults &Results)
+  : CompletePosition(std::move(P)), VCResults(Results) {}
+
+  bool BeginInvocation(CompilerInstance &CI) override {
+auto& opts = CI.getFrontendOpts();
+opts.CodeCompletionAt = CompletePosition;
+CI.setCodeCompletionConsumer(new VisitedContextFinder(VCResults));
+return true;
+  }
+
+private:
+  // 1-based code complete position ;
+  ParsedSourceLocation CompletePosition;
+  VisitedContextResults& VCResults;
+};
+
+ParsedSourceLocation offsetToPosition(llvm::StringRef Code, size_t Offset) {
+  Offset = std::min(Code.size(), Offset);
+  StringRef Before = Code.substr(0, Offset);
+  int Lines = Before.count('\n');
+  size_t PrevNL = Before.rfind('\n');
+  size_t StartOfLine = (PrevNL == StringRef::npos) ? 0 : (PrevNL + 1);
+  return {TestCCName, static_cast(Lines + 1),
+  static_cast(Offset - StartOfLine + 1)};
+}
+
+VisitedContextResults runCodeCompleteOnCode(StringRef Code) {
+  VisitedContextResults Results;
+  auto TokenOffset = Code.find('^');
+  assert(TokenOffset != StringRef::npos &&
+ "Completion token ^ wasn't found in Code.");
+  std::string WithoutToken = Code.take_front(TokenOffset);
+  WithoutToken += Code.drop_front(WithoutToken.size() + 1);
+  assert(StringRef(WithoutToken).find('^') == StringRef::npos &&
+ "expected exactly one completion token ^ inside the code");
+
+  auto Action = llvm::make_unique(
+  offsetToPosition(WithoutToken, TokenOffset), Results);
+  clang::tooling::runToolOnCodeWithArgs(Action.release(), Code, {"-std=c++11"},
+TestCCName);
+  return Results;
+}
+
+TEST(SemaCodeCompleteTest, VisitedNSForValidQualifiedId) {
+  auto VisitedNS = runCodeCompleteOnCode(R"cpp(
+ namespace ns1 {}
+ namespace ns2 {}
+ namespace ns3 {}
+ namespace ns3 { namespace nns3 {} }
+
+ namespace foo {
+ using namespace ns1;
+ namespace ns4 {} // not visited
+ namespace { using namespace ns2; }
+ inline namespace bar { using namespace ns3::nns3; }
+ } //

[PATCH] D42072: [Sema] Expose current scope in qualified-id code completion.

2018-01-17 Thread Haojian Wu via Phabricator via cfe-commits
hokein abandoned this revision.
hokein added a comment.

This is not needed now, we decide to keep lookup logic in Sema instead of 
clangd side.


Repository:
  rC Clang

https://reviews.llvm.org/D42072



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


Re: r322350 - [ODRHash] Don't hash friend functions.

2018-01-17 Thread Hans Wennborg via cfe-commits
Merged in r322632.

On Wed, Jan 17, 2018 at 9:52 AM, NAKAMURA Takumi via cfe-commits
 wrote:
> That's good to hear. Thanks!
>
>
> 2018年1月17日(水) 13:51 Richard Trieu :
>>
>> I feel it's best to merge this change into the release branch instead of
>> reverting the previous change.  I've filed a bug to request this revision,
>> and a few others that fix the test case, to be merged.
>> https://bugs.llvm.org/show_bug.cgi?id=35981
>>
>>
>> On Tue, Jan 16, 2018 at 2:44 PM, NAKAMURA Takumi 
>> wrote:
>>>
>>> If r322350 is temporary fix, I suggest r321395 may be reverted in
>>> release_60. Richard, how do you think?
>>>
>>> On Wed, Jan 17, 2018 at 4:27 AM Richard Trieu via cfe-commits
>>>  wrote:

 There was a different, possibly related, issue with templated methods
 that I just disabled checking for methods all together in r321396 until I
 can investigate further.


 On Mon, Jan 15, 2018 at 10:45 AM, David Blaikie 
 wrote:
>
> I'm surprised this problem is unique to friend functions with
> definitions inline and the friend declaration site - doesn't a similar 
> issue
> occur with member functions of templates that are not instantiated in some
> (similar) contexts?
>
> Is there a common solution that could be used for both cases?
>
>
> On Thu, Jan 11, 2018 at 8:43 PM Richard Trieu via cfe-commits
>  wrote:
>>
>> Author: rtrieu
>> Date: Thu Jan 11 20:42:27 2018
>> New Revision: 322350
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=322350&view=rev
>> Log:
>> [ODRHash] Don't hash friend functions.
>>
>> In certain combinations of templated classes and friend functions, the
>> body
>> of friend functions does not get propagated along with function
>> signature.
>> Exclude friend functions for hashing to avoid this case.
>>
>> Added:
>> cfe/trunk/test/Modules/Inputs/odr_hash-Friend/
>> cfe/trunk/test/Modules/Inputs/odr_hash-Friend/Box.h
>> cfe/trunk/test/Modules/Inputs/odr_hash-Friend/M1.h
>> cfe/trunk/test/Modules/Inputs/odr_hash-Friend/M2.h
>> cfe/trunk/test/Modules/Inputs/odr_hash-Friend/M3.h
>> cfe/trunk/test/Modules/Inputs/odr_hash-Friend/module.modulemap
>> cfe/trunk/test/Modules/odr_hash-Friend.cpp
>> Modified:
>> cfe/trunk/lib/AST/ODRHash.cpp
>>
>> Modified: cfe/trunk/lib/AST/ODRHash.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ODRHash.cpp?rev=322350&r1=322349&r2=322350&view=diff
>>
>> ==
>> --- cfe/trunk/lib/AST/ODRHash.cpp (original)
>> +++ cfe/trunk/lib/AST/ODRHash.cpp Thu Jan 11 20:42:27 2018
>> @@ -478,6 +478,8 @@ void ODRHash::AddFunctionDecl(const Func
>>
>>// TODO: Fix hashing for class methods.
>>if (isa(Function)) return;
>> +  // And friend functions.
>> +  if (Function->getFriendObjectKind()) return;
>>
>>// Skip functions that are specializations or in specialization
>> context.
>>const DeclContext *DC = Function;
>>
>> Added: cfe/trunk/test/Modules/Inputs/odr_hash-Friend/Box.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/odr_hash-Friend/Box.h?rev=322350&view=auto
>>
>> ==
>> --- cfe/trunk/test/Modules/Inputs/odr_hash-Friend/Box.h (added)
>> +++ cfe/trunk/test/Modules/Inputs/odr_hash-Friend/Box.h Thu Jan 11
>> 20:42:27 2018
>> @@ -0,0 +1,14 @@
>> +template 
>> +struct iterator {
>> +  void Compare(const iterator &x) { }
>> +  friend void Check(iterator) {}
>> +};
>> +
>> +template  struct Box {
>> +  iterator I;
>> +
>> +  void test() {
>> +Check(I);
>> +I.Compare(I);
>> +  }
>> +};
>>
>> Added: cfe/trunk/test/Modules/Inputs/odr_hash-Friend/M1.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/odr_hash-Friend/M1.h?rev=322350&view=auto
>>
>> ==
>> --- cfe/trunk/test/Modules/Inputs/odr_hash-Friend/M1.h (added)
>> +++ cfe/trunk/test/Modules/Inputs/odr_hash-Friend/M1.h Thu Jan 11
>> 20:42:27 2018
>> @@ -0,0 +1,6 @@
>> +#include "Box.h"
>> +
>> +void Peek() {
>> +  Box<> Gift;
>> +  Gift.test();
>> +}
>>
>> Added: cfe/trunk/test/Modules/Inputs/odr_hash-Friend/M2.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/odr_hash-Friend/M2.h?rev=322350&view=auto
>>
>> ==
>> --- cfe/trunk/test/Modules/Inputs/odr_hash-Friend/M2.h (added)
>> +++ cfe/trunk/test/Modules/Inputs/odr_hash-Friend/M2.h Thu Jan 11
>>

[PATCH] D42164: [clangd] Don't crash on LSP calls for non-added files

2018-01-17 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov created this revision.
ilya-biryukov added reviewers: sammccall, ioeric, hokein.
Herald added a subscriber: klimek.

We will return errors for non-added files for now.
Another alternative for clangd would be to read non-added files from
disk and provide useful features anyway.

There are still some cases that fail with assertion (e.g., code
complete). We should address those too, but they require more subtle
changes to the code and therefore out of scope of this patch.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42164

Files:
  clangd/ClangdLSPServer.cpp
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  test/clangd/crash.test

Index: test/clangd/crash.test
===
--- /dev/null
+++ test/clangd/crash.test
@@ -0,0 +1,45 @@
+# RUN: clangd -pretty -run-synchronously < %s | FileCheck -strict-whitespace %s
+# It is absolutely vital that this file has CRLF line endings.
+#
+Content-Length: 125
+
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
+#
+Content-Length: 746
+
+{"jsonrpc":"2.0","id":2,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"file:///foo.c"},"range":{"start":{"line":104,"character":13},"end":{"line":0,"character":35}},"context":{"diagnostics":[{"range":{"start": {"line": 0, "character": 32}, "end": {"line": 0, "character": 37}},"severity":2,"message":"using the result of an assignment as a condition without parentheses"},{"range":{"start": {"line": 0, "character": 34}, "end": {"line": 0, "character": 35}},"severity":3,"message":"place parentheses around the assignment to silence this warning"},{"range":{"start": {"line": 0, "character": 34}, "end": {"line": 0, "character": 35}},"severity":3,"message":"use '==' to turn this assignment into an equality comparison"}]}}}
+#  CHECK:  "error": {
+# CHECK-NEXT:"code": -32602
+# CHECK-NEXT:"message": "onCodeAction called for non-added file"
+# CHECK-NEXT:  },
+# CHECK-NEXT:  "id": 2,
+Content-Length: 233
+
+{"jsonrpc":"2.0","id":3,"method":"textDocument/rangeFormatting","params":{"textDocument":{"uri":"file:///foo.c"},"range":{"start":{"line":1,"character":4},"end":{"line":1,"character":12}},"options":{"tabSize":4,"insertSpaces":true}}}
+#  CHECK:  "error": {
+# CHECK-NEXT:"code": -32602
+# CHECK-NEXT:"message": "onDocumentRangeFormatting called for non-added file"
+# CHECK-NEXT:  },
+# CHECK-NEXT:  "id": 3,
+Content-Length: 153
+
+{"jsonrpc":"2.0","id":4,"method":"textDocument/formatting","params":{"textDocument":{"uri":"file:///foo.c"},"options":{"tabSize":4,"insertSpaces":true}}}
+#  CHECK:  "error": {
+# CHECK-NEXT:"code": -32602
+# CHECK-NEXT:"message": "onDocumentFormatting called for non-added file"
+# CHECK-NEXT:  },
+# CHECK-NEXT:  "id": 4,
+Content-Length: 204
+
+{"jsonrpc":"2.0","id":5,"method":"textDocument/onTypeFormatting","params":{"textDocument":{"uri":"file:///foo.c"},"position":{"line":3,"character":1},"ch":"}","options":{"tabSize":4,"insertSpaces":true}}}
+#  CHECK:  "error": {
+# CHECK-NEXT:"code": -32602
+# CHECK-NEXT:"message": "onDocumentOnTypeFormatting called for non-added file"
+# CHECK-NEXT:  },
+# CHECK-NEXT:  "id": 5,
+Content-Length: 44
+
+{"jsonrpc":"2.0","id":6,"method":"shutdown"}
+Content-Length: 33
+
+{"jsonrpc":"2.0","method":"exit"}
Index: clangd/ClangdServer.h
===
--- clangd/ClangdServer.h
+++ clangd/ClangdServer.h
@@ -308,11 +308,11 @@
  PathRef File, Position Pos,
  llvm::StringRef NewName);
 
-  /// Gets current document contents for \p File. \p File must point to a
-  /// currently tracked file.
+  /// Gets current document contents for \p File. Returns None if \p File is not
+  /// currently tracked.
   /// FIXME(ibiryukov): This function is here to allow offset-to-Position
   /// conversions in outside code, maybe there's a way to get rid of it.
-  std::string getDocument(PathRef File);
+  llvm::Optional getDocument(PathRef File);
 
   /// Only for testing purposes.
   /// Waits until all requests to worker thread are finished and dumps AST for
Index: clangd/ClangdServer.cpp
===
--- clangd/ClangdServer.cpp
+++ clangd/ClangdServer.cpp
@@ -356,7 +356,6 @@
 Expected>
 ClangdServer::rename(const Context &Ctx, PathRef File, Position Pos,
  llvm::StringRef NewName) {
-  std::string Code = getDocument(File);
   std::shared_ptr Resources = Units.getFile(File);
   RefactoringResultCollector ResultCollector;
   Resources->getAST().get()->runUnderLock([&](ParsedAST *AST) {
@@ -402,15 +401,17 @@
   return Replacements;
 }
 
-std::string ClangdServer::getDocument(PathRef File) {
-  auto draft = DraftMgr.getDraft(File);
-  assert(draft.Draf

[PATCH] D42164: [clangd] Don't crash on LSP calls for non-added files

2018-01-17 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clangd/ClangdLSPServer.cpp:153
+
+  auto Code = Server.getDocument(File);
+  if (!Code)

don't you want to do this before computing replacements?



Comment at: clangd/ClangdLSPServer.cpp:155
+  if (!Code)
+return replyError(C, ErrorCode::InternalError,
+  "onRename called for non-added file");

invalidparams


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42164



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


r322634 - [clang-format] Reorganize RawStringFormat based on language

2018-01-17 Thread Krasimir Georgiev via cfe-commits
Author: krasimir
Date: Wed Jan 17 04:24:59 2018
New Revision: 322634

URL: http://llvm.org/viewvc/llvm-project?rev=322634&view=rev
Log:
[clang-format] Reorganize RawStringFormat based on language

Summary:
This patch changes the structure for raw string formatting options by making it
language based (enumerate delimiters per language) as opposed to delimiter-based
(specify the language for a delimiter). The raw string formatting now uses an
appropriate style from the .clang-format file, if exists.

Reviewers: bkramer

Reviewed By: bkramer

Subscribers: cfe-commits, klimek

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

Modified:
cfe/trunk/include/clang/Format/Format.h
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
cfe/trunk/unittests/Format/FormatTestRawStrings.cpp

Modified: cfe/trunk/include/clang/Format/Format.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=322634&r1=322633&r2=322634&view=diff
==
--- cfe/trunk/include/clang/Format/Format.h (original)
+++ cfe/trunk/include/clang/Format/Format.h Wed Jan 17 04:24:59 2018
@@ -1363,36 +1363,43 @@ struct FormatStyle {
 
   /// See documentation of ``RawStringFormats``.
   struct RawStringFormat {
-/// \brief The delimiter that this raw string format matches.
-std::string Delimiter;
 /// \brief The language of this raw string.
 LanguageKind Language;
+/// \brief A list of raw string delimiters that match this language.
+std::vector Delimiters;
 /// \brief The style name on which this raw string format is based on.
 /// If not specified, the raw string format is based on the style that this
 /// format is based on.
 std::string BasedOnStyle;
 bool operator==(const RawStringFormat &Other) const {
-  return Delimiter == Other.Delimiter && Language == Other.Language &&
+  return Language == Other.Language && Delimiters == Other.Delimiters &&
  BasedOnStyle == Other.BasedOnStyle;
 }
   };
 
-  /// \brief Raw string delimiters denoting that the raw string contents are
-  /// code in a particular language and can be reformatted.
+  /// \brief Defines hints for detecting supported languages code blocks in raw
+  /// strings.
   ///
   /// A raw string with a matching delimiter will be reformatted assuming the
-  /// specified language based on a predefined style given by 'BasedOnStyle'.
-  /// If 'BasedOnStyle' is not found, the formatting is based on llvm style.
+  /// specified language based on the style for that language defined in the
+  /// .clang-format file. If no style has been defined in the .clang-format 
file
+  /// for the specific language, a predefined style given by 'BasedOnStyle' is
+  /// used. If 'BasedOnStyle' is not found, the formatting is based on llvm
+  /// style.
   ///
   /// To configure this in the .clang-format file, use:
   /// \code{.yaml}
   ///   RawStringFormats:
-  /// - Delimiter: 'pb'
-  ///   Language:  TextProto
-  ///   BasedOnStyle: llvm
-  /// - Delimiter: 'proto'
-  ///   Language:  TextProto
-  ///   BasedOnStyle: google
+  /// - Language: TextProto
+  /// Delimiters:
+  ///   - 'pb'
+  ///   - 'proto'
+  /// BasedOnStyle: google
+  /// - Language: Cpp
+  /// Delimiters:
+  ///   - 'cc'
+  ///   - 'cpp'
+  /// BasedOnStyle: llvm
   /// \endcode
   std::vector RawStringFormats;
 

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=322634&r1=322633&r2=322634&view=diff
==
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Wed Jan 17 04:24:59 2018
@@ -105,14 +105,21 @@ static llvm::Optional getRawS
 RawStringFormatStyleManager::RawStringFormatStyleManager(
 const FormatStyle &CodeStyle) {
   for (const auto &RawStringFormat : CodeStyle.RawStringFormats) {
-FormatStyle Style;
-if (!getPredefinedStyle(RawStringFormat.BasedOnStyle,
-RawStringFormat.Language, &Style)) {
-  Style = getLLVMStyle();
-  Style.Language = RawStringFormat.Language;
+for (StringRef Delimiter : RawStringFormat.Delimiters) {
+  llvm::Optional LanguageStyle =
+  CodeStyle.GetLanguageStyle(RawStringFormat.Language);
+  if (!LanguageStyle) {
+FormatStyle PredefinedStyle;
+if (!getPredefinedStyle(RawStringFormat.BasedOnStyle,
+RawStringFormat.Language, &PredefinedStyle)) {
+  PredefinedStyle = getLLVMStyle();
+  PredefinedStyle.Language = RawStringFormat.Language;
+}
+LanguageStyle = PredefinedStyle;
+  }
+   

[PATCH] D42098: [clang-format] Reorganize RawStringFormat based on language

2018-01-17 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL322634: [clang-format] Reorganize RawStringFormat based on 
language (authored by krasimir, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D42098

Files:
  cfe/trunk/include/clang/Format/Format.h
  cfe/trunk/lib/Format/ContinuationIndenter.cpp
  cfe/trunk/lib/Format/Format.cpp
  cfe/trunk/unittests/Format/FormatTest.cpp
  cfe/trunk/unittests/Format/FormatTestRawStrings.cpp

Index: cfe/trunk/include/clang/Format/Format.h
===
--- cfe/trunk/include/clang/Format/Format.h
+++ cfe/trunk/include/clang/Format/Format.h
@@ -1363,36 +1363,43 @@
 
   /// See documentation of ``RawStringFormats``.
   struct RawStringFormat {
-/// \brief The delimiter that this raw string format matches.
-std::string Delimiter;
 /// \brief The language of this raw string.
 LanguageKind Language;
+/// \brief A list of raw string delimiters that match this language.
+std::vector Delimiters;
 /// \brief The style name on which this raw string format is based on.
 /// If not specified, the raw string format is based on the style that this
 /// format is based on.
 std::string BasedOnStyle;
 bool operator==(const RawStringFormat &Other) const {
-  return Delimiter == Other.Delimiter && Language == Other.Language &&
+  return Language == Other.Language && Delimiters == Other.Delimiters &&
  BasedOnStyle == Other.BasedOnStyle;
 }
   };
 
-  /// \brief Raw string delimiters denoting that the raw string contents are
-  /// code in a particular language and can be reformatted.
+  /// \brief Defines hints for detecting supported languages code blocks in raw
+  /// strings.
   ///
   /// A raw string with a matching delimiter will be reformatted assuming the
-  /// specified language based on a predefined style given by 'BasedOnStyle'.
-  /// If 'BasedOnStyle' is not found, the formatting is based on llvm style.
+  /// specified language based on the style for that language defined in the
+  /// .clang-format file. If no style has been defined in the .clang-format file
+  /// for the specific language, a predefined style given by 'BasedOnStyle' is
+  /// used. If 'BasedOnStyle' is not found, the formatting is based on llvm
+  /// style.
   ///
   /// To configure this in the .clang-format file, use:
   /// \code{.yaml}
   ///   RawStringFormats:
-  /// - Delimiter: 'pb'
-  ///   Language:  TextProto
-  ///   BasedOnStyle: llvm
-  /// - Delimiter: 'proto'
-  ///   Language:  TextProto
-  ///   BasedOnStyle: google
+  /// - Language: TextProto
+  /// Delimiters:
+  ///   - 'pb'
+  ///   - 'proto'
+  /// BasedOnStyle: google
+  /// - Language: Cpp
+  /// Delimiters:
+  ///   - 'cc'
+  ///   - 'cpp'
+  /// BasedOnStyle: llvm
   /// \endcode
   std::vector RawStringFormats;
 
Index: cfe/trunk/lib/Format/ContinuationIndenter.cpp
===
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp
@@ -105,14 +105,21 @@
 RawStringFormatStyleManager::RawStringFormatStyleManager(
 const FormatStyle &CodeStyle) {
   for (const auto &RawStringFormat : CodeStyle.RawStringFormats) {
-FormatStyle Style;
-if (!getPredefinedStyle(RawStringFormat.BasedOnStyle,
-RawStringFormat.Language, &Style)) {
-  Style = getLLVMStyle();
-  Style.Language = RawStringFormat.Language;
+for (StringRef Delimiter : RawStringFormat.Delimiters) {
+  llvm::Optional LanguageStyle =
+  CodeStyle.GetLanguageStyle(RawStringFormat.Language);
+  if (!LanguageStyle) {
+FormatStyle PredefinedStyle;
+if (!getPredefinedStyle(RawStringFormat.BasedOnStyle,
+RawStringFormat.Language, &PredefinedStyle)) {
+  PredefinedStyle = getLLVMStyle();
+  PredefinedStyle.Language = RawStringFormat.Language;
+}
+LanguageStyle = PredefinedStyle;
+  }
+  LanguageStyle->ColumnLimit = CodeStyle.ColumnLimit;
+  DelimiterStyle.insert({Delimiter, *LanguageStyle});
 }
-Style.ColumnLimit = CodeStyle.ColumnLimit;
-DelimiterStyle.insert({RawStringFormat.Delimiter, Style});
   }
 }
 
Index: cfe/trunk/lib/Format/Format.cpp
===
--- cfe/trunk/lib/Format/Format.cpp
+++ cfe/trunk/lib/Format/Format.cpp
@@ -455,8 +455,8 @@
 
 template <> struct MappingTraits {
   static void mapping(IO &IO, FormatStyle::RawStringFormat &Format) {
-IO.mapOptional("Delimiter", Format.Delimiter);
 IO.mapOptional("Language", Format.Language);
+IO.mapOptional("Delimiters", Format.Delimiters);
 IO.mapOptional("BasedOnStyle", Format.Based

[PATCH] D42164: [clangd] Don't crash on LSP calls for non-added files

2018-01-17 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 130127.
ilya-biryukov added a comment.

- Do the check in rename before calling into ClangdServer


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42164

Files:
  clangd/ClangdLSPServer.cpp
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  test/clangd/crash-non-added-files.test

Index: test/clangd/crash-non-added-files.test
===
--- /dev/null
+++ test/clangd/crash-non-added-files.test
@@ -0,0 +1,45 @@
+# RUN: clangd -pretty -run-synchronously < %s | FileCheck -strict-whitespace %s
+# It is absolutely vital that this file has CRLF line endings.
+#
+Content-Length: 125
+
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
+#
+Content-Length: 746
+
+{"jsonrpc":"2.0","id":2,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"file:///foo.c"},"range":{"start":{"line":104,"character":13},"end":{"line":0,"character":35}},"context":{"diagnostics":[{"range":{"start": {"line": 0, "character": 32}, "end": {"line": 0, "character": 37}},"severity":2,"message":"using the result of an assignment as a condition without parentheses"},{"range":{"start": {"line": 0, "character": 34}, "end": {"line": 0, "character": 35}},"severity":3,"message":"place parentheses around the assignment to silence this warning"},{"range":{"start": {"line": 0, "character": 34}, "end": {"line": 0, "character": 35}},"severity":3,"message":"use '==' to turn this assignment into an equality comparison"}]}}}
+#  CHECK:  "error": {
+# CHECK-NEXT:"code": -32602
+# CHECK-NEXT:"message": "onCodeAction called for non-added file"
+# CHECK-NEXT:  },
+# CHECK-NEXT:  "id": 2,
+Content-Length: 233
+
+{"jsonrpc":"2.0","id":3,"method":"textDocument/rangeFormatting","params":{"textDocument":{"uri":"file:///foo.c"},"range":{"start":{"line":1,"character":4},"end":{"line":1,"character":12}},"options":{"tabSize":4,"insertSpaces":true}}}
+#  CHECK:  "error": {
+# CHECK-NEXT:"code": -32602
+# CHECK-NEXT:"message": "onDocumentRangeFormatting called for non-added file"
+# CHECK-NEXT:  },
+# CHECK-NEXT:  "id": 3,
+Content-Length: 153
+
+{"jsonrpc":"2.0","id":4,"method":"textDocument/formatting","params":{"textDocument":{"uri":"file:///foo.c"},"options":{"tabSize":4,"insertSpaces":true}}}
+#  CHECK:  "error": {
+# CHECK-NEXT:"code": -32602
+# CHECK-NEXT:"message": "onDocumentFormatting called for non-added file"
+# CHECK-NEXT:  },
+# CHECK-NEXT:  "id": 4,
+Content-Length: 204
+
+{"jsonrpc":"2.0","id":5,"method":"textDocument/onTypeFormatting","params":{"textDocument":{"uri":"file:///foo.c"},"position":{"line":3,"character":1},"ch":"}","options":{"tabSize":4,"insertSpaces":true}}}
+#  CHECK:  "error": {
+# CHECK-NEXT:"code": -32602
+# CHECK-NEXT:"message": "onDocumentOnTypeFormatting called for non-added file"
+# CHECK-NEXT:  },
+# CHECK-NEXT:  "id": 5,
+Content-Length: 44
+
+{"jsonrpc":"2.0","id":6,"method":"shutdown"}
+Content-Length: 33
+
+{"jsonrpc":"2.0","method":"exit"}
Index: clangd/ClangdServer.h
===
--- clangd/ClangdServer.h
+++ clangd/ClangdServer.h
@@ -308,11 +308,11 @@
  PathRef File, Position Pos,
  llvm::StringRef NewName);
 
-  /// Gets current document contents for \p File. \p File must point to a
-  /// currently tracked file.
+  /// Gets current document contents for \p File. Returns None if \p File is not
+  /// currently tracked.
   /// FIXME(ibiryukov): This function is here to allow offset-to-Position
   /// conversions in outside code, maybe there's a way to get rid of it.
-  std::string getDocument(PathRef File);
+  llvm::Optional getDocument(PathRef File);
 
   /// Only for testing purposes.
   /// Waits until all requests to worker thread are finished and dumps AST for
Index: clangd/ClangdServer.cpp
===
--- clangd/ClangdServer.cpp
+++ clangd/ClangdServer.cpp
@@ -356,7 +356,6 @@
 Expected>
 ClangdServer::rename(const Context &Ctx, PathRef File, Position Pos,
  llvm::StringRef NewName) {
-  std::string Code = getDocument(File);
   std::shared_ptr Resources = Units.getFile(File);
   RefactoringResultCollector ResultCollector;
   Resources->getAST().get()->runUnderLock([&](ParsedAST *AST) {
@@ -402,15 +401,17 @@
   return Replacements;
 }
 
-std::string ClangdServer::getDocument(PathRef File) {
-  auto draft = DraftMgr.getDraft(File);
-  assert(draft.Draft && "File is not tracked, cannot get contents");
-  return *draft.Draft;
+llvm::Optional ClangdServer::getDocument(PathRef File) {
+  auto Latest = DraftMgr.getDraft(File);
+  if (!Latest.Draft)
+return llvm::None;
+  return std::move(*Latest.Draft);
 }
 
 std::string ClangdServer::dumpAST(Pa

[PATCH] D42164: [clangd] Don't crash on LSP calls for non-added files

2018-01-17 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 130125.
ilya-biryukov added a comment.

- Renamed crash.test to crash-non-added-files.test


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42164

Files:
  clangd/ClangdLSPServer.cpp
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  test/clangd/crash-non-added-files.test

Index: test/clangd/crash-non-added-files.test
===
--- /dev/null
+++ test/clangd/crash-non-added-files.test
@@ -0,0 +1,45 @@
+# RUN: clangd -pretty -run-synchronously < %s | FileCheck -strict-whitespace %s
+# It is absolutely vital that this file has CRLF line endings.
+#
+Content-Length: 125
+
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
+#
+Content-Length: 746
+
+{"jsonrpc":"2.0","id":2,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"file:///foo.c"},"range":{"start":{"line":104,"character":13},"end":{"line":0,"character":35}},"context":{"diagnostics":[{"range":{"start": {"line": 0, "character": 32}, "end": {"line": 0, "character": 37}},"severity":2,"message":"using the result of an assignment as a condition without parentheses"},{"range":{"start": {"line": 0, "character": 34}, "end": {"line": 0, "character": 35}},"severity":3,"message":"place parentheses around the assignment to silence this warning"},{"range":{"start": {"line": 0, "character": 34}, "end": {"line": 0, "character": 35}},"severity":3,"message":"use '==' to turn this assignment into an equality comparison"}]}}}
+#  CHECK:  "error": {
+# CHECK-NEXT:"code": -32602
+# CHECK-NEXT:"message": "onCodeAction called for non-added file"
+# CHECK-NEXT:  },
+# CHECK-NEXT:  "id": 2,
+Content-Length: 233
+
+{"jsonrpc":"2.0","id":3,"method":"textDocument/rangeFormatting","params":{"textDocument":{"uri":"file:///foo.c"},"range":{"start":{"line":1,"character":4},"end":{"line":1,"character":12}},"options":{"tabSize":4,"insertSpaces":true}}}
+#  CHECK:  "error": {
+# CHECK-NEXT:"code": -32602
+# CHECK-NEXT:"message": "onDocumentRangeFormatting called for non-added file"
+# CHECK-NEXT:  },
+# CHECK-NEXT:  "id": 3,
+Content-Length: 153
+
+{"jsonrpc":"2.0","id":4,"method":"textDocument/formatting","params":{"textDocument":{"uri":"file:///foo.c"},"options":{"tabSize":4,"insertSpaces":true}}}
+#  CHECK:  "error": {
+# CHECK-NEXT:"code": -32602
+# CHECK-NEXT:"message": "onDocumentFormatting called for non-added file"
+# CHECK-NEXT:  },
+# CHECK-NEXT:  "id": 4,
+Content-Length: 204
+
+{"jsonrpc":"2.0","id":5,"method":"textDocument/onTypeFormatting","params":{"textDocument":{"uri":"file:///foo.c"},"position":{"line":3,"character":1},"ch":"}","options":{"tabSize":4,"insertSpaces":true}}}
+#  CHECK:  "error": {
+# CHECK-NEXT:"code": -32602
+# CHECK-NEXT:"message": "onDocumentOnTypeFormatting called for non-added file"
+# CHECK-NEXT:  },
+# CHECK-NEXT:  "id": 5,
+Content-Length: 44
+
+{"jsonrpc":"2.0","id":6,"method":"shutdown"}
+Content-Length: 33
+
+{"jsonrpc":"2.0","method":"exit"}
Index: clangd/ClangdServer.h
===
--- clangd/ClangdServer.h
+++ clangd/ClangdServer.h
@@ -308,11 +308,11 @@
  PathRef File, Position Pos,
  llvm::StringRef NewName);
 
-  /// Gets current document contents for \p File. \p File must point to a
-  /// currently tracked file.
+  /// Gets current document contents for \p File. Returns None if \p File is not
+  /// currently tracked.
   /// FIXME(ibiryukov): This function is here to allow offset-to-Position
   /// conversions in outside code, maybe there's a way to get rid of it.
-  std::string getDocument(PathRef File);
+  llvm::Optional getDocument(PathRef File);
 
   /// Only for testing purposes.
   /// Waits until all requests to worker thread are finished and dumps AST for
Index: clangd/ClangdServer.cpp
===
--- clangd/ClangdServer.cpp
+++ clangd/ClangdServer.cpp
@@ -356,7 +356,6 @@
 Expected>
 ClangdServer::rename(const Context &Ctx, PathRef File, Position Pos,
  llvm::StringRef NewName) {
-  std::string Code = getDocument(File);
   std::shared_ptr Resources = Units.getFile(File);
   RefactoringResultCollector ResultCollector;
   Resources->getAST().get()->runUnderLock([&](ParsedAST *AST) {
@@ -402,15 +401,17 @@
   return Replacements;
 }
 
-std::string ClangdServer::getDocument(PathRef File) {
-  auto draft = DraftMgr.getDraft(File);
-  assert(draft.Draft && "File is not tracked, cannot get contents");
-  return *draft.Draft;
+llvm::Optional ClangdServer::getDocument(PathRef File) {
+  auto Latest = DraftMgr.getDraft(File);
+  if (!Latest.Draft)
+return llvm::None;
+  return std::move(*Latest.Draft);
 }
 
 std::string ClangdServer::dumpAST(PathRef F

[clang-tools-extra] r322637 - [clangd] Don't crash on LSP calls for non-added files

2018-01-17 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Wed Jan 17 04:30:24 2018
New Revision: 322637

URL: http://llvm.org/viewvc/llvm-project?rev=322637&view=rev
Log:
[clangd] Don't crash on LSP calls for non-added files

Summary:
We will return errors for non-added files for now.
Another alternative for clangd would be to read non-added files from
disk and provide useful features anyway.

There are still some cases that fail with assertion (e.g., code
complete). We should address those too, but they require more subtle
changes to the code and therefore out of scope of this patch.

Reviewers: sammccall, ioeric, hokein

Reviewed By: sammccall

Subscribers: klimek, cfe-commits

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

Added:
clang-tools-extra/trunk/test/clangd/crash-non-added-files.test
Modified:
clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/ClangdServer.h

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=322637&r1=322636&r2=322637&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Wed Jan 17 04:30:24 2018
@@ -143,14 +143,19 @@ void ClangdLSPServer::onCommand(Ctx C, E
 
 void ClangdLSPServer::onRename(Ctx C, RenameParams &Params) {
   auto File = Params.textDocument.uri.file;
+  auto Code = Server.getDocument(File);
+  if (!Code)
+return replyError(C, ErrorCode::InvalidParams,
+  "onRename called for non-added file");
+
   auto Replacements = Server.rename(C, File, Params.position, Params.newName);
   if (!Replacements) {
 replyError(C, ErrorCode::InternalError,
llvm::toString(Replacements.takeError()));
 return;
   }
-  std::string Code = Server.getDocument(File);
-  std::vector Edits = replacementsToEdits(Code, *Replacements);
+
+  std::vector Edits = replacementsToEdits(*Code, *Replacements);
   WorkspaceEdit WE;
   WE.changes = {{Params.textDocument.uri.uri, Edits}};
   reply(C, WE);
@@ -164,10 +169,14 @@ void ClangdLSPServer::onDocumentDidClose
 void ClangdLSPServer::onDocumentOnTypeFormatting(
 Ctx C, DocumentOnTypeFormattingParams &Params) {
   auto File = Params.textDocument.uri.file;
-  std::string Code = Server.getDocument(File);
-  auto ReplacementsOrError = Server.formatOnType(Code, File, Params.position);
+  auto Code = Server.getDocument(File);
+  if (!Code)
+return replyError(C, ErrorCode::InvalidParams,
+  "onDocumentOnTypeFormatting called for non-added file");
+
+  auto ReplacementsOrError = Server.formatOnType(*Code, File, Params.position);
   if (ReplacementsOrError)
-reply(C, json::ary(replacementsToEdits(Code, ReplacementsOrError.get(;
+reply(C, json::ary(replacementsToEdits(*Code, ReplacementsOrError.get(;
   else
 replyError(C, ErrorCode::UnknownErrorCode,
llvm::toString(ReplacementsOrError.takeError()));
@@ -176,10 +185,14 @@ void ClangdLSPServer::onDocumentOnTypeFo
 void ClangdLSPServer::onDocumentRangeFormatting(
 Ctx C, DocumentRangeFormattingParams &Params) {
   auto File = Params.textDocument.uri.file;
-  std::string Code = Server.getDocument(File);
-  auto ReplacementsOrError = Server.formatRange(Code, File, Params.range);
+  auto Code = Server.getDocument(File);
+  if (!Code)
+return replyError(C, ErrorCode::InvalidParams,
+  "onDocumentRangeFormatting called for non-added file");
+
+  auto ReplacementsOrError = Server.formatRange(*Code, File, Params.range);
   if (ReplacementsOrError)
-reply(C, json::ary(replacementsToEdits(Code, ReplacementsOrError.get(;
+reply(C, json::ary(replacementsToEdits(*Code, ReplacementsOrError.get(;
   else
 replyError(C, ErrorCode::UnknownErrorCode,
llvm::toString(ReplacementsOrError.takeError()));
@@ -188,10 +201,14 @@ void ClangdLSPServer::onDocumentRangeFor
 void ClangdLSPServer::onDocumentFormatting(Ctx C,
DocumentFormattingParams &Params) {
   auto File = Params.textDocument.uri.file;
-  std::string Code = Server.getDocument(File);
-  auto ReplacementsOrError = Server.formatFile(Code, File);
+  auto Code = Server.getDocument(File);
+  if (!Code)
+return replyError(C, ErrorCode::InvalidParams,
+  "onDocumentFormatting called for non-added file");
+
+  auto ReplacementsOrError = Server.formatFile(*Code, File);
   if (ReplacementsOrError)
-reply(C, json::ary(replacementsToEdits(Code, ReplacementsOrError.get(;
+reply(C, json::ary(replacementsToEdits(*Code, ReplacementsOrError.get(;
   else
 replyError(C, ErrorCode::UnknownErrorCode,
llvm::toString(ReplacementsOrError.takeError()));
@@ -200,7 +217,11 @@ void ClangdLSPServer::o

[PATCH] D42164: [clangd] Don't crash on LSP calls for non-added files

2018-01-17 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clangd/ClangdLSPServer.cpp:153
+
+  auto Code = Server.getDocument(File);
+  if (!Code)

sammccall wrote:
> don't you want to do this before computing replacements?
Makes sense.



Comment at: clangd/ClangdLSPServer.cpp:155
+  if (!Code)
+return replyError(C, ErrorCode::InternalError,
+  "onRename called for non-added file");

sammccall wrote:
> invalidparams
I used `InternalError`, because `rename` should've returned an error for 
non-added file. If we do the check before calling `rename`, `InvalidParams` 
make more sense.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42164



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


[PATCH] D42164: [clangd] Don't crash on LSP calls for non-added files

2018-01-17 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE322637: [clangd] Don't crash on LSP calls for 
non-added files (authored by ibiryukov, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D42164?vs=130127&id=130130#toc

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42164

Files:
  clangd/ClangdLSPServer.cpp
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  test/clangd/crash-non-added-files.test

Index: test/clangd/crash-non-added-files.test
===
--- test/clangd/crash-non-added-files.test
+++ test/clangd/crash-non-added-files.test
@@ -0,0 +1,45 @@
+# RUN: clangd -pretty -run-synchronously < %s | FileCheck -strict-whitespace %s
+# It is absolutely vital that this file has CRLF line endings.
+#
+Content-Length: 125
+
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
+#
+Content-Length: 746
+
+{"jsonrpc":"2.0","id":2,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"file:///foo.c"},"range":{"start":{"line":104,"character":13},"end":{"line":0,"character":35}},"context":{"diagnostics":[{"range":{"start": {"line": 0, "character": 32}, "end": {"line": 0, "character": 37}},"severity":2,"message":"using the result of an assignment as a condition without parentheses"},{"range":{"start": {"line": 0, "character": 34}, "end": {"line": 0, "character": 35}},"severity":3,"message":"place parentheses around the assignment to silence this warning"},{"range":{"start": {"line": 0, "character": 34}, "end": {"line": 0, "character": 35}},"severity":3,"message":"use '==' to turn this assignment into an equality comparison"}]}}}
+#  CHECK:  "error": {
+# CHECK-NEXT:"code": -32602
+# CHECK-NEXT:"message": "onCodeAction called for non-added file"
+# CHECK-NEXT:  },
+# CHECK-NEXT:  "id": 2,
+Content-Length: 233
+
+{"jsonrpc":"2.0","id":3,"method":"textDocument/rangeFormatting","params":{"textDocument":{"uri":"file:///foo.c"},"range":{"start":{"line":1,"character":4},"end":{"line":1,"character":12}},"options":{"tabSize":4,"insertSpaces":true}}}
+#  CHECK:  "error": {
+# CHECK-NEXT:"code": -32602
+# CHECK-NEXT:"message": "onDocumentRangeFormatting called for non-added file"
+# CHECK-NEXT:  },
+# CHECK-NEXT:  "id": 3,
+Content-Length: 153
+
+{"jsonrpc":"2.0","id":4,"method":"textDocument/formatting","params":{"textDocument":{"uri":"file:///foo.c"},"options":{"tabSize":4,"insertSpaces":true}}}
+#  CHECK:  "error": {
+# CHECK-NEXT:"code": -32602
+# CHECK-NEXT:"message": "onDocumentFormatting called for non-added file"
+# CHECK-NEXT:  },
+# CHECK-NEXT:  "id": 4,
+Content-Length: 204
+
+{"jsonrpc":"2.0","id":5,"method":"textDocument/onTypeFormatting","params":{"textDocument":{"uri":"file:///foo.c"},"position":{"line":3,"character":1},"ch":"}","options":{"tabSize":4,"insertSpaces":true}}}
+#  CHECK:  "error": {
+# CHECK-NEXT:"code": -32602
+# CHECK-NEXT:"message": "onDocumentOnTypeFormatting called for non-added file"
+# CHECK-NEXT:  },
+# CHECK-NEXT:  "id": 5,
+Content-Length: 44
+
+{"jsonrpc":"2.0","id":6,"method":"shutdown"}
+Content-Length: 33
+
+{"jsonrpc":"2.0","method":"exit"}
Index: clangd/ClangdServer.h
===
--- clangd/ClangdServer.h
+++ clangd/ClangdServer.h
@@ -308,11 +308,11 @@
  PathRef File, Position Pos,
  llvm::StringRef NewName);
 
-  /// Gets current document contents for \p File. \p File must point to a
-  /// currently tracked file.
+  /// Gets current document contents for \p File. Returns None if \p File is not
+  /// currently tracked.
   /// FIXME(ibiryukov): This function is here to allow offset-to-Position
   /// conversions in outside code, maybe there's a way to get rid of it.
-  std::string getDocument(PathRef File);
+  llvm::Optional getDocument(PathRef File);
 
   /// Only for testing purposes.
   /// Waits until all requests to worker thread are finished and dumps AST for
Index: clangd/ClangdServer.cpp
===
--- clangd/ClangdServer.cpp
+++ clangd/ClangdServer.cpp
@@ -356,7 +356,6 @@
 Expected>
 ClangdServer::rename(const Context &Ctx, PathRef File, Position Pos,
  llvm::StringRef NewName) {
-  std::string Code = getDocument(File);
   std::shared_ptr Resources = Units.getFile(File);
   RefactoringResultCollector ResultCollector;
   Resources->getAST().get()->runUnderLock([&](ParsedAST *AST) {
@@ -402,15 +401,17 @@
   return Replacements;
 }
 
-std::string ClangdServer::getDocument(PathRef File) {
-  auto draft = DraftMgr.getDraft(File);
-  assert(draft.Draft && "File is not tracked, cannot get contents");
-  return *draft.Draft;
+llvm::Optional ClangdServer::getDocument(PathRef File) 

[PATCH] D42143: add ID as a special acronym to objc property declaration check for property names like bundleID.allow using acronyms as suffix.

2018-01-17 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: 
clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp:45
+"FTP;"
+"ID";
 

We also need to update the doc of the check.


Repository:
  rL LLVM

https://reviews.llvm.org/D42143



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


Re: [PATCH] D41837: Add Function multiversion to the release notes.

2018-01-17 Thread Hans Wennborg via cfe-commits
Did this functionality land before the 6.0 branch, that is, should we
copy the release notes to the branch?

Thanks
Hans

On Tue, Jan 9, 2018 at 12:37 AM, Erich Keane via Phabricator
 wrote:
> This revision was automatically updated to reflect the committed changes.
> Closed by commit rC322043: Document attribute target multiversioning. 
> (authored by erichkeane, committed by ).
>
> Changed prior to commit:
>   https://reviews.llvm.org/D41837?vs=128982&id=128995#toc
>
> Repository:
>   rC Clang
>
> https://reviews.llvm.org/D41837
>
> Files:
>   docs/ReleaseNotes.rst
>   include/clang/Basic/AttrDocs.td
>
>
> Index: docs/ReleaseNotes.rst
> ===
> --- docs/ReleaseNotes.rst
> +++ docs/ReleaseNotes.rst
> @@ -80,6 +80,12 @@
>  Attribute Changes in Clang
>  --
>
> +- Clang now supports function multiversioning with attribute 'target' on ELF
> +  based x86/x86-64 environments by using indirect functions. This 
> implementation
> +  has a few minor limitations over the GCC implementation for the sake of AST
> +  sanity, however it is otherwise compatible with existing code using this
> +  feature for GCC. Consult the documentation for the target attribute for 
> more
> +  information.
>  - ...
>
>  Windows Support
> Index: include/clang/Basic/AttrDocs.td
> ===
> --- include/clang/Basic/AttrDocs.td
> +++ include/clang/Basic/AttrDocs.td
> @@ -1474,6 +1474,24 @@
>  Example "subtarget features" from the x86 backend include: "mmx", "sse", 
> "sse4.2",
>  "avx", "xop" and largely correspond to the machine specific options handled 
> by
>  the front end.
> +
> +Additionally, this attribute supports function multiversioning for ELF based
> +x86/x86-64 targets, which can be used to create multiple implementations of 
> the
> +same function that will be resolved at runtime based on the priority of their
> +``target`` attribute strings. A function is considered a multiversioned 
> function
> +if either two declarations of the function have different ``target`` 
> attribute
> +  strings, or if it has a ``target`` attribute string of ``default``.  For
> +  example:
> +
> +  .. code-block:: c++
> +  __attribute__((target("arch=atom")))
> +  void foo() {} // will be called on 'atom' processors.
> +  __attribute__((target("default")))
> +  void foo() {} // will be called on any other processors.
> +
> +All multiversioned functions must contain a ``default`` (fallback)
> +implementation, otherwise usages of the function are considered invalid.
> +Additionally, a function may not become multiversioned after its first use.
>  }];
>  }
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42167: [clang-format] adds enclosing function detection to raw string formatting

2018-01-17 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir created this revision.
Herald added subscribers: cfe-commits, klimek.

This patch adds enclosing function detection to raw string formatting.


Repository:
  rC Clang

https://reviews.llvm.org/D42167

Files:
  docs/ClangFormatStyleOptions.rst
  include/clang/Format/Format.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/ContinuationIndenter.h
  lib/Format/Format.cpp
  unittests/Format/FormatTest.cpp
  unittests/Format/FormatTestRawStrings.cpp

Index: unittests/Format/FormatTestRawStrings.cpp
===
--- unittests/Format/FormatTestRawStrings.cpp
+++ unittests/Format/FormatTestRawStrings.cpp
@@ -65,23 +65,32 @@
   FormatStyle getRawStringPbStyleWithColumns(unsigned ColumnLimit) {
 FormatStyle Style = getLLVMStyle();
 Style.ColumnLimit = ColumnLimit;
-Style.RawStringFormats = {{/*Language=*/FormatStyle::LK_TextProto,
-   /*Delimiters=*/{"pb"},
-   /*BasedOnStyle=*/"google"}};
+Style.RawStringFormats = {
+{/*Language=*/FormatStyle::LK_TextProto,
+ /*Delimiters=*/{"pb"},
+ /*EnclosingFunctions=*/{},
+ /*BasedOnStyle=*/"google"},
+};
 return Style;
   }
 
   FormatStyle getRawStringLLVMCppStyleBasedOn(std::string BasedOnStyle) {
 FormatStyle Style = getLLVMStyle();
-Style.RawStringFormats = {{/*Language=*/FormatStyle::LK_Cpp,
-   /*Delimiters=*/{"cpp"}, BasedOnStyle}};
+Style.RawStringFormats = {
+{/*Language=*/FormatStyle::LK_Cpp,
+ /*Delimiters=*/{"cpp"},
+ /*EnclosingFunctions=*/{}, BasedOnStyle},
+};
 return Style;
   }
 
   FormatStyle getRawStringGoogleCppStyleBasedOn(std::string BasedOnStyle) {
 FormatStyle Style = getGoogleStyle(FormatStyle::LK_Cpp);
-Style.RawStringFormats = {{/*Language=*/FormatStyle::LK_Cpp,
-   /*Delimiters=*/{"cpp"}, BasedOnStyle}};
+Style.RawStringFormats = {
+{/*Language=*/FormatStyle::LK_Cpp,
+ /*Delimiters=*/{"cpp"},
+ /*EnclosingFunctions=*/{}, BasedOnStyle},
+};
 return Style;
   }
 
@@ -122,7 +131,7 @@
   EXPECT_EQ(0, parseConfiguration("---\n"
   "Language: Cpp\n"
   "BasedOnStyle: Google", &Style).value());
-  Style.RawStringFormats = {{FormatStyle::LK_Cpp, {"cpp"}, "llvm"}};
+  Style.RawStringFormats = {{FormatStyle::LK_Cpp, {"cpp"}, {}, "llvm"}};
   expect_eq(R"test(int* i = R"cpp(int* j = 0;)cpp";)test",
 format(R"test(int * i = R"cpp(int * j = 0;)cpp";)test", Style));
 }
@@ -720,6 +729,29 @@
getRawStringPbStyleWithColumns(20)));
 }
 
+TEST_F(FormatTestRawStrings, FormatsRawStringsWithEnclosingFunctionName) {
+  FormatStyle Style = getRawStringPbStyleWithColumns(40);
+  Style.RawStringFormats[0].EnclosingFunctions.push_back(
+  "PARSE_TEXT_PROTO");
+  Style.RawStringFormats[0].EnclosingFunctions.push_back("ParseTextProto");
+  expect_eq(R"test(a = PARSE_TEXT_PROTO(R"(key: value)");)test",
+format(R"test(a = PARSE_TEXT_PROTO(R"(key:value)");)test", Style));
+
+  expect_eq(R"test(
+a = PARSE_TEXT_PROTO /**/ (
+/**/ R"(key: value)");)test",
+format(R"test(
+a = PARSE_TEXT_PROTO/**/(/**/R"(key:value)");)test",
+   Style));
+
+  expect_eq(R"test(
+a = ParseTextProto(
+R"(key: value)");)test",
+format(R"test(
+a = ParseTextProto(R"(key:value)");)test",
+   Style));
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -10408,21 +10408,35 @@
 
   Style.RawStringFormats.clear();
   std::vector ExpectedRawStringFormats = {
-  {FormatStyle::LK_TextProto, {"pb", "proto"}, "llvm"},
-  {FormatStyle::LK_Cpp, {"cc", "cpp"}, "google"},
+  {
+  FormatStyle::LK_TextProto,
+  {"pb", "proto"},
+  {"PARSE_TEXT_PROTO"},
+  "llvm",
+  },
+  {
+  FormatStyle::LK_Cpp,
+  {"cc", "cpp"},
+  {"C_CODEBLOCK", "CPPEVAL"},
+  "",
+  },
   };
 
   CHECK_PARSE("RawStringFormats:\n"
   "  - Language: TextProto\n"
   "Delimiters:\n"
   "  - 'pb'\n"
   "  - 'proto'\n"
+  "EnclosingFunctions:\n"
+  "  - 'PARSE_TEXT_PROTO'\n"
   "BasedOnStyle: llvm\n"
   "  - Language: Cpp\n"
   "Delimiters:\n"
   "  - 'cc'\n"
   "  - 'cpp'\n"
-  "BasedOnStyle: google\n",
+  "EnclosingFunctions:\n"
+  "  - 'C_CODEBLOCK'\n"
+  "  - 'CPPEVAL'\n",
   RawStringFormats, ExpectedRawStringFormats);
 }
 
Index:

Re: r322236 - In C++17, when instantiating an out-of-line definition of an inline static data

2018-01-17 Thread Hans Wennborg via cfe-commits
Merged to 6.0 in r322641.

On Thu, Jan 11, 2018 at 12:08 AM, Richard Smith via cfe-commits
 wrote:
> Author: rsmith
> Date: Wed Jan 10 15:08:26 2018
> New Revision: 322236
>
> URL: http://llvm.org/viewvc/llvm-project?rev=322236&view=rev
> Log:
> In C++17, when instantiating an out-of-line definition of an inline static 
> data
> member, don't forget to instantiate the initializer too.
>
> Modified:
> cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
> cfe/trunk/test/CodeGenCXX/cxx1z-inline-variables.cpp
> cfe/trunk/test/SemaTemplate/cxx17-inline-variables.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=322236&r1=322235&r2=322236&view=diff
> ==
> --- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Wed Jan 10 15:08:26 
> 2018
> @@ -4151,7 +4151,8 @@ void Sema::BuildVariableInstantiation(
>// it right away if the type contains 'auto'.
>if ((!isa(NewVar) &&
> !InstantiatingVarTemplate &&
> -   !(OldVar->isInline() && OldVar->isThisDeclarationADefinition())) ||
> +   !(OldVar->isInline() && OldVar->isThisDeclarationADefinition() &&
> + !NewVar->isThisDeclarationADefinition())) ||
>NewVar->getType()->isUndeducedType())
>  InstantiateVariableInitializer(NewVar, OldVar, TemplateArgs);
>
>
> Modified: cfe/trunk/test/CodeGenCXX/cxx1z-inline-variables.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/cxx1z-inline-variables.cpp?rev=322236&r1=322235&r2=322236&view=diff
> ==
> --- cfe/trunk/test/CodeGenCXX/cxx1z-inline-variables.cpp (original)
> +++ cfe/trunk/test/CodeGenCXX/cxx1z-inline-variables.cpp Wed Jan 10 15:08:26 
> 2018
> @@ -58,14 +58,22 @@ template struct X {
>static int a;
>static inline int b;
>static int c;
> +  static const int d;
> +  static int e;
>  };
>  // CHECK: @_ZN1XIiE1aE = linkonce_odr global i32 10
>  // CHECK: @_ZN1XIiE1bE = global i32 20
>  // CHECK-NOT: @_ZN1XIiE1cE
> +// CHECK: @_ZN1XIiE1dE = linkonce_odr constant i32 40
> +// CHECK: @_ZN1XIiE1eE = linkonce_odr global i32 50
>  template<> inline int X::a = 10;
>  int &use3 = X::a;
>  template<> int X::b = 20;
>  template<> inline int X::c = 30;
> +template constexpr int X::d = 40;
> +template inline int X::e = 50;
> +const int *use_x_int_d = &X::d;
> +const int *use_x_int_e = &X::e;
>
>  template struct Y;
>  template<> struct Y {
>
> Modified: cfe/trunk/test/SemaTemplate/cxx17-inline-variables.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/cxx17-inline-variables.cpp?rev=322236&r1=322235&r2=322236&view=diff
> ==
> --- cfe/trunk/test/SemaTemplate/cxx17-inline-variables.cpp (original)
> +++ cfe/trunk/test/SemaTemplate/cxx17-inline-variables.cpp Wed Jan 10 
> 15:08:26 2018
> @@ -16,3 +16,14 @@ namespace CompleteType {
>
>constexpr int n = X::value;
>  }
> +
> +template  struct A {
> +  static const int n;
> +  static const int m;
> +  constexpr int f() { return n; }
> +  constexpr int g() { return n; }
> +};
> +template  constexpr int A::n = sizeof(A) + sizeof(T);
> +template  inline constexpr int A::m = sizeof(A) + sizeof(T);
> +static_assert(A().f() == 5);
> +static_assert(A().g() == 5);
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42167: [clang-format] adds enclosing function detection to raw string formatting

2018-01-17 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 130142.
krasimir added a comment.

- Update comments


Repository:
  rC Clang

https://reviews.llvm.org/D42167

Files:
  docs/ClangFormatStyleOptions.rst
  include/clang/Format/Format.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/ContinuationIndenter.h
  lib/Format/Format.cpp
  unittests/Format/FormatTest.cpp
  unittests/Format/FormatTestRawStrings.cpp

Index: unittests/Format/FormatTestRawStrings.cpp
===
--- unittests/Format/FormatTestRawStrings.cpp
+++ unittests/Format/FormatTestRawStrings.cpp
@@ -65,23 +65,32 @@
   FormatStyle getRawStringPbStyleWithColumns(unsigned ColumnLimit) {
 FormatStyle Style = getLLVMStyle();
 Style.ColumnLimit = ColumnLimit;
-Style.RawStringFormats = {{/*Language=*/FormatStyle::LK_TextProto,
-   /*Delimiters=*/{"pb"},
-   /*BasedOnStyle=*/"google"}};
+Style.RawStringFormats = {
+{/*Language=*/FormatStyle::LK_TextProto,
+ /*Delimiters=*/{"pb"},
+ /*EnclosingFunctions=*/{},
+ /*BasedOnStyle=*/"google"},
+};
 return Style;
   }
 
   FormatStyle getRawStringLLVMCppStyleBasedOn(std::string BasedOnStyle) {
 FormatStyle Style = getLLVMStyle();
-Style.RawStringFormats = {{/*Language=*/FormatStyle::LK_Cpp,
-   /*Delimiters=*/{"cpp"}, BasedOnStyle}};
+Style.RawStringFormats = {
+{/*Language=*/FormatStyle::LK_Cpp,
+ /*Delimiters=*/{"cpp"},
+ /*EnclosingFunctions=*/{}, BasedOnStyle},
+};
 return Style;
   }
 
   FormatStyle getRawStringGoogleCppStyleBasedOn(std::string BasedOnStyle) {
 FormatStyle Style = getGoogleStyle(FormatStyle::LK_Cpp);
-Style.RawStringFormats = {{/*Language=*/FormatStyle::LK_Cpp,
-   /*Delimiters=*/{"cpp"}, BasedOnStyle}};
+Style.RawStringFormats = {
+{/*Language=*/FormatStyle::LK_Cpp,
+ /*Delimiters=*/{"cpp"},
+ /*EnclosingFunctions=*/{}, BasedOnStyle},
+};
 return Style;
   }
 
@@ -122,7 +131,7 @@
   EXPECT_EQ(0, parseConfiguration("---\n"
   "Language: Cpp\n"
   "BasedOnStyle: Google", &Style).value());
-  Style.RawStringFormats = {{FormatStyle::LK_Cpp, {"cpp"}, "llvm"}};
+  Style.RawStringFormats = {{FormatStyle::LK_Cpp, {"cpp"}, {}, "llvm"}};
   expect_eq(R"test(int* i = R"cpp(int* j = 0;)cpp";)test",
 format(R"test(int * i = R"cpp(int * j = 0;)cpp";)test", Style));
 }
@@ -720,6 +729,29 @@
getRawStringPbStyleWithColumns(20)));
 }
 
+TEST_F(FormatTestRawStrings, FormatsRawStringsWithEnclosingFunctionName) {
+  FormatStyle Style = getRawStringPbStyleWithColumns(40);
+  Style.RawStringFormats[0].EnclosingFunctions.push_back(
+  "PARSE_TEXT_PROTO");
+  Style.RawStringFormats[0].EnclosingFunctions.push_back("ParseTextProto");
+  expect_eq(R"test(a = PARSE_TEXT_PROTO(R"(key: value)");)test",
+format(R"test(a = PARSE_TEXT_PROTO(R"(key:value)");)test", Style));
+
+  expect_eq(R"test(
+a = PARSE_TEXT_PROTO /**/ (
+/**/ R"(key: value)");)test",
+format(R"test(
+a = PARSE_TEXT_PROTO/**/(/**/R"(key:value)");)test",
+   Style));
+
+  expect_eq(R"test(
+a = ParseTextProto(
+R"(key: value)");)test",
+format(R"test(
+a = ParseTextProto(R"(key:value)");)test",
+   Style));
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -10408,21 +10408,35 @@
 
   Style.RawStringFormats.clear();
   std::vector ExpectedRawStringFormats = {
-  {FormatStyle::LK_TextProto, {"pb", "proto"}, "llvm"},
-  {FormatStyle::LK_Cpp, {"cc", "cpp"}, "google"},
+  {
+  FormatStyle::LK_TextProto,
+  {"pb", "proto"},
+  {"PARSE_TEXT_PROTO"},
+  "llvm",
+  },
+  {
+  FormatStyle::LK_Cpp,
+  {"cc", "cpp"},
+  {"C_CODEBLOCK", "CPPEVAL"},
+  "",
+  },
   };
 
   CHECK_PARSE("RawStringFormats:\n"
   "  - Language: TextProto\n"
   "Delimiters:\n"
   "  - 'pb'\n"
   "  - 'proto'\n"
+  "EnclosingFunctions:\n"
+  "  - 'PARSE_TEXT_PROTO'\n"
   "BasedOnStyle: llvm\n"
   "  - Language: Cpp\n"
   "Delimiters:\n"
   "  - 'cc'\n"
   "  - 'cpp'\n"
-  "BasedOnStyle: google\n",
+  "EnclosingFunctions:\n"
+  "  - 'C_CODEBLOCK'\n"
+  "  - 'CPPEVAL'\n",
   RawStringFormats, ExpectedRawStringFormats);
 }
 
Index: lib/Format/Format.cpp

[clang-tools-extra] r322602 - add ID as a special acronym to objc property declaration check for property names like bundleID.allow using acronyms as suffix.

2018-01-17 Thread Yan Zhang via cfe-commits
Author: wizard
Date: Tue Jan 16 16:19:35 2018
New Revision: 322602

URL: http://llvm.org/viewvc/llvm-project?rev=322602&view=rev
Log:
add ID as a special acronym to objc property declaration check for property 
names like bundleID.allow using acronyms as suffix.

Reviewers: benhamilton, hokein

Reviewed By: benhamilton

Subscribers: klimek, cfe-commits

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

Modified:
clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration.m

Modified: clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp?rev=322602&r1=322601&r2=322602&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp Tue 
Jan 16 16:19:35 2018
@@ -41,7 +41,8 @@ constexpr char DefaultSpecialAcronyms[]
 "RGB;"
 "CMYK;"
 "MIDI;"
-"FTP";
+"FTP;"
+"ID";
 
 /// For now we will only fix 'CamelCase' property to
 /// 'camelCase'. For other cases the users need to
@@ -58,13 +59,13 @@ FixItHint generateFixItHint(const ObjCPr
   return FixItHint();
 }
 
-std::string validPropertyNameRegex(const std::vector &Prefixes) {
-  std::vector EscapedPrefixes;
-  EscapedPrefixes.reserve(Prefixes.size());
+std::string validPropertyNameRegex(const std::vector &Acronyms) {
+  std::vector EscapedAcronyms;
+  EscapedAcronyms.reserve(Acronyms.size());
   // In case someone defines a custom prefix which includes a regex
   // special character, escape all the prefixes.
-  std::transform(Prefixes.begin(), Prefixes.end(),
- std::back_inserter(EscapedPrefixes), [](const std::string& s) 
{
+  std::transform(Acronyms.begin(), Acronyms.end(),
+ std::back_inserter(EscapedAcronyms), [](const std::string& s) 
{
return llvm::Regex::escape(s); });
   // Allow any of these names:
   // foo
@@ -73,9 +74,11 @@ std::string validPropertyNameRegex(const
   // urlString
   // URL
   // URLString
+  // bundleID
   return std::string("::((") +
-  llvm::join(EscapedPrefixes.begin(), EscapedPrefixes.end(), "|") +
-  ")[A-Z]?)?[a-z]+[a-z0-9]*([A-Z][a-z0-9]+)*$";
+  llvm::join(EscapedAcronyms.begin(), EscapedAcronyms.end(), "|") +
+  ")[A-Z]?)?[a-z]+[a-z0-9]*([A-Z][a-z0-9]+)*" + "(" +
+  llvm::join(EscapedAcronyms.begin(), EscapedAcronyms.end(), "|") + ")?$";
 }
 }  // namespace
 

Modified: clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration.m
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration.m?rev=322602&r1=322601&r2=322602&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration.m 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration.m Tue Jan 
16 16:19:35 2018
@@ -7,6 +7,7 @@
 // CHECK-FIXES: @property(assign, nonatomic) int notCamelCase;
 @property(assign, nonatomic) int camelCase;
 @property(strong, nonatomic) NSString *URLString;
+@property(strong, nonatomic) NSString *bundleID;
 @property(strong, nonatomic) NSString *URL_string;
 // CHECK-MESSAGES: :[[@LINE-1]]:40: warning: property name 'URL_string' should 
use lowerCamelCase style, according to the Apple Coding Guidelines 
[objc-property-declaration]
 @end


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


Re: [PATCH] D41881: [analyzer] Flag bcmp, bcopy and bzero as obsolete

2018-01-17 Thread Tom via cfe-commits

I do not have commit access.

Can you please commit this for me ?

Tom


On 01/12/2018 05:50 PM, Devin Coughlin via Phabricator wrote:

dcoughlin accepted this revision.
dcoughlin added a comment.
This revision is now accepted and ready to land.

Thanks for adding these! This looks good to me. Do you have commit access, or 
do you need someone to commit this?


Repository:
   rC Clang

https://reviews.llvm.org/D41881







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


[PATCH] D42168: [OpenMP] Generate unique name for offloading entries

2018-01-17 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld created this revision.
Hahnfeld added reviewers: gtbercea, ABataev, carlo.bertolli.
Herald added subscribers: cfe-commits, guansong.

If there are multiple files with target regions, each file and
region must generate a unique name or the linker will complain.


Repository:
  rC Clang

https://reviews.llvm.org/D42168

Files:
  lib/CodeGen/CGOpenMPRuntime.cpp


Index: lib/CodeGen/CGOpenMPRuntime.cpp
===
--- lib/CodeGen/CGOpenMPRuntime.cpp
+++ lib/CodeGen/CGOpenMPRuntime.cpp
@@ -3573,11 +3573,11 @@
   EntryInit.addInt(CGM.SizeTy, Size);
   EntryInit.addInt(CGM.Int32Ty, Flags);
   EntryInit.addInt(CGM.Int32Ty, 0);
-  llvm::GlobalVariable *Entry =
-EntryInit.finishAndCreateGlobal(".omp_offloading.entry",
-Align,
-/*constant*/ true,
-llvm::GlobalValue::ExternalLinkage);
+  SmallString<128> EntryGblName(".omp_offloading.entry.");
+  EntryGblName += Name;
+  llvm::GlobalVariable *Entry = EntryInit.finishAndCreateGlobal(
+  EntryGblName, Align,
+  /*constant*/ true, llvm::GlobalValue::ExternalLinkage);
 
   // The entry has to be created in the section the linker expects it to be.
   Entry->setSection(".omp_offloading.entries");


Index: lib/CodeGen/CGOpenMPRuntime.cpp
===
--- lib/CodeGen/CGOpenMPRuntime.cpp
+++ lib/CodeGen/CGOpenMPRuntime.cpp
@@ -3573,11 +3573,11 @@
   EntryInit.addInt(CGM.SizeTy, Size);
   EntryInit.addInt(CGM.Int32Ty, Flags);
   EntryInit.addInt(CGM.Int32Ty, 0);
-  llvm::GlobalVariable *Entry =
-EntryInit.finishAndCreateGlobal(".omp_offloading.entry",
-Align,
-/*constant*/ true,
-llvm::GlobalValue::ExternalLinkage);
+  SmallString<128> EntryGblName(".omp_offloading.entry.");
+  EntryGblName += Name;
+  llvm::GlobalVariable *Entry = EntryInit.finishAndCreateGlobal(
+  EntryGblName, Align,
+  /*constant*/ true, llvm::GlobalValue::ExternalLinkage);
 
   // The entry has to be created in the section the linker expects it to be.
   Entry->setSection(".omp_offloading.entries");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42157: [clang-cl] Let /FA output use intel assembly.

2018-01-17 Thread Hans Wennborg via Phabricator via cfe-commits
hans accepted this revision.
hans added a comment.
This revision is now accepted and ready to land.

lgtm, thanks for fixing!


https://reviews.llvm.org/D42157



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


[PATCH] D37014: [clang-tidy] Add a checker to remove useless intermediate variables before return statements with comparisons

2018-01-17 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

Thank you for working on this!
Some thoughts below.




Comment at: clang-tidy/readability/CMakeLists.txt:31
   UniqueptrDeleteReleaseCheck.cpp
+  UnnecessaryIntermediateVarCheck.cpp
 

Please upload patches with full context (`-U99`)



Comment at: clang-tidy/utils/LexerUtils.h:26
+/// Get source code text for statement.
+Optional getStmtText(const Stmt* Statement, const SourceManager& 
SM);
+

This should probably be split into new differential, and it should have a 
unit-test.
(And mark that diff as parent of this one)



Comment at: clang-tidy/utils/Matchers.h:54
+// Matches the next statement within the parent statement sequence.
+AST_MATCHER_P(Stmt, hasSuccessor,
+  ast_matchers::internal::Matcher, InnerMatcher) {

This should be split into another new differential, and it should have a 
unit-test.
(And mark that diff as parent of this one)
Also, the docs will need to be updated, which is sadly impossible now, see 
D41455.



Comment at: test/clang-tidy/readability-unnecessary-intermediate-var.cpp:1
+// RUN: %check_clang_tidy %s readability-unnecessary-intermediate-var %t
+

Still no tests for macros, preprocessor definitions.
I do see that it will still do the wrong thing, but i need to see that in the 
tests and release notes.


https://reviews.llvm.org/D37014



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


Re: r322390 - [Lex] Avoid out-of-bounds dereference in LexAngledStringLiteral.

2018-01-17 Thread Hans Wennborg via cfe-commits
Merged in r322649.

(Richard, please shout if you object to the merging; I figured since
you lgtm'ed it, this would be fine.)

On Fri, Jan 12, 2018 at 8:43 PM, Volodymyr Sapsai  wrote:
> Hans, I am nominating this change to be merged into 6.0.0 release branch.
>
> Thanks,
> Volodymyr
>
>> On Jan 12, 2018, at 10:54, Volodymyr Sapsai via cfe-commits 
>>  wrote:
>>
>> Author: vsapsai
>> Date: Fri Jan 12 10:54:35 2018
>> New Revision: 322390
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=322390&view=rev
>> Log:
>> [Lex] Avoid out-of-bounds dereference in LexAngledStringLiteral.
>>
>> Fix makes the loop in LexAngledStringLiteral more like the loops in
>> LexStringLiteral, LexCharConstant. When we skip a character after
>> backslash, we need to check if we reached the end of the file instead of
>> reading the next character unconditionally.
>>
>> Discovered by OSS-Fuzz:
>> https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=3832
>>
>> rdar://problem/35572754
>>
>> Reviewers: arphaman, kcc, rsmith, dexonsmith
>>
>> Reviewed By: rsmith, dexonsmith
>>
>> Subscribers: cfe-commits, rsmith, dexonsmith
>>
>> Differential Revision: https://reviews.llvm.org/D41423
>>
>> Added:
>>cfe/trunk/test/Lexer/null-character-in-literal.c   (with props)
>> Modified:
>>cfe/trunk/lib/Lex/Lexer.cpp
>>cfe/trunk/unittests/Lex/LexerTest.cpp
>>
>> Modified: cfe/trunk/lib/Lex/Lexer.cpp
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Lexer.cpp?rev=322390&r1=322389&r2=322390&view=diff
>> ==
>> --- cfe/trunk/lib/Lex/Lexer.cpp (original)
>> +++ cfe/trunk/lib/Lex/Lexer.cpp Fri Jan 12 10:54:35 2018
>> @@ -2009,18 +2009,21 @@ bool Lexer::LexAngledStringLiteral(Token
>>   const char *AfterLessPos = CurPtr;
>>   char C = getAndAdvanceChar(CurPtr, Result);
>>   while (C != '>') {
>> -// Skip escaped characters.
>> -if (C == '\\' && CurPtr < BufferEnd) {
>> -  // Skip the escaped character.
>> -  getAndAdvanceChar(CurPtr, Result);
>> -} else if (C == '\n' || C == '\r' || // Newline.
>> -   (C == 0 && (CurPtr-1 == BufferEnd ||  // End of file.
>> -   isCodeCompletionPoint(CurPtr-1 {
>> +// Skip escaped characters.  Escaped newlines will already be processed 
>> by
>> +// getAndAdvanceChar.
>> +if (C == '\\')
>> +  C = getAndAdvanceChar(CurPtr, Result);
>> +
>> +if (C == '\n' || C == '\r' || // Newline.
>> +(C == 0 && (CurPtr-1 == BufferEnd ||  // End of file.
>> +isCodeCompletionPoint(CurPtr-1 {
>>   // If the filename is unterminated, then it must just be a lone <
>>   // character.  Return this as such.
>>   FormTokenWithChars(Result, AfterLessPos, tok::less);
>>   return true;
>> -} else if (C == 0) {
>> +}
>> +
>> +if (C == 0) {
>>   NulCharacter = CurPtr-1;
>> }
>> C = getAndAdvanceChar(CurPtr, Result);
>>
>> Added: cfe/trunk/test/Lexer/null-character-in-literal.c
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/null-character-in-literal.c?rev=322390&view=auto
>> ==
>> Binary file - no diff available.
>>
>> Propchange: cfe/trunk/test/Lexer/null-character-in-literal.c
>> --
>>svn:mime-type = application/octet-stream
>>
>> Modified: cfe/trunk/unittests/Lex/LexerTest.cpp
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Lex/LexerTest.cpp?rev=322390&r1=322389&r2=322390&view=diff
>> ==
>> --- cfe/trunk/unittests/Lex/LexerTest.cpp (original)
>> +++ cfe/trunk/unittests/Lex/LexerTest.cpp Fri Jan 12 10:54:35 2018
>> @@ -475,6 +475,8 @@ TEST_F(LexerTest, GetBeginningOfTokenWit
>>
>> TEST_F(LexerTest, AvoidPastEndOfStringDereference) {
>>   EXPECT_TRUE(Lex("  //  \\\n").empty());
>> +  EXPECT_TRUE(Lex("#include <").empty());
>> +  EXPECT_TRUE(Lex("#include <\n").empty());
>> }
>>
>> TEST_F(LexerTest, StringizingRasString) {
>>
>>
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D32747: [Analyzer] Iterator Checker - Part 3: Invalidation check, first for (copy) assignments

2018-01-17 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 130149.
baloghadamsoftware added a comment.

Updated according to the comments.


https://reviews.llvm.org/D32747

Files:
  include/clang/StaticAnalyzer/Checkers/Checkers.td
  lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
  test/Analysis/Inputs/system-header-simulator-cxx.h
  test/Analysis/diagnostics/explicit-suppression.cpp
  test/Analysis/invalidated-iterator.cpp

Index: test/Analysis/invalidated-iterator.cpp
===
--- /dev/null
+++ test/Analysis/invalidated-iterator.cpp
@@ -0,0 +1,32 @@
+// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,cplusplus,alpha.cplusplus.InvalidatedIterator -analyzer-eagerly-assume -analyzer-config aggressive-relational-comparison-simplification=true -analyzer-config c++-container-inlining=false %s -verify
+// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,cplusplus,alpha.cplusplus.InvalidatedIterator -analyzer-eagerly-assume -analyzer-config aggressive-relational-comparison-simplification=true -analyzer-config c++-container-inlining=true -DINLINE=1 %s -verify
+
+#include "Inputs/system-header-simulator-cxx.h"
+
+void bad_copy_assign_operator_list1(std::list &L1,
+const std::list &L2) {
+  auto i0 = L1.cbegin();
+  L1 = L2;
+  *i0; // expected-warning{{Invalidated iterator accessed}}
+}
+
+void bad_copy_assign_operator_vector1(std::vector &V1,
+  const std::vector &V2) {
+  auto i0 = V1.cbegin();
+  V1 = V2;
+  *i0; // expected-warning{{Invalidated iterator accessed}}
+}
+
+void bad_copy_assign_operator_deque1(std::deque &D1,
+ const std::deque &D2) {
+  auto i0 = D1.cbegin();
+  D1 = D2;
+  *i0; // expected-warning{{Invalidated iterator accessed}}
+}
+
+void bad_copy_assign_operator_forward_list1(std::forward_list &FL1,
+const std::forward_list &FL2) {
+  auto i0 = FL1.cbegin();
+  FL1 = FL2;
+  *i0; // expected-warning{{Invalidated iterator accessed}}
+}
Index: test/Analysis/diagnostics/explicit-suppression.cpp
===
--- test/Analysis/diagnostics/explicit-suppression.cpp
+++ test/Analysis/diagnostics/explicit-suppression.cpp
@@ -19,6 +19,6 @@
 void testCopyNull(C *I, C *E) {
   std::copy(I, E, (C *)0);
 #ifndef SUPPRESSED
-  // expected-warning@../Inputs/system-header-simulator-cxx.h:514 {{Called C++ object pointer is null}}
+  // expected-warning@../Inputs/system-header-simulator-cxx.h:554 {{Called C++ object pointer is null}}
 #endif
 }
Index: test/Analysis/Inputs/system-header-simulator-cxx.h
===
--- test/Analysis/Inputs/system-header-simulator-cxx.h
+++ test/Analysis/Inputs/system-header-simulator-cxx.h
@@ -252,6 +252,15 @@
   return size_t(_finish - _start);
 }
 
+vector& operator=(const vector &other);
+vector& operator=(vector &&other);
+vector& operator=(std::initializer_list ilist);
+
+void assign(size_type count, const T &value);
+template 
+void assign(InputIterator first, InputIterator last);
+void assign(std::initializer_list ilist);
+
 void clear();
 
 void push_back(const T &value);
@@ -301,8 +310,21 @@
 list& operator=(list &&other);
 list& operator=(std::initializer_list ilist);
 
+void assign(size_type count, const T &value);
+template 
+void assign(InputIterator first, InputIterator last);
+void assign(std::initializer_list ilist);
+
 void clear();
 
+void push_back(const T &value);
+void push_back(T &&value);
+void pop_back();
+
+void push_front(const T &value);
+void push_front(T &&value);
+void pop_front();
+
 iterator begin() { return iterator(_start); }
 const_iterator begin() const { return const_iterator(_start); }
 const_iterator cbegin() const { return const_iterator(_start); }
@@ -338,6 +360,15 @@
   return size_t(_finish - _start);
 }
 
+deque& operator=(const deque &other);
+deque& operator=(deque &&other);
+deque& operator=(std::initializer_list ilist);
+
+void assign(size_type count, const T &value);
+template 
+void assign(InputIterator first, InputIterator last);
+void assign(std::initializer_list ilist);
+
 void clear();
 
 void push_back(const T &value);
@@ -351,11 +382,11 @@
 T &operator[](size_t n) {
   return _start[n];
 }
-
+
 const T &operator[](size_t n) const {
   return _start[n];
 }
-
+
 iterator begin() { return iterator(_start); }
 const_iterator begin() const { return const_iterator(_start); }
 const_iterator cbegin() const { return const_iterator(_start); }
@@ -367,7 +398,7 @@
 T& back() { return *(end() - 1); }
 const T& back() const { return *(end() - 1); }
   };
-  
+
   template
   class forward_list {
 struct

[PATCH] D42157: [clang-cl] Let /FA output use intel assembly.

2018-01-17 Thread Nico Weber via Phabricator via cfe-commits
thakis closed this revision.
thakis added a comment.

r322652, thanks!


https://reviews.llvm.org/D42157



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


r322652 - [clang-cl] Let /FA output use intel assembly.

2018-01-17 Thread Nico Weber via cfe-commits
Author: nico
Date: Wed Jan 17 05:34:20 2018
New Revision: 322652

URL: http://llvm.org/viewvc/llvm-project?rev=322652&view=rev
Log:
[clang-cl] Let /FA output use intel assembly.

cl's assembly output is in intel syntax, so clang-cl's should be too, PR35031.
https://reviews.llvm.org/D42157

Modified:
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/test/Driver/masm.c

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=322652&r1=322651&r2=322652&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Wed Jan 17 05:34:20 2018
@@ -1761,6 +1761,9 @@ void Clang::AddX86TargetArgs(const ArgLi
   
getToolChain().getDriver().Diag(diag::err_drv_unsupported_option_argument)
   << A->getOption().getName() << Value;
 }
+  } else if (getToolChain().getDriver().IsCLMode()) {
+CmdArgs.push_back("-mllvm");
+CmdArgs.push_back("-x86-asm-syntax=intel");
   }
 
   // Set flags to support MCU ABI.

Modified: cfe/trunk/test/Driver/masm.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/masm.c?rev=322652&r1=322651&r2=322652&view=diff
==
--- cfe/trunk/test/Driver/masm.c (original)
+++ cfe/trunk/test/Driver/masm.c Wed Jan 17 05:34:20 2018
@@ -2,11 +2,13 @@
 // RUN: %clang -target i386-unknown-linux -masm=att -S %s -### 2>&1 | 
FileCheck --check-prefix=CHECK-ATT %s
 // RUN: %clang -target i386-unknown-linux -S -masm=somerequired %s -### 2>&1 | 
FileCheck --check-prefix=CHECK-SOMEREQUIRED %s
 // RUN: %clang -target arm-unknown-eabi -S -masm=intel %s -### 2>&1 | 
FileCheck --check-prefix=CHECK-ARM %s
+// RUN: %clang_cl /FA -### -- %s 2>&1 | FileCheck --check-prefix=CHECK-CL %s
 
 int f() {
 // CHECK-INTEL: -x86-asm-syntax=intel
 // CHECK-ATT: -x86-asm-syntax=att
 // CHECK-SOMEREQUIRED: error: unsupported argument 'somerequired' to option 
'masm='
 // CHECK-ARM: warning: argument unused during compilation: '-masm=intel'
+// CHECK-CL: -x86-asm-syntax=intel
   return 0;
 }


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


[PATCH] D42071: [Sema] Add visited contexts to CodeCompleteContext

2018-01-17 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov accepted this revision.
ilya-biryukov added a comment.
This revision is now accepted and ready to land.

LGTM.
Look at the comments for a few NITs.




Comment at: include/clang/Sema/CodeCompleteConsumer.h:271
 
+  using VisitedContextSet = llvm::SmallPtrSet;
+

Given that lookup does not visit the same `DeclContext` twice, we're probably 
fine with vector here, rather than the set.
On the other hand, using set gives a better understanding that the order of 
items is not specified.
I don't think we should necessarily changes the code here, just something to 
think about.




Comment at: include/clang/Sema/CodeCompleteConsumer.h:290
 
+  /// \breif The declaration contexts Sema has already visited during code
+  /// completion.

s/breif/brief



Comment at: include/clang/Sema/CodeCompleteConsumer.h:290
 
+  /// \breif The declaration contexts Sema has already visited during code
+  /// completion.

ilya-biryukov wrote:
> s/breif/brief
I'd mention lookup explicitly in the comment, e.g.
```
/// \brief A set of decl contexts visited when doing lookup for code completion.
```



Comment at: unittests/Sema/CodeCompleteTest.cpp:53
+for (const auto *Context : VisitedContexts)
+  if (const auto *NS = llvm::dyn_cast(Context))
+NSNames.push_back(NS->getQualifiedNameAsString());

Why onyl namespaces and not all `DeclContext`s?



Comment at: unittests/Sema/CodeCompleteTest.cpp:70
+  bool BeginInvocation(CompilerInstance &CI) override {
+auto& opts = CI.getFrontendOpts();
+opts.CodeCompletionAt = CompletePosition;

NIT: local var starts with a lower-case letter.


Repository:
  rC Clang

https://reviews.llvm.org/D42071



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


[PATCH] D42170: Fixit for 'typedef' instead of 'typename' typo

2018-01-17 Thread Jan Korous via Phabricator via cfe-commits
jkorous-apple created this revision.

https://reviews.llvm.org/D42170

Files:
  Parse/ParseTemplate.cpp
  Parser/typedef-instead-of-typename-typo.hpp
  clang/Basic/DiagnosticParseKinds.td


Index: Parser/typedef-instead-of-typename-typo.hpp
===
--- /dev/null
+++ Parser/typedef-instead-of-typename-typo.hpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits -verify %s
+
+template  struct Foo {
+  a
+}; // CHECK: expected-error{{expected template parameter}} \
+// CHECK: expected-note{{Did you mean to use 'typename'?}} \
+// CHECK: fix-it:{{.*}}:{4:23-4:30}:"typename" \
+// Check that we are speculatively (with fixit applied) trying to parse the 
rest. \
+// CHECK: expected-error{{unknown type name 'a'}} \
+// CHECK: expected-error{{expected member name or ';' after declaration 
specifiers}}
Index: Parse/ParseTemplate.cpp
===
--- Parse/ParseTemplate.cpp
+++ Parse/ParseTemplate.cpp
@@ -488,6 +488,20 @@
   if (Tok.is(tok::kw_template))
 return ParseTemplateTemplateParameter(Depth, Position);
 
+  // Is there just a typo in the input code? ('typedef' instead of 'typename')
+  if (Tok.is(tok::kw_typedef)) {
+Diag(Tok.getLocation(), diag::err_expected_template_parameter);
+
+Diag(Tok.getLocation(), diag::note_meant_to_use_typename)
+<< FixItHint::CreateReplacement(CharSourceRange::getCharRange(
+Tok.getLocation(), 
Tok.getEndLoc()),
+"typename");
+
+Tok.setKind(tok::kw_typename);
+
+return ParseTypeParameter(Depth, Position);
+  }
+
   // If it's none of the above, then it must be a parameter declaration.
   // NOTE: This will pick up errors in the closure of the template parameter
   // list (e.g., template < ; Check here to implement >> style closures.
Index: clang/Basic/DiagnosticParseKinds.td
===
--- clang/Basic/DiagnosticParseKinds.td
+++ clang/Basic/DiagnosticParseKinds.td
@@ -1162,6 +1162,9 @@
 
 def err_objc_type_args_after_protocols : Error<
   "protocol qualifiers must precede type arguments">;
+
+def note_meant_to_use_typename : Note<
+  "Did you mean to use 'typename'?">;
 }
 
 let CategoryName = "Coroutines Issue" in {


Index: Parser/typedef-instead-of-typename-typo.hpp
===
--- /dev/null
+++ Parser/typedef-instead-of-typename-typo.hpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits -verify %s
+
+template  struct Foo {
+  a
+}; // CHECK: expected-error{{expected template parameter}} \
+// CHECK: expected-note{{Did you mean to use 'typename'?}} \
+// CHECK: fix-it:{{.*}}:{4:23-4:30}:"typename" \
+// Check that we are speculatively (with fixit applied) trying to parse the rest. \
+// CHECK: expected-error{{unknown type name 'a'}} \
+// CHECK: expected-error{{expected member name or ';' after declaration specifiers}}
Index: Parse/ParseTemplate.cpp
===
--- Parse/ParseTemplate.cpp
+++ Parse/ParseTemplate.cpp
@@ -488,6 +488,20 @@
   if (Tok.is(tok::kw_template))
 return ParseTemplateTemplateParameter(Depth, Position);
 
+  // Is there just a typo in the input code? ('typedef' instead of 'typename')
+  if (Tok.is(tok::kw_typedef)) {
+Diag(Tok.getLocation(), diag::err_expected_template_parameter);
+
+Diag(Tok.getLocation(), diag::note_meant_to_use_typename)
+<< FixItHint::CreateReplacement(CharSourceRange::getCharRange(
+Tok.getLocation(), Tok.getEndLoc()),
+"typename");
+
+Tok.setKind(tok::kw_typename);
+
+return ParseTypeParameter(Depth, Position);
+  }
+
   // If it's none of the above, then it must be a parameter declaration.
   // NOTE: This will pick up errors in the closure of the template parameter
   // list (e.g., template < ; Check here to implement >> style closures.
Index: clang/Basic/DiagnosticParseKinds.td
===
--- clang/Basic/DiagnosticParseKinds.td
+++ clang/Basic/DiagnosticParseKinds.td
@@ -1162,6 +1162,9 @@
 
 def err_objc_type_args_after_protocols : Error<
   "protocol qualifiers must precede type arguments">;
+
+def note_meant_to_use_typename : Note<
+  "Did you mean to use 'typename'?">;
 }
 
 let CategoryName = "Coroutines Issue" in {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D41271: [RISCV] Propagate -mabi and -march values to GNU assembler.

2018-01-17 Thread Alex Bradbury via Phabricator via cfe-commits
asb added a comment.

In https://reviews.llvm.org/D41271#977222, @apazos wrote:

> I tested this on windows and I had to add an assembler placeholder 
> executable, just like it was done with the linker in the RISCV multilib dir 
> checked under Inputs. 
>  Other observations, are these known issues?
>
> - multilib dir checked in has only riscv64-unknown-linux-gnu which we see the 
> riscv tests invoking even when the target is 32 bit.
> - riscv64 is not honoring gcc-toolchain flag, it keeps invoking default 
> /usr/bin/as. Anyways, the test now passes on windows.


For the first issue: I've matched the multilib toolchain generated from the 
riscv-gnu-toolchain build scripts, which uses the riscv64-* triple prefix 
throughout (see https://github.com/riscv/riscv-gnu-toolchain/issues/296).
For the second: driver support for riscv64 hasn't been added, as we don't yet 
have codegen support upstream. Codegen support doesn't really block 
driver+tests of course, so we can add riscv64 if it's useful to you.


https://reviews.llvm.org/D41271



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


[PATCH] D42071: [Sema] Add visited contexts to CodeCompleteContext

2018-01-17 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 130155.
hokein marked 5 inline comments as done.
hokein retitled this revision from " [Sema] Add visited contexts to 
CodeCompleteContext" to "[Sema] Add visited contexts to CodeCompleteContext".
hokein edited the summary of this revision.
hokein added a comment.

Address review comments.


Repository:
  rC Clang

https://reviews.llvm.org/D42071

Files:
  include/clang/Sema/CodeCompleteConsumer.h
  include/clang/Sema/Lookup.h
  lib/Sema/SemaCodeComplete.cpp
  lib/Sema/SemaLookup.cpp
  unittests/Sema/CMakeLists.txt
  unittests/Sema/CodeCompleteTest.cpp

Index: unittests/Sema/CodeCompleteTest.cpp
===
--- /dev/null
+++ unittests/Sema/CodeCompleteTest.cpp
@@ -0,0 +1,134 @@
+//=== unittests/Sema/CodeCompleteTest.cpp - Code Complete tests ==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Parse/ParseAST.h"
+#include "clang/Sema/Sema.h"
+#include "clang/Sema/SemaDiagnostic.h"
+#include "clang/Tooling/Tooling.h"
+#include "gtest/gtest.h"
+#include "gmock/gmock.h"
+
+namespace {
+
+using namespace clang;
+using namespace clang::tooling;
+using ::testing::UnorderedElementsAre;
+
+const char TestCCName[] = "test.cc";
+using VisitedContextResults = std::vector;
+
+class VisitedContextFinder: public CodeCompleteConsumer {
+public:
+  VisitedContextFinder(VisitedContextResults &Results)
+  : CodeCompleteConsumer(/*CodeCompleteOpts=*/{},
+ /*CodeCompleteConsumer*/ false),
+VCResults(Results),
+CCTUInfo(std::make_shared()) {}
+
+  void ProcessCodeCompleteResults(Sema &S, CodeCompletionContext Context,
+  CodeCompletionResult *Results,
+  unsigned NumResults) override {
+VisitedContexts = Context.getVisitedContexts();
+VCResults = getVisitedNamespace();
+  }
+
+  CodeCompletionAllocator &getAllocator() override {
+return CCTUInfo.getAllocator();
+  }
+
+  CodeCompletionTUInfo &getCodeCompletionTUInfo() override { return CCTUInfo; }
+
+  std::vector getVisitedNamespace() const {
+std::vector NSNames;
+for (const auto *Context : VisitedContexts)
+  if (const auto *NS = llvm::dyn_cast(Context))
+NSNames.push_back(NS->getQualifiedNameAsString());
+return NSNames;
+  }
+
+private:
+  VisitedContextResults& VCResults;
+  CodeCompletionTUInfo CCTUInfo;
+  CodeCompletionContext::VisitedContextSet VisitedContexts;
+};
+
+class CodeCompleteAction : public SyntaxOnlyAction {
+public:
+  CodeCompleteAction(ParsedSourceLocation P, VisitedContextResults &Results)
+  : CompletePosition(std::move(P)), VCResults(Results) {}
+
+  bool BeginInvocation(CompilerInstance &CI) override {
+CI.getFrontendOpts().CodeCompletionAt = CompletePosition;
+CI.setCodeCompletionConsumer(new VisitedContextFinder(VCResults));
+return true;
+  }
+
+private:
+  // 1-based code complete position ;
+  ParsedSourceLocation CompletePosition;
+  VisitedContextResults& VCResults;
+};
+
+ParsedSourceLocation offsetToPosition(llvm::StringRef Code, size_t Offset) {
+  Offset = std::min(Code.size(), Offset);
+  StringRef Before = Code.substr(0, Offset);
+  int Lines = Before.count('\n');
+  size_t PrevNL = Before.rfind('\n');
+  size_t StartOfLine = (PrevNL == StringRef::npos) ? 0 : (PrevNL + 1);
+  return {TestCCName, static_cast(Lines + 1),
+  static_cast(Offset - StartOfLine + 1)};
+}
+
+VisitedContextResults runCodeCompleteOnCode(StringRef Code) {
+  VisitedContextResults Results;
+  auto TokenOffset = Code.find('^');
+  assert(TokenOffset != StringRef::npos &&
+ "Completion token ^ wasn't found in Code.");
+  std::string WithoutToken = Code.take_front(TokenOffset);
+  WithoutToken += Code.drop_front(WithoutToken.size() + 1);
+  assert(StringRef(WithoutToken).find('^') == StringRef::npos &&
+ "expected exactly one completion token ^ inside the code");
+
+  auto Action = llvm::make_unique(
+  offsetToPosition(WithoutToken, TokenOffset), Results);
+  clang::tooling::runToolOnCodeWithArgs(Action.release(), Code, {"-std=c++11"},
+TestCCName);
+  return Results;
+}
+
+TEST(SemaCodeCompleteTest, VisitedNSForValidQualifiedId) {
+  auto VisitedNS = runCodeCompleteOnCode(R"cpp(
+ namespace ns1 {}
+ namespace ns2 {}
+ namespace ns3 {}
+ namespace ns3 { namespace nns3 {} }
+
+ namespace foo {
+ using namespace ns1;
+ namespace ns4 {} // not visited
+ namespace { using namespace ns2; }
+ inline namespace bar { using namespace ns3::nns3; }
+

[PATCH] D42071: [Sema] Add visited contexts to CodeCompleteContext

2018-01-17 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: include/clang/Sema/CodeCompleteConsumer.h:271
 
+  using VisitedContextSet = llvm::SmallPtrSet;
+

ilya-biryukov wrote:
> Given that lookup does not visit the same `DeclContext` twice, we're probably 
> fine with vector here, rather than the set.
> On the other hand, using set gives a better understanding that the order of 
> items is not specified.
> I don't think we should necessarily changes the code here, just something to 
> think about.
> 
Good point. Yeah, technically, there should be no duplicated DeclContext.



Comment at: include/clang/Sema/Lookup.h:791
+  /// \param Ctx the context which Sema begins to visit.
+  virtual void BeginVisitContext(DeclContext *Ctx) {};
 };

bkramer wrote:
> ilya-biryukov wrote:
> > Maybe rename it to `VisitedContext` ? Seems more in-line with `FoundDecl`.
> > `BeginVisitContext` also suggest there should be `EndVisitContext`
> Semicolon is not needed here.
Renamed it to `EnteredContext` based on offline discussion.



Comment at: unittests/Sema/CodeCompleteTest.cpp:53
+for (const auto *Context : VisitedContexts)
+  if (const auto *NS = llvm::dyn_cast(Context))
+NSNames.push_back(NS->getQualifiedNameAsString());

ilya-biryukov wrote:
> Why onyl namespaces and not all `DeclContext`s?
Yeah, this is intended (the method name has indicated it), we only verify the 
results for namespaces in the test (for simplicity).


Repository:
  rC Clang

https://reviews.llvm.org/D42071



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


[PATCH] D41708: [clang-tidy] Update fuchsia-overloaded-operator to check for valid loc

2018-01-17 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

In https://reviews.llvm.org/D41708#978186, @alexfh wrote:

> In https://reviews.llvm.org/D41708#977000, @hans wrote:
>
> > Alex, do you think the fix is still OK for the 6.0 branch? Let me know, and 
> > I'll merge it.
>
>
> Yes, please. Thank you!


Oh, it was already merged in r321800. Sorry for the noise.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41708



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


[PATCH] D42173: [clangd] Simplify code handling compile commands

2018-01-17 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov created this revision.
ilya-biryukov added reviewers: sammccall, bkramer.
Herald added a subscriber: klimek.

CppFile can now change compilation arguments during rebuild. This allows
simplifying code that manages CppFiles.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42173

Files:
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/ClangdUnit.cpp
  clangd/ClangdUnit.h
  clangd/ClangdUnitStore.cpp
  clangd/ClangdUnitStore.h

Index: clangd/ClangdUnitStore.h
===
--- clangd/ClangdUnitStore.h
+++ clangd/ClangdUnitStore.h
@@ -32,42 +32,19 @@
 
   std::shared_ptr
   getOrCreateFile(PathRef File, PathRef ResourceDir,
-  GlobalCompilationDatabase &CDB, bool StorePreamblesInMemory,
+  bool StorePreamblesInMemory,
   std::shared_ptr PCHs) {
 std::lock_guard Lock(Mutex);
-
 auto It = OpenedFiles.find(File);
 if (It == OpenedFiles.end()) {
-  auto Command = getCompileCommand(CDB, File, ResourceDir);
-
   It = OpenedFiles
-   .try_emplace(File, CppFile::Create(File, std::move(Command),
-  StorePreamblesInMemory,
+   .try_emplace(File, CppFile::Create(File, StorePreamblesInMemory,
   std::move(PCHs), ASTCallback))
.first;
 }
 return It->second;
   }
 
-  struct RecreateResult {
-/// A CppFile, stored in this CppFileCollection for the corresponding
-/// filepath after calling recreateFileIfCompileCommandChanged.
-std::shared_ptr FileInCollection;
-/// If a new CppFile had to be created to account for changed
-/// CompileCommand, a previous CppFile instance will be returned in this
-/// field.
-std::shared_ptr RemovedFile;
-  };
-
-  /// Similar to getOrCreateFile, but will replace a current CppFile for \p File
-  /// with a new one if CompileCommand, provided by \p CDB has changed.
-  /// If a currently stored CppFile had to be replaced, the previous instance
-  /// will be returned in RecreateResult.RemovedFile.
-  RecreateResult recreateFileIfCompileCommandChanged(
-  PathRef File, PathRef ResourceDir, GlobalCompilationDatabase &CDB,
-  bool StorePreamblesInMemory,
-  std::shared_ptr PCHs);
-
   std::shared_ptr getFile(PathRef File) {
 std::lock_guard Lock(Mutex);
 
@@ -82,12 +59,6 @@
   std::shared_ptr removeIfPresent(PathRef File);
 
 private:
-  tooling::CompileCommand getCompileCommand(GlobalCompilationDatabase &CDB,
-PathRef File, PathRef ResourceDir);
-
-  bool compileCommandsAreEqual(tooling::CompileCommand const &LHS,
-   tooling::CompileCommand const &RHS);
-
   std::mutex Mutex;
   llvm::StringMap> OpenedFiles;
   ASTParsedCallback ASTCallback;
Index: clangd/ClangdUnitStore.cpp
===
--- clangd/ClangdUnitStore.cpp
+++ clangd/ClangdUnitStore.cpp
@@ -25,53 +25,3 @@
   OpenedFiles.erase(It);
   return Result;
 }
-
-CppFileCollection::RecreateResult
-CppFileCollection::recreateFileIfCompileCommandChanged(
-PathRef File, PathRef ResourceDir, GlobalCompilationDatabase &CDB,
-bool StorePreamblesInMemory, std::shared_ptr PCHs) {
-  auto NewCommand = getCompileCommand(CDB, File, ResourceDir);
-
-  std::lock_guard Lock(Mutex);
-
-  RecreateResult Result;
-
-  auto It = OpenedFiles.find(File);
-  if (It == OpenedFiles.end()) {
-It = OpenedFiles
- .try_emplace(File, CppFile::Create(File, std::move(NewCommand),
-StorePreamblesInMemory,
-std::move(PCHs), ASTCallback))
- .first;
-  } else if (!compileCommandsAreEqual(It->second->getCompileCommand(),
-  NewCommand)) {
-Result.RemovedFile = std::move(It->second);
-It->second =
-CppFile::Create(File, std::move(NewCommand), StorePreamblesInMemory,
-std::move(PCHs), ASTCallback);
-  }
-  Result.FileInCollection = It->second;
-  return Result;
-}
-
-tooling::CompileCommand
-CppFileCollection::getCompileCommand(GlobalCompilationDatabase &CDB,
- PathRef File, PathRef ResourceDir) {
-  llvm::Optional C = CDB.getCompileCommand(File);
-  if (!C) // FIXME: Suppress diagnostics? Let the user know?
-C = CDB.getFallbackCommand(File);
-
-  // Inject the resource dir.
-  // FIXME: Don't overwrite it if it's already there.
-  C->CommandLine.push_back("-resource-dir=" + ResourceDir.str());
-  return std::move(*C);
-}
-
-bool CppFileCollection::compileCommandsAreEqual(
-tooling::CompileCommand const &LHS, tooling::CompileCommand const &RHS) {
-  // tooling::CompileCommand.Output is ignored, it's not relevant for clangd.
-  return LHS.Directory == RHS.Directory 

[PATCH] D42174: [clangd] Refactored threading in ClangdServer

2018-01-17 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov created this revision.
ilya-biryukov added reviewers: sammccall, bkramer.
Herald added a subscriber: klimek.

We now provide an abstraction of Scheduler that abstracts threading
and resource management in ClangdServer.
No changes to behavior are intended with an exception of changed error
messages.
This patch is preliminary work to allow a revamped threading
implementation that will move the threading code out of CppFile.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42174

Files:
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/ClangdUnit.h
  clangd/ClangdUnitStore.h

Index: clangd/ClangdUnitStore.h
===
--- clangd/ClangdUnitStore.h
+++ clangd/ClangdUnitStore.h
@@ -27,27 +27,26 @@
 public:
   /// \p ASTCallback is called when a file is parsed synchronously. This should
   /// not be expensive since it blocks diagnostics.
-  explicit CppFileCollection(ASTParsedCallback ASTCallback)
-  : ASTCallback(std::move(ASTCallback)) {}
+  explicit CppFileCollection(bool StorePreamblesInMemory,
+ std::shared_ptr PCHs,
+ ASTParsedCallback ASTCallback)
+  : ASTCallback(std::move(ASTCallback)), PCHs(std::move(PCHs)),
+StorePreamblesInMemory(StorePreamblesInMemory) {}
 
-  std::shared_ptr
-  getOrCreateFile(PathRef File, PathRef ResourceDir,
-  bool StorePreamblesInMemory,
-  std::shared_ptr PCHs) {
+  std::shared_ptr getOrCreateFile(PathRef File) {
 std::lock_guard Lock(Mutex);
 auto It = OpenedFiles.find(File);
 if (It == OpenedFiles.end()) {
   It = OpenedFiles
.try_emplace(File, CppFile::Create(File, StorePreamblesInMemory,
-  std::move(PCHs), ASTCallback))
+  PCHs, ASTCallback))
.first;
 }
 return It->second;
   }
 
-  std::shared_ptr getFile(PathRef File) {
+  std::shared_ptr getFile(PathRef File) const {
 std::lock_guard Lock(Mutex);
-
 auto It = OpenedFiles.find(File);
 if (It == OpenedFiles.end())
   return nullptr;
@@ -59,9 +58,11 @@
   std::shared_ptr removeIfPresent(PathRef File);
 
 private:
-  std::mutex Mutex;
+  mutable std::mutex Mutex;
   llvm::StringMap> OpenedFiles;
   ASTParsedCallback ASTCallback;
+  std::shared_ptr PCHs;
+  bool StorePreamblesInMemory;
 };
 } // namespace clangd
 } // namespace clang
Index: clangd/ClangdUnit.h
===
--- clangd/ClangdUnit.h
+++ clangd/ClangdUnit.h
@@ -64,11 +64,8 @@
   ParseInputs(tooling::CompileCommand CompileCommand,
   IntrusiveRefCntPtr FS, std::string Contents);
 
-  /// Compilation arguments.
   tooling::CompileCommand CompileCommand;
-  /// FileSystem.
   IntrusiveRefCntPtr FS;
-  /// Contents to parse.
   std::string Contents;
 };
 
Index: clangd/ClangdServer.h
===
--- clangd/ClangdServer.h
+++ clangd/ClangdServer.h
@@ -98,21 +98,20 @@
 
 class ClangdServer;
 
-/// Returns a number of a default async threads to use for ClangdScheduler.
+/// Returns a number of a default async threads to use for Scheduler.
 /// Returned value is always >= 1 (i.e. will not cause requests to be processed
 /// synchronously).
 unsigned getDefaultAsyncThreadsCount();
 
-/// Handles running WorkerRequests of ClangdServer on a number of worker
-/// threads.
-class ClangdScheduler {
+/// A simple fixed-size thread pool implementation.
+class SimpleThreadPool {
 public:
   /// If \p AsyncThreadsCount is 0, requests added using addToFront and addToEnd
   /// will be processed synchronously on the calling thread.
   // Otherwise, \p AsyncThreadsCount threads will be created to schedule the
   // requests.
-  ClangdScheduler(unsigned AsyncThreadsCount);
-  ~ClangdScheduler();
+  SimpleThreadPool(unsigned AsyncThreadsCount);
+  ~SimpleThreadPool();
 
   /// Add a new request to run function \p F with args \p As to the start of the
   /// queue. The request will be run on a separate thread.
@@ -149,20 +148,64 @@
 
 private:
   bool RunSynchronously;
-  std::mutex Mutex;
+  mutable std::mutex Mutex;
   /// We run some tasks on separate threads(parsing, CppFile cleanup).
   /// These threads looks into RequestQueue to find requests to handle and
   /// terminate when Done is set to true.
   std::vector Workers;
   /// Setting Done to true will make the worker threads terminate.
   bool Done = false;
-  /// A queue of requests. Elements of this vector are async computations (i.e.
-  /// results of calling std::async(std::launch::deferred, ...)).
+  /// A queue of requests.
   std::deque> RequestQueue;
   /// Condition variable to wake up worker threads.
   std::condition_variable RequestCV;
 };
 
+/// Handles running tasks for ClangdServer and managing the resources (e.g.,
+/// preamb

[PATCH] D42111: [Tooling] Don't deduplicate tool results in the All-TUs executor.

2018-01-17 Thread Benjamin Kramer via Phabricator via cfe-commits
bkramer accepted this revision.
bkramer added a comment.
This revision is now accepted and ready to land.

lg


Repository:
  rC Clang

https://reviews.llvm.org/D42111



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


[PATCH] D42177: DO NOT SUBMIT. Combined diff of D42174 and D42173.

2018-01-17 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov created this revision.
Herald added subscribers: cfe-commits, klimek.

To simplify review of both changes.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42177

Files:
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/ClangdUnit.cpp
  clangd/ClangdUnit.h
  clangd/ClangdUnitStore.cpp
  clangd/ClangdUnitStore.h

Index: clangd/ClangdUnitStore.h
===
--- clangd/ClangdUnitStore.h
+++ clangd/ClangdUnitStore.h
@@ -27,50 +27,26 @@
 public:
   /// \p ASTCallback is called when a file is parsed synchronously. This should
   /// not be expensive since it blocks diagnostics.
-  explicit CppFileCollection(ASTParsedCallback ASTCallback)
-  : ASTCallback(std::move(ASTCallback)) {}
+  explicit CppFileCollection(bool StorePreamblesInMemory,
+ std::shared_ptr PCHs,
+ ASTParsedCallback ASTCallback)
+  : ASTCallback(std::move(ASTCallback)), PCHs(std::move(PCHs)),
+StorePreamblesInMemory(StorePreamblesInMemory) {}
 
-  std::shared_ptr
-  getOrCreateFile(PathRef File, PathRef ResourceDir,
-  GlobalCompilationDatabase &CDB, bool StorePreamblesInMemory,
-  std::shared_ptr PCHs) {
+  std::shared_ptr getOrCreateFile(PathRef File) {
 std::lock_guard Lock(Mutex);
-
 auto It = OpenedFiles.find(File);
 if (It == OpenedFiles.end()) {
-  auto Command = getCompileCommand(CDB, File, ResourceDir);
-
   It = OpenedFiles
-   .try_emplace(File, CppFile::Create(File, std::move(Command),
-  StorePreamblesInMemory,
-  std::move(PCHs), ASTCallback))
+   .try_emplace(File, CppFile::Create(File, StorePreamblesInMemory,
+  PCHs, ASTCallback))
.first;
 }
 return It->second;
   }
 
-  struct RecreateResult {
-/// A CppFile, stored in this CppFileCollection for the corresponding
-/// filepath after calling recreateFileIfCompileCommandChanged.
-std::shared_ptr FileInCollection;
-/// If a new CppFile had to be created to account for changed
-/// CompileCommand, a previous CppFile instance will be returned in this
-/// field.
-std::shared_ptr RemovedFile;
-  };
-
-  /// Similar to getOrCreateFile, but will replace a current CppFile for \p File
-  /// with a new one if CompileCommand, provided by \p CDB has changed.
-  /// If a currently stored CppFile had to be replaced, the previous instance
-  /// will be returned in RecreateResult.RemovedFile.
-  RecreateResult recreateFileIfCompileCommandChanged(
-  PathRef File, PathRef ResourceDir, GlobalCompilationDatabase &CDB,
-  bool StorePreamblesInMemory,
-  std::shared_ptr PCHs);
-
-  std::shared_ptr getFile(PathRef File) {
+  std::shared_ptr getFile(PathRef File) const {
 std::lock_guard Lock(Mutex);
-
 auto It = OpenedFiles.find(File);
 if (It == OpenedFiles.end())
   return nullptr;
@@ -82,15 +58,11 @@
   std::shared_ptr removeIfPresent(PathRef File);
 
 private:
-  tooling::CompileCommand getCompileCommand(GlobalCompilationDatabase &CDB,
-PathRef File, PathRef ResourceDir);
-
-  bool compileCommandsAreEqual(tooling::CompileCommand const &LHS,
-   tooling::CompileCommand const &RHS);
-
-  std::mutex Mutex;
+  mutable std::mutex Mutex;
   llvm::StringMap> OpenedFiles;
   ASTParsedCallback ASTCallback;
+  std::shared_ptr PCHs;
+  bool StorePreamblesInMemory;
 };
 } // namespace clangd
 } // namespace clang
Index: clangd/ClangdUnitStore.cpp
===
--- clangd/ClangdUnitStore.cpp
+++ clangd/ClangdUnitStore.cpp
@@ -25,53 +25,3 @@
   OpenedFiles.erase(It);
   return Result;
 }
-
-CppFileCollection::RecreateResult
-CppFileCollection::recreateFileIfCompileCommandChanged(
-PathRef File, PathRef ResourceDir, GlobalCompilationDatabase &CDB,
-bool StorePreamblesInMemory, std::shared_ptr PCHs) {
-  auto NewCommand = getCompileCommand(CDB, File, ResourceDir);
-
-  std::lock_guard Lock(Mutex);
-
-  RecreateResult Result;
-
-  auto It = OpenedFiles.find(File);
-  if (It == OpenedFiles.end()) {
-It = OpenedFiles
- .try_emplace(File, CppFile::Create(File, std::move(NewCommand),
-StorePreamblesInMemory,
-std::move(PCHs), ASTCallback))
- .first;
-  } else if (!compileCommandsAreEqual(It->second->getCompileCommand(),
-  NewCommand)) {
-Result.RemovedFile = std::move(It->second);
-It->second =
-CppFile::Create(File, std::move(NewCommand), StorePreamblesInMemory,
-std::move(PCHs), ASTCallback);
-  }
-  Result.FileInCollection = 

[PATCH] D42174: [clangd] Refactored threading in ClangdServer

2018-01-17 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

Here's also a combined diff from both this and child revision: 
https://reviews.llvm.org/D42177


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42174



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


[PATCH] D42167: [clang-format] adds enclosing function detection to raw string formatting

2018-01-17 Thread Benjamin Kramer via Phabricator via cfe-commits
bkramer added inline comments.



Comment at: lib/Format/ContinuationIndenter.cpp:1454
+// found.
+static StringRef getEnclosingFunctionName(const FormatToken& Current) {
+  // Look for: 'function(' or 'function(' before Current.

This function doesn't look clang-formatted.


Repository:
  rC Clang

https://reviews.llvm.org/D42167



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


[libcxx] r322659 - Merging r321963:

2018-01-17 Thread Hans Wennborg via cfe-commits
Author: hans
Date: Wed Jan 17 06:26:10 2018
New Revision: 322659

URL: http://llvm.org/viewvc/llvm-project?rev=322659&view=rev
Log:
Merging r321963:

r321963 | dim | 2018-01-07 08:45:11 -0800 (Sun, 07 Jan 2018) | 51 lines

Add pre-C++11 is_constructible wrappers for 3 arguments

Summary:
After rL319736 for D28253 (which fixes PR28929), gcc cannot compile `` 
anymore in pre-C+11 modes, complaining:

```
In file included from /usr/include/c++/v1/memory:648:0,
 from test.cpp:1:
/usr/include/c++/v1/memory: In static member function 'static 
std::__1::shared_ptr<_Tp> std::__1::shared_ptr<_Tp>::make_shared(_A0&, _A1&, 
_A2&)':
/usr/include/c++/v1/memory:4365:5: error: wrong number of template arguments 
(4, should be at least 1)
 static_assert((is_constructible<_Tp, _A0, _A1, _A2>::value), "Can't 
construct object in make_shared" );
 ^
In file included from /usr/include/c++/v1/memory:649:0,
 from test.cpp:1:
/usr/include/c++/v1/type_traits:3198:29: note: provided for 'template struct std::__1::is_constructible'
 struct _LIBCPP_TEMPLATE_VIS is_constructible
 ^~~~
In file included from /usr/include/c++/v1/memory:648:0,
 from test.cpp:1:
/usr/include/c++/v1/memory:4365:5: error: template argument 1 is invalid
 static_assert((is_constructible<_Tp, _A0, _A1, _A2>::value), "Can't 
construct object in make_shared" );
 ^
/usr/include/c++/v1/memory: In static member function 'static 
std::__1::shared_ptr<_Tp> std::__1::shared_ptr<_Tp>::allocate_shared(const 
_Alloc&, _A0&, _A1&, _A2&)':
/usr/include/c++/v1/memory::5: error: wrong number of template arguments 
(4, should be at least 1)
 static_assert((is_constructible<_Tp, _A0, _A1, _A2>::value), "Can't 
construct object in allocate_shared" );
 ^
In file included from /usr/include/c++/v1/memory:649:0,
 from test.cpp:1:
/usr/include/c++/v1/type_traits:3198:29: note: provided for 'template struct std::__1::is_constructible'
 struct _LIBCPP_TEMPLATE_VIS is_constructible
 ^~~~
In file included from /usr/include/c++/v1/memory:648:0,
 from test.cpp:1:
/usr/include/c++/v1/memory::5: error: template argument 1 is invalid
 static_assert((is_constructible<_Tp, _A0, _A1, _A2>::value), "Can't 
construct object in allocate_shared" );
 ^
```

This is also reported in https://bugs.freebsd.org/224946 (FreeBSD is apparently 
one of the very few projects that regularly builds programs against libc++ with 
gcc).

The reason is that the static assertions are invoking `is_constructible` with 
three arguments, while gcc does not have the built-in `is_constructible` 
feature, and the pre-C++11 `is_constructible` wrappers in `` only 
provide up to two arguments.

I have added additional wrappers for three arguments, modified the 
`is_constructible` entry point to take three arguments instead, and added a 
simple test to is_constructible.pass.cpp.

Reviewers: EricWF, mclow.lists

Reviewed By: EricWF

Subscribers: krytarowski, cfe-commits, emaste

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


Modified:
libcxx/branches/release_60/   (props changed)
libcxx/branches/release_60/include/type_traits

libcxx/branches/release_60/test/std/utilities/meta/meta.unary/meta.unary.prop/is_constructible.pass.cpp

Propchange: libcxx/branches/release_60/
--
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jan 17 06:26:10 2018
@@ -1 +1,2 @@
 /libcxx/branches/apple:136569-137939
+/libcxx/trunk:321963

Modified: libcxx/branches/release_60/include/type_traits
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/branches/release_60/include/type_traits?rev=322659&r1=322658&r2=322659&view=diff
==
--- libcxx/branches/release_60/include/type_traits (original)
+++ libcxx/branches/release_60/include/type_traits Wed Jan 17 06:26:10 2018
@@ -3172,6 +3172,14 @@ template 
 false_type
 __is_constructible2_test(__any, _A0&, _A1&);
 
+template 
+decltype((_Tp(_VSTD::declval<_A0>(), _VSTD::declval<_A1>(), 
_VSTD::declval<_A2>()), true_type()))
+__is_constructible3_test(_Tp&, _A0&, _A1&, _A2&);
+
+template 
+false_type
+__is_constructible3_test(__any, _A0&, _A1&, _A2&);
+
 template 
 struct __is_constructible0_imp // false, _Tp is not a scalar
 : public common_type
@@ -3196,6 +3204,14 @@ struct __is_constructible2_imp // false,
  >::type
 {};
 
+template 
+struct __is_constructible3_imp // false, _Tp is not a scalar
+: public common_type
+ <
+ decltype(__is_constructible3_test(declval<_Tp&>(), 
declval<_A0>(), declval<_A1>(), declval<_A2>()))
+ >::type
+{};
+
 

[PATCH] D41535: Add -vfsoverlay option for Clang-Tidy

2018-01-17 Thread Vladimir Plyashkun via Phabricator via cfe-commits
vladimir.plyashkun added a comment.

Friendly ping


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41535



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


Re: [libcxx] r321963 - Add pre-C++11 is_constructible wrappers for 3 arguments

2018-01-17 Thread Hans Wennborg via cfe-commits
Merged to 6.0 in r322659.

On Sun, Jan 7, 2018 at 5:45 PM, Dimitry Andric via cfe-commits
 wrote:
> Author: dim
> Date: Sun Jan  7 08:45:11 2018
> New Revision: 321963
>
> URL: http://llvm.org/viewvc/llvm-project?rev=321963&view=rev
> Log:
> Add pre-C++11 is_constructible wrappers for 3 arguments
>
> Summary:
> After rL319736 for D28253 (which fixes PR28929), gcc cannot compile 
> `` anymore in pre-C+11 modes, complaining:
>
> ```
> In file included from /usr/include/c++/v1/memory:648:0,
>  from test.cpp:1:
> /usr/include/c++/v1/memory: In static member function 'static 
> std::__1::shared_ptr<_Tp> std::__1::shared_ptr<_Tp>::make_shared(_A0&, _A1&, 
> _A2&)':
> /usr/include/c++/v1/memory:4365:5: error: wrong number of template arguments 
> (4, should be at least 1)
>  static_assert((is_constructible<_Tp, _A0, _A1, _A2>::value), "Can't 
> construct object in make_shared" );
>  ^
> In file included from /usr/include/c++/v1/memory:649:0,
>  from test.cpp:1:
> /usr/include/c++/v1/type_traits:3198:29: note: provided for 'template _Tp, class _A0, class _A1> struct std::__1::is_constructible'
>  struct _LIBCPP_TEMPLATE_VIS is_constructible
>  ^~~~
> In file included from /usr/include/c++/v1/memory:648:0,
>  from test.cpp:1:
> /usr/include/c++/v1/memory:4365:5: error: template argument 1 is invalid
>  static_assert((is_constructible<_Tp, _A0, _A1, _A2>::value), "Can't 
> construct object in make_shared" );
>  ^
> /usr/include/c++/v1/memory: In static member function 'static 
> std::__1::shared_ptr<_Tp> std::__1::shared_ptr<_Tp>::allocate_shared(const 
> _Alloc&, _A0&, _A1&, _A2&)':
> /usr/include/c++/v1/memory::5: error: wrong number of template arguments 
> (4, should be at least 1)
>  static_assert((is_constructible<_Tp, _A0, _A1, _A2>::value), "Can't 
> construct object in allocate_shared" );
>  ^
> In file included from /usr/include/c++/v1/memory:649:0,
>  from test.cpp:1:
> /usr/include/c++/v1/type_traits:3198:29: note: provided for 'template _Tp, class _A0, class _A1> struct std::__1::is_constructible'
>  struct _LIBCPP_TEMPLATE_VIS is_constructible
>  ^~~~
> In file included from /usr/include/c++/v1/memory:648:0,
>  from test.cpp:1:
> /usr/include/c++/v1/memory::5: error: template argument 1 is invalid
>  static_assert((is_constructible<_Tp, _A0, _A1, _A2>::value), "Can't 
> construct object in allocate_shared" );
>  ^
> ```
>
> This is also reported in https://bugs.freebsd.org/224946 (FreeBSD is 
> apparently one of the very few projects that regularly builds programs 
> against libc++ with gcc).
>
> The reason is that the static assertions are invoking `is_constructible` with 
> three arguments, while gcc does not have the built-in `is_constructible` 
> feature, and the pre-C++11 `is_constructible` wrappers in `` 
> only provide up to two arguments.
>
> I have added additional wrappers for three arguments, modified the 
> `is_constructible` entry point to take three arguments instead, and added a 
> simple test to is_constructible.pass.cpp.
>
> Reviewers: EricWF, mclow.lists
>
> Reviewed By: EricWF
>
> Subscribers: krytarowski, cfe-commits, emaste
>
> Differential Revision: https://reviews.llvm.org/D41805
>
> Modified:
> libcxx/trunk/include/type_traits
> 
> libcxx/trunk/test/std/utilities/meta/meta.unary/meta.unary.prop/is_constructible.pass.cpp
>
> Modified: libcxx/trunk/include/type_traits
> URL: 
> http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/type_traits?rev=321963&r1=321962&r2=321963&view=diff
> ==
> --- libcxx/trunk/include/type_traits (original)
> +++ libcxx/trunk/include/type_traits Sun Jan  7 08:45:11 2018
> @@ -3172,6 +3172,14 @@ template 
>  false_type
>  __is_constructible2_test(__any, _A0&, _A1&);
>
> +template 
> +decltype((_Tp(_VSTD::declval<_A0>(), _VSTD::declval<_A1>(), 
> _VSTD::declval<_A2>()), true_type()))
> +__is_constructible3_test(_Tp&, _A0&, _A1&, _A2&);
> +
> +template 
> +false_type
> +__is_constructible3_test(__any, _A0&, _A1&, _A2&);
> +
>  template 
>  struct __is_constructible0_imp // false, _Tp is not a scalar
>  : public common_type
> @@ -3196,6 +3204,14 @@ struct __is_constructible2_imp // false,
>   >::type
>  {};
>
> +template 
> +struct __is_constructible3_imp // false, _Tp is not a scalar
> +: public common_type
> + <
> + decltype(__is_constructible3_test(declval<_Tp&>(), 
> declval<_A0>(), declval<_A1>(), declval<_A2>()))
> + >::type
> +{};
> +
>  //  handle scalars and reference types
>
>  //  Scalars are default constructible, references are not
> @@ -3215,6 +3231,11 @@ struct __is_constructible2_imp  : public false_type
>  {};
>
> +template 
> +struct __is_constructible3_imp
> +: public 

[PATCH] D41947: Provide default virtual filesystem argument to ClangTool constructor

2018-01-17 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

LGTM, but could we add a test that checks the VFS is actually used?


Repository:
  rC Clang

https://reviews.llvm.org/D41947



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


r322661 - [Sema] Add visited contexts to CodeCompleteContext

2018-01-17 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Wed Jan 17 06:29:25 2018
New Revision: 322661

URL: http://llvm.org/viewvc/llvm-project?rev=322661&view=rev
Log:
[Sema] Add visited contexts to CodeCompleteContext

Summary:
This would allow code completion clients to know which context is visited 
during Sema code completion.

Also some changes:
 * add `EnteredContext` callback in VisibleDeclConsumer.
 * add a simple unittest for sema code completion (only for visited contexts at 
the moment).

Reviewers: ilya-biryukov

Reviewed By: ilya-biryukov

Subscribers: mgorny, bkramer, cfe-commits

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

Added:
cfe/trunk/unittests/Sema/CodeCompleteTest.cpp
Modified:
cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h
cfe/trunk/include/clang/Sema/Lookup.h
cfe/trunk/lib/Sema/SemaCodeComplete.cpp
cfe/trunk/lib/Sema/SemaLookup.cpp
cfe/trunk/unittests/Sema/CMakeLists.txt

Modified: cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h?rev=322661&r1=322660&r2=322661&view=diff
==
--- cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h (original)
+++ cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h Wed Jan 17 06:29:25 2018
@@ -268,6 +268,8 @@ public:
 CCC_Recovery
   };
 
+  using VisitedContextSet = llvm::SmallPtrSet;
+
 private:
   enum Kind Kind;
 
@@ -285,6 +287,10 @@ private:
   /// "a::b::"
   llvm::Optional ScopeSpecifier;
 
+  /// \brief A set of declaration contexts visited by Sema when doing lookup 
for
+  /// code completion.
+  VisitedContextSet VisitedContexts;
+
 public:
   /// \brief Construct a new code-completion context of the given kind.
   CodeCompletionContext(enum Kind Kind) : Kind(Kind), SelIdents(None) { }
@@ -328,6 +334,16 @@ public:
 this->ScopeSpecifier = std::move(SS);
   }
 
+  /// \brief Adds a visited context.
+  void addVisitedContext(DeclContext* Ctx) {
+VisitedContexts.insert(Ctx);
+  }
+
+  /// \brief Retrieves all visited contexts.
+  const VisitedContextSet &getVisitedContexts() const {
+return VisitedContexts;
+  }
+
   llvm::Optional getCXXScopeSpecifier() {
 if (ScopeSpecifier)
   return ScopeSpecifier.getPointer();

Modified: cfe/trunk/include/clang/Sema/Lookup.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Lookup.h?rev=322661&r1=322660&r2=322661&view=diff
==
--- cfe/trunk/include/clang/Sema/Lookup.h (original)
+++ cfe/trunk/include/clang/Sema/Lookup.h Wed Jan 17 06:29:25 2018
@@ -784,6 +784,12 @@ public:
   /// class of the context we searched.
   virtual void FoundDecl(NamedDecl *ND, NamedDecl *Hiding, DeclContext *Ctx,
  bool InBaseClass) = 0;
+
+  /// \brief Callback to inform the client that Sema entered into a new context
+  /// to find a visible declaration.
+  //
+  /// \param Ctx the context which Sema entered.
+  virtual void EnteredContext(DeclContext *Ctx) {}
 };
 
 /// \brief A class for storing results from argument-dependent lookup.

Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=322661&r1=322660&r2=322661&view=diff
==
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Wed Jan 17 06:29:25 2018
@@ -318,6 +318,11 @@ namespace {
 /// \brief Ignore this declaration, if it is seen again.
 void Ignore(const Decl *D) { AllDeclsFound.insert(D->getCanonicalDecl()); }
 
+/// \brief Add a visited context.
+void addVisitedContext(DeclContext *Ctx) {
+  CompletionContext.addVisitedContext(Ctx);
+}
+
 /// \name Name lookup predicates
 ///
 /// These predicates can be passed to the name lookup functions to filter 
the
@@ -1280,7 +1285,7 @@ namespace {
   class CodeCompletionDeclConsumer : public VisibleDeclConsumer {
 ResultBuilder &Results;
 DeclContext *CurContext;
-
+
   public:
 CodeCompletionDeclConsumer(ResultBuilder &Results, DeclContext *CurContext)
   : Results(Results), CurContext(CurContext) { }
@@ -1295,6 +1300,10 @@ namespace {
false, Accessible);
   Results.AddResult(Result, CurContext, Hiding, InBaseClass);
 }
+
+void EnteredContext(DeclContext* Ctx) override {
+  Results.addVisitedContext(Ctx);
+}
   };
 }
 

Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=322661&r1=322660&r2=322661&view=diff
==
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Wed Jan 17 06:29:25 2018
@@ -3507,6 +3507,8 @@ static void L

[PATCH] D42071: [Sema] Add visited contexts to CodeCompleteContext

2018-01-17 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC322661: [Sema] Add visited contexts to CodeCompleteContext 
(authored by hokein, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D42071?vs=130155&id=130170#toc

Repository:
  rC Clang

https://reviews.llvm.org/D42071

Files:
  include/clang/Sema/CodeCompleteConsumer.h
  include/clang/Sema/Lookup.h
  lib/Sema/SemaCodeComplete.cpp
  lib/Sema/SemaLookup.cpp
  unittests/Sema/CMakeLists.txt
  unittests/Sema/CodeCompleteTest.cpp

Index: lib/Sema/SemaLookup.cpp
===
--- lib/Sema/SemaLookup.cpp
+++ lib/Sema/SemaLookup.cpp
@@ -3507,6 +3507,8 @@
   if (Visited.visitedContext(Ctx->getPrimaryContext()))
 return;
 
+  Consumer.EnteredContext(Ctx);
+
   // Outside C++, lookup results for the TU live on identifiers.
   if (isa(Ctx) &&
   !Result.getSema().getLangOpts().CPlusPlus) {
Index: lib/Sema/SemaCodeComplete.cpp
===
--- lib/Sema/SemaCodeComplete.cpp
+++ lib/Sema/SemaCodeComplete.cpp
@@ -318,6 +318,11 @@
 /// \brief Ignore this declaration, if it is seen again.
 void Ignore(const Decl *D) { AllDeclsFound.insert(D->getCanonicalDecl()); }
 
+/// \brief Add a visited context.
+void addVisitedContext(DeclContext *Ctx) {
+  CompletionContext.addVisitedContext(Ctx);
+}
+
 /// \name Name lookup predicates
 ///
 /// These predicates can be passed to the name lookup functions to filter the
@@ -1280,7 +1285,7 @@
   class CodeCompletionDeclConsumer : public VisibleDeclConsumer {
 ResultBuilder &Results;
 DeclContext *CurContext;
-
+
   public:
 CodeCompletionDeclConsumer(ResultBuilder &Results, DeclContext *CurContext)
   : Results(Results), CurContext(CurContext) { }
@@ -1295,6 +1300,10 @@
false, Accessible);
   Results.AddResult(Result, CurContext, Hiding, InBaseClass);
 }
+
+void EnteredContext(DeclContext* Ctx) override {
+  Results.addVisitedContext(Ctx);
+}
   };
 }
 
Index: unittests/Sema/CMakeLists.txt
===
--- unittests/Sema/CMakeLists.txt
+++ unittests/Sema/CMakeLists.txt
@@ -4,6 +4,7 @@
 
 add_clang_unittest(SemaTests
   ExternalSemaSourceTest.cpp
+  CodeCompleteTest.cpp
   )
 
 target_link_libraries(SemaTests
Index: unittests/Sema/CodeCompleteTest.cpp
===
--- unittests/Sema/CodeCompleteTest.cpp
+++ unittests/Sema/CodeCompleteTest.cpp
@@ -0,0 +1,134 @@
+//=== unittests/Sema/CodeCompleteTest.cpp - Code Complete tests ==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Parse/ParseAST.h"
+#include "clang/Sema/Sema.h"
+#include "clang/Sema/SemaDiagnostic.h"
+#include "clang/Tooling/Tooling.h"
+#include "gtest/gtest.h"
+#include "gmock/gmock.h"
+
+namespace {
+
+using namespace clang;
+using namespace clang::tooling;
+using ::testing::UnorderedElementsAre;
+
+const char TestCCName[] = "test.cc";
+using VisitedContextResults = std::vector;
+
+class VisitedContextFinder: public CodeCompleteConsumer {
+public:
+  VisitedContextFinder(VisitedContextResults &Results)
+  : CodeCompleteConsumer(/*CodeCompleteOpts=*/{},
+ /*CodeCompleteConsumer*/ false),
+VCResults(Results),
+CCTUInfo(std::make_shared()) {}
+
+  void ProcessCodeCompleteResults(Sema &S, CodeCompletionContext Context,
+  CodeCompletionResult *Results,
+  unsigned NumResults) override {
+VisitedContexts = Context.getVisitedContexts();
+VCResults = getVisitedNamespace();
+  }
+
+  CodeCompletionAllocator &getAllocator() override {
+return CCTUInfo.getAllocator();
+  }
+
+  CodeCompletionTUInfo &getCodeCompletionTUInfo() override { return CCTUInfo; }
+
+  std::vector getVisitedNamespace() const {
+std::vector NSNames;
+for (const auto *Context : VisitedContexts)
+  if (const auto *NS = llvm::dyn_cast(Context))
+NSNames.push_back(NS->getQualifiedNameAsString());
+return NSNames;
+  }
+
+private:
+  VisitedContextResults& VCResults;
+  CodeCompletionTUInfo CCTUInfo;
+  CodeCompletionContext::VisitedContextSet VisitedContexts;
+};
+
+class CodeCompleteAction : public SyntaxOnlyAction {
+public:
+  CodeCompleteAction(ParsedSourceLocation P, VisitedContextResults &Results)
+  : CompletePosition(std::move(P)), VCResults(Results) {}
+
+  bool BeginInvocation(CompilerInstance

[PATCH] D42181: [clangd] Merge index-provided completions with those from Sema.

2018-01-17 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: ioeric.
Herald added subscribers: cfe-commits, mgrang, ilya-biryukov, klimek.

- we match on USR, and do a field-by-field merge if both have results
- scoring is post-merge, with both sets of information available (for now, sema 
priority is used if available, static score for index results)
- limit is applied to the complete result set (previously index ignored limit)
- CompletionItem is only produces for the returned results
- If the user doesn't type a scope, we send the scopeless query to the index 
for global completion.

This needs tests for the new functionality, but I thought you could take a look
while I work on that. It passes the existing tests, and works in VSCode.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42181

Files:
  clangd/CodeComplete.cpp
  test/clangd/authority-less-uri.test
  unittests/clangd/CodeCompleteTests.cpp

Index: unittests/clangd/CodeCompleteTests.cpp
===
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -497,6 +497,7 @@
   Sym.Scope = QName.substr(0, Pos);
 }
 Sym.CompletionPlainInsertText = Sym.Name;
+Sym.CompletionLabel = Sym.Name;
 Sym.SymInfo.Kind = Pair.second;
 Slab.insert(Sym);
   }
@@ -528,8 +529,8 @@
   void f() { ::ns::^ }
   )cpp",
  Opts);
-  EXPECT_THAT(Results.items, Contains(Labeled("[I]XYZ")));
-  EXPECT_THAT(Results.items, Contains(Labeled("[I]foo")));
+  EXPECT_THAT(Results.items, Contains(Labeled("XYZ")));
+  EXPECT_THAT(Results.items, Contains(Labeled("foo")));
 }
 
 TEST(CompletionTest, SimpleIndexBased) {
Index: test/clangd/authority-less-uri.test
===
--- test/clangd/authority-less-uri.test
+++ test/clangd/authority-less-uri.test
@@ -25,7 +25,7 @@
 # CHECK-NEXT:"insertTextFormat": 1,
 # CHECK-NEXT:"kind": 7,
 # CHECK-NEXT:"label": "fake::",
-# CHECK-NEXT:"sortText": "{{.*}}fake"
+# CHECK-NEXT:"sortText": "{{.*}}fake::"
 #  CHECK:]
 # CHECK-NEXT:  }
 Content-Length: 173
@@ -43,7 +43,7 @@
 # CHECK-NEXT:"insertTextFormat": 1,
 # CHECK-NEXT:"kind": 7,
 # CHECK-NEXT:"label": "fake::",
-# CHECK-NEXT:"sortText": "{{.*}}fake"
+# CHECK-NEXT:"sortText": "{{.*}}fake::"
 #  CHECK:]
 # CHECK-NEXT:  }
 Content-Length: 44
Index: clangd/CodeComplete.cpp
===
--- clangd/CodeComplete.cpp
+++ clangd/CodeComplete.cpp
@@ -22,6 +22,7 @@
 #include "index/Index.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendActions.h"
+#include "clang/Index/USRGeneration.h"
 #include "clang/Sema/CodeCompleteConsumer.h"
 #include "clang/Sema/Sema.h"
 #include "llvm/Support/Format.h"
@@ -185,48 +186,53 @@
   return Result;
 }
 
-/// A scored code completion result.
-/// It may be promoted to a CompletionItem if it's among the top-ranked results.
-///
-/// We score candidates by multiplying the symbolScore ("quality" of the result)
-/// with the filterScore (how well it matched the query).
-/// This is sensitive to the distribution of both component scores!
-struct CompletionCandidate {
-  CompletionCandidate(CodeCompletionResult &Result, float FilterScore)
-  : Result(&Result) {
-Scores.symbolScore = score(Result);  // Higher is better.
-Scores.filterScore = FilterScore;// 0-1, higher is better.
-Scores.finalScore = Scores.symbolScore * Scores.filterScore;
-  }
+// Produces an integer that sorts in the same order as F.
+// That is: a < b <==> encodeFloat(a) < encodeFloat(b).
+uint32_t encodeFloat(float F) {
+  static_assert(std::numeric_limits::is_iec559, "");
+  static_assert(sizeof(float) == sizeof(uint32_t), "");
+  constexpr uint32_t TopBit = ~(~uint32_t{0} >> 1);
+
+  // Get the bits of the float. Endianness is the same as for integers.
+  uint32_t U;
+  memcpy(&U, &F, sizeof(float));
+  // IEEE 754 floats compare like sign-magnitude integers.
+  if (U & TopBit)// Negative float.
+return 0 - U;// Map onto the low half of integers, order reversed.
+  return U + TopBit; // Positive floats map onto the high half of integers.
+}
 
-  CodeCompletionResult *Result;
-  CompletionItemScores Scores;
+// Returns a string that sorts in the same order as (-Score, Name), for LSP.
+std::string sortText(float Score, llvm::StringRef Name) {
+  // We convert -Score to an integer, and hex-encode for readability.
+  // Example: [0.5, "foo"] -> "4100foo"
+  std::string S;
+  llvm::raw_string_ostream OS(S);
+  write_hex(OS, encodeFloat(-Score), llvm::HexPrintStyle::Lower,
+/*Width=*/2 * sizeof(Score));
+  OS << Name;
+  OS.flush();
+  return S;
+}
 
-  // Comparison reflects rank: better candidates are smaller.
-  bool operator<(const CompletionCandidate &C) const {
-

[PATCH] D41921: [Parse] Forward brace locations to TypeConstructExpr

2018-01-17 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM!


https://reviews.llvm.org/D41921



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


[PATCH] D32845: [Analyzer] Iterator Checker - Part 4: Mismatched iterator checker for function parameters

2018-01-17 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 130174.
baloghadamsoftware marked an inline comment as done.
baloghadamsoftware added a comment.

Updated according to some comments.


https://reviews.llvm.org/D32845

Files:
  include/clang/StaticAnalyzer/Checkers/Checkers.td
  lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
  test/Analysis/Inputs/system-header-simulator-cxx.h
  test/Analysis/mismatched-iterator.cpp

Index: test/Analysis/mismatched-iterator.cpp
===
--- /dev/null
+++ test/Analysis/mismatched-iterator.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,cplusplus,alpha.cplusplus.MismatchedIterator -analyzer-eagerly-assume -analyzer-config aggressive-relational-comparison-simplification=true -analyzer-config c++-container-inlining=false %s -verify
+// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,cplusplus,alpha.cplusplus.MismatchedIterator -analyzer-eagerly-assume -analyzer-config aggressive-relational-comparison-simplification=true -analyzer-config c++-container-inlining=true -DINLINE=1 %s -verify
+
+#include "Inputs/system-header-simulator-cxx.h"
+
+void good_find(std::vector &v, int n) {
+  std::find(v.cbegin(), v.cend(), n); // no-warning
+}
+
+void good_find_first_of(std::vector &v1, std::vector &v2) {
+  std::find_first_of(v1.cbegin(), v1.cend(), v2.cbegin(), v2.cend()); // no-warning
+}
+
+void good_copy(std::vector &v1, std::vector &v2, int n) {
+  std::copy(v1.cbegin(), v1.cend(), v2.begin()); // no-warning
+}
+
+void bad_find(std::vector &v1, std::vector &v2, int n) {
+  std::find(v1.cbegin(), v2.cend(), n); // expected-warning{{Iterator access mismatched}}
+}
+
+void bad_find_first_of(std::vector &v1, std::vector &v2) {
+  std::find_first_of(v1.cbegin(), v2.cend(), v2.cbegin(), v2.cend()); // expected-warning{{Iterator access mismatched}}
+  std::find_first_of(v1.cbegin(), v1.cend(), v2.cbegin(), v1.cend()); // expected-warning{{Iterator access mismatched}}
+}
Index: test/Analysis/Inputs/system-header-simulator-cxx.h
===
--- test/Analysis/Inputs/system-header-simulator-cxx.h
+++ test/Analysis/Inputs/system-header-simulator-cxx.h
@@ -642,6 +642,12 @@
   template 
   InputIterator find(InputIterator first, InputIterator last, const T &val);
 
+  template 
+  ForwardIterator1 find_first_of(ForwardIterator1 first1,
+ ForwardIterator1 last1,
+ ForwardIterator2 first2,
+ ForwardIterator2 last2);
+
   template 
   OutputIterator copy(InputIterator first, InputIterator last,
   OutputIterator result);
Index: lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
+++ lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
@@ -199,6 +199,7 @@
  eval::Assume> {
 
   std::unique_ptr OutOfRangeBugType;
+  std::unique_ptr MismatchedBugType;
   std::unique_ptr InvalidatedBugType;
 
   void handleComparison(CheckerContext &C, const SVal &RetVal, const SVal &LVal,
@@ -222,16 +223,23 @@
   void verifyRandomIncrOrDecr(CheckerContext &C, OverloadedOperatorKind Op,
   const SVal &RetVal, const SVal &LHS,
   const SVal &RHS) const;
+  void verifyMatch(CheckerContext &C, const SVal &Iter1,
+   const SVal &Iter2) const;
+
   void reportOutOfRangeBug(const StringRef &Message, const SVal &Val,
CheckerContext &C, ExplodedNode *ErrNode) const;
+  void reportMismatchedBug(const StringRef &Message, const SVal &Val1,
+   const SVal &Val2, CheckerContext &C,
+   ExplodedNode *ErrNode) const;
   void reportInvalidatedBug(const StringRef &Message, const SVal &Val,
 CheckerContext &C, ExplodedNode *ErrNode) const;
 
 public:
   IteratorChecker();
 
   enum CheckKind {
 CK_IteratorRangeChecker,
+CK_MismatchedIteratorChecker,
 CK_InvalidatedIteratorChecker,
 CK_NumCheckKinds
   };
@@ -321,6 +329,9 @@
   OutOfRangeBugType.reset(
   new BugType(this, "Iterator out of range", "Misuse of STL APIs"));
   OutOfRangeBugType->setSuppressOnSink(true);
+  MismatchedBugType.reset(
+  new BugType(this, "Iterator(s) mismatched", "Misuse of STL APIs"));
+  MismatchedBugType->setSuppressOnSink(true);
   InvalidatedBugType.reset(
   new BugType(this, "Iterator invalidated", "Misuse of STL APIs"));
   InvalidatedBugType->setSuppressOnSink(true);
@@ -369,6 +380,65 @@
 verifyDereference(C, Call.getArgSVal(0));
   }
 }
+  } else if (!isa(&Call)) {
+// The main purpose of iterators is to abstract away from different
+// containers and provide a (maybe limited) uniform access to them.
+// This implies that a

[PATCH] D42167: [clang-format] adds enclosing function detection to raw string formatting

2018-01-17 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 130177.
krasimir added a comment.

- Format a function


Repository:
  rC Clang

https://reviews.llvm.org/D42167

Files:
  docs/ClangFormatStyleOptions.rst
  include/clang/Format/Format.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/ContinuationIndenter.h
  lib/Format/Format.cpp
  unittests/Format/FormatTest.cpp
  unittests/Format/FormatTestRawStrings.cpp

Index: unittests/Format/FormatTestRawStrings.cpp
===
--- unittests/Format/FormatTestRawStrings.cpp
+++ unittests/Format/FormatTestRawStrings.cpp
@@ -65,23 +65,32 @@
   FormatStyle getRawStringPbStyleWithColumns(unsigned ColumnLimit) {
 FormatStyle Style = getLLVMStyle();
 Style.ColumnLimit = ColumnLimit;
-Style.RawStringFormats = {{/*Language=*/FormatStyle::LK_TextProto,
-   /*Delimiters=*/{"pb"},
-   /*BasedOnStyle=*/"google"}};
+Style.RawStringFormats = {
+{/*Language=*/FormatStyle::LK_TextProto,
+ /*Delimiters=*/{"pb"},
+ /*EnclosingFunctions=*/{},
+ /*BasedOnStyle=*/"google"},
+};
 return Style;
   }
 
   FormatStyle getRawStringLLVMCppStyleBasedOn(std::string BasedOnStyle) {
 FormatStyle Style = getLLVMStyle();
-Style.RawStringFormats = {{/*Language=*/FormatStyle::LK_Cpp,
-   /*Delimiters=*/{"cpp"}, BasedOnStyle}};
+Style.RawStringFormats = {
+{/*Language=*/FormatStyle::LK_Cpp,
+ /*Delimiters=*/{"cpp"},
+ /*EnclosingFunctions=*/{}, BasedOnStyle},
+};
 return Style;
   }
 
   FormatStyle getRawStringGoogleCppStyleBasedOn(std::string BasedOnStyle) {
 FormatStyle Style = getGoogleStyle(FormatStyle::LK_Cpp);
-Style.RawStringFormats = {{/*Language=*/FormatStyle::LK_Cpp,
-   /*Delimiters=*/{"cpp"}, BasedOnStyle}};
+Style.RawStringFormats = {
+{/*Language=*/FormatStyle::LK_Cpp,
+ /*Delimiters=*/{"cpp"},
+ /*EnclosingFunctions=*/{}, BasedOnStyle},
+};
 return Style;
   }
 
@@ -122,7 +131,7 @@
   EXPECT_EQ(0, parseConfiguration("---\n"
   "Language: Cpp\n"
   "BasedOnStyle: Google", &Style).value());
-  Style.RawStringFormats = {{FormatStyle::LK_Cpp, {"cpp"}, "llvm"}};
+  Style.RawStringFormats = {{FormatStyle::LK_Cpp, {"cpp"}, {}, "llvm"}};
   expect_eq(R"test(int* i = R"cpp(int* j = 0;)cpp";)test",
 format(R"test(int * i = R"cpp(int * j = 0;)cpp";)test", Style));
 }
@@ -720,6 +729,29 @@
getRawStringPbStyleWithColumns(20)));
 }
 
+TEST_F(FormatTestRawStrings, FormatsRawStringsWithEnclosingFunctionName) {
+  FormatStyle Style = getRawStringPbStyleWithColumns(40);
+  Style.RawStringFormats[0].EnclosingFunctions.push_back(
+  "PARSE_TEXT_PROTO");
+  Style.RawStringFormats[0].EnclosingFunctions.push_back("ParseTextProto");
+  expect_eq(R"test(a = PARSE_TEXT_PROTO(R"(key: value)");)test",
+format(R"test(a = PARSE_TEXT_PROTO(R"(key:value)");)test", Style));
+
+  expect_eq(R"test(
+a = PARSE_TEXT_PROTO /**/ (
+/**/ R"(key: value)");)test",
+format(R"test(
+a = PARSE_TEXT_PROTO/**/(/**/R"(key:value)");)test",
+   Style));
+
+  expect_eq(R"test(
+a = ParseTextProto(
+R"(key: value)");)test",
+format(R"test(
+a = ParseTextProto(R"(key:value)");)test",
+   Style));
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -10408,21 +10408,35 @@
 
   Style.RawStringFormats.clear();
   std::vector ExpectedRawStringFormats = {
-  {FormatStyle::LK_TextProto, {"pb", "proto"}, "llvm"},
-  {FormatStyle::LK_Cpp, {"cc", "cpp"}, "google"},
+  {
+  FormatStyle::LK_TextProto,
+  {"pb", "proto"},
+  {"PARSE_TEXT_PROTO"},
+  "llvm",
+  },
+  {
+  FormatStyle::LK_Cpp,
+  {"cc", "cpp"},
+  {"C_CODEBLOCK", "CPPEVAL"},
+  "",
+  },
   };
 
   CHECK_PARSE("RawStringFormats:\n"
   "  - Language: TextProto\n"
   "Delimiters:\n"
   "  - 'pb'\n"
   "  - 'proto'\n"
+  "EnclosingFunctions:\n"
+  "  - 'PARSE_TEXT_PROTO'\n"
   "BasedOnStyle: llvm\n"
   "  - Language: Cpp\n"
   "Delimiters:\n"
   "  - 'cc'\n"
   "  - 'cpp'\n"
-  "BasedOnStyle: google\n",
+  "EnclosingFunctions:\n"
+  "  - 'C_CODEBLOCK'\n"
+  "  - 'CPPEVAL'\n",
   RawStringFormats, ExpectedRawStringFormats);
 }
 
Index: lib/Format/Format.cpp
==

RE: [PATCH] D41837: Add Function multiversion to the release notes.

2018-01-17 Thread Keane, Erich via cfe-commits
It did not, I held it until just after the branch was made.

-Original Message-
From: hwennb...@google.com [mailto:hwennb...@google.com] On Behalf Of Hans 
Wennborg
Sent: Wednesday, January 17, 2018 4:47 AM
To: reviews+d41837+public+36225483e5851...@reviews.llvm.org
Cc: Keane, Erich ; Richard Smith 
; Aaron Ballman ; Eric 
Christopher ; cfe-commits 
Subject: Re: [PATCH] D41837: Add Function multiversion to the release notes.

Did this functionality land before the 6.0 branch, that is, should we copy the 
release notes to the branch?

Thanks
Hans

On Tue, Jan 9, 2018 at 12:37 AM, Erich Keane via Phabricator 
 wrote:
> This revision was automatically updated to reflect the committed changes.
> Closed by commit rC322043: Document attribute target multiversioning. 
> (authored by erichkeane, committed by ).
>
> Changed prior to commit:
>   https://reviews.llvm.org/D41837?vs=128982&id=128995#toc
>
> Repository:
>   rC Clang
>
> https://reviews.llvm.org/D41837
>
> Files:
>   docs/ReleaseNotes.rst
>   include/clang/Basic/AttrDocs.td
>
>
> Index: docs/ReleaseNotes.rst
> ===
> --- docs/ReleaseNotes.rst
> +++ docs/ReleaseNotes.rst
> @@ -80,6 +80,12 @@
>  Attribute Changes in Clang
>  --
>
> +- Clang now supports function multiversioning with attribute 'target' 
> +on ELF
> +  based x86/x86-64 environments by using indirect functions. This 
> +implementation
> +  has a few minor limitations over the GCC implementation for the 
> +sake of AST
> +  sanity, however it is otherwise compatible with existing code using 
> +this
> +  feature for GCC. Consult the documentation for the target attribute 
> +for more
> +  information.
>  - ...
>
>  Windows Support
> Index: include/clang/Basic/AttrDocs.td 
> ===
> --- include/clang/Basic/AttrDocs.td
> +++ include/clang/Basic/AttrDocs.td
> @@ -1474,6 +1474,24 @@
>  Example "subtarget features" from the x86 backend include: "mmx", 
> "sse", "sse4.2",  "avx", "xop" and largely correspond to the machine 
> specific options handled by  the front end.
> +
> +Additionally, this attribute supports function multiversioning for 
> +ELF based
> +x86/x86-64 targets, which can be used to create multiple 
> +implementations of the same function that will be resolved at runtime 
> +based on the priority of their ``target`` attribute strings. A 
> +function is considered a multiversioned function if either two 
> +declarations of the function have different ``target`` attribute
> +  strings, or if it has a ``target`` attribute string of ``default``.  
> +For
> +  example:
> +
> +  .. code-block:: c++
> +  __attribute__((target("arch=atom")))
> +  void foo() {} // will be called on 'atom' processors.
> +  __attribute__((target("default")))
> +  void foo() {} // will be called on any other processors.
> +
> +All multiversioned functions must contain a ``default`` (fallback) 
> +implementation, otherwise usages of the function are considered invalid.
> +Additionally, a function may not become multiversioned after its first use.
>  }];
>  }
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D41837: Add Function multiversion to the release notes.

2018-01-17 Thread Hans Wennborg via cfe-commits
OK, thanks for clarifying.

On Wed, Jan 17, 2018 at 4:18 PM, Keane, Erich  wrote:
> It did not, I held it until just after the branch was made.
>
> -Original Message-
> From: hwennb...@google.com [mailto:hwennb...@google.com] On Behalf Of Hans 
> Wennborg
> Sent: Wednesday, January 17, 2018 4:47 AM
> To: reviews+d41837+public+36225483e5851...@reviews.llvm.org
> Cc: Keane, Erich ; Richard Smith 
> ; Aaron Ballman ; Eric 
> Christopher ; cfe-commits 
> Subject: Re: [PATCH] D41837: Add Function multiversion to the release notes.
>
> Did this functionality land before the 6.0 branch, that is, should we copy 
> the release notes to the branch?
>
> Thanks
> Hans
>
> On Tue, Jan 9, 2018 at 12:37 AM, Erich Keane via Phabricator 
>  wrote:
>> This revision was automatically updated to reflect the committed changes.
>> Closed by commit rC322043: Document attribute target multiversioning. 
>> (authored by erichkeane, committed by ).
>>
>> Changed prior to commit:
>>   https://reviews.llvm.org/D41837?vs=128982&id=128995#toc
>>
>> Repository:
>>   rC Clang
>>
>> https://reviews.llvm.org/D41837
>>
>> Files:
>>   docs/ReleaseNotes.rst
>>   include/clang/Basic/AttrDocs.td
>>
>>
>> Index: docs/ReleaseNotes.rst
>> ===
>> --- docs/ReleaseNotes.rst
>> +++ docs/ReleaseNotes.rst
>> @@ -80,6 +80,12 @@
>>  Attribute Changes in Clang
>>  --
>>
>> +- Clang now supports function multiversioning with attribute 'target'
>> +on ELF
>> +  based x86/x86-64 environments by using indirect functions. This
>> +implementation
>> +  has a few minor limitations over the GCC implementation for the
>> +sake of AST
>> +  sanity, however it is otherwise compatible with existing code using
>> +this
>> +  feature for GCC. Consult the documentation for the target attribute
>> +for more
>> +  information.
>>  - ...
>>
>>  Windows Support
>> Index: include/clang/Basic/AttrDocs.td
>> ===
>> --- include/clang/Basic/AttrDocs.td
>> +++ include/clang/Basic/AttrDocs.td
>> @@ -1474,6 +1474,24 @@
>>  Example "subtarget features" from the x86 backend include: "mmx",
>> "sse", "sse4.2",  "avx", "xop" and largely correspond to the machine
>> specific options handled by  the front end.
>> +
>> +Additionally, this attribute supports function multiversioning for
>> +ELF based
>> +x86/x86-64 targets, which can be used to create multiple
>> +implementations of the same function that will be resolved at runtime
>> +based on the priority of their ``target`` attribute strings. A
>> +function is considered a multiversioned function if either two
>> +declarations of the function have different ``target`` attribute
>> +  strings, or if it has a ``target`` attribute string of ``default``.
>> +For
>> +  example:
>> +
>> +  .. code-block:: c++
>> +  __attribute__((target("arch=atom")))
>> +  void foo() {} // will be called on 'atom' processors.
>> +  __attribute__((target("default")))
>> +  void foo() {} // will be called on any other processors.
>> +
>> +All multiversioned functions must contain a ``default`` (fallback)
>> +implementation, otherwise usages of the function are considered invalid.
>> +Additionally, a function may not become multiversioned after its first use.
>>  }];
>>  }
>>
>>
>>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r322668 - [clangd] Avoid divide-by-zero

2018-01-17 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Wed Jan 17 07:25:55 2018
New Revision: 322668

URL: http://llvm.org/viewvc/llvm-project?rev=322668&view=rev
Log:
[clangd] Avoid divide-by-zero

Modified:
clang-tools-extra/trunk/clangd/FuzzyMatch.cpp

Modified: clang-tools-extra/trunk/clangd/FuzzyMatch.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/FuzzyMatch.cpp?rev=322668&r1=322667&r2=322668&view=diff
==
--- clang-tools-extra/trunk/clangd/FuzzyMatch.cpp (original)
+++ clang-tools-extra/trunk/clangd/FuzzyMatch.cpp Wed Jan 17 07:25:55 2018
@@ -75,7 +75,7 @@ static constexpr int PerfectBonus = 3; /
 
 FuzzyMatcher::FuzzyMatcher(StringRef Pattern)
 : PatN(std::min(MaxPat, Pattern.size())), CaseSensitive(false),
-  ScoreScale(float{1} / (PerfectBonus * PatN)), WordN(0) {
+  ScoreScale(PatN ? float{1} / (PerfectBonus * PatN) : 0), WordN(0) {
   memcpy(Pat, Pattern.data(), PatN);
   for (int I = 0; I < PatN; ++I) {
 LowPat[I] = lower(Pat[I]);


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


[PATCH] D41760: Introduce __builtin_load_no_speculate

2018-01-17 Thread Kristof Beyls via Phabricator via cfe-commits
kristof.beyls added a comment.

The API design has been discussed over the past weeks in detail on the gcc 
mailing list. As a result of that, we propose to adapt the API, to enable 
efficient code generation also on architectures that need to generate a barrier 
instruction to achieve the desired semantics.

The main change in the proposed API is to drop the failval parameter and to 
tweak the semantics to the below.
There is a more detailed rationale for these changes at 
https://gcc.gnu.org/ml/gcc-patches/2018-01/msg01546.html

I haven't updated the code to implement the new specification yet, but thought 
I'd share the new specification as soon as possible, while I find the time to 
adapt the implementation:

The signature of the new, polymorphic, builtin is:

  T __builtin_speculation_safe_load(const volatile T *ptr,
const volatile void *lower,
const volatile void *upper,
const volatile void *cmpptr)

T can be any integral type (signed or unsigned char, int, short, long, etc) or 
any pointer type.

This builtin provides a means to limit the extent to which a processor can 
continue speculative execution with the result of loading a value stored at 
ptr. The boundary conditions, described by cmpptr, lower_bound and upper_bound, 
define the conditions under which execution after the load can continue safely:

- When the builtin is not being executed speculatively:
  - if lower_bound <= cmpptr < upper_bound, the value at address ptr is 
returned.
  - if cmpptr is not within these bounds, the behaviour is undefined.
- When the builtin is being executed speculatively, either:
  - Execution of instructions following the builtin that have a dependency on 
the result of the intrinsic will be blocked, until the builtin is no longer 
executing speculatively. At this point, the semantics under point 1 above apply.
  - Speculation may continue using the value at address ptr as the return value 
of the builtin, if lower_bound <= cmpptr < upper_bound, or an unspecified 
constant value if cmpptr is outside these bounds.

The final argument, cmpptr, may be omitted if it is the same as ptr.

The builtin is supported for all architectures, but on machines where 
target-specific support for inhibiting speculation is not implemented, or not 
necessary, the compiler will emit a warning.

The pre-processor macro __HAVE_SPECULATION_SAFE_LOAD is defined with the value 
1 when the compiler supports this builtin.


https://reviews.llvm.org/D41760



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


[PATCH] D42174: [clangd] Refactored threading in ClangdServer

2018-01-17 Thread Benjamin Kramer via Phabricator via cfe-commits
bkramer added inline comments.



Comment at: clangd/ClangdServer.h:107
+/// A simple fixed-size thread pool implementation.
+class SimpleThreadPool {
 public:

What's so simple about it? Why not `clangd::ThreadPool`?

Also there's `llvm::ThreadPool`, what's the difference between them?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42174



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


[PATCH] D42167: [clang-format] adds enclosing function detection to raw string formatting

2018-01-17 Thread Benjamin Kramer via Phabricator via cfe-commits
bkramer accepted this revision.
bkramer added a comment.
This revision is now accepted and ready to land.

lgtm


Repository:
  rC Clang

https://reviews.llvm.org/D42167



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


[PATCH] D42116: [clang-tidy] Adding Fuchsia checker for trailing returns

2018-01-17 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang-tidy/fuchsia/TrailingReturnCheck.cpp:23
+  const auto *F = cast(T);
+  return F->hasTrailingReturn();
+}

I'd rewrite this as: `return 
Node.getType()->castAs()->hasTrailingReturnType();`



Comment at: clang-tidy/fuchsia/TrailingReturnCheck.cpp:26-28
+AST_MATCHER(QualType, isDecltypeType) {
+  return isa(Node.getTypePtr());
+}

Can you use something like this instead?

`extern const internal::VariadicDynCastAllOfMatcher 
decltypeType;`



Comment at: clang-tidy/fuchsia/TrailingReturnCheck.cpp:30
+
+void TrailingReturnCheck::registerMatchers(MatchFinder *Finder) {
+  // Functions which have trailing returns are disallowed, except for those 

The matchers should only be registered for C++11 and higher. This also fixes a 
bug where the `hasTrailingReturn()` would assert if given a K&R C function.



Comment at: clang-tidy/fuchsia/TrailingReturnCheck.cpp:31
+void TrailingReturnCheck::registerMatchers(MatchFinder *Finder) {
+  // Functions which have trailing returns are disallowed, except for those 
+  // using decltype specifiers and lambda with otherwise unutterable 

s/which/that



Comment at: clang-tidy/fuchsia/TrailingReturnCheck.cpp:45
+  if (const auto *D = Result.Nodes.getNodeAs("decl"))
+diag(D->getLocStart(), "trailing returns are disallowed");
+}

The "trailing returns" isn't worded like our other diagnostics. How about "a 
trailing return type is disallowed for this declaration" or something along 
those lines?



Comment at: clang-tidy/fuchsia/TrailingReturnCheck.h:19
+
+/// Functions which have trailing returns are disallowed, except for those 
+/// using decltype specifiers and lambda with otherwise unutterable 

s/which/that



Comment at: docs/ReleaseNotes.rst:70
+
+  Functions which have trailing returns are disallowed, except for those 
+  using decltype specifiers and lambda with otherwise unutterable 

s/which/that



Comment at: docs/clang-tidy/checks/fuchsia-trailing-return.rst:6
+
+Functions which have trailing returns are disallowed, except for those using 
+decltype specifiers and lambda with otherwise unutterable return types.

s/which/that


https://reviews.llvm.org/D42116



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


[PATCH] D16403: Add scope information to CFG

2018-01-17 Thread Maxim Ostapenko via Phabricator via cfe-commits
m.ostapenko updated this revision to Diff 130183.
m.ostapenko retitled this revision from "Add scope information to CFG for 
If/While/For/Do/Compound/CXXRangeFor statements" to "Add scope information to 
CFG".
m.ostapenko added a comment.

Some code cleanup + updated test case.


https://reviews.llvm.org/D16403

Files:
  include/clang/Analysis/AnalysisDeclContext.h
  include/clang/Analysis/CFG.h
  include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
  lib/Analysis/AnalysisDeclContext.cpp
  lib/Analysis/CFG.cpp
  lib/StaticAnalyzer/Core/AnalysisManager.cpp
  lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
  test/Analysis/analyzer-config.c
  test/Analysis/analyzer-config.cpp
  test/Analysis/scopes-cfg-output.cpp

Index: test/Analysis/scopes-cfg-output.cpp
===
--- /dev/null
+++ test/Analysis/scopes-cfg-output.cpp
@@ -0,0 +1,1171 @@
+// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -analyze -analyzer-checker=debug.DumpCFG -analyzer-config cfg-scopes=true %s > %t 2>&1
+// RUN: FileCheck --input-file=%t %s
+
+class A {
+public:
+// CHECK:  [B1 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:  [B0 (EXIT)]
+// CHECK-NEXT:   Preds (1): B1
+  A() {}
+
+// CHECK:  [B1 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:  [B0 (EXIT)]
+// CHECK-NEXT:   Preds (1): B1
+  ~A() {}
+
+// CHECK:  [B2 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B1
+// CHECK:  [B1]
+// CHECK-NEXT:   1: 1
+// CHECK-NEXT:   2: return [B1.1];
+// CHECK-NEXT:   Preds (1): B2
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:  [B0 (EXIT)]
+// CHECK-NEXT:   Preds (1): B1
+  operator int() const { return 1; }
+};
+
+int getX();
+extern const bool UV;
+
+// CHECK:  [B2 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B1
+// CHECK:  [B1]
+// CHECK-NEXT:   1: CFGScopeBegin(a)
+// CHECK-NEXT:   2:  (CXXConstructExpr, class A [2])
+// CHECK-NEXT:   3: A a[2];
+// CHECK-NEXT:   4:  (CXXConstructExpr, class A [0])
+// CHECK-NEXT:   5: A b[0];
+// CHECK-NEXT:   6: CFGScopeEnd(a)
+// CHECK-NEXT:   7: [B1.3].~A() (Implicit destructor)
+// CHECK-NEXT:   Preds (1): B2
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:  [B0 (EXIT)]
+// CHECK-NEXT:   Preds (1): B1
+void test_array() {
+  A a[2];
+  A b[0];
+}
+
+// CHECK:  [B2 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B1
+// CHECK:  [B1]
+// CHECK-NEXT:   1: CFGScopeBegin(a)
+// CHECK-NEXT:   2:  (CXXConstructExpr, class A)
+// CHECK-NEXT:   3: A a;
+// CHECK-NEXT:   4: CFGScopeBegin(c)
+// CHECK-NEXT:   5:  (CXXConstructExpr, class A)
+// CHECK-NEXT:   6: A c;
+// CHECK-NEXT:   7:  (CXXConstructExpr, class A)
+// CHECK-NEXT:   8: A d;
+// CHECK-NEXT:   9: CFGScopeEnd(c)
+// CHECK-NEXT:  10: [B1.8].~A() (Implicit destructor)
+// CHECK-NEXT:  11: [B1.6].~A() (Implicit destructor)
+// CHECK-NEXT:  12:  (CXXConstructExpr, class A)
+// CHECK-NEXT:  13: A b;
+// CHECK-NEXT:  14: CFGScopeEnd(a)
+// CHECK-NEXT:  15: [B1.13].~A() (Implicit destructor)
+// CHECK-NEXT:  16: [B1.3].~A() (Implicit destructor)
+// CHECK-NEXT:   Preds (1): B2
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:  [B0 (EXIT)]
+// CHECK-NEXT:   Preds (1): B1
+void test_scope() {
+  A a;
+  { A c;
+A d;
+  }
+  A b;
+}
+
+// CHECK:  [B4 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B3
+// CHECK:  [B1]
+// CHECK-NEXT:   1:  (CXXConstructExpr, class A)
+// CHECK-NEXT:   2: A c;
+// CHECK-NEXT:   3: CFGScopeEnd(a)
+// CHECK-NEXT:   4: [B1.2].~A() (Implicit destructor)
+// CHECK-NEXT:   5: [B3.5].~A() (Implicit destructor)
+// CHECK-NEXT:   6: [B3.3].~A() (Implicit destructor)
+// CHECK-NEXT:   Preds (1): B3
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:  [B2]
+// CHECK-NEXT:   1: return;
+// CHECK-NEXT:   2: CFGScopeEnd(a)
+// CHECK-NEXT:   3: [B3.5].~A() (Implicit destructor)
+// CHECK-NEXT:   4: [B3.3].~A() (Implicit destructor)
+// CHECK-NEXT:   Preds (1): B3
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:  [B3]
+// CHECK-NEXT:   1: CFGScopeBegin(a)
+// CHECK-NEXT:   2:  (CXXConstructExpr, class A)
+// CHECK-NEXT:   3: A a;
+// CHECK-NEXT:   4:  (CXXConstructExpr, class A)
+// CHECK-NEXT:   5: A b;
+// CHECK-NEXT:   6: UV
+// CHECK-NEXT:   7: [B3.6] (ImplicitCastExpr, LValueToRValue, _Bool)
+// CHECK-NEXT:   T: if [B3.7]
+// CHECK-NEXT:   Preds (1): B4
+// CHECK-NEXT:   Succs (2): B2 B1
+// CHECK:  [B0 (EXIT)]
+// CHECK-NEXT:   Preds (2): B1 B2
+void test_return() {
+  A a;
+  A b;
+  if (UV) return;
+  A c;
+}
+
+// CHECK:  [B5 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B4
+// CHECK:  [B1]
+// CHECK-NEXT:   1: CFGScopeEnd(b)
+// CHECK-NEXT:   2: [B4.8].~A() (Implicit destructor)
+// CHECK-NEXT:   3: CFGScopeEnd(a)
+// CHECK-NEXT:   4: [B4.3].~A() (Implicit destructor)
+// CHECK-NEXT:   Preds (2): B2 B3
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:  [B2]
+// CHECK-NEXT:   1: CFGScopeBegin(c)
+// CHECK-NEXT:   2:  (CXXConstructExpr, class A)
+// CHECK-NEXT:   3: A c;
+// CHECK-NEXT:   4: CFGScopeEnd(c)
+// CHECK-NEXT:   5: [B2.3].~A() (Implicit destructor)
+// CHECK-NEXT:  

[PATCH] D32860: [Analyzer] Iterator Checker - Part 6: Mismatched iterator checker for constructors and comparisons

2018-01-17 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 130186.
baloghadamsoftware added a comment.

Rebased.


https://reviews.llvm.org/D32860

Files:
  lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
  test/Analysis/mismatched-iterator.cpp

Index: test/Analysis/mismatched-iterator.cpp
===
--- test/Analysis/mismatched-iterator.cpp
+++ test/Analysis/mismatched-iterator.cpp
@@ -3,6 +3,10 @@
 
 #include "Inputs/system-header-simulator-cxx.h"
 
+void good_ctor(std::vector &v) {
+  std::vector new_v(v.cbegin(), v.cend()); // no-warning
+}
+
 void good_find(std::vector &v, int n) {
   std::find(v.cbegin(), v.cend(), n); // no-warning
 }
@@ -34,6 +38,14 @@
   std::find(v2.cbegin(), i0, n); // no-warning
 }
 
+void good_comparison(std::vector &v) {
+  if (v.cbegin() == v.cend()) {} // no-warning
+}
+
+void bad_ctor(std::vector &v1, std::vector &v2) {
+  std::vector new_v(v1.cbegin(), v2.cend()); // expected-warning{{Iterator access mismatched}}
+}
+
 void bad_find(std::vector &v1, std::vector &v2, int n) {
   std::find(v1.cbegin(), v2.cend(), n); // expected-warning{{Iterator access mismatched}}
 }
@@ -61,3 +73,8 @@
   std::find(v1.cbegin(), i0, n); // expected-warning{{Iterator access mismatched}}
 }
 
+void bad_comparison(std::vector &v1, std::vector &v2) {
+  if (v1.cbegin() != v2.cend()) { // expected-warning{{Iterator access mismatched}}
+*v1.cbegin();
+  }
+}
Index: lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
+++ lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
@@ -197,6 +197,7 @@
 
 class IteratorChecker
 : public Checker,
  check::PreStmt,
  check::PostStmt,
  check::LiveSymbols, check::DeadSymbols,
@@ -229,14 +230,19 @@
   void verifyRandomIncrOrDecr(CheckerContext &C, OverloadedOperatorKind Op,
   const SVal &RetVal, const SVal &LHS,
   const SVal &RHS) const;
+  void verifyMatch(CheckerContext &C, const SVal &Iter,
+   const MemRegion *Cont) const;
   void verifyMatch(CheckerContext &C, const SVal &Iter1,
const SVal &Iter2) const;
 
   void reportOutOfRangeBug(const StringRef &Message, const SVal &Val,
CheckerContext &C, ExplodedNode *ErrNode) const;
   void reportMismatchedBug(const StringRef &Message, const SVal &Val1,
const SVal &Val2, CheckerContext &C,
ExplodedNode *ErrNode) const;
+  void reportMismatchedBug(const StringRef &Message, const SVal &Val,
+   const MemRegion *Reg, CheckerContext &C,
+   ExplodedNode *ErrNode) const;
   void reportInvalidatedBug(const StringRef &Message, const SVal &Val,
 CheckerContext &C, ExplodedNode *ErrNode) const;
 
@@ -255,6 +261,7 @@
 
   void checkPreCall(const CallEvent &Call, CheckerContext &C) const;
   void checkPostCall(const CallEvent &Call, CheckerContext &C) const;
+  void checkPreStmt(const CXXConstructExpr *CCE, CheckerContext &C) const;
   void checkPreStmt(const CXXOperatorCallExpr *COCE, CheckerContext &C) const;
   void checkPostStmt(const MaterializeTemporaryExpr *MTE,
  CheckerContext &C) const;
@@ -278,6 +285,7 @@
 
 bool isIteratorType(const QualType &Type);
 bool isIterator(const CXXRecordDecl *CRD);
+bool isComparisonOperator(OverloadedOperatorKind OK);
 bool isBeginCall(const FunctionDecl *Func);
 bool isEndCall(const FunctionDecl *Func);
 bool isAssignmentOperator(OverloadedOperatorKind OK);
@@ -396,6 +404,28 @@
   } else {
 verifyDereference(C, Call.getArgSVal(0));
   }
+} else if (ChecksEnabled[CK_MismatchedIteratorChecker] &&
+   isComparisonOperator(Func->getOverloadedOperator())) {
+  // Check for comparisons of iterators of different containers
+  if (const auto *InstCall = dyn_cast(&Call)) {
+if (Call.getNumArgs() < 1)
+  return;
+
+if (!isIteratorType(InstCall->getCXXThisExpr()->getType()) ||
+!isIteratorType(Call.getArgExpr(0)->getType()))
+  return;
+
+verifyMatch(C, InstCall->getCXXThisVal(), Call.getArgSVal(0));
+  } else {
+if (Call.getNumArgs() < 2)
+  return;
+
+if (!isIteratorType(Call.getArgExpr(0)->getType()) ||
+!isIteratorType(Call.getArgExpr(1)->getType()))
+  return;
+
+verifyMatch(C, Call.getArgSVal(0), Call.getArgSVal(1));
+  }
 }
   } else if (!isa(&Call)) {
 // The main purpose of iterators is to abstract away from different
@@ -570,6 +600,31 @@
   }
 }
 
+void IteratorChecker::checkPreStmt(const CXXConstructExpr *CCE,
+   CheckerContext &C) const {
+  // Check match of first-last iterator pair in a constructor of 

[PATCH] D32859: [Analyzer] Iterator Checker - Part 5: Move Assignment of Containers

2018-01-17 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 130185.
baloghadamsoftware added a comment.

Rebased.


https://reviews.llvm.org/D32859

Files:
  lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
  test/Analysis/mismatched-iterator.cpp

Index: test/Analysis/mismatched-iterator.cpp
===
--- test/Analysis/mismatched-iterator.cpp
+++ test/Analysis/mismatched-iterator.cpp
@@ -15,11 +15,49 @@
   std::copy(v1.cbegin(), v1.cend(), v2.begin()); // no-warning
 }
 
+void good_move_find1(std::vector &v1, std::vector &v2, int n) {
+  auto i0 = v2.cbegin();
+  v1 = std::move(v2);
+  std::find(i0, v1.cend(), n); // no-warning
+}
+
+void good_move_find2(std::vector &v1, std::vector &v2, int n) {
+  auto i0 = --v2.cend();
+  v1 = std::move(v2);
+  std::find(i0, v1.cend(), n); // no-warning
+}
+
+void good_move_find3(std::vector &v1, std::vector &v2, int n) {
+  auto i0 = v2.cend();
+  v1 = std::move(v2);
+  v2.push_back(n);
+  std::find(v2.cbegin(), i0, n); // no-warning
+}
+
 void bad_find(std::vector &v1, std::vector &v2, int n) {
   std::find(v1.cbegin(), v2.cend(), n); // expected-warning{{Iterator access mismatched}}
 }
 
 void bad_find_first_of(std::vector &v1, std::vector &v2) {
   std::find_first_of(v1.cbegin(), v2.cend(), v2.cbegin(), v2.cend()); // expected-warning{{Iterator access mismatched}}
   std::find_first_of(v1.cbegin(), v1.cend(), v2.cbegin(), v1.cend()); // expected-warning{{Iterator access mismatched}}
 }
+
+void bad_move_find1(std::vector &v1, std::vector &v2, int n) {
+  auto i0 = v2.cbegin();
+  v1 = std::move(v2);
+  std::find(i0, v2.cend(), n); // expected-warning{{Iterator access mismatched}}
+}
+
+void bad_move_find2(std::vector &v1, std::vector &v2, int n) {
+  auto i0 = --v2.cend();
+  v1 = std::move(v2);
+  std::find(i0, v2.cend(), n); // expected-warning{{Iterator access mismatched}}
+}
+
+void bad_move_find3(std::vector &v1, std::vector &v2, int n) {
+  auto i0 = v2.cend();
+  v1 = std::move(v2);
+  std::find(v1.cbegin(), i0, n); // expected-warning{{Iterator access mismatched}}
+}
+
Index: lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
+++ lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
@@ -114,6 +114,10 @@
 return IteratorPosition(Cont, Valid, NewOf);
   }
 
+  IteratorPosition reAssign(const MemRegion *NewCont) const {
+return IteratorPosition(NewCont, Valid, Offset);
+  }
+
   bool operator==(const IteratorPosition &X) const {
 return Cont == X.Cont && Valid == X.Valid && Offset == X.Offset;
   }
@@ -219,7 +223,9 @@
  const SVal &Cont) const;
   void assignToContainer(CheckerContext &C, const Expr *CE, const SVal &RetVal,
  const MemRegion *Cont) const;
-  void handleAssign(CheckerContext &C, const SVal &Cont) const;
+  void handleAssign(CheckerContext &C, const SVal &Cont,
+const Expr *CE = nullptr,
+const SVal &OldCont = UndefinedVal()) const;
   void verifyRandomIncrOrDecr(CheckerContext &C, OverloadedOperatorKind Op,
   const SVal &RetVal, const SVal &LHS,
   const SVal &RHS) const;
@@ -317,6 +323,17 @@
 bool Equal);
 ProgramStateRef invalidateAllIteratorPositions(ProgramStateRef State,
const MemRegion *Cont);
+ProgramStateRef reassignAllIteratorPositions(ProgramStateRef State,
+ const MemRegion *Cont,
+ const MemRegion *NewCont);
+ProgramStateRef reassignAllIteratorPositionsUnless(ProgramStateRef State,
+   const MemRegion *Cont,
+   const MemRegion *NewCont,
+   SymbolRef Offset,
+   BinaryOperator::Opcode Opc);
+ProgramStateRef replaceSymbolInIteratorPositionsIf(
+ProgramStateRef State, SValBuilder &SVB, SymbolRef OldSym,
+SymbolRef NewSym, SymbolRef CondSym, BinaryOperator::Opcode Opc);
 const ContainerData *getContainerData(ProgramStateRef State,
   const MemRegion *Cont);
 ProgramStateRef setContainerData(ProgramStateRef State, const MemRegion *Cont,
@@ -453,7 +470,12 @@
 const auto Op = Func->getOverloadedOperator();
 if (isAssignmentOperator(Op)) {
   const auto *InstCall = dyn_cast(&Call);
-  handleAssign(C, InstCall->getCXXThisVal());
+  if (Func->getParamDecl(0)->getType()->isRValueReferenceType()) {
+handleAssign(C, InstCall->getCXXThisVal(), Call.getOriginExpr(),
+ Call.getArgSVal(0));
+  } else {
+handleAssign(C, InstCall->getCXXThisVal());
+  }
 } else if (isSimpleCompari

[PATCH] D42168: [OpenMP] Generate unique name for offloading entries

2018-01-17 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

After some investigation, I think this whole code is incorrect. We should not 
rely on the fact that there is no padding on some architectures and should mix 
the type generated by the Clang and initial value, generated by LLVM.


Repository:
  rC Clang

https://reviews.llvm.org/D42168



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


[PATCH] D42168: [OpenMP] Generate unique name for offloading entries

2018-01-17 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added a comment.

In https://reviews.llvm.org/D42168#978593, @ABataev wrote:

> After some investigation, I think this whole code is incorrect. We should not 
> rely on the fact that there is no padding on some architectures and should 
> mix the type generated by the Clang and initial value, generated by LLVM.


I'm not sure I understand what you mean. Do you refer to `auto Align = 
CharUnits::fromQuantity(1)`?


Repository:
  rC Clang

https://reviews.llvm.org/D42168



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


[PATCH] D42185: [ASTMatcher] Add isScoped matcher for enumDecl.

2018-01-17 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: bkramer.
Herald added a subscriber: klimek.

No doc update on the LibASTMatchersReference.html - The dump_ast_matchers.py
script has been broken since r318304.


Repository:
  rC Clang

https://reviews.llvm.org/D42185

Files:
  include/clang/ASTMatchers/ASTMatchers.h
  unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp


Index: unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -2029,5 +2029,12 @@
   cxxRecordDecl(hasDefinition(;
 }
 
+TEST(IsScopedEnum, MatchesScopedEnum) {
+  EXPECT_TRUE(matches("enum class X {};",
+  enumDecl(isScoped(;
+  EXPECT_TRUE(notMatches("enum X {};;",
+  enumDecl(isScoped(;
+}
+
 } // namespace ast_matchers
 } // namespace clang
Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -5864,6 +5864,17 @@
   return Node.hasDefinition();
 }
 
+/// \brief Matches C++11 scoped enum declaration.
+///
+/// Example matches Y (matcher = enumDecl(isScoped()))
+/// \code
+/// enum X {};
+/// enum class Y {};
+/// \endcode
+AST_MATCHER(EnumDecl, isScoped) {
+  return Node.isScoped();
+}
+
 } // namespace ast_matchers
 } // namespace clang
 


Index: unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -2029,5 +2029,12 @@
   cxxRecordDecl(hasDefinition(;
 }
 
+TEST(IsScopedEnum, MatchesScopedEnum) {
+  EXPECT_TRUE(matches("enum class X {};",
+  enumDecl(isScoped(;
+  EXPECT_TRUE(notMatches("enum X {};;",
+  enumDecl(isScoped(;
+}
+
 } // namespace ast_matchers
 } // namespace clang
Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -5864,6 +5864,17 @@
   return Node.hasDefinition();
 }
 
+/// \brief Matches C++11 scoped enum declaration.
+///
+/// Example matches Y (matcher = enumDecl(isScoped()))
+/// \code
+/// enum X {};
+/// enum class Y {};
+/// \endcode
+AST_MATCHER(EnumDecl, isScoped) {
+  return Node.isScoped();
+}
+
 } // namespace ast_matchers
 } // namespace clang
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D42157: [clang-cl] Let /FA output use intel assembly.

2018-01-17 Thread Yvan Roux via cfe-commits
Hi Nico,

On 17 January 2018 at 14:35, Nico Weber via Phabricator via
cfe-commits  wrote:
> thakis closed this revision.
> thakis added a comment.
>
> r322652, thanks!

This commit broke ARM bots:
http://lab.llvm.org:8011/builders/clang-cmake-armv7-a15/builds/14839

Cheers,
Yvan

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


r322672 - [Index] Fix GCC warning. This is silly, but no llvm_unreachable and no C99.

2018-01-17 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Wed Jan 17 07:57:14 2018
New Revision: 322672

URL: http://llvm.org/viewvc/llvm-project?rev=322672&view=rev
Log:
[Index] Fix GCC warning. This is silly, but no llvm_unreachable and no C99.

Modified:
cfe/trunk/tools/c-index-test/c-index-test.c

Modified: cfe/trunk/tools/c-index-test/c-index-test.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/c-index-test.c?rev=322672&r1=322671&r2=322672&view=diff
==
--- cfe/trunk/tools/c-index-test/c-index-test.c (original)
+++ cfe/trunk/tools/c-index-test/c-index-test.c Wed Jan 17 07:57:14 2018
@@ -724,13 +724,13 @@ static int lineCol_cmp(const void *p1, c
 }
 
 static CXString CursorToText(CXCursor Cursor) {
+  CXString text;
   switch (wanted_display_type) {
   case DisplayType_Spelling:
 return clang_getCursorSpelling(Cursor);
   case DisplayType_DisplayName:
 return clang_getCursorDisplayName(Cursor);
   case DisplayType_Pretty: {
-CXString text;
 CXPrintingPolicy Policy = clang_getCursorPrintingPolicy(Cursor);
 ModifyPrintingPolicyAccordingToEnv(Policy);
 text = clang_getCursorPrettyPrinted(Cursor, Policy);
@@ -738,6 +738,8 @@ static CXString CursorToText(CXCursor Cu
 return text;
   }
   }
+  assert(0 && "unknown display type"); // no llvm_unreachable in C.
+  return text; // garbage
 }
 
 static void PrintCursor(CXCursor Cursor, const char *CommentSchemaFile) {


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


[PATCH] D41074: [ClangFormat] ObjCSpaceBeforeProtocolList should be true in the google style

2018-01-17 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton added a comment.

Any way we can get an accept on this one?


Repository:
  rC Clang

https://reviews.llvm.org/D41074



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


r322674 - Attempt to fix test/Driver/masm.c on the ARM bots.

2018-01-17 Thread Nico Weber via cfe-commits
Author: nico
Date: Wed Jan 17 08:03:08 2018
New Revision: 322674

URL: http://llvm.org/viewvc/llvm-project?rev=322674&view=rev
Log:
Attempt to fix test/Driver/masm.c on the ARM bots.

Modified:
cfe/trunk/test/Driver/masm.c

Modified: cfe/trunk/test/Driver/masm.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/masm.c?rev=322674&r1=322673&r2=322674&view=diff
==
--- cfe/trunk/test/Driver/masm.c (original)
+++ cfe/trunk/test/Driver/masm.c Wed Jan 17 08:03:08 2018
@@ -2,7 +2,7 @@
 // RUN: %clang -target i386-unknown-linux -masm=att -S %s -### 2>&1 | 
FileCheck --check-prefix=CHECK-ATT %s
 // RUN: %clang -target i386-unknown-linux -S -masm=somerequired %s -### 2>&1 | 
FileCheck --check-prefix=CHECK-SOMEREQUIRED %s
 // RUN: %clang -target arm-unknown-eabi -S -masm=intel %s -### 2>&1 | 
FileCheck --check-prefix=CHECK-ARM %s
-// RUN: %clang_cl /FA -### -- %s 2>&1 | FileCheck --check-prefix=CHECK-CL %s
+// RUN: %clang_cl --target=x86_64 /FA -### -- %s 2>&1 | FileCheck 
--check-prefix=CHECK-CL %s
 
 int f() {
 // CHECK-INTEL: -x86-asm-syntax=intel


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


Re: r322549 - Squash -Wcovered-switch-default wairning

2018-01-17 Thread Sam McCall via cfe-commits
Fixed in r322672.
(Slightly awkwardly, because we don't have llvm_unreachable in C)

On Tue, Jan 16, 2018 at 11:52 PM, Galina Kistanova 
wrote:

> Hello Sam,
>
> This commit broke one of our builders:
> http://lab.llvm.org:8011/builders/ubuntu-gcc7.1-werror/builds/4517
>
> . . .
> FAILED: /usr/local/gcc-7.1/bin/gcc-7.1  -DGTEST_HAS_RTTI=0 -D_DEBUG
> -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS
> -D__STDC_LIMIT_MACROS -Itools/clang/tools/c-index-test
> -I/home/buildslave/am1i-slv2/ubuntu-gcc7.1-werror/llvm/tools/clang/tools/c-index-test
> -I/home/buildslave/am1i-slv2/ubuntu-gcc7.1-werror/llvm/tools/clang/include
> -Itools/clang/include -Iinclude -I/home/buildslave/am1i-slv2/
> ubuntu-gcc7.1-werror/llvm/include -fPIC -Werror -Werror=date-time -Wall
> -W -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers
> -pedantic -Wno-long-long -Wno-comment -ffunction-sections -fdata-sections
> -O3-UNDEBUG -std=gnu89 -MD -MT tools/clang/tools/c-index-
> test/CMakeFiles/c-index-test.dir/c-index-test.c.o -MF
> tools/clang/tools/c-index-test/CMakeFiles/c-index-test.dir/c-index-test.c.o.d
> -o tools/clang/tools/c-index-test/CMakeFiles/c-index-test.dir/c-index-test.c.o
> -c /home/buildslave/am1i-slv2/ubuntu-gcc7.1-werror/llvm/
> tools/clang/tools/c-index-test/c-index-test.c
> /home/buildslave/am1i-slv2/ubuntu-gcc7.1-werror/llvm/
> tools/clang/tools/c-index-test/c-index-test.c: In function ‘CursorToText’:
> /home/buildslave/am1i-slv2/ubuntu-gcc7.1-werror/llvm/
> tools/clang/tools/c-index-test/c-index-test.c:741:1: error: control
> reaches end of non-void function [-Werror=return-type]
>  }
>  ^
> cc1: all warnings being treated as errors
>
> Please have a look?
>
> Thanks
>
> Galina
>
> On Tue, Jan 16, 2018 at 4:54 AM, Sam McCall via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: sammccall
>> Date: Tue Jan 16 04:54:28 2018
>> New Revision: 322549
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=322549&view=rev
>> Log:
>> Squash -Wcovered-switch-default wairning
>>
>> Modified:
>> cfe/trunk/tools/c-index-test/c-index-test.c
>>
>> Modified: cfe/trunk/tools/c-index-test/c-index-test.c
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-
>> test/c-index-test.c?rev=322549&r1=322548&r2=322549&view=diff
>> 
>> ==
>> --- cfe/trunk/tools/c-index-test/c-index-test.c (original)
>> +++ cfe/trunk/tools/c-index-test/c-index-test.c Tue Jan 16 04:54:28 2018
>> @@ -729,8 +729,7 @@ static CXString CursorToText(CXCursor Cu
>>  return clang_getCursorSpelling(Cursor);
>>case DisplayType_DisplayName:
>>  return clang_getCursorDisplayName(Cursor);
>> -  case DisplayType_Pretty:
>> -  default: {
>> +  case DisplayType_Pretty: {
>>  CXString text;
>>  CXPrintingPolicy Policy = clang_getCursorPrintingPolicy(Cursor);
>>  ModifyPrintingPolicyAccordingToEnv(Policy);
>>
>>
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D42157: [clang-cl] Let /FA output use intel assembly.

2018-01-17 Thread Nico Weber via cfe-commits
r322674 attempts to fix.

On Wed, Jan 17, 2018 at 10:54 AM, Yvan Roux via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Hi Nico,
>
> On 17 January 2018 at 14:35, Nico Weber via Phabricator via
> cfe-commits  wrote:
> > thakis closed this revision.
> > thakis added a comment.
> >
> > r322652, thanks!
>
> This commit broke ARM bots:
> http://lab.llvm.org:8011/builders/clang-cmake-armv7-a15/builds/14839
>
> Cheers,
> Yvan
>
> >
> > https://reviews.llvm.org/D42157
> >
> >
> >
> > ___
> > cfe-commits mailing list
> > cfe-commits@lists.llvm.org
> > http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42168: [OpenMP] Generate unique name for offloading entries

2018-01-17 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

In https://reviews.llvm.org/D42168#978594, @Hahnfeld wrote:

> In https://reviews.llvm.org/D42168#978593, @ABataev wrote:
>
> > After some investigation, I think this whole code is incorrect. We should 
> > not rely on the fact that there is no padding on some architectures and 
> > should mix the type generated by the Clang and initial value, generated by 
> > LLVM.
>
>
> I'm not sure I understand what you mean. Do you refer to `auto Align = 
> CharUnits::fromQuantity(1)`?


Yes, this one too. But the main problem here is that we expect some layout of 
structure, though it may be different.


Repository:
  rC Clang

https://reviews.llvm.org/D42168



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


[PATCH] D42168: [OpenMP] Generate unique name for offloading entries

2018-01-17 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

Or, there is another one solution - mark `_tgt_offload_entry` record as packed.


Repository:
  rC Clang

https://reviews.llvm.org/D42168



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


[PATCH] D41991: [clangd] Always use preamble (even stale) for code completion

2018-01-17 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.
Herald added a reviewer: jkorous-apple.

Big +1 to the change here.
Just suggestions for the comments.




Comment at: clangd/CodeComplete.cpp:522
 
-  // Attempt to reuse the PCH from precompiled preamble, if it was built.
-  if (Preamble) {
-auto Bounds =
-ComputePreambleBounds(*CI->getLangOpts(), ContentsBuffer.get(), 0);
-if (!Preamble->CanReuse(*CI, ContentsBuffer.get(), Bounds, VFS.get()))
-  Preamble = nullptr;
-  }
-
+  // Note that we delibirately don't check if preamble is up-to-date. This
+  // operation is very expensive and we feel the right trade-off here is to

delibirately -> deliberately

Thanks for adding the motivation here! I think this can be a bit terser, but up 
to you.
e.g.
  // We reuse the preamble whether it's valid or not. This is a 
correctness/performance 
  // tradeoff: building without a preamble is slow, and completion is 
latency-sensitive.



Comment at: clangd/Compiler.h:39
+/// be consumed by the FrontendAction as it will have a pointer to the MainFile
+/// buffer that will only be deleted if BeginSourceFile is called.
 std::unique_ptr prepareCompilerInstance(

bkramer wrote:
> This comment is somewhat messy now. Can you rephrase it a bit?
+1, this has grown a bit unwieldy. Maybe:
  /// Creates a compiler which will build the provided file.
  /// The preamble will not be checked for validity - caller should do that if 
needed.
  /// The returned compiler's VFS may differ due to command-line flags.
  /// The returned value must be consumed by a FrontendAction to avoid leaking 
MainFile.
  /// May return null in error cases.



Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41991



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


Re: r321777 - PR35028: Retain duplicate alignas attributes in template instantiation.

2018-01-17 Thread Hans Wennborg via cfe-commits
Merged to 6.0 in r322676.

On Thu, Jan 4, 2018 at 2:02 AM, Richard Smith via cfe-commits
 wrote:
> Author: rsmith
> Date: Wed Jan  3 17:02:18 2018
> New Revision: 321777
>
> URL: http://llvm.org/viewvc/llvm-project?rev=321777&view=rev
> Log:
> PR35028: Retain duplicate alignas attributes in template instantiation.
>
> Modified:
> cfe/trunk/include/clang/Basic/Attr.td
> cfe/trunk/test/SemaTemplate/alignas.cpp
>
> Modified: cfe/trunk/include/clang/Basic/Attr.td
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=321777&r1=321776&r2=321777&view=diff
> ==
> --- cfe/trunk/include/clang/Basic/Attr.td (original)
> +++ cfe/trunk/include/clang/Basic/Attr.td Wed Jan  3 17:02:18 2018
> @@ -552,6 +552,7 @@ def Aligned : InheritableAttr {
>Keyword<"_Alignas">]>,
> Accessor<"isDeclspec",[Declspec<"align">]>];
>let Documentation = [Undocumented];
> +  let DuplicatesAllowedWhileMerging = 1;
>  }
>
>  def AlignValue : Attr {
>
> Modified: cfe/trunk/test/SemaTemplate/alignas.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/alignas.cpp?rev=321777&r1=321776&r2=321777&view=diff
> ==
> --- cfe/trunk/test/SemaTemplate/alignas.cpp (original)
> +++ cfe/trunk/test/SemaTemplate/alignas.cpp Wed Jan  3 17:02:18 2018
> @@ -21,3 +21,14 @@ struct C { char a[16]; };
>
>  static_assert(sizeof(my_union) == 16, "");
>  static_assert(alignof(my_union) == 8, "");
> +
> +namespace PR35028 {
> +  template struct alignas(X) alignas(long long) 
> alignas(long double) alignas(Alignment) Aligned {
> +union {
> +  long long align1;
> +  long double align2;
> +  char data[sizeof(X)];
> +};
> +  };
> +  Aligned a;
> +}
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42185: [ASTMatcher] Add isScoped matcher for enumDecl.

2018-01-17 Thread Benjamin Kramer via Phabricator via cfe-commits
bkramer accepted this revision.
bkramer added a comment.
This revision is now accepted and ready to land.

lg


Repository:
  rC Clang

https://reviews.llvm.org/D42185



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


[PATCH] D42168: [OpenMP] Generate unique name for offloading entries

2018-01-17 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

1. Please, mark the record as packed.
2. Tests




Comment at: lib/CodeGen/CGOpenMPRuntime.cpp:3576-3577
   EntryInit.addInt(CGM.Int32Ty, 0);
-  llvm::GlobalVariable *Entry =
-EntryInit.finishAndCreateGlobal(".omp_offloading.entry",
-Align,
-/*constant*/ true,
-llvm::GlobalValue::ExternalLinkage);
+  SmallString<128> EntryGblName(".omp_offloading.entry.");
+  EntryGblName += Name;
+  llvm::GlobalVariable *Entry = EntryInit.finishAndCreateGlobal(

Use `llvm::Twine` here instead.


Repository:
  rC Clang

https://reviews.llvm.org/D42168



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


Re: r321779 - PR35045: Convert injected-class-name to its corresponding simple-template-id

2018-01-17 Thread Hans Wennborg via cfe-commits
Merged to 6.0 in r322677.

On Thu, Jan 4, 2018 at 2:24 AM, Richard Smith via cfe-commits
 wrote:
> Author: rsmith
> Date: Wed Jan  3 17:24:17 2018
> New Revision: 321779
>
> URL: http://llvm.org/viewvc/llvm-project?rev=321779&view=rev
> Log:
> PR35045: Convert injected-class-name to its corresponding simple-template-id
> during template argument deduction.
>
> We already did this when the injected-class-name was in P, but missed the case
> where it was in A. This (probably) can't happen except in implicit deduction
> guides.
>
> Modified:
> cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
> cfe/trunk/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp?rev=321779&r1=321778&r2=321779&view=diff
> ==
> --- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Wed Jan  3 17:24:17 2018
> @@ -502,6 +502,10 @@ DeduceTemplateArguments(Sema &S,
>  SmallVectorImpl &Deduced) {
>assert(Arg.isCanonical() && "Argument type must be canonical");
>
> +  // Treat an injected-class-name as its underlying template-id.
> +  if (auto *Injected = dyn_cast(Arg))
> +Arg = Injected->getInjectedSpecializationType();
> +
>// Check whether the template argument is a dependent template-id.
>if (const TemplateSpecializationType *SpecArg
>  = dyn_cast(Arg)) {
>
> Modified: cfe/trunk/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp?rev=321779&r1=321778&r2=321779&view=diff
> ==
> --- cfe/trunk/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp 
> (original)
> +++ cfe/trunk/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp Wed 
> Jan  3 17:24:17 2018
> @@ -309,6 +309,17 @@ namespace dependent {
>template int New(int);
>  }
>
> +namespace injected_class_name {
> +  template struct A {
> +A();
> +template A(A);
> +  };
> +  A a;
> +  A b = a;
> +  using T = decltype(a);
> +  using T = decltype(b);
> +}
> +
>  #else
>
>  // expected-no-diagnostics
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r322678 - [clang-format] adds enclosing function detection to raw string formatting

2018-01-17 Thread Krasimir Georgiev via cfe-commits
Author: krasimir
Date: Wed Jan 17 08:17:26 2018
New Revision: 322678

URL: http://llvm.org/viewvc/llvm-project?rev=322678&view=rev
Log:
[clang-format] adds enclosing function detection to raw string formatting

Summary: This patch adds enclosing function detection to raw string formatting.

Reviewers: bkramer

Reviewed By: bkramer

Subscribers: klimek, cfe-commits

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

Modified:
cfe/trunk/docs/ClangFormatStyleOptions.rst
cfe/trunk/include/clang/Format/Format.h
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/lib/Format/ContinuationIndenter.h
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
cfe/trunk/unittests/Format/FormatTestRawStrings.cpp

Modified: cfe/trunk/docs/ClangFormatStyleOptions.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormatStyleOptions.rst?rev=322678&r1=322677&r2=322678&view=diff
==
--- cfe/trunk/docs/ClangFormatStyleOptions.rst (original)
+++ cfe/trunk/docs/ClangFormatStyleOptions.rst Wed Jan 17 08:17:26 2018
@@ -994,9 +994,9 @@ the configuration (without a prefix: ``A
 
 .. code-block:: c++
 
-  Constructor()
-  : initializer1(),
-initializer2()
+Constructor()
+: initializer1(),
+  initializer2()
 
   * ``BCIS_BeforeComma`` (in configuration: ``BeforeComma``)
 Break constructor initializers before the colon and commas, and align
@@ -1004,18 +1004,18 @@ the configuration (without a prefix: ``A
 
 .. code-block:: c++
 
-  Constructor()
-  : initializer1()
-  , initializer2()
+Constructor()
+: initializer1()
+, initializer2()
 
   * ``BCIS_AfterColon`` (in configuration: ``AfterColon``)
 Break constructor initializers after the colon and commas.
 
 .. code-block:: c++
 
-  Constructor() :
-  initializer1(),
-  initializer2()
+Constructor() :
+initializer1(),
+initializer2()
 
 
 
@@ -1201,7 +1201,8 @@ the configuration (without a prefix: ``A
 
   * ``IBS_Regroup`` (in configuration: ``Regroup``)
 Merge multiple ``#include`` blocks together and sort as one.
-Then split into groups based on category priority. See 
``IncludeCategories``.
+Then split into groups based on category priority. See
+``IncludeCategories``.
 
 .. code-block:: c++
 
@@ -1577,24 +1578,38 @@ the configuration (without a prefix: ``A
 
 
 **RawStringFormats** (``std::vector``)
-  Raw string delimiters denoting that the raw string contents are
-  code in a particular language and can be reformatted.
+  Defines hints for detecting supported languages code blocks in raw
+  strings.
+
+  A raw string with a matching delimiter or a matching enclosing function
+  name will be reformatted assuming the specified language based on the
+  style for that language defined in the .clang-format file. If no style has
+  been defined in the .clang-format file for the specific language, a
+  predefined style given by 'BasedOnStyle' is used. If 'BasedOnStyle' is not
+  found, the formatting is based on llvm style. A matching delimiter takes
+  precedence over a matching enclosing function name for determining the
+  language of the raw string contents.
 
-  A raw string with a matching delimiter will be reformatted assuming the
-  specified language based on a predefined style given by 'BasedOnStyle'.
-  If 'BasedOnStyle' is not found, the formatting is based on llvm style.
+  There should be at most one specification per language and each delimiter
+  and enclosing function should not occur in multiple specifications.
 
   To configure this in the .clang-format file, use:
 
   .. code-block:: yaml
 
 RawStringFormats:
-  - Delimiter: 'pb'
-Language:  TextProto
-BasedOnStyle: llvm
-  - Delimiter: 'proto'
-Language:  TextProto
-BasedOnStyle: google
+  - Language: TextProto
+  Delimiters:
+- 'pb'
+- 'proto'
+  EnclosingFunctions:
+- 'PARSE_TEXT_PROTO'
+  BasedOnStyle: google
+  - Language: Cpp
+  Delimiters:
+- 'cc'
+- 'cpp'
+  BasedOnStyle: llvm
 
 **ReflowComments** (``bool``)
   If ``true``, clang-format will attempt to re-flow comments.

Modified: cfe/trunk/include/clang/Format/Format.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=322678&r1=322677&r2=322678&view=diff
==
--- cfe/trunk/include/clang/Format/Format.h (original)
+++ cfe/trunk/include/clang/Format/Format.h Wed Jan 17 08:17:26 2018
@@ -1367,12 +1367,15 @@ struct FormatStyle {
 LanguageKind Language;
 /// \brief A list of raw string delimiters that match this language.
 std::vector Delimiters;
+/// \brief A list of enclosing function 

[PATCH] D42113: [clangd] Deduplicate symbols collected in global-symbol-builder tool.

2018-01-17 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.
Herald added a reviewer: jkorous-apple.



Comment at: clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp:109
+  // Deduplicate the result by key.
+  // FIXME(ioeric): we need a better way to merge symbols with the same key. 
For
+  // example, class forward-declarations can have the same key as the class

nit: this comment could be tightened up a bit:

  // FIXME(ioeric): Merge occurrences, rather than just dropping all but one.
  // Definitions and forward declarations have the same key and may both have 
information.
  // Usage count will need to be aggregated across occurrences, too.



Comment at: clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp:113
+  // would also need to aggregate signals like usage count when they are added.
+  llvm::StringMap ReducedSymbols;
   Executor->get()->getToolResults()->forEachResult(

nit: UniqueSymbols? "Reduce" makes sense from an MR perspective but there's not 
enough context.



Comment at: clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp:116
+  [&ReducedSymbols](llvm::StringRef Key, llvm::StringRef Value) {
+ReducedSymbols[Key] = Value;
+  });

picking the longest string might be better than random, but I'm not sure if 
it's enough to be worthwhile.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42113



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


[PATCH] D42167: [clang-format] adds enclosing function detection to raw string formatting

2018-01-17 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC322678: [clang-format] adds enclosing function detection to 
raw string formatting (authored by krasimir, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D42167?vs=130177&id=130191#toc

Repository:
  rC Clang

https://reviews.llvm.org/D42167

Files:
  docs/ClangFormatStyleOptions.rst
  include/clang/Format/Format.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/ContinuationIndenter.h
  lib/Format/Format.cpp
  unittests/Format/FormatTest.cpp
  unittests/Format/FormatTestRawStrings.cpp

Index: lib/Format/ContinuationIndenter.h
===
--- lib/Format/ContinuationIndenter.h
+++ lib/Format/ContinuationIndenter.h
@@ -38,10 +38,14 @@
 
 struct RawStringFormatStyleManager {
   llvm::StringMap DelimiterStyle;
+  llvm::StringMap EnclosingFunctionStyle;
 
   RawStringFormatStyleManager(const FormatStyle &CodeStyle);
 
-  llvm::Optional get(StringRef Delimiter) const;
+  llvm::Optional getDelimiterStyle(StringRef Delimiter) const;
+
+  llvm::Optional
+  getEnclosingFunctionStyle(StringRef EnclosingFunction) const;
 };
 
 class ContinuationIndenter {
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -105,32 +105,44 @@
 RawStringFormatStyleManager::RawStringFormatStyleManager(
 const FormatStyle &CodeStyle) {
   for (const auto &RawStringFormat : CodeStyle.RawStringFormats) {
-for (StringRef Delimiter : RawStringFormat.Delimiters) {
-  llvm::Optional LanguageStyle =
-  CodeStyle.GetLanguageStyle(RawStringFormat.Language);
-  if (!LanguageStyle) {
-FormatStyle PredefinedStyle;
-if (!getPredefinedStyle(RawStringFormat.BasedOnStyle,
-RawStringFormat.Language, &PredefinedStyle)) {
-  PredefinedStyle = getLLVMStyle();
-  PredefinedStyle.Language = RawStringFormat.Language;
-}
-LanguageStyle = PredefinedStyle;
+llvm::Optional LanguageStyle =
+CodeStyle.GetLanguageStyle(RawStringFormat.Language);
+if (!LanguageStyle) {
+  FormatStyle PredefinedStyle;
+  if (!getPredefinedStyle(RawStringFormat.BasedOnStyle,
+  RawStringFormat.Language, &PredefinedStyle)) {
+PredefinedStyle = getLLVMStyle();
+PredefinedStyle.Language = RawStringFormat.Language;
   }
-  LanguageStyle->ColumnLimit = CodeStyle.ColumnLimit;
+  LanguageStyle = PredefinedStyle;
+}
+LanguageStyle->ColumnLimit = CodeStyle.ColumnLimit;
+for (StringRef Delimiter : RawStringFormat.Delimiters) {
   DelimiterStyle.insert({Delimiter, *LanguageStyle});
 }
+for (StringRef EnclosingFunction : RawStringFormat.EnclosingFunctions) {
+  EnclosingFunctionStyle.insert({EnclosingFunction, *LanguageStyle});
+}
   }
 }
 
 llvm::Optional
-RawStringFormatStyleManager::get(StringRef Delimiter) const {
+RawStringFormatStyleManager::getDelimiterStyle(StringRef Delimiter) const {
   auto It = DelimiterStyle.find(Delimiter);
   if (It == DelimiterStyle.end())
 return None;
   return It->second;
 }
 
+llvm::Optional
+RawStringFormatStyleManager::getEnclosingFunctionStyle(
+StringRef EnclosingFunction) const {
+  auto It = EnclosingFunctionStyle.find(EnclosingFunction);
+  if (It == EnclosingFunctionStyle.end())
+return None;
+  return It->second;
+}
+
 ContinuationIndenter::ContinuationIndenter(const FormatStyle &Style,
const AdditionalKeywords &Keywords,
const SourceManager &SourceMgr,
@@ -1437,15 +1449,38 @@
   return Penalty;
 }
 
+// Returns the enclosing function name of a token, or the empty string if not
+// found.
+static StringRef getEnclosingFunctionName(const FormatToken &Current) {
+  // Look for: 'function(' or 'function(' before Current.
+  auto Tok = Current.getPreviousNonComment();
+  if (!Tok || !Tok->is(tok::l_paren))
+return "";
+  Tok = Tok->getPreviousNonComment();
+  if (!Tok)
+return "";
+  if (Tok->is(TT_TemplateCloser)) {
+Tok = Tok->MatchingParen;
+if (Tok)
+  Tok = Tok->getPreviousNonComment();
+  }
+  if (!Tok || !Tok->is(tok::identifier))
+return "";
+  return Tok->TokenText;
+}
+
 llvm::Optional
 ContinuationIndenter::getRawStringStyle(const FormatToken &Current,
 const LineState &State) {
   if (!Current.isStringLiteral())
 return None;
   auto Delimiter = getRawStringDelimiter(Current.TokenText);
   if (!Delimiter)
 return None;
-  auto RawStringStyle = RawStringFormats.get(*Delimiter);
+  auto RawStringStyle = RawStringFormats.getDelimiterStyle(*Delimiter);
+  if (!RawStringStyle)
+RawStringStyle = RawStringFormats.getEnclosingFunctionStyle(
+getEnclosing

[PATCH] D42167: [clang-format] adds enclosing function detection to raw string formatting

2018-01-17 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL322678: [clang-format] adds enclosing function detection to 
raw string formatting (authored by krasimir, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D42167

Files:
  cfe/trunk/docs/ClangFormatStyleOptions.rst
  cfe/trunk/include/clang/Format/Format.h
  cfe/trunk/lib/Format/ContinuationIndenter.cpp
  cfe/trunk/lib/Format/ContinuationIndenter.h
  cfe/trunk/lib/Format/Format.cpp
  cfe/trunk/unittests/Format/FormatTest.cpp
  cfe/trunk/unittests/Format/FormatTestRawStrings.cpp

Index: cfe/trunk/lib/Format/Format.cpp
===
--- cfe/trunk/lib/Format/Format.cpp
+++ cfe/trunk/lib/Format/Format.cpp
@@ -457,6 +457,7 @@
   static void mapping(IO &IO, FormatStyle::RawStringFormat &Format) {
 IO.mapOptional("Language", Format.Language);
 IO.mapOptional("Delimiters", Format.Delimiters);
+IO.mapOptional("EnclosingFunctions", Format.EnclosingFunctions);
 IO.mapOptional("BasedOnStyle", Format.BasedOnStyle);
   }
 };
@@ -705,6 +706,12 @@
   "textproto",
   "TEXTPROTO",
   },
+  /*EnclosingFunctionNames=*/
+   {
+   "EqualsProto",
+   "PARSE_TEXT_PROTO",
+   "ParseTextProto",
+   },
   /*BasedOnStyle=*/"google",
   }};
   GoogleStyle.SpacesBeforeTrailingComments = 2;
Index: cfe/trunk/lib/Format/ContinuationIndenter.h
===
--- cfe/trunk/lib/Format/ContinuationIndenter.h
+++ cfe/trunk/lib/Format/ContinuationIndenter.h
@@ -38,10 +38,14 @@
 
 struct RawStringFormatStyleManager {
   llvm::StringMap DelimiterStyle;
+  llvm::StringMap EnclosingFunctionStyle;
 
   RawStringFormatStyleManager(const FormatStyle &CodeStyle);
 
-  llvm::Optional get(StringRef Delimiter) const;
+  llvm::Optional getDelimiterStyle(StringRef Delimiter) const;
+
+  llvm::Optional
+  getEnclosingFunctionStyle(StringRef EnclosingFunction) const;
 };
 
 class ContinuationIndenter {
Index: cfe/trunk/lib/Format/ContinuationIndenter.cpp
===
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp
@@ -105,32 +105,44 @@
 RawStringFormatStyleManager::RawStringFormatStyleManager(
 const FormatStyle &CodeStyle) {
   for (const auto &RawStringFormat : CodeStyle.RawStringFormats) {
-for (StringRef Delimiter : RawStringFormat.Delimiters) {
-  llvm::Optional LanguageStyle =
-  CodeStyle.GetLanguageStyle(RawStringFormat.Language);
-  if (!LanguageStyle) {
-FormatStyle PredefinedStyle;
-if (!getPredefinedStyle(RawStringFormat.BasedOnStyle,
-RawStringFormat.Language, &PredefinedStyle)) {
-  PredefinedStyle = getLLVMStyle();
-  PredefinedStyle.Language = RawStringFormat.Language;
-}
-LanguageStyle = PredefinedStyle;
+llvm::Optional LanguageStyle =
+CodeStyle.GetLanguageStyle(RawStringFormat.Language);
+if (!LanguageStyle) {
+  FormatStyle PredefinedStyle;
+  if (!getPredefinedStyle(RawStringFormat.BasedOnStyle,
+  RawStringFormat.Language, &PredefinedStyle)) {
+PredefinedStyle = getLLVMStyle();
+PredefinedStyle.Language = RawStringFormat.Language;
   }
-  LanguageStyle->ColumnLimit = CodeStyle.ColumnLimit;
+  LanguageStyle = PredefinedStyle;
+}
+LanguageStyle->ColumnLimit = CodeStyle.ColumnLimit;
+for (StringRef Delimiter : RawStringFormat.Delimiters) {
   DelimiterStyle.insert({Delimiter, *LanguageStyle});
 }
+for (StringRef EnclosingFunction : RawStringFormat.EnclosingFunctions) {
+  EnclosingFunctionStyle.insert({EnclosingFunction, *LanguageStyle});
+}
   }
 }
 
 llvm::Optional
-RawStringFormatStyleManager::get(StringRef Delimiter) const {
+RawStringFormatStyleManager::getDelimiterStyle(StringRef Delimiter) const {
   auto It = DelimiterStyle.find(Delimiter);
   if (It == DelimiterStyle.end())
 return None;
   return It->second;
 }
 
+llvm::Optional
+RawStringFormatStyleManager::getEnclosingFunctionStyle(
+StringRef EnclosingFunction) const {
+  auto It = EnclosingFunctionStyle.find(EnclosingFunction);
+  if (It == EnclosingFunctionStyle.end())
+return None;
+  return It->second;
+}
+
 ContinuationIndenter::ContinuationIndenter(const FormatStyle &Style,
const AdditionalKeywords &Keywords,
const SourceManager &SourceMgr,
@@ -1437,15 +1449,38 @@
   return Penalty;
 }
 
+// Returns the enclosing function name of a token, or the empty string if not
+// found.
+static StringRef getEnclosingFunctionName(const FormatToken &Current) {
+  // Look for: 'function(' or 'function(' before Current.
+  auto Tok = Current.get

[PATCH] D42135: [Format] Improve ObjC header guessing heuristic

2018-01-17 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton updated this revision to Diff 130192.
benhamilton added a comment.

- Remove unused variable.


Repository:
  rC Clang

https://reviews.llvm.org/D42135

Files:
  lib/Format/Format.cpp
  unittests/Format/FormatTestObjC.cpp

Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -94,6 +94,66 @@
   Style = getStyle("LLVM", "a.h", "none", "void f() {}");
   ASSERT_TRUE((bool)Style);
   EXPECT_EQ(FormatStyle::LK_Cpp, Style->Language);
+
+  Style = getStyle("{}", "a.h", "none", "@interface Foo\n@end\n");
+  ASSERT_TRUE((bool)Style);
+  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
+
+  Style = getStyle("{}", "a.h", "none",
+   "const int interface = 1;\nconst int end = 2;\n");
+  ASSERT_TRUE((bool)Style);
+  EXPECT_EQ(FormatStyle::LK_Cpp, Style->Language);
+
+  Style = getStyle("{}", "a.h", "none", "@protocol Foo\n@end\n");
+  ASSERT_TRUE((bool)Style);
+  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
+
+  Style = getStyle("{}", "a.h", "none",
+   "const int protocol = 1;\nconst int end = 2;\n");
+  ASSERT_TRUE((bool)Style);
+  EXPECT_EQ(FormatStyle::LK_Cpp, Style->Language);
+
+  Style = getStyle("{}", "a.h", "none", "extern NSString *kFoo;\n");
+  ASSERT_TRUE((bool)Style);
+  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
+
+  Style =
+  getStyle("{}", "a.h", "none", "typedef NS_ENUM(NSInteger, Foo) {};\n");
+  ASSERT_TRUE((bool)Style);
+  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
+
+  Style = getStyle("{}", "a.h", "none", "enum Foo {};");
+  ASSERT_TRUE((bool)Style);
+  EXPECT_EQ(FormatStyle::LK_Cpp, Style->Language);
+
+  Style = getStyle("{}", "a.h", "none", "extern NSInteger Foo();\n");
+  ASSERT_TRUE((bool)Style);
+  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
+
+  Style =
+  getStyle("{}", "a.h", "none", "inline void Foo() { Log(@\"Foo\"); }\n");
+  ASSERT_TRUE((bool)Style);
+  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
+
+  Style =
+  getStyle("{}", "a.h", "none", "inline void Foo() { Log(\"Foo\"); }\n");
+  ASSERT_TRUE((bool)Style);
+  EXPECT_EQ(FormatStyle::LK_Cpp, Style->Language);
+
+  Style =
+  getStyle("{}", "a.h", "none", "inline void Foo() { id = @[1, 2, 3]; }\n");
+  ASSERT_TRUE((bool)Style);
+  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
+
+  Style = getStyle("{}", "a.h", "none",
+   "inline void Foo() { id foo = @{1: 2, 3: 4, 5: 6}; }\n");
+  ASSERT_TRUE((bool)Style);
+  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
+
+  Style = getStyle("{}", "a.h", "none",
+   "inline void Foo() { int foo[] = {1, 2, 3}; }\n");
+  ASSERT_TRUE((bool)Style);
+  EXPECT_EQ(FormatStyle::LK_Cpp, Style->Language);
 }
 
 TEST_F(FormatTestObjC, FormatObjCTryCatch) {
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -39,6 +39,7 @@
 #include "llvm/Support/YAMLTraits.h"
 #include 
 #include 
+#include 
 #include 
 
 #define DEBUG_TYPE "format-formatter"
@@ -1381,6 +1382,106 @@
   std::set DeletedTokens;
 };
 
+class ObjCHeaderStyleGuesser : public TokenAnalyzer {
+public:
+  ObjCHeaderStyleGuesser(const Environment &Env, const FormatStyle &Style)
+  : TokenAnalyzer(Env, Style), IsObjC(false) {}
+
+  std::pair
+  analyze(TokenAnnotator &Annotator,
+  SmallVectorImpl &AnnotatedLines,
+  FormatTokenLexer &Tokens) override {
+assert(Style.Language == FormatStyle::LK_Cpp);
+IsObjC = guessIsObjC(AnnotatedLines, Tokens.getKeywords());
+tooling::Replacements Result;
+return {Result, 0};
+  }
+
+  bool isObjC() { return IsObjC; }
+
+private:
+  static bool guessIsObjC(const SmallVectorImpl &AnnotatedLines,
+  const AdditionalKeywords &Keywords) {
+static const std::set FoundationIdentifiers = {
+"CGFloat",
+"NSAffineTransform",
+"NSArray",
+"NSAttributedString",
+"NSCache",
+"NSCharacterSet",
+"NSCountedSet",
+"NSData",
+"NSDataDetector",
+"NSDecimal",
+"NSDecimalNumber",
+"NSDictionary",
+"NSEdgeInsets",
+"NSHashTable",
+"NSIndexPath",
+"NSIndexSet",
+"NSInteger",
+"NSLocale",
+"NSMapTable",
+"NSMutableArray",
+"NSMutableAttributedString",
+"NSMutableCharacterSet",
+"NSMutableData",
+"NSMutableDictionary",
+"NSMutableIndexSet",
+"NSMutableOrderedSet",
+"NSMutableSet",
+"NSMutableString",
+"NSNumber",
+"NSNumberFormatter",
+"NSOrderedSet",
+"NSPoint",
+"NSPointerArray",
+"NSRange",
+"NSRect",
+"NSRegularExpression",
+"NSSet",
+"NSSize",
+"NSString",
+"NSUInteger",
+"NSURL",
+ 

Re: r322246 - [X86] Fix vpshrd builtins to require an ICE for their constant argument to match vpshld.

2018-01-17 Thread Hans Wennborg via cfe-commits
Merged to 6.0 in r322682.

On Thu, Jan 11, 2018 at 2:38 AM, Craig Topper via cfe-commits
 wrote:
> Author: ctopper
> Date: Wed Jan 10 17:38:00 2018
> New Revision: 322246
>
> URL: http://llvm.org/viewvc/llvm-project?rev=322246&view=rev
> Log:
> [X86] Fix vpshrd builtins to require an ICE for their constant argument to 
> match vpshld.
>
> Modified:
> cfe/trunk/include/clang/Basic/BuiltinsX86.def
>
> Modified: cfe/trunk/include/clang/Basic/BuiltinsX86.def
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsX86.def?rev=322246&r1=322245&r2=322246&view=diff
> ==
> --- cfe/trunk/include/clang/Basic/BuiltinsX86.def (original)
> +++ cfe/trunk/include/clang/Basic/BuiltinsX86.def Wed Jan 10 17:38:00 2018
> @@ -1357,15 +1357,15 @@ TARGET_BUILTIN(__builtin_ia32_vpshrdvw12
>  TARGET_BUILTIN(__builtin_ia32_vpshrdvw256_maskz, "V16sV16sV16sV16sUs", "", 
> "avx512vl,avx512vbmi2")
>  TARGET_BUILTIN(__builtin_ia32_vpshrdvw512_maskz, "V32sV32sV32sV32sUi", "", 
> "avx512vbmi2")
>
> -TARGET_BUILTIN(__builtin_ia32_vpshrdd128_mask, "V4iV4iV4iiV4iUc", "", 
> "avx512vl,avx512vbmi2")
> -TARGET_BUILTIN(__builtin_ia32_vpshrdd256_mask, "V8iV8iV8iiV8iUc", "", 
> "avx512vl,avx512vbmi2")
> -TARGET_BUILTIN(__builtin_ia32_vpshrdd512_mask, "V16iV16iV16iiV16iUs", "", 
> "avx512vbmi2")
> -TARGET_BUILTIN(__builtin_ia32_vpshrdq128_mask, "V2LLiV2LLiV2LLiiV2LLiUc", 
> "", "avx512vl,avx512vbmi2")
> -TARGET_BUILTIN(__builtin_ia32_vpshrdq256_mask, "V4LLiV4LLiV4LLiiV4LLiUc", 
> "", "avx512vl,avx512vbmi2")
> -TARGET_BUILTIN(__builtin_ia32_vpshrdq512_mask, "V8LLiV8LLiV8LLiiV8LLiUc", 
> "", "avx512vbmi2")
> -TARGET_BUILTIN(__builtin_ia32_vpshrdw128_mask, "V8sV8sV8siV8sUc", "", 
> "avx512vl,avx512vbmi2")
> -TARGET_BUILTIN(__builtin_ia32_vpshrdw256_mask, "V16sV16sV16siV16sUs", "", 
> "avx512vl,avx512vbmi2")
> -TARGET_BUILTIN(__builtin_ia32_vpshrdw512_mask, "V32sV32sV32siV32sUi", "", 
> "avx512vbmi2")
> +TARGET_BUILTIN(__builtin_ia32_vpshrdd128_mask, "V4iV4iV4iIiV4iUc", "", 
> "avx512vl,avx512vbmi2")
> +TARGET_BUILTIN(__builtin_ia32_vpshrdd256_mask, "V8iV8iV8iIiV8iUc", "", 
> "avx512vl,avx512vbmi2")
> +TARGET_BUILTIN(__builtin_ia32_vpshrdd512_mask, "V16iV16iV16iIiV16iUs", "", 
> "avx512vbmi2")
> +TARGET_BUILTIN(__builtin_ia32_vpshrdq128_mask, "V2LLiV2LLiV2LLiIiV2LLiUc", 
> "", "avx512vl,avx512vbmi2")
> +TARGET_BUILTIN(__builtin_ia32_vpshrdq256_mask, "V4LLiV4LLiV4LLiIiV4LLiUc", 
> "", "avx512vl,avx512vbmi2")
> +TARGET_BUILTIN(__builtin_ia32_vpshrdq512_mask, "V8LLiV8LLiV8LLiIiV8LLiUc", 
> "", "avx512vbmi2")
> +TARGET_BUILTIN(__builtin_ia32_vpshrdw128_mask, "V8sV8sV8sIiV8sUc", "", 
> "avx512vl,avx512vbmi2")
> +TARGET_BUILTIN(__builtin_ia32_vpshrdw256_mask, "V16sV16sV16sIiV16sUs", "", 
> "avx512vl,avx512vbmi2")
> +TARGET_BUILTIN(__builtin_ia32_vpshrdw512_mask, "V32sV32sV32sIiV32sUi", "", 
> "avx512vbmi2")
>
>  TARGET_BUILTIN(__builtin_ia32_pmovswb512_mask, "V32cV32sV32cUi", "", 
> "avx512bw")
>  TARGET_BUILTIN(__builtin_ia32_pmovuswb512_mask, "V32cV32sV32cUi", "", 
> "avx512bw")
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42185: [ASTMatcher] Add isScoped matcher for enumDecl.

2018-01-17 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman requested changes to this revision.
aaron.ballman added a comment.
This revision now requires changes to proceed.

This needs to be added to the dynamic matcher registry and also should not be 
commit until the documentation is generated for it.




Comment at: unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp:2035
+  enumDecl(isScoped(;
+  EXPECT_TRUE(notMatches("enum X {};;",
+  enumDecl(isScoped(;

Spurious semi colon.


Repository:
  rC Clang

https://reviews.llvm.org/D42185



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


[PATCH] D41852: [clang-tidy] Don't generate fix for argument constructed from std::initializer_list.

2018-01-17 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov accepted this revision.
ilya-biryukov added a comment.
This revision is now accepted and ready to land.

LGTM modulo a change to the 'initializer_list.h'. Do we really need it for this 
patch?




Comment at: test/clang-tidy/Inputs/modernize-smart-ptr/initializer_list.h:30
   vector(initializer_list<_E> init);
+  ~vector();
 };

Why do we need to add this destructor in this patch?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41852



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


[PATCH] D41991: [clangd] Always use preamble (even stale) for code completion

2018-01-17 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 130193.
ilya-biryukov added a comment.

- Rewrote the comment for prepareCompilerInstance
- Call CanReuse() and discard its results. We have clients that rely on having 
the stat() calls for files from preamble


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41991

Files:
  clangd/CodeComplete.cpp
  clangd/Compiler.cpp
  clangd/Compiler.h


Index: clangd/Compiler.h
===
--- clangd/Compiler.h
+++ clangd/Compiler.h
@@ -28,13 +28,16 @@
 const clang::Diagnostic &Info) override {}
 };
 
-/// Creates a CompilerInstance with the main file contens overridden.
-/// The preamble will be reused unless it is null.
-/// Note that the vfs::FileSystem inside returned instance may differ if
-/// additional file remappings occur in command-line arguments.
-/// On some errors, returns null. When non-null value is returned, it's 
expected
-/// to be consumed by the FrontendAction as it will have a pointer to the
-/// MainFile buffer that will only be deleted if BeginSourceFile is called.
+/// Creates a compiler instance, configured so that:
+///   - Contents of the parsed file are remapped to \p MainFile.
+///   - Preamble is overriden to use PCH passed to this function. It means the
+/// changes to the preamble headers or files included in the preamble are
+/// not visible to this compiler instance.
+///   - vfs::FileSystem is used for all underlying file accesses. The actual
+/// vfs used by the compiler may be an overlay over the passe vfs.
+/// Returns null on errors. When non-null value is returned, it is expected to
+/// be consumed by FrontendAction::BeginSourceFile to properly destroy buffer
+/// for \p MainFile.
 std::unique_ptr prepareCompilerInstance(
 std::unique_ptr, const PrecompiledPreamble *,
 std::unique_ptr MainFile,
Index: clangd/Compiler.cpp
===
--- clangd/Compiler.cpp
+++ clangd/Compiler.cpp
@@ -14,13 +14,6 @@
 namespace clang {
 namespace clangd {
 
-/// Creates a CompilerInstance from \p CI, with main buffer overriden to \p
-/// Buffer and arguments to read the PCH from \p Preamble, if \p Preamble is 
not
-/// null. Note that vfs::FileSystem inside returned instance may differ from \p
-/// VFS if additional file remapping were set in command-line arguments.
-/// On some errors, returns null. When non-null value is returned, it's 
expected
-/// to be consumed by the FrontendAction as it will have a pointer to the \p
-/// Buffer that will only be deleted if BeginSourceFile is called.
 std::unique_ptr
 prepareCompilerInstance(std::unique_ptr CI,
 const PrecompiledPreamble *Preamble,
@@ -36,7 +29,7 @@
   // NOTE: we use Buffer.get() when adding remapped files, so we have to make
   // sure it will be released if no error is emitted.
   if (Preamble) {
-Preamble->AddImplicitPreamble(*CI, VFS, Buffer.get());
+Preamble->OverridePreamble(*CI, VFS, Buffer.get());
   } else {
 CI->getPreprocessorOpts().addRemappedFile(
 CI->getFrontendOpts().Inputs[0].getFile(), Buffer.get());
Index: clangd/CodeComplete.cpp
===
--- clangd/CodeComplete.cpp
+++ clangd/CodeComplete.cpp
@@ -517,14 +517,20 @@
   std::unique_ptr ContentsBuffer =
   llvm::MemoryBuffer::getMemBufferCopy(Contents, FileName);
 
-  // Attempt to reuse the PCH from precompiled preamble, if it was built.
+  // Note that we delibirately allow outdated preambles. Not using the preamble
+  // makes code completion much slower and we feel that the right trade-off 
here
+  // is to trade correctness in some cases (preamble has not been rebuilt after
+  // changes to a file) for performance. Eventually the preamble will be 
rebuilt
+  // and code completion will produce correct results.
   if (Preamble) {
 auto Bounds =
 ComputePreambleBounds(*CI->getLangOpts(), ContentsBuffer.get(), 0);
-if (!Preamble->CanReuse(*CI, ContentsBuffer.get(), Bounds, VFS.get()))
-  Preamble = nullptr;
+// FIXME(ibiryukov): Remove this call to CanReuse() after we'll fix
+// clients relying on getting stats for preamble files during code
+// completion.
+// Note that results of CanReuse() are ignored, see the comment above.
+Preamble->CanReuse(*CI, ContentsBuffer.get(), Bounds, VFS.get());
   }
-
   auto Clang = prepareCompilerInstance(
   std::move(CI), Preamble, std::move(ContentsBuffer), std::move(PCHs),
   std::move(VFS), DummyDiagsConsumer);


Index: clangd/Compiler.h
===
--- clangd/Compiler.h
+++ clangd/Compiler.h
@@ -28,13 +28,16 @@
 const clang::Diagnostic &Info) override {}
 };
 
-/// Creates a CompilerInstance with the main file contens overridden.
-/// The preamble will be reused unless it is null.
-/// 

[PATCH] D41991: [clangd] Always use preamble (even stale) for code completion

2018-01-17 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 130194.
ilya-biryukov marked an inline comment as done.
ilya-biryukov added a comment.

- Use a better comment suggest by Sam


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41991

Files:
  clangd/CodeComplete.cpp
  clangd/Compiler.cpp
  clangd/Compiler.h


Index: clangd/Compiler.h
===
--- clangd/Compiler.h
+++ clangd/Compiler.h
@@ -28,13 +28,16 @@
 const clang::Diagnostic &Info) override {}
 };
 
-/// Creates a CompilerInstance with the main file contens overridden.
-/// The preamble will be reused unless it is null.
-/// Note that the vfs::FileSystem inside returned instance may differ if
-/// additional file remappings occur in command-line arguments.
-/// On some errors, returns null. When non-null value is returned, it's 
expected
-/// to be consumed by the FrontendAction as it will have a pointer to the
-/// MainFile buffer that will only be deleted if BeginSourceFile is called.
+/// Creates a compiler instance, configured so that:
+///   - Contents of the parsed file are remapped to \p MainFile.
+///   - Preamble is overriden to use PCH passed to this function. It means the
+/// changes to the preamble headers or files included in the preamble are
+/// not visible to this compiler instance.
+///   - vfs::FileSystem is used for all underlying file accesses. The actual
+/// vfs used by the compiler may be an overlay over the passe vfs.
+/// Returns null on errors. When non-null value is returned, it is expected to
+/// be consumed by FrontendAction::BeginSourceFile to properly destroy buffer
+/// for \p MainFile.
 std::unique_ptr prepareCompilerInstance(
 std::unique_ptr, const PrecompiledPreamble *,
 std::unique_ptr MainFile,
Index: clangd/Compiler.cpp
===
--- clangd/Compiler.cpp
+++ clangd/Compiler.cpp
@@ -14,13 +14,6 @@
 namespace clang {
 namespace clangd {
 
-/// Creates a CompilerInstance from \p CI, with main buffer overriden to \p
-/// Buffer and arguments to read the PCH from \p Preamble, if \p Preamble is 
not
-/// null. Note that vfs::FileSystem inside returned instance may differ from \p
-/// VFS if additional file remapping were set in command-line arguments.
-/// On some errors, returns null. When non-null value is returned, it's 
expected
-/// to be consumed by the FrontendAction as it will have a pointer to the \p
-/// Buffer that will only be deleted if BeginSourceFile is called.
 std::unique_ptr
 prepareCompilerInstance(std::unique_ptr CI,
 const PrecompiledPreamble *Preamble,
@@ -36,7 +29,7 @@
   // NOTE: we use Buffer.get() when adding remapped files, so we have to make
   // sure it will be released if no error is emitted.
   if (Preamble) {
-Preamble->AddImplicitPreamble(*CI, VFS, Buffer.get());
+Preamble->OverridePreamble(*CI, VFS, Buffer.get());
   } else {
 CI->getPreprocessorOpts().addRemappedFile(
 CI->getFrontendOpts().Inputs[0].getFile(), Buffer.get());
Index: clangd/CodeComplete.cpp
===
--- clangd/CodeComplete.cpp
+++ clangd/CodeComplete.cpp
@@ -517,14 +517,18 @@
   std::unique_ptr ContentsBuffer =
   llvm::MemoryBuffer::getMemBufferCopy(Contents, FileName);
 
-  // Attempt to reuse the PCH from precompiled preamble, if it was built.
+  // We reuse the preamble whether it's valid or not. This is a
+  // correctness/performance tradeoff: building without a preamble is slow, and
+  // completion is latency-sensitive.
   if (Preamble) {
 auto Bounds =
 ComputePreambleBounds(*CI->getLangOpts(), ContentsBuffer.get(), 0);
-if (!Preamble->CanReuse(*CI, ContentsBuffer.get(), Bounds, VFS.get()))
-  Preamble = nullptr;
+// FIXME(ibiryukov): Remove this call to CanReuse() after we'll fix
+// clients relying on getting stats for preamble files during code
+// completion.
+// Note that results of CanReuse() are ignored, see the comment above.
+Preamble->CanReuse(*CI, ContentsBuffer.get(), Bounds, VFS.get());
   }
-
   auto Clang = prepareCompilerInstance(
   std::move(CI), Preamble, std::move(ContentsBuffer), std::move(PCHs),
   std::move(VFS), DummyDiagsConsumer);


Index: clangd/Compiler.h
===
--- clangd/Compiler.h
+++ clangd/Compiler.h
@@ -28,13 +28,16 @@
 const clang::Diagnostic &Info) override {}
 };
 
-/// Creates a CompilerInstance with the main file contens overridden.
-/// The preamble will be reused unless it is null.
-/// Note that the vfs::FileSystem inside returned instance may differ if
-/// additional file remappings occur in command-line arguments.
-/// On some errors, returns null. When non-null value is returned, it's expected
-/// to be consumed by the FrontendAction as it will have a pointer 

[PATCH] D41991: [clangd] Always use preamble (even stale) for code completion

2018-01-17 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clangd/CodeComplete.cpp:522
 
-  // Attempt to reuse the PCH from precompiled preamble, if it was built.
-  if (Preamble) {
-auto Bounds =
-ComputePreambleBounds(*CI->getLangOpts(), ContentsBuffer.get(), 0);
-if (!Preamble->CanReuse(*CI, ContentsBuffer.get(), Bounds, VFS.get()))
-  Preamble = nullptr;
-  }
-
+  // Note that we delibirately don't check if preamble is up-to-date. This
+  // operation is very expensive and we feel the right trade-off here is to

sammccall wrote:
> delibirately -> deliberately
> 
> Thanks for adding the motivation here! I think this can be a bit terser, but 
> up to you.
> e.g.
>   // We reuse the preamble whether it's valid or not. This is a 
> correctness/performance 
>   // tradeoff: building without a preamble is slow, and completion is 
> latency-sensitive.
Looks much better, thanks.



Comment at: clangd/Compiler.h:39
+/// be consumed by the FrontendAction as it will have a pointer to the MainFile
+/// buffer that will only be deleted if BeginSourceFile is called.
 std::unique_ptr prepareCompilerInstance(

sammccall wrote:
> bkramer wrote:
> > This comment is somewhat messy now. Can you rephrase it a bit?
> +1, this has grown a bit unwieldy. Maybe:
>   /// Creates a compiler which will build the provided file.
>   /// The preamble will not be checked for validity - caller should do that 
> if needed.
>   /// The returned compiler's VFS may differ due to command-line flags.
>   /// The returned value must be consumed by a FrontendAction to avoid 
> leaking MainFile.
>   /// May return null in error cases.
> 
I rewrote the comment before reading your suggestion, it should be better now.
If it's still unclear, let me know.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41991



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


[PATCH] D42157: [clang-cl] Let /FA output use intel assembly.

2018-01-17 Thread Bill Seurer via Phabricator via cfe-commits
seurer added a comment.

This patch fails on powerpc64

http://lab.llvm.org:8011/builders/clang-ppc64be-linux/builds/14380
http://lab.llvm.org:8011/builders/clang-ppc64le-linux/builds/13463

- TEST 'Clang :: Driver/masm.c' FAILED 

Script:
---

/home/buildbots/ppc64le-clang-test/clang-ppc64le/stage1/bin/clang -target 
i386-unknown-linux -masm=intel -S 
/home/buildbots/ppc64le-clang-test/clang-ppc64le/llvm/tools/clang/test/Driver/masm.c
 -### 2>&1 | 
/home/buildbots/ppc64le-clang-test/clang-ppc64le/stage1/bin/FileCheck 
--check-prefix=CHECK-INTEL 
/home/buildbots/ppc64le-clang-test/clang-ppc64le/llvm/tools/clang/test/Driver/masm.c
/home/buildbots/ppc64le-clang-test/clang-ppc64le/stage1/bin/clang -target 
i386-unknown-linux -masm=att -S 
/home/buildbots/ppc64le-clang-test/clang-ppc64le/llvm/tools/clang/test/Driver/masm.c
 -### 2>&1 | 
/home/buildbots/ppc64le-clang-test/clang-ppc64le/stage1/bin/FileCheck 
--check-prefix=CHECK-ATT 
/home/buildbots/ppc64le-clang-test/clang-ppc64le/llvm/tools/clang/test/Driver/masm.c
/home/buildbots/ppc64le-clang-test/clang-ppc64le/stage1/bin/clang -target 
i386-unknown-linux -S -masm=somerequired 
/home/buildbots/ppc64le-clang-test/clang-ppc64le/llvm/tools/clang/test/Driver/masm.c
 -### 2>&1 | 
/home/buildbots/ppc64le-clang-test/clang-ppc64le/stage1/bin/FileCheck 
--check-prefix=CHECK-SOMEREQUIRED 
/home/buildbots/ppc64le-clang-test/clang-ppc64le/llvm/tools/clang/test/Driver/masm.c
/home/buildbots/ppc64le-clang-test/clang-ppc64le/stage1/bin/clang -target 
arm-unknown-eabi -S -masm=intel 
/home/buildbots/ppc64le-clang-test/clang-ppc64le/llvm/tools/clang/test/Driver/masm.c
 -### 2>&1 | 
/home/buildbots/ppc64le-clang-test/clang-ppc64le/stage1/bin/FileCheck 
--check-prefix=CHECK-ARM 
/home/buildbots/ppc64le-clang-test/clang-ppc64le/llvm/tools/clang/test/Driver/masm.c

/home/buildbots/ppc64le-clang-test/clang-ppc64le/stage1/bin/clang 
--driver-mode=cl /FA -### -- 
/home/buildbots/ppc64le-clang-test/clang-ppc64le/llvm/tools/clang/test/Driver/masm.c
 2>&1 | /home/buildbots/ppc64le-clang-test/clang-ppc64le/stage1/bin/FileCheck 
--check-prefix=CHECK-CL 
/home/buildbots/ppc64le-clang-test/clang-ppc64le/llvm/tools/clang/test/Driver/masm.c
-

Exit Code: 1

Command Output (stderr):


/home/buildbots/ppc64le-clang-test/clang-ppc64le/llvm/tools/clang/test/Driver/masm.c:12:14:
 error: expected string not found in input
// CHECK-CL: -x86-asm-syntax=intel

  ^

:1:1: note: scanning from here
clang version 7.0.0 (trunk 322652)
^
:6:930: note: possible intended match here
 "/home/buildbots/ppc64le-clang-test/clang-ppc64le/stage1/bin/clang-6.0" "-cc1" 
"-triple" "powerpc64le-pc-windows-msvc19.11.0" "-S" "-disable-free" 
"-main-file-name" "masm.c" "-mrelocation-model" "static" "-mthread-model" 
"posix" "-relaxed-aliasing" "-fmath-errno" "-masm-verbose" 
"-mconstructor-aliases" "-target-cpu" "ppc64le" "-mfloat-abi" "hard" "-D_MT" 
"-flto-visibility-public-std" "--dependent-lib=libcmt" 
"--dependent-lib=oldnames" "-stack-protector" "2" "-fdiagnostics-format" "msvc" 
"-dwarf-column-info" "-debugger-tuning=gdb" "-momit-leaf-frame-pointer" 
"-resource-dir" 
"/home/buildbots/ppc64le-clang-test/clang-ppc64le/stage1/lib/clang/7.0.0" 
"-internal-isystem" 
"/home/buildbots/ppc64le-clang-test/clang-ppc64le/stage1/lib/clang/7.0.0/include"
 "-fdebug-compilation-dir" 
"/home/buildbots/ppc64le-clang-test/clang-ppc64le/stage1/tools/clang/test/Driver"
 "-ferror-limit" "19" "-fmessage-length" "0" "-fno-signed-char" 
"-fno-use-cxa-atexit" "-fms-extensions" "-fms-compatibility" 
"-fms-compatibility-version=19.11" "-fdelayed-template-parsing" 
"-fobjc-runtime=gcc" "-fseh-exceptions" "-fdiagnostics-show-option" "-o" 
"masm.asm" "-x" "c" 
"/home/buildbots/ppc64le-clang-test/clang-ppc64le/llvm/tools/clang/test/Driver/masm.c"


https://reviews.llvm.org/D42157



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


[PATCH] D41991: [clangd] Always use preamble (even stale) for code completion

2018-01-17 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 130195.
ilya-biryukov added a comment.

- Fixed a typo


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41991

Files:
  clangd/CodeComplete.cpp
  clangd/Compiler.cpp
  clangd/Compiler.h


Index: clangd/Compiler.h
===
--- clangd/Compiler.h
+++ clangd/Compiler.h
@@ -28,13 +28,16 @@
 const clang::Diagnostic &Info) override {}
 };
 
-/// Creates a CompilerInstance with the main file contens overridden.
-/// The preamble will be reused unless it is null.
-/// Note that the vfs::FileSystem inside returned instance may differ if
-/// additional file remappings occur in command-line arguments.
-/// On some errors, returns null. When non-null value is returned, it's 
expected
-/// to be consumed by the FrontendAction as it will have a pointer to the
-/// MainFile buffer that will only be deleted if BeginSourceFile is called.
+/// Creates a compiler instance, configured so that:
+///   - Contents of the parsed file are remapped to \p MainFile.
+///   - Preamble is overriden to use PCH passed to this function. It means the
+/// changes to the preamble headers or files included in the preamble are
+/// not visible to this compiler instance.
+///   - vfs::FileSystem is used for all underlying file accesses. The actual
+/// vfs used by the compiler may be an overlay over the passed vfs.
+/// Returns null on errors. When non-null value is returned, it is expected to
+/// be consumed by FrontendAction::BeginSourceFile to properly destroy buffer
+/// for \p MainFile.
 std::unique_ptr prepareCompilerInstance(
 std::unique_ptr, const PrecompiledPreamble *,
 std::unique_ptr MainFile,
Index: clangd/Compiler.cpp
===
--- clangd/Compiler.cpp
+++ clangd/Compiler.cpp
@@ -14,13 +14,6 @@
 namespace clang {
 namespace clangd {
 
-/// Creates a CompilerInstance from \p CI, with main buffer overriden to \p
-/// Buffer and arguments to read the PCH from \p Preamble, if \p Preamble is 
not
-/// null. Note that vfs::FileSystem inside returned instance may differ from \p
-/// VFS if additional file remapping were set in command-line arguments.
-/// On some errors, returns null. When non-null value is returned, it's 
expected
-/// to be consumed by the FrontendAction as it will have a pointer to the \p
-/// Buffer that will only be deleted if BeginSourceFile is called.
 std::unique_ptr
 prepareCompilerInstance(std::unique_ptr CI,
 const PrecompiledPreamble *Preamble,
@@ -36,7 +29,7 @@
   // NOTE: we use Buffer.get() when adding remapped files, so we have to make
   // sure it will be released if no error is emitted.
   if (Preamble) {
-Preamble->AddImplicitPreamble(*CI, VFS, Buffer.get());
+Preamble->OverridePreamble(*CI, VFS, Buffer.get());
   } else {
 CI->getPreprocessorOpts().addRemappedFile(
 CI->getFrontendOpts().Inputs[0].getFile(), Buffer.get());
Index: clangd/CodeComplete.cpp
===
--- clangd/CodeComplete.cpp
+++ clangd/CodeComplete.cpp
@@ -517,14 +517,18 @@
   std::unique_ptr ContentsBuffer =
   llvm::MemoryBuffer::getMemBufferCopy(Contents, FileName);
 
-  // Attempt to reuse the PCH from precompiled preamble, if it was built.
+  // We reuse the preamble whether it's valid or not. This is a
+  // correctness/performance tradeoff: building without a preamble is slow, and
+  // completion is latency-sensitive.
   if (Preamble) {
 auto Bounds =
 ComputePreambleBounds(*CI->getLangOpts(), ContentsBuffer.get(), 0);
-if (!Preamble->CanReuse(*CI, ContentsBuffer.get(), Bounds, VFS.get()))
-  Preamble = nullptr;
+// FIXME(ibiryukov): Remove this call to CanReuse() after we'll fix
+// clients relying on getting stats for preamble files during code
+// completion.
+// Note that results of CanReuse() are ignored, see the comment above.
+Preamble->CanReuse(*CI, ContentsBuffer.get(), Bounds, VFS.get());
   }
-
   auto Clang = prepareCompilerInstance(
   std::move(CI), Preamble, std::move(ContentsBuffer), std::move(PCHs),
   std::move(VFS), DummyDiagsConsumer);


Index: clangd/Compiler.h
===
--- clangd/Compiler.h
+++ clangd/Compiler.h
@@ -28,13 +28,16 @@
 const clang::Diagnostic &Info) override {}
 };
 
-/// Creates a CompilerInstance with the main file contens overridden.
-/// The preamble will be reused unless it is null.
-/// Note that the vfs::FileSystem inside returned instance may differ if
-/// additional file remappings occur in command-line arguments.
-/// On some errors, returns null. When non-null value is returned, it's expected
-/// to be consumed by the FrontendAction as it will have a pointer to the
-/// MainFile buffer that will only be deleted if BeginSourceFi

[PATCH] D41991: [clangd] Always use preamble (even stale) for code completion

2018-01-17 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.

Thanks, LG!




Comment at: clangd/Compiler.h:39
+/// Returns null on errors. When non-null value is returned, it is expected to
+/// be consumed by FrontendAction::BeginSourceFile to properly destroy buffer
+/// for \p MainFile.

nit: "buffer for MainFile" -> "MainFile"
(since MainFile is already a buffer. also: less wrapping!)


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41991



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


r322687 - Update dump_ast_matchers for many recent changes.

2018-01-17 Thread Benjamin Kramer via cfe-commits
Author: d0k
Date: Wed Jan 17 08:50:14 2018
New Revision: 322687

URL: http://llvm.org/viewvc/llvm-project?rev=322687&view=rev
Log:
Update dump_ast_matchers for many recent changes.

The html file hasn't been updated in a long time so there are quite a
few changes in there. No matchers were removed though.

Modified:
cfe/trunk/docs/LibASTMatchersReference.html
cfe/trunk/docs/tools/dump_ast_matchers.py
cfe/trunk/include/clang/ASTMatchers/ASTMatchersMacros.h

Modified: cfe/trunk/docs/LibASTMatchersReference.html
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=322687&r1=322686&r2=322687&view=diff
==
--- cfe/trunk/docs/LibASTMatchersReference.html (original)
+++ cfe/trunk/docs/LibASTMatchersReference.html Wed Jan 17 08:50:14 2018
@@ -1255,10 +1255,9 @@ NSString's "alloc". This matcher should
 
 
 MatcherStmt>objcThrowStmtMatcherObjCAtThrowStmt>...
-Matches Objective-C 
@throw statements.
+Matches Objective-C 
statements.
 
-Example matches @throw
-  @throw obj;
+Example matches @throw obj;
 
 
 
@@ -1927,7 +1926,11 @@ Example matches a || b (matcher = binary
 
 
 
-MatcherCXXBoolLiteralExpr>equalsValueT  Value
+MatcherCXXBoolLiteralExpr>equalsbool Value
+
+
+
+MatcherCXXBoolLiteralExpr>equalsconst ValueT  Value
 Matches literals that are 
equal to the given value of type ValueT.
 
 Given
@@ -1953,10 +1956,6 @@ Usable as: MatcherCXXBoolLiteralExpr>equalsbool Value
-
-
-
 MatcherCXXBoolLiteralExpr>equalsdouble Value
 
 
@@ -2409,7 +2408,11 @@ Example: matches the implicit cast aroun
 
 
 
-MatcherCharacterLiteral>equalsValueT  Value
+MatcherCharacterLiteral>equalsbool Value
+
+
+
+MatcherCharacterLiteral>equalsconst ValueT  Value
 Matches literals that are 
equal to the given value of type ValueT.
 
 Given
@@ -2435,10 +2438,6 @@ Usable as: MatcherCharacterLiteral>equalsbool Value
-
-
-
 MatcherCharacterLiteral>equalsdouble Value
 
 
@@ -2673,7 +2672,7 @@ fieldDecl(isBitField())
 
 
 
-MatcherFloatingLiteral>equalsValueT  Value
+MatcherFloatingLiteral>equalsconst ValueT  Value
 Matches literals that are 
equal to the given value of type ValueT.
 
 Given
@@ -2811,6 +2810,7 @@ functionDecl(isExplicitTemplateSpecializ
 Usable as: MatcherFunctionDecl>,
 MatcherVarDecl>,
 MatcherCXXRecordDecl>
 
 
+
 MatcherFunctionDecl>isExternC
 Matches extern "C" 
function or variable declarations.
 
@@ -2827,6 +2827,7 @@ varDecl(isExternC())
   matches the declaration of x and y, but not the declaration of z.
 
 
+
 MatcherFunctionDecl>isInline
 Matches function and 
namespace declarations that are marked with
 the inline keyword.
@@ -2974,7 +2975,11 @@ functionProtoType(parameterCountIs(3))
 
 
 
-MatcherIntegerLiteral>equalsValueT  Value
+MatcherIntegerLiteral>equalsbool Value
+
+
+
+MatcherIntegerLiteral>equalsconst ValueT  Value
 Matches literals that are 
equal to the given value of type ValueT.
 
 Given
@@ -3000,10 +3005,6 @@ Usable as: MatcherIntegerLiteral>equalsbool Value
-
-
-
 MatcherIntegerLiteral>equalsdouble Value
 
 
@@ -3049,7 +3050,7 @@ void f() {}
 
 
 
-MatcherNamedDecl>hasNamestd::string  Name
+MatcherNa

  1   2   3   >