[PATCH] D84136: [clangd] Fix visitation of ConceptSpecializationExpr in constrained-parameter

2020-07-27 Thread Nathan Ridge via Phabricator via cfe-commits
nridge updated this revision to Diff 280797.
nridge marked an inline comment as done.
nridge added a comment.
Herald added a subscriber: mgorny.

Finish addressing review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84136

Files:
  clang-tools-extra/clangd/unittests/FindTargetTests.cpp
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/unittests/Tooling/CMakeLists.txt
  clang/unittests/Tooling/RecursiveASTVisitorTests/Concept.cpp

Index: clang/unittests/Tooling/RecursiveASTVisitorTests/Concept.cpp
===
--- /dev/null
+++ clang/unittests/Tooling/RecursiveASTVisitorTests/Concept.cpp
@@ -0,0 +1,45 @@
+//===- unittest/Tooling/RecursiveASTVisitorTests/Concept.cpp
+//===//
+//
+// 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 "TestVisitor.h"
+#include "clang/AST/ExprConcepts.h"
+
+using namespace clang;
+
+namespace {
+
+struct ConceptVisitor : ExpectedLocationVisitor {
+  bool VisitConceptSpecializationExpr(ConceptSpecializationExpr *E) {
+++ConceptSpecializationExprsVisited;
+return true;
+  }
+  bool TraverseConceptReference(const ConceptReference &R) {
+++ConceptReferencesTraversed;
+return true;
+  }
+
+  int ConceptSpecializationExprsVisited = 0;
+  int ConceptReferencesTraversed = 0;
+};
+
+TEST(RecursiveASTVisitor, ConstrainedParameter) {
+  ConceptVisitor Visitor;
+  EXPECT_TRUE(Visitor.runOver("template  concept Fooable = true;\n"
+  "template  void bar(T);",
+  ConceptVisitor::Lang_CXX2a));
+  // Check that we visit the "Fooable T" template parameter's TypeConstraint's
+  // ImmediatelyDeclaredConstraint, which is a ConceptSpecializationExpr.
+  EXPECT_EQ(1, Visitor.ConceptSpecializationExprsVisited);
+  // There are two ConceptReference objects in the AST: the base subobject
+  // of the ConceptSpecializationExpr, and the base subobject of the
+  // TypeConstraint itself. Check that we traverse both.
+  EXPECT_EQ(2, Visitor.ConceptReferencesTraversed);
+}
+
+} // end anonymous namespace
Index: clang/unittests/Tooling/CMakeLists.txt
===
--- clang/unittests/Tooling/CMakeLists.txt
+++ clang/unittests/Tooling/CMakeLists.txt
@@ -30,6 +30,7 @@
   RecursiveASTVisitorTests/Attr.cpp
   RecursiveASTVisitorTests/Callbacks.cpp
   RecursiveASTVisitorTests/Class.cpp
+  RecursiveASTVisitorTests/Concept.cpp
   RecursiveASTVisitorTests/ConstructExpr.cpp
   RecursiveASTVisitorTests/CXXBoolLiteralExpr.cpp
   RecursiveASTVisitorTests/CXXMemberCall.cpp
Index: clang/include/clang/AST/RecursiveASTVisitor.h
===
--- clang/include/clang/AST/RecursiveASTVisitor.h
+++ clang/include/clang/AST/RecursiveASTVisitor.h
@@ -1777,8 +1777,10 @@
   // D is the "T" in something like "template class vector;"
   if (D->getTypeForDecl())
 TRY_TO(TraverseType(QualType(D->getTypeForDecl(), 0)));
-  if (const auto *TC = D->getTypeConstraint())
+  if (const auto *TC = D->getTypeConstraint()) {
+TRY_TO(TraverseStmt(TC->getImmediatelyDeclaredConstraint()));
 TRY_TO(TraverseConceptReference(*TC));
+  }
   if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited())
 TRY_TO(TraverseTypeLoc(D->getDefaultArgumentInfo()->getTypeLoc()));
 })
Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp
===
--- clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -405,6 +405,11 @@
 }
 
 TEST_F(TargetDeclTest, Concept) {
+  Flags.push_back("-std=c++20");
+
+  // FIXME: Should we truncate the pretty-printed form of a concept decl
+  // somewhere?
+
   Code = R"cpp(
 template 
 concept Fooable = requires (T t) { t.foo(); };
@@ -414,12 +419,31 @@
   t.foo();
 }
   )cpp";
-  Flags.push_back("-std=c++20");
   EXPECT_DECLS(
   "ConceptSpecializationExpr",
-  // FIXME: Should we truncate the pretty-printed form of a concept decl
-  // somewhere?
   {"template  concept Fooable = requires (T t) { t.foo(); };"});
+
+  // constrained-parameter
+  Code = R"cpp(
+template 
+concept Fooable = true;
+
+template <[[Fooable]] T>
+void bar(T t);
+  )cpp";
+  EXPECT_DECLS("ConceptSpecializationExpr",
+   {"template  concept Fooable = true;"});
+
+  // partial-concept-id
+  Code = R"cpp(
+template 
+concept Fooable = true;
+
+template <[[Fooable]] T>
+void bar(T t);
+  )cpp";
+  EXPECT_DECLS("ConceptSpecializationExpr",
+ 

[PATCH] D84136: [clangd] Fix visitation of ConceptSpecializationExpr in constrained-parameter

2020-07-27 Thread Nathan Ridge via Phabricator via cfe-commits
nridge marked an inline comment as done.
nridge added inline comments.



Comment at: clang-tools-extra/clangd/unittests/FindTargetTests.cpp:426
+
+  // constrained-parameter
+  Code = R"cpp(

I'd like to keep this clangd-specific test coverage as I think it's valuable to 
have. However, I can spin it off into a separate patch if you prefer.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84136



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


[PATCH] D84622: [PowerPC] Implement Vector Extract Low/High Order Builtins in LLVM/Clang

2020-07-27 Thread Biplob Mishra via Phabricator via cfe-commits
biplmish created this revision.
biplmish added reviewers: amyk, lei, steven.zhang, PowerPC.
Herald added subscribers: cfe-commits, shchenz, wuzish, kbarton, hiraditya, 
nemanjai.
Herald added projects: clang, LLVM.

This patch implements builtins for the following prototypes:

vector unsigned long long vec_extractl (vector unsigned char, vector unsigned 
char, unsigned int);
vector unsigned long long vec_extractl (vector unsigned short, vector unsigned 
short, unsigned int);
vector unsigned long long vec_extractl (vector unsigned int, vector unsigned 
int, unsigned int);
vector unsigned long long vec_extractl (vector unsigned long long, vector 
unsigned long long, unsigned int);

vector unsigned long long vec_extracth (vector unsigned char, vector unsigned 
char, unsigned int);
vector unsigned long long vec_extracth (vector unsigned short, vector unsigned 
short, unsigned int);
vector unsigned long long vec_extracth (vector unsigned int, vector unsigned 
int, unsigned int);
vector unsigned long long vec_extracth (vector unsigned long long, vector 
unsigned long long, unsigned int);


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D84622

Files:
  clang/include/clang/Basic/BuiltinsPPC.def
  clang/lib/Headers/altivec.h
  clang/test/CodeGen/builtins-ppc-p10vector.c
  llvm/include/llvm/IR/IntrinsicsPowerPC.td
  llvm/lib/Target/PowerPC/PPCInstrPrefix.td
  llvm/test/CodeGen/PowerPC/builtins-ppc-p10permute.ll

Index: llvm/test/CodeGen/PowerPC/builtins-ppc-p10permute.ll
===
--- llvm/test/CodeGen/PowerPC/builtins-ppc-p10permute.ll
+++ llvm/test/CodeGen/PowerPC/builtins-ppc-p10permute.ll
@@ -253,3 +253,91 @@
   ret <2 x i64> %0
 }
 declare <2 x i64> @llvm.ppc.altivec.vinsd(<2 x i64>, i64, i32 immarg)
+
+define <2 x i64> @testVEXTDUBVLX(<16 x i8> %a, <16 x i8> %b, i32 %c) {
+; CHECK-LABEL: testVEXTDUBVLX:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:vextdubvlx v2, v2, v3, r7
+; CHECK-NEXT:blr
+entry:
+  %0 = tail call <2 x i64> @llvm.ppc.altivec.vextdubvlx(<16 x i8> %a, <16 x i8> %b, i32 %c)
+  ret <2 x i64> %0
+}
+declare <2 x i64> @llvm.ppc.altivec.vextdubvlx(<16 x i8>, <16 x i8>, i32)
+
+define <2 x i64> @testVEXTDUBVRX(<16 x i8> %a, <16 x i8> %b, i32 %c) {
+; CHECK-LABEL: testVEXTDUBVRX:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:vextdubvrx v2, v2, v3, r7
+; CHECK-NEXT:blr
+entry:
+  %0 = tail call <2 x i64> @llvm.ppc.altivec.vextdubvrx(<16 x i8> %a, <16 x i8> %b, i32 %c)
+  ret <2 x i64> %0
+}
+declare <2 x i64> @llvm.ppc.altivec.vextdubvrx(<16 x i8>, <16 x i8>, i32)
+
+define <2 x i64> @testVEXTDUHVLX(<8 x i16> %a, <8 x i16> %b, i32 %c) {
+; CHECK-LABEL: testVEXTDUHVLX:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:vextduhvlx v2, v2, v3, r7
+; CHECK-NEXT:blr
+entry:
+  %0 = tail call <2 x i64> @llvm.ppc.altivec.vextduhvlx(<8 x i16> %a, <8 x i16> %b, i32 %c)
+  ret <2 x i64> %0
+}
+declare <2 x i64> @llvm.ppc.altivec.vextduhvlx(<8 x i16>, <8 x i16>, i32)
+
+define <2 x i64> @testVEXTDUHVRX(<8 x i16> %a, <8 x i16> %b, i32 %c) {
+; CHECK-LABEL: testVEXTDUHVRX:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:vextduhvrx v2, v2, v3, r7
+; CHECK-NEXT:blr
+entry:
+  %0 = tail call <2 x i64> @llvm.ppc.altivec.vextduhvrx(<8 x i16> %a, <8 x i16> %b, i32 %c)
+  ret <2 x i64> %0
+}
+declare <2 x i64> @llvm.ppc.altivec.vextduhvrx(<8 x i16>, <8 x i16>, i32)
+
+define <2 x i64> @testVEXTDUWVLX(<4 x i32> %a, <4 x i32> %b, i32 %c) {
+; CHECK-LABEL: testVEXTDUWVLX:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:vextduwvlx v2, v2, v3, r7
+; CHECK-NEXT:blr
+entry:
+  %0 = tail call <2 x i64> @llvm.ppc.altivec.vextduwvlx(<4 x i32> %a, <4 x i32> %b, i32 %c)
+  ret <2 x i64> %0
+}
+declare <2 x i64> @llvm.ppc.altivec.vextduwvlx(<4 x i32>, <4 x i32>, i32)
+
+define <2 x i64> @testVEXTDUWVRX(<4 x i32> %a, <4 x i32> %b, i32 %c) {
+; CHECK-LABEL: testVEXTDUWVRX:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:vextduwvrx v2, v2, v3, r7
+; CHECK-NEXT:blr
+entry:
+  %0 = tail call <2 x i64> @llvm.ppc.altivec.vextduwvrx(<4 x i32> %a, <4 x i32> %b, i32 %c)
+  ret <2 x i64> %0
+}
+declare <2 x i64> @llvm.ppc.altivec.vextduwvrx(<4 x i32>, <4 x i32>, i32)
+
+define <2 x i64> @testVEXTDDVLX(<2 x i64> %a, <2 x i64> %b, i32 %c) {
+; CHECK-LABEL: testVEXTDDVLX:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:vextddvlx v2, v2, v3, r7
+; CHECK-NEXT:blr
+entry:
+  %0 = tail call <2 x i64> @llvm.ppc.altivec.vextddvlx(<2 x i64> %a, <2 x i64> %b, i32 %c)
+  ret <2 x i64> %0
+}
+declare <2 x i64> @llvm.ppc.altivec.vextddvlx(<2 x i64>, <2 x i64>, i32)
+
+define <2 x i64> @testVEXTDDVRX(<2 x i64> %a, <2 x i64> %b, i32 %c) {
+; CHECK-LABEL: testVEXTDDVRX:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:vextddvrx v2, v2, v3, r7
+; CHECK-NEXT:blr
+entry:
+  %0 = tail call <2 x i64> @llvm.ppc.altivec.vextddvrx(<2 x i64> %a, <2 x i64> %b, i32 %c)
+  ret <2 x i64> %0
+}
+declare <2 x i64> @llvm.ppc.altivec.vextd

[PATCH] D84005: Introduce ns_error_domain attribute.

2020-07-27 Thread Michael Forster via Phabricator via cfe-commits
MForster updated this revision to Diff 280804.
MForster marked 8 inline comments as done.
MForster edited the summary of this revision.
MForster added a comment.

- Address review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84005

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/Sema/ns_error_enum.c

Index: clang/test/Sema/ns_error_enum.c
===
--- /dev/null
+++ clang/test/Sema/ns_error_enum.c
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -verify %s -x c -Wno-elaborated-enum-base
+// RUN: %clang_cc1 -verify %s -x c++ -Wno-elaborated-enum-base
+// RUN: %clang_cc1 -verify %s -x objective-c
+// RUN: %clang_cc1 -verify %s -x objective-c++
+
+
+#define CF_ENUM(_type, _name) enum _name : _type _name; enum _name : _type
+#define NS_ENUM(_type, _name) CF_ENUM(_type, _name)
+
+#define NS_ERROR_ENUM(_type, _name, _domain)  \
+  enum _name : _type _name; enum __attribute__((ns_error_domain(_domain))) _name : _type
+
+typedef NS_ENUM(unsigned, MyEnum) {
+  MyFirst,
+  MySecond,
+};
+
+typedef NS_ENUM(invalidType, MyInvalidEnum) {
+// expected-error@-1{{unknown type name 'invalidType'}}
+// expected-error@-2{{unknown type name 'invalidType'}}
+  MyFirstInvalid,
+  MySecondInvalid,
+};
+
+const char *MyErrorDomain;
+typedef NS_ERROR_ENUM(unsigned char, MyErrorEnum, MyErrorDomain) {
+	MyErrFirst,
+	MyErrSecond,
+};
+struct __attribute__((ns_error_domain(MyErrorDomain))) MyStructErrorDomain {};
+  // expected-error@-1{{'ns_error_domain' attribute only applies to enums}}
+
+int __attribute__((ns_error_domain(MyErrorDomain))) NotTagDecl;
+  // expected-error@-1{{'ns_error_domain' attribute only applies to enums}}
+
+typedef NS_ERROR_ENUM(unsigned char, MyErrorEnumInvalid, InvalidDomain) {
+	// expected-error@-1{{domain argument 'InvalidDomain' does not refer to global constant}}
+	MyErrFirstInvalid,
+	MyErrSecondInvalid,
+};
+
+typedef NS_ERROR_ENUM(unsigned char, MyErrorEnumInvalid, "domain-string");
+  // expected-error@-1{{'ns_error_domain' attribute requires parameter 1 to be an identifier}}
+
+void foo() {}
+typedef NS_ERROR_ENUM(unsigned char, MyErrorEnumInvalidFunction, foo);
+  // expected-error@-1{{domain argument 'foo' does not refer to global constant}}
Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -80,6 +80,7 @@
 // CHECK-NEXT: MipsShortCall (SubjectMatchRule_function)
 // CHECK-NEXT: NSConsumed (SubjectMatchRule_variable_is_parameter)
 // CHECK-NEXT: NSConsumesSelf (SubjectMatchRule_objc_method)
+// CHECK-NEXT: NSErrorDomain (SubjectMatchRule_enum)
 // CHECK-NEXT: Naked (SubjectMatchRule_function)
 // CHECK-NEXT: NoBuiltin (SubjectMatchRule_function)
 // CHECK-NEXT: NoCommon (SubjectMatchRule_variable)
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -5322,6 +5322,35 @@
   D->addAttr(::new (S.Context) ObjCRequiresSuperAttr(S.Context, Attrs));
 }
 
+static void handleNSErrorDomain(Sema &S, Decl *D, const ParsedAttr &AL) {
+  IdentifierLoc *IdentLoc = AL.isArgIdent(0) ? AL.getArgAsIdent(0) : nullptr;
+  if (!IdentLoc || !IdentLoc->Ident) {
+// Try to locate the argument directly
+SourceLocation Loc = AL.getLoc();
+if (const Expr *E = AL.getArgAsExpr(0))
+  Loc = E->getBeginLoc();
+
+S.Diag(Loc, diag::err_attribute_argument_n_type)
+<< AL << 1 << AANT_ArgumentIdentifier;
+
+return;
+  }
+
+  // Verify that the identifier is a valid decl in the C decl namespace
+  LookupResult lookupResult(S, DeclarationName(IdentLoc->Ident),
+SourceLocation(),
+Sema::LookupNameKind::LookupOrdinaryName);
+  if (!S.LookupName(lookupResult, S.TUScope) ||
+  !lookupResult.getAsSingle()) {
+S.Diag(IdentLoc->Loc, diag::err_nserrordomain_invalid_decl)
+<< IdentLoc->Ident;
+return;
+  }
+
+  D->addAttr(::new (S.Context)
+ NSErrorDomainAttr(S.Context, AL, IdentLoc->Ident));
+}
+
 static void handleObjCBridgeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
   IdentifierLoc *Parm = AL.isArgIdent(0) ? AL.getArgAsIdent(0) : nullptr;
 
@@ -7093,6 +7122,9 @@
   case ParsedAttr::AT_ObjCBoxable:
 handleObjCBoxable(S, D, AL);
 break;
+  case ParsedAttr::AT_NSErrorDomain:
+handleNSErrorDomain(S, D, AL);
+break;
   case ParsedAttr::AT_CFAuditedTransfer:
 handleSimpleAttributeWithExclusions(S, D, AL);
Index: cla

[PATCH] D84005: Introduce ns_error_domain attribute.

2020-07-27 Thread Michael Forster via Phabricator via cfe-commits
MForster added a comment.

I have updated the attribute documentation to include the additional 
information provided by Doug. I think adding additional diagnostics would 
rather be separate changes.

I think I have addressed all remaining review comments.




Comment at: clang/lib/Sema/SemaDeclAttr.cpp:5344
+  if (!S.LookupName(lookupResult, S.TUScope) ||
+  !lookupResult.getAsSingle()) {
+S.Diag(IdentLoc->Loc, diag::err_nserrordomain_invalid_decl)

riccibruno wrote:
> Just a note that `LookupResult::getAsSingle` has tricky semantics (returns 
> null if the result is not exactly `LookupResultKind::Found`) and has been 
> (and still is) the source of many bugs in clang.
> 
> (Example: my favourite one is still the silly:
> ```
> struct S {
>   void not_overloaded();
>   enum { not_overloaded }; // error; redefinition of 'not_overloaded'
> 
>   void overloaded();
>   void overloaded(int);
>   enum { overloaded }; // clang is fine with this!
> };
> ```
> )
> 
> I don't know if it is a problem here or not though.
> Just a note that LookupResult::getAsSingle has tricky semantics [...]

Thanks for the advice, but I think this is not an issue here. The check should 
only succeed if there is a unique lookup result.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84005



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


[PATCH] D84005: Introduce ns_error_domain attribute.

2020-07-27 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 accepted this revision.
gribozavr2 added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/include/clang/Basic/AttrDocs.td:3340
+
+const char *MyErrorDomain;
+typedef NS_ERROR_ENUM(unsigned char, MyErrorEnum, MyErrorDomain) {

const char * => NSString * const?



Comment at: clang/test/Sema/ns_error_enum.c:25
+
+const char *MyErrorDomain;
+typedef NS_ERROR_ENUM(unsigned char, MyErrorEnum, MyErrorDomain) {

const char * => NSString * const? You'd need to define a fake NSString type, 
but that should be rather easy:

```
@interface NSString
@end
```



Comment at: clang/test/Sema/ns_error_enum.c:30
+};
+struct __attribute__((ns_error_domain(MyErrorDomain))) MyStructErrorDomain {};
+  // expected-error@-1{{'ns_error_domain' attribute only applies to enums}}

"MyStructWithErrorDomain" would be a better name, I think.



Comment at: clang/test/Sema/ns_error_enum.c:42
+
+typedef NS_ERROR_ENUM(unsigned char, MyErrorEnumInvalid, "domain-string");
+  // expected-error@-1{{'ns_error_domain' attribute requires parameter 1 to be 
an identifier}}

Also a test for passing 0 or more than 1 argument to the attribute?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84005



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


[PATCH] D84554: Use INTERFACE_COMPILE_OPTIONS to disable -Wsuggest-override for any target that links to gtest

2020-07-27 Thread Pavel Labath via Phabricator via cfe-commits
labath accepted this revision.
labath added a comment.
This revision is now accepted and ready to land.

This looks good to me. Thanks.

Could you elaborate on the lldb issue? I'd like to take a look at that...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84554



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


[PATCH] D84520: [Analyzer] Improve invalid dereference bug reporting in DereferenceChecker.

2020-07-27 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a comment.

Change of the existing error messages and checker category is not necessary but 
it would be improvement because more the uniform error messages. (And not the 
"logic error" is the best category for this checker, if this value is used at 
all. Other checkers have bad values too.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84520



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


[PATCH] D84005: Introduce ns_error_domain attribute.

2020-07-27 Thread Michael Forster via Phabricator via cfe-commits
MForster updated this revision to Diff 280806.
MForster added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84005

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/Sema/ns_error_enum.c

Index: clang/test/Sema/ns_error_enum.c
===
--- /dev/null
+++ clang/test/Sema/ns_error_enum.c
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -verify %s -x c -Wno-elaborated-enum-base
+// RUN: %clang_cc1 -verify %s -x c++ -Wno-elaborated-enum-base
+// RUN: %clang_cc1 -verify %s -x objective-c
+// RUN: %clang_cc1 -verify %s -x objective-c++
+
+
+#define CF_ENUM(_type, _name) enum _name : _type _name; enum _name : _type
+#define NS_ENUM(_type, _name) CF_ENUM(_type, _name)
+
+#define NS_ERROR_ENUM(_type, _name, _domain)  \
+  enum _name : _type _name; enum __attribute__((ns_error_domain(_domain))) _name : _type
+
+typedef NS_ENUM(unsigned, MyEnum) {
+  MyFirst,
+  MySecond,
+};
+
+typedef NS_ENUM(invalidType, MyInvalidEnum) {
+// expected-error@-1{{unknown type name 'invalidType'}}
+// expected-error@-2{{unknown type name 'invalidType'}}
+  MyFirstInvalid,
+  MySecondInvalid,
+};
+
+const char *MyErrorDomain;
+typedef NS_ERROR_ENUM(unsigned char, MyErrorEnum, MyErrorDomain) {
+	MyErrFirst,
+	MyErrSecond,
+};
+struct __attribute__((ns_error_domain(MyErrorDomain))) MyStructErrorDomain {};
+  // expected-error@-1{{'ns_error_domain' attribute only applies to enums}}
+
+int __attribute__((ns_error_domain(MyErrorDomain))) NotTagDecl;
+  // expected-error@-1{{'ns_error_domain' attribute only applies to enums}}
+
+typedef NS_ERROR_ENUM(unsigned char, MyErrorEnumInvalid, InvalidDomain) {
+	// expected-error@-1{{domain argument 'InvalidDomain' does not refer to global constant}}
+	MyErrFirstInvalid,
+	MyErrSecondInvalid,
+};
+
+typedef NS_ERROR_ENUM(unsigned char, MyErrorEnumInvalid, "domain-string");
+  // expected-error@-1{{'ns_error_domain' attribute requires parameter 1 to be an identifier}}
+
+void foo() {}
+typedef NS_ERROR_ENUM(unsigned char, MyErrorEnumInvalidFunction, foo);
+  // expected-error@-1{{domain argument 'foo' does not refer to global constant}}
Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -80,6 +80,7 @@
 // CHECK-NEXT: MipsShortCall (SubjectMatchRule_function)
 // CHECK-NEXT: NSConsumed (SubjectMatchRule_variable_is_parameter)
 // CHECK-NEXT: NSConsumesSelf (SubjectMatchRule_objc_method)
+// CHECK-NEXT: NSErrorDomain (SubjectMatchRule_enum)
 // CHECK-NEXT: Naked (SubjectMatchRule_function)
 // CHECK-NEXT: NoBuiltin (SubjectMatchRule_function)
 // CHECK-NEXT: NoCommon (SubjectMatchRule_variable)
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -5322,6 +5322,35 @@
   D->addAttr(::new (S.Context) ObjCRequiresSuperAttr(S.Context, Attrs));
 }
 
+static void handleNSErrorDomain(Sema &S, Decl *D, const ParsedAttr &AL) {
+  IdentifierLoc *IdentLoc = AL.isArgIdent(0) ? AL.getArgAsIdent(0) : nullptr;
+  if (!IdentLoc || !IdentLoc->Ident) {
+// Try to locate the argument directly
+SourceLocation Loc = AL.getLoc();
+if (const Expr *E = AL.getArgAsExpr(0))
+  Loc = E->getBeginLoc();
+
+S.Diag(Loc, diag::err_attribute_argument_n_type)
+<< AL << 1 << AANT_ArgumentIdentifier;
+
+return;
+  }
+
+  // Verify that the identifier is a valid decl in the C decl namespace
+  LookupResult lookupResult(S, DeclarationName(IdentLoc->Ident),
+SourceLocation(),
+Sema::LookupNameKind::LookupOrdinaryName);
+  if (!S.LookupName(lookupResult, S.TUScope) ||
+  !lookupResult.getAsSingle()) {
+S.Diag(IdentLoc->Loc, diag::err_nserrordomain_invalid_decl)
+<< IdentLoc->Ident;
+return;
+  }
+
+  D->addAttr(::new (S.Context)
+ NSErrorDomainAttr(S.Context, AL, IdentLoc->Ident));
+}
+
 static void handleObjCBridgeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
   IdentifierLoc *Parm = AL.isArgIdent(0) ? AL.getArgAsIdent(0) : nullptr;
 
@@ -7093,6 +7122,9 @@
   case ParsedAttr::AT_ObjCBoxable:
 handleObjCBoxable(S, D, AL);
 break;
+  case ParsedAttr::AT_NSErrorDomain:
+handleNSErrorDomain(S, D, AL);
+break;
   case ParsedAttr::AT_CFAuditedTransfer:
 handleSimpleAttributeWithExclusions(S, D, AL);
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
==

[PATCH] D78902: [Driver] Add output file to properties of Command

2020-07-27 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff added a comment.

Adding output files property is a prerequisite for D78903 
 (Add option -fproc-stat-report). Despite 
large size of the patch, the change is very simple: it only adds new state 
variable `OutputFilenames` initialized by the new parameter to the constructor 
of `Command`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78902



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


[PATCH] D84260: [OpenMP][AMDGCN] Support OpenMP offloading for AMDGCN architecture - Part 3

2020-07-27 Thread Saiyedul Islam via Phabricator via cfe-commits
saiislam updated this revision to Diff 280810.
saiislam added a comment.

Generalized regex in one of the test to pass harbormaster build.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84260

Files:
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeAMDGCN.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeAMDGCN.h
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.h
  clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.h
  clang/lib/CodeGen/CMakeLists.txt
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/OpenMP/amdgcn_target_codegen.cpp
  clang/test/OpenMP/amdgcn_target_init_temp_alloca.cpp

Index: clang/test/OpenMP/amdgcn_target_init_temp_alloca.cpp
===
--- /dev/null
+++ clang/test/OpenMP/amdgcn_target_init_temp_alloca.cpp
@@ -0,0 +1,25 @@
+// REQUIRES: amdgpu-registered-target
+
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm-bc %s -o %t-ppc-host.bc
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple amdgcn-amd-amdhsa -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s
+// expected-no-diagnostics
+
+#define N 100
+
+int test_amdgcn_target_temp_alloca() {
+  // CHECK-LABEL: test_amdgcn_target_temp_alloca
+  // CHECK-LABEL: entry:
+
+  int arr[N];
+
+  // CHECK:  %arr.addr = alloca [100 x i32]*, align 8, addrspace(5)
+  // CHECK-NEXT: %arr.addr.ascast = addrspacecast [100 x i32]* addrspace(5)* %arr.addr to [100 x i32]**
+  // CHECK-DAG:  store [100 x i32]* %arr, [100 x i32]** %arr.addr.ascast, align 8
+
+#pragma omp target
+  for (int i = 0; i < N; i++) {
+arr[i] = 1;
+  }
+
+  return arr[0];
+}
Index: clang/test/OpenMP/amdgcn_target_codegen.cpp
===
--- /dev/null
+++ clang/test/OpenMP/amdgcn_target_codegen.cpp
@@ -0,0 +1,45 @@
+// REQUIRES: amdgpu-registered-target
+
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm-bc %s -o %t-ppc-host.bc
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple amdgcn-amd-amdhsa -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s
+// expected-no-diagnostics
+#ifndef HEADER
+#define HEADER
+
+#define N 1000
+
+int test_amdgcn_target_tid_threads() {
+  // CHECK-LABEL: test_amdgcn_target_tid_threads
+  // CHECK-LABEL: entry:
+
+  int arr[N];
+
+// CHECK: %nvptx_num_threads = call i64 @__ockl_get_local_size(i32 0)
+// CHECK-DAG: [[VAR1:%[0-9]+]] = trunc i64 %nvptx_num_threads to i32
+// CHECK-DAG: %thread_limit = sub nuw i32 [[VAR1]], 64
+// CHECK-DAG: %nvptx_tid{{[0-9]*}} = call i32 @llvm.amdgcn.workitem.id.x()
+#pragma omp target
+  for (int i = 0; i < N; i++) {
+arr[i] = 1;
+  }
+
+  return arr[0];
+}
+
+int test_amdgcn_target_tid_threads_simd() {
+  // CHECK-LABEL: test_amdgcn_target_tid_threads_simd
+  // CHECK-LABEL: entry:
+
+  int arr[N];
+
+// CHECK: %nvptx_num_threads = call i64 @__ockl_get_local_size(i32 0)
+// CHECK-DAG: [[VAR2:%[0-9]+]] = trunc i64 %nvptx_num_threads to i32
+// CHECK-DAG: call void @__kmpc_spmd_kernel_init(i32 [[VAR2]], i16 0, i16 0)
+#pragma omp target simd
+  for (int i = 0; i < N; i++) {
+arr[i] = 1;
+  }
+  return arr[0];
+}
+
+#endif
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -19,6 +19,7 @@
 #include "CGObjCRuntime.h"
 #include "CGOpenCLRuntime.h"
 #include "CGOpenMPRuntime.h"
+#include "CGOpenMPRuntimeAMDGCN.h"
 #include "CGOpenMPRuntimeNVPTX.h"
 #include "CodeGenFunction.h"
 #include "CodeGenPGO.h"
@@ -215,6 +216,11 @@
"OpenMP NVPTX is only prepared to deal with device code.");
 OpenMPRuntime.reset(new CGOpenMPRuntimeNVPTX(*this));
 break;
+  case llvm::Triple::amdgcn:
+assert(getLangOpts().OpenMPIsDevice &&
+   "OpenMP AMDGCN is only prepared to deal with device code.");
+OpenMPRuntime.reset(new CGOpenMPRuntimeAMDGCN(*this));
+break;
   default:
 if (LangOpts.OpenMPSimd)
   OpenMPRuntime.reset(new CGOpenMPSIMDRuntime(*this));
Index: clang/lib/CodeGen/CMakeLists.txt
===
--- clang/lib/CodeGen/CMakeLists.txt
+++ clang/lib/CodeGen/CMakeLists.txt
@@ -62,6 +62,7 @@
   CGObjCRuntime.cpp
   CGOpenCLRuntime.cpp
   CGOpenMPRuntime.cpp
+  CGOpenMPRuntimeAMDGCN.cpp
   CGOpenMPRuntimeGPU.cpp
   CGOpenMPRuntimeNVPTX.cpp
   CGRecordLayoutBuilder.cpp
Index: clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntim

[PATCH] D84315: [libTooling] Add a `between` range-selector combinator.

2020-07-27 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 accepted this revision.
gribozavr2 added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/include/clang/Tooling/Transformer/RangeSelector.h:59
 
