[PATCH] D89212: PR47663: Warn if an entity becomes weak after its first use.

2020-10-12 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

It does seem necessary to distinguish weak definitions from weak 
non-definitions, but that's completely reasonable — those two cases essentially 
act like totally different attributes that happen to be written with the same 
spelling.  If we acknowledge that, I think that gives us a straightforward 
rule: the problem is adding `weak` to a non-definition after a previous 
non-weak non-definition.

I think the only reasonable solution for aliases is to assume they don't 
happen, given the language rules.  We could add an attribute to allow, but I'm 
not sure anyone would use it: in practice I think it's extremely uncommon to 
define an external symbol as an alias of another external symbol.  Maybe we 
should just document alongside the alias attribute that the behavior of 
equality comparisons involving aliased symbols may be inconsistent between 
translation units.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89212/new/

https://reviews.llvm.org/D89212

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


[PATCH] D89146: [SyntaxTree] Fix rtti for `Expression`.

2020-10-12 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 297502.
eduucaldas added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89146/new/

https://reviews.llvm.org/D89146

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h


Index: clang/include/clang/Tooling/Syntax/Nodes.h
===
--- clang/include/clang/Tooling/Syntax/Nodes.h
+++ clang/include/clang/Tooling/Syntax/Nodes.h
@@ -206,7 +206,7 @@
   Expression(NodeKind K) : Tree(K) {}
   static bool classof(const Node *N) {
 return NodeKind::UnknownExpression <= N->getKind() &&
-   N->getKind() <= NodeKind::UnknownExpression;
+   N->getKind() <= NodeKind::CallExpression;
   }
 };
 


Index: clang/include/clang/Tooling/Syntax/Nodes.h
===
--- clang/include/clang/Tooling/Syntax/Nodes.h
+++ clang/include/clang/Tooling/Syntax/Nodes.h
@@ -206,7 +206,7 @@
   Expression(NodeKind K) : Tree(K) {}
   static bool classof(const Node *N) {
 return NodeKind::UnknownExpression <= N->getKind() &&
-   N->getKind() <= NodeKind::UnknownExpression;
+   N->getKind() <= NodeKind::CallExpression;
   }
 };
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D89220: [clang-rename] Simplify the code of handling class paritial specializations, NFC.

2020-10-12 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: kbobyrev.
Herald added a project: clang.
hokein requested review of this revision.

Instead of collecting all specializations and doing a post-filterin, we
can just get all targeted specializations from 
getPartialSpecializationsizations.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D89220

Files:
  clang/include/clang/AST/DeclTemplate.h
  clang/lib/AST/DeclTemplate.cpp
  clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp


Index: clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
===
--- clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
+++ clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
@@ -27,6 +27,7 @@
 #include "clang/Tooling/Refactoring.h"
 #include "clang/Tooling/Refactoring/Rename/USRFinder.h"
 #include "clang/Tooling/Tooling.h"
+#include "llvm/ADT/STLExtras.h"
 
 #include 
 #include 
@@ -96,12 +97,6 @@
 return true;
   }
 
-  bool VisitClassTemplatePartialSpecializationDecl(
-  const ClassTemplatePartialSpecializationDecl *PartialSpec) {
-PartialSpecs.push_back(PartialSpec);
-return true;
-  }
-
 private:
   void handleCXXRecordDecl(const CXXRecordDecl *RecordDecl) {
 if (!RecordDecl->getDefinition()) {
@@ -118,11 +113,10 @@
   void handleClassTemplateDecl(const ClassTemplateDecl *TemplateDecl) {
 for (const auto *Specialization : TemplateDecl->specializations())
   addUSRsOfCtorDtors(Specialization);
-
-for (const auto *PartialSpec : PartialSpecs) {
-  if (PartialSpec->getSpecializedTemplate() == TemplateDecl)
-addUSRsOfCtorDtors(PartialSpec);
-}
+SmallVector PartialSpecs;
+TemplateDecl->getPartialSpecializations(PartialSpecs);
+llvm::for_each(PartialSpecs,
+   [&](const auto *Spec) { addUSRsOfCtorDtors(Spec); });
 addUSRsOfCtorDtors(TemplateDecl->getTemplatedDecl());
   }
 
@@ -184,7 +178,6 @@
   std::set USRSet;
   std::vector OverriddenMethods;
   std::vector InstantiatedMethods;
-  std::vector PartialSpecs;
 };
 } // namespace
 
Index: clang/lib/AST/DeclTemplate.cpp
===
--- clang/lib/AST/DeclTemplate.cpp
+++ clang/lib/AST/DeclTemplate.cpp
@@ -440,7 +440,7 @@
 }
 
 llvm::FoldingSetVector &
-ClassTemplateDecl::getPartialSpecializations() {
+ClassTemplateDecl::getPartialSpecializations() const {
   LoadLazySpecializations();
   return getCommonPtr()->PartialSpecializations;
 }
@@ -528,7 +528,7 @@
 }
 
 void ClassTemplateDecl::getPartialSpecializations(
-  SmallVectorImpl &PS) {
+SmallVectorImpl &PS) const {
   llvm::FoldingSetVector &PartialSpecs
 = getPartialSpecializations();
   PS.clear();
Index: clang/include/clang/AST/DeclTemplate.h
===
--- clang/include/clang/AST/DeclTemplate.h
+++ clang/include/clang/AST/DeclTemplate.h
@@ -2266,7 +2266,7 @@
   /// Retrieve the set of partial specializations of this class
   /// template.
   llvm::FoldingSetVector &
-  getPartialSpecializations();
+  getPartialSpecializations() const;
 
   ClassTemplateDecl(ASTContext &C, DeclContext *DC, SourceLocation L,
 DeclarationName Name, TemplateParameterList *Params,
@@ -2363,7 +2363,7 @@
 
   /// Retrieve the partial specializations as an ordered list.
   void getPartialSpecializations(
-  SmallVectorImpl &PS);
+  SmallVectorImpl &PS) const;
 
   /// Find a class template partial specialization with the given
   /// type T.


Index: clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
===
--- clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
+++ clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
@@ -27,6 +27,7 @@
 #include "clang/Tooling/Refactoring.h"
 #include "clang/Tooling/Refactoring/Rename/USRFinder.h"
 #include "clang/Tooling/Tooling.h"
+#include "llvm/ADT/STLExtras.h"
 
 #include 
 #include 
@@ -96,12 +97,6 @@
 return true;
   }
 
-  bool VisitClassTemplatePartialSpecializationDecl(
-  const ClassTemplatePartialSpecializationDecl *PartialSpec) {
-PartialSpecs.push_back(PartialSpec);
-return true;
-  }
-
 private:
   void handleCXXRecordDecl(const CXXRecordDecl *RecordDecl) {
 if (!RecordDecl->getDefinition()) {
@@ -118,11 +113,10 @@
   void handleClassTemplateDecl(const ClassTemplateDecl *TemplateDecl) {
 for (const auto *Specialization : TemplateDecl->specializations())
   addUSRsOfCtorDtors(Specialization);
-
-for (const auto *PartialSpec : PartialSpecs) {
-  if (PartialSpec->getSpecializedTemplate() == TemplateDecl)
-addUSRsOfCtorDtors(PartialSpec);
-}
+SmallVector PartialSpecs;
+TemplateDecl->getPartialSpecializations(PartialSpecs);
+llvm::for_each(PartialSpecs,
+   [&](const auto *Spec) { addUSRsOfCtorDtors(Spec); });
 

[PATCH] D89221: [clang-rename] Fix rename on function template specializations.

2020-10-12 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: kbobyrev.
Herald added a project: clang.
hokein requested review of this revision.

previously, we missed to rename occurrences to explicit function template
specilizations.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D89221

Files:
  clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
  clang/test/clang-rename/FunctionTemplate.cpp


Index: clang/test/clang-rename/FunctionTemplate.cpp
===
--- /dev/null
+++ clang/test/clang-rename/FunctionTemplate.cpp
@@ -0,0 +1,19 @@
+template 
+void Foo(T t); // CHECK: void Bar(T t);
+
+template <>
+void Foo(int a); // CHECK: void Bar(int a);
+
+void test() {
+  Foo(1); // CHECK: Bar(1);
+}
+
+// Test 1.
+// RUN: clang-rename -offset=28 -new-name=Bar %s -- | sed 's,//.*,,' | 
FileCheck %s
+// Test 2.
+// RUN: clang-rename -offset=81 -new-name=Bar %s -- | sed 's,//.*,,' | 
FileCheck %s
+// Test 3.
+// RUN: clang-rename -offset=137 -new-name=Bar %s -- | sed 's,//.*,,' | 
FileCheck %s
+
+// To find offsets after modifying the file, use:
+//   grep -Ubo 'Foo.*' 
Index: clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
===
--- clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
+++ clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
@@ -81,6 +81,12 @@
 } else if (const auto *TemplateDecl =
dyn_cast(FoundDecl)) {
   handleClassTemplateDecl(TemplateDecl);
+} else if (const auto *FD = dyn_cast(FoundDecl)) {
+  USRSet.insert(getUSRForDecl(FD));
+  if (const auto *FTD = FD->getPrimaryTemplate())
+handleFunctionTemplateDecl(FTD);
+} else if (const auto *FD = dyn_cast(FoundDecl)) {
+  handleFunctionTemplateDecl(FD);
 } else {
   USRSet.insert(getUSRForDecl(FoundDecl));
 }
@@ -120,6 +126,12 @@
 addUSRsOfCtorDtors(TemplateDecl->getTemplatedDecl());
   }
 
+  void handleFunctionTemplateDecl(const FunctionTemplateDecl *FTD) {
+USRSet.insert(getUSRForDecl(FTD));
+for (const auto *S : FTD->specializations())
+  USRSet.insert(getUSRForDecl(S));
+  }
+
   void addUSRsOfCtorDtors(const CXXRecordDecl *RD) {
 const auto* RecordDecl = RD->getDefinition();
 


Index: clang/test/clang-rename/FunctionTemplate.cpp
===
--- /dev/null
+++ clang/test/clang-rename/FunctionTemplate.cpp
@@ -0,0 +1,19 @@
+template 
+void Foo(T t); // CHECK: void Bar(T t);
+
+template <>
+void Foo(int a); // CHECK: void Bar(int a);
+
+void test() {
+  Foo(1); // CHECK: Bar(1);
+}
+
+// Test 1.
+// RUN: clang-rename -offset=28 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s
+// Test 2.
+// RUN: clang-rename -offset=81 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s
+// Test 3.
+// RUN: clang-rename -offset=137 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s
+
+// To find offsets after modifying the file, use:
+//   grep -Ubo 'Foo.*' 
Index: clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
===
--- clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
+++ clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
@@ -81,6 +81,12 @@
 } else if (const auto *TemplateDecl =
dyn_cast(FoundDecl)) {
   handleClassTemplateDecl(TemplateDecl);
+} else if (const auto *FD = dyn_cast(FoundDecl)) {
+  USRSet.insert(getUSRForDecl(FD));
+  if (const auto *FTD = FD->getPrimaryTemplate())
+handleFunctionTemplateDecl(FTD);
+} else if (const auto *FD = dyn_cast(FoundDecl)) {
+  handleFunctionTemplateDecl(FD);
 } else {
   USRSet.insert(getUSRForDecl(FoundDecl));
 }
@@ -120,6 +126,12 @@
 addUSRsOfCtorDtors(TemplateDecl->getTemplatedDecl());
   }
 
+  void handleFunctionTemplateDecl(const FunctionTemplateDecl *FTD) {
+USRSet.insert(getUSRForDecl(FTD));
+for (const auto *S : FTD->specializations())
+  USRSet.insert(getUSRForDecl(S));
+  }
+
   void addUSRsOfCtorDtors(const CXXRecordDecl *RD) {
 const auto* RecordDecl = RD->getDefinition();
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D89066: [Coroutine][Sema] Only tighten the suspend call temp lifetime for final awaiter

2020-10-12 Thread JunMa via Phabricator via cfe-commits
junparser added a comment.

In D89066#2324151 , @lxfind wrote:

> In D89066#2324115 , @junparser wrote:
>
>> why we should not do this with normal await call?
>
> To be honest, I don't know yet. My understanding of how expression cleanup 
> and temp lifetime management is insufficient at the moment.
> But first of all, without adding any cleanup expression here, I saw ASAN 
> failures due to heap-use-after-free, because sometimes the frame have already 
> been destroyed after the await_suspend call, and yet we are still writing 
> into the frame due to unnecessarily cross-suspend lifetime. However, if I 
> apply the cleanup to all await_suepend calls, it also causes ASAN failures as 
> it's cleaning up data that's still alive.
> So this patch is more of a temporary walkaround to stop bleeding without 
> causing any trouble.
> I plan to get back to this latter after I am done with the spilling/alloca 
> issues.

I'm not familiar with ASAN instrumentation. Do you have any testcases to 
explain this?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89066/new/

https://reviews.llvm.org/D89066

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


[PATCH] D89147: [SyntaxTree] Improve the signature of `replaceChildRangeLowLevel`.

2020-10-12 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 297511.
eduucaldas added a comment.

Add asserts to `MutationsImpl::remove`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89147/new/

https://reviews.llvm.org/D89147

Files:
  clang/include/clang/Tooling/Syntax/Tree.h
  clang/lib/Tooling/Syntax/Mutations.cpp
  clang/lib/Tooling/Syntax/Tree.cpp

Index: clang/lib/Tooling/Syntax/Tree.cpp
===
--- clang/lib/Tooling/Syntax/Tree.cpp
+++ clang/lib/Tooling/Syntax/Tree.cpp
@@ -92,50 +92,84 @@
   this->FirstChild = Child;
 }
 
-void syntax::Tree::replaceChildRangeLowLevel(Node *BeforeBegin, Node *End,
- Node *New) {
-  assert(!BeforeBegin || BeforeBegin->Parent == this);
+std::vector>
+syntax::Tree::replaceChildRangeLowLevel(
+Node *BeforeBegin, Node *End,
+ArrayRef> NewRange) {
+  assert(!BeforeBegin || BeforeBegin->Parent == this &&
+ "`BeforeBegin` is not a child of `this`");
+  assert(!End || End->Parent == this && "`End` is not a child of `this`");
 
 #ifndef NDEBUG
-  for (auto *N = New; N; N = N->getNextSibling()) {
+  for (const auto &NodeAndRole : NewRange) {
+auto *N = NodeAndRole.first;
 assert(N->Parent == nullptr);
-assert(N->getRole() != NodeRole::Detached && "Roles must be set");
-// FIXME: sanity-check the role.
+assert(N->getRole() == NodeRole::Detached && "Roles must not be set");
+
+auto Role = NodeAndRole.second;
+assert(Role != NodeRole::Detached);
   }
+
+  auto Reachable = [](Node *From, Node *N) {
+if (!N)
+  return true;
+for (auto *It = From; It; It = It->NextSibling)
+  if (It == N)
+return true;
+return false;
+  };
+  assert(Reachable(FirstChild, BeforeBegin) &&
+ "`BeforeBegin` is not reachable");
+  assert(Reachable(BeforeBegin ? BeforeBegin->NextSibling : FirstChild, End) &&
+ "`End` is not after `BeforeBegin`");
 #endif
 
-  // Detach old nodes.
-  for (auto *N = !BeforeBegin ? FirstChild : BeforeBegin->getNextSibling();
-   N != End;) {
+  auto GetBegin = [&BeforeBegin, &FirstChild = this->FirstChild]() -> Node *& {
+return BeforeBegin ? BeforeBegin->NextSibling : FirstChild;
+  };
+
+  // Extract old nodes.
+  std::vector> ExtractedChildren;
+  for (auto *N = GetBegin(); N != End;) {
 auto *Next = N->NextSibling;
+ExtractedChildren.push_back({N, N->getRole()});
 
 N->setRole(NodeRole::Detached);
 N->Parent = nullptr;
 N->NextSibling = nullptr;
 if (N->Original)
-  traverse(N, [&](Node *C) { C->Original = false; });
+  traverse(N, [](Node *C) { C->Original = false; });
 
 N = Next;
   }
 
-  // Attach new nodes.
-  if (BeforeBegin)
-BeforeBegin->NextSibling = New ? New : End;
-  else
-FirstChild = New ? New : End;
+  // If any modification occurred mark them.
+  if (!ExtractedChildren.empty() || !NewRange.empty())
+for (auto *T = this; T && T->Original; T = T->Parent)
+  T->Original = false;
 
-  if (New) {
-auto *Last = New;
-for (auto *N = New; N != nullptr; N = N->getNextSibling()) {
-  Last = N;
-  N->Parent = this;
-}
-Last->NextSibling = End;
+  // Attach new children to the replaced range.
+
+  if (NewRange.empty()) {
+GetBegin() = End;
+return ExtractedChildren;
+  }
+  GetBegin() = NewRange.front().first;
+  NewRange.back().first->NextSibling = End;
+
+  for (const auto &NodeAndRole : NewRange) {
+NodeAndRole.first->setRole(NodeAndRole.second);
+NodeAndRole.first->Parent = this;
+  }
+
+  for (const auto *It = NewRange.begin(); It != std::prev(NewRange.end());
+   ++It) {
+auto *Node = It->first;
+auto *Next = std::next(It)->first;
+Node->NextSibling = Next;
   }
 
-  // Mark the node as modified.
-  for (auto *T = this; T && T->Original; T = T->Parent)
-T->Original = false;
+  return ExtractedChildren;
 }
 
 namespace {
Index: clang/lib/Tooling/Syntax/Mutations.cpp
===
--- clang/lib/Tooling/Syntax/Mutations.cpp
+++ clang/lib/Tooling/Syntax/Mutations.cpp
@@ -23,6 +23,17 @@
 
 using namespace clang;
 
+static syntax::Node *findPrevious(syntax::Node *N) {
+  if (N->getParent()->getFirstChild() == N)
+return nullptr;
+  for (syntax::Node *C = N->getParent()->getFirstChild(); C != nullptr;
+   C = C->getNextSibling()) {
+if (C->getNextSibling() == N)
+  return C;
+  }
+  llvm_unreachable("could not find a child node");
+}
+
 // This class has access to the internals of tree nodes. Its sole purpose is to
 // define helpers that allow implementing the high-level mutation operations.
 class syntax::MutationsImpl {
@@ -30,14 +41,15 @@
   /// Add a new node with a specified role.
   static void addAfter(syntax::Node *Anchor, syntax::Node *New, NodeRole Role) {
 assert(Anchor != nullptr);
+assert(Anchor->Parent != nullptr);
 a

[PATCH] D89148: [SyntaxTree] Artificial use of the Mutations API.

2020-10-12 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas added a subscriber: gribozavr2.
eduucaldas added a comment.

This patch implements the use case we discussed. It is merely for illustration.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89148/new/

https://reviews.llvm.org/D89148

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


[PATCH] D89098: [clang] Fix returning the underlying VarDecl as top-level decl for VarTemplateDecl.

2020-10-12 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 297512.
hokein marked 3 inline comments as done.
hokein added a comment.

address review comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89098/new/

https://reviews.llvm.org/D89098

Files:
  clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
  clang/lib/Parse/ParseDecl.cpp


Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -2195,6 +2195,7 @@
 
   // Inform the current actions module that we just parsed this declarator.
   Decl *ThisDecl = nullptr;
+  Decl *OuterDecl = nullptr;
   switch (TemplateInfo.Kind) {
   case ParsedTemplateInfo::NonTemplate:
 ThisDecl = Actions.ActOnDeclarator(getCurScope(), D);
@@ -2205,10 +2206,12 @@
 ThisDecl = Actions.ActOnTemplateDeclarator(getCurScope(),
*TemplateInfo.TemplateParams,
D);
-if (VarTemplateDecl *VT = dyn_cast_or_null(ThisDecl))
+if (VarTemplateDecl *VT = dyn_cast_or_null(ThisDecl)) {
   // Re-direct this decl to refer to the templated decl so that we can
   // initialize it.
   ThisDecl = VT->getTemplatedDecl();
+  OuterDecl = VT;
+}
 break;
   }
   case ParsedTemplateInfo::ExplicitInstantiation: {
@@ -2385,8 +2388,7 @@
   }
 
   Actions.FinalizeDeclaration(ThisDecl);
-
-  return ThisDecl;
+  return OuterDecl ? OuterDecl : ThisDecl;
 }
 
 /// ParseSpecifierQualifierList
Index: clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
===
--- clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
+++ clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
@@ -57,6 +57,12 @@
   return false;
 }
 
+MATCHER_P(DeclKind, Kind, "") {
+  if (NamedDecl *ND = dyn_cast(arg))
+return ND->getDeclKindName() == Kind;
+  return false;
+}
+
 // Matches if the Decl has template args equal to ArgName. If the decl is a
 // NamedDecl and ArgName is an empty string it also matches.
 MATCHER_P(WithTemplateArgs, ArgName, "") {
@@ -99,9 +105,23 @@
 int header1();
 int header2;
   )";
-  TU.Code = "int main();";
+  TU.Code = R"cpp(
+int main();
+template  bool X = true;
+  )cpp";
   auto AST = TU.build();
-  EXPECT_THAT(AST.getLocalTopLevelDecls(), ElementsAre(DeclNamed("main")));
+  EXPECT_THAT(
+  AST.getLocalTopLevelDecls(),
+  ElementsAreArray({AllOf(DeclNamed("main"), DeclKind("Function")),
+AllOf(DeclNamed("X"), DeclKind("VarTemplate"))}));
+}
+
+TEST(ParsedASTTest, VarTemplateDecl) {
+  TestTU TU;
+  TU.Code = "template  bool X = true;";
+  auto AST = TU.build();
+  EXPECT_THAT(AST.getLocalTopLevelDecls(),
+  ElementsAre(AllOf(DeclNamed("X"), WithTemplateArgs("";
 }
 
 TEST(ParsedASTTest, DoesNotGetIncludedTopDecls) {


Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -2195,6 +2195,7 @@
 
   // Inform the current actions module that we just parsed this declarator.
   Decl *ThisDecl = nullptr;
+  Decl *OuterDecl = nullptr;
   switch (TemplateInfo.Kind) {
   case ParsedTemplateInfo::NonTemplate:
 ThisDecl = Actions.ActOnDeclarator(getCurScope(), D);
@@ -2205,10 +2206,12 @@
 ThisDecl = Actions.ActOnTemplateDeclarator(getCurScope(),
*TemplateInfo.TemplateParams,
D);
-if (VarTemplateDecl *VT = dyn_cast_or_null(ThisDecl))
+if (VarTemplateDecl *VT = dyn_cast_or_null(ThisDecl)) {
   // Re-direct this decl to refer to the templated decl so that we can
   // initialize it.
   ThisDecl = VT->getTemplatedDecl();
+  OuterDecl = VT;
+}
 break;
   }
   case ParsedTemplateInfo::ExplicitInstantiation: {
@@ -2385,8 +2388,7 @@
   }
 
   Actions.FinalizeDeclaration(ThisDecl);
-
-  return ThisDecl;
+  return OuterDecl ? OuterDecl : ThisDecl;
 }
 
 /// ParseSpecifierQualifierList
Index: clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
===
--- clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
+++ clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
@@ -57,6 +57,12 @@
   return false;
 }
 
+MATCHER_P(DeclKind, Kind, "") {
+  if (NamedDecl *ND = dyn_cast(arg))
+return ND->getDeclKindName() == Kind;
+  return false;
+}
+
 // Matches if the Decl has template args equal to ArgName. If the decl is a
 // NamedDecl and ArgName is an empty string it also matches.
 MATCHER_P(WithTemplateArgs, ArgName, "") {
@@ -99,9 +105,23 @@
 int header1();
 int header2;
   )";
-  TU.Code = "int main();";
+  TU.Code = R"cpp(
+int main();
+template  bool X = true;
+  )cpp";
   auto AST = TU.build();
-  E

[PATCH] D89025: [RISCV] Add -mtune support

2020-10-12 Thread Kuan Hsu Chen (Zakk) via Phabricator via cfe-commits
khchen added a comment.

RISCV supports `-mcpu` with default empty arch to align gcc's `-mtune` behavior 
since clang didn't support `-mtune` before. But now clang has `-mtune`, is it a 
good idea to remove those options? (ex. `rocket-rv32/rv64`, `sifive-7-rv32/64`)




Comment at: clang/test/Driver/riscv-cpus.c:82
+// Check interaction between mcpu and mtune.
+//
+// RUN: %clang -target riscv32 -### -c %s 2>&1 -mcpu=sifive-e31 
-mtune=sifive-e76 | FileCheck -check-prefix=MTUNE-E31-MCPU-E76 %s

maybe we can describe what is expected interaction behavior somewhere.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89025/new/

https://reviews.llvm.org/D89025

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


[PATCH] D89131: [clangd] Validate optional fields more strictly.

2020-10-12 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang-tools-extra/clangd/Protocol.cpp:800
+  return O && O.map("applied", R.applied) &&
+ O.mapOptional("failureReason", R.failureReason);
 }

R.failureReason's type is `llvm::Optional`, I think we should 
probably use the `O.map` (the overload one for llvm::Optional)?



Comment at: clang-tools-extra/clangd/Protocol.cpp:1130
+ O.mapOptional("compilationDatabasePath",
+   Opts.compilationDatabasePath) &&
+ O.mapOptional("fallbackFlags", Opts.fallbackFlags) &&

And this one.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89131/new/

https://reviews.llvm.org/D89131

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


[clang-tools-extra] 702529d - [clang] Fix returning the underlying VarDecl as top-level decl for VarTemplateDecl.

2020-10-12 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2020-10-12T10:46:18+02:00
New Revision: 702529d899c87e9268bb33d836dbc91b6bce0b16

URL: 
https://github.com/llvm/llvm-project/commit/702529d899c87e9268bb33d836dbc91b6bce0b16
DIFF: 
https://github.com/llvm/llvm-project/commit/702529d899c87e9268bb33d836dbc91b6bce0b16.diff

LOG: [clang] Fix returning the underlying VarDecl as top-level decl for 
VarTemplateDecl.

Given the following VarTemplateDecl AST,

```
VarTemplateDecl col:26 X
|-TemplateTypeParmDecl typename depth 0 index 0
`-VarDecl X 'bool' cinit
  `-CXXBoolLiteralExpr 'bool' true
```

previously, we returned the VarDecl as the top-level decl, which was not
correct, the top-level decl should be VarTemplateDecl.

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

Added: 


Modified: 
clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
clang/lib/Parse/ParseDecl.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp 
b/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
index 65d9cffeedc7..db23438766d2 100644
--- a/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
+++ b/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
@@ -57,6 +57,12 @@ MATCHER_P(DeclNamed, Name, "") {
   return false;
 }
 
+MATCHER_P(DeclKind, Kind, "") {
+  if (NamedDecl *ND = dyn_cast(arg))
+return ND->getDeclKindName() == Kind;
+  return false;
+}
+
 // Matches if the Decl has template args equal to ArgName. If the decl is a
 // NamedDecl and ArgName is an empty string it also matches.
 MATCHER_P(WithTemplateArgs, ArgName, "") {
@@ -99,9 +105,15 @@ TEST(ParsedASTTest, TopLevelDecls) {
 int header1();
 int header2;
   )";
-  TU.Code = "int main();";
+  TU.Code = R"cpp(
+int main();
+template  bool X = true;
+  )cpp";
   auto AST = TU.build();
-  EXPECT_THAT(AST.getLocalTopLevelDecls(), ElementsAre(DeclNamed("main")));
+  EXPECT_THAT(
+  AST.getLocalTopLevelDecls(),
+  ElementsAreArray({AllOf(DeclNamed("main"), DeclKind("Function")),
+AllOf(DeclNamed("X"), DeclKind("VarTemplate"))}));
 }
 
 TEST(ParsedASTTest, DoesNotGetIncludedTopDecls) {

diff  --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 3f314c59ade6..01a16575c239 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -2195,6 +2195,7 @@ Decl 
*Parser::ParseDeclarationAfterDeclaratorAndAttributes(
 
   // Inform the current actions module that we just parsed this declarator.
   Decl *ThisDecl = nullptr;
+  Decl *OuterDecl = nullptr;
   switch (TemplateInfo.Kind) {
   case ParsedTemplateInfo::NonTemplate:
 ThisDecl = Actions.ActOnDeclarator(getCurScope(), D);
@@ -2205,10 +2206,12 @@ Decl 
*Parser::ParseDeclarationAfterDeclaratorAndAttributes(
 ThisDecl = Actions.ActOnTemplateDeclarator(getCurScope(),
*TemplateInfo.TemplateParams,
D);
-if (VarTemplateDecl *VT = dyn_cast_or_null(ThisDecl))
+if (VarTemplateDecl *VT = dyn_cast_or_null(ThisDecl)) {
   // Re-direct this decl to refer to the templated decl so that we can
   // initialize it.
   ThisDecl = VT->getTemplatedDecl();
+  OuterDecl = VT;
+}
 break;
   }
   case ParsedTemplateInfo::ExplicitInstantiation: {
@@ -2385,8 +2388,7 @@ Decl 
*Parser::ParseDeclarationAfterDeclaratorAndAttributes(
   }
 
   Actions.FinalizeDeclaration(ThisDecl);
-
-  return ThisDecl;
+  return OuterDecl ? OuterDecl : ThisDecl;
 }
 
 /// ParseSpecifierQualifierList



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


[PATCH] D89098: [clang] Fix returning the underlying VarDecl as top-level decl for VarTemplateDecl.

2020-10-12 Thread Haojian Wu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG702529d899c8: [clang] Fix returning the underlying VarDecl 
as top-level decl for… (authored by hokein).

Changed prior to commit:
  https://reviews.llvm.org/D89098?vs=297512&id=297514#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89098/new/

https://reviews.llvm.org/D89098

Files:
  clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
  clang/lib/Parse/ParseDecl.cpp


Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -2195,6 +2195,7 @@
 
   // Inform the current actions module that we just parsed this declarator.
   Decl *ThisDecl = nullptr;
+  Decl *OuterDecl = nullptr;
   switch (TemplateInfo.Kind) {
   case ParsedTemplateInfo::NonTemplate:
 ThisDecl = Actions.ActOnDeclarator(getCurScope(), D);
@@ -2205,10 +2206,12 @@
 ThisDecl = Actions.ActOnTemplateDeclarator(getCurScope(),
*TemplateInfo.TemplateParams,
D);
-if (VarTemplateDecl *VT = dyn_cast_or_null(ThisDecl))
+if (VarTemplateDecl *VT = dyn_cast_or_null(ThisDecl)) {
   // Re-direct this decl to refer to the templated decl so that we can
   // initialize it.
   ThisDecl = VT->getTemplatedDecl();
+  OuterDecl = VT;
+}
 break;
   }
   case ParsedTemplateInfo::ExplicitInstantiation: {
@@ -2385,8 +2388,7 @@
   }
 
   Actions.FinalizeDeclaration(ThisDecl);
-
-  return ThisDecl;
+  return OuterDecl ? OuterDecl : ThisDecl;
 }
 
 /// ParseSpecifierQualifierList
Index: clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
===
--- clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
+++ clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
@@ -57,6 +57,12 @@
   return false;
 }
 
+MATCHER_P(DeclKind, Kind, "") {
+  if (NamedDecl *ND = dyn_cast(arg))
+return ND->getDeclKindName() == Kind;
+  return false;
+}
+
 // Matches if the Decl has template args equal to ArgName. If the decl is a
 // NamedDecl and ArgName is an empty string it also matches.
 MATCHER_P(WithTemplateArgs, ArgName, "") {
@@ -99,9 +105,15 @@
 int header1();
 int header2;
   )";
-  TU.Code = "int main();";
+  TU.Code = R"cpp(
+int main();
+template  bool X = true;
+  )cpp";
   auto AST = TU.build();
-  EXPECT_THAT(AST.getLocalTopLevelDecls(), ElementsAre(DeclNamed("main")));
+  EXPECT_THAT(
+  AST.getLocalTopLevelDecls(),
+  ElementsAreArray({AllOf(DeclNamed("main"), DeclKind("Function")),
+AllOf(DeclNamed("X"), DeclKind("VarTemplate"))}));
 }
 
 TEST(ParsedASTTest, DoesNotGetIncludedTopDecls) {


Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -2195,6 +2195,7 @@
 
   // Inform the current actions module that we just parsed this declarator.
   Decl *ThisDecl = nullptr;
+  Decl *OuterDecl = nullptr;
   switch (TemplateInfo.Kind) {
   case ParsedTemplateInfo::NonTemplate:
 ThisDecl = Actions.ActOnDeclarator(getCurScope(), D);
@@ -2205,10 +2206,12 @@
 ThisDecl = Actions.ActOnTemplateDeclarator(getCurScope(),
*TemplateInfo.TemplateParams,
D);
-if (VarTemplateDecl *VT = dyn_cast_or_null(ThisDecl))
+if (VarTemplateDecl *VT = dyn_cast_or_null(ThisDecl)) {
   // Re-direct this decl to refer to the templated decl so that we can
   // initialize it.
   ThisDecl = VT->getTemplatedDecl();
+  OuterDecl = VT;
+}
 break;
   }
   case ParsedTemplateInfo::ExplicitInstantiation: {
@@ -2385,8 +2388,7 @@
   }
 
   Actions.FinalizeDeclaration(ThisDecl);
-
-  return ThisDecl;
+  return OuterDecl ? OuterDecl : ThisDecl;
 }
 
 /// ParseSpecifierQualifierList
Index: clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
===
--- clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
+++ clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
@@ -57,6 +57,12 @@
   return false;
 }
 
+MATCHER_P(DeclKind, Kind, "") {
+  if (NamedDecl *ND = dyn_cast(arg))
+return ND->getDeclKindName() == Kind;
+  return false;
+}
+
 // Matches if the Decl has template args equal to ArgName. If the decl is a
 // NamedDecl and ArgName is an empty string it also matches.
 MATCHER_P(WithTemplateArgs, ArgName, "") {
@@ -99,9 +105,15 @@
 int header1();
 int header2;
   )";
-  TU.Code = "int main();";
+  TU.Code = R"cpp(
+int main();
+template  bool X = true;
+  )cpp";
   auto AST = TU.build();
-  EXPECT_THAT(AST.getLocalTopLevelDecls(), Ele

[PATCH] D84304: [AST][RecoveryExpr] Part 2: Build dependent callexpr in C for error-recovery.

2020-10-12 Thread Haojian Wu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbb406f36dca3: [AST][RecoveryExpr] Build dependent callexpr 
in C for error-recovery. (authored by hokein).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D84304/new/

https://reviews.llvm.org/D84304

Files:
  clang/lib/Sema/SemaExpr.cpp
  clang/test/AST/ast-dump-recovery.c
  clang/test/Sema/error-dependence.c


Index: clang/test/Sema/error-dependence.c
===
--- clang/test/Sema/error-dependence.c
+++ clang/test/Sema/error-dependence.c
@@ -10,6 +10,9 @@
   // verify diagnostic "operand of type '' where arithmetic or
   // pointer type is required" is not emitted.
   (float)call(); // expected-error {{too few arguments to function call}}
+  // verify disgnostic "called object type '' is not a function
+  // or function pointer" is not emitted.
+  (*__builtin_classify_type)(1); // expected-error {{builtin functions must be 
directly called}}
 }
 
 void test2(int* ptr, float f) {
Index: clang/test/AST/ast-dump-recovery.c
===
--- clang/test/AST/ast-dump-recovery.c
+++ clang/test/AST/ast-dump-recovery.c
@@ -87,3 +87,18 @@
   // CHECK-NEXT:   `-DeclRefExpr {{.*}} 'some_func'
   (float)some_func();
 }
