[PATCH] D49724: [VFS] Cleanups to VFS interfaces.

2018-07-25 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

For the record: this got reverted in https://reviews.llvm.org/rL337850


Repository:
  rL LLVM

https://reviews.llvm.org/D49724



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


[PATCH] D48827: [clang-format ]Extend IncludeCategories regex documentation

2018-07-25 Thread Wim Leflere via Phabricator via cfe-commits
WimLeflere added a comment.

I don't have commit access, can someone else commit this change?


Repository:
  rC Clang

https://reviews.llvm.org/D48827



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


Re: r337850 - Revert "[VFS] Cleanups to VFS interfaces."

2018-07-25 Thread Eric Liu via cfe-commits
Please also include a link to the test failure in the commit message or
this email thread.

On Tue, Jul 24, 2018 at 10:28 PM Jordan Rupprecht via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: rupprecht
> Date: Tue Jul 24 13:28:07 2018
> New Revision: 337850
>
> URL: http://llvm.org/viewvc/llvm-project?rev=337850&view=rev
> Log:
> Revert "[VFS] Cleanups to VFS interfaces."
>
> This reverts commit r337834 due to test failures.
>
> Modified:
> cfe/trunk/include/clang/Basic/VirtualFileSystem.h
> cfe/trunk/lib/Basic/FileManager.cpp
> cfe/trunk/lib/Basic/VirtualFileSystem.cpp
>
> Modified: cfe/trunk/include/clang/Basic/VirtualFileSystem.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/VirtualFileSystem.h?rev=337850&r1=337849&r2=337850&view=diff
>
> ==
> --- cfe/trunk/include/clang/Basic/VirtualFileSystem.h (original)
> +++ cfe/trunk/include/clang/Basic/VirtualFileSystem.h Tue Jul 24 13:28:07
> 2018
> @@ -45,8 +45,7 @@ class MemoryBuffer;
>  namespace clang {
>  namespace vfs {
>
> -/// File information from a \p File::status() operation.
> -/// This is roughly equivalent to a `struct stat` plus a file path.
> +/// The result of a \p status operation.
>  class Status {
>std::string Name;
>llvm::sys::fs::UniqueID UID;
> @@ -67,14 +66,13 @@ public:
>   llvm::sys::TimePoint<> MTime, uint32_t User, uint32_t Group,
>   uint64_t Size, llvm::sys::fs::file_type Type,
>   llvm::sys::fs::perms Perms);
> -  Status(const llvm::sys::fs::file_status &FSStatus, StringRef Name);
>
> -  /// Get a copy of a this Status with a different name.
> -  Status copyWithNewName(StringRef NewName);
> +  /// Get a copy of a Status with a different name.
> +  static Status copyWithNewName(const Status &In, StringRef NewName);
> +  static Status copyWithNewName(const llvm::sys::fs::file_status &In,
> +StringRef NewName);
>
>/// Returns the name that should be used for this file or directory.
> -  /// This is usually the path that the file was opened as, without
> resolving
> -  /// relative paths or symlinks.
>StringRef getName() const { return Name; }
>
>/// @name Status interface from llvm::sys::fs
> @@ -109,16 +107,15 @@ public:
>virtual ~File();
>
>/// Get the status of the file.
> -  /// This may access the filesystem (e.g. `stat()`), or return a cached
> value.
>virtual llvm::ErrorOr status() = 0;
>
> -  /// Get the "real name" of the file, if available.
> -  /// This should be absolute, and typically has symlinks resolved.
> -  ///
> -  /// Only some VFS implementations provide this, and only sometimes.
> -  /// FIXME: these maybe-available semantics are not very useful. It
> would be
> -  /// nice if this was more consistent with FileSystem::getRealPath().
> -  virtual llvm::Optional getRealPath() { return llvm::None; }
> +  /// Get the name of the file
> +  virtual llvm::ErrorOr getName() {
> +if (auto Status = status())
> +  return Status->getName().str();
> +else
> +  return Status.getError();
> +  }
>
>/// Get the contents of the file as a \p MemoryBuffer.
>virtual llvm::ErrorOr>
>
> Modified: cfe/trunk/lib/Basic/FileManager.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/FileManager.cpp?rev=337850&r1=337849&r2=337850&view=diff
>
> ==
> --- cfe/trunk/lib/Basic/FileManager.cpp (original)
> +++ cfe/trunk/lib/Basic/FileManager.cpp Tue Jul 24 13:28:07 2018
> @@ -316,7 +316,7 @@ const FileEntry *FileManager::getFile(St
>UFE.File = std::move(F);
>UFE.IsValid = true;
>if (UFE.File)
> -if (auto RealPathName = UFE.File->getRealPath())
> +if (auto RealPathName = UFE.File->getName())
>UFE.RealPathName = *RealPathName;
>return &UFE;
>  }
>
> Modified: cfe/trunk/lib/Basic/VirtualFileSystem.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/VirtualFileSystem.cpp?rev=337850&r1=337849&r2=337850&view=diff
>
> ==
> --- cfe/trunk/lib/Basic/VirtualFileSystem.cpp (original)
> +++ cfe/trunk/lib/Basic/VirtualFileSystem.cpp Tue Jul 24 13:28:07 2018
> @@ -73,14 +73,16 @@ Status::Status(StringRef Name, UniqueID
>  : Name(Name), UID(UID), MTime(MTime), User(User), Group(Group),
> Size(Size),
>Type(Type), Perms(Perms) {}
>
> -Status::Status(const file_status &In, StringRef NewName)
> -: Status(NewName, In.getUniqueID(), In.getLastModificationTime(),
> - In.getUser(), In.getGroup(), In.getSize(), In.type(),
> - In.permissions()) {}
> -
> -Status Status::copyWithNewName(StringRef NewName) {
> -  return Status(NewName, getUniqueID(), getLastModificationTime(),
> getUser(),
> -getGroup(), getSize(), getType(), getPermissions());
> +Status Status::copyW

[PATCH] D49780: [clangd] Use a sigmoid style function for #usages boost in symbol quality.

2018-07-25 Thread Eric Liu via Phabricator via cfe-commits
ioeric created this revision.
ioeric added a reviewer: ilya-biryukov.
Herald added subscribers: cfe-commits, arphaman, jkorous, MaskRay.

This has a shape to similar logrithm function but grows much slower for
large #usages.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D49780

Files:
  clangd/Quality.cpp
  unittests/clangd/CodeCompleteTests.cpp


Index: unittests/clangd/CodeCompleteTests.cpp
===
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -476,11 +476,12 @@
 }
 
 TEST(CompletionTest, ReferencesAffectRanking) {
-  auto Results = completions("int main() { abs^ }", {ns("absl"), func("abs")});
-  EXPECT_THAT(Results.Completions, HasSubsequence(Named("abs"), 
Named("absl")));
+  auto Results = completions("int main() { abs^ }", {ns("absl"), 
func("absb")});
+  EXPECT_THAT(Results.Completions, HasSubsequence(Named("absb"), 
Named("absl")));
   Results = completions("int main() { abs^ }",
-{withReferences(1, ns("absl")), func("abs")});
-  EXPECT_THAT(Results.Completions, HasSubsequence(Named("absl"), 
Named("abs")));
+{withReferences(1, ns("absl")), func("absb")});
+  EXPECT_THAT(Results.Completions,
+  HasSubsequence(Named("absl"), Named("absb")));
 }
 
 TEST(CompletionTest, GlobalQualified) {
Index: clangd/Quality.cpp
===
--- clangd/Quality.cpp
+++ clangd/Quality.cpp
@@ -190,8 +190,19 @@
 
   // This avoids a sharp gradient for tail symbols, and also neatly avoids the
   // question of whether 0 references means a bad symbol or missing data.
-  if (References >= 10)
-Score *= std::log10(References);
+  if (References >= 10) {
+// Use a sigmoid style boosting function. The shape is similar to logrithm
+// except this flats out better for large numbers (e.g. 2.58 for 1M
+// refererences).
+// The following boosting function is a simplication of:
+//   m = 0.06
+//   f = 12.0
+//   boost = f * sigmoid(m * std::log(References)) - 0.5 * f + 0.59
+// Sample data points: (10, 1.00), (100, 1.41), (1000, 1.82),
+// (10K, 2.21), (100K, 2.58), (1M, 2.94)
+float s = 1.0 / std::pow(References, 0.06);
+Score *= 6.0 * (1 - s) / (1 + s) + 0.59;
+  }
 
   if (Deprecated)
 Score *= 0.1f;


Index: unittests/clangd/CodeCompleteTests.cpp
===
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -476,11 +476,12 @@
 }
 
 TEST(CompletionTest, ReferencesAffectRanking) {
-  auto Results = completions("int main() { abs^ }", {ns("absl"), func("abs")});
-  EXPECT_THAT(Results.Completions, HasSubsequence(Named("abs"), Named("absl")));
+  auto Results = completions("int main() { abs^ }", {ns("absl"), func("absb")});
+  EXPECT_THAT(Results.Completions, HasSubsequence(Named("absb"), Named("absl")));
   Results = completions("int main() { abs^ }",
-{withReferences(1, ns("absl")), func("abs")});
-  EXPECT_THAT(Results.Completions, HasSubsequence(Named("absl"), Named("abs")));
+{withReferences(1, ns("absl")), func("absb")});
+  EXPECT_THAT(Results.Completions,
+  HasSubsequence(Named("absl"), Named("absb")));
 }
 
 TEST(CompletionTest, GlobalQualified) {
Index: clangd/Quality.cpp
===
--- clangd/Quality.cpp
+++ clangd/Quality.cpp
@@ -190,8 +190,19 @@
 
   // This avoids a sharp gradient for tail symbols, and also neatly avoids the
   // question of whether 0 references means a bad symbol or missing data.
-  if (References >= 10)
-Score *= std::log10(References);
+  if (References >= 10) {
+// Use a sigmoid style boosting function. The shape is similar to logrithm
+// except this flats out better for large numbers (e.g. 2.58 for 1M
+// refererences).
+// The following boosting function is a simplication of:
+//   m = 0.06
+//   f = 12.0
+//   boost = f * sigmoid(m * std::log(References)) - 0.5 * f + 0.59
+// Sample data points: (10, 1.00), (100, 1.41), (1000, 1.82),
+// (10K, 2.21), (100K, 2.58), (1M, 2.94)
+float s = 1.0 / std::pow(References, 0.06);
+Score *= 6.0 * (1 - s) / (1 + s) + 0.59;
+  }
 
   if (Deprecated)
 Score *= 0.1f;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D49546: [clangd] Implement query iterators for Dex symbol index

2018-07-25 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 157203.
kbobyrev marked 14 inline comments as done.
kbobyrev added a comment.

Address the last round of comments.

Incoming: documentation overhaul.


https://reviews.llvm.org/D49546

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/index/dex/Iterator.cpp
  clang-tools-extra/clangd/index/dex/Iterator.h
  clang-tools-extra/unittests/clangd/CMakeLists.txt
  clang-tools-extra/unittests/clangd/DexIndexTests.cpp

Index: clang-tools-extra/unittests/clangd/DexIndexTests.cpp
===
--- /dev/null
+++ clang-tools-extra/unittests/clangd/DexIndexTests.cpp
@@ -0,0 +1,191 @@
+//===--- DexIndexTests.cpp *- C++ -*---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "index/dex/Iterator.h"
+#include "llvm/Support/ScopedPrinter.h"
+#include "llvm/Support/raw_ostream.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+#include 
+
+namespace clang {
+namespace clangd {
+namespace dex {
+
+using ::testing::ElementsAre;
+
+TEST(DexIndexIterators, DocumentIterator) {
+  auto DocIterator = create({4, 7, 8, 20, 42, 100});
+
+  EXPECT_EQ(DocIterator->peek(), 4U);
+  EXPECT_EQ(DocIterator->reachedEnd(), false);
+
+  DocIterator->advance();
+  EXPECT_EQ(DocIterator->peek(), 7U);
+  EXPECT_EQ(DocIterator->reachedEnd(), false);
+
+  DocIterator->advanceTo(20);
+  EXPECT_EQ(DocIterator->peek(), 20U);
+  EXPECT_EQ(DocIterator->reachedEnd(), false);
+
+  DocIterator->advanceTo(65);
+  EXPECT_EQ(DocIterator->peek(), 100U);
+  EXPECT_EQ(DocIterator->reachedEnd(), false);
+
+  DocIterator->advanceTo(420);
+  EXPECT_EQ(DocIterator->reachedEnd(), true);
+
+  EXPECT_EQ(llvm::to_string(*DocIterator), "[4, 7, 8, 20, 42, 100]");
+}
+
+TEST(DexIndexIterators, AndIterator) {
+  const PostingList EmptyList;
+  const PostingList FirstList = {0, 5, 7, 10, 42, 320, 9000};
+  const PostingList SecondList = {0, 4, 7, 10, 30, 60, 320, 9000};
+  const PostingList ThirdList = {1, 4, 7, 11, 30, 60, 320, 9000};
+
+  auto And = createAnd({create(EmptyList)});
+
+  EXPECT_EQ(llvm::to_string(*And), "(& [])");
+
+  And = createAnd({create(EmptyList), create(FirstList)});
+
+  EXPECT_EQ(llvm::to_string(*And), "(& [] [0, 5, 7, 10, 42, 320, 9000])");
+
+  And = createAnd({create(FirstList), create(SecondList)});
+
+  EXPECT_EQ(And->reachedEnd(), false);
+  EXPECT_THAT(consume(*And), ElementsAre(0U, 7U, 10U, 320U, 9000U));
+
+  EXPECT_EQ(
+  llvm::to_string(*And),
+  "(& [0, 5, 7, 10, 42, 320, 9000] [0, 4, 7, 10, 30, 60, 320, 9000])");
+
+  And = createAnd({create(SecondList), create(FirstList)});
+
+  And->advanceTo(0);
+  EXPECT_EQ(And->peek(), 0U);
+  And->advanceTo(5);
+  EXPECT_EQ(And->peek(), 7U);
+  And->advanceTo(10);
+  EXPECT_EQ(And->peek(), 10U);
+  And->advanceTo(42);
+  EXPECT_EQ(And->peek(), 320U);
+  And->advanceTo(8999);
+  EXPECT_EQ(And->peek(), 9000U);
+  And->advanceTo(9001);
+
+  And = createAnd({create(FirstList), create(SecondList), create(ThirdList)});
+  EXPECT_EQ(And->peek(), 7U);
+  And->advanceTo(300);
+  EXPECT_EQ(And->peek(), 320U);
+  And->advanceTo(10);
+
+  EXPECT_EQ(And->reachedEnd(), true);
+}
+
+TEST(DexIndexIterators, OrIterator) {
+  const PostingList EmptyList;
+  const PostingList FirstList = {0, 5, 7, 10, 42, 320, 9000};
+  const PostingList SecondList = {0, 4, 7, 10, 30, 60, 320, 9000};
+  const PostingList ThirdList = {1, 4, 7, 11, 30, 60, 320, 9000};
+
+  auto Or = createOr({create(EmptyList)});
+
+  EXPECT_EQ(Or->reachedEnd(), true);
+
+  Or = createOr({create(FirstList), create(EmptyList)});
+
+  EXPECT_EQ(Or->reachedEnd(), false);
+  EXPECT_EQ(Or->peek(), 0U);
+  Or->advance();
+  EXPECT_EQ(Or->peek(), 5U);
+  Or->advance();
+  EXPECT_EQ(Or->peek(), 7U);
+  Or->advance();
+  EXPECT_EQ(Or->peek(), 10U);
+  Or->advance();
+  EXPECT_EQ(Or->peek(), 42U);
+  Or->advanceTo(42);
+  EXPECT_EQ(Or->peek(), 42U);
+  Or->advanceTo(300);
+  EXPECT_EQ(Or->peek(), 320U);
+  Or->advanceTo(9000);
+  EXPECT_EQ(Or->peek(), 9000U);
+  Or->advanceTo(9001);
+
+  Or = createOr({create(FirstList), create(SecondList), create(ThirdList)});
+
+  EXPECT_EQ(Or->reachedEnd(), false);
+  EXPECT_EQ(Or->peek(), 0U);
+
+  Or->advance();
+  EXPECT_EQ(Or->peek(), 1U);
+
+  Or->advance();
+  EXPECT_EQ(Or->peek(), 4U);
+
+  Or->advanceTo(7);
+
+  Or->advanceTo(59);
+  EXPECT_EQ(Or->peek(), 60U);
+
+  Or->advanceTo(9001);
+}
+
+// FIXME(kbobyrev): The testcase below is similar to what is expected in real
+// queries. It should be updated once new iterators (such as boosting, limiting,
+// etc iterators) appear. However, it is not exhaustive and it would be
+// beneficial to implement automatic generation of query trees for more
+// comprehensive testing.

[PATCH] D49546: [clangd] Implement query iterators for Dex symbol index

2018-07-25 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev added inline comments.



Comment at: clang-tools-extra/clangd/index/dex/Iterator.cpp:181
+const auto HighestID = peek();
+DocID ChildrenToAdvance = 0;
+while ((ChildrenToAdvance++ < Children.size()) && !reachedEnd() &&

sammccall wrote:
> I can't follow this one - why is the outer loop needed?
> 
> (It looks like you're using DocID as integer again, but I can't tell why the 
> variable is needed at all)
An artifact from min-heap implementation.


https://reviews.llvm.org/D49546



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


[PATCH] D49770: [ARM64] [Windows] Follow MS X86_64 C++ ABI when passing structs

2018-07-25 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo accepted this revision.
mstorsjo added a comment.
This revision is now accepted and ready to land.

This seems to be another case of all other arches being the same while x86_32 
is different. The thumb case (with same actual code as x86_64) has a comment 
about a corner case where this doesn't match MSVC exactly, does that also apply 
here?


Repository:
  rC Clang

https://reviews.llvm.org/D49770



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


[PATCH] D49780: [clangd] Use a sigmoid style function for #usages boost in symbol quality.

2018-07-25 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

Overall LG. I'm sure it's an improvement overall, just wanted to get some 
clarifying comments and references, if that's possible.

NIT: a typo in the commit message
s/logrithm/logarithm




Comment at: clangd/Quality.cpp:200
+//   f = 12.0
+//   boost = f * sigmoid(m * std::log(References)) - 0.5 * f + 0.59
+// Sample data points: (10, 1.00), (100, 1.41), (1000, 1.82),

Made add references or intuition on why this boosting function is good?
Also on why can't we use the original boost function and need to simplify it?



Comment at: clangd/Quality.cpp:203
+// (10K, 2.21), (100K, 2.58), (1M, 2.94)
+float s = 1.0 / std::pow(References, 0.06);
+Score *= 6.0 * (1 - s) / (1 + s) + 0.59;

Any reason to not use `std::pow(References, -0.06)` instead?
(not a suggestion to actually change the code, just wondering if there are any 
reasons (apart from personal preferences) to prefer one over the other)


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D49780



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


[PATCH] D49546: [clangd] Implement query iterators for Dex symbol index

2018-07-25 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 157206.
kbobyrev added a comment.

Slightly refactored the code, improved documentation. This patch is ready for 
review.


https://reviews.llvm.org/D49546

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/index/dex/Iterator.cpp
  clang-tools-extra/clangd/index/dex/Iterator.h
  clang-tools-extra/unittests/clangd/CMakeLists.txt
  clang-tools-extra/unittests/clangd/DexIndexTests.cpp

Index: clang-tools-extra/unittests/clangd/DexIndexTests.cpp
===
--- /dev/null
+++ clang-tools-extra/unittests/clangd/DexIndexTests.cpp
@@ -0,0 +1,191 @@
+//===--- DexIndexTests.cpp *- C++ -*---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "index/dex/Iterator.h"
+#include "llvm/Support/ScopedPrinter.h"
+#include "llvm/Support/raw_ostream.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+#include 
+
+namespace clang {
+namespace clangd {
+namespace dex {
+
+using ::testing::ElementsAre;
+
+TEST(DexIndexIterators, DocumentIterator) {
+  auto DocIterator = create({4, 7, 8, 20, 42, 100});
+
+  EXPECT_EQ(DocIterator->peek(), 4U);
+  EXPECT_EQ(DocIterator->reachedEnd(), false);
+
+  DocIterator->advance();
+  EXPECT_EQ(DocIterator->peek(), 7U);
+  EXPECT_EQ(DocIterator->reachedEnd(), false);
+
+  DocIterator->advanceTo(20);
+  EXPECT_EQ(DocIterator->peek(), 20U);
+  EXPECT_EQ(DocIterator->reachedEnd(), false);
+
+  DocIterator->advanceTo(65);
+  EXPECT_EQ(DocIterator->peek(), 100U);
+  EXPECT_EQ(DocIterator->reachedEnd(), false);
+
+  DocIterator->advanceTo(420);
+  EXPECT_EQ(DocIterator->reachedEnd(), true);
+
+  EXPECT_EQ(llvm::to_string(*DocIterator), "[4, 7, 8, 20, 42, 100]");
+}
+
+TEST(DexIndexIterators, AndIterator) {
+  const PostingList EmptyList;
+  const PostingList FirstList = {0, 5, 7, 10, 42, 320, 9000};
+  const PostingList SecondList = {0, 4, 7, 10, 30, 60, 320, 9000};
+  const PostingList ThirdList = {1, 4, 7, 11, 30, 60, 320, 9000};
+
+  auto And = createAnd({create(EmptyList)});
+
+  EXPECT_EQ(llvm::to_string(*And), "(& [])");
+
+  And = createAnd({create(EmptyList), create(FirstList)});
+
+  EXPECT_EQ(llvm::to_string(*And), "(& [] [0, 5, 7, 10, 42, 320, 9000])");
+
+  And = createAnd({create(FirstList), create(SecondList)});
+
+  EXPECT_EQ(And->reachedEnd(), false);
+  EXPECT_THAT(consume(*And), ElementsAre(0U, 7U, 10U, 320U, 9000U));
+
+  EXPECT_EQ(
+  llvm::to_string(*And),
+  "(& [0, 5, 7, 10, 42, 320, 9000] [0, 4, 7, 10, 30, 60, 320, 9000])");
+
+  And = createAnd({create(SecondList), create(FirstList)});
+
+  And->advanceTo(0);
+  EXPECT_EQ(And->peek(), 0U);
+  And->advanceTo(5);
+  EXPECT_EQ(And->peek(), 7U);
+  And->advanceTo(10);
+  EXPECT_EQ(And->peek(), 10U);
+  And->advanceTo(42);
+  EXPECT_EQ(And->peek(), 320U);
+  And->advanceTo(8999);
+  EXPECT_EQ(And->peek(), 9000U);
+  And->advanceTo(9001);
+
+  And = createAnd({create(FirstList), create(SecondList), create(ThirdList)});
+  EXPECT_EQ(And->peek(), 7U);
+  And->advanceTo(300);
+  EXPECT_EQ(And->peek(), 320U);
+  And->advanceTo(10);
+
+  EXPECT_EQ(And->reachedEnd(), true);
+}
+
+TEST(DexIndexIterators, OrIterator) {
+  const PostingList EmptyList;
+  const PostingList FirstList = {0, 5, 7, 10, 42, 320, 9000};
+  const PostingList SecondList = {0, 4, 7, 10, 30, 60, 320, 9000};
+  const PostingList ThirdList = {1, 4, 7, 11, 30, 60, 320, 9000};
+
+  auto Or = createOr({create(EmptyList)});
+
+  EXPECT_EQ(Or->reachedEnd(), true);
+
+  Or = createOr({create(FirstList), create(EmptyList)});
+
+  EXPECT_EQ(Or->reachedEnd(), false);
+  EXPECT_EQ(Or->peek(), 0U);
+  Or->advance();
+  EXPECT_EQ(Or->peek(), 5U);
+  Or->advance();
+  EXPECT_EQ(Or->peek(), 7U);
+  Or->advance();
+  EXPECT_EQ(Or->peek(), 10U);
+  Or->advance();
+  EXPECT_EQ(Or->peek(), 42U);
+  Or->advanceTo(42);
+  EXPECT_EQ(Or->peek(), 42U);
+  Or->advanceTo(300);
+  EXPECT_EQ(Or->peek(), 320U);
+  Or->advanceTo(9000);
+  EXPECT_EQ(Or->peek(), 9000U);
+  Or->advanceTo(9001);
+
+  Or = createOr({create(FirstList), create(SecondList), create(ThirdList)});
+
+  EXPECT_EQ(Or->reachedEnd(), false);
+  EXPECT_EQ(Or->peek(), 0U);
+
+  Or->advance();
+  EXPECT_EQ(Or->peek(), 1U);
+
+  Or->advance();
+  EXPECT_EQ(Or->peek(), 4U);
+
+  Or->advanceTo(7);
+
+  Or->advanceTo(59);
+  EXPECT_EQ(Or->peek(), 60U);
+
+  Or->advanceTo(9001);
+}
+
+// FIXME(kbobyrev): The testcase below is similar to what is expected in real
+// queries. It should be updated once new iterators (such as boosting, limiting,
+// etc iterators) appear. However, it is not exhaustive and it would be
+// beneficial to implement automatic generation of query trees for more
+// comprehensive testing.
+TEST(DexIndexIterators, Que

[PATCH] D49780: [clangd] Use a sigmoid style function for #usages boost in symbol quality.

2018-07-25 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 157207.
ioeric marked 2 inline comments as done.
ioeric added a comment.

Addressed review comments.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D49780

Files:
  clangd/Quality.cpp
  unittests/clangd/CodeCompleteTests.cpp


Index: unittests/clangd/CodeCompleteTests.cpp
===
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -476,11 +476,12 @@
 }
 
 TEST(CompletionTest, ReferencesAffectRanking) {
-  auto Results = completions("int main() { abs^ }", {ns("absl"), func("abs")});
-  EXPECT_THAT(Results.Completions, HasSubsequence(Named("abs"), 
Named("absl")));
+  auto Results = completions("int main() { abs^ }", {ns("absl"), 
func("absb")});
+  EXPECT_THAT(Results.Completions, HasSubsequence(Named("absb"), 
Named("absl")));
   Results = completions("int main() { abs^ }",
-{withReferences(1, ns("absl")), func("abs")});
-  EXPECT_THAT(Results.Completions, HasSubsequence(Named("absl"), 
Named("abs")));
+{withReferences(1, ns("absl")), func("absb")});
+  EXPECT_THAT(Results.Completions,
+  HasSubsequence(Named("absl"), Named("absb")));
 }
 
 TEST(CompletionTest, GlobalQualified) {
Index: clangd/Quality.cpp
===
--- clangd/Quality.cpp
+++ clangd/Quality.cpp
@@ -190,8 +190,18 @@
 
   // This avoids a sharp gradient for tail symbols, and also neatly avoids the
   // question of whether 0 references means a bad symbol or missing data.
-  if (References >= 10)
-Score *= std::log10(References);
+  if (References >= 10) {
+// Use a sigmoid style boosting function, which flats out better for large
+// numbers (e.g. 2.58 for 1M refererences).
+// The following boosting function is equivalent to:
+//   m = 0.06
+//   f = 12.0
+//   boost = f * sigmoid(m * std::log(References)) - 0.5 * f + 0.59
+// Sample data points: (10, 1.00), (100, 1.41), (1000, 1.82),
+// (10K, 2.21), (100K, 2.58), (1M, 2.94)
+float s = std::pow(References, -0.06);
+Score *= 6.0 * (1 - s) / (1 + s) + 0.59;
+  }
 
   if (Deprecated)
 Score *= 0.1f;


Index: unittests/clangd/CodeCompleteTests.cpp
===
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -476,11 +476,12 @@
 }
 
 TEST(CompletionTest, ReferencesAffectRanking) {
-  auto Results = completions("int main() { abs^ }", {ns("absl"), func("abs")});
-  EXPECT_THAT(Results.Completions, HasSubsequence(Named("abs"), Named("absl")));
+  auto Results = completions("int main() { abs^ }", {ns("absl"), func("absb")});
+  EXPECT_THAT(Results.Completions, HasSubsequence(Named("absb"), Named("absl")));
   Results = completions("int main() { abs^ }",
-{withReferences(1, ns("absl")), func("abs")});
-  EXPECT_THAT(Results.Completions, HasSubsequence(Named("absl"), Named("abs")));
+{withReferences(1, ns("absl")), func("absb")});
+  EXPECT_THAT(Results.Completions,
+  HasSubsequence(Named("absl"), Named("absb")));
 }
 
 TEST(CompletionTest, GlobalQualified) {
Index: clangd/Quality.cpp
===
--- clangd/Quality.cpp
+++ clangd/Quality.cpp
@@ -190,8 +190,18 @@
 
   // This avoids a sharp gradient for tail symbols, and also neatly avoids the
   // question of whether 0 references means a bad symbol or missing data.
-  if (References >= 10)
-Score *= std::log10(References);
+  if (References >= 10) {
+// Use a sigmoid style boosting function, which flats out better for large
+// numbers (e.g. 2.58 for 1M refererences).
+// The following boosting function is equivalent to:
+//   m = 0.06
+//   f = 12.0
+//   boost = f * sigmoid(m * std::log(References)) - 0.5 * f + 0.59
+// Sample data points: (10, 1.00), (100, 1.41), (1000, 1.82),
+// (10K, 2.21), (100K, 2.58), (1M, 2.94)
+float s = std::pow(References, -0.06);
+Score *= 6.0 * (1 - s) / (1 + s) + 0.59;
+  }
 
   if (Deprecated)
 Score *= 0.1f;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D49780: [clangd] Use a sigmoid style function for #usages boost in symbol quality.

2018-07-25 Thread Eric Liu via Phabricator via cfe-commits
ioeric added inline comments.



Comment at: clangd/Quality.cpp:200
+//   f = 12.0
+//   boost = f * sigmoid(m * std::log(References)) - 0.5 * f + 0.59
+// Sample data points: (10, 1.00), (100, 1.41), (1000, 1.82),

ilya-biryukov wrote:
> Made add references or intuition on why this boosting function is good?
> Also on why can't we use the original boost function and need to simplify it?
Turned out "simplification" might be the wrong word. Improved the comment a bit.



Comment at: clangd/Quality.cpp:203
+// (10K, 2.21), (100K, 2.58), (1M, 2.94)
+float s = 1.0 / std::pow(References, 0.06);
+Score *= 6.0 * (1 - s) / (1 + s) + 0.59;

ilya-biryukov wrote:
> Any reason to not use `std::pow(References, -0.06)` instead?
> (not a suggestion to actually change the code, just wondering if there are 
> any reasons (apart from personal preferences) to prefer one over the other)
Nope, no particular reason. Positive exponent looks a bit nicer in formula, but 
I think it's fine here. Switched to `std::pow(References, -0.06)`.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D49780



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


[PATCH] D49546: [clangd] Proof-of-concept query iterators for Dex symbol index

2018-07-25 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 157208.
kbobyrev retitled this revision from "[clangd] Implement query iterators for 
Dex symbol index" to "[clangd] Proof-of-concept query iterators for Dex symbol 
index".
kbobyrev edited the summary of this revision.
kbobyrev added a comment.

Choose better wording in a couple of places.


https://reviews.llvm.org/D49546

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/index/dex/Iterator.cpp
  clang-tools-extra/clangd/index/dex/Iterator.h
  clang-tools-extra/unittests/clangd/CMakeLists.txt
  clang-tools-extra/unittests/clangd/DexIndexTests.cpp

Index: clang-tools-extra/unittests/clangd/DexIndexTests.cpp
===
--- /dev/null
+++ clang-tools-extra/unittests/clangd/DexIndexTests.cpp
@@ -0,0 +1,191 @@
+//===--- DexIndexTests.cpp *- C++ -*---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "index/dex/Iterator.h"
+#include "llvm/Support/ScopedPrinter.h"
+#include "llvm/Support/raw_ostream.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+#include 
+
+namespace clang {
+namespace clangd {
+namespace dex {
+
+using ::testing::ElementsAre;
+
+TEST(DexIndexIterators, DocumentIterator) {
+  auto DocIterator = create({4, 7, 8, 20, 42, 100});
+
+  EXPECT_EQ(DocIterator->peek(), 4U);
+  EXPECT_EQ(DocIterator->reachedEnd(), false);
+
+  DocIterator->advance();
+  EXPECT_EQ(DocIterator->peek(), 7U);
+  EXPECT_EQ(DocIterator->reachedEnd(), false);
+
+  DocIterator->advanceTo(20);
+  EXPECT_EQ(DocIterator->peek(), 20U);
+  EXPECT_EQ(DocIterator->reachedEnd(), false);
+
+  DocIterator->advanceTo(65);
+  EXPECT_EQ(DocIterator->peek(), 100U);
+  EXPECT_EQ(DocIterator->reachedEnd(), false);
+
+  DocIterator->advanceTo(420);
+  EXPECT_EQ(DocIterator->reachedEnd(), true);
+
+  EXPECT_EQ(llvm::to_string(*DocIterator), "[4, 7, 8, 20, 42, 100]");
+}
+
+TEST(DexIndexIterators, AndIterator) {
+  const PostingList EmptyList;
+  const PostingList FirstList = {0, 5, 7, 10, 42, 320, 9000};
+  const PostingList SecondList = {0, 4, 7, 10, 30, 60, 320, 9000};
+  const PostingList ThirdList = {1, 4, 7, 11, 30, 60, 320, 9000};
+
+  auto And = createAnd({create(EmptyList)});
+
+  EXPECT_EQ(llvm::to_string(*And), "(& [])");
+
+  And = createAnd({create(EmptyList), create(FirstList)});
+
+  EXPECT_EQ(llvm::to_string(*And), "(& [] [0, 5, 7, 10, 42, 320, 9000])");
+
+  And = createAnd({create(FirstList), create(SecondList)});
+
+  EXPECT_EQ(And->reachedEnd(), false);
+  EXPECT_THAT(consume(*And), ElementsAre(0U, 7U, 10U, 320U, 9000U));
+
+  EXPECT_EQ(
+  llvm::to_string(*And),
+  "(& [0, 5, 7, 10, 42, 320, 9000] [0, 4, 7, 10, 30, 60, 320, 9000])");
+
+  And = createAnd({create(SecondList), create(FirstList)});
+
+  And->advanceTo(0);
+  EXPECT_EQ(And->peek(), 0U);
+  And->advanceTo(5);
+  EXPECT_EQ(And->peek(), 7U);
+  And->advanceTo(10);
+  EXPECT_EQ(And->peek(), 10U);
+  And->advanceTo(42);
+  EXPECT_EQ(And->peek(), 320U);
+  And->advanceTo(8999);
+  EXPECT_EQ(And->peek(), 9000U);
+  And->advanceTo(9001);
+
+  And = createAnd({create(FirstList), create(SecondList), create(ThirdList)});
+  EXPECT_EQ(And->peek(), 7U);
+  And->advanceTo(300);
+  EXPECT_EQ(And->peek(), 320U);
+  And->advanceTo(10);
+
+  EXPECT_EQ(And->reachedEnd(), true);
+}
+
+TEST(DexIndexIterators, OrIterator) {
+  const PostingList EmptyList;
+  const PostingList FirstList = {0, 5, 7, 10, 42, 320, 9000};
+  const PostingList SecondList = {0, 4, 7, 10, 30, 60, 320, 9000};
+  const PostingList ThirdList = {1, 4, 7, 11, 30, 60, 320, 9000};
+
+  auto Or = createOr({create(EmptyList)});
+
+  EXPECT_EQ(Or->reachedEnd(), true);
+
+  Or = createOr({create(FirstList), create(EmptyList)});
+
+  EXPECT_EQ(Or->reachedEnd(), false);
+  EXPECT_EQ(Or->peek(), 0U);
+  Or->advance();
+  EXPECT_EQ(Or->peek(), 5U);
+  Or->advance();
+  EXPECT_EQ(Or->peek(), 7U);
+  Or->advance();
+  EXPECT_EQ(Or->peek(), 10U);
+  Or->advance();
+  EXPECT_EQ(Or->peek(), 42U);
+  Or->advanceTo(42);
+  EXPECT_EQ(Or->peek(), 42U);
+  Or->advanceTo(300);
+  EXPECT_EQ(Or->peek(), 320U);
+  Or->advanceTo(9000);
+  EXPECT_EQ(Or->peek(), 9000U);
+  Or->advanceTo(9001);
+
+  Or = createOr({create(FirstList), create(SecondList), create(ThirdList)});
+
+  EXPECT_EQ(Or->reachedEnd(), false);
+  EXPECT_EQ(Or->peek(), 0U);
+
+  Or->advance();
+  EXPECT_EQ(Or->peek(), 1U);
+
+  Or->advance();
+  EXPECT_EQ(Or->peek(), 4U);
+
+  Or->advanceTo(7);
+
+  Or->advanceTo(59);
+  EXPECT_EQ(Or->peek(), 60U);
+
+  Or->advanceTo(9001);
+}
+
+// FIXME(kbobyrev): The testcase below is similar to what is expected in real
+// queries. It should be updated once new iterators (such as boosting, limiting,
+// etc iterators) appear. Howe

[PATCH] D49722: [CStringSyntaxChecker] Check strlcat sizeof check

2018-07-25 Thread David CARLIER via Phabricator via cfe-commits
devnexen added a comment.

Hopefully will try to push it before the freeze just announced, that s my last 
change in this area (except potential fixes) :)


Repository:
  rC Clang

https://reviews.llvm.org/D49722



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


[libcxx] r337897 - Fix typos, spelling, and grammar in the FileTimeType design docs.

2018-07-25 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Wed Jul 25 03:17:04 2018
New Revision: 337897

URL: http://llvm.org/viewvc/llvm-project?rev=337897&view=rev
Log:
Fix typos, spelling, and grammar in the FileTimeType design docs.

I'm sure I'll discover more mistakes as I go on...

Modified:
libcxx/trunk/docs/DesignDocs/FileTimeType.rst

Modified: libcxx/trunk/docs/DesignDocs/FileTimeType.rst
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/docs/DesignDocs/FileTimeType.rst?rev=337897&r1=337896&r2=337897&view=diff
==
--- libcxx/trunk/docs/DesignDocs/FileTimeType.rst (original)
+++ libcxx/trunk/docs/DesignDocs/FileTimeType.rst Wed Jul 25 03:17:04 2018
@@ -83,14 +83,14 @@ To get the same range, we would need to
 to come close to having the same range.
 
 This begs the question, is the range problem "really a problem"? Sane usages
-of file time stamps shouldn't exceed +/- 300, so should we care to support it?
+of file time stamps shouldn't exceed +/- 300 years, so should we care to 
support it?
 
 I believe the answer is yes. We're not designing the filesystem time API, we're
 providing glorified C++ wrappers for it. If the underlying API supports
 a value, then we should too. Our wrappers should not place artificial 
restrictions
 on users that are not present in the underlying filesystem.
 
-Additionally, having a smaller range that the underlying filesystem forces the
+Having a smaller range that the underlying filesystem forces the
 implementation to report ``value_too_large`` errors when it encounters a time
 point that it can't represent. This can cause the call to ``last_write_time``
 to throw in cases where the user was confident the call should succeed. (See 
below)
@@ -135,7 +135,7 @@ Having a Smaller Resolution than ``times
 -
 
 As mentioned in the previous section, one way to solve the range problem
-is by reducing the resolution, and matching the range of ``timespec`` using a
+is by reducing the resolution. But matching the range of ``timespec`` using a
 64 bit representation requires limiting the resolution to seconds.
 
 So we might ask: Do users "need" nanosecond precision? Is seconds not good 
enough?
@@ -148,16 +148,16 @@ representation, not design it.
 Having a Larger Range than ``timespec``
 
 
-We also should consider the opposite problem of having ``file_time_type``
-be able to represent a larger range than that of ``timespec``. At least in
+We should also consider the opposite problem of having a ``file_time_type``
+that is able to represent a larger range than ``timespec``. At least in
 this case ``last_write_time`` can be used to get and set all possible values
 supported by the underlying filesystem; meaning ``last_write_time(p)`` will
-never throw a overflow error.
+never throw a overflow error when retrieving a value.
 
-However, this introduces a new problem, where users are allowed to create time
-points beyond what the filesystem can represent. Two particular values are
-``file_time_type::min()`` and ``file_time_type::max()``. As such the following
-code would throw:
+However, this introduces a new problem, where users are allowed to attempt to
+create a time point beyond what the filesystem can represent. Two particular
+values which cause this are ``file_time_type::min()`` and
+``file_time_type::max()``. As a result, the following code would throw:
 
 .. code-block:: cpp
 
@@ -167,8 +167,8 @@ code would throw:
   }
 
 Apart from cases explicitly using ``min`` and ``max``, I don't see users taking
-a valid time point, adding a couple hundred billions of years to it in error,
-and then trying to update a files write time with that value very often.
+a valid time point, adding a couple hundred billions of years in error,
+and then trying to update a file's write time to that value very often.
 
 Compared to having a smaller range, this problem seems preferable. At least
 now we can represent any time point the filesystem can, so users won't be 
forced
@@ -190,10 +190,10 @@ than 64 bits. The possible solutions inc
 arithmetic type. All three will solve allow us to, at minimum, match the range
 and resolution, and the last one might even allow us to match them exactly.
 
-But when considering these potential solutions, we need to consider more than
-just the values they can represent. We need to consider the effect they will 
have
-on users and their code. For example, each of them breaks the following code
-in some way:
+But when considering these potential solutions we need to consider more than
+just the values they can represent. We need to consider the effects they will
+have on users and their code. For example, each of them breaks the following
+code in some way:
 
 .. code-block:: cpp
 
@@ -234,12 +234,12 @@ in some way:
 
 
 Each of the above examples would require a user to adjust their filesystem code
-to the particular eccentricitie

[PATCH] D48098: clang-format-diff: Make it work with python3 too

2018-07-25 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added a comment.

MarcoFalke: do you need someone to submit this for you?


https://reviews.llvm.org/D48098



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


r337898 - [ASTImporter] Add support for import of CXXInheritedCtorInitExpr.

2018-07-25 Thread Balazs Keri via cfe-commits
Author: balazske
Date: Wed Jul 25 03:21:06 2018
New Revision: 337898

URL: http://llvm.org/viewvc/llvm-project?rev=337898&view=rev
Log:
[ASTImporter] Add support for import of CXXInheritedCtorInitExpr.

Reviewers: a.sidorin, martong

Reviewed By: martong

Subscribers: rnkovacs, a_sidorin, martong, cfe-commits

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

Added:
cfe/trunk/test/Import/inherited-ctor-init-expr/
cfe/trunk/test/Import/inherited-ctor-init-expr/Inputs/
cfe/trunk/test/Import/inherited-ctor-init-expr/Inputs/A.cpp
cfe/trunk/test/Import/inherited-ctor-init-expr/test.cpp
Modified:
cfe/trunk/lib/AST/ASTImporter.cpp

Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=337898&r1=337897&r2=337898&view=diff
==
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Wed Jul 25 03:21:06 2018
@@ -460,6 +460,7 @@ namespace clang {
 Expr *VisitLambdaExpr(LambdaExpr *LE);
 Expr *VisitInitListExpr(InitListExpr *E);
 Expr *VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E);
+Expr *VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E);
 Expr *VisitArrayInitLoopExpr(ArrayInitLoopExpr *E);
 Expr *VisitArrayInitIndexExpr(ArrayInitIndexExpr *E);
 Expr *VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E);
@@ -6772,6 +6773,22 @@ Expr *ASTNodeImporter::VisitCXXStdInitia
   return new (Importer.getToContext()) CXXStdInitializerListExpr(T, SE);
 }
 
+Expr *ASTNodeImporter::VisitCXXInheritedCtorInitExpr(
+CXXInheritedCtorInitExpr *E) {
+  QualType T = Importer.Import(E->getType());
+  if (T.isNull())
+return nullptr;
+
+  auto *Ctor = cast_or_null(Importer.Import(
+  E->getConstructor()));
+  if (!Ctor)
+return nullptr;
+
+  return new (Importer.getToContext()) CXXInheritedCtorInitExpr(
+  Importer.Import(E->getLocation()), T, Ctor,
+  E->constructsVBase(), E->inheritedFromVBase());
+}
+
 Expr *ASTNodeImporter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) {
   QualType ToType = Importer.Import(E->getType());
   if (ToType.isNull())

Added: cfe/trunk/test/Import/inherited-ctor-init-expr/Inputs/A.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Import/inherited-ctor-init-expr/Inputs/A.cpp?rev=337898&view=auto
==
--- cfe/trunk/test/Import/inherited-ctor-init-expr/Inputs/A.cpp (added)
+++ cfe/trunk/test/Import/inherited-ctor-init-expr/Inputs/A.cpp Wed Jul 25 
03:21:06 2018
@@ -0,0 +1,11 @@
+class A {
+public:
+  A(int a) : a(a) {}
+  int a;
+};
+class B : public A {
+  using A::A;
+};
+class C : public B {
+  C() : B(1) {}
+};

Added: cfe/trunk/test/Import/inherited-ctor-init-expr/test.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Import/inherited-ctor-init-expr/test.cpp?rev=337898&view=auto
==
--- cfe/trunk/test/Import/inherited-ctor-init-expr/test.cpp (added)
+++ cfe/trunk/test/Import/inherited-ctor-init-expr/test.cpp Wed Jul 25 03:21:06 
2018
@@ -0,0 +1,6 @@
+// RUN: clang-import-test -dump-ast -expression=%s -import=%S/Inputs/A.cpp | 
FileCheck %s
+// CHECK: | | | `-CXXInheritedCtorInitExpr
+
+void foo() {
+  C c;
+}


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


[PATCH] D49293: [ASTImporter] Add support for import of CXXInheritedCtorInitExpr.

2018-07-25 Thread Balázs Kéri via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC337898: [ASTImporter] Add support for import of 
CXXInheritedCtorInitExpr. (authored by balazske, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D49293?vs=155838&id=157212#toc

Repository:
  rC Clang

https://reviews.llvm.org/D49293

Files:
  lib/AST/ASTImporter.cpp
  test/Import/inherited-ctor-init-expr/Inputs/A.cpp
  test/Import/inherited-ctor-init-expr/test.cpp


Index: test/Import/inherited-ctor-init-expr/Inputs/A.cpp
===
--- test/Import/inherited-ctor-init-expr/Inputs/A.cpp
+++ test/Import/inherited-ctor-init-expr/Inputs/A.cpp
@@ -0,0 +1,11 @@
+class A {
+public:
+  A(int a) : a(a) {}
+  int a;
+};
+class B : public A {
+  using A::A;
+};
+class C : public B {
+  C() : B(1) {}
+};
Index: test/Import/inherited-ctor-init-expr/test.cpp
===
--- test/Import/inherited-ctor-init-expr/test.cpp
+++ test/Import/inherited-ctor-init-expr/test.cpp
@@ -0,0 +1,6 @@
+// RUN: clang-import-test -dump-ast -expression=%s -import=%S/Inputs/A.cpp | 
FileCheck %s
+// CHECK: | | | `-CXXInheritedCtorInitExpr
+
+void foo() {
+  C c;
+}
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -460,6 +460,7 @@
 Expr *VisitLambdaExpr(LambdaExpr *LE);
 Expr *VisitInitListExpr(InitListExpr *E);
 Expr *VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E);
+Expr *VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E);
 Expr *VisitArrayInitLoopExpr(ArrayInitLoopExpr *E);
 Expr *VisitArrayInitIndexExpr(ArrayInitIndexExpr *E);
 Expr *VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E);
@@ -6772,6 +6773,22 @@
   return new (Importer.getToContext()) CXXStdInitializerListExpr(T, SE);
 }
 
+Expr *ASTNodeImporter::VisitCXXInheritedCtorInitExpr(
+CXXInheritedCtorInitExpr *E) {
+  QualType T = Importer.Import(E->getType());
+  if (T.isNull())
+return nullptr;
+
+  auto *Ctor = cast_or_null(Importer.Import(
+  E->getConstructor()));
+  if (!Ctor)
+return nullptr;
+
+  return new (Importer.getToContext()) CXXInheritedCtorInitExpr(
+  Importer.Import(E->getLocation()), T, Ctor,
+  E->constructsVBase(), E->inheritedFromVBase());
+}
+
 Expr *ASTNodeImporter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) {
   QualType ToType = Importer.Import(E->getType());
   if (ToType.isNull())


Index: test/Import/inherited-ctor-init-expr/Inputs/A.cpp
===
--- test/Import/inherited-ctor-init-expr/Inputs/A.cpp
+++ test/Import/inherited-ctor-init-expr/Inputs/A.cpp
@@ -0,0 +1,11 @@
+class A {
+public:
+  A(int a) : a(a) {}
+  int a;
+};
+class B : public A {
+  using A::A;
+};
+class C : public B {
+  C() : B(1) {}
+};
Index: test/Import/inherited-ctor-init-expr/test.cpp
===
--- test/Import/inherited-ctor-init-expr/test.cpp
+++ test/Import/inherited-ctor-init-expr/test.cpp
@@ -0,0 +1,6 @@
+// RUN: clang-import-test -dump-ast -expression=%s -import=%S/Inputs/A.cpp | FileCheck %s
+// CHECK: | | | `-CXXInheritedCtorInitExpr
+
+void foo() {
+  C c;
+}
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -460,6 +460,7 @@
 Expr *VisitLambdaExpr(LambdaExpr *LE);
 Expr *VisitInitListExpr(InitListExpr *E);
 Expr *VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E);
+Expr *VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E);
 Expr *VisitArrayInitLoopExpr(ArrayInitLoopExpr *E);
 Expr *VisitArrayInitIndexExpr(ArrayInitIndexExpr *E);
 Expr *VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E);