+/// Convenience constructor of the range between two ranges.
+inline RangeSelector between(RangeSelector R1, RangeSelector R2) {

"Selects the range between the two ranges."

I don't think users care much that it is expressible in terms of other 
combinators.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84315



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


[PATCH] D84499: [clangd] Add more logs and attach tracers to remote index server routines

2020-07-27 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev added inline comments.



Comment at: clang-tools-extra/clangd/index/remote/server/Server.cpp:73
 private:
+  template 

sammccall wrote:
> you don't need both RequestT and ClangdRequest as template params:
>  - the things you're currently doing are all available through 
> protobuf::Message base class
>  - but why not move the request fromProtobuf call in here so you only need to 
> pass a single parameter?
> but why not move the request fromProtobuf call in here so you only need to 
> pass a single parameter?
Yeah this is the idea; I have D84525 for extending `fromProtobuf` so that it 
can be moved here.



Comment at: clang-tools-extra/clangd/index/remote/server/Server.cpp:75
+typename IndexCall, typename StreamType, typename CallbackT>
+  typename std::result_of::type

sammccall wrote:
> can't the return type just be `auto`?
> Then I think you don't need CallbackT as a template param.
Ah, I thought LLVM is still C++ 11, not 14. Good to know, thanks!



Comment at: clang-tools-extra/clangd/index/remote/server/Server.cpp:96
+} Counter(Request->DebugString());
+return std::forward(Call)(
+*Index, ClangdRequest, [&](const StreamType &Item) {

sammccall wrote:
> kbobyrev wrote:
> > sammccall wrote:
> > > I don't think you need forward here... just take the param by const 
> > > reference?
> > How do I do that? The problem is that some functions return `bool` and one 
> > `void`, so I can't really assign the result to variable and then return it.
> Currently you have 
> ```
> template (IndexCall&& Call) {
>   forward(Call);
> }
> ```
> but I think this would work fine here:
> ```
> template (const IndexCall& Call) {
>   IndexCall(Call);
> }
> ```
> (nothing particularly wrong with this use of forward, but "more template 
> goop" feels particularly expensive here.
Ah, you meant passing the callback by const reference. I see, thanks for the 
suggestion!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84499



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


[PATCH] D84499: [clangd] Add more logs and attach tracers to remote index server routines

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

Resolve most review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84499

Files:
  clang-tools-extra/clangd/index/remote/Client.cpp
  clang-tools-extra/clangd/index/remote/server/Server.cpp

Index: clang-tools-extra/clangd/index/remote/server/Server.cpp
===
--- clang-tools-extra/clangd/index/remote/server/Server.cpp
+++ clang-tools-extra/clangd/index/remote/server/Server.cpp
@@ -8,7 +8,10 @@
 
 #include "index/Index.h"
 #include "index/Serialization.h"
+#include "index/Symbol.h"
 #include "index/remote/marshalling/Marshalling.h"
+#include "support/Logger.h"
+#include "support/Trace.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Path.h"
@@ -16,6 +19,7 @@
 
 #include 
 #include 
+#include 
 
 #include "Index.grpc.pb.h"
 
@@ -35,6 +39,16 @@
 llvm::cl::opt IndexRoot(llvm::cl::desc(""),
  llvm::cl::Positional, llvm::cl::Required);
 
+llvm::cl::opt TraceFile(
+"trace-file",
+llvm::cl::desc("Path to the file where tracer logs will be stored"));
+
+llvm::cl::opt PrettyPrint{
+"pretty",
+llvm::cl::desc("Pretty-print JSON output in the trace"),
+llvm::cl::init(false),
+};
+
 llvm::cl::opt ServerAddress(
 "server-address", llvm::cl::init("0.0.0.0:50051"),
 llvm::cl::desc("Address of the invoked server. Defaults to 0.0.0.0:50051"));
@@ -56,24 +70,60 @@
   }
 
 private:
+  template 
+  auto streamRPC(const RequestT *Request, grpc::ServerWriter *Reply,
+ ClangdRequestT ClangdRequest, const IndexCall &Call) {
+// Adding Sent and FailedToSend messages to the tracer has to happen after
+// Callback but the temporary value can not be stored. Use a dummy struct
+// to hold data for tracer and then add data to the trace on destruction
+// happening after the callback.
+struct TracerCounter {
+  trace::Span Tracer;
+  unsigned Sent = 0;
+  unsigned FailedToSend = 0;
+  TracerCounter(llvm::StringRef RequestInfo)
+  : Tracer(RequestT::descriptor()->name()) {
+SPAN_ATTACH(Tracer, "Request", RequestInfo);
+  }
+  ~TracerCounter() {
+SPAN_ATTACH(Tracer, "Sent", Sent);
+SPAN_ATTACH(Tracer, "Failed to send", FailedToSend);
+  }
+} Counter(Request->DebugString());
+return Call(*Index, ClangdRequest, [&](const auto &Item) {
+  auto SerializedItem = ProtobufMarshaller->toProtobuf(Item);
+  if (!SerializedItem) {
+++Counter.FailedToSend;
+return;
+  }
+  ReplyT NextMessage;
+  *NextMessage.mutable_stream_result() = *SerializedItem;
+  Reply->Write(NextMessage);
+  ++Counter.Sent;
+});
+  }
+
   grpc::Status Lookup(grpc::ServerContext *Context,
   const LookupRequest *Request,
   grpc::ServerWriter *Reply) override {
 clangd::LookupRequest Req;
 for (const auto &ID : Request->ids()) {
   auto SID = SymbolID::fromStr(StringRef(ID));
-  if (!SID)
+  if (!SID) {
+elog("Lookup request cancelled: invalid SymbolID {1}", SID.takeError());
 return grpc::Status::CANCELLED;
+  }
   Req.IDs.insert(*SID);
 }
-Index->lookup(Req, [&](const clangd::Symbol &Sym) {
-  auto SerializedSymbol = ProtobufMarshaller->toProtobuf(Sym);
-  if (!SerializedSymbol)
-return;
-  LookupReply NextMessage;
-  *NextMessage.mutable_stream_result() = *SerializedSymbol;
-  Reply->Write(NextMessage);
-});
+std::function)>
+IndexCall = &clangd::SymbolIndex::lookup;
+streamRPC>(
+Request, Reply, Req, std::move(IndexCall));
 LookupReply LastMessage;
 LastMessage.set_final_result(true);
 Reply->Write(LastMessage);
@@ -84,14 +134,14 @@
  const FuzzyFindRequest *Request,
  grpc::ServerWriter *Reply) override {
 const auto Req = ProtobufMarshaller->fromProtobuf(Request);
-bool HasMore = Index->fuzzyFind(Req, [&](const clangd::Symbol &Sym) {
-  auto SerializedSymbol = ProtobufMarshaller->toProtobuf(Sym);
-  if (!SerializedSymbol)
-return;
-  FuzzyFindReply NextMessage;
-  *NextMessage.mutable_stream_result() = *SerializedSymbol;
-  Reply->Write(NextMessage);
-});
+std::function)>
+IndexCall = &clangd::SymbolIndex::fuzzyFind;
+bool HasMore = streamRPC>(
+Request, Reply, Req, std::move(IndexCall));
 FuzzyFindReply LastMessage;
 LastMessage.set_final_result(HasMore);
 Reply->Write(LastMessage);
@@ -103,18 +153,20 @@
 clangd::RefsRequest Req;
 for (const auto &ID : Request->ids()) {
   auto SID = SymbolID::fromStr(StringRef(ID));
-  if (!SID)
+  if (!SID)

[PATCH] D84623: Remove HAVE_VCS_VERSION_INC, not needed

2020-07-27 Thread Marcel Hlopko via Phabricator via cfe-commits
hlopko created this revision.
hlopko added a reviewer: gribozavr2.
Herald added subscribers: llvm-commits, lldb-commits, cfe-commits, mgorny.
Herald added a reviewer: MaskRay.
Herald added projects: clang, LLDB, LLVM.

This preprocessor define was meant to be used to conditionally include
headers with VCS information (for example VCSRevision.inc). However, the
define was always set, and it was the content of the header that was
conditionally generated. Therefore HAVE_VCS_VERSION_INC should be
cleaned up.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D84623

Files:
  clang/lib/Basic/CMakeLists.txt
  clang/lib/Basic/Version.cpp
  lld/Common/CMakeLists.txt
  lld/Common/Version.cpp
  lldb/source/CMakeLists.txt
  lldb/source/lldb.cpp
  llvm/utils/gn/secondary/clang/lib/Basic/BUILD.gn
  llvm/utils/gn/secondary/lld/Common/BUILD.gn

Index: llvm/utils/gn/secondary/lld/Common/BUILD.gn
===
--- llvm/utils/gn/secondary/lld/Common/BUILD.gn
+++ llvm/utils/gn/secondary/lld/Common/BUILD.gn
@@ -42,5 +42,4 @@
 "Timer.cpp",
 "Version.cpp",
   ]
-  defines = [ "HAVE_VCS_VERSION_INC" ]  # For Version.cpp
 }
Index: llvm/utils/gn/secondary/clang/lib/Basic/BUILD.gn
===
--- llvm/utils/gn/secondary/clang/lib/Basic/BUILD.gn
+++ llvm/utils/gn/secondary/clang/lib/Basic/BUILD.gn
@@ -102,5 +102,4 @@
 "XRayInstr.cpp",
 "XRayLists.cpp",
   ]
-  defines = [ "HAVE_VCS_VERSION_INC" ]  # For Version.cpp
 }
Index: lldb/source/lldb.cpp
===
--- lldb/source/lldb.cpp
+++ lldb/source/lldb.cpp
@@ -13,9 +13,7 @@
 
 #include "clang/Basic/Version.h"
 
-#ifdef HAVE_VCS_VERSION_INC
 #include "VCSVersion.inc"
-#endif
 
 static const char *GetLLDBRevision() {
 #ifdef LLDB_REVISION
Index: lldb/source/CMakeLists.txt
===
--- lldb/source/CMakeLists.txt
+++ lldb/source/CMakeLists.txt
@@ -34,9 +34,6 @@
   PROPERTIES GENERATED TRUE
  HEADER_FILE_ONLY TRUE)
 
-set_property(SOURCE lldb.cpp APPEND PROPERTY
- COMPILE_DEFINITIONS "HAVE_VCS_VERSION_INC")
-
 list(APPEND lldbBase_SOURCES ${version_inc})
 
 if(LLDB_VERSION_STRING)
Index: lld/Common/Version.cpp
===
--- lld/Common/Version.cpp
+++ lld/Common/Version.cpp
@@ -12,9 +12,7 @@
 
 #include "lld/Common/Version.h"
 
-#ifdef HAVE_VCS_VERSION_INC
 #include "VCSVersion.inc"
-#endif
 
 // Returns a version string, e.g.:
 // lld 9.0.0 (https://github.com/llvm/llvm-project.git 9efdd7ac5e914d3c9fa1ef)
Index: lld/Common/CMakeLists.txt
===
--- lld/Common/CMakeLists.txt
+++ lld/Common/CMakeLists.txt
@@ -20,9 +20,6 @@
   PROPERTIES GENERATED TRUE
   HEADER_FILE_ONLY TRUE)
 