+
+void test3() {
+  // CHECK: CallExpr {{.*}} '' contains-errors
+  // CHECK-NEXT: |-ParenExpr {{.*}} contains-errors lvalue
+  // CHECK-NEXT: | `-RecoveryExpr {{.*}} contains-errors
+  // CHECK-NEXT: |   `-DeclRefExpr {{.*}} '__builtin_classify_type'
+  // CHECK-NEXT: `-IntegerLiteral {{.*}} 'int' 1
+  (*__builtin_classify_type)(1);
+
+  extern void ext();
+  // CHECK: CallExpr {{.*}} 'void' contains-errors
+  // CHECK-NEXT: |-DeclRefExpr {{.*}} 'ext'
+  // CHECK-NEXT: `-RecoveryExpr {{.*}} ''
+  ext(undef_var);
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -6375,6 +6375,21 @@
 checkDirectCallValidity(*this, Fn, FD, ArgExprs);
   }
 
+  if (Context.isDependenceAllowed() &&
+  (Fn->isTypeDependent() || Expr::hasAnyTypeDependentArguments(ArgExprs))) 
{
+assert(!getLangOpts().CPlusPlus);
+assert(Fn->containsErrors() ||
+   llvm::any_of(ArgExprs,
+[](clang::Expr *E) { return E->containsErrors(); }) &&
+   "should only occur in error-recovery path.");
+QualType ReturnType =
+llvm::isa_and_nonnull(NDecl)
+? dyn_cast(NDecl)->getCallResultType()
+: Context.DependentTy;
+return CallExpr::Create(Context, Fn, ArgExprs, ReturnType,
+Expr::getValueKindForType(ReturnType), RParenLoc,
+CurFPFeatureOverrides());
+  }
   return BuildResolvedCallExpr(Fn, NDecl, LParenLoc, ArgExprs, RParenLoc,
ExecConfig, IsExecConfig);
 }
@@ -6515,7 +6530,7 @@
  CurFPFeatureOverrides(), NumParams, UsesADL);
   }
 