@@ -6772,6 +6773,22 @@
   return new (Importer.getToContext()) CXXStdInitializerListExpr(T, SE);
 }
 
+Expr *ASTNodeImporter::VisitCXXInheritedCtorInitExpr(
+CXXInheritedCtorInitExpr *E) {
+  QualType T = Importer.Import(E->getType());
+  if (T.isNull())
+return nullptr;
+
+  auto *Ctor = cast_or_null(Importer.Import(
+  E->getConstructor()));
+  if (!Ctor)
+return nullptr;
+
+  return new (Importer.getToContext()) CXXInheritedCtorInitExpr(
+  Importer.Import(E->getLocation()), T, Ctor,
+  E->constructsVBase(), E->inheritedFromVBase());
+}
+
 Expr *ASTNodeImporter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) {
   QualType ToType = Importer.Import(E->getType());
   if (ToType.isNull())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r337899 - [clang-format ]Extend IncludeCategories regex documentation

2018-07-25 Thread Krasimir Georgiev via cfe-commits
Author: krasimir
Date: Wed Jul 25 03:21:47 2018
New Revision: 337899

URL: http://llvm.org/viewvc/llvm-project?rev=337899&view=rev
Log:
[clang-format ]Extend IncludeCategories regex documentation

Summary:
Extend the Clang-Format IncludeCategories documentation by adding a link to the 
supported regular expression standard (POSIX).
And extenting the example with a system header regex.
[[ https://bugs.llvm.org/show_bug.cgi?id=35041 | bug 35041]]

Contributed by WimLeflere!

Reviewers: krasimir, Typz

Reviewed By: krasimir

Subscribers: cfe-commits

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

Modified:
cfe/trunk/docs/ClangFormatStyleOptions.rst
cfe/trunk/docs/tools/dump_format_style.py
cfe/trunk/include/clang/Format/Format.h
cfe/trunk/include/clang/Tooling/Inclusions/IncludeStyle.h

Modified: cfe/trunk/docs/ClangFormatStyleOptions.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormatStyleOptions.rst?rev=337899&r1=337898&r2=337899&view=diff
==
--- cfe/trunk/docs/ClangFormatStyleOptions.rst (original)
+++ cfe/trunk/docs/ClangFormatStyleOptions.rst Wed Jul 25 03:21:47 2018
@@ -1280,6 +1280,10 @@ the configuration (without a prefix: ``A
   Regular expressions denoting the different ``#include`` categories
   used for ordering ``#includes``.
 
+  `POSIX extended
+  `_
+  regular expressions are supported.
+
   These regular expressions are matched against the filename of an include
   (including the <> or "") in order. The value belonging to the first
   matching regular expression is assigned and ``#includes`` are sorted first
@@ -1302,6 +1306,8 @@ the configuration (without a prefix: ``A
 Priority:2
   - Regex:   '^(<|"(gtest|gmock|isl|json)/)'
 Priority:3
+  - Regex:   '<[[:alnum:].]+>'
+Priority:4
   - Regex:   '.*'
 Priority:1
 

Modified: cfe/trunk/docs/tools/dump_format_style.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/tools/dump_format_style.py?rev=337899&r1=337898&r2=337899&view=diff
==
--- cfe/trunk/docs/tools/dump_format_style.py (original)
+++ cfe/trunk/docs/tools/dump_format_style.py Wed Jul 25 03:21:47 2018
@@ -10,6 +10,7 @@ import urllib2
 
 CLANG_DIR = os.path.join(os.path.dirname(__file__), '../..')
 FORMAT_STYLE_FILE = os.path.join(CLANG_DIR, 'include/clang/Format/Format.h')
+INCLUDE_STYLE_FILE = os.path.join(CLANG_DIR, 
'include/clang/Tooling/Inclusions/IncludeStyle.h')
 DOC_FILE = os.path.join(CLANG_DIR, 'docs/ClangFormatStyleOptions.rst')
 
 
@@ -115,7 +116,7 @@ def read_options(header):
   for line in header:
 line = line.strip()
 if state == State.BeforeStruct:
-  if line == 'struct FormatStyle {':
+  if line == 'struct FormatStyle {' or line == 'struct IncludeStyle {':
 state = State.InStruct
 elif state == State.InStruct:
   if line.startswith('///'):
@@ -188,6 +189,7 @@ def read_options(header):
   return options
 
 options = read_options(open(FORMAT_STYLE_FILE))
+options += read_options(open(INCLUDE_STYLE_FILE))
 
 options = sorted(options, key=lambda x: x.name)
 options_text = '\n\n'.join(map(str, options))

Modified: cfe/trunk/include/clang/Format/Format.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=337899&r1=337898&r2=337899&view=diff
==
--- cfe/trunk/include/clang/Format/Format.h (original)
+++ cfe/trunk/include/clang/Format/Format.h Wed Jul 25 03:21:47 2018
@@ -1296,7 +1296,7 @@ struct FormatStyle {
   /// If ``Never``, lays out Objective-C protocol conformance list items
   /// onto individual lines whenever they go over ``ColumnLimit``.
   ///
-  /// \code
+  /// \code{.objc}
   ///Always (or Auto, if BinPackParameters=true):
   ///@interface c () <
   ///c, c,

Modified: cfe/trunk/include/clang/Tooling/Inclusions/IncludeStyle.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Inclusions/IncludeStyle.h?rev=337899&r1=337898&r2=337899&view=diff
==
--- cfe/trunk/include/clang/Tooling/Inclusions/IncludeStyle.h (original)
+++ cfe/trunk/include/clang/Tooling/Inclusions/IncludeStyle.h Wed Jul 25 
03:21:47 2018
@@ -67,6 +67,10 @@ struct IncludeStyle {
   /// Regular expressions denoting the different ``#include`` categories
   /// used for ordering ``#includes``.
   ///
+  /// `POSIX extended
+  /// 
`_
+  /// regular expressions are supported.
+  ///
   /// These regular expressions are matched against the filename of an include
   /// (

[libcxx] r337900 - Fix another typo in the FileTimeType docs

2018-07-25 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Wed Jul 25 03:22:07 2018
New Revision: 337900

URL: http://llvm.org/viewvc/llvm-project?rev=337900&view=rev
Log:
Fix another typo in the FileTimeType docs

Modified:
libcxx/trunk/docs/DesignDocs/FileTimeType.rst

Modified: libcxx/trunk/docs/DesignDocs/FileTimeType.rst
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/docs/DesignDocs/FileTimeType.rst?rev=337900&r1=337899&r2=337900&view=diff
==
--- libcxx/trunk/docs/DesignDocs/FileTimeType.rst (original)
+++ libcxx/trunk/docs/DesignDocs/FileTimeType.rst Wed Jul 25 03:22:07 2018
@@ -224,7 +224,7 @@ code in some way:
 
   // Implicit truncation during conversion bug.
   intmax_t get_time_in_seconds(path p) {
-using fs_seconds = duration;
+using fs_seconds = duration >;
 auto tp = last_write_time(p);
 
 // This works with truncation for __int128_t, but what does it do for


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


[PATCH] D48827: [clang-format ]Extend IncludeCategories regex documentation

2018-07-25 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL337899: [clang-format ]Extend IncludeCategories regex 
documentation (authored by krasimir, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D48827?vs=154176&id=157213#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D48827

Files:
  cfe/trunk/docs/ClangFormatStyleOptions.rst
  cfe/trunk/docs/tools/dump_format_style.py
  cfe/trunk/include/clang/Format/Format.h
  cfe/trunk/include/clang/Tooling/Inclusions/IncludeStyle.h


Index: cfe/trunk/docs/ClangFormatStyleOptions.rst
===
--- cfe/trunk/docs/ClangFormatStyleOptions.rst
+++ cfe/trunk/docs/ClangFormatStyleOptions.rst
@@ -1280,6 +1280,10 @@
   Regular expressions denoting the different ``#include`` categories
   used for ordering ``#includes``.
 
+  `POSIX extended
+  `_
+  regular expressions are supported.
+
   These regular expressions are matched against the filename of an include
   (including the <> or "") in order. The value belonging to the first
   matching regular expression is assigned and ``#includes`` are sorted first
@@ -1302,6 +1306,8 @@
 Priority:2
   - Regex:   '^(<|"(gtest|gmock|isl|json)/)'
 Priority:3
+  - Regex:   '<[[:alnum:].]+>'
+Priority:4
   - Regex:   '.*'
 Priority:1
 
Index: cfe/trunk/docs/tools/dump_format_style.py
===
--- cfe/trunk/docs/tools/dump_format_style.py
+++ cfe/trunk/docs/tools/dump_format_style.py
@@ -10,6 +10,7 @@
 
 CLANG_DIR = os.path.join(os.path.dirname(__file__), '../..')
 FORMAT_STYLE_FILE = os.path.join(CLANG_DIR, 'include/clang/Format/Format.h')
+INCLUDE_STYLE_FILE = os.path.join(CLANG_DIR, 
'include/clang/Tooling/Inclusions/IncludeStyle.h')
 DOC_FILE = os.path.join(CLANG_DIR, 'docs/ClangFormatStyleOptions.rst')
 
 
@@ -115,7 +116,7 @@
   for line in header:
 line = line.strip()
 if state == State.BeforeStruct:
-  if line == 'struct FormatStyle {':
+  if line == 'struct FormatStyle {' or line == 'struct IncludeStyle {':
 state = State.InStruct
 elif state == State.InStruct:
   if line.startswith('///'):
@@ -188,6 +189,7 @@
   return options
 
 options = read_options(open(FORMAT_STYLE_FILE))
+options += read_options(open(INCLUDE_STYLE_FILE))
 
 options = sorted(options, key=lambda x: x.name)
 options_text = '\n\n'.join(map(str, options))
Index: cfe/trunk/include/clang/Tooling/Inclusions/IncludeStyle.h
===
--- cfe/trunk/include/clang/Tooling/Inclusions/IncludeStyle.h
+++ cfe/trunk/include/clang/Tooling/Inclusions/IncludeStyle.h
@@ -67,6 +67,10 @@
   /// Regular expressions denoting the different ``#include`` categories
   /// used for ordering ``#includes``.
   ///
+  /// `POSIX extended
+  /// 
`_
+  /// regular expressions are supported.
+  ///
   /// These regular expressions are matched against the filename of an include
   /// (including the <> or "") in order. The value belonging to the first
   /// matching regular expression is assigned and ``#includes`` are sorted 
first
@@ -87,6 +91,8 @@
   ///   Priority:2
   /// - Regex:   '^(<|"(gtest|gmock|isl|json)/)'
   ///   Priority:3
+  /// - Regex:   '<[[:alnum:].]+>'
+  ///   Priority:4
   /// - Regex:   '.*'
   ///   Priority:1
   /// \endcode
Index: cfe/trunk/include/clang/Format/Format.h
===
--- cfe/trunk/include/clang/Format/Format.h
+++ cfe/trunk/include/clang/Format/Format.h
@@ -1296,7 +1296,7 @@
   /// If ``Never``, lays out Objective-C protocol conformance list items
   /// onto individual lines whenever they go over ``ColumnLimit``.
   ///
-  /// \code
+  /// \code{.objc}
   ///Always (or Auto, if BinPackParameters=true):
   ///@interface c () <
   ///c, c,


Index: cfe/trunk/docs/ClangFormatStyleOptions.rst
===
--- cfe/trunk/docs/ClangFormatStyleOptions.rst
+++ cfe/trunk/docs/ClangFormatStyleOptions.rst
@@ -1280,6 +1280,10 @@
   Regular expressions denoting the different ``#include`` categories
   used for ordering ``#includes``.
 
+  `POSIX extended
+  `_
+  regular expressions are supported.
+
   These regular expressions are matched against the filename of an include
   (including the <> or "") in order. The value belonging to the first
   matching regular expression is assigned and ``#includes`` 

[PATCH] D49782: [libcxx] [windows] Fix warning about comparing ints of different signs

2018-07-25 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo created this revision.
mstorsjo added reviewers: pirama, pcc, compnerd, srhines.
Herald added a reviewer: EricWF.
Herald added a subscriber: ldionne.

This fixes a warning like this:

warning: comparison of integers of different signs:

  'std::__1::__libcpp_tls_key' (aka 'long') and 'DWORD'
  (aka 'unsigned long') [-Wsign-compare]
  if (*__key == FLS_OUT_OF_INDEXES)
  ~~ ^  ~~
   


Repository:
  rCXX libc++

https://reviews.llvm.org/D49782

Files:
  src/support/win32/thread_win32.cpp


Index: src/support/win32/thread_win32.cpp
===
--- src/support/win32/thread_win32.cpp
+++ src/support/win32/thread_win32.cpp
@@ -254,9 +254,10 @@
 int __libcpp_tls_create(__libcpp_tls_key* __key,
 void(_LIBCPP_TLS_DESTRUCTOR_CC* __at_exit)(void*))
 {
-  *__key = FlsAlloc(__at_exit);
-  if (*__key == FLS_OUT_OF_INDEXES)
+  DWORD index = FlsAlloc(__at_exit);
+  if (index == FLS_OUT_OF_INDEXES)
 return GetLastError();
+  *__key = index;
   return 0;
 }
 


Index: src/support/win32/thread_win32.cpp
===
--- src/support/win32/thread_win32.cpp
+++ src/support/win32/thread_win32.cpp
@@ -254,9 +254,10 @@
 int __libcpp_tls_create(__libcpp_tls_key* __key,
 void(_LIBCPP_TLS_DESTRUCTOR_CC* __at_exit)(void*))
 {
-  *__key = FlsAlloc(__at_exit);
-  if (*__key == FLS_OUT_OF_INDEXES)
+  DWORD index = FlsAlloc(__at_exit);
+  if (index == FLS_OUT_OF_INDEXES)
 return GetLastError();
+  *__key = index;
   return 0;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r337901 - [clangd] Introduce Dex symbol index search tokens

2018-07-25 Thread Kirill Bobyrev via cfe-commits
Author: omtcyfz
Date: Wed Jul 25 03:34:57 2018
New Revision: 337901

URL: http://llvm.org/viewvc/llvm-project?rev=337901&view=rev
Log:
[clangd] Introduce Dex symbol index search tokens

This patch introduces the core building block of the next-generation
Clangd symbol index - Dex. Search tokens are the keys in the inverted
index and represent a characteristic of a specific symbol: examples of
search token types (Token Namespaces) are

* Trigrams -  these are essential for unqualified symbol name fuzzy
search * Scopes for filtering the symbols by the namespace * Paths, e.g.
these can be used to uprank symbols defined close to the edited file

This patch outlines the generic for such token namespaces, but only
implements trigram generation.

The intuition behind trigram generation algorithm is that each extracted
trigram is a valid sequence for Fuzzy Matcher jumps, proposed
implementation utilize existing FuzzyMatcher API for segmentation and
trigram extraction.

However, trigrams generation algorithm for the query string is different
from the previous one: it simply yields sequences of 3 consecutive
lowercased valid characters (letters, digits).

Dex RFC in the mailing list:
http://lists.llvm.org/pipermail/clangd-dev/2018-July/22.html

The trigram generation techniques are described in detail in the
proposal:
https://docs.google.com/document/d/1C-A6PGT6TynyaX4PXyExNMiGmJ2jL1UwV91Kyx11gOI/edit#heading=h.903u1zon9nkj

Reviewers: sammccall, ioeric, ilya-biryukovA

Subscribers: cfe-commits, klimek, mgorny, MaskRay, jkorous, arphaman

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

Added:
clang-tools-extra/trunk/clangd/index/dex/
clang-tools-extra/trunk/clangd/index/dex/Token.h
clang-tools-extra/trunk/clangd/index/dex/Trigram.cpp
clang-tools-extra/trunk/clangd/index/dex/Trigram.h
clang-tools-extra/trunk/unittests/clangd/DexIndexTests.cpp
Modified:
clang-tools-extra/trunk/clangd/CMakeLists.txt
clang-tools-extra/trunk/unittests/clangd/CMakeLists.txt

Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CMakeLists.txt?rev=337901&r1=337900&r2=337901&view=diff
==
--- clang-tools-extra/trunk/clangd/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clangd/CMakeLists.txt Wed Jul 25 03:34:57 2018
@@ -34,6 +34,7 @@ add_clang_library(clangDaemon
   TUScheduler.cpp
   URI.cpp
   XRefs.cpp
+
   index/CanonicalIncludes.cpp
   index/FileIndex.cpp
   index/Index.cpp
@@ -42,6 +43,8 @@ add_clang_library(clangDaemon
   index/SymbolCollector.cpp
   index/SymbolYAML.cpp
 
+  index/dex/Trigram.cpp
+
   LINK_LIBS
   clangAST
   clangASTMatchers

Added: clang-tools-extra/trunk/clangd/index/dex/Token.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/dex/Token.h?rev=337901&view=auto
==
--- clang-tools-extra/trunk/clangd/index/dex/Token.h (added)
+++ clang-tools-extra/trunk/clangd/index/dex/Token.h Wed Jul 25 03:34:57 2018
@@ -0,0 +1,112 @@
+//===--- Token.h - Symbol Search primitive --*- C++ 
-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Token objects represent a characteristic of a symbol, which can be used to
+// perform efficient search. Tokens are keys for inverted index which are 
mapped
+// to the corresponding posting lists.
+//
+// The symbol std::cout might have the tokens:
+// * Scope "std::"
+// * Trigram "cou"
+// * Trigram "out"
+// * Type "std::ostream"
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_DEX_TOKEN_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_DEX_TOKEN_H
+
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/Support/raw_ostream.h"
+
+#include 
+#include 
+
+namespace clang {
+namespace clangd {
+namespace dex {
+
+/// A Token represents an attribute of a symbol, such as a particular trigram
+/// present in the name (used for fuzzy search).
+///
+/// Tokens can be used to perform more sophisticated search queries by
+/// constructing complex iterator trees.
+struct Token {
+  /// Kind specifies Token type which defines semantics for the internal
+  /// representation. Each Kind has different representation stored in Data
+  /// field.
+  enum class Kind {
+/// Represents trigram used for fuzzy search of unqualified symbol names.
+///
+/// Data contains 3 bytes with trigram contents.
+Trigram,
+/// Scope primitives, e.g. "symbol belongs to namespace foo::bar".
+///
+/// Data stroes full scope name , e.g. "foo::bar::baz::" or "" (for global
+/// scope).
+Scope,

[PATCH] D49591: [clangd] Introduce Dex symbol index search tokens

2018-07-25 Thread Kirill Bobyrev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL337901: [clangd] Introduce Dex symbol index search tokens 
(authored by omtcyfz, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D49591?vs=157196&id=157216#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D49591

Files:
  clang-tools-extra/trunk/clangd/CMakeLists.txt
  clang-tools-extra/trunk/clangd/index/dex/Token.h
  clang-tools-extra/trunk/clangd/index/dex/Trigram.cpp
  clang-tools-extra/trunk/clangd/index/dex/Trigram.h
  clang-tools-extra/trunk/unittests/clangd/CMakeLists.txt
  clang-tools-extra/trunk/unittests/clangd/DexIndexTests.cpp

Index: clang-tools-extra/trunk/unittests/clangd/CMakeLists.txt
===
--- clang-tools-extra/trunk/unittests/clangd/CMakeLists.txt
+++ clang-tools-extra/trunk/unittests/clangd/CMakeLists.txt
@@ -15,9 +15,10 @@
   CodeCompleteTests.cpp
   CodeCompletionStringsTests.cpp
   ContextTests.cpp
+  DexIndexTests.cpp
   DraftStoreTests.cpp
-  FileIndexTests.cpp
   FileDistanceTests.cpp
+  FileIndexTests.cpp
   FindSymbolsTests.cpp
   FuzzyMatchTests.cpp
   GlobalCompilationDatabaseTests.cpp
@@ -27,11 +28,11 @@
   SourceCodeTests.cpp
   SymbolCollectorTests.cpp
   SyncAPI.cpp
+  TUSchedulerTests.cpp
   TestFS.cpp
   TestTU.cpp
   ThreadingTests.cpp
   TraceTests.cpp
-  TUSchedulerTests.cpp
   URITests.cpp
   XRefsTests.cpp
   )
Index: clang-tools-extra/trunk/unittests/clangd/DexIndexTests.cpp
===
--- clang-tools-extra/trunk/unittests/clangd/DexIndexTests.cpp
+++ clang-tools-extra/trunk/unittests/clangd/DexIndexTests.cpp
@@ -0,0 +1,96 @@
+//===-- DexIndexTests.cpp  *- C++ -*---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "index/dex/Token.h"
+#include "index/dex/Trigram.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+#include 
+#include 
+
+namespace clang {
+namespace clangd {
+namespace dex {
+
+testing::Matcher>
+trigramsAre(std::initializer_list Trigrams) {
+  std::vector Tokens;
+  for (const auto &Symbols : Trigrams) {
+Tokens.push_back(Token(Token::Kind::Trigram, Symbols));
+  }
+  return testing::UnorderedElementsAreArray(Tokens);
+}
+
+TEST(DexIndexTrigrams, IdentifierTrigrams) {
+  EXPECT_THAT(generateIdentifierTrigrams("X86"), trigramsAre({"x86"}));
+
+  EXPECT_THAT(generateIdentifierTrigrams("nl"), trigramsAre({}));
+
+  EXPECT_THAT(generateIdentifierTrigrams("clangd"),
+  trigramsAre({"cla", "lan", "ang", "ngd"}));
+
+  EXPECT_THAT(generateIdentifierTrigrams("abc_def"),
+  trigramsAre({"abc", "abd", "ade", "bcd", "bde", "cde", "def"}));
+
+  EXPECT_THAT(
+  generateIdentifierTrigrams("a_b_c_d_e_"),
+  trigramsAre({"abc", "abd", "acd", "ace", "bcd", "bce", "bde", "cde"}));
+
+  EXPECT_THAT(
+  generateIdentifierTrigrams("unique_ptr"),
+  trigramsAre({"uni", "unp", "upt", "niq", "nip", "npt", "iqu", "iqp",
+   "ipt", "que", "qup", "qpt", "uep", "ept", "ptr"}));
+
+  EXPECT_THAT(generateIdentifierTrigrams("TUDecl"),
+  trigramsAre({"tud", "tde", "ude", "dec", "ecl"}));
+
+  EXPECT_THAT(generateIdentifierTrigrams("IsOK"),
+  trigramsAre({"iso", "iok", "sok"}));
+
+  EXPECT_THAT(generateIdentifierTrigrams("abc_defGhij__klm"),
+  trigramsAre({
+  "abc", "abd", "abg", "ade", "adg", "adk", "agh", "agk", "bcd",
+  "bcg", "bde", "bdg", "bdk", "bgh", "bgk", "cde", "cdg", "cdk",
+  "cgh", "cgk", "def", "deg", "dek", "dgh", "dgk", "dkl", "efg",
+  "efk", "egh", "egk", "ekl", "fgh", "fgk", "fkl", "ghi", "ghk",
+  "gkl", "hij", "hik", "hkl", "ijk", "ikl", "jkl", "klm",
+  }));
+}
+
+TEST(DexIndexTrigrams, QueryTrigrams) {
+  EXPECT_THAT(generateQueryTrigrams("X86"), trigramsAre({"x86"}));
+
+  EXPECT_THAT(generateQueryTrigrams("nl"), trigramsAre({}));
+
+  EXPECT_THAT(generateQueryTrigrams("clangd"),
+  trigramsAre({"cla", "lan", "ang", "ngd"}));
+
+  EXPECT_THAT(generateQueryTrigrams("abc_def"),
+  trigramsAre({"abc", "bcd", "cde", "def"}));
+
+  EXPECT_THAT(generateQueryTrigrams("a_b_c_d_e_"),
+  trigramsAre({"abc", "bcd", "cde"}));
+
+  EXPECT_THAT(generateQueryTrigrams("unique_ptr"),
+  trigramsAre({"uni", "niq", "iqu", "que", "uep", "ept", "ptr"}));
+
+  EXPECT_THAT(generateQueryTrigrams("TUDecl"),
+  trigramsAre({"tud", "ude", "dec", "ecl"}));
+
+  EXPECT_THAT(generateQueryTrigrams("IsOK"), trigramsAre({"iso", "sok"}));
+
+  EXPECT_THAT(generateQueryTrigrams("abc_defGhij__klm"

[PATCH] D45094: [LibTooling] Make interface of VFS injection into ClangTool more user-friendly

2018-07-25 Thread Whisperity via Phabricator via cfe-commits
whisperity added a comment.

Softly pinging this. Perhaps we could discuss this and get it in before Clang7 
rides off into the sunset?


https://reviews.llvm.org/D45094



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


[PATCH] D45095: [clang-tidy] Align usage of ClangTool interface with new VFS injection

2018-07-25 Thread Whisperity via Phabricator via cfe-commits
whisperity added a comment.

Akin to https://reviews.llvm.org/D45094, pinging this too. 🙂


https://reviews.llvm.org/D45095



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


[PATCH] D49782: [libcxx] [windows] Fix warning about comparing ints of different signs

2018-07-25 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF accepted this revision.
EricWF added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rCXX libc++

https://reviews.llvm.org/D49782



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


[PATCH] D49783: [clangd] Do not rebuild AST if inputs have not changed

2018-07-25 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov created this revision.
ilya-biryukov added a reviewer: ioeric.
Herald added subscribers: jfb, arphaman, jkorous, MaskRay, javed.absar.

If the contents are the same, the update most likely comes from the
fact that compile commands were invalidated. In that case we want to
avoid rebuilds in case the compile commands are actually the same.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D49783

Files:
  clangd/TUScheduler.cpp
  test/clangd/extra-flags.test
  unittests/clangd/TUSchedulerTests.cpp
  unittests/clangd/TestFS.cpp
  unittests/clangd/TestFS.h

Index: unittests/clangd/TestFS.h
===
--- unittests/clangd/TestFS.h
+++ unittests/clangd/TestFS.h
@@ -23,7 +23,8 @@
 // Builds a VFS that provides access to the provided files, plus temporary
 // directories.
 llvm::IntrusiveRefCntPtr
-buildTestFS(llvm::StringMap const &Files);
+buildTestFS(llvm::StringMap const &Files,
+llvm::StringMap const &Timestamps = {});
 
 // A VFS provider that returns TestFSes containing a provided set of files.
 class MockFSProvider : public FileSystemProvider {
Index: unittests/clangd/TestFS.cpp
===
--- unittests/clangd/TestFS.cpp
+++ unittests/clangd/TestFS.cpp
@@ -19,13 +19,15 @@
 using namespace llvm;
 
 IntrusiveRefCntPtr
-buildTestFS(StringMap const &Files) {
+buildTestFS(llvm::StringMap const &Files,
+llvm::StringMap const &Timestamps) {
   IntrusiveRefCntPtr MemFS(
   new vfs::InMemoryFileSystem);
   for (auto &FileAndContents : Files) {
-MemFS->addFile(FileAndContents.first(), time_t(),
-   MemoryBuffer::getMemBufferCopy(FileAndContents.second,
-  FileAndContents.first()));
+StringRef File = FileAndContents.first();
+MemFS->addFile(
+File, Timestamps.lookup(File),
+MemoryBuffer::getMemBufferCopy(FileAndContents.second, File));
   }
   return MemFS;
 }
Index: unittests/clangd/TUSchedulerTests.cpp
===
--- unittests/clangd/TUSchedulerTests.cpp
+++ unittests/clangd/TUSchedulerTests.cpp
@@ -33,13 +33,12 @@
 class TUSchedulerTests : public ::testing::Test {
 protected:
   ParseInputs getInputs(PathRef File, std::string Contents) {
-return ParseInputs{*CDB.getCompileCommand(File), buildTestFS(Files),
-   std::move(Contents)};
+return ParseInputs{*CDB.getCompileCommand(File),
+   buildTestFS(Files, Timestamps), std::move(Contents)};
   }
 
   llvm::StringMap Files;
-
-private:
+  llvm::StringMap Timestamps;
   MockCompilationDatabase CDB;
 };
 
@@ -263,6 +262,10 @@
 int* a;
 double* b = a;
   )cpp";
+  llvm::StringLiteral OtherSourceContents = R"cpp(
+int* a;
+double* b = a + 0;
+  )cpp";
 
   auto Foo = testPath("foo.cpp");
   auto Bar = testPath("bar.cpp");
@@ -288,7 +291,7 @@
   ASSERT_THAT(S.getFilesWithCachedAST(), UnorderedElementsAre(Bar, Baz));
 
   // Access the old file again.
-  S.update(Foo, getInputs(Foo, SourceContents), WantDiagnostics::Yes,
+  S.update(Foo, getInputs(Foo, OtherSourceContents), WantDiagnostics::Yes,
[&BuiltASTCounter](std::vector Diags) { ++BuiltASTCounter; });
   ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(1)));
   ASSERT_EQ(BuiltASTCounter.load(), 4);
@@ -334,5 +337,58 @@
   ASSERT_THAT(Preambles, Each(Preambles[0]));
 }
 
+TEST_F(TUSchedulerTests, NoopOnEmptyChanges) {
+  TUScheduler S(
+  /*AsyncThreadsCount=*/getDefaultAsyncThreadsCount(),
+  /*StorePreambleInMemory=*/true, PreambleParsedCallback(),
+  /*UpdateDebounce=*/std::chrono::steady_clock::duration::zero(),
+  ASTRetentionPolicy());
+
+  auto Source = testPath("foo.cpp");
+  auto Header = testPath("foo.h");
+
+  Files[Header] = "int a;";
+  Timestamps[Header] = time_t(0);
+
+  auto SourceContents = R"cpp(
+  #include "foo.h"
+  int b = a;
+)cpp";
+
+  // Return value indicates if the updated callback was received.
+  auto DoUpdate = [&](ParseInputs Inputs) -> bool {
+std::atomic Updated(false);
+Updated = false;
+S.update(Source, std::move(Inputs), WantDiagnostics::Yes,
+ [&Updated](std::vector) { Updated = true; });
+bool UpdateFinished = S.blockUntilIdle(timeoutSeconds(1));
+if (!UpdateFinished)
+  ADD_FAILURE() << "Updated has not finished in one second. Threading bug?";
+return Updated;
+  };
+
+  // Test that subsequent updates with the same inputs do not cause rebuilds.
+  ASSERT_TRUE(DoUpdate(getInputs(Source, SourceContents)));
+  ASSERT_FALSE(DoUpdate(getInputs(Source, SourceContents)));
+
+  // Update to a header should cause a rebuild, though.
+  Files[Header] = time_t(1);
+  ASSERT_TRUE(DoUpdate(getInputs(Source, SourceContents)));
+  ASSERT_FALSE(DoUpdate(getInputs(Source, SourceContents)));
+
+  // Update to the contents should cause a rebuild.
+

[PATCH] D49780: [clangd] Use a sigmoid style function for #usages boost in symbol quality.

2018-07-25 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/Quality.cpp:194
+  if (References >= 10) {
+// Use a sigmoid style boosting function, which flats out better for large
+// numbers (e.g. 2.58 for 1M refererences).

NIT: better, but nothing to compare to in the comment.
Maybe use "better than log" or "nicely" instead?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D49780



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


[PATCH] D49723: [OpenCL] Check for invalid kernel arguments in array types

2018-07-25 Thread Andrew Savonichev via Phabricator via cfe-commits
asavonic updated this revision to Diff 157219.
asavonic added a comment.

Moved a chunk from https://reviews.llvm.org/D49725; added 2 more tests.


Repository:
  rC Clang

https://reviews.llvm.org/D49723

Files:
  lib/Sema/SemaDecl.cpp
  test/SemaOpenCL/invalid-kernel-parameters.cl


Index: test/SemaOpenCL/invalid-kernel-parameters.cl
===
--- test/SemaOpenCL/invalid-kernel-parameters.cl
+++ test/SemaOpenCL/invalid-kernel-parameters.cl
@@ -136,3 +136,16 @@
 };
 
 kernel void pointer_in_nested_struct_arg_2(struct Valid valid, struct 
NestedPointer arg, struct AlsoUser also) { } // expected-error 2 {{struct 
kernel parameters may not contain pointers}}
+
+struct ArrayOfPtr // expected-note{{within field of type 'ArrayOfPtr' declared 
here}}
+{
+  float *arr[3]; // expected-note{{field of illegal type 'float *[3]' declared 
here}}
+ // expected-note@-1{{field of illegal type 'float *[3]' 
declared here}}
+};
+kernel void array_of_ptr(struct ArrayOfPtr arr) {} // expected-error{{struct 
kernel parameters may not contain pointers}}
+
+struct ArrayOfStruct // expected-note{{within field of type 'ArrayOfStruct' 
declared here}}
+{
+  struct ArrayOfPtr arr[3]; // expected-note{{within field of type 'struct 
ArrayOfPtr [3]' declared here}}
+};
+kernel void array_of_struct(struct ArrayOfStruct arr) {} // 
expected-error{{struct kernel parameters may not contain pointers}}
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -8079,6 +8079,15 @@
   if (PT->isRecordType())
 return RecordKernelParam;
 
+  // Look into an array argument to check if it has a forbidden type.
+  if (PT->isArrayType()) {
+const Type *UnderlyingTy = PT->getPointeeOrArrayElementType();
+// Call ourself to check an underlying type of an array. Since the
+// getPointeeOrArrayElementType returns an innermost type which is not an
+// array, this recusive call only happens once.
+return getOpenCLKernelParameterType(S, QualType(UnderlyingTy, 0));
+  }
+
   return ValidKernelParam;
 }
 
@@ -8146,9 +8155,14 @@
   SmallVector HistoryStack;
   HistoryStack.push_back(nullptr);
 
-  const RecordDecl *PD = PT->castAs()->getDecl();
-  VisitStack.push_back(PD);
+  // At this point we already handled everything except of a RecordType or
+  // an ArrayType of a RecordType.
+  assert((PT->isArrayType() || PT->isRecordType()) && "Unexpected type.");
+  const RecordType *RecTy =
+  PT->getPointeeOrArrayElementType()->getAs();
+  const RecordDecl *OrigRecDecl = RecTy->getDecl();
 
+  VisitStack.push_back(RecTy->getDecl());
   assert(VisitStack.back() && "First decl null?");
 
   do {
@@ -8167,7 +8181,13 @@
 const RecordDecl *RD;
 if (const FieldDecl *Field = dyn_cast(Next)) {
   HistoryStack.push_back(Field);
-  RD = Field->getType()->castAs()->getDecl();
+
+  // Other field types (known to be valid or invalid) are handled while we
+  // walk around RecordDecl::fields().
+  assert((PT->isArrayType() || PT->isRecordType()) && "Unexpected type.");
+  const Type *FieldRecTy = 
Field->getType()->getPointeeOrArrayElementType();
+
+  RD = FieldRecTy->castAs()->getDecl();
 } else {
   RD = cast(Next);
 }


Index: test/SemaOpenCL/invalid-kernel-parameters.cl
===
--- test/SemaOpenCL/invalid-kernel-parameters.cl
+++ test/SemaOpenCL/invalid-kernel-parameters.cl
@@ -136,3 +136,16 @@
 };
 
 kernel void pointer_in_nested_struct_arg_2(struct Valid valid, struct NestedPointer arg, struct AlsoUser also) { } // expected-error 2 {{struct kernel parameters may not contain pointers}}
+
+struct ArrayOfPtr // expected-note{{within field of type 'ArrayOfPtr' declared here}}
+{
+  float *arr[3]; // expected-note{{field of illegal type 'float *[3]' declared here}}
+ // expected-note@-1{{field of illegal type 'float *[3]' declared here}}
+};
+kernel void array_of_ptr(struct ArrayOfPtr arr) {} // expected-error{{struct kernel parameters may not contain pointers}}
+
+struct ArrayOfStruct // expected-note{{within field of type 'ArrayOfStruct' declared here}}
+{
+  struct ArrayOfPtr arr[3]; // expected-note{{within field of type 'struct ArrayOfPtr [3]' declared here}}
+};
+kernel void array_of_struct(struct ArrayOfStruct arr) {} // expected-error{{struct kernel parameters may not contain pointers}}
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -8079,6 +8079,15 @@
   if (PT->isRecordType())
 return RecordKernelParam;
 
+  // Look into an array argument to check if it has a forbidden type.
+  if (PT->isArrayType()) {
+const Type *UnderlyingTy = PT->getPointeeOrArrayElementType();
+// Call ourself to check an underlying type of an array. Since the
+/

[PATCH] D49723: [OpenCL] Check for invalid kernel arguments in array types

2018-07-25 Thread Andrew Savonichev via Phabricator via cfe-commits
asavonic added a comment.

In https://reviews.llvm.org/D49723#1173352, @Anastasia wrote:

> Btw, has this restriction been removed from CL 2.0?


No, it applies for CL2.0 as well.


Repository:
  rC Clang

https://reviews.llvm.org/D49723



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


[PATCH] D49725: [OpenCL] Forbid size dependent types used as kernel arguments

2018-07-25 Thread Andrew Savonichev via Phabricator via cfe-commits
asavonic updated this revision to Diff 157222.
asavonic added a comment.

Added a diagnostic note for typedefs; moved unrelated changes to
https://reviews.llvm.org/D49723.


Repository:
  rC Clang

https://reviews.llvm.org/D49725

Files:
  lib/Sema/SemaDecl.cpp
  test/SemaOpenCL/invalid-kernel-parameters.cl

Index: test/SemaOpenCL/invalid-kernel-parameters.cl
===
--- test/SemaOpenCL/invalid-kernel-parameters.cl
+++ test/SemaOpenCL/invalid-kernel-parameters.cl
@@ -9,7 +9,35 @@
 // bool, half, size_t, ptrdiff_t, intptr_t, and uintptr_t
 // or a struct / union with any of these types in them
 
-// TODO: Ban int types, size_t, ptrdiff_t ...
+typedef __SIZE_TYPE__ size_t; // expected-note{{'size_t' (aka 'unsigned int') declared here}}
+  // expected-note@-1{{'size_t' (aka 'unsigned int') declared here}}
+typedef __PTRDIFF_TYPE__ ptrdiff_t; // expected-note{{'ptrdiff_t' (aka 'int') declared here}}
+typedef __INTPTR_TYPE__ intptr_t; // expected-note{{'intptr_t' (aka 'int') declared here}}
+typedef __UINTPTR_TYPE__ uintptr_t; // expected-note{{'uintptr_t' (aka 'unsigned int') declared here}}
+
+kernel void size_t_arg(size_t x) {} // expected-error{{'size_t' (aka 'unsigned int') cannot be used as the type of a kernel parameter}}
+
+kernel void ptrdiff_t_arg(ptrdiff_t x) {} // expected-error{{'ptrdiff_t' (aka 'int') cannot be used as the type of a kernel parameter}}
+
+kernel void intptr_t_arg(intptr_t x) {} // expected-error{{'intptr_t' (aka 'int') cannot be used as the type of a kernel parameter}}
+
+kernel void uintptr_t_arg(uintptr_t x) {} // expected-error{{'uintptr_t' (aka 'unsigned int') cannot be used as the type of a kernel parameter}}
+
+typedef size_t size_ty;
+struct SizeTStruct { // expected-note{{within field of type 'SizeTStruct' declared here}}
+  size_ty s; // expected-note{{field of illegal type 'size_ty' (aka 'unsigned int') declared here}}
+};
+kernel void size_t_struct_arg(struct SizeTStruct x) {} // expected-error{{'struct SizeTStruct' cannot be used as the type of a kernel parameter}}
+
+union SizeTUnion { // expected-note{{within field of type 'SizeTUnion' declared here}}
+  size_t s; // expected-note{{field of illegal type 'size_t' (aka 'unsigned int') declared here}}
+  float f;
+};
+kernel void size_t_union_arg(union SizeTUnion x) {} // expected-error{{'union SizeTUnion' cannot be used as the type of a kernel parameter}}
+
+typedef size_t s_ty; // expected-note{{'s_ty' (aka 'unsigned int') declared here}}
+typedef s_ty ss_ty; // expected-note{{'ss_ty' (aka 'unsigned int') declared here}}
+kernel void typedef_to_size_t(ss_ty s) {} // expected-error{{'ss_ty' (aka 'unsigned int') cannot be used as the type of a kernel parameter}}
 
 kernel void bool_arg(bool x) { } // expected-error{{'bool' cannot be used as the type of a kernel parameter}}
 
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -8049,6 +8049,29 @@
   RecordKernelParam
 };
 
+static bool isOpenCLSizeDependentType(ASTContext &C, QualType Ty) {
+  // Size dependent types are just typedefs to normal integer types
+  // (e.g. unsigned long), so we cannot distinguish them from other typedefs to
+  // integers other than by their names.
+  StringRef SizeTypeNames[] = {"size_t", "intptr_t", "uintptr_t", "ptrdiff_t"};
+
+  // Remove typedefs one by one until we reach a typedef
+  // for a size dependent type.
+  QualType DesugaredTy = Ty;
+  do {
+ArrayRef Names(SizeTypeNames);
+auto Match =
+std::find(Names.begin(), Names.end(), DesugaredTy.getAsString());
+if (Names.end() != Match)
+  return true;
+
+Ty = DesugaredTy;
+DesugaredTy = Ty.getSingleStepDesugaredType(C);
+  } while (DesugaredTy != Ty);
+
+  return false;
+}
+
 static OpenCLParamType getOpenCLKernelParameterType(Sema &S, QualType PT) {
   if (PT->isPointerType()) {
 QualType PointeeType = PT->getPointeeType();
@@ -8061,8 +8084,13 @@
 return PtrKernelParam;
   }
 
-  // TODO: Forbid the other integer types (size_t, ptrdiff_t...) when they can
-  // be used as builtin types.
+  // OpenCL v1.2 s6.9.k:
+  // Arguments to kernel functions in a program cannot be declared with the
+  // built-in scalar types bool, half, size_t, ptrdiff_t, intptr_t, and
+  // uintptr_t or a struct and/or union that contain fields declared to be one
+  // of these built-in scalar types.
+  if (isOpenCLSizeDependentType(S.getASTContext(), PT))
+return InvalidKernelParam;
 
   if (PT->isImageType())
 return PtrKernelParam;
@@ -8133,8 +8161,20 @@
 // of event_t type.
 // Do not diagnose half type since it is diagnosed as invalid argument
 // type for any function elsewhere.
-if (!PT->isHalfType())
+if (!PT->isHalfType()) {
   S.Diag(Param->getLocation(), diag::err_bad_kernel_param_type) << PT;
+
+  // Explain what typedefs are involved.
+

[libcxx] r337905 - Fix diagnostic test to tolerate Clang diagnosing it as well.

2018-07-25 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Wed Jul 25 04:16:39 2018
New Revision: 337905

URL: http://llvm.org/viewvc/llvm-project?rev=337905&view=rev
Log:
Fix diagnostic test to tolerate Clang diagnosing it as well.

Tuple has tests that ensure we diagnose non-lifetime extended
reference bindings inside tuples constructors. As of yesterday,
Clang now does this for us.

Adjust the test to tolerate the new diagnostics, while still
testing that we emit diagnostics of our own. Maybe after this
version of Clang has been adopted by most users we should
remove our diagnostics; but for now more error detection is
better!

Modified:

libcxx/trunk/test/libcxx/utilities/tuple/tuple.tuple/tuple.cnstr/PR20855_tuple_ref_binding_diagnostics.fail.cpp

Modified: 
libcxx/trunk/test/libcxx/utilities/tuple/tuple.tuple/tuple.cnstr/PR20855_tuple_ref_binding_diagnostics.fail.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/utilities/tuple/tuple.tuple/tuple.cnstr/PR20855_tuple_ref_binding_diagnostics.fail.cpp?rev=337905&r1=337904&r2=337905&view=diff
==
--- 
libcxx/trunk/test/libcxx/utilities/tuple/tuple.tuple/tuple.cnstr/PR20855_tuple_ref_binding_diagnostics.fail.cpp
 (original)
+++ 
libcxx/trunk/test/libcxx/utilities/tuple/tuple.tuple/tuple.cnstr/PR20855_tuple_ref_binding_diagnostics.fail.cpp
 Wed Jul 25 04:16:39 2018
@@ -46,7 +46,12 @@ void F(typename CannotDeduce(std::make_tuple(1, "abc")); // expected-note 1 
{{requested here}}
   }


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


[libcxxabi] r337906 - Fix dangling reference in test

2018-07-25 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Wed Jul 25 04:19:13 2018
New Revision: 337906

URL: http://llvm.org/viewvc/llvm-project?rev=337906&view=rev
Log:
Fix dangling reference in test

Modified:
libcxxabi/trunk/test/cxa_bad_cast.pass.cpp

Modified: libcxxabi/trunk/test/cxa_bad_cast.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/test/cxa_bad_cast.pass.cpp?rev=337906&r1=337905&r2=337906&view=diff
==
--- libcxxabi/trunk/test/cxa_bad_cast.pass.cpp (original)
+++ libcxxabi/trunk/test/cxa_bad_cast.pass.cpp Wed Jul 25 04:19:13 2018
@@ -21,7 +21,7 @@ class Base {
 
 class Derived : public Base {};
 
-Derived &test_bad_cast(Base b) {
+Derived &test_bad_cast(Base& b) {
   return dynamic_cast(b);
 }
 


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


[PATCH] D49725: [OpenCL] Forbid size dependent types used as kernel arguments

2018-07-25 Thread Andrew Savonichev via Phabricator via cfe-commits
asavonic marked 5 inline comments as done.
asavonic added a comment.

In https://reviews.llvm.org/D49725#1173321, @yaxunl wrote:

> This patch also adds check for array of structs. Can you include this in 
> title or split to a separate patch?


I'm sorry, this change with arrays should actually go into 
https://reviews.llvm.org/D49723. Moved it there.




Comment at: lib/Sema/SemaDecl.cpp:8065
+std::find(Names.begin(), Names.end(), DesugaredTy.getAsString());
+if (Names.end() != Match)
+  return true;

yaxunl wrote:
> Can we record the real size_t/intptr_t/etc typedef and later on emit a note 
> for it? It helps user to locate the culprit typedef in case of multiple 
> typedefs.
I changed the patch to emit a note for all typedefs involved in
InvalidKernelParam. This way it works not only for size_t types, but
also for other invalid types which were typedef'ed.




Comment at: lib/Sema/SemaDecl.cpp:8186
 
-  const RecordDecl *PD = PT->castAs()->getDecl();
-  VisitStack.push_back(PD);
+  // At this point we already handled everything except of a RecordType or
+  // an ArrayType[RecordType].

Anastasia wrote:
> Anastasia wrote:
> > I am a bit confused about this comment, `do you mean a PointerType to a 
> > RecordType or an ArrayType of a RecordType`?
> Also is there any test case covering this change?
ArrayType of a RecordType. Fixed.



Comment at: lib/Sema/SemaDecl.cpp:8186
 
-  const RecordDecl *PD = PT->castAs()->getDecl();
-  VisitStack.push_back(PD);
+  // At this point we already handled everything except of a RecordType or
+  // an ArrayType[RecordType].

asavonic wrote:
> Anastasia wrote:
> > Anastasia wrote:
> > > I am a bit confused about this comment, `do you mean a PointerType to a 
> > > RecordType or an ArrayType of a RecordType`?
> > Also is there any test case covering this change?
> ArrayType of a RecordType. Fixed.
I added 2 tests for this change in https://reviews.llvm.org/D49723.



Comment at: lib/Sema/SemaDecl.cpp:8189
+  const RecordType *RecTy =
+  PT->getPointeeOrArrayElementType()->getAs();
+  const RecordDecl *OrigRecDecl = RecTy->getDecl();

Anastasia wrote:
> yaxunl wrote:
> > Can we have a test for this change? e.g. an array of structs
> I am wondering if `PT->getPointeeOrArrayElementType()` is `nullptr`? Do we 
> need to add an extra check?
Added in https://reviews.llvm.org/D49723.



Comment at: lib/Sema/SemaDecl.cpp:8189
+  const RecordType *RecTy =
+  PT->getPointeeOrArrayElementType()->getAs();
+  const RecordDecl *OrigRecDecl = RecTy->getDecl();

asavonic wrote:
> Anastasia wrote:
> > yaxunl wrote:
> > > Can we have a test for this change? e.g. an array of structs
> > I am wondering if `PT->getPointeeOrArrayElementType()` is `nullptr`? Do we 
> > need to add an extra check?
> Added in https://reviews.llvm.org/D49723.
It should not return null, unless the PT is null:
https://clang.llvm.org/doxygen/Type_8h_source.html#l06487



Repository:
  rC Clang

https://reviews.llvm.org/D49725



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


Re: r337790 - Warn if a local variable's initializer retains a pointer/reference to a

2018-07-25 Thread Eric Fiselier via cfe-commits
Nice!

This found one bug in the libc++abi tests (r337906), and started diagnosing
the
dangling tuple reference case that libc++ worked hard to diagnose manually
(r337905).

/Eric

On Mon, Jul 23, 2018 at 6:55 PM Richard Smith via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: rsmith
> Date: Mon Jul 23 17:55:08 2018
> New Revision: 337790
>
> URL: http://llvm.org/viewvc/llvm-project?rev=337790&view=rev
> Log:
> Warn if a local variable's initializer retains a pointer/reference to a
> non-lifetime-extended temporary object.
>
> Added:
> cfe/trunk/test/SemaCXX/warn-dangling-local.cpp
> Modified:
> cfe/trunk/include/clang/Basic/DiagnosticGroups.td
> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> cfe/trunk/lib/Sema/SemaInit.cpp
> cfe/trunk/test/CXX/drs/dr16xx.cpp
> cfe/trunk/test/SemaCXX/address-of-temporary.cpp
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=337790&r1=337789&r2=337790&view=diff
>
> ==
> --- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Mon Jul 23 17:55:08
> 2018
> @@ -273,6 +273,10 @@ def OverloadedShiftOpParentheses: DiagGr
>  def DanglingElse: DiagGroup<"dangling-else">;
>  def DanglingField : DiagGroup<"dangling-field">;
>  def DanglingInitializerList : DiagGroup<"dangling-initializer-list">;
> +def ReturnStackAddress : DiagGroup<"return-stack-address">;
> +def Dangling : DiagGroup<"dangling", [DanglingField,
> +  DanglingInitializerList,
> +  ReturnStackAddress]>;
>  def DistributedObjectModifiers :
> DiagGroup<"distributed-object-modifiers">;
>  def ExpansionToDefined : DiagGroup<"expansion-to-defined">;
>  def FlagEnum : DiagGroup<"flag-enum">;
> @@ -407,7 +411,6 @@ def RedeclaredClassMember : DiagGroup<"r
>  def GNURedeclaredEnum : DiagGroup<"gnu-redeclared-enum">;
>  def RedundantMove : DiagGroup<"redundant-move">;
>  def Register : DiagGroup<"register", [DeprecatedRegister]>;
> -def ReturnStackAddress : DiagGroup<"return-stack-address">;
>  def ReturnTypeCLinkage : DiagGroup<"return-type-c-linkage">;
>  def ReturnType : DiagGroup<"return-type", [ReturnTypeCLinkage]>;
>  def BindToTemporaryCopy : DiagGroup<"bind-to-temporary-copy",
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=337790&r1=337789&r2=337790&view=diff
>
> ==
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Jul 23
> 17:55:08 2018
> @@ -1845,10 +1845,6 @@ def err_reference_bind_failed : Error<
>"type $|could not bind to %select{rvalue|lvalue}1 of incompatible
> type}0,2">;
>  def err_reference_bind_init_list : Error<
>"reference to type %0 cannot bind to an initializer list">;
> -def warn_temporary_array_to_pointer_decay : Warning<
> -  "pointer is initialized by a temporary array, which will be destroyed
> at the "
> -  "end of the full-expression">,
> -  InGroup>;
>  def err_init_list_bad_dest_type : Error<
>"%select{|non-aggregate }0type %1 cannot be initialized with an
> initializer "
>"list">;
> @@ -7876,15 +7872,31 @@ def warn_init_ptr_member_to_parameter_ad
>  def note_ref_or_ptr_member_declared_here : Note<
>"%select{reference|pointer}0 member declared here">;
>
> -def err_bind_ref_member_to_temporary : Error<
> +def err_dangling_member : Error<
>"%select{reference|backing array for 'std::initializer_list'}2 "
>"%select{|subobject of }1member %0 "
>"%select{binds to|is}2 a temporary object "
> -  "whose lifetime would be shorter than the constructed object">;
> +  "whose lifetime would be shorter than the lifetime of "
> +  "the constructed object">;
> +def warn_dangling_member : Warning<
> +  "%select{reference|backing array for 'std::initializer_list'}2 "
> +  "%select{|subobject of }1member %0 "
> +  "%select{binds to|is}2 a temporary object "
> +  "whose lifetime is shorter than the lifetime of the constructed
> object">,
> +  InGroup;
>  def note_lifetime_extending_member_declared_here : Note<
>"%select{%select{reference|'std::initializer_list'}0 member|"
>"member with %select{reference|'std::initializer_list'}0 subobject}1 "
>"declared here">;
> +def warn_dangling_variable : Warning<
> +  "%select{temporary %select{whose address is used as value of|bound to}3
> "
> +  "%select{%select{|reference }3member of local variable|"
> +  "local %select{variable|reference}3}1|"
> +  "array backing "
> +  "%select{initializer list subobject of local variable|"
> +  "local initializer list}1}0 "
> +  "%2 will be destroyed at the e

[PATCH] D49780: [clangd] Use a sigmoid style function for #usages boost in symbol quality.

2018-07-25 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 157225.
ioeric added a comment.

s/better/nicely/


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D49780

Files:
  clangd/Quality.cpp
  unittests/clangd/CodeCompleteTests.cpp


Index: unittests/clangd/CodeCompleteTests.cpp
===
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -476,11 +476,12 @@
 }
 
 TEST(CompletionTest, ReferencesAffectRanking) {
-  auto Results = completions("int main() { abs^ }", {ns("absl"), func("abs")});
-  EXPECT_THAT(Results.Completions, HasSubsequence(Named("abs"), 
Named("absl")));
+  auto Results = completions("int main() { abs^ }", {ns("absl"), 
func("absb")});
+  EXPECT_THAT(Results.Completions, HasSubsequence(Named("absb"), 
Named("absl")));
   Results = completions("int main() { abs^ }",
-{withReferences(1, ns("absl")), func("abs")});
-  EXPECT_THAT(Results.Completions, HasSubsequence(Named("absl"), 
Named("abs")));
+{withReferences(1, ns("absl")), func("absb")});
+  EXPECT_THAT(Results.Completions,
+  HasSubsequence(Named("absl"), Named("absb")));
 }
 
 TEST(CompletionTest, GlobalQualified) {
Index: clangd/Quality.cpp
===
--- clangd/Quality.cpp
+++ clangd/Quality.cpp
@@ -190,8 +190,18 @@
 
   // This avoids a sharp gradient for tail symbols, and also neatly avoids the
   // question of whether 0 references means a bad symbol or missing data.
-  if (References >= 10)
-Score *= std::log10(References);
+  if (References >= 10) {
+// Use a sigmoid style boosting function, which flats out nicely for large
+// numbers (e.g. 2.58 for 1M refererences).
+// The following boosting function is equivalent to:
+//   m = 0.06
+//   f = 12.0
+//   boost = f * sigmoid(m * std::log(References)) - 0.5 * f + 0.59
+// Sample data points: (10, 1.00), (100, 1.41), (1000, 1.82),
+// (10K, 2.21), (100K, 2.58), (1M, 2.94)
+float s = std::pow(References, -0.06);
+Score *= 6.0 * (1 - s) / (1 + s) + 0.59;
+  }
 
   if (Deprecated)
 Score *= 0.1f;


Index: unittests/clangd/CodeCompleteTests.cpp
===
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -476,11 +476,12 @@
 }
 
 TEST(CompletionTest, ReferencesAffectRanking) {
-  auto Results = completions("int main() { abs^ }", {ns("absl"), func("abs")});
-  EXPECT_THAT(Results.Completions, HasSubsequence(Named("abs"), Named("absl")));
+  auto Results = completions("int main() { abs^ }", {ns("absl"), func("absb")});
+  EXPECT_THAT(Results.Completions, HasSubsequence(Named("absb"), Named("absl")));
   Results = completions("int main() { abs^ }",
-{withReferences(1, ns("absl")), func("abs")});
-  EXPECT_THAT(Results.Completions, HasSubsequence(Named("absl"), Named("abs")));
+{withReferences(1, ns("absl")), func("absb")});
+  EXPECT_THAT(Results.Completions,
+  HasSubsequence(Named("absl"), Named("absb")));
 }
 
 TEST(CompletionTest, GlobalQualified) {
Index: clangd/Quality.cpp
===
--- clangd/Quality.cpp
+++ clangd/Quality.cpp
@@ -190,8 +190,18 @@
 
   // This avoids a sharp gradient for tail symbols, and also neatly avoids the
   // question of whether 0 references means a bad symbol or missing data.
-  if (References >= 10)
-Score *= std::log10(References);
+  if (References >= 10) {
+// Use a sigmoid style boosting function, which flats out nicely for large
+// numbers (e.g. 2.58 for 1M refererences).
+// The following boosting function is equivalent to:
+//   m = 0.06
+//   f = 12.0
+//   boost = f * sigmoid(m * std::log(References)) - 0.5 * f + 0.59
+// Sample data points: (10, 1.00), (100, 1.41), (1000, 1.82),
+// (10K, 2.21), (100K, 2.58), (1M, 2.94)
+float s = std::pow(References, -0.06);
+Score *= 6.0 * (1 - s) / (1 + s) + 0.59;
+  }
 
   if (Deprecated)
 Score *= 0.1f;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r337907 - [clangd] Use a sigmoid style function for #usages boost in symbol quality.

2018-07-25 Thread Eric Liu via cfe-commits
Author: ioeric
Date: Wed Jul 25 04:26:35 2018
New Revision: 337907

URL: http://llvm.org/viewvc/llvm-project?rev=337907&view=rev
Log:
[clangd] Use a sigmoid style function for #usages boost in symbol quality.

Summary:
This has a shape to similar logarithm function but grows much slower for
large #usages.

Metrics: https://reviews.llvm.org/P8096

Reviewers: ilya-biryukov

Reviewed By: ilya-biryukov

Subscribers: MaskRay, jkorous, arphaman, cfe-commits, sammccall

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

Modified:
clang-tools-extra/trunk/clangd/Quality.cpp
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp

Modified: clang-tools-extra/trunk/clangd/Quality.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Quality.cpp?rev=337907&r1=337906&r2=337907&view=diff
==
--- clang-tools-extra/trunk/clangd/Quality.cpp (original)
+++ clang-tools-extra/trunk/clangd/Quality.cpp Wed Jul 25 04:26:35 2018
@@ -190,8 +190,18 @@ float SymbolQualitySignals::evaluate() c
 
   // This avoids a sharp gradient for tail symbols, and also neatly avoids the
   // question of whether 0 references means a bad symbol or missing data.
-  if (References >= 10)
-Score *= std::log10(References);
+  if (References >= 10) {
+// Use a sigmoid style boosting function, which flats out nicely for large
+// numbers (e.g. 2.58 for 1M refererences).
+// The following boosting function is equivalent to:
+//   m = 0.06
+//   f = 12.0
+//   boost = f * sigmoid(m * std::log(References)) - 0.5 * f + 0.59
+// Sample data points: (10, 1.00), (100, 1.41), (1000, 1.82),
+// (10K, 2.21), (100K, 2.58), (1M, 2.94)
+float s = std::pow(References, -0.06);
+Score *= 6.0 * (1 - s) / (1 + s) + 0.59;
+  }
 
   if (Deprecated)
 Score *= 0.1f;

Modified: clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp?rev=337907&r1=337906&r2=337907&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Wed Jul 25 
04:26:35 2018
@@ -476,11 +476,12 @@ TEST(CompletionTest, ScopedWithFilter) {
 }
 
 TEST(CompletionTest, ReferencesAffectRanking) {
-  auto Results = completions("int main() { abs^ }", {ns("absl"), func("abs")});
-  EXPECT_THAT(Results.Completions, HasSubsequence(Named("abs"), 
Named("absl")));
+  auto Results = completions("int main() { abs^ }", {ns("absl"), 
func("absb")});
+  EXPECT_THAT(Results.Completions, HasSubsequence(Named("absb"), 
Named("absl")));
   Results = completions("int main() { abs^ }",
-{withReferences(1, ns("absl")), func("abs")});
-  EXPECT_THAT(Results.Completions, HasSubsequence(Named("absl"), 
Named("abs")));
+{withReferences(1, ns("absl")), func("absb")});
+  EXPECT_THAT(Results.Completions,
+  HasSubsequence(Named("absl"), Named("absb")));
 }
 
 TEST(CompletionTest, GlobalQualified) {


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


[PATCH] D49780: [clangd] Use a sigmoid style function for #usages boost in symbol quality.

2018-07-25 Thread Eric Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE337907: [clangd] Use a sigmoid style function for #usages 
boost in symbol quality. (authored by ioeric, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D49780?vs=157225&id=157226#toc

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D49780

Files:
  clangd/Quality.cpp
  unittests/clangd/CodeCompleteTests.cpp


Index: clangd/Quality.cpp
===
--- clangd/Quality.cpp
+++ clangd/Quality.cpp
@@ -190,8 +190,18 @@
 
   // This avoids a sharp gradient for tail symbols, and also neatly avoids the
   // question of whether 0 references means a bad symbol or missing data.
-  if (References >= 10)
-Score *= std::log10(References);
+  if (References >= 10) {
+// Use a sigmoid style boosting function, which flats out nicely for large
+// numbers (e.g. 2.58 for 1M refererences).
+// The following boosting function is equivalent to:
+//   m = 0.06
+//   f = 12.0
+//   boost = f * sigmoid(m * std::log(References)) - 0.5 * f + 0.59
+// Sample data points: (10, 1.00), (100, 1.41), (1000, 1.82),
+// (10K, 2.21), (100K, 2.58), (1M, 2.94)
+float s = std::pow(References, -0.06);
+Score *= 6.0 * (1 - s) / (1 + s) + 0.59;
+  }
 
   if (Deprecated)
 Score *= 0.1f;
Index: unittests/clangd/CodeCompleteTests.cpp
===
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -476,11 +476,12 @@
 }
 
 TEST(CompletionTest, ReferencesAffectRanking) {
-  auto Results = completions("int main() { abs^ }", {ns("absl"), func("abs")});
-  EXPECT_THAT(Results.Completions, HasSubsequence(Named("abs"), 
Named("absl")));
+  auto Results = completions("int main() { abs^ }", {ns("absl"), 
func("absb")});
+  EXPECT_THAT(Results.Completions, HasSubsequence(Named("absb"), 
Named("absl")));
   Results = completions("int main() { abs^ }",
-{withReferences(1, ns("absl")), func("abs")});
-  EXPECT_THAT(Results.Completions, HasSubsequence(Named("absl"), 
Named("abs")));
+{withReferences(1, ns("absl")), func("absb")});
+  EXPECT_THAT(Results.Completions,
+  HasSubsequence(Named("absl"), Named("absb")));
 }
 
 TEST(CompletionTest, GlobalQualified) {


Index: clangd/Quality.cpp
===
--- clangd/Quality.cpp
+++ clangd/Quality.cpp
@@ -190,8 +190,18 @@
 
   // This avoids a sharp gradient for tail symbols, and also neatly avoids the
   // question of whether 0 references means a bad symbol or missing data.
-  if (References >= 10)
-Score *= std::log10(References);
+  if (References >= 10) {
+// Use a sigmoid style boosting function, which flats out nicely for large
+// numbers (e.g. 2.58 for 1M refererences).
+// The following boosting function is equivalent to:
+//   m = 0.06
+//   f = 12.0
+//   boost = f * sigmoid(m * std::log(References)) - 0.5 * f + 0.59
+// Sample data points: (10, 1.00), (100, 1.41), (1000, 1.82),
+// (10K, 2.21), (100K, 2.58), (1M, 2.94)
+float s = std::pow(References, -0.06);
+Score *= 6.0 * (1 - s) / (1 + s) + 0.59;
+  }
 
   if (Deprecated)
 Score *= 0.1f;
Index: unittests/clangd/CodeCompleteTests.cpp
===
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -476,11 +476,12 @@
 }
 
 TEST(CompletionTest, ReferencesAffectRanking) {
-  auto Results = completions("int main() { abs^ }", {ns("absl"), func("abs")});
-  EXPECT_THAT(Results.Completions, HasSubsequence(Named("abs"), Named("absl")));
+  auto Results = completions("int main() { abs^ }", {ns("absl"), func("absb")});
+  EXPECT_THAT(Results.Completions, HasSubsequence(Named("absb"), Named("absl")));
   Results = completions("int main() { abs^ }",
-{withReferences(1, ns("absl")), func("abs")});
-  EXPECT_THAT(Results.Completions, HasSubsequence(Named("absl"), Named("abs")));
+{withReferences(1, ns("absl")), func("absb")});
+  EXPECT_THAT(Results.Completions,
+  HasSubsequence(Named("absl"), Named("absb")));
 }
 
 TEST(CompletionTest, GlobalQualified) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r337746 - [clang-cl] Expose -fblocks and -fno-builtin as driver flags

2018-07-25 Thread Nico Weber via cfe-commits
I thought about adding -fblocks when that thread happened, but since
there's no runtime for them that just works exposing it doesn't seem very
helpful. Maybe we should instead change the warning text to not suggest
-fblocks when building on a non-mac target?

On Mon, Jul 23, 2018 at 5:29 PM Reid Kleckner via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: rnk
> Date: Mon Jul 23 14:29:43 2018
> New Revision: 337746
>
> URL: http://llvm.org/viewvc/llvm-project?rev=337746&view=rev
> Log:
> [clang-cl] Expose -fblocks and -fno-builtin as driver flags
>
> Users have requested them.
>
> Helps with PR36427.
>
> Modified:
> cfe/trunk/include/clang/Driver/Options.td
> cfe/trunk/test/Driver/cl-options.c
>
> Modified: cfe/trunk/include/clang/Driver/Options.td
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=337746&r1=337745&r2=337746&view=diff
>
> ==
> --- cfe/trunk/include/clang/Driver/Options.td (original)
> +++ cfe/trunk/include/clang/Driver/Options.td Mon Jul 23 14:29:43 2018
> @@ -762,12 +762,12 @@ def faddrsig : Flag<["-"], "faddrsig">,
>HelpText<"Emit an address-significance table">;
>  def fno_addrsig : Flag<["-"], "fno-addrsig">, Group,
> Flags<[CoreOption]>,
>HelpText<"Don't emit an address-significance table">;
> -def fblocks : Flag<["-"], "fblocks">, Group, Flags<[CC1Option]>,
> +def fblocks : Flag<["-"], "fblocks">, Group, Flags<[CoreOption,
> CC1Option]>,
>HelpText<"Enable the 'blocks' language feature">;
>  def fbootclasspath_EQ : Joined<["-"], "fbootclasspath=">, Group;
>  def fborland_extensions : Flag<["-"], "fborland-extensions">,
> Group, Flags<[CC1Option]>,
>HelpText<"Accept non-standard constructs supported by the Borland
> compiler">;
> -def fbuiltin : Flag<["-"], "fbuiltin">, Group;
> +def fbuiltin : Flag<["-"], "fbuiltin">, Group,
> Flags<[CoreOption]>;
>  def fbuiltin_module_map : Flag <["-"], "fbuiltin-module-map">,
> Group,
>Flags<[DriverOption]>, HelpText<"Load the clang builtins module map
> file.">;
>  def fcaret_diagnostics : Flag<["-"], "fcaret-diagnostics">,
> Group;
> @@ -1320,11 +1320,11 @@ def fno_asynchronous_unwind_tables : Fla
>  def fno_assume_sane_operator_new : Flag<["-"],
> "fno-assume-sane-operator-new">, Group,
>HelpText<"Don't assume that C++'s global operator new can't alias any
> pointer">,
>Flags<[CC1Option]>;
> -def fno_blocks : Flag<["-"], "fno-blocks">, Group;
> +def fno_blocks : Flag<["-"], "fno-blocks">, Group,
> Flags<[CoreOption]>;
>  def fno_borland_extensions : Flag<["-"], "fno-borland-extensions">,
> Group;
> -def fno_builtin : Flag<["-"], "fno-builtin">, Group,
> Flags<[CC1Option]>,
> +def fno_builtin : Flag<["-"], "fno-builtin">, Group,
> Flags<[CC1Option, CoreOption]>,
>HelpText<"Disable implicit builtin knowledge of functions">;
> -def fno_builtin_ : Joined<["-"], "fno-builtin-">, Group,
> Flags<[CC1Option]>,
> +def fno_builtin_ : Joined<["-"], "fno-builtin-">, Group,
> Flags<[CC1Option, CoreOption]>,
>HelpText<"Disable implicit builtin knowledge of a specific function">;
>  def fno_caret_diagnostics : Flag<["-"], "fno-caret-diagnostics">,
> Group,
>   Flags<[CC1Option]>;
>
> Modified: cfe/trunk/test/Driver/cl-options.c
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/cl-options.c?rev=337746&r1=337745&r2=337746&view=diff
>
> ==
> --- cfe/trunk/test/Driver/cl-options.c (original)
> +++ cfe/trunk/test/Driver/cl-options.c Mon Jul 23 14:29:43 2018
> @@ -565,6 +565,11 @@
>  // (/Zs is for syntax-only, -Werror makes it fail hard on unknown options)
>  // RUN: %clang_cl \
>  // RUN: --driver-mode=cl \
> +// RUN: -fblocks \
> +// RUN: -fno-blocks \
> +// RUN: -fbuiltin \
> +// RUN: -fno-builtin \
> +// RUN: -fno-builtin-strcpy \
>  // RUN: -fcolor-diagnostics \
>  // RUN: -fno-color-diagnostics \
>  // RUN: -fcoverage-mapping \
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D49785: [clangd] Give an example for global-symbol-builder usage

2018-07-25 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev created this revision.
kbobyrev added reviewers: ioeric, ilya-biryukov.
kbobyrev added a project: clang-tools-extra.
Herald added subscribers: arphaman, jkorous, MaskRay.

`global-symbol-builder` help message mentions `-executor=` option, but 
doesn't give any example of what the value could be

Assuming the most popular use case to be building the whole project index, help 
message should probably give an example of such usage.


https://reviews.llvm.org/D49785

Files:
  clang-tools-extra/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp


Index: 
clang-tools-extra/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
===
--- clang-tools-extra/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
+++ clang-tools-extra/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
@@ -150,10 +150,16 @@
 int main(int argc, const char **argv) {
   llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
 
-  const char* Overview =
-  "This is an **experimental** tool to generate YAML-format "
-  "project-wide symbols for clangd (global code completion). It would be "
-  "changed and deprecated eventually. Don't use it in production code!";
+  const auto Overview = R"(
+  This is an **experimental** tool to generate YAML-format project-wide symbols
+  for clangd (global code completion). It would be changed and deprecated
+  eventually. Don't use it in production code!
+
+  Example usage for building index for the whole project:
+
+  $ global-symbol-builder --executor=all-TUs compile_commands.json > index.yaml
+  )";
+
   auto Executor = clang::tooling::createExecutorFromCommandLineArgs(
   argc, argv, cl::GeneralCategory, Overview);
 


Index: clang-tools-extra/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
===
--- clang-tools-extra/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
+++ clang-tools-extra/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
@@ -150,10 +150,16 @@
 int main(int argc, const char **argv) {
   llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
 
-  const char* Overview =
-  "This is an **experimental** tool to generate YAML-format "
-  "project-wide symbols for clangd (global code completion). It would be "
-  "changed and deprecated eventually. Don't use it in production code!";
+  const auto Overview = R"(
+  This is an **experimental** tool to generate YAML-format project-wide symbols
+  for clangd (global code completion). It would be changed and deprecated
+  eventually. Don't use it in production code!
+
+  Example usage for building index for the whole project:
+
+  $ global-symbol-builder --executor=all-TUs compile_commands.json > index.yaml
+  )";
+
   auto Executor = clang::tooling::createExecutorFromCommandLineArgs(
   argc, argv, cl::GeneralCategory, Overview);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D49701: [ASTMatchers] Introduce a matcher for `ObjCIvarExpr`, support getting it's declaration

2018-07-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

The docs do not look correct to me. For instance, I don't see any changes to 
the `hasDeclaration()` documentation for the newly supported type. There also 
appear to be a bunch of unrelated changes in the generated HTML.




Comment at: clang/docs/LibASTMatchersReference.html:3292-3294
+  [x containsString:@"h"];
 but not
+  [NSString stringWithFormat:@"format"];

I thought these changes already went in as a separate commit? These are 
unrelated to the patch.



Comment at: clang/include/clang/ASTMatchers/ASTMatchersInternal.h:44
 #include "clang/AST/Expr.h"
+#include "clang/AST/ExprObjC.h"
 #include "clang/AST/ExprCXX.h"

This list should remain sorted alphabetically.


https://reviews.llvm.org/D49701



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


[PATCH] D49785: [clangd] Give an example for global-symbol-builder usage

2018-07-25 Thread Eric Liu via Phabricator via cfe-commits
ioeric accepted this revision.
ioeric added inline comments.
This revision is now accepted and ready to land.



Comment at: 
clang-tools-extra/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp:153
 
-  const char* Overview =
-  "This is an **experimental** tool to generate YAML-format "
-  "project-wide symbols for clangd (global code completion). It would be "
-  "changed and deprecated eventually. Don't use it in production code!";
+  const auto Overview = R"(
+  This is an **experimental** tool to generate YAML-format project-wide symbols

why replace `char *` with `auto`? I'd keep char * as it's clearer and short 
enough.



Comment at: 
clang-tools-extra/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp:158
+
+  Example usage for building index for the whole project:
+

Maybe also give an example for running on one file?


https://reviews.llvm.org/D49785



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


[PATCH] D49788: [Docs] Update supported oses for ubsan, asan and msan

2018-07-25 Thread David CARLIER via Phabricator via cfe-commits
devnexen created this revision.
devnexen added reviewers: morehouse, krytarowski.
devnexen created this object with visibility "All Users".
Herald added a subscriber: cfe-commits.

Repository:
  rC Clang

https://reviews.llvm.org/D49788

Files:
  docs/AddressSanitizer.rst
  docs/MemorySanitizer.rst
  docs/UndefinedBehaviorSanitizer.rst


Index: docs/UndefinedBehaviorSanitizer.rst
===
--- docs/UndefinedBehaviorSanitizer.rst
+++ docs/UndefinedBehaviorSanitizer.rst
@@ -253,6 +253,7 @@
 * Android
 * Linux
 * FreeBSD
+* OpenBSD
 * OS X 10.6 onwards
 
 and for the following architectures:
Index: docs/MemorySanitizer.rst
===
--- docs/MemorySanitizer.rst
+++ docs/MemorySanitizer.rst
@@ -185,7 +185,15 @@
 Supported Platforms
 ===
 
-MemorySanitizer is supported on Linux x86\_64/MIPS64/AArch64.
+MemorySanitizer is supported on the following OS:
+
+* Linux 
+* NetBSD
+* FreeBSD
+  
+and for the following architectures:
+
+* x86\_64/MIPS64/AArch64.
 
 Limitations
 ===
Index: docs/AddressSanitizer.rst
===
--- docs/AddressSanitizer.rst
+++ docs/AddressSanitizer.rst
@@ -276,6 +276,7 @@
 * OS X 10.7 - 10.11 (i386/x86\_64)
 * iOS Simulator
 * Android ARM
+* NetBSD i386/x86\_64
 * FreeBSD i386/x86\_64 (tested on FreeBSD 11-current)
 
 Ports to various other platforms are in progress.


Index: docs/UndefinedBehaviorSanitizer.rst
===
--- docs/UndefinedBehaviorSanitizer.rst
+++ docs/UndefinedBehaviorSanitizer.rst
@@ -253,6 +253,7 @@
 * Android
 * Linux
 * FreeBSD
+* OpenBSD
 * OS X 10.6 onwards
 
 and for the following architectures:
Index: docs/MemorySanitizer.rst
===
--- docs/MemorySanitizer.rst
+++ docs/MemorySanitizer.rst
@@ -185,7 +185,15 @@
 Supported Platforms
 ===
 
-MemorySanitizer is supported on Linux x86\_64/MIPS64/AArch64.
+MemorySanitizer is supported on the following OS:
+
+* Linux 
+* NetBSD
+* FreeBSD
+  
+and for the following architectures:
+
+* x86\_64/MIPS64/AArch64.
 
 Limitations
 ===
Index: docs/AddressSanitizer.rst
===
--- docs/AddressSanitizer.rst
+++ docs/AddressSanitizer.rst
@@ -276,6 +276,7 @@
 * OS X 10.7 - 10.11 (i386/x86\_64)
 * iOS Simulator
 * Android ARM
+* NetBSD i386/x86\_64
 * FreeBSD i386/x86\_64 (tested on FreeBSD 11-current)
 
 Ports to various other platforms are in progress.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D49788: [Docs] Update supported oses for ubsan, asan and msan

2018-07-25 Thread David CARLIER via Phabricator via cfe-commits
devnexen added a comment.

This is the first time I m involved into a release so I do not know if it s too 
early to update those docs but with the freeze incoming, I thought it was worth 
before it get forgotten.


Repository:
  rC Clang

https://reviews.llvm.org/D49788



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


[PATCH] D49790: [AST] Small doc update for DeclContext

2018-07-25 Thread Bruno Ricci via Phabricator via cfe-commits
bricci created this revision.
bricci added a project: clang.
Herald added a subscriber: cfe-commits.

Factored out from https://reviews.llvm.org/D49729
following @erichkeane comments.

- Add missing classes in the list of classes deriving directly from DeclContext.
- Move the friend declarations together and add a comment for why they are 
required. Also remove a friend declaration which is not needed.


Repository:
  rC Clang

https://reviews.llvm.org/D49790

Files:
  include/clang/AST/DeclBase.h


Index: include/clang/AST/DeclBase.h
===
--- include/clang/AST/DeclBase.h
+++ include/clang/AST/DeclBase.h
@@ -1250,16 +1250,25 @@
 /// that directly derive from DeclContext are mentioned, not their subclasses):
 ///
 ///   TranslationUnitDecl
+///   ExternCContext
 ///   NamespaceDecl
-///   FunctionDecl
 ///   TagDecl
+///   OMPDeclareReductionDecl
+///   FunctionDecl
 ///   ObjCMethodDecl
 ///   ObjCContainerDecl
 ///   LinkageSpecDecl
 ///   ExportDecl
 ///   BlockDecl
-///   OMPDeclareReductionDecl
+///   CapturedDecl
 class DeclContext {
+  /// For makeDeclVisibleInContextImpl
+  friend class ASTDeclReader;
+  /// For reconcileExternalVisibleStorage, CreateStoredDeclsMap
+  friend class ExternalASTSource;
+  /// For CreateStoredDeclsMap
+  friend class DependentDiagnostic;
+
   // We use uint64_t in the bit-fields below since some bit-fields
   // cross the unsigned boundary and this breaks the packing.
 
@@ -1709,10 +1718,6 @@
   "BlockDeclBitfields is larger than 8 bytes!");
   };
 
-  friend class ASTDeclReader;
-  friend class ASTWriter;
-  friend class ExternalASTSource;
-
   /// FirstDecl - The first declaration stored within this declaration
   /// context.
   mutable Decl *FirstDecl = nullptr;
@@ -2391,8 +2396,6 @@
 DeclContextBits.HasLazyExternalLexicalLookups = HasLELL;
   }
 
-  friend class DependentDiagnostic;
-
   void reconcileExternalVisibleStorage() const;
   bool LoadLexicalDeclsFromExternalStorage() const;
 


Index: include/clang/AST/DeclBase.h
===
--- include/clang/AST/DeclBase.h
+++ include/clang/AST/DeclBase.h
@@ -1250,16 +1250,25 @@
 /// that directly derive from DeclContext are mentioned, not their subclasses):
 ///
 ///   TranslationUnitDecl
+///   ExternCContext
 ///   NamespaceDecl
-///   FunctionDecl
 ///   TagDecl
+///   OMPDeclareReductionDecl
+///   FunctionDecl
 ///   ObjCMethodDecl
 ///   ObjCContainerDecl
 ///   LinkageSpecDecl
 ///   ExportDecl
 ///   BlockDecl
-///   OMPDeclareReductionDecl
+///   CapturedDecl
 class DeclContext {
+  /// For makeDeclVisibleInContextImpl
+  friend class ASTDeclReader;
+  /// For reconcileExternalVisibleStorage, CreateStoredDeclsMap
+  friend class ExternalASTSource;
+  /// For CreateStoredDeclsMap
+  friend class DependentDiagnostic;
+
   // We use uint64_t in the bit-fields below since some bit-fields
   // cross the unsigned boundary and this breaks the packing.
 
@@ -1709,10 +1718,6 @@
   "BlockDeclBitfields is larger than 8 bytes!");
   };
 
-  friend class ASTDeclReader;
-  friend class ASTWriter;
-  friend class ExternalASTSource;
-
   /// FirstDecl - The first declaration stored within this declaration
   /// context.
   mutable Decl *FirstDecl = nullptr;
@@ -2391,8 +2396,6 @@
 DeclContextBits.HasLazyExternalLexicalLookups = HasLELL;
   }
 
-  friend class DependentDiagnostic;
-
   void reconcileExternalVisibleStorage() const;
   bool LoadLexicalDeclsFromExternalStorage() const;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D49729: [AST][1/4] Move the bit-fields from TagDecl, EnumDecl and RecordDecl into DeclContext

2018-07-25 Thread Bruno Ricci via Phabricator via cfe-commits
bricci updated this revision to Diff 157231.
bricci marked 10 inline comments as done.
bricci added a comment.

address @erichkeane comments:

- ran clang-format on changed parts
- made the setters setNumPositiveBits, setNumPositiveBits, setScoped, 
setScopedUsingClassTag and setFixed in EnumDecl private.
- made the setters setBeingDefined and setBeingDefined in TagDecl protected
- moved the static_asserts to the anonymous union
- factored out the doc update of DeclBase. This is now 
https://reviews.llvm.org/D49790
- various typos


Repository:
  rC Clang

https://reviews.llvm.org/D49729

Files:
  include/clang/AST/Decl.h
  include/clang/AST/DeclBase.h
  lib/AST/Decl.cpp
  lib/AST/DeclBase.cpp
  lib/AST/DeclCXX.cpp
  lib/AST/DeclTemplate.cpp
  lib/Serialization/ASTReaderDecl.cpp
  lib/Serialization/ASTWriter.cpp
  lib/Serialization/ASTWriterDecl.cpp

Index: lib/Serialization/ASTWriterDecl.cpp
===
--- lib/Serialization/ASTWriterDecl.cpp
+++ lib/Serialization/ASTWriterDecl.cpp
@@ -1273,7 +1273,7 @@
 
   // Store (what we currently believe to be) the key function to avoid
   // deserializing every method so we can compute it.
-  if (D->IsCompleteDefinition)
+  if (D->isCompleteDefinition())
 Record.AddDeclRef(Context.getCurrentKeyFunction(D));
 
   Code = serialization::DECL_CXX_RECORD;
Index: lib/Serialization/ASTWriter.cpp
===
--- lib/Serialization/ASTWriter.cpp
+++ lib/Serialization/ASTWriter.cpp
@@ -3960,7 +3960,8 @@
 
 bool ASTWriter::isLookupResultExternal(StoredDeclsList &Result,
DeclContext *DC) {
-  return Result.hasExternalDecls() && DC->NeedToReconcileExternalVisibleStorage;
+  return Result.hasExternalDecls() &&
+ DC->hasNeedToReconcileExternalVisibleStorage();
 }
 
 bool ASTWriter::isLookupResultEntirelyExternal(StoredDeclsList &Result,
@@ -3975,8 +3976,8 @@
 void
 ASTWriter::GenerateNameLookupTable(const DeclContext *ConstDC,
llvm::SmallVectorImpl &LookupTable) {
-  assert(!ConstDC->HasLazyLocalLexicalLookups &&
- !ConstDC->HasLazyExternalLexicalLookups &&
+  assert(!ConstDC->hasLazyLocalLexicalLookups() &&
+ !ConstDC->hasLazyExternalLexicalLookups() &&
  "must call buildLookups first");
 
   // FIXME: We need to build the lookups table, which is logically const.
Index: lib/Serialization/ASTReaderDecl.cpp
===
--- lib/Serialization/ASTReaderDecl.cpp
+++ lib/Serialization/ASTReaderDecl.cpp
@@ -742,13 +742,13 @@
   ED->setPromotionType(Record.readType());
   ED->setNumPositiveBits(Record.readInt());
   ED->setNumNegativeBits(Record.readInt());
-  ED->IsScoped = Record.readInt();
-  ED->IsScopedUsingClassTag = Record.readInt();
-  ED->IsFixed = Record.readInt();
+  ED->setScoped(Record.readInt());
+  ED->setScopedUsingClassTag(Record.readInt());
+  ED->setFixed(Record.readInt());
 
   // If this is a definition subject to the ODR, and we already have a
   // definition, merge this one into it.
-  if (ED->IsCompleteDefinition &&
+  if (ED->isCompleteDefinition() &&
   Reader.getContext().getLangOpts().Modules &&
   Reader.getContext().getLangOpts().CPlusPlus) {
 EnumDecl *&OldDef = Reader.EnumDefinitions[ED->getCanonicalDecl()];
@@ -764,7 +764,7 @@
 }
 if (OldDef) {
   Reader.MergedDeclContexts.insert(std::make_pair(ED, OldDef));
-  ED->IsCompleteDefinition = false;
+  ED->setCompleteDefinition(false);
   Reader.mergeDefinitionVisibility(OldDef, ED);
 } else {
   OldDef = ED;
@@ -1739,7 +1739,7 @@
 Reader.MergedDeclContexts.insert(std::make_pair(MergeDD.Definition,
 DD.Definition));
 Reader.PendingDefinitions.erase(MergeDD.Definition);
-MergeDD.Definition->IsCompleteDefinition = false;
+MergeDD.Definition->setCompleteDefinition(false);
 Reader.mergeDefinitionVisibility(DD.Definition, MergeDD.Definition);
 assert(Reader.Lookups.find(MergeDD.Definition) == Reader.Lookups.end() &&
"already loaded pending lookups for merged definition");
@@ -1879,7 +1879,7 @@
   }
 
   // Mark this declaration as being a definition.
-  D->IsCompleteDefinition = true;
+  D->setCompleteDefinition(true);
 
   // If this is not the first declaration or is an update record, we can have
   // other redeclarations already. Make a note that we need to propagate the
@@ -1941,7 +1941,7 @@
   // compute it.
   if (WasDefinition) {
 DeclID KeyFn = ReadDeclID();
-if (KeyFn && D->IsCompleteDefinition)
+if (KeyFn && D->isCompleteDefinition())
   // FIXME: This is wrong for the ARM ABI, where some other module may have
   // made this function no longer be a key function. We need an update
   // record or similar for that case.
@@ -3071,7 +3071,7 @@
 // we load the update record.
 

[PATCH] D49788: [Docs] Update supported oses for ubsan, asan and msan

2018-07-25 Thread Kamil Rytarowski via Phabricator via cfe-commits
krytarowski added a comment.

Please include NetBSD in UBSan. Also please drop the list of supported 
architectures or rephrase it. It works on e.g. NetBSD/vax.


Repository:
  rC Clang

https://reviews.llvm.org/D49788



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


[PATCH] D49788: [Docs] Update supported oses for ubsan, asan and msan

2018-07-25 Thread Kamil Rytarowski via Phabricator via cfe-commits
krytarowski added a comment.

Please update the documentation of ThreadSanitizer.rst and include at least 
NetBSD/amd64.


Repository:
  rC Clang

https://reviews.llvm.org/D49788



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


[PATCH] D49788: [Docs] Update supported oses for ubsan, asan and msan

2018-07-25 Thread David CARLIER via Phabricator via cfe-commits
devnexen added a comment.

Ah I forgot NetBSD sorry yes you re right.


Repository:
  rC Clang

https://reviews.llvm.org/D49788



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


[PATCH] D49788: [Docs] Update supported oses for ubsan, asan and msan

2018-07-25 Thread Kamil Rytarowski via Phabricator via cfe-commits
krytarowski added a comment.

In SafeStack.rst +NetBSD.


Repository:
  rC Clang

https://reviews.llvm.org/D49788



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


[PATCH] D49792: [ASTmporter] SourceRange-free function parameter checking for declarations

2018-07-25 Thread Zoltán Gera via Phabricator via cfe-commits
gerazo created this revision.
gerazo added reviewers: a.sidorin, r.stahl.
Herald added a subscriber: cfe-commits.

The previous code which avoided infinite recursion (because of reparsing 
declarations in function parameter lists) contained SourceRange dependent code 
which had some problems when parameter types were coming from macros. The new 
solution is not using macros and therefore much safer. A couple of importer 
problems are fixed in redis and tmux by this fix. Various unittests are 
included.


Repository:
  rC Clang

https://reviews.llvm.org/D49792

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


Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -989,7 +989,7 @@
"  return 0;"
"}",
Lang_C, "input.c");
-  auto FromVar =
+  auto *FromVar =
   FirstDeclMatcher().match(FromTU, varDecl(hasName("d")));
   ASSERT_TRUE(FromVar);
   auto ToType =
@@ -999,12 +999,41 @@
 
 TEST_P(ASTImporterTestBase, ImportRecordDeclInFuncParams) {
   // This construct is not supported by ASTImporter.
-  Decl *FromTU =
-  getTuDecl("int declToImport(struct data_t{int a;int b;} *d){ return 0; 
}",
-Lang_C, "input.c");
-  auto From = FirstDeclMatcher().match(FromTU, functionDecl());
+  Decl *FromTU = getTuDecl(
+  "int declToImport(struct data_t{int a;int b;} ***d){ return 0; }",
+  Lang_C, "input.c");
+  auto *From = FirstDeclMatcher().match(
+  FromTU, functionDecl(hasName("declToImport")));
+  ASSERT_TRUE(From);
+  auto *To = Import(From, Lang_C);
+  EXPECT_EQ(To, nullptr);
+}
+
+TEST_P(ASTImporterTestBase, ImportRecordDeclInFuncFromMacro) {
+  Decl *FromTU = getTuDecl(
+  "#define NONAME_SIZEOF(type) sizeof(struct{type *dummy;}) \n"
+  "int declToImport(){ return NONAME_SIZEOF(int); }",
+  Lang_C, "input.c");
+  auto *From = FirstDeclMatcher().match(
+  FromTU, functionDecl(hasName("declToImport")));
+  ASSERT_TRUE(From);
+  auto *To = Import(From, Lang_C);
+  ASSERT_TRUE(To);
+  EXPECT_TRUE(MatchVerifier().match(
+  To, functionDecl(hasName("declToImport"),
+   hasDescendant(unaryExprOrTypeTraitExpr();
+}
+
+TEST_P(ASTImporterTestBase, ImportRecordDeclInFuncParamsFromMacro) {
+  // This construct is not supported by ASTImporter.
+  Decl *FromTU = getTuDecl(
+  "#define PAIR_STRUCT(type) struct data_t{type a;type b;} \n"
+  "int declToImport(PAIR_STRUCT(int) ***d){ return 0; }",
+  Lang_C, "input.c");
+  auto *From = FirstDeclMatcher().match(
+  FromTU, functionDecl(hasName("declToImport")));
   ASSERT_TRUE(From);
-  auto To = Import(From, Lang_C);
+  auto *To = Import(From, Lang_C);
   EXPECT_EQ(To, nullptr);
 }
 
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -1146,15 +1146,21 @@
   FunctionDecl *FunDecl;
   if (isa(D) && (FunDecl = dyn_cast(OrigDC)) &&
   FunDecl->hasBody()) {
-SourceRange RecR = D->getSourceRange();
-SourceRange BodyR = FunDecl->getBody()->getSourceRange();
-// If RecordDecl is not in Body (it is a param), we bail out.
-if (RecR.isValid() && BodyR.isValid() &&
-(RecR.getBegin() < BodyR.getBegin() ||
- BodyR.getEnd() < RecR.getEnd())) {
-  Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
-  << D->getDeclKindName();
-  return true;
+auto getLeafPointeeType = [](const Type *T) {
+  while (T->isPointerType() || T->isArrayType()) {
+T = T->getPointeeOrArrayElementType();
+  }
+  return T;
+};
+for (const ParmVarDecl *P : FunDecl->parameters()) {
+  const Type *LeafT =
+  getLeafPointeeType(P->getType().getCanonicalType().getTypePtr());
+  auto *RT = dyn_cast(LeafT);
+  if (RT && RT->getDecl() == D) {
+Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
+<< D->getDeclKindName();
+return true;
+  }
 }
   }
 


Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -989,7 +989,7 @@
"  return 0;"
"}",
Lang_C, "input.c");
-  auto FromVar =
+  auto *FromVar =
   FirstDeclMatcher().match(FromTU, varDecl(hasName("d")));
   ASSERT_TRUE(FromVar);
   auto ToType =
@@ -999,12 +999,41 @@
 
 TEST_P(ASTImporterTestBase, ImportRecordDeclInFuncParams) {
   // This construct is not supported by ASTImporter.
-  Decl *FromTU =
-  getTuDecl("int declToImport(struct data_t{int a;int b;} *d){ return 0; }",
-Lang_C, "input.c");
-  auto From = FirstDeclMatcher().match(FromTU, fun

[PATCH] D49788: [Docs] Update supported oses for ubsan, asan and msan

2018-07-25 Thread David CARLIER via Phabricator via cfe-commits
devnexen updated this revision to Diff 157237.

https://reviews.llvm.org/D49788

Files:
  docs/AddressSanitizer.rst
  docs/MemorySanitizer.rst
  docs/SafeStack.rst
  docs/ThreadSanitizer.rst
  docs/UndefinedBehaviorSanitizer.rst


Index: docs/UndefinedBehaviorSanitizer.rst
===
--- docs/UndefinedBehaviorSanitizer.rst
+++ docs/UndefinedBehaviorSanitizer.rst
@@ -252,17 +252,11 @@
 
 * Android
 * Linux
+* NetBSD
 * FreeBSD
+* OpenBSD
 * OS X 10.6 onwards
 
-and for the following architectures:
-
-* i386/x86\_64
-* ARM
-* AArch64
-* PowerPC64
-* MIPS/MIPS64
-
 Current Status
 ==
 
Index: docs/ThreadSanitizer.rst
===
--- docs/ThreadSanitizer.rst
+++ docs/ThreadSanitizer.rst
@@ -17,7 +17,11 @@
 Supported Platforms
 ---
 
-ThreadSanitizer is supported on Linux x86_64 (tested on Ubuntu 12.04).
+ThreadSanitizer is supported on the following OS:
+
+* Linux
+* NetBSD
+* FreeBSD
 Support for other 64-bit architectures is possible, contributions are welcome.
 Support for 32-bit platforms is problematic and is not planned.
 
Index: docs/SafeStack.rst
===
--- docs/SafeStack.rst
+++ docs/SafeStack.rst
@@ -126,7 +126,7 @@
 Supported Platforms
 ---
 
-SafeStack was tested on Linux, FreeBSD and MacOSX.
+SafeStack was tested on Linux, NetBSD, FreeBSD and MacOSX.
 
 Low-level API
 -
Index: docs/MemorySanitizer.rst
===
--- docs/MemorySanitizer.rst
+++ docs/MemorySanitizer.rst
@@ -185,7 +185,11 @@
 Supported Platforms
 ===
 
-MemorySanitizer is supported on Linux x86\_64/MIPS64/AArch64.
+MemorySanitizer is supported on the following OS:
+
+* Linux
+* NetBSD
+* FreeBSD
 
 Limitations
 ===
Index: docs/AddressSanitizer.rst
===
--- docs/AddressSanitizer.rst
+++ docs/AddressSanitizer.rst
@@ -276,6 +276,7 @@
 * OS X 10.7 - 10.11 (i386/x86\_64)
 * iOS Simulator
 * Android ARM
+* NetBSD i386/x86\_64
 * FreeBSD i386/x86\_64 (tested on FreeBSD 11-current)
 
 Ports to various other platforms are in progress.


Index: docs/UndefinedBehaviorSanitizer.rst
===
--- docs/UndefinedBehaviorSanitizer.rst
+++ docs/UndefinedBehaviorSanitizer.rst
@@ -252,17 +252,11 @@
 
 * Android
 * Linux
+* NetBSD
 * FreeBSD
+* OpenBSD
 * OS X 10.6 onwards
 
-and for the following architectures:
-
-* i386/x86\_64
-* ARM
-* AArch64
-* PowerPC64
-* MIPS/MIPS64
-
 Current Status
 ==
 
Index: docs/ThreadSanitizer.rst
===
--- docs/ThreadSanitizer.rst
+++ docs/ThreadSanitizer.rst
@@ -17,7 +17,11 @@
 Supported Platforms
 ---
 
-ThreadSanitizer is supported on Linux x86_64 (tested on Ubuntu 12.04).
+ThreadSanitizer is supported on the following OS:
+
+* Linux
+* NetBSD
+* FreeBSD
 Support for other 64-bit architectures is possible, contributions are welcome.
 Support for 32-bit platforms is problematic and is not planned.
 
Index: docs/SafeStack.rst
===
--- docs/SafeStack.rst
+++ docs/SafeStack.rst
@@ -126,7 +126,7 @@
 Supported Platforms
 ---
 
-SafeStack was tested on Linux, FreeBSD and MacOSX.
+SafeStack was tested on Linux, NetBSD, FreeBSD and MacOSX.
 
 Low-level API
 -
Index: docs/MemorySanitizer.rst
===
--- docs/MemorySanitizer.rst
+++ docs/MemorySanitizer.rst
@@ -185,7 +185,11 @@
 Supported Platforms
 ===
 
-MemorySanitizer is supported on Linux x86\_64/MIPS64/AArch64.
+MemorySanitizer is supported on the following OS:
+
+* Linux
+* NetBSD
+* FreeBSD
 
 Limitations
 ===
Index: docs/AddressSanitizer.rst
===
--- docs/AddressSanitizer.rst
+++ docs/AddressSanitizer.rst
@@ -276,6 +276,7 @@
 * OS X 10.7 - 10.11 (i386/x86\_64)
 * iOS Simulator
 * Android ARM
+* NetBSD i386/x86\_64
 * FreeBSD i386/x86\_64 (tested on FreeBSD 11-current)
 
 Ports to various other platforms are in progress.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r337915 - [analyzer] Moved static Context to class member

2018-07-25 Thread Mikhail R. Gadelha via cfe-commits
Author: mramalho
Date: Wed Jul 25 05:49:11 2018
New Revision: 337915

URL: http://llvm.org/viewvc/llvm-project?rev=337915&view=rev
Log:
[analyzer] Moved static Context to class member

Summary:
Although it is a big patch, the changes are simple:
1. There is one `Z3_Context` now, member of the `SMTConstraintManager` class.
2. `Z3Expr`, `Z3Sort`, `Z3Model` and `Z3Solver` are constructed with a 
reference to the `Z3_Context` in `SMTConstraintManager`.
3. All static functions are now members of `Z3Solver`, e.g, the 
`SMTConstraintManager` now calls `Solver.fromBoolean(false)` instead of 
`Z3Expr::fromBoolean(false)`.

Most of the patch only move stuff around except:
1. New method `Z3Sort MkSort(const QualType &Ty, unsigned BitWidth)`, that 
creates a sort based on the `QualType` and its width. Used to simplify the 
`fromData` method.

Unfortunate consequence of this patch:
1. `getInterpretation` was moved from `Z3Model` class to `Z3Solver`, because it 
needs to create a `Z3Sort` before returning the interpretation. This can be 
fixed by changing both `toAPFloat` and `toAPSInt` by removing the dependency of 
`Z3Sort` (it's only used to check which Sort was created and to retrieve the 
type width).

Reviewers: NoQ, george.karpenkov, ddcc

Reviewed By: george.karpenkov

Subscribers: xazax.hun, szepet, a.sidorin

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

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp?rev=337915&r1=337914&r2=337915&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp Wed Jul 25 
05:49:11 2018
@@ -64,48 +64,55 @@ public:
   ~Z3Config() { Z3_del_config(Config); }
 }; // end class Z3Config
 
+void Z3ErrorHandler(Z3_context Context, Z3_error_code Error) {
+  llvm::report_fatal_error("Z3 error: " +
+   llvm::Twine(Z3_get_error_msg_ex(Context, Error)));
+}
+
 class Z3Context : public SMTContext {
 public:
-  static Z3_context ZC;
+  Z3_context Context;
 
   Z3Context() : SMTContext() {
 Context = Z3_mk_context_rc(Z3Config().Config);
-ZC = Context;
+Z3_set_error_handler(Context, Z3ErrorHandler);
   }
 
-  ~Z3Context() {
-Z3_del_context(ZC);
+  virtual ~Z3Context() {
+Z3_del_context(Context);
 Context = nullptr;
   }
-
-protected:
-  Z3_context Context;
 }; // end class Z3Context
 
 class Z3Sort {
   friend class Z3Expr;
+  friend class Z3Solver;
+
+  Z3Context &Context;
 
   Z3_sort Sort;
 
-  Z3Sort() : Sort(nullptr) {}
-  Z3Sort(Z3_sort ZS) : Sort(ZS) {
-Z3_inc_ref(Z3Context::ZC, reinterpret_cast(Sort));
+  Z3Sort(Z3Context &C, Z3_sort ZS) : Context(C), Sort(ZS) {
+assert(C.Context != nullptr);
+Z3_inc_ref(Context.Context, reinterpret_cast(Sort));
   }
 
 public:
   /// Override implicit copy constructor for correct reference counting.
-  Z3Sort(const Z3Sort &Copy) : Sort(Copy.Sort) {
-Z3_inc_ref(Z3Context::ZC, reinterpret_cast(Sort));
+  Z3Sort(const Z3Sort &Copy) : Context(Copy.Context), Sort(Copy.Sort) {
+Z3_inc_ref(Context.Context, reinterpret_cast(Sort));
   }
 
   /// Provide move constructor
-  Z3Sort(Z3Sort &&Move) : Sort(nullptr) { *this = std::move(Move); }
+  Z3Sort(Z3Sort &&Move) : Context(Move.Context), Sort(nullptr) {
+*this = std::move(Move);
+  }
 
   /// Provide move assignment constructor
   Z3Sort &operator=(Z3Sort &&Move) {
 if (this != &Move) {
   if (Sort)
-Z3_dec_ref(Z3Context::ZC, reinterpret_cast(Sort));
+Z3_dec_ref(Context.Context, reinterpret_cast(Sort));
   Sort = Move.Sort;
   Move.Sort = nullptr;
 }
@@ -114,75 +121,38 @@ public:
 
   ~Z3Sort() {
 if (Sort)
-  Z3_dec_ref(Z3Context::ZC, reinterpret_cast(Sort));
-  }
-
-  // Return a boolean sort.
-  static Z3Sort getBoolSort() { return Z3Sort(Z3_mk_bool_sort(Z3Context::ZC)); 
}
-
-  // Return an appropriate bitvector sort for the given bitwidth.
-  static Z3Sort getBitvectorSort(unsigned BitWidth) {
-return Z3Sort(Z3_mk_bv_sort(Z3Context::ZC, BitWidth));
-  }
-
-  // Return an appropriate floating-point sort for the given bitwidth.
-  static Z3Sort getFloatSort(unsigned BitWidth) {
-Z3_sort Sort;
-
-switch (BitWidth) {
-default:
-  llvm_unreachable("Unsupported floating-point bitwidth!");
-  break;
-case 16:
-  Sort = Z3_mk_fpa_sort_16(Z3Context::ZC);
-  break;
-case 32:
-  Sort = Z3_mk_fpa_sort_32(Z3Context::ZC);
-  break;
-case 64:
-  Sort = Z3_mk_fpa_sort_64(Z3Context::ZC);
-  break;
-case 128:
-  Sort = Z3_mk_fpa_sort_128(Z3Context::ZC);
-  break;
-}
-return Z3Sort(Sort);
-  }
-
-  // Return an appropriate sort for the given AST.
-  static Z3Sort getSort(Z3_

r337917 - [analyzer] Create generic SMT Expr class

2018-07-25 Thread Mikhail R. Gadelha via cfe-commits
Author: mramalho
Date: Wed Jul 25 05:49:19 2018
New Revision: 337917

URL: http://llvm.org/viewvc/llvm-project?rev=337917&view=rev
Log:
[analyzer] Create generic SMT Expr class

Summary:
New base class for all future SMT Exprs.

No major changes except moving `areEquivalent` and `getFloatSemantics` outside 
of `Z3Expr` to keep the class minimal.

Reviewers: NoQ, george.karpenkov

Reviewed By: george.karpenkov

Subscribers: xazax.hun, szepet, a.sidorin

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

Added:
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTExpr.h
Modified:
cfe/trunk/lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp

Added: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTExpr.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTExpr.h?rev=337917&view=auto
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTExpr.h (added)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTExpr.h Wed Jul 
25 05:49:19 2018
@@ -0,0 +1,57 @@
+//== SMTExpr.h --*- C++ 
-*--==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+//  This file defines a SMT generic Expr API, which will be the base class
+//  for every SMT solver expr specific class.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SMTEXPR_H
+#define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SMTEXPR_H
+
+#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
+
+namespace clang {
+namespace ento {
+
+class SMTExpr {
+public:
+  SMTExpr() = default;
+  virtual ~SMTExpr() = default;
+
+  bool operator<(const SMTExpr &Other) const {
+llvm::FoldingSetNodeID ID1, ID2;
+Profile(ID1);
+Other.Profile(ID2);
+return ID1 < ID2;
+  }
+
+  virtual void Profile(llvm::FoldingSetNodeID &ID) const {
+static int Tag = 0;
+ID.AddPointer(&Tag);
+  }
+
+  friend bool operator==(SMTExpr const &LHS, SMTExpr const &RHS) {
+return LHS.equal_to(RHS);
+  }
+
+  virtual void print(raw_ostream &OS) const = 0;
+
+  LLVM_DUMP_METHOD void dump() const { print(llvm::errs()); }
+
+protected:
+  virtual bool equal_to(SMTExpr const &other) const = 0;
+};
+
+using SMTExprRef = std::shared_ptr;
+
+} // namespace ento
+} // namespace clang
+
+#endif

Modified: cfe/trunk/lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp?rev=337917&r1=337916&r2=337917&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp Wed Jul 25 
05:49:19 2018
@@ -12,6 +12,7 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/SMTContext.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/SMTExpr.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/SMTSort.h"
 
 #include "clang/Config/config.h"
@@ -162,40 +163,25 @@ public:
   }
 }; // end class Z3Sort
 
-class Z3Expr {
-  friend class Z3Model;
+class Z3Expr : public SMTExpr {
   friend class Z3Solver;
 
   Z3Context &Context;
 
   Z3_ast AST;
 
-  Z3Expr(Z3Context &C, Z3_ast ZA) : Context(C), AST(ZA) {
-assert(C.Context != nullptr);
+  Z3Expr(Z3Context &C, Z3_ast ZA) : SMTExpr(), Context(C), AST(ZA) {
 Z3_inc_ref(Context.Context, AST);
   }
 
-  // Determine whether two float semantics are equivalent
-  static bool areEquivalent(const llvm::fltSemantics &LHS,
-const llvm::fltSemantics &RHS) {
-return (llvm::APFloat::semanticsPrecision(LHS) ==
-llvm::APFloat::semanticsPrecision(RHS)) &&
-   (llvm::APFloat::semanticsMinExponent(LHS) ==
-llvm::APFloat::semanticsMinExponent(RHS)) &&
-   (llvm::APFloat::semanticsMaxExponent(LHS) ==
-llvm::APFloat::semanticsMaxExponent(RHS)) &&
-   (llvm::APFloat::semanticsSizeInBits(LHS) ==
-llvm::APFloat::semanticsSizeInBits(RHS));
-  }
-
 public:
   /// Override implicit copy constructor for correct reference counting.
-  Z3Expr(const Z3Expr &Copy) : Context(Copy.Context), AST(Copy.AST) {
+  Z3Expr(const Z3Expr &Copy) : SMTExpr(), Context(Copy.Context), AST(Copy.AST) 
{
 Z3_inc_ref(Context.Context, AST);
   }
 
   /// Provide move constructor
-  Z3Expr(Z3Expr &&Move) : Context(Move.Context), AST(nullptr) {
+  Z3Expr(Z3Expr &&Mov

r337916 - [analyzer] Create generic SMT Sort Class

2018-07-25 Thread Mikhail R. Gadelha via cfe-commits
Author: mramalho
Date: Wed Jul 25 05:49:15 2018
New Revision: 337916

URL: http://llvm.org/viewvc/llvm-project?rev=337916&view=rev
Log:
[analyzer] Create generic SMT Sort Class

Summary:
New base class for all future SMT sorts.

The only change is that the class implements methods `isBooleanSort()`, 
`isBitvectorSort()` and `isFloatSort()` so it doesn't rely on `Z3`'s enum.

Reviewers: NoQ, george.karpenkov

Reviewed By: george.karpenkov

Subscribers: xazax.hun, szepet, a.sidorin

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

Added:
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTSort.h
Modified:
cfe/trunk/lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp

Added: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTSort.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTSort.h?rev=337916&view=auto
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTSort.h (added)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTSort.h Wed Jul 
25 05:49:15 2018
@@ -0,0 +1,71 @@
+//== SMTSort.h --*- C++ 
-*--==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+//  This file defines a SMT generic Sort API, which will be the base class
+//  for every SMT solver sort specific class.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SMTSORT_H
+#define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SMTSORT_H
+
+namespace clang {
+namespace ento {
+
+class SMTSort {
+public:
+  SMTSort() = default;
+  virtual ~SMTSort() = default;
+
+  virtual bool isBitvectorSort() const { return isBitvectorSortImpl(); }
+  virtual bool isFloatSort() const { return isFloatSortImpl(); }
+  virtual bool isBooleanSort() const { return isBooleanSortImpl(); }
+
+  virtual unsigned getBitvectorSortSize() const {
+assert(isBitvectorSort() && "Not a bitvector sort!");
+unsigned Size = getBitvectorSortSizeImpl();
+assert(Size && "Size is zero!");
+return Size;
+  };
+
+  virtual unsigned getFloatSortSize() const {
+assert(isFloatSort() && "Not a floating-point sort!");
+unsigned Size = getFloatSortSizeImpl();
+assert(Size && "Size is zero!");
+return Size;
+  };
+
+  friend bool operator==(SMTSort const &LHS, SMTSort const &RHS) {
+return LHS.equal_to(RHS);
+  }
+
+  virtual void print(raw_ostream &OS) const = 0;
+
+  LLVM_DUMP_METHOD void dump() const { print(llvm::errs()); }
+
+protected:
+  virtual bool equal_to(SMTSort const &other) const = 0;
+
+  virtual bool isBitvectorSortImpl() const = 0;
+
+  virtual bool isFloatSortImpl() const = 0;
+
+  virtual bool isBooleanSortImpl() const = 0;
+
+  virtual unsigned getBitvectorSortSizeImpl() const = 0;
+
+  virtual unsigned getFloatSortSizeImpl() const = 0;
+};
+
+using SMTSortRef = std::shared_ptr;
+
+} // namespace ento
+} // namespace clang
+
+#endif

Modified: cfe/trunk/lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp?rev=337916&r1=337915&r2=337916&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp Wed Jul 25 
05:49:15 2018
@@ -12,6 +12,7 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/SMTContext.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/SMTSort.h"
 
 #include "clang/Config/config.h"
 
@@ -84,27 +85,26 @@ public:
   }
 }; // end class Z3Context
 
-class Z3Sort {
-  friend class Z3Expr;
+class Z3Sort : public SMTSort {
   friend class Z3Solver;
 
   Z3Context &Context;
 
   Z3_sort Sort;
 
-  Z3Sort(Z3Context &C, Z3_sort ZS) : Context(C), Sort(ZS) {
-assert(C.Context != nullptr);
+  Z3Sort(Z3Context &C, Z3_sort ZS) : SMTSort(), Context(C), Sort(ZS) {
 Z3_inc_ref(Context.Context, reinterpret_cast(Sort));
   }
 
 public:
   /// Override implicit copy constructor for correct reference counting.
-  Z3Sort(const Z3Sort &Copy) : Context(Copy.Context), Sort(Copy.Sort) {
+  Z3Sort(const Z3Sort &Copy)
+  : SMTSort(), Context(Copy.Context), Sort(Copy.Sort) {
 Z3_inc_ref(Context.Context, reinterpret_cast(Sort));
   }
 
   /// Provide move constructor
-  Z3Sort(Z3Sort &&Move) : Context(Move.Context), Sort(nullptr) {
+  Z3Sort(Z3Sort &&Move) : SMTSort(), Context(Move.Context), Sort(nullptr) {

r337918 - [analyzer] Implemented SMT generic API

2018-07-25 Thread Mikhail R. Gadelha via cfe-commits
Author: mramalho
Date: Wed Jul 25 05:49:23 2018
New Revision: 337918

URL: http://llvm.org/viewvc/llvm-project?rev=337918&view=rev
Log:
[analyzer] Implemented SMT generic API

Summary:
Created new SMT generic API.

Small changes to `Z3ConstraintManager` because of the new generic objects 
(`SMTSort` and `SMTExpr`) returned by `SMTSolver`.

Reviewers: george.karpenkov, NoQ

Reviewed By: george.karpenkov

Subscribers: mgorny, xazax.hun, szepet, a.sidorin

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

Added:
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTSolver.h
Modified:
cfe/trunk/lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp

Added: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTSolver.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTSolver.h?rev=337918&view=auto
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTSolver.h 
(added)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTSolver.h Wed 
Jul 25 05:49:23 2018
@@ -0,0 +1,546 @@
+//== SMTSolver.h *- C++ 
-*--==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+//  This file defines a SMT generic Solver API, which will be the base class
+//  for every SMT solver specific class.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SMTSOLVER_H
+#define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SMTSOLVER_H
+
+#include "clang/StaticAnalyzer/Core/PathSensitive/SMTExpr.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/SMTSort.h"
+
+namespace clang {
+namespace ento {
+
+class SMTSolver {
+public:
+  SMTSolver() = default;
+  virtual ~SMTSolver() = default;
+
+  LLVM_DUMP_METHOD void dump() const { print(llvm::errs()); }
+
+  // Return an appropriate floating-point sort for the given bitwidth.
+  SMTSortRef getFloatSort(unsigned BitWidth) {
+switch (BitWidth) {
+case 16:
+  return getFloat16Sort();
+case 32:
+  return getFloat32Sort();
+case 64:
+  return getFloat64Sort();
+case 128:
+  return getFloat128Sort();
+default:;
+}
+llvm_unreachable("Unsupported floating-point bitwidth!");
+  }
+
+  // Return an appropriate sort, given a QualType
+  SMTSortRef mkSort(const QualType &Ty, unsigned BitWidth) {
+if (Ty->isBooleanType())
+  return getBoolSort();
+
+if (Ty->isRealFloatingType())
+  return getFloatSort(BitWidth);
+
+return getBitvectorSort(BitWidth);
+  }
+
+  /// Construct a Z3Expr from a unary operator, given a Z3_context.
+  SMTExprRef fromUnOp(const UnaryOperator::Opcode Op, const SMTExprRef &Exp) {
+switch (Op) {
+case UO_Minus:
+  return mkBVNeg(Exp);
+
+case UO_Not:
+  return mkBVNot(Exp);
+
+case UO_LNot:
+  return mkNot(Exp);
+
+default:;
+}
+llvm_unreachable("Unimplemented opcode");
+  }
+
+  /// Construct a Z3Expr from a floating-point unary operator, given a
+  /// Z3_context.
+  SMTExprRef fromFloatUnOp(const UnaryOperator::Opcode Op,
+   const SMTExprRef &Exp) {
+switch (Op) {
+case UO_Minus:
+  return mkFPNeg(Exp);
+
+case UO_LNot:
+  return fromUnOp(Op, Exp);
+
+default:;
+}
+llvm_unreachable("Unimplemented opcode");
+  }
+
+  /// Construct a Z3Expr from a n-ary binary operator.
+  SMTExprRef fromNBinOp(const BinaryOperator::Opcode Op,
+const std::vector &ASTs) {
+assert(!ASTs.empty());
+
+if (Op != BO_LAnd && Op != BO_LOr)
+  llvm_unreachable("Unimplemented opcode");
+
+SMTExprRef res = ASTs.front();
+for (std::size_t i = 1; i < ASTs.size(); ++i)
+  res = (Op == BO_LAnd) ? mkAnd(res, ASTs[i]) : mkOr(res, ASTs[i]);
+return res;
+  }
+
+  /// Construct a Z3Expr from a binary operator, given a Z3_context.
+  SMTExprRef fromBinOp(const SMTExprRef &LHS, const BinaryOperator::Opcode Op,
+   const SMTExprRef &RHS, bool isSigned) {
+assert(*getSort(LHS) == *getSort(RHS) && "AST's must have the same sort!");
+
+switch (Op) {
+// Multiplicative operators
+case BO_Mul:
+  return mkBVMul(LHS, RHS);
+
+case BO_Div:
+  return isSigned ? mkBVSDiv(LHS, RHS) : mkBVUDiv(LHS, RHS);
+
+case BO_Rem:
+  return isSigned ? mkBVSRem(LHS, RHS) : mkBVURem(LHS, RHS);
+
+  // Additive operators
+case BO_Add:
+  return mkBVAdd(LHS, RHS);
+
+case BO_Sub:
+  return mkBVSub(LHS, RHS);
+
+  // Bitwise shift operators
+case BO_Shl:
+  return mkBVShl(LHS, RHS);
+
+case BO_Shr:
+  return isSigned ? mkB

r337914 - [analyzer] Create generic SMT Context class

2018-07-25 Thread Mikhail R. Gadelha via cfe-commits
Author: mramalho
Date: Wed Jul 25 05:49:07 2018
New Revision: 337914

URL: http://llvm.org/viewvc/llvm-project?rev=337914&view=rev
Log:
[analyzer] Create generic SMT Context class

Summary:
This patch creates `SMTContext` which will wrap a specific SMT context, through 
`SMTSolverContext`.

The templated `SMTSolverContext` class it's a simple wrapper around a SMT 
specific context (currently only used in the Z3 backend), while `Z3Context` 
inherits `SMTSolverContext` and implements solver specific 
operations like initialization and destruction of the context.

This separation was done because:

1. We might want to keep one single context, shared across different 
`SMTConstraintManager`s. It can be achieved by constructing a `SMTContext`, 
through a function like `CreateSMTContext(Z3)`, `CreateSMTContext(BOOLECTOR)`, 
etc. The rest of the CSA only need to know about `SMTContext`, so maybe it's a 
good idea moving `SMTSolverContext` to a separate header in the future.

2. Any generic SMT operation will only require one `SMTSolverContext`object, 
which can access the specific context by calling `getContext()`.

Reviewers: NoQ, george.karpenkov

Reviewed By: george.karpenkov

Subscribers: xazax.hun, szepet, a.sidorin

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

Added:
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTContext.h
Modified:
cfe/trunk/lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp

Added: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTContext.h?rev=337914&view=auto
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTContext.h 
(added)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTContext.h Wed 
Jul 25 05:49:07 2018
@@ -0,0 +1,30 @@
+//== SMTContext.h ---*- C++ 
-*--==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+//  This file defines a SMT generic Context API, which will be the base class
+//  for every SMT solver context specific class.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SMTCONTEXT_H
+#define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SMTCONTEXT_H
+
+namespace clang {
+namespace ento {
+
+class SMTContext {
+public:
+  SMTContext() = default;
+  virtual ~SMTContext() = default;
+};
+
+} // namespace ento
+} // namespace clang
+
+#endif

Modified: cfe/trunk/lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp?rev=337914&r1=337913&r2=337914&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp Wed Jul 25 
05:49:07 2018
@@ -11,6 +11,7 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/SMTContext.h"
 
 #include "clang/Config/config.h"
 
@@ -63,19 +64,22 @@ public:
   ~Z3Config() { Z3_del_config(Config); }
 }; // end class Z3Config
 
-class Z3Context {
-  Z3_context ZC_P;
-
+class Z3Context : public SMTContext {
 public:
   static Z3_context ZC;
 
-  Z3Context() : ZC_P(Z3_mk_context_rc(Z3Config().Config)) { ZC = ZC_P; }
+  Z3Context() : SMTContext() {
+Context = Z3_mk_context_rc(Z3Config().Config);
+ZC = Context;
+  }
 
   ~Z3Context() {
 Z3_del_context(ZC);
-Z3_finalize_memory();
-ZC_P = nullptr;
+Context = nullptr;
   }
+
+protected:
+  Z3_context Context;
 }; // end class Z3Context
 
 class Z3Sort {


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


r337919 - [analyzer] Moved non solver specific code from Z3ConstraintManager to SMTConstraintManager

2018-07-25 Thread Mikhail R. Gadelha via cfe-commits
Author: mramalho
Date: Wed Jul 25 05:49:29 2018
New Revision: 337919

URL: http://llvm.org/viewvc/llvm-project?rev=337919&view=rev
Log:
[analyzer] Moved non solver specific code from Z3ConstraintManager to 
SMTConstraintManager

Summary:
This patch moves a lot of code from `Z3ConstraintManager` to 
`SMTConstraintManager`, leaving only the necessary:
* `canReasonAbout` which returns if a Solver can handle a given `SVal` (should 
be moved to `SMTSolver` in the future).
* `removeDeadBindings`, `assumeExpr` and `print`: methods that need to use 
`ConstraintZ3Ty`, can probably be moved to `SMTConstraintManager` in the future.

The patch creates a new file, `SMTConstraintManager.cpp` with the moved code. 
Conceptually, this is move in the right direction and needs further 
improvements: `SMTConstraintManager` still does a lot of things that are not 
required by a `ConstraintManager`.

We ought to move the unrelated to `SMTSolver` and remove everything that's not 
related to a `ConstraintManager`. In particular, we could remove 
`addRangeConstraints` and `isModelFeasible`, and make the refutation manager 
create an Z3Solver directly.

Reviewers: NoQ, george.karpenkov

Reviewed By: george.karpenkov

Subscribers: mgorny, xazax.hun, szepet, a.sidorin

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

Added:
cfe/trunk/lib/StaticAnalyzer/Core/SMTConstraintManager.cpp
Modified:

cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
cfe/trunk/lib/StaticAnalyzer/Core/CMakeLists.txt
cfe/trunk/lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h?rev=337919&r1=337918&r2=337919&view=diff
==
--- 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
 (original)
+++ 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
 Wed Jul 25 05:49:29 2018
@@ -16,27 +16,254 @@
 #define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SMTCONSTRAINTMANAGER_H
 
 #include "clang/StaticAnalyzer/Core/PathSensitive/RangedConstraintManager.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/SMTSolver.h"
 
 namespace clang {
 namespace ento {
 
 class SMTConstraintManager : public clang::ento::SimpleConstraintManager {
+  SMTSolverRef &Solver;
 
 public:
-  SMTConstraintManager(clang::ento::SubEngine *SE, clang::ento::SValBuilder 
&SB)
-  : SimpleConstraintManager(SE, SB) {}
+  SMTConstraintManager(clang::ento::SubEngine *SE, clang::ento::SValBuilder 
&SB,
+   SMTSolverRef &S)
+  : SimpleConstraintManager(SE, SB), Solver(S) {}
   virtual ~SMTConstraintManager() = default;
 
+  //===--===//
+  // Implementation for interface from SimpleConstraintManager.
+  //===--===//
+
+  ProgramStateRef assumeSym(ProgramStateRef state, SymbolRef Sym,
+bool Assumption) override;
+
+  ProgramStateRef assumeSymInclusiveRange(ProgramStateRef State, SymbolRef Sym,
+  const llvm::APSInt &From,
+  const llvm::APSInt &To,
+  bool InRange) override;
+
+  ProgramStateRef assumeSymUnsupported(ProgramStateRef State, SymbolRef Sym,
+   bool Assumption) override;
+
+  //===--===//
+  // Implementation for interface from ConstraintManager.
+  //===--===//
+
+  ConditionTruthVal checkNull(ProgramStateRef State, SymbolRef Sym) override;
+
+  const llvm::APSInt *getSymVal(ProgramStateRef State,
+SymbolRef Sym) const override;
+
   /// Converts the ranged constraints of a set of symbols to SMT
   ///
   /// \param CR The set of constraints.
-  virtual void addRangeConstraints(clang::ento::ConstraintRangeTy CR) = 0;
+  void addRangeConstraints(clang::ento::ConstraintRangeTy CR);
 
   /// Checks if the added constraints are satisfiable
-  virtual clang::ento::ConditionTruthVal isModelFeasible() = 0;
+  clang::ento::ConditionTruthVal isModelFeasible();
 
   /// Dumps SMT formula
-  LLVM_DUMP_METHOD virtual void dump() const = 0;
+  LLVM_DUMP_METHOD void dump() const { Solver->dump(); }
+
+protected:
+  //===--===//
+  // Internal implementation.
+  //===--===//
+
+  // Check whether a new model is satisfiable, and update the program state.
+  virtual ProgramStateRef assumeExpr(ProgramS

r337920 - [analyzer] Try to minimize the number of equivalent bug reports evaluated by the refutation manager

2018-07-25 Thread Mikhail R. Gadelha via cfe-commits
Author: mramalho
Date: Wed Jul 25 05:49:32 2018
New Revision: 337920

URL: http://llvm.org/viewvc/llvm-project?rev=337920&view=rev
Log:
[analyzer] Try to minimize the number of equivalent bug reports evaluated by 
the refutation manager

Summary:
This patch changes how the SMT bug refutation runs in an equivalent bug report 
class.

Now, all other visitor are executed until they find a valid bug or mark all 
bugs as invalid. When the one valid bug is found (and crosscheck is enabled), 
the SMT refutation checks the satisfiability of this single bug.

If the bug is still valid after checking with Z3, it is returned and a bug 
report is created. If the bug is found to be invalid, the next bug report in 
the equivalent class goes through the same process, until we find a valid bug 
or all bugs are marked as invalid.

Massive speedups when verifying redis/src/rax.c, from 1500s to 10s.

Reviewers: NoQ, george.karpenkov

Reviewed By: george.karpenkov

Subscribers: xazax.hun, szepet, a.sidorin

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

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp?rev=337920&r1=337919&r2=337920&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp Wed Jul 25 05:49:32 2018
@@ -2605,8 +2605,6 @@ std::pairaddVisitor(llvm::make_unique());
-if (Opts.shouldCrosscheckWithZ3())
-  R->addVisitor(llvm::make_unique());
 
 // Register additional node visitors.
 R->addVisitor(llvm::make_unique());
@@ -2619,9 +2617,24 @@ std::pair visitorNotes =
 generateVisitorsDiagnostics(R, ErrorNode, BRC);
 
-if (R->isValid())
-  return std::make_pair(R, std::move(visitorNotes));
+if (R->isValid()) {
+  if (Opts.shouldCrosscheckWithZ3()) {
+// If crosscheck is enabled, remove all visitors, add the refutation
+// visitor and check again
+R->clearVisitors();
+R->addVisitor(llvm::make_unique());
+
+// We don't overrite the notes inserted by other visitors because the
+// refutation manager does not add any new note to the path
+generateVisitorsDiagnostics(R, ErrorGraph.ErrorNode, BRC);
+  }
+
+  // Check if the bug is still valid
+  if (R->isValid())
+return std::make_pair(R, std::move(visitorNotes));
+}
   }
+
   return std::make_pair(nullptr, llvm::make_unique());
 }
 


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


[PATCH] D49236: [analyzer] Moved static Context to class member

2018-07-25 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC337915: [analyzer] Moved static Context to class member 
(authored by mramalho, committed by ).
Herald added a subscriber: cfe-commits.

Repository:
  rC Clang

https://reviews.llvm.org/D49236

Files:
  lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp

Index: lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp
===
--- lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp
+++ lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp
@@ -64,125 +64,95 @@
   ~Z3Config() { Z3_del_config(Config); }
 }; // end class Z3Config
 
+void Z3ErrorHandler(Z3_context Context, Z3_error_code Error) {
+  llvm::report_fatal_error("Z3 error: " +
+   llvm::Twine(Z3_get_error_msg_ex(Context, Error)));
+}
+
 class Z3Context : public SMTContext {
 public:
-  static Z3_context ZC;
+  Z3_context Context;
 
   Z3Context() : SMTContext() {
 Context = Z3_mk_context_rc(Z3Config().Config);
-ZC = Context;
+Z3_set_error_handler(Context, Z3ErrorHandler);
   }
 
-  ~Z3Context() {
-Z3_del_context(ZC);
+  virtual ~Z3Context() {
+Z3_del_context(Context);
 Context = nullptr;
   }
-
-protected:
-  Z3_context Context;
 }; // end class Z3Context
 
 class Z3Sort {
   friend class Z3Expr;
+  friend class Z3Solver;
+
+  Z3Context &Context;
 
   Z3_sort Sort;
 
-  Z3Sort() : Sort(nullptr) {}
-  Z3Sort(Z3_sort ZS) : Sort(ZS) {
-Z3_inc_ref(Z3Context::ZC, reinterpret_cast(Sort));
+  Z3Sort(Z3Context &C, Z3_sort ZS) : Context(C), Sort(ZS) {
+assert(C.Context != nullptr);
+Z3_inc_ref(Context.Context, reinterpret_cast(Sort));
   }
 
 public:
   /// Override implicit copy constructor for correct reference counting.
-  Z3Sort(const Z3Sort &Copy) : Sort(Copy.Sort) {
-Z3_inc_ref(Z3Context::ZC, reinterpret_cast(Sort));
+  Z3Sort(const Z3Sort &Copy) : Context(Copy.Context), Sort(Copy.Sort) {
+Z3_inc_ref(Context.Context, reinterpret_cast(Sort));
   }
 
   /// Provide move constructor
-  Z3Sort(Z3Sort &&Move) : Sort(nullptr) { *this = std::move(Move); }
+  Z3Sort(Z3Sort &&Move) : Context(Move.Context), Sort(nullptr) {
+*this = std::move(Move);
+  }
 
   /// Provide move assignment constructor
   Z3Sort &operator=(Z3Sort &&Move) {
 if (this != &Move) {
   if (Sort)
-Z3_dec_ref(Z3Context::ZC, reinterpret_cast(Sort));
+Z3_dec_ref(Context.Context, reinterpret_cast(Sort));
   Sort = Move.Sort;
   Move.Sort = nullptr;
 }
 return *this;
   }
 
   ~Z3Sort() {
 if (Sort)
-  Z3_dec_ref(Z3Context::ZC, reinterpret_cast(Sort));
-  }
-
-  // Return a boolean sort.
-  static Z3Sort getBoolSort() { return Z3Sort(Z3_mk_bool_sort(Z3Context::ZC)); }
-
-  // Return an appropriate bitvector sort for the given bitwidth.
-  static Z3Sort getBitvectorSort(unsigned BitWidth) {
-return Z3Sort(Z3_mk_bv_sort(Z3Context::ZC, BitWidth));
-  }
-
-  // Return an appropriate floating-point sort for the given bitwidth.
-  static Z3Sort getFloatSort(unsigned BitWidth) {
-Z3_sort Sort;
-
-switch (BitWidth) {
-default:
-  llvm_unreachable("Unsupported floating-point bitwidth!");
-  break;
-case 16:
-  Sort = Z3_mk_fpa_sort_16(Z3Context::ZC);
-  break;
-case 32:
-  Sort = Z3_mk_fpa_sort_32(Z3Context::ZC);
-  break;
-case 64:
-  Sort = Z3_mk_fpa_sort_64(Z3Context::ZC);
-  break;
-case 128:
-  Sort = Z3_mk_fpa_sort_128(Z3Context::ZC);
-  break;
-}
-return Z3Sort(Sort);
-  }
-
-  // Return an appropriate sort for the given AST.
-  static Z3Sort getSort(Z3_ast AST) {
-return Z3Sort(Z3_get_sort(Z3Context::ZC, AST));
+  Z3_dec_ref(Context.Context, reinterpret_cast(Sort));
   }
 
   Z3_sort_kind getSortKind() const {
-return Z3_get_sort_kind(Z3Context::ZC, Sort);
+return Z3_get_sort_kind(Context.Context, Sort);
   }
 
   unsigned getBitvectorSortSize() const {
 assert(getSortKind() == Z3_BV_SORT && "Not a bitvector sort!");
-return Z3_get_bv_sort_size(Z3Context::ZC, Sort);
+return Z3_get_bv_sort_size(Context.Context, Sort);
   }
 
   unsigned getFloatSortSize() const {
 assert(getSortKind() == Z3_FLOATING_POINT_SORT &&
"Not a floating-point sort!");
-return Z3_fpa_get_ebits(Z3Context::ZC, Sort) +
-   Z3_fpa_get_sbits(Z3Context::ZC, Sort);
+return Z3_fpa_get_ebits(Context.Context, Sort) +
+   Z3_fpa_get_sbits(Context.Context, Sort);
   }
 
   bool operator==(const Z3Sort &Other) const {
-return Z3_is_eq_sort(Z3Context::ZC, Sort, Other.Sort);
+return Z3_is_eq_sort(Context.Context, Sort, Other.Sort);
   }
 
   Z3Sort &operator=(const Z3Sort &Move) {
-Z3_inc_ref(Z3Context::ZC, reinterpret_cast(Move.Sort));
-Z3_dec_ref(Z3Context::ZC, reinterpret_cast(Sort));
+Z3_inc_ref(Context.Context, reinterpret_cast(Move.Sort));
+Z3_dec_ref(Context.Context, reinterpret_cast(Sort));
 Sort = Move.Sort;
   

r337921 - [analyzer] Moved code from SMTConstraintManager to SMTSolver

2018-07-25 Thread Mikhail R. Gadelha via cfe-commits
Author: mramalho
Date: Wed Jul 25 05:49:37 2018
New Revision: 337921

URL: http://llvm.org/viewvc/llvm-project?rev=337921&view=rev
Log:
[analyzer] Moved code from SMTConstraintManager to SMTSolver

Summary:
This is the second part of D49668, and moves all the code that's not specific 
to a ConstraintManager to SMTSolver.

No functional change intended.

Reviewers: NoQ, george.karpenkov

Reviewed By: george.karpenkov

Subscribers: xazax.hun, szepet, a.sidorin

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

Modified:

cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTSolver.h
cfe/trunk/lib/StaticAnalyzer/Core/SMTConstraintManager.cpp

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h?rev=337921&r1=337920&r2=337921&view=diff
==
--- 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
 (original)
+++ 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
 Wed Jul 25 05:49:37 2018
@@ -81,189 +81,6 @@ protected:
   // Generate and check a Z3 model, using the given constraint.
   ConditionTruthVal checkModel(ProgramStateRef State,
const SMTExprRef &Exp) const;
-
-  // Generate a Z3Expr that represents the given symbolic expression.
-  // Sets the hasComparison parameter if the expression has a comparison
-  // operator.
-  // Sets the RetTy parameter to the final return type after promotions and
-  // casts.
-  SMTExprRef getExpr(SymbolRef Sym, QualType *RetTy = nullptr,
- bool *hasComparison = nullptr) const;
-
-  // Generate a Z3Expr that takes the logical not of an expression.
-  SMTExprRef getNotExpr(const SMTExprRef &Exp) const;
-
-  // Generate a Z3Expr that compares the expression to zero.
-  SMTExprRef getZeroExpr(const SMTExprRef &Exp, QualType RetTy,
- bool Assumption) const;
-
-  // Recursive implementation to unpack and generate symbolic expression.
-  // Sets the hasComparison and RetTy parameters. See getZ3Expr().
-  SMTExprRef getSymExpr(SymbolRef Sym, QualType *RetTy,
-bool *hasComparison) const;
-
-  // Wrapper to generate Z3Expr from SymbolData.
-  SMTExprRef getDataExpr(const SymbolID ID, QualType Ty) const;
-
-  // Wrapper to generate Z3Expr from SymbolCast.
-  SMTExprRef getCastExpr(const SMTExprRef &Exp, QualType FromTy,
- QualType Ty) const;
-
-  // Wrapper to generate Z3Expr from BinarySymExpr.
-  // Sets the hasComparison and RetTy parameters. See getZ3Expr().
-  SMTExprRef getSymBinExpr(const BinarySymExpr *BSE, bool *hasComparison,
-   QualType *RetTy) const;
-
-  // Wrapper to generate Z3Expr from unpacked binary symbolic expression.
-  // Sets the RetTy parameter. See getZ3Expr().
-  SMTExprRef getBinExpr(const SMTExprRef &LHS, QualType LTy,
-BinaryOperator::Opcode Op, const SMTExprRef &RHS,
-QualType RTy, QualType *RetTy) const;
-
-  // Wrapper to generate Z3Expr from a range. If From == To, an equality will
-  // be created instead.
-  SMTExprRef getRangeExpr(SymbolRef Sym, const llvm::APSInt &From,
-  const llvm::APSInt &To, bool InRange);
-
-  //===--===//
-  // Helper functions.
-  //===--===//
-
-  // Recover the QualType of an APSInt.
-  // TODO: Refactor to put elsewhere
-  QualType getAPSIntType(const llvm::APSInt &Int) const;
-
-  // Get the QualTy for the input APSInt, and fix it if it has a bitwidth of 1.
-  std::pair fixAPSInt(const llvm::APSInt &Int) const;
-
-  // Perform implicit type conversion on binary symbolic expressions.
-  // May modify all input parameters.
-  // TODO: Refactor to use built-in conversion functions
-  void doTypeConversion(SMTExprRef &LHS, SMTExprRef &RHS, QualType isPromotableIntegerType()) {
-  QualType NewTy = Ctx.getPromotedInteg

r337922 - [analyzer] Removed API used by the Refutation Manager from SMTConstraintManager and replace by proper calls to SMTSolver

2018-07-25 Thread Mikhail R. Gadelha via cfe-commits
Author: mramalho
Date: Wed Jul 25 05:49:43 2018
New Revision: 337922

URL: http://llvm.org/viewvc/llvm-project?rev=337922&view=rev
Log:
[analyzer] Removed API used by the Refutation Manager from SMTConstraintManager 
and replace by proper calls to SMTSolver

Summary:
Third patch in the refactoring series, to decouple the SMT Solver from the 
Refutation Manager (1st: D49668, 2nd: D49767).

The refutation API in the `SMTConstraintManager` was a hack to allow us to 
create an SMT solver and verify the constraints; it was conceptually wrong from 
the start. Now, we don't actually need to use the `SMTConstraintManager` and 
can create an SMT object directly, add the constraints and check them.

While updating the Falsification visitor, I inlined the two functions that were 
used to collect the constraints and add them to the solver.

As a result of this patch, we could move the SMT API elsewhere and as it's not 
really dependent on the CSA anymore. Maybe we can create a new dir (utils/smt) 
for Z3 and future solvers?

Reviewers: NoQ, george.karpenkov

Reviewed By: george.karpenkov

Subscribers: xazax.hun, szepet, a.sidorin

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

Modified:

cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTSolver.h
cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
cfe/trunk/lib/StaticAnalyzer/Core/SMTConstraintManager.cpp
cfe/trunk/lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h?rev=337922&r1=337921&r2=337922&view=diff
==
--- 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
 (original)
+++ 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
 Wed Jul 25 05:49:43 2018
@@ -54,14 +54,6 @@ public:
   const llvm::APSInt *getSymVal(ProgramStateRef State,
 SymbolRef Sym) const override;
 
-  /// Converts the ranged constraints of a set of symbols to SMT
-  ///
-  /// \param CR The set of constraints.
-  void addRangeConstraints(clang::ento::ConstraintRangeTy CR);
-
-  /// Checks if the added constraints are satisfiable
-  clang::ento::ConditionTruthVal isModelFeasible();
-
   /// Dumps SMT formula
   LLVM_DUMP_METHOD void dump() const { Solver->dump(); }
 

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTSolver.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTSolver.h?rev=337922&r1=337921&r2=337922&view=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTSolver.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTSolver.h Wed 
Jul 25 05:49:43 2018
@@ -954,6 +954,8 @@ public:
 
 using SMTSolverRef = std::shared_ptr;
 
+std::unique_ptr CreateZ3Solver();
+
 } // namespace ento
 } // namespace clang
 

Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=337922&r1=337921&r2=337922&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Wed Jul 25 
05:49:43 2018
@@ -2370,34 +2370,6 @@ TaintBugVisitor::VisitNode(const Explode
   return std::make_shared(L, "Taint originated 
here");
 }
 
-static bool areConstraintsUnfeasible(BugReporterContext &BRC,
- const ConstraintRangeTy &Cs) {
-  // Create a refutation manager
-  std::unique_ptr RefutationMgr = CreateZ3ConstraintManager(
-  BRC.getStateManager(), BRC.getStateManager().getOwningEngine());
-
-  SMTConstraintManager *SMTRefutationMgr =
-  static_cast(RefutationMgr.get());
-
-  // Add constraints to the solver
-  SMTRefutationMgr->addRangeConstraints(Cs);
-
-  // And check for satisfiability
-  return SMTRefutationMgr->isModelFeasible().isConstrainedFalse();
-}
-
-static void addNewConstraints(ConstraintRangeTy &Cs,
-  const ConstraintRangeTy &NewCs,
-  ConstraintRangeTy::Factory &CF) {
-  // Add constraints if we don't have them yet
-  for (auto const &C : NewCs) {
-const SymbolRef &Sym = C.first;
-if (!Cs.contains(Sym)) {
-  Cs = CF.add(Cs, Sym, C.second);
-}
-  }
-}
-
 FalsePositiveRefutationBRVisitor::FalsePositiveRefutationBRVisitor()
 : Constraints(ConstraintRangeTy::Factory().getEmptyMap()) {}
 
@@ -2406,8 +2378,26 @@ void FalsePositiveRefut

r337923 - [analyzer] Use the macro REGISTER_TRAIT_WITH_PROGRAMSTATE in the Z3 backend

2018-07-25 Thread Mikhail R. Gadelha via cfe-commits
Author: mramalho
Date: Wed Jul 25 05:49:47 2018
New Revision: 337923

URL: http://llvm.org/viewvc/llvm-project?rev=337923&view=rev
Log:
[analyzer] Use the macro REGISTER_TRAIT_WITH_PROGRAMSTATE in the Z3 backend

Summary:
The macro was manually expanded in the Z3 backend and this patch adds it back.

Adding the expanded code is dangerous as the macro may change in the future and 
the expanded code might be left outdated.

Reviewers: NoQ, george.karpenkov

Reviewed By: george.karpenkov

Subscribers: xazax.hun, szepet, a.sidorin

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

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp?rev=337923&r1=337922&r2=337923&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp Wed Jul 25 
05:49:47 2018
@@ -25,28 +25,6 @@ using namespace ento;
 
 #include 
 
-// Forward declarations
-namespace {
-class Z3Expr;
-class ConstraintZ3 {};
-} // end anonymous namespace
-
-typedef llvm::ImmutableSet> ConstraintZ3Ty;
-
-// Expansion of REGISTER_TRAIT_WITH_PROGRAMSTATE(ConstraintZ3, Z3SetPair)
-namespace clang {
-namespace ento {
-template <>
-struct ProgramStateTrait
-: public ProgramStatePartialTrait {
-  static void *GDMIndex() {
-static int Index;
-return &Index;
-  }
-};
-} // end namespace ento
-} // end namespace clang
-
 namespace {
 
 class Z3Config {
@@ -313,6 +291,13 @@ static bool areEquivalent(const llvm::fl
   llvm::APFloat::semanticsSizeInBits(RHS));
 }
 
+} // end anonymous namespace
+
+typedef llvm::ImmutableSet> ConstraintZ3Ty;
+REGISTER_TRAIT_WITH_PROGRAMSTATE(ConstraintZ3, ConstraintZ3Ty)
+
+namespace {
+
 class Z3Solver : public SMTSolver {
   friend class Z3ConstraintManager;
 


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


[PATCH] D49668: [analyzer] Moved non solver specific code from Z3ConstraintManager to SMTConstraintManager

2018-07-25 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC337919: [analyzer] Moved non solver specific code from 
Z3ConstraintManager to… (authored by mramalho, committed by ).
Herald added a subscriber: cfe-commits.

Repository:
  rC Clang

https://reviews.llvm.org/D49668

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
  lib/StaticAnalyzer/Core/CMakeLists.txt
  lib/StaticAnalyzer/Core/SMTConstraintManager.cpp
  lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp

Index: include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
@@ -16,27 +16,254 @@
 #define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SMTCONSTRAINTMANAGER_H
 
 #include "clang/StaticAnalyzer/Core/PathSensitive/RangedConstraintManager.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/SMTSolver.h"
 
 namespace clang {
 namespace ento {
 
 class SMTConstraintManager : public clang::ento::SimpleConstraintManager {
+  SMTSolverRef &Solver;
 
 public:
-  SMTConstraintManager(clang::ento::SubEngine *SE, clang::ento::SValBuilder &SB)
-  : SimpleConstraintManager(SE, SB) {}
+  SMTConstraintManager(clang::ento::SubEngine *SE, clang::ento::SValBuilder &SB,
+   SMTSolverRef &S)
+  : SimpleConstraintManager(SE, SB), Solver(S) {}
   virtual ~SMTConstraintManager() = default;
 
+  //===--===//
+  // Implementation for interface from SimpleConstraintManager.
+  //===--===//
+
+  ProgramStateRef assumeSym(ProgramStateRef state, SymbolRef Sym,
+bool Assumption) override;
+
+  ProgramStateRef assumeSymInclusiveRange(ProgramStateRef State, SymbolRef Sym,
+  const llvm::APSInt &From,
+  const llvm::APSInt &To,
+  bool InRange) override;
+
+  ProgramStateRef assumeSymUnsupported(ProgramStateRef State, SymbolRef Sym,
+   bool Assumption) override;
+
+  //===--===//
+  // Implementation for interface from ConstraintManager.
+  //===--===//
+
+  ConditionTruthVal checkNull(ProgramStateRef State, SymbolRef Sym) override;
+
+  const llvm::APSInt *getSymVal(ProgramStateRef State,
+SymbolRef Sym) const override;
+
   /// Converts the ranged constraints of a set of symbols to SMT
   ///
   /// \param CR The set of constraints.
-  virtual void addRangeConstraints(clang::ento::ConstraintRangeTy CR) = 0;
+  void addRangeConstraints(clang::ento::ConstraintRangeTy CR);
 
   /// Checks if the added constraints are satisfiable
-  virtual clang::ento::ConditionTruthVal isModelFeasible() = 0;
+  clang::ento::ConditionTruthVal isModelFeasible();
 
   /// Dumps SMT formula
-  LLVM_DUMP_METHOD virtual void dump() const = 0;
+  LLVM_DUMP_METHOD void dump() const { Solver->dump(); }
+
+protected:
+  //===--===//
+  // Internal implementation.
+  //===--===//
+
+  // Check whether a new model is satisfiable, and update the program state.
+  virtual ProgramStateRef assumeExpr(ProgramStateRef State, SymbolRef Sym,
+ const SMTExprRef &Exp) = 0;
+
+  /// Given a program state, construct the logical conjunction and add it to
+  /// the solver
+  virtual void addStateConstraints(ProgramStateRef State) const = 0;
+
+  // Generate and check a Z3 model, using the given constraint.
+  ConditionTruthVal checkModel(ProgramStateRef State,
+   const SMTExprRef &Exp) const;
+
+  // Generate a Z3Expr that represents the given symbolic expression.
+  // Sets the hasComparison parameter if the expression has a comparison
+  // operator.
+  // Sets the RetTy parameter to the final return type after promotions and
+  // casts.
+  SMTExprRef getExpr(SymbolRef Sym, QualType *RetTy = nullptr,
+ bool *hasComparison = nullptr) const;
+
+  // Generate a Z3Expr that takes the logical not of an expression.
+  SMTExprRef getNotExpr(const SMTExprRef &Exp) const;
+
+  // Generate a Z3Expr that compares the expression to zero.
+  SMTExprRef getZeroExpr(const SMTExprRef &Exp, QualType RetTy,
+ bool Assumption) const;
+
+  // Recursive implementation to unpack and generate symbolic expression.
+  // Sets the hasComparison and RetTy parameters. See getZ3Expr().
+  SMTExprRef getSymExpr(SymbolRef Sym, Qua

[PATCH] D49768: [analyzer] Removed API used by the Refutation Manager from SMTConstraintManager and replace by proper calls to SMTSolver

2018-07-25 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC337922: [analyzer] Removed API used by the Refutation 
Manager from SMTConstraintManager… (authored by mramalho, committed by ).
Herald added a subscriber: cfe-commits.

Repository:
  rC Clang

https://reviews.llvm.org/D49768

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
  include/clang/StaticAnalyzer/Core/PathSensitive/SMTSolver.h
  lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  lib/StaticAnalyzer/Core/SMTConstraintManager.cpp
  lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp

Index: include/clang/StaticAnalyzer/Core/PathSensitive/SMTSolver.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/SMTSolver.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/SMTSolver.h
@@ -954,6 +954,8 @@
 
 using SMTSolverRef = std::shared_ptr;
 
+std::unique_ptr CreateZ3Solver();
+
 } // namespace ento
 } // namespace clang
 
Index: include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
@@ -54,14 +54,6 @@
   const llvm::APSInt *getSymVal(ProgramStateRef State,
 SymbolRef Sym) const override;
 
-  /// Converts the ranged constraints of a set of symbols to SMT
-  ///
-  /// \param CR The set of constraints.
-  void addRangeConstraints(clang::ento::ConstraintRangeTy CR);
-
-  /// Checks if the added constraints are satisfiable
-  clang::ento::ConditionTruthVal isModelFeasible();
-
   /// Dumps SMT formula
   LLVM_DUMP_METHOD void dump() const { Solver->dump(); }
 
Index: lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===
--- lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -2370,44 +2370,34 @@
   return std::make_shared(L, "Taint originated here");
 }
 
-static bool areConstraintsUnfeasible(BugReporterContext &BRC,
- const ConstraintRangeTy &Cs) {
-  // Create a refutation manager
-  std::unique_ptr RefutationMgr = CreateZ3ConstraintManager(
-  BRC.getStateManager(), BRC.getStateManager().getOwningEngine());
-
-  SMTConstraintManager *SMTRefutationMgr =
-  static_cast(RefutationMgr.get());
-
-  // Add constraints to the solver
-  SMTRefutationMgr->addRangeConstraints(Cs);
-
-  // And check for satisfiability
-  return SMTRefutationMgr->isModelFeasible().isConstrainedFalse();
-}
-
-static void addNewConstraints(ConstraintRangeTy &Cs,
-  const ConstraintRangeTy &NewCs,
-  ConstraintRangeTy::Factory &CF) {
-  // Add constraints if we don't have them yet
-  for (auto const &C : NewCs) {
-const SymbolRef &Sym = C.first;
-if (!Cs.contains(Sym)) {
-  Cs = CF.add(Cs, Sym, C.second);
-}
-  }
-}
-
 FalsePositiveRefutationBRVisitor::FalsePositiveRefutationBRVisitor()
 : Constraints(ConstraintRangeTy::Factory().getEmptyMap()) {}
 
 void FalsePositiveRefutationBRVisitor::finalizeVisitor(
 BugReporterContext &BRC, const ExplodedNode *EndPathNode, BugReport &BR) {
   // Collect new constraints
   VisitNode(EndPathNode, nullptr, BRC, BR);
 
-  // Create a new refutation manager and check feasibility
-  if (areConstraintsUnfeasible(BRC, Constraints))
+  // Create a refutation manager
+  std::unique_ptr RefutationSolver = CreateZ3Solver();
+  ASTContext &Ctx = BRC.getASTContext();
+
+  // Add constraints to the solver
+  for (const auto &I : Constraints) {
+SymbolRef Sym = I.first;
+
+SMTExprRef Constraints = RefutationSolver->fromBoolean(false);
+for (const auto &Range : I.second) {
+  Constraints = RefutationSolver->mkOr(
+  Constraints,
+  RefutationSolver->getRangeExpr(Ctx, Sym, Range.From(), Range.To(),
+ /*InRange=*/true));
+}
+RefutationSolver->addConstraint(Constraints);
+  }
+
+  // And check for satisfiability
+  if (RefutationSolver->check().isConstrainedFalse())
 BR.markInvalid("Infeasible constraints", EndPathNode->getLocationContext());
 }
 
@@ -2417,8 +2407,17 @@
 BugReporterContext &BRC,
 BugReport &BR) {
   // Collect new constraints
-  addNewConstraints(Constraints, N->getState()->get(),
-N->getState()->get_context());
+  const ConstraintRangeTy &NewCs = N->getState()->get();
+  ConstraintRangeTy::Factory &CF =
+  N->getState()->get_context();
+
+  // Add constraints if we don't have them yet
+  for (auto const &C : NewCs) {
+const SymbolRef &Sym = C.first;
+if (!Constraints.contains(Sym)) {
+  Constraints = CF.add(Constraint

[PATCH] D49769: [analyzer] Use the macro REGISTER_TRAIT_WITH_PROGRAMSTATE in the Z3 backend

2018-07-25 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC337923: [analyzer] Use the macro 
REGISTER_TRAIT_WITH_PROGRAMSTATE in the Z3 backend (authored by mramalho, 
committed by ).
Herald added a subscriber: cfe-commits.

Repository:
  rC Clang

https://reviews.llvm.org/D49769

Files:
  lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp


Index: lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp
===
--- lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp
+++ lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp
@@ -25,28 +25,6 @@
 
 #include 
 
-// Forward declarations
-namespace {
-class Z3Expr;
-class ConstraintZ3 {};
-} // end anonymous namespace
-
-typedef llvm::ImmutableSet> ConstraintZ3Ty;
-
-// Expansion of REGISTER_TRAIT_WITH_PROGRAMSTATE(ConstraintZ3, Z3SetPair)
-namespace clang {
-namespace ento {
-template <>
-struct ProgramStateTrait
-: public ProgramStatePartialTrait {
-  static void *GDMIndex() {
-static int Index;
-return &Index;
-  }
-};
-} // end namespace ento
-} // end namespace clang
-
 namespace {
 
 class Z3Config {
@@ -313,6 +291,13 @@
   llvm::APFloat::semanticsSizeInBits(RHS));
 }
 
+} // end anonymous namespace
+
+typedef llvm::ImmutableSet> ConstraintZ3Ty;
+REGISTER_TRAIT_WITH_PROGRAMSTATE(ConstraintZ3, ConstraintZ3Ty)
+
+namespace {
+
 class Z3Solver : public SMTSolver {
   friend class Z3ConstraintManager;
 


Index: lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp
===
--- lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp
+++ lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp
@@ -25,28 +25,6 @@
 
 #include 
 
-// Forward declarations
-namespace {
-class Z3Expr;
-class ConstraintZ3 {};
-} // end anonymous namespace
-
-typedef llvm::ImmutableSet> ConstraintZ3Ty;
-
-// Expansion of REGISTER_TRAIT_WITH_PROGRAMSTATE(ConstraintZ3, Z3SetPair)
-namespace clang {
-namespace ento {
-template <>
-struct ProgramStateTrait
-: public ProgramStatePartialTrait {
-  static void *GDMIndex() {
-static int Index;
-return &Index;
-  }
-};
-} // end namespace ento
-} // end namespace clang
-
 namespace {
 
 class Z3Config {
@@ -313,6 +291,13 @@
   llvm::APFloat::semanticsSizeInBits(RHS));
 }
 
+} // end anonymous namespace
+
+typedef llvm::ImmutableSet> ConstraintZ3Ty;
+REGISTER_TRAIT_WITH_PROGRAMSTATE(ConstraintZ3, ConstraintZ3Ty)
+
+namespace {
+
 class Z3Solver : public SMTSolver {
   friend class Z3ConstraintManager;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D49267: [clangd] Watch for changes in compile_commands.json

2018-07-25 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a reviewer: ilya-biryukov.
ilya-biryukov added a comment.






Comment at: clangd/ClangdLSPServer.cpp:430
 CDB.clear();
-
-reparseOpenedFiles();
+compileCommandsChangePost(CCChangeData);
   }

ilya-biryukov wrote:
> simark wrote:
> > malaperle wrote:
> > > ilya-biryukov wrote:
> > > > Maybe keep the old logic of reparsing all open files? This would make 
> > > > the change way simpler and I don't think we need this extra complexity 
> > > > in the long run, when we have better integration with the build system.
> > > > 
> > > > ClangdServer will reuse the preamble if compile command didn't change 
> > > > anyway, so reparse will be very fast and shouldn't be affected.
> > > > If the compile command does change, we'll retrigger the full rebuild.
> > > I think the change is not that complex but brings much added value. About 
> > > the integration with the build system, there are many build systems out 
> > > there so I don't think better integration will be useful in many 
> > > scenarios (plain make, custom builds, etc). This solution is generic 
> > > enough so that any build system that generates compile_commands.json will 
> > > be supported in a pretty good way.
> > @malaperle also suggested an alternative way of doing it.  Instead of 
> > saving the the compile commands in a custom structure before clearing the 
> > cache, we could save the compile flags in the `ParsedAST` object.  When 
> > some compile_commands.json changes, we can compare the new compile flags 
> > with this saved copy.  I think it would make the code a bit more 
> > straightforward.
> > I think the change is not that complex but brings much added value.
> > @malaperle also suggested an alternative way of doing it. Instead of saving 
> > the the compile commands in a custom structure before clearing the cache, 
> > we could save the compile flags in the ParsedAST object. When some 
> > compile_commands.json changes, we can compare the new compile flags with 
> > this saved copy. I think it would make the code a bit more straightforward.
> 
> The no-op rebuilds in case nothing changes is a good and long overdue 
> optimization, and I agree that `ParsedAST` or `TUScheduler::update` is 
> probably the right place to put it into. Any other benefits we get from 
> snapshotting the compile commands here? Could we make this optimization in a 
> separate change? It does not seem directly related to the file watching 
> changes. Also happy to look at it, finding the right place to do it might 
> involve digging through layers of classes that manage the AST.
> 
> > About the integration with the build system, there are many build systems 
> > out there so I don't think better integration will be useful in many 
> > scenarios (plain make, custom builds, etc). This solution is generic enough 
> > so that any build system that generates compile_commands.json will be 
> > supported in a pretty good way.
> Just to clarify, the "better buildsystem integration" I refer to is not about 
> enabling support for more build systems (though, that would be nice-to-have), 
> it's about building abstractions that better support the current use-cases, 
> i.e. making the connection between the CompiationDatabase and 
> compiler_commands.json more explicit, allowing the track changes in the build 
> system, etc. We think that file-watching will definitely be part of it, but 
> we don't have full design yet.
> 
> In any case, we do think that there are improvements to be made both in 
> compile_commands.json and in our internal Bazel integration.
D49783 makes the rebuild noop if compile command and preamble deps don't 
change, I think this should be good enough to keep `rebuildOpenedFiles` call 
for now.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D49267



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


[PATCH] D49729: [AST][1/4] Move the bit-fields from TagDecl, EnumDecl and RecordDecl into DeclContext

2018-07-25 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

This looks acceptable to me.  I'd like to get @rsmith or @rnk to approve the 
approach though.


Repository:
  rC Clang

https://reviews.llvm.org/D49729



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


[PATCH] D49794: [libclang] Allow skipping warnings from all included files

2018-07-25 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan created this revision.
yvvan added reviewers: ilya-biryukov, bkramer, akyrtzi, malaperle.

Updated clone for https://reviews.llvm.org/D48116 by Nikolai, now also adds the 
clang driver flag and the test for it.
If clang has plugins they are also affected by this filtering.

Depending on the included files and the used warning flags, e.g. -
Weverything, a huge number of warnings can be reported for included
files. As processing that many diagnostics comes with a performance
impact and not all clients are interested in those diagnostics, add a
flag to skip them.


https://reviews.llvm.org/D49794

Files:
  include/clang-c/Index.h
  include/clang/Basic/Diagnostic.h
  include/clang/Basic/DiagnosticOptions.def
  include/clang/Driver/Options.td
  lib/Basic/DiagnosticIDs.cpp
  lib/Basic/Warnings.cpp
  lib/Frontend/CompilerInvocation.cpp
  tools/c-index-test/c-index-test.c
  tools/libclang/CIndex.cpp

Index: tools/libclang/CIndex.cpp
===
--- tools/libclang/CIndex.cpp
+++ tools/libclang/CIndex.cpp
@@ -3398,6 +3398,9 @@
   if (options & CXTranslationUnit_KeepGoing)
 Diags->setSuppressAfterFatalError(false);
 
+  if (options & CXTranslationUnit_IgnoreNonErrorsFromIncludedFiles)
+  Diags->setSuppressNonErrorsFromIncludedFiles(true);
+
   // Recover resources if we crash before exiting this function.
   llvm::CrashRecoveryContextCleanupRegistrar >
Index: tools/c-index-test/c-index-test.c
===
--- tools/c-index-test/c-index-test.c
+++ tools/c-index-test/c-index-test.c
@@ -84,6 +84,8 @@
 options |= CXTranslationUnit_KeepGoing;
   if (getenv("CINDEXTEST_LIMIT_SKIP_FUNCTION_BODIES_TO_PREAMBLE"))
 options |= CXTranslationUnit_LimitSkipFunctionBodiesToPreamble;
+  if (getenv("CINDEXTEST_IGNORE_NONERRORS_FROM_INCLUDED_FILES"))
+options |= CXTranslationUnit_IgnoreNonErrorsFromIncludedFiles;
 
   return options;
 }
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -1223,6 +1223,8 @@
   Args.getLastArg(OPT_diagnostic_serialized_file, OPT__serialize_diags))
 Opts.DiagnosticSerializationFile = A->getValue();
   Opts.IgnoreWarnings = Args.hasArg(OPT_w);
+  Opts.SuppressNonErrorsFromIncludedFiles =
+  Args.hasArg(OPT_fsuppress_non_errors_from_included_files);
   Opts.NoRewriteMacros = Args.hasArg(OPT_Wno_rewrite_macros);
   Opts.Pedantic = Args.hasArg(OPT_pedantic);
   Opts.PedanticErrors = Args.hasArg(OPT_pedantic_errors);
Index: lib/Basic/Warnings.cpp
===
--- lib/Basic/Warnings.cpp
+++ lib/Basic/Warnings.cpp
@@ -46,6 +46,7 @@
   bool ReportDiags) {
   Diags.setSuppressSystemWarnings(true);  // Default to -Wno-system-headers
   Diags.setIgnoreAllWarnings(Opts.IgnoreWarnings);
+  Diags.setSuppressNonErrorsFromIncludedFiles(Opts.SuppressNonErrorsFromIncludedFiles);
   Diags.setShowOverloads(Opts.getShowOverloads());
 
   Diags.setElideType(Opts.ElideType);
Index: lib/Basic/DiagnosticIDs.cpp
===
--- lib/Basic/DiagnosticIDs.cpp
+++ lib/Basic/DiagnosticIDs.cpp
@@ -477,6 +477,14 @@
   Result = diag::Severity::Fatal;
   }
 
+  // If requested, ignore non-errors from all included files.
+  if (Diag.SuppressNonErrorsFromIncludedFiles &&
+  Result <= diag::Severity::Warning && Loc.isValid() &&
+  !Diag.getSourceManager().isInMainFile(
+  Diag.getSourceManager().getExpansionLoc(Loc))) {
+return diag::Severity::Ignored;
+  }
+
   // Custom diagnostics always are emitted in system headers.
   bool ShowInSystemHeader =
   !GetDiagInfo(DiagID) || GetDiagInfo(DiagID)->WarnShowInSystemHeader;
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1742,6 +1742,8 @@
 def fdebug_prefix_map_EQ
   : Joined<["-"], "fdebug-prefix-map=">, Group, Flags<[CC1Option]>,
 HelpText<"remap file source paths in debug info">;
+def fsuppress_non_errors_from_included_files : Flag<["-"], "fsuppress-non-errors-from-included-files">,
+  Group, Flags<[CC1Option]>;
 def g_Flag : Flag<["-"], "g">, Group,
   HelpText<"Generate source-level debug information">;
 def gline_tables_only : Flag<["-"], "gline-tables-only">, Group,
Index: include/clang/Basic/DiagnosticOptions.def
===
--- include/clang/Basic/DiagnosticOptions.def
+++ include/clang/Basic/DiagnosticOptions.def
@@ -45,6 +45,7 @@
 #endif
 
 SEMANTIC_DIAGOPT(IgnoreWarnings, 1, 0)   /// -w
+DIAGOPT(SuppressNonErrorsFromIncludedFiles, 1, 0)  /// -fsuppress-non-errors-from-included-files
 DIAGOPT(NoRewriteMacros, 1, 0)  /// -Wno-rewrite-macr

[PATCH] D49729: [AST][1/4] Move the bit-fields from TagDecl, EnumDecl and RecordDecl into DeclContext

2018-07-25 Thread Bruno Ricci via Phabricator via cfe-commits
bricci added a comment.

It might be better to wait just after the upcoming release branch in any case
since even though it is all NFC this causes a bit of churn.


Repository:
  rC Clang

https://reviews.llvm.org/D49729



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


[PATCH] D49793: [AArch64] - return address signing

2018-07-25 Thread Javed Absar via Phabricator via cfe-commits
javed.absar added a comment.

Maybe you can provide some more context to this patch (why you need this, or 
point to some document), if possible.




Comment at: include/clang/Frontend/CodeGenOptions.h:111
 
+  enum SignReturnAddressScope { None, Partial, All };
+

Please conform this to the code around (i.e. each option on a separate line 
with comments explaining the option).



Comment at: test/CodeGen/aarch64-sign-return-address.c:5
+
+// NONE: @foo() #[[ATTR:[0-9]*]]
+// NONE-NOT: attributes #[[ATTR]] = { {{.*}} "sign-return-address"={{.*}} }

Can the label check not be under one 'CHECK' prefix? 


Repository:
  rC Clang

https://reviews.llvm.org/D49793



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


[PATCH] D49774: [libc++] Use __int128_t to represent file_time_type.

2018-07-25 Thread Louis Dionne via Phabricator via cfe-commits
ldionne added a comment.

In https://reviews.llvm.org/D49774#1174588, @EricWF wrote:

> In https://reviews.llvm.org/D49774#1174565, @mclow.lists wrote:
>
> > I haven't reviewed this closely, but you might want to look at 
> > http://wg21.link/P0355, where we added a `file_clock` and `file_time` types.
>
>
> Thanks for the information. It doesn't look to have too much bearing on this 
> from a design standpoint. Except to note that it seems to solve
>  the streaming problem by adding explicit streaming overload for time points.


It doesn't change anything from a design standpoint, but I don't think we can 
ship something deemed stable without taking P0355 into account. That's because 
it adds `file_clock` and changes `file_time_type` to use it, which is an ABI 
break. So if we take `filesystem` out of `experimental` and ship it before 
we've actually implemented the parts of P0355 that change the ABI, we'll have 
to take an ABI break in the future. That would suck because this ABI break 
would be necessary to implement C++20 properly in a fairly major way.

That's my understanding. Appart from that, I've read the design docs and while 
I'm not very familiar with the problems involved, I follow the reasoning and I 
think using `__int128_t` makes at least as much sense as the other potential 
solutions.

LGTM


Repository:
  rCXX libc++

https://reviews.llvm.org/D49774



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


[PATCH] D48559: [clangd] refactoring for XPC transport layer [NFCI]

2018-07-25 Thread Jan Korous via Phabricator via cfe-commits
jkorous planned changes to this revision.
jkorous added a comment.

Hi Sam, we are still discussing internally how to fit clangd and XPC together. 
Please bear with us and ignore our patches until we decide.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D48559



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


[libcxx] r337925 - [NFC] Fix grammatical mistakes in libc++ FileTimeType design docs

2018-07-25 Thread Louis Dionne via cfe-commits
Author: ldionne
Date: Wed Jul 25 06:40:49 2018
New Revision: 337925

URL: http://llvm.org/viewvc/llvm-project?rev=337925&view=rev
Log:
[NFC] Fix grammatical mistakes in libc++ FileTimeType design docs

Modified:
libcxx/trunk/docs/DesignDocs/FileTimeType.rst

Modified: libcxx/trunk/docs/DesignDocs/FileTimeType.rst
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/docs/DesignDocs/FileTimeType.rst?rev=337925&r1=337924&r2=337925&view=diff
==
--- libcxx/trunk/docs/DesignDocs/FileTimeType.rst (original)
+++ libcxx/trunk/docs/DesignDocs/FileTimeType.rst Wed Jul 25 06:40:49 2018
@@ -61,7 +61,7 @@ of representing the range of the ``times
 Problems To Consider
 
 
-Before considering solutions, lets consider the problems they should solve,
+Before considering solutions, let's consider the problems they should solve,
 and how important solving those problems are:
 
 
@@ -187,7 +187,7 @@ Source Code Portability Across Implement
 As we've discussed, ``file_time_type`` needs a representation that uses more
 than 64 bits. The possible solutions include using ``__int128_t``, emulating a
 128 bit integer using a class, or potentially defining a ``timespec`` like
-arithmetic type. All three will solve allow us to, at minimum, match the range
+arithmetic type. All three will allow us to, at minimum, match the range
 and resolution, and the last one might even allow us to match them exactly.
 
 But when considering these potential solutions we need to consider more than
@@ -214,7 +214,7 @@ code in some way:
 
   file_time_type correct_timespec_to_file_time_type(struct timespec ts) {
 // This is the correct version of the above example, where we
-// avoid using the chrono typedefs as their not sufficient.
+// avoid using the chrono typedefs as they're not sufficient.
 // Can we expect users to avoid this bug?
 using fs_seconds = chrono::duration;
 using fs_nanoseconds = chrono::duration;
@@ -252,7 +252,7 @@ what the underlying system uses, and bec
 the range and resolution exactly. But would it work with chrono? And could
 it still act at all like a ``timespec`` struct?
 
-For ease of consideration, lets consider the what the implementation might
+For ease of consideration, let's consider what the implementation might
 look like.
 
 .. code-block:: cpp
@@ -278,11 +278,11 @@ directly. A ``chrono::duration`` represe
 number of ticks stored using ``rep``. The representation is unaware of the
 tick period it is being used to represent, but ``timespec`` is setup to assume
 a nanosecond tick period; which is the only case where the names ``tv_sec``
-and ``tv_nsec`` matche the values they store.
+and ``tv_nsec`` match the values they store.
 
-When we convert a nanosecond duration to a seconds, ``fs_timespec_rep`` will
+When we convert a nanosecond duration to seconds, ``fs_timespec_rep`` will
 use ``tv_sec`` to represent the number of giga seconds, and ``tv_nsec`` the
-remaining seconds. Lets consider how this might cause a bug were users allowed
+remaining seconds. Let's consider how this might cause a bug were users allowed
 to manipulate the fields directly.
 
 .. code-block:: cpp
@@ -364,8 +364,8 @@ described by this paper.
 Obviously our implementation for 32-bit builds should act as similarly to the
 64-bit build as possible. Code which compiles in one, should compile in the 
other.
 This consideration is important when choosing between ``__int128_t`` and
-emulating ``timespec``. The solution which provides the most uniformity is
-the preferable one, with the least eccentricity is the preferable one.
+emulating ``timespec``. The solution which provides the most uniformity with
+the least eccentricity is the preferable one.
 
 Summary
 ===
@@ -391,7 +391,7 @@ The Potential Solutions
 
 Pros:
 
-* As a type ``long long`` places the nicest with others:
+* As a type ``long long`` plays the nicest with others:
 
   * It works with streaming operators and other library entities which support
 builtin integer types, but don't support ``__int128_t``.


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


[PATCH] D49796: [ASTImporter] Load external Decls when getting field index.

2018-07-25 Thread Balázs Kéri via Phabricator via cfe-commits
balazske created this revision.
Herald added subscribers: cfe-commits, martong.
Herald added a reviewer: a.sidorin.

At equality check of fields without name the index of fields is compared.
At determining the index of a field all fields of the parent context
should be loaded from external source to find the field at all.


Repository:
  rC Clang

https://reviews.llvm.org/D49796

Files:
  lib/AST/ASTImporter.cpp
  test/ASTMerge/unnamed_fields/Inputs/il.cpp
  test/ASTMerge/unnamed_fields/test.cpp
  unittests/AST/ASTImporterTest.cpp


Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -2612,6 +2612,45 @@
   R1, recordDecl(has(fieldDecl(hasName("next"));
 }
 
+TEST_P(ASTImporterTestBase, ImportUnnamedFieldsInCorrectOrder) {
+  Decl *FromTU = getTuDecl(
+  R"(
+  void f(int X, int Y, bool Z) {
+(void)[X, Y, Z] { (void)Z; };
+  }
+  )",
+  Lang_CXX11, "input0.cc");
+  auto *FromF = FirstDeclMatcher().match(
+  FromTU, functionDecl(hasName("f")));
+  auto *ToF = cast_or_null(Import(FromF, Lang_CXX11));
+  EXPECT_TRUE(ToF);
+
+  CXXRecordDecl *FromLambda =
+  cast(cast(cast(
+  FromF->getBody())->body_front())->getSubExpr())->getLambdaClass();
+
+  auto *ToLambda = cast_or_null(Import(FromLambda, Lang_CXX11));
+  EXPECT_TRUE(ToLambda);
+
+  // Check if the fields of the lambda class are imported in correct order.
+  unsigned FromIndex = 0u;
+  for (auto *FromField : FromLambda->fields()) {
+ASSERT_FALSE(FromField->getDeclName());
+auto *ToField = cast_or_null(Import(FromField, Lang_CXX11));
+EXPECT_TRUE(ToField);
+unsigned ToIndex = 0u;
+for (auto *F : ToLambda->fields()) {
+  if (F == ToField)
+break;
+  ++ToIndex;
+}
+EXPECT_EQ(ToIndex, FromIndex);
+++FromIndex;
+  }
+
+  EXPECT_EQ(FromIndex, 3u);
+}
+
 struct DeclContextTest : ASTImporterTestBase {};
 
 TEST_P(DeclContextTest, removeDeclOfClassTemplateSpecialization) {
Index: test/ASTMerge/unnamed_fields/test.cpp
===
--- /dev/null
+++ test/ASTMerge/unnamed_fields/test.cpp
@@ -0,0 +1,3 @@
+// RUN: %clang_cc1 -emit-pch -o %t.1.ast %S/Inputs/il.cpp
+// RUN: %clang_cc1 -ast-merge %t.1.ast -fsyntax-only %s 2>&1 | FileCheck 
--allow-empty %s
+// CHECK-NOT: warning: field '' declared with incompatible types in different 
translation units ('bool' vs. 'int')
Index: test/ASTMerge/unnamed_fields/Inputs/il.cpp
===
--- /dev/null
+++ test/ASTMerge/unnamed_fields/Inputs/il.cpp
@@ -0,0 +1,3 @@
+void f(int X, int Y, bool Z) {
+  auto x = [X, Y, Z] { (void)Z; };
+}
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -2829,15 +2829,17 @@
 return 0;
 
   unsigned Index = 1;
-  for (const auto *D : Owner->noload_decls()) {
+  for (const auto *D : Owner->decls()) {
 if (D == F)
   return Index;
 
 if (isa(*D) || isa(*D))
   ++Index;
   }
 
-  return Index;
+  assert(false && "Field was not found in its parent context.");
+
+  return 0;
 }
 
 Decl *ASTNodeImporter::VisitFieldDecl(FieldDecl *D) {


Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -2612,6 +2612,45 @@
   R1, recordDecl(has(fieldDecl(hasName("next"));
 }
 
+TEST_P(ASTImporterTestBase, ImportUnnamedFieldsInCorrectOrder) {
+  Decl *FromTU = getTuDecl(
+  R"(
+  void f(int X, int Y, bool Z) {
+(void)[X, Y, Z] { (void)Z; };
+  }
+  )",
+  Lang_CXX11, "input0.cc");
+  auto *FromF = FirstDeclMatcher().match(
+  FromTU, functionDecl(hasName("f")));
+  auto *ToF = cast_or_null(Import(FromF, Lang_CXX11));
+  EXPECT_TRUE(ToF);
+
+  CXXRecordDecl *FromLambda =
+  cast(cast(cast(
+  FromF->getBody())->body_front())->getSubExpr())->getLambdaClass();
+
+  auto *ToLambda = cast_or_null(Import(FromLambda, Lang_CXX11));
+  EXPECT_TRUE(ToLambda);
+
+  // Check if the fields of the lambda class are imported in correct order.
+  unsigned FromIndex = 0u;
+  for (auto *FromField : FromLambda->fields()) {
+ASSERT_FALSE(FromField->getDeclName());
+auto *ToField = cast_or_null(Import(FromField, Lang_CXX11));
+EXPECT_TRUE(ToField);
+unsigned ToIndex = 0u;
+for (auto *F : ToLambda->fields()) {
+  if (F == ToField)
+break;
+  ++ToIndex;
+}
+EXPECT_EQ(ToIndex, FromIndex);
+++FromIndex;
+  }
+
+  EXPECT_EQ(FromIndex, 3u);
+}
+
 struct DeclContextTest : ASTImporterTestBase {};
 
 TEST_P(DeclContextTest, removeDeclOfClassTemplateSpecialization) {
Index: test/ASTMerge/unnamed_fields/test.cpp

[PATCH] D49788: [Docs] Update supported oses for ubsan, asan and msan

2018-07-25 Thread Kamil Rytarowski via Phabricator via cfe-commits
krytarowski accepted this revision.
krytarowski added a comment.
This revision is now accepted and ready to land.

Please improve the commit description and reflect with reality.


https://reviews.llvm.org/D49788



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


r337926 - [Docs] Update supported oses for safestack, ubsan, asan, tsan and msan

2018-07-25 Thread David Carlier via cfe-commits
Author: devnexen
Date: Wed Jul 25 06:55:06 2018
New Revision: 337926

URL: http://llvm.org/viewvc/llvm-project?rev=337926&view=rev
Log:
[Docs] Update supported oses for safestack, ubsan, asan, tsan and msan

Adding oses others than Linux.

Modified:
cfe/trunk/docs/AddressSanitizer.rst
cfe/trunk/docs/MemorySanitizer.rst
cfe/trunk/docs/SafeStack.rst
cfe/trunk/docs/ThreadSanitizer.rst
cfe/trunk/docs/UndefinedBehaviorSanitizer.rst

Modified: cfe/trunk/docs/AddressSanitizer.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/AddressSanitizer.rst?rev=337926&r1=337925&r2=337926&view=diff
==
--- cfe/trunk/docs/AddressSanitizer.rst (original)
+++ cfe/trunk/docs/AddressSanitizer.rst Wed Jul 25 06:55:06 2018
@@ -276,6 +276,7 @@ AddressSanitizer is supported on:
 * OS X 10.7 - 10.11 (i386/x86\_64)
 * iOS Simulator
 * Android ARM
+* NetBSD i386/x86\_64
 * FreeBSD i386/x86\_64 (tested on FreeBSD 11-current)
 
 Ports to various other platforms are in progress.

Modified: cfe/trunk/docs/MemorySanitizer.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/MemorySanitizer.rst?rev=337926&r1=337925&r2=337926&view=diff
==
--- cfe/trunk/docs/MemorySanitizer.rst (original)
+++ cfe/trunk/docs/MemorySanitizer.rst Wed Jul 25 06:55:06 2018
@@ -185,7 +185,11 @@ self-built instrumented libc++ (as a rep
 Supported Platforms
 ===
 
-MemorySanitizer is supported on Linux x86\_64/MIPS64/AArch64.
+MemorySanitizer is supported on the following OS:
+
+* Linux
+* NetBSD
+* FreeBSD
 
 Limitations
 ===

Modified: cfe/trunk/docs/SafeStack.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/SafeStack.rst?rev=337926&r1=337925&r2=337926&view=diff
==
--- cfe/trunk/docs/SafeStack.rst (original)
+++ cfe/trunk/docs/SafeStack.rst Wed Jul 25 06:55:06 2018
@@ -126,7 +126,7 @@ and link command lines.
 Supported Platforms
 ---
 
-SafeStack was tested on Linux, FreeBSD and MacOSX.
+SafeStack was tested on Linux, NetBSD, FreeBSD and MacOSX.
 
 Low-level API
 -

Modified: cfe/trunk/docs/ThreadSanitizer.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ThreadSanitizer.rst?rev=337926&r1=337925&r2=337926&view=diff
==
--- cfe/trunk/docs/ThreadSanitizer.rst (original)
+++ cfe/trunk/docs/ThreadSanitizer.rst Wed Jul 25 06:55:06 2018
@@ -17,7 +17,11 @@ Build LLVM/Clang with `CMake 

[PATCH] D49788: [Docs] Update supported oses for ubsan, asan and msan

2018-07-25 Thread David CARLIER via Phabricator via cfe-commits
devnexen closed this revision.
devnexen added a comment.

Exited too early fro the editor ,.. did not write all the lines but commited 
with https://reviews.llvm.org/rC337926


https://reviews.llvm.org/D49788



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


[PATCH] D49797: [clang-format] Indent after breaking Javadoc annotated line

2018-07-25 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir created this revision.
Herald added subscribers: cfe-commits, acoomans.

This patch makes clang-format indent the subsequent lines created by breaking a
long javadoc annotated line.


Repository:
  rC Clang

https://reviews.llvm.org/D49797

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

Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -2058,8 +2058,8 @@
   verifyFormat(
   "/**\n"
   " * @param This is a\n"
-  " * long comment but\n"
-  " * no type\n"
+  " * long comment\n"
+  " * but no type\n"
   " */",
   "/**\n"
   " * @param This is a long comment but no type\n"
Index: unittests/Format/FormatTestComments.cpp
===
--- unittests/Format/FormatTestComments.cpp
+++ unittests/Format/FormatTestComments.cpp
@@ -3105,6 +3105,87 @@
 // clang-format on
 }
 
+TEST_F(FormatTestComments, IndentsLongJavadocAnnotatedLines) {
+  FormatStyle Style = getGoogleStyle(FormatStyle::LK_Java);
+  Style.ColumnLimit = 60;
+  FormatStyle Style20 = getGoogleStyle(FormatStyle::LK_Java);
+  Style20.ColumnLimit = 20;
+  EXPECT_EQ(
+  "/**\n"
+  " * @param x long long long long long long long long long\n"
+  " * long\n"
+  " */\n",
+  format("/**\n"
+ " * @param x long long long long long long long long long long\n"
+ " */\n",
+ Style));
+  EXPECT_EQ("/**\n"
+" * @param x long long long long long long long long long\n"
+" * long long long long long long long long long long\n"
+" */\n",
+format("/**\n"
+   " * @param x long long long long long long long long long "
+   "long long long long long long long long long long\n"
+   " */\n",
+   Style));
+  EXPECT_EQ("/**\n"
+" * @param x long long long long long long long long long\n"
+" * long long long long long long long long long long\n"
+" * long\n"
+" */\n",
+format("/**\n"
+   " * @param x long long long long long long long long long "
+   "long long long long long long long long long long long\n"
+   " */\n",
+   Style));
+  EXPECT_EQ(
+  "/**\n"
+  " * Sentence that\n"
+  " * should be broken.\n"
+  " * @param short\n"
+  " * keep indentation\n"
+  " */\n", format(
+  "/**\n"
+  " * Sentence that should be broken.\n"
+  " * @param short\n"
+  " * keep indentation\n"
+  " */\n", Style20));
+
+  EXPECT_EQ("/**\n"
+" * @param l1 long1\n"
+" * to break\n"
+" * @param l2 long2\n"
+" * to break\n"
+" */\n",
+format("/**\n"
+   " * @param l1 long1 to break\n"
+   " * @param l2 long2 to break\n"
+   " */\n",
+   Style20));
+
+  EXPECT_EQ("/**\n"
+" * @param xx to\n"
+" * break\n"
+" * no reflow\n"
+" */\n",
+format("/**\n"
+   " * @param xx to break\n"
+   " * no reflow\n"
+   " */\n",
+   Style20));
+
+  EXPECT_EQ("/**\n"
+" * @param xx to\n"
+" * break yes\n"
+" * reflow\n"
+" */\n",
+format("/**\n"
+   " * @param xx to break\n"
+   " * yes reflow\n"
+   " */\n",
+   Style20));
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -22,6 +22,11 @@
 #include "llvm/Support/Debug.h"
 
 #define DEBUG_TYPE "format-indenter"
+#define DBG(A) \
+  LLVM_DEBUG({ \
+llvm::errs() << __func__ << ":" << __LINE__ << ":" << #A << " = " << A \
+ << "\n";  \
+  })
 
 namespace clang {
 namespace format {
@@ -1782,6 +1787,7 @@
   if (!DryRun)
 Token->adaptStartOfLine(0, Whitespaces);
 
+  unsigned ContentIndent = 0;
   unsigned Penalty = 0;
   LLVM_DEBUG(llvm::dbgs() << "Breaking protruding token at column "
   << StartColumn << ".\n");
@@ -1903,8 +1909,15 @@
 }
   }
   LLVM_DEBUG(llvm::dbgs() << " 

[PATCH] D49546: [clangd] Proof-of-concept query iterators for Dex symbol index

2018-07-25 Thread Eric Liu via Phabricator via cfe-commits
ioeric added a comment.

Implementation is in a good shape. I only have nits ;)




Comment at: clang-tools-extra/clangd/index/dex/Iterator.cpp:18
+namespace clangd {
+namespace dex {
+

Please put all local classes and helpers in an anonymous namespace.



Comment at: clang-tools-extra/clangd/index/dex/Iterator.cpp:20
+
+/// Implements Iterator over a PostingList.
+class DocumentIterator : public Iterator {

nit: We could elaborate a bit. This is the most basic or "leaf" iterator.



Comment at: clang-tools-extra/clangd/index/dex/Iterator.cpp:30
+  ///
+  /// Complexity: O(1).
+  void advance() override {

nit: The complexity is obvious, so I'd probably drop it as this is not public.



Comment at: clang-tools-extra/clangd/index/dex/Iterator.cpp:39
+  ///
+  /// Complexity: O(log(N)), N is the size of underlying PostingList.
+  void advanceTo(DocID ID) override {

Again, this should also be obvious given the short implementation.



Comment at: clang-tools-extra/clangd/index/dex/Iterator.cpp:68
+///
+/// AndIterator advances through items which can be pointed to by each child
+/// iterator. It becomes exhausted as soon as any child becomes exhausted. 
After

I'm not exactly sure what this means. Do you mean "AndIterator iterates through 
common items among all children"?



Comment at: clang-tools-extra/clangd/index/dex/Iterator.cpp:75
+  AndIterator(std::vector> AllChildren)
+  : Children(std::move(AllChildren)), ReachedEnd(false) {
+assert(!Children.empty() && "AndIterator should have at least one child.");

nit: `ReachedEnd` is reset in `sync()`. Maybe just make it default value for 
the field?



Comment at: clang-tools-extra/clangd/index/dex/Iterator.cpp:112
+  /// Restores class invariants: each child should point to the same element,
+  /// ReachedEnd indicates whether any child is exhausted.
+  void sync() {

nit: documentation for `ReachedEnd` is already covered below.



Comment at: clang-tools-extra/clangd/index/dex/Iterator.cpp:114
+  void sync() {
+ReachedEnd = Children.front()->reachedEnd();
+if (ReachedEnd)

nit: `ReachedEnd &= ...;` would keep me from worrying about true ReachedEnd 
getting overridden.



Comment at: clang-tools-extra/clangd/index/dex/Iterator.cpp:117
+  return;
+auto ID = Children.front()->peek();
+bool NeedsAdvance = false;

nit: `SyncID`  or `Sync` might be clearer.



Comment at: clang-tools-extra/clangd/index/dex/Iterator.cpp:118
+auto ID = Children.front()->peek();
+bool NeedsAdvance = false;
+do {

Maybe add a comment `NeedsAdvance` indicates whether `advanceTo(ID)` should be 
rerun from the beginning. 



Comment at: clang-tools-extra/clangd/index/dex/Iterator.cpp:145
+  std::vector> Children;
+  /// Local state, which indicates whether any child is exhausted. It is 
cheaper
+  /// to maintain and update a local state, rather than traversing the whole

nit: why "local state"?  (All instance fields are local states)



Comment at: clang-tools-extra/clangd/index/dex/Iterator.cpp:166
+  bool reachedEnd() const override {
+for (const auto &Child : Children)
+  if (!Child->reachedEnd())

use `std::any_of(...)`?



Comment at: clang-tools-extra/clangd/index/dex/Iterator.cpp:176
+   "OrIterator must have at least one child to advance().");
+const auto HighestID = peek();
+for (const auto &Child : Children) {

The comment says `smallest DocID`, but here we call it `highest` :( 



Comment at: clang-tools-extra/clangd/index/dex/Iterator.cpp:178
+for (const auto &Child : Children) {
+  if (!Child->reachedEnd() && Child->peek() == HighestID) {
+Child->advance();

nit: no braces for one-liners.



Comment at: clang-tools-extra/clangd/index/dex/Iterator.cpp:218
+private:
+  // FIXME(kbobyrev): Would storing Children in min-heap be faster?
+  std::vector> Children;

I think this FIXME should live in `peek()` as it's an optimization for `peek()`.



Comment at: clang-tools-extra/clangd/index/dex/Iterator.h:10
+//
+// This file defines interface for Query Tree Nodes - Iterators, which process
+// posting lists and yield the result of contracted search query.

I think we should give more context here. For example, it's unclear what `Query 
Tree Nodes` are. `Posting list` is  not a widely known concept. What is the 
idea behind iterators? What problem do they solve? Roughly what iterators are 
provided? An example like ascii graph you have in the test can be useful here 
as well.



Com

r337927 - Fix tsan doc

2018-07-25 Thread David Carlier via cfe-commits
Author: devnexen
Date: Wed Jul 25 07:27:14 2018
New Revision: 337927

URL: http://llvm.org/viewvc/llvm-project?rev=337927&view=rev
Log:
Fix tsan doc

Modified:
cfe/trunk/docs/ThreadSanitizer.rst

Modified: cfe/trunk/docs/ThreadSanitizer.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ThreadSanitizer.rst?rev=337927&r1=337926&r2=337927&view=diff
==
--- cfe/trunk/docs/ThreadSanitizer.rst (original)
+++ cfe/trunk/docs/ThreadSanitizer.rst Wed Jul 25 07:27:14 2018
@@ -22,6 +22,7 @@ ThreadSanitizer is supported on the foll
 * Linux
 * NetBSD
 * FreeBSD
+
 Support for other 64-bit architectures is possible, contributions are welcome.
 Support for 32-bit platforms is problematic and is not planned.
 


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


[PATCH] D49774: [libc++] Use __int128_t to represent file_time_type.

2018-07-25 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists added a comment.

In https://reviews.llvm.org/D49774#1175062, @ldionne wrote:

> In https://reviews.llvm.org/D49774#1174588, @EricWF wrote:
>
> > In https://reviews.llvm.org/D49774#1174565, @mclow.lists wrote:
> >
> > > I haven't reviewed this closely, but you might want to look at 
> > > http://wg21.link/P0355, where we added a `file_clock` and `file_time` 
> > > types.
> >
> >
> > Thanks for the information. It doesn't look to have too much bearing on 
> > this from a design standpoint. Except to note that it seems to solve
> >  the streaming problem by adding explicit streaming overload for time 
> > points.
>
>
> It doesn't change anything from a design standpoint, but I don't think we can 
> ship something deemed stable without taking P0355 into account. That's 
> because it adds `file_clock` and changes `file_time_type` to use it, which is 
> an ABI break. So if we take `filesystem` out of `experimental` and ship it 
> before we've actually implemented the parts of P0355 that change the ABI, 
> we'll have to take an ABI break in the future. That would suck because this 
> ABI break would be necessary to implement C++20 properly in a fairly major 
> way.


Another problem (that Eric and I discussed last night) is that filesystem is 
part of C++17, and `file_clock` is C++20. So we need a solution for C++17 as 
well.


Repository:
  rCXX libc++

https://reviews.llvm.org/D49774



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


[PATCH] D49785: [clangd] Give an example for global-symbol-builder usage

2018-07-25 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 157263.
kbobyrev marked 2 inline comments as done.
kbobyrev added a comment.

Addressed two comments, added an example of running the tool over a number of 
source files without providing `compile_commands.json`; added a note about 
collecting files from headers only.


https://reviews.llvm.org/D49785

Files:
  clang-tools-extra/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp


Index: 
clang-tools-extra/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
===
--- clang-tools-extra/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
+++ clang-tools-extra/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
@@ -150,10 +150,23 @@
 int main(int argc, const char **argv) {
   llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
 
-  const char* Overview =
-  "This is an **experimental** tool to generate YAML-format "
-  "project-wide symbols for clangd (global code completion). It would be "
-  "changed and deprecated eventually. Don't use it in production code!";
+  const char *Overview = R"(
+  This is an **experimental** tool to generate YAML-format project-wide symbols
+  for clangd (global code completion). It would be changed and deprecated
+  eventually. Don't use it in production code!
+
+  Example usage for building index for the whole project using CMake compile
+  commands:
+
+  $ global-symbol-builder --executor=all-TUs compile_commands.json > index.yaml
+
+  Example usage for file sequence index without flags:
+
+  $ global-symbol-builder File1.cpp File2.cpp ... FileN.cpp > index.yaml
+
+  Note: only symbols from header files will be collected.
+  )";
+
   auto Executor = clang::tooling::createExecutorFromCommandLineArgs(
   argc, argv, cl::GeneralCategory, Overview);
 


Index: clang-tools-extra/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
===
--- clang-tools-extra/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
+++ clang-tools-extra/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
@@ -150,10 +150,23 @@
 int main(int argc, const char **argv) {
   llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
 
-  const char* Overview =
-  "This is an **experimental** tool to generate YAML-format "
-  "project-wide symbols for clangd (global code completion). It would be "
-  "changed and deprecated eventually. Don't use it in production code!";
+  const char *Overview = R"(
+  This is an **experimental** tool to generate YAML-format project-wide symbols
+  for clangd (global code completion). It would be changed and deprecated
+  eventually. Don't use it in production code!
+
+  Example usage for building index for the whole project using CMake compile
+  commands:
+
+  $ global-symbol-builder --executor=all-TUs compile_commands.json > index.yaml
+
+  Example usage for file sequence index without flags:
+
+  $ global-symbol-builder File1.cpp File2.cpp ... FileN.cpp > index.yaml
+
+  Note: only symbols from header files will be collected.
+  )";
+
   auto Executor = clang::tooling::createExecutorFromCommandLineArgs(
   argc, argv, cl::GeneralCategory, Overview);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r337928 - [OPENMP] Fix PR38256: Fix locations of the artificial conditional op.

2018-07-25 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Wed Jul 25 07:40:26 2018
New Revision: 337928

URL: http://llvm.org/viewvc/llvm-project?rev=337928&view=rev
Log:
[OPENMP] Fix PR38256: Fix locations of the artificial conditional op.

Fixed the source locations of the conditional op so that they don'r
crash coverage pass.

Added:
cfe/trunk/test/CoverageMapping/openmp.c
Modified:
cfe/trunk/lib/Sema/SemaOpenMP.cpp

Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=337928&r1=337927&r2=337928&view=diff
==
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Wed Jul 25 07:40:26 2018
@@ -4909,7 +4909,8 @@ checkOpenMPLoop(OpenMPDirectiveKind DKin
 ExprResult IsUBGreater = SemaRef.BuildBinOp(CurScope, InitLoc, BO_GT,
 UB.get(), LastIteration.get());
 ExprResult CondOp = SemaRef.ActOnConditionalOp(
-InitLoc, InitLoc, IsUBGreater.get(), LastIteration.get(), UB.get());
+LastIteration.get()->getExprLoc(), InitLoc, IsUBGreater.get(),
+LastIteration.get(), UB.get());
 EUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, UB.get(),
  CondOp.get());
 EUB = SemaRef.ActOnFinishFullExpr(EUB.get());

Added: cfe/trunk/test/CoverageMapping/openmp.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/openmp.c?rev=337928&view=auto
==
--- cfe/trunk/test/CoverageMapping/openmp.c (added)
+++ cfe/trunk/test/CoverageMapping/openmp.c Wed Jul 25 07:40:26 2018
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -fopenmp -fprofile-instrument=clang -fcoverage-mapping 
-dump-coverage-mapping -emit-llvm-only -main-file-name openmp.c %s | FileCheck 
%s
+
+// CHECK: openmp.c:{{.+}}omp_outlined{{.+}}:
+// CHECK: File 0, 10:3 -> 10:31
+// CHECK: File 0, 10:19 -> 10:24
+// CHECK: File 0, 10:26 -> 10:29
+// CHECK: File 0, 10:30 -> 10:31
+int foo(int time, int n) {
+#pragma omp parallel for default(shared) schedule(dynamic, 1) reduction(+ : 
time)
+  for (int i = 1; i < n; ++i);
+  return 0;
+}


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


[PATCH] D49783: [clangd] Do not rebuild AST if inputs have not changed

2018-07-25 Thread Eric Liu via Phabricator via cfe-commits
ioeric added inline comments.



Comment at: clangd/TUScheduler.cpp:357
+
+bool CanReuseAST = InputsAreTheSame && OldPreamble == NewPreamble;
 {

nit: `(OldPreamble == NewPreamble)`

Do you intend to compare the shared pointer instead of the values?



Comment at: clangd/TUScheduler.cpp:360
   std::lock_guard Lock(Mutex);
+  OldPreamble.reset();
   if (NewPreamble)

Why reset?



Comment at: clangd/TUScheduler.cpp:373
+  // FIXME(ibiryukov): the AST could actually change if non-preamble
+  // includes changed, but we choose to ignore it.
+  // FIXME(ibiryukov): should we refresh the cache in IdleASTs for the

Do we choose to ignore this because it's rare? What are non-preamble #includes?



Comment at: clangd/TUScheduler.cpp:376
+  // current file at this point?
+  vlog("Skipping rebuild of the AST for {0}, inputs are the same.",
+   FileName);

I think this can be a `log`.



Comment at: test/clangd/extra-flags.test:26
 ---
-{"jsonrpc":"2.0","method":"textDocument/didChange","params":{"textDocument":{"uri":"test:///foo.c","version":2},"contentChanges":[{"text":"int
 main() { int i; return i; }"}]}}
+{"jsonrpc":"2.0","method":"textDocument/didChange","params":{"textDocument":{"uri":"test:///foo.c","version":2},"contentChanges":[{"text":"int
 main() { int i; return i+1; }"}]}}
 #  CHECK:  "method": "textDocument/publishDiagnostics",

Why this change?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D49783



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


[PATCH] D49798: [ASTImporter] Adding some friend function related unittests.

2018-07-25 Thread Balázs Kéri via Phabricator via cfe-commits
balazske created this revision.
Herald added subscribers: cfe-commits, martong.
Herald added a reviewer: a.sidorin.

Repository:
  rC Clang

https://reviews.llvm.org/D49798

Files:
  unittests/AST/ASTImporterTest.cpp

Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -2241,6 +2241,217 @@
   EXPECT_EQ(ImportedD1->getPreviousDecl(), ImportedD);
 }
 
+TEST_P(ImportFriendFunctions, Lookup) {
+  auto Pattern = functionDecl(hasName("f"));
+
+  Decl *FromTU =
+  getTuDecl("struct X { friend void f(); };", Lang_CXX, "input0.cc");
+  auto FromD = FirstDeclMatcher().match(FromTU, Pattern);
+  ASSERT_TRUE(FromD->isInIdentifierNamespace(Decl::IDNS_OrdinaryFriend));
+  ASSERT_TRUE(!FromD->isInIdentifierNamespace(Decl::IDNS_Ordinary));
+  auto FromName = FromD->getDeclName();
+  {
+CXXRecordDecl *Class =
+FirstDeclMatcher().match(FromTU, cxxRecordDecl());
+auto lookup_res = Class->noload_lookup(FromName);
+ASSERT_EQ(lookup_res.size(), 0u);
+lookup_res = cast(FromTU)->noload_lookup(FromName);
+ASSERT_EQ(lookup_res.size(), 1u);
+  }
+
+  auto ToD = cast(Import(FromD, Lang_CXX));
+  auto ToName = ToD->getDeclName();
+
+  {
+Decl *ToTU = ToAST->getASTContext().getTranslationUnitDecl();
+CXXRecordDecl *Class =
+FirstDeclMatcher().match(ToTU, cxxRecordDecl());
+auto lookup_res = Class->noload_lookup(ToName);
+EXPECT_EQ(lookup_res.size(), 0u);
+lookup_res = cast(ToTU)->noload_lookup(ToName);
+EXPECT_EQ(lookup_res.size(), 1u);
+  }
+
+  Decl *ToTU = ToAST->getASTContext().getTranslationUnitDecl();
+  ASSERT_EQ(DeclCounter().match(ToTU, Pattern), 1u);
+  auto To0 = FirstDeclMatcher().match(ToTU, Pattern);
+  EXPECT_TRUE(To0->isInIdentifierNamespace(Decl::IDNS_OrdinaryFriend));
+  EXPECT_TRUE(!To0->isInIdentifierNamespace(Decl::IDNS_Ordinary));
+}
+
+TEST_P(ImportFriendFunctions, DISABLED_LookupWithProto) {
+  auto Pattern = functionDecl(hasName("f"));
+
+  Decl *FromTU =
+  getTuDecl("struct X { friend void f(); };"
+// This proto decl makes f available to normal
+// lookup, otherwise it is hidden.
+// Normal C++ lookup (implemented in
+// `clang::Sema::CppLookupName()` and in `LookupDirect()`)
+// returns the found `NamedDecl` only if the set IDNS is matched
+"void f();",
+Lang_CXX, "input0.cc");
+  auto From0 = FirstDeclMatcher().match(FromTU, Pattern);
+  auto From1 = LastDeclMatcher().match(FromTU, Pattern);
+  ASSERT_TRUE(From0->isInIdentifierNamespace(Decl::IDNS_OrdinaryFriend));
+  ASSERT_TRUE(!From0->isInIdentifierNamespace(Decl::IDNS_Ordinary));
+  ASSERT_TRUE(!From1->isInIdentifierNamespace(Decl::IDNS_OrdinaryFriend));
+  ASSERT_TRUE(From1->isInIdentifierNamespace(Decl::IDNS_Ordinary));
+  auto FromName = From0->getDeclName();
+  {
+CXXRecordDecl *Class =
+FirstDeclMatcher().match(FromTU, cxxRecordDecl());
+auto lookup_res = Class->noload_lookup(FromName);
+ASSERT_EQ(lookup_res.size(), 0u);
+lookup_res = cast(FromTU)->noload_lookup(FromName);
+ASSERT_EQ(lookup_res.size(), 1u);
+  }
+
+  auto To0 = cast(Import(From0, Lang_CXX));
+  auto ToName = To0->getDeclName();
+
+  {
+auto ToTU = ToAST->getASTContext().getTranslationUnitDecl();
+CXXRecordDecl *Class =
+FirstDeclMatcher().match(ToTU, cxxRecordDecl());
+auto lookup_res = Class->noload_lookup(ToName);
+EXPECT_EQ(lookup_res.size(), 0u);
+lookup_res = ToTU->noload_lookup(ToName);
+EXPECT_EQ(lookup_res.size(), 1u);
+  }
+
+  auto ToTU = ToAST->getASTContext().getTranslationUnitDecl();
+  ASSERT_EQ(DeclCounter().match(ToTU, Pattern), 2u);
+  To0 = FirstDeclMatcher().match(ToTU, Pattern);
+  auto To1 = LastDeclMatcher().match(ToTU, Pattern);
+  EXPECT_TRUE(To0->isInIdentifierNamespace(Decl::IDNS_OrdinaryFriend));
+  EXPECT_TRUE(!To0->isInIdentifierNamespace(Decl::IDNS_Ordinary));
+  EXPECT_TRUE(!To1->isInIdentifierNamespace(Decl::IDNS_OrdinaryFriend));
+  EXPECT_TRUE(To1->isInIdentifierNamespace(Decl::IDNS_Ordinary));
+}
+
+TEST_P(ImportFriendFunctions, LookupWithProtoFirst) {
+  auto Pattern = functionDecl(hasName("f"));
+
+  Decl *FromTU =
+  getTuDecl("void f();"
+"struct X { friend void f(); };",
+Lang_CXX, "input0.cc");
+  auto From0 = FirstDeclMatcher().match(FromTU, Pattern);
+  auto From1 = LastDeclMatcher().match(FromTU, Pattern);
+  ASSERT_TRUE(!From0->isInIdentifierNamespace(Decl::IDNS_OrdinaryFriend));
+  ASSERT_TRUE(From0->isInIdentifierNamespace(Decl::IDNS_Ordinary));
+  ASSERT_TRUE(From1->isInIdentifierNamespace(Decl::IDNS_OrdinaryFriend));
+  ASSERT_TRUE(From1->isInIdentifierNamespace(Decl::IDNS_Ordinary));
+  auto FromName = From0->getDeclName();
+  {
+CXXRecordDecl *Class =
+FirstDeclMatcher().match(FromTU, cxxRecordDecl());
+auto lo

[PATCH] D49783: [clangd] Do not rebuild AST if inputs have not changed

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

- Use log instead of vlog
- Add parens around &&


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D49783

Files:
  clangd/TUScheduler.cpp
  test/clangd/extra-flags.test
  unittests/clangd/TUSchedulerTests.cpp
  unittests/clangd/TestFS.cpp
  unittests/clangd/TestFS.h

Index: unittests/clangd/TestFS.h
===
--- unittests/clangd/TestFS.h
+++ unittests/clangd/TestFS.h
@@ -23,7 +23,8 @@
 // Builds a VFS that provides access to the provided files, plus temporary
 // directories.
 llvm::IntrusiveRefCntPtr
-buildTestFS(llvm::StringMap const &Files);
+buildTestFS(llvm::StringMap const &Files,
+llvm::StringMap const &Timestamps = {});
 
 // A VFS provider that returns TestFSes containing a provided set of files.
 class MockFSProvider : public FileSystemProvider {
Index: unittests/clangd/TestFS.cpp
===
--- unittests/clangd/TestFS.cpp
+++ unittests/clangd/TestFS.cpp
@@ -19,13 +19,15 @@
 using namespace llvm;
 
 IntrusiveRefCntPtr
-buildTestFS(StringMap const &Files) {
+buildTestFS(llvm::StringMap const &Files,
+llvm::StringMap const &Timestamps) {
   IntrusiveRefCntPtr MemFS(
   new vfs::InMemoryFileSystem);
   for (auto &FileAndContents : Files) {
-MemFS->addFile(FileAndContents.first(), time_t(),
-   MemoryBuffer::getMemBufferCopy(FileAndContents.second,
-  FileAndContents.first()));
+StringRef File = FileAndContents.first();
+MemFS->addFile(
+File, Timestamps.lookup(File),
+MemoryBuffer::getMemBufferCopy(FileAndContents.second, File));
   }
   return MemFS;
 }
Index: unittests/clangd/TUSchedulerTests.cpp
===
--- unittests/clangd/TUSchedulerTests.cpp
+++ unittests/clangd/TUSchedulerTests.cpp
@@ -33,13 +33,12 @@
 class TUSchedulerTests : public ::testing::Test {
 protected:
   ParseInputs getInputs(PathRef File, std::string Contents) {
-return ParseInputs{*CDB.getCompileCommand(File), buildTestFS(Files),
-   std::move(Contents)};
+return ParseInputs{*CDB.getCompileCommand(File),
+   buildTestFS(Files, Timestamps), std::move(Contents)};
   }
 
   llvm::StringMap Files;
-
-private:
+  llvm::StringMap Timestamps;
   MockCompilationDatabase CDB;
 };
 
@@ -263,6 +262,10 @@
 int* a;
 double* b = a;
   )cpp";
+  llvm::StringLiteral OtherSourceContents = R"cpp(
+int* a;
+double* b = a + 0;
+  )cpp";
 
   auto Foo = testPath("foo.cpp");
   auto Bar = testPath("bar.cpp");
@@ -288,7 +291,7 @@
   ASSERT_THAT(S.getFilesWithCachedAST(), UnorderedElementsAre(Bar, Baz));
 
   // Access the old file again.
-  S.update(Foo, getInputs(Foo, SourceContents), WantDiagnostics::Yes,
+  S.update(Foo, getInputs(Foo, OtherSourceContents), WantDiagnostics::Yes,
[&BuiltASTCounter](std::vector Diags) { ++BuiltASTCounter; });
   ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(1)));
   ASSERT_EQ(BuiltASTCounter.load(), 4);
@@ -334,5 +337,58 @@
   ASSERT_THAT(Preambles, Each(Preambles[0]));
 }
 
+TEST_F(TUSchedulerTests, NoopOnEmptyChanges) {
+  TUScheduler S(
+  /*AsyncThreadsCount=*/getDefaultAsyncThreadsCount(),
+  /*StorePreambleInMemory=*/true, PreambleParsedCallback(),
+  /*UpdateDebounce=*/std::chrono::steady_clock::duration::zero(),
+  ASTRetentionPolicy());
+
+  auto Source = testPath("foo.cpp");
+  auto Header = testPath("foo.h");
+
+  Files[Header] = "int a;";
+  Timestamps[Header] = time_t(0);
+
+  auto SourceContents = R"cpp(
+  #include "foo.h"
+  int b = a;
+)cpp";
+
+  // Return value indicates if the updated callback was received.
+  auto DoUpdate = [&](ParseInputs Inputs) -> bool {
+std::atomic Updated(false);
+Updated = false;
+S.update(Source, std::move(Inputs), WantDiagnostics::Yes,
+ [&Updated](std::vector) { Updated = true; });
+bool UpdateFinished = S.blockUntilIdle(timeoutSeconds(1));
+if (!UpdateFinished)
+  ADD_FAILURE() << "Updated has not finished in one second. Threading bug?";
+return Updated;
+  };
+
+  // Test that subsequent updates with the same inputs do not cause rebuilds.
+  ASSERT_TRUE(DoUpdate(getInputs(Source, SourceContents)));
+  ASSERT_FALSE(DoUpdate(getInputs(Source, SourceContents)));
+
+  // Update to a header should cause a rebuild, though.
+  Files[Header] = time_t(1);
+  ASSERT_TRUE(DoUpdate(getInputs(Source, SourceContents)));
+  ASSERT_FALSE(DoUpdate(getInputs(Source, SourceContents)));
+
+  // Update to the contents should cause a rebuild.
+  auto OtherSourceContents = R"cpp(
+  #include "foo.h"
+  int c = d;
+)cpp";
+  ASSERT_TRUE(DoUpdate(getInputs(Source, OtherSourceContents)));
+  ASSERT_FALSE(D

[PATCH] D49793: [AArch64] - return address signing

2018-07-25 Thread Luke Cheeseman via Phabricator via cfe-commits
LukeCheeseman updated this revision to Diff 157266.
LukeCheeseman edited the summary of this revision.

https://reviews.llvm.org/D49793

Files:
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  include/clang/Frontend/CodeGenOptions.h
  lib/CodeGen/TargetInfo.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/aarch64-sign-return-address.c

Index: test/CodeGen/aarch64-sign-return-address.c
===
--- /dev/null
+++ test/CodeGen/aarch64-sign-return-address.c
@@ -0,0 +1,14 @@
+// RUN: %clang -target aarch64-arm-none-eabi -S -emit-llvm -o - -msign-return-address=none  %s | FileCheck %s --check-prefix=CHECK-NONE
+// RUN: %clang -target aarch64-arm-none-eabi -S -emit-llvm -o - -msign-return-address=non-leaf %s | FileCheck %s --check-prefix=CHECK-PARTIAL
+// RUN: %clang -target aarch64-arm-none-eabi -S -emit-llvm -o - -msign-return-address=all %s | FileCheck %s --check-prefix=CHECK-ALL
+
+// CHECK-NONE: @foo() #[[ATTR:[0-9]*]]
+// CHECK-NONE-NOT: attributes #[[ATTR]] = { {{.*}} "sign-return-address"={{.*}} "sign-return-address-key"={{.*}}}
+
+// CHECK-PARTIAL: @foo() #[[ATTR:[0-9]*]]
+// CHECK-PARTIAL: attributes #[[ATTR]] = { {{.*}} "sign-return-address"="partial" "sign-return-address-key"="a_key" {{.*}}}
+
+// CHECK-ALL: @foo() #[[ATTR:[0-9]*]]
+// CHECK-ALL: attributes #[[ATTR]] = { {{.*}} "sign-return-address"="all" "sign-return-address-key"="a_key" {{.*}} }
+
+void foo() {}
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -1125,6 +1125,19 @@
 
   Opts.Addrsig = Args.hasArg(OPT_faddrsig);
 
+  if (Arg *A = Args.getLastArg(OPT_msign_return_address)) {
+StringRef SignScope = A->getValue();
+if (SignScope.equals_lower("none"))
+  Opts.setSignReturnAddress(CodeGenOptions::SignReturnAddressScope::None);
+else if (SignScope.equals_lower("all"))
+  Opts.setSignReturnAddress(CodeGenOptions::SignReturnAddressScope::All);
+else if (SignScope.equals_lower("non-leaf"))
+  Opts.setSignReturnAddress(CodeGenOptions::SignReturnAddressScope::Partial);
+else
+  Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args)
+<< A->getValue();
+  }
+
   return Success;
 }
 
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -4073,6 +4073,11 @@
 options::OPT_mno_stack_arg_probe, true))
 CmdArgs.push_back(Args.MakeArgString("-mno-stack-arg-probe"));
 
+  if (Arg *A = Args.getLastArg(options::OPT_msign_return_address)) {
+CmdArgs.push_back(
+Args.MakeArgString(Twine("-msign-return-address=") + A->getValue()));
+  }
+
   if (Arg *A = Args.getLastArg(options::OPT_mrestrict_it,
options::OPT_mno_restrict_it)) {
 if (A->getOption().matches(options::OPT_mrestrict_it)) {
Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -4969,6 +4969,23 @@
   }
 
   bool doesReturnSlotInterfereWithArgs() const override { return false; }
+
+  void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
+   CodeGen::CodeGenModule &CGM) const override {
+const FunctionDecl *FD = dyn_cast_or_null(D);
+if (!FD)
+  return;
+llvm::Function *Fn = cast(GV);
+
+auto Kind = CGM.getCodeGenOpts().getSignReturnAddress();
+if (Kind == CodeGenOptions::SignReturnAddressScope::None)
+  return;
+
+Fn->addFnAttr("sign-return-address",
+  Kind == CodeGenOptions::SignReturnAddressScope::All
+  ? "all"
+  : "partial");
+  }
 };
 
 class WindowsAArch64TargetCodeGenInfo : public AArch64TargetCodeGenInfo {
Index: include/clang/Frontend/CodeGenOptions.h
===
--- include/clang/Frontend/CodeGenOptions.h
+++ include/clang/Frontend/CodeGenOptions.h
@@ -108,6 +108,12 @@
 Embed_Marker// Embed a marker as a placeholder for bitcode.
   };
 
+  enum SignReturnAddressScope {
+None,   // No signing for any function
+Partial,// Sign the return address of functions that spill LR
+All // Sign the return address of all functions
+  };
+
   /// The code model to use (-mcmodel).
   std::string CodeModel;
 
Index: include/clang/Frontend/CodeGenOptions.def
===
--- include/clang/Frontend/CodeGenOptions.def
+++ include/clang/Frontend/CodeGenOptions.def
@@ -339,6 +339,7 @@
 /// Whether to emit an address-significance table into the object file.
 CODEGE

[PATCH] D49783: [clangd] Do not rebuild AST if inputs have not changed

2018-07-25 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clangd/TUScheduler.cpp:357
+
+bool CanReuseAST = InputsAreTheSame && OldPreamble == NewPreamble;
 {

ioeric wrote:
> nit: `(OldPreamble == NewPreamble)`
> 
> Do you intend to compare the shared pointer instead of the values?
Yes, this is intentional. `buildPreamble` will either return the old one, if it 
can be reused, or build the new one.



Comment at: clangd/TUScheduler.cpp:360
   std::lock_guard Lock(Mutex);
+  OldPreamble.reset();
   if (NewPreamble)

ioeric wrote:
> Why reset?
We don't need the old preamble at this point, so we give it a chance to die (if 
there are no more references).
Note that there's an expensive operation that follows (building the AST), so 
removing the preamble before it seems like a win



Comment at: clangd/TUScheduler.cpp:373
+  // FIXME(ibiryukov): the AST could actually change if non-preamble
+  // includes changed, but we choose to ignore it.
+  // FIXME(ibiryukov): should we refresh the cache in IdleASTs for the

ioeric wrote:
> Do we choose to ignore this because it's rare? What are non-preamble 
> #includes?
Exactly, we don't have the code to track and check for all accessed files.
This should be rare, hopefully won't show up in practice.



Comment at: test/clangd/extra-flags.test:26
 ---
-{"jsonrpc":"2.0","method":"textDocument/didChange","params":{"textDocument":{"uri":"test:///foo.c","version":2},"contentChanges":[{"text":"int
 main() { int i; return i; }"}]}}
+{"jsonrpc":"2.0","method":"textDocument/didChange","params":{"textDocument":{"uri":"test:///foo.c","version":2},"contentChanges":[{"text":"int
 main() { int i; return i+1; }"}]}}
 #  CHECK:  "method": "textDocument/publishDiagnostics",

ioeric wrote:
> Why this change?
The test expects two publishDiagnostics, but it won't get the second one since 
if the contents of the file are the same :-)
So I altered the contents a bit to make sure we get the second result too


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D49783



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


[PATCH] D49800: [clang-tidy: modernize] modernize-redundant-void-arg crashes when a function body is in a macro

2018-07-25 Thread Idriss via Phabricator via cfe-commits
IdrissRio created this revision.
IdrissRio added reviewers: aaron.ballman, hokein, alexfh.
Herald added a subscriber: cfe-commits.

Hello, i would like to suggest a fix for one of the checks in clang-tidy. The 
bug was reported in https://bugs.llvm.org/show_bug.cgi?id=28406 where you can 
find more information.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D49800

Files:
  clang-tidy/modernize/RedundantVoidArgCheck.cpp
  test/clang-tidy/modernize-redundant-void-arg.cpp


Index: test/clang-tidy/modernize-redundant-void-arg.cpp
===
--- test/clang-tidy/modernize-redundant-void-arg.cpp
+++ test/clang-tidy/modernize-redundant-void-arg.cpp
@@ -445,3 +445,10 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: {{.*}} in function definition
   // CHECK-FIXES: DefinitionWithNoBody() = delete;
 };
+
+#define BODY {}
+void foo_lamb(){
+ [](void)BODY;
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: redundant void argument list in 
lambda expression [modernize-redundant-void-arg]
+ // CHECK-FIXES: []()BODY;
+}
Index: clang-tidy/modernize/RedundantVoidArgCheck.cpp
===
--- clang-tidy/modernize/RedundantVoidArgCheck.cpp
+++ clang-tidy/modernize/RedundantVoidArgCheck.cpp
@@ -237,7 +237,13 @@
   Lambda->hasExplicitParameters()) {
 SourceLocation Begin =
 Lambda->getIntroducerRange().getEnd().getLocWithOffset(1);
-SourceLocation End = Lambda->getBody()->getLocStart().getLocWithOffset(-1);
+SourceLocation End =
+Lambda->getBody()->getLocStart().isMacroID()
+? Result.SourceManager
+  
->getImmediateExpansionRange(Lambda->getBody()->getLocStart())
+  .getBegin()
+  .getLocWithOffset(-1)
+: Lambda->getBody()->getLocStart().getLocWithOffset(-1);
 removeVoidArgumentTokens(Result, SourceRange(Begin, End),
  "lambda expression");
   }


Index: test/clang-tidy/modernize-redundant-void-arg.cpp
===
--- test/clang-tidy/modernize-redundant-void-arg.cpp
+++ test/clang-tidy/modernize-redundant-void-arg.cpp
@@ -445,3 +445,10 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: {{.*}} in function definition
   // CHECK-FIXES: DefinitionWithNoBody() = delete;
 };
+
+#define BODY {}
+void foo_lamb(){
+ [](void)BODY;
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: redundant void argument list in lambda expression [modernize-redundant-void-arg]
+ // CHECK-FIXES: []()BODY;
+}
Index: clang-tidy/modernize/RedundantVoidArgCheck.cpp
===
--- clang-tidy/modernize/RedundantVoidArgCheck.cpp
+++ clang-tidy/modernize/RedundantVoidArgCheck.cpp
@@ -237,7 +237,13 @@
   Lambda->hasExplicitParameters()) {
 SourceLocation Begin =
 Lambda->getIntroducerRange().getEnd().getLocWithOffset(1);
-SourceLocation End = Lambda->getBody()->getLocStart().getLocWithOffset(-1);
+SourceLocation End =
+Lambda->getBody()->getLocStart().isMacroID()
+? Result.SourceManager
+  ->getImmediateExpansionRange(Lambda->getBody()->getLocStart())
+  .getBegin()
+  .getLocWithOffset(-1)
+: Lambda->getBody()->getLocStart().getLocWithOffset(-1);
 removeVoidArgumentTokens(Result, SourceRange(Begin, End),
  "lambda expression");
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D49656: [analyzer] Add support for more pointer invalidating functions in InnerPointerChecker

2018-07-25 Thread Reka Kovacs via Phabricator via cfe-commits
rnkovacs updated this revision to Diff 157278.
rnkovacs marked 2 inline comments as done.
rnkovacs added a comment.

Fix note for function pointers & handle argument counting in member operator 
calls.
I also refactored the code a little, because after moving things from 
`checkPreCall` to `checkPostCall`, the structure was a bit confusing.


https://reviews.llvm.org/D49656

Files:
  lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
  lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  test/Analysis/inner-pointer.cpp

Index: test/Analysis/inner-pointer.cpp
===
--- test/Analysis/inner-pointer.cpp
+++ test/Analysis/inner-pointer.cpp
@@ -38,13 +38,26 @@
 typedef basic_string u16string;
 typedef basic_string u32string;
 
+template 
+void func_ref(T &a);
+
+template 
+void func_const_ref(const T &a);
+
+template 
+void func_value(T a);
+
 } // end namespace std
 
 void consume(const char *) {}
 void consume(const wchar_t *) {}
 void consume(const char16_t *) {}
 void consume(const char32_t *) {}
 
+//=--=//
+// `std::string` member functions //
+//=--=//
+
 void deref_after_scope_char(bool cond) {
   const char *c, *d;
   {
@@ -151,6 +164,19 @@
   }  // expected-note@-1 {{Use of memory after it is freed}}
 }
 
+void deref_after_scope_ok(bool cond) {
+  const char *c, *d;
+  std::string s;
+  {
+c = s.c_str();
+d = s.data();
+  }
+  if (cond)
+consume(c); // no-warning
+  else
+consume(d); // no-warning
+}
+
 void deref_after_equals() {
   const char *c;
   std::string s = "hello";
@@ -277,15 +303,49 @@
   // expected-note@-1 {{Use of memory after it is freed}}
 }
 
-void deref_after_scope_ok(bool cond) {
-  const char *c, *d;
+//=---=//
+// Other STL functions //
+//=---=//
+
+void STL_func_ref() {
+  const char *c;
   std::string s;
-  {
-c = s.c_str();
-d = s.data();
-  }
-  if (cond)
-consume(c); // no-warning
-  else
-consume(d); // no-warning
+  c = s.c_str();// expected-note {{Dangling inner pointer obtained here}}
+  std::func_ref(s); // expected-note {{Inner pointer invalidated by call to 'func_ref'}}
+  consume(c);   // expected-warning {{Use of memory after it is freed}}
+  // expected-note@-1 {{Use of memory after it is freed}}
+}
+
+void STL_func_const_ref() {
+  const char *c;
+  std::string s;
+  c = s.c_str();
+  std::func_const_ref(s);
+  consume(c); // no-warning
+}
+
+void STL_func_value() {
+  const char *c;
+  std::string s;
+  c = s.c_str();
+  std::func_value(s);
+  consume(c); // no-warning
+}
+
+void func_ptr_known() {
+  const char *c;
+  std::string s;
+  void (*func_ptr)(std::string &) = std::func_ref;
+  c = s.c_str(); // expected-note {{Dangling inner pointer obtained here}}
+  func_ptr(s);   // expected-note {{Inner pointer invalidated by call to 'func_ref'}}
+  consume(c);// expected-warning {{Use of memory after it is freed}}
+  // expected-note@-1 {{Use of memory after it is freed}}
+}
+
+void func_ptr_unknown(void (*func_ptr)(std::string &)) {
+  const char *c;
+  std::string s;
+  c = s.c_str();
+  func_ptr(s);
+  consume(c); // no-warning
 }
Index: lib/StaticAnalyzer/Checkers/MallocChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -2930,6 +2930,11 @@
   OS << MemCallE->getMethodDecl()->getNameAsString();
 } else if (const auto *OpCallE = dyn_cast(S)) {
   OS << OpCallE->getDirectCallee()->getNameAsString();
+} else if (const auto *CallE = dyn_cast(S)) {
+  auto &CEMgr = BRC.getStateManager().getCallEventManager();
+  CallEventRef<> Call = CEMgr.getSimpleCall(CallE, state, CurrentLC);
+  const auto *D = dyn_cast_or_null(Call->getDecl());
+  OS << (D ? D->getNameAsString() : "unknown");
 }
 OS << "'";
   }
Index: lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
+++ lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
@@ -91,37 +91,53 @@
 ReserveFn("reserve"), ResizeFn("resize"),
 ShrinkToFitFn("shrink_to_fit"), SwapFn("swap") {}
 
-  /// Check whether the function called on the container object is a
-  /// member function that potentially invalidates pointers referring
-  /// to the objects's internal buffer.
-  bool mayInvalidateBuffer(const CallEvent &Call) const;
-
-  /// Record the connection between the symbol returned by c_str() and the
-  /// corresponding string object region in the ProgramState. Mark the symbol
-  /// released if the string object is destroyed.
+  /// Check if the object of this member function call is a `ba

[PATCH] D49656: [analyzer] Add support for more pointer invalidating functions in InnerPointerChecker

2018-07-25 Thread Reka Kovacs via Phabricator via cfe-commits
rnkovacs added inline comments.



Comment at: lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp:207-208
+
+for (unsigned I = 0, E = FD->getNumParams(); I != E; ++I) {
+  QualType ParamTy = FD->getParamDecl(I)->getType();
+  if (!ParamTy->isReferenceType() ||

NoQ wrote:
> NoQ wrote:
> > We need tests for operators here, due to the problem that i recently 
> > encountered in D49627: there's different numbering for arguments and 
> > parameters within in-class operators. Namely, this-argument is counted as 
> > an argument (shifting other argument indices by 1) but not as a parameter.
> (i.e., tests and most likely some actual code branch)
I did the coding part, but for the tests, I'm struggling to find an example of 
a member operator in the STL that takes a non-const string reference as an 
argument. Could you perhaps help me out here?



Comment at: lib/StaticAnalyzer/Checkers/MallocChecker.cpp:2934
+} else if (const auto *CallE = dyn_cast(S)) {
+  OS << CallE->getDirectCallee()->getNameAsString();
 }

NoQ wrote:
> rnkovacs wrote:
> > xazax.hun wrote:
> > > I think `getDirectCallee` might fail and return `nullptr`. One more 
> > > reason to test function pointers :)
> > You're right. Also, it needed a bit more effort to dig up the function 
> > pointer's name. Or should I go further and somehow find out the name of the 
> > function it points to?
> > Also, it needed a bit more effort to dig up the function pointer's name.
> 
> I think it should work out of the box; `Call.getDecl()` is smart enough to 
> show the right decl when a pointer to a concrete function is being called on 
> the current path.
That worked, thanks!



Comment at: test/Analysis/inner-pointer.cpp:41-42
 
+template< class T >
+void func_ref(T& a);
+

NoQ wrote:
> Without a definition for this thing, we won't be able to test much. I suggest 
> you to take a pointer to a function directly, i.e. define a `std::swap(x, 
> y)` somewhere and take a `&std::swap` directly and call it (hope 
> it actually works this way).
I think I am missing something. This is meant to test that the checker 
recognizes standard library function calls taking a non-const reference to a 
string as an argument. At L314, `func_ref` is called with a string argument, 
and the checker seems to do all the things it should after the current patch, 
emitting the new kind of note and such.

I can surely add the `std::swap(x, y)` definition too, but then the analyzer 
will see that the pointer was reallocated at the assignment inside the 
function, and place the note there. I think that would test the previous 
string-member-function patch more than this one.


https://reviews.llvm.org/D49656



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


[PATCH] D41415: [libcxx] implement casts.

2018-07-25 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists added a comment.
Herald added subscribers: bixia, jlebar.

In general, this looks good to me.
I suggested a lot of test improvements, but not very much to the code.
Needs the same kind of namespace changes in the tests as in 
https://reviews.llvm.org/D41376, but that's a minor thing.




Comment at: libcxx/include/experimental/simd:1068
   static typename std::enable_if::size() ==
  simd<_Tp, _NewAbi>::size(),
  simd<_Tp, _NewAbi>>::type

Weird indentation in the `enable_if`



Comment at: libcxx/test/std/experimental/simd/simd.casts/simd_cast.pass.cpp:19
 #include 
 
 using namespace std::experimental::parallelism_v2;

All the tests should `#include "test_macros.h"`



Comment at: libcxx/test/std/experimental/simd/simd.casts/simd_cast.pass.cpp:22
 
+template 
+auto unsupported_cast(Args&&... args)

I think this is worth a comment here - "This conversion is deleted so that it 
prevents ..."



Comment at: 
libcxx/test/std/experimental/simd/simd.casts/static_simd_cast.pass.cpp:33
 static_assert(
 std::is_same>(
  fixed_size_simd())),

General comment: We have a macro called `ASSERT_SAME_TYPE` that makes this 
clearer.

Instead of all this, you can just write:
   ASSERT_SAME_TYPE(decltype(static_simd_cast>(fixed_size_simd())), simd::size()>(

Since this is an extension, then the test needs to live in test/libcxx, not 
test/std.
(and should probably be two tests, one in test/std, and one in test/libcxx).

Same for to_native.pass.cpp below.



Comment at: 
libcxx/test/std/experimental/simd/simd.casts/to_fixed_size.pass.cpp:30
+void test_to_fixed_size() {
+  auto v = to_fixed_size(native_simd([](int i) { return i; }));
+  static_assert(std::is_same::size()>,

All of these tests need to check the "noexcept-ness" of the operation.
Fortunately, we have a macro for that, too:

ASSERT_NOEXCEPT ( to_fixed_size(std::declval>()));
ASSERT_SAME_TYPE(decltype(to_fixed_size(std::declval>())), 
fixed_size_simd::size()>);



https://reviews.llvm.org/D41415



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


[PATCH] D49656: [analyzer] Add support for more pointer invalidating functions in InnerPointerChecker

2018-07-25 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

Small comments inline.




Comment at: lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp:181
 
-  auto *TypeDecl = ObjRegion->getValueType()->getAsCXXRecordDecl();
-  if (TypeDecl->getName() != "basic_string")
-return;
+for (unsigned I = 0, E = FD->getNumParams(); I != E; ++I) {
+  QualType ParamTy = FD->getParamDecl(I)->getType();

Nit: maybe using `FunctionDecl::parameters` and range based for loop is sligtly 
cleaner.



Comment at: lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp:189
+  // argument but not as a parameter.
+  const auto *MemberOpCall = dyn_cast(FC);
+  unsigned ArgI = MemberOpCall ? I+1 : I;

Nit: maybe using isa + bool is cleaner here?



Comment at: lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp:192
 
-  if (Call.isCalled(CStrFn) || Call.isCalled(DataFn)) {
-SVal RawPtr = Call.getReturnValue();
-if (SymbolRef Sym = RawPtr.getAsSymbol(/*IncludeBaseRegions=*/true)) {
-  // Start tracking this raw pointer by adding it to the set of symbols
-  // associated with this container object in the program state map.
-  PtrSet::Factory &F = State->getStateManager().get_context();
-  const PtrSet *SetPtr = State->get(ObjRegion);
-  PtrSet Set = SetPtr ? *SetPtr : F.getEmptySet();
-  assert(C.wasInlined || !Set.contains(Sym));
-  Set = F.add(Set, Sym);
-  State = State->set(ObjRegion, Set);
-  C.addTransition(State);
+  SVal Arg = FC->getArgSVal(ArgI);
+  const auto *ArgRegion =

While I cannot recall examples in the STL the number of arguments and 
parameters might differ. We might have ellipsis in the parameters and this way 
we may pass more arguments. Since we do not have the parameter type for this 
case, I think it is ok to not handle it. But it might be worth to have a 
comment. The other case, when we have default arguments. I do not really know 
how the analyzer behaves with default arguments but maybe it would be worth to 
add a test case to ensure we do not crash on that?


https://reviews.llvm.org/D49656



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


[PATCH] D41422: [libcxx] implement operators and reduction.

2018-07-25 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists added a comment.
Herald added subscribers: bixia, jlebar.

A few nits, a bit of things moving underneath you, but this looks good.
Need to add more stuff to the tests ;-)




Comment at: libcxx/include/experimental/simd:1421
 template 
-_Tp hmin(const simd<_Tp, _Abi>&);
+_Tp hmin(const simd<_Tp, _Abi>& __v) {
+  _Tp __acc = __v[0];

In the TS, `hmin`, `hmax` (and a bunch of others) are noexcept. This was added 
in P1110, in response to NB comments CH 30 and CH 33.

Need to fix that here, and add `ASSERT_NOEXCEPT` to a bunch of tests.



Comment at: libcxx/include/experimental/simd:1482
 template 
 class const_where_expression {
 public:

We're going to need a lot of `_LIBCPP_TYPE_VIS` and other annotations. That can 
be a separate patch, though



Comment at: libcxx/include/experimental/simd:1657
+  simd operator++(int) {
+auto __tmp = *this;
+++*this;

I don't think that `auto` buys you anything here. `simd` is fine, and no longer.



Comment at: libcxx/test/std/experimental/simd/simd.horizontal/hmax.pass.cpp:23
+
+void test_hmax() {
+  {

Check the return types here with `ASSERT_SAME_TYPE`


https://reviews.llvm.org/D41422



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


[PATCH] D49774: [libc++] Use __int128_t to represent file_time_type.

2018-07-25 Thread Louis Dionne via Phabricator via cfe-commits
ldionne added a comment.

In https://reviews.llvm.org/D49774#1175131, @mclow.lists wrote:

> In https://reviews.llvm.org/D49774#1175062, @ldionne wrote:
>
> > In https://reviews.llvm.org/D49774#1174588, @EricWF wrote:
> >
> > > In https://reviews.llvm.org/D49774#1174565, @mclow.lists wrote:
> > >
> > > > I haven't reviewed this closely, but you might want to look at 
> > > > http://wg21.link/P0355, where we added a `file_clock` and `file_time` 
> > > > types.
> > >
> > >
> > > Thanks for the information. It doesn't look to have too much bearing on 
> > > this from a design standpoint. Except to note that it seems to solve
> > >  the streaming problem by adding explicit streaming overload for time 
> > > points.
> >
> >
> > It doesn't change anything from a design standpoint, but I don't think we 
> > can ship something deemed stable without taking P0355 into account. That's 
> > because it adds `file_clock` and changes `file_time_type` to use it, which 
> > is an ABI break. So if we take `filesystem` out of `experimental` and ship 
> > it before we've actually implemented the parts of P0355 that change the 
> > ABI, we'll have to take an ABI break in the future. That would suck because 
> > this ABI break would be necessary to implement C++20 properly in a fairly 
> > major way.
>
>
> Another problem (that Eric and I discussed last night) is that filesystem is 
> part of C++17, and `file_clock` is C++20. So we need a solution for C++17 as 
> well.


I believe one approach here would be to define `__file_clock` in C++17 (the way 
it is specified in C++20), and then have `using file_clock = __file_clock` in 
C++20. Would this be a valid strategy?


Repository:
  rCXX libc++

https://reviews.llvm.org/D49774



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


[PATCH] D49783: [clangd] Do not rebuild AST if inputs have not changed

2018-07-25 Thread Eric Liu via Phabricator via cfe-commits
ioeric accepted this revision.
ioeric added a comment.
This revision is now accepted and ready to land.

lg




Comment at: clangd/TUScheduler.cpp:360
   std::lock_guard Lock(Mutex);
+  OldPreamble.reset();
   if (NewPreamble)

ilya-biryukov wrote:
> ioeric wrote:
> > Why reset?
> We don't need the old preamble at this point, so we give it a chance to die 
> (if there are no more references).
> Note that there's an expensive operation that follows (building the AST), so 
> removing the preamble before it seems like a win
sg. and do we guard this with mutex because the same old preamble data can be 
accessed  by other threads? might worth a comment.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D49783



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


[PATCH] D49804: [VirtualFileSystem] InMemoryFileSystem::status: Return a Status with the requested name (take 2)

2018-07-25 Thread Simon Marchi via Phabricator via cfe-commits
simark created this revision.
simark added reviewers: malaperle, ilya-biryukov, bkramer.

This is a new version of https://reviews.llvm.org/D48903, which has been 
reverted.  @ioeric fixed
the issues caused by this patch downstream, so he told me it was good to
go again.  I also fixed the test failures on Windows.  The issue is that
the paths returned by the InMemoryFileSystem directory iterators in the
tests mix posix and windows directory separators.  This is because we do
queries with posix-style separators ("/a/b") but filenames are appended
using native-style separators (backslash on Windows).  So we end up with
"/a/b\c".

I fixed the test by re-using the ReplaceBackslashes function defined in
another test.  I'm not sure this is the best fix, but the only
alternative I see would be to completely rewrite tests to use
posix-style paths on non-Windows and Windows-style paths on Windows.
That would lead to quite a bit of duplication...

Here's the original commit message:

InMemoryFileSystem::status behaves differently than
RealFileSystem::status.  The Name contained in the Status returned by
RealFileSystem::status will be the path as requested by the caller,
whereas InMemoryFileSystem::status returns the normalized path.

For example, when requested the status for "../src/first.h",
RealFileSystem returns a Status with "../src/first.h" as the Name.
InMemoryFileSystem returns "/absolute/path/to/src/first.h".

The reason for this change is that I want to make a unit test in the
clangd testsuite (where we use an InMemoryFileSystem) to reproduce a
bug I get with the clangd program (where a RealFileSystem is used).
This difference in behavior "hides" the bug in the unit test version.


Repository:
  rC Clang

https://reviews.llvm.org/D49804

Files:
  lib/Basic/FileManager.cpp
  lib/Basic/VirtualFileSystem.cpp
  unittests/Basic/VirtualFileSystemTest.cpp
  unittests/Driver/ToolChainTest.cpp

Index: unittests/Driver/ToolChainTest.cpp
===
--- unittests/Driver/ToolChainTest.cpp
+++ unittests/Driver/ToolChainTest.cpp
@@ -113,7 +113,7 @@
   std::replace(S.begin(), S.end(), '\\', '/');
 #endif
   EXPECT_EQ("Found candidate GCC installation: "
-"/home/test/lib/gcc/arm-linux-gnueabi/4.6.1\n"
+"/home/test/bin/../lib/gcc/arm-linux-gnueabi/4.6.1\n"
 "Selected GCC installation: "
 "/home/test/bin/../lib/gcc/arm-linux-gnueabi/4.6.1\n"
 "Candidate multilib: .;@m32\n"
Index: unittests/Basic/VirtualFileSystemTest.cpp
===
--- unittests/Basic/VirtualFileSystemTest.cpp
+++ unittests/Basic/VirtualFileSystemTest.cpp
@@ -151,6 +151,11 @@
 addEntry(Path, S);
   }
 };
+
+auto ReplaceBackslashes = [](std::string S) {
+  std::replace(S.begin(), S.end(), '\\', '/');
+  return S;
+};
 } // end anonymous namespace
 
 TEST(VirtualFileSystemTest, StatusQueries) {
@@ -782,7 +787,7 @@
 
   I = FS.dir_begin("/b", EC);
   ASSERT_FALSE(EC);
-  ASSERT_EQ("/b/c", I->getName());
+  ASSERT_EQ("/b/c", ReplaceBackslashes(I->getName()));
   I.increment(EC);
   ASSERT_FALSE(EC);
   ASSERT_EQ(vfs::directory_iterator(), I);
@@ -794,16 +799,12 @@
 
   auto Stat = FS.status("/b/c");
   ASSERT_FALSE(Stat.getError()) << Stat.getError() << "\n" << FS.toString();
-  ASSERT_EQ("c", Stat->getName());
+  ASSERT_EQ("/b/c", Stat->getName());
   ASSERT_EQ("/b", *FS.getCurrentWorkingDirectory());
 
   Stat = FS.status("c");
   ASSERT_FALSE(Stat.getError()) << Stat.getError() << "\n" << FS.toString();
 
-  auto ReplaceBackslashes = [](std::string S) {
-std::replace(S.begin(), S.end(), '\\', '/');
-return S;
-  };
   NormalizedFS.setCurrentWorkingDirectory("/b/c");
   NormalizedFS.setCurrentWorkingDirectory(".");
   ASSERT_EQ("/b/c", ReplaceBackslashes(
@@ -919,6 +920,37 @@
   ASSERT_TRUE(Stat->isRegularFile());
 }
 
+// Test that the name returned by status() is in the same form as the path that
+// was requested (to match the behavior of RealFileSystem).
+TEST_F(InMemoryFileSystemTest, StatusName) {
+  NormalizedFS.addFile("/a/b/c", 0, MemoryBuffer::getMemBuffer("abc"),
+   /*User=*/None,
+   /*Group=*/None, sys::fs::file_type::regular_file);
+  NormalizedFS.setCurrentWorkingDirectory("/a/b");
+
+  // Access using InMemoryFileSystem::status.
+  auto Stat = NormalizedFS.status("../b/c");
+  ASSERT_FALSE(Stat.getError()) << Stat.getError() << "\n"
+<< NormalizedFS.toString();
+  ASSERT_TRUE(Stat->isRegularFile());
+  ASSERT_EQ("../b/c", Stat->getName());
+
+  // Access using InMemoryFileAdaptor::status.
+  auto File = NormalizedFS.openFileForRead("../b/c");
+  ASSERT_FALSE(File.getError()) << File.getError() << "\n"
+<< NormalizedFS.toString();
+  Stat = (*File)->status();
+  ASSERT_FALSE(Stat.getError()) << Stat.getError() << "\n"
+<< Normal

[PATCH] D48903: [VirtualFileSystem] InMemoryFileSystem::status: Return a Status with the requested name

2018-07-25 Thread Simon Marchi via Phabricator via cfe-commits
simark added a comment.

I uploaded a new version of this patch here:
https://reviews.llvm.org/D49804


Repository:
  rC Clang

https://reviews.llvm.org/D48903



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


Re: [PATCH] D48903: [VirtualFileSystem] InMemoryFileSystem::status: Return a Status with the requested name

2018-07-25 Thread Eric Liu via cfe-commits
It would make it easier for your reviewers to look at the new changes if
you just reopen this patch and update the diff :)

On Wed, Jul 25, 2018 at 5:49 PM Simon Marchi via Phabricator <
revi...@reviews.llvm.org> wrote:

> simark added a comment.
>
> I uploaded a new version of this patch here:
> https://reviews.llvm.org/D49804
>
>
> Repository:
>   rC Clang
>
> https://reviews.llvm.org/D48903
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   3   >