r318900 - Do not perform the analysis based warning if the warnings are ignored

2017-11-23 Thread Olivier Goffart via cfe-commits
Author: ogoffart
Date: Thu Nov 23 00:15:22 2017
New Revision: 318900

URL: http://llvm.org/viewvc/llvm-project?rev=318900&view=rev
Log:
Do not perform the analysis based warning if the warnings are ignored

This saves some cycles when compiling with "-w".

(Also fix a potential crash on invalid code for tools that tries to recover 
from some
errors, because analysis might compute the CFG which crashes if the code 
contains
invalid declaration. This does not happen normally with because we also don't 
perform
these analysis if there was an error.)

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

Modified:
cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
cfe/trunk/unittests/Tooling/ToolingTest.cpp

Modified: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp?rev=318900&r1=318899&r2=318900&view=diff
==
--- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp (original)
+++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp Thu Nov 23 00:15:22 2017
@@ -2080,10 +2080,10 @@ AnalysisBasedWarnings::IssueWarnings(sem
   // time.
   DiagnosticsEngine &Diags = S.getDiagnostics();
 
-  // Do not do any analysis for declarations in system headers if we are
-  // going to just ignore them.
-  if (Diags.getSuppressSystemWarnings() &&
-  S.SourceMgr.isInSystemHeader(D->getLocation()))
+  // Do not do any analysis if we are going to just ignore them.
+  if (Diags.getIgnoreAllWarnings() ||
+  (Diags.getSuppressSystemWarnings() &&
+   S.SourceMgr.isInSystemHeader(D->getLocation(
 return;
 
   // For code in dependent contexts, we'll do this at instantiation time.

Modified: cfe/trunk/unittests/Tooling/ToolingTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/ToolingTest.cpp?rev=318900&r1=318899&r2=318900&view=diff
==
--- cfe/trunk/unittests/Tooling/ToolingTest.cpp (original)
+++ cfe/trunk/unittests/Tooling/ToolingTest.cpp Thu Nov 23 00:15:22 2017
@@ -564,5 +564,31 @@ TEST(ClangToolTest, InjectDiagnosticCons
 }
 #endif
 
+TEST(runToolOnCode, TestResetDiagnostics) {
+  // This is a tool that resets the diagnostic during the compilation.
+  struct ResetDiagnosticAction : public clang::ASTFrontendAction {
+std::unique_ptr CreateASTConsumer(CompilerInstance &Compiler,
+   StringRef) override {
+  struct Consumer : public clang::ASTConsumer {
+bool HandleTopLevelDecl(clang::DeclGroupRef D) override {
+  auto &Diags = (*D.begin())->getASTContext().getDiagnostics();
+  // Ignore any error
+  Diags.Reset();
+  // Disable warnings because computing the CFG might crash.
+  Diags.setIgnoreAllWarnings(true);
+  return true;
+}
+  };
+  return llvm::make_unique();
+}
+  };
+
+  // Should not crash
+  EXPECT_FALSE(
+  runToolOnCode(new ResetDiagnosticAction,
+"struct Foo { Foo(int); ~Foo(); struct Fwd _fwd; };"
+"void func() { long x; Foo f(x); }"));
+}
+
 } // end namespace tooling
 } // end namespace clang


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


[PATCH] D40242: Do not perform the analysis based warning if all warnings are ignored

2017-11-23 Thread Olivier Goffart via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL318900: Do not perform the analysis based warning if the 
warnings are ignored (authored by ogoffart).

Changed prior to commit:
  https://reviews.llvm.org/D40242?vs=123720&id=124041#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D40242

Files:
  cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
  cfe/trunk/unittests/Tooling/ToolingTest.cpp


Index: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
===
--- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
+++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
@@ -2080,10 +2080,10 @@
   // time.
   DiagnosticsEngine &Diags = S.getDiagnostics();
 
-  // Do not do any analysis for declarations in system headers if we are
-  // going to just ignore them.
-  if (Diags.getSuppressSystemWarnings() &&
-  S.SourceMgr.isInSystemHeader(D->getLocation()))
+  // Do not do any analysis if we are going to just ignore them.
+  if (Diags.getIgnoreAllWarnings() ||
+  (Diags.getSuppressSystemWarnings() &&
+   S.SourceMgr.isInSystemHeader(D->getLocation(
 return;
 
   // For code in dependent contexts, we'll do this at instantiation time.
Index: cfe/trunk/unittests/Tooling/ToolingTest.cpp
===
--- cfe/trunk/unittests/Tooling/ToolingTest.cpp
+++ cfe/trunk/unittests/Tooling/ToolingTest.cpp
@@ -564,5 +564,31 @@
 }
 #endif
 
+TEST(runToolOnCode, TestResetDiagnostics) {
+  // This is a tool that resets the diagnostic during the compilation.
+  struct ResetDiagnosticAction : public clang::ASTFrontendAction {
+std::unique_ptr CreateASTConsumer(CompilerInstance &Compiler,
+   StringRef) override {
+  struct Consumer : public clang::ASTConsumer {
+bool HandleTopLevelDecl(clang::DeclGroupRef D) override {
+  auto &Diags = (*D.begin())->getASTContext().getDiagnostics();
+  // Ignore any error
+  Diags.Reset();
+  // Disable warnings because computing the CFG might crash.
+  Diags.setIgnoreAllWarnings(true);
+  return true;
+}
+  };
+  return llvm::make_unique();
+}
+  };
+
+  // Should not crash
+  EXPECT_FALSE(
+  runToolOnCode(new ResetDiagnosticAction,
+"struct Foo { Foo(int); ~Foo(); struct Fwd _fwd; };"
+"void func() { long x; Foo f(x); }"));
+}
+
 } // end namespace tooling
 } // end namespace clang


Index: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
===
--- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
+++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
@@ -2080,10 +2080,10 @@
   // time.
   DiagnosticsEngine &Diags = S.getDiagnostics();
 
-  // Do not do any analysis for declarations in system headers if we are
-  // going to just ignore them.
-  if (Diags.getSuppressSystemWarnings() &&
-  S.SourceMgr.isInSystemHeader(D->getLocation()))
+  // Do not do any analysis if we are going to just ignore them.
+  if (Diags.getIgnoreAllWarnings() ||
+  (Diags.getSuppressSystemWarnings() &&
+   S.SourceMgr.isInSystemHeader(D->getLocation(
 return;
 
   // For code in dependent contexts, we'll do this at instantiation time.
Index: cfe/trunk/unittests/Tooling/ToolingTest.cpp
===
--- cfe/trunk/unittests/Tooling/ToolingTest.cpp
+++ cfe/trunk/unittests/Tooling/ToolingTest.cpp
@@ -564,5 +564,31 @@
 }
 #endif
 
+TEST(runToolOnCode, TestResetDiagnostics) {
+  // This is a tool that resets the diagnostic during the compilation.
+  struct ResetDiagnosticAction : public clang::ASTFrontendAction {
+std::unique_ptr CreateASTConsumer(CompilerInstance &Compiler,
+   StringRef) override {
+  struct Consumer : public clang::ASTConsumer {
+bool HandleTopLevelDecl(clang::DeclGroupRef D) override {
+  auto &Diags = (*D.begin())->getASTContext().getDiagnostics();
+  // Ignore any error
+  Diags.Reset();
+  // Disable warnings because computing the CFG might crash.
+  Diags.setIgnoreAllWarnings(true);
+  return true;
+}
+  };
+  return llvm::make_unique();
+}
+  };
+
+  // Should not crash
+  EXPECT_FALSE(
+  runToolOnCode(new ResetDiagnosticAction,
+"struct Foo { Foo(int); ~Foo(); struct Fwd _fwd; };"
+"void func() { long x; Foo f(x); }"));
+}
+
 } // end namespace tooling
 } // end namespace clang
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D39903: [libclang] Allow pretty printing declarations

2017-11-23 Thread Nikolai Kosjar via Phabricator via cfe-commits
nik added a comment.

Ping, please review or add more appropriate reviewers.


https://reviews.llvm.org/D39903



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


[PATCH] D40023: [RISCV] Implement ABI lowering

2017-11-23 Thread David Majnemer via Phabricator via cfe-commits
majnemer added a comment.

So how does something like the following work:

  union U { float f; int i; };
  void f(union U u);

The flattening described in 
https://github.com/riscv/riscv-elf-psabi-doc/blob/master/riscv-elf.md#hardware-floating-point-calling-convention
 makes sense for arrays and structs but I couldn't find where unions were 
described.


https://reviews.llvm.org/D40023



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


[PATCH] D40023: [RISCV] Implement ABI lowering

2017-11-23 Thread Alex Bradbury via Phabricator via cfe-commits
asb added a comment.

In https://reviews.llvm.org/D40023#933464, @majnemer wrote:

> So how does something like the following work:
>
>   union U { float f; int i; };
>   void f(union U u);
>   
>
> The flattening described in 
> https://github.com/riscv/riscv-elf-psabi-doc/blob/master/riscv-elf.md#hardware-floating-point-calling-convention
>  makes sense for arrays and structs but I couldn't find where unions were 
> described.


You're right that's not currently described - I have an issue tracking this 
here: https://github.com/riscv/riscv-elf-psabi-doc/issues/24. Last time I tried 
to check gcc behaviour it seemed that such cases would be passed according to 
the integer calling convention, but I'd be happier if one of the GCC devs would 
confirm.


https://reviews.llvm.org/D40023



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


[PATCH] D40301: [clangd] Ensure preamble outlives the AST

2017-11-23 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/ClangdUnit.h:51
 
+struct PreambleData;
+

can you move the definition here to avoid the extra decl?
(I tend to find this more readable and the struct is small, but if you prefer 
"top-down" that's fine too)


https://reviews.llvm.org/D40301



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


[PATCH] D39882: [clangd] Filter completion results by fuzzy-matching identifiers.

2017-11-23 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 124043.
sammccall added a comment.

Rebase


https://reviews.llvm.org/D39882

Files:
  clangd/ClangdUnit.cpp
  unittests/clangd/ClangdTests.cpp

Index: unittests/clangd/ClangdTests.cpp
===
--- unittests/clangd/ClangdTests.cpp
+++ unittests/clangd/ClangdTests.cpp
@@ -742,6 +742,61 @@
   EXPECT_FALSE(ContainsItem(Results, "CCC"));
 }
 
+TEST_F(ClangdCompletionTest, Filter) {
+  MockFSProvider FS;
+  MockCompilationDatabase CDB(/*AddFreestandingFlag=*/true);
+  CDB.ExtraClangFlags.push_back("-xc++");
+  ErrorCheckingDiagConsumer DiagConsumer;
+  clangd::CodeCompleteOptions Opts;
+  ClangdServer Server(CDB, DiagConsumer, FS, getDefaultAsyncThreadsCount(),
+  /*StorePreamblesInMemory=*/true, Opts,
+  EmptyLogger::getInstance());
+
+  auto FooCpp = getVirtualTestFilePath("foo.cpp");
+  FS.Files[FooCpp] = "";
+  FS.ExpectedFile = FooCpp;
+  const char *Body = R"cpp(
+int Abracadabra;
+int Alakazam;
+struct S {
+  int FooBar;
+  int FooBaz;
+  int Qux;
+};
+  )cpp";
+  auto Complete = [&](StringRef Query) {
+StringWithPos Completion = parseTextMarker(
+formatv("{0} int main() { {1}{{complete}} }", Body, Query).str(),
+"complete");
+Server.addDocument(FooCpp, Completion.Text);
+return Server
+.codeComplete(FooCpp, Completion.MarkerPos, StringRef(Completion.Text))
+.get()
+.Value;
+  };
+
+  auto Foba = Complete("S().Foba");
+  EXPECT_TRUE(ContainsItem(Foba, "FooBar"));
+  EXPECT_TRUE(ContainsItem(Foba, "FooBaz"));
+  EXPECT_FALSE(ContainsItem(Foba, "Qux"));
+
+  auto FR = Complete("S().FR");
+  EXPECT_TRUE(ContainsItem(FR, "FooBar"));
+  EXPECT_FALSE(ContainsItem(FR, "FooBaz"));
+  EXPECT_FALSE(ContainsItem(FR, "Qux"));
+
+  auto Op = Complete("S().opr");
+  EXPECT_TRUE(ContainsItem(Op, "operator="));
+
+  auto Aaa = Complete("aaa");
+  EXPECT_TRUE(ContainsItem(Aaa, "Abracadabra"));
+  EXPECT_TRUE(ContainsItem(Aaa, "Alakazam"));
+
+  auto UA = Complete("_a");
+  EXPECT_TRUE(ContainsItem(UA, "static_cast"));
+  EXPECT_FALSE(ContainsItem(UA, "Abracadabra"));
+}
+
 TEST_F(ClangdCompletionTest, CompletionOptions) {
   MockFSProvider FS;
   ErrorCheckingDiagConsumer DiagConsumer;
Index: clangd/ClangdUnit.cpp
===
--- clangd/ClangdUnit.cpp
+++ clangd/ClangdUnit.cpp
@@ -434,9 +434,13 @@
   void ProcessCodeCompleteResults(Sema &S, CodeCompletionContext Context,
   CodeCompletionResult *Results,
   unsigned NumResults) override final {
+StringRef Filter = S.getPreprocessor().getCodeCompletionFilter();
 std::priority_queue Candidates;
 for (unsigned I = 0; I < NumResults; ++I) {
-  Candidates.emplace(Results[I]);
+  auto &Result = Results[I];
+  if (!Filter.empty() && !fuzzyMatch(S, Context, Filter, Result))
+continue;
+  Candidates.emplace(Result);
   if (ClangdOpts.Limit && Candidates.size() > ClangdOpts.Limit) {
 Candidates.pop();
 Items.isIncomplete = true;
@@ -459,6 +463,41 @@
   CodeCompletionTUInfo &getCodeCompletionTUInfo() override { return CCTUInfo; }
 
 private:
+  bool fuzzyMatch(Sema &S, const CodeCompletionContext &CCCtx, StringRef Filter,
+  CodeCompletionResult Result) {
+switch (Result.Kind) {
+case CodeCompletionResult::RK_Declaration:
+  if (auto *ID = Result.Declaration->getIdentifier())
+return fuzzyMatch(Filter, ID->getName());
+  break;
+case CodeCompletionResult::RK_Keyword:
+  return fuzzyMatch(Filter, Result.Keyword);
+case CodeCompletionResult::RK_Macro:
+  return fuzzyMatch(Filter, Result.Macro->getName());
+case CodeCompletionResult::RK_Pattern:
+  return fuzzyMatch(Filter, Result.Pattern->getTypedText());
+}
+auto *CCS = Result.CreateCodeCompletionString(
+S, CCCtx, *Allocator, CCTUInfo, /*IncludeBriefComments=*/false);
+return fuzzyMatch(Filter, CCS->getTypedText());
+  }
+
+  // Checks whether Target matches the Filter.
+  // Currently just requires a case-insensitive subsequence match.
+  // FIXME: make stricter and word-based: 'unique_ptr' should not match 'que'.
+  // FIXME: return a score to be incorporated into ranking.
+  static bool fuzzyMatch(StringRef Filter, StringRef Target) {
+llvm::errs() << "match " << Target << " against " << Filter << "\n";
+size_t TPos = 0;
+for (char C : Filter) {
+  TPos = Target.find_lower(C, TPos);
+  if (TPos == StringRef::npos)
+return false;
+}
+llvm::errs() << "yeah\n";
+return true;
+  }
+
   CompletionItem
   ProcessCodeCompleteResult(const CompletionCandidate &Candidate,
 const CodeCompletionString &CCS) const {
___
cfe-commits mailing list
cfe-commits@lists

[PATCH] D40023: [RISCV] Implement ABI lowering

2017-11-23 Thread David Majnemer via Phabricator via cfe-commits
majnemer added a comment.

In https://reviews.llvm.org/D40023#933466, @asb wrote:

> In https://reviews.llvm.org/D40023#933464, @majnemer wrote:
>
> > So how does something like the following work:
> >
> >   union U { float f; int i; };
> >   void f(union U u);
> >   
> >
> > The flattening described in 
> > https://github.com/riscv/riscv-elf-psabi-doc/blob/master/riscv-elf.md#hardware-floating-point-calling-convention
> >  makes sense for arrays and structs but I couldn't find where unions were 
> > described.
>
>
> You're right that's not currently described - I have an issue tracking this 
> here: https://github.com/riscv/riscv-elf-psabi-doc/issues/24. Last time I 
> tried to check gcc behaviour it seemed that such cases would be passed 
> according to the integer calling convention, but I'd be happier if one of the 
> GCC devs would confirm.


Should we have a test which tries to make sure our behavior matches GCC's? ISTM 
that floats in unions are always in GPRs (at least according to abicop).

How are empty unions/arrays handled? Like a function which takes no args? 
abicop seemed upset when I asked it:

  >>> m.call([Union()])
  Traceback (most recent call last):
File "", line 1, in 
File "~/majnemer/abicop/rvcc.py", line 186, in __init__
  self.alignment = max(m.alignment for m in members)
  ValueError: max() arg is an empty sequence

It'd also be good to have a test for bool and tests for bitfields. Am I correct 
that struct S { int x : 2; int y : 2; }; would get passed in two GPRs which 
were sign extended from 2 to 32?


https://reviews.llvm.org/D40023



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


[PATCH] D39882: [clangd] Filter completion results by fuzzy-matching identifiers.

2017-11-23 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In https://reviews.llvm.org/D39882#932858, @ilya-biryukov wrote:

> We definitely need to:
>
> - Rebase this change on top of current head (to account for limits and 
> scoring)


Done. There's very little interaction - for now the match doesn't affect 
scoring, we're just shifting work from the client to the server.

> - Set `incomplete=true` for fuzzy-matched completion results

Why? If you complete "foo.b^" then "qux" isn't a valid result. Clients *must* 
requery when erasing anyway, regardless of isIncomplete - it's only "further 
typing" that can reuse the result set.

> Maybe also make fuzzy-matching configurable via a flag? Off-by-default for 
> now, so we could start testing it before we finish optimizing 
> single-identifier edits. When we have it, enable fuzzy-matching by default.

Why?
I don't think it makes sense to put this behind a flag, unless we're just 
worried the code is buggy. I'm already concerned about the proliferation of 
flags for features users *might* care about, this one either works or it 
doesn't.
This patch just says "don't return qux() if the user presses ctrl-space after 
foo.b". It doesn't affect the existing behavior when user types "foo." - we'll 
still request completion, the filter will be empty. And this patch doesn't 
affect ranking.


https://reviews.llvm.org/D39882



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


[PATCH] D40089: [clangd] Make completion scores use 0-1 floats internally.

2017-11-23 Thread Sam McCall via Phabricator via cfe-commits
sammccall marked 4 inline comments as done.
sammccall added a comment.

Thanks for the quick review, took me a while to get back to this but I do care 
about it!




Comment at: clangd/ClangdUnit.cpp:387
 
   std::string sortText() const {
 std::string S, NameStorage;

hokein wrote:
> example
Done, also spelled out more what's going on here.



Comment at: clangd/ClangdUnit.cpp:417
+  // Produces an integer that sorts in the same order as F.
+  static uint32_t encodeFloat(float F) {
+// IEEE 754 floats compare like 2s complement integers.

hokein wrote:
> I think we'd better have unittest for this function.
I'd discussed this briefly with Ilya and we weren't sure it was worthwhile.
This is a pretty deep implementation detail - would you expose the function 
from ClangdUnit? Protocol?



Comment at: clangd/ClangdUnit.cpp:423
+memcpy(&U, &F, sizeof(float));
+// Convert U from 2s complement to unsigned, preserving order.
+const uint32_t SignBit = ~(~uint32_t{0} >> 1);

hokein wrote:
> Would be nice to explain more what we do here: we are trying to remap from 
> the signed range [INT_MIN, INT_MAX] to the unsigned range [0, UINT_MAX], so 
> that we can compare them via string literal comparison.
Turns out the explanation was slightly wrong (but the implementation right, 
because I lifted it from a trusted source :-)

Spelled this out some more. (Also sign-magnitude is a bit easier to understand 
that 2s complement)



Comment at: clangd/ClangdUnit.cpp:425
+const uint32_t SignBit = ~(~uint32_t{0} >> 1);
+return U & SignBit ? 0 - U : U + SignBit;
+  }

hokein wrote:
> U ^ SignBit
This matches my old explanation but isn't correct for sign-magnitude.



Comment at: test/clangd/completion-items-kinds.test:1
 # RUN: clangd -enable-snippets -run-synchronously < %s | FileCheck %s
 # It is absolutely vital that this file has CRLF line endings.

hokein wrote:
> an off-topic comment: why not using `-pretty` in this test?
Because of the old check-dag when we didn't want to assert the order.

It's still clumsy to express incomplete multiline assertions due to FileCheck 
limitations though. Given the amount of test merge conflicts i'm looking at, 
I'd rather not change this in this patch...


https://reviews.llvm.org/D40089



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


[PATCH] D40089: [clangd] Make completion scores use 0-1 floats internally.

2017-11-23 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 124044.
sammccall marked 3 inline comments as done.
sammccall added a comment.

address review comments


https://reviews.llvm.org/D40089

Files:
  clangd/ClangdUnit.cpp
  test/clangd/authority-less-uri.test
  test/clangd/completion-items-kinds.test
  test/clangd/completion-priorities.test
  test/clangd/completion-qualifiers.test
  test/clangd/completion-snippet.test
  test/clangd/completion.test
  test/clangd/protocol.test

Index: test/clangd/protocol.test
===
--- test/clangd/protocol.test
+++ test/clangd/protocol.test
@@ -39,7 +39,7 @@
 # CHECK-NEXT:"insertTextFormat": 1,
 # CHECK-NEXT:"kind": 7,
 # CHECK-NEXT:"label": "fake::",
-# CHECK-NEXT:"sortText": "75fake"
+# CHECK-NEXT:"sortText": "{{.*}}"
 #  CHECK:]
 # CHECK-NEXT:  }
 
@@ -68,7 +68,7 @@
 # CHECK-NEXT:"insertTextFormat": 1,
 # CHECK-NEXT:"kind": 7,
 # CHECK-NEXT:"label": "fake::",
-# CHECK-NEXT:"sortText": "75fake"
+# CHECK-NEXT:"sortText": "{{.*}}"
 #  CHECK:]
 # CHECK-NEXT:  }
 # STDERR: Warning: Duplicate Content-Length header received. The previous value for this message (10) was ignored.
@@ -97,7 +97,7 @@
 # CHECK-NEXT:"insertTextFormat": 1,
 # CHECK-NEXT:"kind": 7,
 # CHECK-NEXT:"label": "fake::",
-# CHECK-NEXT:"sortText": "75fake"
+# CHECK-NEXT:"sortText": "{{.*}}"
 #  CHECK:]
 # CHECK-NEXT:  }
 Content-Length: 1024
Index: test/clangd/completion.test
===
--- test/clangd/completion.test
+++ test/clangd/completion.test
@@ -24,51 +24,51 @@
 # CHECK-NEXT:  "insertTextFormat": 1,
 # CHECK-NEXT:  "kind": 5,
 # CHECK-NEXT:  "label": "a",
-# CHECK-NEXT:  "sortText": "35a"
+# CHECK-NEXT:  "sortText": "{{.*}}a"
 # CHECK-NEXT:},
 # CHECK-NEXT:{
 # CHECK-NEXT:  "detail": "int",
 # CHECK-NEXT:  "filterText": "bb",
 # CHECK-NEXT:  "insertText": "bb",
 # CHECK-NEXT:  "insertTextFormat": 1,
 # CHECK-NEXT:  "kind": 5,
 # CHECK-NEXT:  "label": "bb",
-# CHECK-NEXT:  "sortText": "35bb"
+# CHECK-NEXT:  "sortText": "{{.*}}bb"
 # CHECK-NEXT:},
 # CHECK-NEXT:{
 # CHECK-NEXT:  "detail": "int",
 # CHECK-NEXT:  "filterText": "ccc",
 # CHECK-NEXT:  "insertText": "ccc",
 # CHECK-NEXT:  "insertTextFormat": 1,
 # CHECK-NEXT:  "kind": 5,
 # CHECK-NEXT:  "label": "ccc",
-# CHECK-NEXT:  "sortText": "35ccc"
+# CHECK-NEXT:  "sortText": "{{.*}}ccc"
 # CHECK-NEXT:},
 # CHECK-NEXT:{
 # CHECK-NEXT:  "detail": "int",
 # CHECK-NEXT:  "filterText": "f",
 # CHECK-NEXT:  "insertText": "f",
 # CHECK-NEXT:  "insertTextFormat": 1,
 # CHECK-NEXT:  "kind": 2,
 # CHECK-NEXT:  "label": "f(int i, const float f) const",
-# CHECK-NEXT:  "sortText": "35f"
+# CHECK-NEXT:  "sortText": "{{.*}}f"
 # CHECK-NEXT:},
 # CHECK-NEXT:{
 # CHECK-NEXT:  "filterText": "fake",
 # CHECK-NEXT:  "insertText": "fake",
 # CHECK-NEXT:  "insertTextFormat": 1,
 # CHECK-NEXT:  "kind": 7,
 # CHECK-NEXT:  "label": "fake::",
-# CHECK-NEXT:  "sortText": "75fake"
+# CHECK-NEXT:  "sortText": "{{.*}}fake"
 # CHECK-NEXT:},
 # CHECK-NEXT:{
 # CHECK-NEXT:  "detail": "fake &",
 # CHECK-NEXT:  "filterText": "operator=",
 # CHECK-NEXT:  "insertText": "operator=",
 # CHECK-NEXT:  "insertTextFormat": 1,
 # CHECK-NEXT:  "kind": 2,
 # CHECK-NEXT:  "label": "operator=(const fake &)",
-# CHECK-NEXT:  "sortText": "79operator="
+# CHECK-NEXT:  "sortText": "{{.*}}operator="
 # CHECK-NEXT:},
 # FIXME: Why do some buildbots show an extra operator==(fake&&) here?
 #  CHECK:{
@@ -78,7 +78,7 @@
 # CHECK-NEXT:  "insertTextFormat": 1,
 # CHECK-NEXT:  "kind": 4,
 # CHECK-NEXT:  "label": "~fake()",
-# CHECK-NEXT:  "sortText": "79~fake"
+# CHECK-NEXT:  "sortText": "{{.*}}~fake"
 # CHECK-NEXT:}
 # CHECK-NEXT:  ]
 Content-Length: 148
@@ -96,60 +96,60 @@
 # CHECK-NEXT:  "insertTextFormat": 1,
 # CHECK-NEXT:  "kind": 5,
 # CHECK-NEXT:  "label": "a",
-# CHECK-NEXT:  "sortText": "35a"
+# CHECK-NEXT:  "sortText": "{{.*}}"
 # CHECK-NEXT:},
 # CHECK-NEXT:{
 # CHECK-NEXT:  "detail": "int",
 # CHECK-NEXT:  "filterText": "bb",
 # CHECK-NEXT:  "insertText": "bb",
 # CHECK-NEXT:  "insertTextFormat": 1,
 # CHECK-NEXT:  "kind": 5,
 # CHECK-NEXT:  "label": "bb",
-# CHECK-NEXT:  "sortText": "35bb"
+# CHECK-NEXT:  "sortText": "{{.*}}"
 # CHECK-NEXT:},
 # CHECK-NEXT:{
 # CHECK-NEXT:  "detail": "int",
 # CHECK-NEXT:  "filterText": "ccc",
 # CHECK-NEXT:  "insertText": "ccc",
 # CHECK-NEXT:  "insertTextFormat": 1,
 # CHECK-NEXT:  "kind": 5,
 # CHECK-NEXT:  "label": "ccc",
-# CHECK

[PATCH] D40060: [clangd] Fuzzy match scorer

2017-11-23 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added inline comments.



Comment at: clangd/FuzzyMatch.cpp:69
+: NPat(std::min(MaxPat, Pattern.size())), NWord(0),
+  ScoreScale(0.5f / NPat) {
+  memcpy(Pat, Pattern.data(), NPat);

Why .5?



Comment at: clangd/FuzzyMatch.cpp:88
+return None;
+  return ScoreScale * std::min(2 * NPat, std::max(0, Score[NPat][NWord]));
+}

Why 2 * NPat?



Comment at: clangd/FuzzyMatch.cpp:92
+// Segmentation of words and patterns
+// We mark each character as the Head or Tail of a segment, or a Separator.
+// e.g. XMLHttpRequest_Async

Do you mean "part of the Head or Tail"?
Also, explain that these are the CharRoles. A reader reads this first, and will 
search for what CharRole means in the code later. CharRole is defined in a 
different file, without comments, so figuring out how that all relates is super 
hard :)



Comment at: clangd/FuzzyMatch.cpp:101-103
+//   2. A characters segment role can be determined by the Types of itself and
+//  its neighbors. e.g. the middle entry in (Upper, Upper, Lower) is a 
Head.
+//  The Empty type is used to represent the start/end of string.

I think this is the only place where the roles are hinted at. Explain what 
roles mean and what we need them for.



Comment at: clangd/FuzzyMatch.cpp:108
+namespace {
+enum CharType { Empty, Lower, Upper, Punctuation };
+// 4 packed CharTypes per entry, indexed by char.

I'd spell out the numbers, as they are important (here and for CharRole).



Comment at: clangd/FuzzyMatch.cpp:110
+// 4 packed CharTypes per entry, indexed by char.
+constexpr uint8_t CharTypes[] = {
+0x00, 0x00, 0x00, 0x00, // Control characters

Finding bugs in these will be hard :)



Comment at: clangd/FuzzyMatch.cpp:120
+0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, // Bytes over 127 -> Lower.
+0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, // This includes UTF-8.
+0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,

Can you expand in the comment why this works for utf-8?



Comment at: clangd/FuzzyMatch.cpp:137
+} // namespace
+void FuzzyMatcher::calculateRoles(const char *Text, CharRole *Out, int N) {
+  int Types = PackedLookup(CharTypes, Text[0]);

The body of this needs more comments on what it does. I can slowly figure it 
out by doing bit math, but it should be spelled out what's expected to be in 
each value at each point.



Comment at: clangd/FuzzyMatch.cpp:207
+
+ScoreT FuzzyMatcher::matchBonus(int P, int W) {
+  // Forbidden: matching the first pattern character in the middle of a 
segment.

Perhaps add assert(LPat[P] == LWord[W]);



Comment at: clangd/FuzzyMatch.cpp:212
+  ScoreT S = 0;
+  // Bonus: pattern is part of a word prefix.
+  if (P == W)

Why does P == W imply that?



Comment at: clangd/FuzzyMatch.cpp:215
+++S;
+  // Bonus: case matches, or an asserted word break matches an actual.
+  if (Pat[P] == Word[W] || (PatRole[P] == Head && WordRole[W] == Head))

This is the first time the term "asserted word break" shows up, perhaps explain 
this when explaining the roles.



Comment at: clangd/FuzzyMatch.cpp:218
+++S;
+  // Penalty: matching inside a word where the previous didn't match.
+  if (WordRole[W] == Tail && P && !Matched[P - 1][W - 1])

The previous what didn't match?



Comment at: clangd/FuzzyMatch.h:31
+public:
+  FuzzyMatcher(llvm::StringRef Pattern);
+

Document that patterns larger than MaxPat will be silently cut.



Comment at: clangd/FuzzyMatch.h:39
+
+private:
+  constexpr static int MaxPat = 63;

I find most of the abbreviations here non-intuitive, and thus needing comments 
(Pat I get is for pattern :)
N - what does it mean? Number of characters in the pattern? I'd use Length 
instead.
LPat and LWord (no idea what L could stand for).




Comment at: clangd/FuzzyMatch.h:50
+
+  int NPat, NWord;
+  char Pat[MaxPat];

I'd use a StringRef instead, and call the storage *Storage or something.



Comment at: clangd/FuzzyMatch.h:60
+  float ScoreScale;
+  bool IsSubstring;
+};

Comment that this is not actually used inside the algorithm, just for debugging.


https://reviews.llvm.org/D40060



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


[PATCH] D33589: clang-format: consider not splitting tokens in optimization

2017-11-23 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added a comment.

In https://reviews.llvm.org/D33589#931723, @Typz wrote:

> In https://reviews.llvm.org/D33589#925903, @klimek wrote:
>
> > I think this patch doesn't handle a couple of cases that I'd like to see 
> > handled. A counter-proposal with different trade-offs is in 
> > https://reviews.llvm.org/D40068.
>
>
> Can you provide more info on these cases? Are they all added to the tests of 
> https://reviews.llvm.org/D40068?
>
> It may be simpler (though not to my eyes, I am not knowledgeable enough to 
> really understand how you go this fixed...), and works fine for "almost 
> correct" comments: e.g. when there are indeed just a few extra characters 
> overall. But it still procudes strange result when each line of the (long) 
> comment is too long, but not enough to trigger a line-wrap by itself.
>
> Since that version has landed already, not sure how to improve on this. I 
> could probably rewrite my patch on master, but it seems a bit redundant. As a 
> simpler fix, I could imagine adding a "total" overflow counter, to allow 
> detecting the situation; but when this is detected (e.g. on subsequent lines) 
> we would need to "backtrack" and revisit the initial decision...


Yes, I added all tests I was thinking of to the patch. Note that we can always 
go back on submitted patches / do things differently. As my patch fulfilled all 
your tests, I (perhaps incorrectly?) assumed it solved your use cases - can you 
give me a test case of what you would want to happen that doesn't happen with 
my patch?

Are you, for example, saying that in the case

  Limit; 13
  // foo bar baz foo bar baz foo bar baz
  you'd not want
  // foo bar baz
  // foo bar baz
  // foo bar baz
  If the overall penalty of the protruding tokens is - what? More than 1 break 
penalty? If you care about more than 3x break penalty (which I would think is 
correct), the local algorithm will work, as local decisions will make sure the 
overall penalty cannot be exceeded.


https://reviews.llvm.org/D33589



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


[PATCH] D40181: [libcxx] Allow to set locale on Windows.

2017-11-23 Thread Andrey Khalyavin via Phabricator via cfe-commits
halyavin added a comment.

@EricWF, could you please commit this change?


https://reviews.llvm.org/D40181



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


[PATCH] D33589: clang-format: consider not splitting tokens in optimization

2017-11-23 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added a comment.

In https://reviews.llvm.org/D33589#931802, @Typz wrote:

> Btw, another issue I am having is that reflowing does not respect the 
> alignment. For exemple:
>
>   enum {
>  Foo,///< This is a very long comment
>  Bar,///< This is shorter  
>  BarBar, ///< This is shorter
>   } Stuff;
>   
>
> will be reflown to :
>
>   enum {
>  Foo, ///< This is a very long
>   ///< comment
>  Bar, ///< This is shorter  
>  BarBar, ///< This is shorter
>   } Stuff;
>   
>
> when I would expect:
>
>   enum {
>  Foo,///< This is a very
>  ///< long comment
>  Bar,///< This is shorter  
>  BarBar, ///< This is shorter
>   } Stuff;
>   
>
> I see there is no penalty for breaking alignment, which may be accounted for 
> when compressing the whitespace 'before' the comment... Or maybe simply the 
> breaking should be smarter, to try to keep the alignment; but I am not sure 
> it can be done without another kind of 'global' optimization of the comment 
> reflow... Any idea/hint?


I think that's just a bug in comment alignment, which is done at a different 
stage.


https://reviews.llvm.org/D33589



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


[PATCH] D40068: Implement more accurate penalty & trade-offs while breaking protruding tokens.

2017-11-23 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added a comment.

In https://reviews.llvm.org/D40068#931679, @Typz wrote:

> Generally, this indeed improves the situation (though I cannot say much about 
> the code itself, it is still too subtle for my shallow knowledge of 
> clang-format).
>
> But it seems to give some strange looking result with long comments: it seems 
> like the decision is made at each line (e.g. is it better to wrap this line 
> or overflow a bit), so we can get a comment where each line overflows by a 
> few characters, even if the total is worse... For exemple, say we have a 100 
> lines of comment, with 9 characters overflow on each line, and an excess 
> character penalty of 30 : with this patch nothing will be re-wrapped (9*30 = 
> 270 is less the the 300 penalty for wrapping); but the total penatly would be 
> 900
>
> (btw, it seems this got merged, but the ticket does not reflect it)


Ugh, sorry, I think an arc patch I did without --create on a branch that was 
branched after the original patch was sent out broke phab :( :( This is not 
actually the state the patch was in when submitted, or the state it was LG'ed 
in (see https://reviews.llvm.org/rL318515 for the smaller patch)

In https://reviews.llvm.org/D40068#931679, @Typz wrote:

> Generally, this indeed improves the situation (though I cannot say much about 
> the code itself, it is still too subtle for my shallow knowledge of 
> clang-format).
>
> But it seems to give some strange looking result with long comments: it seems 
> like the decision is made at each line (e.g. is it better to wrap this line 
> or overflow a bit), so we can get a comment where each line overflows by a 
> few characters, even if the total is worse... For exemple, say we have a 100 
> lines of comment, with 9 characters overflow on each line, and an excess 
> character penalty of 30 : with this patch nothing will be re-wrapped (9*30 = 
> 270 is less the the 300 penalty for wrapping); but the total penatly would be 
> 900
>
> (btw, it seems this got merged, but the ticket does not reflect it)





https://reviews.llvm.org/D40068



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


[PATCH] D40181: [libcxx] Allow to set locale on Windows.

2017-11-23 Thread Martin Storsjö via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL318902: Allow to set locale on Windows. (authored by 
mstorsjo).

Changed prior to commit:
  https://reviews.llvm.org/D40181?vs=123923&id=124055#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D40181

Files:
  libcxx/trunk/include/__config
  libcxx/trunk/include/__locale
  libcxx/trunk/include/support/win32/locale_win32.h
  libcxx/trunk/src/support/win32/locale_win32.cpp

Index: libcxx/trunk/src/support/win32/locale_win32.cpp
===
--- libcxx/trunk/src/support/win32/locale_win32.cpp
+++ libcxx/trunk/src/support/win32/locale_win32.cpp
@@ -18,21 +18,7 @@
 // FIXME: base currently unused. Needs manual work to construct the new locale
 locale_t newlocale( int mask, const char * locale, locale_t /*base*/ )
 {
-return _create_locale( mask, locale );
-}
-
-locale_t uselocale( locale_t newloc )
-{
-locale_t old_locale = _get_current_locale();
-if ( newloc == NULL )
-return old_locale;
-// uselocale sets the thread's locale by definition, so unconditionally use thread-local locale
-_configthreadlocale( _ENABLE_PER_THREAD_LOCALE );
-// uselocale sets all categories
-// disable setting locale on Windows temporarily because the structure is opaque (PR31516)
-//setlocale( LC_ALL, newloc->locinfo->lc_category[LC_ALL].locale );
-// uselocale returns the old locale_t
-return old_locale;
+return {_create_locale( LC_ALL, locale ), locale};
 }
 
 decltype(MB_CUR_MAX) MB_CUR_MAX_L( locale_t __l )
Index: libcxx/trunk/include/support/win32/locale_win32.h
===
--- libcxx/trunk/include/support/win32/locale_win32.h
+++ libcxx/trunk/include/support/win32/locale_win32.h
@@ -14,6 +14,7 @@
 #include <__config>
 #include 
 #include  // _locale_t
+#include <__nullptr>
 
 #define LC_COLLATE_MASK _M_COLLATE
 #define LC_CTYPE_MASK _M_CTYPE
@@ -28,13 +29,77 @@
  | LC_NUMERIC_MASK \
  | LC_TIME_MASK )
 
-#define locale_t _locale_t
+class locale_t {
+public:
+locale_t()
+: __locale(nullptr), __locale_str(nullptr) {}
+locale_t(std::nullptr_t)
+: __locale(nullptr), __locale_str(nullptr) {}
+locale_t(_locale_t __locale, const char* __locale_str)
+: __locale(__locale), __locale_str(__locale_str) {}
+
+friend bool operator==(const locale_t& __left, const locale_t& __right) {
+return __left.__locale == __right.__locale;
+}
+
+friend bool operator==(const locale_t& __left, int __right) {
+return __left.__locale == nullptr && __right == 0;
+}
+
+friend bool operator==(const locale_t& __left, std::nullptr_t) {
+return __left.__locale == nullptr;
+}
+
+friend bool operator==(int __left, const locale_t& __right) {
+return __left == 0 && nullptr == __right.__locale;
+}
+
+friend bool operator==(std::nullptr_t, const locale_t& __right) {
+return nullptr == __right.__locale;
+}
+
+friend bool operator!=(const locale_t& __left, const locale_t& __right) {
+return !(__left == __right);
+}
+
+friend bool operator!=(const locale_t& __left, int __right) {
+return !(__left == __right);
+}
+
+friend bool operator!=(const locale_t& __left, std::nullptr_t __right) {
+return !(__left == __right);
+}
+
+friend bool operator!=(int __left, const locale_t& __right) {
+return !(__left == __right);
+}
+
+friend bool operator!=(std::nullptr_t __left, const locale_t& __right) {
+return !(__left == __right);
+}
+
+operator bool() const {
+return __locale != nullptr;
+}
+
+const char* __get_locale() const { return __locale_str; }
+
+operator _locale_t() const {
+return __locale;
+}
+private:
+_locale_t __locale;
+const char* __locale_str;
+};
 
 // Locale management functions
 #define freelocale _free_locale
 // FIXME: base currently unused. Needs manual work to construct the new locale
 locale_t newlocale( int mask, const char * locale, locale_t base );
-locale_t uselocale( locale_t newloc );
+// uselocale can't be implemented on Windows because Windows allows partial modification
+// of thread-local locale and so _get_current_locale() returns a copy while uselocale does
+// not create any copies.
+// We can still implement raii even without uselocale though.
 
 
 lconv *localeconv_l( locale_t loc );
Index: libcxx/trunk/include/__locale
===
--- libcxx/trunk/include/__locale
+++ libcxx/trunk/include/__locale
@@ -49,7 +49,7 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if !defined(_LIBCPP_LOCALE__L_EXTENSIONS) || defined(_LIBCPP_MSVCRT)
+#if !defined(_LIBCPP_LOCALE__L_EXTENSIONS)
 struct __libcpp_locale_guard {
   _LIBCPP_INLINE_VISIBILITY
   __libcpp_locale_guard(locale_t& __lo

[libcxx] r318902 - Allow to set locale on Windows.

2017-11-23 Thread Martin Storsjo via cfe-commits
Author: mstorsjo
Date: Thu Nov 23 02:38:18 2017
New Revision: 318902

URL: http://llvm.org/viewvc/llvm-project?rev=318902&view=rev
Log:
Allow to set locale on Windows.

Fix the problem PR31516 with setting locale on Windows by wrapping
_locale_t with a pointer-like class.

Reduces 74 test failures in std/localization test suite to 47 test
failures (on llvm clang, Visual Studio 2015). Number of test failures
doesn't depend on the platform (x86 or x64).

Patch by Andrey Khalyavin.

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

Modified:
libcxx/trunk/include/__config
libcxx/trunk/include/__locale
libcxx/trunk/include/support/win32/locale_win32.h
libcxx/trunk/src/support/win32/locale_win32.cpp

Modified: libcxx/trunk/include/__config
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__config?rev=318902&r1=318901&r2=318902&view=diff
==
--- libcxx/trunk/include/__config (original)
+++ libcxx/trunk/include/__config Thu Nov 23 02:38:18 2017
@@ -890,7 +890,7 @@ template  struct __static_asse
 #define _LIBCPP_NONUNIQUE_RTTI_BIT (1ULL << 63)
 #endif
 
-#if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT) ||   
\
+#if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) 
|| \
 defined(__sun__) || defined(__NetBSD__) || defined(__CloudABI__)
 #define _LIBCPP_LOCALE__L_EXTENSIONS 1
 #endif

Modified: libcxx/trunk/include/__locale
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__locale?rev=318902&r1=318901&r2=318902&view=diff
==
--- libcxx/trunk/include/__locale (original)
+++ libcxx/trunk/include/__locale Thu Nov 23 02:38:18 2017
@@ -49,7 +49,7 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if !defined(_LIBCPP_LOCALE__L_EXTENSIONS) || defined(_LIBCPP_MSVCRT)
+#if !defined(_LIBCPP_LOCALE__L_EXTENSIONS)
 struct __libcpp_locale_guard {
   _LIBCPP_INLINE_VISIBILITY
   __libcpp_locale_guard(locale_t& __loc) : __old_loc_(uselocale(__loc)) {}
@@ -65,6 +65,32 @@ private:
   __libcpp_locale_guard(__libcpp_locale_guard const&);
   __libcpp_locale_guard& operator=(__libcpp_locale_guard const&);
 };
+#elif defined(_LIBCPP_MSVCRT_LIKE)
+struct __libcpp_locale_guard {
+__libcpp_locale_guard(locale_t __l) :
+__status(_configthreadlocale(_ENABLE_PER_THREAD_LOCALE)),
+__locale_collate(setlocale(LC_COLLATE, __l.__get_locale())),
+__locale_ctype(setlocale(LC_CTYPE, __l.__get_locale())),
+__locale_monetary(setlocale(LC_MONETARY, __l.__get_locale())),
+__locale_numeric(setlocale(LC_NUMERIC, __l.__get_locale())),
+__locale_time(setlocale(LC_TIME, __l.__get_locale()))
+// LC_MESSAGES is not supported on Windows.
+{}
+~__libcpp_locale_guard() {
+setlocale(LC_COLLATE, __locale_collate);
+setlocale(LC_CTYPE, __locale_ctype);
+setlocale(LC_MONETARY, __locale_monetary);
+setlocale(LC_NUMERIC, __locale_numeric);
+setlocale(LC_TIME, __locale_time);
+_configthreadlocale(__status);
+}
+int __status;
+char* __locale_collate;
+char* __locale_ctype;
+char* __locale_monetary;
+char* __locale_numeric;
+char* __locale_time;
+};
 #endif
 
 

Modified: libcxx/trunk/include/support/win32/locale_win32.h
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/support/win32/locale_win32.h?rev=318902&r1=318901&r2=318902&view=diff
==
--- libcxx/trunk/include/support/win32/locale_win32.h (original)
+++ libcxx/trunk/include/support/win32/locale_win32.h Thu Nov 23 02:38:18 2017
@@ -14,6 +14,7 @@
 #include <__config>
 #include 
 #include  // _locale_t
+#include <__nullptr>
 
 #define LC_COLLATE_MASK _M_COLLATE
 #define LC_CTYPE_MASK _M_CTYPE
@@ -28,13 +29,77 @@
  | LC_NUMERIC_MASK \
  | LC_TIME_MASK )
 
-#define locale_t _locale_t
+class locale_t {
+public:
+locale_t()
+: __locale(nullptr), __locale_str(nullptr) {}
+locale_t(std::nullptr_t)
+: __locale(nullptr), __locale_str(nullptr) {}
+locale_t(_locale_t __locale, const char* __locale_str)
+: __locale(__locale), __locale_str(__locale_str) {}
+
+friend bool operator==(const locale_t& __left, const locale_t& __right) {
+return __left.__locale == __right.__locale;
+}
+
+friend bool operator==(const locale_t& __left, int __right) {
+return __left.__locale == nullptr && __right == 0;
+}
+
+friend bool operator==(const locale_t& __left, std::nullptr_t) {
+return __left.__locale == nullptr;
+}
+
+friend bool operator==(int __left, const locale_t& __right) {
+return __left == 0 && nullptr == __right.__locale;
+}
+
+friend bool operator==(std::nullptr_t, const locale_t& __right) {
+return nullptr == __right.__loca

[PATCH] D39722: [ASTImporter] Support TypeTraitExpr Importing

2017-11-23 Thread Takafumi Kubota via Phabricator via cfe-commits
tk1012 updated this revision to Diff 124057.
tk1012 added a comment.

Hello there,

I update the diff, reflecting the comments.

Updates:

1. Use ImportContainerChecked() for importing TypeSourceInfo.
2. Modify `bool ToValue = (...) ? ... : false;`.
3. Add a test case for the value-dependent `TypeTraitExpr`.




https://reviews.llvm.org/D39722

Files:
  lib/AST/ASTImporter.cpp
  unittests/AST/ASTImporterTest.cpp


Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -525,6 +525,46 @@
  declRefExpr()));
 }
 
+/// \brief Matches __builtin_types_compatible_p:
+/// GNU extension to check equivalent types
+/// Given
+/// \code
+///   __builtin_types_compatible_p(int, int)
+/// \endcode
+//  will generate TypeTraitExpr <...> 'int'
+const internal::VariadicDynCastAllOfMatcher typeTraitExpr;
+
+TEST(ImportExpr, ImportTypeTraitExpr) {
+  MatchVerifier Verifier;
+  EXPECT_TRUE(testImport("void declToImport() { "
+ "  __builtin_types_compatible_p(int, int);"
+ "}",
+ Lang_C, "", Lang_C, Verifier,
+ functionDecl(
+   hasBody(
+ compoundStmt(
+   has(
+ typeTraitExpr(hasType(asString("int");
+}
+
+TEST(ImportExpr, ImportTypeTraitExprValDep) {
+  MatchVerifier Verifier;
+  EXPECT_TRUE(testImport("template struct declToImport {"
+ "  void m() { __is_pod(T); };"
+ "};",
+ Lang_CXX11, "", Lang_CXX11, Verifier,
+ classTemplateDecl(
+   has(
+ cxxRecordDecl(
+   has(
+ functionDecl(
+   hasBody(
+ compoundStmt(
+   has(
+ typeTraitExpr(
+   hasType(asString("_Bool"))
+   )));
+}
 
 } // end namespace ast_matchers
 } // end namespace clang
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -283,6 +283,7 @@
 Expr *VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E);
 Expr *VisitCXXNamedCastExpr(CXXNamedCastExpr *E);
 Expr *VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E);
+Expr *VisitTypeTraitExpr(TypeTraitExpr *E);
 
 
 template
@@ -5612,6 +5613,26 @@
 Replacement);
 }
 
+Expr *ASTNodeImporter::VisitTypeTraitExpr(TypeTraitExpr *E) {
+  QualType ToType = Importer.Import(E->getType());
+  if (ToType.isNull())
+return nullptr;
+
+  SmallVector ToArgs(E->getNumArgs());
+  if (ImportContainerChecked(E->getArgs(), ToArgs))
+return nullptr;
+
+  // According to Sema::BuildTypeTrait(), if E is value-dependent,
+  // Value is always false.
+  bool ToValue = false;
+  if (!E->isValueDependent())
+ToValue = E->getValue();
+
+  return TypeTraitExpr::Create(
+  Importer.getToContext(), ToType, Importer.Import(E->getLocStart()),
+  E->getTrait(), ToArgs, Importer.Import(E->getLocEnd()), ToValue);
+}
+
 void ASTNodeImporter::ImportOverrides(CXXMethodDecl *ToMethod,
   CXXMethodDecl *FromMethod) {
   for (auto *FromOverriddenMethod : FromMethod->overridden_methods())


Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -525,6 +525,46 @@
  declRefExpr()));
 }
 
+/// \brief Matches __builtin_types_compatible_p:
+/// GNU extension to check equivalent types
+/// Given
+/// \code
+///   __builtin_types_compatible_p(int, int)
+/// \endcode
+//  will generate TypeTraitExpr <...> 'int'
+const internal::VariadicDynCastAllOfMatcher typeTraitExpr;
+
+TEST(ImportExpr, ImportTypeTraitExpr) {
+  MatchVerifier Verifier;
+  EXPECT_TRUE(testImport("void declToImport() { "
+ "  __builtin_types_compatible_p(int, int);"
+ "}",
+ Lang_C, "", Lang_C, Verifier,
+ functionDecl(
+   hasBody(
+ compoundStmt(
+   has(
+ typeTraitExpr(hasType(asString("int");
+}
+
+TEST(ImportExpr, ImportTypeTraitExprValDep) {
+  MatchVerifier Verifier;
+  EXPECT_TRUE(testImport("template struct declToImport {"
+ "  void m() { __is_pod(T); };"
+ 

[PATCH] D39936: [OpenCL] Add extensions cl_intel_subgroups and cl_intel_subgroups_short

2017-11-23 Thread Alexey Bader via Phabricator via cfe-commits
bader accepted this revision.
bader added a comment.

LGTM. Thanks!


https://reviews.llvm.org/D39936



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


[PATCH] D39936: [OpenCL] Add extensions cl_intel_subgroups and cl_intel_subgroups_short

2017-11-23 Thread Alexey Sotkin via Phabricator via cfe-commits
AlexeySotkin added a comment.




https://reviews.llvm.org/D39936



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


[PATCH] D39571: [clangd] DidChangeConfiguration Notification

2017-11-23 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clangd/ClangdLSPServer.cpp:250
+  // Verify if path has value and is a valid path
+  if (Params.settings.compilationDatabasePath.hasValue()) {
+CDB.setCompileCommandsDir(

Replace `Settings` instead of `Params.settings` here?
Or remove the `Settings` variable altogether.



Comment at: clangd/ClangdServer.cpp:579
+std::vector> ClangdServer::reparseOpenedFiles() {
+
+  std::promise DonePromise;

NIT: remote empty line



Comment at: clangd/ClangdServer.cpp:581
+  std::promise DonePromise;
+  std::future DoneFuture = DonePromise.get_future();
+  std::vector> FutureVector;

`DonePromise` and `DoneFuture` are never used. Remove them?



Comment at: clangd/ClangdServer.cpp:587
+
+  for (auto FilePath : ActiveFilePaths)
+FutureVector.push_back(forceReparse(FilePath));

Use "const auto&" or `StringRef` instead to avoid copies?



Comment at: clangd/ClangdServer.h:244
+  /// This method is normally called when the compilation database is changed.
+
+  std::vector> reparseOpenedFiles();

NIT: remove this empty line



Comment at: clangd/GlobalCompilationDatabase.cpp:108
   Logger.log("Failed to find compilation database for " + Twine(File) +
- "in overriden directory " + CompileCommandsDir.getValue() +
+ " in overriden directory " + CompileCommandsDir.getValue() +
  "\n");

Nebiroth wrote:
> ilya-biryukov wrote:
> > Accidental change?
> Twine(File) and "in overriden directory" did not have a space to separate 
> otherwise.
Right. Sorry, my mistake.



Comment at: clangd/Protocol.h:294
+/// since the data received is described as 'any' type in LSP.
+
+struct ClangdConfigurationParamsChange {

NIT: remote empty line



Comment at: clangd/Protocol.h:296
+struct ClangdConfigurationParamsChange {
+
+  llvm::Optional compilationDatabasePath;

NIT: remote empty line



Comment at: clangd/Protocol.h:303
+struct DidChangeConfigurationParams {
+
+  DidChangeConfigurationParams() {}

NIT: remove empty line



Comment at: clangd/Protocol.h:304
+
+  DidChangeConfigurationParams() {}
+  DidChangeConfigurationParams(ClangdConfigurationParamsChange settings) {}

NIT: Use `= default` instead



Comment at: clangd/Protocol.h:305
+  DidChangeConfigurationParams() {}
+  DidChangeConfigurationParams(ClangdConfigurationParamsChange settings) {}
+

We need to initialize `settings` field with `settings` parameter.

Maybe even better to remove both constructors to align with other classes in 
this file?



Comment at: test/clangd/did-change-configuration.test:15
+{"jsonrpc":"2.0","method":"workspace/didChangeConfiguration","params":{"settings":""}}
+#Failed to decode workspace/didChangeConfiguration request.
+#Incorrect mapping node

Do we want to add a `# CHECK:` for that output?



Comment at: test/clangd/did-change-configuration.test:33
+
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///compile_commands.json","languageId":"json","version":1,"text":"[\n{\n"directory":"/",\n"command":"/usr/bin/c++-DGTEST_HAS_RTTI=0-D_GNU_SOURCE-D__STDC_CONSTANT_MACROS-D__STDC_FORMAT_MACROS-D__STDC_LIMIT_MACROS-Ilib/Demangle-I../lib/Demangle-I/usr/include/libxml2-Iinclude-I../include-fPIC-fvisibility-inlines-hidden-Werror=date-time-std=c++11-Wall-W-Wno-unused-parameter-Wwrite-strings-Wcast-qual-Wno-missing-field-initializers-pedantic-Wno-long-long-Wno-maybe-uninitialized-Wdelete-non-virtual-dtor-Wno-comment-O0-g-fno-exceptions-fno-rtti-o/foo.c.o-c/foo.c",\n"file":"/foo.c"\n},"}}}
+

clangd won't see this file. `didOpen` only sets contents for diagnostics, not 
any other features.
You would rather want to add more `# RUN:` directives at the top of the file to 
create `compile_commands.json`, etc.

Writing it under root ('/') is obviously not an option. Lit tests allow you to 
use temporary paths, this is probably an approach you could take. See [[ 
https://llvm.org/docs/TestingGuide.html#substitutions | lit docs ]] for more 
details.



Comment at: test/clangd/initialize-params-invalid.test:2
+
 # RUN: clangd -pretty -run-synchronously < %s | FileCheck -strict-whitespace %s
 # It is absolutely vital that this file has CRLF line endings.

I am still seeing this newline


https://reviews.llvm.org/D39571



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


[PATCH] D33589: clang-format: consider not splitting tokens in optimization

2017-11-23 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added a comment.

In https://reviews.llvm.org/D33589#933568, @klimek wrote:

> In https://reviews.llvm.org/D33589#931723, @Typz wrote:
>
> > In https://reviews.llvm.org/D33589#925903, @klimek wrote:
> >
> > > I think this patch doesn't handle a couple of cases that I'd like to see 
> > > handled. A counter-proposal with different trade-offs is in 
> > > https://reviews.llvm.org/D40068.
> >
> >
> > Can you provide more info on these cases? Are they all added to the tests 
> > of https://reviews.llvm.org/D40068?
> >
> > It may be simpler (though not to my eyes, I am not knowledgeable enough to 
> > really understand how you go this fixed...), and works fine for "almost 
> > correct" comments: e.g. when there are indeed just a few extra characters 
> > overall. But it still procudes strange result when each line of the (long) 
> > comment is too long, but not enough to trigger a line-wrap by itself.
>




>> Since that version has landed already, not sure how to improve on this. I 
>> could probably rewrite my patch on master, but it seems a bit redundant. As 
>> a simpler fix, I could imagine adding a "total" overflow counter, to allow 
>> detecting the situation; but when this is detected (e.g. on subsequent 
>> lines) we would need to "backtrack" and revisit the initial decision...
> 
> Yes, I added all tests I was thinking of to the patch. Note that we can 
> always go back on submitted patches / do things differently. As my patch 
> fulfilled all your tests, I (perhaps incorrectly?) assumed it solved your use 
> cases - can you give me a test case of what you would want to happen that 
> doesn't happen with my patch?
> 
> Are you, for example, saying that in the case
> 
>   Limit; 13
>   // foo bar baz foo bar baz foo bar baz
>   you'd not want
>   // foo bar baz
>   // foo bar baz
>   // foo bar baz
>   If the overall penalty of the protruding tokens is - what? More than 1 
> break penalty? If you care about more than 3x break penalty (which I would 
> think is correct), the local algorithm will work, as local decisions will 
> make sure the overall penalty cannot be exceeded.

Ok, sorry, after reading the comment on the other patch I get it :)
In the above example, we add 3 line breaks, and we'd add 1 (or more) additional 
line breaks when reflowing below the column limit.
I agree that that can lead to different overall outcomes, but I don't see how 
the approach of this patch really fixes it - it will only ever reflow below the 
column limit, so it'll also lead to states for long lines where reflowing and 
leaving chars over the line limit might be the overall best choice (unless I'm 
missing something)?


https://reviews.llvm.org/D33589



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


[PATCH] D39836: [clangd] Drop impossible completions (unavailable or inaccessible)

2017-11-23 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clangd/tool/ClangdMain.cpp:169
+  clangd::CodeCompleteOptions CCOpts;
+  CCOpts.EnableSnippets = EnableSnippets;
+  CCOpts.IncludeIneligibleResults = IncludeIneligibleResults;

ilya-biryukov wrote:
> We should also set `IncludeCodePatterns = EnableSnippets` here.  May be worth 
> adding a test that they are in the completion results.
Good catch!
Unfortunately our previous attempt this failed because static_cast is not a 
code pattern (probably it should be).

 - Added a test to completion-items-kinds.
 - Added documentation to the flag to indicate it does this
 - Changed the CodePatterns default to true (equivalent to setting it here, and 
keeps the defaults in one place)
 - set flag defaults based on CompleteOption defaults so they're in one place



https://reviews.llvm.org/D39836



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


[clang-tools-extra] r318905 - clang-tidy/rename_check.py: support for moving between modules

2017-11-23 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Thu Nov 23 04:08:53 2017
New Revision: 318905

URL: http://llvm.org/viewvc/llvm-project?rev=318905&view=rev
Log:
clang-tidy/rename_check.py: support for moving between modules

Modified:
clang-tools-extra/trunk/clang-tidy/rename_check.py

Modified: clang-tools-extra/trunk/clang-tidy/rename_check.py
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/rename_check.py?rev=318905&r1=318904&r2=318905&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/rename_check.py (original)
+++ clang-tools-extra/trunk/clang-tidy/rename_check.py Thu Nov 23 04:08:53 2017
@@ -9,9 +9,10 @@
 #
 
#======#
 
-import os
-import glob
 import argparse
+import glob
+import os
+import re
 
 
 def replaceInFile(fileName, sFrom, sTo):
@@ -25,7 +26,7 @@ def replaceInFile(fileName, sFrom, sTo):
 return
 
   txt = txt.replace(sFrom, sTo)
-  print("Replace '%s' -> '%s' in '%s'" % (sFrom, sTo, fileName))
+  print("Replacing '%s' -> '%s' in '%s'..." % (sFrom, sTo, fileName))
   with open(fileName, "w") as f:
 f.write(txt)
 
@@ -47,13 +48,28 @@ def generateCommentLineSource(filename):
 
 
 def fileRename(fileName, sFrom, sTo):
-  if sFrom not in fileName:
+  if sFrom not in fileName or sFrom == sTo:
 return fileName
   newFileName = fileName.replace(sFrom, sTo)
-  print("Rename '%s' -> '%s'" % (fileName, newFileName))
+  print("Renaming '%s' -> '%s'..." % (fileName, newFileName))
   os.rename(fileName, newFileName)
   return newFileName
 
+def deleteMatchingLines(fileName, pattern):
+  lines = None
+  with open(fileName, "r") as f:
+lines = f.readlines()
+
+  not_matching_lines = [l for l in lines if not re.search(pattern, l)]
+  if not_matching_lines.count == lines.count:
+return False
+
+  print("Removing lines matching '%s' in '%s'..." % (pattern, fileName))
+  print('  ' + '  '.join([l for l in lines if re.search(pattern, l)]))
+  with open(fileName, "w") as f:
+f.writelines(not_matching_lines)
+
+  return True
 
 def getListOfFiles(clang_tidy_path):
   files = glob.glob(os.path.join(clang_tidy_path, '*'))
@@ -66,43 +82,170 @@ def getListOfFiles(clang_tidy_path):
   'clang-tidy', 'checks', '*'))
   return [filename for filename in files if os.path.isfile(filename)]
 
+# Adapts the module's CMakelist file. Returns 'True' if it could add a new 
entry
+# and 'False' if the entry already existed.
+def adapt_cmake(module_path, check_name_camel):
+  filename = os.path.join(module_path, 'CMakeLists.txt')
+  with open(filename, 'r') as f:
+lines = f.readlines()
+
+  cpp_file = check_name_camel + '.cpp'
+
+  # Figure out whether this check already exists.
+  for line in lines:
+if line.strip() == cpp_file:
+  return False
+
+  print('Updating %s...' % filename)
+  with open(filename, 'wb') as f:
+cpp_found = False
+file_added = False
+for line in lines:
+  cpp_line = line.strip().endswith('.cpp')
+  if (not file_added) and (cpp_line or cpp_found):
+cpp_found = True
+if (line.strip() > cpp_file) or (not cpp_line):
+  f.write('  ' + cpp_file + '\n')
+  file_added = True
+  f.write(line)
+
+  return True
+
+# Modifies the module to include the new check.
+def adapt_module(module_path, module, check_name, check_name_camel):
+  modulecpp = filter(lambda p: p.lower() == module.lower() + 'tidymodule.cpp',
+ os.listdir(module_path))[0]
+  filename = os.path.join(module_path, modulecpp)
+  with open(filename, 'r') as f:
+lines = f.readlines()
+
+  print('Updating %s...' % filename)
+  with open(filename, 'wb') as f:
+header_added = False
+header_found = False
+check_added = False
+check_decl = ('CheckFactories.registerCheck<' + check_name_camel +
+  '>(\n"' + check_name + '");\n')
+
+for line in lines:
+  if not header_added:
+match = re.search('#include "(.*)"', line)
+if match:
+  header_found = True
+  if match.group(1) > check_name_camel:
+header_added = True
+f.write('#include "' + check_name_camel + '.h"\n')
+elif header_found:
+  header_added = True
+  f.write('#include "' + check_name_camel + '.h"\n')
+
+  if not check_added:
+if line.strip() == '}':
+  check_added = True
+  f.write(check_decl)
+else:
+  match = re.search('registerCheck<(.*)>', line)
+  if match and match.group(1) > check_name_camel:
+check_added = True
+f.write(check_decl)
+  f.write(line)
+
+
+# Adds a release notes entry.
+def add_release_notes(clang_tidy_path, old_check_name, new_check_name):
+  filename = os.path.normpath(os.path.join(clang_tidy_path,
+   '../docs/ReleaseNotes.rst'))
+  with 

[PATCH] D40388: [clang-tidy] rename_check.py misc-string-constructor bugprone-string-constructor

2017-11-23 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh created this revision.
Herald added subscribers: xazax.hun, mgorny.

Rename misc-string-constructor to bugprone-string-constructor +
manually update the lenght of '==='s in the doc file.


https://reviews.llvm.org/D40388

Files:
  clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tidy/bugprone/CMakeLists.txt
  clang-tidy/bugprone/StringConstructorCheck.cpp
  clang-tidy/bugprone/StringConstructorCheck.h
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/MiscTidyModule.cpp
  clang-tidy/misc/StringConstructorCheck.cpp
  clang-tidy/misc/StringConstructorCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/bugprone-string-constructor.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-string-constructor.rst
  test/clang-tidy/bugprone-string-constructor.cpp
  test/clang-tidy/misc-string-constructor.cpp

Index: test/clang-tidy/bugprone-string-constructor.cpp
===
--- test/clang-tidy/bugprone-string-constructor.cpp
+++ test/clang-tidy/bugprone-string-constructor.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s misc-string-constructor %t
+// RUN: %check_clang_tidy %s bugprone-string-constructor %t
 
 namespace std {
 template 
@@ -21,7 +21,7 @@
 
 void Test() {
   std::string str('x', 4);
-  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: string constructor parameters are probably swapped; expecting string(count, character) [misc-string-constructor]
+  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: string constructor parameters are probably swapped; expecting string(count, character) [bugprone-string-constructor]
   // CHECK-FIXES: std::string str(4, 'x');
   std::wstring wstr(L'x', 4);
   // CHECK-MESSAGES: [[@LINE-1]]:16: warning: string constructor parameters are probably swapped
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -19,6 +19,7 @@
boost-use-to-string
bugprone-copy-constructor-init
bugprone-integer-division
+   bugprone-string-constructor
bugprone-suspicious-memset-usage
bugprone-undefined-memory-manipulation
cert-dcl03-c (redirects to misc-static-assert) 
@@ -131,7 +132,6 @@
misc-sizeof-expression
misc-static-assert
misc-string-compare
-   misc-string-constructor
misc-string-integer-assignment
misc-string-literal-with-embedded-nul
misc-suspicious-enum-usage
Index: docs/clang-tidy/checks/bugprone-string-constructor.rst
===
--- docs/clang-tidy/checks/bugprone-string-constructor.rst
+++ docs/clang-tidy/checks/bugprone-string-constructor.rst
@@ -1,7 +1,7 @@
-.. title:: clang-tidy - misc-string-constructor
+.. title:: clang-tidy - bugprone-string-constructor
 
-misc-string-constructor
-===
+bugprone-string-constructor
+===
 
 Finds string constructors that are suspicious and probably errors.
 
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -57,6 +57,9 @@
 Improvements to clang-tidy
 --
 
+- The 'misc-string-constructor' check was renamed to `bugprone-string-constructor
+  `_
+
 - New `google-avoid-throwing-objc-exception
   `_ check
 
Index: clang-tidy/misc/MiscTidyModule.cpp
===
--- clang-tidy/misc/MiscTidyModule.cpp
+++ clang-tidy/misc/MiscTidyModule.cpp
@@ -38,7 +38,6 @@
 #include "SizeofExpressionCheck.h"
 #include "StaticAssertCheck.h"
 #include "StringCompareCheck.h"
-#include "StringConstructorCheck.h"
 #include "StringIntegerAssignmentCheck.h"
 #include "StringLiteralWithEmbeddedNulCheck.h"
 #include "SuspiciousEnumUsageCheck.h"
@@ -114,8 +113,6 @@
 "misc-sizeof-expression");
 CheckFactories.registerCheck("misc-static-assert");
 CheckFactories.registerCheck("misc-string-compare");
-CheckFactories.registerCheck(
-"misc-string-constructor");
 CheckFactories.registerCheck(
 "misc-string-integer-assignment");
 CheckFactories.registerCheck(
Index: clang-tidy/misc/CMakeLists.txt
===
--- clang-tidy/misc/CMakeLists.txt
+++ clang-tidy/misc/CMakeLists.txt
@@ -31,7 +31,6 @@
   SizeofExpressionCheck.cpp
   StaticAssertCheck.cpp
   StringCompareCheck.cpp
-  StringConstructorCheck.cpp
   StringIntegerAssignmentCheck.cpp
   StringLiteralWithEmbeddedNulCheck.cpp
   SuspiciousEnumUsageCheck.cpp
Index: clang-tidy/bugprone/StringConstructorCheck.h
===
--- clang-tidy/bugprone/StringConstructorCheck.h
+++ clang-tidy/bugprone/St

[PATCH] D40388: [clang-tidy] rename_check.py misc-string-constructor bugprone-string-constructor

2017-11-23 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun accepted this revision.
xazax.hun added a comment.
This revision is now accepted and ready to land.

LG!


https://reviews.llvm.org/D40388



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


[PATCH] D40388: [clang-tidy] rename_check.py misc-string-constructor bugprone-string-constructor

2017-11-23 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.

LGTM.


https://reviews.llvm.org/D40388



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


[clang-tools-extra] r318906 - [clang-tidy] Misplaced Operator in Strlen in Alloc

2017-11-23 Thread Adam Balogh via cfe-commits
Author: baloghadamsoftware
Date: Thu Nov 23 04:26:28 2017
New Revision: 318906

URL: http://llvm.org/viewvc/llvm-project?rev=318906&view=rev
Log:
[clang-tidy] Misplaced Operator in Strlen in Alloc

A possible error is to write `malloc(strlen(s+1))` instead of
`malloc(strlen(s)+1)`. Unfortunately the former is also valid syntactically,
but allocates less memory by two bytes (if s` is at least one character long,
undefined behavior otherwise) which may result in overflow cases. This check
detects such cases and also suggests the fix for them.


Modified:
clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp?rev=318906&r1=318905&r2=318906&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp Thu Nov 
23 04:26:28 2017
@@ -12,6 +12,7 @@
 #include "../ClangTidyModuleRegistry.h"
 #include "CopyConstructorInitCheck.h"
 #include "IntegerDivisionCheck.h"
+#include "MisplacedOperatorInStrlenInAllocCheck.h"
 #include "SuspiciousMemsetUsageCheck.h"
 #include "UndefinedMemoryManipulationCheck.h"
 
@@ -26,6 +27,8 @@ public:
 "bugprone-copy-constructor-init");
 CheckFactories.registerCheck(
 "bugprone-integer-division");
+CheckFactories.registerCheck(
+"bugprone-misplaced-operator-in-strlen-in-alloc");
 CheckFactories.registerCheck(
 "bugprone-suspicious-memset-usage");
 CheckFactories.registerCheck(

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt?rev=318906&r1=318905&r2=318906&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt Thu Nov 23 
04:26:28 2017
@@ -4,6 +4,7 @@ add_clang_library(clangTidyBugproneModul
   BugproneTidyModule.cpp
   CopyConstructorInitCheck.cpp
   IntegerDivisionCheck.cpp
+  MisplacedOperatorInStrlenInAllocCheck.cpp
   SuspiciousMemsetUsageCheck.cpp
   UndefinedMemoryManipulationCheck.cpp
 

Modified: clang-tools-extra/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/ReleaseNotes.rst?rev=318906&r1=318905&r2=318906&view=diff
==
--- clang-tools-extra/trunk/docs/ReleaseNotes.rst (original)
+++ clang-tools-extra/trunk/docs/ReleaseNotes.rst Thu Nov 23 04:26:28 2017
@@ -85,6 +85,15 @@ Improvements to clang-tidy
   not intended to be subclassed. Includes a list of classes from Foundation
   and UIKit which are documented as not supporting subclassing.
 
+- New `bugprone-misplaced-operator-in-strlen-in-alloc
+  
`_
 check
+
+  Finds cases where ``1`` is added to the string in the argument to
+  ``strlen()``, ``strnlen()``, ``strnlen_s()``, ``wcslen()``, ``wcsnlen()``, 
and
+  ``wcsnlen_s()`` instead of the result and the value is used as an argument to
+  a memory allocation function (``malloc()``, ``calloc()``, ``realloc()``,
+  ``alloca()``).
+
 - Renamed checks to use correct term "implicit conversion" instead of "implicit
   cast" and modified messages and option names accordingly:
 

Modified: clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst?rev=318906&r1=318905&r2=318906&view=diff
==
--- clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst (original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst Thu Nov 23 04:26:28 
2017
@@ -19,6 +19,7 @@ Clang-Tidy Checks
boost-use-to-string
bugprone-copy-constructor-init
bugprone-integer-division
+   bugprone-misplaced-operator-in-strlen-in-alloc
bugprone-suspicious-memset-usage
bugprone-undefined-memory-manipulation
cert-dcl03-c (redirects to misc-static-assert) 


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


[clang-tools-extra] r318907 - [clang-tidy] Misplaced Operator in Strlen in Alloc

2017-11-23 Thread Adam Balogh via cfe-commits
Author: baloghadamsoftware
Date: Thu Nov 23 04:33:12 2017
New Revision: 318907

URL: http://llvm.org/viewvc/llvm-project?rev=318907&view=rev
Log:
[clang-tidy] Misplaced Operator in Strlen in Alloc

A possible error is to write `malloc(strlen(s+1))` instead of
`malloc(strlen(s)+1)`. Unfortunately the former is also valid syntactically,
but allocates less memory by two bytes (if `s` is at least one character long,
undefined behavior otherwise) which may result in overflow cases. This check
detects such cases and also suggests the fix for them.

Fix for r318906, forgot to add new files.


Added:

clang-tools-extra/trunk/clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.cpp

clang-tools-extra/trunk/clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-misplaced-operator-in-strlen-in-alloc.rst

clang-tools-extra/trunk/test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.c

clang-tools-extra/trunk/test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.cpp

Added: 
clang-tools-extra/trunk/clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.cpp?rev=318907&view=auto
==
--- 
clang-tools-extra/trunk/clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.cpp
 (added)
+++ 
clang-tools-extra/trunk/clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.cpp
 Thu Nov 23 04:33:12 2017
@@ -0,0 +1,92 @@
+//===--- MisplacedOperatorInStrlenInAllocCheck.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 "MisplacedOperatorInStrlenInAllocCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace bugprone {
+
+void MisplacedOperatorInStrlenInAllocCheck::registerMatchers(
+MatchFinder *Finder) {
+  const auto StrLenFunc = functionDecl(anyOf(
+  hasName("::strlen"), hasName("::std::strlen"), hasName("::strnlen"),
+  hasName("::std::strnlen"), hasName("::strnlen_s"),
+  hasName("::std::strnlen_s"), hasName("::wcslen"),
+  hasName("::std::wcslen"), hasName("::wcsnlen"), 
hasName("::std::wcsnlen"),
+  hasName("::wcsnlen_s"), hasName("std::wcsnlen_s")));
+
+  const auto BadUse =
+  callExpr(callee(StrLenFunc),
+   hasAnyArgument(ignoringImpCasts(
+   binaryOperator(allOf(hasOperatorName("+"),
+hasRHS(ignoringParenImpCasts(
+integerLiteral(equals(1))
+   .bind("BinOp"
+  .bind("StrLen");
+
+  const auto BadArg = anyOf(
+  allOf(hasDescendant(BadUse),
+unless(binaryOperator(allOf(
+hasOperatorName("+"), hasLHS(BadUse),
+hasRHS(ignoringParenImpCasts(integerLiteral(equals(1,
+  BadUse);
+
+  const auto Alloc0Func =
+  functionDecl(anyOf(hasName("::malloc"), hasName("std::malloc"),
+ hasName("::alloca"), hasName("std::alloca")));
+  const auto Alloc1Func =
+  functionDecl(anyOf(hasName("::calloc"), hasName("std::calloc"),
+ hasName("::realloc"), hasName("std::realloc")));
+
+  Finder->addMatcher(
+  callExpr(callee(Alloc0Func), hasArgument(0, BadArg)).bind("Alloc"), 
this);
+  Finder->addMatcher(
+  callExpr(callee(Alloc1Func), hasArgument(1, BadArg)).bind("Alloc"), 
this);
+}
+
+void MisplacedOperatorInStrlenInAllocCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *Alloc = Result.Nodes.getNodeAs("Alloc");
+  const auto *StrLen = Result.Nodes.getNodeAs("StrLen");
+  const auto *BinOp = Result.Nodes.getNodeAs("BinOp");
+
+  const StringRef StrLenText = Lexer::getSourceText(
+  CharSourceRange::getTokenRange(StrLen->getSourceRange()),
+  *Result.SourceManager, getLangOpts());
+  const StringRef StrLenBegin = StrLenText.substr(0, StrLenText.find('(') + 1);
+  const StringRef Arg0Text = Lexer::getSourceText(
+  CharSourceRange::getTokenRange(StrLen->getArg(0)->getSourceRange()),
+  *Result.SourceManager, getLangOpts());
+  const StringRef StrLenEnd = StrLenText.substr(
+  StrLenText.find(Arg0Text) + Arg0Text.size(), StrLenText.size());
+
+  const StringRef LHSText = Lexer::getSourceText(
+  CharSourceRange::getTokenRange(BinOp->getLHS()->getSourceRange()),
+  *Result.SourceManager, getLangOpts());
+  const StringRef RHSText = Lexer::getSourceText(
+  CharSourceRange::getTokenRange(BinOp->getRHS()->ge

[PATCH] D39121: [clang-tidy] Misplaced Operator in Strlen in Alloc

2017-11-23 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware closed this revision.
baloghadamsoftware marked 2 inline comments as done.
baloghadamsoftware added a comment.

https://reviews.llvm.org/rL318906 and https://reviews.llvm.org/rL318907


https://reviews.llvm.org/D39121



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


[PATCH] D39836: [clangd] Drop impossible completions (unavailable or inaccessible)

2017-11-23 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 124066.
sammccall added a comment.

Address review comments


https://reviews.llvm.org/D39836

Files:
  clangd/ClangdLSPServer.cpp
  clangd/ClangdLSPServer.h
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/ClangdUnit.cpp
  clangd/ClangdUnit.h
  clangd/tool/ClangdMain.cpp
  test/clangd/completion-items-kinds.test
  test/clangd/completion-priorities.test
  test/clangd/completion-qualifiers.test
  unittests/clangd/ClangdTests.cpp

Index: unittests/clangd/ClangdTests.cpp
===
--- unittests/clangd/ClangdTests.cpp
+++ unittests/clangd/ClangdTests.cpp
@@ -788,6 +788,8 @@
   int method();
 
   int field;
+private:
+  int private_field;
 };
 
 int test() {
@@ -828,7 +830,10 @@
   // Class members. The only items that must be present in after-dor
   // completion.
   EXPECT_TRUE(ContainsItem(Results, MethodItemText));
+  EXPECT_TRUE(ContainsItem(Results, MethodItemText));
   EXPECT_TRUE(ContainsItem(Results, "field"));
+  EXPECT_EQ(Opts.IncludeIneligibleResults,
+ContainsItem(Results, "private_field"));
   // Global items.
   EXPECT_FALSE(ContainsItem(Results, "global_var"));
   EXPECT_FALSE(ContainsItem(Results, GlobalFuncItemText));
@@ -889,18 +894,26 @@
 }
   };
 
-  for (bool IncludeMacros : {true, false})
-for (bool IncludeGlobals : {true, false})
-  for (bool IncludeBriefComments : {true, false})
-for (bool EnableSnippets : {true, false})
+  clangd::CodeCompleteOptions CCOpts;
+  for (bool IncludeMacros : {true, false}){
+CCOpts.IncludeMacros = IncludeMacros;
+for (bool IncludeGlobals : {true, false}){
+  CCOpts.IncludeGlobals = IncludeGlobals;
+  for (bool IncludeBriefComments : {true, false}){
+CCOpts.IncludeBriefComments = IncludeBriefComments;
+for (bool EnableSnippets : {true, false}){
+  CCOpts.EnableSnippets = EnableSnippets;
   for (bool IncludeCodePatterns : {true, false}) {
-TestWithOpts(clangd::CodeCompleteOptions(
-/*EnableSnippets=*/EnableSnippets,
-/*IncludeCodePatterns=*/IncludeCodePatterns,
-/*IncludeMacros=*/IncludeMacros,
-/*IncludeGlobals=*/IncludeGlobals,
-/*IncludeBriefComments=*/IncludeBriefComments));
+CCOpts.IncludeCodePatterns = IncludeCodePatterns;
+for (bool IncludeIneligibleResults : {true, false}) {
+  CCOpts.IncludeIneligibleResults = IncludeIneligibleResults;
+  TestWithOpts(CCOpts);
+}
   }
+}
+  }
+}
+  }
 }
 
 class ClangdThreadingTest : public ClangdVFSTest {};
Index: test/clangd/completion-qualifiers.test
===
--- test/clangd/completion-qualifiers.test
+++ test/clangd/completion-qualifiers.test
@@ -13,7 +13,7 @@
 # CHECK-NEXT:  "result": {
 # CHECK-NEXT:"isIncomplete": false,
 # CHECK-NEXT:"items": [
-# Eligible const functions are at the top of the list.
+# Eligible functions are at the top of the list.
 # CHECK-NEXT:  {
 # CHECK-NEXT:"detail": "int",
 # CHECK-NEXT:"filterText": "bar",
@@ -32,18 +32,9 @@
 # CHECK-NEXT:"label": "Foo::foo() const",
 # CHECK-NEXT:"sortText": "37foo"
 # CHECK-NEXT:  },
-# Ineligible non-const function is at the bottom of the list.
-# CHECK-NEXT:  {
-#  CHECK:"detail": "int",
-#  CHECK:"filterText": "foo",
-# CHECK-NEXT:"insertText": "foo",
-# CHECK-NEXT:"insertTextFormat": 1,
-# CHECK-NEXT:"kind": 2,
-# CHECK-NEXT:"label": "foo() const",
-# CHECK-NEXT:"sortText": "200035foo"
-# CHECK-NEXT:  }
-# CHECK-NEXT:]
-# CHECK-NEXT:  }
+# Ineligible private functions are not present.
+#  CHECK-NOT:"label": "foo() const",
+#  CHECK:]
 Content-Length: 44
 
 {"jsonrpc":"2.0","id":4,"method":"shutdown"}
Index: test/clangd/completion-priorities.test
===
--- test/clangd/completion-priorities.test
+++ test/clangd/completion-priorities.test
@@ -61,28 +61,10 @@
 # CHECK-NEXT:"kind": 2,
 # CHECK-NEXT:"label": "pub()",
 # CHECK-NEXT:"sortText": "34pub"
-# CHECK-NEXT:  },
-# priv() and prot() are at the end of the list
-# CHECK-NEXT:  {
-#  CHECK:"detail": "void",
-#  CHECK:"filterText": "priv",
-# CHECK-NEXT:"insertText": "priv",
-# CHECK-NEXT:"insertTextFormat": 1,
-# CHECK-NEXT:"kind": 2,
-# CHECK-NEXT:"label": "priv()",
-# CHECK-NEXT:"sortText": "200034priv"
-# CHECK-NEXT:  },
-# CHECK-NEXT:  {
-# CHECK-NEXT:"detail": "void",
-# CHECK-NEXT:"filterText": "prot",
-# CHECK-NEXT:"insertText": "prot",
-# CHECK-NEXT:"insertTextFormat": 1,
-# CHECK-NEXT:"k

r318909 - [ASTMatchers] Matchers for new[] operators

2017-11-23 Thread Adam Balogh via cfe-commits
Author: baloghadamsoftware
Date: Thu Nov 23 04:43:20 2017
New Revision: 318909

URL: http://llvm.org/viewvc/llvm-project?rev=318909&view=rev
Log:
[ASTMatchers] Matchers for new[] operators

Two new matchers for `CXXNewExpr` are added which may be useful e.g. in
`clang-tidy` checkers. One of them is `isArray` which matches `new[]` but not
plain `new`. The other one, `hasArraySize` matches `new[]` for a given size.


Modified:
cfe/trunk/docs/LibASTMatchersReference.html
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp

Modified: cfe/trunk/docs/LibASTMatchersReference.html
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=318909&r1=318908&r2=318909&view=diff
==
--- cfe/trunk/docs/LibASTMatchersReference.html (original)
+++ cfe/trunk/docs/LibASTMatchersReference.html Thu Nov 23 04:43:20 2017
@@ -2276,6 +2276,16 @@ Given
 
 
 
+MatcherCXXNewExpr>isArray
+Matches array new 
expressions.
+
+Given:
+  MyClass *p1 = new MyClass[10];
+cxxNewExpr(isArray())
+  matches the expression 'new MyClass[10]'.
+
+
+
 MatcherCXXOperatorCallExpr>hasOverloadedOperatorNameStringRef
 Name
 Matches 
overloaded operator names.
 
@@ -4476,6 +4486,16 @@ Example matches A() in the last line
 
 
 
+MatcherCXXNewExpr>hasArraySizeMatcherExpr> 
InnerMatcher
+Matches array new 
expressions with a given array size.
+
+Given:
+  MyClass *p1 = new MyClass[10];
+cxxNewExpr(hasArraySize(intgerLiteral(equals(10
+  matches the expression 'new MyClass[10]'.
+
+
+
 MatcherCXXNewExpr>hasDeclarationMatcherDecl>  
InnerMatcher
 Matches a node if 
the declaration associated with that node
 matches the given matcher.

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=318909&r1=318908&r2=318909&view=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Thu Nov 23 04:43:20 2017
@@ -5828,6 +5828,31 @@ AST_MATCHER(ParmVarDecl, hasDefaultArgum
   return Node.hasDefaultArg(); 
 }
 
+/// \brief Matches array new expressions.
+///
+/// Given:
+/// \code
+///   MyClass *p1 = new MyClass[10];
+/// \endcode
+/// cxxNewExpr(isArray())
+///   matches the expression 'new MyClass[10]'.
+AST_MATCHER(CXXNewExpr, isArray) {
+  return Node.isArray();
+}
+
+/// \brief Matches array new expressions with a given array size.
+///
+/// Given:
+/// \code
+///   MyClass *p1 = new MyClass[10];
+/// \endcode
+/// cxxNewExpr(hasArraySize(intgerLiteral(equals(10
+///   matches the expression 'new MyClass[10]'.
+AST_MATCHER_P(CXXNewExpr, hasArraySize, internal::Matcher, InnerMatcher) 
{
+  return Node.isArray() &&
+InnerMatcher.matches(*Node.getArraySize(), Finder, Builder);
+}
+
 } // namespace ast_matchers
 } // namespace clang
 

Modified: cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp?rev=318909&r1=318908&r2=318909&view=diff
==
--- cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp (original)
+++ cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp Thu Nov 23 04:43:20 2017
@@ -234,6 +234,7 @@ RegistryMaps::RegistryMaps() {
   REGISTER_MATCHER(hasAnyUsingShadowDecl);
   REGISTER_MATCHER(hasArgument);
   REGISTER_MATCHER(hasArgumentOfType);
+  REGISTER_MATCHER(hasArraySize);
   REGISTER_MATCHER(hasAttr);
   REGISTER_MATCHER(hasAutomaticStorageDuration);
   REGISTER_MATCHER(hasBase);
@@ -317,6 +318,7 @@ RegistryMaps::RegistryMaps() {
   REGISTER_MATCHER(isAnonymous);
   REGISTER_MATCHER(isAnyCharacter);
   REGISTER_MATCHER(isAnyPointer);
+  REGISTER_MATCHER(isArray);
   REGISTER_MATCHER(isArrow);
   REGISTER_MATCHER(isBaseInitializer);
   REGISTER_MATCHER(isBitField);

Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp?rev=318909&r1=318908&r2=318909&view=diff
==
--- cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp (original)
+++ cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp Thu Nov 23 
04:43:20 2017
@@ -1998,5 +1998,15 @@ TEST(HasDefaultArgumen

[PATCH] D39366: [ASTMatchers] Matchers for new[] operators

2017-11-23 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware closed this revision.
baloghadamsoftware added a comment.

Closed by commit https://reviews.llvm.org/rL318909.


https://reviews.llvm.org/D39366



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


[clang-tools-extra] r318912 - [clang-tidy] Add support for operator new[] in check bugprone-misplaced-operator-in-strlen-in-alloc

2017-11-23 Thread Adam Balogh via cfe-commits
Author: baloghadamsoftware
Date: Thu Nov 23 04:56:23 2017
New Revision: 318912

URL: http://llvm.org/viewvc/llvm-project?rev=318912&view=rev
Log:
[clang-tidy] Add support for operator new[] in check 
bugprone-misplaced-operator-in-strlen-in-alloc

The check now recognizes error cases like `new char[strlen(s + 1)]` and suggests
a fix in the format `new char[strlen(s) + 1]`.


Modified:

clang-tools-extra/trunk/clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-misplaced-operator-in-strlen-in-alloc.rst

clang-tools-extra/trunk/test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.cpp?rev=318912&r1=318911&r2=318912&view=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.cpp
 (original)
+++ 
clang-tools-extra/trunk/clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.cpp
 Thu Nov 23 04:56:23 2017
@@ -53,21 +53,28 @@ void MisplacedOperatorInStrlenInAllocChe
   callExpr(callee(Alloc0Func), hasArgument(0, BadArg)).bind("Alloc"), 
this);
   Finder->addMatcher(
   callExpr(callee(Alloc1Func), hasArgument(1, BadArg)).bind("Alloc"), 
this);
+  Finder->addMatcher(
+  cxxNewExpr(isArray(), hasArraySize(BadArg)).bind("Alloc"), this);
 }
 
 void MisplacedOperatorInStrlenInAllocCheck::check(
 const MatchFinder::MatchResult &Result) {
-  const auto *Alloc = Result.Nodes.getNodeAs("Alloc");
+  const Expr *Alloc = Result.Nodes.getNodeAs("Alloc");
+  if (!Alloc)
+Alloc = Result.Nodes.getNodeAs("Alloc");
+  assert(Alloc && "Matched node bound by 'Alloc' shoud be either 'CallExpr'"
+ " or 'CXXNewExpr'");
+
   const auto *StrLen = Result.Nodes.getNodeAs("StrLen");
   const auto *BinOp = Result.Nodes.getNodeAs("BinOp");
 
   const StringRef StrLenText = Lexer::getSourceText(
   CharSourceRange::getTokenRange(StrLen->getSourceRange()),
   *Result.SourceManager, getLangOpts());
-  const StringRef StrLenBegin = StrLenText.substr(0, StrLenText.find('(') + 1);
   const StringRef Arg0Text = Lexer::getSourceText(
   CharSourceRange::getTokenRange(StrLen->getArg(0)->getSourceRange()),
   *Result.SourceManager, getLangOpts());
+  const StringRef StrLenBegin = StrLenText.substr(0, 
StrLenText.find(Arg0Text));
   const StringRef StrLenEnd = StrLenText.substr(
   StrLenText.find(Arg0Text) + Arg0Text.size(), StrLenText.size());
 

Modified: clang-tools-extra/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/ReleaseNotes.rst?rev=318912&r1=318911&r2=318912&view=diff
==
--- clang-tools-extra/trunk/docs/ReleaseNotes.rst (original)
+++ clang-tools-extra/trunk/docs/ReleaseNotes.rst Thu Nov 23 04:56:23 2017
@@ -92,7 +92,7 @@ Improvements to clang-tidy
   ``strlen()``, ``strnlen()``, ``strnlen_s()``, ``wcslen()``, ``wcsnlen()``, 
and
   ``wcsnlen_s()`` instead of the result and the value is used as an argument to
   a memory allocation function (``malloc()``, ``calloc()``, ``realloc()``,
-  ``alloca()``).
+  ``alloca()``) or the ``new[]`` operator in `C++`.
 
 - Renamed checks to use correct term "implicit conversion" instead of "implicit
   cast" and modified messages and option names accordingly:

Modified: 
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-misplaced-operator-in-strlen-in-alloc.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-misplaced-operator-in-strlen-in-alloc.rst?rev=318912&r1=318911&r2=318912&view=diff
==
--- 
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-misplaced-operator-in-strlen-in-alloc.rst
 (original)
+++ 
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-misplaced-operator-in-strlen-in-alloc.rst
 Thu Nov 23 04:56:23 2017
@@ -6,12 +6,12 @@ bugprone-misplaced-operator-in-strlen-in
 Finds cases where ``1`` is added to the string in the argument to ``strlen()``,
 ``strnlen()``, ``strnlen_s()``, ``wcslen()``, ``wcsnlen()``, and 
``wcsnlen_s()``
 instead of the result and the value is used as an argument to a memory
-allocation function (``malloc()``, ``calloc()``, ``realloc()``, ``alloca()``).
-Cases where ``1`` is added both to the parameter and the result of the
-``strlen()``-like function are ignored, as are cases where the whole addition 
is
-surrounded by extra parentheses.
+allocation function (``malloc()``, ``calloc()``, ``realloc()``, ``alloca()``) 
or
+the ``new[]`` operator in `C++`. Cases where ``1`` is added both 

[PATCH] D39367: [clang-tidy] Add support for operator new[] in check bugprone-misplaced-operator-in-strlen-in-alloc

2017-11-23 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware closed this revision.
baloghadamsoftware added a comment.

Closed by commit https://reviews.llvm.org/rL318912.


https://reviews.llvm.org/D39367



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


[PATCH] D40132: [clangd] Tracing improvements

2017-11-23 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 124069.
sammccall marked an inline comment as done.
sammccall added a comment.

Address review comment.


https://reviews.llvm.org/D40132

Files:
  clangd/ClangdUnit.cpp
  clangd/JSONRPCDispatcher.cpp
  clangd/JSONRPCDispatcher.h
  clangd/Trace.cpp
  clangd/Trace.h
  clangd/tool/ClangdMain.cpp
  test/clangd/trace.test
  unittests/clangd/TraceTests.cpp

Index: unittests/clangd/TraceTests.cpp
===
--- unittests/clangd/TraceTests.cpp
+++ unittests/clangd/TraceTests.cpp
@@ -116,7 +116,7 @@
   ASSERT_NE(++Event, Events->end()) << "Expected span start";
   EXPECT_TRUE(VerifyObject(*Event, {{"ph", "B"}, {"name", "A"}}));
   ASSERT_NE(++Event, Events->end()) << "Expected log message";
-  EXPECT_TRUE(VerifyObject(*Event, {{"ph", "i"}, {"name", "B"}}));
+  EXPECT_TRUE(VerifyObject(*Event, {{"ph", "i"}, {"name", "Log"}}));
   ASSERT_NE(++Event, Events->end()) << "Expected span end";
   EXPECT_TRUE(VerifyObject(*Event, {{"ph", "E"}}));
   ASSERT_EQ(++Event, Events->end());
Index: test/clangd/trace.test
===
--- test/clangd/trace.test
+++ test/clangd/trace.test
@@ -1,4 +1,4 @@
-# RUN: clangd -run-synchronously -trace %t < %s && FileCheck %s < %t
+# RUN: clangd -pretty -run-synchronously -trace %t < %s && FileCheck %s < %t
 # It is absolutely vital that this file has CRLF line endings.
 #
 Content-Length: 125
@@ -8,9 +8,19 @@
 Content-Length: 152
 
 {"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///foo.c","languageId":"c","version":1,"text":"void main() {}"}}}
-# CHECK: "textDocument/didOpen"
-# CHECK: "Preamble: /foo.c"
-# CHECK: "Build: /foo.c"
+#  CHECK: {"displayTimeUnit":"ns","traceEvents":[
+# Start opening the doc.
+#  CHECK: "name": "textDocument/didOpen"
+#  CHECK: "ph": "E"
+# Start building the preamble.
+#  CHECK: "name": "Preamble"
+#  CHECK: },
+# Finish building the preamble, with filename.
+#  CHECK: "File": "/foo.c"
+# CHECK-NEXT: },
+# CHECK-NEXT: "ph": "E"
+# Start building the file.
+#  CHECK: "name": "Build"
 Content-Length: 44
 
 {"jsonrpc":"2.0","id":5,"method":"shutdown"}
Index: clangd/tool/ClangdMain.cpp
===
--- clangd/tool/ClangdMain.cpp
+++ clangd/tool/ClangdMain.cpp
@@ -114,7 +114,7 @@
   TraceFile.reset();
   llvm::errs() << "Error while opening trace file: " << EC.message();
 } else {
-  TraceSession = trace::Session::create(*TraceStream);
+  TraceSession = trace::Session::create(*TraceStream, PrettyPrint);
 }
   }
 
Index: clangd/Trace.h
===
--- clangd/Trace.h
+++ clangd/Trace.h
@@ -21,6 +21,7 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_TRACE_H_
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_TRACE_H_
 
+#include "JSONExpr.h"
 #include "llvm/ADT/Twine.h"
 #include "llvm/Support/raw_ostream.h"
 
@@ -35,7 +36,8 @@
 class Session {
 public:
   // Starts a sessions capturing trace events and writing Trace Event JSON.
-  static std::unique_ptr create(llvm::raw_ostream &OS);
+  static std::unique_ptr create(llvm::raw_ostream &OS,
+ bool Pretty = false);
   ~Session();
 
 private:
@@ -46,14 +48,30 @@
 void log(const llvm::Twine &Name);
 
 // Records an event whose duration is the lifetime of the Span object.
+//
+// Arbitrary JSON metadata can be attached while this span is active:
+//   SPAN_ATTACH(MySpan, "Payload", SomeJSONExpr);
+// SomeJSONExpr is evaluated and copied only if actually needed.
 class Span {
 public:
-  Span(const llvm::Twine &Name);
+  Span(std::string Name);
   ~Span();
 
+  // Returns mutable span metadata if this span is interested.
+  // Prefer to use SPAN_ATTACH rather than accessing this directly.
+  json::obj *args() { return Args.get(); }
+
 private:
+  std::unique_ptr Args;
 };
 
+#define SPAN_ATTACH(S, Name, Expr) \
+  do { \
+if ((S).args() != nullptr) {   \
+  (*((S).args()))[(Name)] = (Expr);\
+}  \
+  } while (0)
+
 } // namespace trace
 } // namespace clangd
 } // namespace clang
Index: clangd/Trace.cpp
===
--- clangd/Trace.cpp
+++ clangd/Trace.cpp
@@ -27,13 +27,17 @@
 // Perhaps we should replace this by something that disturbs performance less.
 class Tracer {
 public:
-  Tracer(raw_ostream &Out)
-  : Out(Out), Sep(""), Start(std::chrono::system_clock::now()) {
+  Tracer(raw_ostream &Out, bool Pretty)
+  : Out(Out), Sep(""), Start(std::chrono::system_clock::now()),
+JSONFormat(Pretty ? "{0:2}" :

[PATCH] D40132: [clangd] Tracing improvements

2017-11-23 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clangd/JSONRPCDispatcher.h:78
   llvm::Optional ID;
+  std::unique_ptr Tracer;
 };

ilya-biryukov wrote:
> Why do we need `unique_ptr`? Are `Span`s non-movable?
Spans aren't movable, they have an explicitly declared destructor. (The copy 
constructor is only deprecated by this condition, but Span has a unique_ptr 
member).

We could make them movable, though it's not absolutely trivial (we need an 
extra bool to indicate that this is moved-from and the destructor should be a 
no-op).

I think wrapping them in a `unique_ptr` here is slightly simpler than 
implementing the right move semantics by hand, but LMK what you think.



Comment at: clangd/Trace.cpp:50
   // Contents must be a list of the other JSON key/values.
-  template  void event(StringRef Phase, const T &Contents) {
+  void event(StringRef Phase, json::obj &&Contents) {
 uint64_t TID = get_threadid();

ilya-biryukov wrote:
> Any reason why we use rval-ref instead of accepting by-value?
Two reasons I prefer this for json::expr/obj/arr:

 - major: you almost always want to pass a new literal, or move an existing 
one. Passing a `const Expr &` is usually a mistake, and taking `Expr&&`  makes 
it an error.
 - minor: expr/obj/arr aren't trivially cheap to move. We forward these around 
internally, taking && at every level means we only pay for the move constructor 
once, pass-by-value pays on every call.


https://reviews.llvm.org/D40132



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


[clang-tools-extra] r318913 - [clang-tidy] Detect bugs in bugprone-misplaced-operator-in-strlen-in-alloc even in the case the allocation function is called using a constant function pointer

2017-11-23 Thread Adam Balogh via cfe-commits
Author: baloghadamsoftware
Date: Thu Nov 23 05:12:25 2017
New Revision: 318913

URL: http://llvm.org/viewvc/llvm-project?rev=318913&view=rev
Log:
[clang-tidy] Detect bugs in bugprone-misplaced-operator-in-strlen-in-alloc even 
in the case the allocation function is called using a constant function pointer

Detect bugs even if a function of the malloc() family is called using a 
constant pointer.


Modified:

clang-tools-extra/trunk/clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.cpp

clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-misplaced-operator-in-strlen-in-alloc.rst

clang-tools-extra/trunk/test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.c

Modified: 
clang-tools-extra/trunk/clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.cpp?rev=318913&r1=318912&r2=318913&view=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.cpp
 (original)
+++ 
clang-tools-extra/trunk/clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.cpp
 Thu Nov 23 05:12:25 2017
@@ -49,10 +49,23 @@ void MisplacedOperatorInStrlenInAllocChe
   functionDecl(anyOf(hasName("::calloc"), hasName("std::calloc"),
  hasName("::realloc"), hasName("std::realloc")));
 
-  Finder->addMatcher(
-  callExpr(callee(Alloc0Func), hasArgument(0, BadArg)).bind("Alloc"), 
this);
-  Finder->addMatcher(
-  callExpr(callee(Alloc1Func), hasArgument(1, BadArg)).bind("Alloc"), 
this);
+  const auto Alloc0FuncPtr =
+  varDecl(hasType(isConstQualified()),
+  hasInitializer(ignoringParenImpCasts(
+  declRefExpr(hasDeclaration(Alloc0Func);
+  const auto Alloc1FuncPtr =
+  varDecl(hasType(isConstQualified()),
+  hasInitializer(ignoringParenImpCasts(
+  declRefExpr(hasDeclaration(Alloc1Func);
+
+  Finder->addMatcher(callExpr(callee(decl(anyOf(Alloc0Func, Alloc0FuncPtr))),
+  hasArgument(0, BadArg))
+ .bind("Alloc"),
+ this);
+  Finder->addMatcher(callExpr(callee(decl(anyOf(Alloc1Func, Alloc1FuncPtr))),
+  hasArgument(1, BadArg))
+ .bind("Alloc"),
+ this);
   Finder->addMatcher(
   cxxNewExpr(isArray(), hasArraySize(BadArg)).bind("Alloc"), this);
 }

Modified: 
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-misplaced-operator-in-strlen-in-alloc.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-misplaced-operator-in-strlen-in-alloc.rst?rev=318913&r1=318912&r2=318913&view=diff
==
--- 
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-misplaced-operator-in-strlen-in-alloc.rst
 (original)
+++ 
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-misplaced-operator-in-strlen-in-alloc.rst
 Thu Nov 23 05:12:25 2017
@@ -7,9 +7,11 @@ Finds cases where ``1`` is added to the
 ``strnlen()``, ``strnlen_s()``, ``wcslen()``, ``wcsnlen()``, and 
``wcsnlen_s()``
 instead of the result and the value is used as an argument to a memory
 allocation function (``malloc()``, ``calloc()``, ``realloc()``, ``alloca()``) 
or
-the ``new[]`` operator in `C++`. Cases where ``1`` is added both to the
-parameter and the result of the ``strlen()``-like function are ignored, as are
-cases where the whole addition is surrounded by extra parentheses.
+the ``new[]`` operator in `C++`. The check detects error cases even if one of
+these functions (except the ``new[]`` operator) is called by a constant 
function
+pointer.  Cases where ``1`` is added both to the parameter and the result of 
the
+``strlen()``-like function are ignored, as are cases where the whole addition 
is
+surrounded by extra parentheses.
 
 `C` example code:
 

Modified: 
clang-tools-extra/trunk/test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.c
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.c?rev=318913&r1=318912&r2=318913&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.c
 (original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.c
 Thu Nov 23 05:12:25 2017
@@ -75,3 +75,11 @@ void intentional3(char *name) {
   // CHECK-MESSAGES-NOT: :[[@LINE-1]]:28: warning: addition operator is 
applied to the argument of strlen
   // If expression is in extra parentheses, consider it as intentional
 }
+
+void (*(*const alloc_ptr)(size_t)) = malloc;
+
+void bad_indirect_alloc(char *name) {
+  cha

[PATCH] D39370: [clang-tidy] Detect bugs in bugprone-misplaced-operator-in-strlen-in-alloc even in the case the allocation function is called using a constant function pointer

2017-11-23 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware closed this revision.
baloghadamsoftware added a comment.

Closed by commit https://reviews.llvm.org/rL318913.


https://reviews.llvm.org/D39370



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


[PATCH] D39836: [clangd] Drop impossible completions (unavailable or inaccessible)

2017-11-23 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


https://reviews.llvm.org/D39836



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


[clang-tools-extra] r318916 - [clang-tidy] rename_check.py misc-string-constructor bugprone-string-constructor

2017-11-23 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Thu Nov 23 05:49:14 2017
New Revision: 318916

URL: http://llvm.org/viewvc/llvm-project?rev=318916&view=rev
Log:
[clang-tidy] rename_check.py misc-string-constructor bugprone-string-constructor

Summary:
Rename misc-string-constructor to bugprone-string-constructor +
manually update the lenght of '==='s in the doc file.

Reviewers: hokein, xazax.hun

Reviewed By: hokein, xazax.hun

Subscribers: mgorny, xazax.hun, cfe-commits

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

Added:
clang-tools-extra/trunk/clang-tidy/bugprone/StringConstructorCheck.cpp
  - copied, changed from r318913, 
clang-tools-extra/trunk/clang-tidy/misc/StringConstructorCheck.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/StringConstructorCheck.h
  - copied, changed from r318913, 
clang-tools-extra/trunk/clang-tidy/misc/StringConstructorCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-string-constructor.rst
  - copied, changed from r318913, 
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-string-constructor.rst
clang-tools-extra/trunk/test/clang-tidy/bugprone-string-constructor.cpp
  - copied, changed from r318913, 
clang-tools-extra/trunk/test/clang-tidy/misc-string-constructor.cpp
Removed:
clang-tools-extra/trunk/clang-tidy/misc/StringConstructorCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/StringConstructorCheck.h
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-string-constructor.rst
clang-tools-extra/trunk/test/clang-tidy/misc-string-constructor.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp?rev=318916&r1=318915&r2=318916&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp Thu Nov 
23 05:49:14 2017
@@ -13,6 +13,7 @@
 #include "CopyConstructorInitCheck.h"
 #include "IntegerDivisionCheck.h"
 #include "MisplacedOperatorInStrlenInAllocCheck.h"
+#include "StringConstructorCheck.h"
 #include "SuspiciousMemsetUsageCheck.h"
 #include "UndefinedMemoryManipulationCheck.h"
 
@@ -29,6 +30,8 @@ public:
 "bugprone-integer-division");
 CheckFactories.registerCheck(
 "bugprone-misplaced-operator-in-strlen-in-alloc");
+CheckFactories.registerCheck(
+"bugprone-string-constructor");
 CheckFactories.registerCheck(
 "bugprone-suspicious-memset-usage");
 CheckFactories.registerCheck(

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt?rev=318916&r1=318915&r2=318916&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt Thu Nov 23 
05:49:14 2017
@@ -5,6 +5,7 @@ add_clang_library(clangTidyBugproneModul
   CopyConstructorInitCheck.cpp
   IntegerDivisionCheck.cpp
   MisplacedOperatorInStrlenInAllocCheck.cpp
+  StringConstructorCheck.cpp
   SuspiciousMemsetUsageCheck.cpp
   UndefinedMemoryManipulationCheck.cpp
 

Copied: clang-tools-extra/trunk/clang-tidy/bugprone/StringConstructorCheck.cpp 
(from r318913, 
clang-tools-extra/trunk/clang-tidy/misc/StringConstructorCheck.cpp)
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/StringConstructorCheck.cpp?p2=clang-tools-extra/trunk/clang-tidy/bugprone/StringConstructorCheck.cpp&p1=clang-tools-extra/trunk/clang-tidy/misc/StringConstructorCheck.cpp&r1=318913&r2=318916&rev=318916&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/StringConstructorCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/StringConstructorCheck.cpp Thu 
Nov 23 05:49:14 2017
@@ -16,7 +16,7 @@ using namespace clang::ast_matchers;
 
 namespace clang {
 namespace tidy {
-namespace misc {
+namespace bugprone {
 
 AST_MATCHER_P(IntegerLiteral, isBiggerThan, unsigned, N) {
   return Node.getValue().getZExtValue() > N;
@@ -129,6 +129,6 @@ void StringConstructorCheck::check(const
   }
 }
 
-} // namespace misc
+} // namespace bugprone
 } // namespace tidy
 } // namespace clang

Copied: clang-tools-extra/trunk/clang-tidy/bugprone/StringConstructorCheck.h 
(from r318913, clang-tools-extr

[PATCH] D40388: [clang-tidy] rename_check.py misc-string-constructor bugprone-string-constructor

2017-11-23 Thread Alexander Kornienko via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL318916: [clang-tidy] rename_check.py misc-string-constructor 
bugprone-string-constructor (authored by alexfh).

Changed prior to commit:
  https://reviews.llvm.org/D40388?vs=124065&id=124070#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D40388

Files:
  clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/trunk/clang-tidy/bugprone/StringConstructorCheck.cpp
  clang-tools-extra/trunk/clang-tidy/bugprone/StringConstructorCheck.h
  clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/trunk/clang-tidy/misc/StringConstructorCheck.cpp
  clang-tools-extra/trunk/clang-tidy/misc/StringConstructorCheck.h
  clang-tools-extra/trunk/docs/ReleaseNotes.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-string-constructor.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/misc-string-constructor.rst
  clang-tools-extra/trunk/test/clang-tidy/bugprone-string-constructor.cpp
  clang-tools-extra/trunk/test/clang-tidy/misc-string-constructor.cpp

Index: clang-tools-extra/trunk/test/clang-tidy/bugprone-string-constructor.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/bugprone-string-constructor.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/bugprone-string-constructor.cpp
@@ -0,0 +1,56 @@
+// RUN: %check_clang_tidy %s bugprone-string-constructor %t
+
+namespace std {
+template 
+class allocator {};
+template 
+class char_traits {};
+template , typename A = std::allocator >
+struct basic_string {
+  basic_string();
+  basic_string(const C*, unsigned int size);
+  basic_string(unsigned int size, C c);
+};
+typedef basic_string string;
+typedef basic_string wstring;
+}
+
+const char* kText = "";
+const char kText2[] = "";
+extern const char kText3[];
+
+void Test() {
+  std::string str('x', 4);
+  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: string constructor parameters are probably swapped; expecting string(count, character) [bugprone-string-constructor]
+  // CHECK-FIXES: std::string str(4, 'x');
+  std::wstring wstr(L'x', 4);
+  // CHECK-MESSAGES: [[@LINE-1]]:16: warning: string constructor parameters are probably swapped
+  // CHECK-FIXES: std::wstring wstr(4, L'x');
+  std::string s0(0, 'x');
+  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: constructor creating an empty string
+  std::string s1(-4, 'x');
+  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: negative value used as length parameter
+  std::string s2(0x100, 'x');
+  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: suspicious large length parameter
+
+  std::string q0("test", 0);
+  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: constructor creating an empty string
+  std::string q1(kText, -4);
+  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: negative value used as length parameter
+  std::string q2("test", 200);
+  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: length is bigger then string literal size
+  std::string q3(kText, 200);
+  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: length is bigger then string literal size
+  std::string q4(kText2, 200);
+  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: length is bigger then string literal size
+  std::string q5(kText3,  0x100);
+  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: suspicious large length parameter
+}
+
+void Valid() {
+  std::string empty();
+  std::string str(4, 'x');
+  std::wstring wstr(4, L'x');
+  std::string s1("test", 4);
+  std::string s2("test", 3);
+}
Index: clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
===
--- clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -13,6 +13,7 @@
 #include "CopyConstructorInitCheck.h"
 #include "IntegerDivisionCheck.h"
 #include "MisplacedOperatorInStrlenInAllocCheck.h"
+#include "StringConstructorCheck.h"
 #include "SuspiciousMemsetUsageCheck.h"
 #include "UndefinedMemoryManipulationCheck.h"
 
@@ -29,6 +30,8 @@
 "bugprone-integer-division");
 CheckFactories.registerCheck(
 "bugprone-misplaced-operator-in-strlen-in-alloc");
+CheckFactories.registerCheck(
+"bugprone-string-constructor");
 CheckFactories.registerCheck(
 "bugprone-suspicious-memset-usage");
 CheckFactories.registerCheck(
Index: clang-tools-extra/trunk/clang-tidy/bugprone/StringConstructorCheck.h
===
--- clang-tools-extra/trunk/clang-tidy/bugprone/StringConstructorCheck.h
+++ clang-tools-extra/trunk/clang-tidy/bugprone/StringConstructorCheck.h
@@ -0,0 +1,39 @@
+//===--- StringConstructorCheck.h - clang-tidy---

[PATCH] D39722: [ASTImporter] Support TypeTraitExpr Importing

2017-11-23 Thread Aleksei Sidorin via Phabricator via cfe-commits
a.sidorin added a comment.

Hello Takafumi,

This is almost OK to me but there is an inline comment we need to resolve in 
order to avoid Windows buildbot failures.
In addition, as Gabor pointed, when we add a new matcher, we need to update 
matcher documentation as well. To update the docs, you should perform just 
three steps.

1. Rebase your patch onto latest master
2. Launch script docs/tools/dump_ast_matchers.py
3. Add changes made by this script to your commit.

After these changes are made, I will approve the patch. Thank you!




Comment at: unittests/AST/ASTImporterTest.cpp:554
+ "  void m() { __is_pod(T); };"
+ "};",
+ Lang_CXX11, "", Lang_CXX11, Verifier,

Please add `void f() { declToImport().m(); } after `declToImport` 
definition. The reason is that in MSVC mode, uninstantiated templates are 
ignored so the test will fail. We need this to avoid this.


https://reviews.llvm.org/D39722



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


[PATCH] D40389: [clang-tidy] rename_check.py misc-dangling-handle bugprone-dangling-handle

2017-11-23 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh created this revision.
Herald added subscribers: xazax.hun, mgorny.

https://reviews.llvm.org/D40389

Files:
  clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tidy/bugprone/CMakeLists.txt
  clang-tidy/bugprone/DanglingHandleCheck.cpp
  clang-tidy/bugprone/DanglingHandleCheck.h
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/DanglingHandleCheck.cpp
  clang-tidy/misc/DanglingHandleCheck.h
  clang-tidy/misc/MiscTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/bugprone-dangling-handle.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-dangling-handle.rst
  test/clang-tidy/bugprone-dangling-handle.cpp
  test/clang-tidy/misc-dangling-handle.cpp

Index: test/clang-tidy/bugprone-dangling-handle.cpp
===
--- test/clang-tidy/bugprone-dangling-handle.cpp
+++ test/clang-tidy/bugprone-dangling-handle.cpp
@@ -1,6 +1,6 @@
-// RUN: %check_clang_tidy %s misc-dangling-handle %t -- \
+// RUN: %check_clang_tidy %s bugprone-dangling-handle %t -- \
 // RUN:   -config="{CheckOptions: \
-// RUN: [{key: misc-dangling-handle.HandleClasses, \
+// RUN: [{key: bugprone-dangling-handle.HandleClasses, \
 // RUN:   value: 'std::basic_string_view; ::llvm::StringRef;'}]}" \
 // RUN:   -- -std=c++11
 
@@ -79,7 +79,7 @@
 
 void Positives() {
   std::string_view view1 = std::string();
-  // CHECK-MESSAGES: [[@LINE-1]]:20: warning: std::basic_string_view outlives its value [misc-dangling-handle]
+  // CHECK-MESSAGES: [[@LINE-1]]:20: warning: std::basic_string_view outlives its value [bugprone-dangling-handle]
 
   std::string_view view_2 = ReturnsAString();
   // CHECK-MESSAGES: [[@LINE-1]]:20: warning: std::basic_string_view outlives
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -18,6 +18,7 @@
android-cloexec-socket
boost-use-to-string
bugprone-copy-constructor-init
+   bugprone-dangling-handle
bugprone-integer-division
bugprone-misplaced-operator-in-strlen-in-alloc
bugprone-string-constructor
@@ -108,7 +109,6 @@
misc-argument-comment
misc-assert-side-effect
misc-bool-pointer-implicit-conversion
-   misc-dangling-handle
misc-definitions-in-headers
misc-fold-init-type
misc-forward-declaration-namespace
Index: docs/clang-tidy/checks/bugprone-dangling-handle.rst
===
--- docs/clang-tidy/checks/bugprone-dangling-handle.rst
+++ docs/clang-tidy/checks/bugprone-dangling-handle.rst
@@ -1,7 +1,7 @@
-.. title:: clang-tidy - misc-dangling-handle
+.. title:: clang-tidy - bugprone-dangling-handle
 
-misc-dangling-handle
-
+bugprone-dangling-handle
+
 
 Detect dangling references in value handles like
 ``std::experimental::string_view``.
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -57,6 +57,9 @@
 Improvements to clang-tidy
 --
 
+- The 'misc-dangling-handle' check was renamed to `bugprone-dangling-handle
+  `_
+
 - The 'misc-string-constructor' check was renamed to `bugprone-string-constructor
   `_
 
Index: clang-tidy/misc/MiscTidyModule.cpp
===
--- clang-tidy/misc/MiscTidyModule.cpp
+++ clang-tidy/misc/MiscTidyModule.cpp
@@ -13,7 +13,6 @@
 #include "ArgumentCommentCheck.h"
 #include "AssertSideEffectCheck.h"
 #include "BoolPointerImplicitConversionCheck.h"
-#include "DanglingHandleCheck.h"
 #include "DefinitionsInHeadersCheck.h"
 #include "FoldInitTypeCheck.h"
 #include "ForwardDeclarationNamespaceCheck.h"
@@ -75,7 +74,6 @@
 "misc-unconventional-assign-operator");
 CheckFactories.registerCheck(
 "misc-bool-pointer-implicit-conversion");
-CheckFactories.registerCheck("misc-dangling-handle");
 CheckFactories.registerCheck(
 "misc-definitions-in-headers");
 CheckFactories.registerCheck("misc-fold-init-type");
Index: clang-tidy/misc/CMakeLists.txt
===
--- clang-tidy/misc/CMakeLists.txt
+++ clang-tidy/misc/CMakeLists.txt
@@ -8,7 +8,6 @@
   MisplacedConstCheck.cpp
   UnconventionalAssignOperatorCheck.cpp
   BoolPointerImplicitConversionCheck.cpp
-  DanglingHandleCheck.cpp
   DefinitionsInHeadersCheck.cpp
   FoldInitTypeCheck.cpp
   ForwardDeclarationNamespaceCheck.cpp
Index: clang-tidy/bugprone/DanglingHandleCheck.h
===
--- clang-tidy/bugprone/DanglingHandleCheck.h
+++ clang-tidy/bugprone/DanglingHandleCheck.h
@@ -7,20 +7,

[PATCH] D33537: [clang-tidy] Exception Escape Checker

2017-11-23 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware added a comment.

In https://reviews.llvm.org/D33537#902242, @JonasToth wrote:

>




> Will this check find stuff like this (or is it part of the frontend)
> 
>   int throwing() {
>   throw int(42);
>   }
>   
>   int not_throwing() noexcept {
>   throwing();
>   }

Yes, see lines 171-193 of the test file.


https://reviews.llvm.org/D33537



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


[clang-tools-extra] r318918 - [clang-tidy] rename_check.py: Update '=====...' line in the docs.

2017-11-23 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Thu Nov 23 06:05:32 2017
New Revision: 318918

URL: http://llvm.org/viewvc/llvm-project?rev=318918&view=rev
Log:
[clang-tidy] rename_check.py: Update '=...' line in the docs.

Modified:
clang-tools-extra/trunk/clang-tidy/rename_check.py

Modified: clang-tools-extra/trunk/clang-tidy/rename_check.py
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/rename_check.py?rev=318918&r1=318917&r2=318918&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/rename_check.py (original)
+++ clang-tools-extra/trunk/clang-tidy/rename_check.py Thu Nov 23 06:05:32 2017
@@ -226,6 +226,13 @@ def main():
 replaceInFile(filename, generateCommentLineSource(originalName),
   generateCommentLineSource(filename))
 replaceInFile(filename, header_guard_old, header_guard_new)
+
+if args.new_check_name + '.rst' in filename:
+  replaceInFile(
+  filename,
+  args.old_check_name + '\n' + '=' * len(args.old_check_name) + '\n',
+  args.new_check_name + '\n' + '=' * len(args.new_check_name) + '\n')
+
 replaceInFile(filename, args.old_check_name, args.new_check_name)
 replaceInFile(filename, check_name_camel, new_check_name_camel)
 


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


[PATCH] D40132: [clangd] Tracing improvements

2017-11-23 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




Comment at: clangd/JSONRPCDispatcher.h:78
   llvm::Optional ID;
+  std::unique_ptr Tracer;
 };

sammccall wrote:
> ilya-biryukov wrote:
> > Why do we need `unique_ptr`? Are `Span`s non-movable?
> Spans aren't movable, they have an explicitly declared destructor. (The copy 
> constructor is only deprecated by this condition, but Span has a unique_ptr 
> member).
> 
> We could make them movable, though it's not absolutely trivial (we need an 
> extra bool to indicate that this is moved-from and the destructor should be a 
> no-op).
> 
> I think wrapping them in a `unique_ptr` here is slightly simpler than 
> implementing the right move semantics by hand, but LMK what you think.
> We could make them movable, though it's not absolutely trivial (we need an 
> extra bool to indicate that this is moved-from and the destructor should be a 
> no-op).
I kinda hate this part when dealing with movable objects, too. I still do that, 
mostly to avoid heap allocs, but we're not on a hot path, so it's fine both 
ways.
We could use `llvm::Optional` instead of `unique_ptr` to get rid of the heap 
alloc too.



Comment at: clangd/Trace.cpp:50
   // Contents must be a list of the other JSON key/values.
-  template  void event(StringRef Phase, const T &Contents) {
+  void event(StringRef Phase, json::obj &&Contents) {
 uint64_t TID = get_threadid();

sammccall wrote:
> ilya-biryukov wrote:
> > Any reason why we use rval-ref instead of accepting by-value?
> Two reasons I prefer this for json::expr/obj/arr:
> 
>  - major: you almost always want to pass a new literal, or move an existing 
> one. Passing a `const Expr &` is usually a mistake, and taking `Expr&&`  
> makes it an error.
>  - minor: expr/obj/arr aren't trivially cheap to move. We forward these 
> around internally, taking && at every level means we only pay for the move 
> constructor once, pass-by-value pays on every call.
Makes sense, thanks for expanding on this. I'll make sure to pass around by 
r-value ref too when dealing with JSON objects.


https://reviews.llvm.org/D40132



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


[PATCH] D40302: Avoid copying the data of in-memory preambles

2017-11-23 Thread Benjamin Kramer via Phabricator via cfe-commits
bkramer added inline comments.



Comment at: include/clang/Frontend/PrecompiledPreamble.h:101
   /// is accessible.
+  /// For in-memory preambles, PrecompiledPreamble instance continues to owns
+  /// the MemoryBuffer with the Preamble after this method returns. The caller

continues to own


https://reviews.llvm.org/D40302



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


[PATCH] D40302: Avoid copying the data of in-memory preambles

2017-11-23 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 124074.
ilya-biryukov added a comment.

- Fixed a typo.


https://reviews.llvm.org/D40302

Files:
  include/clang/Frontend/PrecompiledPreamble.h
  lib/Frontend/PrecompiledPreamble.cpp


Index: lib/Frontend/PrecompiledPreamble.cpp
===
--- lib/Frontend/PrecompiledPreamble.cpp
+++ lib/Frontend/PrecompiledPreamble.cpp
@@ -699,9 +699,7 @@
 StringRef PCHPath = getInMemoryPreamblePath();
 PreprocessorOpts.ImplicitPCHInclude = PCHPath;
 
-// FIMXE(ibiryukov): Preambles can be large. We should allow shared access
-// to the preamble data instead of copying it here.
-auto Buf = llvm::MemoryBuffer::getMemBufferCopy(Storage.asMemory().Data);
+auto Buf = llvm::MemoryBuffer::getMemBuffer(Storage.asMemory().Data);
 VFS = createVFSOverlayForPreamblePCH(PCHPath, std::move(Buf), VFS);
   }
 }
Index: include/clang/Frontend/PrecompiledPreamble.h
===
--- include/clang/Frontend/PrecompiledPreamble.h
+++ include/clang/Frontend/PrecompiledPreamble.h
@@ -98,6 +98,10 @@
   /// Changes options inside \p CI to use PCH from this preamble. Also remaps
   /// main file to \p MainFileBuffer and updates \p VFS to ensure the preamble
   /// is accessible.
+  /// For in-memory preambles, PrecompiledPreamble instance continues to own
+  /// the MemoryBuffer with the Preamble after this method returns. The caller
+  /// is reponsible for making sure the PrecompiledPreamble instance outlives
+  /// the compiler run and the AST that will be using the PCH.
   void AddImplicitPreamble(CompilerInvocation &CI,
IntrusiveRefCntPtr &VFS,
llvm::MemoryBuffer *MainFileBuffer) const;


Index: lib/Frontend/PrecompiledPreamble.cpp
===
--- lib/Frontend/PrecompiledPreamble.cpp
+++ lib/Frontend/PrecompiledPreamble.cpp
@@ -699,9 +699,7 @@
 StringRef PCHPath = getInMemoryPreamblePath();
 PreprocessorOpts.ImplicitPCHInclude = PCHPath;
 
-// FIMXE(ibiryukov): Preambles can be large. We should allow shared access
-// to the preamble data instead of copying it here.
-auto Buf = llvm::MemoryBuffer::getMemBufferCopy(Storage.asMemory().Data);
+auto Buf = llvm::MemoryBuffer::getMemBuffer(Storage.asMemory().Data);
 VFS = createVFSOverlayForPreamblePCH(PCHPath, std::move(Buf), VFS);
   }
 }
Index: include/clang/Frontend/PrecompiledPreamble.h
===
--- include/clang/Frontend/PrecompiledPreamble.h
+++ include/clang/Frontend/PrecompiledPreamble.h
@@ -98,6 +98,10 @@
   /// Changes options inside \p CI to use PCH from this preamble. Also remaps
   /// main file to \p MainFileBuffer and updates \p VFS to ensure the preamble
   /// is accessible.
+  /// For in-memory preambles, PrecompiledPreamble instance continues to own
+  /// the MemoryBuffer with the Preamble after this method returns. The caller
+  /// is reponsible for making sure the PrecompiledPreamble instance outlives
+  /// the compiler run and the AST that will be using the PCH.
   void AddImplicitPreamble(CompilerInvocation &CI,
IntrusiveRefCntPtr &VFS,
llvm::MemoryBuffer *MainFileBuffer) const;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40302: Avoid copying the data of in-memory preambles

2017-11-23 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


https://reviews.llvm.org/D40302



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


[PATCH] D40310: Restructure how we break tokens.

2017-11-23 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added inline comments.



Comment at: lib/Format/BreakableToken.cpp:198
+ "Getting the length of a part of the string literal indicates that "
+ "the code tries to reflow it.");
+  return UnbreakableTailLength + Postfix.size() +

krasimir wrote:
> How about clients that explicitly pass `Length = Line.size() - Offset`?
That is different (I now also went and updated the comment for getRangeLength 
to explain that).

Generally, Length == Line.size() - Offset is still a portion of the content, as 
opposed to npos, which has a special meaning. I'm wondering whether I should 
just pull out a differently named method for it, now that I'm thinking about it.



Comment at: lib/Format/BreakableToken.h:100
+  /// \brief Returns the number of columns required to format the range at 
bytes
+  /// \p Offset to \p Offset \c + \p Length.
+  ///

krasimir wrote:
> Does this include the byte `Offset + Length`?
Reworded.



Comment at: lib/Format/BreakableToken.h:107
   ///
-  /// Note that previous breaks are not taken into account. \p TailOffset is
-  /// always specified from the start of the (original) line.
-  /// \p Length can be set to StringRef::npos, which means "to the end of 
line".
-  virtual unsigned
-  getLineLengthAfterSplit(unsigned LineIndex, unsigned TailOffset,
-  StringRef::size_type Length) const = 0;
+  /// \p StartColumn is the column at which the text starts, needed to compute
+  ///tab stops correctly.

krasimir wrote:
> `text` is ambiguous here: does it refer to the content of the line or to the 
> range defined by the offset and length?
Introduced 'text' in the first paragraph and reworded.



Comment at: lib/Format/BreakableToken.h:120
   /// \p LineIndex, if previously broken at \p TailOffset. If possible, do not
   /// violate \p ColumnLimit.
   virtual Split getSplit(unsigned LineIndex, unsigned TailOffset,

krasimir wrote:
> What is `ReflownColumn` used for?
Argh, actually not called ReflownColumn in the implementations :)
Changed and commented.



Comment at: lib/Format/BreakableToken.h:142
   /// \brief Returns a whitespace range (offset, length) of the content at
-  /// \p LineIndex such that the content preceding this range needs to be
-  /// reformatted before any breaks are made to this line.
+  /// \p LineIndex such that the content of the current line is reflown to the
+  /// end of the previous one.

krasimir wrote:
> Does the current line refer to the line at LineIndex?
Reworded.



Comment at: lib/Format/ContinuationIndenter.cpp:1504
  : Style.PenaltyBreakComment;
-  unsigned RemainingSpace = ColumnLimit - Current.UnbreakableTailLength;
+  // Stores whether we introduce a break anywhere in the token.
   bool BreakInserted = Token->introducesBreakBeforeToken();

krasimir wrote:
> Does a reflow count as a break?
I do believe so (well, the break in the reflow counts, the reflow itself is not 
a break, but removing a break :)



Comment at: unittests/Format/FormatTest.cpp:10603
 format("\"一\t二 \t三 四 五\t六 \t七 八九十\tqq\"",
getLLVMStyleWithColumns(11)));
 

krasimir wrote:
> What happened here?
It was wrong, it's now correct :)
Those characters are printed in double-width, and llvm's encoding library 
correctly returns this. Reflowing previously did not correctly count that, but 
used the character count instead.
At offset 8 (after a \t), C " pokes one column over the limit (C == 
double-width character, space == 1, " == 1 -> 4 -> 12 columns.



Comment at: unittests/Format/FormatTestComments.cpp:1104
+" * doesn't fit on\n"
+" * one line.  */",
 format("/* "

krasimir wrote:
> I think this is desirable. The jsdoc folks really wanted to fix-up the `*/` 
> at the end. I think it has to do with `DelimitersOnNewline`.
> If this already works in Java and js mode, that could be good enough.
I don't know whether it does - I only know I didn't break any tests :)



Comment at: unittests/Format/FormatTestComments.cpp:2108
+  // FIXME: This assumes we do not continue compressing whitespace once we are
+  // in reflow mode. Consider compressing whitespace.
+

krasimir wrote:
> I thinks that we should be compressing whitespace in reflow mode too.
Correct, but in a different patch - this patch is a strict improvement 
regarding whitespace compression, and adding more would make it more complex.



Comment at: unittests/Format/FormatTestComments.cpp:2149
+  // to keep this?
+  EXPECT_EQ("// some text\n"
+"// that\n"

krasimir wrote:
> This is like this for cases like lists in comments:
> ```
> blah-blah-blah:
>   1. blah
>   2. bl

[PATCH] D40310: Restructure how we break tokens.

2017-11-23 Thread Manuel Klimek via Phabricator via cfe-commits
klimek updated this revision to Diff 124075.
klimek marked 10 inline comments as done.
klimek added a comment.

Address review comments.


https://reviews.llvm.org/D40310

Files:
  lib/Format/BreakableToken.cpp
  lib/Format/BreakableToken.h
  lib/Format/ContinuationIndenter.cpp
  unittests/Format/FormatTest.cpp
  unittests/Format/FormatTestComments.cpp

Index: unittests/Format/FormatTestComments.cpp
===
--- unittests/Format/FormatTestComments.cpp
+++ unittests/Format/FormatTestComments.cpp
@@ -1096,11 +1096,12 @@
 }
 
 TEST_F(FormatTestComments, SplitsLongLinesInComments) {
+  // FIXME: Do we need to fix up the "  */" at the end?
+  // It doesn't look like any of our current logic triggers this.
   EXPECT_EQ("/* This is a long\n"
 " * comment that\n"
-" * doesn't\n"
-" * fit on one line.\n"
-" */",
+" * doesn't fit on\n"
+" * one line.  */",
 format("/* "
"This is a long "
"comment that "
@@ -2102,6 +2103,66 @@
   EXPECT_EQ("///", format(" ///  ", getLLVMStyleWithColumns(20)));
 }
 
+TEST_F(FormatTestComments, ReflowsCommentsPrecise) {
+  // FIXME: This assumes we do not continue compressing whitespace once we are
+  // in reflow mode. Consider compressing whitespace.
+
+  // Test that we stop reflowing precisely at the column limit.
+  // After reflowing, "// reflows into   foo" does not fit the column limit,
+  // so we compress the whitespace.
+  EXPECT_EQ("// some text that\n"
+"// reflows into foo\n",
+format("// some text that reflows\n"
+   "// into   foo\n",
+   getLLVMStyleWithColumns(20)));
+  // Given one more column, "// reflows into   foo" does fit the limit, so we
+  // do not compress the whitespace.
+  EXPECT_EQ("// some text that\n"
+"// reflows into   foo\n",
+format("// some text that reflows\n"
+   "// into   foo\n",
+   getLLVMStyleWithColumns(21)));
+}
+
+TEST_F(FormatTestComments, ReflowsCommentsWithExtraWhitespace) {
+  // Baseline.
+  EXPECT_EQ("// some text\n"
+"// that re flows\n",
+format("// some text that\n"
+   "// re flows\n",
+   getLLVMStyleWithColumns(16)));
+  EXPECT_EQ("// some text\n"
+"// that re flows\n",
+format("// some text that\n"
+   "// reflows\n",
+   getLLVMStyleWithColumns(16)));
+  EXPECT_EQ("/* some text\n"
+" * that re flows\n"
+" */\n",
+format("/* some text that\n"
+   "*  re   flows\n"
+   "*/\n",
+   getLLVMStyleWithColumns(16)));
+  // FIXME: We do not reflow if the indent of two subsequent lines differs;
+  // given that this is different behavior from block comments, do we want
+  // to keep this?
+  EXPECT_EQ("// some text\n"
+"// that\n"
+"// re flows\n",
+format("// some text that\n"
+   "// re   flows\n",
+   getLLVMStyleWithColumns(16)));
+  // Space within parts of a line that fit.
+  // FIXME: Use the earliest possible split while reflowing to compress the
+  // whitespace within the line.
+  EXPECT_EQ("// some text that\n"
+"// does re   flow\n"
+"// more  here\n",
+format("// some text that does\n"
+   "// re   flow  more  here\n",
+   getLLVMStyleWithColumns(21)));
+}
+
 TEST_F(FormatTestComments, IgnoresIf0Contents) {
   EXPECT_EQ("#if 0\n"
 "}{)(&*(^%%#%@! fsadj f;ldjs ,:;| <<<>>>][)(][\n"
@@ -2484,6 +2545,7 @@
   " long */\n"
   "  b);",
   format("a = f(a, /* long long */ b);", getLLVMStyleWithColumns(16)));
+
   EXPECT_EQ(
   "a = f(\n"
   "a,\n"
@@ -2888,16 +2950,15 @@
getLLVMStyleWithColumns(20)));
 }
 
-TEST_F(FormatTestComments, NoCrush_Bug34236) {
+TEST_F(FormatTestComments, NoCrash_Bug34236) {
   // This is a test case from a crasher reported in:
   // https://bugs.llvm.org/show_bug.cgi?id=34236
   // Temporarily disable formatting for readability.
   // clang-format off
   EXPECT_EQ(
 "/**/ /*\n"
 "  *   a\n"
-"  * b c\n"
-"  * d*/",
+"  * b c d*/",
   format(
 "/**/ /*\n"
 " *   a b\n"
Index: unittests/Format/FormatTest.cpp
=

[PATCH] D33589: clang-format: consider not splitting tokens in optimization

2017-11-23 Thread Francois Ferrand via Phabricator via cfe-commits
Typz added a comment.

> @klimek wrote:
>  In the above example, we add 3 line breaks, and we'd add 1 (or more) 
> additional line breaks when reflowing below the column limit.
>  I agree that that can lead to different overall outcomes, but I don't see 
> how the approach of this patch really fixes it - it will only ever reflow 
> below the column limit, so it'll also lead to states for long lines where 
> reflowing and leaving chars over the line limit might be the overall best 
> choice (unless I'm missing something)?

Definitely, this patch may not find the 'optimal' solution. What I mean is that 
we reduce the `PenaltyExcessCharacter` value to allow "occasionally" breaking 
the limit: instead of a hard limit, we want to allow lines to sometimes break 
the limit, but definitely not *all* the time. Both patch work fine when the 
code is "correct", i.e. there is indeed only a few lines which break the limit.

But the local decision approach behaves really wrong IMHO when the code is 
formatted beyond the column: it can very easily reformat in such a way that the 
comment is reflown to what looks like a longer column limit. I currently have a 
ratio of 10 between  PenaltyBreakComment and PenaltyExcessCharacter (which 
empirically seemed to give a decent compromise, and match how our code is 
formatted; I need to try more with your patch, to see if we can get better 
values...): with this setting, a "non wrapped" comment will actually be reflown 
to ColumnLimit+10...

When we do indeed reflow, I think we may be stricter than this, to get 
something that really looks like it obeys the column limit. If this is 
'optimal' in the sense that we may have some overflow still, that is fine, but 
really not the primary requirement IMHO.


https://reviews.llvm.org/D33589



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


[PATCH] D37813: clang-format: better handle namespace macros

2017-11-23 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added a comment.

In https://reviews.llvm.org/D37813#930065, @Typz wrote:

> ping?


Argh, very sorry for the delay in response.

In https://reviews.llvm.org/D37813#905257, @Typz wrote:

> In https://reviews.llvm.org/D37813#876227, @klimek wrote:
>
> > I think instead of introducing more and more special cases of macros we 
> > might want to handle, we should instead allow specifying macro productions 
> > globally.
>
>
> what do you mean?
>  Do you mean to group all the macro configuration options into "Macros" 
> field, still containing one field for each kind of macro? Or do you have 
> something else in mind?


I mean that we can configure macros in the format style, like "define A(X) 
class X {". I'm not 100% sure whether we would just try to use the Preprocessor 
for this, or whether we'd want to only allow a small subset of actual macros, 
but the general idea would be the same: The UnwrappedLineParser would parse the 
macro at the expansion location A(X) into an unwrapped line, and then parse the 
expansion into a child line, with the tokens tha tare not in the argument of 
the call being marked as fixed (parent child might also be better inverted).

That will allow folks to actually specify the semantics they care about instead 
of us growing ever increasing special-case logic for different types of macros.


https://reviews.llvm.org/D37813



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


[PATCH] D35109: [Analyzer] SValBuilder Comparison Rearrangement

2017-11-23 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware added a comment.

Let us summarize the possibilities:

1. Type extension approach. I tested it, all tests pass, and also in Devin's 
examples we do not infer narrower range than we should. (Wider do not matter.) 
I think this is the most complete solution and many checkers could benefit of 
it. There are also two possibilities here:

  a) If the symbols on both sides are equal, we do not extend the type, because 
of `assumeInbound()` in `ProgramState`, which first adds `MIN` to both the 
bound and the index. So e.g. `S-1` and `>=` as well.


https://reviews.llvm.org/D35109



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


[libcxx] r318919 - Update C++2a status and add Glen to CREDITS.TXT. Reviewed as https://reviews.llvm.org/D40379

2017-11-23 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Thu Nov 23 06:50:56 2017
New Revision: 318919

URL: http://llvm.org/viewvc/llvm-project?rev=318919&view=rev
Log:
Update C++2a status and add Glen to CREDITS.TXT. Reviewed as 
https://reviews.llvm.org/D40379

Modified:
libcxx/trunk/CREDITS.TXT
libcxx/trunk/www/cxx2a_status.html

Modified: libcxx/trunk/CREDITS.TXT
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/CREDITS.TXT?rev=318919&r1=318918&r2=318919&view=diff
==
--- libcxx/trunk/CREDITS.TXT (original)
+++ libcxx/trunk/CREDITS.TXT Thu Nov 23 06:50:56 2017
@@ -41,6 +41,10 @@ N: Jonathan B Coe
 E: jb...@me.com
 D: Implementation of propagate_const.
 
+N: Glen Joseph Fernandes
+E: glenj...@gmail.com
+D: Implementation of to_address.
+
 N: Eric Fiselier
 E: e...@efcs.ca
 D: LFTS support, patches and bug fixes.

Modified: libcxx/trunk/www/cxx2a_status.html
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/www/cxx2a_status.html?rev=318919&r1=318918&r2=318919&view=diff
==
--- libcxx/trunk/www/cxx2a_status.html (original)
+++ libcxx/trunk/www/cxx2a_status.html Thu Nov 23 06:50:56 2017
@@ -67,7 +67,7 @@
https://wg21.link/P0550R2";>P0550R2LWGTransformation 
Trait 
remove_cvrefAlbuquerqueComplete6.0
https://wg21.link/P0600R1";>P0600R1LWGnodiscard in 
the LibraryAlbuquerque
https://wg21.link/P0616R0";>P0616R0LWGde-pessimize 
legacy  algorithms with 
std::moveAlbuquerque
-   https://wg21.link/P0653R2";>P0653R2LWGUtility to 
convert a pointer to a raw 
pointerAlbuquerque
+   https://wg21.link/P0653R2";>P0653R2LWGUtility to 
convert a pointer to a raw 
pointerAlbuquerqueComplete6.0
https://wg21.link/P0718R2";>P0718R2LWGAtomic 
shared_ptrAlbuquerque
https://wg21.link/P0767R1";>P0767R1CWGDeprecate 
PODAlbuquerque
https://wg21.link/P0768R1";>P0768R1CWGLibrary 
Support for the Spaceship (Comparison) 
OperatorAlbuquerque


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


[PATCH] D40089: [clangd] Make completion scores use 0-1 floats internally.

2017-11-23 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: clangd/ClangdUnit.cpp:425
+const uint32_t SignBit = ~(~uint32_t{0} >> 1);
+return U & SignBit ? 0 - U : U + SignBit;
+  }

sammccall wrote:
> hokein wrote:
> > U ^ SignBit
> This matches my old explanation but isn't correct for sign-magnitude.
Well, I see! You are right. The implement is **correct** here.


https://reviews.llvm.org/D40089



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


[clang-tools-extra] r318921 - Fixing a typo; NFC.

2017-11-23 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Thu Nov 23 06:57:24 2017
New Revision: 318921

URL: http://llvm.org/viewvc/llvm-project?rev=318921&view=rev
Log:
Fixing a typo; NFC.

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

Modified: clang-tools-extra/trunk/clangd/JSONExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/JSONExpr.cpp?rev=318921&r1=318920&r2=318921&view=diff
==
--- clang-tools-extra/trunk/clangd/JSONExpr.cpp (original)
+++ clang-tools-extra/trunk/clangd/JSONExpr.cpp Thu Nov 23 06:57:24 2017
@@ -519,7 +519,7 @@ bool operator==(const Expr &L, const Exp
   case Expr::Object:
 return *L.object() == *R.object();
   }
-  llvm_unreachable("Unknown expressiopn kind");
+  llvm_unreachable("Unknown expression kind");
 }
 } // namespace json
 } // namespace clangd


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


Re: [clang-tools-extra] r318809 - Silence some MSVC warnings about not all control paths returning a value; NFC.

2017-11-23 Thread Aaron Ballman via cfe-commits
On Thu, Nov 23, 2017 at 1:47 AM, Kim Gräsman  wrote:
>
>
> Den 21 nov. 2017 11:24 em skrev "Aaron Ballman via cfe-commits"
> :
>
> Author: aaronballman
> Date: Tue Nov 21 14:24:13 2017
> New Revision: 318809
>
> URL: http://llvm.org/viewvc/llvm-project?rev=318809&view=rev
> Log:
> Silence some MSVC warnings about not all control paths returning a value;
> NFC.
>
> Modified:
> clang-tools-extra/trunk/clangd/JSONExpr.cpp
> clang-tools-extra/trunk/clangd/JSONExpr.h
>
> Modified: clang-tools-extra/trunk/clangd/JSONExpr.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/JSONExpr.cpp?rev=318809&r1=318808&r2=318809&view=diff
> ==
> --- clang-tools-extra/trunk/clangd/JSONExpr.cpp (original)
> +++ clang-tools-extra/trunk/clangd/JSONExpr.cpp Tue Nov 21 14:24:13 2017
> @@ -519,6 +519,7 @@ bool operator==(const Expr &L, const Exp
>case Expr::Object:
>  return *L.object() == *R.object();
>}
> +  llvm_unreachable("Unknown expressiopn kind");
>
>
> Typo: expressiopn. Though it *is* unreachable :)

Hah, good catch, thank you! I've corrected in r318921.

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


[clang-tools-extra] r318922 - [clang-tidy] rename_check.py: fix a bug in check presence detection

2017-11-23 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Thu Nov 23 06:59:19 2017
New Revision: 318922

URL: http://llvm.org/viewvc/llvm-project?rev=318922&view=rev
Log:
[clang-tidy] rename_check.py: fix a bug in check presence detection

Modified:
clang-tools-extra/trunk/clang-tidy/rename_check.py

Modified: clang-tools-extra/trunk/clang-tidy/rename_check.py
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/rename_check.py?rev=318922&r1=318921&r2=318922&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/rename_check.py (original)
+++ clang-tools-extra/trunk/clang-tidy/rename_check.py Thu Nov 23 06:59:19 2017
@@ -61,7 +61,7 @@ def deleteMatchingLines(fileName, patter
 lines = f.readlines()
 
   not_matching_lines = [l for l in lines if not re.search(pattern, l)]
-  if not_matching_lines.count == lines.count:
+  if len(not_matching_lines) == len(lines):
 return False
 
   print("Removing lines matching '%s' in '%s'..." % (pattern, fileName))


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


[PATCH] D33589: clang-format: consider not splitting tokens in optimization

2017-11-23 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added a comment.

In https://reviews.llvm.org/D33589#933746, @Typz wrote:

> > @klimek wrote:
> >  In the above example, we add 3 line breaks, and we'd add 1 (or more) 
> > additional line breaks when reflowing below the column limit.
> >  I agree that that can lead to different overall outcomes, but I don't see 
> > how the approach of this patch really fixes it - it will only ever reflow 
> > below the column limit, so it'll also lead to states for long lines where 
> > reflowing and leaving chars over the line limit might be the overall best 
> > choice (unless I'm missing something)?
>
> Definitely, this patch may not find the 'optimal' solution. What I mean is 
> that we reduce the `PenaltyExcessCharacter` value to allow "occasionally" 
> breaking the limit: instead of a hard limit, we want to allow lines to 
> sometimes break the limit, but definitely not *all* the time. Both patch work 
> fine when the code is "correct", i.e. there is indeed only a few lines which 
> break the limit.
>
> But the local decision approach behaves really wrong IMHO when the code is 
> formatted beyond the column: it can very easily reformat in such a way that 
> the comment is reflown to what looks like a longer column limit. I currently 
> have a ratio of 10 between  PenaltyBreakComment and PenaltyExcessCharacter 
> (which empirically seemed to give a decent compromise, and match how our code 
> is formatted; I need to try more with your patch, to see if we can get better 
> values...): with this setting, a "non wrapped" comment will actually be 
> reflown to ColumnLimit+10...


To me the reverse intuitively makes sense:
When I see that
// first line
// second line
// third line
stays the same, but
// first line second line third line
gets reflown into something different, I get confused :)

The only way I see to consistently solve this is to optimize the reflow breaks 
like we do the main algorithm.

> When we do indeed reflow, I think we may be stricter than this, to get 
> something that really looks like it obeys the column limit. If this is 
> 'optimal' in the sense that we may have some overflow still, that is fine, 
> but really not the primary requirement IMHO.




https://reviews.llvm.org/D33589



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


[PATCH] D33589: clang-format: consider not splitting tokens in optimization

2017-11-23 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added a comment.

In https://reviews.llvm.org/D33589#933746, @Typz wrote:

> with this setting, a "non wrapped" comment will actually be reflown to 
> ColumnLimit+10...


Isn't the same true for code then, though? Generally, code will protrude by 10 
columns before being broken?


https://reviews.llvm.org/D33589



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


[PATCH] D40392: [clang-tidy] rename_check.py misc-argument-comment bugprone-argument-comment

2017-11-23 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh created this revision.
Herald added subscribers: xazax.hun, mgorny.

+ manually convert the unit test to lit test.


https://reviews.llvm.org/D40392

Files:
  clang-tidy/bugprone/ArgumentCommentCheck.cpp
  clang-tidy/bugprone/ArgumentCommentCheck.h
  clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tidy/bugprone/CMakeLists.txt
  clang-tidy/misc/ArgumentCommentCheck.cpp
  clang-tidy/misc/ArgumentCommentCheck.h
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/MiscTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/bugprone-argument-comment.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-argument-comment.rst
  test/clang-tidy/bugprone-argument-comment-gmock.cpp
  test/clang-tidy/bugprone-argument-comment-strict.cpp
  test/clang-tidy/bugprone-argument-comment.cpp
  test/clang-tidy/misc-argument-comment-gmock.cpp
  test/clang-tidy/misc-argument-comment-strict.cpp
  test/clang-tidy/misc-argument-comment.cpp
  unittests/clang-tidy/CMakeLists.txt
  unittests/clang-tidy/MiscModuleTest.cpp

Index: unittests/clang-tidy/MiscModuleTest.cpp
===
--- unittests/clang-tidy/MiscModuleTest.cpp
+++ /dev/null
@@ -1,39 +0,0 @@
-#include "ClangTidyTest.h"
-#include "misc/ArgumentCommentCheck.h"
-#include "gtest/gtest.h"
-
-namespace clang {
-namespace tidy {
-namespace test {
-
-using misc::ArgumentCommentCheck;
-
-TEST(ArgumentCommentCheckTest, CorrectComments) {
-  EXPECT_NO_CHANGES(ArgumentCommentCheck,
-"void f(int x, int y); void g() { f(/*x=*/0, /*y=*/0); }");
-  EXPECT_NO_CHANGES(ArgumentCommentCheck,
-"struct C { C(int x, int y); }; C c(/*x=*/0, /*y=*/0);");
-}
-
-TEST(ArgumentCommentCheckTest, ThisEditDistanceAboveThreshold) {
-  EXPECT_NO_CHANGES(ArgumentCommentCheck,
-"void f(int xxx); void g() { f(/*xyz=*/0); }");
-}
-
-TEST(ArgumentCommentCheckTest, OtherEditDistanceAboveThreshold) {
-  EXPECT_EQ("void f(int xxx, int yyy); void g() { f(/*xxx=*/0, 0); }",
-runCheckOnCode(
-"void f(int xxx, int yyy); void g() { f(/*Zxx=*/0, 0); }"));
-  EXPECT_EQ("struct C { C(int xxx, int yyy); }; C c(/*xxx=*/0, 0);",
-runCheckOnCode(
-"struct C { C(int xxx, int yyy); }; C c(/*Zxx=*/0, 0);"));
-}
-
-TEST(ArgumentCommentCheckTest, OtherEditDistanceBelowThreshold) {
-  EXPECT_NO_CHANGES(ArgumentCommentCheck,
-"void f(int xxx, int yyy); void g() { f(/*xxy=*/0, 0); }");
-}
-
-} // namespace test
-} // namespace tidy
-} // namespace clang
Index: unittests/clang-tidy/CMakeLists.txt
===
--- unittests/clang-tidy/CMakeLists.txt
+++ unittests/clang-tidy/CMakeLists.txt
@@ -12,7 +12,6 @@
   IncludeInserterTest.cpp
   GoogleModuleTest.cpp
   LLVMModuleTest.cpp
-  MiscModuleTest.cpp
   NamespaceAliaserTest.cpp
   ObjCModuleTest.cpp
   OverlappingReplacementsTest.cpp
@@ -29,7 +28,6 @@
   clangTidyAndroidModule
   clangTidyGoogleModule
   clangTidyLLVMModule
-  clangTidyMiscModule
   clangTidyObjCModule
   clangTidyReadabilityModule
   clangTidyUtils
Index: test/clang-tidy/bugprone-argument-comment.cpp
===
--- test/clang-tidy/bugprone-argument-comment.cpp
+++ test/clang-tidy/bugprone-argument-comment.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s misc-argument-comment %t
+// RUN: %check_clang_tidy %s bugprone-argument-comment %t
 
 // FIXME: clang-tidy should provide a -verify mode to make writing these checks
 // easier and more accurate.
@@ -14,9 +14,16 @@
   f(/*y=*/0, /*z=*/0);
   // CHECK-FIXES: {{^}}  f(/*y=*/0, /*z=*/0);
 
+  f(/*x=*/1, /*y=*/1);
+
   (0 /*=*/, /**/ 0); // Unsupported formats.
 }
 
+struct C {
+  C(int x, int y);
+};
+C c(/*x=*/0, /*y=*/0);
+
 struct Closure {};
 
 template 
@@ -45,11 +52,38 @@
 
 #define FALSE 0
 void qqq(bool aaa);
-void f() { qqq(/*bbb=*/FALSE); }
-// CHECK-MESSAGES: [[@LINE-1]]:16: warning: argument name 'bbb' in comment does not match parameter name 'aaa'
-// CHECK-FIXES: void f() { qqq(/*bbb=*/FALSE); }
+void f2() { qqq(/*bbb=*/FALSE); }
+// CHECK-MESSAGES: [[@LINE-1]]:17: warning: argument name 'bbb' in comment does not match parameter name 'aaa'
+// CHECK-FIXES: void f2() { qqq(/*bbb=*/FALSE); }
 
-void f(bool _with_underscores_);
+void f3(bool _with_underscores_);
 void ignores_underscores() {
-  f(/*With_Underscores=*/false);
+  f3(/*With_Underscores=*/false);
+}
+
+namespace ThisEditDistanceAboveThreshold {
+void f4(int xxx);
+void g() { f4(/*xyz=*/0); }
+// CHECK-MESSAGES: [[@LINE-1]]:15: warning: argument name 'xyz' in comment does not match parameter name 'xxx'
+// CHECK-FIXES: void g() { f4(/*xyz=*/0); }
+}
+
+namespace OtherEditDistanceAboveThreshold {
+void f5(int xxx, int yyy);
+void g() { f5(/*Zxx=*/0, 0); }
+// CHECK-MESSAGES: [[@LINE-1]]:15: warning: argument name 'Zxx' in comment does not match parameter name 

[PATCH] D39963: [RISCV][RFC] Add initial RISC-V target and driver support

2017-11-23 Thread Alex Bradbury via Phabricator via cfe-commits
asb marked an inline comment as done.
asb added a comment.

In https://reviews.llvm.org/D39963#931026, @apazos wrote:

> Can you push this as a patch to review/commit instead of RFC? It has received 
> a lot of comments/corrections already and I think it is getting in a shape we 
> can merge.


I might move the baremetal support to separate patch and discuss that on the 
mailing list. I'll remove the [RFC] tag in the next update, adding tests.




Comment at: test/Preprocessor/init.c:9991
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=riscv32 < /dev/null \
+// RUN:   | FileCheck -match-full-lines -check-prefix=RISCV32 %s
+// RISCV32: #define _ILP32 1

apazos wrote:
> Shouldn't we just check for the target specific defines  in these tests?
Many of the other tests seem to test a similarly large set of defines, plus I 
think you _do_ want to check the majority of these (especially the ones related 
to C types).


https://reviews.llvm.org/D39963



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


[PATCH] D30946: [ScopePrinting] Added support to print full scopes of types and declarations.

2017-11-23 Thread Simon Schroeder via Phabricator via cfe-commits
schroedersi added a comment.

Ping


https://reviews.llvm.org/D30946



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


[PATCH] D40176: [CodeGen] Collect information about sizes of accesses and access types for TBAA

2017-11-23 Thread Ivan Kosarev via Phabricator via cfe-commits
kosarev updated this revision to Diff 124084.
kosarev added a comment.

Rebased.


https://reviews.llvm.org/D40176

Files:
  lib/CodeGen/CGClass.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenModule.h
  lib/CodeGen/CodeGenTBAA.cpp
  lib/CodeGen/CodeGenTBAA.h

Index: lib/CodeGen/CodeGenTBAA.h
===
--- lib/CodeGen/CodeGenTBAA.h
+++ lib/CodeGen/CodeGenTBAA.h
@@ -36,40 +36,53 @@
 enum class TBAAAccessKind : unsigned {
   Ordinary,
   MayAlias,
+  Incomplete,
 };
 
 // TBAAAccessInfo - Describes a memory access in terms of TBAA.
 struct TBAAAccessInfo {
   TBAAAccessInfo(TBAAAccessKind Kind, llvm::MDNode *BaseType,
- llvm::MDNode *AccessType, uint64_t Offset)
-: Kind(Kind), BaseType(BaseType), AccessType(AccessType), Offset(Offset)
+ llvm::MDNode *AccessType, uint64_t Offset, uint64_t Size)
+: Kind(Kind), BaseType(BaseType), AccessType(AccessType),
+  Offset(Offset), Size(Size)
   {}
 
   TBAAAccessInfo(llvm::MDNode *BaseType, llvm::MDNode *AccessType,
- uint64_t Offset)
-: TBAAAccessInfo(TBAAAccessKind::Ordinary, BaseType, AccessType, Offset)
+ uint64_t Offset, uint64_t Size)
+: TBAAAccessInfo(TBAAAccessKind::Ordinary, BaseType, AccessType,
+ Offset, Size)
   {}
 
-  explicit TBAAAccessInfo(llvm::MDNode *AccessType)
-: TBAAAccessInfo(/* BaseType= */ nullptr, AccessType, /* Offset= */ 0)
+  explicit TBAAAccessInfo(llvm::MDNode *AccessType, uint64_t Size)
+: TBAAAccessInfo(/* BaseType= */ nullptr, AccessType, /* Offset= */ 0, Size)
   {}
 
   TBAAAccessInfo()
-: TBAAAccessInfo(/* AccessType= */ nullptr)
+: TBAAAccessInfo(/* AccessType= */ nullptr, /* Size= */ 0)
   {}
 
   static TBAAAccessInfo getMayAliasInfo() {
-return TBAAAccessInfo(TBAAAccessKind::MayAlias, /* BaseType= */ nullptr,
-  /* AccessType= */ nullptr, /* Offset= */ 0);
+return TBAAAccessInfo(TBAAAccessKind::MayAlias,
+  /* BaseType= */ nullptr, /* AccessType= */ nullptr,
+  /* Offset= */ 0, /* Size= */ 0);
   }
 
   bool isMayAlias() const { return Kind == TBAAAccessKind::MayAlias; }
 
+  static TBAAAccessInfo getIncompleteInfo() {
+return TBAAAccessInfo(TBAAAccessKind::Incomplete,
+  /* BaseType= */ nullptr, /* AccessType= */ nullptr,
+  /* Offset= */ 0, /* Size= */ 0);
+  }
+
+  bool isIncomplete() const { return Kind == TBAAAccessKind::Incomplete; }
+
   bool operator==(const TBAAAccessInfo &Other) const {
 return Kind == Other.Kind &&
BaseType == Other.BaseType &&
AccessType == Other.AccessType &&
-   Offset == Other.Offset;
+   Offset == Other.Offset &&
+   Size == Other.Size;
   }
 
   bool operator!=(const TBAAAccessInfo &Other) const {
@@ -95,12 +108,16 @@
   /// Offset - The byte offset of the final access within the base one. Must be
   /// zero if the base access type is not specified.
   uint64_t Offset;
+
+  /// Size - The size of access, in bytes.
+  uint64_t Size;
 };
 
 /// CodeGenTBAA - This class organizes the cross-module state that is used
 /// while lowering AST types to LLVM types.
 class CodeGenTBAA {
   ASTContext &Context;
+  llvm::Module &Module;
   const CodeGenOptions &CodeGenOpts;
   const LangOptions &Features;
   MangleContext &MContext;
@@ -138,10 +155,10 @@
  SmallVectorImpl &Fields,
  bool MayAlias);
 
-  /// A wrapper function to create a scalar type. For struct-path aware TBAA,
-  /// the scalar type has the same format as the struct type: name, offset,
-  /// pointer to another node in the type DAG.
-  llvm::MDNode *createTBAAScalarType(StringRef Name, llvm::MDNode *Parent);
+  /// createScalarTypeNode - A wrapper function to create a metadata node
+  /// describing a scalar type.
+  llvm::MDNode *createScalarTypeNode(StringRef Name, llvm::MDNode *Parent,
+ uint64_t Size);
 
   /// getTypeInfoHelper - An internal helper function to generate metadata used
   /// to describe accesses to objects of the given type.
@@ -152,19 +169,17 @@
   llvm::MDNode *getBaseTypeInfoHelper(const Type *Ty);
 
 public:
-  CodeGenTBAA(ASTContext &Ctx, llvm::LLVMContext &VMContext,
-  const CodeGenOptions &CGO,
-  const LangOptions &Features,
-  MangleContext &MContext);
+  CodeGenTBAA(ASTContext &Ctx, llvm::Module &M, const CodeGenOptions &CGO,
+  const LangOptions &Features, MangleContext &MContext);
   ~CodeGenTBAA();
 
   /// getTypeInfo - Get metadata used to describe accesses to objects of the
   /// given type.
   llvm::MDNode *getTypeInfo(QualType QTy);
 
   /// getVTablePtrAccessInfo - Get the TBAA information that describes an
   /// access to a virtual table pointer.
-  TBAAAccessInfo getVTablePtrAccessInfo();
+  TBAAAccessInfo get

[PATCH] D40310: Restructure how we break tokens.

2017-11-23 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added inline comments.



Comment at: lib/Format/BreakableToken.cpp:198
+ "Getting the length of a part of the string literal indicates that "
+ "the code tries to reflow it.");
+  return UnbreakableTailLength + Postfix.size() +

klimek wrote:
> krasimir wrote:
> > How about clients that explicitly pass `Length = Line.size() - Offset`?
> That is different (I now also went and updated the comment for getRangeLength 
> to explain that).
> 
> Generally, Length == Line.size() - Offset is still a portion of the content, 
> as opposed to npos, which has a special meaning. I'm wondering whether I 
> should just pull out a differently named method for it, now that I'm thinking 
> about it.
Yes please!



Comment at: lib/Format/ContinuationIndenter.cpp:1504
  : Style.PenaltyBreakComment;
-  unsigned RemainingSpace = ColumnLimit - Current.UnbreakableTailLength;
+  // Stores whether we introduce a break anywhere in the token.
   bool BreakInserted = Token->introducesBreakBeforeToken();

klimek wrote:
> krasimir wrote:
> > Does a reflow count as a break?
> I do believe so (well, the break in the reflow counts, the reflow itself is 
> not a break, but removing a break :)
So, if we add a break then remove a break while reflowing, will `BreakInserted` 
be true or false?



Comment at: unittests/Format/FormatTestComments.cpp:2149
+  // to keep this?
+  EXPECT_EQ("// some text\n"
+"// that\n"

klimek wrote:
> krasimir wrote:
> > This is like this for cases like lists in comments:
> > ```
> > blah-blah-blah:
> >   1. blah
> >   2. blah-blah
> > ```
> > I think here the block comments behavior might be wrong.
> Note that on the doc I shared you voted the reverse ;)
Then I should consider re-voting :)


https://reviews.llvm.org/D40310



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


[PATCH] D40132: [clangd] Tracing improvements

2017-11-23 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clangd/JSONRPCDispatcher.h:78
   llvm::Optional ID;
+  std::unique_ptr Tracer;
 };

ilya-biryukov wrote:
> sammccall wrote:
> > ilya-biryukov wrote:
> > > Why do we need `unique_ptr`? Are `Span`s non-movable?
> > Spans aren't movable, they have an explicitly declared destructor. (The 
> > copy constructor is only deprecated by this condition, but Span has a 
> > unique_ptr member).
> > 
> > We could make them movable, though it's not absolutely trivial (we need an 
> > extra bool to indicate that this is moved-from and the destructor should be 
> > a no-op).
> > 
> > I think wrapping them in a `unique_ptr` here is slightly simpler than 
> > implementing the right move semantics by hand, but LMK what you think.
> > We could make them movable, though it's not absolutely trivial (we need an 
> > extra bool to indicate that this is moved-from and the destructor should be 
> > a no-op).
> I kinda hate this part when dealing with movable objects, too. I still do 
> that, mostly to avoid heap allocs, but we're not on a hot path, so it's fine 
> both ways.
> We could use `llvm::Optional` instead of `unique_ptr` to get rid of the heap 
> alloc too.
Oh, sorry, `llvm::Optional` surely doesn't help here, it would still be 
non-movable. Forget what I said.


https://reviews.llvm.org/D40132



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


[PATCH] D40392: [clang-tidy] rename_check.py misc-argument-comment bugprone-argument-comment

2017-11-23 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

LGTM.


https://reviews.llvm.org/D40392



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


[PATCH] D39722: [ASTImporter] Support TypeTraitExpr Importing

2017-11-23 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In https://reviews.llvm.org/D39722#933699, @a.sidorin wrote:

> Hello Takafumi,
>
> This is almost OK to me but there is an inline comment we need to resolve in 
> order to avoid Windows buildbot failures.
>  In addition, as Gabor pointed, when we add a new matcher, we need to update 
> matcher documentation as well. To update the docs, you should perform just 
> three steps.
>
> 1. Rebase your patch onto latest master
> 2. Launch script docs/tools/dump_ast_matchers.py
> 3. Add changes made by this script to your commit.


I'm a bit confused -- I don't see any ASTMatcher changes as part of this patch 
aside from what's in the test file. Are you suggesting the matcher there should 
be hoisted as a separate patch?


https://reviews.llvm.org/D39722



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


[PATCH] D39722: [ASTImporter] Support TypeTraitExpr Importing

2017-11-23 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

In https://reviews.llvm.org/D39722#933828, @aaron.ballman wrote:

> In https://reviews.llvm.org/D39722#933699, @a.sidorin wrote:
>
> > Hello Takafumi,
> >
> > This is almost OK to me but there is an inline comment we need to resolve 
> > in order to avoid Windows buildbot failures.
> >  In addition, as Gabor pointed, when we add a new matcher, we need to 
> > update matcher documentation as well. To update the docs, you should 
> > perform just three steps.
> >
> > 1. Rebase your patch onto latest master
> > 2. Launch script docs/tools/dump_ast_matchers.py
> > 3. Add changes made by this script to your commit.
>
>
> I'm a bit confused -- I don't see any ASTMatcher changes as part of this 
> patch aside from what's in the test file. Are you suggesting the matcher 
> there should be hoisted as a separate patch?


In a previous version the matcher was public. I think it either should be 
public with documentation or it can remain in the test file and no doc update 
required. I am fine with both solution.


https://reviews.llvm.org/D39722



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


[PATCH] D39722: [ASTImporter] Support TypeTraitExpr Importing

2017-11-23 Thread Aleksei Sidorin via Phabricator via cfe-commits
a.sidorin added a comment.

Oh, sorry! I was thinking that a matcher is still in ASTMatchers.h (in previous 
revisions it was there). If matcher is internal (current revision), there is no 
need to update docs.


https://reviews.llvm.org/D39722



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


[PATCH] D39722: [ASTImporter] Support TypeTraitExpr Importing

2017-11-23 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In https://reviews.llvm.org/D39722#933838, @xazax.hun wrote:

> In https://reviews.llvm.org/D39722#933828, @aaron.ballman wrote:
>
> > In https://reviews.llvm.org/D39722#933699, @a.sidorin wrote:
> >
> > > Hello Takafumi,
> > >
> > > This is almost OK to me but there is an inline comment we need to resolve 
> > > in order to avoid Windows buildbot failures.
> > >  In addition, as Gabor pointed, when we add a new matcher, we need to 
> > > update matcher documentation as well. To update the docs, you should 
> > > perform just three steps.
> > >
> > > 1. Rebase your patch onto latest master
> > > 2. Launch script docs/tools/dump_ast_matchers.py
> > > 3. Add changes made by this script to your commit.
> >
> >
> > I'm a bit confused -- I don't see any ASTMatcher changes as part of this 
> > patch aside from what's in the test file. Are you suggesting the matcher 
> > there should be hoisted as a separate patch?
>
>
> In a previous version the matcher was public. I think it either should be 
> public with documentation or it can remain in the test file and no doc update 
> required. I am fine with both solution.


I'm fine with either exposing it as a public matcher or leaving it private for 
the test file, but if it gets exposed, I think it should be in a separate patch.


https://reviews.llvm.org/D39722



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


[PATCH] D40108: [clang-tidy] Adding Fuchsia checkers to clang-tidy

2017-11-23 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang-tidy/fuchsia/DefaultArgumentsCheck.cpp:35-38
+SourceRange RemovalRange(
+  Lexer::getLocForEndOfToken(D->getLocation(), 0, 
+*Result.SourceManager, Result.Context->getLangOpts()),
+  D->getDefaultArgRange().getEnd()

juliehockett wrote:
> aaron.ballman wrote:
> > Does `getDefaultArgRange()` not provide the correct range already (so you 
> > don't need to go back to the original source)? Or does that range miss the 
> > `=`?
> > 
> > You might want to disable the fix-it in the case `getDefaultArgRange()` 
> > returns an empty range, or in case the default arg expression comes from a 
> > macro (and add a test for the latter case). e.g.,
> > ```
> > #define DERP(val)  = val
> > 
> > void f(int i DERP);
> > ```
> > Additionally, a test where the identifier is elided would be good as well: 
> > `void f(int = 12);`
> `getDefaultArgRange()` misses the `=` -- though if there's a better way to do 
> it I'm all ears! 
In that case, this seems fine to me.



Comment at: clang-tidy/fuchsia/DefaultArgumentsCheck.cpp:31
+diag(S->getParam()->getLocStart(),
+"the default parameter was declared here",
+ DiagnosticIDs::Note);

Drop "the" from the diagnostic to match wording in other places



Comment at: clang-tidy/fuchsia/DefaultArgumentsCheck.cpp:44
+  diag(DefaultArgRange.getBegin(),
+"the default parameter was declared here",
+DiagnosticIDs::Note);

Drop "the" here as well.



Comment at: clang-tidy/fuchsia/DefaultArgumentsCheck.cpp:48-52
+  if (!D->getName().empty()) {
+   StartLocation = D->getLocation();
+  } else {
+   StartLocation = D->getLocStart();
+  }

This can be hoisted to the initialization: `SourceLocation StartLocation = 
D->getName().empty() ? D->getLocStart() : D->getLocation();`



Comment at: test/clang-tidy/fuchsia-default-arguments.cpp:40
+  return value;
+  // CHECK-MESSAGES: [[@LINE-2]]:12: warning: declaring a parameter with a 
default argument is disallowed [fuchsia-default-arguments]
+  // CHECK-NEXT: note: the default parameter was declared here:

I think this diagnostic should be suppressed -- having it on the declaration 
where the default argument is defined should be sufficient, no?



Comment at: test/clang-tidy/fuchsia-default-arguments.cpp:57
+// CHECK-MESSAGES: [[@LINE-1]]:8: warning: declaring a parameter with a 
default argument is disallowed [fuchsia-default-arguments]
+// CHECK-FIXES-NOT: void h(int i);

Two more test cases that should be added:
```
void f(int i);
void f(int i = 12);

void f(int i) {

}

struct S {
  void f(int i);
};

void S::f(int i = 12) {}

int main() {
  S s;
  s.f();
  f();
}
```


https://reviews.llvm.org/D40108



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


[PATCH] D40310: Restructure how we break tokens.

2017-11-23 Thread Manuel Klimek via Phabricator via cfe-commits
klimek updated this revision to Diff 124095.
klimek added a comment.

Pull out getRemainingLength.


https://reviews.llvm.org/D40310

Files:
  lib/Format/BreakableToken.cpp
  lib/Format/BreakableToken.h
  lib/Format/ContinuationIndenter.cpp
  unittests/Format/FormatTest.cpp
  unittests/Format/FormatTestComments.cpp

Index: unittests/Format/FormatTestComments.cpp
===
--- unittests/Format/FormatTestComments.cpp
+++ unittests/Format/FormatTestComments.cpp
@@ -1096,11 +1096,12 @@
 }
 
 TEST_F(FormatTestComments, SplitsLongLinesInComments) {
+  // FIXME: Do we need to fix up the "  */" at the end?
+  // It doesn't look like any of our current logic triggers this.
   EXPECT_EQ("/* This is a long\n"
 " * comment that\n"
-" * doesn't\n"
-" * fit on one line.\n"
-" */",
+" * doesn't fit on\n"
+" * one line.  */",
 format("/* "
"This is a long "
"comment that "
@@ -2102,6 +2103,66 @@
   EXPECT_EQ("///", format(" ///  ", getLLVMStyleWithColumns(20)));
 }
 
+TEST_F(FormatTestComments, ReflowsCommentsPrecise) {
+  // FIXME: This assumes we do not continue compressing whitespace once we are
+  // in reflow mode. Consider compressing whitespace.
+
+  // Test that we stop reflowing precisely at the column limit.
+  // After reflowing, "// reflows into   foo" does not fit the column limit,
+  // so we compress the whitespace.
+  EXPECT_EQ("// some text that\n"
+"// reflows into foo\n",
+format("// some text that reflows\n"
+   "// into   foo\n",
+   getLLVMStyleWithColumns(20)));
+  // Given one more column, "// reflows into   foo" does fit the limit, so we
+  // do not compress the whitespace.
+  EXPECT_EQ("// some text that\n"
+"// reflows into   foo\n",
+format("// some text that reflows\n"
+   "// into   foo\n",
+   getLLVMStyleWithColumns(21)));
+}
+
+TEST_F(FormatTestComments, ReflowsCommentsWithExtraWhitespace) {
+  // Baseline.
+  EXPECT_EQ("// some text\n"
+"// that re flows\n",
+format("// some text that\n"
+   "// re flows\n",
+   getLLVMStyleWithColumns(16)));
+  EXPECT_EQ("// some text\n"
+"// that re flows\n",
+format("// some text that\n"
+   "// reflows\n",
+   getLLVMStyleWithColumns(16)));
+  EXPECT_EQ("/* some text\n"
+" * that re flows\n"
+" */\n",
+format("/* some text that\n"
+   "*  re   flows\n"
+   "*/\n",
+   getLLVMStyleWithColumns(16)));
+  // FIXME: We do not reflow if the indent of two subsequent lines differs;
+  // given that this is different behavior from block comments, do we want
+  // to keep this?
+  EXPECT_EQ("// some text\n"
+"// that\n"
+"// re flows\n",
+format("// some text that\n"
+   "// re   flows\n",
+   getLLVMStyleWithColumns(16)));
+  // Space within parts of a line that fit.
+  // FIXME: Use the earliest possible split while reflowing to compress the
+  // whitespace within the line.
+  EXPECT_EQ("// some text that\n"
+"// does re   flow\n"
+"// more  here\n",
+format("// some text that does\n"
+   "// re   flow  more  here\n",
+   getLLVMStyleWithColumns(21)));
+}
+
 TEST_F(FormatTestComments, IgnoresIf0Contents) {
   EXPECT_EQ("#if 0\n"
 "}{)(&*(^%%#%@! fsadj f;ldjs ,:;| <<<>>>][)(][\n"
@@ -2484,6 +2545,7 @@
   " long */\n"
   "  b);",
   format("a = f(a, /* long long */ b);", getLLVMStyleWithColumns(16)));
+
   EXPECT_EQ(
   "a = f(\n"
   "a,\n"
@@ -2888,16 +2950,15 @@
getLLVMStyleWithColumns(20)));
 }
 
-TEST_F(FormatTestComments, NoCrush_Bug34236) {
+TEST_F(FormatTestComments, NoCrash_Bug34236) {
   // This is a test case from a crasher reported in:
   // https://bugs.llvm.org/show_bug.cgi?id=34236
   // Temporarily disable formatting for readability.
   // clang-format off
   EXPECT_EQ(
 "/**/ /*\n"
 "  *   a\n"
-"  * b c\n"
-"  * d*/",
+"  * b c d*/",
   format(
 "/**/ /*\n"
 " *   a b\n"
Index: unittests/Format/FormatTest.cpp
===
--- unittests/Forma

[PATCH] D38425: [clangd] Document highlights for clangd

2017-11-23 Thread Marc-Andre Laperle via Phabricator via cfe-commits
malaperle requested changes to this revision.
malaperle added inline comments.
This revision now requires changes to proceed.



Comment at: clangd/ClangdLSPServer.cpp:67
 );
+
   if (Params.rootUri && !Params.rootUri->file.empty())

extra line



Comment at: clangd/ClangdLSPServer.cpp:242
+
+  auto Items = Server
+   .findDocumentHighlights(Params.textDocument.uri.file,

Items -> Highlights?



Comment at: clangd/ClangdServer.h:291
+  /// Get document highlights for a symbol hovered on.
+  Tagged> findDocumentHighlights(PathRef File,
+Position Pos);

can this thing fail? Should it be Expected DeclarationLocations;

I think this class should be exactly the same as the code hover patch, so 
changes from there and the comments on that patch should apply here too.



Comment at: clangd/ClangdUnit.cpp:944
   std::vector DeclarationLocations;
+  std::vector DeclarationDecls;
+  std::vector DeclarationMacroInfos;

just Decls?



Comment at: clangd/ClangdUnit.cpp:945
+  std::vector DeclarationDecls;
+  std::vector DeclarationMacroInfos;
+  std::vector Kinds;

just MacroInfos?



Comment at: clangd/ClangdUnit.cpp:946
+  std::vector DeclarationMacroInfos;
+  std::vector Kinds;
   const SourceLocation &SearchedLocation;

remove, see comment below.



Comment at: clangd/ClangdUnit.cpp:961
+   std::sort(DeclarationDecls.begin(), DeclarationDecls.end());
+   auto last =
+   std::unique(DeclarationDecls.begin(), DeclarationDecls.end());

Last



Comment at: clangd/ClangdUnit.cpp:969
+// Don't keep the same location multiple times.
+// This can happen when nodes in the AST are visited twice.
+std::sort(DeclarationMacroInfos.begin(), DeclarationMacroInfos.end());

This comment needs to be updated (like the code hover patch)



Comment at: clangd/ClangdUnit.cpp:971
+std::sort(DeclarationMacroInfos.begin(), DeclarationMacroInfos.end());
+auto last =
+std::unique(DeclarationMacroInfos.begin(), 
DeclarationMacroInfos.end());

Last



Comment at: clangd/ClangdUnit.cpp:992
   index::IndexDataConsumer::ASTNodeInfo ASTNode) override {
+
 if (isSearchedLocation(FID, Offset)) {

extra line



Comment at: clangd/ClangdUnit.cpp:996
+  DeclarationDecls.push_back(D);
+  DocumentHighlightKind Kind;
+  switch (Roles) {

I think you need to do this in DocumentHighlightsFinder not here. Each 
occurrence can have its kind, not just the user selected location.



Comment at: clangd/ClangdUnit.cpp:1013
 
+  std::vector getDeclarationDecls() { return DeclarationDecls; };
+  std::vector getDeclarationMacroInfos() { return 
DeclarationMacroInfos; };

I don't think you need any of those getters. Only use the "takes"



Comment at: clangd/ClangdUnit.cpp:1079
 
+/// Finds document highlights that a given FileID and file offset refers to.
+class DocumentHighlightsFinder : public index::IndexDataConsumer {

It's not "a given FileID and file", the finder is given a list of Decls



Comment at: clangd/ClangdUnit.cpp:1122
 
+Location clangd::addDeclarationLocation(ParsedAST &AST, SourceRange SR) {
+  const SourceManager &SourceMgr = AST.getASTContext().getSourceManager();

This is duplicated code with getDeclarationLocation. It also doesn't use 
tryGetRealPathName
I also don't think this is called??



Comment at: clangd/ClangdUnit.cpp:1165
 
+Location clangd::getDeclarationLocation(ParsedAST &AST,
+const SourceRange &ValSourceRange) {

I don't think this is called?



Comment at: clangd/ClangdUnit.cpp:1191
+
+DocumentHighlight clangd::addHighlightLocation(ParsedAST &AST, SourceRange SR,
+   DocumentHighlightKind Kind) {

This doesn't add  or have a location in its signature so I think it should be 
named differently. 
DocumentHighligh getDocumentHighlight(Decl*) ? Or addDocumentHighlight(Decl*) 
if you move it in DocumentHighlightsFinder.



Comment at: clangd/ClangdUnit.cpp:1232
+
+  std::vector TempDecls = 
DeclLocationsFinder->getDeclarationDecls();
+  std::vector TempKinds =

call takeDecls. TempDecls -> SelectedDecls?



Comment at: clangd/ClangdUnit.cpp:1233
+  std::vector TempDecls = 
DeclLocationsFinder->getDeclarationDecls();
+  std::vector TempKinds =
+  DeclLocationsFinder->getKinds();

remove? see comment

[PATCH] D40310: Restructure how we break tokens.

2017-11-23 Thread Manuel Klimek via Phabricator via cfe-commits
klimek marked an inline comment as done.
klimek added inline comments.



Comment at: lib/Format/ContinuationIndenter.cpp:1504
  : Style.PenaltyBreakComment;
-  unsigned RemainingSpace = ColumnLimit - Current.UnbreakableTailLength;
+  // Stores whether we introduce a break anywhere in the token.
   bool BreakInserted = Token->introducesBreakBeforeToken();

krasimir wrote:
> klimek wrote:
> > krasimir wrote:
> > > Does a reflow count as a break?
> > I do believe so (well, the break in the reflow counts, the reflow itself is 
> > not a break, but removing a break :)
> So, if we add a break then remove a break while reflowing, will 
> `BreakInserted` be true or false?
True.


https://reviews.llvm.org/D40310



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


[PATCH] D40060: [clangd] Fuzzy match scorer

2017-11-23 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Thanks for the review, and sorry for the subtlety of the code and sparse 
comments.
It should be a little better now, please let me know which parts aren't clear 
enough.




Comment at: clangd/FuzzyMatch.cpp:69
+: NPat(std::min(MaxPat, Pattern.size())), NWord(0),
+  ScoreScale(0.5f / NPat) {
+  memcpy(Pat, Pattern.data(), NPat);

klimek wrote:
> Why .5?
The .5 and the 2 are the same thing. Extracted a constant with a comment.



Comment at: clangd/FuzzyMatch.cpp:92
+// Segmentation of words and patterns
+// We mark each character as the Head or Tail of a segment, or a Separator.
+// e.g. XMLHttpRequest_Async

klimek wrote:
> Do you mean "part of the Head or Tail"?
> Also, explain that these are the CharRoles. A reader reads this first, and 
> will search for what CharRole means in the code later. CharRole is defined in 
> a different file, without comments, so figuring out how that all relates is 
> super hard :)
Rewrote this section and added more comments. CharRole is defined here now.

Each character in a segment that isn't the Head is the Tail. It's a bit of a 
stretch, but it's short and evocative and (now) explained with examples.



Comment at: clangd/FuzzyMatch.cpp:110
+// 4 packed CharTypes per entry, indexed by char.
+constexpr uint8_t CharTypes[] = {
+0x00, 0x00, 0x00, 0x00, // Control characters

klimek wrote:
> Finding bugs in these will be hard :)
Ack :-(



Comment at: clangd/FuzzyMatch.cpp:120
+0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, // Bytes over 127 -> Lower.
+0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, // This includes UTF-8.
+0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,

klimek wrote:
> Can you expand in the comment why this works for utf-8?
Done. It doesn't really "work", so much as we just give up...



Comment at: clangd/FuzzyMatch.cpp:212
+  ScoreT S = 0;
+  // Bonus: pattern is part of a word prefix.
+  if (P == W)

klimek wrote:
> Why does P == W imply that?
Every pattern character must match in order, so a match with P < W is 
impossible, and P == W means the match is perfect so far.
(Also explained in the comment)



Comment at: clangd/FuzzyMatch.cpp:215
+++S;
+  // Bonus: case matches, or an asserted word break matches an actual.
+  if (Pat[P] == Word[W] || (PatRole[P] == Head && WordRole[W] == Head))

klimek wrote:
> This is the first time the term "asserted word break" shows up, perhaps 
> explain this when explaining the roles.
Rephrased the comment here to use the familiar terminology.



Comment at: clangd/FuzzyMatch.h:39
+
+private:
+  constexpr static int MaxPat = 63;

klimek wrote:
> I find most of the abbreviations here non-intuitive, and thus needing 
> comments (Pat I get is for pattern :)
> N - what does it mean? Number of characters in the pattern? I'd use Length 
> instead.
> LPat and LWord (no idea what L could stand for).
> 
Comments added throughout.

> N - what does it mean? Number of characters in the pattern? I'd use Length 
> instead.

`WordLength` is too long for something so common I think, these each have >20 
refs. Changed `NWord` -> `WordN` which I think reads better - `Word` and 
`WordN` form a nice pair.

(N rather than L for length because of confusion with Lower)

Changed `LWord` to `LowWord` etc.



Comment at: clangd/FuzzyMatch.h:50
+
+  int NPat, NWord;
+  char Pat[MaxPat];

klimek wrote:
> I'd use a StringRef instead, and call the storage *Storage or something.
What's the goal here?

I have a couple of objections to this:
 - if you actually use StringRef[] to access the data, now you've got a 
gratuitous indirection everywhere
 - For `LPat`/`LWord` too? Now we have *more* members than in the first place, 
and two ways to write each bounds check.

If the intent is to clean up the places where I construct `StringRef(Word, 
NWord)` explicitly, adding `StringRef word()` would certainly make sense.


https://reviews.llvm.org/D40060



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


[PATCH] D40060: [clangd] Fuzzy match scorer

2017-11-23 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 124096.
sammccall marked 15 inline comments as done.
sammccall added a comment.

Addressing review comments and generally improving comments.


https://reviews.llvm.org/D40060

Files:
  clangd/CMakeLists.txt
  clangd/FuzzyMatch.cpp
  clangd/FuzzyMatch.h
  unittests/clangd/CMakeLists.txt
  unittests/clangd/FuzzyMatchTests.cpp

Index: unittests/clangd/FuzzyMatchTests.cpp
===
--- /dev/null
+++ unittests/clangd/FuzzyMatchTests.cpp
@@ -0,0 +1,130 @@
+//===-- FuzzyMatchTests.cpp - String fuzzy matcher tests *- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "FuzzyMatch.h"
+
+#include "llvm/ADT/StringExtras.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace clangd {
+namespace {
+using namespace llvm;
+using testing::Not;
+
+struct MatchesMatcher : public testing::MatcherInterface {
+  StringRef Candidate;
+  MatchesMatcher(StringRef Candidate) : Candidate(Candidate) {}
+
+  void DescribeTo(::std::ostream *OS) const override {
+*OS << "Matches '" << Candidate.str() << "'";
+  }
+
+  bool MatchAndExplain(StringRef Pattern,
+   testing::MatchResultListener *L) const override {
+std::unique_ptr OS(
+L->stream() ? (raw_ostream *)(new raw_os_ostream(*L->stream()))
+: new raw_null_ostream());
+FuzzyMatcher Matcher(Pattern);
+auto Result = Matcher.match(Candidate);
+Matcher.dumpLast(*OS << "\n");
+return !!Result;
+  }
+};
+
+// Accepts patterns that match a given word.
+// Dumps the debug tables on match failure.
+testing::Matcher matches(StringRef Word) {
+  return testing::MakeMatcher(new MatchesMatcher(Word));
+}
+
+TEST(FuzzyMatch, Matches) {
+  EXPECT_THAT("u_p", matches("unique_ptr"));
+  EXPECT_THAT("up", matches("unique_ptr"));
+  EXPECT_THAT("uq", matches("unique_ptr"));
+  EXPECT_THAT("qp", Not(matches("unique_ptr")));
+  EXPECT_THAT("log", Not(matches("SVGFEMorphologyElement")));
+}
+
+struct RankMatcher : public testing::MatcherInterface {
+  std::vector RankedStrings;
+  RankMatcher(std::initializer_list RankedStrings)
+  : RankedStrings(RankedStrings) {}
+
+  void DescribeTo(::std::ostream *OS) const override {
+*OS << "Ranks strings in order: ["
+<< join(RankedStrings.begin(), RankedStrings.end(), ", ") << "]";
+  }
+
+  bool MatchAndExplain(StringRef Pattern,
+   testing::MatchResultListener *L) const override {
+std::unique_ptr OS(
+L->stream() ? (raw_ostream *)(new raw_os_ostream(*L->stream()))
+: new raw_null_ostream());
+FuzzyMatcher Matcher(Pattern);
+StringRef LastString;
+Optional LastScore;
+bool Ok = true;
+for (StringRef Str : RankedStrings) {
+  auto Score = Matcher.match(Str);
+  if (!Score) {
+*OS << "\nDoesn't match '" << Str.str() << "'";
+Matcher.dumpLast(*OS << "\n");
+Ok = false;
+  } else if (LastScore && *LastScore < *Score) {
+*OS << "\nRanks '" << Str.str() << "'=" << *Score << " above '"
+<< LastString.str() << "'=" << *LastScore;
+Matcher.dumpLast(*OS << "\n");
+Matcher.match(LastString);
+Matcher.dumpLast(*OS << "\n");
+Ok = false;
+  }
+  LastString = Str;
+  LastScore = Score;
+}
+return Ok;
+  }
+};
+
+// Accepts patterns that match all the strings and rank them in the given order.
+// Dumps the debug tables on match failure.
+template  testing::Matcher ranks(T... RankedStrings) {
+  return testing::MakeMatcher(new RankMatcher{RankedStrings...});
+}
+
+TEST(FuzzyMatch, Ranking) {
+  EXPECT_THAT("eb", ranks("emplace_back", "embed"));
+  EXPECT_THAT("cons", ranks("console", "Console", "ArrayBufferConstructor"));
+  EXPECT_THAT("foo", ranks("foo", "Foo"));
+  EXPECT_THAT("onMess", ranks("onMessage", "onmessage", "onThisMegaEscapes"));
+  EXPECT_THAT("CC", ranks("CamelCase", "camelCase"));
+  EXPECT_THAT("cC", ranks("camelCase", "CamelCase"));
+  EXPECT_THAT("p", ranks("parse", "posix", "pafdsa", "path", "p"));
+  EXPECT_THAT("pa", ranks("parse", "path", "pafdsa"));
+  EXPECT_THAT("log", ranks("log", "ScrollLogicalPosition"));
+  EXPECT_THAT("e", ranks("else", "AbstractElement"));
+  EXPECT_THAT("workbench.sideb",
+  ranks("workbench.sideBar.location",
+"workbench.editor.defaultSideBySideLayout"));
+  EXPECT_THAT("editor.r", ranks("editor.renderControlCharacter",
+"editor.overviewRulerlanes",
+"diffEditor.renderSideBySide"));
+  EXPECT_THAT("-mo", ranks("-moz-columns", "-ms-ime-mode"));
+  EXPECT_THAT("convertModelPosition",
+

[clang-tools-extra] r318925 - [clangd] Drop impossible completions (unavailable or inaccessible)

2017-11-23 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Thu Nov 23 08:58:22 2017
New Revision: 318925

URL: http://llvm.org/viewvc/llvm-project?rev=318925&view=rev
Log:
[clangd] Drop impossible completions (unavailable or inaccessible)

Summary: (There must be some reason why D38077 didn't just do this, but I don't 
get it!)

Reviewers: ilya-biryukov

Subscribers: cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
clang-tools-extra/trunk/clangd/ClangdLSPServer.h
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/ClangdServer.h
clang-tools-extra/trunk/clangd/ClangdUnit.cpp
clang-tools-extra/trunk/clangd/ClangdUnit.h
clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
clang-tools-extra/trunk/test/clangd/completion-items-kinds.test
clang-tools-extra/trunk/test/clangd/completion-priorities.test
clang-tools-extra/trunk/test/clangd/completion-qualifiers.test
clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=318925&r1=318924&r2=318925&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Thu Nov 23 08:58:22 2017
@@ -236,14 +236,12 @@ void ClangdLSPServer::onSwitchSourceHead
 
 ClangdLSPServer::ClangdLSPServer(JSONOutput &Out, unsigned AsyncThreadsCount,
  bool StorePreamblesInMemory,
- bool SnippetCompletions,
+ const clangd::CodeCompleteOptions &CCOpts,
  llvm::Optional ResourceDir,
  llvm::Optional CompileCommandsDir)
 : Out(Out), CDB(/*Logger=*/Out, std::move(CompileCommandsDir)),
   Server(CDB, /*DiagConsumer=*/*this, FSProvider, AsyncThreadsCount,
- StorePreamblesInMemory,
- clangd::CodeCompleteOptions(
- /*EnableSnippetsAndCodePatterns=*/SnippetCompletions),
+ StorePreamblesInMemory, CCOpts,
  /*Logger=*/Out, ResourceDir) {}
 
 bool ClangdLSPServer::run(std::istream &In) {

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.h?rev=318925&r1=318924&r2=318925&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.h Thu Nov 23 08:58:22 2017
@@ -31,7 +31,8 @@ public:
   /// loaded only from \p CompileCommandsDir. Otherwise, clangd will look
   /// for compile_commands.json in all parent directories of each file.
   ClangdLSPServer(JSONOutput &Out, unsigned AsyncThreadsCount,
-  bool StorePreamblesInMemory, bool SnippetCompletions,
+  bool StorePreamblesInMemory,
+  const clangd::CodeCompleteOptions &CCOpts,
   llvm::Optional ResourceDir,
   llvm::Optional CompileCommandsDir);
 

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=318925&r1=318924&r2=318925&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Thu Nov 23 08:58:22 2017
@@ -169,11 +169,14 @@ ClangdScheduler::~ClangdScheduler() {
 Worker.join();
 }
 
-ClangdServer::ClangdServer(
-GlobalCompilationDatabase &CDB, DiagnosticsConsumer &DiagConsumer,
-FileSystemProvider &FSProvider, unsigned AsyncThreadsCount,
-bool StorePreamblesInMemory, clangd::CodeCompleteOptions CodeCompleteOpts,
-clangd::Logger &Logger, llvm::Optional ResourceDir)
+ClangdServer::ClangdServer(GlobalCompilationDatabase &CDB,
+   DiagnosticsConsumer &DiagConsumer,
+   FileSystemProvider &FSProvider,
+   unsigned AsyncThreadsCount,
+   bool StorePreamblesInMemory,
+   const clangd::CodeCompleteOptions &CodeCompleteOpts,
+   clangd::Logger &Logger,
+   llvm::Optional ResourceDir)
 : Logger(Logger), CDB(CDB), DiagConsumer(DiagConsumer),
   FSProvider(FSProvider),
   ResourceDir(ResourceDir ? ResourceDir->str() : getStandardResourceDir()),

Modified: clang-tools-extra/trunk/clangd/ClangdServer.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.h?rev=318925&r1=318924&r2=318925&view=diff
===

[PATCH] D39836: [clangd] Drop impossible completions (unavailable or inaccessible)

2017-11-23 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL318925: [clangd] Drop impossible completions (unavailable or 
inaccessible) (authored by sammccall).

Repository:
  rL LLVM

https://reviews.llvm.org/D39836

Files:
  clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
  clang-tools-extra/trunk/clangd/ClangdLSPServer.h
  clang-tools-extra/trunk/clangd/ClangdServer.cpp
  clang-tools-extra/trunk/clangd/ClangdServer.h
  clang-tools-extra/trunk/clangd/ClangdUnit.cpp
  clang-tools-extra/trunk/clangd/ClangdUnit.h
  clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
  clang-tools-extra/trunk/test/clangd/completion-items-kinds.test
  clang-tools-extra/trunk/test/clangd/completion-priorities.test
  clang-tools-extra/trunk/test/clangd/completion-qualifiers.test
  clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp

Index: clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp
===
--- clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp
+++ clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp
@@ -788,6 +788,8 @@
   int method();
 
   int field;
+private:
+  int private_field;
 };
 
 int test() {
@@ -828,7 +830,10 @@
   // Class members. The only items that must be present in after-dor
   // completion.
   EXPECT_TRUE(ContainsItem(Results, MethodItemText));
+  EXPECT_TRUE(ContainsItem(Results, MethodItemText));
   EXPECT_TRUE(ContainsItem(Results, "field"));
+  EXPECT_EQ(Opts.IncludeIneligibleResults,
+ContainsItem(Results, "private_field"));
   // Global items.
   EXPECT_FALSE(ContainsItem(Results, "global_var"));
   EXPECT_FALSE(ContainsItem(Results, GlobalFuncItemText));
@@ -889,18 +894,26 @@
 }
   };
 
-  for (bool IncludeMacros : {true, false})
-for (bool IncludeGlobals : {true, false})
-  for (bool IncludeBriefComments : {true, false})
-for (bool EnableSnippets : {true, false})
+  clangd::CodeCompleteOptions CCOpts;
+  for (bool IncludeMacros : {true, false}){
+CCOpts.IncludeMacros = IncludeMacros;
+for (bool IncludeGlobals : {true, false}){
+  CCOpts.IncludeGlobals = IncludeGlobals;
+  for (bool IncludeBriefComments : {true, false}){
+CCOpts.IncludeBriefComments = IncludeBriefComments;
+for (bool EnableSnippets : {true, false}){
+  CCOpts.EnableSnippets = EnableSnippets;
   for (bool IncludeCodePatterns : {true, false}) {
-TestWithOpts(clangd::CodeCompleteOptions(
-/*EnableSnippets=*/EnableSnippets,
-/*IncludeCodePatterns=*/IncludeCodePatterns,
-/*IncludeMacros=*/IncludeMacros,
-/*IncludeGlobals=*/IncludeGlobals,
-/*IncludeBriefComments=*/IncludeBriefComments));
+CCOpts.IncludeCodePatterns = IncludeCodePatterns;
+for (bool IncludeIneligibleResults : {true, false}) {
+  CCOpts.IncludeIneligibleResults = IncludeIneligibleResults;
+  TestWithOpts(CCOpts);
+}
   }
+}
+  }
+}
+  }
 }
 
 class ClangdThreadingTest : public ClangdVFSTest {};
Index: clang-tools-extra/trunk/clangd/ClangdServer.h
===
--- clang-tools-extra/trunk/clangd/ClangdServer.h
+++ clang-tools-extra/trunk/clangd/ClangdServer.h
@@ -182,9 +182,6 @@
   /// AsyncThreadsCount worker threads. However, if \p AsyncThreadsCount is 0,
   /// all requests will be processed on the calling thread.
   ///
-  /// When \p SnippetCompletions is true, completion items will be presented
-  /// with embedded snippets. Otherwise, plaintext items will be presented.
-  ///
   /// ClangdServer uses \p FSProvider to get an instance of vfs::FileSystem for
   /// each parsing request. Results of code completion and diagnostics also
   /// include a tag, that \p FSProvider returns along with the vfs::FileSystem.
@@ -213,7 +210,7 @@
DiagnosticsConsumer &DiagConsumer,
FileSystemProvider &FSProvider, unsigned AsyncThreadsCount,
bool StorePreamblesInMemory,
-   clangd::CodeCompleteOptions CodeCompleteOpts,
+   const clangd::CodeCompleteOptions &CodeCompleteOpts,
clangd::Logger &Logger,
llvm::Optional ResourceDir = llvm::None);
 
Index: clang-tools-extra/trunk/clangd/ClangdServer.cpp
===
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp
@@ -169,11 +169,14 @@
 Worker.join();
 }
 
-ClangdServer::ClangdServer(
-GlobalCompilationDatabase &CDB, DiagnosticsConsumer &DiagConsumer,
-FileSystemProvider &FSProvider, unsigned AsyncThreadsCount,
-bool StorePreamblesInMemory, clangd::CodeCompleteOptions CodeCompleteOpts,
-clangd::Logger &Logger, llvm::Optional ResourceDir)
+ClangdServer:

[PATCH] D38425: [clangd] Document highlights for clangd

2017-11-23 Thread Marc-Andre Laperle via Phabricator via cfe-commits
malaperle added inline comments.



Comment at: clangd/ClangdUnit.cpp:1245
+
+  for (unsigned I = 0; I < DocHighlightsFinder->getSourceRanges().size(); I++) 
{
+HighlightLocations.push_back(

malaperle wrote:
> replace all this code (1242-1265) by moving it in DocumentHighlightsFinder? 
> then call takeHighlights.
Also, use a range-based for loop



Comment at: clangd/ClangdUnit.cpp:1247
+HighlightLocations.push_back(
+addHighlightLocation(AST, DocHighlightsFinder->getSourceRanges()[I],
+ DocHighlightsFinder->getKinds()[I]));

The vector returned by getKinds() doesn't match the size of getSourceRanges(). 
This is because the kinds vector is computed in DeclarationLocationsFinder 
which only computes the kind of the occurrence the user has selected, not the 
kinds of all occurrences for a given Decl. Once you move the code to create the 
highlights in DocumentHighlightsFinder, you won't need a vector of kinds and 
this won't be a problem.


https://reviews.llvm.org/D38425



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


[clang-tools-extra] r318926 - [clang-tidy] rename_check.py misc-argument-comment bugprone-argument-comment

2017-11-23 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Thu Nov 23 09:02:48 2017
New Revision: 318926

URL: http://llvm.org/viewvc/llvm-project?rev=318926&view=rev
Log:
[clang-tidy] rename_check.py misc-argument-comment bugprone-argument-comment

Summary: + manually convert the unit test to lit test.

Reviewers: hokein

Reviewed By: hokein

Subscribers: mgorny, xazax.hun, cfe-commits

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

Added:
clang-tools-extra/trunk/clang-tidy/bugprone/ArgumentCommentCheck.cpp
  - copied, changed from r318922, 
clang-tools-extra/trunk/clang-tidy/misc/ArgumentCommentCheck.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/ArgumentCommentCheck.h
  - copied, changed from r318922, 
clang-tools-extra/trunk/clang-tidy/misc/ArgumentCommentCheck.h
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-argument-comment.rst
  - copied, changed from r318922, 
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-argument-comment.rst
clang-tools-extra/trunk/test/clang-tidy/bugprone-argument-comment-gmock.cpp
  - copied, changed from r318922, 
clang-tools-extra/trunk/test/clang-tidy/misc-argument-comment-gmock.cpp
clang-tools-extra/trunk/test/clang-tidy/bugprone-argument-comment-strict.cpp
  - copied, changed from r318922, 
clang-tools-extra/trunk/test/clang-tidy/misc-argument-comment-strict.cpp
clang-tools-extra/trunk/test/clang-tidy/bugprone-argument-comment.cpp
  - copied, changed from r318922, 
clang-tools-extra/trunk/test/clang-tidy/misc-argument-comment.cpp
Removed:
clang-tools-extra/trunk/clang-tidy/misc/ArgumentCommentCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/ArgumentCommentCheck.h
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-argument-comment.rst
clang-tools-extra/trunk/test/clang-tidy/misc-argument-comment-gmock.cpp
clang-tools-extra/trunk/test/clang-tidy/misc-argument-comment-strict.cpp
clang-tools-extra/trunk/test/clang-tidy/misc-argument-comment.cpp
clang-tools-extra/trunk/unittests/clang-tidy/MiscModuleTest.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
clang-tools-extra/trunk/unittests/clang-tidy/CMakeLists.txt

Copied: clang-tools-extra/trunk/clang-tidy/bugprone/ArgumentCommentCheck.cpp 
(from r318922, clang-tools-extra/trunk/clang-tidy/misc/ArgumentCommentCheck.cpp)
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/ArgumentCommentCheck.cpp?p2=clang-tools-extra/trunk/clang-tidy/bugprone/ArgumentCommentCheck.cpp&p1=clang-tools-extra/trunk/clang-tidy/misc/ArgumentCommentCheck.cpp&r1=318922&r2=318926&rev=318926&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/ArgumentCommentCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/ArgumentCommentCheck.cpp Thu 
Nov 23 09:02:48 2017
@@ -18,7 +18,7 @@ using namespace clang::ast_matchers;
 
 namespace clang {
 namespace tidy {
-namespace misc {
+namespace bugprone {
 
 ArgumentCommentCheck::ArgumentCommentCheck(StringRef Name,
ClangTidyContext *Context)
@@ -303,6 +303,6 @@ void ArgumentCommentCheck::check(const M
   }
 }
 
-} // namespace misc
+} // namespace bugprone
 } // namespace tidy
 } // namespace clang

Copied: clang-tools-extra/trunk/clang-tidy/bugprone/ArgumentCommentCheck.h 
(from r318922, clang-tools-extra/trunk/clang-tidy/misc/ArgumentCommentCheck.h)
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/ArgumentCommentCheck.h?p2=clang-tools-extra/trunk/clang-tidy/bugprone/ArgumentCommentCheck.h&p1=clang-tools-extra/trunk/clang-tidy/misc/ArgumentCommentCheck.h&r1=318922&r2=318926&rev=318926&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/ArgumentCommentCheck.h (original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/ArgumentCommentCheck.h Thu Nov 
23 09:02:48 2017
@@ -15,7 +15,7 @@
 
 namespace clang {
 namespace tidy {
-namespace misc {
+namespace bugprone {
 
 /// Checks that argument comments match parameter names.
 ///
@@ -48,7 +48,7 @@ private:
  llvm::ArrayRef Args);
 };
 
-} // namespace misc
+} // namespace bugprone
 } // namespace tidy
 } // namespace clang
 

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp?rev=318926&r1=318925&r2=318926&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/Bugpro

[PATCH] D40392: [clang-tidy] rename_check.py misc-argument-comment bugprone-argument-comment

2017-11-23 Thread Alexander Kornienko via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL318926: [clang-tidy] rename_check.py misc-argument-comment 
bugprone-argument-comment (authored by alexfh).

Changed prior to commit:
  https://reviews.llvm.org/D40392?vs=124079&id=124098#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D40392

Files:
  clang-tools-extra/trunk/clang-tidy/bugprone/ArgumentCommentCheck.cpp
  clang-tools-extra/trunk/clang-tidy/bugprone/ArgumentCommentCheck.h
  clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/trunk/clang-tidy/misc/ArgumentCommentCheck.cpp
  clang-tools-extra/trunk/clang-tidy/misc/ArgumentCommentCheck.h
  clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/trunk/docs/ReleaseNotes.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-argument-comment.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/misc-argument-comment.rst
  clang-tools-extra/trunk/test/clang-tidy/bugprone-argument-comment-gmock.cpp
  clang-tools-extra/trunk/test/clang-tidy/bugprone-argument-comment-strict.cpp
  clang-tools-extra/trunk/test/clang-tidy/bugprone-argument-comment.cpp
  clang-tools-extra/trunk/test/clang-tidy/misc-argument-comment-gmock.cpp
  clang-tools-extra/trunk/test/clang-tidy/misc-argument-comment-strict.cpp
  clang-tools-extra/trunk/test/clang-tidy/misc-argument-comment.cpp
  clang-tools-extra/trunk/unittests/clang-tidy/CMakeLists.txt
  clang-tools-extra/trunk/unittests/clang-tidy/MiscModuleTest.cpp

Index: clang-tools-extra/trunk/test/clang-tidy/bugprone-argument-comment-strict.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/bugprone-argument-comment-strict.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/bugprone-argument-comment-strict.cpp
@@ -0,0 +1,19 @@
+// RUN: %check_clang_tidy %s bugprone-argument-comment %t -- \
+// RUN:   -config="{CheckOptions: [{key: StrictMode, value: 1}]}" --
+
+void f(int _with_underscores_);
+void g(int x_);
+void ignores_underscores() {
+  f(/*With_Underscores=*/0);
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: argument name 'With_Underscores' in comment does not match parameter name '_with_underscores_'
+// CHECK-FIXES: f(/*_with_underscores_=*/0);
+  f(/*with_underscores=*/1);
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: argument name 'with_underscores' in comment does not match parameter name '_with_underscores_'
+// CHECK-FIXES: f(/*_with_underscores_=*/1);
+  f(/*_With_Underscores_=*/2);
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: argument name '_With_Underscores_' in comment does not match parameter name '_with_underscores_'
+// CHECK-FIXES: f(/*_with_underscores_=*/2);
+  g(/*X=*/3);
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: argument name 'X' in comment does not match parameter name 'x_'
+// CHECK-FIXES: g(/*x_=*/3);
+}
Index: clang-tools-extra/trunk/test/clang-tidy/bugprone-argument-comment-gmock.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/bugprone-argument-comment-gmock.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/bugprone-argument-comment-gmock.cpp
@@ -0,0 +1,108 @@
+// RUN: %check_clang_tidy %s bugprone-argument-comment %t
+
+namespace testing {
+namespace internal {
+
+template 
+struct Function;
+
+template 
+struct Function {
+  typedef R Result;
+};
+
+template 
+struct Function
+: Function {
+  typedef A1 Argument1;
+};
+
+template 
+struct Function
+: Function {
+  typedef A2 Argument2;
+};
+
+} // namespace internal
+
+template 
+class MockSpec {
+ public:
+  void f();
+};
+
+template 
+class Matcher {
+ public:
+  explicit Matcher();
+  Matcher(T value);
+};
+
+} // namespace testing
+
+#define GMOCK_RESULT_(tn, ...) \
+tn ::testing::internal::Function<__VA_ARGS__>::Result
+#define GMOCK_ARG_(tn, N, ...) \
+tn ::testing::internal::Function<__VA_ARGS__>::Argument##N
+#define GMOCK_MATCHER_(tn, N, ...) \
+const ::testing::Matcher&
+#define GMOCK_METHOD2_(tn, constness, ct, Method, ...)\
+  GMOCK_RESULT_(tn, __VA_ARGS__)  \
+  ct Method(  \
+  GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1,\
+  GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2) constness; \
+  ::testing::MockSpec<__VA_ARGS__>\
+  gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
+ GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2) constness
+#define MOCK_METHOD2(m, ...) GMOCK_METHOD2_(, , , m, __VA_ARGS__)
+#define MOCK_CONST_METHOD2(m, ...) GMOCK_METHOD2_(, const, , m, __VA_ARGS__)
+#define GMOCK_EXPECT_CALL_IMPL_(obj, call) \
+((obj).gmock_##call).f()
+#define EXPECT_CALL(obj, 

[PATCH] D40089: [clangd] Make completion scores use 0-1 floats internally.

2017-11-23 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL318927: [clangd] Make completion scores use 0-1 floats 
internally. (authored by sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D40089?vs=124044&id=124099#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D40089

Files:
  clang-tools-extra/trunk/clangd/ClangdUnit.cpp
  clang-tools-extra/trunk/test/clangd/authority-less-uri.test
  clang-tools-extra/trunk/test/clangd/completion-items-kinds.test
  clang-tools-extra/trunk/test/clangd/completion-priorities.test
  clang-tools-extra/trunk/test/clangd/completion-qualifiers.test
  clang-tools-extra/trunk/test/clangd/completion-snippet.test
  clang-tools-extra/trunk/test/clangd/completion.test
  clang-tools-extra/trunk/test/clangd/protocol.test

Index: clang-tools-extra/trunk/test/clangd/completion-items-kinds.test
===
--- clang-tools-extra/trunk/test/clangd/completion-items-kinds.test
+++ clang-tools-extra/trunk/test/clangd/completion-items-kinds.test
@@ -12,20 +12,20 @@
 {"jsonrpc":"2.0","id":1,"method":"textDocument/completion","params":{"textDocument":{"uri":"file:///main.cpp"},"position":{"line":4,"character":7}}}
 # CHECK: {"id":1,"jsonrpc":"2.0","result":{"isIncomplete":false,"items":
 #
+# Function
+# CHECK: {"detail":"int","filterText":"function","insertText":"function()","insertTextFormat":1,"kind":3,"label":"function()","sortText":"{{.*}}function"}
+#
+# Variable
+# CHECK: {"detail":"int","filterText":"variable","insertText":"variable","insertTextFormat":1,"kind":6,"label":"variable","sortText":"{{.*}}variable"}
+#
 # Keyword
-# CHECK-DAG: {"filterText":"int","insertText":"int","insertTextFormat":1,"kind":14,"label":"int","sortText":"50int"}
+# CHECK: {"filterText":"int","insertText":"int","insertTextFormat":1,"kind":14,"label":"int","sortText":"{{.*}}int"}
 #
 # Struct
-# CHECK-DAG: {"filterText":"Struct","insertText":"Struct","insertTextFormat":1,"kind":7,"label":"Struct","sortText":"50Struct"}
+# CHECK: {"filterText":"Struct","insertText":"Struct","insertTextFormat":1,"kind":7,"label":"Struct","sortText":"{{.*}}Struct"}
 #
 # Macro
-# CHECK-DAG: {"filterText":"MACRO","insertText":"MACRO","insertTextFormat":1,"kind":1,"label":"MACRO","sortText":"70MACRO"}
-#
-# Variable
-# CHECK-DAG: {"detail":"int","filterText":"variable","insertText":"variable","insertTextFormat":1,"kind":6,"label":"variable","sortText":"12variable"}
-#
-# Function
-# CHECK-DAG: {"detail":"int","filterText":"function","insertText":"function()","insertTextFormat":1,"kind":3,"label":"function()","sortText":"12function"}
+# CHECK: {"filterText":"MACRO","insertText":"MACRO","insertTextFormat":1,"kind":1,"label":"MACRO","sortText":"{{.*}}MACRO"}
 #
 # CHECK-SAME: ]}}
 Content-Length: 146
@@ -35,7 +35,7 @@
 
 {"jsonrpc":"2.0","id":2,"method":"textDocument/completion","params":{"textDocument":{"uri":"file:///main.cpp"},"position":{"line":1,"character":3}}}
 # Code pattern (unfortunately there are none in expression context)
-# CHECK-DAG: {"filterText":"namespace","insertText":"namespace ${1:identifier}{${2:declarations}\n}","insertTextFormat":2,"kind":15,"label":"namespace identifier{declarations}","sortText":"40namespace"}
+# CHECK-DAG: {"filterText":"namespace","insertText":"namespace ${1:identifier}{${2:declarations}\n}","insertTextFormat":2,"kind":15,"label":"namespace identifier{declarations}","sortText":"{{.*}}namespace"}
 #
 Content-Length: 58
 
Index: clang-tools-extra/trunk/test/clangd/completion-snippet.test
===
--- clang-tools-extra/trunk/test/clangd/completion-snippet.test
+++ clang-tools-extra/trunk/test/clangd/completion-snippet.test
@@ -24,51 +24,51 @@
 # CHECK-NEXT:"insertTextFormat": 1,
 # CHECK-NEXT:"kind": 5,
 # CHECK-NEXT:"label": "a",
-# CHECK-NEXT:"sortText": "35a"
+# CHECK-NEXT:"sortText": "{{.*}}a"
 # CHECK-NEXT:  },
 # CHECK-NEXT:  {
 # CHECK-NEXT:"detail": "int",
 # CHECK-NEXT:"filterText": "bb",
 # CHECK-NEXT:"insertText": "bb",
 # CHECK-NEXT:"insertTextFormat": 1,
 # CHECK-NEXT:"kind": 5,
 # CHECK-NEXT:"label": "bb",
-# CHECK-NEXT:"sortText": "35bb"
+# CHECK-NEXT:"sortText": "{{.*}}bb"
 # CHECK-NEXT:  },
 # CHECK-NEXT:  {
 # CHECK-NEXT:"detail": "int",
 # CHECK-NEXT:"filterText": "ccc",
 # CHECK-NEXT:"insertText": "ccc",
 # CHECK-NEXT:"insertTextFormat": 1,
 # CHECK-NEXT:"kind": 5,
 # CHECK-NEXT:"label": "ccc",
-# CHECK-NEXT:"sortText": "35ccc"
+# CHECK-NEXT:"sortText": "{{.*}}ccc"
 # CHECK-NEXT:  },
 # CHECK-NEXT:  {
 # CHECK-NEXT:"detail": "int",
 # CHECK-NEXT:"filterText": "f",
 # CHECK-NEXT:"insertText": "f(${1:int i}, ${2:const float f})",
 # CHECK-NEXT:"insertTextFo

[clang-tools-extra] r318927 - [clangd] Make completion scores use 0-1 floats internally.

2017-11-23 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Thu Nov 23 09:09:04 2017
New Revision: 318927

URL: http://llvm.org/viewvc/llvm-project?rev=318927&view=rev
Log:
[clangd] Make completion scores use 0-1 floats internally.

Summary:
This scale is much easier to mix with other signals, such as fuzzy match 
strength.
Mostly NFC, but it does reorder some low-priority items that get folded 
together at a score of 0 (see completion-qualifiers.test).
Removed the exact sortText from the testcases, because it's the ranking that we 
want to test.

Reviewers: hokein

Subscribers: ilya-biryukov, cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/ClangdUnit.cpp
clang-tools-extra/trunk/test/clangd/authority-less-uri.test
clang-tools-extra/trunk/test/clangd/completion-items-kinds.test
clang-tools-extra/trunk/test/clangd/completion-priorities.test
clang-tools-extra/trunk/test/clangd/completion-qualifiers.test
clang-tools-extra/trunk/test/clangd/completion-snippet.test
clang-tools-extra/trunk/test/clangd/completion.test
clang-tools-extra/trunk/test/clangd/protocol.test

Modified: clang-tools-extra/trunk/clangd/ClangdUnit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.cpp?rev=318927&r1=318926&r2=318927&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdUnit.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp Thu Nov 23 09:09:04 2017
@@ -375,50 +375,62 @@ struct CompletionCandidate {
   : Result(&Result), Score(score(Result)) {}
 
   CodeCompletionResult *Result;
-  // Higher score is worse. FIXME: use a more natural scale!
-  int Score;
+  float Score; // 0 to 1, higher is better.
 
   // Comparison reflects rank: better candidates are smaller.
   bool operator<(const CompletionCandidate &C) const {
 if (Score != C.Score)
-  return Score < C.Score;
+  return Score > C.Score;
 return *Result < *C.Result;
   }
 
+  // Returns a string that sorts in the same order as operator<, for LSP.
+  // Conceptually, this is [-Score, Name]. We convert -Score to an integer, and
+  // hex-encode it for readability. Example: [0.5, "foo"] -> "4100foo"
   std::string sortText() const {
-// Fill in the sortText of the CompletionItem.
-assert(Score <= 99 && "Expecting score to have at most 6-digits");
 std::string S, NameStorage;
-StringRef Name = Result->getOrderedName(NameStorage);
-llvm::raw_string_ostream(S)
-<< llvm::format("%06d%.*s", Score, Name.size(), Name.data());
-return S;
+llvm::raw_string_ostream OS(S);
+write_hex(OS, encodeFloat(-Score), llvm::HexPrintStyle::Lower,
+  /*Width=*/2 * sizeof(Score));
+OS << Result->getOrderedName(NameStorage);
+return OS.str();
   }
 
 private:
-  static int score(const CodeCompletionResult &Result) {
-int Score = Result.Priority;
-// Fill in the sortText of the CompletionItem.
-assert(Score <= 9 && "Expecting code completion result "
- "priority to have at most 5-digits");
+  static float score(const CodeCompletionResult &Result) {
+// Priority 80 is a really bad score.
+float Score = 1 - std::min(80, Result.Priority) / 80;
 
-const int Penalty = 10;
 switch (static_cast(Result.Availability)) {
 case CXAvailability_Available:
   // No penalty.
   break;
 case CXAvailability_Deprecated:
-  Score += Penalty;
+  Score *= 0.1;
   break;
 case CXAvailability_NotAccessible:
-  Score += 2 * Penalty;
-  break;
 case CXAvailability_NotAvailable:
-  Score += 3 * Penalty;
+  Score = 0;
   break;
 }
 return Score;
   }
+
+  // Produces an integer that sorts in the same order as F.
+  // That is: a < b <==> encodeFloat(a) < encodeFloat(b).
+  static 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.
+  }
 };
 
 class CompletionItemsCollector : public CodeCompleteConsumer {

Modified: clang-tools-extra/trunk/test/clangd/authority-less-uri.test
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/authority-less-uri.test?rev=318927&r1=318926&r2=318927&view=diff
==
--- clang-tools-extra/trunk/test/clangd/authority-less-uri.test (original)
+++ clang-tools-extra/trunk/test/clangd

[PATCH] D40132: [clangd] Tracing improvements

2017-11-23 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL318928: [clangd] Tracing improvements (authored by 
sammccall).

Repository:
  rL LLVM

https://reviews.llvm.org/D40132

Files:
  clang-tools-extra/trunk/clangd/ClangdUnit.cpp
  clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp
  clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h
  clang-tools-extra/trunk/clangd/Trace.cpp
  clang-tools-extra/trunk/clangd/Trace.h
  clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
  clang-tools-extra/trunk/test/clangd/trace.test
  clang-tools-extra/trunk/unittests/clangd/TraceTests.cpp

Index: clang-tools-extra/trunk/unittests/clangd/TraceTests.cpp
===
--- clang-tools-extra/trunk/unittests/clangd/TraceTests.cpp
+++ clang-tools-extra/trunk/unittests/clangd/TraceTests.cpp
@@ -116,7 +116,7 @@
   ASSERT_NE(++Event, Events->end()) << "Expected span start";
   EXPECT_TRUE(VerifyObject(*Event, {{"ph", "B"}, {"name", "A"}}));
   ASSERT_NE(++Event, Events->end()) << "Expected log message";
-  EXPECT_TRUE(VerifyObject(*Event, {{"ph", "i"}, {"name", "B"}}));
+  EXPECT_TRUE(VerifyObject(*Event, {{"ph", "i"}, {"name", "Log"}}));
   ASSERT_NE(++Event, Events->end()) << "Expected span end";
   EXPECT_TRUE(VerifyObject(*Event, {{"ph", "E"}}));
   ASSERT_EQ(++Event, Events->end());
Index: clang-tools-extra/trunk/clangd/Trace.cpp
===
--- clang-tools-extra/trunk/clangd/Trace.cpp
+++ clang-tools-extra/trunk/clangd/Trace.cpp
@@ -27,13 +27,17 @@
 // Perhaps we should replace this by something that disturbs performance less.
 class Tracer {
 public:
-  Tracer(raw_ostream &Out)
-  : Out(Out), Sep(""), Start(std::chrono::system_clock::now()) {
+  Tracer(raw_ostream &Out, bool Pretty)
+  : Out(Out), Sep(""), Start(std::chrono::system_clock::now()),
+JSONFormat(Pretty ? "{0:2}" : "{0}") {
 // The displayTimeUnit must be ns to avoid low-precision overlap
 // calculations!
 Out << R"({"displayTimeUnit":"ns","traceEvents":[)"
 << "\n";
-rawEvent("M", R"("name": "process_name", "args":{"name":"clangd"})");
+rawEvent("M", json::obj{
+  {"name", "process_name"},
+  {"args", json::obj{{"name", "clangd"}}},
+  });
   }
 
   ~Tracer() {
@@ -43,32 +47,34 @@
 
   // Record an event on the current thread. ph, pid, tid, ts are set.
   // Contents must be a list of the other JSON key/values.
-  template  void event(StringRef Phase, const T &Contents) {
+  void event(StringRef Phase, json::obj &&Contents) {
 uint64_t TID = get_threadid();
 std::lock_guard Lock(Mu);
 // If we haven't already, emit metadata describing this thread.
 if (ThreadsWithMD.insert(TID).second) {
   SmallString<32> Name;
   get_thread_name(Name);
   if (!Name.empty()) {
-rawEvent(
-"M",
-formatv(
-R"("tid": {0}, "name": "thread_name", "args":{"name":"{1}"})",
-TID, StringRef(&Name[0], Name.size(;
+rawEvent("M", json::obj{
+  {"tid", TID},
+  {"name", "thread_name"},
+  {"args", json::obj{{"name", Name}}},
+  });
   }
 }
-rawEvent(Phase, formatv(R"("ts":{0}, "tid":{1}, {2})", timestamp(), TID,
-Contents));
+Contents["ts"] = timestamp();
+Contents["tid"] = TID;
+rawEvent(Phase, std::move(Contents));
   }
 
 private:
   // Record an event. ph and pid are set.
   // Contents must be a list of the other JSON key/values.
-  template 
-  void rawEvent(StringRef Phase, const T &Contents) /*REQUIRES(Mu)*/ {
+  void rawEvent(StringRef Phase, json::obj &&Event) /*REQUIRES(Mu)*/ {
 // PID 0 represents the clangd process.
-Out << Sep << R"({"pid":0, "ph":")" << Phase << "\", " << Contents << "}";
+Event["pid"] = 0;
+Event["ph"] = Phase;
+Out << Sep << formatv(JSONFormat, json::Expr(std::move(Event)));
 Sep = ",\n";
   }
 
@@ -82,14 +88,15 @@
   const char *Sep /*GUARDED_BY(Mu)*/;
   DenseSet ThreadsWithMD /*GUARDED_BY(Mu)*/;
   const sys::TimePoint<> Start;
+  const char *JSONFormat;
 };
 
 static Tracer *T = nullptr;
 } // namespace
 
-std::unique_ptr Session::create(raw_ostream &OS) {
+std::unique_ptr Session::create(raw_ostream &OS, bool Pretty) {
   assert(!T && "A session is already active");
-  T = new Tracer(OS);
+  T = new Tracer(OS, Pretty);
   return std::unique_ptr(new Session());
 }
 
@@ -101,19 +108,25 @@
 void log(const Twine &Message) {
   if (!T)
 return;
-  T->event("i", formatv(R"("name":"{0}")", yaml::escape(Message.str(;
+  T->event("i", json::obj{
+{"name", "Log"},
+{"args", json::obj{{"Message", Message.str()}}},
+});
 }
 
-Span::Span(const Twine &Text) {
+Span::Span(std::string Name) 

[clang-tools-extra] r318928 - [clangd] Tracing improvements

2017-11-23 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Thu Nov 23 09:12:04 2017
New Revision: 318928

URL: http://llvm.org/viewvc/llvm-project?rev=318928&view=rev
Log:
[clangd] Tracing improvements

Summary:
[clangd] Tracing improvements

Compose JSON using JSONExpr
Allow attaching metadata to spans (and avoid it if tracing is off)
Attach IDs and responses of JSON RPCs to their spans

The downside is that large responses make the trace viewer sluggish.
We should make our responses less huge :-) Or fix trace viewer.

Reviewers: ilya-biryukov

Subscribers: cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/ClangdUnit.cpp
clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp
clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h
clang-tools-extra/trunk/clangd/Trace.cpp
clang-tools-extra/trunk/clangd/Trace.h
clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
clang-tools-extra/trunk/test/clangd/trace.test
clang-tools-extra/trunk/unittests/clangd/TraceTests.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdUnit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.cpp?rev=318928&r1=318927&r2=318928&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdUnit.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp Thu Nov 23 09:12:04 2017
@@ -1293,7 +1293,8 @@ CppFile::deferRebuild(StringRef NewConte
   // (if there are no other references to it).
   OldPreamble.reset();
 
-  trace::Span Tracer(llvm::Twine("Preamble: ") + That->FileName);
+  trace::Span Tracer("Preamble");
+  SPAN_ATTACH(Tracer, "File", That->FileName);
   std::vector PreambleDiags;
   StoreDiagsConsumer PreambleDiagnosticsConsumer(/*ref*/ PreambleDiags);
   IntrusiveRefCntPtr PreambleDiagsEngine =
@@ -1342,7 +1343,8 @@ CppFile::deferRebuild(StringRef NewConte
 // Compute updated AST.
 llvm::Optional NewAST;
 {
-  trace::Span Tracer(llvm::Twine("Build: ") + That->FileName);
+  trace::Span Tracer("Build");
+  SPAN_ATTACH(Tracer, "File", That->FileName);
   NewAST = ParsedAST::Build(
   std::move(CI), PreambleForAST, SerializedPreambleDecls,
   std::move(ContentsBuffer), PCHs, VFS, That->Logger);

Modified: clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp?rev=318928&r1=318927&r2=318928&view=diff
==
--- clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp (original)
+++ clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp Thu Nov 23 09:12:04 
2017
@@ -59,6 +59,7 @@ void RequestContext::reply(json::Expr &&
 Out.log("Attempted to reply to a notification!\n");
 return;
   }
+  SPAN_ATTACH(tracer(), "Reply", Result);
   Out.writeMessage(json::obj{
   {"jsonrpc", "2.0"},
   {"id", *ID},
@@ -69,6 +70,9 @@ void RequestContext::reply(json::Expr &&
 void RequestContext::replyError(ErrorCode code,
 const llvm::StringRef &Message) {
   Out.log("Error " + Twine(static_cast(code)) + ": " + Message + "\n");
+  SPAN_ATTACH(tracer(), "Error",
+  (json::obj{{"code", static_cast(code)},
+ {"message", Message.str()}}));
   if (ID) {
 Out.writeMessage(json::obj{
 {"jsonrpc", "2.0"},
@@ -82,6 +86,8 @@ void RequestContext::replyError(ErrorCod
 void RequestContext::call(StringRef Method, json::Expr &&Params) {
   // FIXME: Generate/Increment IDs for every request so that we can get proper
   // replies once we need to.
+  SPAN_ATTACH(tracer(), "Call",
+  (json::obj{{"method", Method.str()}, {"params", Params}}));
   Out.writeMessage(json::obj{
   {"jsonrpc", "2.0"},
   {"id", 1},
@@ -104,8 +110,7 @@ callHandler(const llvm::StringMapgetValue(MethodStorage);
   auto I = Handlers.find(MethodStr);
   auto &Handler = I != Handlers.end() ? I->second : UnknownHandler;
-  trace::Span Tracer(MethodStr);
-  Handler(RequestContext(Out, std::move(ID)), Params);
+  Handler(RequestContext(Out, MethodStr, std::move(ID)), Params);
 }
 
 bool JSONRPCDispatcher::call(StringRef Content, JSONOutput &Out) const {
@@ -249,7 +254,6 @@ void clangd::runLanguageServerLoop(std::
   std::vector JSON(ContentLength + 1, '\0');
   llvm::StringRef JSONRef;
   {
-trace::Span Tracer("Reading request");
 // Now read the JSON. Insert a trailing null byte as required by the
 // YAML parser.
 In.read(JSON.data(), ContentLength);

Modified: clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h?rev=318928&r1=318927&r2=318928&view=diff
==
--- clang-tools-extra/trunk/clangd/JS

Re: [clang-tools-extra] r318840 - [FindAllSymbols] Cache regexes, creating them is expensive

2017-11-23 Thread Krzysztof Parzyszek via cfe-commits

Hi,
This broke build on FreeBSD 11:

[100%] Building CXX object 
tools/clang/tools/extra/include-fixer/find-all-symbols/CMakeFiles/findAllSymbols.dir/HeaderMapCollector.cpp.o
cd /w/bld/org/tools/clang/tools/extra/include-fixer/find-all-symbols && 
/w/c/clang+llvm-5.0.0-x86_64-unknown-freebsd11/bin/clang++ 
-DGTEST_HAS_RTTI=0 -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS 
-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-I/w/bld/org/tools/clang/tools/extra/include-fixer/find-all-symbols 
-I/w/src/llvm.org/tools/clang/tools/extra/include-fixer/find-all-symbols 
-I/w/src/llvm.org/tools/clang/include -I/w/bld/org/tools/clang/include 
-I/w/bld/org/include -I/w/src/llvm.org/include -isystem 
/usr/local/include -stdlib=libc++ -fPIC -fvisibility-inlines-hidden 
-Werror=date-time -Werror=unguarded-availability-new -std=c++11 -Wall -W 
-Wno-unused-parameter -Wwrite-strings -Wcast-qual 
-Wmissing-field-initializers -pedantic -Wno-long-long 
-Wcovered-switch-default -Wnon-virtual-dtor -Wdelete-non-virtual-dtor 
-Wno-comment -Wstring-conversion -ffunction-sections -fdata-sections 
-fno-common -Woverloaded-virtual -Wno-nested-anon-types -O3-UNDEBUG 
-fno-exceptions -fno-rtti -o 
CMakeFiles/findAllSymbols.dir/HeaderMapCollector.cpp.o -c 
/w/src/llvm.org/tools/clang/tools/extra/include-fixer/find-all-symbols/HeaderMapCollector.cpp
In file included from 
/w/src/llvm.org/tools/clang/tools/extra/include-fixer/find-all-symbols/HeaderMapCollector.cpp:10:
In file included from 
/w/src/llvm.org/tools/clang/tools/extra/include-fixer/find-all-symbols/HeaderMapCollector.h:13:

In file included from /w/src/llvm.org/include/llvm/ADT/StringMap.h:17:
In file included from /w/src/llvm.org/include/llvm/ADT/StringRef.h:13:
In file included from /w/src/llvm.org/include/llvm/ADT/STLExtras.h:20:
In file included from /w/src/llvm.org/include/llvm/ADT/Optional.h:22:
In file included from /w/src/llvm.org/include/llvm/Support/type_traits.h:19:
/usr/include/c++/v1/utility:315:11: error: call to deleted constructor 
of 'llvm::Regex'

: first(__p.first),
  ^ ~
/usr/include/c++/v1/memory:1747:31: note: in instantiation of member 
function 'std::__1::pair::pair' requested here

::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
  ^
/usr/include/c++/v1/memory:1658:18: note: in instantiation of function 
template specialization 'std::__1::allocatorconst char *> >::construct, 
const std::__1::pair &>' requested here

{__a.construct(__p, _VSTD::forward<_Args>(__args)...);}
 ^
/usr/include/c++/v1/memory:1504:14: note: in instantiation of function 
template specialization 
'std::__1::allocator_traitsconst char *> > >::__construct*>, const std::__1::pair &>' requested here

{__construct(__has_construct(),
 ^
/usr/include/c++/v1/memory:1620:17: note: in instantiation of function 
template specialization 
'std::__1::allocator_traitsconst char *> > >::construct, 
const std::__1::pair &>' requested here
construct(__a, _VSTD::__to_raw_pointer(__end2-1), 
_VSTD::move_if_noexcept(*--__end1));

^
/usr/include/c++/v1/vector:892:21: note: in instantiation of function 
template specialization 
'std::__1::allocator_traitsconst char *> > >::__construct_backwardconst char *> *>' requested here
__alloc_traits::__construct_backward(this->__alloc(), 
this->__begin_, this->__end_, __v.__begin_);

^
/usr/include/c++/v1/vector:1537:9: note: in instantiation of member 
function 'std::__1::vector, 
std::__1::allocator > 
>::__swap_out_circular_buffer' requested here

__swap_out_circular_buffer(__v);
^
/w/src/llvm.org/tools/clang/tools/extra/include-fixer/find-all-symbols/HeaderMapCollector.cpp:19:33: 
note: in instantiation of member function 
'std::__1::vector, 
std::__1::allocator > 
>::reserve' requested here

  this->RegexHeaderMappingTable.reserve(RegexHeaderMappingTable->size());
^
/w/src/llvm.org/include/llvm/Support/Regex.h:49:5: note: 'Regex' has 
been explicitly marked deleted here

Regex(const Regex &) = delete;
^
1 error generated.
*** Error code 1


-Krzysztof


On 11/22/2017 9:38 AM, Benjamin Kramer via cfe-commits wrote:

Author: d0k
Date: Wed Nov 22 07:38:23 2017
New Revision: 318840

URL: http://llvm.org/viewvc/llvm-project?rev=318840&view=rev
Log:
[FindAllSymbols] Cache regexes, creating them is expensive

This is a bit annoying because LLVM regexes are always mutable to store
errors. Assert that there are never errors and fix broken hardcoded
regexes.

Modified:
 
clang-tools-extra/trunk/include-fixer/find-all-symbols/HeaderMapCollector.cpp
 clang-tools-extra/trunk/include-fixer/find-all-symbols/HeaderMapCollector.h
 
clang-tools-extra/trunk/include-fixer/find-all-symbols/STLPostfixHeaderMap.cpp

Modified: 
clang-tools-extra/trunk/include-fixer/find-all-symbols/HeaderMapCollector.cpp
URL: 
http://llvm.org/viewv

Re: [clang-tools-extra] r318840 - [FindAllSymbols] Cache regexes, creating them is expensive

2017-11-23 Thread Benjamin Kramer via cfe-commits
That looks like a bug in the standard library. Does removing the call
to reserve fix it? It's not really necessary, that code isn't
performance sensitive at all.

On Thu, Nov 23, 2017 at 6:36 PM, Krzysztof Parzyszek
 wrote:
> Hi,
> This broke build on FreeBSD 11:
>
> [100%] Building CXX object
> tools/clang/tools/extra/include-fixer/find-all-symbols/CMakeFiles/findAllSymbols.dir/HeaderMapCollector.cpp.o
> cd /w/bld/org/tools/clang/tools/extra/include-fixer/find-all-symbols &&
> /w/c/clang+llvm-5.0.0-x86_64-unknown-freebsd11/bin/clang++
> -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS
> -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
> -I/w/bld/org/tools/clang/tools/extra/include-fixer/find-all-symbols
> -I/w/src/llvm.org/tools/clang/tools/extra/include-fixer/find-all-symbols
> -I/w/src/llvm.org/tools/clang/include -I/w/bld/org/tools/clang/include
> -I/w/bld/org/include -I/w/src/llvm.org/include -isystem /usr/local/include
> -stdlib=libc++ -fPIC -fvisibility-inlines-hidden -Werror=date-time
> -Werror=unguarded-availability-new -std=c++11 -Wall -W -Wno-unused-parameter
> -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic
> -Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor
> -Wdelete-non-virtual-dtor -Wno-comment -Wstring-conversion
> -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual
> -Wno-nested-anon-types -O3-UNDEBUG -fno-exceptions -fno-rtti -o
> CMakeFiles/findAllSymbols.dir/HeaderMapCollector.cpp.o -c
> /w/src/llvm.org/tools/clang/tools/extra/include-fixer/find-all-symbols/HeaderMapCollector.cpp
> In file included from
> /w/src/llvm.org/tools/clang/tools/extra/include-fixer/find-all-symbols/HeaderMapCollector.cpp:10:
> In file included from
> /w/src/llvm.org/tools/clang/tools/extra/include-fixer/find-all-symbols/HeaderMapCollector.h:13:
> In file included from /w/src/llvm.org/include/llvm/ADT/StringMap.h:17:
> In file included from /w/src/llvm.org/include/llvm/ADT/StringRef.h:13:
> In file included from /w/src/llvm.org/include/llvm/ADT/STLExtras.h:20:
> In file included from /w/src/llvm.org/include/llvm/ADT/Optional.h:22:
> In file included from /w/src/llvm.org/include/llvm/Support/type_traits.h:19:
> /usr/include/c++/v1/utility:315:11: error: call to deleted constructor of
> 'llvm::Regex'
> : first(__p.first),
>   ^ ~
> /usr/include/c++/v1/memory:1747:31: note: in instantiation of member
> function 'std::__1::pair::pair' requested here
> ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
>   ^
> /usr/include/c++/v1/memory:1658:18: note: in instantiation of function
> template specialization 'std::__1::allocator const char *> >::construct, const
> std::__1::pair &>' requested here
> {__a.construct(__p, _VSTD::forward<_Args>(__args)...);}
>  ^
> /usr/include/c++/v1/memory:1504:14: note: in instantiation of function
> template specialization
> 'std::__1::allocator_traits const char *> > >::__construct,
> const std::__1::pair &>' requested here
> {__construct(__has_construct(),
>  ^
> /usr/include/c++/v1/memory:1620:17: note: in instantiation of function
> template specialization
> 'std::__1::allocator_traits const char *> > >::construct,
> const std::__1::pair &>' requested here
> construct(__a, _VSTD::__to_raw_pointer(__end2-1),
> _VSTD::move_if_noexcept(*--__end1));
> ^
> /usr/include/c++/v1/vector:892:21: note: in instantiation of function
> template specialization
> 'std::__1::allocator_traits const char *> > >::__construct_backward char *> *>' requested here
> __alloc_traits::__construct_backward(this->__alloc(), this->__begin_,
> this->__end_, __v.__begin_);
> ^
> /usr/include/c++/v1/vector:1537:9: note: in instantiation of member function
> 'std::__1::vector,
> std::__1::allocator >
>>::__swap_out_circular_buffer' requested here
> __swap_out_circular_buffer(__v);
> ^
> /w/src/llvm.org/tools/clang/tools/extra/include-fixer/find-all-symbols/HeaderMapCollector.cpp:19:33:
> note: in instantiation of member function
> 'std::__1::vector,
> std::__1::allocator > >::reserve'
> requested here
>   this->RegexHeaderMappingTable.reserve(RegexHeaderMappingTable->size());
> ^
> /w/src/llvm.org/include/llvm/Support/Regex.h:49:5: note: 'Regex' has been
> explicitly marked deleted here
> Regex(const Regex &) = delete;
> ^
> 1 error generated.
> *** Error code 1
>
>
> -Krzysztof
>
>
>
> On 11/22/2017 9:38 AM, Benjamin Kramer via cfe-commits wrote:
>>
>> Author: d0k
>> Date: Wed Nov 22 07:38:23 2017
>> New Revision: 318840
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=318840&view=rev
>> Log:
>> [FindAllSymbols] Cache regexes, creating them is expensive
>>
>> This is a bit annoying because LLVM regexes are always mutable to store
>> errors. Assert that there are never errors and fix broken hardcoded
>> regexes.
>>
>

[PATCH] D39730: Enabling constructor code completion

2017-11-23 Thread Jan Korous via Phabricator via cfe-commits
jkorous-apple added a comment.

Sorry for delays, I'm working on this on and off when there's nothing more 
important.

Let me specify a little narrower scope of this change:

- Make code completion contain constructor item for out-of-line constructor 
definition: struct foo { foo(); }; foo:: // result should 
contain constructor foo()

I would rather leave issues with destructors for other patch.

I haven't previously realized issue with initialization you mentioned and there 
are other cases where completing after id qualified with class prefix shouldn't 
end up containing constructors (e. g. typedef foo::some_embedded_type bar;)

I assume the proper way is to add constructors to code completion results only 
in these contexts:

- http://nongnu.org/hcb/#translation-unit
  - http://nongnu.org/hcb/#declaration-seq
- http://nongnu.org/hcb/#declaration
  - http://nongnu.org/hcb/#function-definition
- CODE_COMPLETE_CTOR
  - http://nongnu.org/hcb/#namespace-definition
- http://nongnu.org/hcb/#named-namespace-definition
  - http://nongnu.org/hcb/#original-namespace-definition | 
http://nongnu.org/hcb/#extension-namespace-definition
- http://nongnu.org/hcb/#namespace-body
  - http://nongnu.org/hcb/#declaration-seq
- ...
  - CODE_COMPLETE_CTOR
- http://nongnu.org/hcb/#unnamed-namespace-definition
  - http://nongnu.org/hcb/#namespace-body
- http://nongnu.org/hcb/#declaration-seq
  - ...
- CODE_COMPLETE_CTOR

Which I think is equivalent to saying that the only parent nodes in ASTContext 
should either be NamespaceDecl or TranslationUnitDecl.

If you think my assumptions are wrong here please let me know.

Basically I need to distinguish between this callstack (foo::)

  * frame  #0: 0x00010bab9e7e libclang.dylib` 
clang::Sema::CodeCompleteQualifiedId(this=0x00011d8b3a00, 
S=0x00011d736fe0, SS=0x78072538, EnteringContext=true, 
AddCtorsToResult=false)  + 46 at SemaCodeComplete.cpp:4550
frame  #1: 0x00010f9a8343 libclang.dylib` 
clang::Parser::ParseOptionalCXXScopeSpecifier(this=0x00011d8b7a00, 
SS=0x78072538, ObjectType=(Ptr = 0x), 
EnteringContext=true, MayBePseudoDestructor=0x, 
IsTypename=false, LastII=0x, OnlyNamespace=false)  + 1987 at 
ParseExprCXX.cpp:253
frame  #2: 0x00010fa34d69 libclang.dylib` 
clang::Parser::TryAnnotateCXXScopeToken(this=0x00011d8b7a00, 
EnteringContext=true)  + 457 at Parser.cpp:1861
frame  #3: 0x00010f9466d7 libclang.dylib` 
clang::Parser::ParseDeclarationSpecifiers(this=0x00011d8b7a00, 
DS=0x78073738, TemplateInfo=0x78073668, AS=AS_none, 
DSContext=DSC_top_level, LateAttrs=0x)  + 5111 at 
ParseDecl.cpp:3224
frame  #4: 0x00010fa2f63b libclang.dylib` 
clang::Parser::ParseDeclOrFunctionDefInternal(this=0x00011d8b7a00, 
attrs=0x78073d08, DS=0x78073738, AS=AS_none)  + 139 at 
Parser.cpp:922
frame  #5: 0x00010fa2f152 libclang.dylib` 
clang::Parser::ParseDeclarationOrFunctionDefinition(this=0x00011d8b7a00, 
attrs=0x78073d08, DS=0x, AS=AS_none)  + 194 at 
Parser.cpp:1003
frame  #6: 0x00010fa2e27f libclang.dylib` 
clang::Parser::ParseExternalDeclaration(this=0x00011d8b7a00, 
attrs=0x78073d08, DS=0x)  + 3599 at Parser.cpp:853
frame  #7: 0x00010f965a38 libclang.dylib` 
clang::Parser::ParseInnerNamespace(this=0x00011d8b7a00, IdentLoc=size=1, 
Ident=size=1, NamespaceLoc=size=1, index=0, InlineLoc=0x780743b8, 
attrs=0x78074300, Tracker=0x780741c0)  + 312 at 
ParseDeclCXX.cpp:221
frame  #8: 0x00010f9651a4 libclang.dylib` 
clang::Parser::ParseNamespace(this=0x00011d8b7a00, Context=0, 
DeclEnd=0x78074e38, InlineLoc=(ID = 0))  + 8180 at ParseDeclCXX.cpp:196
frame  #9: 0x00010f944d59 libclang.dylib` 
clang::Parser::ParseDeclaration(this=0x00011d8b7a00, Context=0, 
DeclEnd=0x78074e38, attrs=0x78075030)  + 505 at 
ParseDecl.cpp:1727
frame #10: 0x00010fa2ddc2 libclang.dylib` 
clang::Parser::ParseExternalDeclaration(this=0x00011d8b7a00, 
attrs=0x78075030, DS=0x)  + 2386 at Parser.cpp:786
frame #11: 0x00010fa2cab8 libclang.dylib` 
clang::Parser::ParseTopLevelDecl(this=0x00011d8b7a00, 
Result=0x78075190)  + 1240 at Parser.cpp:621
frame #12: 0x00010f92d143 libclang.dylib` 
clang::ParseAST(S=0x00011d8b3a00, PrintStats=false, 
SkipFunctionBodies=false)  + 963 at ParseAST.cpp:147
frame #13: 0x00010b5bb755 libclang.dylib` 
clang::ASTFrontendAction::ExecuteAction(this=0x00011d720de0)  + 485 at 
FrontendAction.cpp:1005
frame #14: 0x00010b5ba630 libclang.dylib` 
clang::FrontendAction::Execute(this=0x00011d720de0)  + 112 at 
FrontendAction.cpp:904
frame #15:

Re: [clang-tools-extra] r318840 - [FindAllSymbols] Cache regexes, creating them is expensive

2017-11-23 Thread Krzysztof Parzyszek via cfe-commits
There has been some problem with std::pair on FreeBSD (due to some ABI 
compatibility issue), but I don't know much about what it was.


Commenting the reserve doesn't help, unfortunately. The same problem is 
now flagged in emplace_back.


-Krzysztof


On 11/23/2017 11:47 AM, Benjamin Kramer wrote:

That looks like a bug in the standard library. Does removing the call
to reserve fix it? It's not really necessary, that code isn't
performance sensitive at all.

On Thu, Nov 23, 2017 at 6:36 PM, Krzysztof Parzyszek
 wrote:

Hi,
This broke build on FreeBSD 11:

[100%] Building CXX object
tools/clang/tools/extra/include-fixer/find-all-symbols/CMakeFiles/findAllSymbols.dir/HeaderMapCollector.cpp.o
cd /w/bld/org/tools/clang/tools/extra/include-fixer/find-all-symbols &&
/w/c/clang+llvm-5.0.0-x86_64-unknown-freebsd11/bin/clang++
-DGTEST_HAS_RTTI=0 -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS
-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
-I/w/bld/org/tools/clang/tools/extra/include-fixer/find-all-symbols
-I/w/src/llvm.org/tools/clang/tools/extra/include-fixer/find-all-symbols
-I/w/src/llvm.org/tools/clang/include -I/w/bld/org/tools/clang/include
-I/w/bld/org/include -I/w/src/llvm.org/include -isystem /usr/local/include
-stdlib=libc++ -fPIC -fvisibility-inlines-hidden -Werror=date-time
-Werror=unguarded-availability-new -std=c++11 -Wall -W -Wno-unused-parameter
-Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic
-Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor
-Wdelete-non-virtual-dtor -Wno-comment -Wstring-conversion
-ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual
-Wno-nested-anon-types -O3-UNDEBUG -fno-exceptions -fno-rtti -o
CMakeFiles/findAllSymbols.dir/HeaderMapCollector.cpp.o -c
/w/src/llvm.org/tools/clang/tools/extra/include-fixer/find-all-symbols/HeaderMapCollector.cpp
In file included from
/w/src/llvm.org/tools/clang/tools/extra/include-fixer/find-all-symbols/HeaderMapCollector.cpp:10:
In file included from
/w/src/llvm.org/tools/clang/tools/extra/include-fixer/find-all-symbols/HeaderMapCollector.h:13:
In file included from /w/src/llvm.org/include/llvm/ADT/StringMap.h:17:
In file included from /w/src/llvm.org/include/llvm/ADT/StringRef.h:13:
In file included from /w/src/llvm.org/include/llvm/ADT/STLExtras.h:20:
In file included from /w/src/llvm.org/include/llvm/ADT/Optional.h:22:
In file included from /w/src/llvm.org/include/llvm/Support/type_traits.h:19:
/usr/include/c++/v1/utility:315:11: error: call to deleted constructor of
'llvm::Regex'
 : first(__p.first),
   ^ ~
/usr/include/c++/v1/memory:1747:31: note: in instantiation of member
function 'std::__1::pair::pair' requested here
 ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
   ^
/usr/include/c++/v1/memory:1658:18: note: in instantiation of function
template specialization 'std::__1::allocator >::construct, const
std::__1::pair &>' requested here
 {__a.construct(__p, _VSTD::forward<_Args>(__args)...);}
  ^
/usr/include/c++/v1/memory:1504:14: note: in instantiation of function
template specialization
'std::__1::allocator_traits > >::__construct,
const std::__1::pair &>' requested here
 {__construct(__has_construct(),
  ^
/usr/include/c++/v1/memory:1620:17: note: in instantiation of function
template specialization
'std::__1::allocator_traits > >::construct,
const std::__1::pair &>' requested here
 construct(__a, _VSTD::__to_raw_pointer(__end2-1),
_VSTD::move_if_noexcept(*--__end1));
 ^
/usr/include/c++/v1/vector:892:21: note: in instantiation of function
template specialization
'std::__1::allocator_traits > >::__construct_backward *>' requested here
 __alloc_traits::__construct_backward(this->__alloc(), this->__begin_,
this->__end_, __v.__begin_);
 ^
/usr/include/c++/v1/vector:1537:9: note: in instantiation of member function
'std::__1::vector,
std::__1::allocator >

::__swap_out_circular_buffer' requested here

 __swap_out_circular_buffer(__v);
 ^
/w/src/llvm.org/tools/clang/tools/extra/include-fixer/find-all-symbols/HeaderMapCollector.cpp:19:33:
note: in instantiation of member function
'std::__1::vector,
std::__1::allocator > >::reserve'
requested here
   this->RegexHeaderMappingTable.reserve(RegexHeaderMappingTable->size());
 ^
/w/src/llvm.org/include/llvm/Support/Regex.h:49:5: note: 'Regex' has been
explicitly marked deleted here
 Regex(const Regex &) = delete;
 ^
1 error generated.
*** Error code 1


-Krzysztof



On 11/22/2017 9:38 AM, Benjamin Kramer via cfe-commits wrote:


Author: d0k
Date: Wed Nov 22 07:38:23 2017
New Revision: 318840

URL: http://llvm.org/viewvc/llvm-project?rev=318840&view=rev
Log:
[FindAllSymbols] Cache regexes, creating them is expensive

This is a bit annoying because LLVM regexes are always mutable to store
errors. Assert that there 

[PATCH] D38425: [clangd] Document highlights for clangd

2017-11-23 Thread Marc-Andre Laperle via Phabricator via cfe-commits
malaperle added inline comments.



Comment at: clangd/ClangdUnit.cpp:997
+  DocumentHighlightKind Kind;
+  switch (Roles) {
+  case (unsigned)index::SymbolRole::Read:

With this code, I always get "text" kind. It's because index::SymbolRoleSet is 
a bitfield so you have to check the write, read bits. Something like:

DocumentHighlightKind Kind = DocumentHighlightKind::Text;
if (static_cast(index::SymbolRole::Write) & Roles) {
  Kind = DocumentHighlightKind::Write;
} else if (static_cast(index::SymbolRole::Read) & 
Roles) {
  Kind = DocumentHighlightKind::Read;
}


https://reviews.llvm.org/D38425



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


Re: [clang-tools-extra] r318840 - [FindAllSymbols] Cache regexes, creating them is expensive

2017-11-23 Thread Benjamin Kramer via cfe-commits
I'm afraid I can't really help you here. You can try twiddling the
code a bit by creating the pair explicitly and moving it into the
vector, just to avoid the brokenness in the standard library. Not sure
if that will help though.

On Thu, Nov 23, 2017 at 7:05 PM, Krzysztof Parzyszek
 wrote:
> There has been some problem with std::pair on FreeBSD (due to some ABI
> compatibility issue), but I don't know much about what it was.
>
> Commenting the reserve doesn't help, unfortunately. The same problem is now
> flagged in emplace_back.
>
> -Krzysztof
>
>
>
> On 11/23/2017 11:47 AM, Benjamin Kramer wrote:
>>
>> That looks like a bug in the standard library. Does removing the call
>> to reserve fix it? It's not really necessary, that code isn't
>> performance sensitive at all.
>>
>> On Thu, Nov 23, 2017 at 6:36 PM, Krzysztof Parzyszek
>>  wrote:
>>>
>>> Hi,
>>> This broke build on FreeBSD 11:
>>>
>>> [100%] Building CXX object
>>>
>>> tools/clang/tools/extra/include-fixer/find-all-symbols/CMakeFiles/findAllSymbols.dir/HeaderMapCollector.cpp.o
>>> cd /w/bld/org/tools/clang/tools/extra/include-fixer/find-all-symbols &&
>>> /w/c/clang+llvm-5.0.0-x86_64-unknown-freebsd11/bin/clang++
>>> -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS
>>> -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
>>> -I/w/bld/org/tools/clang/tools/extra/include-fixer/find-all-symbols
>>> -I/w/src/llvm.org/tools/clang/tools/extra/include-fixer/find-all-symbols
>>> -I/w/src/llvm.org/tools/clang/include -I/w/bld/org/tools/clang/include
>>> -I/w/bld/org/include -I/w/src/llvm.org/include -isystem
>>> /usr/local/include
>>> -stdlib=libc++ -fPIC -fvisibility-inlines-hidden -Werror=date-time
>>> -Werror=unguarded-availability-new -std=c++11 -Wall -W
>>> -Wno-unused-parameter
>>> -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic
>>> -Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor
>>> -Wdelete-non-virtual-dtor -Wno-comment -Wstring-conversion
>>> -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual
>>> -Wno-nested-anon-types -O3-UNDEBUG -fno-exceptions -fno-rtti -o
>>> CMakeFiles/findAllSymbols.dir/HeaderMapCollector.cpp.o -c
>>>
>>> /w/src/llvm.org/tools/clang/tools/extra/include-fixer/find-all-symbols/HeaderMapCollector.cpp
>>> In file included from
>>>
>>> /w/src/llvm.org/tools/clang/tools/extra/include-fixer/find-all-symbols/HeaderMapCollector.cpp:10:
>>> In file included from
>>>
>>> /w/src/llvm.org/tools/clang/tools/extra/include-fixer/find-all-symbols/HeaderMapCollector.h:13:
>>> In file included from /w/src/llvm.org/include/llvm/ADT/StringMap.h:17:
>>> In file included from /w/src/llvm.org/include/llvm/ADT/StringRef.h:13:
>>> In file included from /w/src/llvm.org/include/llvm/ADT/STLExtras.h:20:
>>> In file included from /w/src/llvm.org/include/llvm/ADT/Optional.h:22:
>>> In file included from
>>> /w/src/llvm.org/include/llvm/Support/type_traits.h:19:
>>> /usr/include/c++/v1/utility:315:11: error: call to deleted constructor of
>>> 'llvm::Regex'
>>>  : first(__p.first),
>>>^ ~
>>> /usr/include/c++/v1/memory:1747:31: note: in instantiation of member
>>> function 'std::__1::pair::pair' requested here
>>>  ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
>>>^
>>> /usr/include/c++/v1/memory:1658:18: note: in instantiation of function
>>> template specialization 'std::__1::allocator>> const char *> >::construct,
>>> const
>>> std::__1::pair &>' requested here
>>>  {__a.construct(__p, _VSTD::forward<_Args>(__args)...);}
>>>   ^
>>> /usr/include/c++/v1/memory:1504:14: note: in instantiation of function
>>> template specialization
>>>
>>> 'std::__1::allocator_traits>> const char *> > >::__construct,
>>> const std::__1::pair &>' requested here
>>>  {__construct(__has_construct>> _Args...>(),
>>>   ^
>>> /usr/include/c++/v1/memory:1620:17: note: in instantiation of function
>>> template specialization
>>>
>>> 'std::__1::allocator_traits>> const char *> > >::construct,
>>> const std::__1::pair &>' requested here
>>>  construct(__a, _VSTD::__to_raw_pointer(__end2-1),
>>> _VSTD::move_if_noexcept(*--__end1));
>>>  ^
>>> /usr/include/c++/v1/vector:892:21: note: in instantiation of function
>>> template specialization
>>>
>>> 'std::__1::allocator_traits>> const char *> > >::__construct_backward>> char *> *>' requested here
>>>  __alloc_traits::__construct_backward(this->__alloc(),
>>> this->__begin_,
>>> this->__end_, __v.__begin_);
>>>  ^
>>> /usr/include/c++/v1/vector:1537:9: note: in instantiation of member
>>> function
>>> 'std::__1::vector,
>>> std::__1::allocator >

 ::__swap_out_circular_buffer' requested here
>>>
>>>  __swap_out_circular_buffer(__v);
>>>  ^
>>>
>>> /w/src/llvm.org/tools/clang/tools/extra/include-fixer/find-all-symbols/HeaderMapCollector.cpp:19:33:
>>> note: in ins

[PATCH] D40398: Remove ValueDependent assertions on ICE checks.

2017-11-23 Thread Matt Davis via Phabricator via cfe-commits
mattd created this revision.

In the case of ill-formed templates, a value dependent name can reach the 
integral constant expression (ICE) check. After an error occurs following an 
ill-formed template, an ICE check can be performed on a template definition. 
That definition might contain an expression, such as "const a = sizeof(T);" 
where T is a template type argument. In this case, the latter expression is 
ValueDependent, T is type dependent, and the sizeof expression is therefore 
considered Value Dependent.

The assertions will trigger, if the implementation of a templated member 
function occurs in a separate namespace from its definition (bad code). If such 
a case occurs, an ODR marking of a variable decl is performed, which happens to 
check that a particular variable is constant.

Additionally, ValueDependent items can be ICEs, but we never check that case, 
and the assertions assume we never see them in the first place.  In general, I 
don't like removing assertions, for obvious reasons.  But in this case, I am 
not sure they are necessary, and can be problematic as seen by the included 
test case.


https://reviews.llvm.org/D40398

Files:
  lib/AST/Decl.cpp
  lib/AST/ExprConstant.cpp
  test/SemaTemplate/illformed-template-ice.cpp


Index: test/SemaTemplate/illformed-template-ice.cpp
===
--- test/SemaTemplate/illformed-template-ice.cpp
+++ test/SemaTemplate/illformed-template-ice.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+class A {
+public:
+  template  void B();
+};
+
+namespace {
+  template  void A::B() { // expected-error {{cannot define or 
redeclare 'B' here because namespace '' does not enclose namespace 'A'}}
+const int a = sizeof(T);
+int  b = a;
+  }
+}
Index: lib/AST/ExprConstant.cpp
===
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -10250,7 +10250,6 @@
 }
 
 static ICEDiag CheckICE(const Expr* E, const ASTContext &Ctx) {
-  assert(!E->isValueDependent() && "Should not see value dependent exprs!");
   if (!E->getType()->isIntegralOrEnumerationType())
 return ICEDiag(IK_NotICE, E->getLocStart());
 
Index: lib/AST/Decl.cpp
===
--- lib/AST/Decl.cpp
+++ lib/AST/Decl.cpp
@@ -2216,7 +2216,6 @@
 return Eval->Evaluated.isUninit() ? nullptr : &Eval->Evaluated;
 
   const auto *Init = cast(Eval->Value);
-  assert(!Init->isValueDependent());
 
   if (Eval->IsEvaluating) {
 // FIXME: Produce a diagnostic for self-initialization.
@@ -2284,7 +2283,6 @@
 return Eval->IsICE;
 
   const auto *Init = cast(Eval->Value);
-  assert(!Init->isValueDependent());
 
   // In C++11, evaluate the initializer to check whether it's a constant
   // expression.


Index: test/SemaTemplate/illformed-template-ice.cpp
===
--- test/SemaTemplate/illformed-template-ice.cpp
+++ test/SemaTemplate/illformed-template-ice.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+class A {
+public:
+  template  void B();
+};
+
+namespace {
+  template  void A::B() { // expected-error {{cannot define or redeclare 'B' here because namespace '' does not enclose namespace 'A'}}
+const int a = sizeof(T);
+int  b = a;
+  }
+}
Index: lib/AST/ExprConstant.cpp
===
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -10250,7 +10250,6 @@
 }
 
 static ICEDiag CheckICE(const Expr* E, const ASTContext &Ctx) {
-  assert(!E->isValueDependent() && "Should not see value dependent exprs!");
   if (!E->getType()->isIntegralOrEnumerationType())
 return ICEDiag(IK_NotICE, E->getLocStart());
 
Index: lib/AST/Decl.cpp
===
--- lib/AST/Decl.cpp
+++ lib/AST/Decl.cpp
@@ -2216,7 +2216,6 @@
 return Eval->Evaluated.isUninit() ? nullptr : &Eval->Evaluated;
 
   const auto *Init = cast(Eval->Value);
-  assert(!Init->isValueDependent());
 
   if (Eval->IsEvaluating) {
 // FIXME: Produce a diagnostic for self-initialization.
@@ -2284,7 +2283,6 @@
 return Eval->IsICE;
 
   const auto *Init = cast(Eval->Value);
-  assert(!Init->isValueDependent());
 
   // In C++11, evaluate the initializer to check whether it's a constant
   // expression.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40399: [clangd] Add missing (but documented!) JSONExpr typed accessors

2017-11-23 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 124105.
sammccall added a comment.

While here, fix a duplicated test.


https://reviews.llvm.org/D40399

Files:
  clangd/JSONExpr.h
  unittests/clangd/JSONExprTests.cpp

Index: unittests/clangd/JSONExprTests.cpp
===
--- unittests/clangd/JSONExprTests.cpp
+++ unittests/clangd/JSONExprTests.cpp
@@ -167,7 +167,6 @@
   ExpectErr("Unexpected EOF", "");
   ExpectErr("Unexpected EOF", "[");
   ExpectErr("Text after end of document", "[][]");
-  ExpectErr("Text after end of document", "[][]");
   ExpectErr("Invalid bareword", "fuzzy");
   ExpectErr("Expected , or ]", "[2?]");
   ExpectErr("Expected object key", "{a:2}");
@@ -185,6 +184,49 @@
 })");
 }
 
+TEST(JSONTest, Inspection) {
+  llvm::Expected Doc = parse(R"(
+{
+  "null": null,
+  "boolean": false,
+  "number": 2.78,
+  "string": "json",
+  "array": [null, true, 3.14, "hello", [1,2,3], {"time": "arrow"}],
+  "object": {"fruit": "banana"}
+}
+  )");
+  EXPECT_TRUE(!!Doc);
+
+  obj *O = Doc->object();
+  ASSERT_TRUE(O);
+
+  EXPECT_FALSE(O->null("missing"));
+  EXPECT_FALSE(O->null("boolean"));
+  EXPECT_TRUE(O->null("null"));
+
+  EXPECT_EQ(O->number("number"), llvm::Optional(2.78));
+  EXPECT_EQ(O->string("string"), llvm::Optional("json"));
+  ASSERT_FALSE(O->object("missing"));
+  ASSERT_FALSE(O->object("array"));
+  ASSERT_TRUE(O->object("object"));
+  EXPECT_EQ(*O->object("object"), (obj{{"fruit", "banana"}}));
+
+  ary *A = O->array("array");
+  ASSERT_TRUE(A);
+  EXPECT_EQ(A->boolean(1), llvm::Optional(true));
+  ASSERT_TRUE(A->array(4));
+  EXPECT_EQ(*A->array(4), (ary{1, 2, 3}));
+  int I = 0;
+  for (Expr &E : *A) {
+if (I++ == 5) {
+  ASSERT_TRUE(E.object());
+  EXPECT_EQ(E.object()->string("time"),
+llvm::Optional("arrow"));
+} else
+  EXPECT_FALSE(E.object());
+  }
+}
+
 } // namespace
 } // namespace json
 } // namespace clangd
Index: clangd/JSONExpr.h
===
--- clangd/JSONExpr.h
+++ clangd/JSONExpr.h
@@ -172,7 +172,7 @@
 return llvm::None;
   }
   llvm::Optional boolean() const {
-if (LLVM_LIKELY(Type == T_Null))
+if (LLVM_LIKELY(Type == T_Boolean))
   return as();
 return llvm::None;
   }
@@ -292,6 +292,63 @@
 Expr &operator[](ObjectKey &&K) {
   return emplace(std::move(K), Expr(nullptr)).first->second;
 }
+
+// Look up a property, returning nullptr if it doesn't exist.
+json::Expr *get(const ObjectKey &K) {
+  auto I = find(K);
+  if (I == end())
+return nullptr;
+  return &I->second;
+}
+const json::Expr *get(const ObjectKey &K) const {
+  auto I = find(K);
+  if (I == end())
+return nullptr;
+  return &I->second;
+}
+// Typed accessors return None/nullptr if
+//   - the property doesn't exist
+//   - or it has the wrong type
+llvm::Optional null(const ObjectKey &K) const {
+  if (auto *V = get(K))
+return V->null();
+  return llvm::None;
+}
+llvm::Optional boolean(const ObjectKey &K) const {
+  if (auto *V = get(K))
+return V->boolean();
+  return llvm::None;
+}
+llvm::Optional number(const ObjectKey &K) const {
+  if (auto *V = get(K))
+return V->number();
+  return llvm::None;
+}
+llvm::Optional string(const ObjectKey &K) const {
+  if (auto *V = get(K))
+return V->string();
+  return llvm::None;
+}
+const ObjectExpr *object(const ObjectKey &K) const {
+  if (auto *V = get(K))
+return V->object();
+  return nullptr;
+}
+ObjectExpr *object(const ObjectKey &K) {
+  if (auto *V = get(K))
+return V->object();
+  return nullptr;
+}
+const ArrayExpr *array(const ObjectKey &K) const {
+  if (auto *V = get(K))
+return V->array();
+  return nullptr;
+}
+ArrayExpr *array(const ObjectKey &K) {
+  if (auto *V = get(K))
+return V->array();
+  return nullptr;
+}
   };
 
   class ArrayExpr : public std::vector {
@@ -306,6 +363,24 @@
   for (const auto &V : C)
 emplace_back(V);
 }
+
+// Typed accessors return None/nullptr if the element has the wrong type.
+llvm::Optional null(size_t I) const {
+  return (*this)[I].null();
+}
+llvm::Optional boolean(size_t I) const {
+  return (*this)[I].boolean();
+}
+llvm::Optional number(size_t I) const {
+  return (*this)[I].number();
+}
+llvm::Optional string(size_t I) const {
+  return (*this)[I].string();
+}
+const ObjectExpr *object(size_t I) const { return (*this)[I].object(); }
+ObjectExpr *object(size_t I) { return (*this)[I].object(); }
+const ArrayExpr *array(size_t I) const { return (*this)[I].array(); }
+ArrayExpr *array(size_t I) { return (*this)[I].array(); }
   };
 
 private:
__

[PATCH] D40381: Parse concept definition

2017-11-23 Thread Saar Raz via Phabricator via cfe-commits
saar.raz requested changes to this revision.
saar.raz added a comment.
This revision now requires changes to proceed.

Also add:
In ASTDumper

  +void VisitConceptTemplateDecl(const ConceptTemplateDecl *D);

Implementation:

  void ASTDumper::VisitConceptTemplateDecl(const ConceptTemplateDecl *D) {
dumpName(D);
dumpTemplateParameters(D->getTemplateParameters());
VisitExpr(D->getConstraintExpression());
  }

Address the other issues I've mentioned in the inline comments and we're good! 
Great job :)




Comment at: include/clang/AST/DeclTemplate.h:3023
+ Expr *ConstraintExpr);
+
+  Expr *getConstraintExpr() const {

Add CreateDeserialized.



Comment at: include/clang/AST/DeclTemplate.h:3027
+  }
+
+  // TODO: Should do source range properly.

Add setConstraintExpr (for use when calling CreateDeserialized, see 
ASTDeclReader)



Comment at: include/clang/Parse/Parser.h:2787
AccessSpecifier AS = AS_none);
+  // C++ 17: Template, concept definition [temp]
+  Decl *

C++2a



Comment at: lib/Parse/ParseTemplate.cpp:374
+
+  ExprResult ConstraintExpr = ParseConstraintExpression();
+

Add a check to ParseConstraintExpression that the type is either dependent or 
bool, and add an apropriate diagnostic.

```
if (!ConstraintExpr->isTypeDependent() && ConstraintExpr->getType() != 
Context.BoolTy) {
  Diag(Init->getSourceRange().getBegin(),
   diag::err_concept_initialized_with_non_bool_type) << Init->getType();
  Concept->setInvalidDecl();
  return;
}
```



Comment at: lib/Sema/SemaTemplate.cpp:2935
   if (!Template || isa(Template) ||
   isa(Template)) {
 // We might have a substituted template template parameter pack. If so,

Add

```
 || isa

```



Comment at: lib/Sema/SemaTemplate.cpp:3936
 
+  if (R.getAsSingle()) {
+return CheckConceptTemplateId(SS, R.getLookupNameInfo(),

We're gonna want to check
```
!TemplateSpecializationType::anyDependentTemplateArguments(*TemplateArgs, 
InstantiationDependent)
``` 
here as well - so that we can instantiate a ConceptSpecializationExpr later 
when we have it (we're not gonna want to instantiate a 
ConceptSpecializationExpr with dependent arguments.



Comment at: lib/Sema/SemaTemplate.cpp:7698
+
+  // TODO: Maybe we should check TemplateParameterLists for nullptr?
+  Decl *NewDecl = ConceptDecl::Create(Context, DC, L, Name,

Check that !DC->isFileContext() (Concepts may only be defined at namespace 
scope)



Comment at: lib/Sema/SemaTemplate.cpp:7700
+  Decl *NewDecl = ConceptDecl::Create(Context, DC, L, Name,
+  TemplateParameterLists[0],
+  ConstraintExpr);

I think it would be better to just check that TemplateParameterLists.size() != 
1 - it can't happen in a valid situation anyway, you'd want a diagnostic there.



Comment at: lib/Sema/SemaTemplate.cpp:7702
+  ConstraintExpr);
+  ActOnDocumentableDecl(NewDecl);
+  CurContext->addDecl(NewDecl);

Check that c->getAssociatedConstraints() == nullptr ([temp.concept]p4 A concept 
shall not have associated constraints).
Add a TODO to make a test for that once we have actual associated constraints.



Comment at: lib/Sema/SemaTemplateInstantiateDecl.cpp:3099
+Decl *TemplateDeclInstantiator::VisitConceptDecl(ConceptDecl *D) {
+  // TODO: Do something here?
+  return nullptr;

Yes - 

```
llvm_unreachable("Concept definitions cannot reside inside a template");
```



Comment at: lib/Serialization/ASTReaderDecl.cpp:1975
+void ASTDeclReader::VisitConceptDecl(ConceptDecl *D) {
+  VisitTemplateDecl(D);
+}

Add here:

```
  D->setConstraintExpression(Record.readExpr());
```
And in ASTDeclWriter, a method VisitConceptDecl:
```
void ASTDeclWriter::VisitConceptTemplateDecl(ConceptTemplateDecl *D) {
  VisitTemplateDecl(D);
  Record.AddStmt(D->getConstraintExpression());
  Code = serialization::DECL_CONCEPT;
}
```
And call it in the appropriate places.



Comment at: lib/Serialization/ASTReaderDecl.cpp:3503
 break;
   case DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION:
 D = ClassScopeFunctionSpecializationDecl::CreateDeserialized(Context, ID);

Add a case: DECL_CONCEPT, also create that enum member.


https://reviews.llvm.org/D40381



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


[PATCH] D38694: [ASTImporter] Support importing CXXUnresolvedConstructExpr and UnresolvedLookupExpr

2017-11-23 Thread Peter Szecsi via Phabricator via cfe-commits
szepet updated this revision to Diff 124115.
szepet marked 7 inline comments as done.
szepet added a comment.
Herald added a subscriber: rnkovacs.

Updates based on review comments.


https://reviews.llvm.org/D38694

Files:
  lib/AST/ASTImporter.cpp
  unittests/AST/ASTImporterTest.cpp

Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -555,5 +555,39 @@
  has(cxxDependentScopeMemberExpr();
 }
 
+TEST(ImportExpr, ImportUnresolvedLookupExpr) {
+  MatchVerifier Verifier;
+  EXPECT_TRUE(testImport("template int foo();"
+ "template  void declToImport() {"
+ "  ::foo;"
+ "  ::template foo;"
+ "}",
+ Lang_CXX, "", Lang_CXX, Verifier,
+ functionTemplateDecl(has(functionDecl(has(
+ compoundStmt(has(unresolvedLookupExpr();
+}
+
+TEST(ImportExpr, ImportCXXUnresolvedConstructExpr) {
+  MatchVerifier Verifier;
+  EXPECT_TRUE(
+  testImport("template  class C { T t; };"
+ "template  void declToImport() {"
+ "  C d;"
+ "  d.t = T();"
+ "}",
+ Lang_CXX, "", Lang_CXX, Verifier,
+ functionTemplateDecl(has(functionDecl(has(compoundStmt(has(
+ binaryOperator(has(cxxUnresolvedConstructExpr()));
+  EXPECT_TRUE(
+  testImport("template  class C { T t; };"
+ "template  void declToImport() {"
+ "  C d;"
+ "  (&d)->t = T();"
+ "}",
+ Lang_CXX, "", Lang_CXX, Verifier,
+ functionTemplateDecl(has(functionDecl(has(compoundStmt(has(
+ binaryOperator(has(cxxUnresolvedConstructExpr()));
+}
+
 } // end namespace ast_matchers
 } // end namespace clang
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -287,6 +287,8 @@
 Expr *VisitCXXConstructExpr(CXXConstructExpr *E);
 Expr *VisitCXXMemberCallExpr(CXXMemberCallExpr *E);
 Expr *VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E);
+Expr *VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *CE);
+Expr *VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E);
 Expr *VisitExprWithCleanups(ExprWithCleanups *EWC);
 Expr *VisitCXXThisExpr(CXXThisExpr *E);
 Expr *VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E);
@@ -5846,6 +5848,64 @@
   cast_or_null(ToFQ), MemberNameInfo, &ToTAInfo);
 }
 
+Expr *ASTNodeImporter::VisitCXXUnresolvedConstructExpr(
+CXXUnresolvedConstructExpr *CE) {
+
+  unsigned NumArgs = CE->arg_size();
+
+  llvm::SmallVector ToArgs(NumArgs);
+  if (ImportArrayChecked(CE->arg_begin(), CE->arg_end(), ToArgs.begin()))
+return nullptr;
+
+  return CXXUnresolvedConstructExpr::Create(
+  Importer.getToContext(), Importer.Import(CE->getTypeSourceInfo()),
+  Importer.Import(CE->getLParenLoc()), llvm::makeArrayRef(ToArgs),
+  Importer.Import(CE->getRParenLoc()));
+}
+
+Expr *ASTNodeImporter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) {
+  CXXRecordDecl *NamingClass =
+  cast_or_null(Importer.Import(E->getNamingClass()));
+  if (E->getNamingClass() && !NamingClass)
+return nullptr;
+
+  DeclarationName Name = Importer.Import(E->getName());
+  if (E->getName().isEmpty() && Name.isEmpty())
+return nullptr;
+  DeclarationNameInfo NameInfo(Name, Importer.Import(E->getNameLoc()));
+  // Import additional name location/type info.
+  ImportDeclarationNameLoc(E->getNameInfo(), NameInfo);
+
+  UnresolvedSet<8> ToDecls;
+  for (Decl *D : E->decls()) {
+if (NamedDecl *To = cast_or_null(Importer.Import(D)))
+  ToDecls.addDecl(To);
+else
+  return nullptr;
+  }
+
+  TemplateArgumentListInfo *ResInfo = nullptr;
+  if (E->hasExplicitTemplateArgs()) {
+TemplateArgumentListInfo ToTAInfo(Importer.Import(E->getLAngleLoc()),
+  Importer.Import(E->getRAngleLoc()));
+if (ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo))
+  return nullptr;
+ResInfo = &ToTAInfo;
+  }
+
+  if (ResInfo || E->getTemplateKeywordLoc().isValid())
+return UnresolvedLookupExpr::Create(
+Importer.getToContext(), NamingClass,
+Importer.Import(E->getQualifierLoc()),
+Importer.Import(E->getTemplateKeywordLoc()), NameInfo, E->requiresADL(),
+ResInfo, ToDecls.begin(), ToDecls.end());
+
+  return UnresolvedLookupExpr::Create(
+  Importer.getToContext(), NamingClass,
+  Importer.Import(E->getQualifierLoc()), NameInfo, E->requiresADL(),
+  E->isOverloaded(), ToDecls.begin(), ToDecls.end());
+}
+
 Expr *ASTNodeImporter::VisitCallE

Re: [clang-tools-extra] r318840 - [FindAllSymbols] Cache regexes, creating them is expensive

2017-11-23 Thread Krzysztof Parzyszek via cfe-commits

+Dimitry.


On 11/23/2017 12:50 PM, Benjamin Kramer wrote:

I'm afraid I can't really help you here. You can try twiddling the
code a bit by creating the pair explicitly and moving it into the
vector, just to avoid the brokenness in the standard library. Not sure
if that will help though.

On Thu, Nov 23, 2017 at 7:05 PM, Krzysztof Parzyszek
 wrote:

There has been some problem with std::pair on FreeBSD (due to some ABI
compatibility issue), but I don't know much about what it was.

Commenting the reserve doesn't help, unfortunately. The same problem is now
flagged in emplace_back.

-Krzysztof



On 11/23/2017 11:47 AM, Benjamin Kramer wrote:


That looks like a bug in the standard library. Does removing the call
to reserve fix it? It's not really necessary, that code isn't
performance sensitive at all.

On Thu, Nov 23, 2017 at 6:36 PM, Krzysztof Parzyszek
 wrote:


Hi,
This broke build on FreeBSD 11:

[100%] Building CXX object

tools/clang/tools/extra/include-fixer/find-all-symbols/CMakeFiles/findAllSymbols.dir/HeaderMapCollector.cpp.o
cd /w/bld/org/tools/clang/tools/extra/include-fixer/find-all-symbols &&
/w/c/clang+llvm-5.0.0-x86_64-unknown-freebsd11/bin/clang++
-DGTEST_HAS_RTTI=0 -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS
-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
-I/w/bld/org/tools/clang/tools/extra/include-fixer/find-all-symbols
-I/w/src/llvm.org/tools/clang/tools/extra/include-fixer/find-all-symbols
-I/w/src/llvm.org/tools/clang/include -I/w/bld/org/tools/clang/include
-I/w/bld/org/include -I/w/src/llvm.org/include -isystem
/usr/local/include
-stdlib=libc++ -fPIC -fvisibility-inlines-hidden -Werror=date-time
-Werror=unguarded-availability-new -std=c++11 -Wall -W
-Wno-unused-parameter
-Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic
-Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor
-Wdelete-non-virtual-dtor -Wno-comment -Wstring-conversion
-ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual
-Wno-nested-anon-types -O3-UNDEBUG -fno-exceptions -fno-rtti -o
CMakeFiles/findAllSymbols.dir/HeaderMapCollector.cpp.o -c

/w/src/llvm.org/tools/clang/tools/extra/include-fixer/find-all-symbols/HeaderMapCollector.cpp
In file included from

/w/src/llvm.org/tools/clang/tools/extra/include-fixer/find-all-symbols/HeaderMapCollector.cpp:10:
In file included from

/w/src/llvm.org/tools/clang/tools/extra/include-fixer/find-all-symbols/HeaderMapCollector.h:13:
In file included from /w/src/llvm.org/include/llvm/ADT/StringMap.h:17:
In file included from /w/src/llvm.org/include/llvm/ADT/StringRef.h:13:
In file included from /w/src/llvm.org/include/llvm/ADT/STLExtras.h:20:
In file included from /w/src/llvm.org/include/llvm/ADT/Optional.h:22:
In file included from
/w/src/llvm.org/include/llvm/Support/type_traits.h:19:
/usr/include/c++/v1/utility:315:11: error: call to deleted constructor of
'llvm::Regex'
  : first(__p.first),
^ ~
/usr/include/c++/v1/memory:1747:31: note: in instantiation of member
function 'std::__1::pair::pair' requested here
  ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
^
/usr/include/c++/v1/memory:1658:18: note: in instantiation of function
template specialization 'std::__1::allocator >::construct,
const
std::__1::pair &>' requested here
  {__a.construct(__p, _VSTD::forward<_Args>(__args)...);}
   ^
/usr/include/c++/v1/memory:1504:14: note: in instantiation of function
template specialization

'std::__1::allocator_traits > >::__construct,
const std::__1::pair &>' requested here
  {__construct(__has_construct(),
   ^
/usr/include/c++/v1/memory:1620:17: note: in instantiation of function
template specialization

'std::__1::allocator_traits > >::construct,
const std::__1::pair &>' requested here
  construct(__a, _VSTD::__to_raw_pointer(__end2-1),
_VSTD::move_if_noexcept(*--__end1));
  ^
/usr/include/c++/v1/vector:892:21: note: in instantiation of function
template specialization

'std::__1::allocator_traits > >::__construct_backward *>' requested here
  __alloc_traits::__construct_backward(this->__alloc(),
this->__begin_,
this->__end_, __v.__begin_);
  ^
/usr/include/c++/v1/vector:1537:9: note: in instantiation of member
function
'std::__1::vector,
std::__1::allocator >


::__swap_out_circular_buffer' requested here


  __swap_out_circular_buffer(__v);
  ^

/w/src/llvm.org/tools/clang/tools/extra/include-fixer/find-all-symbols/HeaderMapCollector.cpp:19:33:
note: in instantiation of member function
'std::__1::vector,
std::__1::allocator >

::reserve'

requested here

this->RegexHeaderMappingTable.reserve(RegexHeaderMappingTable->size());
  ^
/w/src/llvm.org/include/llvm/Support/Regex.h:49:5: note: 'Regex' has been
explicitly marked deleted here
  Regex(const Regex &) = delete;
  ^
1 error generated.
*** Err

  1   2   >