-  if (!getLangOpts().CPlusPlus) {
+  if (!Context.isDependenceAllowed()) {
 // Forget about the nulled arguments since typo correction
 // do not handle them well.
 TheCall->shrinkNumArgs(Args.size());
@@ -19052,7 +19067,7 @@
 /// Check for operands with placeholder types and complain if found.
 /// Returns ExprError() if there was an error and no recovery was possible.
 ExprResult Sema::CheckPlaceholderExpr(Expr *E) {
-  if (!getLangOpts().CPlusPlus) {
+  if (!Context.isDependenceAllowed()) {
 // C cannot handle TypoExpr nodes on either side of a binop because it
 // doesn't handle dependent types properly, so make sure any TypoExprs have
 // been dealt with before checking the operands.


Index: clang/test/Sema/error-dependence.c
===
--- clang/test/Sema/error-dependence.c
+++ clang/test/Sema/error-dependence.c
@@ -10,6 +10,9 @@
   // verify diagnostic "operand of type '' where arithmetic or
   // pointer type is required" is not emitted.
   (float)call(); // expected-error {{too few arguments to function call}}
+  // verify disgnostic "called object type '' is not a function
+  // or function pointer" is not emitted.
+  (*__builtin_classify_type)(1); // expected-error {{builtin functions must be directly called}}
 }
 
 void test2(int* ptr, float f) {
Index: clang/test/AST/ast-dump-recovery.c
===
--- clang/test/AST/ast-dump-recovery.c
+++ clang/test/AST/ast-dump-recovery.c
@@ -87,3 +87,18 @@
   // CHECK-NEXT:   `-DeclRefExpr {{.*}} 'some_func'
   (float)some_func();
 }
+
+void test3() {
+  // CHECK: CallExpr {{.*}} '' contains-errors
+  // CHECK-NEXT: |-ParenExpr {{.*}} contains-errors lvalue
+  // CHECK-NEXT: | `-RecoveryExpr {{

[clang] bb406f3 - [AST][RecoveryExpr] Build dependent callexpr in C for error-recovery.

2020-10-12 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2020-10-12T11:15:01+02:00
New Revision: bb406f36dca3d53690a31e051d6f75f11eba6aa1

URL: 
https://github.com/llvm/llvm-project/commit/bb406f36dca3d53690a31e051d6f75f11eba6aa1
DIFF: 
https://github.com/llvm/llvm-project/commit/bb406f36dca3d53690a31e051d6f75f11eba6aa1.diff

LOG: [AST][RecoveryExpr] Build dependent callexpr in C for error-recovery.

See whole context: https://reviews.llvm.org/D85025

Reviewed By: sammccall

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

Added: 


Modified: 
clang/lib/Sema/SemaExpr.cpp
clang/test/AST/ast-dump-recovery.c
clang/test/Sema/error-dependence.c

Removed: 




diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 68a8777eae73..b5a366bc7175 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -6375,6 +6375,21 @@ ExprResult Sema::BuildCallExpr(Scope *Scope, Expr *Fn, 
SourceLocation LParenLoc,
 checkDirectCallValidity(*this, Fn, FD, ArgExprs);
   }
 
+  if (Context.isDependenceAllowed() &&
+  (Fn->isTypeDependent() || Expr::hasAnyTypeDependentArguments(ArgExprs))) 
{
+assert(!getLangOpts().CPlusPlus);
+assert(Fn->containsErrors() ||
+   llvm::any_of(ArgExprs,
+[](clang::Expr *E) { return E->containsErrors(); }) &&
+   "should only occur in error-recovery path.");
+QualType ReturnType =
+llvm::isa_and_nonnull(NDecl)
+? dyn_cast(NDecl)->getCallResultType()
+: Context.DependentTy;
+return CallExpr::Create(Context, Fn, ArgExprs, ReturnType,
+Expr::getValueKindForType(ReturnType), RParenLoc,
+CurFPFeatureOverrides());
+  }
   return BuildResolvedCallExpr(Fn, NDecl, LParenLoc, ArgExprs, RParenLoc,
ExecConfig, IsExecConfig);
 }
@@ -6515,7 +6530,7 @@ ExprResult Sema::BuildResolvedCallExpr(Expr *Fn, 
NamedDecl *NDecl,
  CurFPFeatureOverrides(), NumParams, UsesADL);
   }
 
-  if (!getLangOpts().CPlusPlus) {
+  if (!Context.isDependenceAllowed()) {
 // Forget about the nulled arguments since typo correction
 // do not handle them well.
 TheCall->shrinkNumArgs(Args.size());
@@ -19052,7 +19067,7 @@ static ExprResult diagnoseUnknownAnyExpr(Sema &S, Expr 
*E) {
 /// Check for operands with placeholder types and complain if found.
 /// Returns ExprError() if there was an error and no recovery was possible.
 ExprResult Sema::CheckPlaceholderExpr(Expr *E) {
-  if (!getLangOpts().CPlusPlus) {
+  if (!Context.isDependenceAllowed()) {
 // C cannot handle TypoExpr nodes on either side of a binop because it
 // doesn't handle dependent types properly, so make sure any TypoExprs have
 // been dealt with before checking the operands.

diff  --git a/clang/test/AST/ast-dump-recovery.c 
b/clang/test/AST/ast-dump-recovery.c
index d14aedebe490..4cb0c5be21e0 100644
--- a/clang/test/AST/ast-dump-recovery.c
+++ b/clang/test/AST/ast-dump-recovery.c
@@ -87,3 +87,18 @@ void test2() {
   // CHECK-NEXT:   `-DeclRefExpr {{.*}} 'some_func'
   (float)some_func();
 }
+
+void test3() {
+  // CHECK: CallExpr {{.*}} '' contains-errors
+  // CHECK-NEXT: |-ParenExpr {{.*}} contains-errors lvalue
+  // CHECK-NEXT: | `-RecoveryExpr {{.*}} contains-errors
+  // CHECK-NEXT: |   `-DeclRefExpr {{.*}} '__builtin_classify_type'
+  // CHECK-NEXT: `-IntegerLiteral {{.*}} 'int' 1
+  (*__builtin_classify_type)(1);
+
+  extern void ext();
+  // CHECK: CallExpr {{.*}} 'void' contains-errors
+  // CHECK-NEXT: |-DeclRefExpr {{.*}} 'ext'
+  // CHECK-NEXT: `-RecoveryExpr {{.*}} ''
+  ext(undef_var);
+}

diff  --git a/clang/test/Sema/error-dependence.c 
b/clang/test/Sema/error-dependence.c
index 41733cdba3fe..608e9afe 100644
--- a/clang/test/Sema/error-dependence.c
+++ b/clang/test/Sema/error-dependence.c
@@ -10,6 +10,9 @@ void test1(int s) {
   // verify diagnostic "operand of type '' where arithmetic or
   // pointer type is required" is not emitted.
   (float)call(); // expected-error {{too few arguments to function call}}
+  // verify disgnostic "called object type '' is not a function
+  // or function pointer" is not emitted.
+  (*__builtin_classify_type)(1); // expected-error {{builtin functions must be 
directly called}}
 }
 
 void test2(int* ptr, float f) {



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


[PATCH] D87989: [Flang][Driver] Add infrastructure for basic frontend actions and file I/O

2020-10-12 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a comment.

@reviewers A note regarding the changes in Clang.

This patch introduces a Flang option (`-test-io`), that should not be 
available/visible in Clang. AFAIK, there's no precedent of that, hence 
`options::NoClangOption` is introduced. This is discussed in more detail here: 
http://lists.llvm.org/pipermail/cfe-dev/2020-October/066953.html.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87989/new/

https://reviews.llvm.org/D87989

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


[PATCH] D89045: [AST][RecoveryExpr] Don't perform early typo correction in C.

2020-10-12 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8852d30b1c1b: [AST][RecoveryExpr] Don't perform early 
typo correction in C. (authored by hokein).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89045/new/

https://reviews.llvm.org/D89045

Files:
  clang/lib/Sema/SemaExpr.cpp
  clang/test/AST/ast-dump-recovery.c


Index: clang/test/AST/ast-dump-recovery.c
===
--- clang/test/AST/ast-dump-recovery.c
+++ clang/test/AST/ast-dump-recovery.c
@@ -24,14 +24,10 @@
 int unary_address = &(a + 1);
 
 // CHECK:   VarDecl {{.*}} ternary 'int' cinit
-// CHECK-NEXT:  `-RecoveryExpr {{.*}}
+// CHECK-NEXT:  `-ConditionalOperator {{.*}}
 // CHECK-NEXT:|-DeclRefExpr {{.*}} 'a'
-// CHECK-NEXT:|-TypoExpr {{.*}}
+// CHECK-NEXT:|-RecoveryExpr {{.*}}
 // CHECK-NEXT:`-DeclRefExpr {{.*}} 'a'
-// FIXME: The TypoExpr should never be print, and should be downgraded to
-// RecoveryExpr -- typo correction is performed too early in C-only codepath,
-// which makes no correction when clang finishes the full expr 
(Sema::Sema::ActOnFinishFullExpr).
-// this will be fixed when we support dependent mechanism and delayed typo 
correction for C.
 int ternary = a ? undef : a;
 
 void test1() {
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -8494,7 +8494,7 @@
 SourceLocation ColonLoc,
 Expr *CondExpr, Expr *LHSExpr,
 Expr *RHSExpr) {
-  if (!getLangOpts().CPlusPlus) {
+  if (!Context.isDependenceAllowed()) {
 // C cannot handle TypoExpr nodes in the condition because it
 // doesn't handle dependent types properly, so make sure any TypoExprs have
 // been dealt with before checking the operands.


Index: clang/test/AST/ast-dump-recovery.c
===
--- clang/test/AST/ast-dump-recovery.c
+++ clang/test/AST/ast-dump-recovery.c
@@ -24,14 +24,10 @@
 int unary_address = &(a + 1);
 
 // CHECK:   VarDecl {{.*}} ternary 'int' cinit
-// CHECK-NEXT:  `-RecoveryExpr {{.*}}
+// CHECK-NEXT:  `-ConditionalOperator {{.*}}
 // CHECK-NEXT:|-DeclRefExpr {{.*}} 'a'
-// CHECK-NEXT:|-TypoExpr {{.*}}
+// CHECK-NEXT:|-RecoveryExpr {{.*}}
 // CHECK-NEXT:`-DeclRefExpr {{.*}} 'a'
-// FIXME: The TypoExpr should never be print, and should be downgraded to
-// RecoveryExpr -- typo correction is performed too early in C-only codepath,
-// which makes no correction when clang finishes the full expr (Sema::Sema::ActOnFinishFullExpr).
-// this will be fixed when we support dependent mechanism and delayed typo correction for C.
 int ternary = a ? undef : a;
 
 void test1() {
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -8494,7 +8494,7 @@
 SourceLocation ColonLoc,
 Expr *CondExpr, Expr *LHSExpr,
 Expr *RHSExpr) {
-  if (!getLangOpts().CPlusPlus) {
+  if (!Context.isDependenceAllowed()) {
 // C cannot handle TypoExpr nodes in the condition because it
 // doesn't handle dependent types properly, so make sure any TypoExprs have
 // been dealt with before checking the operands.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 8852d30 - [AST][RecoveryExpr] Don't perform early typo correction in C.

2020-10-12 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2020-10-12T11:24:45+02:00
New Revision: 8852d30b1c1b3b65cec0147cdf442051aa35e31b

URL: 
https://github.com/llvm/llvm-project/commit/8852d30b1c1b3b65cec0147cdf442051aa35e31b
DIFF: 
https://github.com/llvm/llvm-project/commit/8852d30b1c1b3b65cec0147cdf442051aa35e31b.diff

LOG: [AST][RecoveryExpr] Don't perform early typo correction in C.

The dependent mechanism for C error-recovery is mostly finished,
this is the only place we have missed.

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

Added: 


Modified: 
clang/lib/Sema/SemaExpr.cpp
clang/test/AST/ast-dump-recovery.c

Removed: 




diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index b5a366bc7175..f0cb227ff58e 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -8494,7 +8494,7 @@ ExprResult Sema::ActOnConditionalOp(SourceLocation 
QuestionLoc,
 SourceLocation ColonLoc,
 Expr *CondExpr, Expr *LHSExpr,
 Expr *RHSExpr) {
-  if (!getLangOpts().CPlusPlus) {
+  if (!Context.isDependenceAllowed()) {
 // C cannot handle TypoExpr nodes in the condition because it
 // doesn't handle dependent types properly, so make sure any TypoExprs have
 // been dealt with before checking the operands.

diff  --git a/clang/test/AST/ast-dump-recovery.c 
b/clang/test/AST/ast-dump-recovery.c
index 4cb0c5be21e0..f7b3c7bb4f2f 100644
--- a/clang/test/AST/ast-dump-recovery.c
+++ b/clang/test/AST/ast-dump-recovery.c
@@ -24,14 +24,10 @@ int postfix_inc = a++;
 int unary_address = &(a + 1);
 
 // CHECK:   VarDecl {{.*}} ternary 'int' cinit
-// CHECK-NEXT:  `-RecoveryExpr {{.*}}
+// CHECK-NEXT:  `-ConditionalOperator {{.*}}
 // CHECK-NEXT:|-DeclRefExpr {{.*}} 'a'
-// CHECK-NEXT:|-TypoExpr {{.*}}
+// CHECK-NEXT:|-RecoveryExpr {{.*}}
 // CHECK-NEXT:`-DeclRefExpr {{.*}} 'a'
-// FIXME: The TypoExpr should never be print, and should be downgraded to
-// RecoveryExpr -- typo correction is performed too early in C-only codepath,
-// which makes no correction when clang finishes the full expr 
(Sema::Sema::ActOnFinishFullExpr).
-// this will be fixed when we support dependent mechanism and delayed typo 
correction for C.
 int ternary = a ? undef : a;
 
 void test1() {



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


[PATCH] D89197: [X86] Support -march=x86-64-v[234]

2020-10-12 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added inline comments.



Comment at: clang/docs/ReleaseNotes.rst:191
 
-- Support for -march=sapphirerapids was added.
+* Support for ``-march=sapphirerapids`` and ``-march=x86-64-v[234]`` has been 
added.
 

Fix the bullet point: '-'

Please can you extend this and describe whats in each level? It'd be good to 
have this in a longer term doc as well as the release notes will get wiped at 
13.0.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89197/new/

https://reviews.llvm.org/D89197

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


[PATCH] D89135: [clangd] Stop capturing trace args if the tracer doesn't need them.

2020-10-12 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clangd/support/Trace.cpp:91
   public:
-JSONSpan(JSONTracer *Tracer, llvm::StringRef Name, llvm::json::Object 
*Args)
+llvm::json::Object Args;
+JSONSpan(JSONTracer *Tracer, llvm::StringRef Name)

move this near other fileds?



Comment at: clang-tools-extra/clangd/support/Trace.h:86
+  beginSpan(llvm::StringRef Name,
+llvm::function_ref RequestArgs);
   // Called when a Span is destroyed (it may still be active on other threads).

nit: at first i parsed request in `RequestArgs` as a verb (e.g. `i request 
arguments`), which was confusing a little bit. Hence the comment also didn't 
make much sense, I only managed to error correct after seeing the usage :D

Maybe something like `SetRequestArgs` to emphasize that one provides request 
arguments using this lambda rather than receiving them?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89135/new/

https://reviews.llvm.org/D89135

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


[PATCH] D88463: [clangd] Try harder to get accurate ranges for documentSymbols in macros

2020-10-12 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

Thanks! This seems totally complete now, though I bet there's another case 
possible somehow!




Comment at: clang-tools-extra/clangd/FindSymbols.cpp:157
+  SourceLocation FallbackNameLoc;
+  if (isSpelledInSource(Loc, SM)) {
+// Prefer the spelling loc, but save the expansion loc as a fallback.

Hmm... the common file-location case takes a pretty weird path here: both 
NameLoc and FallbackNameLoc end up set to Loc, and hopefully we never hit the 
!contains condition (but if we did, we'd just calculate it twice and then hit 
the second fallback)

Maybe clearer, though a little longer, to handle explicitly like

```
SourceLocation NameLoc = ND.getLocation();
SourceLocation FallbackNameLoc;
if (NameLoc.isMacroLocation()) {
  if (spelled in source) {
NameLoc = getSpelling
FallbackNameLoc = getExpanson
  } else {
NameLoc = getExpansion
  }
}
```

up to you



Comment at: clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp:637
+  AllOf(WithName("Test"), SymNameRange(Main.range("expansion2"))),
+  AllOf(WithName("waldo"),
+SymRangeContains(Main.range("bodyStatement");

nit: despite the "contains" relation being critical, I think it's worth 
asserting the exact range


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88463/new/

https://reviews.llvm.org/D88463

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


[PATCH] D89225: [MinGW][clang-shlib] Build only when LLVM_LINK_LLVM_DYLIB is enabled

2020-10-12 Thread Mateusz Mikuła via Phabricator via cfe-commits
mati865 created this revision.
mati865 added a reviewer: mstorsjo.
mati865 added a project: clang.
Herald added subscribers: cfe-commits, mgorny.
mati865 requested review of this revision.

Otherwise it's easy to hit 2^16 DLL exports limit.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D89225

Files:
  clang/tools/CMakeLists.txt


Index: clang/tools/CMakeLists.txt
===
--- clang/tools/CMakeLists.txt
+++ clang/tools/CMakeLists.txt
@@ -15,7 +15,9 @@
 
 add_clang_subdirectory(clang-rename)
 add_clang_subdirectory(clang-refactor)
-if(UNIX OR MINGW)
+# For MinGW we only enable shared library if LLVM_LINK_LLVM_DYLIB=ON.
+# Without that option resulting library is too close to 2^16 DLL exports limit.
+if(UNIX OR (MINGW AND LLVM_LINK_LLVM_DYLIB))
   add_clang_subdirectory(clang-shlib)
 endif()
 


Index: clang/tools/CMakeLists.txt
===
--- clang/tools/CMakeLists.txt
+++ clang/tools/CMakeLists.txt
@@ -15,7 +15,9 @@
 
 add_clang_subdirectory(clang-rename)
 add_clang_subdirectory(clang-refactor)
-if(UNIX OR MINGW)
+# For MinGW we only enable shared library if LLVM_LINK_LLVM_DYLIB=ON.
+# Without that option resulting library is too close to 2^16 DLL exports limit.
+if(UNIX OR (MINGW AND LLVM_LINK_LLVM_DYLIB))
   add_clang_subdirectory(clang-shlib)
 endif()
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87547: [MinGW][clang-shlib] Build by default on MinGW

2020-10-12 Thread Mateusz Mikuła via Phabricator via cfe-commits
mati865 abandoned this revision.
mati865 added a comment.

Opened https://reviews.llvm.org/D89225


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87547/new/

https://reviews.llvm.org/D87547

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


[clang-tools-extra] f1bf41e - Fix buildbot failure for 702529d899c87e9268bb33d836dbc91b6bce0b16.

2020-10-12 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2020-10-12T12:04:44+02:00
New Revision: f1bf41e433e196ecffcc4fb7cd04c58d48445425

URL: 
https://github.com/llvm/llvm-project/commit/f1bf41e433e196ecffcc4fb7cd04c58d48445425
DIFF: 
https://github.com/llvm/llvm-project/commit/f1bf41e433e196ecffcc4fb7cd04c58d48445425.diff

LOG: Fix buildbot failure for 702529d899c87e9268bb33d836dbc91b6bce0b16.

Added: 


Modified: 
clang-tools-extra/clangd/unittests/ParsedASTTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp 
b/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
index db23438766d2..e2de95909fbf 100644
--- a/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
+++ b/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
@@ -60,6 +60,10 @@ MATCHER_P(DeclNamed, Name, "") {
 MATCHER_P(DeclKind, Kind, "") {
   if (NamedDecl *ND = dyn_cast(arg))
 return ND->getDeclKindName() == Kind;
+  if (auto *Stream = result_listener->stream()) {
+llvm::raw_os_ostream OS(*Stream);
+arg->dump(OS);
+  }
   return false;
 }
 
@@ -110,10 +114,10 @@ TEST(ParsedASTTest, TopLevelDecls) {
 template  bool X = true;
   )cpp";
   auto AST = TU.build();
-  EXPECT_THAT(
-  AST.getLocalTopLevelDecls(),
-  ElementsAreArray({AllOf(DeclNamed("main"), DeclKind("Function")),
-AllOf(DeclNamed("X"), DeclKind("VarTemplate"))}));
+  EXPECT_THAT(AST.getLocalTopLevelDecls(),
+  testing::UnorderedElementsAreArray(
+  {AllOf(DeclNamed("main"), DeclKind("Function")),
+   AllOf(DeclNamed("X"), DeclKind("VarTemplate"))}));
 }
 
 TEST(ParsedASTTest, DoesNotGetIncludedTopDecls) {



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


[PATCH] D88204: [clangd] Drop path suffix mapping for std symbols

2020-10-12 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet marked an inline comment as done.
kadircet added a comment.

> We don't have an alternative database for these. Maybe we should keep the 
> mechanism but stop using it for the standard library? What do you think?

Yes i think you are right. Just dropping STL mappings from the list.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88204/new/

https://reviews.llvm.org/D88204

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


[PATCH] D88204: [clangd] Drop path suffix mapping for std symbols

2020-10-12 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 297528.
kadircet added a comment.

- Only drop STL mapping instead of getting rid of suffix mapping completely.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88204/new/

https://reviews.llvm.org/D88204

Files:
  clang-tools-extra/clangd/index/CanonicalIncludes.cpp
  clang-tools-extra/clangd/index/CanonicalIncludes.h
  clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
  clang-tools-extra/clangd/unittests/FileIndexTests.cpp

Index: clang-tools-extra/clangd/unittests/FileIndexTests.cpp
===
--- clang-tools-extra/clangd/unittests/FileIndexTests.cpp
+++ clang-tools-extra/clangd/unittests/FileIndexTests.cpp
@@ -226,10 +226,11 @@
 
 TEST(FileIndexTest, HasSystemHeaderMappingsInPreamble) {
   TestTU TU;
-  TU.HeaderCode = "class Foo{};";
-  TU.HeaderFilename = "algorithm";
+  // std::max is mapped back to 
+  TU.HeaderCode = "namespace std { void max(); }";
+  TU.HeaderFilename = "ignored_header_name.h";
 
-  auto Symbols = runFuzzyFind(*TU.index(), "");
+  auto Symbols = runFuzzyFind(*TU.index(), "max");
   EXPECT_THAT(Symbols, ElementsAre(_));
   EXPECT_THAT(Symbols.begin()->IncludeHeaders.front().IncludeHeader,
   "");
Index: clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
===
--- clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
+++ clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
@@ -21,10 +21,6 @@
   CI.addSystemHeadersMapping(Language);
   // Usual standard library symbols are mapped correctly.
   EXPECT_EQ("", CI.mapHeader("path/stdio.h", "printf"));
-  // Suffix mapping isn't available for C, instead of mapping to ` we
-  // just leave the header as-is.
-  EXPECT_EQ("include/stdio.h",
-CI.mapHeader("include/stdio.h", "unknown_symbol"));
 }
 
 TEST(CanonicalIncludesTest, CXXStandardLibrary) {
@@ -34,17 +30,12 @@
   CI.addSystemHeadersMapping(Language);
 
   // Usual standard library symbols are mapped correctly.
-  EXPECT_EQ("", CI.mapHeader("path/vector.h", "std::vector"));
-  EXPECT_EQ("", CI.mapHeader("path/stdio.h", "std::printf"));
-  // std::move is ambiguous, currently always mapped to 
-  EXPECT_EQ("",
-CI.mapHeader("libstdc++/bits/stl_algo.h", "std::move"));
+  EXPECT_EQ("", CI.mapHeader("some_lib.h", "std::vector"));
+  EXPECT_EQ("", CI.mapHeader("some_lib.h", "std::printf"));
+  // std::move is ambiguous, always map to .
+  EXPECT_EQ("", CI.mapHeader("some_lib.h", "std::move"));
   // Unknown std symbols aren't mapped.
   EXPECT_EQ("foo/bar.h", CI.mapHeader("foo/bar.h", "std::notathing"));
-  // iosfwd declares some symbols it doesn't own.
-  EXPECT_EQ("", CI.mapHeader("iosfwd", "std::ostream"));
-  // And (for now) we assume it owns the others.
-  EXPECT_EQ("", CI.mapHeader("iosfwd", "std::notwathing"));
 }
 
 TEST(CanonicalIncludesTest, PathMapping) {
@@ -77,8 +68,6 @@
 
   // We added a mapping from some/path to .
   ASSERT_EQ("", CI.mapHeader("some/path", ""));
-  // We should have a path from 'bits/stl_vector.h' to ''.
-  ASSERT_EQ("", CI.mapHeader("bits/stl_vector.h", ""));
   // We should also have a symbol mapping from 'std::map' to ''.
   ASSERT_EQ("", CI.mapHeader("some/header.h", "std::map"));
 
Index: clang-tools-extra/clangd/index/CanonicalIncludes.h
===
--- clang-tools-extra/clangd/index/CanonicalIncludes.h
+++ clang-tools-extra/clangd/index/CanonicalIncludes.h
@@ -44,10 +44,10 @@
   llvm::StringRef mapHeader(llvm::StringRef Header,
 llvm::StringRef QualifiedName) const;
 
-  /// Adds mapping for system headers and some special symbols (e.g. STL symbols
-  /// in  need to be mapped individually). Approximately, the following
-  /// system headers are handled:
-  ///   - C++ standard library e.g. bits/basic_string.h$ -> 
+  /// Adds mapping for system headers and some special symbols. Uses a symbol
+  /// based mapping for STL symbols. Handles other libraries by matching on the
+  /// path. Approximately, the following system headers are handled:
+  ///   - C++ standard library e.g. std::string -> 
   ///   - Posix library e.g. bits/pthreadtypes.h$ -> 
   ///   - Compiler extensions, e.g. include/avx512bwintrin.h$ -> 
   /// The mapping is hardcoded and hand-maintained, so it might not cover all
Index: clang-tools-extra/clangd/index/CanonicalIncludes.cpp
===
--- clang-tools-extra/clangd/index/CanonicalIncludes.cpp
+++ clang-tools-extra/clangd/index/CanonicalIncludes.cpp
@@ -108,7 +108,11 @@
   // it serves as a fallback to disambiguate:
   //   - symbols with multiple headers (e.g. std::move)
   static const auto *SystemHeaderMap = new llvm::StringMap({
+  // Resource lib
   {"include/__stddef_max_align_t.h", ""},
+  {"in

[PATCH] D88913: [FPEnv] Use strictfp metadata in casting nodes

2020-10-12 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff added inline comments.



Comment at: clang/lib/CodeGen/CodeGenFunction.cpp:137-139
+  FPOptions FPFeatures = E->getFPFeaturesInEffect(CGF.getLangOpts());
+
+  ConstructorHelper(FPFeatures);

The local variable `FPFeatures` can be eliminated here.



Comment at: clang/lib/CodeGen/CodeGenFunction.cpp:154-155
+  OldRounding = CGF.Builder.getDefaultConstrainedRounding();
   if (OldFPFeatures == FPFeatures)
 return;
 

This check can be lifted to just after the definition of `OldFPFeatures`.



Comment at: clang/lib/CodeGen/CodeGenFunction.h:618-619
 FPOptions OldFPFeatures;
+llvm::fp::ExceptionBehavior OldExcept;
+llvm::RoundingMode OldRounding;
 Optional FMFGuard;

Is it possible to merge this variables into `OldFPFeatures`? In what cases 
state of `Builder` may differ from the state of `CGF.CurFPFeatures`?



Comment at: clang/test/CodeGen/aarch64-v8.2a-neon-intrinsics-constrained.c:6
 // RUN: %clang_cc1 -triple arm64-none-linux-gnu -target-feature +neon 
-target-feature +fullfp16 -target-feature +v8.2a\
-// RUN: -ffp-exception-behavior=strict \
+// RUN: -ffp-exception-behavior=maytrap -DEXCEPT=1 \
 // RUN: -fexperimental-strict-floating-point \

Why did you change exception behavior to `maytrap`?



Comment at: clang/test/CodeGen/aarch64-v8.2a-neon-intrinsics-constrained.c:26
+// metadata from the AST instead of the global default from the command line.
+// FIXME: All cases of "fpexcept.maytrap" in this test are wrong.
+

Why they are wrong?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88913/new/

https://reviews.llvm.org/D88913

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


[PATCH] D89204: Make likelihood lit test less brittle

2020-10-12 Thread Jeremy Morse via Phabricator via cfe-commits
jmorse accepted this revision.
jmorse added a comment.
This revision is now accepted and ready to land.

This fixes things for us, and by limiting to one optimisation pass it's much 
less brittle for the future -- much appreciated!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89204/new/

https://reviews.llvm.org/D89204

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


Re: Upcoming upgrade of LLVM buildbot

2020-10-12 Thread Vitaly Buka via cfe-commits
Thanks, I see them.

On Wed, 7 Oct 2020 at 16:32, Galina Kistanova  wrote:

> They are online now - http://lab.llvm.org:8011/#/waterfall?tags=sanitizer
>
> AnnotatedCommand has severe design conflict with the new buildbot.
> We have changed it to be safe and still do something useful, but it will
> need more love and care.
>
> Please let me know if you have some spare time to work on porting
> AnnotatedCommand.
>
> It's unlikely in near future.
What is missing exactly?


> Thanks
>
> Galina
>
> On Wed, Oct 7, 2020 at 2:57 PM Vitaly Buka  wrote:
>
>> It looks like all sanitizer builder are still offline
>> http://lab.llvm.org:8011/#/builders
>>
>> On Tue, 6 Oct 2020 at 00:34, Galina Kistanova via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>> Hello everyone,
>>>
>>> The staging buildbot was up and running for 6 days now, and looks good.
>>>
>>> Tomorrow at 12:00 PM PDT we will switch the production buildbot to the
>>> new version.
>>>
>>> If you are a bot owner, you do not need to do anything at this point,
>>> unless I'll ask you to help.
>>> The buildbot will go down for a short period of time, and then a new
>>> version will come up and will accept connections from your bots.
>>>
>>> Please note that the new version has a bit different URL structure. You
>>> will need to update the bookmarks or scripts if you have stored direct URLs
>>> to inside the buldbot.
>>>
>>> We will be watching the production and staging bots and will be
>>> improving zorg for the next week or so.
>>>
>>> I will need your feedback about blame e-mails delivery, IRC reporting
>>> issues, and anything you could spot wrong with the new bot. I  hope the
>>> transition will go smoothly and we will handle issues quickly if any would
>>> come up.
>>>
>>> After production is good and we have about a week of running history,
>>> I'll ask the bot owners to upgrade buildbots on their side. Please do
>>> not upgrade your buildbots unless I'll ask you to. We are trying to
>>> limit a number of moving parts at this stage. We will start accepting
>>> change to zorg at this point. Please feel free to talk to me if you will
>>> have a special situation and if you would absolutely have to make changes.
>>>
>>> Thanks for your support and help. And please feel free to ask if you
>>> have questions.
>>>
>>> Galina
>>>
>>>
>>> On Thu, Sep 10, 2020 at 9:35 PM Galina Kistanova 
>>> wrote:
>>>
 Hello everyone,

 The buildbot upgrade is entering the phase when the results to become
 visible.

 No change is required at this time on any of the builders. The bot
 owners could upgrade the buildbot on build computers later, at their
 convenience, as this is not on the critical path.

 We are going to upgrade the staging bot first. Then, once that is
 stable and all detected issues are resolved, we will upgrade the production
 bot.

 I will need some help with testing, and will be asking to move some of
 the builders temporarily to the staging. LLVM buildbot is a piece of
 critical infrastructure, so more eyes and hands in making sure it works
 properly the better.

 I'll be posting updates and ETA of particular changes in this thread.

 Please feel free to ask if you have any questions or concerns.

 Thanks

 Galina

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


[PATCH] D88413: [clangd] Add a metric for tracking memory usage

2020-10-12 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 297542.
kadircet marked an inline comment as done.
kadircet added a comment.

- Make traversal a free function and take metric to populate as a parameter.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88413/new/

https://reviews.llvm.org/D88413

Files:
  clang-tools-extra/clangd/support/MemoryTree.cpp
  clang-tools-extra/clangd/support/MemoryTree.h
  clang-tools-extra/clangd/unittests/support/MemoryTreeTests.cpp

Index: clang-tools-extra/clangd/unittests/support/MemoryTreeTests.cpp
===
--- clang-tools-extra/clangd/unittests/support/MemoryTreeTests.cpp
+++ clang-tools-extra/clangd/unittests/support/MemoryTreeTests.cpp
@@ -7,6 +7,8 @@
 //===--===//
 
 #include "support/MemoryTree.h"
+#include "support/TestTracer.h"
+#include "support/Trace.h"
 #include "llvm/Support/Allocator.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
@@ -16,6 +18,7 @@
 namespace clangd {
 namespace {
 using testing::Contains;
+using testing::ElementsAre;
 using testing::IsEmpty;
 using testing::UnorderedElementsAre;
 
@@ -73,6 +76,46 @@
 EXPECT_THAT(Detail.children(), Contains(WithNameAndSize("leaf", 1)));
   }
 }
+
+TEST(MemoryTree, Record) {
+  trace::TestTracer Tracer;
+  static constexpr llvm::StringLiteral MetricName = "memory_usage";
+  static constexpr trace::Metric OutMetric(MetricName, trace::Metric::Value,
+   "component_name");
+  auto AddNodes = [](MemoryTree Root) {
+Root.child("leaf").addUsage(1);
+
+{
+  auto &Detail = Root.detail("detail");
+  Detail.addUsage(1);
+  Detail.child("leaf").addUsage(1);
+  auto &Child = Detail.child("child");
+  Child.addUsage(1);
+  Child.child("leaf").addUsage(1);
+}
+
+{
+  auto &Child = Root.child("child");
+  Child.addUsage(1);
+  Child.child("leaf").addUsage(1);
+}
+return Root;
+  };
+
+  llvm::BumpPtrAllocator Alloc;
+  record(AddNodes(MemoryTree(&Alloc)), "root", OutMetric);
+  EXPECT_THAT(Tracer.takeMetric(MetricName, "root"), ElementsAre(7));
+  EXPECT_THAT(Tracer.takeMetric(MetricName, "root.leaf"), ElementsAre(1));
+  EXPECT_THAT(Tracer.takeMetric(MetricName, "root.detail"), ElementsAre(4));
+  EXPECT_THAT(Tracer.takeMetric(MetricName, "root.detail.leaf"),
+  ElementsAre(1));
+  EXPECT_THAT(Tracer.takeMetric(MetricName, "root.detail.child"),
+  ElementsAre(2));
+  EXPECT_THAT(Tracer.takeMetric(MetricName, "root.detail.child.leaf"),
+  ElementsAre(1));
+  EXPECT_THAT(Tracer.takeMetric(MetricName, "root.child"), ElementsAre(2));
+  EXPECT_THAT(Tracer.takeMetric(MetricName, "root.child.leaf"), ElementsAre(1));
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/support/MemoryTree.h
===
--- clang-tools-extra/clangd/support/MemoryTree.h
+++ clang-tools-extra/clangd/support/MemoryTree.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_SUPPORT_MEMORYTREE_H_
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_SUPPORT_MEMORYTREE_H_
 
+#include "Trace.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringRef.h"
@@ -80,6 +81,11 @@
   llvm::DenseMap Children;
 };
 
+/// Records total memory usage of each node under \p Out. Labels are edges on
+/// the path joined with ".", starting with \p RootName.
+void record(const MemoryTree &MT, std::string RootName,
+const trace::Metric &Out);
+
 } // namespace clangd
 } // namespace clang
 
Index: clang-tools-extra/clangd/support/MemoryTree.cpp
===
--- clang-tools-extra/clangd/support/MemoryTree.cpp
+++ clang-tools-extra/clangd/support/MemoryTree.cpp
@@ -1,4 +1,5 @@
 #include "support/MemoryTree.h"
+#include "Trace.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include 
@@ -6,6 +7,25 @@
 namespace clang {
 namespace clangd {
 
+namespace {
+
+size_t traverseTree(const MemoryTree &MT, std::string &ComponentName,
+const trace::Metric &Out) {
+  size_t OriginalLen = ComponentName.size();
+  if (!ComponentName.empty())
+ComponentName += '.';
+  size_t Total = MT.self();
+  for (const auto &Entry : MT.children()) {
+ComponentName += Entry.first;
+Total += traverseTree(Entry.getSecond(), ComponentName, Out);
+ComponentName.resize(OriginalLen + 1);
+  }
+  ComponentName.resize(OriginalLen);
+  Out.record(Total, ComponentName);
+  return Total;
+}
+} // namespace
+
 MemoryTree &MemoryTree::createChild(llvm::StringRef Name) {
   auto &Child = Children.try_emplace(Name, DetailAlloc).first->getSecond();
   return Child;
@@ -22,5 +42,10 @@
 Total += Entry.getSecond().total();
   return Total;
 }
+
+void record(const MemoryTre

[clang-tools-extra] c2d4280 - [clangd] Validate optional fields more strictly.

2020-10-12 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2020-10-12T13:01:59+02:00
New Revision: c2d4280328e4f69fd9e1258196e9dbc8362fce95

URL: 
https://github.com/llvm/llvm-project/commit/c2d4280328e4f69fd9e1258196e9dbc8362fce95
DIFF: 
https://github.com/llvm/llvm-project/commit/c2d4280328e4f69fd9e1258196e9dbc8362fce95.diff

LOG: [clangd] Validate optional fields more strictly.

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

Added: 


Modified: 
clang-tools-extra/clangd/Protocol.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Protocol.cpp 
b/clang-tools-extra/clangd/Protocol.cpp
index f8aca226a599..f41cea28fea3 100644
--- a/clang-tools-extra/clangd/Protocol.cpp
+++ b/clang-tools-extra/clangd/Protocol.cpp
@@ -484,12 +484,10 @@ bool fromJSON(const llvm::json::Value &Params, 
DidSaveTextDocumentParams &R,
 bool fromJSON(const llvm::json::Value &Params, DidChangeTextDocumentParams &R,
   llvm::json::Path P) {
   llvm::json::ObjectMapper O(Params, P);
-  if (!O)
-return false;
-  O.map("forceRebuild", R.forceRebuild);  // Optional clangd extension.
-  return O.map("textDocument", R.textDocument) &&
+  return O && O.map("textDocument", R.textDocument) &&
  O.map("contentChanges", R.contentChanges) &&
- O.map("wantDiagnostics", R.wantDiagnostics);
+ O.map("wantDiagnostics", R.wantDiagnostics) &&
+ O.mapOptional("forceRebuild", R.forceRebuild);
 }
 
 bool fromJSON(const llvm::json::Value &E, FileChangeType &Out,
@@ -578,12 +576,10 @@ llvm::json::Value toJSON(const Diagnostic &D) {
 bool fromJSON(const llvm::json::Value &Params, Diagnostic &R,
   llvm::json::Path P) {
   llvm::json::ObjectMapper O(Params, P);
-  if (!O || !O.map("range", R.range) || !O.map("message", R.message))
-return false;
-  O.map("severity", R.severity);
-  O.map("category", R.category);
-  O.map("code", R.code);
-  O.map("source", R.source);
+  return O && O.map("range", R.range) && O.map("message", R.message) &&
+ O.mapOptional("severity", R.severity) &&
+ O.mapOptional("category", R.category) &&
+ O.mapOptional("code", R.code) && O.mapOptional("source", R.source);
   return true;
 }
 
@@ -800,10 +796,8 @@ llvm::json::Value toJSON(const ApplyWorkspaceEditParams 
&Params) {
 bool fromJSON(const llvm::json::Value &Response, ApplyWorkspaceEditResponse &R,
   llvm::json::Path P) {
   llvm::json::ObjectMapper O(Response, P);
-  if (!O || !O.map("applied", R.applied))
-return false;
-  O.map("failureReason", R.failureReason);
-  return true;
+  return O && O.map("applied", R.applied) &&
+ O.map("failureReason", R.failureReason);
 }
 
 bool fromJSON(const llvm::json::Value &Params, TextDocumentPositionParams &R,
@@ -816,16 +810,11 @@ bool fromJSON(const llvm::json::Value &Params, 
TextDocumentPositionParams &R,
 bool fromJSON(const llvm::json::Value &Params, CompletionContext &R,
   llvm::json::Path P) {
   llvm::json::ObjectMapper O(Params, P);
-  if (!O)
-return false;
-
   int TriggerKind;
-  if (!O.map("triggerKind", TriggerKind))
+  if (!O || !O.map("triggerKind", TriggerKind) ||
+  !O.mapOptional("triggerCharacter", R.triggerCharacter))
 return false;
   R.triggerKind = static_cast(TriggerKind);
-
-  if (auto *TC = Params.getAsObject()->get("triggerCharacter"))
-return fromJSON(*TC, R.triggerCharacter, P.field("triggerCharacter"));
   return true;
 }
 
@@ -1126,8 +1115,8 @@ bool fromJSON(const llvm::json::Value &Params, 
ConfigurationSettings &S,
   llvm::json::ObjectMapper O(Params, P);
   if (!O)
 return true; // 'any' type in LSP.
-  O.map("compilationDatabaseChanges", S.compilationDatabaseChanges);
-  return true;
+  return O.mapOptional("compilationDatabaseChanges",
+   S.compilationDatabaseChanges);
 }
 
 bool fromJSON(const llvm::json::Value &Params, InitializationOptions &Opts,
@@ -1136,11 +1125,10 @@ bool fromJSON(const llvm::json::Value &Params, 
InitializationOptions &Opts,
   if (!O)
 return true; // 'any' type in LSP.
 
-  fromJSON(Params, Opts.ConfigSettings, P);
-  O.map("compilationDatabasePath", Opts.compilationDatabasePath);
-  O.map("fallbackFlags", Opts.fallbackFlags);
-  O.map("clangdFileStatus", Opts.FileStatus);
-  return true;
+  return fromJSON(Params, Opts.ConfigSettings, P) &&
+ O.map("compilationDatabasePath", Opts.compilationDatabasePath) &&
+ O.mapOptional("fallbackFlags", Opts.fallbackFlags) &&
+ O.mapOptional("clangdFileStatus", Opts.FileStatus);
 }
 
 bool fromJSON(const llvm::json::Value &E, TypeHierarchyDirection &Out,
@@ -1193,20 +1181,13 @@ bool fromJSON(const llvm::json::Value &Params, 
TypeHierarchyItem &I,
   llvm::json::ObjectMapper O(Params, P);
 
   // Required fields.
-  if (!(O && O.map("name", I.name) && O.map("kind", I.kind) &&
-O.map("uri", I.uri) && O.map("range", I.range) &&
-O.map("selectionRange", I.selecti

[PATCH] D89131: [clangd] Validate optional fields more strictly.

2020-10-12 Thread Sam McCall via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
sammccall marked 2 inline comments as done.
Closed by commit rGc2d4280328e4: [clangd] Validate optional fields more 
strictly. (authored by sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D89131?vs=297228&id=297547#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89131/new/

https://reviews.llvm.org/D89131

Files:
  clang-tools-extra/clangd/Protocol.cpp

Index: clang-tools-extra/clangd/Protocol.cpp
===
--- clang-tools-extra/clangd/Protocol.cpp
+++ clang-tools-extra/clangd/Protocol.cpp
@@ -484,12 +484,10 @@
 bool fromJSON(const llvm::json::Value &Params, DidChangeTextDocumentParams &R,
   llvm::json::Path P) {
   llvm::json::ObjectMapper O(Params, P);
-  if (!O)
-return false;
-  O.map("forceRebuild", R.forceRebuild);  // Optional clangd extension.
-  return O.map("textDocument", R.textDocument) &&
+  return O && O.map("textDocument", R.textDocument) &&
  O.map("contentChanges", R.contentChanges) &&
- O.map("wantDiagnostics", R.wantDiagnostics);
+ O.map("wantDiagnostics", R.wantDiagnostics) &&
+ O.mapOptional("forceRebuild", R.forceRebuild);
 }
 
 bool fromJSON(const llvm::json::Value &E, FileChangeType &Out,
@@ -578,12 +576,10 @@
 bool fromJSON(const llvm::json::Value &Params, Diagnostic &R,
   llvm::json::Path P) {
   llvm::json::ObjectMapper O(Params, P);
-  if (!O || !O.map("range", R.range) || !O.map("message", R.message))
-return false;
-  O.map("severity", R.severity);
-  O.map("category", R.category);
-  O.map("code", R.code);
-  O.map("source", R.source);
+  return O && O.map("range", R.range) && O.map("message", R.message) &&
+ O.mapOptional("severity", R.severity) &&
+ O.mapOptional("category", R.category) &&
+ O.mapOptional("code", R.code) && O.mapOptional("source", R.source);
   return true;
 }
 
@@ -800,10 +796,8 @@
 bool fromJSON(const llvm::json::Value &Response, ApplyWorkspaceEditResponse &R,
   llvm::json::Path P) {
   llvm::json::ObjectMapper O(Response, P);
-  if (!O || !O.map("applied", R.applied))
-return false;
-  O.map("failureReason", R.failureReason);
-  return true;
+  return O && O.map("applied", R.applied) &&
+ O.map("failureReason", R.failureReason);
 }
 
 bool fromJSON(const llvm::json::Value &Params, TextDocumentPositionParams &R,
@@ -816,16 +810,11 @@
 bool fromJSON(const llvm::json::Value &Params, CompletionContext &R,
   llvm::json::Path P) {
   llvm::json::ObjectMapper O(Params, P);
-  if (!O)
-return false;
-
   int TriggerKind;
-  if (!O.map("triggerKind", TriggerKind))
+  if (!O || !O.map("triggerKind", TriggerKind) ||
+  !O.mapOptional("triggerCharacter", R.triggerCharacter))
 return false;
   R.triggerKind = static_cast(TriggerKind);
-
-  if (auto *TC = Params.getAsObject()->get("triggerCharacter"))
-return fromJSON(*TC, R.triggerCharacter, P.field("triggerCharacter"));
   return true;
 }
 
@@ -1126,8 +1115,8 @@
   llvm::json::ObjectMapper O(Params, P);
   if (!O)
 return true; // 'any' type in LSP.
-  O.map("compilationDatabaseChanges", S.compilationDatabaseChanges);
-  return true;
+  return O.mapOptional("compilationDatabaseChanges",
+   S.compilationDatabaseChanges);
 }
 
 bool fromJSON(const llvm::json::Value &Params, InitializationOptions &Opts,
@@ -1136,11 +1125,10 @@
   if (!O)
 return true; // 'any' type in LSP.
 
-  fromJSON(Params, Opts.ConfigSettings, P);
-  O.map("compilationDatabasePath", Opts.compilationDatabasePath);
-  O.map("fallbackFlags", Opts.fallbackFlags);
-  O.map("clangdFileStatus", Opts.FileStatus);
-  return true;
+  return fromJSON(Params, Opts.ConfigSettings, P) &&
+ O.map("compilationDatabasePath", Opts.compilationDatabasePath) &&
+ O.mapOptional("fallbackFlags", Opts.fallbackFlags) &&
+ O.mapOptional("clangdFileStatus", Opts.FileStatus);
 }
 
 bool fromJSON(const llvm::json::Value &E, TypeHierarchyDirection &Out,
@@ -1193,20 +1181,13 @@
   llvm::json::ObjectMapper O(Params, P);
 
   // Required fields.
-  if (!(O && O.map("name", I.name) && O.map("kind", I.kind) &&
-O.map("uri", I.uri) && O.map("range", I.range) &&
-O.map("selectionRange", I.selectionRange))) {
-return false;
-  }
-
-  // Optional fields.
-  O.map("detail", I.detail);
-  O.map("deprecated", I.deprecated);
-  O.map("parents", I.parents);
-  O.map("children", I.children);
-  O.map("data", I.data);
-
-  return true;
+  return O && O.map("name", I.name) && O.map("kind", I.kind) &&
+ O.map("uri", I.uri) && O.map("range", I.range) &&
+ O.map("selectionRange", I.selectionRange) &&
+ O.mapOptional("detail", I.

[PATCH] D89225: [MinGW][clang-shlib] Build only when LLVM_LINK_LLVM_DYLIB is enabled

2020-10-12 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a reviewer: ASDenysPetrov.
mstorsjo added a comment.

+1, looks sensible to me - I can give it the formal approval a bit later, but 
leaving it open for a bit for others to comment on first.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89225/new/

https://reviews.llvm.org/D89225

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


[PATCH] D89135: [clangd] Stop capturing trace args if the tracer doesn't need them.

2020-10-12 Thread Sam McCall via Phabricator via cfe-commits
sammccall marked an inline comment as done.
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/support/Trace.cpp:91
   public:
-JSONSpan(JSONTracer *Tracer, llvm::StringRef Name, llvm::json::Object 
*Args)
+llvm::json::Object Args;
+JSONSpan(JSONTracer *Tracer, llvm::StringRef Name)

kadircet wrote:
> move this near other fileds?
It's public unlike the other fields, but moved it to the bottom of the public 
section



Comment at: clang-tools-extra/clangd/support/Trace.cpp:302
+: llvm::StringRef(Name.str()),
+   [&](llvm::json::Object *A) { Args = A; });
+  return std::make_pair(std::move(Ctx), Args);

added assertions here (nonnull and empty) to guard against any API confusion



Comment at: clang-tools-extra/clangd/support/Trace.h:86
+  beginSpan(llvm::StringRef Name,
+llvm::function_ref RequestArgs);
   // Called when a Span is destroyed (it may still be active on other threads).

kadircet wrote:
> nit: at first i parsed request in `RequestArgs` as a verb (e.g. `i request 
> arguments`), which was confusing a little bit. Hence the comment also didn't 
> make much sense, I only managed to error correct after seeing the usage :D
> 
> Maybe something like `SetRequestArgs` to emphasize that one provides request 
> arguments using this lambda rather than receiving them?
This *is* actually the intention.

Changed to `AttachDetails` to avoid ambiguity, and rewrote the comment.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89135/new/

https://reviews.llvm.org/D89135

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


[PATCH] D89135: [clangd] Stop capturing trace args if the tracer doesn't need them.

2020-10-12 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 297555.
sammccall marked an inline comment as done.
sammccall added a comment.

address comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89135/new/

https://reviews.llvm.org/D89135

Files:
  clang-tools-extra/clangd/support/Trace.cpp
  clang-tools-extra/clangd/support/Trace.h
  clang-tools-extra/clangd/unittests/support/TraceTests.cpp

Index: clang-tools-extra/clangd/unittests/support/TraceTests.cpp
===
--- clang-tools-extra/clangd/unittests/support/TraceTests.cpp
+++ clang-tools-extra/clangd/unittests/support/TraceTests.cpp
@@ -186,6 +186,11 @@
  StartsWith("d,dist,\"a\nb\",1"), ""));
 }
 
+TEST_F(CSVMetricsTracerTest, IgnoresArgs) {
+  trace::Span Tracer("Foo");
+  EXPECT_EQ(nullptr, Tracer.Args);
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/support/Trace.h
===
--- clang-tools-extra/clangd/support/Trace.h
+++ clang-tools-extra/clangd/support/Trace.h
@@ -79,8 +79,13 @@
   /// Returns a derived context that will be destroyed when the event ends.
   /// Usually implementations will store an object in the returned context
   /// whose destructor records the end of the event.
-  /// The args are *Args, only complete when the event ends.
-  virtual Context beginSpan(llvm::StringRef Name, llvm::json::Object *Args);
+  /// The tracer may capture event details provided in SPAN_ATTACH() calls.
+  /// In this case it should call AttachDetails(), and pass in an empty Object
+  /// to hold them. This Object should be owned by the context, and the data
+  /// will be complete by the time the context is destroyed.
+  virtual Context
+  beginSpan(llvm::StringRef Name,
+llvm::function_ref AttachDetails);
   // Called when a Span is destroyed (it may still be active on other threads).
   // beginSpan() and endSpan() will always form a proper stack on each thread.
   // The Context returned by beginSpan is active, but Args is not ready.
@@ -146,6 +151,8 @@
   llvm::json::Object *const Args;
 
 private:
+  // Awkward constructor works around constant initialization.
+  Span(std::pair);
   WithContext RestoreCtx;
 };
 
Index: clang-tools-extra/clangd/support/Trace.cpp
===
--- clang-tools-extra/clangd/support/Trace.cpp
+++ clang-tools-extra/clangd/support/Trace.cpp
@@ -53,9 +53,12 @@
 
   // We stash a Span object in the context. It will record the start/end,
   // and this also allows us to look up the parent Span's information.
-  Context beginSpan(llvm::StringRef Name, llvm::json::Object *Args) override {
-return Context::current().derive(
-SpanKey, std::make_unique(this, Name, Args));
+  Context beginSpan(
+  llvm::StringRef Name,
+  llvm::function_ref AttachDetails) override {
+auto JS = std::make_unique(this, Name);
+AttachDetails(&JS->Args);
+return Context::current().derive(SpanKey, std::move(JS));
   }
 
   // Trace viewer requires each thread to properly stack events.
@@ -85,9 +88,9 @@
 private:
   class JSONSpan {
   public:
-JSONSpan(JSONTracer *Tracer, llvm::StringRef Name, llvm::json::Object *Args)
+JSONSpan(JSONTracer *Tracer, llvm::StringRef Name)
 : StartTime(Tracer->timestamp()), EndTime(0), Name(Name),
-  TID(llvm::get_threadid()), Tracer(Tracer), Args(Args) {
+  TID(llvm::get_threadid()), Tracer(Tracer) {
   // ~JSONSpan() may run in a different thread, so we need to capture now.
   Tracer->captureThreadMetadata();
 
@@ -125,7 +128,7 @@
   // Finally, record the event (ending at EndTime, not timestamp())!
   Tracer->jsonEvent("X",
 llvm::json::Object{{"name", std::move(Name)},
-   {"args", std::move(*Args)},
+   {"args", std::move(Args)},
{"dur", EndTime - StartTime}},
 TID, StartTime);
 }
@@ -133,6 +136,8 @@
 // May be called by any thread.
 void markEnded() { EndTime = Tracer->timestamp(); }
 
+llvm::json::Object Args;
+
   private:
 static int64_t nextID() {
   static std::atomic Next = {0};
@@ -144,7 +149,6 @@
 std::string Name;
 uint64_t TID;
 JSONTracer *Tracer;
-llvm::json::Object *Args;
   };
   static Key> SpanKey;
 
@@ -277,12 +281,11 @@
   T->instant("Log", llvm::json::Object{{"Message", Message.str()}});
 }
 
-// Returned context owns Args.
-static Context makeSpanContext(llvm::Twine Name, llvm::json::Object *Args,
-   const Metric &LatencyMetric) {
+// The JSON object is event args (owned by context), if the tracer wants them.
+static std::pair
+makeSpanContext(llvm::Twine Name, const Metric &La

[PATCH] D89233: [clangd] Refine recoveryAST flags in clangd

2020-10-12 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: sammccall.
Herald added subscribers: usaxena95, kadircet, arphaman.
Herald added a project: clang.
hokein requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.

so that we could start experiment for C.

Previously, these flags in clangd were only meaningful for C++. We need
to flip them for C, this patch repurpose these flags.

- if true, just set it.
- if false, just respect the value in clang.

this would allow us to keep flags on for C++, and optionally flip them on for C.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D89233

Files:
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/Compiler.cpp
  clang-tools-extra/clangd/tool/ClangdMain.cpp
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang-tools-extra/clangd/unittests/FindTargetTests.cpp
  clang-tools-extra/clangd/unittests/TestTU.cpp

Index: clang-tools-extra/clangd/unittests/TestTU.cpp
===
--- clang-tools-extra/clangd/unittests/TestTU.cpp
+++ clang-tools-extra/clangd/unittests/TestTU.cpp
@@ -59,8 +59,6 @@
 FS.OverlayRealFileSystemForModules = true;
   Inputs.TFS = &FS;
   Inputs.Opts = ParseOptions();
-  Inputs.Opts.BuildRecoveryAST = true;
-  Inputs.Opts.PreserveRecoveryASTType = true;
   Inputs.Opts.ClangTidyOpts.Checks = ClangTidyChecks;
   Inputs.Opts.ClangTidyOpts.WarningsAsErrors = ClangTidyWarningsAsErrors;
   Inputs.Index = ExternalIndex;
Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp
===
--- clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -148,6 +148,17 @@
   EXPECT_DECLS("LabelStmt", "label:");
 }
 
+TEST_F(TargetDeclTest, RecoveryForC) {
+  Flags = {"-xc", "-Xclang", "-frecovery-ast"};
+  Code = R"cpp(
+// error-ok: testing behavior on broken code
+// int f();
+int f(int);
+int x = [[f]]();
+  )cpp";
+  EXPECT_DECLS("DeclRefExpr", "int f(int)");
+}
+
 TEST_F(TargetDeclTest, Recovery) {
   Code = R"cpp(
 // error-ok: testing behavior on broken code
Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -111,8 +111,6 @@
 
   MockFS FS;
   auto Inputs = TU.inputs(FS);
-  Inputs.Opts.BuildRecoveryAST = true;
-  Inputs.Opts.PreserveRecoveryASTType = true;
   IgnoreDiagnostics Diags;
   auto CI = buildCompilerInvocation(Inputs, Diags);
   if (!CI) {
@@ -1100,8 +1098,6 @@
   MockFS FS;
   auto Inputs = TU.inputs(FS);
   Inputs.Index = Index.get();
-  Inputs.Opts.BuildRecoveryAST = true;
-  Inputs.Opts.PreserveRecoveryASTType = true;
   IgnoreDiagnostics Diags;
   auto CI = buildCompilerInvocation(Inputs, Diags);
   if (!CI) {
Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -310,7 +310,7 @@
 opt RecoveryAST{
 "recovery-ast",
 cat(Features),
-desc("Preserve expressions in AST for broken code (C++ only)."),
+desc("Preserve expressions in AST for broken code."),
 init(ClangdServer::Options().BuildRecoveryAST),
 };
 
Index: clang-tools-extra/clangd/Compiler.cpp
===
--- clang-tools-extra/clangd/Compiler.cpp
+++ clang-tools-extra/clangd/Compiler.cpp
@@ -81,11 +81,11 @@
   // Don't crash on `#pragma clang __debug parser_crash`
   CI->getPreprocessorOpts().DisablePragmaDebugCrash = true;
 
-  // Recovery expression currently only works for C++.
-  if (CI->getLangOpts()->CPlusPlus) {
-CI->getLangOpts()->RecoveryAST = Inputs.Opts.BuildRecoveryAST;
-CI->getLangOpts()->RecoveryASTType = Inputs.Opts.PreserveRecoveryASTType;
-  }
+  if (Inputs.Opts.BuildRecoveryAST)
+CI->getLangOpts()->RecoveryAST = true;
+  if (Inputs.Opts.PreserveRecoveryASTType)
+CI->getLangOpts()->RecoveryASTType = true;
+
   return CI;
 }
 
Index: clang-tools-extra/clangd/ClangdServer.h
===
--- clang-tools-extra/clangd/ClangdServer.h
+++ clang-tools-extra/clangd/ClangdServer.h
@@ -127,11 +127,13 @@
 /// enabled.
 ClangTidyOptionsBuilder GetClangTidyOptions;
 
-/// If true, turn on the `-frecovery-ast` clang flag.
-bool BuildRecoveryAST = true;
+/// If true, turn on the `-frecovery-ast` clang flag;
+/// If false, respect to the value in clang.
+bool BuildRecoveryAST = false;
 
 /// If true, turn on the `-frecovery-ast-type` clang flag.
-bool PreserveRecoveryASTType = true;
+/// If false, respect to the value in clang.
+bool PreserveRecoveryASTType =

[PATCH] D89135: [clangd] Stop capturing trace args if the tracer doesn't need them.

2020-10-12 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.

still LGTM. thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89135/new/

https://reviews.llvm.org/D89135

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


[PATCH] D89225: [MinGW][clang-shlib] Build only when LLVM_LINK_LLVM_DYLIB is enabled

2020-10-12 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov accepted this revision.
ASDenysPetrov added a comment.
This revision is now accepted and ready to land.

It works for me. Well done!

I've applied your patch and tried this:

  cmake -GNinja ../llvm -DLLVM_LIT_ARGS=-sv -DLLVM_LINK_LLVM_DYLIB=ON 
-DLLVM_ENABLE_PROJECTS=clang -DLLVM_TARGETS_TO_BUILD=X86 
-DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../../install 
-DLLVM_ENABLE_ASSERTIONS=ON
  ninja




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89225/new/

https://reviews.llvm.org/D89225

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


[clang-tools-extra] 8f1de22 - [clangd] Stop capturing trace args if the tracer doesn't need them.

2020-10-12 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2020-10-12T13:43:05+02:00
New Revision: 8f1de22c7681a21fcdbe2d8c39de7698baab724a

URL: 
https://github.com/llvm/llvm-project/commit/8f1de22c7681a21fcdbe2d8c39de7698baab724a
DIFF: 
https://github.com/llvm/llvm-project/commit/8f1de22c7681a21fcdbe2d8c39de7698baab724a.diff

LOG: [clangd] Stop capturing trace args if the tracer doesn't need them.

The tracer is now expected to allocate+free the args itself.

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

Added: 


Modified: 
clang-tools-extra/clangd/support/Trace.cpp
clang-tools-extra/clangd/support/Trace.h
clang-tools-extra/clangd/unittests/support/TraceTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/support/Trace.cpp 
b/clang-tools-extra/clangd/support/Trace.cpp
index 7ab09cd23e6a..89d65e686ebc 100644
--- a/clang-tools-extra/clangd/support/Trace.cpp
+++ b/clang-tools-extra/clangd/support/Trace.cpp
@@ -53,9 +53,12 @@ class JSONTracer : public EventTracer {
 
   // We stash a Span object in the context. It will record the start/end,
   // and this also allows us to look up the parent Span's information.
-  Context beginSpan(llvm::StringRef Name, llvm::json::Object *Args) override {
-return Context::current().derive(
-SpanKey, std::make_unique(this, Name, Args));
+  Context beginSpan(
+  llvm::StringRef Name,
+  llvm::function_ref AttachDetails) override {
+auto JS = std::make_unique(this, Name);
+AttachDetails(&JS->Args);
+return Context::current().derive(SpanKey, std::move(JS));
   }
 
   // Trace viewer requires each thread to properly stack events.
@@ -85,9 +88,9 @@ class JSONTracer : public EventTracer {
 private:
   class JSONSpan {
   public:
-JSONSpan(JSONTracer *Tracer, llvm::StringRef Name, llvm::json::Object 
*Args)
+JSONSpan(JSONTracer *Tracer, llvm::StringRef Name)
 : StartTime(Tracer->timestamp()), EndTime(0), Name(Name),
-  TID(llvm::get_threadid()), Tracer(Tracer), Args(Args) {
+  TID(llvm::get_threadid()), Tracer(Tracer) {
   // ~JSONSpan() may run in a 
diff erent thread, so we need to capture now.
   Tracer->captureThreadMetadata();
 
@@ -125,7 +128,7 @@ class JSONTracer : public EventTracer {
   // Finally, record the event (ending at EndTime, not timestamp())!
   Tracer->jsonEvent("X",
 llvm::json::Object{{"name", std::move(Name)},
-   {"args", std::move(*Args)},
+   {"args", std::move(Args)},
{"dur", EndTime - StartTime}},
 TID, StartTime);
 }
@@ -133,6 +136,8 @@ class JSONTracer : public EventTracer {
 // May be called by any thread.
 void markEnded() { EndTime = Tracer->timestamp(); }
 
+llvm::json::Object Args;
+
   private:
 static int64_t nextID() {
   static std::atomic Next = {0};
@@ -144,7 +149,6 @@ class JSONTracer : public EventTracer {
 std::string Name;
 uint64_t TID;
 JSONTracer *Tracer;
-llvm::json::Object *Args;
   };
   static Key> SpanKey;
 
@@ -277,12 +281,11 @@ void log(const llvm::Twine &Message) {
   T->instant("Log", llvm::json::Object{{"Message", Message.str()}});
 }
 
-// Returned context owns Args.
-static Context makeSpanContext(llvm::Twine Name, llvm::json::Object *Args,
-   const Metric &LatencyMetric) {
+// The JSON object is event args (owned by context), if the tracer wants them.
+static std::pair
+makeSpanContext(llvm::Twine Name, const Metric &LatencyMetric) {
   if (!T)
-return Context::current().clone();
-  WithContextValue WithArgs{std::unique_ptr(Args)};
+return std::make_pair(Context::current().clone(), nullptr);
   llvm::Optional WithLatency;
   using Clock = std::chrono::high_resolution_clock;
   WithLatency.emplace(llvm::make_scope_exit(
@@ -293,9 +296,15 @@ static Context makeSpanContext(llvm::Twine Name, 
llvm::json::Object *Args,
 .count(),
 Name);
   }));
-  return T->beginSpan(Name.isSingleStringRef() ? Name.getSingleStringRef()
-   : llvm::StringRef(Name.str()),
-  Args);
+  llvm::json::Object *Args = nullptr;
+  Context Ctx = T->beginSpan(
+  Name.isSingleStringRef() ? Name.getSingleStringRef()
+   : llvm::StringRef(Name.str()),
+  [&](llvm::json::Object *A) {
+assert(A && A->empty() && "Invalid AttachDetails() placeholder!");
+Args = A;
+  });
+  return std::make_pair(std::move(Ctx), Args);
 }
 
 // Fallback metric that measures latencies for spans without an explicit 
latency
@@ -307,8 +316,9 @@ constexpr Metric SpanLatency("span_latency", 
Metric::Distribution, "span_name");
 // beginSpan() context is destroyed, when the tracing engine will consume them.
 Span::Span(llvm:

[PATCH] D89135: [clangd] Stop capturing trace args if the tracer doesn't need them.

2020-10-12 Thread Sam McCall via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8f1de22c7681: [clangd] Stop capturing trace args if the 
tracer doesn't need them. (authored by sammccall).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89135/new/

https://reviews.llvm.org/D89135

Files:
  clang-tools-extra/clangd/support/Trace.cpp
  clang-tools-extra/clangd/support/Trace.h
  clang-tools-extra/clangd/unittests/support/TraceTests.cpp

Index: clang-tools-extra/clangd/unittests/support/TraceTests.cpp
===
--- clang-tools-extra/clangd/unittests/support/TraceTests.cpp
+++ clang-tools-extra/clangd/unittests/support/TraceTests.cpp
@@ -186,6 +186,11 @@
  StartsWith("d,dist,\"a\nb\",1"), ""));
 }
 
+TEST_F(CSVMetricsTracerTest, IgnoresArgs) {
+  trace::Span Tracer("Foo");
+  EXPECT_EQ(nullptr, Tracer.Args);
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/support/Trace.h
===
--- clang-tools-extra/clangd/support/Trace.h
+++ clang-tools-extra/clangd/support/Trace.h
@@ -79,8 +79,13 @@
   /// Returns a derived context that will be destroyed when the event ends.
   /// Usually implementations will store an object in the returned context
   /// whose destructor records the end of the event.
-  /// The args are *Args, only complete when the event ends.
-  virtual Context beginSpan(llvm::StringRef Name, llvm::json::Object *Args);
+  /// The tracer may capture event details provided in SPAN_ATTACH() calls.
+  /// In this case it should call AttachDetails(), and pass in an empty Object
+  /// to hold them. This Object should be owned by the context, and the data
+  /// will be complete by the time the context is destroyed.
+  virtual Context
+  beginSpan(llvm::StringRef Name,
+llvm::function_ref AttachDetails);
   // Called when a Span is destroyed (it may still be active on other threads).
   // beginSpan() and endSpan() will always form a proper stack on each thread.
   // The Context returned by beginSpan is active, but Args is not ready.
@@ -146,6 +151,8 @@
   llvm::json::Object *const Args;
 
 private:
+  // Awkward constructor works around constant initialization.
+  Span(std::pair);
   WithContext RestoreCtx;
 };
 
Index: clang-tools-extra/clangd/support/Trace.cpp
===
--- clang-tools-extra/clangd/support/Trace.cpp
+++ clang-tools-extra/clangd/support/Trace.cpp
@@ -53,9 +53,12 @@
 
   // We stash a Span object in the context. It will record the start/end,
   // and this also allows us to look up the parent Span's information.
-  Context beginSpan(llvm::StringRef Name, llvm::json::Object *Args) override {
-return Context::current().derive(
-SpanKey, std::make_unique(this, Name, Args));
+  Context beginSpan(
+  llvm::StringRef Name,
+  llvm::function_ref AttachDetails) override {
+auto JS = std::make_unique(this, Name);
+AttachDetails(&JS->Args);
+return Context::current().derive(SpanKey, std::move(JS));
   }
 
   // Trace viewer requires each thread to properly stack events.
@@ -85,9 +88,9 @@
 private:
   class JSONSpan {
   public:
-JSONSpan(JSONTracer *Tracer, llvm::StringRef Name, llvm::json::Object *Args)
+JSONSpan(JSONTracer *Tracer, llvm::StringRef Name)
 : StartTime(Tracer->timestamp()), EndTime(0), Name(Name),
-  TID(llvm::get_threadid()), Tracer(Tracer), Args(Args) {
+  TID(llvm::get_threadid()), Tracer(Tracer) {
   // ~JSONSpan() may run in a different thread, so we need to capture now.
   Tracer->captureThreadMetadata();
 
@@ -125,7 +128,7 @@
   // Finally, record the event (ending at EndTime, not timestamp())!
   Tracer->jsonEvent("X",
 llvm::json::Object{{"name", std::move(Name)},
-   {"args", std::move(*Args)},
+   {"args", std::move(Args)},
{"dur", EndTime - StartTime}},
 TID, StartTime);
 }
@@ -133,6 +136,8 @@
 // May be called by any thread.
 void markEnded() { EndTime = Tracer->timestamp(); }
 
+llvm::json::Object Args;
+
   private:
 static int64_t nextID() {
   static std::atomic Next = {0};
@@ -144,7 +149,6 @@
 std::string Name;
 uint64_t TID;
 JSONTracer *Tracer;
-llvm::json::Object *Args;
   };
   static Key> SpanKey;
 
@@ -277,12 +281,11 @@
   T->instant("Log", llvm::json::Object{{"Message", Message.str()}});
 }
 
-// Returned context owns Args.
-static Context makeSpanContext(llvm::Twine Name, llvm::json::Object *Args,
-   const Metric &LatencyMetric) {
+// The JSON object is event a

[PATCH] D88106: [SyntaxTree] Provide iterator-like functions for Lists

2020-10-12 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 added inline comments.



Comment at: clang/include/clang/Tooling/Syntax/Tree.h:211
+  return element == Other.element && delimiter == Other.delimiter;
+}
   };

Please also define `operator!=` even if it is not used yet.



Comment at: clang/include/clang/Tooling/Syntax/Tree.h:225
+  /// elements and delimiters are represented as null pointers. Below we give
+  /// examples of how this iteration would look like:
   ///

"how something looks" or "what something looks like"



Comment at: clang/include/clang/Tooling/Syntax/Tree.h:238-273
+  class ElementAndDelimiterIterator
+  : public llvm::iterator_facade_base> {
+  public:
+ElementAndDelimiterIterator(llvm::Optional> ED)
+: EDI(ED) {}

eduucaldas wrote:
> Should we hide some of this? Most of the member functions are a couple of 
> lines, so I decided not to. What is your opinion?
I think it is fine as is.



Comment at: clang/include/clang/Tooling/Syntax/Tree.h:269
+  return EDI == Other.EDI;
+}
+

Please also define `operator!=`.



Comment at: clang/include/clang/Tooling/Syntax/Tree.h:283
+return ElementsAndDelimitersRange(getBegin(), getEnd());
+  }
+

I'd imagine derived classes would have iterators that produce strongly-typed 
elements, right?

If so, these methods getBegin()/getEnd()/getRange() should have the word "Node" 
in them.



Comment at: clang/include/clang/Tooling/Syntax/Tree.h:314
+private:
+  // Auxiliary methods for implementing `ElementAndDelimiterIterator`.
+  static ElementAndDelimiter getWithDelimiter(Node *Element);

People can use "find usages" to find what uses these methods. Such comments 
often go out of date.



Comment at: clang/lib/Tooling/Syntax/Tree.cpp:350
+  auto *Next = Element->getNextSibling();
+  // a  b, x => End of list, this was the last ElementAndDelimiter.
+  if (!Next)

I have a hard time understand what a b x and the comma stand for in these 
comments.



Comment at: clang/lib/Tooling/Syntax/Tree.cpp:391-396
+  auto Children = std::vector>();
+  for (auto C : getRange()) {
+Children.push_back(C);
   }
+
+  return Children;





Comment at: clang/lib/Tooling/Syntax/Tree.cpp:405
 
   return Children;
 }

Ditto?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88106/new/

https://reviews.llvm.org/D88106

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


[PATCH] D89131: [clangd] Validate optional fields more strictly.

2020-10-12 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Sorry, I thought this was accepted. Had addressed the two comments, happy to 
address more or revert, LMK


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89131/new/

https://reviews.llvm.org/D89131

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


[PATCH] D89233: [clangd] Refine recoveryAST flags in clangd

2020-10-12 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

This is fine as is, but could consider retiring the flags instead.




Comment at: clang-tools-extra/clangd/ClangdServer.h:131
+/// If true, turn on the `-frecovery-ast` clang flag;
+/// If false, respect to the value in clang.
+bool BuildRecoveryAST = false;

nit: respect to -> respect

This could just be "If true, force -frecovery-ast-type"



Comment at: clang-tools-extra/clangd/Compiler.cpp:84
 
-  // Recovery expression currently only works for C++.
-  if (CI->getLangOpts()->CPlusPlus) {
-CI->getLangOpts()->RecoveryAST = Inputs.Opts.BuildRecoveryAST;
-CI->getLangOpts()->RecoveryASTType = Inputs.Opts.PreserveRecoveryASTType;
-  }
+  if (Inputs.Opts.BuildRecoveryAST)
+CI->getLangOpts()->RecoveryAST = true;

I don't have any problem with the changes to the flags, but we can also do 
experiments just with config now:

```
CompileFlags:
  Add: [-Xclang, -frecovery-ast]
```

in ~/.config/clangd/config.yaml


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89233/new/

https://reviews.llvm.org/D89233

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


[PATCH] D89131: [clangd] Validate optional fields more strictly.

2020-10-12 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

ah, I thought I clicked the accepted button.

anyway, LGTM.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89131/new/

https://reviews.llvm.org/D89131

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


[clang-tools-extra] 9407686 - [clangd][NFC] Fix formatting in ClangdLSPServer

2020-10-12 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2020-10-12T14:24:44+02:00
New Revision: 9407686687907fa2af24219e1d6e57787872bef8

URL: 
https://github.com/llvm/llvm-project/commit/9407686687907fa2af24219e1d6e57787872bef8
DIFF: 
https://github.com/llvm/llvm-project/commit/9407686687907fa2af24219e1d6e57787872bef8.diff

LOG: [clangd][NFC] Fix formatting in ClangdLSPServer

Added: 


Modified: 
clang-tools-extra/clangd/ClangdLSPServer.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp 
b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index 9ed635c88e71..01f962ad5b48 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -1049,22 +1049,21 @@ void ClangdLSPServer::onCompletion(const 
CompletionParams &Params,
 vlog("ignored auto-triggered completion, preceding char did not match");
 return Reply(CompletionList());
   }
-  Server->codeComplete(Params.textDocument.uri.file(), Params.position,
-   Opts.CodeComplete,
-   [Reply = std::move(Reply),
-this](llvm::Expected List) mutable 
{
- if (!List)
-   return Reply(List.takeError());
- CompletionList LSPList;
- LSPList.isIncomplete = List->HasMore;
- for (const auto &R : List->Completions) {
-   CompletionItem C = R.render(Opts.CodeComplete);
-   C.kind = adjustKindToCapability(
-   C.kind, SupportedCompletionItemKinds);
-   LSPList.items.push_back(std::move(C));
- }
- return Reply(std::move(LSPList));
-   });
+  Server->codeComplete(
+  Params.textDocument.uri.file(), Params.position, Opts.CodeComplete,
+  [Reply = std::move(Reply),
+   this](llvm::Expected List) mutable {
+if (!List)
+  return Reply(List.takeError());
+CompletionList LSPList;
+LSPList.isIncomplete = List->HasMore;
+for (const auto &R : List->Completions) {
+  CompletionItem C = R.render(Opts.CodeComplete);
+  C.kind = adjustKindToCapability(C.kind, 
SupportedCompletionItemKinds);
+  LSPList.items.push_back(std::move(C));
+}
+return Reply(std::move(LSPList));
+  });
 }
 
 void ClangdLSPServer::onSignatureHelp(const TextDocumentPositionParams &Params,



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


[PATCH] D88417: [clangd] Record memory usages after each notification

2020-10-12 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 297565.
kadircet marked 5 inline comments as done.
kadircet added a comment.

- Separate profiling and exporting into 2 functions
- Rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88417/new/

https://reviews.llvm.org/D88417

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/unittests/ClangdTests.cpp

Index: clang-tools-extra/clangd/unittests/ClangdTests.cpp
===
--- clang-tools-extra/clangd/unittests/ClangdTests.cpp
+++ clang-tools-extra/clangd/unittests/ClangdTests.cpp
@@ -17,6 +17,7 @@
 #include "TestFS.h"
 #include "TestTU.h"
 #include "URI.h"
+#include "support/MemoryTree.h"
 #include "support/Path.h"
 #include "support/Threading.h"
 #include "clang/Config/config.h"
@@ -27,6 +28,7 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Allocator.h"
 #include "llvm/Support/Errc.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Regex.h"
@@ -48,6 +50,7 @@
 namespace {
 
 using ::testing::AllOf;
+using ::testing::Contains;
 using ::testing::ElementsAre;
 using ::testing::Field;
 using ::testing::Gt;
@@ -1236,6 +1239,21 @@
   EXPECT_FALSE(DiagConsumer.HadDiagsInLastCallback);
 }
 
+TEST(ClangdServer, MemoryUsageTest) {
+  MockFS FS;
+  MockCompilationDatabase CDB;
+  ClangdServer Server(CDB, FS, ClangdServer::optsForTest());
+
+  auto FooCpp = testPath("foo.cpp");
+  Server.addDocument(FooCpp, "");
+  ASSERT_TRUE(Server.blockUntilIdleForTest());
+
+  llvm::BumpPtrAllocator Alloc;
+  MemoryTree MT(&Alloc);
+  Server.profile(MT);
+  ASSERT_TRUE(MT.children().count("tuscheduler"));
+  EXPECT_TRUE(MT.child("tuscheduler").children().count(FooCpp));
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/ClangdServer.h
===
--- clang-tools-extra/clangd/ClangdServer.h
+++ clang-tools-extra/clangd/ClangdServer.h
@@ -25,6 +25,7 @@
 #include "refactor/Tweak.h"
 #include "support/Cancellation.h"
 #include "support/Function.h"
+#include "support/MemoryTree.h"
 #include "support/ThreadsafeFS.h"
 #include "clang/Tooling/CompilationDatabase.h"
 #include "clang/Tooling/Core/Replacement.h"
@@ -337,6 +338,9 @@
   LLVM_NODISCARD bool
   blockUntilIdleForTest(llvm::Optional TimeoutSeconds = 10);
 
+  /// Builds a nested representation of memory used by components.
+  void profile(MemoryTree &MT) const;
+
 private:
   void formatCode(PathRef File, llvm::StringRef Code,
   ArrayRef Ranges,
Index: clang-tools-extra/clangd/ClangdServer.cpp
===
--- clang-tools-extra/clangd/ClangdServer.cpp
+++ clang-tools-extra/clangd/ClangdServer.cpp
@@ -28,6 +28,7 @@
 #include "refactor/Tweak.h"
 #include "support/Logger.h"
 #include "support/Markup.h"
+#include "support/MemoryTree.h"
 #include "support/ThreadsafeFS.h"
 #include "support/Trace.h"
 #include "clang/Format/Format.h"
@@ -826,5 +827,12 @@
   BackgroundIdx->blockUntilIdleForTest(TimeoutSeconds));
 }
 
+void ClangdServer::profile(MemoryTree &MT) const {
+  if (DynamicIdx)
+DynamicIdx->profile(MT.child("dynamic_index"));
+  if (BackgroundIdx)
+BackgroundIdx->profile(MT.child("background_index"));
+  WorkScheduler.profile(MT.child("tuscheduler"));
+}
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/ClangdLSPServer.h
===
--- clang-tools-extra/clangd/ClangdLSPServer.h
+++ clang-tools-extra/clangd/ClangdLSPServer.h
@@ -17,11 +17,13 @@
 #include "Protocol.h"
 #include "Transport.h"
 #include "support/Context.h"
+#include "support/MemoryTree.h"
 #include "support/Path.h"
 #include "clang/Tooling/Core/Replacement.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/StringSet.h"
 #include "llvm/Support/JSON.h"
+#include 
 #include 
 
 namespace clang {
@@ -67,6 +69,9 @@
   /// \return Whether we shut down cleanly with a 'shutdown' -> 'exit' sequence.
   bool run();
 
+  /// Profiles resource-usage. No-op if there's no active tracer.
+  void profile(MemoryTree &MT) const;
+
 private:
   // Implement ClangdServer::Callbacks.
   void onDiagnosticsReady(PathRef File, llvm::StringRef Version,
@@ -160,6 +165,14 @@
   /// Sends a "publishDiagnostics" notification to the LSP client.
   void publishDiagnostics(const PublishDiagnosticsParams &);
 
+  /// Runs profiling and exports memory usage metrics if tracing is enabled and
+  /// profiling hasn't happened recently.
+  void maybeExportMemoryProfile();
+
+  /// Timepoint until which profiling is off. It is used to throttle profiling
+  /// requests.
+  std::chrono::steady_cl

[clang-tools-extra] 1968a61 - [clang-tidy] Fix IncludeInserter usage example in a comment.

2020-10-12 Thread Alexander Kornienko via cfe-commits

Author: Alexander Kornienko
Date: 2020-10-12T15:05:42+02:00
New Revision: 1968a6155fd5ef178598b204cc6a176719b99f2e

URL: 
https://github.com/llvm/llvm-project/commit/1968a6155fd5ef178598b204cc6a176719b99f2e
DIFF: 
https://github.com/llvm/llvm-project/commit/1968a6155fd5ef178598b204cc6a176719b99f2e.diff

LOG: [clang-tidy] Fix IncludeInserter usage example in a comment.

Added: 


Modified: 
clang-tools-extra/clang-tidy/utils/IncludeInserter.h

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/utils/IncludeInserter.h 
b/clang-tools-extra/clang-tidy/utils/IncludeInserter.h
index 95236c732f13..74903b2d166d 100644
--- a/clang-tools-extra/clang-tidy/utils/IncludeInserter.h
+++ b/clang-tools-extra/clang-tidy/utils/IncludeInserter.h
@@ -34,7 +34,7 @@ namespace utils {
 ///  public:
 ///   void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
 ///Preprocessor *ModuleExpanderPP) override {
-/// Inserter.registerPreprocessor();
+/// Inserter.registerPreprocessor(PP);
 ///   }
 ///
 ///   void registerMatchers(ast_matchers::MatchFinder* Finder) override { ... }
@@ -42,8 +42,7 @@ namespace utils {
 ///   void check(
 ///   const ast_matchers::MatchFinder::MatchResult& Result) override {
 /// ...
-/// Inserter.createMainFileIncludeInsertion("path/to/Header.h",
-/// /*IsAngled=*/false);
+/// Inserter.createMainFileIncludeInsertion("path/to/Header.h");
 /// ...
 ///   }
 ///



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


[PATCH] D88417: [clangd] Record memory usages after each notification

2020-10-12 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clangd/ClangdLSPServer.h:72
 
+  /// Profiles resource-usage. No-op if there's no active tracer.
+  void profile(MemoryTree &MT) const;

drop the no-op part?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88417/new/

https://reviews.llvm.org/D88417

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


[PATCH] D76620: [SYCL] Implement __builtin_unique_stable_name.

2020-10-12 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In D76620#2324119 , @rjmccall wrote:

> Richard and I just found out about this commit, and we've decided to revert 
> it.  I apologize for the very late reversion, but the reality of Clang 
> development is that it's very difficult for the code owners to watch 
> literally every commit, and we rely on the community to follow policies and 
> bring things to our attention when there's a question about the right thing 
> to do.  This is a new feature that was submitted without properly following 
> any of the guidelines for new features: it was neither approved by a relevant 
> standards body, added for compatibility with an existing frontend, or taken 
> through the RFC process.  If you had brought it to our attention as an RFC, 
> we would've expressed serious concerns about the design.
>
> Please start an RFC thread and CC Richard and me.

The feature that this supports is a part of the SYCL 2020 Provisional Spec, I 
thought that was sufficient.  We'll look into an RFC to re-submit in the future.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76620/new/

https://reviews.llvm.org/D76620

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


[PATCH] D88417: [clangd] Record memory usages after each notification

2020-10-12 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 297568.
kadircet marked an inline comment as done.
kadircet added a comment.

- Update stale comment


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88417/new/

https://reviews.llvm.org/D88417

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/unittests/ClangdTests.cpp

Index: clang-tools-extra/clangd/unittests/ClangdTests.cpp
===
--- clang-tools-extra/clangd/unittests/ClangdTests.cpp
+++ clang-tools-extra/clangd/unittests/ClangdTests.cpp
@@ -17,6 +17,7 @@
 #include "TestFS.h"
 #include "TestTU.h"
 #include "URI.h"
+#include "support/MemoryTree.h"
 #include "support/Path.h"
 #include "support/Threading.h"
 #include "clang/Config/config.h"
@@ -27,6 +28,7 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Allocator.h"
 #include "llvm/Support/Errc.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Regex.h"
@@ -48,6 +50,7 @@
 namespace {
 
 using ::testing::AllOf;
+using ::testing::Contains;
 using ::testing::ElementsAre;
 using ::testing::Field;
 using ::testing::Gt;
@@ -1236,6 +1239,21 @@
   EXPECT_FALSE(DiagConsumer.HadDiagsInLastCallback);
 }
 
+TEST(ClangdServer, MemoryUsageTest) {
+  MockFS FS;
+  MockCompilationDatabase CDB;
+  ClangdServer Server(CDB, FS, ClangdServer::optsForTest());
+
+  auto FooCpp = testPath("foo.cpp");
+  Server.addDocument(FooCpp, "");
+  ASSERT_TRUE(Server.blockUntilIdleForTest());
+
+  llvm::BumpPtrAllocator Alloc;
+  MemoryTree MT(&Alloc);
+  Server.profile(MT);
+  ASSERT_TRUE(MT.children().count("tuscheduler"));
+  EXPECT_TRUE(MT.child("tuscheduler").children().count(FooCpp));
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/ClangdServer.h
===
--- clang-tools-extra/clangd/ClangdServer.h
+++ clang-tools-extra/clangd/ClangdServer.h
@@ -25,6 +25,7 @@
 #include "refactor/Tweak.h"
 #include "support/Cancellation.h"
 #include "support/Function.h"
+#include "support/MemoryTree.h"
 #include "support/ThreadsafeFS.h"
 #include "clang/Tooling/CompilationDatabase.h"
 #include "clang/Tooling/Core/Replacement.h"
@@ -337,6 +338,9 @@
   LLVM_NODISCARD bool
   blockUntilIdleForTest(llvm::Optional TimeoutSeconds = 10);
 
+  /// Builds a nested representation of memory used by components.
+  void profile(MemoryTree &MT) const;
+
 private:
   void formatCode(PathRef File, llvm::StringRef Code,
   ArrayRef Ranges,
Index: clang-tools-extra/clangd/ClangdServer.cpp
===
--- clang-tools-extra/clangd/ClangdServer.cpp
+++ clang-tools-extra/clangd/ClangdServer.cpp
@@ -28,6 +28,7 @@
 #include "refactor/Tweak.h"
 #include "support/Logger.h"
 #include "support/Markup.h"
+#include "support/MemoryTree.h"
 #include "support/ThreadsafeFS.h"
 #include "support/Trace.h"
 #include "clang/Format/Format.h"
@@ -826,5 +827,12 @@
   BackgroundIdx->blockUntilIdleForTest(TimeoutSeconds));
 }
 
+void ClangdServer::profile(MemoryTree &MT) const {
+  if (DynamicIdx)
+DynamicIdx->profile(MT.child("dynamic_index"));
+  if (BackgroundIdx)
+BackgroundIdx->profile(MT.child("background_index"));
+  WorkScheduler.profile(MT.child("tuscheduler"));
+}
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/ClangdLSPServer.h
===
--- clang-tools-extra/clangd/ClangdLSPServer.h
+++ clang-tools-extra/clangd/ClangdLSPServer.h
@@ -17,11 +17,13 @@
 #include "Protocol.h"
 #include "Transport.h"
 #include "support/Context.h"
+#include "support/MemoryTree.h"
 #include "support/Path.h"
 #include "clang/Tooling/Core/Replacement.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/StringSet.h"
 #include "llvm/Support/JSON.h"
+#include 
 #include 
 
 namespace clang {
@@ -67,6 +69,9 @@
   /// \return Whether we shut down cleanly with a 'shutdown' -> 'exit' sequence.
   bool run();
 
+  /// Profiles resource-usage.
+  void profile(MemoryTree &MT) const;
+
 private:
   // Implement ClangdServer::Callbacks.
   void onDiagnosticsReady(PathRef File, llvm::StringRef Version,
@@ -160,6 +165,14 @@
   /// Sends a "publishDiagnostics" notification to the LSP client.
   void publishDiagnostics(const PublishDiagnosticsParams &);
 
+  /// Runs profiling and exports memory usage metrics if tracing is enabled and
+  /// profiling hasn't happened recently.
+  void maybeExportMemoryProfile();
+
+  /// Timepoint until which profiling is off. It is used to throttle profiling
+  /// requests.
+  std::chrono::steady_clock::time_point NextProfileTime;
+
   /// Since initialization of CDBs an

[PATCH] D88411: [clangd] Introduce MemoryTrees

2020-10-12 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf9317f7bf6bd: [clangd] Introduce MemoryTrees (authored by 
kadircet).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88411/new/

https://reviews.llvm.org/D88411

Files:
  clang-tools-extra/clangd/support/CMakeLists.txt
  clang-tools-extra/clangd/support/MemoryTree.cpp
  clang-tools-extra/clangd/support/MemoryTree.h
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/support/MemoryTreeTests.cpp

Index: clang-tools-extra/clangd/unittests/support/MemoryTreeTests.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/support/MemoryTreeTests.cpp
@@ -0,0 +1,78 @@
+//===-- MemoryTreeTests.cpp -*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "support/MemoryTree.h"
+#include "llvm/Support/Allocator.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+#include 
+
+namespace clang {
+namespace clangd {
+namespace {
+using testing::Contains;
+using testing::IsEmpty;
+using testing::UnorderedElementsAre;
+
+MATCHER_P2(WithNameAndSize, Name, Size, "") {
+  return arg.first == Name &&
+ arg.getSecond().total() == static_cast(Size);
+}
+
+TEST(MemoryTree, Basics) {
+  MemoryTree MT;
+  EXPECT_EQ(MT.total(), 0U);
+  EXPECT_THAT(MT.children(), IsEmpty());
+
+  MT.addUsage(42);
+  EXPECT_EQ(MT.total(), 42U);
+  EXPECT_THAT(MT.children(), IsEmpty());
+
+  MT.child("leaf").addUsage(1);
+  EXPECT_EQ(MT.total(), 43U);
+  EXPECT_THAT(MT.children(), UnorderedElementsAre(WithNameAndSize("leaf", 1)));
+
+  // child should be idempotent.
+  MT.child("leaf").addUsage(1);
+  EXPECT_EQ(MT.total(), 44U);
+  EXPECT_THAT(MT.children(), UnorderedElementsAre(WithNameAndSize("leaf", 2)));
+}
+
+TEST(MemoryTree, DetailedNodesWithoutDetails) {
+  MemoryTree MT;
+  MT.detail("should_be_ignored").addUsage(2);
+  EXPECT_THAT(MT.children(), IsEmpty());
+  EXPECT_EQ(MT.total(), 2U);
+
+  // Make sure children from details are merged.
+  MT.detail("first_detail").child("leaf").addUsage(1);
+  MT.detail("second_detail").child("leaf").addUsage(1);
+  EXPECT_THAT(MT.children(), Contains(WithNameAndSize("leaf", 2)));
+}
+
+TEST(MemoryTree, DetailedNodesWithDetails) {
+  llvm::BumpPtrAllocator Alloc;
+  MemoryTree MT(&Alloc);
+
+  {
+auto &Detail = MT.detail("first_detail");
+Detail.child("leaf").addUsage(1);
+EXPECT_THAT(MT.children(), Contains(WithNameAndSize("first_detail", 1)));
+EXPECT_THAT(Detail.children(), Contains(WithNameAndSize("leaf", 1)));
+  }
+
+  {
+auto &Detail = MT.detail("second_detail");
+Detail.child("leaf").addUsage(1);
+EXPECT_THAT(MT.children(), Contains(WithNameAndSize("second_detail", 1)));
+EXPECT_THAT(Detail.children(), Contains(WithNameAndSize("leaf", 1)));
+  }
+}
+} // namespace
+} // namespace clangd
+} // namespace clang
Index: clang-tools-extra/clangd/unittests/CMakeLists.txt
===
--- clang-tools-extra/clangd/unittests/CMakeLists.txt
+++ clang-tools-extra/clangd/unittests/CMakeLists.txt
@@ -99,6 +99,7 @@
   support/ContextTests.cpp
   support/FunctionTests.cpp
   support/MarkupTests.cpp
+  support/MemoryTreeTests.cpp
   support/ThreadingTests.cpp
   support/TestTracer.cpp
   support/TraceTests.cpp
Index: clang-tools-extra/clangd/support/MemoryTree.h
===
--- /dev/null
+++ clang-tools-extra/clangd/support/MemoryTree.h
@@ -0,0 +1,86 @@
+//===--- MemoryTree.h - A special tree for components and sizes -*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_SUPPORT_MEMORYTREE_H_
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_SUPPORT_MEMORYTREE_H_
+
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Allocator.h"
+#include "llvm/Support/StringSaver.h"
+#include 
+#include 
+#include 
+
+namespace clang {
+namespace clangd {
+
+/// A tree that can be used to represent memory usage of nested components while
+/// preserving the hierarchy.
+/// Edges have associated names. An edge that might not be interesting to all
+/// traversers or costly to copy (e.g. file names) can be marked as "detail".
+/// Tree construc

[clang-tools-extra] 23a5330 - [clangd] Introduce memory usage dumping to TUScheduler, for Preambles and ASTCache

2020-10-12 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2020-10-12T15:25:29+02:00
New Revision: 23a53301c545b45a6c809cc3f444c5f4e577f6c0

URL: 
https://github.com/llvm/llvm-project/commit/23a53301c545b45a6c809cc3f444c5f4e577f6c0
DIFF: 
https://github.com/llvm/llvm-project/commit/23a53301c545b45a6c809cc3f444c5f4e577f6c0.diff

LOG: [clangd] Introduce memory usage dumping to TUScheduler, for Preambles and 
ASTCache

File-granular information is considered details.

Depends on D88411

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

Added: 


Modified: 
clang-tools-extra/clangd/TUScheduler.cpp
clang-tools-extra/clangd/TUScheduler.h
clang-tools-extra/clangd/unittests/ClangdTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/TUScheduler.cpp 
b/clang-tools-extra/clangd/TUScheduler.cpp
index c408c8c0731d..baf3f910b45e 100644
--- a/clang-tools-extra/clangd/TUScheduler.cpp
+++ b/clang-tools-extra/clangd/TUScheduler.cpp
@@ -56,6 +56,7 @@
 #include "support/Cancellation.h"
 #include "support/Context.h"
 #include "support/Logger.h"
+#include "support/MemoryTree.h"
 #include "support/Path.h"
 #include "support/Threading.h"
 #include "support/Trace.h"
@@ -932,9 +933,9 @@ TUScheduler::FileStats ASTWorker::stats() const {
   // Note that we don't report the size of ASTs currently used for processing
   // the in-flight requests. We used this information for debugging purposes
   // only, so this should be fine.
-  Result.UsedBytes = IdleASTs.getUsedBytes(this);
+  Result.UsedBytesAST = IdleASTs.getUsedBytes(this);
   if (auto Preamble = getPossiblyStalePreamble())
-Result.UsedBytes += Preamble->Preamble.getSize();
+Result.UsedBytesPreamble = Preamble->Preamble.getSize();
   return Result;
 }
 
@@ -1429,5 +1430,14 @@ DebouncePolicy DebouncePolicy::fixed(clock::duration T) {
   return P;
 }
 
+void TUScheduler::profile(MemoryTree &MT) const {
+  for (const auto &Elem : fileStats()) {
+MT.detail(Elem.first())
+.child("preamble")
+.addUsage(Opts.StorePreamblesInMemory ? Elem.second.UsedBytesPreamble
+  : 0);
+MT.detail(Elem.first()).child("ast").addUsage(Elem.second.UsedBytesAST);
+  }
+}
 } // namespace clangd
 } // namespace clang

diff  --git a/clang-tools-extra/clangd/TUScheduler.h 
b/clang-tools-extra/clangd/TUScheduler.h
index 5d545b366ec3..cc38db8071ab 100644
--- a/clang-tools-extra/clangd/TUScheduler.h
+++ b/clang-tools-extra/clangd/TUScheduler.h
@@ -14,6 +14,7 @@
 #include "GlobalCompilationDatabase.h"
 #include "index/CanonicalIncludes.h"
 #include "support/Function.h"
+#include "support/MemoryTree.h"
 #include "support/Path.h"
 #include "support/Threading.h"
 #include "llvm/ADT/Optional.h"
@@ -207,7 +208,8 @@ class TUScheduler {
   ~TUScheduler();
 
   struct FileStats {
-std::size_t UsedBytes = 0;
+std::size_t UsedBytesAST = 0;
+std::size_t UsedBytesPreamble = 0;
 unsigned PreambleBuilds = 0;
 unsigned ASTBuilds = 0;
   };
@@ -311,6 +313,8 @@ class TUScheduler {
   // FIXME: move to ClangdServer via createProcessingContext.
   static llvm::Optional getFileBeingProcessedInContext();
 
+  void profile(MemoryTree &MT) const;
+
 private:
   const GlobalCompilationDatabase &CDB;
   Options Opts;

diff  --git a/clang-tools-extra/clangd/unittests/ClangdTests.cpp 
b/clang-tools-extra/clangd/unittests/ClangdTests.cpp
index 813b95aa3c82..b047759faa47 100644
--- a/clang-tools-extra/clangd/unittests/ClangdTests.cpp
+++ b/clang-tools-extra/clangd/unittests/ClangdTests.cpp
@@ -565,7 +565,9 @@ int hello;
 }
 
 MATCHER_P4(Stats, Name, UsesMemory, PreambleBuilds, ASTBuilds, "") {
-  return arg.first() == Name && (arg.second.UsedBytes != 0) == UsesMemory &&
+  return arg.first() == Name &&
+ (arg.second.UsedBytesAST + arg.second.UsedBytesPreamble != 0) ==
+ UsesMemory &&
  std::tie(arg.second.PreambleBuilds, ASTBuilds) ==
  std::tie(PreambleBuilds, ASTBuilds);
 }



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


[clang-tools-extra] f9317f7 - [clangd] Introduce MemoryTrees

2020-10-12 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2020-10-12T15:25:29+02:00
New Revision: f9317f7bf6bdac10d6f8a1c106ef8d489da7efbf

URL: 
https://github.com/llvm/llvm-project/commit/f9317f7bf6bdac10d6f8a1c106ef8d489da7efbf
DIFF: 
https://github.com/llvm/llvm-project/commit/f9317f7bf6bdac10d6f8a1c106ef8d489da7efbf.diff

LOG: [clangd] Introduce MemoryTrees

A structure that can be used to represent memory usage of a nested
set of systems.

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

Added: 
clang-tools-extra/clangd/support/MemoryTree.cpp
clang-tools-extra/clangd/support/MemoryTree.h
clang-tools-extra/clangd/unittests/support/MemoryTreeTests.cpp

Modified: 
clang-tools-extra/clangd/support/CMakeLists.txt
clang-tools-extra/clangd/unittests/CMakeLists.txt

Removed: 




diff  --git a/clang-tools-extra/clangd/support/CMakeLists.txt 
b/clang-tools-extra/clangd/support/CMakeLists.txt
index ce08f7d58cd0..e3412447142c 100644
--- a/clang-tools-extra/clangd/support/CMakeLists.txt
+++ b/clang-tools-extra/clangd/support/CMakeLists.txt
@@ -21,6 +21,7 @@ add_clang_library(clangdSupport
   Context.cpp
   Logger.cpp
   Markup.cpp
+  MemoryTree.cpp
   Shutdown.cpp
   Threading.cpp
   ThreadsafeFS.cpp

diff  --git a/clang-tools-extra/clangd/support/MemoryTree.cpp 
b/clang-tools-extra/clangd/support/MemoryTree.cpp
new file mode 100644
index ..d7acf7b3d8c0
--- /dev/null
+++ b/clang-tools-extra/clangd/support/MemoryTree.cpp
@@ -0,0 +1,26 @@
+#include "support/MemoryTree.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringRef.h"
+#include 
+
+namespace clang {
+namespace clangd {
+
+MemoryTree &MemoryTree::createChild(llvm::StringRef Name) {
+  auto &Child = Children.try_emplace(Name, DetailAlloc).first->getSecond();
+  return Child;
+}
+
+const llvm::DenseMap &
+MemoryTree::children() const {
+  return Children;
+}
+
+size_t MemoryTree::total() const {
+  size_t Total = Size;
+  for (const auto &Entry : Children)
+Total += Entry.getSecond().total();
+  return Total;
+}
+} // namespace clangd
+} // namespace clang

diff  --git a/clang-tools-extra/clangd/support/MemoryTree.h 
b/clang-tools-extra/clangd/support/MemoryTree.h
new file mode 100644
index ..9cb7be5e04fd
--- /dev/null
+++ b/clang-tools-extra/clangd/support/MemoryTree.h
@@ -0,0 +1,86 @@
+//===--- MemoryTree.h - A special tree for components and sizes -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_SUPPORT_MEMORYTREE_H_
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_SUPPORT_MEMORYTREE_H_
+
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Allocator.h"
+#include "llvm/Support/StringSaver.h"
+#include 
+#include 
+#include 
+
+namespace clang {
+namespace clangd {
+
+/// A tree that can be used to represent memory usage of nested components 
while
+/// preserving the hierarchy.
+/// Edges have associated names. An edge that might not be interesting to all
+/// traversers or costly to copy (e.g. file names) can be marked as "detail".
+/// Tree construction allows chosing between a detailed and brief mode, in 
brief
+/// mode all "detail" edges are ignored and tree is constructed without any
+/// string copies.
+struct MemoryTree {
+public:
+  /// If Alloc is nullptr, tree is in brief mode and will ignore detail edges.
+  MemoryTree(llvm::BumpPtrAllocator *DetailAlloc = nullptr)
+  : DetailAlloc(DetailAlloc) {}
+
+  /// No copy of the \p Name.
+  /// Note that returned pointers are invalidated with subsequent calls to
+  /// child/detail.
+  MemoryTree &child(llvm::StringLiteral Name) { return createChild(Name); }
+
+  MemoryTree(const MemoryTree &) = delete;
+  MemoryTree &operator=(const MemoryTree &) = delete;
+
+  MemoryTree(MemoryTree &&) = default;
+  MemoryTree &operator=(MemoryTree &&) = default;
+
+  /// Makes a copy of the \p Name in detailed mode, returns current node
+  /// otherwise.
+  /// Note that returned pointers are invalidated with subsequent calls to
+  /// child/detail.
+  MemoryTree &detail(llvm::StringRef Name) {
+return DetailAlloc ? createChild(Name.copy(*DetailAlloc)) : *this;
+  }
+
+  /// Increases size of current node by \p Increment.
+  void addUsage(size_t Increment) { Size += Increment; }
+
+  /// Returns edges to direct children of this node.
+  const llvm::DenseMap &children() const;
+
+  /// Returns total number of bytes used by this sub-tree. Performs a 
traversal.
+  size_t total() const;
+
+  /// Returns total number of bytes used by this node only.
+  size_t self() const { return Size; }
+
+private:
+  /// Adds a child with an edge la

[clang-tools-extra] c9d2876 - [clangd] Add a metric for tracking memory usage

2020-10-12 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2020-10-12T15:25:29+02:00
New Revision: c9d2876da95c5a15c85de8473a0cb5fb44eb3289

URL: 
https://github.com/llvm/llvm-project/commit/c9d2876da95c5a15c85de8473a0cb5fb44eb3289
DIFF: 
https://github.com/llvm/llvm-project/commit/c9d2876da95c5a15c85de8473a0cb5fb44eb3289.diff

LOG: [clangd] Add a metric for tracking memory usage

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

Added: 


Modified: 
clang-tools-extra/clangd/support/MemoryTree.cpp
clang-tools-extra/clangd/support/MemoryTree.h
clang-tools-extra/clangd/unittests/support/MemoryTreeTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/support/MemoryTree.cpp 
b/clang-tools-extra/clangd/support/MemoryTree.cpp
index d7acf7b3d8c0..a495778b9e5b 100644
--- a/clang-tools-extra/clangd/support/MemoryTree.cpp
+++ b/clang-tools-extra/clangd/support/MemoryTree.cpp
@@ -1,4 +1,5 @@
 #include "support/MemoryTree.h"
+#include "Trace.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include 
@@ -6,6 +7,25 @@
 namespace clang {
 namespace clangd {
 
+namespace {
+
+size_t traverseTree(const MemoryTree &MT, std::string &ComponentName,
+const trace::Metric &Out) {
+  size_t OriginalLen = ComponentName.size();
+  if (!ComponentName.empty())
+ComponentName += '.';
+  size_t Total = MT.self();
+  for (const auto &Entry : MT.children()) {
+ComponentName += Entry.first;
+Total += traverseTree(Entry.getSecond(), ComponentName, Out);
+ComponentName.resize(OriginalLen + 1);
+  }
+  ComponentName.resize(OriginalLen);
+  Out.record(Total, ComponentName);
+  return Total;
+}
+} // namespace
+
 MemoryTree &MemoryTree::createChild(llvm::StringRef Name) {
   auto &Child = Children.try_emplace(Name, DetailAlloc).first->getSecond();
   return Child;
@@ -22,5 +42,10 @@ size_t MemoryTree::total() const {
 Total += Entry.getSecond().total();
   return Total;
 }
+
+void record(const MemoryTree &MT, std::string RootName,
+const trace::Metric &Out) {
+  traverseTree(MT, RootName, Out);
+}
 } // namespace clangd
 } // namespace clang

diff  --git a/clang-tools-extra/clangd/support/MemoryTree.h 
b/clang-tools-extra/clangd/support/MemoryTree.h
index 9cb7be5e04fd..903cd64ebb7c 100644
--- a/clang-tools-extra/clangd/support/MemoryTree.h
+++ b/clang-tools-extra/clangd/support/MemoryTree.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_SUPPORT_MEMORYTREE_H_
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_SUPPORT_MEMORYTREE_H_
 
+#include "Trace.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringRef.h"
@@ -80,6 +81,11 @@ struct MemoryTree {
   llvm::DenseMap Children;
 };
 
+/// Records total memory usage of each node under \p Out. Labels are edges on
+/// the path joined with ".", starting with \p RootName.
+void record(const MemoryTree &MT, std::string RootName,
+const trace::Metric &Out);
+
 } // namespace clangd
 } // namespace clang
 

diff  --git a/clang-tools-extra/clangd/unittests/support/MemoryTreeTests.cpp 
b/clang-tools-extra/clangd/unittests/support/MemoryTreeTests.cpp
index 72095f04fc68..7d3d29a9e1dd 100644
--- a/clang-tools-extra/clangd/unittests/support/MemoryTreeTests.cpp
+++ b/clang-tools-extra/clangd/unittests/support/MemoryTreeTests.cpp
@@ -7,6 +7,8 @@
 
//===--===//
 
 #include "support/MemoryTree.h"
+#include "support/TestTracer.h"
+#include "support/Trace.h"
 #include "llvm/Support/Allocator.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
@@ -16,6 +18,7 @@ namespace clang {
 namespace clangd {
 namespace {
 using testing::Contains;
+using testing::ElementsAre;
 using testing::IsEmpty;
 using testing::UnorderedElementsAre;
 
@@ -73,6 +76,46 @@ TEST(MemoryTree, DetailedNodesWithDetails) {
 EXPECT_THAT(Detail.children(), Contains(WithNameAndSize("leaf", 1)));
   }
 }
+
+TEST(MemoryTree, Record) {
+  trace::TestTracer Tracer;
+  static constexpr llvm::StringLiteral MetricName = "memory_usage";
+  static constexpr trace::Metric OutMetric(MetricName, trace::Metric::Value,
+   "component_name");
+  auto AddNodes = [](MemoryTree Root) {
+Root.child("leaf").addUsage(1);
+
+{
+  auto &Detail = Root.detail("detail");
+  Detail.addUsage(1);
+  Detail.child("leaf").addUsage(1);
+  auto &Child = Detail.child("child");
+  Child.addUsage(1);
+  Child.child("leaf").addUsage(1);
+}
+
+{
+  auto &Child = Root.child("child");
+  Child.addUsage(1);
+  Child.child("leaf").addUsage(1);
+}
+return Root;
+  };
+
+  llvm::BumpPtrAllocator Alloc;
+  record(AddNodes(MemoryTree(&Alloc)), "root", OutMetric);
+  EXPECT_THAT(Tracer.takeMetric(MetricName, "root"), ElementsAre(7));
+  EXPECT_THAT(Tracer.takeMetric(MetricName, "root.leaf"), ElementsAre(1));
+  EXPECT_TH

[clang-tools-extra] a74d594 - [clangd] Introduce memory dumping to FileIndex, FileSymbols and BackgroundIndex

2020-10-12 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2020-10-12T15:25:29+02:00
New Revision: a74d594948611164f88a79ca0544721183a0b19c

URL: 
https://github.com/llvm/llvm-project/commit/a74d594948611164f88a79ca0544721183a0b19c
DIFF: 
https://github.com/llvm/llvm-project/commit/a74d594948611164f88a79ca0544721183a0b19c.diff

LOG: [clangd] Introduce memory dumping to FileIndex, FileSymbols and 
BackgroundIndex

File-granular information is considered details.

Depends on D88411

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

Added: 


Modified: 
clang-tools-extra/clangd/index/Background.cpp
clang-tools-extra/clangd/index/Background.h
clang-tools-extra/clangd/index/FileIndex.cpp
clang-tools-extra/clangd/index/FileIndex.h
clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
clang-tools-extra/clangd/unittests/FileIndexTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/index/Background.cpp 
b/clang-tools-extra/clangd/index/Background.cpp
index a1aafeaf31a9..4779cb8d4c23 100644
--- a/clang-tools-extra/clangd/index/Background.cpp
+++ b/clang-tools-extra/clangd/index/Background.cpp
@@ -16,6 +16,7 @@
 #include "URI.h"
 #include "index/BackgroundIndexLoader.h"
 #include "index/FileIndex.h"
+#include "index/Index.h"
 #include "index/IndexAction.h"
 #include "index/MemIndex.h"
 #include "index/Ref.h"
@@ -414,5 +415,10 @@ BackgroundIndex::loadProject(std::vector 
MainFiles) {
   return {TUsToIndex.begin(), TUsToIndex.end()};
 }
 
+void BackgroundIndex::profile(MemoryTree &MT) const {
+  IndexedSymbols.profile(MT.child("symbols"));
+  // We don't want to mix memory used by index and symbols, so call base class.
+  MT.child("index").addUsage(SwapIndex::estimateMemoryUsage());
+}
 } // namespace clangd
 } // namespace clang

diff  --git a/clang-tools-extra/clangd/index/Background.h 
b/clang-tools-extra/clangd/index/Background.h
index 472603013a53..e8f9468889f2 100644
--- a/clang-tools-extra/clangd/index/Background.h
+++ b/clang-tools-extra/clangd/index/Background.h
@@ -16,9 +16,11 @@
 #include "index/Index.h"
 #include "index/Serialization.h"
 #include "support/Context.h"
+#include "support/MemoryTree.h"
 #include "support/Path.h"
 #include "support/Threading.h"
 #include "support/ThreadsafeFS.h"
+#include "support/Trace.h"
 #include "clang/Tooling/CompilationDatabase.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/Support/Threading.h"
@@ -172,6 +174,8 @@ class BackgroundIndex : public SwapIndex {
 return Queue.blockUntilIdleForTest(TimeoutSeconds);
   }
 
+  void profile(MemoryTree &MT) const;
+
 private:
   /// Represents the state of a single file when indexing was performed.
   struct ShardVersion {

diff  --git a/clang-tools-extra/clangd/index/FileIndex.cpp 
b/clang-tools-extra/clangd/index/FileIndex.cpp
index ad55b6ad7f5d..587c7eb78170 100644
--- a/clang-tools-extra/clangd/index/FileIndex.cpp
+++ b/clang-tools-extra/clangd/index/FileIndex.cpp
@@ -22,6 +22,7 @@
 #include "index/SymbolOrigin.h"
 #include "index/dex/Dex.h"
 #include "support/Logger.h"
+#include "support/MemoryTree.h"
 #include "support/Path.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/Index/IndexingAction.h"
@@ -388,6 +389,25 @@ FileSymbols::buildIndex(IndexType Type, DuplicateHandling 
DuplicateHandle,
   llvm_unreachable("Unknown clangd::IndexType");
 }
 
+void FileSymbols::profile(MemoryTree &MT) const {
+  std::lock_guard Lock(Mutex);
+  for (const auto &SymSlab : SymbolsSnapshot) {
+MT.detail(SymSlab.first())
+.child("symbols")
+.addUsage(SymSlab.second->bytes());
+  }
+  for (const auto &RefSlab : RefsSnapshot) {
+MT.detail(RefSlab.first())
+.child("references")
+.addUsage(RefSlab.second.Slab->bytes());
+  }
+  for (const auto &RelSlab : RelationsSnapshot) {
+MT.detail(RelSlab.first())
+.child("relations")
+.addUsage(RelSlab.second->bytes());
+  }
+}
+
 FileIndex::FileIndex(bool UseDex, bool CollectMainFileRefs)
 : MergedIndex(&MainFileIndex, &PreambleIndex), UseDex(UseDex),
   CollectMainFileRefs(CollectMainFileRefs),
@@ -457,5 +477,15 @@ void FileIndex::updateMain(PathRef Path, ParsedAST &AST) {
   }
 }
 
+void FileIndex::profile(MemoryTree &MT) const {
+  PreambleSymbols.profile(MT.child("preamble").child("symbols"));
+  MT.child("preamble")
+  .child("index")
+  .addUsage(PreambleIndex.estimateMemoryUsage());
+  MainFileSymbols.profile(MT.child("main_file").child("symbols"));
+  MT.child("main_file")
+  .child("index")
+  .addUsage(MainFileIndex.estimateMemoryUsage());
+}
 } // namespace clangd
 } // namespace clang

diff  --git a/clang-tools-extra/clangd/index/FileIndex.h 
b/clang-tools-extra/clangd/index/FileIndex.h
index 127203c84c48..8ecae66373a5 100644
--- a/clang-tools-extra/clangd/index/FileIndex.h
+++ b/clang-tools-extra/clangd/index/FileIndex.h
@@ -24,6 +24,7 @@
 #include "index/Relation.h"
 #include "index/Serializatio

[clang-tools-extra] 20f69cc - [clangd] Add a helper for exposing tracer status

2020-10-12 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2020-10-12T15:25:29+02:00
New Revision: 20f69ccfe64aeab9c32d1698df399bd864dda8b1

URL: 
https://github.com/llvm/llvm-project/commit/20f69ccfe64aeab9c32d1698df399bd864dda8b1
DIFF: 
https://github.com/llvm/llvm-project/commit/20f69ccfe64aeab9c32d1698df399bd864dda8b1.diff

LOG: [clangd] Add a helper for exposing tracer status

Added: 


Modified: 
clang-tools-extra/clangd/support/Trace.cpp
clang-tools-extra/clangd/support/Trace.h

Removed: 




diff  --git a/clang-tools-extra/clangd/support/Trace.cpp 
b/clang-tools-extra/clangd/support/Trace.cpp
index 89d65e686ebc..d69b1c2bbde5 100644
--- a/clang-tools-extra/clangd/support/Trace.cpp
+++ b/clang-tools-extra/clangd/support/Trace.cpp
@@ -281,6 +281,8 @@ void log(const llvm::Twine &Message) {
   T->instant("Log", llvm::json::Object{{"Message", Message.str()}});
 }
 
+bool enabled() { return T != nullptr; }
+
 // The JSON object is event args (owned by context), if the tracer wants them.
 static std::pair
 makeSpanContext(llvm::Twine Name, const Metric &LatencyMetric) {

diff  --git a/clang-tools-extra/clangd/support/Trace.h 
b/clang-tools-extra/clangd/support/Trace.h
index 7bcfbef7aad2..52ee2ae617da 100644
--- a/clang-tools-extra/clangd/support/Trace.h
+++ b/clang-tools-extra/clangd/support/Trace.h
@@ -128,6 +128,9 @@ std::unique_ptr 
createCSVMetricTracer(llvm::raw_ostream &OS);
 /// Records a single instant event, associated with the current thread.
 void log(const llvm::Twine &Name);
 
+/// Returns true if there is an active tracer.
+bool enabled();
+
 /// Records an event whose duration is the lifetime of the Span object.
 /// This lifetime is extended when the span's context is reused.
 ///



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


[clang-tools-extra] 35871fd - [clangd] Record memory usages after each notification

2020-10-12 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2020-10-12T15:25:29+02:00
New Revision: 35871fde55ac98b543edd2e7c62d1456a26562d8

URL: 
https://github.com/llvm/llvm-project/commit/35871fde55ac98b543edd2e7c62d1456a26562d8
DIFF: 
https://github.com/llvm/llvm-project/commit/35871fde55ac98b543edd2e7c62d1456a26562d8.diff

LOG: [clangd] Record memory usages after each notification

Depends on D88415

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

Added: 


Modified: 
clang-tools-extra/clangd/ClangdLSPServer.cpp
clang-tools-extra/clangd/ClangdLSPServer.h
clang-tools-extra/clangd/ClangdServer.cpp
clang-tools-extra/clangd/ClangdServer.h
clang-tools-extra/clangd/unittests/ClangdTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp 
b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index 01f962ad5b48..d46147ac89cd 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "ClangdLSPServer.h"
+#include "ClangdServer.h"
 #include "CodeComplete.h"
 #include "Diagnostics.h"
 #include "DraftStore.h"
@@ -18,6 +19,7 @@
 #include "URI.h"
 #include "refactor/Tweak.h"
 #include "support/Context.h"
+#include "support/MemoryTree.h"
 #include "support/Trace.h"
 #include "clang/Basic/Version.h"
 #include "clang/Tooling/Core/Replacement.h"
@@ -26,6 +28,7 @@
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/iterator_range.h"
+#include "llvm/Support/Allocator.h"
 #include "llvm/Support/Errc.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/FormatVariadic.h"
@@ -33,6 +36,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/SHA1.h"
 #include "llvm/Support/ScopedPrinter.h"
+#include 
 #include 
 #include 
 #include 
@@ -144,7 +148,6 @@ llvm::Error validateEdits(const DraftStore &DraftMgr, const 
FileEdits &FE) {
   return error("Files must be saved first: {0} (and {1} others)",
LastInvalidFile, InvalidFileCount - 1);
 }
-
 } // namespace
 
 // MessageHandler dispatches incoming LSP messages.
@@ -163,14 +166,16 @@ class ClangdLSPServer::MessageHandler : public 
Transport::MessageHandler {
 log("<-- {0}", Method);
 if (Method == "exit")
   return false;
-if (!Server.Server)
+if (!Server.Server) {
   elog("Notification {0} before initialization", Method);
-else if (Method == "$/cancelRequest")
+} else if (Method == "$/cancelRequest") {
   onCancel(std::move(Params));
-else if (auto Handler = Notifications.lookup(Method))
+} else if (auto Handler = Notifications.lookup(Method)) {
   Handler(std::move(Params));
-else
+  Server.maybeExportMemoryProfile();
+} else {
   log("unhandled notification {0}", Method);
+}
 return true;
   }
 
@@ -1234,6 +1239,25 @@ void ClangdLSPServer::publishDiagnostics(
   notify("textDocument/publishDiagnostics", Params);
 }
 
+void ClangdLSPServer::maybeExportMemoryProfile() {
+  if (!trace::enabled())
+return;
+  // Profiling might be expensive, so we throttle it to happen once every 5
+  // minutes.
+  static constexpr auto ProfileInterval = std::chrono::minutes(5);
+  auto Now = std::chrono::steady_clock::now();
+  if (Now < NextProfileTime)
+return;
+
+  static constexpr trace::Metric MemoryUsage(
+  "memory_usage", trace::Metric::Value, "component_name");
+  trace::Span Tracer("ProfileBrief");
+  MemoryTree MT;
+  profile(MT);
+  record(MT, "clangd_lsp_server", MemoryUsage);
+  NextProfileTime = Now + ProfileInterval;
+}
+
 // FIXME: This function needs to be properly tested.
 void ClangdLSPServer::onChangeConfiguration(
 const DidChangeConfigurationParams &Params) {
@@ -1404,6 +1428,9 @@ ClangdLSPServer::ClangdLSPServer(class Transport &Transp,
   if (Opts.FoldingRanges)
 MsgHandler->bind("textDocument/foldingRange", 
&ClangdLSPServer::onFoldingRange);
   // clang-format on
+
+  // Delay first profile until we've finished warming up.
+  NextProfileTime = std::chrono::steady_clock::now() + std::chrono::minutes(1);
 }
 
 ClangdLSPServer::~ClangdLSPServer() {
@@ -1424,6 +1451,11 @@ bool ClangdLSPServer::run() {
   return CleanExit && ShutdownRequestReceived;
 }
 
+void ClangdLSPServer::profile(MemoryTree &MT) const {
+  if (Server)
+Server->profile(MT.child("clangd_server"));
+}
+
 std::vector ClangdLSPServer::getFixes(llvm::StringRef File,
const clangd::Diagnostic &D) {
   std::lock_guard Lock(FixItsMutex);

diff  --git a/clang-tools-extra/clangd/ClangdLSPServer.h 
b/clang-tools-extra/clangd/ClangdLSPServer.h
index a853a4087156..7054c48652c5 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.h
+++ b/clang-tools-extra/clangd/ClangdLSPServer.h
@@ -17,11 +17,13 @@
 #include "Protocol.h"
 #include "Transport.h"
 #include 

[PATCH] D88414: [clangd] Introduce memory dumping to FileIndex, FileSymbols and BackgroundIndex

2020-10-12 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa74d59494861: [clangd] Introduce memory dumping to 
FileIndex, FileSymbols and BackgroundIndex (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88414/new/

https://reviews.llvm.org/D88414

Files:
  clang-tools-extra/clangd/index/Background.cpp
  clang-tools-extra/clangd/index/Background.h
  clang-tools-extra/clangd/index/FileIndex.cpp
  clang-tools-extra/clangd/index/FileIndex.h
  clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
  clang-tools-extra/clangd/unittests/FileIndexTests.cpp

Index: clang-tools-extra/clangd/unittests/FileIndexTests.cpp
===
--- clang-tools-extra/clangd/unittests/FileIndexTests.cpp
+++ clang-tools-extra/clangd/unittests/FileIndexTests.cpp
@@ -22,20 +22,25 @@
 #include "index/Relation.h"
 #include "index/Serialization.h"
 #include "index/Symbol.h"
+#include "index/SymbolID.h"
 #include "support/Threading.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Frontend/Utils.h"
 #include "clang/Index/IndexSymbol.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Tooling/CompilationDatabase.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/Support/Allocator.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
+#include 
 
 using ::testing::_;
 using ::testing::AllOf;
 using ::testing::Contains;
 using ::testing::ElementsAre;
+using ::testing::Gt;
 using ::testing::IsEmpty;
 using ::testing::Pair;
 using ::testing::UnorderedElementsAre;
@@ -88,6 +93,13 @@
   return std::make_unique(std::move(Slab).build());
 }
 
+std::unique_ptr relSlab(llvm::ArrayRef Rels) {
+  RelationSlab::Builder RelBuilder;
+  for (auto &Rel : Rels)
+RelBuilder.insert(Rel);
+  return std::make_unique(std::move(RelBuilder).build());
+}
+
 TEST(FileSymbolsTest, UpdateAndGet) {
   FileSymbols FS;
   EXPECT_THAT(runFuzzyFind(*FS.buildIndex(IndexType::Light), ""), IsEmpty());
@@ -643,6 +655,50 @@
 EXPECT_TRUE(Shard->Cmd.hasValue());
   }
 }
+
+TEST(FileIndexTest, Profile) {
+  FileIndex FI;
+
+  auto FileName = testPath("foo.cpp");
+  auto AST = TestTU::withHeaderCode("int a;").build();
+  FI.updateMain(FileName, AST);
+  FI.updatePreamble(FileName, "v1", AST.getASTContext(),
+AST.getPreprocessorPtr(), AST.getCanonicalIncludes());
+
+  llvm::BumpPtrAllocator Alloc;
+  MemoryTree MT(&Alloc);
+  FI.profile(MT);
+  ASSERT_THAT(MT.children(),
+  UnorderedElementsAre(Pair("preamble", _), Pair("main_file", _)));
+
+  ASSERT_THAT(MT.child("preamble").children(),
+  UnorderedElementsAre(Pair("index", _), Pair("symbols", _)));
+  ASSERT_THAT(MT.child("main_file").children(),
+  UnorderedElementsAre(Pair("index", _), Pair("symbols", _)));
+
+  ASSERT_THAT(MT.child("preamble").child("index").total(), Gt(0U));
+  ASSERT_THAT(MT.child("main_file").child("index").total(), Gt(0U));
+}
+
+TEST(FileSymbolsTest, Profile) {
+  FileSymbols FS;
+  FS.update("f1", numSlab(1, 2), nullptr, nullptr, false);
+  FS.update("f2", nullptr, refSlab(SymbolID("1"), "f1"), nullptr, false);
+  FS.update("f3", nullptr, nullptr,
+relSlab({{SymbolID("1"), RelationKind::BaseOf, SymbolID("2")}}),
+false);
+  llvm::BumpPtrAllocator Alloc;
+  MemoryTree MT(&Alloc);
+  FS.profile(MT);
+  ASSERT_THAT(MT.children(), UnorderedElementsAre(Pair("f1", _), Pair("f2", _),
+  Pair("f3", _)));
+  EXPECT_THAT(MT.child("f1").children(), ElementsAre(Pair("symbols", _)));
+  EXPECT_THAT(MT.child("f1").total(), Gt(0U));
+  EXPECT_THAT(MT.child("f2").children(), ElementsAre(Pair("references", _)));
+  EXPECT_THAT(MT.child("f2").total(), Gt(0U));
+  EXPECT_THAT(MT.child("f3").children(), ElementsAre(Pair("relations", _)));
+  EXPECT_THAT(MT.child("f3").total(), Gt(0U));
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
===
--- clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
+++ clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
@@ -21,6 +21,7 @@
 using ::testing::Contains;
 using ::testing::ElementsAre;
 using ::testing::Not;
+using ::testing::Pair;
 using ::testing::UnorderedElementsAre;
 
 namespace clang {
@@ -916,5 +917,18 @@
   EXPECT_EQ(S.LastIdle, 2000u);
 }
 
+TEST(BackgroundIndex, Profile) {
+  MockFS FS;
+  MockCompilationDatabase CDB;
+  BackgroundIndex Idx(FS, CDB, [](llvm::StringRef) { return nullptr; },
+  /*Opts=*/{});
+
+  llvm::BumpPtrAllocator Alloc;
+  MemoryTree MT(&Alloc);
+  Idx.profile(MT);
+  ASSERT_THAT(MT.children(),
+  UnorderedElementsAre(Pair("symbols", _), Pair("index", _)));
+}
+
 } // namespace clangd

[PATCH] D88413: [clangd] Add a metric for tracking memory usage

2020-10-12 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc9d2876da95c: [clangd] Add a metric for tracking memory 
usage (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88413/new/

https://reviews.llvm.org/D88413

Files:
  clang-tools-extra/clangd/support/MemoryTree.cpp
  clang-tools-extra/clangd/support/MemoryTree.h
  clang-tools-extra/clangd/unittests/support/MemoryTreeTests.cpp

Index: clang-tools-extra/clangd/unittests/support/MemoryTreeTests.cpp
===
--- clang-tools-extra/clangd/unittests/support/MemoryTreeTests.cpp
+++ clang-tools-extra/clangd/unittests/support/MemoryTreeTests.cpp
@@ -7,6 +7,8 @@
 //===--===//
 
 #include "support/MemoryTree.h"
+#include "support/TestTracer.h"
+#include "support/Trace.h"
 #include "llvm/Support/Allocator.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
@@ -16,6 +18,7 @@
 namespace clangd {
 namespace {
 using testing::Contains;
+using testing::ElementsAre;
 using testing::IsEmpty;
 using testing::UnorderedElementsAre;
 
@@ -73,6 +76,46 @@
 EXPECT_THAT(Detail.children(), Contains(WithNameAndSize("leaf", 1)));
   }
 }
+
+TEST(MemoryTree, Record) {
+  trace::TestTracer Tracer;
+  static constexpr llvm::StringLiteral MetricName = "memory_usage";
+  static constexpr trace::Metric OutMetric(MetricName, trace::Metric::Value,
+   "component_name");
+  auto AddNodes = [](MemoryTree Root) {
+Root.child("leaf").addUsage(1);
+
+{
+  auto &Detail = Root.detail("detail");
+  Detail.addUsage(1);
+  Detail.child("leaf").addUsage(1);
+  auto &Child = Detail.child("child");
+  Child.addUsage(1);
+  Child.child("leaf").addUsage(1);
+}
+
+{
+  auto &Child = Root.child("child");
+  Child.addUsage(1);
+  Child.child("leaf").addUsage(1);
+}
+return Root;
+  };
+
+  llvm::BumpPtrAllocator Alloc;
+  record(AddNodes(MemoryTree(&Alloc)), "root", OutMetric);
+  EXPECT_THAT(Tracer.takeMetric(MetricName, "root"), ElementsAre(7));
+  EXPECT_THAT(Tracer.takeMetric(MetricName, "root.leaf"), ElementsAre(1));
+  EXPECT_THAT(Tracer.takeMetric(MetricName, "root.detail"), ElementsAre(4));
+  EXPECT_THAT(Tracer.takeMetric(MetricName, "root.detail.leaf"),
+  ElementsAre(1));
+  EXPECT_THAT(Tracer.takeMetric(MetricName, "root.detail.child"),
+  ElementsAre(2));
+  EXPECT_THAT(Tracer.takeMetric(MetricName, "root.detail.child.leaf"),
+  ElementsAre(1));
+  EXPECT_THAT(Tracer.takeMetric(MetricName, "root.child"), ElementsAre(2));
+  EXPECT_THAT(Tracer.takeMetric(MetricName, "root.child.leaf"), ElementsAre(1));
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/support/MemoryTree.h
===
--- clang-tools-extra/clangd/support/MemoryTree.h
+++ clang-tools-extra/clangd/support/MemoryTree.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_SUPPORT_MEMORYTREE_H_
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_SUPPORT_MEMORYTREE_H_
 
+#include "Trace.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringRef.h"
@@ -80,6 +81,11 @@
   llvm::DenseMap Children;
 };
 
+/// Records total memory usage of each node under \p Out. Labels are edges on
+/// the path joined with ".", starting with \p RootName.
+void record(const MemoryTree &MT, std::string RootName,
+const trace::Metric &Out);
+
 } // namespace clangd
 } // namespace clang
 
Index: clang-tools-extra/clangd/support/MemoryTree.cpp
===
--- clang-tools-extra/clangd/support/MemoryTree.cpp
+++ clang-tools-extra/clangd/support/MemoryTree.cpp
@@ -1,4 +1,5 @@
 #include "support/MemoryTree.h"
+#include "Trace.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include 
@@ -6,6 +7,25 @@
 namespace clang {
 namespace clangd {
 
+namespace {
+
+size_t traverseTree(const MemoryTree &MT, std::string &ComponentName,
+const trace::Metric &Out) {
+  size_t OriginalLen = ComponentName.size();
+  if (!ComponentName.empty())
+ComponentName += '.';
+  size_t Total = MT.self();
+  for (const auto &Entry : MT.children()) {
+ComponentName += Entry.first;
+Total += traverseTree(Entry.getSecond(), ComponentName, Out);
+ComponentName.resize(OriginalLen + 1);
+  }
+  ComponentName.resize(OriginalLen);
+  Out.record(Total, ComponentName);
+  return Total;
+}
+} // namespace
+
 MemoryTree &MemoryTree::createChild(llvm::StringRef Name) {
   auto &Child = Children.try_emplace(Name, DetailAlloc).first->getSecond();
   return Child;
@@ -22,5 +42,10 @@
 Total += Entry.getSecond().total();
   return

[PATCH] D88417: [clangd] Record memory usages after each notification

2020-10-12 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG35871fde55ac: [clangd] Record memory usages after each 
notification (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88417/new/

https://reviews.llvm.org/D88417

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/unittests/ClangdTests.cpp

Index: clang-tools-extra/clangd/unittests/ClangdTests.cpp
===
--- clang-tools-extra/clangd/unittests/ClangdTests.cpp
+++ clang-tools-extra/clangd/unittests/ClangdTests.cpp
@@ -17,6 +17,7 @@
 #include "TestFS.h"
 #include "TestTU.h"
 #include "URI.h"
+#include "support/MemoryTree.h"
 #include "support/Path.h"
 #include "support/Threading.h"
 #include "clang/Config/config.h"
@@ -27,6 +28,7 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Allocator.h"
 #include "llvm/Support/Errc.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Regex.h"
@@ -48,6 +50,7 @@
 namespace {
 
 using ::testing::AllOf;
+using ::testing::Contains;
 using ::testing::ElementsAre;
 using ::testing::Field;
 using ::testing::Gt;
@@ -1236,6 +1239,21 @@
   EXPECT_FALSE(DiagConsumer.HadDiagsInLastCallback);
 }
 
+TEST(ClangdServer, MemoryUsageTest) {
+  MockFS FS;
+  MockCompilationDatabase CDB;
+  ClangdServer Server(CDB, FS, ClangdServer::optsForTest());
+
+  auto FooCpp = testPath("foo.cpp");
+  Server.addDocument(FooCpp, "");
+  ASSERT_TRUE(Server.blockUntilIdleForTest());
+
+  llvm::BumpPtrAllocator Alloc;
+  MemoryTree MT(&Alloc);
+  Server.profile(MT);
+  ASSERT_TRUE(MT.children().count("tuscheduler"));
+  EXPECT_TRUE(MT.child("tuscheduler").children().count(FooCpp));
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/ClangdServer.h
===
--- clang-tools-extra/clangd/ClangdServer.h
+++ clang-tools-extra/clangd/ClangdServer.h
@@ -25,6 +25,7 @@
 #include "refactor/Tweak.h"
 #include "support/Cancellation.h"
 #include "support/Function.h"
+#include "support/MemoryTree.h"
 #include "support/ThreadsafeFS.h"
 #include "clang/Tooling/CompilationDatabase.h"
 #include "clang/Tooling/Core/Replacement.h"
@@ -337,6 +338,9 @@
   LLVM_NODISCARD bool
   blockUntilIdleForTest(llvm::Optional TimeoutSeconds = 10);
 
+  /// Builds a nested representation of memory used by components.
+  void profile(MemoryTree &MT) const;
+
 private:
   void formatCode(PathRef File, llvm::StringRef Code,
   ArrayRef Ranges,
Index: clang-tools-extra/clangd/ClangdServer.cpp
===
--- clang-tools-extra/clangd/ClangdServer.cpp
+++ clang-tools-extra/clangd/ClangdServer.cpp
@@ -28,6 +28,7 @@
 #include "refactor/Tweak.h"
 #include "support/Logger.h"
 #include "support/Markup.h"
+#include "support/MemoryTree.h"
 #include "support/ThreadsafeFS.h"
 #include "support/Trace.h"
 #include "clang/Format/Format.h"
@@ -826,5 +827,12 @@
   BackgroundIdx->blockUntilIdleForTest(TimeoutSeconds));
 }
 
+void ClangdServer::profile(MemoryTree &MT) const {
+  if (DynamicIdx)
+DynamicIdx->profile(MT.child("dynamic_index"));
+  if (BackgroundIdx)
+BackgroundIdx->profile(MT.child("background_index"));
+  WorkScheduler.profile(MT.child("tuscheduler"));
+}
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/ClangdLSPServer.h
===
--- clang-tools-extra/clangd/ClangdLSPServer.h
+++ clang-tools-extra/clangd/ClangdLSPServer.h
@@ -17,11 +17,13 @@
 #include "Protocol.h"
 #include "Transport.h"
 #include "support/Context.h"
+#include "support/MemoryTree.h"
 #include "support/Path.h"
 #include "clang/Tooling/Core/Replacement.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/StringSet.h"
 #include "llvm/Support/JSON.h"
+#include 
 #include 
 
 namespace clang {
@@ -67,6 +69,9 @@
   /// \return Whether we shut down cleanly with a 'shutdown' -> 'exit' sequence.
   bool run();
 
+  /// Profiles resource-usage.
+  void profile(MemoryTree &MT) const;
+
 private:
   // Implement ClangdServer::Callbacks.
   void onDiagnosticsReady(PathRef File, llvm::StringRef Version,
@@ -160,6 +165,14 @@
   /// Sends a "publishDiagnostics" notification to the LSP client.
   void publishDiagnostics(const PublishDiagnosticsParams &);
 
+  /// Runs profiling and exports memory usage metrics if tracing is enabled and
+  /// profiling hasn't happened recently.
+  void maybeExportMemoryProfile();
+
+  /// Timepoint until which profiling is off. It is used to throttle profiling
+  /// request

[PATCH] D88415: [clangd] Introduce memory usage dumping to TUScheduler, for Preambles and ASTCache

2020-10-12 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG23a53301c545: [clangd] Introduce memory usage dumping to 
TUScheduler, for Preambles and… (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88415/new/

https://reviews.llvm.org/D88415

Files:
  clang-tools-extra/clangd/TUScheduler.cpp
  clang-tools-extra/clangd/TUScheduler.h
  clang-tools-extra/clangd/unittests/ClangdTests.cpp


Index: clang-tools-extra/clangd/unittests/ClangdTests.cpp
===
--- clang-tools-extra/clangd/unittests/ClangdTests.cpp
+++ clang-tools-extra/clangd/unittests/ClangdTests.cpp
@@ -565,7 +565,9 @@
 }
 
 MATCHER_P4(Stats, Name, UsesMemory, PreambleBuilds, ASTBuilds, "") {
-  return arg.first() == Name && (arg.second.UsedBytes != 0) == UsesMemory &&
+  return arg.first() == Name &&
+ (arg.second.UsedBytesAST + arg.second.UsedBytesPreamble != 0) ==
+ UsesMemory &&
  std::tie(arg.second.PreambleBuilds, ASTBuilds) ==
  std::tie(PreambleBuilds, ASTBuilds);
 }
Index: clang-tools-extra/clangd/TUScheduler.h
===
--- clang-tools-extra/clangd/TUScheduler.h
+++ clang-tools-extra/clangd/TUScheduler.h
@@ -14,6 +14,7 @@
 #include "GlobalCompilationDatabase.h"
 #include "index/CanonicalIncludes.h"
 #include "support/Function.h"
+#include "support/MemoryTree.h"
 #include "support/Path.h"
 #include "support/Threading.h"
 #include "llvm/ADT/Optional.h"
@@ -207,7 +208,8 @@
   ~TUScheduler();
 
   struct FileStats {
-std::size_t UsedBytes = 0;
+std::size_t UsedBytesAST = 0;
+std::size_t UsedBytesPreamble = 0;
 unsigned PreambleBuilds = 0;
 unsigned ASTBuilds = 0;
   };
@@ -311,6 +313,8 @@
   // FIXME: move to ClangdServer via createProcessingContext.
   static llvm::Optional getFileBeingProcessedInContext();
 
+  void profile(MemoryTree &MT) const;
+
 private:
   const GlobalCompilationDatabase &CDB;
   Options Opts;
Index: clang-tools-extra/clangd/TUScheduler.cpp
===
--- clang-tools-extra/clangd/TUScheduler.cpp
+++ clang-tools-extra/clangd/TUScheduler.cpp
@@ -56,6 +56,7 @@
 #include "support/Cancellation.h"
 #include "support/Context.h"
 #include "support/Logger.h"
+#include "support/MemoryTree.h"
 #include "support/Path.h"
 #include "support/Threading.h"
 #include "support/Trace.h"
@@ -932,9 +933,9 @@
   // Note that we don't report the size of ASTs currently used for processing
   // the in-flight requests. We used this information for debugging purposes
   // only, so this should be fine.
-  Result.UsedBytes = IdleASTs.getUsedBytes(this);
+  Result.UsedBytesAST = IdleASTs.getUsedBytes(this);
   if (auto Preamble = getPossiblyStalePreamble())
-Result.UsedBytes += Preamble->Preamble.getSize();
+Result.UsedBytesPreamble = Preamble->Preamble.getSize();
   return Result;
 }
 
@@ -1429,5 +1430,14 @@
   return P;
 }
 
+void TUScheduler::profile(MemoryTree &MT) const {
+  for (const auto &Elem : fileStats()) {
+MT.detail(Elem.first())
+.child("preamble")
+.addUsage(Opts.StorePreamblesInMemory ? Elem.second.UsedBytesPreamble
+  : 0);
+MT.detail(Elem.first()).child("ast").addUsage(Elem.second.UsedBytesAST);
+  }
+}
 } // namespace clangd
 } // namespace clang


Index: clang-tools-extra/clangd/unittests/ClangdTests.cpp
===
--- clang-tools-extra/clangd/unittests/ClangdTests.cpp
+++ clang-tools-extra/clangd/unittests/ClangdTests.cpp
@@ -565,7 +565,9 @@
 }
 
 MATCHER_P4(Stats, Name, UsesMemory, PreambleBuilds, ASTBuilds, "") {
-  return arg.first() == Name && (arg.second.UsedBytes != 0) == UsesMemory &&
+  return arg.first() == Name &&
+ (arg.second.UsedBytesAST + arg.second.UsedBytesPreamble != 0) ==
+ UsesMemory &&
  std::tie(arg.second.PreambleBuilds, ASTBuilds) ==
  std::tie(PreambleBuilds, ASTBuilds);
 }
Index: clang-tools-extra/clangd/TUScheduler.h
===
--- clang-tools-extra/clangd/TUScheduler.h
+++ clang-tools-extra/clangd/TUScheduler.h
@@ -14,6 +14,7 @@
 #include "GlobalCompilationDatabase.h"
 #include "index/CanonicalIncludes.h"
 #include "support/Function.h"
+#include "support/MemoryTree.h"
 #include "support/Path.h"
 #include "support/Threading.h"
 #include "llvm/ADT/Optional.h"
@@ -207,7 +208,8 @@
   ~TUScheduler();
 
   struct FileStats {
-std::size_t UsedBytes = 0;
+std::size_t UsedBytesAST = 0;
+std::size_t UsedBytesPreamble = 0;
 unsigned PreambleBuilds = 0;
 unsigned ASTBuilds = 0;
   };
@@ -311,6 +313,8 @@
   // FIXME: move to ClangdServer via createProcessingContext.
   static llvm

[PATCH] D88106: [SyntaxTree] Provide iterator-like functions for Lists

2020-10-12 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 297574.
eduucaldas marked 8 inline comments as done.
eduucaldas added a comment.

Answer comments, TODO: think about templated iterators


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88106/new/

https://reviews.llvm.org/D88106

Files:
  clang/include/clang/Tooling/Syntax/Tree.h
  clang/lib/Tooling/Syntax/Nodes.cpp
  clang/lib/Tooling/Syntax/Tree.cpp

Index: clang/lib/Tooling/Syntax/Tree.cpp
===
--- clang/lib/Tooling/Syntax/Tree.cpp
+++ clang/lib/Tooling/Syntax/Tree.cpp
@@ -9,6 +9,7 @@
 #include "clang/Basic/TokenKinds.h"
 #include "clang/Tooling/Syntax/Nodes.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/Casting.h"
 #include 
@@ -294,91 +295,110 @@
   }
 }
 
-std::vector>
-syntax::List::getElementsAsNodesAndDelimiters() {
-  if (!getFirstChild())
-return {};
-
-  std::vector> Children;
-  syntax::Node *ElementWithoutDelimiter = nullptr;
-  for (auto *C = getFirstChild(); C; C = C->getNextSibling()) {
-switch (C->getRole()) {
-case syntax::NodeRole::ListElement: {
-  if (ElementWithoutDelimiter) {
-Children.push_back({ElementWithoutDelimiter, nullptr});
-  }
-  ElementWithoutDelimiter = C;
-  break;
-}
-case syntax::NodeRole::ListDelimiter: {
-  Children.push_back({ElementWithoutDelimiter, cast(C)});
-  ElementWithoutDelimiter = nullptr;
-  break;
-}
-default:
-  llvm_unreachable(
-  "A list can have only elements and delimiters as children.");
-}
+syntax::List::ElementAndDelimiter
+syntax::List::getWithDelimiter(syntax::Node *Element) {
+  assert(Element && Element->getRole() == syntax::NodeRole::ListElement);
+  auto *Next = Element->getNextSibling();
+  if (!Next)
+return {Element, nullptr};
+  switch (Next->getRole()) {
+  case syntax::NodeRole::ListElement:
+return {Element, nullptr};
+  case syntax::NodeRole::ListDelimiter:
+return {Element, cast(Next)};
+  default:
+llvm_unreachable(
+"A list can have only elements and delimiters as children.");
   }
+}
 
-  switch (getTerminationKind()) {
-  case syntax::List::TerminationKind::Separated: {
-Children.push_back({ElementWithoutDelimiter, nullptr});
-break;
-  }
-  case syntax::List::TerminationKind::Terminated:
-  case syntax::List::TerminationKind::MaybeTerminated: {
-if (ElementWithoutDelimiter) {
-  Children.push_back({ElementWithoutDelimiter, nullptr});
+llvm::Optional>
+syntax::List::getElementAndDelimiterAfterDelimiter(syntax::Leaf *Delimiter) {
+  assert(Delimiter && Delimiter->getRole() == syntax::NodeRole::ListDelimiter);
+  auto *List = cast(Delimiter->getParent());
+  auto *Next = Delimiter->getNextSibling();
+  if (!Next) {
+switch (List->getTerminationKind()) {
+// List is separated and ends with delimiter
+// => missing last ElementAndDelimiter.
+case syntax::List::TerminationKind::Separated:
+  return llvm::Optional>(
+  {nullptr, nullptr});
+case syntax::List::TerminationKind::Terminated:
+case syntax::List::TerminationKind::MaybeTerminated:
+  return None;
 }
-break;
   }
+  switch (Next->getRole()) {
+  case syntax::NodeRole::ListElement:
+return getWithDelimiter(Next);
+
+  // Consecutive Delimiters => missing Element
+  case syntax::NodeRole::ListDelimiter:
+return llvm::Optional>(
+{nullptr, cast(Next)});
+  default:
+llvm_unreachable(
+"A list can have only elements and delimiters as children.");
   }
-
-  return Children;
 }
 
-// Almost the same implementation of `getElementsAsNodesAndDelimiters` but
-// ignoring delimiters
-std::vector syntax::List::getElementsAsNodes() {
-  if (!getFirstChild())
-return {};
+llvm::Optional>
+syntax::List::getElementAndDelimiterAfterElement(syntax::Node *Element) {
+  assert(Element && Element->getRole() == syntax::NodeRole::ListElement);
+  auto *Next = Element->getNextSibling();
+  if (!Next)
+// This was the last element of the list.
+return None;
+
+  switch (Next->getRole()) {
+  case syntax::NodeRole::ListElement:
+// We have something of the form "a b ..." => 'b' starts the next
+// `ElementAndDelimiter`.
+return getWithDelimiter(Next);
+
+  case syntax::NodeRole::ListDelimiter:
+// We have something of the form "a , ..." => whatever comes after the comma
+// starts the next `ElementAndDelimiter`.
+return getElementAndDelimiterAfterDelimiter(cast(Next));
 
-  std::vector Children;
-  syntax::Node *ElementWithoutDelimiter = nullptr;
-  for (auto *C = getFirstChild(); C; C = C->getNextSibling()) {
-switch (C->getRole()) {
-case syntax::NodeRole::ListElement: {
-  if (ElementWithoutDelimiter) {
-Children.push_back(ElementWithoutDelimiter);
-  }
-  ElementWithoutDelimiter = C;
-  break;
-}
-case sy

[PATCH] D79674: [clang-tidy] Better support for Override function in RenamerClangTidy based checks

2020-10-12 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

Looks good! Thanks for the fix! IIUC, this is related to 
https://bugs.llvm.org/show_bug.cgi?id=34879? Makes sense to specify this in the 
patch description.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79674/new/

https://reviews.llvm.org/D79674

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


[PATCH] D79674: [clang-tidy] Better support for Override function in RenamerClangTidy based checks

2020-10-12 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

Feel free to ping patches every week or so. It looks like in this case all the 
reviewers were swamped with something else at the time.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79674/new/

https://reviews.llvm.org/D79674

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


[PATCH] D89098: [clang] Fix returning the underlying VarDecl as top-level decl for VarTemplateDecl.

2020-10-12 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a subscriber: rsmith.
hokein added a comment.

> Is this https://github.com/clangd/clangd/issues/554 ? :-)

Yeah, the github issue exposes multiple bugs, this is part of the fix.

The AST of `VarTemplateSpeicalizationDecl` is a bit unusual, given the follow 
code,

  template  bool X = true;
  bool Z = X;



  TranslationUnitDecl 0x8a2ec28 <> 
  |-VarTemplateDecl 0x8a6faf8  col:26 X
  | |-TemplateTypeParmDecl 0x8a6f9c0  col:19 typename depth 0 index 0
  | |-VarDecl 0x8a6fa90  col:26 X 'bool' cinit
  | | `-CXXBoolLiteralExpr 0x8a6fb98  'bool' true
  | `-VarTemplateSpecializationDecl 0x8a6fd08  col:26 used X 
'bool' cinit
  |   |-TemplateArgument type 'int'
  |   | `-BuiltinType 0x8a2ed20 'int'
  |   `-CXXBoolLiteralExpr 0x8a6fb98  'bool' true
  |-VarDecl 0x8a6fbb8  col:6 Z 'bool' cinit
  | `-ImplicitCastExpr 0x8a6ff28  'bool' 
  |   `-DeclRefExpr 0x8a6fed8  'bool' lvalue 
VarTemplateSpecialization 0x8a6fd08 'X' 'bool'
  `-VarTemplateSpecializationDecl 0x8a6fd08  col:26 used X 
'bool' cinit   < here
|-TemplateArgument type 'int'
| `-BuiltinType 0x8a2ed20 'int'
`-CXXBoolLiteralExpr 0x8a6fb98  'bool' true

Note that the implicitly-instantiated `VarTemplateSpecializationDecl` is one of 
`TranslationUnitDecl::decls()`, this is different than function/class templates 
-- for function/class templates, only *explicit* template specializations will 
be in the `TranslationUnitDecl::decls()`

Related code is at 
https://github.com/llvm/llvm-project/blob/master/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp#L5015.
 @rsmith do you think this is expected? or we should fix that? like making it 
align with function/class templates?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89098/new/

https://reviews.llvm.org/D89098

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


[PATCH] D62574: Add support for target-configurable address spaces.

2020-10-12 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

In D62574#2249817 , @ebevhan wrote:

> In D62574#2242471 , @Anastasia wrote:
>
>> The only thing is that it would be good to test the new target setting logic 
>> somehow... do you have any ideas in mind? We could think of creating a dummy 
>> target for that or adding a dummy setting in existing targets - maybe SPIR 
>> could be a candidate. We have done something similar in the past if you look 
>> at `FakeAddrSpaceMap` in `LangOpts`.
>
> Perhaps we could add a configuration to AMDGPU? That has address spaces.
>
> I'm not a big fan of adding an option just for testing.

Ok yes if that can be done it would be better. However, it might need extra 
involvement from AMD side to make sure at least they would agree on maintaining 
this.




Comment at: clang/include/clang/AST/ASTContext.h:2612
+
+  /// Returns true if an explicit cast from address space A to B is legal.
+  /// Explicit conversion between address spaces is permitted if the address

ebevhan wrote:
> Anastasia wrote:
> > Here we should say that this is an extension or enhancement of embedded C 
> > rules that clang implements.
> > 
> > Technically for OpenCL we could refactor to use this functionality as we 
> > don't support such explicit casts on disjoint address spaces. But then this 
> > would not be necessarily a target setting.
> I'm still a bit on the fence about what Embedded-C really stipulates. I don't 
> think it's against the spec to simply disallow disjoint conversion 
> altogether, but it's only necessary to keep Clang's current implementation 
> working.
Technically Clang's policy is to implement documented and standardized 
behavior. So the question is not necessarily about its usefulness, but about 
adhering to good practices. 

I think it is ok to deviate from the standard to make the behavior more helpful 
in some cases but we should aim at documenting such changes. This will help the 
developers in the future if they need to fix bugs or build something on top.



Comment at: clang/lib/AST/ASTContext.cpp:10959
+  // Otherwise, ask the target.
+  return Target->isAddressSpaceSupersetOf(A, B);
+}

ebevhan wrote:
> Anastasia wrote:
> > I guess we should add a similar check here as below?
> > 
> >  
> > ```
> > if (isTargetAddressSpace(From) || isTargetAddressSpace(To) ||
> >   From == LangAS::Default || To == LangAS::Default)
> > ```
> Is it not useful for targets to be able to express relations of LangASes and 
> target ASes?
> 
> The method below must be guarded because otherwise all casts between LangASes 
> would be legal.
I am not sure I follow your comment.

> Is it not useful for targets to be able to express relations of LangASes and 
> target ASes?

yes that's why I was thinking we should add a check to make sure we only ask 
target for target ASes...

However, I am not sure what we should do if there is a mix of target and 
language AS. I guess this should be governed by the target hooks?



Comment at: clang/lib/Sema/SemaOverload.cpp:3235
   //  - in non-top levels it is not a valid conversion.
+  // FIXME: This should probably be using isExplicitAddrSpaceConversionLegal,
+  // but we don't know if this is an implicit or explicit conversion.

ebevhan wrote:
> Anastasia wrote:
> > Sorry if this has been discussed previously, do you refer to the first or 
> > the second case and is there any failing test case?
> It refers to the first case of "valid to convert to addr space that is a 
> superset in all cases". Technically, it could be permitted even if the addr 
> space is not a superset, if this is an explicit cast. But we don't know that. 
> We only know if it's a c-style cast, because those are always 'explicit'.
> 
> I don't have a test case, unfortunately. I just made this observation as I 
> was redoing all of the overlap/superspace checks. It might not even be a 
> problem.
Ok, we could update to:
`
 This should probably be using isExplicitAddrSpaceConversionLegal -> The first 
conversion should probably be using isExplicitAddrSpaceConversionLegal too.`

If you already have a failing test case we could create a bug to track this 
better.



Comment at: clang/lib/Sema/SemaOverload.cpp:5289
 
+  // FIXME: hasAddressSpace is wrong; this check will be skipped if FromType is
+  // not qualified with an address space, but if there's no implicit conversion

ebevhan wrote:
> Anastasia wrote:
> > Do you have a failing test case, if so feel free to create a bug?
> Unsure how I'd make one. I suspect this can't be triggered in OpenCL++, 
> because you can't really have LangAS::Default on FromType there, can you? It 
> would always be some AS.
> 
> Doing it in another way would require a target that has configurable ASes, 
> which doesn't exist yet. Also, it would require methods qualified 

Re: [clang-tools-extra] 702529d - [clang] Fix returning the underlying VarDecl as top-level decl for VarTemplateDecl.

2020-10-12 Thread Hubert Tong via cfe-commits
ParsedASTTest.TopLevelDecls has not recovered on clang-ppc64le-rhel since
this went in (even when including f1bf41e433e196ecffcc4fb7cd04c58d48445425,
which is purported to fix buildbot failures from this commit).

http://lab.llvm.org:8011/#/builders/57/builds/81

On Mon, Oct 12, 2020 at 5:06 AM Haojian Wu via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

>
> Author: Haojian Wu
> Date: 2020-10-12T10:46:18+02:00
> New Revision: 702529d899c87e9268bb33d836dbc91b6bce0b16
>
> URL:
> https://github.com/llvm/llvm-project/commit/702529d899c87e9268bb33d836dbc91b6bce0b16
> DIFF:
> https://github.com/llvm/llvm-project/commit/702529d899c87e9268bb33d836dbc91b6bce0b16.diff
>
> LOG: [clang] Fix returning the underlying VarDecl as top-level decl for
> VarTemplateDecl.
>
> Given the following VarTemplateDecl AST,
>
> ```
> VarTemplateDecl col:26 X
> |-TemplateTypeParmDecl typename depth 0 index 0
> `-VarDecl X 'bool' cinit
>   `-CXXBoolLiteralExpr 'bool' true
> ```
>
> previously, we returned the VarDecl as the top-level decl, which was not
> correct, the top-level decl should be VarTemplateDecl.
>
> Differential Revision: https://reviews.llvm.org/D89098
>
> Added:
>
>
> Modified:
> clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
> clang/lib/Parse/ParseDecl.cpp
>
> Removed:
>
>
>
>
> 
> diff  --git a/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
> b/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
> index 65d9cffeedc7..db23438766d2 100644
> --- a/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
> +++ b/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
> @@ -57,6 +57,12 @@ MATCHER_P(DeclNamed, Name, "") {
>return false;
>  }
>
> +MATCHER_P(DeclKind, Kind, "") {
> +  if (NamedDecl *ND = dyn_cast(arg))
> +return ND->getDeclKindName() == Kind;
> +  return false;
> +}
> +
>  // Matches if the Decl has template args equal to ArgName. If the decl is
> a
>  // NamedDecl and ArgName is an empty string it also matches.
>  MATCHER_P(WithTemplateArgs, ArgName, "") {
> @@ -99,9 +105,15 @@ TEST(ParsedASTTest, TopLevelDecls) {
>  int header1();
>  int header2;
>)";
> -  TU.Code = "int main();";
> +  TU.Code = R"cpp(
> +int main();
> +template  bool X = true;
> +  )cpp";
>auto AST = TU.build();
> -  EXPECT_THAT(AST.getLocalTopLevelDecls(),
> ElementsAre(DeclNamed("main")));
> +  EXPECT_THAT(
> +  AST.getLocalTopLevelDecls(),
> +  ElementsAreArray({AllOf(DeclNamed("main"), DeclKind("Function")),
> +AllOf(DeclNamed("X"), DeclKind("VarTemplate"))}));
>  }
>
>  TEST(ParsedASTTest, DoesNotGetIncludedTopDecls) {
>
> diff  --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
> index 3f314c59ade6..01a16575c239 100644
> --- a/clang/lib/Parse/ParseDecl.cpp
> +++ b/clang/lib/Parse/ParseDecl.cpp
> @@ -2195,6 +2195,7 @@ Decl
> *Parser::ParseDeclarationAfterDeclaratorAndAttributes(
>
>// Inform the current actions module that we just parsed this
> declarator.
>Decl *ThisDecl = nullptr;
> +  Decl *OuterDecl = nullptr;
>switch (TemplateInfo.Kind) {
>case ParsedTemplateInfo::NonTemplate:
>  ThisDecl = Actions.ActOnDeclarator(getCurScope(), D);
> @@ -2205,10 +2206,12 @@ Decl
> *Parser::ParseDeclarationAfterDeclaratorAndAttributes(
>  ThisDecl = Actions.ActOnTemplateDeclarator(getCurScope(),
>
> *TemplateInfo.TemplateParams,
> D);
> -if (VarTemplateDecl *VT = dyn_cast_or_null(ThisDecl))
> +if (VarTemplateDecl *VT =
> dyn_cast_or_null(ThisDecl)) {
>// Re-direct this decl to refer to the templated decl so that we can
>// initialize it.
>ThisDecl = VT->getTemplatedDecl();
> +  OuterDecl = VT;
> +}
>  break;
>}
>case ParsedTemplateInfo::ExplicitInstantiation: {
> @@ -2385,8 +2388,7 @@ Decl
> *Parser::ParseDeclarationAfterDeclaratorAndAttributes(
>}
>
>Actions.FinalizeDeclaration(ThisDecl);
> -
> -  return ThisDecl;
> +  return OuterDecl ? OuterDecl : ThisDecl;
>  }
>
>  /// ParseSpecifierQualifierList
>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D88469: [clangd] Heuristic resolution for dependent type and template names

2020-10-12 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

thanks.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88469/new/

https://reviews.llvm.org/D88469

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


[PATCH] D82089: [clang-tidy] modernize-loop-convert reverse iteration support

2020-10-12 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

Looks good!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82089/new/

https://reviews.llvm.org/D82089

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


[PATCH] D49864: [clang-tidy] The script clang-tidy-diff.py doesn't accept 'pass by' options (--)

2020-10-12 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

Sorry for the delay. This patch fell through the cracks. If you're still 
interested, could you rebase it on top of current HEAD and upload a full diff? 
Or use the arcanist tool, see https://llvm.org/docs/Phabricator.html.


Repository:
  rCTE Clang Tools Extra

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D49864/new/

https://reviews.llvm.org/D49864

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


[clang-tools-extra] b144cd8 - Dump decl when the test matcher fails.

2020-10-12 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2020-10-12T15:42:18+02:00
New Revision: b144cd867b6fdfbf0e80064cb67d06c267fa295c

URL: 
https://github.com/llvm/llvm-project/commit/b144cd867b6fdfbf0e80064cb67d06c267fa295c
DIFF: 
https://github.com/llvm/llvm-project/commit/b144cd867b6fdfbf0e80064cb67d06c267fa295c.diff

LOG: Dump decl when the test matcher fails.

Added: 


Modified: 
clang-tools-extra/clangd/unittests/ParsedASTTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp 
b/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
index e2de95909fbf..5b26773d95db 100644
--- a/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
+++ b/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
@@ -59,7 +59,8 @@ MATCHER_P(DeclNamed, Name, "") {
 
 MATCHER_P(DeclKind, Kind, "") {
   if (NamedDecl *ND = dyn_cast(arg))
-return ND->getDeclKindName() == Kind;
+if (ND->getDeclKindName() == Kind)
+  return true;
   if (auto *Stream = result_listener->stream()) {
 llvm::raw_os_ostream OS(*Stream);
 arg->dump(OS);



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


Re: [clang-tools-extra] 702529d - [clang] Fix returning the underlying VarDecl as top-level decl for VarTemplateDecl.

2020-10-12 Thread Haojian Wu via cfe-commits
sorry, I'm looking at it.

On Mon, 12 Oct 2020 at 15:35, Hubert Tong 
wrote:

> ParsedASTTest.TopLevelDecls has not recovered on clang-ppc64le-rhel since
> this went in (even when including f1bf41e433e196ecffcc4fb7cd04c58d48445425,
> which is purported to fix buildbot failures from this commit).
>
> http://lab.llvm.org:8011/#/builders/57/builds/81
>
> On Mon, Oct 12, 2020 at 5:06 AM Haojian Wu via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>>
>> Author: Haojian Wu
>> Date: 2020-10-12T10:46:18+02:00
>> New Revision: 702529d899c87e9268bb33d836dbc91b6bce0b16
>>
>> URL:
>> https://github.com/llvm/llvm-project/commit/702529d899c87e9268bb33d836dbc91b6bce0b16
>> DIFF:
>> https://github.com/llvm/llvm-project/commit/702529d899c87e9268bb33d836dbc91b6bce0b16.diff
>>
>> LOG: [clang] Fix returning the underlying VarDecl as top-level decl for
>> VarTemplateDecl.
>>
>> Given the following VarTemplateDecl AST,
>>
>> ```
>> VarTemplateDecl col:26 X
>> |-TemplateTypeParmDecl typename depth 0 index 0
>> `-VarDecl X 'bool' cinit
>>   `-CXXBoolLiteralExpr 'bool' true
>> ```
>>
>> previously, we returned the VarDecl as the top-level decl, which was not
>> correct, the top-level decl should be VarTemplateDecl.
>>
>> Differential Revision: https://reviews.llvm.org/D89098
>>
>> Added:
>>
>>
>> Modified:
>> clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
>> clang/lib/Parse/ParseDecl.cpp
>>
>> Removed:
>>
>>
>>
>>
>> 
>> diff  --git a/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
>> b/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
>> index 65d9cffeedc7..db23438766d2 100644
>> --- a/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
>> +++ b/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
>> @@ -57,6 +57,12 @@ MATCHER_P(DeclNamed, Name, "") {
>>return false;
>>  }
>>
>> +MATCHER_P(DeclKind, Kind, "") {
>> +  if (NamedDecl *ND = dyn_cast(arg))
>> +return ND->getDeclKindName() == Kind;
>> +  return false;
>> +}
>> +
>>  // Matches if the Decl has template args equal to ArgName. If the decl
>> is a
>>  // NamedDecl and ArgName is an empty string it also matches.
>>  MATCHER_P(WithTemplateArgs, ArgName, "") {
>> @@ -99,9 +105,15 @@ TEST(ParsedASTTest, TopLevelDecls) {
>>  int header1();
>>  int header2;
>>)";
>> -  TU.Code = "int main();";
>> +  TU.Code = R"cpp(
>> +int main();
>> +template  bool X = true;
>> +  )cpp";
>>auto AST = TU.build();
>> -  EXPECT_THAT(AST.getLocalTopLevelDecls(),
>> ElementsAre(DeclNamed("main")));
>> +  EXPECT_THAT(
>> +  AST.getLocalTopLevelDecls(),
>> +  ElementsAreArray({AllOf(DeclNamed("main"), DeclKind("Function")),
>> +AllOf(DeclNamed("X"),
>> DeclKind("VarTemplate"))}));
>>  }
>>
>>  TEST(ParsedASTTest, DoesNotGetIncludedTopDecls) {
>>
>> diff  --git a/clang/lib/Parse/ParseDecl.cpp
>> b/clang/lib/Parse/ParseDecl.cpp
>> index 3f314c59ade6..01a16575c239 100644
>> --- a/clang/lib/Parse/ParseDecl.cpp
>> +++ b/clang/lib/Parse/ParseDecl.cpp
>> @@ -2195,6 +2195,7 @@ Decl
>> *Parser::ParseDeclarationAfterDeclaratorAndAttributes(
>>
>>// Inform the current actions module that we just parsed this
>> declarator.
>>Decl *ThisDecl = nullptr;
>> +  Decl *OuterDecl = nullptr;
>>switch (TemplateInfo.Kind) {
>>case ParsedTemplateInfo::NonTemplate:
>>  ThisDecl = Actions.ActOnDeclarator(getCurScope(), D);
>> @@ -2205,10 +2206,12 @@ Decl
>> *Parser::ParseDeclarationAfterDeclaratorAndAttributes(
>>  ThisDecl = Actions.ActOnTemplateDeclarator(getCurScope(),
>>
>> *TemplateInfo.TemplateParams,
>> D);
>> -if (VarTemplateDecl *VT =
>> dyn_cast_or_null(ThisDecl))
>> +if (VarTemplateDecl *VT =
>> dyn_cast_or_null(ThisDecl)) {
>>// Re-direct this decl to refer to the templated decl so that we
>> can
>>// initialize it.
>>ThisDecl = VT->getTemplatedDecl();
>> +  OuterDecl = VT;
>> +}
>>  break;
>>}
>>case ParsedTemplateInfo::ExplicitInstantiation: {
>> @@ -2385,8 +2388,7 @@ Decl
>> *Parser::ParseDeclarationAfterDeclaratorAndAttributes(
>>}
>>
>>Actions.FinalizeDeclaration(ThisDecl);
>> -
>> -  return ThisDecl;
>> +  return OuterDecl ? OuterDecl : ThisDecl;
>>  }
>>
>>  /// ParseSpecifierQualifierList
>>
>>
>>
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [clang-tools-extra] 702529d - [clang] Fix returning the underlying VarDecl as top-level decl for VarTemplateDecl.

2020-10-12 Thread Hubert Tong via cfe-commits
On Mon, Oct 12, 2020 at 9:43 AM Haojian Wu  wrote:

> sorry, I'm looking at it.
>
No problem, thanks!


> On Mon, 12 Oct 2020 at 15:35, Hubert Tong <
> hubert.reinterpretc...@gmail.com> wrote:
>
>> ParsedASTTest.TopLevelDecls has not recovered on clang-ppc64le-rhel since
>> this went in (even when including f1bf41e433e196ecffcc4fb7cd04c58d48445425,
>> which is purported to fix buildbot failures from this commit).
>>
>> http://lab.llvm.org:8011/#/builders/57/builds/81
>>
>> On Mon, Oct 12, 2020 at 5:06 AM Haojian Wu via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>>
>>> Author: Haojian Wu
>>> Date: 2020-10-12T10:46:18+02:00
>>> New Revision: 702529d899c87e9268bb33d836dbc91b6bce0b16
>>>
>>> URL:
>>> https://github.com/llvm/llvm-project/commit/702529d899c87e9268bb33d836dbc91b6bce0b16
>>> DIFF:
>>> https://github.com/llvm/llvm-project/commit/702529d899c87e9268bb33d836dbc91b6bce0b16.diff
>>>
>>> LOG: [clang] Fix returning the underlying VarDecl as top-level decl for
>>> VarTemplateDecl.
>>>
>>> Given the following VarTemplateDecl AST,
>>>
>>> ```
>>> VarTemplateDecl col:26 X
>>> |-TemplateTypeParmDecl typename depth 0 index 0
>>> `-VarDecl X 'bool' cinit
>>>   `-CXXBoolLiteralExpr 'bool' true
>>> ```
>>>
>>> previously, we returned the VarDecl as the top-level decl, which was not
>>> correct, the top-level decl should be VarTemplateDecl.
>>>
>>> Differential Revision: https://reviews.llvm.org/D89098
>>>
>>> Added:
>>>
>>>
>>> Modified:
>>> clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
>>> clang/lib/Parse/ParseDecl.cpp
>>>
>>> Removed:
>>>
>>>
>>>
>>>
>>> 
>>> diff  --git a/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
>>> b/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
>>> index 65d9cffeedc7..db23438766d2 100644
>>> --- a/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
>>> +++ b/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
>>> @@ -57,6 +57,12 @@ MATCHER_P(DeclNamed, Name, "") {
>>>return false;
>>>  }
>>>
>>> +MATCHER_P(DeclKind, Kind, "") {
>>> +  if (NamedDecl *ND = dyn_cast(arg))
>>> +return ND->getDeclKindName() == Kind;
>>> +  return false;
>>> +}
>>> +
>>>  // Matches if the Decl has template args equal to ArgName. If the decl
>>> is a
>>>  // NamedDecl and ArgName is an empty string it also matches.
>>>  MATCHER_P(WithTemplateArgs, ArgName, "") {
>>> @@ -99,9 +105,15 @@ TEST(ParsedASTTest, TopLevelDecls) {
>>>  int header1();
>>>  int header2;
>>>)";
>>> -  TU.Code = "int main();";
>>> +  TU.Code = R"cpp(
>>> +int main();
>>> +template  bool X = true;
>>> +  )cpp";
>>>auto AST = TU.build();
>>> -  EXPECT_THAT(AST.getLocalTopLevelDecls(),
>>> ElementsAre(DeclNamed("main")));
>>> +  EXPECT_THAT(
>>> +  AST.getLocalTopLevelDecls(),
>>> +  ElementsAreArray({AllOf(DeclNamed("main"), DeclKind("Function")),
>>> +AllOf(DeclNamed("X"),
>>> DeclKind("VarTemplate"))}));
>>>  }
>>>
>>>  TEST(ParsedASTTest, DoesNotGetIncludedTopDecls) {
>>>
>>> diff  --git a/clang/lib/Parse/ParseDecl.cpp
>>> b/clang/lib/Parse/ParseDecl.cpp
>>> index 3f314c59ade6..01a16575c239 100644
>>> --- a/clang/lib/Parse/ParseDecl.cpp
>>> +++ b/clang/lib/Parse/ParseDecl.cpp
>>> @@ -2195,6 +2195,7 @@ Decl
>>> *Parser::ParseDeclarationAfterDeclaratorAndAttributes(
>>>
>>>// Inform the current actions module that we just parsed this
>>> declarator.
>>>Decl *ThisDecl = nullptr;
>>> +  Decl *OuterDecl = nullptr;
>>>switch (TemplateInfo.Kind) {
>>>case ParsedTemplateInfo::NonTemplate:
>>>  ThisDecl = Actions.ActOnDeclarator(getCurScope(), D);
>>> @@ -2205,10 +2206,12 @@ Decl
>>> *Parser::ParseDeclarationAfterDeclaratorAndAttributes(
>>>  ThisDecl = Actions.ActOnTemplateDeclarator(getCurScope(),
>>>
>>> *TemplateInfo.TemplateParams,
>>> D);
>>> -if (VarTemplateDecl *VT =
>>> dyn_cast_or_null(ThisDecl))
>>> +if (VarTemplateDecl *VT =
>>> dyn_cast_or_null(ThisDecl)) {
>>>// Re-direct this decl to refer to the templated decl so that we
>>> can
>>>// initialize it.
>>>ThisDecl = VT->getTemplatedDecl();
>>> +  OuterDecl = VT;
>>> +}
>>>  break;
>>>}
>>>case ParsedTemplateInfo::ExplicitInstantiation: {
>>> @@ -2385,8 +2388,7 @@ Decl
>>> *Parser::ParseDeclarationAfterDeclaratorAndAttributes(
>>>}
>>>
>>>Actions.FinalizeDeclaration(ThisDecl);
>>> -
>>> -  return ThisDecl;
>>> +  return OuterDecl ? OuterDecl : ThisDecl;
>>>  }
>>>
>>>  /// ParseSpecifierQualifierList
>>>
>>>
>>>
>>> ___
>>> cfe-commits mailing list
>>> cfe-commits@lists.llvm.org
>>> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>>
>>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 16a4b0f - [clangd] Disable a failure TopLevelDecls test.

2020-10-12 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2020-10-12T16:03:52+02:00
New Revision: 16a4b0f0e36c8e1efa586ca4b2be8effefa75e6e

URL: 
https://github.com/llvm/llvm-project/commit/16a4b0f0e36c8e1efa586ca4b2be8effefa75e6e
DIFF: 
https://github.com/llvm/llvm-project/commit/16a4b0f0e36c8e1efa586ca4b2be8effefa75e6e.diff

LOG: [clangd] Disable a failure TopLevelDecls test.

The test fails on clang-ppc64le-rhel buildbot, needs further
investigation.

Added: 


Modified: 
clang-tools-extra/clangd/unittests/ParsedASTTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp 
b/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
index 5b26773d95db..9b7b2e2dcd47 100644
--- a/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
+++ b/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
@@ -104,7 +104,8 @@ MATCHER(EqInc, "") {
  std::tie(Expected.HashLine, Expected.Written);
 }
 
-TEST(ParsedASTTest, TopLevelDecls) {
+// FIXME: figure out why it fails on clang-ppc64le-rhel buildbot.
+TEST(ParsedASTTest, DISABLED_TopLevelDecls) {
   TestTU TU;
   TU.HeaderCode = R"(
 int header1();



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


Re: [clang-tools-extra] 702529d - [clang] Fix returning the underlying VarDecl as top-level decl for VarTemplateDecl.

2020-10-12 Thread Haojian Wu via cfe-commits
I haven't found out the root cause yet. I have disabled this test to
make the buildbot happey. Will continue to investigate tomorrow.

On Mon, 12 Oct 2020 at 15:45, Hubert Tong 
wrote:

> On Mon, Oct 12, 2020 at 9:43 AM Haojian Wu  wrote:
>
>> sorry, I'm looking at it.
>>
> No problem, thanks!
>
>
>> On Mon, 12 Oct 2020 at 15:35, Hubert Tong <
>> hubert.reinterpretc...@gmail.com> wrote:
>>
>>> ParsedASTTest.TopLevelDecls has not recovered on clang-ppc64le-rhel
>>> since this went in (even when including
>>> f1bf41e433e196ecffcc4fb7cd04c58d48445425, which is purported to fix
>>> buildbot failures from this commit).
>>>
>>> http://lab.llvm.org:8011/#/builders/57/builds/81
>>>
>>> On Mon, Oct 12, 2020 at 5:06 AM Haojian Wu via cfe-commits <
>>> cfe-commits@lists.llvm.org> wrote:
>>>

 Author: Haojian Wu
 Date: 2020-10-12T10:46:18+02:00
 New Revision: 702529d899c87e9268bb33d836dbc91b6bce0b16

 URL:
 https://github.com/llvm/llvm-project/commit/702529d899c87e9268bb33d836dbc91b6bce0b16
 DIFF:
 https://github.com/llvm/llvm-project/commit/702529d899c87e9268bb33d836dbc91b6bce0b16.diff

 LOG: [clang] Fix returning the underlying VarDecl as top-level decl for
 VarTemplateDecl.

 Given the following VarTemplateDecl AST,

 ```
 VarTemplateDecl col:26 X
 |-TemplateTypeParmDecl typename depth 0 index 0
 `-VarDecl X 'bool' cinit
   `-CXXBoolLiteralExpr 'bool' true
 ```

 previously, we returned the VarDecl as the top-level decl, which was not
 correct, the top-level decl should be VarTemplateDecl.

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

 Added:


 Modified:
 clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
 clang/lib/Parse/ParseDecl.cpp

 Removed:




 
 diff  --git a/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
 b/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
 index 65d9cffeedc7..db23438766d2 100644
 --- a/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
 +++ b/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
 @@ -57,6 +57,12 @@ MATCHER_P(DeclNamed, Name, "") {
return false;
  }

 +MATCHER_P(DeclKind, Kind, "") {
 +  if (NamedDecl *ND = dyn_cast(arg))
 +return ND->getDeclKindName() == Kind;
 +  return false;
 +}
 +
  // Matches if the Decl has template args equal to ArgName. If the decl
 is a
  // NamedDecl and ArgName is an empty string it also matches.
  MATCHER_P(WithTemplateArgs, ArgName, "") {
 @@ -99,9 +105,15 @@ TEST(ParsedASTTest, TopLevelDecls) {
  int header1();
  int header2;
)";
 -  TU.Code = "int main();";
 +  TU.Code = R"cpp(
 +int main();
 +template  bool X = true;
 +  )cpp";
auto AST = TU.build();
 -  EXPECT_THAT(AST.getLocalTopLevelDecls(),
 ElementsAre(DeclNamed("main")));
 +  EXPECT_THAT(
 +  AST.getLocalTopLevelDecls(),
 +  ElementsAreArray({AllOf(DeclNamed("main"), DeclKind("Function")),
 +AllOf(DeclNamed("X"),
 DeclKind("VarTemplate"))}));
  }

  TEST(ParsedASTTest, DoesNotGetIncludedTopDecls) {

 diff  --git a/clang/lib/Parse/ParseDecl.cpp
 b/clang/lib/Parse/ParseDecl.cpp
 index 3f314c59ade6..01a16575c239 100644
 --- a/clang/lib/Parse/ParseDecl.cpp
 +++ b/clang/lib/Parse/ParseDecl.cpp
 @@ -2195,6 +2195,7 @@ Decl
 *Parser::ParseDeclarationAfterDeclaratorAndAttributes(

// Inform the current actions module that we just parsed this
 declarator.
Decl *ThisDecl = nullptr;
 +  Decl *OuterDecl = nullptr;
switch (TemplateInfo.Kind) {
case ParsedTemplateInfo::NonTemplate:
  ThisDecl = Actions.ActOnDeclarator(getCurScope(), D);
 @@ -2205,10 +2206,12 @@ Decl
 *Parser::ParseDeclarationAfterDeclaratorAndAttributes(
  ThisDecl = Actions.ActOnTemplateDeclarator(getCurScope(),

 *TemplateInfo.TemplateParams,
 D);
 -if (VarTemplateDecl *VT =
 dyn_cast_or_null(ThisDecl))
 +if (VarTemplateDecl *VT =
 dyn_cast_or_null(ThisDecl)) {
// Re-direct this decl to refer to the templated decl so that we
 can
// initialize it.
ThisDecl = VT->getTemplatedDecl();
 +  OuterDecl = VT;
 +}
  break;
}
case ParsedTemplateInfo::ExplicitInstantiation: {
 @@ -2385,8 +2388,7 @@ Decl
 *Parser::ParseDeclarationAfterDeclaratorAndAttributes(
}

Actions.FinalizeDeclaration(ThisDecl);
 -
 -  return ThisDecl;
 +  return OuterDecl ? OuterDecl : ThisDecl;
  }

  /// ParseSpecifierQualifierList



 _

[PATCH] D89055: [analyzer] Wrong type cast occures during pointer dereferencing after type punning

2020-10-12 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov updated this revision to Diff 297579.
ASDenysPetrov added a comment.

Updat patch due to suggestions and fixed formating.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89055/new/

https://reviews.llvm.org/D89055

Files:
  clang/lib/StaticAnalyzer/Core/Store.cpp
  clang/test/Analysis/nonloc-as-loc-crash.c
  clang/test/Analysis/string.c


Index: clang/test/Analysis/string.c
===
--- clang/test/Analysis/string.c
+++ clang/test/Analysis/string.c
@@ -363,6 +363,14 @@
 strcpy(x, y); // no-warning
 }
 
+// PR37503
+void *get_void_ptr();
+char ***type_punned_ptr;
+void strcpy_no_assertion(char c) {
+  *(unsigned char **)type_punned_ptr = (unsigned char *)(get_void_ptr());
+  strcpy(**type_punned_ptr, &c); // no-crash
+}
+
 //===--===
 // stpcpy()
 //===--===
Index: clang/test/Analysis/nonloc-as-loc-crash.c
===
--- /dev/null
+++ clang/test/Analysis/nonloc-as-loc-crash.c
@@ -0,0 +1,12 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core -verify %s
+// expected-no-diagnostics
+
+void test(int *a, char ***b, float *c) {
+  *(unsigned char **)b = (unsigned char *)a;
+  if (**b == 0) // no-crash
+;
+
+  *(unsigned char **)b = (unsigned char *)c;
+  if (**b == 0) // no-crash
+;
+}
Index: clang/lib/StaticAnalyzer/Core/Store.cpp
===
--- clang/lib/StaticAnalyzer/Core/Store.cpp
+++ clang/lib/StaticAnalyzer/Core/Store.cpp
@@ -426,12 +426,17 @@
   // We might need to do that for non-void pointers as well.
   // FIXME: We really need a single good function to perform casts for us
   // correctly every time we need it.
-  if (castTy->isPointerType() && !castTy->isVoidPointerType())
+  if (castTy->isPointerType() && !castTy->isVoidPointerType()) {
 if (const auto *SR = dyn_cast_or_null(V.getAsRegion())) {
   QualType sr = SR->getSymbol()->getType();
   if (!hasSameUnqualifiedPointeeType(sr, castTy))
-  return loc::MemRegionVal(castRegion(SR, castTy));
+return loc::MemRegionVal(castRegion(SR, castTy));
 }
+// Next fixes pointer dereference using type different from its initial one
+// See PR37503 for details
+if (const auto *SR = dyn_cast_or_null(V.getAsRegion()))
+  return loc::MemRegionVal(castRegion(SR, castTy));
+  }
 
   return svalBuilder.dispatchCast(V, castTy);
 }


Index: clang/test/Analysis/string.c
===
--- clang/test/Analysis/string.c
+++ clang/test/Analysis/string.c
@@ -363,6 +363,14 @@
 strcpy(x, y); // no-warning
 }
 
+// PR37503
+void *get_void_ptr();
+char ***type_punned_ptr;
+void strcpy_no_assertion(char c) {
+  *(unsigned char **)type_punned_ptr = (unsigned char *)(get_void_ptr());
+  strcpy(**type_punned_ptr, &c); // no-crash
+}
+
 //===--===
 // stpcpy()
 //===--===
Index: clang/test/Analysis/nonloc-as-loc-crash.c
===
--- /dev/null
+++ clang/test/Analysis/nonloc-as-loc-crash.c
@@ -0,0 +1,12 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core -verify %s
+// expected-no-diagnostics
+
+void test(int *a, char ***b, float *c) {
+  *(unsigned char **)b = (unsigned char *)a;
+  if (**b == 0) // no-crash
+;
+
+  *(unsigned char **)b = (unsigned char *)c;
+  if (**b == 0) // no-crash
+;
+}
Index: clang/lib/StaticAnalyzer/Core/Store.cpp
===
--- clang/lib/StaticAnalyzer/Core/Store.cpp
+++ clang/lib/StaticAnalyzer/Core/Store.cpp
@@ -426,12 +426,17 @@
   // We might need to do that for non-void pointers as well.
   // FIXME: We really need a single good function to perform casts for us
   // correctly every time we need it.
-  if (castTy->isPointerType() && !castTy->isVoidPointerType())
+  if (castTy->isPointerType() && !castTy->isVoidPointerType()) {
 if (const auto *SR = dyn_cast_or_null(V.getAsRegion())) {
   QualType sr = SR->getSymbol()->getType();
   if (!hasSameUnqualifiedPointeeType(sr, castTy))
-  return loc::MemRegionVal(castRegion(SR, castTy));
+return loc::MemRegionVal(castRegion(SR, castTy));
 }
+// Next fixes pointer dereference using type different from its initial one
+// See PR37503 for details
+if (const auto *SR = dyn_cast_or_null(V.getAsRegion()))
+  return loc::MemRegionVal(castRegion(SR, castTy));
+  }
 
   return svalBuilder.dispatchCast(V, castTy);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D89238: [clangd] Go-to-definition from non-renaming alias is unambiguous.

2020-10-12 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: hokein.
Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman.
Herald added a project: clang.
sammccall requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.

It's not helpful to show the alias itself as an option.
This fixes a regression accepted in f24649b77d856157c64841457dcc4f70530d607c 
.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D89238

Files:
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp

Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1118,13 +1118,12 @@
   // decls.
   R"cpp(
   namespace ns { class [[Foo]] {}; }
-  // FIXME: don't return the using decl if it touches the cursor position.
-  using ns::[[F^oo]];
+  using ns::F^oo;
 )cpp",
 
   R"cpp(
   namespace ns { int [[x]](char); int [[x]](double); }
-  using ns::[[^x]];
+  using ns::^x;
 )cpp",
 
   R"cpp(
@@ -1157,7 +1156,7 @@
   };
   template 
   struct Derived : Base {
-using Base::[[w^aldo]];
+using Base::w^aldo;
   };
 )cpp",
   };
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -171,22 +171,33 @@
   return Merged.CanonicalDeclaration;
 }
 
+std::vector>
+getDeclAtPositionWithRelations(ParsedAST &AST, SourceLocation Pos,
+   DeclRelationSet Relations,
+   ASTNodeKind *NodeKind = nullptr) {
+  unsigned Offset = AST.getSourceManager().getDecomposedSpellingLoc(Pos).second;
+  std::vector> Result;
+  auto ResultFromTree = [&](SelectionTree ST) {
+if (const SelectionTree::Node *N = ST.commonAncestor()) {
+  if (NodeKind)
+*NodeKind = N->ASTNode.getNodeKind();
+  llvm::copy_if(allTargetDecls(N->ASTNode), std::back_inserter(Result),
+[&](auto &Entry) { return !(Entry.second & ~Relations); });
+}
+return !Result.empty();
+  };
+  SelectionTree::createEach(AST.getASTContext(), AST.getTokens(), Offset,
+Offset, ResultFromTree);
+  return Result;
+}
+
 std::vector
 getDeclAtPosition(ParsedAST &AST, SourceLocation Pos, DeclRelationSet Relations,
   ASTNodeKind *NodeKind = nullptr) {
-  unsigned Offset = AST.getSourceManager().getDecomposedSpellingLoc(Pos).second;
   std::vector Result;
-  SelectionTree::createEach(AST.getASTContext(), AST.getTokens(), Offset,
-Offset, [&](SelectionTree ST) {
-  if (const SelectionTree::Node *N =
-  ST.commonAncestor()) {
-if (NodeKind)
-  *NodeKind = N->ASTNode.getNodeKind();
-llvm::copy(targetDecl(N->ASTNode, Relations),
-   std::back_inserter(Result));
-  }
-  return !Result.empty();
-});
+  for (auto &Entry :
+   getDeclAtPositionWithRelations(AST, Pos, Relations, NodeKind))
+Result.push_back(Entry.first);
   return Result;
 }
 
@@ -316,8 +327,10 @@
   // Emit all symbol locations (declaration or definition) from AST.
   DeclRelationSet Relations =
   DeclRelation::TemplatePattern | DeclRelation::Alias;
-  for (const NamedDecl *D :
-   getDeclAtPosition(AST, CurLoc, Relations, NodeKind)) {
+  auto Candidates =
+  getDeclAtPositionWithRelations(AST, CurLoc, Relations, NodeKind);
+  for (const auto &E : Candidates) {
+const NamedDecl *D = E.first;
 // Special case: void foo() ^override: jump to the overridden method.
 if (const auto *CMD = llvm::dyn_cast(D)) {
   const InheritableAttr *Attr = D->getAttr();
@@ -333,6 +346,18 @@
   }
 }
 
+// Special case: the cursor is on an alias, prefer other results.
+// This targets "using ns::^Foo", where the target is more interesting.
+// This does not trigger on renaming aliases:
+//   `using Foo = ^Bar` already targets Bar via a TypeLoc
+//   `using ^Foo = Bar` has no other results, as Underlying is filtered.
+if (E.second & DeclRelation::Alias && Candidates.size() > 1 &&
+// beginLoc/endLoc are a token range, so rewind the identifier we're in.
+SM.isPointWithin(TouchedIdentifier ? TouchedIdentifier->location()
+   : CurLoc,
+ D->getBeginLoc(), D->getEndLoc()))
+  continue;
+
 // Special case: the point of declaration o

[PATCH] D89242: [PowerPC] [Clang] Port SSE4.1-compatible insert intrinsics

2020-10-12 Thread Qiu Chaofan via Phabricator via cfe-commits
qiucf created this revision.
qiucf added reviewers: nemanjai, jsji, kbarton, PowerPC, wschmidt, rsmith.
Herald added subscribers: cfe-commits, steven.zhang, pengfei, shchenz.
Herald added a project: clang.
qiucf requested review of this revision.

This patch adds three intrinsics compatible to x86's SSE 4.1 on PowerPC target, 
with tests:

- _mm_insert_epi8
- _mm_insert_epi32
- _mm_insert_epi64

The intrinsics implementation is contributed by Paul Clarke.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D89242

Files:
  clang/lib/Headers/ppc_wrappers/smmintrin.h
  clang/test/CodeGen/ppc-smmintrin.c


Index: clang/test/CodeGen/ppc-smmintrin.c
===
--- clang/test/CodeGen/ppc-smmintrin.c
+++ clang/test/CodeGen/ppc-smmintrin.c
@@ -116,3 +116,32 @@
 // CHECK-NEXT: [[REG80:[0-9a-zA-Z_%.]+]] = call <16 x i8> @vec_sel(unsigned 
char vector[16], unsigned char vector[16], unsigned char vector[16])(<16 x i8> 
[[REG76]], <16 x i8> [[REG78]], <16 x i8> [[REG79]])
 // CHECK-NEXT: [[REG81:[0-9a-zA-Z_%.]+]] = bitcast <16 x i8> [[REG80]] to <2 x 
i64>
 // CHECK-NEXT: ret <2 x i64> [[REG81]]
+
+void __attribute__((noinline))
+test_insert() {
+  _mm_insert_epi8(m1, 1, 0);
+  _mm_insert_epi32(m1, 1, 0);
+  _mm_insert_epi64(m1, 0x1L, 0);
+}
+
+// CHECK-LABEL: @test_insert
+
+// CHECK: define available_externally <2 x i64> @_mm_insert_epi8(<2 x i64> 
{{[0-9a-zA-Z_%.]+}}, i32 signext {{[0-9a-zA-Z_%.]+}}, i32 signext 
{{[0-9a-zA-Z_%.]+}})
+// CHECK: %{{[0-9a-zA-Z_.]+}} = bitcast <2 x i64> %{{[0-9a-zA-Z_.]+}} to <16 x 
i8>
+// CHECK: %[[R0:[0-9a-zA-Z_.]+]] = trunc i32 %{{[0-9a-zA-Z_.]+}} to i8
+// CHECK: %[[R1:[0-9a-zA-Z_.]+]] = and i32 %{{[0-9a-zA-Z_.]+}}, 15
+// CHECK: %{{[0-9a-zA-Z_.]+}} = insertelement <16 x i8> %{{[0-9a-zA-Z_.]+}}, 
i8 %[[R0]], i32 %[[R1]]
+// CHECK: %[[R2:[0-9a-zA-Z_.]+]] = bitcast <16 x i8> %{{[0-9a-zA-Z_.]+}} to <2 
x i64>
+// CHECK: ret <2 x i64> %[[R2]]
+
+// CHECK: define available_externally <2 x i64> @_mm_insert_epi32(<2 x i64> 
{{[0-9a-zA-Z_%.]+}}, i32 signext {{[0-9a-zA-Z_%.]+}}, i32 signext 
{{[0-9a-zA-Z_%.]+}})
+// CHECK: %{{[0-9a-zA-Z_.]+}} = bitcast <2 x i64> %{{[0-9a-zA-Z_.]+}} to <4 x 
i32>
+// CHECK: %[[R0:[0-9a-zA-Z_.]+]] = and i32 %{{[0-9a-zA-Z_.]+}}, 3
+// CHECK: %{{[0-9a-zA-Z_.]+}} = insertelement <4 x i32> %{{[0-9a-zA-Z_.]+}}, 
i32 %{{[0-9a-zA-Z_.]+}}, i32 %[[R0]]
+// CHECK: %[[R1:[0-9a-zA-Z_.]+]] = bitcast <4 x i32> %{{[0-9a-zA-Z_.]+}} to <2 
x i64>
+// CHECK: ret <2 x i64> %[[R1]]
+
+// CHECK: define available_externally <2 x i64> @_mm_insert_epi64(<2 x i64> 
{{[0-9a-zA-Z_%.]+}}, i64 {{[0-9a-zA-Z_%.]+}}, i32 signext {{[0-9a-zA-Z_%.]+}})
+// CHECK: %[[R0:[0-9a-zA-Z_.]+]] = and i32 %{{[0-9a-zA-Z_.]+}}, 1
+// CHECK: %{{[0-9a-zA-Z_.]+}} = insertelement <2 x i64> %{{[0-9a-zA-Z_.]+}}, 
i64 %{{[0-9a-zA-Z_.]+}}, i32 %[[R0:[0-9a-zA-Z_.]+]]
+// CHECK: ret <2 x i64> %{{[0-9a-zA-Z_.]+}}
Index: clang/lib/Headers/ppc_wrappers/smmintrin.h
===
--- clang/lib/Headers/ppc_wrappers/smmintrin.h
+++ clang/lib/Headers/ppc_wrappers/smmintrin.h
@@ -78,6 +78,30 @@
   return (__m128i)vec_sel((__v16qu)__A, (__v16qu)__B, __lmask);
 }
 
+extern __inline __m128i
+__attribute__((__gnu_inline__, __always_inline__, __artificial__))
+_mm_insert_epi8(__m128i const __A, int const __D, int const __N) {
+  __v16qi result = (__v16qi)__A;
+  result[__N & 0xf] = __D;
+  return (__m128i)result;
+}
+
+extern __inline __m128i
+__attribute__((__gnu_inline__, __always_inline__, __artificial__))
+_mm_insert_epi32(__m128i const __A, int const __D, int const __N) {
+  __v4si result = (__v4si)__A;
+  result[__N & 3] = __D;
+  return (__m128i)result;
+}
+
+extern __inline __m128i
+__attribute__((__gnu_inline__, __always_inline__, __artificial__))
+_mm_insert_epi64(__m128i const __A, long long const __D, int const __N) {
+  __v2di result = (__v2di)__A;
+  result[__N & 1] = __D;
+  return (__m128i)result;
+}
+
 #else
 #include_next 
 #endif /* defined(__linux__) && defined(__ppc64__) */


Index: clang/test/CodeGen/ppc-smmintrin.c
===
--- clang/test/CodeGen/ppc-smmintrin.c
+++ clang/test/CodeGen/ppc-smmintrin.c
@@ -116,3 +116,32 @@
 // CHECK-NEXT: [[REG80:[0-9a-zA-Z_%.]+]] = call <16 x i8> @vec_sel(unsigned char vector[16], unsigned char vector[16], unsigned char vector[16])(<16 x i8> [[REG76]], <16 x i8> [[REG78]], <16 x i8> [[REG79]])
 // CHECK-NEXT: [[REG81:[0-9a-zA-Z_%.]+]] = bitcast <16 x i8> [[REG80]] to <2 x i64>
 // CHECK-NEXT: ret <2 x i64> [[REG81]]
+
+void __attribute__((noinline))
+test_insert() {
+  _mm_insert_epi8(m1, 1, 0);
+  _mm_insert_epi32(m1, 1, 0);
+  _mm_insert_epi64(m1, 0x1L, 0);
+}
+
+// CHECK-LABEL: @test_insert
+
+// CHECK: define available_externally <2 x i64> @_mm_insert_epi8(<2 x i64> {{[0-9a-zA-Z_%.]+}}, i32 signext {{[0-9a-zA-Z_%.]+}}, i32 signext {{[0-9a-zA-Z_%.]+}

[PATCH] D88984: Prefer libc++ headers in the -isysroot over the toolchain

2020-10-12 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith requested changes to this revision.
dexonsmith added a comment.
This revision now requires changes to proceed.

@rsmith , @teemperor , @ldionne , thoughts on the above?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88984/new/

https://reviews.llvm.org/D88984

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


[PATCH] D89197: [X86] Support -march=x86-64-v[234]

2020-10-12 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 297606.
MaskRay added a comment.

Fix bullet point.
Add a link to 
https://gitlab.com/x86-psABIs/x86-64-ABI/-/commit/77566eb03bc6a326811cb7e9


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89197/new/

https://reviews.llvm.org/D89197

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Basic/Targets/X86.cpp
  clang/lib/Basic/Targets/X86.h
  clang/test/CodeGen/attr-target-x86.c
  clang/test/Driver/x86-march.c
  clang/test/Driver/x86-mtune.c
  clang/test/Misc/target-invalid-cpu-note.c
  clang/test/Preprocessor/predefined-arch-macros-x86.c
  clang/test/Preprocessor/predefined-arch-macros.c
  clang/test/Sema/builtin-cpu-supports.c
  llvm/docs/ReleaseNotes.rst
  llvm/include/llvm/Support/X86TargetParser.h
  llvm/lib/Support/X86TargetParser.cpp
  llvm/lib/Target/X86/X86.td
  llvm/test/CodeGen/X86/cpus-other.ll

Index: llvm/test/CodeGen/X86/cpus-other.ll
===
--- llvm/test/CodeGen/X86/cpus-other.ll
+++ llvm/test/CodeGen/X86/cpus-other.ll
@@ -16,6 +16,11 @@
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=c3 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=c3-2 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 
+;; x86-64 micro-architecture levels.
+; RUN: llc %s -filetype=null -mtriple=x86_64 -mcpu=x86-64-v2
+; RUN: llc %s -filetype=null -mtriple=x86_64 -mcpu=x86-64-v3
+; RUN: llc %s -filetype=null -mtriple=x86_64 -mcpu=x86-64-v4
+
 define void @foo() {
   ret void
 }
Index: llvm/lib/Target/X86/X86.td
===
--- llvm/lib/Target/X86/X86.td
+++ llvm/lib/Target/X86/X86.td
@@ -558,18 +558,27 @@
 //===--===//
 
 def ProcessorFeatures {
+  // x86-64 and x86-64-v[234]
+  list X86_64V1Features = [
+FeatureX87, FeatureCMPXCHG8B, FeatureCMOV, FeatureMMX, FeatureSSE2,
+FeatureFXSR, FeatureNOPL, Feature64Bit
+  ];
+  list X86_64V2Features = !listconcat(
+  X86_64V1Features,
+  [FeatureCMPXCHG16B, FeatureLAHFSAHF, FeaturePOPCNT, FeatureSSE42]);
+  list X86_64V3Features = !listconcat(X86_64V2Features, [
+FeatureAVX2, FeatureBMI, FeatureBMI2, FeatureF16C, FeatureFMA, FeatureLZCNT,
+FeatureMOVBE, FeatureXSAVE
+  ]);
+  list X86_64V4Features = !listconcat(X86_64V3Features, [
+FeatureBWI,
+FeatureCDI,
+FeatureDQI,
+FeatureVLX,
+  ]);
+
   // Nehalem
-  list NHMFeatures = [FeatureX87,
-FeatureCMPXCHG8B,
-FeatureCMOV,
-FeatureMMX,
-FeatureSSE42,
-FeatureFXSR,
-FeatureNOPL,
-Feature64Bit,
-FeatureCMPXCHG16B,
-FeaturePOPCNT,
-FeatureLAHFSAHF];
+  list NHMFeatures = X86_64V2Features;
   list NHMTuning = [FeatureMacroFusion,
   FeatureInsertVZEROUPPER];
 
@@ -1350,16 +1359,7 @@
 // covers a huge swath of x86 processors. If there are specific scheduling
 // knobs which need to be tuned differently for AMD chips, we might consider
 // forming a common base for them.
-def : ProcModel<"x86-64", SandyBridgeModel, [
-  FeatureX87,
-  FeatureCMPXCHG8B,
-  FeatureCMOV,
-  FeatureMMX,
-  FeatureSSE2,
-  FeatureFXSR,
-  FeatureNOPL,
-  Feature64Bit,
-],
+def : ProcModel<"x86-64", SandyBridgeModel, ProcessorFeatures.X86_64V1Features,
 [
   FeatureSlow3OpsLEA,
   FeatureSlowDivide64,
@@ -1368,6 +1368,16 @@
   FeatureInsertVZEROUPPER
 ]>;
 
+// x86-64 micro-architecture levels.
+def : ProcModel<"x86-64-v2", SandyBridgeModel, ProcessorFeatures.X86_64V2Features,
+ProcessorFeatures.SNBTuning>;
+// Close to Haswell.
+def : ProcModel<"x86-64-v3", HaswellModel, ProcessorFeatures.X86_64V3Features,
+ProcessorFeatures.HSWTuning>;
+// Close to the AVX-512 level implemented by Xeon Scalable Processors.
+def : ProcModel<"x86-64-v4", HaswellModel, ProcessorFeatures.X86_64V4Features,
+ProcessorFeatures.SKXTuning>;
+
 //===--===//
 // Calling Conventions
 //===--===//
Index: llvm/lib/Support/X86TargetParser.cpp
===
--- llvm/lib/Support/X86TargetParser.cpp
+++ llvm/lib/Support/X86TargetParser.cpp
@@ -137,6 +137,15 @@
 
 // Basic 64-bit capable CPU.
 constexpr FeatureBitset FeaturesX86_64 = FeaturesPentium4 | Feature64BIT;
+constexpr FeatureBitset FeaturesX86_64_V2 = FeaturesX

[PATCH] D89197: [X86] Support -march=x86-64-v[234]

2020-10-12 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay marked an inline comment as done.
MaskRay added inline comments.



Comment at: clang/docs/ReleaseNotes.rst:191
 
-- Support for -march=sapphirerapids was added.
+* Support for ``-march=sapphirerapids`` and ``-march=x86-64-v[234]`` has been 
added.
 

RKSimon wrote:
> Fix the bullet point: '-'
> 
> Please can you extend this and describe whats in each level? It'd be good to 
> have this in a longer term doc as well as the release notes will get wiped at 
> 13.0.
Extended a bit. I think it is sufficient to include a link 
https://gitlab.com/x86-psABIs/x86-64-ABI/-/commit/77566eb03bc6a326811cb7e9 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89197/new/

https://reviews.llvm.org/D89197

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


[PATCH] D87604: [X86] Convert integer _mm_reduce_* intrinsics to emit llvm.reduction intrinsics (PR47506)

2020-10-12 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added a comment.

Ping?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87604/new/

https://reviews.llvm.org/D87604

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


[PATCH] D88984: Prefer libc++ headers in the -isysroot over the toolchain

2020-10-12 Thread Raphael Isemann via Phabricator via cfe-commits
teemperor added a comment.

From the LLDB side we can just change our test setup to explicitly add an 
include the libc++ in our build tree (and have -nostdinc to avoid the libc++ in 
the SDK). So it wouldn't be a problem for us. I can make a review for that once 
this gets accepted.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88984/new/

https://reviews.llvm.org/D88984

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


[PATCH] D89197: [X86] Support -march=x86-64-v[234]

2020-10-12 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added a comment.

I'd prefer that our docs explicitly state what we've implemented instead of 
just referencing an external webpage.

Please add the full explanation to UserManual.rst under the "CPU Architectures 
Features and Limitations" x86 section for long term reference - the release 
notes can then just summarize it (and link to UserManual).

Sorry for pressuring on this but the lack of clear documentation on these 
abstractions is something that worries me.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89197/new/

https://reviews.llvm.org/D89197

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


[PATCH] D87360: clang-cl: Alias /wd4101 to -Wno-unused-variable

2020-10-12 Thread Ilia K via Phabricator via cfe-commits
ki.stfu added a comment.

@rsmith Friendly ping.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87360/new/

https://reviews.llvm.org/D87360

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


[PATCH] D87368: clang-cl: Alias /wd5054 to -Wno-deprecated-anon-enum-enum-conversion

2020-10-12 Thread Ilia K via Phabricator via cfe-commits
ki.stfu added a comment.

@rsmith Friendly ping.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87368/new/

https://reviews.llvm.org/D87368

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


[PATCH] D87364: clang-cl: Alias /wd4238 to -Wno-address-of-temporary

2020-10-12 Thread Ilia K via Phabricator via cfe-commits
ki.stfu added a comment.

@rsmith Friendly ping.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87364/new/

https://reviews.llvm.org/D87364

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


[PATCH] D87372: clang-cl: Ignore /Zc:externConstexpr and /Zc:throwingNew

2020-10-12 Thread Ilia K via Phabricator via cfe-commits
ki.stfu added a comment.

@rsmith Friendly ping.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87372/new/

https://reviews.llvm.org/D87372

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


[PATCH] D89197: [X86] Support -march=x86-64-v[234]

2020-10-12 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 297612.
MaskRay added a comment.

Update clang/docs/UsersManual.rst


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89197/new/

https://reviews.llvm.org/D89197

Files:
  clang/docs/ReleaseNotes.rst
  clang/docs/UsersManual.rst
  clang/lib/Basic/Targets/X86.cpp
  clang/lib/Basic/Targets/X86.h
  clang/test/CodeGen/attr-target-x86.c
  clang/test/Driver/x86-march.c
  clang/test/Driver/x86-mtune.c
  clang/test/Misc/target-invalid-cpu-note.c
  clang/test/Preprocessor/predefined-arch-macros-x86.c
  clang/test/Preprocessor/predefined-arch-macros.c
  clang/test/Sema/builtin-cpu-supports.c
  llvm/docs/ReleaseNotes.rst
  llvm/include/llvm/Support/X86TargetParser.h
  llvm/lib/Support/X86TargetParser.cpp
  llvm/lib/Target/X86/X86.td
  llvm/test/CodeGen/X86/cpus-other.ll

Index: llvm/test/CodeGen/X86/cpus-other.ll
===
--- llvm/test/CodeGen/X86/cpus-other.ll
+++ llvm/test/CodeGen/X86/cpus-other.ll
@@ -16,6 +16,11 @@
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=c3 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=c3-2 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 
+;; x86-64 micro-architecture levels.
+; RUN: llc %s -filetype=null -mtriple=x86_64 -mcpu=x86-64-v2
+; RUN: llc %s -filetype=null -mtriple=x86_64 -mcpu=x86-64-v3
+; RUN: llc %s -filetype=null -mtriple=x86_64 -mcpu=x86-64-v4
+
 define void @foo() {
   ret void
 }
Index: llvm/lib/Target/X86/X86.td
===
--- llvm/lib/Target/X86/X86.td
+++ llvm/lib/Target/X86/X86.td
@@ -558,18 +558,27 @@
 //===--===//
 
 def ProcessorFeatures {
+  // x86-64 and x86-64-v[234]
+  list X86_64V1Features = [
+FeatureX87, FeatureCMPXCHG8B, FeatureCMOV, FeatureMMX, FeatureSSE2,
+FeatureFXSR, FeatureNOPL, Feature64Bit
+  ];
+  list X86_64V2Features = !listconcat(
+  X86_64V1Features,
+  [FeatureCMPXCHG16B, FeatureLAHFSAHF, FeaturePOPCNT, FeatureSSE42]);
+  list X86_64V3Features = !listconcat(X86_64V2Features, [
+FeatureAVX2, FeatureBMI, FeatureBMI2, FeatureF16C, FeatureFMA, FeatureLZCNT,
+FeatureMOVBE, FeatureXSAVE
+  ]);
+  list X86_64V4Features = !listconcat(X86_64V3Features, [
+FeatureBWI,
+FeatureCDI,
+FeatureDQI,
+FeatureVLX,
+  ]);
+
   // Nehalem
-  list NHMFeatures = [FeatureX87,
-FeatureCMPXCHG8B,
-FeatureCMOV,
-FeatureMMX,
-FeatureSSE42,
-FeatureFXSR,
-FeatureNOPL,
-Feature64Bit,
-FeatureCMPXCHG16B,
-FeaturePOPCNT,
-FeatureLAHFSAHF];
+  list NHMFeatures = X86_64V2Features;
   list NHMTuning = [FeatureMacroFusion,
   FeatureInsertVZEROUPPER];
 
@@ -1350,16 +1359,7 @@
 // covers a huge swath of x86 processors. If there are specific scheduling
 // knobs which need to be tuned differently for AMD chips, we might consider
 // forming a common base for them.
-def : ProcModel<"x86-64", SandyBridgeModel, [
-  FeatureX87,
-  FeatureCMPXCHG8B,
-  FeatureCMOV,
-  FeatureMMX,
-  FeatureSSE2,
-  FeatureFXSR,
-  FeatureNOPL,
-  Feature64Bit,
-],
+def : ProcModel<"x86-64", SandyBridgeModel, ProcessorFeatures.X86_64V1Features,
 [
   FeatureSlow3OpsLEA,
   FeatureSlowDivide64,
@@ -1368,6 +1368,16 @@
   FeatureInsertVZEROUPPER
 ]>;
 
+// x86-64 micro-architecture levels.
+def : ProcModel<"x86-64-v2", SandyBridgeModel, ProcessorFeatures.X86_64V2Features,
+ProcessorFeatures.SNBTuning>;
+// Close to Haswell.
+def : ProcModel<"x86-64-v3", HaswellModel, ProcessorFeatures.X86_64V3Features,
+ProcessorFeatures.HSWTuning>;
+// Close to the AVX-512 level implemented by Xeon Scalable Processors.
+def : ProcModel<"x86-64-v4", HaswellModel, ProcessorFeatures.X86_64V4Features,
+ProcessorFeatures.SKXTuning>;
+
 //===--===//
 // Calling Conventions
 //===--===//
Index: llvm/lib/Support/X86TargetParser.cpp
===
--- llvm/lib/Support/X86TargetParser.cpp
+++ llvm/lib/Support/X86TargetParser.cpp
@@ -137,6 +137,15 @@
 
 // Basic 64-bit capable CPU.
 constexpr FeatureBitset FeaturesX86_64 = FeaturesPentium4 | Feature64BIT;
+constexpr FeatureBitset FeaturesX86_64_V2 = FeaturesX86_64 | FeatureSAHF |
+  

[PATCH] D72932: [ARM] Follow AACPS standard for volatile bit-fields access width

2020-10-12 Thread Oliver Stannard (Linaro) via Phabricator via cfe-commits
ostannard accepted this revision.
ostannard added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72932/new/

https://reviews.llvm.org/D72932

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


[PATCH] D89197: [X86] Support -march=x86-64-v[234]

2020-10-12 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 297613.
MaskRay added a comment.

ReleaseNotes.rst: use `` :doc:`UsersManual` ``


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89197/new/

https://reviews.llvm.org/D89197

Files:
  clang/docs/ReleaseNotes.rst
  clang/docs/UsersManual.rst
  clang/lib/Basic/Targets/X86.cpp
  clang/lib/Basic/Targets/X86.h
  clang/test/CodeGen/attr-target-x86.c
  clang/test/Driver/x86-march.c
  clang/test/Driver/x86-mtune.c
  clang/test/Misc/target-invalid-cpu-note.c
  clang/test/Preprocessor/predefined-arch-macros-x86.c
  clang/test/Preprocessor/predefined-arch-macros.c
  clang/test/Sema/builtin-cpu-supports.c
  llvm/docs/ReleaseNotes.rst
  llvm/include/llvm/Support/X86TargetParser.h
  llvm/lib/Support/X86TargetParser.cpp
  llvm/lib/Target/X86/X86.td
  llvm/test/CodeGen/X86/cpus-other.ll

Index: llvm/test/CodeGen/X86/cpus-other.ll
===
--- llvm/test/CodeGen/X86/cpus-other.ll
+++ llvm/test/CodeGen/X86/cpus-other.ll
@@ -16,6 +16,11 @@
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=c3 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=c3-2 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 
+;; x86-64 micro-architecture levels.
+; RUN: llc %s -filetype=null -mtriple=x86_64 -mcpu=x86-64-v2
+; RUN: llc %s -filetype=null -mtriple=x86_64 -mcpu=x86-64-v3
+; RUN: llc %s -filetype=null -mtriple=x86_64 -mcpu=x86-64-v4
+
 define void @foo() {
   ret void
 }
Index: llvm/lib/Target/X86/X86.td
===
--- llvm/lib/Target/X86/X86.td
+++ llvm/lib/Target/X86/X86.td
@@ -558,18 +558,27 @@
 //===--===//
 
 def ProcessorFeatures {
+  // x86-64 and x86-64-v[234]
+  list X86_64V1Features = [
+FeatureX87, FeatureCMPXCHG8B, FeatureCMOV, FeatureMMX, FeatureSSE2,
+FeatureFXSR, FeatureNOPL, Feature64Bit
+  ];
+  list X86_64V2Features = !listconcat(
+  X86_64V1Features,
+  [FeatureCMPXCHG16B, FeatureLAHFSAHF, FeaturePOPCNT, FeatureSSE42]);
+  list X86_64V3Features = !listconcat(X86_64V2Features, [
+FeatureAVX2, FeatureBMI, FeatureBMI2, FeatureF16C, FeatureFMA, FeatureLZCNT,
+FeatureMOVBE, FeatureXSAVE
+  ]);
+  list X86_64V4Features = !listconcat(X86_64V3Features, [
+FeatureBWI,
+FeatureCDI,
+FeatureDQI,
+FeatureVLX,
+  ]);
+
   // Nehalem
-  list NHMFeatures = [FeatureX87,
-FeatureCMPXCHG8B,
-FeatureCMOV,
-FeatureMMX,
-FeatureSSE42,
-FeatureFXSR,
-FeatureNOPL,
-Feature64Bit,
-FeatureCMPXCHG16B,
-FeaturePOPCNT,
-FeatureLAHFSAHF];
+  list NHMFeatures = X86_64V2Features;
   list NHMTuning = [FeatureMacroFusion,
   FeatureInsertVZEROUPPER];
 
@@ -1350,16 +1359,7 @@
 // covers a huge swath of x86 processors. If there are specific scheduling
 // knobs which need to be tuned differently for AMD chips, we might consider
 // forming a common base for them.
-def : ProcModel<"x86-64", SandyBridgeModel, [
-  FeatureX87,
-  FeatureCMPXCHG8B,
-  FeatureCMOV,
-  FeatureMMX,
-  FeatureSSE2,
-  FeatureFXSR,
-  FeatureNOPL,
-  Feature64Bit,
-],
+def : ProcModel<"x86-64", SandyBridgeModel, ProcessorFeatures.X86_64V1Features,
 [
   FeatureSlow3OpsLEA,
   FeatureSlowDivide64,
@@ -1368,6 +1368,16 @@
   FeatureInsertVZEROUPPER
 ]>;
 
+// x86-64 micro-architecture levels.
+def : ProcModel<"x86-64-v2", SandyBridgeModel, ProcessorFeatures.X86_64V2Features,
+ProcessorFeatures.SNBTuning>;
+// Close to Haswell.
+def : ProcModel<"x86-64-v3", HaswellModel, ProcessorFeatures.X86_64V3Features,
+ProcessorFeatures.HSWTuning>;
+// Close to the AVX-512 level implemented by Xeon Scalable Processors.
+def : ProcModel<"x86-64-v4", HaswellModel, ProcessorFeatures.X86_64V4Features,
+ProcessorFeatures.SKXTuning>;
+
 //===--===//
 // Calling Conventions
 //===--===//
Index: llvm/lib/Support/X86TargetParser.cpp
===
--- llvm/lib/Support/X86TargetParser.cpp
+++ llvm/lib/Support/X86TargetParser.cpp
@@ -137,6 +137,15 @@
 
 // Basic 64-bit capable CPU.
 constexpr FeatureBitset FeaturesX86_64 = FeaturesPentium4 | Feature64BIT;
+constexpr FeatureBitset FeaturesX86_64_V2 = FeaturesX86_64 | FeatureSAHF |
+ 

[PATCH] D66782: SourceManager: Prefer Optional over MemoryBuffer*

2020-10-12 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added inline comments.



Comment at: clang-tools-extra/clangd/SourceCode.cpp:459
 Position P) {
-  llvm::StringRef Code = SM.getBuffer(SM.getMainFileID())->getBuffer();
+  llvm::StringRef Code = SM.getBufferOrFake(SM.getMainFileID()).getBuffer();
   auto Offset =

I feel like all buffer requests for the main file should succeed and shouldn't 
need the fake buffer, unless something gone terribly wrong, Do you agree? Do 
you think it might be valuable to add a method like `SM.getMainFileBuffer` 
which has an `llvm_unreachable` if buffer is invalid?



Comment at: clang/include/clang/Basic/SourceManager.h:303
 
+static FileInfo getForRecovery() {
+  FileInfo X = get(SourceLocation(), nullptr, SrcMgr::C_User, "");

This doesn't seem to be used in this patch, is this dead code?



Comment at: clang/lib/Basic/SourceLocation.cpp:253
+  if (Buffer)
+return Buffer->getBuffer();
+  return "";

Can be simplified to `return Buffer ? Buffer->getBuffer() : ""`



Comment at: clang/lib/Basic/SourceManager.cpp:1179
+*Invalid = !Buffer;
+  return Buffer ? Buffer->getBufferStart() + LocInfo.second : nullptr;
 }

How come you're returning `nullptr` here instead of `"<<<>>>"` 
like in the error condition above? It seems that clients will not be able to 
handle this nullptr.



Comment at: clang/lib/Basic/SourceManager.cpp:1467
+return Buffer->getBufferIdentifier();
+  return "";
 }

Should you return `""` here to be consistent with the `"invalid 
loc"` above?



Comment at: clang/lib/Basic/SourceManager.cpp:1698
+if (llvm::Optional RawSize =
+Content->getBufferSize(Diag, getFileManager()))
+  if (*RawSize > 0)

NIT: Please use `{}` for the outer `if`



Comment at: clang/lib/Basic/SourceManager.cpp:1706
+  Content->getBuffer(Diag, getFileManager());
   unsigned FilePos = Content->SourceLineCache[Line - 1];
   const char *Buf = Buffer->getBufferStart() + FilePos;

It appears you're not checking if `Buffer` is `None` here. Previously this 
should've been fine as it seems `getBuffer` created fake recovery buffers.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66782/new/

https://reviews.llvm.org/D66782

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


[PATCH] D89066: [Coroutine][Sema] Only tighten the suspend call temp lifetime for final awaiter

2020-10-12 Thread Xun Li via Phabricator via cfe-commits
lxfind added a comment.

In D89066#2324291 , @junparser wrote:

> In D89066#2324151 , @lxfind wrote:
>
>> In D89066#2324115 , @junparser 
>> wrote:
>>
>>> why we should not do this with normal await call?
>>
>> To be honest, I don't know yet. My understanding of how expression cleanup 
>> and temp lifetime management is insufficient at the moment.
>> But first of all, without adding any cleanup expression here, I saw ASAN 
>> failures due to heap-use-after-free, because sometimes the frame have 
>> already been destroyed after the await_suspend call, and yet we are still 
>> writing into the frame due to unnecessarily cross-suspend lifetime. However, 
>> if I apply the cleanup to all await_suepend calls, it also causes ASAN 
>> failures as it's cleaning up data that's still alive.
>> So this patch is more of a temporary walkaround to stop bleeding without 
>> causing any trouble.
>> I plan to get back to this latter after I am done with the spilling/alloca 
>> issues.
>
> I'm not familiar with ASAN instrumentation. Do you have any testcases to 
> explain this?

Unfortunately I don't.  But this is not related to ASAN. Basically, this is 
causing destructing of objects that should still be alive. I suspect that it's 
because ExprWithCleanups always clean up temps that belongs to the full 
expression, not just the sub-expression in it.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89066/new/

https://reviews.llvm.org/D89066

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


[PATCH] D89136: Lex: Avoid MemoryBuffer* key in ExcludedPreprocessorDirectiveSkipMapping, NFC

2020-10-12 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added inline comments.



Comment at: 
clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp:222
 
-  const llvm::MemoryBuffer *getBufferPtr() const { return Buffer.get(); }
+  const char *getBufferPtr() const {
+return Buffer ? nullptr : Buffer->getBufferStart();

Looking over the code this method doesn't seem necessary anymore. Can you get 
the buffer pointer in `createFile` down below, after 
`llvm::MemoryBuffer::getMemBuffer(*Contents, Entry->getName(), 
/*RequiresNullTerminator=*/false)` is constructed?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89136/new/

https://reviews.llvm.org/D89136

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


[PATCH] D89204: Make likelihood lit test less brittle

2020-10-12 Thread Mark de Wever via Phabricator via cfe-commits
Mordante added a comment.

In D89204#2324563 , @jmorse wrote:

> This fixes things for us, and by limiting to one optimisation pass it's much 
> less brittle for the future -- much appreciated!

I'm glad to hear it fixes your issue. Thanks for testing!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89204/new/

https://reviews.llvm.org/D89204

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


[PATCH] D89204: Make likelihood lit test less brittle

2020-10-12 Thread Mark de Wever via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG551caec4a8af: Make likelihood lit test less brittle 
(authored by Mordante).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89204/new/

https://reviews.llvm.org/D89204

Files:
  clang/test/CodeGenCXX/attr-likelihood-if-vs-builtin-expect.cpp

Index: clang/test/CodeGenCXX/attr-likelihood-if-vs-builtin-expect.cpp
===
--- clang/test/CodeGenCXX/attr-likelihood-if-vs-builtin-expect.cpp
+++ clang/test/CodeGenCXX/attr-likelihood-if-vs-builtin-expect.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -O1 -emit-llvm %s -o - -triple=x86_64-linux-gnu | FileCheck %s
+// RUN: %clang_cc1 -O1 -disable-llvm-passes -emit-llvm %s -o - -triple=x86_64-linux-gnu | opt --lower-expect -S | FileCheck %s
 
 // Verifies the output of __builtin_expect versus the output of the likelihood
 // attributes. They should generate the same probabilities for the branches.
@@ -9,9 +9,9 @@
 
 void ab1(int &i) {
   // CHECK-LABEL: define{{.*}}ab1
-  // CHECK: br {{.*}} !prof !2
-  // CHECK: br {{.*}} !prof !2
-  // CHECK: br {{.*}} !prof !2
+  // CHECK: br {{.*}} !prof !6
+  // CHECK: br {{.*}} !prof !6
+  // CHECK: br {{.*}} !prof !6
   if (__builtin_expect(a() && b() && a(), 1)) {
 ++i;
   } else {
@@ -21,9 +21,9 @@
 
 void al(int &i) {
   // CHECK-LABEL: define{{.*}}al
-  // CHECK: br {{.*}} !prof !2
-  // CHECK: br {{.*}} !prof !2
-  // CHECK: br {{.*}} !prof !2
+  // CHECK: br {{.*}} !prof !6
+  // CHECK: br {{.*}} !prof !6
+  // CHECK: br {{.*}} !prof !6
   if (a() && b() && c()) [[likely]] {
 ++i;
   } else {
@@ -33,9 +33,10 @@
 
 void ab0(int &i) {
   // CHECK-LABEL: define{{.*}}ab0
-  // CHECK: br {{.*}}else{{$}}
-  // CHECK: br {{.*}}else{{$}}
-  // CHECK: br {{.*}} !prof !8
+  // CHECK: br {{.*}}end{{$}}
+  // CHECK: br {{.*}}end{{$}}
+  // CHECK: br {{.*}}end{{$}}
+  // CHECK: br {{.*}} !prof !10
   if (__builtin_expect(a() && b() && c(), 0)) {
 ++i;
   } else {
@@ -47,7 +48,7 @@
   // CHECK-LABEL: define{{.*}}au
   // CHECK: br {{.*}}else{{$}}
   // CHECK: br {{.*}}else{{$}}
-  // CHECK: br {{.*}} !prof !8
+  // CHECK: br {{.*}} !prof !10
   if (a() && b() && c()) [[unlikely]] {
 ++i;
   } else {
@@ -59,7 +60,8 @@
   // CHECK-LABEL: define{{.*}}ob1
   // CHECK: br {{.*}}false{{$}}
   // CHECK: br {{.*}}rhs{{$}}
-  // CHECK: br {{.*}} !prof !2
+  // CHECK: br {{.*}}end{{$}}
+  // CHECK: br {{.*}} !prof !6
   if (__builtin_expect(a() || b() || a(), 1)) {
 i = 0;
   } else {
@@ -71,7 +73,7 @@
   // CHECK-LABEL: define{{.*}}ol
   // CHECK: br {{.*}}false{{$}}
   // CHECK: br {{.*}}false2{{$}}
-  // CHECK: br {{.*}} !prof !2
+  // CHECK: br {{.*}} !prof !6
   if (a() || b() || c()) [[likely]] {
 i = 0;
   } else {
@@ -81,9 +83,9 @@
 
 void ob0(int &i) {
   // CHECK-LABEL: define{{.*}}ob0
-  // CHECK: br {{.*}} !prof !8
-  // CHECK: br {{.*}} !prof !8
-  // CHECK: br {{.*}} !prof !8
+  // CHECK: br {{.*}} !prof !10
+  // CHECK: br {{.*}} !prof !10
+  // CHECK: br {{.*}} !prof !10
   if (__builtin_expect(a() || b() || c(), 0)) {
 i = 0;
   } else {
@@ -93,9 +95,9 @@
 
 void ou(int &i) {
   // CHECK-LABEL: define{{.*}}ou
-  // CHECK: br {{.*}} !prof !8
-  // CHECK: br {{.*}} !prof !8
-  // CHECK: br {{.*}} !prof !8
+  // CHECK: br {{.*}} !prof !10
+  // CHECK: br {{.*}} !prof !10
+  // CHECK: br {{.*}} !prof !10
   if (a() || b() || c()) [[unlikely]] {
 i = 0;
   } else {
@@ -105,7 +107,7 @@
 
 void nb1(int &i) {
   // CHECK-LABEL: define{{.*}}nb1
-  // CHECK: storemerge{{.*}} !prof !8
+  // CHECK: br {{.*}} !prof !6
   if (__builtin_expect(!a(), 1)) {
 ++i;
   } else {
@@ -115,8 +117,8 @@
 
 void nl(int &i) {
   // CHECK-LABEL: define{{.*}}nl
-  // CHECK: storemerge{{.*}} !prof !8
-  if (!a()) [[likely]] {
+  // CHECK: br {{.*}} !prof !6
+  if (bool d = !a()) [[likely]] {
 ++i;
   } else {
 --i;
@@ -125,7 +127,7 @@
 
 void nb0(int &i) {
   // CHECK-LABEL: define{{.*}}nb0
-  // CHECK: storemerge{{.*}} !prof !2
+  // CHECK: br {{.*}} !prof !10
   if (__builtin_expect(!a(), 0)) {
 ++i;
   } else {
@@ -135,8 +137,8 @@
 
 void nu(int &i) {
   // CHECK-LABEL: define{{.*}}nu
-  // CHECK: storemerge{{.*}} !prof !2
-  if (!a()) [[unlikely]] {
+  // CHECK: br {{.*}} !prof !10
+  if (bool d = !a()) [[unlikely]] {
 ++i;
   } else {
 --i;
@@ -148,7 +150,7 @@
   // CHECK: br {{.*}}false{{$}}
   // CHECK: br {{.*}}end{{$}}
   // CHECK: br {{.*}}end{{$}}
-  // CHECK: storemerge{{.*}} !prof !2
+  // CHECK: br {{.*}} !prof !6
   if (__builtin_expect(a() ? b() : c(), 1)) {
 ++i;
   } else {
@@ -161,7 +163,7 @@
   // CHECK: br {{.*}}false{{$}}
   // CHECK: br {{.*}}end{{$}}
   // CHECK: br {{.*}}end{{$}}
-  // CHECK: storemerge{{.*}} !prof !2
+  // CHECK: br {{.*}} !prof !6
   if (bool d = a() ? b() : c()) [[likely]] {
 ++i;
   } else {
@@ -172,8 +174,

[clang] 551caec - Make likelihood lit test less brittle

2020-10-12 Thread Mark de Wever via cfe-commits

Author: Mark de Wever
Date: 2020-10-12T18:58:21+02:00
New Revision: 551caec4a8af79483823e2940d40afb4c1df5da1

URL: 
https://github.com/llvm/llvm-project/commit/551caec4a8af79483823e2940d40afb4c1df5da1
DIFF: 
https://github.com/llvm/llvm-project/commit/551caec4a8af79483823e2940d40afb4c1df5da1.diff

LOG: Make likelihood lit test less brittle

Jeremy Morse discovered an issue with the lit test introduced in D88363. The
test gives different results for Sony's `-O1`.

The test needs to run at `-O1` otherwise the likelihood attribute will be
ignored. Instead of running all `-O1` passes it only runs the lower-expect pass
which is needed to lower `__builtin_expect`.

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

Added: 


Modified: 
clang/test/CodeGenCXX/attr-likelihood-if-vs-builtin-expect.cpp

Removed: 




diff  --git a/clang/test/CodeGenCXX/attr-likelihood-if-vs-builtin-expect.cpp 
b/clang/test/CodeGenCXX/attr-likelihood-if-vs-builtin-expect.cpp
index 5e73cd096742..5872c4c5273f 100644
--- a/clang/test/CodeGenCXX/attr-likelihood-if-vs-builtin-expect.cpp
+++ b/clang/test/CodeGenCXX/attr-likelihood-if-vs-builtin-expect.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -O1 -emit-llvm %s -o - -triple=x86_64-linux-gnu | FileCheck 
%s
+// RUN: %clang_cc1 -O1 -disable-llvm-passes -emit-llvm %s -o - 
-triple=x86_64-linux-gnu | opt --lower-expect -S | FileCheck %s
 
 // Verifies the output of __builtin_expect versus the output of the likelihood
 // attributes. They should generate the same probabilities for the branches.
@@ -9,9 +9,9 @@ extern bool c();
 
 void ab1(int &i) {
   // CHECK-LABEL: define{{.*}}ab1
-  // CHECK: br {{.*}} !prof !2
-  // CHECK: br {{.*}} !prof !2
-  // CHECK: br {{.*}} !prof !2
+  // CHECK: br {{.*}} !prof !6
+  // CHECK: br {{.*}} !prof !6
+  // CHECK: br {{.*}} !prof !6
   if (__builtin_expect(a() && b() && a(), 1)) {
 ++i;
   } else {
@@ -21,9 +21,9 @@ void ab1(int &i) {
 
 void al(int &i) {
   // CHECK-LABEL: define{{.*}}al
-  // CHECK: br {{.*}} !prof !2
-  // CHECK: br {{.*}} !prof !2
-  // CHECK: br {{.*}} !prof !2
+  // CHECK: br {{.*}} !prof !6
+  // CHECK: br {{.*}} !prof !6
+  // CHECK: br {{.*}} !prof !6
   if (a() && b() && c()) [[likely]] {
 ++i;
   } else {
@@ -33,9 +33,10 @@ void al(int &i) {
 
 void ab0(int &i) {
   // CHECK-LABEL: define{{.*}}ab0
-  // CHECK: br {{.*}}else{{$}}
-  // CHECK: br {{.*}}else{{$}}
-  // CHECK: br {{.*}} !prof !8
+  // CHECK: br {{.*}}end{{$}}
+  // CHECK: br {{.*}}end{{$}}
+  // CHECK: br {{.*}}end{{$}}
+  // CHECK: br {{.*}} !prof !10
   if (__builtin_expect(a() && b() && c(), 0)) {
 ++i;
   } else {
@@ -47,7 +48,7 @@ void au(int &i) {
   // CHECK-LABEL: define{{.*}}au
   // CHECK: br {{.*}}else{{$}}
   // CHECK: br {{.*}}else{{$}}
-  // CHECK: br {{.*}} !prof !8
+  // CHECK: br {{.*}} !prof !10
   if (a() && b() && c()) [[unlikely]] {
 ++i;
   } else {
@@ -59,7 +60,8 @@ void ob1(int &i) {
   // CHECK-LABEL: define{{.*}}ob1
   // CHECK: br {{.*}}false{{$}}
   // CHECK: br {{.*}}rhs{{$}}
-  // CHECK: br {{.*}} !prof !2
+  // CHECK: br {{.*}}end{{$}}
+  // CHECK: br {{.*}} !prof !6
   if (__builtin_expect(a() || b() || a(), 1)) {
 i = 0;
   } else {
@@ -71,7 +73,7 @@ void ol(int &i) {
   // CHECK-LABEL: define{{.*}}ol
   // CHECK: br {{.*}}false{{$}}
   // CHECK: br {{.*}}false2{{$}}
-  // CHECK: br {{.*}} !prof !2
+  // CHECK: br {{.*}} !prof !6
   if (a() || b() || c()) [[likely]] {
 i = 0;
   } else {
@@ -81,9 +83,9 @@ void ol(int &i) {
 
 void ob0(int &i) {
   // CHECK-LABEL: define{{.*}}ob0
-  // CHECK: br {{.*}} !prof !8
-  // CHECK: br {{.*}} !prof !8
-  // CHECK: br {{.*}} !prof !8
+  // CHECK: br {{.*}} !prof !10
+  // CHECK: br {{.*}} !prof !10
+  // CHECK: br {{.*}} !prof !10
   if (__builtin_expect(a() || b() || c(), 0)) {
 i = 0;
   } else {
@@ -93,9 +95,9 @@ void ob0(int &i) {
 
 void ou(int &i) {
   // CHECK-LABEL: define{{.*}}ou
-  // CHECK: br {{.*}} !prof !8
-  // CHECK: br {{.*}} !prof !8
-  // CHECK: br {{.*}} !prof !8
+  // CHECK: br {{.*}} !prof !10
+  // CHECK: br {{.*}} !prof !10
+  // CHECK: br {{.*}} !prof !10
   if (a() || b() || c()) [[unlikely]] {
 i = 0;
   } else {
@@ -105,7 +107,7 @@ void ou(int &i) {
 
 void nb1(int &i) {
   // CHECK-LABEL: define{{.*}}nb1
-  // CHECK: storemerge{{.*}} !prof !8
+  // CHECK: br {{.*}} !prof !6
   if (__builtin_expect(!a(), 1)) {
 ++i;
   } else {
@@ -115,8 +117,8 @@ void nb1(int &i) {
 
 void nl(int &i) {
   // CHECK-LABEL: define{{.*}}nl
-  // CHECK: storemerge{{.*}} !prof !8
-  if (!a()) [[likely]] {
+  // CHECK: br {{.*}} !prof !6
+  if (bool d = !a()) [[likely]] {
 ++i;
   } else {
 --i;
@@ -125,7 +127,7 @@ void nl(int &i) {
 
 void nb0(int &i) {
   // CHECK-LABEL: define{{.*}}nb0
-  // CHECK: storemerge{{.*}} !prof !2
+  // CHECK: br {{.*}} !prof !10
   if (__builtin_expect(!a(), 0)) {
 ++i;
   } else {
@@ -135,8 +137,8 @@ void nb0(int &i) {

[PATCH] D79388: [clang-format] Fix AlignConsecutive on PP blocks

2020-10-12 Thread Sylvestre Ledru via Phabricator via cfe-commits
sylvestre.ledru added a comment.

@JakeMerdichAMD as the regression caused by this change is way more significant 
than the initial bug, I am planning to revert this patch in the next few days 
(both in master and 11).
Please let me know if you have any objection.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79388/new/

https://reviews.llvm.org/D79388

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


[PATCH] D76620: [SYCL] Implement __builtin_unique_stable_name.

2020-10-12 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Thank you.  If it were SYCL-namespaced and -restricted, that would be fine, but 
as is it's positioned as a generic language feature.  (I think we might still 
have had implementation/design feedback, though.)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76620/new/

https://reviews.llvm.org/D76620

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


[PATCH] D89197: [X86] Support -march=x86-64-v[234]

2020-10-12 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon accepted this revision.
RKSimon added a comment.
This revision is now accepted and ready to land.

LGTM - thank you!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89197/new/

https://reviews.llvm.org/D89197

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


[PATCH] D89197: [X86] Support -march=x86-64-v[234]

2020-10-12 Thread Fangrui Song via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG012dd42e027e: [X86] Support -march=x86-64-v[234] (authored 
by MaskRay).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89197/new/

https://reviews.llvm.org/D89197

Files:
  clang/docs/ReleaseNotes.rst
  clang/docs/UsersManual.rst
  clang/lib/Basic/Targets/X86.cpp
  clang/lib/Basic/Targets/X86.h
  clang/test/CodeGen/attr-target-x86.c
  clang/test/Driver/x86-march.c
  clang/test/Driver/x86-mtune.c
  clang/test/Misc/target-invalid-cpu-note.c
  clang/test/Preprocessor/predefined-arch-macros-x86.c
  clang/test/Preprocessor/predefined-arch-macros.c
  clang/test/Sema/builtin-cpu-supports.c
  llvm/docs/ReleaseNotes.rst
  llvm/include/llvm/Support/X86TargetParser.h
  llvm/lib/Support/X86TargetParser.cpp
  llvm/lib/Target/X86/X86.td
  llvm/test/CodeGen/X86/cpus-other.ll

Index: llvm/test/CodeGen/X86/cpus-other.ll
===
--- llvm/test/CodeGen/X86/cpus-other.ll
+++ llvm/test/CodeGen/X86/cpus-other.ll
@@ -16,6 +16,11 @@
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=c3 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=c3-2 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 
+;; x86-64 micro-architecture levels.
+; RUN: llc %s -filetype=null -mtriple=x86_64 -mcpu=x86-64-v2
+; RUN: llc %s -filetype=null -mtriple=x86_64 -mcpu=x86-64-v3
+; RUN: llc %s -filetype=null -mtriple=x86_64 -mcpu=x86-64-v4
+
 define void @foo() {
   ret void
 }
Index: llvm/lib/Target/X86/X86.td
===
--- llvm/lib/Target/X86/X86.td
+++ llvm/lib/Target/X86/X86.td
@@ -558,18 +558,27 @@
 //===--===//
 
 def ProcessorFeatures {
+  // x86-64 and x86-64-v[234]
+  list X86_64V1Features = [
+FeatureX87, FeatureCMPXCHG8B, FeatureCMOV, FeatureMMX, FeatureSSE2,
+FeatureFXSR, FeatureNOPL, Feature64Bit
+  ];
+  list X86_64V2Features = !listconcat(
+  X86_64V1Features,
+  [FeatureCMPXCHG16B, FeatureLAHFSAHF, FeaturePOPCNT, FeatureSSE42]);
+  list X86_64V3Features = !listconcat(X86_64V2Features, [
+FeatureAVX2, FeatureBMI, FeatureBMI2, FeatureF16C, FeatureFMA, FeatureLZCNT,
+FeatureMOVBE, FeatureXSAVE
+  ]);
+  list X86_64V4Features = !listconcat(X86_64V3Features, [
+FeatureBWI,
+FeatureCDI,
+FeatureDQI,
+FeatureVLX,
+  ]);
+
   // Nehalem
-  list NHMFeatures = [FeatureX87,
-FeatureCMPXCHG8B,
-FeatureCMOV,
-FeatureMMX,
-FeatureSSE42,
-FeatureFXSR,
-FeatureNOPL,
-Feature64Bit,
-FeatureCMPXCHG16B,
-FeaturePOPCNT,
-FeatureLAHFSAHF];
+  list NHMFeatures = X86_64V2Features;
   list NHMTuning = [FeatureMacroFusion,
   FeatureInsertVZEROUPPER];
 
@@ -1350,16 +1359,7 @@
 // covers a huge swath of x86 processors. If there are specific scheduling
 // knobs which need to be tuned differently for AMD chips, we might consider
 // forming a common base for them.
-def : ProcModel<"x86-64", SandyBridgeModel, [
-  FeatureX87,
-  FeatureCMPXCHG8B,
-  FeatureCMOV,
-  FeatureMMX,
-  FeatureSSE2,
-  FeatureFXSR,
-  FeatureNOPL,
-  Feature64Bit,
-],
+def : ProcModel<"x86-64", SandyBridgeModel, ProcessorFeatures.X86_64V1Features,
 [
   FeatureSlow3OpsLEA,
   FeatureSlowDivide64,
@@ -1368,6 +1368,16 @@
   FeatureInsertVZEROUPPER
 ]>;
 
+// x86-64 micro-architecture levels.
+def : ProcModel<"x86-64-v2", SandyBridgeModel, ProcessorFeatures.X86_64V2Features,
+ProcessorFeatures.SNBTuning>;
+// Close to Haswell.
+def : ProcModel<"x86-64-v3", HaswellModel, ProcessorFeatures.X86_64V3Features,
+ProcessorFeatures.HSWTuning>;
+// Close to the AVX-512 level implemented by Xeon Scalable Processors.
+def : ProcModel<"x86-64-v4", HaswellModel, ProcessorFeatures.X86_64V4Features,
+ProcessorFeatures.SKXTuning>;
+
 //===--===//
 // Calling Conventions
 //===--===//
Index: llvm/lib/Support/X86TargetParser.cpp
===
--- llvm/lib/Support/X86TargetParser.cpp
+++ llvm/lib/Support/X86TargetParser.cpp
@@ -137,6 +137,15 @@
 
 // Basic 64-bit capable CPU.
 constexpr FeatureBitset FeaturesX86_64 = FeaturesPentium4 

  1   2   3   >