-set_property(SOURCE Version.cpp APPEND PROPERTY
-  COMPILE_DEFINITIONS "HAVE_VCS_VERSION_INC")
-
 add_lld_library(lldCommon
   Args.cpp
   DWARF.cpp
Index: clang/lib/Basic/Version.cpp
===
--- clang/lib/Basic/Version.cpp
+++ clang/lib/Basic/Version.cpp
@@ -17,9 +17,7 @@
 #include 
 #include 
 
-#ifdef HAVE_VCS_VERSION_INC
 #include "VCSVersion.inc"
-#endif
 
 namespace clang {
 
Index: clang/lib/Basic/CMakeLists.txt
===
--- clang/lib/Basic/CMakeLists.txt
+++ clang/lib/Basic/CMakeLists.txt
@@ -33,9 +33,6 @@
   PROPERTIES GENERATED TRUE
  HEADER_FILE_ONLY TRUE)
 
-set_property(SOURCE Version.cpp APPEND PROPERTY
- COMPILE_DEFINITIONS "HAVE_VCS_VERSION_INC")
-
 add_clang_library(clangBasic
   Attributes.cpp
   Builtins.cpp
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D84535: [clangd] Switch from EXPECT_TRUE to ASSERT_TRUE in remote marshalling tests

2020-07-27 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev marked 5 inline comments as done.
kbobyrev added inline comments.



Comment at: clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp:159
   Deserialized = ProtobufMarshaller.fromProtobuf(*Serialized);
   EXPECT_TRUE(Deserialized);
 

kbobyrev wrote:
> kadircet wrote:
> > maybe make this an assert too (and also consider issuing ASSERT_FALSE 
> > directly on the expression instead of an extra assingment)
> Why is would asserting be better here? If I'm not dereferencing it I guess 
> this should be worse because only the first assertion failure is checked, 
> right?
Should be OK as discussed in PM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84535



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


[clang-tools-extra] 974ffee - [clangd] Switch from EXPECT_TRUE to ASSERT_TRUE in remote marshalling tests

2020-07-27 Thread Kirill Bobyrev via cfe-commits

Author: Kirill Bobyrev
Date: 2020-07-27T10:44:23+02:00
New Revision: 974ffee9ccd70703c6edb880ac4934a5dc12e56d

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

LOG: [clangd] Switch from EXPECT_TRUE to ASSERT_TRUE in remote marshalling tests

Summary:
When dereferencing Optional's it makes sense to use ASSERT_TRUE for better
test failures readability. Switch from EXPECT_TRUE to ASSERT_TRUE where
it is appropriate.

Reviewers: kadircet

Reviewed By: kadircet

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits

Tags: #clang

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

Signed-off-by: Kirill Bobyrev 

Added: 


Modified: 
clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp 
b/clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
index 7db7c03d61c9..147601b665c4 100644
--- a/clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
+++ b/clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
@@ -49,11 +49,11 @@ TEST(RemoteMarshallingTest, URITranslation) {
   "clangd/unittests/remote/MarshallingTests.cpp",
   Strings);
   auto Serialized = ProtobufMarshaller.toProtobuf(Original);
-  EXPECT_TRUE(Serialized);
+  ASSERT_TRUE(Serialized);
   EXPECT_EQ(Serialized->location().file_path(),
 "clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp");
   auto Deserialized = ProtobufMarshaller.fromProtobuf(*Serialized);
-  EXPECT_TRUE(Deserialized);
+  ASSERT_TRUE(Deserialized);
   EXPECT_STREQ(Deserialized->Location.FileURI,
testPathURI("home/my-projects/llvm-project/clang-tools-extra/"
"clangd/unittests/remote/MarshallingTests.cpp",
@@ -61,38 +61,34 @@ TEST(RemoteMarshallingTest, URITranslation) {
 
   // Can't have empty paths.
   *Serialized->mutable_location()->mutable_file_path() = std::string();
-  Deserialized = ProtobufMarshaller.fromProtobuf(*Serialized);
-  EXPECT_FALSE(Deserialized);
+  EXPECT_FALSE(ProtobufMarshaller.fromProtobuf(*Serialized));
 
   clangd::Ref WithInvalidURI;
   // Invalid URI results in serialization failure.
   WithInvalidURI.Location.FileURI = "This is not a URI";
-  Serialized = ProtobufMarshaller.toProtobuf(WithInvalidURI);
-  EXPECT_FALSE(Serialized);
+  EXPECT_FALSE(ProtobufMarshaller.toProtobuf(WithInvalidURI));
 
   // Can not use URIs with scheme 
diff erent from "file".
   auto UnittestURI =
   URI::create(testPath("project/lib/HelloWorld.cpp"), "unittest");
-  EXPECT_TRUE(bool(UnittestURI));
+  ASSERT_TRUE(bool(UnittestURI));
   WithInvalidURI.Location.FileURI =
   Strings.save(UnittestURI->toString()).begin();
-  Serialized = ProtobufMarshaller.toProtobuf(WithInvalidURI);
-  EXPECT_FALSE(Serialized);
+  EXPECT_FALSE(ProtobufMarshaller.toProtobuf(WithInvalidURI));
 
   // Paths transmitted over the wire can not be absolute, they have to be
   // relative.
   Ref WithAbsolutePath;
   *WithAbsolutePath.mutable_location()->mutable_file_path() =
   "/usr/local/user/home/HelloWorld.cpp";
-  Deserialized = ProtobufMarshaller.fromProtobuf(WithAbsolutePath);
-  EXPECT_FALSE(Deserialized);
+  EXPECT_FALSE(ProtobufMarshaller.fromProtobuf(WithAbsolutePath));
 }
 
 TEST(RemoteMarshallingTest, SymbolSerialization) {
   clangd::Symbol Sym;
 
   auto ID = SymbolID::fromStr("057557CEBF6E6B2D");
-  EXPECT_TRUE(bool(ID));
+  ASSERT_TRUE(bool(ID));
   Sym.ID = *ID;
 
   index::SymbolInfo Info;
@@ -140,9 +136,9 @@ TEST(RemoteMarshallingTest, SymbolSerialization) {
   // Check that symbols are exactly the same if the path to indexed project is
   // the same on indexing machine and the client.
   auto Serialized = ProtobufMarshaller.toProtobuf(Sym);
-  EXPECT_TRUE(Serialized);
+  ASSERT_TRUE(Serialized);
   auto Deserialized = ProtobufMarshaller.fromProtobuf(*Serialized);
-  EXPECT_TRUE(Deserialized);
+  ASSERT_TRUE(Deserialized);
   EXPECT_EQ(toYAML(Sym), toYAML(*Deserialized));
   // Serialized paths are relative and have UNIX slashes.
   EXPECT_EQ(convert_to_slash(Serialized->definition().file_path(),
@@ -154,44 +150,39 @@ TEST(RemoteMarshallingTest, SymbolSerialization) {
   // Missing definition is OK.
   Sym.Definition = clangd::SymbolLocation();
   Serialized = ProtobufMarshaller.toProtobuf(Sym);
-  EXPECT_TRUE(Serialized);
-  Deserialized = ProtobufMarshaller.fromProtobuf(*Serialized);
-  EXPECT_TRUE(Deserialized);
+  ASSERT_TRUE(Serialized);
+  EXPECT_TRUE(ProtobufMarshaller.fromProtobuf(*Serialized));
 
   // Relative path is absolute.
   *Serialized->mutable_canonical_declaration()->mutable_file_path() =
   convert_to_slash("/path/to/Declaration.h");
-  Deserialized = ProtobufMarshaller.fro

[PATCH] D84535: [clangd] Switch from EXPECT_TRUE to ASSERT_TRUE in remote marshalling tests

2020-07-27 Thread Kirill Bobyrev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
kbobyrev marked an inline comment as done.
Closed by commit rG974ffee9ccd7: [clangd] Switch from EXPECT_TRUE to 
ASSERT_TRUE in remote marshalling tests (authored by kbobyrev).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84535

Files:
  clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp

Index: clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
===
--- clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
+++ clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
@@ -49,11 +49,11 @@
   "clangd/unittests/remote/MarshallingTests.cpp",
   Strings);
   auto Serialized = ProtobufMarshaller.toProtobuf(Original);
-  EXPECT_TRUE(Serialized);
+  ASSERT_TRUE(Serialized);
   EXPECT_EQ(Serialized->location().file_path(),
 "clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp");
   auto Deserialized = ProtobufMarshaller.fromProtobuf(*Serialized);
-  EXPECT_TRUE(Deserialized);
+  ASSERT_TRUE(Deserialized);
   EXPECT_STREQ(Deserialized->Location.FileURI,
testPathURI("home/my-projects/llvm-project/clang-tools-extra/"
"clangd/unittests/remote/MarshallingTests.cpp",
@@ -61,38 +61,34 @@
 
   // Can't have empty paths.
   *Serialized->mutable_location()->mutable_file_path() = std::string();
-  Deserialized = ProtobufMarshaller.fromProtobuf(*Serialized);
-  EXPECT_FALSE(Deserialized);
+  EXPECT_FALSE(ProtobufMarshaller.fromProtobuf(*Serialized));
 
   clangd::Ref WithInvalidURI;
   // Invalid URI results in serialization failure.
   WithInvalidURI.Location.FileURI = "This is not a URI";
-  Serialized = ProtobufMarshaller.toProtobuf(WithInvalidURI);
-  EXPECT_FALSE(Serialized);
+  EXPECT_FALSE(ProtobufMarshaller.toProtobuf(WithInvalidURI));
 
   // Can not use URIs with scheme different from "file".
   auto UnittestURI =
   URI::create(testPath("project/lib/HelloWorld.cpp"), "unittest");
-  EXPECT_TRUE(bool(UnittestURI));
+  ASSERT_TRUE(bool(UnittestURI));
   WithInvalidURI.Location.FileURI =
   Strings.save(UnittestURI->toString()).begin();
-  Serialized = ProtobufMarshaller.toProtobuf(WithInvalidURI);
-  EXPECT_FALSE(Serialized);
+  EXPECT_FALSE(ProtobufMarshaller.toProtobuf(WithInvalidURI));
 
   // Paths transmitted over the wire can not be absolute, they have to be
   // relative.
   Ref WithAbsolutePath;
   *WithAbsolutePath.mutable_location()->mutable_file_path() =
   "/usr/local/user/home/HelloWorld.cpp";
-  Deserialized = ProtobufMarshaller.fromProtobuf(WithAbsolutePath);
-  EXPECT_FALSE(Deserialized);
+  EXPECT_FALSE(ProtobufMarshaller.fromProtobuf(WithAbsolutePath));
 }
 
 TEST(RemoteMarshallingTest, SymbolSerialization) {
   clangd::Symbol Sym;
 
   auto ID = SymbolID::fromStr("057557CEBF6E6B2D");
-  EXPECT_TRUE(bool(ID));
+  ASSERT_TRUE(bool(ID));
   Sym.ID = *ID;
 
   index::SymbolInfo Info;
@@ -140,9 +136,9 @@
   // Check that symbols are exactly the same if the path to indexed project is
   // the same on indexing machine and the client.
   auto Serialized = ProtobufMarshaller.toProtobuf(Sym);
-  EXPECT_TRUE(Serialized);
+  ASSERT_TRUE(Serialized);
   auto Deserialized = ProtobufMarshaller.fromProtobuf(*Serialized);
-  EXPECT_TRUE(Deserialized);
+  ASSERT_TRUE(Deserialized);
   EXPECT_EQ(toYAML(Sym), toYAML(*Deserialized));
   // Serialized paths are relative and have UNIX slashes.
   EXPECT_EQ(convert_to_slash(Serialized->definition().file_path(),
@@ -154,44 +150,39 @@
   // Missing definition is OK.
   Sym.Definition = clangd::SymbolLocation();
   Serialized = ProtobufMarshaller.toProtobuf(Sym);
-  EXPECT_TRUE(Serialized);
-  Deserialized = ProtobufMarshaller.fromProtobuf(*Serialized);
-  EXPECT_TRUE(Deserialized);
+  ASSERT_TRUE(Serialized);
+  EXPECT_TRUE(ProtobufMarshaller.fromProtobuf(*Serialized));
 
   // Relative path is absolute.
   *Serialized->mutable_canonical_declaration()->mutable_file_path() =
   convert_to_slash("/path/to/Declaration.h");
-  Deserialized = ProtobufMarshaller.fromProtobuf(*Serialized);
-  EXPECT_FALSE(Deserialized);
+  EXPECT_FALSE(ProtobufMarshaller.fromProtobuf(*Serialized));
 
   // Fail with an invalid URI.
   Location.FileURI = "Not A URI";
   Sym.Definition = Location;
-  Serialized = ProtobufMarshaller.toProtobuf(Sym);
-  EXPECT_FALSE(Serialized);
+  EXPECT_FALSE(ProtobufMarshaller.toProtobuf(Sym));
 
   // Schemes other than "file" can not be used.
   auto UnittestURI = URI::create(testPath("home/SomePath.h"), "unittest");
-  EXPECT_TRUE(bool(UnittestURI));
+  ASSERT_TRUE(bool(UnittestURI));
   Location.FileURI = Strings.save(UnittestURI->toString()).begin();
   Sym.Definition = Location;
-  Serialized = ProtobufMarshaller.toProtobuf(Sym);
-  EXPECT_FALSE(Serialized);
+  EXPECT_FALSE(ProtobufMarsha

[PATCH] D84525: [clangd] Add marshalling code for all request types

2020-07-27 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 280819.
kbobyrev added a comment.

Fix formatting.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84525

Files:
  clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
  clang-tools-extra/clangd/index/remote/marshalling/Marshalling.h
  clang-tools-extra/clangd/index/remote/server/Server.cpp
  clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp

Index: clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
===
--- clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
+++ clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
@@ -289,7 +289,8 @@
   auto Serialized = ProtobufMarshaller.toProtobuf(Request);
   EXPECT_EQ(Serialized.proximity_paths_size(), 2);
   auto Deserialized = ProtobufMarshaller.fromProtobuf(&Serialized);
-  EXPECT_THAT(Deserialized.ProximityPaths,
+  ASSERT_TRUE(Deserialized);
+  EXPECT_THAT(Deserialized->ProximityPaths,
   testing::ElementsAre(testPath("remote/Header.h"),
testPath("remote/subdir/OtherHeader.h")));
 }
Index: clang-tools-extra/clangd/index/remote/server/Server.cpp
===
--- clang-tools-extra/clangd/index/remote/server/Server.cpp
+++ clang-tools-extra/clangd/index/remote/server/Server.cpp
@@ -59,14 +59,10 @@
   grpc::Status Lookup(grpc::ServerContext *Context,
   const LookupRequest *Request,
   grpc::ServerWriter *Reply) override {
-clangd::LookupRequest Req;
-for (const auto &ID : Request->ids()) {
-  auto SID = SymbolID::fromStr(StringRef(ID));
-  if (!SID)
-return grpc::Status::CANCELLED;
-  Req.IDs.insert(*SID);
-}
-Index->lookup(Req, [&](const clangd::Symbol &Sym) {
+const auto Req = ProtobufMarshaller->fromProtobuf(Request);
+if (!Req)
+  return grpc::Status::CANCELLED;
+Index->lookup(*Req, [&](const clangd::Symbol &Sym) {
   auto SerializedSymbol = ProtobufMarshaller->toProtobuf(Sym);
   if (!SerializedSymbol)
 return;
@@ -84,7 +80,9 @@
  const FuzzyFindRequest *Request,
  grpc::ServerWriter *Reply) override {
 const auto Req = ProtobufMarshaller->fromProtobuf(Request);
-bool HasMore = Index->fuzzyFind(Req, [&](const clangd::Symbol &Sym) {
+if (!Req)
+  return grpc::Status::CANCELLED;
+bool HasMore = Index->fuzzyFind(*Req, [&](const clangd::Symbol &Sym) {
   auto SerializedSymbol = ProtobufMarshaller->toProtobuf(Sym);
   if (!SerializedSymbol)
 return;
@@ -100,14 +98,10 @@
 
   grpc::Status Refs(grpc::ServerContext *Context, const RefsRequest *Request,
 grpc::ServerWriter *Reply) override {
-clangd::RefsRequest Req;
-for (const auto &ID : Request->ids()) {
-  auto SID = SymbolID::fromStr(StringRef(ID));
-  if (!SID)
-return grpc::Status::CANCELLED;
-  Req.IDs.insert(*SID);
-}
-bool HasMore = Index->refs(Req, [&](const clangd::Ref &Reference) {
+const auto Req = ProtobufMarshaller->fromProtobuf(Request);
+if (!Req)
+  return grpc::Status::CANCELLED;
+bool HasMore = Index->refs(*Req, [&](const clangd::Ref &Reference) {
   auto SerializedRef = ProtobufMarshaller->toProtobuf(Reference);
   if (!SerializedRef)
 return;
Index: clang-tools-extra/clangd/index/remote/marshalling/Marshalling.h
===
--- clang-tools-extra/clangd/index/remote/marshalling/Marshalling.h
+++ clang-tools-extra/clangd/index/remote/marshalling/Marshalling.h
@@ -38,10 +38,15 @@
   Marshaller() = delete;
   Marshaller(llvm::StringRef RemoteIndexRoot, llvm::StringRef LocalIndexRoot);
 
-  clangd::FuzzyFindRequest fromProtobuf(const FuzzyFindRequest *Request);
   llvm::Optional fromProtobuf(const Symbol &Message);
   llvm::Optional fromProtobuf(const Ref &Message);
 
+  llvm::Optional
+  fromProtobuf(const LookupRequest *Message);
+  llvm::Optional
+  fromProtobuf(const FuzzyFindRequest *Message);
+  llvm::Optional fromProtobuf(const RefsRequest *Message);
+
   /// toProtobuf() functions serialize native clangd types and strip IndexRoot
   /// from the file paths specific to indexing machine. fromProtobuf() functions
   /// deserialize clangd types and translate relative paths into machine-native
Index: clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
===
--- clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
+++ clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
@@ -17,6 +17,7 @@
 #include "index/SymbolOrigin.h"
 #include "support/Logger.h"
 #include "clang/Index/IndexSymbol.h"
+#include "llvm/ADT/DenseSet.h"
 #include

[PATCH] D84525: [clangd] Add marshalling code for all request types

2020-07-27 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 280820.
kbobyrev added a comment.

Rebase on top of master.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84525

Files:
  clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
  clang-tools-extra/clangd/index/remote/marshalling/Marshalling.h
  clang-tools-extra/clangd/index/remote/server/Server.cpp
  clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp

Index: clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
===
--- clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
+++ clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
@@ -280,7 +280,8 @@
   auto Serialized = ProtobufMarshaller.toProtobuf(Request);
   EXPECT_EQ(Serialized.proximity_paths_size(), 2);
   auto Deserialized = ProtobufMarshaller.fromProtobuf(&Serialized);
-  EXPECT_THAT(Deserialized.ProximityPaths,
+  ASSERT_TRUE(Deserialized);
+  EXPECT_THAT(Deserialized->ProximityPaths,
   testing::ElementsAre(testPath("remote/Header.h"),
testPath("remote/subdir/OtherHeader.h")));
 }
Index: clang-tools-extra/clangd/index/remote/server/Server.cpp
===
--- clang-tools-extra/clangd/index/remote/server/Server.cpp
+++ clang-tools-extra/clangd/index/remote/server/Server.cpp
@@ -59,14 +59,10 @@
   grpc::Status Lookup(grpc::ServerContext *Context,
   const LookupRequest *Request,
   grpc::ServerWriter *Reply) override {
-clangd::LookupRequest Req;
-for (const auto &ID : Request->ids()) {
-  auto SID = SymbolID::fromStr(StringRef(ID));
-  if (!SID)
-return grpc::Status::CANCELLED;
-  Req.IDs.insert(*SID);
-}
-Index->lookup(Req, [&](const clangd::Symbol &Sym) {
+const auto Req = ProtobufMarshaller->fromProtobuf(Request);
+if (!Req)
+  return grpc::Status::CANCELLED;
+Index->lookup(*Req, [&](const clangd::Symbol &Sym) {
   auto SerializedSymbol = ProtobufMarshaller->toProtobuf(Sym);
   if (!SerializedSymbol)
 return;
@@ -84,7 +80,9 @@
  const FuzzyFindRequest *Request,
  grpc::ServerWriter *Reply) override {
 const auto Req = ProtobufMarshaller->fromProtobuf(Request);
-bool HasMore = Index->fuzzyFind(Req, [&](const clangd::Symbol &Sym) {
+if (!Req)
+  return grpc::Status::CANCELLED;
+bool HasMore = Index->fuzzyFind(*Req, [&](const clangd::Symbol &Sym) {
   auto SerializedSymbol = ProtobufMarshaller->toProtobuf(Sym);
   if (!SerializedSymbol)
 return;
@@ -100,14 +98,10 @@
 
   grpc::Status Refs(grpc::ServerContext *Context, const RefsRequest *Request,
 grpc::ServerWriter *Reply) override {
-clangd::RefsRequest Req;
-for (const auto &ID : Request->ids()) {
-  auto SID = SymbolID::fromStr(StringRef(ID));
-  if (!SID)
-return grpc::Status::CANCELLED;
-  Req.IDs.insert(*SID);
-}
-bool HasMore = Index->refs(Req, [&](const clangd::Ref &Reference) {
+const auto Req = ProtobufMarshaller->fromProtobuf(Request);
+if (!Req)
+  return grpc::Status::CANCELLED;
+bool HasMore = Index->refs(*Req, [&](const clangd::Ref &Reference) {
   auto SerializedRef = ProtobufMarshaller->toProtobuf(Reference);
   if (!SerializedRef)
 return;
Index: clang-tools-extra/clangd/index/remote/marshalling/Marshalling.h
===
--- clang-tools-extra/clangd/index/remote/marshalling/Marshalling.h
+++ clang-tools-extra/clangd/index/remote/marshalling/Marshalling.h
@@ -38,10 +38,15 @@
   Marshaller() = delete;
   Marshaller(llvm::StringRef RemoteIndexRoot, llvm::StringRef LocalIndexRoot);
 
-  clangd::FuzzyFindRequest fromProtobuf(const FuzzyFindRequest *Request);
   llvm::Optional fromProtobuf(const Symbol &Message);
   llvm::Optional fromProtobuf(const Ref &Message);
 
+  llvm::Optional
+  fromProtobuf(const LookupRequest *Message);
+  llvm::Optional
+  fromProtobuf(const FuzzyFindRequest *Message);
+  llvm::Optional fromProtobuf(const RefsRequest *Message);
+
   /// toProtobuf() functions serialize native clangd types and strip IndexRoot
   /// from the file paths specific to indexing machine. fromProtobuf() functions
   /// deserialize clangd types and translate relative paths into machine-native
Index: clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
===
--- clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
+++ clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
@@ -17,6 +17,7 @@
 #include "index/SymbolOrigin.h"
 #include "support/Logger.h"
 #include "clang/Index/IndexSymbol.h"
+#include "llvm/ADT/DenseSet.h"

[PATCH] D83817: [clangd] Add option to use remote index as static index

2020-07-27 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

mostly good, just a concern about the linking dependence.




Comment at: clang-tools-extra/clangd/CMakeLists.txt:143
   clangToolingSyntax
+  clangdRemoteIndex
   )

the dependence here seems to be a layer violation.  we add remote-index library 
when linking the clangDaemon, but `clangdRemoteIndex` *depends* on `clangDaemon`

I think we should do this when linking the clangd binary (in 
`clangd/tool/CMakeLists.txt`).




Comment at: clang-tools-extra/clangd/tool/ClangdMain.cpp:462
+opt ProjectRoot{
+"project-path",
+cat(Features),

nit: project-path -> project-root.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83817



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


[PATCH] D83817: [clangd] Add option to use remote index as static index

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

Resolve more comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83817

Files:
  clang-tools-extra/clangd/Features.inc.in
  clang-tools-extra/clangd/tool/CMakeLists.txt
  clang-tools-extra/clangd/tool/ClangdMain.cpp


Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -14,6 +14,7 @@
 #include "Transport.h"
 #include "index/Background.h"
 #include "index/Serialization.h"
+#include "index/remote/Client.h"
 #include "refactor/Rename.h"
 #include "support/Path.h"
 #include "support/Shutdown.h"
@@ -449,6 +450,21 @@
 init(true),
 };
 
+#ifdef CLANGD_ENABLE_REMOTE
+opt RemoteIndexAddress{
+"remote-index-address",
+cat(Features),
+desc("Address of the remote index server"),
+};
+
+// FIXME(kirillbobyrev): Should this be the location of compile_commands.json?
+opt ProjectRoot{
+"project-root",
+cat(Features),
+desc("Path to the project root. Requires remote-index-address to be set."),
+};
+#endif
+
 /// Supports a test URI scheme with relaxed constraints for lit tests.
 /// The path in a test URI will be combined with a platform-specific fake
 /// directory to form an absolute path. For example, test:///a.cpp is resolved
@@ -680,6 +696,23 @@
 if (Sync)
   AsyncIndexLoad.wait();
   }
+#ifdef CLANGD_ENABLE_REMOTE
+  if (RemoteIndexAddress.empty() != ProjectRoot.empty()) {
+llvm::errs() << "remote-index-address and project-path have to be "
+"specified at the same time.";
+return 1;
+  }
+  if (!RemoteIndexAddress.empty()) {
+if (IndexFile.empty()) {
+  log("Connecting to remote index at {0}", RemoteIndexAddress);
+  StaticIdx = remote::getClient(RemoteIndexAddress, ProjectRoot);
+  EnableBackgroundIndex = false;
+} else {
+  elog("When enabling remote index, IndexFile should not be specified. "
+   "Only one can be used at time. Remote index will ignored.");
+}
+  }
+#endif
   Opts.StaticIndex = StaticIdx.get();
   Opts.AsyncThreadsCount = WorkerThreadsCount;
   Opts.BuildRecoveryAST = RecoveryAST;
Index: clang-tools-extra/clangd/tool/CMakeLists.txt
===
--- clang-tools-extra/clangd/tool/CMakeLists.txt
+++ clang-tools-extra/clangd/tool/CMakeLists.txt
@@ -27,6 +27,7 @@
   clangToolingCore
   clangToolingRefactoring
   clangToolingSyntax
+  clangdRemoteIndex
   )
 target_link_libraries(clangd
   PRIVATE
Index: clang-tools-extra/clangd/Features.inc.in
===
--- clang-tools-extra/clangd/Features.inc.in
+++ clang-tools-extra/clangd/Features.inc.in
@@ -1 +1,2 @@
 #define CLANGD_BUILD_XPC @CLANGD_BUILD_XPC@
+#define CLANGD_ENABLE_REMOTE @CLANGD_ENABLE_REMTE@


Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -14,6 +14,7 @@
 #include "Transport.h"
 #include "index/Background.h"
 #include "index/Serialization.h"
+#include "index/remote/Client.h"
 #include "refactor/Rename.h"
 #include "support/Path.h"
 #include "support/Shutdown.h"
@@ -449,6 +450,21 @@
 init(true),
 };
 
+#ifdef CLANGD_ENABLE_REMOTE
+opt RemoteIndexAddress{
+"remote-index-address",
+cat(Features),
+desc("Address of the remote index server"),
+};
+
+// FIXME(kirillbobyrev): Should this be the location of compile_commands.json?
+opt ProjectRoot{
+"project-root",
+cat(Features),
+desc("Path to the project root. Requires remote-index-address to be set."),
+};
+#endif
+
 /// Supports a test URI scheme with relaxed constraints for lit tests.
 /// The path in a test URI will be combined with a platform-specific fake
 /// directory to form an absolute path. For example, test:///a.cpp is resolved
@@ -680,6 +696,23 @@
 if (Sync)
   AsyncIndexLoad.wait();
   }
+#ifdef CLANGD_ENABLE_REMOTE
+  if (RemoteIndexAddress.empty() != ProjectRoot.empty()) {
+llvm::errs() << "remote-index-address and project-path have to be "
+"specified at the same time.";
+return 1;
+  }
+  if (!RemoteIndexAddress.empty()) {
+if (IndexFile.empty()) {
+  log("Connecting to remote index at {0}", RemoteIndexAddress);
+  StaticIdx = remote::getClient(RemoteIndexAddress, ProjectRoot);
+  EnableBackgroundIndex = false;
+} else {
+  elog("When enabling remote index, IndexFile should not be specified. "
+   "Only one can be used at time. Remote index will ignored.");
+}
+  }
+#endif
   Opts.StaticIndex = StaticIdx.get();
   Opts.AsyncThreadsCoun

[PATCH] D84525: [clangd] Add marshalling code for all request types

2020-07-27 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: 
clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp:111
+  Req.IDs = std::move(*IDs);
+  Req.Filter = static_cast(Message->filter());
+  if (Message->limit())

can you also add tests for these? (well actually it looks like there are no 
tests for LookupRequests too)



Comment at: clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp:55
+template 
+llvm::Optional> getIDs(MessageT *Message) {
+  llvm::DenseSet Result;

kbobyrev wrote:
> kadircet wrote:
> > I would make this return an expected instead of an optional and print the 
> > error in the callers, instead of logging twice.
> > 
> > (I also think a similar problem is present with the existing `fromProtobuf` 
> > APIs too, they return None in case of failure while logging the error, and 
> > then callers again log the error. I am not sure if we plan to implement 
> > some error handling strategies but even if we did, it feels like 
> > Marshalling is the lowest layer that wouldn't know any other strategy to 
> > handle such errors, so it seems like always returning an error from the 
> > marshalling and letting the caller handle the error sounds like a safe bet. 
> > But no action needed in this patch just stating some ideas in case you find 
> > them useful :D)
> Good point: we thought about error handling and discussed it with Sam on 
> multiple occasions, we tested several strategies and I think converged to 
> this. I don't think it's optimal, you are right, but this code is consistent 
> with the rest of the file.
> 
> The problem here is that in some cases these should actually be `Optional`s 
> (some fields may or may not be missing) and in some cases it makes sense to 
> have `Expected`s, which would leave a weird mixture of these things. But 
> maybe carefully thinking about those cases would simplify the code.
> 
> How do you feel about leaving this as is and maybe carefully thinking about 
> `Optional`s to `Expected` in the next patches?
> Good point: we thought about error handling and discussed it with Sam on 
> multiple occasions, we tested several strategies and I think converged to 
> this. I don't think it's optimal, you are right, but this code is consistent 
> with the rest of the file.

i believe rest of the file doesn't handle such low level primitives, i.e. this 
one is specifically for extracting symbol ids, not for converting bigger proto 
messages into native structs (as done in the rest of the file)

> The problem here is that in some cases these should actually be Optionals 
> (some fields may or may not be missing) and in some cases it makes sense to 
> have Expecteds, which would leave a weird mixture of these things. But maybe 
> carefully thinking about those cases would simplify the code.

i agree that it might be the case in other places, I haven't really looked at 
them carefully and they are also submitted (hence they were in parentheses in 
my previous comment). But I think the situation specifically in here is a 
little bit different.
There is a more clear struct for indicating missing fields in here, an empty 
set of results(and actually you are using that already), and using None to 
indicate an error. I believe using an `Error` (through an `Expected`) is a lot 
clear to indicate that.

> How do you feel about leaving this as is and maybe carefully thinking about 
> Optionals to Expected in the next patches?

As I mentioned, I believe this one is different than other places, and at least 
my taste/reasoning says that this should clearly be an Expected rather than an 
Optional. But it is not a big issue for me totally up to you.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84525



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


[PATCH] D84525: [clangd] Add marshalling code for all request types

2020-07-27 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev planned changes to this revision.
kbobyrev added a comment.

Need to address the review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84525



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


[PATCH] D84499: [clangd] Add more logs and attach tracers to remote index server routines

2020-07-27 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev planned changes to this revision.
kbobyrev added a comment.

As discussed in PM, should move back to duplicated code 😢


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84499



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


[PATCH] D83817: [clangd] Add option to use remote index as static index

2020-07-27 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.

looks good, thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83817



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


[clang-tools-extra] 37ac559 - [clangd] Add option to use remote index as static index

2020-07-27 Thread Kirill Bobyrev via cfe-commits

Author: Kirill Bobyrev
Date: 2020-07-27T11:24:15+02:00
New Revision: 37ac559fccd46dcec246ceb3907c8d3910728c69

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

LOG: [clangd] Add option to use remote index as static index

Reviewers: hokein

Reviewed By: hokein

Subscribers: usaxena95, mgorny, ilya-biryukov, MaskRay, jkorous, arphaman, 
kadircet, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang-tools-extra/clangd/Features.inc.in
clang-tools-extra/clangd/tool/CMakeLists.txt
clang-tools-extra/clangd/tool/ClangdMain.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Features.inc.in 
b/clang-tools-extra/clangd/Features.inc.in
index da75aa67a65b..8584b87c6205 100644
--- a/clang-tools-extra/clangd/Features.inc.in
+++ b/clang-tools-extra/clangd/Features.inc.in
@@ -1 +1,2 @@
 #define CLANGD_BUILD_XPC @CLANGD_BUILD_XPC@
+#define CLANGD_ENABLE_REMOTE @CLANGD_ENABLE_REMTE@

diff  --git a/clang-tools-extra/clangd/tool/CMakeLists.txt 
b/clang-tools-extra/clangd/tool/CMakeLists.txt
index 3368013f5079..670e5a17013a 100644
--- a/clang-tools-extra/clangd/tool/CMakeLists.txt
+++ b/clang-tools-extra/clangd/tool/CMakeLists.txt
@@ -27,6 +27,7 @@ clang_target_link_libraries(clangd
   clangToolingCore
   clangToolingRefactoring
   clangToolingSyntax
+  clangdRemoteIndex
   )
 target_link_libraries(clangd
   PRIVATE

diff  --git a/clang-tools-extra/clangd/tool/ClangdMain.cpp 
b/clang-tools-extra/clangd/tool/ClangdMain.cpp
index 7bce1c062e81..8d1bf5c42260 100644
--- a/clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ b/clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -14,6 +14,7 @@
 #include "Transport.h"
 #include "index/Background.h"
 #include "index/Serialization.h"
+#include "index/remote/Client.h"
 #include "refactor/Rename.h"
 #include "support/Path.h"
 #include "support/Shutdown.h"
@@ -449,6 +450,21 @@ opt EnableConfig{
 init(true),
 };
 
+#ifdef CLANGD_ENABLE_REMOTE
+opt RemoteIndexAddress{
+"remote-index-address",
+cat(Features),
+desc("Address of the remote index server"),
+};
+
+// FIXME(kirillbobyrev): Should this be the location of compile_commands.json?
+opt ProjectRoot{
+"project-root",
+cat(Features),
+desc("Path to the project root. Requires remote-index-address to be set."),
+};
+#endif
+
 /// Supports a test URI scheme with relaxed constraints for lit tests.
 /// The path in a test URI will be combined with a platform-specific fake
 /// directory to form an absolute path. For example, test:///a.cpp is resolved
@@ -680,6 +696,23 @@ clangd accepts flags on the commandline, and in the 
CLANGD_FLAGS environment var
 if (Sync)
   AsyncIndexLoad.wait();
   }
+#ifdef CLANGD_ENABLE_REMOTE
+  if (RemoteIndexAddress.empty() != ProjectRoot.empty()) {
+llvm::errs() << "remote-index-address and project-path have to be "
+"specified at the same time.";
+return 1;
+  }
+  if (!RemoteIndexAddress.empty()) {
+if (IndexFile.empty()) {
+  log("Connecting to remote index at {0}", RemoteIndexAddress);
+  StaticIdx = remote::getClient(RemoteIndexAddress, ProjectRoot);
+  EnableBackgroundIndex = false;
+} else {
+  elog("When enabling remote index, IndexFile should not be specified. "
+   "Only one can be used at time. Remote index will ignored.");
+}
+  }
+#endif
   Opts.StaticIndex = StaticIdx.get();
   Opts.AsyncThreadsCount = WorkerThreadsCount;
   Opts.BuildRecoveryAST = RecoveryAST;



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


[PATCH] D83817: [clangd] Add option to use remote index as static index

2020-07-27 Thread Kirill Bobyrev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG37ac559fccd4: [clangd] Add option to use remote index as 
static index (authored by kbobyrev).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83817

Files:
  clang-tools-extra/clangd/Features.inc.in
  clang-tools-extra/clangd/tool/CMakeLists.txt
  clang-tools-extra/clangd/tool/ClangdMain.cpp


Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -14,6 +14,7 @@
 #include "Transport.h"
 #include "index/Background.h"
 #include "index/Serialization.h"
+#include "index/remote/Client.h"
 #include "refactor/Rename.h"
 #include "support/Path.h"
 #include "support/Shutdown.h"
@@ -449,6 +450,21 @@
 init(true),
 };
 
+#ifdef CLANGD_ENABLE_REMOTE
+opt RemoteIndexAddress{
+"remote-index-address",
+cat(Features),
+desc("Address of the remote index server"),
+};
+
+// FIXME(kirillbobyrev): Should this be the location of compile_commands.json?
+opt ProjectRoot{
+"project-root",
+cat(Features),
+desc("Path to the project root. Requires remote-index-address to be set."),
+};
+#endif
+
 /// Supports a test URI scheme with relaxed constraints for lit tests.
 /// The path in a test URI will be combined with a platform-specific fake
 /// directory to form an absolute path. For example, test:///a.cpp is resolved
@@ -680,6 +696,23 @@
 if (Sync)
   AsyncIndexLoad.wait();
   }
+#ifdef CLANGD_ENABLE_REMOTE
+  if (RemoteIndexAddress.empty() != ProjectRoot.empty()) {
+llvm::errs() << "remote-index-address and project-path have to be "
+"specified at the same time.";
+return 1;
+  }
+  if (!RemoteIndexAddress.empty()) {
+if (IndexFile.empty()) {
+  log("Connecting to remote index at {0}", RemoteIndexAddress);
+  StaticIdx = remote::getClient(RemoteIndexAddress, ProjectRoot);
+  EnableBackgroundIndex = false;
+} else {
+  elog("When enabling remote index, IndexFile should not be specified. "
+   "Only one can be used at time. Remote index will ignored.");
+}
+  }
+#endif
   Opts.StaticIndex = StaticIdx.get();
   Opts.AsyncThreadsCount = WorkerThreadsCount;
   Opts.BuildRecoveryAST = RecoveryAST;
Index: clang-tools-extra/clangd/tool/CMakeLists.txt
===
--- clang-tools-extra/clangd/tool/CMakeLists.txt
+++ clang-tools-extra/clangd/tool/CMakeLists.txt
@@ -27,6 +27,7 @@
   clangToolingCore
   clangToolingRefactoring
   clangToolingSyntax
+  clangdRemoteIndex
   )
 target_link_libraries(clangd
   PRIVATE
Index: clang-tools-extra/clangd/Features.inc.in
===
--- clang-tools-extra/clangd/Features.inc.in
+++ clang-tools-extra/clangd/Features.inc.in
@@ -1 +1,2 @@
 #define CLANGD_BUILD_XPC @CLANGD_BUILD_XPC@
+#define CLANGD_ENABLE_REMOTE @CLANGD_ENABLE_REMTE@


Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -14,6 +14,7 @@
 #include "Transport.h"
 #include "index/Background.h"
 #include "index/Serialization.h"
+#include "index/remote/Client.h"
 #include "refactor/Rename.h"
 #include "support/Path.h"
 #include "support/Shutdown.h"
@@ -449,6 +450,21 @@
 init(true),
 };
 
+#ifdef CLANGD_ENABLE_REMOTE
+opt RemoteIndexAddress{
+"remote-index-address",
+cat(Features),
+desc("Address of the remote index server"),
+};
+
+// FIXME(kirillbobyrev): Should this be the location of compile_commands.json?
+opt ProjectRoot{
+"project-root",
+cat(Features),
+desc("Path to the project root. Requires remote-index-address to be set."),
+};
+#endif
+
 /// Supports a test URI scheme with relaxed constraints for lit tests.
 /// The path in a test URI will be combined with a platform-specific fake
 /// directory to form an absolute path. For example, test:///a.cpp is resolved
@@ -680,6 +696,23 @@
 if (Sync)
   AsyncIndexLoad.wait();
   }
+#ifdef CLANGD_ENABLE_REMOTE
+  if (RemoteIndexAddress.empty() != ProjectRoot.empty()) {
+llvm::errs() << "remote-index-address and project-path have to be "
+"specified at the same time.";
+return 1;
+  }
+  if (!RemoteIndexAddress.empty()) {
+if (IndexFile.empty()) {
+  log("Connecting to remote index at {0}", RemoteIndexAddress);
+  StaticIdx = remote::getClient(RemoteIndexAddress, ProjectRoot);
+  EnableBackgroundIndex = false;
+} else {
+  elog("When enabling remote index, IndexFile should not be specified. "
+   "Only one can be used at time. Remote index will ignored.");
+}
+  }
+#endif
   Opts.StaticIn

[PATCH] D78899: [Driver] Add callback to Command execution

2020-07-27 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff updated this revision to Diff 280827.
sepavloff added a comment.

Rebased patch


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78899

Files:
  clang/include/clang/Driver/Compilation.h
  clang/lib/Driver/Compilation.cpp
  clang/unittests/Driver/ToolChainTest.cpp


Index: clang/unittests/Driver/ToolChainTest.cpp
===
--- clang/unittests/Driver/ToolChainTest.cpp
+++ clang/unittests/Driver/ToolChainTest.cpp
@@ -259,4 +259,29 @@
   EXPECT_STREQ(Res.DriverMode, "--driver-mode=cl");
   EXPECT_FALSE(Res.TargetIsValid);
 }
+
+TEST(ToolChainTest, PostCallback) {
+  IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions();
+  IntrusiveRefCntPtr DiagID(new DiagnosticIDs());
+  struct TestDiagnosticConsumer : public DiagnosticConsumer {};
+  DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer);
+  IntrusiveRefCntPtr InMemoryFileSystem(
+  new llvm::vfs::InMemoryFileSystem);
+
+  // The executable path must not exist.
+  Driver CCDriver("/home/test/bin/clang", "arm-linux-gnueabi", Diags,
+  InMemoryFileSystem);
+  CCDriver.setCheckInputsExist(false);
+  std::unique_ptr CC(
+  CCDriver.BuildCompilation({"/home/test/bin/clang", "foo.cpp"}));
+  bool CallbackHasCalled = false;
+  CC->setPostCallback(
+  [&](const Command &C, int Ret) { CallbackHasCalled = true; });
+  const JobList &Jobs = CC->getJobs();
+  auto &CmdCompile = Jobs.getJobs().front();
+  const Command *FailingCmd = nullptr;
+  CC->ExecuteCommand(*CmdCompile, FailingCmd);
+  EXPECT_TRUE(CallbackHasCalled);
+}
+
 } // end anonymous namespace.
Index: clang/lib/Driver/Compilation.cpp
===
--- clang/lib/Driver/Compilation.cpp
+++ clang/lib/Driver/Compilation.cpp
@@ -193,6 +193,8 @@
   std::string Error;
   bool ExecutionFailed;
   int Res = C.Execute(Redirects, &Error, &ExecutionFailed);
+  if (PostCallback)
+PostCallback(C, Res);
   if (!Error.empty()) {
 assert(Res && "Error string set with 0 result code!");
 getDriver().Diag(diag::err_drv_command_failure) << Error;
Index: clang/include/clang/Driver/Compilation.h
===
--- clang/include/clang/Driver/Compilation.h
+++ clang/include/clang/Driver/Compilation.h
@@ -115,6 +115,9 @@
   /// Optional redirection for stdin, stdout, stderr.
   std::vector> Redirects;
 
+  /// Callback called after the command has been executed.
+  std::function PostCallback;
+
   /// Whether we're compiling for diagnostic purposes.
   bool ForDiagnostics = false;
 
@@ -212,6 +215,10 @@
 return FailureResultFiles;
   }
 
+  void setPostCallback(const std::function &CB) {
+PostCallback = CB;
+  }
+
   /// Returns the sysroot path.
   StringRef getSysRoot() const;
 


Index: clang/unittests/Driver/ToolChainTest.cpp
===
--- clang/unittests/Driver/ToolChainTest.cpp
+++ clang/unittests/Driver/ToolChainTest.cpp
@@ -259,4 +259,29 @@
   EXPECT_STREQ(Res.DriverMode, "--driver-mode=cl");
   EXPECT_FALSE(Res.TargetIsValid);
 }
+
+TEST(ToolChainTest, PostCallback) {
+  IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions();
+  IntrusiveRefCntPtr DiagID(new DiagnosticIDs());
+  struct TestDiagnosticConsumer : public DiagnosticConsumer {};
+  DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer);
+  IntrusiveRefCntPtr InMemoryFileSystem(
+  new llvm::vfs::InMemoryFileSystem);
+
+  // The executable path must not exist.
+  Driver CCDriver("/home/test/bin/clang", "arm-linux-gnueabi", Diags,
+  InMemoryFileSystem);
+  CCDriver.setCheckInputsExist(false);
+  std::unique_ptr CC(
+  CCDriver.BuildCompilation({"/home/test/bin/clang", "foo.cpp"}));
+  bool CallbackHasCalled = false;
+  CC->setPostCallback(
+  [&](const Command &C, int Ret) { CallbackHasCalled = true; });
+  const JobList &Jobs = CC->getJobs();
+  auto &CmdCompile = Jobs.getJobs().front();
+  const Command *FailingCmd = nullptr;
+  CC->ExecuteCommand(*CmdCompile, FailingCmd);
+  EXPECT_TRUE(CallbackHasCalled);
+}
+
 } // end anonymous namespace.
Index: clang/lib/Driver/Compilation.cpp
===
--- clang/lib/Driver/Compilation.cpp
+++ clang/lib/Driver/Compilation.cpp
@@ -193,6 +193,8 @@
   std::string Error;
   bool ExecutionFailed;
   int Res = C.Execute(Redirects, &Error, &ExecutionFailed);
+  if (PostCallback)
+PostCallback(C, Res);
   if (!Error.empty()) {
 assert(Res && "Error string set with 0 result code!");
 getDriver().Diag(diag::err_drv_command_failure) << Error;
Index: clang/include/clang/Driver/Compilation.h
===
--- clang/include/clang/Driver/Compilation.h
+++ clang/include/clang/Driver/Compilation.h
@@

[PATCH] D84005: Introduce ns_error_domain attribute.

2020-07-27 Thread Michael Forster via Phabricator via cfe-commits
MForster updated this revision to Diff 280828.
MForster marked 3 inline comments as done.
MForster added a comment.

Address review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84005

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/Sema/ns_error_enum.c

Index: clang/test/Sema/ns_error_enum.c
===
--- /dev/null
+++ clang/test/Sema/ns_error_enum.c
@@ -0,0 +1,54 @@
+// RUN: %clang_cc1 -verify %s -x objective-c
+// RUN: %clang_cc1 -verify %s -x objective-c++
+
+
+#define CF_ENUM(_type, _name) enum _name : _type _name; enum _name : _type
+#define NS_ENUM(_type, _name) CF_ENUM(_type, _name)
+
+#define NS_ERROR_ENUM(_type, _name, _domain)  \
+  enum _name : _type _name; enum __attribute__((ns_error_domain(_domain))) _name : _type
+
+typedef NS_ENUM(unsigned, MyEnum) {
+  MyFirst,
+  MySecond,
+};
+
+typedef NS_ENUM(invalidType, MyInvalidEnum) {
+// expected-error@-1{{unknown type name 'invalidType'}}
+// expected-error@-2{{unknown type name 'invalidType'}}
+  MyFirstInvalid,
+  MySecondInvalid,
+};
+
+@interface NSString
+@end
+
+extern NSString *const MyErrorDomain;
+typedef NS_ERROR_ENUM(unsigned char, MyErrorEnum, MyErrorDomain) {
+	MyErrFirst,
+	MyErrSecond,
+};
+struct __attribute__((ns_error_domain(MyErrorDomain))) MyStructWithErrorDomain {};
+  // expected-error@-1{{'ns_error_domain' attribute only applies to enums}}
+
+int __attribute__((ns_error_domain(MyErrorDomain))) NotTagDecl;
+  // expected-error@-1{{'ns_error_domain' attribute only applies to enums}}
+
+enum __attribute__((ns_error_domain())) NoArg { NoArgError };
+  // expected-error@-1{{'ns_error_domain' attribute takes one argument}}
+
+enum __attribute__((ns_error_domain())) TwoArgs { TwoArgsError };
+  // expected-error@-1{{'ns_error_domain' attribute takes one argument}}
+
+typedef NS_ERROR_ENUM(unsigned char, MyErrorEnumInvalid, InvalidDomain) {
+	// expected-error@-1{{domain argument 'InvalidDomain' does not refer to global constant}}
+	MyErrFirstInvalid,
+	MyErrSecondInvalid,
+};
+
+typedef NS_ERROR_ENUM(unsigned char, MyErrorEnumInvalid, "domain-string");
+  // expected-error@-1{{'ns_error_domain' attribute requires parameter 1 to be an identifier}}
+
+void foo() {}
+typedef NS_ERROR_ENUM(unsigned char, MyErrorEnumInvalidFunction, foo);
+  // expected-error@-1{{domain argument 'foo' does not refer to global constant}}
Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -80,6 +80,7 @@
 // CHECK-NEXT: MipsShortCall (SubjectMatchRule_function)
 // CHECK-NEXT: NSConsumed (SubjectMatchRule_variable_is_parameter)
 // CHECK-NEXT: NSConsumesSelf (SubjectMatchRule_objc_method)
+// CHECK-NEXT: NSErrorDomain (SubjectMatchRule_enum)
 // CHECK-NEXT: Naked (SubjectMatchRule_function)
 // CHECK-NEXT: NoBuiltin (SubjectMatchRule_function)
 // CHECK-NEXT: NoCommon (SubjectMatchRule_variable)
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -5322,6 +5322,35 @@
   D->addAttr(::new (S.Context) ObjCRequiresSuperAttr(S.Context, Attrs));
 }
 
+static void handleNSErrorDomain(Sema &S, Decl *D, const ParsedAttr &AL) {
+  IdentifierLoc *IdentLoc = AL.isArgIdent(0) ? AL.getArgAsIdent(0) : nullptr;
+  if (!IdentLoc || !IdentLoc->Ident) {
+// Try to locate the argument directly
+SourceLocation Loc = AL.getLoc();
+if (const Expr *E = AL.getArgAsExpr(0))
+  Loc = E->getBeginLoc();
+
+S.Diag(Loc, diag::err_attribute_argument_n_type)
+<< AL << 1 << AANT_ArgumentIdentifier;
+
+return;
+  }
+
+  // Verify that the identifier is a valid decl in the C decl namespace
+  LookupResult lookupResult(S, DeclarationName(IdentLoc->Ident),
+SourceLocation(),
+Sema::LookupNameKind::LookupOrdinaryName);
+  if (!S.LookupName(lookupResult, S.TUScope) ||
+  !lookupResult.getAsSingle()) {
+S.Diag(IdentLoc->Loc, diag::err_nserrordomain_invalid_decl)
+<< IdentLoc->Ident;
+return;
+  }
+
+  D->addAttr(::new (S.Context)
+ NSErrorDomainAttr(S.Context, AL, IdentLoc->Ident));
+}
+
 static void handleObjCBridgeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
   IdentifierLoc *Parm = AL.isArgIdent(0) ? AL.getArgAsIdent(0) : nullptr;
 
@@ -7093,6 +7122,9 @@
   case ParsedAttr::AT_ObjCBoxable:
 handleObjCBoxable(S, D, AL);
 break;
+  case ParsedAttr::AT_NSErrorDomain:

[PATCH] D84005: Introduce ns_error_domain attribute.

2020-07-27 Thread Michael Forster via Phabricator via cfe-commits
MForster marked an inline comment as done.
MForster added inline comments.



Comment at: clang/test/Sema/ns_error_enum.c:25
+
+const char *MyErrorDomain;
+typedef NS_ERROR_ENUM(unsigned char, MyErrorEnum, MyErrorDomain) {

gribozavr2 wrote:
> const char * => NSString * const? You'd need to define a fake NSString type, 
> but that should be rather easy:
> 
> ```
> @interface NSString
> @end
> ```
> const char * => NSString * const?

Done.

Turns out that this makes the test incompatible with C and C++. Some more 
research makes me believe that this feature is only supposed to be used from 
ObjC(++). I removed the C/C++ RUN lines from this test. I will also send a 
follow-up change to turn this into an error in those languages. But I want to 
make it a separate change because of the potential for breakage in existing 
code.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84005



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


[PATCH] D84005: Introduce ns_error_domain attribute.

2020-07-27 Thread Michael Forster via Phabricator via cfe-commits
MForster updated this revision to Diff 280829.
MForster marked an inline comment as done.
MForster added a comment.

Fix typo


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84005

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/Sema/ns_error_enum.c

Index: clang/test/Sema/ns_error_enum.c
===
--- /dev/null
+++ clang/test/Sema/ns_error_enum.c
@@ -0,0 +1,54 @@
+// RUN: %clang_cc1 -verify %s -x objective-c
+// RUN: %clang_cc1 -verify %s -x objective-c++
+
+
+#define CF_ENUM(_type, _name) enum _name : _type _name; enum _name : _type
+#define NS_ENUM(_type, _name) CF_ENUM(_type, _name)
+
+#define NS_ERROR_ENUM(_type, _name, _domain)  \
+  enum _name : _type _name; enum __attribute__((ns_error_domain(_domain))) _name : _type
+
+typedef NS_ENUM(unsigned, MyEnum) {
+  MyFirst,
+  MySecond,
+};
+
+typedef NS_ENUM(invalidType, MyInvalidEnum) {
+// expected-error@-1{{unknown type name 'invalidType'}}
+// expected-error@-2{{unknown type name 'invalidType'}}
+  MyFirstInvalid,
+  MySecondInvalid,
+};
+
+@interface NSString
+@end
+
+extern NSString *const MyErrorDomain;
+typedef NS_ERROR_ENUM(unsigned char, MyErrorEnum, MyErrorDomain) {
+	MyErrFirst,
+	MyErrSecond,
+};
+struct __attribute__((ns_error_domain(MyErrorDomain))) MyStructWithErrorDomain {};
+// expected-error@-1{{'ns_error_domain' attribute only applies to enums}}
+
+int __attribute__((ns_error_domain(MyErrorDomain))) NotTagDecl;
+  // expected-error@-1{{'ns_error_domain' attribute only applies to enums}}
+
+enum __attribute__((ns_error_domain())) NoArg { NoArgError };
+// expected-error@-1{{'ns_error_domain' attribute takes one argument}}
+
+enum __attribute__((ns_error_domain(MyErrorDomain, MyErrorDomain))) TwoArgs { TwoArgsError };
+// expected-error@-1{{'ns_error_domain' attribute takes one argument}}
+
+typedef NS_ERROR_ENUM(unsigned char, MyErrorEnumInvalid, InvalidDomain) {
+	// expected-error@-1{{domain argument 'InvalidDomain' does not refer to global constant}}
+	MyErrFirstInvalid,
+	MyErrSecondInvalid,
+};
+
+typedef NS_ERROR_ENUM(unsigned char, MyErrorEnumInvalid, "domain-string");
+  // expected-error@-1{{'ns_error_domain' attribute requires parameter 1 to be an identifier}}
+
+void foo() {}
+typedef NS_ERROR_ENUM(unsigned char, MyErrorEnumInvalidFunction, foo);
+  // expected-error@-1{{domain argument 'foo' does not refer to global constant}}
Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -80,6 +80,7 @@
 // CHECK-NEXT: MipsShortCall (SubjectMatchRule_function)
 // CHECK-NEXT: NSConsumed (SubjectMatchRule_variable_is_parameter)
 // CHECK-NEXT: NSConsumesSelf (SubjectMatchRule_objc_method)
+// CHECK-NEXT: NSErrorDomain (SubjectMatchRule_enum)
 // CHECK-NEXT: Naked (SubjectMatchRule_function)
 // CHECK-NEXT: NoBuiltin (SubjectMatchRule_function)
 // CHECK-NEXT: NoCommon (SubjectMatchRule_variable)
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -5322,6 +5322,35 @@
   D->addAttr(::new (S.Context) ObjCRequiresSuperAttr(S.Context, Attrs));
 }
 
+static void handleNSErrorDomain(Sema &S, Decl *D, const ParsedAttr &AL) {
+  IdentifierLoc *IdentLoc = AL.isArgIdent(0) ? AL.getArgAsIdent(0) : nullptr;
+  if (!IdentLoc || !IdentLoc->Ident) {
+// Try to locate the argument directly
+SourceLocation Loc = AL.getLoc();
+if (const Expr *E = AL.getArgAsExpr(0))
+  Loc = E->getBeginLoc();
+
+S.Diag(Loc, diag::err_attribute_argument_n_type)
+<< AL << 1 << AANT_ArgumentIdentifier;
+
+return;
+  }
+
+  // Verify that the identifier is a valid decl in the C decl namespace
+  LookupResult lookupResult(S, DeclarationName(IdentLoc->Ident),
+SourceLocation(),
+Sema::LookupNameKind::LookupOrdinaryName);
+  if (!S.LookupName(lookupResult, S.TUScope) ||
+  !lookupResult.getAsSingle()) {
+S.Diag(IdentLoc->Loc, diag::err_nserrordomain_invalid_decl)
+<< IdentLoc->Ident;
+return;
+  }
+
+  D->addAttr(::new (S.Context)
+ NSErrorDomainAttr(S.Context, AL, IdentLoc->Ident));
+}
+
 static void handleObjCBridgeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
   IdentifierLoc *Parm = AL.isArgIdent(0) ? AL.getArgAsIdent(0) : nullptr;
 
@@ -7093,6 +7122,9 @@
   case ParsedAttr::AT_ObjCBoxable:
 handleObjCBoxable(S, D, AL);
 break;
+  case ParsedAttr::AT_NSErrorD

[PATCH] D84306: [clang-format][NFC] Be more careful about the layout of FormatToken.

2020-07-27 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

a new minor Nits but looks good.




Comment at: clang/lib/Format/ContinuationIndenter.cpp:1488
 (Style.ExperimentalAutoDetectBinPacking &&
- (Current.PackingKind == PPK_OnePerLine ||
+ (Current.getPackingKind() == PPK_OnePerLine ||
   (!BinPackInconclusiveFunctions &&

Current.is(PPK_OnePerLine)



Comment at: clang/lib/Format/ContinuationIndenter.cpp:1490
   (!BinPackInconclusiveFunctions &&
-   Current.PackingKind == PPK_Inconclusive)));
+   Current.getPackingKind() == PPK_Inconclusive)));
 

Current.is(PPK_Inconclusive)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84306



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


[PATCH] D84005: Introduce ns_error_domain attribute.

2020-07-27 Thread Michael Forster via Phabricator via cfe-commits
MForster updated this revision to Diff 280831.
MForster added a comment.

Rename test back to ns_error_enum.m


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84005

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/Sema/ns_error_enum.m

Index: clang/test/Sema/ns_error_enum.m
===
--- /dev/null
+++ clang/test/Sema/ns_error_enum.m
@@ -0,0 +1,54 @@
+// RUN: %clang_cc1 -verify %s -x objective-c
+// RUN: %clang_cc1 -verify %s -x objective-c++
+
+
+#define CF_ENUM(_type, _name) enum _name : _type _name; enum _name : _type
+#define NS_ENUM(_type, _name) CF_ENUM(_type, _name)
+
+#define NS_ERROR_ENUM(_type, _name, _domain)  \
+  enum _name : _type _name; enum __attribute__((ns_error_domain(_domain))) _name : _type
+
+typedef NS_ENUM(unsigned, MyEnum) {
+  MyFirst,
+  MySecond,
+};
+
+typedef NS_ENUM(invalidType, MyInvalidEnum) {
+// expected-error@-1{{unknown type name 'invalidType'}}
+// expected-error@-2{{unknown type name 'invalidType'}}
+  MyFirstInvalid,
+  MySecondInvalid,
+};
+
+@interface NSString
+@end
+
+extern NSString *const MyErrorDomain;
+typedef NS_ERROR_ENUM(unsigned char, MyErrorEnum, MyErrorDomain) {
+	MyErrFirst,
+	MyErrSecond,
+};
+struct __attribute__((ns_error_domain(MyErrorDomain))) MyStructWithErrorDomain {};
+// expected-error@-1{{'ns_error_domain' attribute only applies to enums}}
+
+int __attribute__((ns_error_domain(MyErrorDomain))) NotTagDecl;
+  // expected-error@-1{{'ns_error_domain' attribute only applies to enums}}
+
+enum __attribute__((ns_error_domain())) NoArg { NoArgError };
+// expected-error@-1{{'ns_error_domain' attribute takes one argument}}
+
+enum __attribute__((ns_error_domain(MyErrorDomain, MyErrorDomain))) TwoArgs { TwoArgsError };
+// expected-error@-1{{'ns_error_domain' attribute takes one argument}}
+
+typedef NS_ERROR_ENUM(unsigned char, MyErrorEnumInvalid, InvalidDomain) {
+	// expected-error@-1{{domain argument 'InvalidDomain' does not refer to global constant}}
+	MyErrFirstInvalid,
+	MyErrSecondInvalid,
+};
+
+typedef NS_ERROR_ENUM(unsigned char, MyErrorEnumInvalid, "domain-string");
+  // expected-error@-1{{'ns_error_domain' attribute requires parameter 1 to be an identifier}}
+
+void foo() {}
+typedef NS_ERROR_ENUM(unsigned char, MyErrorEnumInvalidFunction, foo);
+  // expected-error@-1{{domain argument 'foo' does not refer to global constant}}
Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -80,6 +80,7 @@
 // CHECK-NEXT: MipsShortCall (SubjectMatchRule_function)
 // CHECK-NEXT: NSConsumed (SubjectMatchRule_variable_is_parameter)
 // CHECK-NEXT: NSConsumesSelf (SubjectMatchRule_objc_method)
+// CHECK-NEXT: NSErrorDomain (SubjectMatchRule_enum)
 // CHECK-NEXT: Naked (SubjectMatchRule_function)
 // CHECK-NEXT: NoBuiltin (SubjectMatchRule_function)
 // CHECK-NEXT: NoCommon (SubjectMatchRule_variable)
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -5322,6 +5322,35 @@
   D->addAttr(::new (S.Context) ObjCRequiresSuperAttr(S.Context, Attrs));
 }
 
+static void handleNSErrorDomain(Sema &S, Decl *D, const ParsedAttr &AL) {
+  IdentifierLoc *IdentLoc = AL.isArgIdent(0) ? AL.getArgAsIdent(0) : nullptr;
+  if (!IdentLoc || !IdentLoc->Ident) {
+// Try to locate the argument directly
+SourceLocation Loc = AL.getLoc();
+if (const Expr *E = AL.getArgAsExpr(0))
+  Loc = E->getBeginLoc();
+
+S.Diag(Loc, diag::err_attribute_argument_n_type)
+<< AL << 1 << AANT_ArgumentIdentifier;
+
+return;
+  }
+
+  // Verify that the identifier is a valid decl in the C decl namespace
+  LookupResult lookupResult(S, DeclarationName(IdentLoc->Ident),
+SourceLocation(),
+Sema::LookupNameKind::LookupOrdinaryName);
+  if (!S.LookupName(lookupResult, S.TUScope) ||
+  !lookupResult.getAsSingle()) {
+S.Diag(IdentLoc->Loc, diag::err_nserrordomain_invalid_decl)
+<< IdentLoc->Ident;
+return;
+  }
+
+  D->addAttr(::new (S.Context)
+ NSErrorDomainAttr(S.Context, AL, IdentLoc->Ident));
+}
+
 static void handleObjCBridgeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
   IdentifierLoc *Parm = AL.isArgIdent(0) ? AL.getArgAsIdent(0) : nullptr;
 
@@ -7093,6 +7122,9 @@
   case ParsedAttr::AT_ObjCBoxable:
 handleObjCBoxable(S, D, AL);
 break;
+  case ParsedAttr::AT_NSErrorDomain:
+hand

[PATCH] D84136: [clang] Fix visitation of ConceptSpecializationExpr in constrained-parameter

2020-07-27 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno added a comment.

> Will do. By the way, is there something more tailored than ninja check-clang 
> to run these ast-dump tests? ninja check-clang takes quite a while to run...

You can use `check-clang-ast` for the lit tests in `AST/`, `check-clang-sema` 
for the lit tests in `Sema/` and so on. Or you can run an individual test with 
`llvm-lit ~/path/to/the/lit/test`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84136



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


[PATCH] D84461: [Concepts] Fix ast dump for immediately declared constraint.

2020-07-27 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno added inline comments.



Comment at: clang/test/AST/ast-dump-concepts.cpp:1
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -std=c++2a -ast-dump 
-ast-dump-filter Foo %s | FileCheck -strict-whitespace %s
+

Can you also test for serialization by round-tripping through a PCH (see the 
other AST dump tests for examples; you just need to add two RUN lines)?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84461



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


[PATCH] D80873: [clang][cmake] Force CMAKE_LINKER for multistage build in case of BOOTSTRAP_LLVM_ENABLE_LLD and MSVC

2020-07-27 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb updated this revision to Diff 280835.
krisb added a comment.

Addressed the review comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80873

Files:
  clang/CMakeLists.txt
  llvm/cmake/modules/HandleLLVMOptions.cmake


Index: llvm/cmake/modules/HandleLLVMOptions.cmake
===
--- llvm/cmake/modules/HandleLLVMOptions.cmake
+++ llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -261,7 +261,12 @@
   if ( LLVM_USE_LINKER )
 message(FATAL_ERROR "LLVM_ENABLE_LLD and LLVM_USE_LINKER can't be set at 
the same time")
   endif()
-  set(LLVM_USE_LINKER "lld")
+  # In case of MSVC cmake always invokes the linker directly, so the linker
+  # should be specified by CMAKE_LINKER cmake variable instead of by -fuse-ld
+  # compiler option.
+  if ( NOT MSVC )
+set(LLVM_USE_LINKER "lld")
+  endif()
 endif()
 
 if( LLVM_USE_LINKER )
Index: clang/CMakeLists.txt
===
--- clang/CMakeLists.txt
+++ clang/CMakeLists.txt
@@ -757,6 +757,14 @@
 -DCMAKE_ASM_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/${C_COMPILER}
 -DCMAKE_ASM_COMPILER_ID=Clang)
 
+  # cmake requires CMAKE_LINKER to be specified if the compiler is MSVC-like,
+  # otherwise it defaults the linker to be link.exe.
+  if(BOOTSTRAP_LLVM_ENABLE_LLD)
+if((WIN32 AND NOT BOOTSTRAP_CMAKE_SYSTEM_NAME) OR 
BOOTSTRAP_CMAKE_SYSTEM_NAME STREQUAL "Windows")
+  set(${CLANG_STAGE}_LINKER 
-DCMAKE_LINKER=${LLVM_RUNTIME_OUTPUT_INTDIR}/lld-link${CMAKE_EXECUTABLE_SUFFIX})
+endif()
+  endif()
+
   if(BOOTSTRAP_CMAKE_SYSTEM_NAME)
 set(${CLANG_STAGE}_CONFIG 
-DLLVM_CONFIG_PATH=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-config)
 set(${CLANG_STAGE}_TABLEGEN


Index: llvm/cmake/modules/HandleLLVMOptions.cmake
===
--- llvm/cmake/modules/HandleLLVMOptions.cmake
+++ llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -261,7 +261,12 @@
   if ( LLVM_USE_LINKER )
 message(FATAL_ERROR "LLVM_ENABLE_LLD and LLVM_USE_LINKER can't be set at the same time")
   endif()
-  set(LLVM_USE_LINKER "lld")
+  # In case of MSVC cmake always invokes the linker directly, so the linker
+  # should be specified by CMAKE_LINKER cmake variable instead of by -fuse-ld
+  # compiler option.
+  if ( NOT MSVC )
+set(LLVM_USE_LINKER "lld")
+  endif()
 endif()
 
 if( LLVM_USE_LINKER )
Index: clang/CMakeLists.txt
===
--- clang/CMakeLists.txt
+++ clang/CMakeLists.txt
@@ -757,6 +757,14 @@
 -DCMAKE_ASM_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/${C_COMPILER}
 -DCMAKE_ASM_COMPILER_ID=Clang)
 
+  # cmake requires CMAKE_LINKER to be specified if the compiler is MSVC-like,
+  # otherwise it defaults the linker to be link.exe.
+  if(BOOTSTRAP_LLVM_ENABLE_LLD)
+if((WIN32 AND NOT BOOTSTRAP_CMAKE_SYSTEM_NAME) OR BOOTSTRAP_CMAKE_SYSTEM_NAME STREQUAL "Windows")
+  set(${CLANG_STAGE}_LINKER -DCMAKE_LINKER=${LLVM_RUNTIME_OUTPUT_INTDIR}/lld-link${CMAKE_EXECUTABLE_SUFFIX})
+endif()
+  endif()
+
   if(BOOTSTRAP_CMAKE_SYSTEM_NAME)
 set(${CLANG_STAGE}_CONFIG -DLLVM_CONFIG_PATH=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-config)
 set(${CLANG_STAGE}_TABLEGEN
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D84613: [clang] Fix ConceptSpecializationExpr::getEndLoc()

2020-07-27 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang/test/AST/ast-dump-concepts.cpp:14
   // CHECK-NEXT: `-TemplateArgument {{.*}} type 'int'
   template  R>
   Foo(R) requires(true);

could you also verify what's the end loc for this case? 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84613



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


[PATCH] D84525: [clangd] Add marshalling code for all request types

2020-07-27 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 280840.
kbobyrev marked 4 inline comments as done.
kbobyrev added a comment.

Resolve the remaining comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84525

Files:
  clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
  clang-tools-extra/clangd/index/remote/marshalling/Marshalling.h
  clang-tools-extra/clangd/index/remote/server/Server.cpp
  clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp

Index: clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
===
--- clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
+++ clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
@@ -18,6 +18,7 @@
 #include "clang/Index/IndexSymbol.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Error.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/StringSaver.h"
 #include "gmock/gmock.h"
@@ -271,6 +272,29 @@
   EXPECT_EQ(toYAML(Sym), toYAML(*Deserialized));
 }
 
+TEST(RemoteMarshallingTest, LookupRequestSerialization) {
+  clangd::LookupRequest Request;
+  auto ID = SymbolID::fromStr("057557CEBF6E6B2D");
+  ASSERT_TRUE(bool(ID));
+  Request.IDs.insert(*ID);
+  ID = SymbolID::fromStr("0575A7CEBF6E6B2F");
+  ASSERT_TRUE(bool(ID));
+  Request.IDs.insert(*ID);
+
+  Marshaller ProtobufMarshaller(testPath("remote/"), testPath("local/"));
+
+  auto Serialized = ProtobufMarshaller.toProtobuf(Request);
+  EXPECT_EQ(Serialized.ids_size(), 2);
+  auto Deserialized = ProtobufMarshaller.fromProtobuf(&Serialized);
+  ASSERT_TRUE(bool(Deserialized));
+  EXPECT_EQ(Deserialized->IDs.size(), 2U);
+
+  Serialized.add_ids("Invalid Symbol ID");
+  Deserialized = ProtobufMarshaller.fromProtobuf(&Serialized);
+  ASSERT_FALSE(bool(Deserialized));
+  llvm::consumeError(Deserialized.takeError());
+}
+
 TEST(RemoteMarshallingTest, FuzzyFindRequestSerialization) {
   clangd::FuzzyFindRequest Request;
   Request.ProximityPaths = {testPath("local/Header.h"),
@@ -280,11 +304,42 @@
   auto Serialized = ProtobufMarshaller.toProtobuf(Request);
   EXPECT_EQ(Serialized.proximity_paths_size(), 2);
   auto Deserialized = ProtobufMarshaller.fromProtobuf(&Serialized);
-  EXPECT_THAT(Deserialized.ProximityPaths,
+  ASSERT_TRUE(bool(Deserialized));
+  EXPECT_THAT(Deserialized->ProximityPaths,
   testing::ElementsAre(testPath("remote/Header.h"),
testPath("remote/subdir/OtherHeader.h")));
 }
 
+TEST(RemoteMarshallingTest, RefsRequestSerialization) {
+  clangd::RefsRequest Request;
+  auto ID = SymbolID::fromStr("057557CEBF6E6B2D");
+  ASSERT_TRUE(bool(ID));
+  Request.IDs.insert(*ID);
+  ID = SymbolID::fromStr("0575A7CEBF6E6B2F");
+  ASSERT_TRUE(bool(ID));
+  Request.IDs.insert(*ID);
+
+  Request.Limit = 9000;
+  Request.Filter = RefKind::Spelled | RefKind::Declaration;
+
+  Marshaller ProtobufMarshaller(testPath("remote/"), testPath("local/"));
+
+  auto Serialized = ProtobufMarshaller.toProtobuf(Request);
+  EXPECT_EQ(Serialized.ids_size(), 2);
+  EXPECT_EQ(Serialized.limit(), 9000U);
+  auto Deserialized = ProtobufMarshaller.fromProtobuf(&Serialized);
+  ASSERT_TRUE(bool(Deserialized));
+  EXPECT_EQ(Deserialized->IDs.size(), 2U);
+  ASSERT_TRUE(Deserialized->Limit);
+  EXPECT_EQ(*Deserialized->Limit, 9000U);
+  EXPECT_EQ(Deserialized->Filter, RefKind::Spelled | RefKind::Declaration);
+
+  Serialized.add_ids("Invalid Symbol ID");
+  Deserialized = ProtobufMarshaller.fromProtobuf(&Serialized);
+  EXPECT_FALSE(Deserialized);
+  llvm::consumeError(Deserialized.takeError());
+}
+
 TEST(RemoteMarshallingTest, RelativePathToURITranslation) {
   Marshaller ProtobufMarshaller(/*RemoteIndexRoot=*/"",
 /*LocalIndexRoot=*/testPath("home/project/"));
Index: clang-tools-extra/clangd/index/remote/server/Server.cpp
===
--- clang-tools-extra/clangd/index/remote/server/Server.cpp
+++ clang-tools-extra/clangd/index/remote/server/Server.cpp
@@ -9,6 +9,7 @@
 #include "index/Index.h"
 #include "index/Serialization.h"
 #include "index/remote/marshalling/Marshalling.h"
+#include "support/Logger.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Path.h"
@@ -59,14 +60,12 @@
   grpc::Status Lookup(grpc::ServerContext *Context,
   const LookupRequest *Request,
   grpc::ServerWriter *Reply) override {
-clangd::LookupRequest Req;
-for (const auto &ID : Request->ids()) {
-  auto SID = SymbolID::fromStr(StringRef(ID));
-  if (!SID)
-return grpc::Status::CANCELLED;
-  Req.IDs.insert(*SID);
+auto Req = ProtobufMarshaller->fromProtobuf(Request);
+if (!Req) {
+  elog("Can not parse LookupRequest from protobuf: {1}", Req.takeError());
+

[PATCH] D80873: [clang][cmake] Force CMAKE_LINKER for multistage build in case of BOOTSTRAP_LLVM_ENABLE_LLD and MSVC

2020-07-27 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb marked an inline comment as done.
krisb added a comment.

@phosek thank you for reviewing this!




Comment at: clang/CMakeLists.txt:751
+  if(BOOTSTRAP_LLVM_ENABLE_LLD)
+if(MSVC AND NOT BOOTSTRAP_CMAKE_SYSTEM_NAME)
+  set(${CLANG_STAGE}_LINKER 
-DCMAKE_LINKER=${LLVM_RUNTIME_OUTPUT_INTDIR}/lld-link.exe)

phosek wrote:
> krisb wrote:
> > phosek wrote:
> > > I don't understand the second part of this condition, can you elaborate? 
> > > Why not set `CMAKE_LINKER` to `lld-link.exe` even if 
> > > `BOOTSTRAP_CMAKE_SYSTEM_NAME STREQUAL "Windows"`?
> > The only reason that stopped me from adding `BOOTSTRAP_CMAKE_SYSTEM_NAME 
> > STREQUAL "Windows"` case here is that there is no way to keep it working in 
> > the future (or, at least, I don't know one). Moreover, the build which sets 
> > BOOTSTRAP_CMAKE_SYSTEM_NAME equal to "Windows" is currently broken.
> > Since the same issue is exposed if to build LLVM with 
> > `clang/cmake/caches/DistributionExample.cmake` on Windows, I included only 
> > the changes that contribute to making this configuration buildable. I 
> > wanted to avoid making the impression that some other configurations are 
> > supported (because they are not) and also avoid adding any dead code that 
> > nobody would use and that would easily be broken.
> > 
> I'd prefer to use `WIN32 OR BOOTSTRAP_CMAKE_SYSTEM_NAME STREQUAL "Windows"` 
> here even if we don't support cross-compilation to Windows now as I hope it's 
> something we're going to support in the future and this will be one less 
> thing we need to address. Alternatively, please at least leave a `TODO` so 
> it's easier to find later. 
Okay, I made the condition to be `(WIN32 AND NOT BOOTSTRAP_CMAKE_SYSTEM_NAME) 
OR BOOTSTRAP_CMAKE_SYSTEM_NAME STREQUAL "Windows"` to avoid setting 
`CMAKE_LINKER` in case of cross-compiling with Windows host and non-Windows 
target.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80873



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


[PATCH] D84499: [clangd] Add more logs and attach tracers to remote index server routines

2020-07-27 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 280846.
kbobyrev marked 3 inline comments as done.
kbobyrev added a comment.

Move back to duplicated code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84499

Files:
  clang-tools-extra/clangd/index/remote/Client.cpp
  clang-tools-extra/clangd/index/remote/server/Server.cpp

Index: clang-tools-extra/clangd/index/remote/server/Server.cpp
===
--- clang-tools-extra/clangd/index/remote/server/Server.cpp
+++ clang-tools-extra/clangd/index/remote/server/Server.cpp
@@ -6,9 +6,13 @@
 //
 //===--===//
 
+#include "Index.pb.h"
 #include "index/Index.h"
 #include "index/Serialization.h"
+#include "index/Symbol.h"
 #include "index/remote/marshalling/Marshalling.h"
+#include "support/Logger.h"
+#include "support/Trace.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Path.h"
@@ -16,6 +20,7 @@
 
 #include 
 #include 
+#include 
 
 #include "Index.grpc.pb.h"
 
@@ -35,6 +40,16 @@
 llvm::cl::opt IndexRoot(llvm::cl::desc(""),
  llvm::cl::Positional, llvm::cl::Required);
 
+llvm::cl::opt TraceFile(
+"trace-file",
+llvm::cl::desc("Path to the file where tracer logs will be stored"));
+
+llvm::cl::opt PrettyPrint{
+"pretty",
+llvm::cl::desc("Pretty-print JSON output in the trace"),
+llvm::cl::init(false),
+};
+
 llvm::cl::opt ServerAddress(
 "server-address", llvm::cl::init("0.0.0.0:50051"),
 llvm::cl::desc("Address of the invoked server. Defaults to 0.0.0.0:50051"));
@@ -59,6 +74,7 @@
   grpc::Status Lookup(grpc::ServerContext *Context,
   const LookupRequest *Request,
   grpc::ServerWriter *Reply) override {
+trace::Span Tracer(LookupRequest::descriptor()->name());
 clangd::LookupRequest Req;
 for (const auto &ID : Request->ids()) {
   auto SID = SymbolID::fromStr(StringRef(ID));
@@ -66,58 +82,83 @@
 return grpc::Status::CANCELLED;
   Req.IDs.insert(*SID);
 }
-Index->lookup(Req, [&](const clangd::Symbol &Sym) {
-  auto SerializedSymbol = ProtobufMarshaller->toProtobuf(Sym);
-  if (!SerializedSymbol)
+unsigned Sent = 0;
+unsigned FailedToSend = 0;
+Index->lookup(Req, [&](const auto &Item) {
+  auto SerializedItem = ProtobufMarshaller->toProtobuf(Item);
+  if (!SerializedItem) {
+++FailedToSend;
 return;
+  }
   LookupReply NextMessage;
-  *NextMessage.mutable_stream_result() = *SerializedSymbol;
+  *NextMessage.mutable_stream_result() = *SerializedItem;
   Reply->Write(NextMessage);
+  ++Sent;
 });
 LookupReply LastMessage;
 LastMessage.set_final_result(true);
 Reply->Write(LastMessage);
+SPAN_ATTACH(Tracer, "Sent", Sent);
+SPAN_ATTACH(Tracer, "Failed to send", FailedToSend);
 return grpc::Status::OK;
   }
 
   grpc::Status FuzzyFind(grpc::ServerContext *Context,
  const FuzzyFindRequest *Request,
  grpc::ServerWriter *Reply) override {
+trace::Span Tracer(LookupRequest::descriptor()->name());
 const auto Req = ProtobufMarshaller->fromProtobuf(Request);
-bool HasMore = Index->fuzzyFind(Req, [&](const clangd::Symbol &Sym) {
-  auto SerializedSymbol = ProtobufMarshaller->toProtobuf(Sym);
-  if (!SerializedSymbol)
+unsigned Sent = 0;
+unsigned FailedToSend = 0;
+bool HasMore = Index->fuzzyFind(Req, [&](const auto &Item) {
+  auto SerializedItem = ProtobufMarshaller->toProtobuf(Item);
+  if (!SerializedItem) {
+++FailedToSend;
 return;
+  }
   FuzzyFindReply NextMessage;
-  *NextMessage.mutable_stream_result() = *SerializedSymbol;
+  *NextMessage.mutable_stream_result() = *SerializedItem;
   Reply->Write(NextMessage);
+  ++Sent;
 });
 FuzzyFindReply LastMessage;
 LastMessage.set_final_result(HasMore);
 Reply->Write(LastMessage);
+SPAN_ATTACH(Tracer, "Sent", Sent);
+SPAN_ATTACH(Tracer, "Failed to send", FailedToSend);
 return grpc::Status::OK;
   }
 
   grpc::Status Refs(grpc::ServerContext *Context, const RefsRequest *Request,
 grpc::ServerWriter *Reply) override {
+trace::Span Tracer(LookupRequest::descriptor()->name());
 clangd::RefsRequest Req;
 for (const auto &ID : Request->ids()) {
   auto SID = SymbolID::fromStr(StringRef(ID));
-  if (!SID)
+  if (!SID) {
+elog("Refs request cancelled: invalid SymbolID {1}", SID.takeError());
 return grpc::Status::CANCELLED;
+  }
   Req.IDs.insert(*SID);
 }
-bool HasMore = Index->refs(Req, [&](const clangd::Ref &Reference) {
-  auto SerializedRef = ProtobufMarshaller->toProtobuf(Reference);
-  if (!SerializedRef)
+u

[PATCH] D84499: [clangd] Add more logs and attach tracers to remote index server routines

2020-07-27 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev marked 3 inline comments as done.
kbobyrev added inline comments.



Comment at: clang-tools-extra/clangd/index/remote/server/Server.cpp:73
 private:
+  template 

kbobyrev wrote:
> sammccall wrote:
> > you don't need both RequestT and ClangdRequest as template params:
> >  - the things you're currently doing are all available through 
> > protobuf::Message base class
> >  - but why not move the request fromProtobuf call in here so you only need 
> > to pass a single parameter?
> > but why not move the request fromProtobuf call in here so you only need to 
> > pass a single parameter?
> Yeah this is the idea; I have D84525 for extending `fromProtobuf` so that it 
> can be moved here.
Not doing this because of getting back to code duplication.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84499



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


[PATCH] D84499: [clangd] Add more logs and attach tracers to remote index server routines

2020-07-27 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 280848.
kbobyrev added a comment.

Fix code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84499

Files:
  clang-tools-extra/clangd/index/remote/Client.cpp
  clang-tools-extra/clangd/index/remote/server/Server.cpp

Index: clang-tools-extra/clangd/index/remote/server/Server.cpp
===
--- clang-tools-extra/clangd/index/remote/server/Server.cpp
+++ clang-tools-extra/clangd/index/remote/server/Server.cpp
@@ -6,9 +6,13 @@
 //
 //===--===//
 
+#include "Index.pb.h"
 #include "index/Index.h"
 #include "index/Serialization.h"
+#include "index/Symbol.h"
 #include "index/remote/marshalling/Marshalling.h"
+#include "support/Logger.h"
+#include "support/Trace.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Path.h"
@@ -35,6 +39,16 @@
 llvm::cl::opt IndexRoot(llvm::cl::desc(""),
  llvm::cl::Positional, llvm::cl::Required);
 
+llvm::cl::opt TraceFile(
+"trace-file",
+llvm::cl::desc("Path to the file where tracer logs will be stored"));
+
+llvm::cl::opt PrettyPrint{
+"pretty",
+llvm::cl::desc("Pretty-print JSON output in the trace"),
+llvm::cl::init(false),
+};
+
 llvm::cl::opt ServerAddress(
 "server-address", llvm::cl::init("0.0.0.0:50051"),
 llvm::cl::desc("Address of the invoked server. Defaults to 0.0.0.0:50051"));
@@ -59,6 +73,7 @@
   grpc::Status Lookup(grpc::ServerContext *Context,
   const LookupRequest *Request,
   grpc::ServerWriter *Reply) override {
+trace::Span Tracer(LookupRequest::descriptor()->name());
 clangd::LookupRequest Req;
 for (const auto &ID : Request->ids()) {
   auto SID = SymbolID::fromStr(StringRef(ID));
@@ -66,40 +81,56 @@
 return grpc::Status::CANCELLED;
   Req.IDs.insert(*SID);
 }
-Index->lookup(Req, [&](const clangd::Symbol &Sym) {
-  auto SerializedSymbol = ProtobufMarshaller->toProtobuf(Sym);
-  if (!SerializedSymbol)
+unsigned Sent = 0;
+unsigned FailedToSend = 0;
+Index->lookup(Req, [&](const auto &Item) {
+  auto SerializedItem = ProtobufMarshaller->toProtobuf(Item);
+  if (!SerializedItem) {
+++FailedToSend;
 return;
+  }
   LookupReply NextMessage;
-  *NextMessage.mutable_stream_result() = *SerializedSymbol;
+  *NextMessage.mutable_stream_result() = *SerializedItem;
   Reply->Write(NextMessage);
+  ++Sent;
 });
 LookupReply LastMessage;
 LastMessage.set_final_result(true);
 Reply->Write(LastMessage);
+SPAN_ATTACH(Tracer, "Sent", Sent);
+SPAN_ATTACH(Tracer, "Failed to send", FailedToSend);
 return grpc::Status::OK;
   }
 
   grpc::Status FuzzyFind(grpc::ServerContext *Context,
  const FuzzyFindRequest *Request,
  grpc::ServerWriter *Reply) override {
+trace::Span Tracer(FuzzyFindRequest::descriptor()->name());
 const auto Req = ProtobufMarshaller->fromProtobuf(Request);
-bool HasMore = Index->fuzzyFind(Req, [&](const clangd::Symbol &Sym) {
-  auto SerializedSymbol = ProtobufMarshaller->toProtobuf(Sym);
-  if (!SerializedSymbol)
+unsigned Sent = 0;
+unsigned FailedToSend = 0;
+bool HasMore = Index->fuzzyFind(Req, [&](const auto &Item) {
+  auto SerializedItem = ProtobufMarshaller->toProtobuf(Item);
+  if (!SerializedItem) {
+++FailedToSend;
 return;
+  }
   FuzzyFindReply NextMessage;
-  *NextMessage.mutable_stream_result() = *SerializedSymbol;
+  *NextMessage.mutable_stream_result() = *SerializedItem;
   Reply->Write(NextMessage);
+  ++Sent;
 });
 FuzzyFindReply LastMessage;
 LastMessage.set_final_result(HasMore);
 Reply->Write(LastMessage);
+SPAN_ATTACH(Tracer, "Sent", Sent);
+SPAN_ATTACH(Tracer, "Failed to send", FailedToSend);
 return grpc::Status::OK;
   }
 
   grpc::Status Refs(grpc::ServerContext *Context, const RefsRequest *Request,
 grpc::ServerWriter *Reply) override {
+trace::Span Tracer(RefsRequest::descriptor()->name());
 clangd::RefsRequest Req;
 for (const auto &ID : Request->ids()) {
   auto SID = SymbolID::fromStr(StringRef(ID));
@@ -107,17 +138,24 @@
 return grpc::Status::CANCELLED;
   Req.IDs.insert(*SID);
 }
-bool HasMore = Index->refs(Req, [&](const clangd::Ref &Reference) {
-  auto SerializedRef = ProtobufMarshaller->toProtobuf(Reference);
-  if (!SerializedRef)
+unsigned Sent = 0;
+unsigned FailedToSend = 0;
+bool HasMore = Index->refs(Req, [&](const auto &Item) {
+  auto SerializedItem = ProtobufMarshaller->toProtobuf(Item);
+  if (!SerializedItem) {
+++FailedToSend;
 return;

[PATCH] D84525: [clangd] Add marshalling code for all request types

2020-07-27 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

mostly LG. sorry for lots of nits, only two important bits are changing the {1} 
to {0} in logs, wrapping symbolid generations in `llvm::cantFail` and making 
sure `Deserialized` is exactly the same thing as `Request` in tests. feel free 
to ignore the rest (I should've marked them with `nit` hopefully, but might've 
missed some)




Comment at: 
clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp:104
+  auto IDs = getIDs(Message);
+  if (!IDs) {
+return IDs.takeError();

nit: braces



Comment at: clang-tools-extra/clangd/index/remote/server/Server.cpp:65
+if (!Req) {
+  elog("Can not parse LookupRequest from protobuf: {1}", Req.takeError());
+  return grpc::Status::CANCELLED;

printing indices are zero-based so

s/{1}/{0}/g

(same for others)



Comment at: clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp:277
+  clangd::LookupRequest Request;
+  auto ID = SymbolID::fromStr("057557CEBF6E6B2D");
+  ASSERT_TRUE(bool(ID));

you can wrap these in `llvm::cantFail` as the symbolid generation bit is 
constant, and isn't really something we are testing here

nit: also I would suggest a less random string to indicate that these are 
arbitrary like ...001 (the length still needs to match tho)



Comment at: clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp:287
+  auto Serialized = ProtobufMarshaller.toProtobuf(Request);
+  EXPECT_EQ(Serialized.ids_size(), 2);
+  auto Deserialized = ProtobufMarshaller.fromProtobuf(&Serialized);

nit: instead of `2` use `Request.IDs.size()`

Moreover, `SymbolID` has an `opreator==` so in theory you could do an 
`EXPECT_THAT(Serialized.ids(), ElementsAreArray(Request.IDs))` trick to make 
this check even nicer. But I am not sure about how nicely repeated proto fields 
plays with gtest version in llvm. So if it doesn't work nvm. (same for the 
other places with this pattern)



Comment at: clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp:290
+  ASSERT_TRUE(bool(Deserialized));
+  EXPECT_EQ(Deserialized->IDs.size(), 2U);
+

you should definitely be able to make sure `IDs` are exactly the same with 
`Request.IDs`



Comment at: clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp:292
+
+  Serialized.add_ids("Invalid Symbol ID");
+  Deserialized = ProtobufMarshaller.fromProtobuf(&Serialized);

nit: I would put this one into a separate test



Comment at: clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp:328
+  auto Serialized = ProtobufMarshaller.toProtobuf(Request);
+  EXPECT_EQ(Serialized.ids_size(), 2);
+  EXPECT_EQ(Serialized.limit(), 9000U);

again I would suggest comparing to Requests.IDs.size(), and other relevant 
fields below instead of repeating some constants (which would be tedious to 
change in future)



Comment at: clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp:332
+  ASSERT_TRUE(bool(Deserialized));
+  EXPECT_EQ(Deserialized->IDs.size(), 2U);
+  ASSERT_TRUE(Deserialized->Limit);

again I would make sure `IDs` are same element-wise in here.



Comment at: clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp:337
+
+  Serialized.add_ids("Invalid Symbol ID");
+  Deserialized = ProtobufMarshaller.fromProtobuf(&Serialized);

nit: again this could be a separate test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84525



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


[PATCH] D84513: [clangd] Collect references for externally visible main-file symbols

2020-07-27 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.
This revision is now accepted and ready to land.

thanks! numbers and the patch LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84513



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


[PATCH] D80802: [RISCV] Upgrade RVV MC to v0.9.

2020-07-27 Thread Ferran Pallarès Roca via Phabricator via cfe-commits
fpallares added a comment.

Thanks for the update @HsiangKai.

I've noticed that we aren't handling the exceptions that state that the `V0` 
constraint shouldn't be enforced for instructions that generate masks or for 
reductions.

For instance the following (valid) instructions are rejected:

  vmslt.vv v0, v2, v3, v0.t

  vredsum.vs v0, v1, v2, v0.t




Comment at: llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp:776
 }
-return "";
+llvm_unreachable("Unknown SEW.");
   }

evandro wrote:
> I'd rather the first case be the `default` case and that it would call 
> `llvm_unreachabe()` instead.
I believe the LLVM Coding Standards recommend against `default` labels in 
switches over enums:

> -Wswitch warns if a switch, without a default label, over an enumeration does 
> not cover every enumeration value. If you write a default label on a fully 
> covered switch over an enumeration then the -Wswitch warning won’t fire when 
> new elements are added to that enumeration.


See 
https://llvm.org/docs/CodingStandards.html#don-t-use-default-labels-in-fully-covered-switches-over-enumerations
 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80802



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


[PATCH] D84525: [clangd] Add marshalling code for all request types

2020-07-27 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 280853.
kbobyrev marked 9 inline comments as done.
kbobyrev added a comment.

Resolve nits.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84525

Files:
  clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
  clang-tools-extra/clangd/index/remote/marshalling/Marshalling.h
  clang-tools-extra/clangd/index/remote/server/Server.cpp
  clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp

Index: clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
===
--- clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
+++ clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
@@ -18,6 +18,7 @@
 #include "clang/Index/IndexSymbol.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Error.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/StringSaver.h"
 #include "gmock/gmock.h"
@@ -271,6 +272,37 @@
   EXPECT_EQ(toYAML(Sym), toYAML(*Deserialized));
 }
 
+TEST(RemoteMarshallingTest, LookupRequestSerialization) {
+  clangd::LookupRequest Request;
+  auto ID = llvm::cantFail(SymbolID::fromStr("0001"));
+  Request.IDs.insert(ID);
+  ID = llvm::cantFail(SymbolID::fromStr("0002"));
+  Request.IDs.insert(ID);
+
+  Marshaller ProtobufMarshaller(testPath("remote/"), testPath("local/"));
+
+  auto Serialized = ProtobufMarshaller.toProtobuf(Request);
+  EXPECT_EQ(static_cast(Serialized.ids_size()), Request.IDs.size());
+  auto Deserialized = ProtobufMarshaller.fromProtobuf(&Serialized);
+  ASSERT_TRUE(bool(Deserialized));
+  EXPECT_EQ(Deserialized->IDs, Request.IDs);
+
+  Serialized.add_ids("Invalid Symbol ID");
+  Deserialized = ProtobufMarshaller.fromProtobuf(&Serialized);
+  ASSERT_FALSE(bool(Deserialized));
+  llvm::consumeError(Deserialized.takeError());
+}
+
+TEST(RemoteMarshallingTest, LookupRequestFailingSerialization) {
+  clangd::LookupRequest Request;
+  Marshaller ProtobufMarshaller(testPath("remote/"), testPath("local/"));
+  auto Serialized = ProtobufMarshaller.toProtobuf(Request);
+  Serialized.add_ids("Invalid Symbol ID");
+  auto Deserialized = ProtobufMarshaller.fromProtobuf(&Serialized);
+  EXPECT_FALSE(Deserialized);
+  llvm::consumeError(Deserialized.takeError());
+}
+
 TEST(RemoteMarshallingTest, FuzzyFindRequestSerialization) {
   clangd::FuzzyFindRequest Request;
   Request.ProximityPaths = {testPath("local/Header.h"),
@@ -280,11 +312,50 @@
   auto Serialized = ProtobufMarshaller.toProtobuf(Request);
   EXPECT_EQ(Serialized.proximity_paths_size(), 2);
   auto Deserialized = ProtobufMarshaller.fromProtobuf(&Serialized);
-  EXPECT_THAT(Deserialized.ProximityPaths,
+  ASSERT_TRUE(bool(Deserialized));
+  EXPECT_THAT(Deserialized->ProximityPaths,
   testing::ElementsAre(testPath("remote/Header.h"),
testPath("remote/subdir/OtherHeader.h")));
 }
 
+TEST(RemoteMarshallingTest, RefsRequestSerialization) {
+  clangd::RefsRequest Request;
+  auto ID = llvm::cantFail(SymbolID::fromStr("0001"));
+  Request.IDs.insert(ID);
+  ID = llvm::cantFail(SymbolID::fromStr("0002"));
+  Request.IDs.insert(ID);
+
+  Request.Limit = 9000;
+  Request.Filter = RefKind::Spelled | RefKind::Declaration;
+
+  Marshaller ProtobufMarshaller(testPath("remote/"), testPath("local/"));
+
+  auto Serialized = ProtobufMarshaller.toProtobuf(Request);
+  EXPECT_EQ(static_cast(Serialized.ids_size()), Request.IDs.size());
+  EXPECT_EQ(Serialized.limit(), 9000U);
+  auto Deserialized = ProtobufMarshaller.fromProtobuf(&Serialized);
+  ASSERT_TRUE(bool(Deserialized));
+  EXPECT_EQ(Deserialized->IDs, Request.IDs);
+  ASSERT_TRUE(Deserialized->Limit);
+  EXPECT_EQ(*Deserialized->Limit, 9000U);
+  EXPECT_EQ(Deserialized->Filter, RefKind::Spelled | RefKind::Declaration);
+
+  Serialized.add_ids("Invalid Symbol ID");
+  Deserialized = ProtobufMarshaller.fromProtobuf(&Serialized);
+  EXPECT_FALSE(Deserialized);
+  llvm::consumeError(Deserialized.takeError());
+}
+
+TEST(RemoteMarshallingTest, RefsRequestFailingSerialization) {
+  clangd::RefsRequest Request;
+  Marshaller ProtobufMarshaller(testPath("remote/"), testPath("local/"));
+  auto Serialized = ProtobufMarshaller.toProtobuf(Request);
+  Serialized.add_ids("Invalid Symbol ID");
+  auto Deserialized = ProtobufMarshaller.fromProtobuf(&Serialized);
+  EXPECT_FALSE(Deserialized);
+  llvm::consumeError(Deserialized.takeError());
+}
+
 TEST(RemoteMarshallingTest, RelativePathToURITranslation) {
   Marshaller ProtobufMarshaller(/*RemoteIndexRoot=*/"",
 /*LocalIndexRoot=*/testPath("home/project/"));
Index: clang-tools-extra/clangd/index/remote/server/Server.cpp
===
--- clang-tools-extra/clangd/index/remote/server/Server.cpp
+++ clang-tools-ex

[PATCH] D82081: [z/OS] Add binary format goff and operating system zos to the triple

2020-07-27 Thread Kai Nacke via Phabricator via cfe-commits
Kai added reviewers: RKSimon, SjoerdMeijer, dexonsmith, rjmccall.
Kai added a comment.

Still looking for opinions on the clang part!


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

https://reviews.llvm.org/D82081



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


[PATCH] D83817: [clangd] Add option to use remote index as static index

2020-07-27 Thread Hans Wennborg via Phabricator via cfe-commits
hans added inline comments.



Comment at: clang-tools-extra/clangd/Features.inc.in:2
 #define CLANGD_BUILD_XPC @CLANGD_BUILD_XPC@
+#define CLANGD_ENABLE_REMOTE @CLANGD_ENABLE_REMTE@

I'm guessing this should be @CLANGD_ENABLE_REMOTE@
The gn build was upset: http://45.33.8.238/linux/23942/step_4.txt
Speculatively fixed in 47a0254229ca425aa4e169c2db14e92b8db86784. Please shout 
if this was wrong.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83817



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


[clang-tools-extra] 47a0254 - Speculative build fix for clangd/Features.inc.in

2020-07-27 Thread Hans Wennborg via cfe-commits

Author: Hans Wennborg
Date: 2020-07-27T13:39:54+02:00
New Revision: 47a0254229ca425aa4e169c2db14e92b8db86784

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

LOG: Speculative build fix for clangd/Features.inc.in

Added: 


Modified: 
clang-tools-extra/clangd/Features.inc.in

Removed: 




diff  --git a/clang-tools-extra/clangd/Features.inc.in 
b/clang-tools-extra/clangd/Features.inc.in
index 8584b87c6205..6797232ddac7 100644
--- a/clang-tools-extra/clangd/Features.inc.in
+++ b/clang-tools-extra/clangd/Features.inc.in
@@ -1,2 +1,2 @@
 #define CLANGD_BUILD_XPC @CLANGD_BUILD_XPC@
-#define CLANGD_ENABLE_REMOTE @CLANGD_ENABLE_REMTE@
+#define CLANGD_ENABLE_REMOTE @CLANGD_ENABLE_REMOTE@



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


[clang-tools-extra] 13c9bbc - [clang-tidy] Refactor IncludeInserter

2020-07-27 Thread Nathan James via cfe-commits

Author: Nathan James
Date: 2020-07-27T12:48:55+01:00
New Revision: 13c9bbc28ef9cf9976a0962e6c930a7dfc52c877

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

LOG: [clang-tidy] Refactor IncludeInserter

Simplified how `IncludeInserter` is used in Checks by abstracting away the 
SourceManager and PPCallbacks inside the method `registerPreprocessor`.
Changed checks that use `IncludeInserter` to no longer use a `std::unique_ptr`, 
instead the IncludeInserter is just a member of the class thats initialized 
with an `IncludeStyle`.
Saving an unnecessary allocation.

This results in the removal of the field `IncludeSorter::IncludeStyle` from the 
checks, as its wrapped in the `IncludeInserter`.
No longer need to create an instance of the `IncludeInserter` in the 
registerPPCallbacks, now that method only needs to contain:
```
Inserter.registerPreprocessor(PP);
```
Also added a helper method to `IncludeInserter` called 
`createMainFileInclusionInsertion`, purely sugar but does better express 
intentions.

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp
clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.h
clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.h

clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp

clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.h
clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.h
clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
clang-tools-extra/clang-tidy/modernize/PassByValueCheck.h
clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp
clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.h
clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp
clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.h
clang-tools-extra/clang-tidy/performance/MoveConstructorInitCheck.cpp
clang-tools-extra/clang-tidy/performance/MoveConstructorInitCheck.h
clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp
clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.h
clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.h
clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp
clang-tools-extra/clang-tidy/utils/IncludeInserter.h
clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp 
b/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp
index 11bbcbcb527f..e775fc21d2d0 100644
--- a/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp
+++ b/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp
@@ -26,8 +26,8 @@ 
StringFindStartswithCheck::StringFindStartswithCheck(StringRef Name,
 : ClangTidyCheck(Name, Context),
   StringLikeClasses(utils::options::parseStringList(
   Options.get("StringLikeClasses", "::std::basic_string"))),
-  IncludeStyle(Options.getLocalOrGlobal("IncludeStyle",
-utils::IncludeSorter::IS_LLVM)),
+  IncludeInserter(Options.getLocalOrGlobal("IncludeStyle",
+   utils::IncludeSorter::IS_LLVM)),
   AbseilStringsMatchHeader(
   Options.get("AbseilStringsMatchHeader", "absl/strings/match.h")) {}
 
@@ -105,23 +105,21 @@ void StringFindStartswithCheck::check(const 
MatchFinder::MatchResult &Result) {
 
   // Create a preprocessor #include FixIt hint (CreateIncludeInsertion checks
   // whether this already exists).
-  Diagnostic << IncludeInserter->CreateIncludeInsertion(
+  Diagnostic << IncludeInserter.createIncludeInsertion(
   Source.getFileID(ComparisonExpr->getBeginLoc()), 
AbseilStringsMatchHeader,
   false);
 }
 
 void StringFindStartswithCheck::registerPPCallbacks(
 const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) 
{
-  IncludeInserter = std::make_unique(SM, getLangOpts(),
-  IncludeStyle);
-  PP->addPPCallbacks(IncludeInserter->CreatePPCallbacks());
+  IncludeInserter.registerPreprocessor(PP);
 }
 
 void StringFindStartswithCheck::storeOptions(
 ClangTidyOptions::Option

[PATCH] D83680: [clang-tidy] Refactor IncludeInserter

2020-07-27 Thread Nathan James via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG13c9bbc28ef9: [clang-tidy] Refactor IncludeInserter 
(authored by njames93).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83680

Files:
  clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp
  clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.h
  clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.h
  
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.h
  clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
  clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.h
  clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
  clang-tools-extra/clang-tidy/modernize/PassByValueCheck.h
  clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp
  clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.h
  clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp
  clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.h
  clang-tools-extra/clang-tidy/performance/MoveConstructorInitCheck.cpp
  clang-tools-extra/clang-tidy/performance/MoveConstructorInitCheck.h
  clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp
  clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.h
  clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
  clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.h
  clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp
  clang-tools-extra/clang-tidy/utils/IncludeInserter.h
  clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
  clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
  clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp
@@ -33,9 +33,7 @@
 
   void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
Preprocessor *ModuleExpanderPP) override {
-Inserter = std::make_unique(
-SM, getLangOpts(), utils::IncludeSorter::IS_Google);
-PP->addPPCallbacks(Inserter->CreatePPCallbacks());
+Inserter.registerPreprocessor(PP);
   }
 
   void registerMatchers(ast_matchers::MatchFinder *Finder) override {
@@ -46,15 +44,15 @@
 auto Diag = diag(Result.Nodes.getNodeAs("stmt")->getBeginLoc(),
  "foo, bar");
 for (StringRef Header : HeadersToInclude()) {
-  Diag << Inserter->CreateIncludeInsertion(
-  Result.SourceManager->getMainFileID(), Header, IsAngledInclude());
+  Diag << Inserter.createMainFileIncludeInsertion(Header,
+  IsAngledInclude());
 }
   }
 
   virtual std::vector HeadersToInclude() const = 0;
   virtual bool IsAngledInclude() const = 0;
 
-  std::unique_ptr Inserter;
+  utils::IncludeInserter Inserter{utils::IncludeSorter::IS_Google};
 };
 
 class NonSystemHeaderInserterCheck : public IncludeInserterCheckBase {
Index: clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
===
--- clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
+++ clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
@@ -70,8 +70,7 @@
 
 private:
   Optional Rule;
-  const IncludeSorter::IncludeStyle IncludeStyle;
-  std::unique_ptr Inserter;
+  IncludeInserter Inserter;
 };
 
 } // namespace utils
Index: clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
===
--- clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
+++ clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
@@ -32,8 +32,8 @@
 MakeRule,
 StringRef Name, ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context), Rule(MakeRule(getLangOpts(), Options)),
-  IncludeStyle(Options.getLocalOrGlobal("IncludeStyle",
-IncludeSorter::IS_LLVM)) {
+  Inserter(
+  Options.getLocalOrGlobal("IncludeStyle", IncludeSorter::IS_LLVM)) {
   if (Rule)
 assert(llvm::all_of(Rule->Cases, hasExplanation) &&
"clang-tidy checks must have an explanation by default;"
@@ -44,8 +44,8 @@
  StringRef Name,
  ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context), Rule(std::move(R)),
-  IncludeStyle(Options.getLocalOrGlobal("Incl

[PATCH] D84525: [clangd] Add marshalling code for all request types

2020-07-27 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.
This revision is now accepted and ready to land.

thanks for bearing with me, LGTM!




Comment at: clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp:277
+  clangd::LookupRequest Request;
+  auto ID = llvm::cantFail(SymbolID::fromStr("0001"));
+  Request.IDs.insert(ID);

nit: you could inline these into insert calls now.



Comment at: clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp:290
+
+  Serialized.add_ids("Invalid Symbol ID");
+  Deserialized = ProtobufMarshaller.fromProtobuf(&Serialized);

looks like you forgot to delete this



Comment at: clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp:335
+  EXPECT_EQ(static_cast(Serialized.ids_size()), Request.IDs.size());
+  EXPECT_EQ(Serialized.limit(), 9000U);
+  auto Deserialized = ProtobufMarshaller.fromProtobuf(&Serialized);

s/9000U/Request.Limit



Comment at: clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp:340
+  ASSERT_TRUE(Deserialized->Limit);
+  EXPECT_EQ(*Deserialized->Limit, 9000U);
+  EXPECT_EQ(Deserialized->Filter, RefKind::Spelled | RefKind::Declaration);

s/9000U/Request.Limit





Comment at: clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp:341
+  EXPECT_EQ(*Deserialized->Limit, 9000U);
+  EXPECT_EQ(Deserialized->Filter, RefKind::Spelled | RefKind::Declaration);
+

s/RefKind::Spelled | RefKind::Declaration/Request.Filter



Comment at: clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp:343
+
+  Serialized.add_ids("Invalid Symbol ID");
+  Deserialized = ProtobufMarshaller.fromProtobuf(&Serialized);

again you forgot to delete this


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84525



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


[clang-tools-extra] 40d11a8 - ClangdMain.cpp: this #ifdef should be an #if

2020-07-27 Thread Hans Wennborg via cfe-commits

Author: Hans Wennborg
Date: 2020-07-27T14:05:02+02:00
New Revision: 40d11a878044711708fb6738e4b78a4c9ac3de7b

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

LOG: ClangdMain.cpp: this #ifdef should be an #if

CLANGD_ENABLE_REMOTE is always defined; to 0 or 1.

Added: 


Modified: 
clang-tools-extra/clangd/tool/ClangdMain.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/tool/ClangdMain.cpp 
b/clang-tools-extra/clangd/tool/ClangdMain.cpp
index 8d1bf5c42260..f04dad7186df 100644
--- a/clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ b/clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -696,7 +696,7 @@ clangd accepts flags on the commandline, and in the 
CLANGD_FLAGS environment var
 if (Sync)
   AsyncIndexLoad.wait();
   }
-#ifdef CLANGD_ENABLE_REMOTE
+#if CLANGD_ENABLE_REMOTE
   if (RemoteIndexAddress.empty() != ProjectRoot.empty()) {
 llvm::errs() << "remote-index-address and project-path have to be "
 "specified at the same time.";



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


[PATCH] D83817: [clangd] Add option to use remote index as static index

2020-07-27 Thread Hans Wennborg via Phabricator via cfe-commits
hans added inline comments.



Comment at: clang-tools-extra/clangd/tool/ClangdMain.cpp:702
   }
+  if (RemoteIndexAddress.empty() != ProjectPath.empty()) {
+llvm::errs() << "remote-index-address and project-path have to be "

hokein wrote:
> the new code section here should be guarded under `#ifdef 
> CLANGD_ENABLE_REMOTE`
I think it should be an #if since the macro is always defined (0 or 1). Doing 
that in 40d11a878044711708fb6738e4b78a4c9ac3de7b


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83817



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


[PATCH] D84637: [AST] Enhance the const expression evaluator to support error-dependent exprs.

2020-07-27 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fix a crash when evaluating a constexpr function which contains
recovery-exprs. https://bugs.llvm.org/show_bug.cgi?id=46837

Would be nice to have constant expression evaluator support general template
value-dependent expressions, but it requires more work.

This patch is a good start I think, to handle the error-only
value-dependent expressions.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D84637

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/test/SemaCXX/constexpr-function-recovery-crash.cpp
  clang/test/SemaCXX/enable_if.cpp
  clang/test/SemaCXX/recovery-expr-type.cpp

Index: clang/test/SemaCXX/recovery-expr-type.cpp
===
--- clang/test/SemaCXX/recovery-expr-type.cpp
+++ clang/test/SemaCXX/recovery-expr-type.cpp
@@ -53,14 +53,12 @@
 return 2;
   }
   static constexpr int foo2() {
-return AA::getB(); // expected-error{{no matching function for call to 'getB'}} \
-  // expected-note {{subexpression not valid in a constant expression}}
+return AA::getB(); // expected-error{{no matching function for call to 'getB'}}
   }
 };
 // FIXME: should we suppress the "be initialized by a constant expression" diagnostic?
 constexpr auto x2 = AA::foo2(); // expected-error {{be initialized by a constant expression}} \
- // expected-note {{in instantiation of member function}} \
- // expected-note {{in call to}}
+ // expected-note {{in instantiation of member function}}
 }
 
 // verify no assertion failure on violating value category.
Index: clang/test/SemaCXX/enable_if.cpp
===
--- clang/test/SemaCXX/enable_if.cpp
+++ clang/test/SemaCXX/enable_if.cpp
@@ -415,7 +415,7 @@
 template  constexpr int callTemplated() { return templated(); }
 
 constexpr int B = 10 + // expected-error {{initialized by a constant expression}}
-callTemplated<0>(); // expected-error@-3{{no matching function for call to 'templated'}} expected-note{{in instantiation of function template}} expected-note@-10{{candidate disabled}} expected-note {{in call to 'callTemplated()'}} expected-note@-3 {{subexpression not valid in a constant expression}}
+callTemplated<0>(); // expected-error@-3{{no matching function for call to 'templated'}} expected-note{{in instantiation of function template}} expected-note@-10{{candidate disabled}}
 static_assert(callTemplated<1>() == 1, "");
 }
 
Index: clang/test/SemaCXX/constexpr-function-recovery-crash.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/constexpr-function-recovery-crash.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 %s -std=c++20 -fsyntax-only -verify
+
+// verify no value-dependent-assertion crash in constexpr function body.
+class Foo {
+  constexpr Foo() {
+while (invalid()) {} // expected-error {{use of undeclared identifier}}
+if (invalid()) {} // expected-error {{use of undeclared identifier}}
+  }
+};
+
+constexpr void test1() {
+  while (invalid()) {} // expected-error {{use of undeclared identifier}}
+  if (invalid()) {} // expected-error {{use of undeclared identifier}}
+}
\ No newline at end of file
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -1868,6 +1868,7 @@
 /// result.
 /// \return \c true if the caller should keep evaluating.
 static bool EvaluateIgnoredValue(EvalInfo &Info, const Expr *E) {
+  assert(!E->isValueDependent());
   APValue Scratch;
   if (!Evaluate(Scratch, Info, E))
 // We don't need the value, but we might have skipped a side effect here.
@@ -2369,6 +2370,7 @@
 
 static bool EvaluateAsBooleanCondition(const Expr *E, bool &Result,
EvalInfo &Info) {
+  assert(!E->isValueDependent());
   assert(E->isRValue() && "missing lvalue-to-rvalue conv in bool condition");
   APValue Val;
   if (!Evaluate(Val, Info, E))
@@ -4611,6 +4613,7 @@
 /// Evaluate a condition (either a variable declaration or an expression).
 static bool EvaluateCond(EvalInfo &Info, const VarDecl *CondDecl,
  const Expr *Cond, bool &Result) {
+  assert(!Cond->isValueDependent());
   FullExpressionRAII Scope(Info);
   if (CondDecl && !EvaluateDecl(Info, CondDecl))
 return false;
@@ -4868,6 +4871,10 @@
   switch (S->getStmtClass()) {
   default:
 if (const Expr *E = dyn_cast(S)) {
+  if (E->isValueDependent()) {
+assert(E->containsErrors());
+return ESR_Failed;
+  }
   // Don't bother evaluating beyond an expression-statement which couldn't
   // be evaluated.
   // FIXME: Do we need the FullExpressionRAII object he

[clang-tools-extra] 529441e - Fix another #ifdef CLANGD_ENABLE_REMOTE

2020-07-27 Thread Hans Wennborg via cfe-commits

Author: Hans Wennborg
Date: 2020-07-27T14:11:29+02:00
New Revision: 529441e88e81a2e7dae6108e3d95e043c670e1a6

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

LOG: Fix another #ifdef CLANGD_ENABLE_REMOTE

Added: 


Modified: 
clang-tools-extra/clangd/tool/ClangdMain.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/tool/ClangdMain.cpp 
b/clang-tools-extra/clangd/tool/ClangdMain.cpp
index f04dad7186df..0d4267774c92 100644
--- a/clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ b/clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -450,7 +450,7 @@ opt EnableConfig{
 init(true),
 };
 
-#ifdef CLANGD_ENABLE_REMOTE
+#if CLANGD_ENABLE_REMOTE
 opt RemoteIndexAddress{
 "remote-index-address",
 cat(Features),



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


[PATCH] D84525: [clangd] Add marshalling code for all request types

2020-07-27 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 280862.
kbobyrev marked 6 inline comments as done.
kbobyrev added a comment.

Address post-LGTM comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84525

Files:
  clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
  clang-tools-extra/clangd/index/remote/marshalling/Marshalling.h
  clang-tools-extra/clangd/index/remote/server/Server.cpp
  clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp

Index: clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
===
--- clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
+++ clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
@@ -18,6 +18,7 @@
 #include "clang/Index/IndexSymbol.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Error.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/StringSaver.h"
 #include "gmock/gmock.h"
@@ -271,6 +272,30 @@
   EXPECT_EQ(toYAML(Sym), toYAML(*Deserialized));
 }
 
+TEST(RemoteMarshallingTest, LookupRequestSerialization) {
+  clangd::LookupRequest Request;
+  Request.IDs.insert(llvm::cantFail(SymbolID::fromStr("0001")));
+  Request.IDs.insert(llvm::cantFail(SymbolID::fromStr("0002")));
+
+  Marshaller ProtobufMarshaller(testPath("remote/"), testPath("local/"));
+
+  auto Serialized = ProtobufMarshaller.toProtobuf(Request);
+  EXPECT_EQ(static_cast(Serialized.ids_size()), Request.IDs.size());
+  auto Deserialized = ProtobufMarshaller.fromProtobuf(&Serialized);
+  ASSERT_TRUE(bool(Deserialized));
+  EXPECT_EQ(Deserialized->IDs, Request.IDs);
+}
+
+TEST(RemoteMarshallingTest, LookupRequestFailingSerialization) {
+  clangd::LookupRequest Request;
+  Marshaller ProtobufMarshaller(testPath("remote/"), testPath("local/"));
+  auto Serialized = ProtobufMarshaller.toProtobuf(Request);
+  Serialized.add_ids("Invalid Symbol ID");
+  auto Deserialized = ProtobufMarshaller.fromProtobuf(&Serialized);
+  EXPECT_FALSE(Deserialized);
+  llvm::consumeError(Deserialized.takeError());
+}
+
 TEST(RemoteMarshallingTest, FuzzyFindRequestSerialization) {
   clangd::FuzzyFindRequest Request;
   Request.ProximityPaths = {testPath("local/Header.h"),
@@ -280,11 +305,43 @@
   auto Serialized = ProtobufMarshaller.toProtobuf(Request);
   EXPECT_EQ(Serialized.proximity_paths_size(), 2);
   auto Deserialized = ProtobufMarshaller.fromProtobuf(&Serialized);
-  EXPECT_THAT(Deserialized.ProximityPaths,
+  ASSERT_TRUE(bool(Deserialized));
+  EXPECT_THAT(Deserialized->ProximityPaths,
   testing::ElementsAre(testPath("remote/Header.h"),
testPath("remote/subdir/OtherHeader.h")));
 }
 
+TEST(RemoteMarshallingTest, RefsRequestSerialization) {
+  clangd::RefsRequest Request;
+  Request.IDs.insert(llvm::cantFail(SymbolID::fromStr("0001")));
+  Request.IDs.insert(llvm::cantFail(SymbolID::fromStr("0002")));
+
+  Request.Limit = 9000;
+  Request.Filter = RefKind::Spelled | RefKind::Declaration;
+
+  Marshaller ProtobufMarshaller(testPath("remote/"), testPath("local/"));
+
+  auto Serialized = ProtobufMarshaller.toProtobuf(Request);
+  EXPECT_EQ(static_cast(Serialized.ids_size()), Request.IDs.size());
+  EXPECT_EQ(Serialized.limit(), Request.Limit);
+  auto Deserialized = ProtobufMarshaller.fromProtobuf(&Serialized);
+  ASSERT_TRUE(bool(Deserialized));
+  EXPECT_EQ(Deserialized->IDs, Request.IDs);
+  ASSERT_TRUE(Deserialized->Limit);
+  EXPECT_EQ(*Deserialized->Limit, Request.Limit);
+  EXPECT_EQ(Deserialized->Filter, Request.Filter);
+}
+
+TEST(RemoteMarshallingTest, RefsRequestFailingSerialization) {
+  clangd::RefsRequest Request;
+  Marshaller ProtobufMarshaller(testPath("remote/"), testPath("local/"));
+  auto Serialized = ProtobufMarshaller.toProtobuf(Request);
+  Serialized.add_ids("Invalid Symbol ID");
+  auto Deserialized = ProtobufMarshaller.fromProtobuf(&Serialized);
+  EXPECT_FALSE(Deserialized);
+  llvm::consumeError(Deserialized.takeError());
+}
+
 TEST(RemoteMarshallingTest, RelativePathToURITranslation) {
   Marshaller ProtobufMarshaller(/*RemoteIndexRoot=*/"",
 /*LocalIndexRoot=*/testPath("home/project/"));
Index: clang-tools-extra/clangd/index/remote/server/Server.cpp
===
--- clang-tools-extra/clangd/index/remote/server/Server.cpp
+++ clang-tools-extra/clangd/index/remote/server/Server.cpp
@@ -9,6 +9,7 @@
 #include "index/Index.h"
 #include "index/Serialization.h"
 #include "index/remote/marshalling/Marshalling.h"
+#include "support/Logger.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Path.h"
@@ -59,14 +60,12 @@
   grpc::Status Lookup(grpc::ServerContext *Context,
   const LookupRequest *Request,
   

[clang-tools-extra] f49a7ad - [clangd] Add marshalling code for all request types

2020-07-27 Thread Kirill Bobyrev via cfe-commits

Author: Kirill Bobyrev
Date: 2020-07-27T14:16:03+02:00
New Revision: f49a7ad8c0854a01b945c27de2fd313b9013ae0d

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

LOG: [clangd] Add marshalling code for all request types

Summary:
Only FuzzyFindRequest is implemented via Marshaller even though other requests
also follow a similar pattern. Unify them under the marshalling umbrella and
make the server requests even more uniform to complement D84499.

Reviewers: kadircet

Reviewed By: kadircet

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits, 
sammccall

Tags: #clang

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

Added: 


Modified: 
clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
clang-tools-extra/clangd/index/remote/marshalling/Marshalling.h
clang-tools-extra/clangd/index/remote/server/Server.cpp
clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp 
b/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
index b6c83c974072..b2085bc21f48 100644
--- a/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
+++ b/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
@@ -17,6 +17,7 @@
 #include "index/SymbolOrigin.h"
 #include "support/Logger.h"
 #include "clang/Index/IndexSymbol.h"
+#include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/None.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallString.h"
@@ -30,6 +31,22 @@ namespace clang {
 namespace clangd {
 namespace remote {
 
+namespace {
+
+template 
+llvm::Expected> getIDs(MessageT *Message) {
+  llvm::DenseSet Result;
+  for (const auto &ID : Message->ids()) {
+auto SID = SymbolID::fromStr(StringRef(ID));
+if (!SID)
+  return SID.takeError();
+Result.insert(*SID);
+  }
+  return Result;
+}
+
+} // namespace
+
 Marshaller::Marshaller(llvm::StringRef RemoteIndexRoot,
llvm::StringRef LocalIndexRoot)
 : Strings(Arena) {
@@ -49,27 +66,50 @@ Marshaller::Marshaller(llvm::StringRef RemoteIndexRoot,
   assert(!RemoteIndexRoot.empty() || !LocalIndexRoot.empty());
 }
 
-clangd::FuzzyFindRequest
-Marshaller::fromProtobuf(const FuzzyFindRequest *Request) {
+llvm::Expected
+Marshaller::fromProtobuf(const LookupRequest *Message) {
+  clangd::LookupRequest Req;
+  auto IDs = getIDs(Message);
+  if (!IDs)
+return IDs.takeError();
+  Req.IDs = std::move(*IDs);
+  return Req;
+}
+
+llvm::Expected
+Marshaller::fromProtobuf(const FuzzyFindRequest *Message) {
   assert(RemoteIndexRoot);
   clangd::FuzzyFindRequest Result;
-  Result.Query = Request->query();
-  for (const auto &Scope : Request->scopes())
+  Result.Query = Message->query();
+  for (const auto &Scope : Message->scopes())
 Result.Scopes.push_back(Scope);
-  Result.AnyScope = Request->any_scope();
-  if (Request->limit())
-Result.Limit = Request->limit();
-  Result.RestrictForCodeCompletion = Request->restricted_for_code_completion();
-  for (const auto &Path : Request->proximity_paths()) {
+  Result.AnyScope = Message->any_scope();
+  if (Message->limit())
+Result.Limit = Message->limit();
+  Result.RestrictForCodeCompletion = Message->restricted_for_code_completion();
+  for (const auto &Path : Message->proximity_paths()) {
 llvm::SmallString<256> LocalPath = llvm::StringRef(*RemoteIndexRoot);
 llvm::sys::path::append(LocalPath, Path);
 Result.ProximityPaths.push_back(std::string(LocalPath));
   }
-  for (const auto &Type : Request->preferred_types())
+  for (const auto &Type : Message->preferred_types())
 Result.ProximityPaths.push_back(Type);
   return Result;
 }
 
+llvm::Expected
+Marshaller::fromProtobuf(const RefsRequest *Message) {
+  clangd::RefsRequest Req;
+  auto IDs = getIDs(Message);
+  if (!IDs)
+return IDs.takeError();
+  Req.IDs = std::move(*IDs);
+  Req.Filter = static_cast(Message->filter());
+  if (Message->limit())
+Req.Limit = Message->limit();
+  return Req;
+}
+
 llvm::Optional Marshaller::fromProtobuf(const Symbol &Message) 
{
   if (!Message.has_info() || !Message.has_canonical_declaration()) {
 elog("Cannot convert Symbol from protobuf (missing info, definition or "
@@ -157,8 +197,7 @@ FuzzyFindRequest Marshaller::toProtobuf(const 
clangd::FuzzyFindRequest &From) {
   
RPCRequest.set_restricted_for_code_completion(From.RestrictForCodeCompletion);
   for (const auto &Path : From.ProximityPaths) {
 llvm::SmallString<256> RelativePath = llvm::StringRef(Path);
-if (llvm::sys::path::replace_path_prefix(RelativePath, *LocalIndexRoot,
- ""))
+if (llvm::sys::path::replace_path_prefix(RelativePath, *LocalIndexRoot, 
"")

[PATCH] D84525: [clangd] Add marshalling code for all request types

2020-07-27 Thread Kirill Bobyrev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf49a7ad8c085: [clangd] Add marshalling code for all request 
types (authored by kbobyrev).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84525

Files:
  clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
  clang-tools-extra/clangd/index/remote/marshalling/Marshalling.h
  clang-tools-extra/clangd/index/remote/server/Server.cpp
  clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp

Index: clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
===
--- clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
+++ clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
@@ -18,6 +18,7 @@
 #include "clang/Index/IndexSymbol.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Error.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/StringSaver.h"
 #include "gmock/gmock.h"
@@ -271,6 +272,30 @@
   EXPECT_EQ(toYAML(Sym), toYAML(*Deserialized));
 }
 
+TEST(RemoteMarshallingTest, LookupRequestSerialization) {
+  clangd::LookupRequest Request;
+  Request.IDs.insert(llvm::cantFail(SymbolID::fromStr("0001")));
+  Request.IDs.insert(llvm::cantFail(SymbolID::fromStr("0002")));
+
+  Marshaller ProtobufMarshaller(testPath("remote/"), testPath("local/"));
+
+  auto Serialized = ProtobufMarshaller.toProtobuf(Request);
+  EXPECT_EQ(static_cast(Serialized.ids_size()), Request.IDs.size());
+  auto Deserialized = ProtobufMarshaller.fromProtobuf(&Serialized);
+  ASSERT_TRUE(bool(Deserialized));
+  EXPECT_EQ(Deserialized->IDs, Request.IDs);
+}
+
+TEST(RemoteMarshallingTest, LookupRequestFailingSerialization) {
+  clangd::LookupRequest Request;
+  Marshaller ProtobufMarshaller(testPath("remote/"), testPath("local/"));
+  auto Serialized = ProtobufMarshaller.toProtobuf(Request);
+  Serialized.add_ids("Invalid Symbol ID");
+  auto Deserialized = ProtobufMarshaller.fromProtobuf(&Serialized);
+  EXPECT_FALSE(Deserialized);
+  llvm::consumeError(Deserialized.takeError());
+}
+
 TEST(RemoteMarshallingTest, FuzzyFindRequestSerialization) {
   clangd::FuzzyFindRequest Request;
   Request.ProximityPaths = {testPath("local/Header.h"),
@@ -280,11 +305,43 @@
   auto Serialized = ProtobufMarshaller.toProtobuf(Request);
   EXPECT_EQ(Serialized.proximity_paths_size(), 2);
   auto Deserialized = ProtobufMarshaller.fromProtobuf(&Serialized);
-  EXPECT_THAT(Deserialized.ProximityPaths,
+  ASSERT_TRUE(bool(Deserialized));
+  EXPECT_THAT(Deserialized->ProximityPaths,
   testing::ElementsAre(testPath("remote/Header.h"),
testPath("remote/subdir/OtherHeader.h")));
 }
 
+TEST(RemoteMarshallingTest, RefsRequestSerialization) {
+  clangd::RefsRequest Request;
+  Request.IDs.insert(llvm::cantFail(SymbolID::fromStr("0001")));
+  Request.IDs.insert(llvm::cantFail(SymbolID::fromStr("0002")));
+
+  Request.Limit = 9000;
+  Request.Filter = RefKind::Spelled | RefKind::Declaration;
+
+  Marshaller ProtobufMarshaller(testPath("remote/"), testPath("local/"));
+
+  auto Serialized = ProtobufMarshaller.toProtobuf(Request);
+  EXPECT_EQ(static_cast(Serialized.ids_size()), Request.IDs.size());
+  EXPECT_EQ(Serialized.limit(), Request.Limit);
+  auto Deserialized = ProtobufMarshaller.fromProtobuf(&Serialized);
+  ASSERT_TRUE(bool(Deserialized));
+  EXPECT_EQ(Deserialized->IDs, Request.IDs);
+  ASSERT_TRUE(Deserialized->Limit);
+  EXPECT_EQ(*Deserialized->Limit, Request.Limit);
+  EXPECT_EQ(Deserialized->Filter, Request.Filter);
+}
+
+TEST(RemoteMarshallingTest, RefsRequestFailingSerialization) {
+  clangd::RefsRequest Request;
+  Marshaller ProtobufMarshaller(testPath("remote/"), testPath("local/"));
+  auto Serialized = ProtobufMarshaller.toProtobuf(Request);
+  Serialized.add_ids("Invalid Symbol ID");
+  auto Deserialized = ProtobufMarshaller.fromProtobuf(&Serialized);
+  EXPECT_FALSE(Deserialized);
+  llvm::consumeError(Deserialized.takeError());
+}
+
 TEST(RemoteMarshallingTest, RelativePathToURITranslation) {
   Marshaller ProtobufMarshaller(/*RemoteIndexRoot=*/"",
 /*LocalIndexRoot=*/testPath("home/project/"));
Index: clang-tools-extra/clangd/index/remote/server/Server.cpp
===
--- clang-tools-extra/clangd/index/remote/server/Server.cpp
+++ clang-tools-extra/clangd/index/remote/server/Server.cpp
@@ -9,6 +9,7 @@
 #include "index/Index.h"
 #include "index/Serialization.h"
 #include "index/remote/marshalling/Marshalling.h"
+#include "support/Logger.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Path.h"
@@ -59,14 +60,12 @@
   grpc::Status Lookup(grpc::ServerContext *Context,
   con

[PATCH] D84005: Introduce ns_error_domain attribute.

2020-07-27 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:5328
+  if (!IdentLoc || !IdentLoc->Ident) {
+// Try to locate the argument directly
+SourceLocation Loc = AL.getLoc();

Comments should be grammatical including punctuation (elsewhere as well).



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:5340
+  // Verify that the identifier is a valid decl in the C decl namespace
+  LookupResult lookupResult(S, DeclarationName(IdentLoc->Ident),
+SourceLocation(),

`lookupResult` -> `Result` (or something else that matches the usual naming 
conventions).



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:5350
+
+  D->addAttr(::new (S.Context)
+ NSErrorDomainAttr(S.Context, AL, IdentLoc->Ident));

Shouldn't we also be validating that what we found is an NSString that has the 
correct properties? (That doesn't seem like it should be a change which risks 
breaking code based on what I understood from Doug's description.)



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:5355
+S.Diag(identLoc->Loc, diag::err_nserrordomain_invalid_decl)
+<< identLoc->Ident;
+return;

MForster wrote:
> aaron.ballman wrote:
> > We're doing this lookup in the context of where the attribute is being 
> > used, but then creating the attribute with only the identifier and not the 
> > result of that lookup. This makes me a bit worried that when something goes 
> > to resolve that identifier to a variable later, it may get a different 
> > result because the lookup context will be different. Do you need to store 
> > the VarDecl on the semantic attribute, rather than the identifier?
> >We're doing this lookup in the context of where the attribute is being used, 
> >but then creating the attribute with only the identifier and not the result 
> >of that lookup. This makes me a bit worried that when something goes to 
> >resolve that identifier to a variable later, it may get a different result 
> >because the lookup context will be different. Do you need to store the 
> >VarDecl on the semantic attribute, rather than the identifier?
> 
> 
> When this gets imported into Swift, only the name of the identifier gets 
> used. I'm not quite sure why this was defined like this. This is another 
> thing where I would hope that @gribozavr2 or @milseman know more...
Based on the answer from @doug.gregor, I think this should be adding the result 
of the lookup to the semantic attribute and not the identifier (the identifier 
may not be unique, the VarDecl must be unique though).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84005



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


Re: [PATCH] D83817: [clangd] Add option to use remote index as static index

2020-07-27 Thread Kirill Bobyrev via cfe-commits
Ah, that's why... Thank you again and apologies for inconovinience!

On Mon, Jul 27, 2020 at 3:06 PM Hans Wennborg via Phabricator <
revi...@reviews.llvm.org> wrote:

> hans added inline comments.
>
>
> 
> Comment at: clang-tools-extra/clangd/tool/ClangdMain.cpp:702
>}
> +  if (RemoteIndexAddress.empty() != ProjectPath.empty()) {
> +llvm::errs() << "remote-index-address and project-path have to be "
> 
> hokein wrote:
> > the new code section here should be guarded under `#ifdef
> CLANGD_ENABLE_REMOTE`
> I think it should be an #if since the macro is always defined (0 or 1).
> Doing that in 40d11a878044711708fb6738e4b78a4c9ac3de7b
>
>
> Repository:
>   rG LLVM Github Monorepo
>
> CHANGES SINCE LAST ACTION
>   https://reviews.llvm.org/D83817/new/
>
> https://reviews.llvm.org/D83817
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D83817: [clangd] Add option to use remote index as static index

2020-07-27 Thread Kirill Bobyrev via cfe-commits
Uh, you're right, thank you for the fix! I wonder why that was building for
me...

Again, thank you for noticing!

Kirill

On Mon, Jul 27, 2020 at 2:41 PM Hans Wennborg via Phabricator <
revi...@reviews.llvm.org> wrote:

> hans added inline comments.
>
>
> 
> Comment at: clang-tools-extra/clangd/Features.inc.in:2
>  #define CLANGD_BUILD_XPC @CLANGD_BUILD_XPC@
> +#define CLANGD_ENABLE_REMOTE @CLANGD_ENABLE_REMTE@
> 
> I'm guessing this should be @CLANGD_ENABLE_REMOTE@
> The gn build was upset: http://45.33.8.238/linux/23942/step_4.txt
> Speculatively fixed in 47a0254229ca425aa4e169c2db14e92b8db86784. Please
> shout if this was wrong.
>
>
> Repository:
>   rG LLVM Github Monorepo
>
> CHANGES SINCE LAST ACTION
>   https://reviews.llvm.org/D83817/new/
>
> https://reviews.llvm.org/D83817
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D84513: [clangd] Collect references for externally visible main-file symbols

2020-07-27 Thread Aleksandr Platonov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG90684d154516: [clangd] Collect references for externally 
visible main-file symbols (authored by ArcsinX).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84513

Files:
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
  clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp


Index: clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
===
--- clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -624,11 +624,13 @@
   EXPECT_THAT(Refs, Not(Contains(Pair(findSymbol(Symbols, "NS").ID, _;
   EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, "MACRO").ID,
   HaveRanges(Main.ranges("macro");
-  // Symbols *only* in the main file (a, b, c, FUNC) had no refs collected.
+  // Symbols *only* in the main file:
+  // - (a, b) externally visible and should have refs.
+  // - (c, FUNC) externally invisible and had no refs collected.
   auto MainSymbols =
   TestTU::withHeaderCode(SymbolsOnlyInMainCode.code()).headerSymbols();
-  EXPECT_THAT(Refs, Not(Contains(Pair(findSymbol(MainSymbols, "a").ID, _;
-  EXPECT_THAT(Refs, Not(Contains(Pair(findSymbol(MainSymbols, "b").ID, _;
+  EXPECT_THAT(Refs, Contains(Pair(findSymbol(MainSymbols, "a").ID, _)));
+  EXPECT_THAT(Refs, Contains(Pair(findSymbol(MainSymbols, "b").ID, _)));
   EXPECT_THAT(Refs, Not(Contains(Pair(findSymbol(MainSymbols, "c").ID, _;
   EXPECT_THAT(Refs, Not(Contains(Pair(findSymbol(MainSymbols, "FUNC").ID, 
_;
 }
@@ -816,11 +818,15 @@
 $Foo[[Foo]] fo;
   }
   )");
-  // The main file is normal .cpp file, we shouldn't collect any refs of 
symbols
-  // which are not declared in the preamble.
+  // The main file is normal .cpp file, we should collect the refs
+  // for externally visible symbols.
   TestFileName = testPath("foo.cpp");
   runSymbolCollector("", Header.code());
-  EXPECT_THAT(Refs, UnorderedElementsAre());
+  EXPECT_THAT(Refs,
+  UnorderedElementsAre(Pair(findSymbol(Symbols, "Foo").ID,
+HaveRanges(Header.ranges("Foo"))),
+   Pair(findSymbol(Symbols, "Func").ID,
+HaveRanges(Header.ranges("Func");
 
   // Run the .h file as main file, we should collect the refs.
   TestFileName = testPath("foo.h");
Index: clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
===
--- clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
+++ clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
@@ -171,7 +171,7 @@
   #endif
   )cpp";
   FS.Files[testPath("root/A.cc")] =
-  "#include \"A.h\"\nvoid g() { (void)common; }";
+  "#include \"A.h\"\nstatic void g() { (void)common; }";
   FS.Files[testPath("root/B.cc")] =
   R"cpp(
   #define A 0
Index: clang-tools-extra/clangd/index/SymbolCollector.cpp
===
--- clang-tools-extra/clangd/index/SymbolCollector.cpp
+++ clang-tools-extra/clangd/index/SymbolCollector.cpp
@@ -314,7 +314,8 @@
   // file locations for references (as it aligns the behavior of clangd's
   // AST-based xref).
   // FIXME: we should try to use the file locations for other fields.
-  if (CollectRef && !IsMainFileOnly && !isa(ND) &&
+  if (CollectRef && (!IsMainFileOnly || ND->isExternallyVisible()) &&
+  !isa(ND) &&
   (Opts.RefsInHeaders ||
SM.getFileID(SM.getFileLoc(Loc)) == SM.getMainFileID()))
 DeclRefs[ND].emplace_back(SM.getFileLoc(Loc), Roles);


Index: clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
===
--- clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -624,11 +624,13 @@
   EXPECT_THAT(Refs, Not(Contains(Pair(findSymbol(Symbols, "NS").ID, _;
   EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, "MACRO").ID,
   HaveRanges(Main.ranges("macro");
-  // Symbols *only* in the main file (a, b, c, FUNC) had no refs collected.
+  // Symbols *only* in the main file:
+  // - (a, b) externally visible and should have refs.
+  // - (c, FUNC) externally invisible and had no refs collected.
   auto MainSymbols =
   TestTU::withHeaderCode(SymbolsOnlyInMainCode.code()).headerSymbols();
-  EXPECT_THAT(Refs, Not(Contains(Pair(findSymbol(MainSymbols, "a").ID, _;
-  EXPECT_THAT(Refs, Not(Contains(Pair(findSymbol(MainSymbols, "b").ID, _;
+  EXPECT_THAT(Refs, Contains(Pair(findSymbol(MainSymbols, "a").ID, _

[clang-tools-extra] 90684d1 - [clangd] Collect references for externally visible main-file symbols

2020-07-27 Thread Aleksandr Platonov via cfe-commits

Author: Aleksandr Platonov
Date: 2020-07-27T15:35:53+03:00
New Revision: 90684d1545167ee4e0c93d8eaf6ba4a3c7ab710e

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

LOG: [clangd] Collect references for externally visible main-file symbols

Summary:
Without this patch clangd does not collect references for main-file symbols if 
there is no public declaration in preamble.
Example:
`test1.c`
```
void f1() {}
```

`test2.c`
```
extern void f1();
void f2() {
  f^1();
}
```
`Find all references` does not show definition of f1() in the result, but GTD 
works OK.

Reviewers: sammccall, kadircet

Reviewed By: kadircet

Subscribers: ilya-golovenko, ilya-biryukov, MaskRay, jkorous, arphaman, 
kadircet, usaxena95, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang-tools-extra/clangd/index/SymbolCollector.cpp
clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/index/SymbolCollector.cpp 
b/clang-tools-extra/clangd/index/SymbolCollector.cpp
index 6c11399c87b6..c163951aff9b 100644
--- a/clang-tools-extra/clangd/index/SymbolCollector.cpp
+++ b/clang-tools-extra/clangd/index/SymbolCollector.cpp
@@ -314,7 +314,8 @@ bool SymbolCollector::handleDeclOccurrence(
   // file locations for references (as it aligns the behavior of clangd's
   // AST-based xref).
   // FIXME: we should try to use the file locations for other fields.
-  if (CollectRef && !IsMainFileOnly && !isa(ND) &&
+  if (CollectRef && (!IsMainFileOnly || ND->isExternallyVisible()) &&
+  !isa(ND) &&
   (Opts.RefsInHeaders ||
SM.getFileID(SM.getFileLoc(Loc)) == SM.getMainFileID()))
 DeclRefs[ND].emplace_back(SM.getFileLoc(Loc), Roles);

diff  --git a/clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp 
b/clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
index 70d5156b1072..f1c582ef1abe 100644
--- a/clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
+++ b/clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
@@ -171,7 +171,7 @@ TEST_F(BackgroundIndexTest, IndexTwoFiles) {
   #endif
   )cpp";
   FS.Files[testPath("root/A.cc")] =
-  "#include \"A.h\"\nvoid g() { (void)common; }";
+  "#include \"A.h\"\nstatic void g() { (void)common; }";
   FS.Files[testPath("root/B.cc")] =
   R"cpp(
   #define A 0

diff  --git a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp 
b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
index 9e4f75b5cca3..3614ab2c5cb9 100644
--- a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -624,11 +624,13 @@ TEST_F(SymbolCollectorTest, Refs) {
   EXPECT_THAT(Refs, Not(Contains(Pair(findSymbol(Symbols, "NS").ID, _;
   EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, "MACRO").ID,
   HaveRanges(Main.ranges("macro");
-  // Symbols *only* in the main file (a, b, c, FUNC) had no refs collected.
+  // Symbols *only* in the main file:
+  // - (a, b) externally visible and should have refs.
+  // - (c, FUNC) externally invisible and had no refs collected.
   auto MainSymbols =
   TestTU::withHeaderCode(SymbolsOnlyInMainCode.code()).headerSymbols();
-  EXPECT_THAT(Refs, Not(Contains(Pair(findSymbol(MainSymbols, "a").ID, _;
-  EXPECT_THAT(Refs, Not(Contains(Pair(findSymbol(MainSymbols, "b").ID, _;
+  EXPECT_THAT(Refs, Contains(Pair(findSymbol(MainSymbols, "a").ID, _)));
+  EXPECT_THAT(Refs, Contains(Pair(findSymbol(MainSymbols, "b").ID, _)));
   EXPECT_THAT(Refs, Not(Contains(Pair(findSymbol(MainSymbols, "c").ID, _;
   EXPECT_THAT(Refs, Not(Contains(Pair(findSymbol(MainSymbols, "FUNC").ID, 
_;
 }
@@ -816,11 +818,15 @@ TEST_F(SymbolCollectorTest, HeaderAsMainFile) {
 $Foo[[Foo]] fo;
   }
   )");
-  // The main file is normal .cpp file, we shouldn't collect any refs of 
symbols
-  // which are not declared in the preamble.
+  // The main file is normal .cpp file, we should collect the refs
+  // for externally visible symbols.
   TestFileName = testPath("foo.cpp");
   runSymbolCollector("", Header.code());
-  EXPECT_THAT(Refs, UnorderedElementsAre());
+  EXPECT_THAT(Refs,
+  UnorderedElementsAre(Pair(findSymbol(Symbols, "Foo").ID,
+HaveRanges(Header.ranges("Foo"))),
+   Pair(findSymbol(Symbols, "Func").ID,
+HaveRanges(Header.ranges("Func");
 
   // Run the .h file as main file, we should collect the refs.
   TestFileName = testPath("foo.h");



___

[clang-tools-extra] 08e9556 - llvm_canonicalize_cmake_booleans(CLANGD_ENABLE_REMOTE)

2020-07-27 Thread Hans Wennborg via cfe-commits

Author: Hans Wennborg
Date: 2020-07-27T14:42:04+02:00
New Revision: 08e9556d5d77fb424b8cb99fe16ffe2bc77f555e

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

LOG: llvm_canonicalize_cmake_booleans(CLANGD_ENABLE_REMOTE)

Otherwise it got defined as e.g. OFF in Features.inc.

Added: 


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

Removed: 




diff  --git a/clang-tools-extra/clangd/CMakeLists.txt 
b/clang-tools-extra/clangd/CMakeLists.txt
index 8db6656e5291..639441e8130a 100644
--- a/clang-tools-extra/clangd/CMakeLists.txt
+++ b/clang-tools-extra/clangd/CMakeLists.txt
@@ -15,6 +15,7 @@ if (NOT DEFINED CLANGD_BUILD_XPC)
 endif ()
 
 llvm_canonicalize_cmake_booleans(CLANGD_BUILD_XPC)
+llvm_canonicalize_cmake_booleans(CLANGD_ENABLE_REMOTE)
 
 configure_file(
   ${CMAKE_CURRENT_SOURCE_DIR}/Features.inc.in



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


[PATCH] D84048: DR2303: Prefer 'nearer' base classes during template deduction.

2020-07-27 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Ping!  I believe I've done all of the requested changes.


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

https://reviews.llvm.org/D84048



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


[PATCH] D84499: [clangd] Add more logs and attach tracers to remote index server routines

2020-07-27 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.
This revision is now accepted and ready to land.

thanks, LGTM apart from templated-lambdas.




Comment at: clang-tools-extra/clangd/index/remote/server/Server.cpp:86
+unsigned FailedToSend = 0;
+Index->lookup(Req, [&](const auto &Item) {
+  auto SerializedItem = ProtobufMarshaller->toProtobuf(Item);

usage of `auto` in here results in a templated-lambda. I don't think we want 
that (please let me know if I am missing something) maybe go back to using 
clangd::Symbol ? (same for other lambdas)



Comment at: clang-tools-extra/clangd/index/remote/server/Server.cpp:203
+  TracerStream.reset();
+  llvm::errs() << "Error while opening trace file " << TraceFile << ": "
+   << EC.message();

any reasons for not using elog in here (and in other places using 
`llvm::errs()` ?



Comment at: clang-tools-extra/clangd/index/remote/server/Server.cpp:122
 }
-Index->lookup(Req, [&](const clangd::Symbol &Sym) {
-  auto SerializedSymbol = ProtobufMarshaller->toProtobuf(Sym);
-  if (!SerializedSymbol)
-return;
-  LookupReply NextMessage;
-  *NextMessage.mutable_stream_result() = *SerializedSymbol;
-  Reply->Write(NextMessage);
-});
+std::function kbobyrev wrote:
> > kadircet wrote:
> > > all of this trickery is really nice. but i am not sure if it improves 
> > > readability at all, from the perspective of call sites the amount of code 
> > > is almost the same. moreover it was some trivial lambda before and 
> > > instead it is lots of template parameters now.
> > > 
> > > maybe just have templated function to replace the lambda body instead? 
> > > e.g.
> > > 
> > > ```
> > > template 
> > > void IndexCallback(Marshaller &M, StreamType &Item) {
> > >   trace::Span Tracer;
> > >   auto SerializedSymbol = M.toProtobuf(Item);
> > >   // log the events and much more ...
> > > }
> > > 
> > > ```
> > > 
> > > then call it in the callbacks. WDYT?
> > I think this is a good idea but I can't think of a nice way to do that, 
> > too. `IndexCallback` would have to update `Sent` and `FailedToSend` 
> > (`Tracer` should be outside of the callback, right?), and the callback 
> > signature if fixed so I wouldn't be able to pass these parameters by 
> > reference :( I could probably make those two fields of the class but this 
> > doesn't look very nice, or pass member function (templated one) to the 
> > callback in each index request, but this also doesn't look very nice.
> > 
> > I think the reason was initially to improve readability but then it's more 
> > about code deduplication: right now there are 3 pieces of code that do 
> > exactly the same, there will be a fourth one (relations request). Maybe 
> > readability even decreases but I really think that having 4 pieces of code 
> > with different types is not very nice. Also, D84525 compliments this and 
> > there will be practically only no functional code in the functions 
> > themselves.
> > 
> > I can understand your argument and I partially support it but I really 
> > think we're unfortunately choosing between bad and worse.
> FWIW, I find the template to be very hard to read, and would prefer the 
> version that is duplicated 4 times. 
> 
> I've left some suggestions for how to simplify (mostly, eliminating template 
> parameters) but I'm still not sure it's worth it.
> I think this is a good idea but I can't think of a nice way to do that, too. 
> IndexCallback would have to update Sent and FailedToSend (Tracer should be 
> outside of the callback, right?), and the callback signature if fixed so I 
> wouldn't be able to pass these parameters by reference :( I could probably 
> make those two fields of the class but this doesn't look very nice, or pass 
> member function (templated one) to the callback in each index request, but 
> this also doesn't look very nice.

right, i've missed that bit. but I was suggesting you to call `IndexCallback` 
inside the lambda, e.g. callsites would look like this:

```
Index->lookup(Req, [&](const auto &Item) {
IndexCallback(*ProtobufMarshaller, Item);
});
```

so in theory you could pass in `Sent` and `FailedToSend` as parameters to 
`IndexCallback` and mutate them in there.


but not really relevant anymore.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84499



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


[PATCH] D84637: [AST] Enhance the const expression evaluator to support error-dependent exprs.

2020-07-27 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Based on richard's suggestions, that seems about right.  However I believe all 
the asserts should have a message to go along with them as we typicaly do.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84637



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


[PATCH] D82502: [PowerPC] Implement Load VSX Vector and Sign Extend and Zero Extend

2020-07-27 Thread Lei Huang via Phabricator via cfe-commits
lei added inline comments.



Comment at: llvm/lib/Target/PowerPC/PPCISelLowering.cpp:14156
+
+  // This transformation is only valid if the we are loading either a byte,
+  // halfword, word, or doubleword.

Conanap wrote:
> NeHuang wrote:
> > nit: if we are loading either a byte
> I'm not too sure what you mean, would you be able to elaborate?  
> The comment is:
> 
> 
> > This transformation is only valid if the we are loading either a byte,
> > halfword, word, or doubleword.
> 
> Thanks!
> 
> 
Extra `the` in your sentence:
`This transformation is only valid if the we are loading` -> `This 
transformation is only valid if we are loading`


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

https://reviews.llvm.org/D82502



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


[PATCH] D84461: [Concepts] Fix ast dump for immediately declared constraint.

2020-07-27 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 280890.
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/D84461/new/

https://reviews.llvm.org/D84461

Files:
  clang/lib/AST/TextNodeDumper.cpp
  clang/test/AST/ast-dump-concepts.cpp


Index: clang/test/AST/ast-dump-concepts.cpp
===
--- /dev/null
+++ clang/test/AST/ast-dump-concepts.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -std=c++2a -ast-dump 
-ast-dump-filter Foo %s | FileCheck -strict-whitespace %s
+
+// Test with serialization:
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -x c++ -std=c++20 -triple x86_64-unknown-unknown 
-include-pch %t \
+// RUN: -ast-dump-all -ast-dump-filter Foo /dev/null \
+// RUN: | FileCheck --strict-whitespace %s
+
+template 
+concept binary_concept = true;
+
+template 
+struct Foo {
+  // CHECK:  TemplateTypeParmDecl {{.*}} referenced Concept {{.*}} 
'binary_concept'
+  // CHECK-NEXT: |-ConceptSpecializationExpr {{.*}} 'bool'
+  // CHECK-NEXT: `-TemplateArgument {{.*}} type 'int'
+  template  R>
+  Foo(R);
+};
Index: clang/lib/AST/TextNodeDumper.cpp
===
--- clang/lib/AST/TextNodeDumper.cpp
+++ clang/lib/AST/TextNodeDumper.cpp
@@ -1994,7 +1994,7 @@
   dumpBareDeclRef(TC->getFoundDecl());
   OS << ")";
 }
-Visit(TC->getImmediatelyDeclaredConstraint());
+AddChild([=] { Visit(TC->getImmediatelyDeclaredConstraint()); });
   } else if (D->wasDeclaredWithTypename())
 OS << " typename";
   else


Index: clang/test/AST/ast-dump-concepts.cpp
===
--- /dev/null
+++ clang/test/AST/ast-dump-concepts.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -std=c++2a -ast-dump -ast-dump-filter Foo %s | FileCheck -strict-whitespace %s
+
+// Test with serialization:
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -x c++ -std=c++20 -triple x86_64-unknown-unknown -include-pch %t \
+// RUN: -ast-dump-all -ast-dump-filter Foo /dev/null \
+// RUN: | FileCheck --strict-whitespace %s
+
+template 
+concept binary_concept = true;
+
+template 
+struct Foo {
+  // CHECK:  TemplateTypeParmDecl {{.*}} referenced Concept {{.*}} 'binary_concept'
+  // CHECK-NEXT: |-ConceptSpecializationExpr {{.*}} 'bool'
+  // CHECK-NEXT: `-TemplateArgument {{.*}} type 'int'
+  template  R>
+  Foo(R);
+};
Index: clang/lib/AST/TextNodeDumper.cpp
===
--- clang/lib/AST/TextNodeDumper.cpp
+++ clang/lib/AST/TextNodeDumper.cpp
@@ -1994,7 +1994,7 @@
   dumpBareDeclRef(TC->getFoundDecl());
   OS << ")";
 }
-Visit(TC->getImmediatelyDeclaredConstraint());
+AddChild([=] { Visit(TC->getImmediatelyDeclaredConstraint()); });
   } else if (D->wasDeclaredWithTypename())
 OS << " typename";
   else
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D83338: [PowerPC][Power10] Implemented Vector Shift Builtins

2020-07-27 Thread Lei Huang via Phabricator via cfe-commits
lei added a comment.

Please address the auto generated clang-format issues for the added code in 
this patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83338



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


[PATCH] D84005: Introduce ns_error_domain attribute.

2020-07-27 Thread Michael Forster via Phabricator via cfe-commits
MForster marked 3 inline comments as done.
MForster added a comment.

Two clarifying questions...




Comment at: clang/lib/Sema/SemaDeclAttr.cpp:5350
+
+  D->addAttr(::new (S.Context)
+ NSErrorDomainAttr(S.Context, AL, IdentLoc->Ident));

aaron.ballman wrote:
> Shouldn't we also be validating that what we found is an NSString that has 
> the correct properties? (That doesn't seem like it should be a change which 
> risks breaking code based on what I understood from Doug's description.)
> Shouldn't we also be validating that what we found is an NSString that has 
> the correct properties?

Is your suggestion to string-compare the name of the type?



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:5355
+S.Diag(identLoc->Loc, diag::err_nserrordomain_invalid_decl)
+<< identLoc->Ident;
+return;

aaron.ballman wrote:
> MForster wrote:
> > aaron.ballman wrote:
> > > We're doing this lookup in the context of where the attribute is being 
> > > used, but then creating the attribute with only the identifier and not 
> > > the result of that lookup. This makes me a bit worried that when 
> > > something goes to resolve that identifier to a variable later, it may get 
> > > a different result because the lookup context will be different. Do you 
> > > need to store the VarDecl on the semantic attribute, rather than the 
> > > identifier?
> > >We're doing this lookup in the context of where the attribute is being 
> > >used, but then creating the attribute with only the identifier and not the 
> > >result of that lookup. This makes me a bit worried that when something 
> > >goes to resolve that identifier to a variable later, it may get a 
> > >different result because the lookup context will be different. Do you need 
> > >to store the VarDecl on the semantic attribute, rather than the identifier?
> > 
> > 
> > When this gets imported into Swift, only the name of the identifier gets 
> > used. I'm not quite sure why this was defined like this. This is another 
> > thing where I would hope that @gribozavr2 or @milseman know more...
> Based on the answer from @doug.gregor, I think this should be adding the 
> result of the lookup to the semantic attribute and not the identifier (the 
> identifier may not be unique, the VarDecl must be unique though).
> Based on the answer from @doug.gregor, I think this should be adding the 
> result of the lookup to the semantic attribute and not the identifier (the 
> identifier may not be unique, the VarDecl must be unique though).

How are you suggesting to implement that? Change the argument to to be a 
`DeclArgument` or `ExprArgument` instead of an `IdentifierArgument`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84005



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


[PATCH] D81865: use string tables for static diagnostic descriptions

2020-07-27 Thread Nathan Froyd via Phabricator via cfe-commits
froydnj added a comment.

Ping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81865



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


[PATCH] D84656: [clang] Pass the NamedDecl* instead of the DeclarationName into many diagnostics.

2020-07-27 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno created this revision.
riccibruno added reviewers: rsmith, aaron.ballman, erichkeane.
riccibruno added a project: clang.
Herald added a subscriber: cfe-commits.

Background:
---

There are two related argument types which can be sent into a diagnostic to 
display the name of an entity: `DeclarationName` (`ak_declarationname`) or 
`NamedDecl *` (`ak_nameddecl`) (there is also `ak_identifierinfo` for 
`IdentifierInfo *`, but we are not concerned with it here).

A `DeclarationName` in a diagnostic will just be streamed to the output, which 
will directly result in a call to `DeclarationName::print`.

A `NamedDecl *` in a diagnostic will also ultimately result in a call to 
`DeclarationName::print`, but with two customisation points along the way.

The first customisation point is `NamedDecl::getNameForDiagnostic` which is 
overloaded by `FunctionDecl`, `ClassTemplateSpecializationDecl` and 
`VarTemplateSpecializationDecl` to print the template arguments if any.

The second customisation point is `NamedDecl::printName`. By default it just 
streams the stored `DeclarationName` into the output but it can be customised 
to provide a user-friendly name for an entity. It is currently overloaded by 
`DecompositionDecl` and `MSGuidDecl`.

What this patch does:
-

For many diagnostics a `DeclarationName` is used instead of the `NamedDecl *`. 
This bypasses the two customisation points mentioned above. This patches fix 
this for diagnostics in `Sema.cpp`, `SemaCast.cpp`, `SemaChecking.cpp`, 
`SemaDecl.cpp`, `SemaDeclAttr.cpp`, `SemaDecl.cpp`, `SemaOverload.cpp` and 
`SemaStmt.cpp`.

I have only modified diagnostics where I could construct a test-case which 
demonstrates that the change is appropriate (either with this patch or the next 
one).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D84656

Files:
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp
  clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p3.cpp
  clang/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp
  clang/test/CXX/temp/temp.param/p15-cxx0x.cpp
  clang/test/Modules/module-private.cpp
  clang/test/SemaCXX/array-bounds.cpp
  clang/test/SemaCXX/attr-unused.cpp
  clang/test/SemaCXX/cxx1y-variable-templates_in_class.cpp
  clang/test/SemaCXX/default2.cpp
  clang/test/SemaCXX/incomplete-call.cpp
  clang/test/SemaCXX/references.cpp
  clang/test/SemaCXX/return-void.cpp
  clang/test/SemaCXX/warn-func-not-needed.cpp
  clang/test/SemaCXX/warn-large-by-value-copy.cpp
  clang/test/SemaCXX/warn-member-not-needed.cpp
  clang/test/SemaCXX/warn-pure-virtual-call-from-ctor-dtor.cpp
  clang/test/SemaCXX/warn-pure-virtual-kext.cpp
  clang/test/SemaCXX/warn-unused-filescoped.cpp
  clang/test/SemaCXX/warn-variable-not-needed.cpp

Index: clang/test/SemaCXX/warn-variable-not-needed.cpp
===
--- clang/test/SemaCXX/warn-variable-not-needed.cpp
+++ clang/test/SemaCXX/warn-variable-not-needed.cpp
@@ -5,7 +5,7 @@
 
   namespace {
   template  int abc_template = 0;
-  template <> int abc_template = 0; // expected-warning {{variable 'abc_template' is not needed and will not be emitted}}
+  template <> int abc_template = 0; // expected-warning {{variable 'abc_template' is not needed and will not be emitted}}
   }  // namespace
   template 
   int foo(void) {
Index: clang/test/SemaCXX/warn-unused-filescoped.cpp
===
--- clang/test/SemaCXX/warn-unused-filescoped.cpp
+++ clang/test/SemaCXX/warn-unused-filescoped.cpp
@@ -67,7 +67,7 @@
 
   template 
   void tf() {}  // expected-warning{{unused function template 'tf'}}
-  template <> void tf() {} // expected-warning{{unused function 'tf'}}
+  template <> void tf() {} // expected-warning{{unused function 'tf'}}
 
   struct VS {
 virtual void vm() { }
@@ -102,7 +102,7 @@
 
   template  int vt = 0; // expected-warning {{unused variable template 'vt'}}
   template  int vt = 0;
-  template <> int vt = 0; // expected-warning {{unused variable 'vt'}}
+  template <> int vt = 0; // expected-warning {{unused variable 'vt'}}
 }
 
 namespace PR8841 {
@@ -132,7 +132,7 @@
 namespace rdar8733476 {
 static void foo() {} // expected-warning {{function 'foo' is not needed and will not be emitted}}
 template  static void foo_t() {} // expected-warning {{unused function template 'foo_t'}}
-template <> void foo_t() {} // expected-warning {{function 'foo_t' is not needed and will not be emitted}}
+template <> void foo_t() {} // expected-warning {{function 'foo_t' is not needed and will not be emitted}}
 
 template 
 void bar() {
@@ 

[PATCH] D84348: WIP: Add complete id-expression support to syntax trees

2020-07-27 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 280899.
eduucaldas marked 9 inline comments as done.
eduucaldas added a comment.

- Answer code review
- Simpler logic for `getUnqualifiedIdSourceRange` and inline it
- Remove ambiguously named variable NNS


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84348

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.cpp
  clang/unittests/Tooling/Syntax/TreeTest.cpp

Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -867,24 +867,47 @@
   }
   EXPECT_TRUE(treeDumpEqual(
   R"cpp(
-namespace a {
+namespace n {
   struct S {
 template
-static T f(){}
+struct ST {
+  static void f();
+};
   };
 }
+template
+struct ST {
+  struct S {
+template
+static U f();
+  };
+};
 void test() {
-  ::  // global-namespace-specifier
-  a:: // namespace-specifier
-  S:: // type-name-specifier
+  :: // global-namespace-specifier
+  n::// namespace-specifier
+  S::// type-name-specifier
+  template ST:: // type-template-instantiation-specifier
+  f();
+
+  n::// namespace-specifier
+  S::// type-name-specifier
+  ST::  // type-template-instantiation-specifier
+  f();
+
+  ST:: // type-name-specifier
+  S::   // type-name-specifier
   f();
+
+  ST:: // type-name-specifier
+  S::   // type-name-specifier
+  template f();
 }
 )cpp",
   R"txt(
 *: TranslationUnit
 |-NamespaceDefinition
 | |-namespace
-| |-a
+| |-n
 | |-{
 | |-SimpleDeclaration
 | | |-struct
@@ -898,19 +921,58 @@
 | | | | `-T
 | | | |->
 | | | `-SimpleDeclaration
-| | |   |-static
-| | |   |-T
-| | |   |-SimpleDeclarator
-| | |   | |-f
-| | |   | `-ParametersAndQualifiers
-| | |   |   |-(
-| | |   |   `-)
-| | |   `-CompoundStatement
-| | | |-{
-| | | `-}
+| | |   |-struct
+| | |   |-ST
+| | |   |-{
+| | |   |-SimpleDeclaration
+| | |   | |-static
+| | |   | |-void
+| | |   | |-SimpleDeclarator
+| | |   | | |-f
+| | |   | | `-ParametersAndQualifiers
+| | |   | |   |-(
+| | |   | |   `-)
+| | |   | `-;
+| | |   |-}
+| | |   `-;
 | | |-}
 | | `-;
 | `-}
+|-TemplateDeclaration
+| |-template
+| |-<
+| |-UnknownDeclaration
+| | |-typename
+| | `-T
+| |->
+| `-SimpleDeclaration
+|   |-struct
+|   |-ST
+|   |-{
+|   |-SimpleDeclaration
+|   | |-struct
+|   | |-S
+|   | |-{
+|   | |-TemplateDeclaration
+|   | | |-template
+|   | | |-<
+|   | | |-UnknownDeclaration
+|   | | | |-typename
+|   | | | `-U
+|   | | |->
+|   | | `-SimpleDeclaration
+|   | |   |-static
+|   | |   |-U
+|   | |   |-SimpleDeclarator
+|   | |   | |-f
+|   | |   | `-ParametersAndQualifiers
+|   | |   |   |-(
+|   | |   |   `-)
+|   | |   `-;
+|   | |-}
+|   | `-;
+|   |-}
+|   `-;
 `-SimpleDeclaration
   |-void
   |-SimpleDeclarator
@@ -924,14 +986,81 @@
 | |-UnknownExpression
 | | |-IdExpression
 | | | |-NestedNameSpecifier
-| | | | |-NameSpecifier
-| | | | | `-::
-| | | | |-NameSpecifier
-| | | | | |-a
-| | | | | `-::
-| | | | `-NameSpecifier
-| | | |   |-S
-| | | |   `-::
+| | | | |-::
+| | | | |-IdentifierNameSpecifier
+| | | | | `-n
+| | | | |-::
+| | | | |-IdentifierNameSpecifier
+| | | | | `-S
+| | | | |-::
+| | | | |-SimpleTemplateNameSpecifier
+| | | | | |-template
+| | | | | |-ST
+| | | | | |-<
+| | | | | |-int
+| | | | | `->
+| | | | `-::
+| | | `-UnqualifiedId
+| | |   `-f
+| | |-(
+| | `-)
+| `-;
+|-ExpressionStatement
+| |-UnknownExpression
+| | |-IdExpression
+| | | |-NestedNameSpecifier
+| | | | |-IdentifierNameSpecifier
+| | | | | `-n
+| | | | |-::
+| | | | |-IdentifierNameSpecifier
+| | | | | `-S
+| | | | |-::
+| | | | |-SimpleTemplateNameSpecifier
+| | | | | |-ST
+| | | | | |-<
+| | | | | |-int
+| | | | | `->
+| | | | `-::
+| | | `-UnqualifiedId
+| | |   `-f
+| | |-(
+| | `-)
+| `-;
+|-ExpressionStatement
+| |-UnknownExpression
+| | |-IdExpression
+| | | |-NestedNameSpecifier
+| | | | |-SimpleTemplateNameSpecifier
+| | | | | |-ST
+| | | | | |-<
+| | | | | |-int
+| | | | | `->
+| | | | |-::
+| | | | |-IdentifierNameSpecifier
+| | | | | `-S
+| | | | `-::
+| | | `-UnqualifiedId
+| | |   |-f
+| | |   |-<
+| | |   |-int
+| | |   `->
+| | |-(
+| | `-)
+| `-;
+|-ExpressionStatement
+| |-UnknownExpression
+| | |-IdExpression
+| | | |-NestedNameSpecifier
+| | | | |-SimpleTemplateNameSpecifier
+| | | | | |-ST
+| | | | | |-<

[PATCH] D84534: [AIX] Static init frontend recovery and backend support

2020-07-27 Thread Xiangling Liao via Phabricator via cfe-commits
Xiangling_L updated this revision to Diff 280897.
Xiangling_L added a comment.

Fix clang-tidy errors;


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

https://reviews.llvm.org/D84534

Files:
  clang/lib/CodeGen/CGDeclCXX.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/test/CodeGenCXX/aix-static-init-debug-info.cpp
  clang/test/CodeGenCXX/aix-static-init-temp-spec-and-inline-var.cpp
  clang/test/CodeGenCXX/aix-static-init.cpp
  llvm/include/llvm/CodeGen/AsmPrinter.h
  llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
  llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
  llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
  llvm/test/CodeGen/PowerPC/aix-static-init-default-priority.ll
  llvm/test/CodeGen/PowerPC/aix-static-init-no-unique-module-id.ll
  llvm/test/CodeGen/PowerPC/aix-static-init-non-default-priority.ll

Index: llvm/test/CodeGen/PowerPC/aix-static-init-non-default-priority.ll
===
--- /dev/null
+++ llvm/test/CodeGen/PowerPC/aix-static-init-non-default-priority.ll
@@ -0,0 +1,10 @@
+; RUN: not llc -mtriple powerpc-ibm-aix-xcoff < %s 2>&1 | FileCheck %s
+; RUN: not llc -mtriple powerpc64-ibm-aix-xcoff < %s 2>&1 | FileCheck %s
+
+@llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 655, void ()* @foo, i8* null }]
+
+define void @foo() {
+  ret void
+}
+
+// CHECK: LLVM ERROR: prioritized sinit and sterm functions are not yet supported
Index: llvm/test/CodeGen/PowerPC/aix-static-init-no-unique-module-id.ll
===
--- /dev/null
+++ llvm/test/CodeGen/PowerPC/aix-static-init-no-unique-module-id.ll
@@ -0,0 +1,7 @@
+; RUN: not llc -mtriple powerpc-ibm-aix-xcoff < %s 2>&1 | FileCheck %s
+; RUN: not llc -mtriple powerpc64-ibm-aix-xcoff < %s 2>&1 | FileCheck %s
+
+@llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @foo, i8* null }]
+@llvm.global_dtors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @bar, i8* null }]
+
+// CHECK: LLVM ERROR: cannot produce a unique identifier for this module based on strong external symbols
Index: llvm/test/CodeGen/PowerPC/aix-static-init-default-priority.ll
===
--- /dev/null
+++ llvm/test/CodeGen/PowerPC/aix-static-init-default-priority.ll
@@ -0,0 +1,31 @@
+; RUN: llc -mtriple powerpc-ibm-aix-xcoff < %s | FileCheck %s
+; RUN: llc -mtriple powerpc64-ibm-aix-xcoff < %s | FileCheck %s
+
+@llvm.global_ctors = appending global [2 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @init1, i8* null }, { i32, void ()*, i8* } { i32 65535, void ()* @init2, i8* null }]
+@llvm.global_dtors = appending global [2 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @destruct1, i8* null }, { i32, void ()*, i8* } { i32 65535, void ()* @destruct2, i8* null }]
+
+define i32 @extFunc() {
+entry:
+  ret i32 3
+}
+
+define internal void @init1() {
+  ret void
+}
+
+define internal void @destruct1() {
+  ret void
+}
+
+define internal void @init2() {
+  ret void
+}
+
+define internal void @destruct2() {
+  ret void
+}
+
+; CHECK: .globl	.__sinit8000_clang_ac404299654d2af7eae71e75c17f7c9b_0
+; CHECK: .globl	.__sterm8000_clang_ac404299654d2af7eae71e75c17f7c9b_0
+; CHECK: .globl	.__sinit8000_clang_ac404299654d2af7eae71e75c17f7c9b_1
+; CHECK: .globl	.__sterm8000_clang_ac404299654d2af7eae71e75c17f7c9b_1
Index: llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
===
--- llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
+++ llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
@@ -67,6 +67,7 @@
 #include "llvm/Support/TargetRegistry.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/TargetMachine.h"
+#include "llvm/Transforms/Utils/ModuleUtils.h"
 #include 
 #include 
 #include 
@@ -153,6 +154,9 @@
   /// linkage for them in AIX.
   SmallPtrSet ExtSymSDNodeSymbols;
 
+  /// A unique trailing identifier as a part of sinit/sterm functions.
+  std::string GlobalUniqueModuleId;
+
   static void ValidateGV(const GlobalVariable *GV);
   // Record a list of GlobalAlias associated with a GlobalObject.
   // This is used for AIX's extra-label-at-definition aliasing strategy.
@@ -171,6 +175,9 @@
 
   bool doInitialization(Module &M) override;
 
+  void emitXXStructor(const DataLayout &DL, const int Priority,
+  const unsigned Index, Constant *CV, bool IsCtor) override;
+
   void SetupMachineFunction(MachineFunction &MF) override;
 
   void emitGlobalVariable(const GlobalVariable *GV) override;
@@ -1687,10 +1694,7 @@
 void PPCAIXAsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {
   ValidateGV(GV);
 
-  // TODO: Update the handling of global arrays for 

[PATCH] D84005: Introduce ns_error_domain attribute.

2020-07-27 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:5350
+
+  D->addAttr(::new (S.Context)
+ NSErrorDomainAttr(S.Context, AL, IdentLoc->Ident));

MForster wrote:
> aaron.ballman wrote:
> > Shouldn't we also be validating that what we found is an NSString that has 
> > the correct properties? (That doesn't seem like it should be a change which 
> > risks breaking code based on what I understood from Doug's description.)
> > Shouldn't we also be validating that what we found is an NSString that has 
> > the correct properties?
> 
> Is your suggestion to string-compare the name of the type?
>>Shouldn't we also be validating that what we found is an NSString that has 
>>the correct properties?
> Is your suggestion to string-compare the name of the type?

You should be able to compare the `QualType` of the resulting `VarDecl` against 
`ASTContext::getObjCNSStringType()` (accounting for qualifiers, pointers, etc).



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:5355
+S.Diag(identLoc->Loc, diag::err_nserrordomain_invalid_decl)
+<< identLoc->Ident;
+return;

MForster wrote:
> aaron.ballman wrote:
> > MForster wrote:
> > > aaron.ballman wrote:
> > > > We're doing this lookup in the context of where the attribute is being 
> > > > used, but then creating the attribute with only the identifier and not 
> > > > the result of that lookup. This makes me a bit worried that when 
> > > > something goes to resolve that identifier to a variable later, it may 
> > > > get a different result because the lookup context will be different. Do 
> > > > you need to store the VarDecl on the semantic attribute, rather than 
> > > > the identifier?
> > > >We're doing this lookup in the context of where the attribute is being 
> > > >used, but then creating the attribute with only the identifier and not 
> > > >the result of that lookup. This makes me a bit worried that when 
> > > >something goes to resolve that identifier to a variable later, it may 
> > > >get a different result because the lookup context will be different. Do 
> > > >you need to store the VarDecl on the semantic attribute, rather than the 
> > > >identifier?
> > > 
> > > 
> > > When this gets imported into Swift, only the name of the identifier gets 
> > > used. I'm not quite sure why this was defined like this. This is another 
> > > thing where I would hope that @gribozavr2 or @milseman know more...
> > Based on the answer from @doug.gregor, I think this should be adding the 
> > result of the lookup to the semantic attribute and not the identifier (the 
> > identifier may not be unique, the VarDecl must be unique though).
> > Based on the answer from @doug.gregor, I think this should be adding the 
> > result of the lookup to the semantic attribute and not the identifier (the 
> > identifier may not be unique, the VarDecl must be unique though).
> 
> How are you suggesting to implement that? Change the argument to to be a 
> `DeclArgument` or `ExprArgument` instead of an `IdentifierArgument`?
>>Based on the answer from @doug.gregor, I think this should be adding the 
>>result of the lookup to the semantic attribute and not the identifier (the 
>>identifier may not be unique, the VarDecl must be unique though).
> How are you suggesting to implement that? Change the argument to to be a 
> DeclArgument or ExprArgument instead of an IdentifierArgument?

I think `DeclArgument` is probably the correct approach and you should be able 
to model it somewhat off the `cleanup` attribute. Otherwise, you can gin up a 
"fake" attribute argument. Those aren't arguments used by the parser or pretty 
printer, but are used to form the semantic attribute constructor to provide 
additional information.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84005



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


[PATCH] D84656: [clang] Pass the NamedDecl* instead of the DeclarationName into many diagnostics.

2020-07-27 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added a comment.
This revision is now accepted and ready to land.

I looked through the code changes, and they all seem quite mechanical.  I 
believe they are all correct.

After reading through the test changes, I believe that this change is strictly 
an improvement thanks to printing the template arguments. Therefore, I don't 
believe I know of any way that htis is controversial.

That said, because I'm approving so quickly after submission, please give at 
least a few hours before committing to give the other reviewers a chance to 
take a look.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84656



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


[PATCH] D84658: [clang] Overload NamedDecl::printName to provide a user-friendly name for unnamed entities

2020-07-27 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno created this revision.
riccibruno added reviewers: rsmith, aaron.ballman, erichkeane.
riccibruno added a project: clang.
Herald added subscribers: cfe-commits, arphaman, dexonsmith.

See D84656  for the background on 
`NamedDecl::printName`.

This patch overloads `NamedDecl::printName` for `VarDecl`, `FieldDecl` 
,`RecordDecl` and `EnumDecl` to provide a more user-friendly name in 
diagnostics. We try to only use the term "anonymous" when we have an anonymous 
struct or union; otherwise we use the term "unnamed".


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D84658

Files:
  clang/include/clang/AST/Decl.h
  clang/lib/AST/Decl.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/test/AST/ast-dump-APValue-anon-union.cpp
  clang/test/AST/ast-dump-record-definition-data-json.cpp
  clang/test/Analysis/explain-svals.cpp
  clang/test/CXX/special/class.dtor/p5-0x.cpp
  clang/test/Index/annotate-comments-typedef.m
  clang/test/Index/annotate-tokens.cpp
  clang/test/Index/c-index-api-loadTU-test.m
  clang/test/Index/c-index-getCursor-test.m
  clang/test/Index/linkage.c
  clang/test/Index/load-decls.c
  clang/test/Index/load-namespaces.cpp
  clang/test/Index/preamble.c
  clang/test/Index/print-bitwidth.c
  clang/test/Index/print-type.c
  clang/test/Index/print-type.cpp
  clang/test/Index/recursive-cxx-member-calls.cpp
  clang/test/Index/targeted-annotation.c
  clang/test/Index/targeted-cursor.c
  clang/test/Index/usrs.m
  clang/test/Modules/module-private.cpp
  clang/test/Sema/address-packed.c
  clang/test/Sema/attr-flag-enum.c
  clang/test/Sema/transparent-union.c
  clang/test/SemaCXX/attr-unused.cpp
  clang/test/SemaCXX/cxx0x-nontrivial-union.cpp
  clang/test/SemaCXX/lambda-expressions.cpp
  clang/test/SemaCXX/ms-interface.cpp
  clang/test/SemaCXX/warn-large-by-value-copy.cpp
  clang/test/SemaObjCXX/arc-0x.mm
  clang/test/Tooling/clang-diff-ast.cpp
  clang/unittests/AST/ASTTraverserTest.cpp

Index: clang/unittests/AST/ASTTraverserTest.cpp
===
--- clang/unittests/AST/ASTTraverserTest.cpp
+++ clang/unittests/AST/ASTTraverserTest.cpp
@@ -825,7 +825,7 @@
 | |-FieldDecl ''
 | |-FieldDecl ''
 | |-FieldDecl ''
-| `-CXXDestructorDecl '~'
+| `-CXXDestructorDecl '~(unnamed class at input.cc:9:3)'
 |-ImplicitCastExpr
 | `-DeclRefExpr 'a'
 |-DeclRefExpr 'b'
Index: clang/test/Tooling/clang-diff-ast.cpp
===
--- clang/test/Tooling/clang-diff-ast.cpp
+++ clang/test/Tooling/clang-diff-ast.cpp
@@ -56,7 +56,7 @@
   int not_initialized;
   // CHECK: CXXConstructorDecl: :X(void (char, int){{( __attribute__\(\(thiscall\)\))?}})(
   // CHECK-NEXT: ParmVarDecl: s(char)
-  // CHECK-NEXT: ParmVarDecl: (int)
+  // CHECK-NEXT: ParmVarDecl: (unnamed variable at {{.*}}:64:16 of type int)(int)
   // CHECK-NEXT: CXXCtorInitializer: Base
   // CHECK-NEXT: CXXConstructExpr
   // CHECK-NEXT: CXXCtorInitializer: m
Index: clang/test/SemaObjCXX/arc-0x.mm
===
--- clang/test/SemaObjCXX/arc-0x.mm
+++ clang/test/SemaObjCXX/arc-0x.mm
@@ -154,15 +154,17 @@
   // functions of the containing class.
   struct S0 {
 union {
-  id f0; // expected-note 6 {{'' is implicitly deleted because variant field 'f0' is an ObjC pointer}}
+  id f0; // expected-note-re 6 {{of '(anonymous union at {{.*}}:156:5)' is implicitly deleted because variant field 'f0' is an ObjC pointer}}
   char f1;
 };
   };
 
   struct S1 {
 union {
-  union { // expected-note {{copy constructor of 'S1' is implicitly deleted because field '' has a deleted copy constructor}} expected-note {{copy assignment operator of 'S1' is implicitly deleted because field '' has a deleted copy assignment operator}} expected-note 4 {{'S1' is implicitly deleted because field '' has a deleted}}
-id f0; // expected-note 2 {{'' is implicitly deleted because variant field 'f0' is an ObjC pointer}}
+  union {  // expected-note-re {{copy constructor of 'S1' is implicitly deleted because field '(unnamed field of type test_union::S1::(anonymous union at {{.*}}:164:7))' has a deleted copy constructor}}
+   // expected-note-re@-1 {{copy assignment operator of 'S1' is implicitly deleted because field '(unnamed field of type test_union::S1::(anonymous union at{{.*}}:164:7))' has a deleted copy assignment operator}}
+   // expected-note-re@-2 4{{'S1' is implicitly deleted because field '(unnamed field of type test_union::S1::(anonymous union at {{.*}}:164:7))' has a deleted}}
+id f0; // expected-note-re 2 {{of '(anonymous union at {{.*}}:164:7)' is implicitly deleted because variant field 'f0' is an ObjC pointer}}
 char f1;
   };
   int f2;
@@ -172,7 +174,7 @@
   struct S2 {
 union {
   // FIXME: the note should say 'f0' is causing the special functions to be deleted.
-  struct { // expect

[PATCH] D84656: [clang] Pass the NamedDecl* instead of the DeclarationName into many diagnostics.

2020-07-27 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno added a comment.

In D84656#2175813 , @erichkeane wrote:

> I looked through the code changes, and they all seem quite mechanical.  I 
> believe they are all correct.
>
> After reading through the test changes, I believe that this change is 
> strictly an improvement thanks to printing the template arguments. Therefore, 
> I don't believe I know of any way that htis is controversial.
>
> That said, because I'm approving so quickly after submission, please give at 
> least a few hours before committing to give the other reviewers a chance to 
> take a look.


I will. Thanks for the review!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84656



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


[PATCH] D84348: WIP: Add complete id-expression support to syntax trees

2020-07-27 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas marked 2 inline comments as done.
eduucaldas added inline comments.



Comment at: clang/lib/Tooling/Syntax/BuildTree.cpp:834
+  // FIXME: I feel like this could be upstreamed.
+  SourceRange getUnqualifiedIdSourceRange(DeclRefExpr *S) {
+if (S->hasExplicitTemplateArgs())

gribozavr2 wrote:
> WDYM by "upstream"?
I meant to put that logic under the DeclRefExpr node, instead of here. But I 
found a way of writing this logic in a simpler way :). So I just inlined it!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84348



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


[PATCH] D66035: [WebAssembly] WIP: Add support for reference types

2020-07-27 Thread Paulo Matos via Phabricator via cfe-commits
pmatos added a comment.

I am interested in continuing this work  and have a patch in progress based on 
the current available one here. Should I post the new patch here or under a new 
bug?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66035



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


[PATCH] D76646: Rename/refactor isIntegerConstantExpression to getIntegerConstantExpression

2020-07-27 Thread Stephan Bergmann via Phabricator via cfe-commits
sberg added inline comments.



Comment at: clang/include/clang/AST/Expr.h:513
 
-  /// isIntegerConstantExpr - Return true if this expression is a valid integer
-  /// constant expression, and, if so, return its value in Result.  If not a
-  /// valid i-c-e, return false and fill in Loc (if specified) with the 
location
-  /// of the invalid expression.
+  /// isIntegerConstantExpr - Return the value if this expression is a valid
+  /// integer constant expression.  If not a valid i-c-e, return None and fill

I think the "Return the value..." description now matches 
getIntegerConstantExpr, not isIntegerConstantExpr


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76646



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


[clang] 92fa91b - [OpenCL] Fixed missing address space for templated copy constructor.

2020-07-27 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2020-07-27T15:18:49+01:00
New Revision: 92fa91bb402921a5705507c38f583e9b8e9d84e4

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

LOG: [OpenCL] Fixed missing address space for templated copy constructor.

Added missing address space for the parameter of copy ctor created
for templated constructor with an R-value reference.

Patch by Ole Strohm (olestrohm)!

Tags: #clang

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

Added: 


Modified: 
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/test/SemaOpenCLCXX/address-space-templates.cl

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 52062e9a5039..8e7b4e1655ea 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -3815,8 +3815,11 @@ static bool AdjustFunctionParmAndArgTypesForDeduction(
 //   If P is a forwarding reference and the argument is an lvalue, the type
 //   "lvalue reference to A" is used in place of A for type deduction.
 if (isForwardingReference(QualType(ParamRefType, 0), FirstInnerIndex) &&
-Arg->isLValue())
+Arg->isLValue()) {
+  if (S.getLangOpts().OpenCL)
+ArgType = S.Context.getAddrSpaceQualType(ArgType, 
LangAS::opencl_generic);
   ArgType = S.Context.getLValueReferenceType(ArgType);
+}
   } else {
 // C++ [temp.deduct.call]p2:
 //   If P is not a reference type:

diff  --git a/clang/test/SemaOpenCLCXX/address-space-templates.cl 
b/clang/test/SemaOpenCLCXX/address-space-templates.cl
index 6b304d2fdda4..be187de5684b 100644
--- a/clang/test/SemaOpenCLCXX/address-space-templates.cl
+++ b/clang/test/SemaOpenCLCXX/address-space-templates.cl
@@ -22,10 +22,28 @@ void foo3() {
   __private T ii; // expected-error{{conflicting address space qualifiers are 
provided between types '__private T' and '__global int'}}
 }
 
+template  struct remove_reference { typedef _Tp type; };
+template  struct remove_reference<_Tp &>  { typedef _Tp type; };
+template  struct as_pointer {
+typedef typename remove_reference<_Tp>::type* type;
+};
+
+struct rep {
+  // CHECK |-CXXConstructorDecl {{.*}} rep 'void (const __generic rep 
&__private) __generic'
+  template::type>
+  rep(U&& v) {}
+};
+
+struct rep_outer : private rep {
+  rep_outer()
+: rep(0) {}
+};
+
 void bar() {
   S sintgl; // expected-note{{in instantiation of template 
class 'S' requested here}}
 
   foo1<__local int>(1); // expected-error{{no matching function for call to 
'foo1'}}
   foo2<__global int>(0);
   foo3<__global int>(); // expected-note{{in instantiation of function 
template specialization 'foo3<__global int>' requested here}}
+  rep_outer r;
 }



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


[PATCH] D83665: [OpenCL] Fixed missing address space for templated copy constructor

2020-07-27 Thread Anastasia Stulova via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG92fa91bb4029: [OpenCL] Fixed missing address space for 
templated copy constructor. (authored by Anastasia).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83665

Files:
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/test/SemaOpenCLCXX/address-space-templates.cl


Index: clang/test/SemaOpenCLCXX/address-space-templates.cl
===
--- clang/test/SemaOpenCLCXX/address-space-templates.cl
+++ clang/test/SemaOpenCLCXX/address-space-templates.cl
@@ -22,10 +22,28 @@
   __private T ii; // expected-error{{conflicting address space qualifiers are 
provided between types '__private T' and '__global int'}}
 }
 
+template  struct remove_reference { typedef _Tp type; };
+template  struct remove_reference<_Tp &>  { typedef _Tp type; };
+template  struct as_pointer {
+typedef typename remove_reference<_Tp>::type* type;
+};
+
+struct rep {
+  // CHECK |-CXXConstructorDecl {{.*}} rep 'void (const __generic rep 
&__private) __generic'
+  template::type>
+  rep(U&& v) {}
+};
+
+struct rep_outer : private rep {
+  rep_outer()
+: rep(0) {}
+};
+
 void bar() {
   S sintgl; // expected-note{{in instantiation of template 
class 'S' requested here}}
 
   foo1<__local int>(1); // expected-error{{no matching function for call to 
'foo1'}}
   foo2<__global int>(0);
   foo3<__global int>(); // expected-note{{in instantiation of function 
template specialization 'foo3<__global int>' requested here}}
+  rep_outer r;
 }
Index: clang/lib/Sema/SemaTemplateDeduction.cpp
===
--- clang/lib/Sema/SemaTemplateDeduction.cpp
+++ clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -3815,8 +3815,11 @@
 //   If P is a forwarding reference and the argument is an lvalue, the type
 //   "lvalue reference to A" is used in place of A for type deduction.
 if (isForwardingReference(QualType(ParamRefType, 0), FirstInnerIndex) &&
-Arg->isLValue())
+Arg->isLValue()) {
+  if (S.getLangOpts().OpenCL)
+ArgType = S.Context.getAddrSpaceQualType(ArgType, 
LangAS::opencl_generic);
   ArgType = S.Context.getLValueReferenceType(ArgType);
+}
   } else {
 // C++ [temp.deduct.call]p2:
 //   If P is not a reference type:


Index: clang/test/SemaOpenCLCXX/address-space-templates.cl
===
--- clang/test/SemaOpenCLCXX/address-space-templates.cl
+++ clang/test/SemaOpenCLCXX/address-space-templates.cl
@@ -22,10 +22,28 @@
   __private T ii; // expected-error{{conflicting address space qualifiers are provided between types '__private T' and '__global int'}}
 }
 
+template  struct remove_reference { typedef _Tp type; };
+template  struct remove_reference<_Tp &>  { typedef _Tp type; };
+template  struct as_pointer {
+typedef typename remove_reference<_Tp>::type* type;
+};
+
+struct rep {
+  // CHECK |-CXXConstructorDecl {{.*}} rep 'void (const __generic rep &__private) __generic'
+  template::type>
+  rep(U&& v) {}
+};
+
+struct rep_outer : private rep {
+  rep_outer()
+: rep(0) {}
+};
+
 void bar() {
   S sintgl; // expected-note{{in instantiation of template class 'S' requested here}}
 
   foo1<__local int>(1); // expected-error{{no matching function for call to 'foo1'}}
   foo2<__global int>(0);
   foo3<__global int>(); // expected-note{{in instantiation of function template specialization 'foo3<__global int>' requested here}}
+  rep_outer r;
 }
Index: clang/lib/Sema/SemaTemplateDeduction.cpp
===
--- clang/lib/Sema/SemaTemplateDeduction.cpp
+++ clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -3815,8 +3815,11 @@
 //   If P is a forwarding reference and the argument is an lvalue, the type
 //   "lvalue reference to A" is used in place of A for type deduction.
 if (isForwardingReference(QualType(ParamRefType, 0), FirstInnerIndex) &&
-Arg->isLValue())
+Arg->isLValue()) {
+  if (S.getLangOpts().OpenCL)
+ArgType = S.Context.getAddrSpaceQualType(ArgType, LangAS::opencl_generic);
   ArgType = S.Context.getLValueReferenceType(ArgType);
+}
   } else {
 // C++ [temp.deduct.call]p2:
 //   If P is not a reference type:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D81865: use string tables for static diagnostic descriptions

2020-07-27 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno added a comment.

Add some reviewers based on `git diff --name-only | xargs -n 1 git blame 
--porcelain | grep  "^author " | sort | uniq -c | sort -nr | head -30`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81865



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


[PATCH] D66035: [WebAssembly] WIP: Add support for reference types

2020-07-27 Thread Valentin Churavy via Phabricator via cfe-commits
vchuravy abandoned this revision.
vchuravy added a comment.

In D66035#2175839 , @pmatos wrote:

> I am interested in continuing this work  and have a patch in progress based 
> on the current available one here. Should I post the new patch here or under 
> a new bug?


Feel free to commandeer this revision


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66035



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


[PATCH] D66035: [WebAssembly] WIP: Add support for reference types

2020-07-27 Thread Paulo Matos via Phabricator via cfe-commits
pmatos added a comment.

In D66035#2175906 , @vchuravy wrote:

> In D66035#2175839 , @pmatos wrote:
>
> > I am interested in continuing this work  and have a patch in progress based 
> > on the current available one here. Should I post the new patch here or 
> > under a new bug?
>
>
> Feel free to commandeer this revision


Thanks. I will post something soon.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66035



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


[PATCH] D84658: [clang] Overload NamedDecl::printName to provide a user-friendly name for unnamed entities

2020-07-27 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

This seems like a strict improvement as well.  That said, there are two 
opportunities to clean up the code that I suggest evaluating.




Comment at: clang/lib/AST/Decl.cpp:2032
+  // additional complexity needed to prevent this is not worthwhile.
+  OS << (Policy.MSVCFormatting ? '`' : '(')
+ << (IsAnonymousStructOrUnion ? "anonymous" : "unnamed") << ' '

This pattern is happening a bunch too  Does it deserve some function?  
Perhaps a function that either takes Policy, or a member of Policy to get the 
formatting open-tick or close-tick?



Comment at: clang/lib/AST/Decl.cpp:2074
+  if (Policy.AnonymousTagLocations && !SuppressLocation) {
+PresumedLoc PLoc = 
Ctx.getSourceManager().getPresumedLoc(DD->getLocation());
+if (PLoc.isValid()) {

It seems this entire block can be pulled out of these two functions.  This is 
probably worth while?

It seems that in this function, it would be:

if (!SuppressLocation)
printLocation();

And in the other, just a call to PrintLocation().


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84658



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


[PATCH] D83961: [Analyzer] Fix bug report source locations in minimal output.

2020-07-27 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a comment.

From the beginning on in this patch I assumed that the location of the bug 
report should be the end of the bug path. But this is probably a wrong 
approach, specially if the bug report has uniqueing location. In that case the 
uniqueing location may be a better place for the bug report. Specially for 
resource leak it is not bad if the report is located at the allocation site 
(still there is a bug path that shows the full path and place of leak). So 
another approach can be to allow only bug equivalence classes where the reports 
have same locations. If this is not true the checker should be fixed that 
generates the reports.

The behavior with `RefLeakReport` is correct if the indicated location in 
minimal output mode should be the end of the bug path. Otherwise it is not 
correct, the report has a different location (allocation site) than the end of 
the path (return point) and we want to see this in minimal mode (or not?). 
Still there is problem, in text output mode the summary line indicates not the 
correct place but the end of the bug path:
before the patch:

  $ clang -cc1 -internal-isystem 
~/clang/llvm1/build/Debug/lib/clang/11.0.0/include -nostdsysteminc -analyze 
-analyzer-constraints=range -setup-static-analyzer 
-analyzer-checker=core,osx.cocoa.RetainCount -analyzer-store=region 
~/clang/llvm1/llvm-project/clang/test/Analysis/CGColorSpace.c
  ~/clang/llvm1/llvm-project/clang/test/Analysis/CGColorSpace.c:9:23: warning: 
Potential leak of an object stored into 'X' [osx.cocoa.RetainCount]
CGColorSpaceRef X = CGColorSpaceCreateDeviceRGB(); // 
expected-warning{{leak}}
^
  1 warning generated.
  
  $ clang -cc1 -internal-isystem 
~/clang/llvm1/build/Debug/lib/clang/11.0.0/include -nostdsysteminc -analyze 
-analyzer-constraints=range -setup-static-analyzer 
-analyzer-checker=core,osx.cocoa.RetainCount -analyzer-store=region 
~/clang/llvm1/llvm-project/clang/test/Analysis/CGColorSpace.c -analyzer-output 
text
  ~/clang/llvm1/llvm-project/clang/test/Analysis/CGColorSpace.c:11:1: warning: 
Potential leak of an object stored into 'X' [osx.cocoa.RetainCount]
  }
  ^
  ~/clang/llvm1/llvm-project/clang/test/Analysis/CGColorSpace.c:9:23: note: 
Call to function 'CGColorSpaceCreateDeviceRGB' returns a Core Foundation object 
of type 'CGColorSpaceRef' with a +1 retain count
CGColorSpaceRef X = CGColorSpaceCreateDeviceRGB(); // 
expected-warning{{leak}}
^
  ~/clang/llvm1/llvm-project/clang/test/Analysis/CGColorSpace.c:10:3: note: 
Reference count incremented. The object now has a +2 retain count
CGColorSpaceRetain(X);
^
  ~/clang/llvm1/llvm-project/clang/test/Analysis/CGColorSpace.c:11:1: note: 
Object leaked: object allocated and stored into 'X' is not referenced later in 
this execution path and has a retain count of +2
  }
  ^
  1 warning generated.

after the patch:

  $ clang -cc1 -internal-isystem 
~/clang/llvm1/build/Debug/lib/clang/11.0.0/include -nostdsysteminc -analyze 
-analyzer-constraints=range -setup-static-analyzer 
-analyzer-checker=core,osx.cocoa.RetainCount -analyzer-store=region 
~/clang/llvm1/llvm-project/clang/test/Analysis/CGColorSpace.c
  ~/clang/llvm1/llvm-project/clang/test/Analysis/CGColorSpace.c:11:1: warning: 
Potential leak of an object stored into 'X' [osx.cocoa.RetainCount]
  }
  ^
  1 warning generated.
  
  $ clang -cc1 -internal-isystem 
~/clang/llvm1/build/Debug/lib/clang/11.0.0/include -nostdsysteminc -analyze 
-analyzer-constraints=range -setup-static-analyzer 
-analyzer-checker=core,osx.cocoa.RetainCount -analyzer-store=region 
~/clang/llvm1/llvm-project/clang/test/Analysis/CGColorSpace.c -analyzer-output 
text
  ~/clang/llvm1/llvm-project/clang/test/Analysis/CGColorSpace.c:11:1: warning: 
Potential leak of an object stored into 'X' [osx.cocoa.RetainCount]
  }
  ^
  ~/clang/llvm1/llvm-project/clang/test/Analysis/CGColorSpace.c:9:23: note: 
Call to function 'CGColorSpaceCreateDeviceRGB' returns a Core Foundation object 
of type 'CGColorSpaceRef' with a +1 retain count
CGColorSpaceRef X = CGColorSpaceCreateDeviceRGB(); // 
expected-warning{{leak}}
^
  ~/clang/llvm1/llvm-project/clang/test/Analysis/CGColorSpace.c:10:3: note: 
Reference count incremented. The object now has a +2 retain count
CGColorSpaceRetain(X);
^
  ~/clang/llvm1/llvm-project/clang/test/Analysis/CGColorSpace.c:11:1: note: 
Object leaked: object allocated and stored into 'X' is not referenced later in 
this execution path and has a retain count of +2
  }
  ^
  1 warning generated.

So it should be clarified how this should work, have the end of the bug path or 
the "location" of the bug report as display location of the bug report.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83961



___

[PATCH] D84658: [clang] Overload NamedDecl::printName to provide a user-friendly name for unnamed entities

2020-07-27 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno marked 2 inline comments as done.
riccibruno added inline comments.



Comment at: clang/lib/AST/Decl.cpp:2032
+  // additional complexity needed to prevent this is not worthwhile.
+  OS << (Policy.MSVCFormatting ? '`' : '(')
+ << (IsAnonymousStructOrUnion ? "anonymous" : "unnamed") << ' '

erichkeane wrote:
> This pattern is happening a bunch too  Does it deserve some function?  
> Perhaps a function that either takes Policy, or a member of Policy to get the 
> formatting open-tick or close-tick?
Do you mean a member function of `PrintingPolicy`, something like `getOpenTick` 
and `getCloseTick`?



Comment at: clang/lib/AST/Decl.cpp:2074
+  if (Policy.AnonymousTagLocations && !SuppressLocation) {
+PresumedLoc PLoc = 
Ctx.getSourceManager().getPresumedLoc(DD->getLocation());
+if (PLoc.isValid()) {

erichkeane wrote:
> It seems this entire block can be pulled out of these two functions.  This is 
> probably worth while?
> 
> It seems that in this function, it would be:
> 
> if (!SuppressLocation)
> printLocation();
> 
> And in the other, just a call to PrintLocation().
Good point yes. I will do so.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84658



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


[PATCH] D84658: [clang] Overload NamedDecl::printName to provide a user-friendly name for unnamed entities

2020-07-27 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/AST/Decl.cpp:2032
+  // additional complexity needed to prevent this is not worthwhile.
+  OS << (Policy.MSVCFormatting ? '`' : '(')
+ << (IsAnonymousStructOrUnion ? "anonymous" : "unnamed") << ' '

riccibruno wrote:
> erichkeane wrote:
> > This pattern is happening a bunch too  Does it deserve some function?  
> > Perhaps a function that either takes Policy, or a member of Policy to get 
> > the formatting open-tick or close-tick?
> Do you mean a member function of `PrintingPolicy`, something like 
> `getOpenTick` and `getCloseTick`?
Yeah, exactly, something like that. "Delimiter" is perhaps better than 'tick', 
but I'm not attached to either.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84658



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


[PATCH] D84658: [clang] Overload NamedDecl::printName to provide a user-friendly name for unnamed entities

2020-07-27 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno marked an inline comment as done.
riccibruno added inline comments.



Comment at: clang/lib/AST/Decl.cpp:2032
+  // additional complexity needed to prevent this is not worthwhile.
+  OS << (Policy.MSVCFormatting ? '`' : '(')
+ << (IsAnonymousStructOrUnion ? "anonymous" : "unnamed") << ' '

erichkeane wrote:
> riccibruno wrote:
> > erichkeane wrote:
> > > This pattern is happening a bunch too  Does it deserve some function? 
> > >  Perhaps a function that either takes Policy, or a member of Policy to 
> > > get the formatting open-tick or close-tick?
> > Do you mean a member function of `PrintingPolicy`, something like 
> > `getOpenTick` and `getCloseTick`?
> Yeah, exactly, something like that. "Delimiter" is perhaps better than 
> 'tick', but I'm not attached to either.
"Delimiter" sounds good to me. Thanks for the suggestion!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84658



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


[PATCH] D84534: [AIX] Static init frontend recovery and backend support

2020-07-27 Thread Jason Liu via Phabricator via cfe-commits
jasonliu added inline comments.



Comment at: clang/lib/CodeGen/ItaniumCXXABI.cpp:4609
+// their own llvm.global_dtors entry.
+CGM.AddCXXStermFinalizerToGlobalDtor(StermFinalizer, 65535);
+  else

Handling template instantiation seems fairly orthogonal to "moving naming logic 
from frontend to backend". Could we put it in a separate patch (which could be 
a child of this one)? 



Comment at: llvm/include/llvm/CodeGen/AsmPrinter.h:460
+  virtual void emitXXStructor(const DataLayout &DL, const int Priority,
+  const unsigned index, Constant *CV, bool isCtor) 
{
+llvm_unreachable("Emit CXXStructor with priority is target-specific.");

Remove `const` from value type (e.g. Priority and index), as there is no real 
need for it.



Comment at: llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp:2165
+  emitXXStructor(DL, S.Priority, index, S.Func, isCtor);
+  ++index;
+  continue;

Maybe a naive quesiton, in what situation would we have name collision and need 
`index` as suffix to differentiate?
Could we just report_fatal_error in those situation?



Comment at: llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp:1848
+// beforing emitting them.
+if (isSpecialLLVMGlobalArrayForStaticInit(&G)) {
+  if (GlobalUniqueModuleId.empty()) {

This would have conflict with D84363. You might want to rebase it later. 



Comment at: llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp:1935
+  Function *Func = cast(CV);
+  Func->setLinkage(GlobalValue::ExternalLinkage);
+  Func->setName((isCtor ? llvm::Twine("__sinit") : llvm::Twine("__sterm")) +

Changing Function name and linkage underneath looks a bit scary. People would 
have a hard time to map IR to final assembly that gets produced. Have you 
thought about creating an alias (with the correct linkage and name) to the 
original function instead?


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

https://reviews.llvm.org/D84534



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


[PATCH] D81865: [clang] Use string tables for static diagnostic descriptions

2020-07-27 Thread Benjamin Kramer via Phabricator via cfe-commits
bkramer accepted this revision.
bkramer added a comment.
This revision is now accepted and ready to land.

Nice, those relocations have annoyed me for years. I'm worried about whether 
the way you're accessing StaticDiagInfoDescriptionStringTable might be 
undefined behavior. I won't block this change on that though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81865



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


[PATCH] D84554: Use INTERFACE_COMPILE_OPTIONS to disable -Wsuggest-override for any target that links to gtest

2020-07-27 Thread Logan Smith via Phabricator via cfe-commits
logan-5 added a comment.

In D84554#2175012 , @labath wrote:

> Could you elaborate on the lldb issue? I'd like to take a look at that...


It looks like lldb/unittests/TestingSupport/CMakeLists.txt and 
lldb/unittests/TestingSupport/Symbol/CMakeLists.txt both both manually pull in 
the googletest/googlemock headers via `include_directories`. It also seems, 
although I'm not sure, like they don't themselves link to gtest, since simply 
removing those `include_directories` didn't work.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84554



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


[PATCH] D83501: [clangd][ObjC] Improve xrefs for protocols and classes

2020-07-27 Thread David Goldman via Phabricator via cfe-commits
dgoldman added a comment.

In D83501#2173534 , @sammccall wrote:

> (Sorry this has been pending a while - I think it's basically there. Only 
> things we really need to address to land this is have a consistent view of 
> what the canonical decl is for the no-@interface case, and avoid too much 
> duplication of mechanisms in the tests)


No problem, thanks for the review




Comment at: clang-tools-extra/clangd/unittests/FindTargetTests.cpp:696
+  )cpp";
+  EXPECT_DECLS("ObjCImplementationDecl", "@interface Implicit");
+

sammccall wrote:
> Hmm, do we want to use the @interface or @implementation for this case? The 
> interface is implicit but probably still has a valid location.
> Currently symbolcollector and findtarget do different things...
Good catch, don't think this is a common case but yeah I think the impl makes 
more sense then. swapped over



Comment at: clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp:614
+
+TEST_F(SymbolCollectorTest, ObjCClassExtensions) {
+  Annotations Header(R"(

sammccall wrote:
> dgoldman wrote:
> > Here's the ClassExtension that I was talking about.
> > 
> > Ideally we can map each
> > 
> > `Cat ()` --> `@implementation Cat` like I did in XRefs
> > 
> > But as you said the `Cat ()` could be in a different file and I think it 
> > has a different USR.
> > 
> > See also 
> > https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/CustomizingExistingClasses/CustomizingExistingClasses.html#//apple_ref/doc/uid/TP40011210-CH6-SW3
> > Ideally we can map each
> > Cat () --> @implementation Cat like I did in XRefs
> 
> I'm not sure there's anything that would ideally be done differently here.
> The logic in xrefs is a special "go-to-definition" action - there's some 
> ambiguity about what's being *targeted* by the user. But here there's no 
> targeting going on, and there's no ambiguity about what's being *declared*.
> 
> The thing to test would be that we're emitting *refs* from `@interface 
> [[Cat]] ()` to catdecl.
> 
Hmm, it looks like at the moment it either shares the same QName or doesn't 
have one. This might be good to look into a follow up patch?



Comment at: clang-tools-extra/clangd/unittests/XRefsTests.cpp:803
+  };
+  for (const char *Test : Tests) {
+Annotations T(Test);

sammccall wrote:
> this seems to be copy/pasted from the test above.
> Is there a reason this can't be part of the test above?
I could merge them but I figured it would be better to separate tests with 
multi def/decls from those with just one. WDYT?



Comment at: clang-tools-extra/clangd/unittests/XRefsTests.cpp:838
+
+TEST(LocateSymbol, MultipleDeclsWithSameDefinition) {
+  // Ranges in tests:

sammccall wrote:
> and again here
> 
> Desire to split these tables up into named tests is something we want to 
> address somehow, but we don't have a good answer right now and it's important 
> for maintenance that the logic/annotation conventions don't diverge across 
> different tests that could be the same.
This one is split because you can't annotate one symbol with multiple 
annotations. I can instead make this a regular non generic test like the 
following, WDYT?

  @interface $interfacedecl[[Cat]]
  @end
  @interface $classextensiondecl[[Ca^t]] ()
  - (void)meow;
  @end
  @implementation $implementationdecl[[Cat]]
  - (void)meow {}
  @end


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83501



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


[PATCH] D83501: [clangd][ObjC] Improve xrefs for protocols and classes

2020-07-27 Thread David Goldman via Phabricator via cfe-commits
dgoldman updated this revision to Diff 280930.
dgoldman marked 7 inline comments as done.
dgoldman added a comment.

- More fixes for review


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83501

Files:
  clang-tools-extra/clangd/FindTarget.cpp
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang-tools-extra/clangd/unittests/FindTargetTests.cpp
  clang-tools-extra/clangd/unittests/SymbolCollectorTests.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
@@ -674,7 +674,57 @@
   enum class E { [[A]], B };
   E e = E::A^;
 };
-  )cpp"};
+  )cpp",
+
+  R"objc(
+@protocol Dog;
+@protocol $decl[[Dog]]
+- (void)bark;
+@end
+id getDoggo() {
+  return 0;
+}
+  )objc",
+
+  R"objc(
+@interface Cat
+@end
+@implementation Cat
+@end
+@interface $decl[[Cat]] (Exte^nsion)
+- (void)meow;
+@end
+@implementation $def[[Cat]] (Extension)
+- (void)meow {}
+@end
+  )objc",
+
+  R"objc(
+@class $decl[[Foo]];
+Fo^o * getFoo() {
+  return 0;
+}
+  )objc",
+
+  R"objc(// Prefer interface definition over forward declaration
+@class Foo;
+@interface $decl[[Foo]]
+@end
+Fo^o * getFoo() {
+  return 0;
+}
+  )objc",
+
+  R"objc(
+@class Foo;
+@interface $decl[[Foo]]
+@end
+@implementation $def[[Foo]]
+@end
+Fo^o * getFoo() {
+  return 0;
+}
+  )objc"};
   for (const char *Test : Tests) {
 Annotations T(Test);
 llvm::Optional WantDecl;
@@ -692,6 +742,7 @@
 // FIXME: Auto-completion in a template requires disabling delayed template
 // parsing.
 TU.ExtraArgs.push_back("-fno-delayed-template-parsing");
+TU.ExtraArgs.push_back("-xobjective-c++");
 
 auto AST = TU.build();
 auto Results = locateSymbolAt(AST, T.point());
@@ -709,6 +760,131 @@
   }
 }
 
+TEST(LocateSymbol, AllMulti) {
+  // Ranges in tests:
+  //   $declN is the declaration location
+  //   $defN is the definition location (if absent, symbol has no definition)
+  //
+  // NOTE:
+  //   N starts at 0.
+  //   Due to limitations in clang's Annotations, you can't annotate the same
+  //   text with multiple ranges, e.g. `$def0$def1[[Foo]]` is invalid.
+  struct ExpectedRanges {
+Range WantDecl;
+llvm::Optional WantDef;
+  };
+  const char *Tests[] = {
+  R"objc(
+  @interface $decl0[[Cat]]
+  @end
+  @implementation $def0[[Cat]]
+  @end
+  @interface $decl1[[Ca^t]] (Extension)
+  - (void)meow;
+  @end
+  @implementation $def1[[Cat]] (Extension)
+  - (void)meow {}
+  @end
+)objc",
+
+  R"objc(
+  @interface $decl0[[Cat]]
+  @end
+  @implementation $def0[[Cat]]
+  @end
+  @interface $decl1[[Cat]] (Extension)
+  - (void)meow;
+  @end
+  @implementation $def1[[Ca^t]] (Extension)
+  - (void)meow {}
+  @end
+)objc",
+  };
+  for (const char *Test : Tests) {
+Annotations T(Test);
+std::vector Ranges;
+for (int Idx = 0; true; Idx++) {
+  bool HasDecl = !T.ranges("decl" + std::to_string(Idx)).empty();
+  bool HasDef = !T.ranges("def" + std::to_string(Idx)).empty();
+  if (!HasDecl && !HasDef)
+break;
+  ExpectedRanges Range;
+  if (HasDecl)
+Range.WantDecl = T.range("decl" + std::to_string(Idx));
+  if (HasDef)
+Range.WantDef = T.range("def" + std::to_string(Idx));
+  Ranges.push_back(Range);
+}
+
+TestTU TU;
+TU.Code = std::string(T.code());
+TU.ExtraArgs.push_back("-xobjective-c++");
+
+auto AST = TU.build();
+auto Results = locateSymbolAt(AST, T.point());
+
+ASSERT_THAT(Results, ::testing::SizeIs(Ranges.size())) << Test;
+for (size_t Idx = 0; Idx < Ranges.size(); Idx++) {
+  EXPECT_EQ(Results[Idx].PreferredDeclaration.range, Ranges[Idx].WantDecl)
+  << "($decl" << Idx << ")" << Test;
+  llvm::Optional GotDef;
+  if (Results[Idx].Definition)
+GotDef = Results[Idx].Definition->range;
+  EXPECT_EQ(GotDef, Ranges[Idx].WantDef) << "($def" << Idx << ")" << Test;
+}
+  }
+}
+
+TEST(LocateSymbol, MultipleDeclsWithSameDefinition) {
+  // Ranges in tests:
+  //   $def is the shared definition location
+  //   $declN is one of the declaration locations
+  //
+  // NOTE:
+  //   N starts at 0.
+  const char *Tests[] = {
+  R"objc(
+  @interface $decl0[[Cat]]
+  @end
+  @interface $decl1[[Ca^t]] ()
+  - (void)m

[PATCH] D84666: [NFC] Sema: use checkArgCount instead of custom checking

2020-07-27 Thread JF Bastien via Phabricator via cfe-commits
jfb created this revision.
jfb added a reviewer: rsmith.
Herald added subscribers: cfe-commits, ributzka, dexonsmith, jkorous, kbarton, 
nemanjai.
Herald added a project: clang.

As requested in D79279 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D84666

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins-ppc-error.c
  clang/test/SemaOpenCL/to_addr_builtin.cl

Index: clang/test/SemaOpenCL/to_addr_builtin.cl
===
--- clang/test/SemaOpenCL/to_addr_builtin.cl
+++ clang/test/SemaOpenCL/to_addr_builtin.cl
@@ -15,7 +15,7 @@
   // expected-error@-2{{implicit declaration of function 'to_global' is invalid in OpenCL}}
   // expected-warning@-3{{incompatible integer to pointer conversion assigning to '__global int *__private' from 'int'}}
 #else
-  // expected-error@-5{{invalid number of arguments to function: 'to_global'}}
+  // expected-error@-5{{too many arguments to function call, expected 1, have 2}}
 #endif
 
   int x;
Index: clang/test/CodeGen/builtins-ppc-error.c
===
--- clang/test/CodeGen/builtins-ppc-error.c
+++ clang/test/CodeGen/builtins-ppc-error.c
@@ -32,16 +32,16 @@
 }
 
 void testXXPERMDI(int index) {
-  vec_xxpermdi(vsi); //expected-error {{too few arguments to function call, expected at least 3, have 1}}
-  vec_xxpermdi(vsi, vsi, 2, 4); //expected-error {{too many arguments to function call, expected at most 3, have 4}}
+  vec_xxpermdi(vsi); //expected-error {{too few arguments to function call, expected 3, have 1}}
+  vec_xxpermdi(vsi, vsi, 2, 4); //expected-error {{too many arguments to function call, expected 3, have 4}}
   vec_xxpermdi(vsi, vsi, index); //expected-error {{argument 3 to '__builtin_vsx_xxpermdi' must be a 2-bit unsigned literal (i.e. 0, 1, 2 or 3)}}
   vec_xxpermdi(1, 2, 3); //expected-error {{first two arguments to '__builtin_vsx_xxpermdi' must be vectors}}
   vec_xxpermdi(vsi, vuc, 2); //expected-error {{first two arguments to '__builtin_vsx_xxpermdi' must have the same type}}
 }
 
 void testXXSLDWI(int index) {
-  vec_xxsldwi(vsi); //expected-error {{too few arguments to function call, expected at least 3, have 1}}
-  vec_xxsldwi(vsi, vsi, 2, 4); //expected-error {{too many arguments to function call, expected at most 3, have 4}}
+  vec_xxsldwi(vsi); //expected-error {{too few arguments to function call, expected 3, have 1}}
+  vec_xxsldwi(vsi, vsi, 2, 4); //expected-error {{too many arguments to function call, expected 3, have 4}}
   vec_xxsldwi(vsi, vsi, index); //expected-error {{argument 3 to '__builtin_vsx_xxsldwi' must be a 2-bit unsigned literal (i.e. 0, 1, 2 or 3)}}
   vec_xxsldwi(1, 2, 3); //expected-error {{first two arguments to '__builtin_vsx_xxsldwi' must be vectors}}
   vec_xxsldwi(vsi, vuc, 2); //expected-error {{first two arguments to '__builtin_vsx_xxsldwi' must have the same type}}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -1274,11 +1274,8 @@
 // \return True if a semantic error has been found, false otherwise.
 static bool SemaOpenCLBuiltinToAddr(Sema &S, unsigned BuiltinID,
 CallExpr *Call) {
-  if (Call->getNumArgs() != 1) {
-S.Diag(Call->getBeginLoc(), diag::err_opencl_builtin_to_addr_arg_num)
-<< Call->getDirectCallee() << Call->getSourceRange();
+  if (checkArgCount(S, Call, 1))
 return true;
-  }
 
   auto RT = Call->getArg(0)->getType();
   if (!RT->isPointerType() || RT->getPointeeType()
@@ -5572,21 +5569,8 @@
   if (checkVAStartABI(*this, BuiltinID, Fn))
 return true;
 
-  if (TheCall->getNumArgs() > 2) {
-Diag(TheCall->getArg(2)->getBeginLoc(),
- diag::err_typecheck_call_too_many_args)
-<< 0 /*function call*/ << 2 << TheCall->getNumArgs()
-<< Fn->getSourceRange()
-<< SourceRange(TheCall->getArg(2)->getBeginLoc(),
-   (*(TheCall->arg_end() - 1))->getEndLoc());
+  if (checkArgCount(*this, TheCall, 2))
 return true;
-  }
-
-  if (TheCall->getNumArgs() < 2) {
-return Diag(TheCall->getEndLoc(),
-diag::err_typecheck_call_too_few_args_at_least)
-   << 0 /*function call*/ << 2 << TheCall->getNumArgs();
-  }
 
   // Type-check the first argument normally.
   if (checkBuiltinArgument(*this, TheCall, 0))
@@ -5696,15 +5680,8 @@
 /// SemaBuiltinUnorderedCompare - Handle functions like __builtin_isgreater and
 /// friends.  This is declared to take (...), so we have to check everything.
 bool Sema::SemaBuiltinUnorderedCompare(CallExpr *TheCall) {
-  if (TheCall->getNumArgs() < 2)
-return Diag(TheCall->getEndLoc(), diag::err_typecheck_call_too_few_args)
-   << 0 << 2 << TheCall->getNumArgs() /*function call*/;
-  if (TheCall

  1   2   3   >