[PATCH] D89785: [clangd] Add basic support for attributes (selection, hover)

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



Comment at: clang-tools-extra/clangd/AST.cpp:434
+for (AttributedTypeLoc ATL = *ATLPtr; !ATL.isNull();
+ ATL = ATL.getNextTypeLoc().getAs())
+  Result.push_back(ATL.getAttr());

this looks like not safe, `getNextTypeLoc()` may return a null TypeLoc.



Comment at: clang-tools-extra/clangd/unittests/ASTTests.cpp:233
+  };
+  ASSERT_THAT(DeclAttrs("X"), Each(implicitAttr()));
+  ASSERT_THAT(DeclAttrs("Y"), Contains(attrKind(attr::WarnUnusedResult)));

sorry, I'm not familiar with attributes, what is an implicit attr? It is 
unclear to me why there is an attr for `class X`, the source code doesn't have 
any attribute label for X (the same question for f and a)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89785

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


[PATCH] D89972: Add pipeline model for HiSilicon's TSV110

2020-10-23 Thread Elvina Yakubova via Phabricator via cfe-commits
Elvina added a comment.

Failure on test "linux > HWAddressSanitizer-x86_64.TestCases::sizes.cpp" looks 
bogus. I found the same cases https://reviews.llvm.org/D89895 and 
https://reviews.llvm.org/D89964.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89972

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


[PATCH] D89785: [clangd] Add basic support for attributes (selection, hover)

2020-10-23 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 300182.
sammccall added a comment.

Add comment+assert to clarify


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89785

Files:
  clang-tools-extra/clangd/AST.cpp
  clang-tools-extra/clangd/AST.h
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/Selection.cpp
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/unittests/ASTTests.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang-tools-extra/clangd/unittests/SelectionTests.cpp

Index: clang-tools-extra/clangd/unittests/SelectionTests.cpp
===
--- clang-tools-extra/clangd/unittests/SelectionTests.cpp
+++ clang-tools-extra/clangd/unittests/SelectionTests.cpp
@@ -415,7 +415,19 @@
 template  class Container> class A {};
 A<[[V^ector]]> a;
   )cpp",
-   "TemplateArgumentLoc"}};
+   "TemplateArgumentLoc"},
+
+  // Attributes
+  {R"cpp(
+void f(int * __attribute__(([[no^nnull]])) );
+  )cpp",
+   "NonNullAttr"},
+
+  {R"cpp(
+// Digraph syntax for attributes to avoid accidental annotations.
+class <:[gsl::Owner([[in^t]])]:> X{};
+  )cpp",
+   "BuiltinTypeLoc"}};
 
   for (const Case &C : Cases) {
 trace::TestTracer Tracer;
Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -1991,6 +1991,16 @@
 HI.NamespaceScope = "ObjC::"; // FIXME: fix it
 HI.Definition = "char data";
   }},
+  {
+  R"cpp(
+   void foo(int * __attribute__(([[non^null]], noescape)) );
+  )cpp",
+  [](HoverInfo &HI) {
+HI.Name = "nonnull";
+HI.Kind = index::SymbolKind::Unknown; // FIXME: no suitable value
+HI.Definition = "__attribute__((nonnull()))";
+HI.Documentation = ""; // FIXME
+  }},
   };
 
   // Create a tiny index, so tests above can verify documentation is fetched.
Index: clang-tools-extra/clangd/unittests/ASTTests.cpp
===
--- clang-tools-extra/clangd/unittests/ASTTests.cpp
+++ clang-tools-extra/clangd/unittests/ASTTests.cpp
@@ -11,8 +11,11 @@
 #include "Annotations.h"
 #include "ParsedAST.h"
 #include "TestTU.h"
+#include "clang/AST/ASTTypeTraits.h"
+#include "clang/AST/Attr.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclBase.h"
+#include "clang/Basic/AttrKinds.h"
 #include "clang/Basic/SourceManager.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Casting.h"
@@ -25,6 +28,8 @@
 namespace clang {
 namespace clangd {
 namespace {
+using testing::Contains;
+using testing::Each;
 
 TEST(GetDeducedType, KwAutoExpansion) {
   struct Test {
@@ -206,6 +211,39 @@
 }
   }
 }
+
+MATCHER_P(attrKind, K, "") { return arg->getKind() == K; }
+
+MATCHER(implicitAttr, "") { return arg->isImplicit(); }
+
+TEST(ClangdAST, GetAttributes) {
+  const char *Code = R"cpp(
+class X{};
+class [[nodiscard]] Y{};
+void f(int * a, int * __attribute__((nonnull)) b);
+void foo(bool c) {
+  if (c)
+[[unlikely]] return;
+}
+  )cpp";
+  ParsedAST AST = TestTU::withCode(Code).build();
+  auto DeclAttrs = [&](llvm::StringRef Name) {
+return getAttributes(DynTypedNode::create(findUnqualifiedDecl(AST, Name)));
+  };
+  // Implicit attributes may be present (e.g. visibility on windows).
+  ASSERT_THAT(DeclAttrs("X"), Each(implicitAttr()));
+  ASSERT_THAT(DeclAttrs("Y"), Contains(attrKind(attr::WarnUnusedResult)));
+  ASSERT_THAT(DeclAttrs("f"), Each(implicitAttr()));
+  ASSERT_THAT(DeclAttrs("a"), Each(implicitAttr()));
+  ASSERT_THAT(DeclAttrs("b"), Contains(attrKind(attr::NonNull)));
+
+  Stmt *FooBody = cast(findDecl(AST, "foo")).getBody();
+  IfStmt *FooIf = cast(cast(FooBody)->body_front());
+  ASSERT_THAT(getAttributes(DynTypedNode::create(*FooIf)),
+  Each(implicitAttr()));
+  ASSERT_THAT(getAttributes(DynTypedNode::create(*FooIf->getThen())),
+  Contains(attrKind(attr::Unlikely)));
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -182,6 +182,12 @@
   ST.commonAncestor()) {
 if (NodeKind)
   *NodeKind = N->ASTNode.getNodeKind();
+// Attributes don't target decls, look at the
+// thing it's attached to.
+// We still report the original NodeKind!
+ 

[PATCH] D89785: [clangd] Add basic support for attributes (selection, hover)

2020-10-23 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/AST.cpp:434
+for (AttributedTypeLoc ATL = *ATLPtr; !ATL.isNull();
+ ATL = ATL.getNextTypeLoc().getAs())
+  Result.push_back(ATL.getAttr());

hokein wrote:
> this looks like not safe, `getNextTypeLoc()` may return a null TypeLoc.
I don't think it can - an AttributedType always modifies a real type.
I've added an assert.



Comment at: clang-tools-extra/clangd/unittests/ASTTests.cpp:233
+  };
+  ASSERT_THAT(DeclAttrs("X"), Each(implicitAttr()));
+  ASSERT_THAT(DeclAttrs("Y"), Contains(attrKind(attr::WarnUnusedResult)));

hokein wrote:
> sorry, I'm not familiar with attributes, what is an implicit attr? It is 
> unclear to me why there is an attr for `class X`, the source code doesn't 
> have any attribute label for X (the same question for f and a)
Right, implicit attributes are when there's nothing written in the source ,but 
something else modifies the semantics in a way that clang authors decided to 
model as an attribute (e.g. because semantics match that of an explicit 
attribute).

I'm not familiar with many examples either, but a couple:
- when targeting windows, top-level classes appear to have an implicit "type 
visibility" attribute that I guess models the difference between default 
unix/windows symbol visibility.
- Aaron Ballman gave an example of `[[interrupt(...)]]` which also adds an 
implicit `[[used]]` attribute.

The windows example was why I assert there are no explicit attributes, instead 
of that there are none at all. I've added a comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89785

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


[PATCH] D88553: [clangd] Start using SyntaxTrees for folding ranges feature

2020-10-23 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/SemanticSelection.cpp:40
 
-// Recursively collects FoldingRange from a symbol and its children.
-void collectFoldingRanges(DocumentSymbol Symbol,
-  std::vector &Result) {
+llvm::Optional toFoldingRange(SourceRange SR,
+const SourceManager &SM) {

Here you're looking at positions but ignoring file ID, which is always a reason 
to be cautious...

We've dropped macro IDs, and we're traversing only the syntax tree for this 
file, but we could still end up in the wrong file:
```
void foo() {
  #include "SomeTablegen.inc"
}
```

We need to verify both start/end are in the main file.

I'd suggest passing in the main FileID as a param here, and decomposing the 
start/end locations into (FileID, Offset), and bailing out if either FID 
doesn't match.
This subsumes the macro check (since macro expansions have their own FileIDs) 
though you might want to keep it to be explicit, as we likely want to support 
some cases later.

As a bonus, then you get to use SourceManager::get{Line,Column}Number(FileID, 
Offset) instead of the "spelling" variants that are slightly confusing as we've 
already established we have a file location already.



Comment at: clang-tools-extra/clangd/SemanticSelection.cpp:60
+   *RBrace = cast_or_null(
+   Stmt->findChild(syntax::NodeRole::CloseParen));
+if (!LBrace || !RBrace)

strictly this should probably be findLastChild both semantically and for 
performance... but that doesn't exist, because it's a single-linked list for 
now.

Not a big deal in practice, but we should fix this (and add STL iterators!)



Comment at: clang-tools-extra/clangd/SemanticSelection.cpp:158
+  const auto *SyntaxTree =
+  syntax::buildSyntaxTree(A, 
*AST.getASTContext().getTranslationUnitDecl());
+  return collectFoldingRanges(SyntaxTree, AST.getSourceManager());

this actually does the right thing (traverses the ASTContext's registered roots 
rather than the TUDecl itself), but... what a misleading API. We should fix 
that to take ASTContext instead...

(Not in this patch, maybe a followup?)



Comment at: clang/include/clang/Tooling/Syntax/Tree.h:175
+  const Node *findChild(NodeRole R) const {
+return const_cast(this)->findChild(R);
+  }

I think it's more conventional to implement the const variant and use 
const_cast for the non-const variant, so the compiler will verify that the 
function implementation is const, and the cast is just adding "I know if I'm 
not const then the returned object isn't either".

By implementing the *non-const* variant, the compiler doesn't help you verify 
any part of the const contract.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88553

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


[PATCH] D89946: [clang] Suppress "follow-up" diagnostics on recovery call expressions.

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



Comment at: clang/lib/Sema/SemaOverload.cpp:12814
   // end up here.
   return SemaRef.BuildCallExpr(/*Scope*/ nullptr, NewFn.get(), LParenLoc,
MultiExprArg(Args.data(), Args.size()),

sammccall wrote:
> This results in (IIUC):
> 
> ```
> CallExpr
> >RecoveryExpr (indirection we inserted)
> >>DeclRefExpr (callee)
> >Arg1
> ```
> 
> Whereas when overload resolution fails, we create:
> ```
> RecoveryExpr (call)
> > OverloadExpr (callee)
> > Arg1
> ```
> 
> I can see advantages for either, but is there a reason not to be consistent?
> (Which I guess means emitting the first one here)
> (Which I guess means emitting the first one here)

yes, exactly. 

reasons:
- BuildCallExpr could emit diagnostics if we pass a non-dependent callee to it, 
this is something we want to avoid;
- we'd save some cost -- `BuildCallExpr` has dedicated code path to handle 
dependent expr; 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89946

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


[PATCH] D89946: [clang] Suppress "follow-up" diagnostics on recovery call expressions.

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

address comments and add AST tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89946

Files:
  clang/lib/Sema/SemaOverload.cpp
  clang/test/AST/ast-dump-recovery.cpp
  clang/test/CXX/basic/basic.lookup/basic.lookup.argdep/p4.cpp
  clang/test/Modules/submodules-merge-defs.cpp
  clang/test/SemaCXX/enable_if.cpp
  clang/test/SemaCXX/typo-correction-delayed.cpp

Index: clang/test/SemaCXX/typo-correction-delayed.cpp
===
--- clang/test/SemaCXX/typo-correction-delayed.cpp
+++ clang/test/SemaCXX/typo-correction-delayed.cpp
@@ -209,6 +209,15 @@
 // expected-error-re@-1 {{use of undeclared identifier 'N'{{$
 }
 
+namespace noSecondaryDiags {
+void abcc(); // expected-note {{'abcc' declared here}}
+
+void test() {
+  // Verify the secondary diagnostic ".. convertiable to 'bool'" is suppressed.
+  if (abc()) {} // expected-error {{use of undeclared identifier 'abc'; did you mean 'abcc'?}}
+}
+}
+
 // PR 23285. This test must be at the end of the file to avoid additional,
 // unwanted diagnostics.
 // expected-error-re@+2 {{use of undeclared identifier 'uintmax_t'{{$
Index: clang/test/SemaCXX/enable_if.cpp
===
--- clang/test/SemaCXX/enable_if.cpp
+++ clang/test/SemaCXX/enable_if.cpp
@@ -356,9 +356,9 @@
   __attribute__((enable_if(num != 1, "")));
 }  // namespace ns
 
-using ns::Function; // expected-note 3{{declared here}}
+using ns::Function; // expected-note 2{{declared here}}
 void Run() {
-  Functioon(0); // expected-error{{use of undeclared identifier}} expected-error{{too few arguments}}
+  Functioon(0); // expected-error{{use of undeclared identifier}}
   Functioon(0, 1); // expected-error{{use of undeclared identifier}}
   Functioon(0, 1, 2); // expected-error{{use of undeclared identifier}}
 }
Index: clang/test/Modules/submodules-merge-defs.cpp
===
--- clang/test/Modules/submodules-merge-defs.cpp
+++ clang/test/Modules/submodules-merge-defs.cpp
@@ -18,7 +18,7 @@
 // expected-error-re@-1 {{missing '#include "{{.*}}-defs.h"'; 'A' must be declared}}
 // expected-note@defs.h:1 +{{here}}
 extern class A pre_a2;
-int pre_use_a = use_a(pre_a2); // expected-error 2{{'A' must be defined}} expected-error {{'use_a' must be declared}}
+int pre_use_a = use_a(pre_a2); // expected-error {{'use_a' must be declared}}
 // expected-note@defs.h:2 +{{here}}
 
 B::Inner2 pre_bi; // expected-error +{{must be declared}} expected-error +{{must be defined}}
Index: clang/test/CXX/basic/basic.lookup/basic.lookup.argdep/p4.cpp
===
--- clang/test/CXX/basic/basic.lookup/basic.lookup.argdep/p4.cpp
+++ clang/test/CXX/basic/basic.lookup/basic.lookup.argdep/p4.cpp
@@ -21,12 +21,10 @@
 }
 
 namespace C {
-  class C {}; // expected-note {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'B::B' to 'const C::C &' for 1st argument}}
+  class C {};
 #if __cplusplus >= 201103L // C++11 or later
-  // expected-note@-2 {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'B::B' to 'C::C &&' for 1st argument}}
 #endif
-  void func(C); // expected-note {{'C::func' declared here}} \
-// expected-note {{passing argument to parameter here}}
+  void func(C); // expected-note {{'C::func' declared here}}
   C operator+(C,C);
   D::D operator+(D::D,D::D);
 }
@@ -38,13 +36,7 @@
 namespace Test {
   void test() {
 func(A::A());
-// FIXME: namespace-aware typo correction causes an extra, misleading
-// message in this case; some form of backtracking, diagnostic message
-// delaying, or argument checking before emitting diagnostics is needed to
-// avoid accepting and printing out a typo correction that proves to be
-// incorrect once argument-dependent lookup resolution has occurred.
-func(B::B()); // expected-error {{use of undeclared identifier 'func'; did you mean 'C::func'?}} \
-  // expected-error {{no viable conversion from 'B::B' to 'C::C'}}
+func(B::B()); // expected-error {{use of undeclared identifier 'func'; did you mean 'C::func'?}}
 func(C::C());
 A::A() + A::A();
 B::B() + B::B();
Index: clang/test/AST/ast-dump-recovery.cpp
===
--- clang/test/AST/ast-dump-recovery.cpp
+++ clang/test/AST/ast-dump-recovery.cpp
@@ -271,3 +271,11 @@
   // CHECK-NEXT: `-IntegerLiteral {{.*}} 'int' 2
   invalid() ? 1 : 2;
 }
+
+void abcc();
+void TypoCorrection() {
+  // CHECK:  CallExpr {{.*}} '' contains-errors
+  // CHECK-NEXT: `-RecoveryExpr {{.*}}
+  // CHECK-NEXT:   `-DeclRefExpr {{.*}} 'a

[PATCH] D89785: [clangd] Add basic support for attributes (selection, hover)

2020-10-23 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clangd/unittests/ASTTests.cpp:233
+  };
+  ASSERT_THAT(DeclAttrs("X"), Each(implicitAttr()));
+  ASSERT_THAT(DeclAttrs("Y"), Contains(attrKind(attr::WarnUnusedResult)));

sammccall wrote:
> hokein wrote:
> > sorry, I'm not familiar with attributes, what is an implicit attr? It is 
> > unclear to me why there is an attr for `class X`, the source code doesn't 
> > have any attribute label for X (the same question for f and a)
> Right, implicit attributes are when there's nothing written in the source 
> ,but something else modifies the semantics in a way that clang authors 
> decided to model as an attribute (e.g. because semantics match that of an 
> explicit attribute).
> 
> I'm not familiar with many examples either, but a couple:
> - when targeting windows, top-level classes appear to have an implicit "type 
> visibility" attribute that I guess models the difference between default 
> unix/windows symbol visibility.
> - Aaron Ballman gave an example of `[[interrupt(...)]]` which also adds an 
> implicit `[[used]]` attribute.
> 
> The windows example was why I assert there are no explicit attributes, 
> instead of that there are none at all. I've added a comment.
ah, thanks for the explanation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89785

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


[PATCH] D90009: [X86] VEX/EVEX prefix doesn't work for inline assembly.

2020-10-23 Thread LiuChen via Phabricator via cfe-commits
LiuChen3 updated this revision to Diff 300188.
LiuChen3 added a comment.

Address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90009

Files:
  clang/test/CodeGen/X86/att-inline-asm-prefix.c
  llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
  llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h
  llvm/lib/Target/X86/MCTargetDesc/X86InstPrinterCommon.cpp

Index: llvm/lib/Target/X86/MCTargetDesc/X86InstPrinterCommon.cpp
===
--- llvm/lib/Target/X86/MCTargetDesc/X86InstPrinterCommon.cpp
+++ llvm/lib/Target/X86/MCTargetDesc/X86InstPrinterCommon.cpp
@@ -346,6 +346,21 @@
 O << "\trepne\t";
   else if (Flags & X86::IP_HAS_REPEAT)
 O << "\trep\t";
+
+  // These all require a pseudo prefix
+  if (Flags & X86::IP_USE_VEX)
+O << "\t{vex}";
+  else if (Flags & X86::IP_USE_VEX2)
+O << "\t{vex2}";
+  else if (Flags & X86::IP_USE_VEX3)
+O << "\t{vex3}";
+  else if (Flags & X86::IP_USE_EVEX)
+O << "\t{evex}";
+
+  if (Flags & X86::IP_USE_DISP8)
+O << "\t{disp8}";
+  else if (Flags & X86::IP_USE_DISP32)
+O << "\t{disp32}";
 }
 
 void X86InstPrinterCommon::printVKPair(const MCInst *MI, unsigned OpNo,
Index: llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h
===
--- llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h
+++ llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h
@@ -55,15 +55,18 @@
   /// The constants to describe instr prefixes if there are
   enum IPREFIXES {
 IP_NO_PREFIX = 0,
-IP_HAS_OP_SIZE = 1,
-IP_HAS_AD_SIZE = 2,
-IP_HAS_REPEAT_NE = 4,
-IP_HAS_REPEAT = 8,
-IP_HAS_LOCK = 16,
-IP_HAS_NOTRACK = 32,
-IP_USE_VEX3 = 64,
-IP_USE_DISP8 = 128,
-IP_USE_DISP32 = 256,
+IP_HAS_OP_SIZE =   1U << 0,
+IP_HAS_AD_SIZE =   1U << 1,
+IP_HAS_REPEAT_NE = 1U << 2,
+IP_HAS_REPEAT =1U << 3,
+IP_HAS_LOCK =  1U << 4,
+IP_HAS_NOTRACK =   1U << 5,
+IP_USE_VEX =   1U << 6,
+IP_USE_VEX2 =  1U << 7,
+IP_USE_VEX3 =  1U << 8,
+IP_USE_EVEX =  1U << 9,
+IP_USE_DISP8 = 1U << 10,
+IP_USE_DISP32 =1U << 11,
   };
 
   enum OperandType : unsigned {
Index: llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
===
--- llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
+++ llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
@@ -83,6 +83,7 @@
   enum VEXEncoding {
 VEXEncoding_Default,
 VEXEncoding_VEX,
+VEXEncoding_VEX2,
 VEXEncoding_VEX3,
 VEXEncoding_EVEX,
   };
@@ -2818,8 +2819,10 @@
 return Error(Parser.getTok().getLoc(), "Expected '}'");
   Parser.Lex(); // Eat curly.
 
-  if (Prefix == "vex" || Prefix == "vex2")
+  if (Prefix == "vex")
 ForcedVEXEncoding = VEXEncoding_VEX;
+  else if (Prefix == "vex2")
+ForcedVEXEncoding = VEXEncoding_VEX2;
   else if (Prefix == "vex3")
 ForcedVEXEncoding = VEXEncoding_VEX3;
   else if (Prefix == "evex")
@@ -3837,6 +3840,7 @@
 return Match_Unsupported;
 
   if ((ForcedVEXEncoding == VEXEncoding_VEX ||
+   ForcedVEXEncoding == VEXEncoding_VEX2 ||
ForcedVEXEncoding == VEXEncoding_VEX3) &&
   (MCID.TSFlags & X86II::EncodingMask) != X86II::VEX)
 return Match_Unsupported;
@@ -3879,10 +3883,16 @@
 
   MCInst Inst;
 
-  // If VEX3 encoding is forced, we need to pass the USE_VEX3 flag to the
-  // encoder.
-  if (ForcedVEXEncoding == VEXEncoding_VEX3)
+  // If VEX/EVEX encoding is forced, we need to pass the USE_* flag to the
+  // encoder and printer.
+  if (ForcedVEXEncoding == VEXEncoding_VEX)
+Prefixes |= X86::IP_USE_VEX;
+  else if (ForcedVEXEncoding == VEXEncoding_VEX2)
+Prefixes |= X86::IP_USE_VEX2;
+  else if (ForcedVEXEncoding == VEXEncoding_VEX3)
 Prefixes |= X86::IP_USE_VEX3;
+  else if (ForcedVEXEncoding == VEXEncoding_EVEX)
+Prefixes |= X86::IP_USE_EVEX;
 
   // Set encoded flags for {disp8} and {disp32}.
   if (ForcedDispEncoding == DispEncoding_Disp8)
Index: clang/test/CodeGen/X86/att-inline-asm-prefix.c
===
--- /dev/null
+++ clang/test/CodeGen/X86/att-inline-asm-prefix.c
@@ -0,0 +1,25 @@
+// RUN:%clang_cc1 %s -ferror-limit 0 -triple=x86_64-pc -target-feature +avx512f -target-feature +avx2 -target-feature +avx512vl -S -o -  | FileCheck %s -check-prefix CHECK
+
+// This test is to check if the prefix in inline assembly is correctly
+// preserved.
+
+void check_inline_prefix(void) {
+  __asm__ (
+// CHECK: vcvtps2pd %xmm0, %xmm1
+// CHECK: {vex} vcvtps2pd %xmm0, %xmm1
+// CHECK: {vex2} vcvtps2pd %xmm0, %xmm1
+// CHECK: {vex3} vcvtps2pd %xmm0, %xmm1
+// CHECK: {evex} vcvtps2pd %xmm0, %xmm1
+// CHECK: movl $1, (%rax)
+// CHECK: {disp8}  movl $1, (%rax)
+// CHECK: {disp32} movl $1, (%rax)
+"vcvtps2pd %xmm0, %xmm1\n\t"
+"{vex} vcvt

[PATCH] D90009: [X86] VEX/EVEX prefix doesn't work for inline assembly.

2020-10-23 Thread LiuChen via Phabricator via cfe-commits
LiuChen3 added inline comments.



Comment at: llvm/lib/Target/X86/MCTargetDesc/X86InstPrinterCommon.cpp:352
+  if (Flags & X86::Force_VEXEncoding)
+O << "\t{vex}";
+  else if (Flags & X86::Force_VEX2Encoding)

pengfei wrote:
> `"\t{vex}\t"` ?
No "\t" needed to add to the end of prefix. The printer will handle it 
correctly. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90009

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


[PATCH] D89946: [clang] Suppress "follow-up" diagnostics on recovery call expressions.

2020-10-23 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang/lib/Sema/SemaOverload.cpp:12814
   // end up here.
   return SemaRef.BuildCallExpr(/*Scope*/ nullptr, NewFn.get(), LParenLoc,
MultiExprArg(Args.data(), Args.size()),

hokein wrote:
> sammccall wrote:
> > This results in (IIUC):
> > 
> > ```
> > CallExpr
> > >RecoveryExpr (indirection we inserted)
> > >>DeclRefExpr (callee)
> > >Arg1
> > ```
> > 
> > Whereas when overload resolution fails, we create:
> > ```
> > RecoveryExpr (call)
> > > OverloadExpr (callee)
> > > Arg1
> > ```
> > 
> > I can see advantages for either, but is there a reason not to be consistent?
> > (Which I guess means emitting the first one here)
> > (Which I guess means emitting the first one here)
> 
> yes, exactly. 
> 
> reasons:
> - BuildCallExpr could emit diagnostics if we pass a non-dependent callee to 
> it, this is something we want to avoid;
> - we'd save some cost -- `BuildCallExpr` has dedicated code path to handle 
> dependent expr; 
Sorry, I meant emitting the second one here. (Or changing the callexpr recovery 
to use the first form, but that's a larger patch).

I understand we save some code, but not very much (the second form is easy to 
produce), and we produce quite different ASTs for essentially the same pattern 
(the only difference is whether we attempted recovery or not). This doesn't 
seem like a good trade...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89946

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


[PATCH] D90014: [clangd] Add support for multiple DecisionForest model experiments.

2020-10-23 Thread Utkarsh Saxena via Phabricator via cfe-commits
usaxena95 created this revision.
Herald added subscribers: cfe-commits, kadircet, arphaman.
Herald added a project: clang.
usaxena95 requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.

With every incremental change, one needs to check-in new model upstream.
This also significantly increases the size of the git repo with every
new model.
Testing and comparing the old and previous model is also not possible as
we run only a single model at any point.

One solution is to have a "staging" decision forest which can be
injected into clangd without pushing it to upstream. Compare the
performance of the staging model with the live model. After a couple of
enhancements have been done to staging model, we can then replace the
live model upstream with the staging model. This reduces upstream churn
and also allows us to compare models with current baseline model.

This is done by having a callback in CodeCompleteOptions which is called
only when we want to use a decision forest ranking model. This allows us
to inject different completion model internally.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D90014

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/CodeComplete.h
  clang-tools-extra/clangd/Quality.cpp
  clang-tools-extra/clangd/Quality.h

Index: clang-tools-extra/clangd/Quality.h
===
--- clang-tools-extra/clangd/Quality.h
+++ clang-tools-extra/clangd/Quality.h
@@ -165,8 +165,18 @@
 /// Combine symbol quality and relevance into a single score.
 float evaluateSymbolAndRelevance(float SymbolQuality, float SymbolRelevance);
 
-float evaluateDecisionForest(const SymbolQualitySignals &Quality,
- const SymbolRelevanceSignals &Relevance);
+/// Same semantics as CodeComplete::Score. Quality score and Relevance score
+/// have been removed since DecisionForest cannot assign individual scores to
+/// Quality and Relevance signals.
+struct DecisionForestScores {
+  float Total = 0.f;
+  float ExcludingName = 0.f;
+};
+
+DecisionForestScores
+evaluateDecisionForest(const SymbolQualitySignals &Quality,
+   const SymbolRelevanceSignals &Relevance, float Base);
+
 /// TopN is a lossy container that preserves only the "best" N elements.
 template > class TopN {
 public:
Index: clang-tools-extra/clangd/Quality.cpp
===
--- clang-tools-extra/clangd/Quality.cpp
+++ clang-tools-extra/clangd/Quality.cpp
@@ -487,8 +487,9 @@
   return SymbolQuality * SymbolRelevance;
 }
 
-float evaluateDecisionForest(const SymbolQualitySignals &Quality,
- const SymbolRelevanceSignals &Relevance) {
+DecisionForestScores
+evaluateDecisionForest(const SymbolQualitySignals &Quality,
+   const SymbolRelevanceSignals &Relevance, float Base) {
   Example E;
   E.setIsDeprecated(Quality.Deprecated);
   E.setIsReservedName(Quality.ReservedName);
@@ -512,7 +513,19 @@
   E.setHadSymbolType(Relevance.HadSymbolType);
   E.setTypeMatchesPreferred(Relevance.TypeMatchesPreferred);
   E.setFilterLength(Relevance.FilterLength);
-  return Evaluate(E);
+
+  DecisionForestScores Scores;
+  // Exponentiating DecisionForest prediction makes the score of each tree a
+  // multiplciative boost (like NameMatch). This allows us to weigh the
+  // prediciton score and NameMatch appropriately.
+  Scores.ExcludingName = pow(Base, Evaluate(E));
+  // NeedsFixIts is not part of the DecisionForest as generating training
+  // data that needs fixits is not-feasible.
+  if (Relevance.NeedsFixIts)
+Scores.ExcludingName *= 0.5;
+  // NameMatch should be a multiplier on total score to support rescoring.
+  Scores.Total = Relevance.NameMatch * Scores.ExcludingName;
+  return Scores;
 }
 
 // Produces an integer that sorts in the same order as F.
Index: clang-tools-extra/clangd/CodeComplete.h
===
--- clang-tools-extra/clangd/CodeComplete.h
+++ clang-tools-extra/clangd/CodeComplete.h
@@ -154,14 +154,17 @@
 DecisionForest,
   } RankingModel = Heuristics;
 
+  std::function
+  DecisionForestScorer = &evaluateDecisionForest;
   /// Weight for combining NameMatch and Prediction of DecisionForest.
   /// CompletionScore is NameMatch * pow(Base, Prediction).
   /// The optimal value of Base largely depends on the semantics of the model
   /// and prediction score (e.g. algorithm used during training, number of
   /// trees, etc.). Usually if the range of Prediciton is [-20, 20] then a Base
   /// in [1.2, 1.7] works fine.
-  /// Semantics: E.g. the completion score reduces by 50% if the Prediciton
-  /// score is reduced by 2.6 points for Base = 1.3.
+  /// Semantics: E.g. For Base = 1.3, if the Prediciton score reduces by 2.6
+  /// points then completion score reduces by 50% or 1.3^(-2.6).
   float DecisionForestBase =

[PATCH] D89987: [analyzer] [NFC] Rename SymbolRef to SymExprRef

2020-10-23 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

@ASDenysPetrov 
Please grep for the `SymbolRef` and rename the other symbols/comments as well, 
especially the compound names.

In D89987#2348935 , @OikawaKirie wrote:

> Since `SymbolRef` is just a `const SymExpr *` in the current codebase, I'd 
> prefer using `const SymExpr *` directly, just like how `MemRegion` is used, 
> which would be clearer than both `SymbolRef` and `SymExprRef` as far as I am 
> thinking.

IMO using `SymExprRef` is more readable. However, I don't have any strong 
opinion on this.

> Different from `ProgramStateRef` which is an alias to `IntrusiveRefCntPtr`, 
> or `StoreRef` which is a wrapper object, an alias to a `const SymExpr *` 
> makes no sense to me.
> And this is also where I have been confused for a long while.
>
> Or on the opposite, do we also need a similar alias for a `const MemRegion 
> *`, maybe say `MemRegionRef`? After all, it is shorter. :-)

Yes, that would make the codebase more consistant.




Comment at: clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymExpr.h:111
+using SymExprRef = const SymExpr *;
+using SymbolRefSmallVectorTy = SmallVector;
 using SymbolID = unsigned;

`SymbolRefSmallVectorTy` -> `SymExprRefSmallVectorTy`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89987

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


[PATCH] D89852: [clangd] Get rid of llvm::Optional in Remote- and LocalIndexRoot; NFC

2020-10-23 Thread Aleksandr Platonov via Phabricator via cfe-commits
ArcsinX added inline comments.



Comment at: clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp:60
+llvm::StringRef Path(this->RemoteIndexRoot);
+if (!is_separator(this->RemoteIndexRoot.back(),
+  llvm::sys::path::Style::posix))

I know this already commited, but maybe we could use 
`llvm::sys::path::is_separator` instead of `is_separator` to be consistent with 
other function calls from `llvm::sys::path` namespace in this file.

P.S. `llvm::sys::path::is_separator` checks a single char, but 
`llvm::sys::path::get_separator` returns string. Can not understand why. Could 
there be a multi-char separator in the future?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89852

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


[PATCH] D89852: [clangd] Get rid of llvm::Optional in Remote- and LocalIndexRoot; NFC

2020-10-23 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev added inline comments.



Comment at: clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp:60
+llvm::StringRef Path(this->RemoteIndexRoot);
+if (!is_separator(this->RemoteIndexRoot.back(),
+  llvm::sys::path::Style::posix))

ArcsinX wrote:
> I know this already commited, but maybe we could use 
> `llvm::sys::path::is_separator` instead of `is_separator` to be consistent 
> with other function calls from `llvm::sys::path` namespace in this file.
> 
> P.S. `llvm::sys::path::is_separator` checks a single char, but 
> `llvm::sys::path::get_separator` returns string. Can not understand why. 
> Could there be a multi-char separator in the future?
I think it'd be better to strip `llvm::sys::path` elsewhere and simply rely on 
ADL. Spelling `llvm::sys::path::` twice does not really add much value and 
simply takes more space. I'll send a separate patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89852

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


[PATCH] D89852: [clangd] Get rid of llvm::Optional in Remote- and LocalIndexRoot; NFC

2020-10-23 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp:60
+llvm::StringRef Path(this->RemoteIndexRoot);
+if (!is_separator(this->RemoteIndexRoot.back(),
+  llvm::sys::path::Style::posix))

ArcsinX wrote:
> I know this already commited, but maybe we could use 
> `llvm::sys::path::is_separator` instead of `is_separator` to be consistent 
> with other function calls from `llvm::sys::path` namespace in this file.
> 
> P.S. `llvm::sys::path::is_separator` checks a single char, but 
> `llvm::sys::path::get_separator` returns string. Can not understand why. 
> Could there be a multi-char separator in the future?
Because `llvm::sys::path::get_separator` returns a null terminated string.

> Could there be a multi-char separator in the future?

I would expect the person doing such a change to also update `is_separator`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89852

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


[PATCH] D90016: [clangd] NFC: Rely on ADL in llvm::sys::path calls in marshalling

2020-10-23 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev created this revision.
kbobyrev added a reviewer: kadircet.
Herald added subscribers: cfe-commits, usaxena95, arphaman.
Herald added a project: clang.
kbobyrev requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.

Spelling out `llvm::sys::path::` twice does not add much value and can
be omitted thanks to ADL.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D90016

Files:
  clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp


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
@@ -50,12 +50,11 @@
 Marshaller::Marshaller(llvm::StringRef RemoteIndexRoot,
llvm::StringRef LocalIndexRoot)
 : Strings(Arena) {
-  llvm::StringRef PosixSeparator =
-  llvm::sys::path::get_separator(llvm::sys::path::Style::posix);
+  llvm::StringRef PosixSeparator = 
get_separator(llvm::sys::path::Style::posix);
   if (!RemoteIndexRoot.empty()) {
 assert(llvm::sys::path::is_absolute(RemoteIndexRoot));
-this->RemoteIndexRoot = llvm::sys::path::convert_to_slash(
-RemoteIndexRoot, llvm::sys::path::Style::windows);
+this->RemoteIndexRoot =
+convert_to_slash(RemoteIndexRoot, llvm::sys::path::Style::windows);
 llvm::StringRef Path(this->RemoteIndexRoot);
 if (!is_separator(this->RemoteIndexRoot.back(),
   llvm::sys::path::Style::posix))
@@ -63,8 +62,8 @@
   }
   if (!LocalIndexRoot.empty()) {
 assert(llvm::sys::path::is_absolute(LocalIndexRoot));
-this->LocalIndexRoot = llvm::sys::path::convert_to_slash(
-LocalIndexRoot, llvm::sys::path::Style::windows);
+this->LocalIndexRoot =
+convert_to_slash(LocalIndexRoot, llvm::sys::path::Style::windows);
 llvm::StringRef Path(this->LocalIndexRoot);
 if (!is_separator(this->LocalIndexRoot.back(),
   llvm::sys::path::Style::posix))
@@ -218,8 +217,8 @@
   for (const auto &Path : From.ProximityPaths) {
 llvm::SmallString<256> RelativePath = llvm::StringRef(Path);
 if (llvm::sys::path::replace_path_prefix(RelativePath, LocalIndexRoot, ""))
-  RPCRequest.add_proximity_paths(llvm::sys::path::convert_to_slash(
-  RelativePath, llvm::sys::path::Style::windows));
+  RPCRequest.add_proximity_paths(
+  convert_to_slash(RelativePath, llvm::sys::path::Style::windows));
   }
   for (const auto &Type : From.PreferredTypes)
 RPCRequest.add_preferred_types(Type);
@@ -311,7 +310,7 @@
   assert(RelativePath == llvm::sys::path::convert_to_slash(RelativePath));
   if (RelativePath.empty())
 return error("Empty relative path.");
-  if (llvm::sys::path::is_absolute(RelativePath, 
llvm::sys::path::Style::posix))
+  if (is_absolute(RelativePath, llvm::sys::path::Style::posix))
 return error("RelativePath '{0}' is absolute.", RelativePath);
   llvm::SmallString<256> FullPath = llvm::StringRef(LocalIndexRoot);
   llvm::sys::path::append(FullPath, RelativePath);
@@ -329,14 +328,12 @@
   llvm::SmallString<256> Result = ParsedURI->body();
   llvm::StringRef Path(Result);
   // Check for Windows paths (URI=file:///X:/path => Body=/X:/path)
-  if (llvm::sys::path::is_absolute(Path.substr(1),
-   llvm::sys::path::Style::windows))
+  if (is_absolute(Path.substr(1), llvm::sys::path::Style::windows))
 Result = Path.drop_front();
   if (!llvm::sys::path::replace_path_prefix(Result, RemoteIndexRoot, ""))
 return error("File path '{0}' doesn't start with '{1}'.", Result.str(),
  RemoteIndexRoot);
-  assert(Result == llvm::sys::path::convert_to_slash(
-   Result, llvm::sys::path::Style::windows));
+  assert(Result == convert_to_slash(Result, llvm::sys::path::Style::windows));
   return std::string(Result);
 }
 


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
@@ -50,12 +50,11 @@
 Marshaller::Marshaller(llvm::StringRef RemoteIndexRoot,
llvm::StringRef LocalIndexRoot)
 : Strings(Arena) {
-  llvm::StringRef PosixSeparator =
-  llvm::sys::path::get_separator(llvm::sys::path::Style::posix);
+  llvm::StringRef PosixSeparator = get_separator(llvm::sys::path::Style::posix);
   if (!RemoteIndexRoot.empty()) {
 assert(llvm::sys::path::is_absolute(RemoteIndexRoot));
-this->RemoteIndexRoot = llvm::sys::path::convert_to_slash(
-RemoteIndexRoot, llvm::sys::path::Style::windows);
+this->RemoteIndexRoot =
+convert_to_slash(RemoteIndexRoot, llvm::sys::path::Style::windows);
 llvm::StringRef Path(this->RemoteI

[PATCH] D89852: [clangd] Get rid of llvm::Optional in Remote- and LocalIndexRoot; NFC

2020-10-23 Thread Aleksandr Platonov via Phabricator via cfe-commits
ArcsinX added inline comments.



Comment at: clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp:60
+llvm::StringRef Path(this->RemoteIndexRoot);
+if (!is_separator(this->RemoteIndexRoot.back(),
+  llvm::sys::path::Style::posix))

kbobyrev wrote:
> kadircet wrote:
> > ArcsinX wrote:
> > > I know this already commited, but maybe we could use 
> > > `llvm::sys::path::is_separator` instead of `is_separator` to be 
> > > consistent with other function calls from `llvm::sys::path` namespace in 
> > > this file.
> > > 
> > > P.S. `llvm::sys::path::is_separator` checks a single char, but 
> > > `llvm::sys::path::get_separator` returns string. Can not understand why. 
> > > Could there be a multi-char separator in the future?
> > Because `llvm::sys::path::get_separator` returns a null terminated string.
> > 
> > > Could there be a multi-char separator in the future?
> > 
> > I would expect the person doing such a change to also update `is_separator`.
> I think it'd be better to strip `llvm::sys::path` elsewhere and simply rely 
> on ADL. Spelling `llvm::sys::path::` twice does not really add much value and 
> simply takes more space. I'll send a separate patch.
> Because llvm::sys::path::get_separator returns a null terminated string.
Why does not `llvm::sys::path::get_separator()` return a single char instead of 
a null-terminated string?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89852

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


[PATCH] D89986: [AIX]ignore the option -fvisibility-inlines-hidden when there is no option -fvisibility=*

2020-10-23 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai added inline comments.



Comment at: clang/test/CodeGen/aix-visibility-inlines-hidden.cpp:30-34
+// COMMON-ASM: mflr 0
+// COMMON-ASM-NEXT:stw 0, 8(1)
+// COMMON-ASM-NEXT:stwu 1, -64(1)
+// COMMON-ASM-NEXT:bl ._Z1fv
+// NOP-ASM-NEXT:   nop

rsmith wrote:
> Generally we strongly prefer for frontend tests to test only the frontend; in 
> this case, that means testing only the IR that Clang is producing and not the 
> assembly that comes out of LLVM for that IR. This should also remove the need 
> to require PPC as a registered target.
+1
The asm test can go into `llvm/test/CodeGen/PowerPC`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89986

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


[PATCH] D90016: [clangd] NFC: Rely on ADL in llvm::sys::path calls in marshalling

2020-10-23 Thread Aleksandr Platonov via Phabricator via cfe-commits
ArcsinX added inline comments.



Comment at: clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp:55
   if (!RemoteIndexRoot.empty()) {
 assert(llvm::sys::path::is_absolute(RemoteIndexRoot));
+this->RemoteIndexRoot =

llvm::sys::path::is_absolute(RemoteIndexRoot) => is_absolute(RemoteIndexRoot) ?



Comment at: clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp:64
   if (!LocalIndexRoot.empty()) {
 assert(llvm::sys::path::is_absolute(LocalIndexRoot));
+this->LocalIndexRoot =

llvm::sys::path::is_absolute(LocalIndexRoot) => is_absolute(LocalIndexRoot) ?



Comment at: 
clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp:310
   assert(!LocalIndexRoot.empty());
   assert(RelativePath == llvm::sys::path::convert_to_slash(RelativePath));
   if (RelativePath.empty())

llvm::sys::path::convert_to_slash(RelativePath) => 
convert_to_slash(RelativePath) ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90016

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


[PATCH] D90016: [clangd] NFC: Rely on ADL in llvm::sys::path calls in marshalling

2020-10-23 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev added a comment.

The ones you proposed would not work without `using llvm::sys::path::*` which I 
avoid :( They have to have an argument from `llvm::sys::path::` in order for 
the lookup to be performed correctly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90016

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


[PATCH] D90016: [clangd] NFC: Rely on ADL in llvm::sys::path calls in marshalling

2020-10-23 Thread Aleksandr Platonov via Phabricator via cfe-commits
ArcsinX added a comment.

In D90016#2349436 , @kbobyrev wrote:

> The ones you proposed would not work without `using llvm::sys::path::*` which 
> I avoid :( They have to have an argument from `llvm::sys::path::` in order 
> for the lookup to be performed correctly.

Ah, sorry, got it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90016

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


[PATCH] D89852: [clangd] Get rid of llvm::Optional in Remote- and LocalIndexRoot; NFC

2020-10-23 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp:60
+llvm::StringRef Path(this->RemoteIndexRoot);
+if (!is_separator(this->RemoteIndexRoot.back(),
+  llvm::sys::path::Style::posix))

ArcsinX wrote:
> kbobyrev wrote:
> > kadircet wrote:
> > > ArcsinX wrote:
> > > > I know this already commited, but maybe we could use 
> > > > `llvm::sys::path::is_separator` instead of `is_separator` to be 
> > > > consistent with other function calls from `llvm::sys::path` namespace 
> > > > in this file.
> > > > 
> > > > P.S. `llvm::sys::path::is_separator` checks a single char, but 
> > > > `llvm::sys::path::get_separator` returns string. Can not understand 
> > > > why. Could there be a multi-char separator in the future?
> > > Because `llvm::sys::path::get_separator` returns a null terminated string.
> > > 
> > > > Could there be a multi-char separator in the future?
> > > 
> > > I would expect the person doing such a change to also update 
> > > `is_separator`.
> > I think it'd be better to strip `llvm::sys::path` elsewhere and simply rely 
> > on ADL. Spelling `llvm::sys::path::` twice does not really add much value 
> > and simply takes more space. I'll send a separate patch.
> > Because llvm::sys::path::get_separator returns a null terminated string.
> Why does not `llvm::sys::path::get_separator()` return a single char instead 
> of a null-terminated string?
> Why does not llvm::sys::path::get_separator() return a single char instead of 
> a null-terminated string?

Probably to make composition with `+` easier. But one would need to dig-up the 
git blame and see if there are any other reasons I suppose, or ask the authors 
as mine is merely a guess :D


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89852

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


[PATCH] D90016: [clangd] NFC: Rely on ADL in llvm::sys::path calls in marshalling

2020-10-23 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

I am not really keen about trusting ADL for these, as it makes the code less 
explicit for reader, especially as it is not something we commonly depend on 
clangd so readers/reviewers would not be expecting that. So I believe we should 
not stray away from the general project style in here.

Though I am a fan of not spelling `llvm::sys::path` bazillion times. What about 
having either a `using namepsace` for it or, using declarations for the 
individual symbols we are using (e.g. Style, covnert_to_slash and is_absolute)? 
This would also help with not spelling qualifiers over and over again in the 
argument names.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90016

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


[PATCH] D88645: [Annotation] Allows annotation to carry some additional constant arguments.

2020-10-23 Thread Tyker via Phabricator via cfe-commits
Tyker updated this revision to Diff 300213.
Tyker added a comment.

In D88645#2347731 , @aaron.ballman 
wrote:

> In D88645#2347725 , @Tyker wrote:
>
>> In D88645#2347050 , @aaron.ballman 
>> wrote:
>>
>>> LGTM aside from a request for a comment to be added. Thank you!
>>
>> do you mean an RFC on llvm-dev/cfe-dev ?
>
> Oh gosh no! I just meant I was asking for a comment to be added in 
> SemaDeclAttr.td before you commit. Sorry for the confusion! :-)

Thank for the review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88645

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/ParsedAttr.h
  clang/include/clang/Sema/Sema.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/AST/ast-dump-attr.cpp
  clang/test/CodeGen/annotations-field.c
  clang/test/CodeGen/annotations-global.c
  clang/test/CodeGen/annotations-loc.c
  clang/test/CodeGen/annotations-var.c
  clang/test/CodeGenCXX/attr-annotate.cpp
  clang/test/CodeGenCXX/attr-annotate2.cpp
  clang/test/Misc/pragma-attribute-cxx.cpp
  clang/test/Misc/pragma-attribute-objc.m
  clang/test/Parser/access-spec-attrs.cpp
  clang/test/Parser/objc-implementation-attrs.m
  clang/test/Sema/annotate.c
  clang/test/Sema/pragma-attribute.c
  clang/test/SemaCXX/attr-annotate.cpp
  llvm/include/llvm/IR/Intrinsics.td
  llvm/test/Analysis/CostModel/X86/free-intrinsics.ll
  llvm/test/Analysis/CostModel/free-intrinsics-datalayout.ll
  llvm/test/Analysis/CostModel/free-intrinsics-no_info.ll
  llvm/test/CodeGen/Generic/ptr-annotate.ll
  llvm/test/Transforms/InstCombine/assume_inevitable.ll

Index: llvm/test/Transforms/InstCombine/assume_inevitable.ll
===
--- llvm/test/Transforms/InstCombine/assume_inevitable.ll
+++ llvm/test/Transforms/InstCombine/assume_inevitable.ll
@@ -15,7 +15,7 @@
 ; CHECK-NEXT:[[DUMMY_EQ:%.*]] = icmp ugt i32 [[LOADRES]], 42
 ; CHECK-NEXT:tail call void @llvm.assume(i1 [[DUMMY_EQ]])
 ; CHECK-NEXT:[[M_I8:%.*]] = bitcast i64* [[M]] to i8*
-; CHECK-NEXT:[[M_A:%.*]] = call i8* @llvm.ptr.annotation.p0i8(i8* nonnull [[M_I8]], i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str1, i64 0, i64 0), i32 2)
+; CHECK-NEXT:[[M_A:%.*]] = call i8* @llvm.ptr.annotation.p0i8(i8* nonnull [[M_I8]], i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str1, i64 0, i64 0), i32 2, i8* null)
 ; CHECK-NEXT:[[M_X:%.*]] = bitcast i8* [[M_A]] to i64*
 ; CHECK-NEXT:[[OBJSZ:%.*]] = call i64 @llvm.objectsize.i64.p0i8(i8* [[C:%.*]], i1 false, i1 false, i1 false)
 ; CHECK-NEXT:store i64 [[OBJSZ]], i64* [[M_X]], align 4
@@ -44,7 +44,7 @@
   call void @llvm.lifetime.end.p0i8(i64 1, i8* %dummy)
 
   %m_i8 = bitcast i64* %m to i8*
-  %m_a = call i8* @llvm.ptr.annotation.p0i8(i8* %m_i8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str1, i32 0, i32 0), i32 2)
+  %m_a = call i8* @llvm.ptr.annotation.p0i8(i8* %m_i8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str1, i32 0, i32 0), i32 2, i8* null)
   %m_x = bitcast i8* %m_a to i64*
   %objsz = call i64 @llvm.objectsize.i64.p0i8(i8* %c, i1 false)
   store i64 %objsz, i64* %m_x
@@ -64,7 +64,7 @@
 
 declare i64 @llvm.objectsize.i64.p0i8(i8*, i1)
 declare i32 @llvm.annotation.i32(i32, i8*, i8*, i32)
-declare i8* @llvm.ptr.annotation.p0i8(i8*, i8*, i8*, i32)
+declare i8* @llvm.ptr.annotation.p0i8(i8*, i8*, i8*, i32, i8*)
 
 declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture)
 declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture)
Index: llvm/test/CodeGen/Generic/ptr-annotate.ll
===
--- llvm/test/CodeGen/Generic/ptr-annotate.ll
+++ llvm/test/CodeGen/Generic/ptr-annotate.ll
@@ -10,9 +10,9 @@
 define void @foo() {
 entry:
   %m = alloca i8, align 4
-  %0 = call i8* @llvm.ptr.annotation.p0i8(i8* %m, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str1, i32 0, i32 0), i32 2)
+  %0 = call i8* @llvm.ptr.annotation.p0i8(i8* %m, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str1, i32 0, i32 0), i32 2, i8* null)
   store i8 1, i8* %0, align 4
   ret void
 }
 
-declare i8* @l

[PATCH] D69844: [clang][Basic] Integrate SourceLocation with FoldingSet, NFCI

2020-10-23 Thread Mikhail Maltsev via Phabricator via cfe-commits
miyuki updated this revision to Diff 300214.
miyuki added a comment.

Fixed linter errors.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69844

Files:
  clang/include/clang/Basic/SourceLocation.h
  clang/lib/Analysis/PathDiagnostic.cpp
  clang/lib/Basic/SourceLocation.cpp
  clang/lib/StaticAnalyzer/Core/BugReporter.cpp

Index: clang/lib/StaticAnalyzer/Core/BugReporter.cpp
===
--- clang/lib/StaticAnalyzer/Core/BugReporter.cpp
+++ clang/lib/StaticAnalyzer/Core/BugReporter.cpp
@@ -2193,8 +2193,8 @@
   for (SourceRange range : Ranges) {
 if (!range.isValid())
   continue;
-hash.AddInteger(range.getBegin().getRawEncoding());
-hash.AddInteger(range.getEnd().getRawEncoding());
+hash.Add(range.getBegin());
+hash.Add(range.getEnd());
   }
 }
 
@@ -2216,8 +2216,8 @@
   for (SourceRange range : Ranges) {
 if (!range.isValid())
   continue;
-hash.AddInteger(range.getBegin().getRawEncoding());
-hash.AddInteger(range.getEnd().getRawEncoding());
+hash.Add(range.getBegin());
+hash.Add(range.getEnd());
   }
 }
 
Index: clang/lib/Basic/SourceLocation.cpp
===
--- clang/lib/Basic/SourceLocation.cpp
+++ clang/lib/Basic/SourceLocation.cpp
@@ -15,6 +15,7 @@
 #include "clang/Basic/PrettyStackTrace.h"
 #include "clang/Basic/SourceManager.h"
 #include "llvm/ADT/DenseMapInfo.h"
+#include "llvm/ADT/FoldingSet.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/MemoryBuffer.h"
@@ -45,6 +46,11 @@
   return llvm::DenseMapInfo::getHashValue(ID);
 }
 
+void llvm::FoldingSetTrait::Profile(
+const SourceLocation &X, llvm::FoldingSetNodeID &ID) {
+  ID.AddInteger(X.ID);
+}
+
 void SourceLocation::print(raw_ostream &OS, const SourceManager &SM)const{
   if (!isValid()) {
 OS << "";
Index: clang/lib/Analysis/PathDiagnostic.cpp
===
--- clang/lib/Analysis/PathDiagnostic.cpp
+++ clang/lib/Analysis/PathDiagnostic.cpp
@@ -1083,9 +1083,9 @@
 //===--===//
 
 void PathDiagnosticLocation::Profile(llvm::FoldingSetNodeID &ID) const {
-  ID.AddInteger(Range.getBegin().getRawEncoding());
-  ID.AddInteger(Range.getEnd().getRawEncoding());
-  ID.AddInteger(Loc.getRawEncoding());
+  ID.Add(Range.getBegin());
+  ID.Add(Range.getEnd());
+  ID.Add(static_cast(Loc));
 }
 
 void PathDiagnosticPiece::Profile(llvm::FoldingSetNodeID &ID) const {
@@ -1095,8 +1095,8 @@
   ID.AddInteger((unsigned) getDisplayHint());
   ArrayRef Ranges = getRanges();
   for (const auto &I : Ranges) {
-ID.AddInteger(I.getBegin().getRawEncoding());
-ID.AddInteger(I.getEnd().getRawEncoding());
+ID.Add(I.getBegin());
+ID.Add(I.getEnd());
   }
 }
 
Index: clang/include/clang/Basic/SourceLocation.h
===
--- clang/include/clang/Basic/SourceLocation.h
+++ clang/include/clang/Basic/SourceLocation.h
@@ -26,6 +26,9 @@
 
 template  struct DenseMapInfo;
 
+class FoldingSetNodeID;
+template  struct FoldingSetTrait;
+
 } // namespace llvm
 
 namespace clang {
@@ -87,6 +90,7 @@
   friend class ASTReader;
   friend class ASTWriter;
   friend class SourceManager;
+  friend struct llvm::FoldingSetTrait;
 
   unsigned ID = 0;
 
@@ -501,6 +505,11 @@
 }
   };
 
+  // Allow calling FoldingSetNodeID::Add with SourceLocation object as parameter
+  template <> struct FoldingSetTrait {
+static void Profile(const clang::SourceLocation &X, FoldingSetNodeID &ID);
+  };
+
   // Teach SmallPtrSet how to handle SourceLocation.
   template<>
   struct PointerLikeTypeTraits {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87528: Enable '#pragma STDC FENV_ACCESS' in frontend cf. D69272 - Work in Progress

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



Comment at: clang/lib/Sema/SemaAttr.cpp:1020-1023
+// Resume the default rounding and exception modes.
+NewFPFeatures.setRoundingModeOverride(
+llvm::RoundingMode::NearestTiesToEven);
+NewFPFeatures.setFPExceptionModeOverride(LangOptions::FPE_Ignore);

mibintc wrote:
> sepavloff wrote:
> > The previous values of rounding mode and exception behavior may differ from 
> > the default values. For example, `#pragma STDC FENV_ROUND` may set constant 
> > rounding direction different from FE_TONEAREST`. Similarly, command line 
> > options may set exception behavior different from `ignore`.
> > Can pragma stack be used for this?
> > The previous values of rounding mode and exception behavior may differ from 
> > the default values. For example, `#pragma STDC FENV_ROUND` may set constant 
> > rounding direction different from FE_TONEAREST`. Similarly, command line 
> > options may set exception behavior different from `ignore`.
> > Can pragma stack be used for this?
> 
> I guess I could just NewFPFeatures.setAllowFEnvAccessOverride(false); and 
> leave the other 2 unset, does that sound right? The values of the FPFeatures 
> are being preserved around compound statements with FPFeaturesStateRAII
> I guess I could just NewFPFeatures.setAllowFEnvAccessOverride(false); and 
> leave the other 2 unset, does that sound right?

It should fix the most important case:
```
// RUN: %clang_cc1 -S -emit-llvm %s -o - | FileCheck %s

float func_01(float x, float y, float z) {
  #pragma STDC FENV_ROUND FE_DOWNWARD
  float res = x + y;
  {
#pragma STDC FENV_ACCESS OFF
res *= z;
  }
  return res - x;
}

// CHECK: call float @llvm.experimental.constrained.fadd.f32(float {{.*}}, 
float {{.*}}, metadata !"round.downward", metadata !"fpexcept.ignore")
// CHECK: call float @llvm.experimental.constrained.fmul.f32(float {{.*}}, 
float {{.*}}, metadata !"round.downward", metadata !"fpexcept.ignore")
// CHECK: call float @llvm.experimental.constrained.fsub.f32(float {{.*}}, 
float {{.*}}, metadata !"round.downward", metadata !"fpexcept.ignore")
```
Another case, which now fails is:
```
// RUN: %clang_cc1 -S -emit-llvm -frounding-math %s -o - | FileCheck %s

float func_01(float x, float y, float z) {
  float res = x + y;
  {
#pragma STDC FENV_ACCESS OFF
res *= z;
  }
  return res - x;
}

// CHECK: call float @llvm.experimental.constrained.fadd.f32(float {{.*}}, 
float {{.*}}, metadata !"round.dynamic", metadata !"fpexcept.ignore")
// CHECK: call float @llvm.experimental.constrained.fmul.f32(float {{.*}}, 
float {{.*}}, metadata !"round.dynamic", metadata !"fpexcept.ignore")
// CHECK: call float @llvm.experimental.constrained.fsub.f32(float {{.*}}, 
float {{.*}}, metadata !"round.dynamic", metadata !"fpexcept.ignore")
```
The function may be called from a context, where rounding mode is not default, 
command-line options allow that. So rounding mode inside the inner block is 
dynamic, although FP state is not accessed in it.

Now consider exception behavior. For example, the test case, which now passes:
```
// RUN: %clang_cc1 -S -emit-llvm -ffp-exception-behavior=strict %s -o - | 
FileCheck %s

float func_01(float x, float y, float z) {
  float res = x + y;
  {
#pragma STDC FENV_ACCESS OFF
res *= z;
  }
  return res - x;
}

// CHECK: call float @llvm.experimental.constrained.fadd.f32(float {{.*}}, 
float {{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict")
// CHECK: call float @llvm.experimental.constrained.fmul.f32(float {{.*}}, 
float {{.*}}, metadata !"round.tonearest", metadata !"fpexcept.ignore")
// CHECK: call float @llvm.experimental.constrained.fsub.f32(float {{.*}}, 
float {{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict")
```
... is correct IMHO. Setting FENV_ACCESS to OFF means the code in the affected 
region does not check FP exceptions, so they can be ignored. This is a way to 
have default FP state even if the command-line options set FENV_ACCESS. As for 
`maytrap` I am not sure, but I think the following test should pass:  
```
// RUN: %clang_cc1 -S -emit-llvm -ffp-exception-behavior=maytrap %s -o - | 
FileCheck %s

float func_01(float x, float y, float z) {
  float res = x + y;
  {
#pragma STDC FENV_ACCESS OFF
res *= z;
  }
  return res - x;
}

// CHECK: call float @llvm.experimental.constrained.fadd.f32(float {{.*}}, 
float {{.*}}, metadata !"round.tonearest", metadata !"fpexcept.maytrap")
// CHECK: call float @llvm.experimental.constrained.fmul.f32(float {{.*}}, 
float {{.*}}, metadata !"round.tonearest", metadata !"fpexcept.maytrap")
// CHECK: call float @llvm.experimental.constrained.fsub.f32(float {{.*}}, 
float {{.*}}, metadata !"round.tonearest", metadata !"fpexcept.maytrap")
```
The outer code may set hardware for trapping and although in the inner block 
there is no access to FP state, traps are possible and compiler must be aware 
of them.

And finally the following test

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

2020-10-23 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff added a comment.

Ping.
This is the only remaining prerequisite for D78903 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78899

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


[PATCH] D90023: [Syntax] Add iterators over children of syntax trees.

2020-10-23 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added reviewers: gribozavr, eduucaldas.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
sammccall requested review of this revision.

This gives us slightly nicer syntax (foreach) for idioms currently expressed
as a loop, and the option to use range algorithms where it makes sense
(e.g. llvm::all_of et al encapsulate the needed flow control in a useful way).

It's also a building block for iteration over filtered views (e.g. iterate over
all Stmt children, with the right type):
for (const Statement &S : filter(N.children()))

  ...

I realize the recent direction has been mostly towards strongly-typed
node-specific facilities, but I think it's important we have convenient
generic facilities too.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D90023

Files:
  clang/include/clang/Tooling/Syntax/Tree.h
  clang/lib/Tooling/Syntax/Tree.cpp
  clang/unittests/Tooling/Syntax/TreeTest.cpp
  clang/unittests/Tooling/Syntax/TreeTestBase.h

Index: clang/unittests/Tooling/Syntax/TreeTestBase.h
===
--- clang/unittests/Tooling/Syntax/TreeTestBase.h
+++ clang/unittests/Tooling/Syntax/TreeTestBase.h
@@ -20,7 +20,9 @@
 #include "clang/Tooling/Syntax/Tokens.h"
 #include "clang/Tooling/Syntax/Tree.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Testing/Support/Annotations.h"
+#include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
 namespace clang {
@@ -53,6 +55,14 @@
 };
 
 std::vector allTestClangConfigs();
+
+MATCHER_P(role, R, "") {
+  if (arg.getRole() == R)
+return true;
+  *result_listener << "role is " << llvm::to_string(arg.getRole());
+  return false;
+}
+
 } // namespace syntax
 } // namespace clang
 #endif // LLVM_CLANG_UNITTESTS_TOOLING_SYNTAX_TREETESTBASE_H
Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -8,6 +8,7 @@
 
 #include "clang/Tooling/Syntax/Tree.h"
 #include "TreeTestBase.h"
+#include "clang/Basic/SourceManager.h"
 #include "clang/Tooling/Syntax/BuildTree.h"
 #include "clang/Tooling/Syntax/Nodes.h"
 #include "llvm/ADT/STLExtras.h"
@@ -17,6 +18,7 @@
 using namespace clang::syntax;
 
 namespace {
+using testing::ElementsAre;
 
 class TreeTest : public SyntaxTreeTest {
 private:
@@ -124,6 +126,56 @@
   }
 }
 
+TEST_F(TreeTest, Iterators) {
+  buildTree("", allTestClangConfigs().front());
+  std::vector Children = {createLeaf(*Arena, tok::identifier, "a"),
+  createLeaf(*Arena, tok::identifier, "b"),
+  createLeaf(*Arena, tok::identifier, "c")};
+  auto *Tree = syntax::createTree(*Arena,
+  {{Children[0], NodeRole::LeftHandSide},
+   {Children[1], NodeRole::OperatorToken},
+   {Children[2], NodeRole::RightHandSide}},
+  NodeKind::TranslationUnit);
+  const syntax::Tree *ConstTree = Tree;
+
+  auto Range = Tree->children();
+  EXPECT_THAT(Range, ElementsAre(role(NodeRole::LeftHandSide),
+ role(NodeRole::OperatorToken),
+ role(NodeRole::RightHandSide)));
+
+  auto ConstRange = ConstTree->children();
+  EXPECT_THAT(ConstRange, ElementsAre(role(NodeRole::LeftHandSide),
+  role(NodeRole::OperatorToken),
+  role(NodeRole::RightHandSide)));
+
+  // FIXME: mutate and observe no invalidation. Mutations are private for now...
+  auto It = Range.begin();
+  auto CIt = ConstRange.begin();
+  static_assert(std::is_same::value,
+"mutable range");
+  static_assert(std::is_same::value,
+"const range");
+
+  for (unsigned I = 0; I < 3; ++I) {
+EXPECT_EQ(It, CIt);
+EXPECT_TRUE(It);
+EXPECT_TRUE(CIt);
+EXPECT_EQ(It.asPointer(), Children[I]);
+EXPECT_EQ(CIt.asPointer(), Children[I]);
+EXPECT_EQ(&*It, Children[I]);
+EXPECT_EQ(&*CIt, Children[I]);
+++It;
+++CIt;
+  }
+  EXPECT_EQ(It, CIt);
+  EXPECT_EQ(It, Tree::child_iterator());
+  EXPECT_EQ(CIt, Tree::const_child_iterator());
+  EXPECT_FALSE(It);
+  EXPECT_FALSE(CIt);
+  EXPECT_EQ(nullptr, It.asPointer());
+  EXPECT_EQ(nullptr, CIt.asPointer());
+}
+
 class ListTest : public SyntaxTreeTest {
 private:
   std::string dumpQuotedTokensOrNull(const Node *N) {
Index: clang/lib/Tooling/Syntax/Tree.cpp
===
--- clang/lib/Tooling/Syntax/Tree.cpp
+++ clang/lib/Tooling/Syntax/Tree.cpp
@@ -19,8 +19,8 @@
 static void traverse(const syntax::Node *N,
  llvm::function_ref Visit) {
   if (auto *T = dyn_cast(N)) {
-for (const auto *C = T->getFirstChild(); C; C 

[PATCH] D90016: [clangd] NFC: Rely on ADL in llvm::sys::path calls in marshalling

2020-10-23 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 300222.
kbobyrev added a comment.

Add using directives for llvm::sys::path functions used more than once.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90016

Files:
  clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp

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
@@ -27,6 +27,12 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/StringSaver.h"
 
+using llvm::sys::path::append;
+using llvm::sys::path::convert_to_slash;
+using llvm::sys::path::is_absolute;
+using llvm::sys::path::replace_path_prefix;
+using llvm::sys::path::Style;
+
 namespace clang {
 namespace clangd {
 namespace remote {
@@ -50,24 +56,19 @@
 Marshaller::Marshaller(llvm::StringRef RemoteIndexRoot,
llvm::StringRef LocalIndexRoot)
 : Strings(Arena) {
-  llvm::StringRef PosixSeparator =
-  llvm::sys::path::get_separator(llvm::sys::path::Style::posix);
+  llvm::StringRef PosixSeparator = get_separator(Style::posix);
   if (!RemoteIndexRoot.empty()) {
-assert(llvm::sys::path::is_absolute(RemoteIndexRoot));
-this->RemoteIndexRoot = llvm::sys::path::convert_to_slash(
-RemoteIndexRoot, llvm::sys::path::Style::windows);
+assert(is_absolute(RemoteIndexRoot));
+this->RemoteIndexRoot = convert_to_slash(RemoteIndexRoot, Style::windows);
 llvm::StringRef Path(this->RemoteIndexRoot);
-if (!is_separator(this->RemoteIndexRoot.back(),
-  llvm::sys::path::Style::posix))
+if (!is_separator(this->RemoteIndexRoot.back(), Style::posix))
   this->RemoteIndexRoot += PosixSeparator;
   }
   if (!LocalIndexRoot.empty()) {
-assert(llvm::sys::path::is_absolute(LocalIndexRoot));
-this->LocalIndexRoot = llvm::sys::path::convert_to_slash(
-LocalIndexRoot, llvm::sys::path::Style::windows);
+assert(is_absolute(LocalIndexRoot));
+this->LocalIndexRoot = convert_to_slash(LocalIndexRoot, Style::windows);
 llvm::StringRef Path(this->LocalIndexRoot);
-if (!is_separator(this->LocalIndexRoot.back(),
-  llvm::sys::path::Style::posix))
+if (!is_separator(this->LocalIndexRoot.back(), Style::posix))
   this->LocalIndexRoot += PosixSeparator;
   }
   assert(!RemoteIndexRoot.empty() || !LocalIndexRoot.empty());
@@ -96,7 +97,7 @@
   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);
+append(LocalPath, Path);
 // FuzzyFindRequest requires proximity paths to have platform-native format
 // in order for SymbolIndex to process the query correctly.
 llvm::sys::path::native(LocalPath);
@@ -217,9 +218,9 @@
   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, ""))
-  RPCRequest.add_proximity_paths(llvm::sys::path::convert_to_slash(
-  RelativePath, llvm::sys::path::Style::windows));
+if (replace_path_prefix(RelativePath, LocalIndexRoot, ""))
+  RPCRequest.add_proximity_paths(
+  convert_to_slash(RelativePath, Style::windows));
   }
   for (const auto &Type : From.PreferredTypes)
 RPCRequest.add_preferred_types(Type);
@@ -308,13 +309,13 @@
 llvm::Expected
 Marshaller::relativePathToURI(llvm::StringRef RelativePath) {
   assert(!LocalIndexRoot.empty());
-  assert(RelativePath == llvm::sys::path::convert_to_slash(RelativePath));
+  assert(RelativePath == convert_to_slash(RelativePath));
   if (RelativePath.empty())
 return error("Empty relative path.");
-  if (llvm::sys::path::is_absolute(RelativePath, llvm::sys::path::Style::posix))
+  if (is_absolute(RelativePath, Style::posix))
 return error("RelativePath '{0}' is absolute.", RelativePath);
   llvm::SmallString<256> FullPath = llvm::StringRef(LocalIndexRoot);
-  llvm::sys::path::append(FullPath, RelativePath);
+  append(FullPath, RelativePath);
   auto Result = URI::createFile(FullPath);
   return Result.toString();
 }
@@ -329,14 +330,12 @@
   llvm::SmallString<256> Result = ParsedURI->body();
   llvm::StringRef Path(Result);
   // Check for Windows paths (URI=file:///X:/path => Body=/X:/path)
-  if (llvm::sys::path::is_absolute(Path.substr(1),
-   llvm::sys::path::Style::windows))
+  if (is_absolute(Path.substr(1), Style::windows))
 Result = Path.drop_front();
-  if (!llvm::sys::path::replace_path_prefix(Res

[PATCH] D90026: [FPEnv] Tests for rounding properties of constant evalution

2020-10-23 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff created this revision.
sepavloff added reviewers: rsmith, rjmccall, mibintc.
Herald added a project: clang.
sepavloff requested review of this revision.

These are moved from D88498 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D90026

Files:
  clang/test/CodeGen/rounding-math.c
  clang/test/CodeGen/rounding-math.cpp
  clang/test/SemaCXX/rounding-math.cpp

Index: clang/test/SemaCXX/rounding-math.cpp
===
--- clang/test/SemaCXX/rounding-math.cpp
+++ clang/test/SemaCXX/rounding-math.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -triple x86_64-linux -verify=norounding %s
-// RUN: %clang_cc1 -triple x86_64-linux -verify=rounding %s -frounding-math
+// RUN: %clang_cc1 -triple x86_64-linux -verify=norounding -Wno-unknown-pragmas %s
+// RUN: %clang_cc1 -triple x86_64-linux -verify=rounding %s -frounding-math -Wno-unknown-pragmas
 // rounding-no-diagnostics
 
 #define fold(x) (__builtin_constant_p(x) ? (x) : (x))
@@ -39,3 +39,40 @@
 int *h() {
   return new int[int(-3 * (1.0 / 3.0))]; // norounding-error {{too large}}
 }
+
+
+// nextUp(1.F) == 0x1.02p0F
+static_assert(1.0F + 0x0.01p0F == 0x1.0p0F, "");
+
+char Arr01[1 + (1.0F + 0x0.01p0F > 1.0F)];
+static_assert(sizeof(Arr01) == 1, "");
+
+struct S1 {
+  int : (1.0F + 0x0.01p0F > 1.0F);
+  int f;
+};
+static_assert(sizeof(S1) == sizeof(int), "");
+
+#pragma STDC FENV_ROUND FE_UPWARD
+static_assert(1.0F + 0x0.01p0F == 0x1.02p0F, "");
+
+char Arr01u[1 + (1.0F + 0x0.01p0F > 1.0F)];
+static_assert(sizeof(Arr01u) == 2, "");
+
+struct S1u {
+  int : (1.0F + 0x0.01p0F > 1.0F);
+  int f;
+};
+static_assert(sizeof(S1u) > sizeof(int), "");
+
+#pragma STDC FENV_ROUND FE_DOWNWARD
+static_assert(1.0F + 0x0.01p0F == 1.0F, "");
+
+char Arr01d[1 + (1.0F + 0x0.01p0F > 1.0F)];
+static_assert(sizeof(Arr01d) == 1, "");
+
+struct S1d {
+  int : (1.0F + 0x0.01p0F > 1.0F);
+  int f;
+};
+static_assert(sizeof(S1d) == sizeof(int), "");
Index: clang/test/CodeGen/rounding-math.cpp
===
--- /dev/null
+++ clang/test/CodeGen/rounding-math.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -S -emit-llvm -triple i386-linux -Wno-unknown-pragmas -frounding-math %s -o - | FileCheck %s
+
+constexpr float func_01(float x, float y) {
+  return x + y;
+}
+
+float V1 = func_01(1.0F, 0x0.01p0F);
+float V2 = 1.0F + 0x0.01p0F;
+float V3 = func_01(1.0F, 2.0F);
+
+// CHECK: @V1 = {{.*}}global float 1.00e+00, align 4
+// CHECK: @V2 = {{.*}}global float 1.00e+00, align 4
+// CHECK: @V3 = {{.*}}global float 3.00e+00, align 4
Index: clang/test/CodeGen/rounding-math.c
===
--- /dev/null
+++ clang/test/CodeGen/rounding-math.c
@@ -0,0 +1,45 @@
+// RUN: %clang_cc1 -S -emit-llvm -ffp-exception-behavior=strict -Wno-unknown-pragmas %s -o - | FileCheck %s
+// RUN: %clang_cc1 -S -emit-llvm -frounding-math -Wno-unknown-pragmas %s -o - | FileCheck %s
+
+float PR47807 = -8.6563630030e-03;
+
+// nextUp(1.F) == 0x1.02p0F
+
+struct S {
+  float f;
+};
+
+static struct S var_01 = {0x1.01p0};
+struct S *func_01() {
+  return &var_01;
+}
+
+struct S var_02 = {0x1.01p0};
+
+struct S *func_03() {
+  static struct S var_03 = {0x1.01p0};
+  return &var_03;
+}
+
+// CHECK: @var_01 = {{.*}} %struct.S { float 1.00e+00 }
+// CHECK: @var_02 = {{.*}} %struct.S { float 1.00e+00 }
+// CHECK: @func_03.var_03 = {{.*}} %struct.S { float 1.00e+00 }
+
+#pragma STDC FENV_ROUND FE_UPWARD
+
+static struct S var_04 = {0x1.01p0};
+struct S *func_04() {
+  return &var_04;
+}
+
+struct S var_05 = {0x1.01p0};
+
+struct S *func_06() {
+  static struct S var_06 = {0x1.01p0};
+  return &var_06;
+}
+
+// CHECK: @var_04 = {{.*}} %struct.S { float 0x3FF02000 }
+// CHECK: @var_05 = {{.*}} %struct.S { float 0x3FF02000 }
+// CHECK: @func_06.var_06 = {{.*}} %struct.S { float 0x3FF02000 }
+
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D89882: [clangd] Offset enum values by when marshalling

2020-10-23 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 300229.
kbobyrev added a comment.

Migrate to proto2 syntax.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89882

Files:
  clang-tools-extra/clangd/index/remote/Index.proto
  clang-tools-extra/clangd/index/remote/marshalling/Marshalling.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
@@ -377,6 +377,7 @@
   EXPECT_EQ(static_cast(Serialized.subjects_size()),
 Request.Subjects.size());
   EXPECT_EQ(Serialized.limit(), Request.Limit);
+  // Serialized enums are offset by one.
   EXPECT_EQ(static_cast(Serialized.predicate()),
 Request.Predicate);
   auto Deserialized = ProtobufMarshaller.fromProtobuf(&Serialized);
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
@@ -11,6 +11,7 @@
 #include "Index.pb.h"
 #include "Protocol.h"
 #include "index/Index.h"
+#include "index/Ref.h"
 #include "index/Serialization.h"
 #include "index/Symbol.h"
 #include "index/SymbolID.h"
@@ -114,7 +115,12 @@
   if (!IDs)
 return IDs.takeError();
   Req.IDs = std::move(*IDs);
-  Req.Filter = static_cast(Message->filter());
+  // This sets a default for RefKind. Doing it explicitly in proto definition
+  // is error-prone because clangd::RefKind::All can change unexpectedly.
+  if (Message->has_filter())
+Req.Filter = static_cast(Message->filter());
+  else
+Req.Filter = clangd::RefKind::All;
   if (Message->limit())
 Req.Limit = Message->limit();
   return Req;
@@ -127,7 +133,10 @@
   if (!IDs)
 return IDs.takeError();
   Req.Subjects = std::move(*IDs);
+  if (!Message->has_predicate())
+return error("RelationnsRequest requires RelationKind predicate.");
   Req.Predicate = static_cast(Message->predicate());
+
   if (Message->limit())
 Req.Limit = Message->limit();
   return Req;
@@ -180,7 +189,7 @@
   if (!Location)
 return Location.takeError();
   Result.Location = *Location;
-  Result.Kind = static_cast(Message.kind());
+  Result.Kind = static_cast(Message.kind());
   return Result;
 }
 
Index: clang-tools-extra/clangd/index/remote/Index.proto
===
--- clang-tools-extra/clangd/index/remote/Index.proto
+++ clang-tools-extra/clangd/index/remote/Index.proto
@@ -6,12 +6,13 @@
 //
 //===--===//
 
-syntax = "proto3";
+syntax = "proto2";
 
 package clang.clangd.remote.v1;
 
 // Semantics of SymbolIndex match clangd::SymbolIndex with all required
 // structures corresponding to their clangd::* counterparts.
+// NOTE: Enum values are offset by one to detect missing values.
 service SymbolIndex {
   rpc Lookup(LookupRequest) returns (stream LookupReply) {}
 
@@ -34,11 +35,11 @@
 }
 
 message FuzzyFindRequest {
-  string query = 1;
+  optional string query = 1;
   repeated string scopes = 2;
-  bool any_scope = 3;
-  uint32 limit = 4;
-  bool restricted_for_code_completion = 5;
+  optional bool any_scope = 3;
+  optional uint32 limit = 4;
+  optional bool restricted_for_code_completion = 5;
   repeated string proximity_paths = 6;
   repeated string preferred_types = 7;
 }
@@ -54,8 +55,8 @@
 
 message RefsRequest {
   repeated string ids = 1;
-  uint32 filter = 2;
-  uint32 limit = 3;
+  optional uint32 filter = 2;
+  optional uint32 limit = 3;
 }
 
 // The response is a stream of reference messages, and one terminating has_more
@@ -68,59 +69,59 @@
 }
 
 message Symbol {
-  string id = 1;
-  SymbolInfo info = 2;
-  string name = 3;
-  SymbolLocation definition = 4;
-  string scope = 5;
-  SymbolLocation canonical_declaration = 6;
-  int32 references = 7;
-  uint32 origin = 8;
-  string signature = 9;
-  string template_specialization_args = 10;
-  string completion_snippet_suffix = 11;
-  string documentation = 12;
-  string return_type = 13;
-  string type = 14;
+  optional string id = 1;
+  optional SymbolInfo info = 2;
+  optional string name = 3;
+  optional SymbolLocation definition = 4;
+  optional string scope = 5;
+  optional SymbolLocation canonical_declaration = 6;
+  optional int32 references = 7;
+  optional uint32 origin = 8;
+  optional string signature = 9;
+  optional string template_specialization_args = 10;
+  optional string completion_snippet_suffix = 11;
+  optional string documentation = 12;
+  optional string return_type = 13;
+  optional string type = 14;
   repeated HeaderWithReferences headers = 15;

[PATCH] D89882: [clangd] Offset enum values by when marshalling

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

Remove outdated comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89882

Files:
  clang-tools-extra/clangd/index/remote/Index.proto
  clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp

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
@@ -11,6 +11,7 @@
 #include "Index.pb.h"
 #include "Protocol.h"
 #include "index/Index.h"
+#include "index/Ref.h"
 #include "index/Serialization.h"
 #include "index/Symbol.h"
 #include "index/SymbolID.h"
@@ -114,7 +115,12 @@
   if (!IDs)
 return IDs.takeError();
   Req.IDs = std::move(*IDs);
-  Req.Filter = static_cast(Message->filter());
+  // This sets a default for RefKind. Doing it explicitly in proto definition
+  // is error-prone because clangd::RefKind::All can change unexpectedly.
+  if (Message->has_filter())
+Req.Filter = static_cast(Message->filter());
+  else
+Req.Filter = clangd::RefKind::All;
   if (Message->limit())
 Req.Limit = Message->limit();
   return Req;
@@ -127,7 +133,10 @@
   if (!IDs)
 return IDs.takeError();
   Req.Subjects = std::move(*IDs);
+  if (!Message->has_predicate())
+return error("RelationnsRequest requires RelationKind predicate.");
   Req.Predicate = static_cast(Message->predicate());
+
   if (Message->limit())
 Req.Limit = Message->limit();
   return Req;
@@ -180,7 +189,7 @@
   if (!Location)
 return Location.takeError();
   Result.Location = *Location;
-  Result.Kind = static_cast(Message.kind());
+  Result.Kind = static_cast(Message.kind());
   return Result;
 }
 
Index: clang-tools-extra/clangd/index/remote/Index.proto
===
--- clang-tools-extra/clangd/index/remote/Index.proto
+++ clang-tools-extra/clangd/index/remote/Index.proto
@@ -6,12 +6,13 @@
 //
 //===--===//
 
-syntax = "proto3";
+syntax = "proto2";
 
 package clang.clangd.remote.v1;
 
 // Semantics of SymbolIndex match clangd::SymbolIndex with all required
 // structures corresponding to their clangd::* counterparts.
+// NOTE: Enum values are offset by one to detect missing values.
 service SymbolIndex {
   rpc Lookup(LookupRequest) returns (stream LookupReply) {}
 
@@ -34,11 +35,11 @@
 }
 
 message FuzzyFindRequest {
-  string query = 1;
+  optional string query = 1;
   repeated string scopes = 2;
-  bool any_scope = 3;
-  uint32 limit = 4;
-  bool restricted_for_code_completion = 5;
+  optional bool any_scope = 3;
+  optional uint32 limit = 4;
+  optional bool restricted_for_code_completion = 5;
   repeated string proximity_paths = 6;
   repeated string preferred_types = 7;
 }
@@ -54,8 +55,8 @@
 
 message RefsRequest {
   repeated string ids = 1;
-  uint32 filter = 2;
-  uint32 limit = 3;
+  optional uint32 filter = 2;
+  optional uint32 limit = 3;
 }
 
 // The response is a stream of reference messages, and one terminating has_more
@@ -68,59 +69,59 @@
 }
 
 message Symbol {
-  string id = 1;
-  SymbolInfo info = 2;
-  string name = 3;
-  SymbolLocation definition = 4;
-  string scope = 5;
-  SymbolLocation canonical_declaration = 6;
-  int32 references = 7;
-  uint32 origin = 8;
-  string signature = 9;
-  string template_specialization_args = 10;
-  string completion_snippet_suffix = 11;
-  string documentation = 12;
-  string return_type = 13;
-  string type = 14;
+  optional string id = 1;
+  optional SymbolInfo info = 2;
+  optional string name = 3;
+  optional SymbolLocation definition = 4;
+  optional string scope = 5;
+  optional SymbolLocation canonical_declaration = 6;
+  optional int32 references = 7;
+  optional uint32 origin = 8;
+  optional string signature = 9;
+  optional string template_specialization_args = 10;
+  optional string completion_snippet_suffix = 11;
+  optional string documentation = 12;
+  optional string return_type = 13;
+  optional string type = 14;
   repeated HeaderWithReferences headers = 15;
-  uint32 flags = 16;
+  optional uint32 flags = 16;
 }
 
 message Ref {
-  SymbolLocation location = 1;
-  uint32 kind = 2;
+  optional SymbolLocation location = 1;
+  optional uint32 kind = 2;
 }
 
 message SymbolInfo {
-  uint32 kind = 1;
-  uint32 subkind = 2;
-  uint32 language = 3;
-  uint32 properties = 4;
+  optional uint32 kind = 1;
+  optional uint32 subkind = 2;
+  optional uint32 language = 3;
+  optional uint32 properties = 4;
 }
 
 message SymbolLocation {
-  Position start = 1;
-  Position end = 2;
+  optional Position start = 1;
+  optional Position end = 2;
   // clangd::SymbolLocation stores FileURI, but the protocol transmi

[PATCH] D89882: [clangd] Migrate to proto2 syntax

2020-10-23 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 300231.
kbobyrev added a comment.

Remove a newline.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89882

Files:
  clang-tools-extra/clangd/index/remote/Index.proto
  clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp

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
@@ -11,6 +11,7 @@
 #include "Index.pb.h"
 #include "Protocol.h"
 #include "index/Index.h"
+#include "index/Ref.h"
 #include "index/Serialization.h"
 #include "index/Symbol.h"
 #include "index/SymbolID.h"
@@ -114,7 +115,12 @@
   if (!IDs)
 return IDs.takeError();
   Req.IDs = std::move(*IDs);
-  Req.Filter = static_cast(Message->filter());
+  // This sets a default for RefKind. Doing it explicitly in proto definition
+  // is error-prone because clangd::RefKind::All can change unexpectedly.
+  if (Message->has_filter())
+Req.Filter = static_cast(Message->filter());
+  else
+Req.Filter = clangd::RefKind::All;
   if (Message->limit())
 Req.Limit = Message->limit();
   return Req;
@@ -127,6 +133,8 @@
   if (!IDs)
 return IDs.takeError();
   Req.Subjects = std::move(*IDs);
+  if (!Message->has_predicate())
+return error("RelationnsRequest requires RelationKind predicate.");
   Req.Predicate = static_cast(Message->predicate());
   if (Message->limit())
 Req.Limit = Message->limit();
@@ -180,7 +188,7 @@
   if (!Location)
 return Location.takeError();
   Result.Location = *Location;
-  Result.Kind = static_cast(Message.kind());
+  Result.Kind = static_cast(Message.kind());
   return Result;
 }
 
Index: clang-tools-extra/clangd/index/remote/Index.proto
===
--- clang-tools-extra/clangd/index/remote/Index.proto
+++ clang-tools-extra/clangd/index/remote/Index.proto
@@ -6,12 +6,13 @@
 //
 //===--===//
 
-syntax = "proto3";
+syntax = "proto2";
 
 package clang.clangd.remote.v1;
 
 // Semantics of SymbolIndex match clangd::SymbolIndex with all required
 // structures corresponding to their clangd::* counterparts.
+// NOTE: Enum values are offset by one to detect missing values.
 service SymbolIndex {
   rpc Lookup(LookupRequest) returns (stream LookupReply) {}
 
@@ -34,11 +35,11 @@
 }
 
 message FuzzyFindRequest {
-  string query = 1;
+  optional string query = 1;
   repeated string scopes = 2;
-  bool any_scope = 3;
-  uint32 limit = 4;
-  bool restricted_for_code_completion = 5;
+  optional bool any_scope = 3;
+  optional uint32 limit = 4;
+  optional bool restricted_for_code_completion = 5;
   repeated string proximity_paths = 6;
   repeated string preferred_types = 7;
 }
@@ -54,8 +55,8 @@
 
 message RefsRequest {
   repeated string ids = 1;
-  uint32 filter = 2;
-  uint32 limit = 3;
+  optional uint32 filter = 2;
+  optional uint32 limit = 3;
 }
 
 // The response is a stream of reference messages, and one terminating has_more
@@ -68,59 +69,59 @@
 }
 
 message Symbol {
-  string id = 1;
-  SymbolInfo info = 2;
-  string name = 3;
-  SymbolLocation definition = 4;
-  string scope = 5;
-  SymbolLocation canonical_declaration = 6;
-  int32 references = 7;
-  uint32 origin = 8;
-  string signature = 9;
-  string template_specialization_args = 10;
-  string completion_snippet_suffix = 11;
-  string documentation = 12;
-  string return_type = 13;
-  string type = 14;
+  optional string id = 1;
+  optional SymbolInfo info = 2;
+  optional string name = 3;
+  optional SymbolLocation definition = 4;
+  optional string scope = 5;
+  optional SymbolLocation canonical_declaration = 6;
+  optional int32 references = 7;
+  optional uint32 origin = 8;
+  optional string signature = 9;
+  optional string template_specialization_args = 10;
+  optional string completion_snippet_suffix = 11;
+  optional string documentation = 12;
+  optional string return_type = 13;
+  optional string type = 14;
   repeated HeaderWithReferences headers = 15;
-  uint32 flags = 16;
+  optional uint32 flags = 16;
 }
 
 message Ref {
-  SymbolLocation location = 1;
-  uint32 kind = 2;
+  optional SymbolLocation location = 1;
+  optional uint32 kind = 2;
 }
 
 message SymbolInfo {
-  uint32 kind = 1;
-  uint32 subkind = 2;
-  uint32 language = 3;
-  uint32 properties = 4;
+  optional uint32 kind = 1;
+  optional uint32 subkind = 2;
+  optional uint32 language = 3;
+  optional uint32 properties = 4;
 }
 
 message SymbolLocation {
-  Position start = 1;
-  Position end = 2;
+  optional Position start = 1;
+  optional Position end = 2;
   // clangd::SymbolLocation stores FileURI, but the protocol transmits a the
   // relative path. Because paths are different on the rem

[PATCH] D90027: [CMake] generate_grpc_protos -> generate_protos(... GRPC). NFC

2020-10-23 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: kbobyrev.
Herald added subscribers: llvm-commits, cfe-commits, usaxena95, kadircet, 
arphaman, mgorny.
Herald added projects: clang, LLVM.
sammccall requested review of this revision.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D90027

Files:
  clang-tools-extra/clangd/index/remote/CMakeLists.txt
  llvm/cmake/modules/FindGRPC.cmake


Index: llvm/cmake/modules/FindGRPC.cmake
===
--- llvm/cmake/modules/FindGRPC.cmake
+++ llvm/cmake/modules/FindGRPC.cmake
@@ -83,27 +83,31 @@
 
 # Proto headers are generated in ${CMAKE_CURRENT_BINARY_DIR}.
 # Libraries that use these headers should adjust the include path.
-# FIXME(kirillbobyrev): Allow optional generation of gRPC code and give callers
-# control over it via additional parameters.
-function(generate_grpc_protos LibraryName ProtoFile)
+# If the "GRPC" argument is given, services are also generated.
+function(generate_protos LibraryName ProtoFile)
+  cmake_parse_arguments(PARSE_ARGV 2 PROTO "GRPC" "" "")
   get_filename_component(ProtoSourceAbsolutePath 
"${CMAKE_CURRENT_SOURCE_DIR}/${ProtoFile}" ABSOLUTE)
   get_filename_component(ProtoSourcePath ${ProtoSourceAbsolutePath} PATH)
 
   set(GeneratedProtoSource "${CMAKE_CURRENT_BINARY_DIR}/Index.pb.cc")
   set(GeneratedProtoHeader "${CMAKE_CURRENT_BINARY_DIR}/Index.pb.h")
-  set(GeneratedGRPCSource "${CMAKE_CURRENT_BINARY_DIR}/Index.grpc.pb.cc")
-  set(GeneratedGRPCHeader "${CMAKE_CURRENT_BINARY_DIR}/Index.grpc.pb.h")
+  set(Flags
+--cpp_out="${CMAKE_CURRENT_BINARY_DIR}"
+--proto_path="${ProtoSourcePath}")
+  if (PROTO_GRPC)
+list(APPEND Flags
+  --grpc_out="${CMAKE_CURRENT_BINARY_DIR}"
+  --plugin=protoc-gen-grpc="${GRPC_CPP_PLUGIN}")
+list(APPEND GeneratedProtoSource 
"${CMAKE_CURRENT_BINARY_DIR}/Index.grpc.pb.cc")
+list(APPEND GeneratedProtoHeader 
"${CMAKE_CURRENT_BINARY_DIR}/Index.grpc.pb.h")
+  endif()
   add_custom_command(
-OUTPUT "${GeneratedProtoSource}" "${GeneratedProtoHeader}" 
"${GeneratedGRPCSource}" "${GeneratedGRPCHeader}"
+OUTPUT ${GeneratedProtoSource} ${GeneratedProtoHeader}
 COMMAND ${PROTOC}
-ARGS --grpc_out="${CMAKE_CURRENT_BINARY_DIR}"
-  --cpp_out="${CMAKE_CURRENT_BINARY_DIR}"
-  --proto_path="${ProtoSourcePath}"
-  --plugin=protoc-gen-grpc="${GRPC_CPP_PLUGIN}"
-  "${ProtoSourceAbsolutePath}"
-  DEPENDS "${ProtoSourceAbsolutePath}")
+ARGS ${Flags} "${ProtoSourceAbsolutePath}"
+DEPENDS "${ProtoSourceAbsolutePath}")
 
-  add_clang_library(${LibraryName} ${GeneratedProtoSource} 
${GeneratedGRPCSource}
+  add_clang_library(${LibraryName} ${GeneratedProtoSource}
 PARTIAL_SOURCES_INTENDED
 LINK_LIBS grpc++ protobuf)
 endfunction()
Index: clang-tools-extra/clangd/index/remote/CMakeLists.txt
===
--- clang-tools-extra/clangd/index/remote/CMakeLists.txt
+++ clang-tools-extra/clangd/index/remote/CMakeLists.txt
@@ -1,5 +1,5 @@
 if (CLANGD_ENABLE_REMOTE)
-  generate_grpc_protos(RemoteIndexProtos "Index.proto")
+  generate_protos(RemoteIndexProtos "Index.proto" GRPC)
   include_directories(${CMAKE_CURRENT_BINARY_DIR})
   include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../)
 


Index: llvm/cmake/modules/FindGRPC.cmake
===
--- llvm/cmake/modules/FindGRPC.cmake
+++ llvm/cmake/modules/FindGRPC.cmake
@@ -83,27 +83,31 @@
 
 # Proto headers are generated in ${CMAKE_CURRENT_BINARY_DIR}.
 # Libraries that use these headers should adjust the include path.
-# FIXME(kirillbobyrev): Allow optional generation of gRPC code and give callers
-# control over it via additional parameters.
-function(generate_grpc_protos LibraryName ProtoFile)
+# If the "GRPC" argument is given, services are also generated.
+function(generate_protos LibraryName ProtoFile)
+  cmake_parse_arguments(PARSE_ARGV 2 PROTO "GRPC" "" "")
   get_filename_component(ProtoSourceAbsolutePath "${CMAKE_CURRENT_SOURCE_DIR}/${ProtoFile}" ABSOLUTE)
   get_filename_component(ProtoSourcePath ${ProtoSourceAbsolutePath} PATH)
 
   set(GeneratedProtoSource "${CMAKE_CURRENT_BINARY_DIR}/Index.pb.cc")
   set(GeneratedProtoHeader "${CMAKE_CURRENT_BINARY_DIR}/Index.pb.h")
-  set(GeneratedGRPCSource "${CMAKE_CURRENT_BINARY_DIR}/Index.grpc.pb.cc")
-  set(GeneratedGRPCHeader "${CMAKE_CURRENT_BINARY_DIR}/Index.grpc.pb.h")
+  set(Flags
+--cpp_out="${CMAKE_CURRENT_BINARY_DIR}"
+--proto_path="${ProtoSourcePath}")
+  if (PROTO_GRPC)
+list(APPEND Flags
+  --grpc_out="${CMAKE_CURRENT_BINARY_DIR}"
+  --plugin=protoc-gen-grpc="${GRPC_CPP_PLUGIN}")
+list(APPEND GeneratedProtoSource "${CMAKE_CURRENT_BINARY_DIR}/Index.grpc.pb.cc")
+list(APPEND GeneratedProtoHeader "${CMAKE_CURRENT_BINARY_DIR}/Index.grpc.pb.h")
+  endif()
   add_custom_command(
-OUTPUT "${

[PATCH] D89882: [clangd] Migrate to proto2 syntax

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



Comment at: 
clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp:118
   Req.IDs = std::move(*IDs);
-  Req.Filter = static_cast(Message->filter());
+  // This sets a default for RefKind. Doing it explicitly in proto definition
+  // is error-prone because clangd::RefKind::All can change unexpectedly.

I don't think this comment is necessary. The code reads clearly and is more 
obvious/natural than the alternative you're arguing against here.



Comment at: 
clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp:137
+  if (!Message->has_predicate())
+return error("RelationnsRequest requires RelationKind predicate.");
   Req.Predicate = static_cast(Message->predicate());

nit: RelationsRequest


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89882

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


[PATCH] D90016: [clangd] NFC: Rely on ADL in llvm::sys::path calls in marshalling

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



Comment at: clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp:30
 
+using llvm::sys::path::append;
+using llvm::sys::path::convert_to_slash;

nit: I would move those into `clang::clangd::remote` (i.e. between `namespace 
remote {` and `namespace {`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90016

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


[clang-tools-extra] 55a2dee - [clang-tidy] Fix redefinition of module in the same module.modulemap file

2020-10-23 Thread Dmitry Polukhin via cfe-commits

Author: Dmitry Polukhin
Date: 2020-10-23T13:20:18+01:00
New Revision: 55a2deed075b87646db62abc7bcd476541eda403

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

LOG: [clang-tidy] Fix redefinition of module in the same module.modulemap file

In memory VFS cannot handle aceesssing the same file with different paths.
This diff just stops using VFS for modulemap files.

Fixes PR47839

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp 
b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
index 4299baedd79f..9e693b62e50d 100644
--- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
+++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
@@ -13,13 +13,22 @@
 #include "clang/Lex/PreprocessorOptions.h"
 #include "clang/Serialization/ASTReader.h"
 
+#define DEBUG_TYPE "clang-tidy"
+
 namespace clang {
 namespace tooling {
 
 class ExpandModularHeadersPPCallbacks::FileRecorder {
 public:
   /// Records that a given file entry is needed for replaying callbacks.
-  void addNecessaryFile(const FileEntry *File) { FilesToRecord.insert(File); }
+  void addNecessaryFile(const FileEntry *File) {
+// Don't record modulemap files because it breaks same file detection.
+if (!(File->getName().endswith("module.modulemap") ||
+  File->getName().endswith("module.private.modulemap") ||
+  File->getName().endswith("module.map") ||
+  File->getName().endswith("module_private.map")))
+  FilesToRecord.insert(File);
+  }
 
   /// Records content for a file and adds it to the FileSystem.
   void recordFileContent(const FileEntry *File,
@@ -44,8 +53,8 @@ class ExpandModularHeadersPPCallbacks::FileRecorder {
   /// `FilesToRecord` should be empty.
   void checkAllFilesRecorded() {
 for (auto FileEntry : FilesToRecord)
-  llvm::errs() << "Did not record contents for input file: "
-   << FileEntry->getName() << "\n";
+  LLVM_DEBUG(llvm::dbgs() << "Did not record contents for input file: "
+  << FileEntry->getName() << "\n");
   }
 
 private:



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


[PATCH] D90031: [clang] Split remote index service definition into a separate file.

2020-10-23 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: kbobyrev.
Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman, mgorny.
Herald added a project: clang.
sammccall requested review of this revision.

This allows it to have a separate namespace (grpc versioned service) without
putting versioning info on all of the other protos (before we need it).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D90031

Files:
  clang-tools-extra/clangd/index/remote/CMakeLists.txt
  clang-tools-extra/clangd/index/remote/Client.cpp
  clang-tools-extra/clangd/index/remote/Index.proto
  clang-tools-extra/clangd/index/remote/Service.proto
  clang-tools-extra/clangd/index/remote/marshalling/CMakeLists.txt
  clang-tools-extra/clangd/index/remote/server/CMakeLists.txt
  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
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "Index.pb.h"
+#include "Service.grpc.pb.h"
 #include "index/Index.h"
 #include "index/Serialization.h"
 #include "index/Symbol.h"
Index: clang-tools-extra/clangd/index/remote/server/CMakeLists.txt
===
--- clang-tools-extra/clangd/index/remote/server/CMakeLists.txt
+++ clang-tools-extra/clangd/index/remote/server/CMakeLists.txt
@@ -5,7 +5,8 @@
   Server.cpp
 
   DEPENDS
-  RemoteIndexProtos
+  RemoteIndexProto
+  RemoteIndexServiceProto
   )
 
 target_link_libraries(clangd-index-server
@@ -13,7 +14,8 @@
   clangDaemon
   clangdSupport
 
-  RemoteIndexProtos
+  RemoteIndexProto
+  RemoteIndexServiceProto
   clangdRemoteMarshalling
 
   grpc++
Index: clang-tools-extra/clangd/index/remote/marshalling/CMakeLists.txt
===
--- clang-tools-extra/clangd/index/remote/marshalling/CMakeLists.txt
+++ clang-tools-extra/clangd/index/remote/marshalling/CMakeLists.txt
@@ -2,12 +2,12 @@
   Marshalling.cpp
 
   LINK_LIBS
-  RemoteIndexProtos
+  RemoteIndexProto
 
   protobuf
   clangDaemon
   clangdSupport
 
   DEPENDS
-  RemoteIndexProtos
+  RemoteIndexProto
   )
Index: clang-tools-extra/clangd/index/remote/Service.proto
===
--- /dev/null
+++ clang-tools-extra/clangd/index/remote/Service.proto
@@ -0,0 +1,26 @@
+//===--- Service.proto - Remote index service definition --===//
+//
+// 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
+//
+//===--===//
+
+syntax = "proto3";
+
+package clang.clangd.remote;
+
+import "Index.proto";
+
+// Semantics of SymbolIndex match clangd::SymbolIndex with all required
+// structures corresponding to their clangd::* counterparts.
+service SymbolIndex {
+  rpc Lookup(LookupRequest) returns (stream LookupReply) {}
+
+  rpc FuzzyFind(FuzzyFindRequest) returns (stream FuzzyFindReply) {}
+
+  rpc Refs(RefsRequest) returns (stream RefsReply) {}
+
+  rpc Relations(RelationsRequest) returns (stream RelationsReply) {}
+}
+
Index: clang-tools-extra/clangd/index/remote/Index.proto
===
--- clang-tools-extra/clangd/index/remote/Index.proto
+++ clang-tools-extra/clangd/index/remote/Index.proto
@@ -10,18 +10,6 @@
 
 package clang.clangd.remote;
 
-// Semantics of SymbolIndex match clangd::SymbolIndex with all required
-// structures corresponding to their clangd::* counterparts.
-service SymbolIndex {
-  rpc Lookup(LookupRequest) returns (stream LookupReply) {}
-
-  rpc FuzzyFind(FuzzyFindRequest) returns (stream FuzzyFindReply) {}
-
-  rpc Refs(RefsRequest) returns (stream RefsReply) {}
-
-  rpc Relations(RelationsRequest) returns (stream RelationsReply) {}
-}
-
 message LookupRequest { repeated string ids = 1; }
 
 // The response is a stream of symbol messages and the terminating message
Index: clang-tools-extra/clangd/index/remote/Client.cpp
===
--- clang-tools-extra/clangd/index/remote/Client.cpp
+++ clang-tools-extra/clangd/index/remote/Client.cpp
@@ -9,7 +9,7 @@
 #include 
 
 #include "Client.h"
-#include "Index.grpc.pb.h"
+#include "Service.grpc.pb.h"
 #include "index/Index.h"
 #include "index/Serialization.h"
 #include "marshalling/Marshalling.h"
Index: clang-tools-extra/clangd/index/remote/CMakeLists.txt
===
--- clang-tools-extra/clangd/index/remote/CMakeLists.txt
+++ clang-tools-extra/clangd/index/

[PATCH] D89886: [clang-tidy] Fix redefinition of module in the same module.modulemap file

2020-10-23 Thread Dmitry Polukhin via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
DmitryPolukhin marked an inline comment as done.
Closed by commit rG55a2deed075b: [clang-tidy] Fix redefinition of module in the 
same module.modulemap file (authored by DmitryPolukhin).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89886

Files:
  clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp


Index: clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
===
--- clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
+++ clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
@@ -13,13 +13,22 @@
 #include "clang/Lex/PreprocessorOptions.h"
 #include "clang/Serialization/ASTReader.h"
 
+#define DEBUG_TYPE "clang-tidy"
+
 namespace clang {
 namespace tooling {
 
 class ExpandModularHeadersPPCallbacks::FileRecorder {
 public:
   /// Records that a given file entry is needed for replaying callbacks.
-  void addNecessaryFile(const FileEntry *File) { FilesToRecord.insert(File); }
+  void addNecessaryFile(const FileEntry *File) {
+// Don't record modulemap files because it breaks same file detection.
+if (!(File->getName().endswith("module.modulemap") ||
+  File->getName().endswith("module.private.modulemap") ||
+  File->getName().endswith("module.map") ||
+  File->getName().endswith("module_private.map")))
+  FilesToRecord.insert(File);
+  }
 
   /// Records content for a file and adds it to the FileSystem.
   void recordFileContent(const FileEntry *File,
@@ -44,8 +53,8 @@
   /// `FilesToRecord` should be empty.
   void checkAllFilesRecorded() {
 for (auto FileEntry : FilesToRecord)
-  llvm::errs() << "Did not record contents for input file: "
-   << FileEntry->getName() << "\n";
+  LLVM_DEBUG(llvm::dbgs() << "Did not record contents for input file: "
+  << FileEntry->getName() << "\n");
   }
 
 private:


Index: clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
===
--- clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
+++ clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
@@ -13,13 +13,22 @@
 #include "clang/Lex/PreprocessorOptions.h"
 #include "clang/Serialization/ASTReader.h"
 
+#define DEBUG_TYPE "clang-tidy"
+
 namespace clang {
 namespace tooling {
 
 class ExpandModularHeadersPPCallbacks::FileRecorder {
 public:
   /// Records that a given file entry is needed for replaying callbacks.
-  void addNecessaryFile(const FileEntry *File) { FilesToRecord.insert(File); }
+  void addNecessaryFile(const FileEntry *File) {
+// Don't record modulemap files because it breaks same file detection.
+if (!(File->getName().endswith("module.modulemap") ||
+  File->getName().endswith("module.private.modulemap") ||
+  File->getName().endswith("module.map") ||
+  File->getName().endswith("module_private.map")))
+  FilesToRecord.insert(File);
+  }
 
   /// Records content for a file and adds it to the FileSystem.
   void recordFileContent(const FileEntry *File,
@@ -44,8 +53,8 @@
   /// `FilesToRecord` should be empty.
   void checkAllFilesRecorded() {
 for (auto FileEntry : FilesToRecord)
-  llvm::errs() << "Did not record contents for input file: "
-   << FileEntry->getName() << "\n";
+  LLVM_DEBUG(llvm::dbgs() << "Did not record contents for input file: "
+  << FileEntry->getName() << "\n");
   }
 
 private:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D90031: [clang] Split remote index service definition into a separate file.

2020-10-23 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev accepted this revision.
kbobyrev added a comment.
This revision is now accepted and ready to land.

LGTM, Thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90031

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


[PATCH] D89882: [clangd] Migrate to proto2 syntax

2020-10-23 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 300246.
kbobyrev added a comment.

Remove unnecessary comment and fix a typo.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89882

Files:
  clang-tools-extra/clangd/index/remote/Index.proto
  clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp

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
@@ -11,6 +11,7 @@
 #include "Index.pb.h"
 #include "Protocol.h"
 #include "index/Index.h"
+#include "index/Ref.h"
 #include "index/Serialization.h"
 #include "index/Symbol.h"
 #include "index/SymbolID.h"
@@ -114,7 +115,10 @@
   if (!IDs)
 return IDs.takeError();
   Req.IDs = std::move(*IDs);
-  Req.Filter = static_cast(Message->filter());
+  if (Message->has_filter())
+Req.Filter = static_cast(Message->filter());
+  else
+Req.Filter = clangd::RefKind::All;
   if (Message->limit())
 Req.Limit = Message->limit();
   return Req;
@@ -127,6 +131,8 @@
   if (!IDs)
 return IDs.takeError();
   Req.Subjects = std::move(*IDs);
+  if (!Message->has_predicate())
+return error("RelationsRequest requires RelationKind predicate.");
   Req.Predicate = static_cast(Message->predicate());
   if (Message->limit())
 Req.Limit = Message->limit();
@@ -180,7 +186,7 @@
   if (!Location)
 return Location.takeError();
   Result.Location = *Location;
-  Result.Kind = static_cast(Message.kind());
+  Result.Kind = static_cast(Message.kind());
   return Result;
 }
 
Index: clang-tools-extra/clangd/index/remote/Index.proto
===
--- clang-tools-extra/clangd/index/remote/Index.proto
+++ clang-tools-extra/clangd/index/remote/Index.proto
@@ -6,12 +6,13 @@
 //
 //===--===//
 
-syntax = "proto3";
+syntax = "proto2";
 
 package clang.clangd.remote.v1;
 
 // Semantics of SymbolIndex match clangd::SymbolIndex with all required
 // structures corresponding to their clangd::* counterparts.
+// NOTE: Enum values are offset by one to detect missing values.
 service SymbolIndex {
   rpc Lookup(LookupRequest) returns (stream LookupReply) {}
 
@@ -34,11 +35,11 @@
 }
 
 message FuzzyFindRequest {
-  string query = 1;
+  optional string query = 1;
   repeated string scopes = 2;
-  bool any_scope = 3;
-  uint32 limit = 4;
-  bool restricted_for_code_completion = 5;
+  optional bool any_scope = 3;
+  optional uint32 limit = 4;
+  optional bool restricted_for_code_completion = 5;
   repeated string proximity_paths = 6;
   repeated string preferred_types = 7;
 }
@@ -54,8 +55,8 @@
 
 message RefsRequest {
   repeated string ids = 1;
-  uint32 filter = 2;
-  uint32 limit = 3;
+  optional uint32 filter = 2;
+  optional uint32 limit = 3;
 }
 
 // The response is a stream of reference messages, and one terminating has_more
@@ -68,59 +69,59 @@
 }
 
 message Symbol {
-  string id = 1;
-  SymbolInfo info = 2;
-  string name = 3;
-  SymbolLocation definition = 4;
-  string scope = 5;
-  SymbolLocation canonical_declaration = 6;
-  int32 references = 7;
-  uint32 origin = 8;
-  string signature = 9;
-  string template_specialization_args = 10;
-  string completion_snippet_suffix = 11;
-  string documentation = 12;
-  string return_type = 13;
-  string type = 14;
+  optional string id = 1;
+  optional SymbolInfo info = 2;
+  optional string name = 3;
+  optional SymbolLocation definition = 4;
+  optional string scope = 5;
+  optional SymbolLocation canonical_declaration = 6;
+  optional int32 references = 7;
+  optional uint32 origin = 8;
+  optional string signature = 9;
+  optional string template_specialization_args = 10;
+  optional string completion_snippet_suffix = 11;
+  optional string documentation = 12;
+  optional string return_type = 13;
+  optional string type = 14;
   repeated HeaderWithReferences headers = 15;
-  uint32 flags = 16;
+  optional uint32 flags = 16;
 }
 
 message Ref {
-  SymbolLocation location = 1;
-  uint32 kind = 2;
+  optional SymbolLocation location = 1;
+  optional uint32 kind = 2;
 }
 
 message SymbolInfo {
-  uint32 kind = 1;
-  uint32 subkind = 2;
-  uint32 language = 3;
-  uint32 properties = 4;
+  optional uint32 kind = 1;
+  optional uint32 subkind = 2;
+  optional uint32 language = 3;
+  optional uint32 properties = 4;
 }
 
 message SymbolLocation {
-  Position start = 1;
-  Position end = 2;
+  optional Position start = 1;
+  optional Position end = 2;
   // clangd::SymbolLocation stores FileURI, but the protocol transmits a the
   // relative path. Because paths are different on the remote and local machines
   // they will be translated in the marshalling layer.
-  string file_path = 3;
+  optional string file_pa

[clang-tools-extra] 421a2a0 - [clangd] Migrate to proto2 syntax

2020-10-23 Thread Kirill Bobyrev via cfe-commits

Author: Kirill Bobyrev
Date: 2020-10-23T14:27:15+02:00
New Revision: 421a2a0dbbd691abeb86dee150cf710a6122e269

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

LOG: [clangd] Migrate to proto2 syntax

This allows us to check whether enum field is actually sent over the wire or 
missing.

Reviewed By: sammccall

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

Added: 


Modified: 
clang-tools-extra/clangd/index/remote/Index.proto
clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/index/remote/Index.proto 
b/clang-tools-extra/clangd/index/remote/Index.proto
index 34c49756b1da..a9ebc75ebc88 100644
--- a/clang-tools-extra/clangd/index/remote/Index.proto
+++ b/clang-tools-extra/clangd/index/remote/Index.proto
@@ -6,12 +6,13 @@
 //
 
//===--===//
 
-syntax = "proto3";
+syntax = "proto2";
 
 package clang.clangd.remote.v1;
 
 // Semantics of SymbolIndex match clangd::SymbolIndex with all required
 // structures corresponding to their clangd::* counterparts.
+// NOTE: Enum values are offset by one to detect missing values.
 service SymbolIndex {
   rpc Lookup(LookupRequest) returns (stream LookupReply) {}
 
@@ -34,11 +35,11 @@ message LookupReply {
 }
 
 message FuzzyFindRequest {
-  string query = 1;
+  optional string query = 1;
   repeated string scopes = 2;
-  bool any_scope = 3;
-  uint32 limit = 4;
-  bool restricted_for_code_completion = 5;
+  optional bool any_scope = 3;
+  optional uint32 limit = 4;
+  optional bool restricted_for_code_completion = 5;
   repeated string proximity_paths = 6;
   repeated string preferred_types = 7;
 }
@@ -54,8 +55,8 @@ message FuzzyFindReply {
 
 message RefsRequest {
   repeated string ids = 1;
-  uint32 filter = 2;
-  uint32 limit = 3;
+  optional uint32 filter = 2;
+  optional uint32 limit = 3;
 }
 
 // The response is a stream of reference messages, and one terminating has_more
@@ -68,59 +69,59 @@ message RefsReply {
 }
 
 message Symbol {
-  string id = 1;
-  SymbolInfo info = 2;
-  string name = 3;
-  SymbolLocation definition = 4;
-  string scope = 5;
-  SymbolLocation canonical_declaration = 6;
-  int32 references = 7;
-  uint32 origin = 8;
-  string signature = 9;
-  string template_specialization_args = 10;
-  string completion_snippet_suffix = 11;
-  string documentation = 12;
-  string return_type = 13;
-  string type = 14;
+  optional string id = 1;
+  optional SymbolInfo info = 2;
+  optional string name = 3;
+  optional SymbolLocation definition = 4;
+  optional string scope = 5;
+  optional SymbolLocation canonical_declaration = 6;
+  optional int32 references = 7;
+  optional uint32 origin = 8;
+  optional string signature = 9;
+  optional string template_specialization_args = 10;
+  optional string completion_snippet_suffix = 11;
+  optional string documentation = 12;
+  optional string return_type = 13;
+  optional string type = 14;
   repeated HeaderWithReferences headers = 15;
-  uint32 flags = 16;
+  optional uint32 flags = 16;
 }
 
 message Ref {
-  SymbolLocation location = 1;
-  uint32 kind = 2;
+  optional SymbolLocation location = 1;
+  optional uint32 kind = 2;
 }
 
 message SymbolInfo {
-  uint32 kind = 1;
-  uint32 subkind = 2;
-  uint32 language = 3;
-  uint32 properties = 4;
+  optional uint32 kind = 1;
+  optional uint32 subkind = 2;
+  optional uint32 language = 3;
+  optional uint32 properties = 4;
 }
 
 message SymbolLocation {
-  Position start = 1;
-  Position end = 2;
+  optional Position start = 1;
+  optional Position end = 2;
   // clangd::SymbolLocation stores FileURI, but the protocol transmits a the
   // relative path. Because paths are 
diff erent on the remote and local machines
   // they will be translated in the marshalling layer.
-  string file_path = 3;
+  optional string file_path = 3;
 }
 
 message Position {
-  uint32 line = 1;
-  uint32 column = 2;
+  optional uint32 line = 1;
+  optional uint32 column = 2;
 }
 
 message HeaderWithReferences {
-  string header = 1;
-  uint32 references = 2;
+  optional string header = 1;
+  optional uint32 references = 2;
 }
 
 message RelationsRequest {
   repeated string subjects = 1;
-  uint32 predicate = 2;
-  uint32 limit = 3;
+  optional uint32 predicate = 2;
+  optional uint32 limit = 3;
 }
 
 // The response is a stream of reference messages, and one terminating has_more
@@ -135,6 +136,6 @@ message RelationsReply {
 // This struct does not mirror clangd::Relation but rather the arguments of
 // SymbolIndex::relations callback.
 message Relation {
-  string subject_id = 1;
-  Symbol object = 2;
+  optional string subject_id = 1;
+  optional Symbol object = 2;
 }

diff  --git a/clang-tools-extra/clangd/ind

[PATCH] D89882: [clangd] Migrate to proto2 syntax

2020-10-23 Thread Kirill Bobyrev via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG421a2a0dbbd6: [clangd] Migrate to proto2 syntax (authored by 
kbobyrev).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89882

Files:
  clang-tools-extra/clangd/index/remote/Index.proto
  clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp

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
@@ -11,6 +11,7 @@
 #include "Index.pb.h"
 #include "Protocol.h"
 #include "index/Index.h"
+#include "index/Ref.h"
 #include "index/Serialization.h"
 #include "index/Symbol.h"
 #include "index/SymbolID.h"
@@ -114,7 +115,10 @@
   if (!IDs)
 return IDs.takeError();
   Req.IDs = std::move(*IDs);
-  Req.Filter = static_cast(Message->filter());
+  if (Message->has_filter())
+Req.Filter = static_cast(Message->filter());
+  else
+Req.Filter = clangd::RefKind::All;
   if (Message->limit())
 Req.Limit = Message->limit();
   return Req;
@@ -127,6 +131,8 @@
   if (!IDs)
 return IDs.takeError();
   Req.Subjects = std::move(*IDs);
+  if (!Message->has_predicate())
+return error("RelationsRequest requires RelationKind predicate.");
   Req.Predicate = static_cast(Message->predicate());
   if (Message->limit())
 Req.Limit = Message->limit();
@@ -180,7 +186,7 @@
   if (!Location)
 return Location.takeError();
   Result.Location = *Location;
-  Result.Kind = static_cast(Message.kind());
+  Result.Kind = static_cast(Message.kind());
   return Result;
 }
 
Index: clang-tools-extra/clangd/index/remote/Index.proto
===
--- clang-tools-extra/clangd/index/remote/Index.proto
+++ clang-tools-extra/clangd/index/remote/Index.proto
@@ -6,12 +6,13 @@
 //
 //===--===//
 
-syntax = "proto3";
+syntax = "proto2";
 
 package clang.clangd.remote.v1;
 
 // Semantics of SymbolIndex match clangd::SymbolIndex with all required
 // structures corresponding to their clangd::* counterparts.
+// NOTE: Enum values are offset by one to detect missing values.
 service SymbolIndex {
   rpc Lookup(LookupRequest) returns (stream LookupReply) {}
 
@@ -34,11 +35,11 @@
 }
 
 message FuzzyFindRequest {
-  string query = 1;
+  optional string query = 1;
   repeated string scopes = 2;
-  bool any_scope = 3;
-  uint32 limit = 4;
-  bool restricted_for_code_completion = 5;
+  optional bool any_scope = 3;
+  optional uint32 limit = 4;
+  optional bool restricted_for_code_completion = 5;
   repeated string proximity_paths = 6;
   repeated string preferred_types = 7;
 }
@@ -54,8 +55,8 @@
 
 message RefsRequest {
   repeated string ids = 1;
-  uint32 filter = 2;
-  uint32 limit = 3;
+  optional uint32 filter = 2;
+  optional uint32 limit = 3;
 }
 
 // The response is a stream of reference messages, and one terminating has_more
@@ -68,59 +69,59 @@
 }
 
 message Symbol {
-  string id = 1;
-  SymbolInfo info = 2;
-  string name = 3;
-  SymbolLocation definition = 4;
-  string scope = 5;
-  SymbolLocation canonical_declaration = 6;
-  int32 references = 7;
-  uint32 origin = 8;
-  string signature = 9;
-  string template_specialization_args = 10;
-  string completion_snippet_suffix = 11;
-  string documentation = 12;
-  string return_type = 13;
-  string type = 14;
+  optional string id = 1;
+  optional SymbolInfo info = 2;
+  optional string name = 3;
+  optional SymbolLocation definition = 4;
+  optional string scope = 5;
+  optional SymbolLocation canonical_declaration = 6;
+  optional int32 references = 7;
+  optional uint32 origin = 8;
+  optional string signature = 9;
+  optional string template_specialization_args = 10;
+  optional string completion_snippet_suffix = 11;
+  optional string documentation = 12;
+  optional string return_type = 13;
+  optional string type = 14;
   repeated HeaderWithReferences headers = 15;
-  uint32 flags = 16;
+  optional uint32 flags = 16;
 }
 
 message Ref {
-  SymbolLocation location = 1;
-  uint32 kind = 2;
+  optional SymbolLocation location = 1;
+  optional uint32 kind = 2;
 }
 
 message SymbolInfo {
-  uint32 kind = 1;
-  uint32 subkind = 2;
-  uint32 language = 3;
-  uint32 properties = 4;
+  optional uint32 kind = 1;
+  optional uint32 subkind = 2;
+  optional uint32 language = 3;
+  optional uint32 properties = 4;
 }
 
 message SymbolLocation {
-  Position start = 1;
-  Position end = 2;
+  optional Position start = 1;
+  optional Position end = 2;
   // clangd::SymbolLocation stores FileURI, but the protocol transmits a the
   // relative path. Because paths are different on the remote and local machines
   

[PATCH] D90027: [CMake] generate_grpc_protos -> generate_protos(... GRPC). NFC

2020-10-23 Thread Sam McCall via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG81f7b2ac0fdc: [CMake] generate_grpc_protos -> 
generate_protos(... GRPC). NFC (authored by sammccall).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90027

Files:
  clang-tools-extra/clangd/index/remote/CMakeLists.txt
  llvm/cmake/modules/FindGRPC.cmake


Index: llvm/cmake/modules/FindGRPC.cmake
===
--- llvm/cmake/modules/FindGRPC.cmake
+++ llvm/cmake/modules/FindGRPC.cmake
@@ -83,27 +83,31 @@
 
 # Proto headers are generated in ${CMAKE_CURRENT_BINARY_DIR}.
 # Libraries that use these headers should adjust the include path.
-# FIXME(kirillbobyrev): Allow optional generation of gRPC code and give callers
-# control over it via additional parameters.
-function(generate_grpc_protos LibraryName ProtoFile)
+# If the "GRPC" argument is given, services are also generated.
+function(generate_protos LibraryName ProtoFile)
+  cmake_parse_arguments(PARSE_ARGV 2 PROTO "GRPC" "" "")
   get_filename_component(ProtoSourceAbsolutePath 
"${CMAKE_CURRENT_SOURCE_DIR}/${ProtoFile}" ABSOLUTE)
   get_filename_component(ProtoSourcePath ${ProtoSourceAbsolutePath} PATH)
 
   set(GeneratedProtoSource "${CMAKE_CURRENT_BINARY_DIR}/Index.pb.cc")
   set(GeneratedProtoHeader "${CMAKE_CURRENT_BINARY_DIR}/Index.pb.h")
-  set(GeneratedGRPCSource "${CMAKE_CURRENT_BINARY_DIR}/Index.grpc.pb.cc")
-  set(GeneratedGRPCHeader "${CMAKE_CURRENT_BINARY_DIR}/Index.grpc.pb.h")
+  set(Flags
+--cpp_out="${CMAKE_CURRENT_BINARY_DIR}"
+--proto_path="${ProtoSourcePath}")
+  if (PROTO_GRPC)
+list(APPEND Flags
+  --grpc_out="${CMAKE_CURRENT_BINARY_DIR}"
+  --plugin=protoc-gen-grpc="${GRPC_CPP_PLUGIN}")
+list(APPEND GeneratedProtoSource 
"${CMAKE_CURRENT_BINARY_DIR}/Index.grpc.pb.cc")
+list(APPEND GeneratedProtoHeader 
"${CMAKE_CURRENT_BINARY_DIR}/Index.grpc.pb.h")
+  endif()
   add_custom_command(
-OUTPUT "${GeneratedProtoSource}" "${GeneratedProtoHeader}" 
"${GeneratedGRPCSource}" "${GeneratedGRPCHeader}"
+OUTPUT ${GeneratedProtoSource} ${GeneratedProtoHeader}
 COMMAND ${PROTOC}
-ARGS --grpc_out="${CMAKE_CURRENT_BINARY_DIR}"
-  --cpp_out="${CMAKE_CURRENT_BINARY_DIR}"
-  --proto_path="${ProtoSourcePath}"
-  --plugin=protoc-gen-grpc="${GRPC_CPP_PLUGIN}"
-  "${ProtoSourceAbsolutePath}"
-  DEPENDS "${ProtoSourceAbsolutePath}")
+ARGS ${Flags} "${ProtoSourceAbsolutePath}"
+DEPENDS "${ProtoSourceAbsolutePath}")
 
-  add_clang_library(${LibraryName} ${GeneratedProtoSource} 
${GeneratedGRPCSource}
+  add_clang_library(${LibraryName} ${GeneratedProtoSource}
 PARTIAL_SOURCES_INTENDED
 LINK_LIBS grpc++ protobuf)
 endfunction()
Index: clang-tools-extra/clangd/index/remote/CMakeLists.txt
===
--- clang-tools-extra/clangd/index/remote/CMakeLists.txt
+++ clang-tools-extra/clangd/index/remote/CMakeLists.txt
@@ -1,5 +1,5 @@
 if (CLANGD_ENABLE_REMOTE)
-  generate_grpc_protos(RemoteIndexProtos "Index.proto")
+  generate_protos(RemoteIndexProtos "Index.proto" GRPC)
   include_directories(${CMAKE_CURRENT_BINARY_DIR})
   include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../)
 


Index: llvm/cmake/modules/FindGRPC.cmake
===
--- llvm/cmake/modules/FindGRPC.cmake
+++ llvm/cmake/modules/FindGRPC.cmake
@@ -83,27 +83,31 @@
 
 # Proto headers are generated in ${CMAKE_CURRENT_BINARY_DIR}.
 # Libraries that use these headers should adjust the include path.
-# FIXME(kirillbobyrev): Allow optional generation of gRPC code and give callers
-# control over it via additional parameters.
-function(generate_grpc_protos LibraryName ProtoFile)
+# If the "GRPC" argument is given, services are also generated.
+function(generate_protos LibraryName ProtoFile)
+  cmake_parse_arguments(PARSE_ARGV 2 PROTO "GRPC" "" "")
   get_filename_component(ProtoSourceAbsolutePath "${CMAKE_CURRENT_SOURCE_DIR}/${ProtoFile}" ABSOLUTE)
   get_filename_component(ProtoSourcePath ${ProtoSourceAbsolutePath} PATH)
 
   set(GeneratedProtoSource "${CMAKE_CURRENT_BINARY_DIR}/Index.pb.cc")
   set(GeneratedProtoHeader "${CMAKE_CURRENT_BINARY_DIR}/Index.pb.h")
-  set(GeneratedGRPCSource "${CMAKE_CURRENT_BINARY_DIR}/Index.grpc.pb.cc")
-  set(GeneratedGRPCHeader "${CMAKE_CURRENT_BINARY_DIR}/Index.grpc.pb.h")
+  set(Flags
+--cpp_out="${CMAKE_CURRENT_BINARY_DIR}"
+--proto_path="${ProtoSourcePath}")
+  if (PROTO_GRPC)
+list(APPEND Flags
+  --grpc_out="${CMAKE_CURRENT_BINARY_DIR}"
+  --plugin=protoc-gen-grpc="${GRPC_CPP_PLUGIN}")
+list(APPEND GeneratedProtoSource "${CMAKE_CURRENT_BINARY_DIR}/I

[clang-tools-extra] 81f7b2a - [CMake] generate_grpc_protos -> generate_protos(... GRPC). NFC

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

Author: Sam McCall
Date: 2020-10-23T14:28:07+02:00
New Revision: 81f7b2ac0fdc84906d31f6824e34103798d3306c

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

LOG: [CMake] generate_grpc_protos -> generate_protos(... GRPC). NFC

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

Added: 


Modified: 
clang-tools-extra/clangd/index/remote/CMakeLists.txt
llvm/cmake/modules/FindGRPC.cmake

Removed: 




diff  --git a/clang-tools-extra/clangd/index/remote/CMakeLists.txt 
b/clang-tools-extra/clangd/index/remote/CMakeLists.txt
index 81287b58afa5..8bd5db543921 100644
--- a/clang-tools-extra/clangd/index/remote/CMakeLists.txt
+++ b/clang-tools-extra/clangd/index/remote/CMakeLists.txt
@@ -1,5 +1,5 @@
 if (CLANGD_ENABLE_REMOTE)
-  generate_grpc_protos(RemoteIndexProtos "Index.proto")
+  generate_protos(RemoteIndexProtos "Index.proto" GRPC)
   include_directories(${CMAKE_CURRENT_BINARY_DIR})
   include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../)
 

diff  --git a/llvm/cmake/modules/FindGRPC.cmake 
b/llvm/cmake/modules/FindGRPC.cmake
index 3e33c2ed8a93..757b16adefac 100644
--- a/llvm/cmake/modules/FindGRPC.cmake
+++ b/llvm/cmake/modules/FindGRPC.cmake
@@ -83,27 +83,31 @@ endif()
 
 # Proto headers are generated in ${CMAKE_CURRENT_BINARY_DIR}.
 # Libraries that use these headers should adjust the include path.
-# FIXME(kirillbobyrev): Allow optional generation of gRPC code and give callers
-# control over it via additional parameters.
-function(generate_grpc_protos LibraryName ProtoFile)
+# If the "GRPC" argument is given, services are also generated.
+function(generate_protos LibraryName ProtoFile)
+  cmake_parse_arguments(PARSE_ARGV 2 PROTO "GRPC" "" "")
   get_filename_component(ProtoSourceAbsolutePath 
"${CMAKE_CURRENT_SOURCE_DIR}/${ProtoFile}" ABSOLUTE)
   get_filename_component(ProtoSourcePath ${ProtoSourceAbsolutePath} PATH)
 
   set(GeneratedProtoSource "${CMAKE_CURRENT_BINARY_DIR}/Index.pb.cc")
   set(GeneratedProtoHeader "${CMAKE_CURRENT_BINARY_DIR}/Index.pb.h")
-  set(GeneratedGRPCSource "${CMAKE_CURRENT_BINARY_DIR}/Index.grpc.pb.cc")
-  set(GeneratedGRPCHeader "${CMAKE_CURRENT_BINARY_DIR}/Index.grpc.pb.h")
+  set(Flags
+--cpp_out="${CMAKE_CURRENT_BINARY_DIR}"
+--proto_path="${ProtoSourcePath}")
+  if (PROTO_GRPC)
+list(APPEND Flags
+  --grpc_out="${CMAKE_CURRENT_BINARY_DIR}"
+  --plugin=protoc-gen-grpc="${GRPC_CPP_PLUGIN}")
+list(APPEND GeneratedProtoSource 
"${CMAKE_CURRENT_BINARY_DIR}/Index.grpc.pb.cc")
+list(APPEND GeneratedProtoHeader 
"${CMAKE_CURRENT_BINARY_DIR}/Index.grpc.pb.h")
+  endif()
   add_custom_command(
-OUTPUT "${GeneratedProtoSource}" "${GeneratedProtoHeader}" 
"${GeneratedGRPCSource}" "${GeneratedGRPCHeader}"
+OUTPUT ${GeneratedProtoSource} ${GeneratedProtoHeader}
 COMMAND ${PROTOC}
-ARGS --grpc_out="${CMAKE_CURRENT_BINARY_DIR}"
-  --cpp_out="${CMAKE_CURRENT_BINARY_DIR}"
-  --proto_path="${ProtoSourcePath}"
-  --plugin=protoc-gen-grpc="${GRPC_CPP_PLUGIN}"
-  "${ProtoSourceAbsolutePath}"
-  DEPENDS "${ProtoSourceAbsolutePath}")
+ARGS ${Flags} "${ProtoSourceAbsolutePath}"
+DEPENDS "${ProtoSourceAbsolutePath}")
 
-  add_clang_library(${LibraryName} ${GeneratedProtoSource} 
${GeneratedGRPCSource}
+  add_clang_library(${LibraryName} ${GeneratedProtoSource}
 PARTIAL_SOURCES_INTENDED
 LINK_LIBS grpc++ protobuf)
 endfunction()



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


[PATCH] D90016: [clangd] NFC: Rely on ADL in llvm::sys::path calls in marshalling

2020-10-23 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 300249.
kbobyrev marked an inline comment as done.
kbobyrev added a comment.

Resolve the comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90016

Files:
  clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp

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
@@ -31,6 +31,12 @@
 namespace clangd {
 namespace remote {
 
+using llvm::sys::path::append;
+using llvm::sys::path::convert_to_slash;
+using llvm::sys::path::is_absolute;
+using llvm::sys::path::replace_path_prefix;
+using llvm::sys::path::Style;
+
 namespace {
 
 template 
@@ -50,24 +56,19 @@
 Marshaller::Marshaller(llvm::StringRef RemoteIndexRoot,
llvm::StringRef LocalIndexRoot)
 : Strings(Arena) {
-  llvm::StringRef PosixSeparator =
-  llvm::sys::path::get_separator(llvm::sys::path::Style::posix);
+  llvm::StringRef PosixSeparator = get_separator(Style::posix);
   if (!RemoteIndexRoot.empty()) {
-assert(llvm::sys::path::is_absolute(RemoteIndexRoot));
-this->RemoteIndexRoot = llvm::sys::path::convert_to_slash(
-RemoteIndexRoot, llvm::sys::path::Style::windows);
+assert(is_absolute(RemoteIndexRoot));
+this->RemoteIndexRoot = convert_to_slash(RemoteIndexRoot, Style::windows);
 llvm::StringRef Path(this->RemoteIndexRoot);
-if (!is_separator(this->RemoteIndexRoot.back(),
-  llvm::sys::path::Style::posix))
+if (!is_separator(this->RemoteIndexRoot.back(), Style::posix))
   this->RemoteIndexRoot += PosixSeparator;
   }
   if (!LocalIndexRoot.empty()) {
-assert(llvm::sys::path::is_absolute(LocalIndexRoot));
-this->LocalIndexRoot = llvm::sys::path::convert_to_slash(
-LocalIndexRoot, llvm::sys::path::Style::windows);
+assert(is_absolute(LocalIndexRoot));
+this->LocalIndexRoot = convert_to_slash(LocalIndexRoot, Style::windows);
 llvm::StringRef Path(this->LocalIndexRoot);
-if (!is_separator(this->LocalIndexRoot.back(),
-  llvm::sys::path::Style::posix))
+if (!is_separator(this->LocalIndexRoot.back(), Style::posix))
   this->LocalIndexRoot += PosixSeparator;
   }
   assert(!RemoteIndexRoot.empty() || !LocalIndexRoot.empty());
@@ -96,7 +97,7 @@
   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);
+append(LocalPath, Path);
 // FuzzyFindRequest requires proximity paths to have platform-native format
 // in order for SymbolIndex to process the query correctly.
 llvm::sys::path::native(LocalPath);
@@ -217,9 +218,9 @@
   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, ""))
-  RPCRequest.add_proximity_paths(llvm::sys::path::convert_to_slash(
-  RelativePath, llvm::sys::path::Style::windows));
+if (replace_path_prefix(RelativePath, LocalIndexRoot, ""))
+  RPCRequest.add_proximity_paths(
+  convert_to_slash(RelativePath, Style::windows));
   }
   for (const auto &Type : From.PreferredTypes)
 RPCRequest.add_preferred_types(Type);
@@ -308,13 +309,13 @@
 llvm::Expected
 Marshaller::relativePathToURI(llvm::StringRef RelativePath) {
   assert(!LocalIndexRoot.empty());
-  assert(RelativePath == llvm::sys::path::convert_to_slash(RelativePath));
+  assert(RelativePath == convert_to_slash(RelativePath));
   if (RelativePath.empty())
 return error("Empty relative path.");
-  if (llvm::sys::path::is_absolute(RelativePath, llvm::sys::path::Style::posix))
+  if (is_absolute(RelativePath, Style::posix))
 return error("RelativePath '{0}' is absolute.", RelativePath);
   llvm::SmallString<256> FullPath = llvm::StringRef(LocalIndexRoot);
-  llvm::sys::path::append(FullPath, RelativePath);
+  append(FullPath, RelativePath);
   auto Result = URI::createFile(FullPath);
   return Result.toString();
 }
@@ -329,14 +330,12 @@
   llvm::SmallString<256> Result = ParsedURI->body();
   llvm::StringRef Path(Result);
   // Check for Windows paths (URI=file:///X:/path => Body=/X:/path)
-  if (llvm::sys::path::is_absolute(Path.substr(1),
-   llvm::sys::path::Style::windows))
+  if (is_absolute(Path.substr(1), Style::windows))
 Result = Path.drop_front();
-  if (!llvm::sys::path::replace_path_prefix(Result, RemoteIndexRoot, ""))
+  if (!replace_path_prefix(Result, RemoteInde

[PATCH] D90016: [clangd] NFC: Add using directives to avoid spelling out llvm::sys::path

2020-10-23 Thread Kirill Bobyrev via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe6c4d880fa8c: [clangd] NFC: Add using directives to avoid 
spelling out llvm::sys::path (authored by kbobyrev).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90016

Files:
  clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp

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
@@ -32,6 +32,12 @@
 namespace clangd {
 namespace remote {
 
+using llvm::sys::path::append;
+using llvm::sys::path::convert_to_slash;
+using llvm::sys::path::is_absolute;
+using llvm::sys::path::replace_path_prefix;
+using llvm::sys::path::Style;
+
 namespace {
 
 template 
@@ -51,24 +57,19 @@
 Marshaller::Marshaller(llvm::StringRef RemoteIndexRoot,
llvm::StringRef LocalIndexRoot)
 : Strings(Arena) {
-  llvm::StringRef PosixSeparator =
-  llvm::sys::path::get_separator(llvm::sys::path::Style::posix);
+  llvm::StringRef PosixSeparator = get_separator(Style::posix);
   if (!RemoteIndexRoot.empty()) {
-assert(llvm::sys::path::is_absolute(RemoteIndexRoot));
-this->RemoteIndexRoot = llvm::sys::path::convert_to_slash(
-RemoteIndexRoot, llvm::sys::path::Style::windows);
+assert(is_absolute(RemoteIndexRoot));
+this->RemoteIndexRoot = convert_to_slash(RemoteIndexRoot, Style::windows);
 llvm::StringRef Path(this->RemoteIndexRoot);
-if (!is_separator(this->RemoteIndexRoot.back(),
-  llvm::sys::path::Style::posix))
+if (!is_separator(this->RemoteIndexRoot.back(), Style::posix))
   this->RemoteIndexRoot += PosixSeparator;
   }
   if (!LocalIndexRoot.empty()) {
-assert(llvm::sys::path::is_absolute(LocalIndexRoot));
-this->LocalIndexRoot = llvm::sys::path::convert_to_slash(
-LocalIndexRoot, llvm::sys::path::Style::windows);
+assert(is_absolute(LocalIndexRoot));
+this->LocalIndexRoot = convert_to_slash(LocalIndexRoot, Style::windows);
 llvm::StringRef Path(this->LocalIndexRoot);
-if (!is_separator(this->LocalIndexRoot.back(),
-  llvm::sys::path::Style::posix))
+if (!is_separator(this->LocalIndexRoot.back(), Style::posix))
   this->LocalIndexRoot += PosixSeparator;
   }
   assert(!RemoteIndexRoot.empty() || !LocalIndexRoot.empty());
@@ -97,7 +98,7 @@
   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);
+append(LocalPath, Path);
 // FuzzyFindRequest requires proximity paths to have platform-native format
 // in order for SymbolIndex to process the query correctly.
 llvm::sys::path::native(LocalPath);
@@ -223,9 +224,9 @@
   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, ""))
-  RPCRequest.add_proximity_paths(llvm::sys::path::convert_to_slash(
-  RelativePath, llvm::sys::path::Style::windows));
+if (replace_path_prefix(RelativePath, LocalIndexRoot, ""))
+  RPCRequest.add_proximity_paths(
+  convert_to_slash(RelativePath, Style::windows));
   }
   for (const auto &Type : From.PreferredTypes)
 RPCRequest.add_preferred_types(Type);
@@ -314,13 +315,13 @@
 llvm::Expected
 Marshaller::relativePathToURI(llvm::StringRef RelativePath) {
   assert(!LocalIndexRoot.empty());
-  assert(RelativePath == llvm::sys::path::convert_to_slash(RelativePath));
+  assert(RelativePath == convert_to_slash(RelativePath));
   if (RelativePath.empty())
 return error("Empty relative path.");
-  if (llvm::sys::path::is_absolute(RelativePath, llvm::sys::path::Style::posix))
+  if (is_absolute(RelativePath, Style::posix))
 return error("RelativePath '{0}' is absolute.", RelativePath);
   llvm::SmallString<256> FullPath = llvm::StringRef(LocalIndexRoot);
-  llvm::sys::path::append(FullPath, RelativePath);
+  append(FullPath, RelativePath);
   auto Result = URI::createFile(FullPath);
   return Result.toString();
 }
@@ -335,14 +336,12 @@
   llvm::SmallString<256> Result = ParsedURI->body();
   llvm::StringRef Path(Result);
   // Check for Windows paths (URI=file:///X:/path => Body=/X:/path)
-  if (llvm::sys::path::is_absolute(Path.substr(1),
-   llvm::sys::path::Style::windows))
+  if (is_absolute(Path.substr(1), Style::windows))
 Result = Path.drop_front()

[clang-tools-extra] e6c4d88 - [clangd] NFC: Add using directives to avoid spelling out llvm::sys::path

2020-10-23 Thread Kirill Bobyrev via cfe-commits

Author: Kirill Bobyrev
Date: 2020-10-23T14:38:31+02:00
New Revision: e6c4d880fa8c1fdb55850cccd5d56050b7f3ecc5

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

LOG: [clangd] NFC: Add using directives to avoid spelling out llvm::sys::path

`llvm::sys::path` is used a lot in the remote index marshalling code. We can 
save space by avoiding spelling it out explicitly for most functions and times.

Reviewed By: kadircet

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

Added: 


Modified: 
clang-tools-extra/clangd/index/remote/marshalling/Marshalling.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 1945d9142f126..598d9434023fe 100644
--- a/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
+++ b/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
@@ -32,6 +32,12 @@ namespace clang {
 namespace clangd {
 namespace remote {
 
+using llvm::sys::path::append;
+using llvm::sys::path::convert_to_slash;
+using llvm::sys::path::is_absolute;
+using llvm::sys::path::replace_path_prefix;
+using llvm::sys::path::Style;
+
 namespace {
 
 template 
@@ -51,24 +57,19 @@ llvm::Expected> getIDs(IDRange 
IDs) {
 Marshaller::Marshaller(llvm::StringRef RemoteIndexRoot,
llvm::StringRef LocalIndexRoot)
 : Strings(Arena) {
-  llvm::StringRef PosixSeparator =
-  llvm::sys::path::get_separator(llvm::sys::path::Style::posix);
+  llvm::StringRef PosixSeparator = get_separator(Style::posix);
   if (!RemoteIndexRoot.empty()) {
-assert(llvm::sys::path::is_absolute(RemoteIndexRoot));
-this->RemoteIndexRoot = llvm::sys::path::convert_to_slash(
-RemoteIndexRoot, llvm::sys::path::Style::windows);
+assert(is_absolute(RemoteIndexRoot));
+this->RemoteIndexRoot = convert_to_slash(RemoteIndexRoot, Style::windows);
 llvm::StringRef Path(this->RemoteIndexRoot);
-if (!is_separator(this->RemoteIndexRoot.back(),
-  llvm::sys::path::Style::posix))
+if (!is_separator(this->RemoteIndexRoot.back(), Style::posix))
   this->RemoteIndexRoot += PosixSeparator;
   }
   if (!LocalIndexRoot.empty()) {
-assert(llvm::sys::path::is_absolute(LocalIndexRoot));
-this->LocalIndexRoot = llvm::sys::path::convert_to_slash(
-LocalIndexRoot, llvm::sys::path::Style::windows);
+assert(is_absolute(LocalIndexRoot));
+this->LocalIndexRoot = convert_to_slash(LocalIndexRoot, Style::windows);
 llvm::StringRef Path(this->LocalIndexRoot);
-if (!is_separator(this->LocalIndexRoot.back(),
-  llvm::sys::path::Style::posix))
+if (!is_separator(this->LocalIndexRoot.back(), Style::posix))
   this->LocalIndexRoot += PosixSeparator;
   }
   assert(!RemoteIndexRoot.empty() || !LocalIndexRoot.empty());
@@ -97,7 +98,7 @@ Marshaller::fromProtobuf(const v1::FuzzyFindRequest *Message) 
{
   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);
+append(LocalPath, Path);
 // FuzzyFindRequest requires proximity paths to have platform-native format
 // in order for SymbolIndex to process the query correctly.
 llvm::sys::path::native(LocalPath);
@@ -223,9 +224,9 @@ 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, ""))
-  RPCRequest.add_proximity_paths(llvm::sys::path::convert_to_slash(
-  RelativePath, llvm::sys::path::Style::windows));
+if (replace_path_prefix(RelativePath, LocalIndexRoot, ""))
+  RPCRequest.add_proximity_paths(
+  convert_to_slash(RelativePath, Style::windows));
   }
   for (const auto &Type : From.PreferredTypes)
 RPCRequest.add_preferred_types(Type);
@@ -314,13 +315,13 @@ Marshaller::toProtobuf(const clangd::SymbolID &Subject,
 llvm::Expected
 Marshaller::relativePathToURI(llvm::StringRef RelativePath) {
   assert(!LocalIndexRoot.empty());
-  assert(RelativePath == llvm::sys::path::convert_to_slash(RelativePath));
+  assert(RelativePath == convert_to_slash(RelativePath));
   if (RelativePath.empty())
 return error("Empty relative path.");
-  if (llvm::sys::path::is_absolute(RelativePath, 
llvm::sys::path::Style::posix))
+  if (is_absolute(RelativePath, Style::posix))
 return error("RelativePath '{0}' is absolute.

[PATCH] D90031: [clang] Split remote index service definition into a separate file.

2020-10-23 Thread Sam McCall via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe6c1c3f97f13: [clang] Split remote index service definition 
into a separate file. (authored by sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D90031?vs=300243&id=300261#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90031

Files:
  clang-tools-extra/clangd/index/remote/CMakeLists.txt
  clang-tools-extra/clangd/index/remote/Client.cpp
  clang-tools-extra/clangd/index/remote/Index.proto
  clang-tools-extra/clangd/index/remote/Service.proto
  clang-tools-extra/clangd/index/remote/marshalling/CMakeLists.txt
  clang-tools-extra/clangd/index/remote/server/CMakeLists.txt
  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
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "Index.pb.h"
+#include "Service.grpc.pb.h"
 #include "index/Index.h"
 #include "index/Serialization.h"
 #include "index/Symbol.h"
Index: clang-tools-extra/clangd/index/remote/server/CMakeLists.txt
===
--- clang-tools-extra/clangd/index/remote/server/CMakeLists.txt
+++ clang-tools-extra/clangd/index/remote/server/CMakeLists.txt
@@ -5,7 +5,8 @@
   Server.cpp
 
   DEPENDS
-  RemoteIndexProtos
+  RemoteIndexProto
+  RemoteIndexServiceProto
   )
 
 target_link_libraries(clangd-index-server
@@ -13,7 +14,8 @@
   clangDaemon
   clangdSupport
 
-  RemoteIndexProtos
+  RemoteIndexProto
+  RemoteIndexServiceProto
   clangdRemoteMarshalling
 
   grpc++
Index: clang-tools-extra/clangd/index/remote/marshalling/CMakeLists.txt
===
--- clang-tools-extra/clangd/index/remote/marshalling/CMakeLists.txt
+++ clang-tools-extra/clangd/index/remote/marshalling/CMakeLists.txt
@@ -2,12 +2,12 @@
   Marshalling.cpp
 
   LINK_LIBS
-  RemoteIndexProtos
+  RemoteIndexProto
 
   protobuf
   clangDaemon
   clangdSupport
 
   DEPENDS
-  RemoteIndexProtos
+  RemoteIndexProto
   )
Index: clang-tools-extra/clangd/index/remote/Service.proto
===
--- /dev/null
+++ clang-tools-extra/clangd/index/remote/Service.proto
@@ -0,0 +1,26 @@
+//===--- Service.proto - Remote index service definition --===//
+//
+// 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
+//
+//===--===//
+
+syntax = "proto2";
+
+package clang.clangd.remote.v1;
+
+import "Index.proto";
+
+// Semantics of SymbolIndex match clangd::SymbolIndex with all required
+// structures corresponding to their clangd::* counterparts.
+service SymbolIndex {
+  rpc Lookup(LookupRequest) returns (stream LookupReply) {}
+
+  rpc FuzzyFind(FuzzyFindRequest) returns (stream FuzzyFindReply) {}
+
+  rpc Refs(RefsRequest) returns (stream RefsReply) {}
+
+  rpc Relations(RelationsRequest) returns (stream RelationsReply) {}
+}
+
Index: clang-tools-extra/clangd/index/remote/Index.proto
===
--- clang-tools-extra/clangd/index/remote/Index.proto
+++ clang-tools-extra/clangd/index/remote/Index.proto
@@ -10,19 +10,6 @@
 
 package clang.clangd.remote.v1;
 
-// Semantics of SymbolIndex match clangd::SymbolIndex with all required
-// structures corresponding to their clangd::* counterparts.
-// NOTE: Enum values are offset by one to detect missing values.
-service SymbolIndex {
-  rpc Lookup(LookupRequest) returns (stream LookupReply) {}
-
-  rpc FuzzyFind(FuzzyFindRequest) returns (stream FuzzyFindReply) {}
-
-  rpc Refs(RefsRequest) returns (stream RefsReply) {}
-
-  rpc Relations(RelationsRequest) returns (stream RelationsReply) {}
-}
-
 message LookupRequest { repeated string ids = 1; }
 
 // The response is a stream of symbol messages and the terminating message
Index: clang-tools-extra/clangd/index/remote/Client.cpp
===
--- clang-tools-extra/clangd/index/remote/Client.cpp
+++ clang-tools-extra/clangd/index/remote/Client.cpp
@@ -9,7 +9,7 @@
 #include 
 
 #include "Client.h"
-#include "Index.grpc.pb.h"
+#include "Service.grpc.pb.h"
 #include "index/Index.h"
 #include "index/Serialization.h"
 #include "marshalling/Marshalling.h"
Index: clang-tools-extra/clangd/index/remote/CMakeLists.txt
=

[clang-tools-extra] e6c1c3f - [clang] Split remote index service definition into a separate file.

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

Author: Sam McCall
Date: 2020-10-23T15:20:51+02:00
New Revision: e6c1c3f97f13b7d973fa786a3f2da883fa31bdf6

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

LOG: [clang] Split remote index service definition into a separate file.

This allows it to have a separate namespace (grpc versioned service) without
putting versioning info on all of the other protos (before we need it).

clang-index-server is still broken (from 81e5f298c431555).

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

Added: 
clang-tools-extra/clangd/index/remote/Service.proto

Modified: 
clang-tools-extra/clangd/index/remote/CMakeLists.txt
clang-tools-extra/clangd/index/remote/Client.cpp
clang-tools-extra/clangd/index/remote/Index.proto
clang-tools-extra/clangd/index/remote/marshalling/CMakeLists.txt
clang-tools-extra/clangd/index/remote/server/CMakeLists.txt
clang-tools-extra/clangd/index/remote/server/Server.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/index/remote/CMakeLists.txt 
b/clang-tools-extra/clangd/index/remote/CMakeLists.txt
index 8bd5db543921..94f5699b42d6 100644
--- a/clang-tools-extra/clangd/index/remote/CMakeLists.txt
+++ b/clang-tools-extra/clangd/index/remote/CMakeLists.txt
@@ -1,5 +1,6 @@
 if (CLANGD_ENABLE_REMOTE)
-  generate_protos(RemoteIndexProtos "Index.proto" GRPC)
+  generate_protos(RemoteIndexServiceProto "Service.proto" GRPC)
+  generate_protos(RemoteIndexProto "Index.proto")
   include_directories(${CMAKE_CURRENT_BINARY_DIR})
   include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../)
 
@@ -12,7 +13,8 @@ if (CLANGD_ENABLE_REMOTE)
 Client.cpp
 
 LINK_LIBS
-RemoteIndexProtos
+RemoteIndexProto
+RemoteIndexServiceProto
 clangdRemoteMarshalling
 
 protobuf
@@ -21,7 +23,8 @@ if (CLANGD_ENABLE_REMOTE)
 clangdSupport
 
 DEPENDS
-RemoteIndexProtos
+RemoteIndexProto
+RemoteIndexServiceProto
 )
 
   add_subdirectory(marshalling)

diff  --git a/clang-tools-extra/clangd/index/remote/Client.cpp 
b/clang-tools-extra/clangd/index/remote/Client.cpp
index d01dd4483974..a134d9c72932 100644
--- a/clang-tools-extra/clangd/index/remote/Client.cpp
+++ b/clang-tools-extra/clangd/index/remote/Client.cpp
@@ -9,7 +9,7 @@
 #include 
 
 #include "Client.h"
-#include "Index.grpc.pb.h"
+#include "Service.grpc.pb.h"
 #include "index/Index.h"
 #include "index/Serialization.h"
 #include "marshalling/Marshalling.h"

diff  --git a/clang-tools-extra/clangd/index/remote/Index.proto 
b/clang-tools-extra/clangd/index/remote/Index.proto
index a9ebc75ebc88..654d1eb750f0 100644
--- a/clang-tools-extra/clangd/index/remote/Index.proto
+++ b/clang-tools-extra/clangd/index/remote/Index.proto
@@ -10,19 +10,6 @@ syntax = "proto2";
 
 package clang.clangd.remote.v1;
 
-// Semantics of SymbolIndex match clangd::SymbolIndex with all required
-// structures corresponding to their clangd::* counterparts.
-// NOTE: Enum values are offset by one to detect missing values.
-service SymbolIndex {
-  rpc Lookup(LookupRequest) returns (stream LookupReply) {}
-
-  rpc FuzzyFind(FuzzyFindRequest) returns (stream FuzzyFindReply) {}
-
-  rpc Refs(RefsRequest) returns (stream RefsReply) {}
-
-  rpc Relations(RelationsRequest) returns (stream RelationsReply) {}
-}
-
 message LookupRequest { repeated string ids = 1; }
 
 // The response is a stream of symbol messages and the terminating message

diff  --git a/clang-tools-extra/clangd/index/remote/Service.proto 
b/clang-tools-extra/clangd/index/remote/Service.proto
new file mode 100644
index ..4e39ff9ec666
--- /dev/null
+++ b/clang-tools-extra/clangd/index/remote/Service.proto
@@ -0,0 +1,26 @@
+//===--- Service.proto - Remote index service definition 
--===//
+//
+// 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
+//
+//===--===//
+
+syntax = "proto2";
+
+package clang.clangd.remote.v1;
+
+import "Index.proto";
+
+// Semantics of SymbolIndex match clangd::SymbolIndex with all required
+// structures corresponding to their clangd::* counterparts.
+service SymbolIndex {
+  rpc Lookup(LookupRequest) returns (stream LookupReply) {}
+
+  rpc FuzzyFind(FuzzyFindRequest) returns (stream FuzzyFindReply) {}
+
+  rpc Refs(RefsRequest) returns (stream RefsReply) {}
+
+  rpc Relations(RelationsRequest) returns (stream RelationsReply) {}
+}
+

diff  --git a/clang-tools-extra/clangd/index/remote/marshalling/CMakeLists.txt 
b/clang-tools-extra/clangd/index/remote/marshalling/CMakeLists.txt
index 75e57edd45d9..7b78ba3bb690 100644
--- a/clang-tools-extra/clangd/index/remote/marshall

[PATCH] D89994: [libomptarget][nvptx] Undef, internal shared variables

2020-10-23 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp:2858
 TransferMedium = new llvm::GlobalVariable(
-M, Ty, /*isConstant=*/false, llvm::GlobalVariable::CommonLinkage,
-llvm::Constant::getNullValue(Ty), TransferMediumName,
+M, Ty, /*isConstant=*/false, llvm::GlobalVariable::InternalLinkage,
+llvm::UndefValue::get(Ty), TransferMediumName,

"Internalization" is not the best option, it increases mem pressure. Common 
linkage is a better choice, allows to "squash" the same objects, defined in 
different units. Make it arch dependable, maybe?
For NVPTX zero initialization is not a problem, it is resolved when PTX is 
generated.



Comment at: clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp:4794
   CGM.getModule(), LLVMStaticTy,
-  /*isConstant=*/false, llvm::GlobalValue::CommonLinkage,
-  llvm::Constant::getNullValue(LLVMStaticTy),
+  /*isConstant=*/false, llvm::GlobalValue::InternalLinkage,
+  llvm::UndefValue::get(LLVMStaticTy),

JonChesterfield wrote:
> Perhaps weak_any + undef?
> 
> Could use internal for symbols that may vary in size and weak_any for those 
> that don't.
Yeah, it is a good idea, I think.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89994

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


[PATCH] D89832: [CUDA] Extract CUDA version from cuda.h if version.txt is not found

2020-10-23 Thread Evgeny Mankov via Phabricator via cfe-commits
emankov added a comment.

I confirm that D89752  eliminates 47332 
 on Windows. Tested against the 
following CUDA versions: 7.0, 7,5, 9,2, 10.0, 10,1, 10.2, 11.0 Update 1, 11.1.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89832

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


[PATCH] D86671: [clang-tidy] Add new case type to check variables with Hungarian notation

2020-10-23 Thread Douglas Chen via Phabricator via cfe-commits
dougpuob added a comment.

Hi @aaron.ballman,

Thank you for the suggestion.




Comment at: 
clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp:237
+static void getHungarianNotationDefaultConfig(
+std::shared_ptr HNOption) {
+

aaron.ballman wrote:
> It seems like this function should take `HNOption` as a reference rather than 
> a `shared_ptr`.
OK!



Comment at: clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h:87
+HungarianPrefixOption HungarianPrefixOpt;
+std::shared_ptr
+HungarianNotationOption;

aaron.ballman wrote:
> I'd like to avoid using a `shared_ptr` here if we can avoid it -- do we 
> expect this to be super expensive to copy by value (I would imagine it'll be 
> an expensive copy but we don't make copies all that often, but maybe my 
> intuition is wrong)?
Good idea. A reference object is good enough. I will change it at next commit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86671

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


[clang-tools-extra] ce63383 - [clangd] Drop version from remote index proto names, fix clangd-index-server

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

Author: Sam McCall
Date: 2020-10-23T15:28:11+02:00
New Revision: ce63383e45f4c833dbff6a89b242bfd1d188786e

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

LOG: [clangd] Drop version from remote index proto names, fix 
clangd-index-server

We only need to version these messages if they actually diverge.
Unlike the service, the namespace name isn't part of the wire format.

clangd-index-server was broken by 81e5f298c431555d809f898c196945ca879c1150
as the namespace names weren't updated there, this fixes it (by adding
them for the service, and not requiring them elsewhere).

Added: 


Modified: 
clang-tools-extra/clangd/index/remote/Index.proto
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/Index.proto 
b/clang-tools-extra/clangd/index/remote/Index.proto
index 654d1eb750f0..7619d0cb2ef3 100644
--- a/clang-tools-extra/clangd/index/remote/Index.proto
+++ b/clang-tools-extra/clangd/index/remote/Index.proto
@@ -8,7 +8,7 @@
 
 syntax = "proto2";
 
-package clang.clangd.remote.v1;
+package clang.clangd.remote;
 
 message LookupRequest { repeated string ids = 1; }
 

diff  --git a/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp 
b/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
index 598d9434023f..296f99cdfa38 100644
--- a/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
+++ b/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
@@ -76,7 +76,7 @@ Marshaller::Marshaller(llvm::StringRef RemoteIndexRoot,
 }
 
 llvm::Expected
-Marshaller::fromProtobuf(const v1::LookupRequest *Message) {
+Marshaller::fromProtobuf(const LookupRequest *Message) {
   clangd::LookupRequest Req;
   auto IDs = getIDs(Message->ids());
   if (!IDs)
@@ -86,7 +86,7 @@ Marshaller::fromProtobuf(const v1::LookupRequest *Message) {
 }
 
 llvm::Expected
-Marshaller::fromProtobuf(const v1::FuzzyFindRequest *Message) {
+Marshaller::fromProtobuf(const FuzzyFindRequest *Message) {
   assert(!RemoteIndexRoot.empty());
   clangd::FuzzyFindRequest Result;
   Result.Query = Message->query();
@@ -110,7 +110,7 @@ Marshaller::fromProtobuf(const v1::FuzzyFindRequest 
*Message) {
 }
 
 llvm::Expected
-Marshaller::fromProtobuf(const v1::RefsRequest *Message) {
+Marshaller::fromProtobuf(const RefsRequest *Message) {
   clangd::RefsRequest Req;
   auto IDs = getIDs(Message->ids());
   if (!IDs)
@@ -126,7 +126,7 @@ Marshaller::fromProtobuf(const v1::RefsRequest *Message) {
 }
 
 llvm::Expected
-Marshaller::fromProtobuf(const v1::RelationsRequest *Message) {
+Marshaller::fromProtobuf(const RelationsRequest *Message) {
   clangd::RelationsRequest Req;
   auto IDs = getIDs(Message->subjects());
   if (!IDs)
@@ -140,8 +140,7 @@ Marshaller::fromProtobuf(const v1::RelationsRequest 
*Message) {
   return Req;
 }
 
-llvm::Expected
-Marshaller::fromProtobuf(const v1::Symbol &Message) {
+llvm::Expected Marshaller::fromProtobuf(const Symbol &Message) 
{
   if (!Message.has_info() || !Message.has_canonical_declaration())
 return error("Missing info or declaration.");
   clangd::Symbol Result;
@@ -179,7 +178,7 @@ Marshaller::fromProtobuf(const v1::Symbol &Message) {
   return Result;
 }
 
-llvm::Expected Marshaller::fromProtobuf(const v1::Ref &Message) {
+llvm::Expected Marshaller::fromProtobuf(const Ref &Message) {
   if (!Message.has_location())
 return error("Missing location.");
   clangd::Ref Result;
@@ -192,7 +191,7 @@ llvm::Expected Marshaller::fromProtobuf(const 
v1::Ref &Message) {
 }
 
 llvm::Expected>
-Marshaller::fromProtobuf(const v1::Relation &Message) {
+Marshaller::fromProtobuf(const Relation &Message) {
   auto SubjectID = SymbolID::fromStr(Message.subject_id());
   if (!SubjectID)
 return SubjectID.takeError();
@@ -204,17 +203,16 @@ Marshaller::fromProtobuf(const v1::Relation &Message) {
   return std::make_pair(*SubjectID, *Object);
 }
 
-v1::LookupRequest Marshaller::toProtobuf(const clangd::LookupRequest &From) {
-  v1::LookupRequest RPCRequest;
+LookupRequest Marshaller::toProtobuf(const clangd::LookupRequest &From) {
+  LookupRequest RPCRequest;
   for (const auto &SymbolID : From.IDs)
 RPCRequest.add_ids(SymbolID.str());
   return RPCRequest;
 }
 
-v1::FuzzyFindRequest
-Marshaller::toProtobuf(const clangd::FuzzyFindRequest &From) {
+FuzzyFindRequest Marshaller::toProtobuf(const clangd::FuzzyFindRequest &From) {
   assert(!LocalIndexRoot.empty());
-  v1::FuzzyFindRequest RPCRequest;
+  FuzzyFindRequest RPCRequest;
   RPCRequest.set_query(From.Query);
   for (const auto 

[PATCH] D89987: [analyzer] [NFC] Rename SymbolRef to SymExprRef

2020-10-23 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment.

@OikawaKirie

> Different from ProgramStateRef which is an alias to IntrusiveRefCntPtr, or 
> StoreRef which is a wrapper object, an alias to a const SymExpr * makes no 
> sense to me.

Yes. I omit this, because in such case we should go further and rename all 
those which are not real `Ref` to `Ptr` or smth that would emphasise that it's 
just a pointer alias, not a wrapper or another class.
That's why I prefered to change the name a little in favor of complex approach 
of renaming all the rest.

> And this is also where I have been confused for a long while.

So have been I. The patch is called to make it more clear :)

Thanks to @steakhal comment I investigated more in terms of what other names 
use `Symbol` but mean `SymExpr`. They are:

  class SymbolManager;
  using SymbolID;
  using SymbolDependTy;
  class SymbolData;
  class SymbolMetadata;
  class SymbolReaper;
  enum SymbolStatus;
  using SymbolSetTy;
  using SymbolMapTy;
  class SymbolCast;
  class SymbolVal;
  class symbol_iterator;
  etc.

This is not a full list! I also didn't count //methods// and //file names//.
There is also a list of objects names which straightly use `SymExpr`. They are 
less spread. Mostly they a derived classes:

  class BinarySymExprImpl;
  class SymIntExpr;
  class IntSymExpr;
  class SymSymExpr;
  some enums, several methods, etc.

As a result we whould accurately define the difference between `Symbol` and 
`SymExpr`.
I see the next options:

1. `Symbol` and `SymExpr` are different. Leave the names as are. Fix minor 
mismatches if presented. And follow that definitions.
2. `Symbol` and `SymExpr` are the same. `SymExpr` is a dominant one. Change all 
the names from `Symbol` to `SymExpr` and get rid of `Symbol`.
3. `Symbol` and `SymExpr` are the same. `Symbol` is a dominant one. Change all 
the names from `SymExpr` to `Symbol` and get rid of `SymExpr`.
4. Ignore the naming due to loss of **git blame** (or any other reason) like in 
an llvm naming rules topic.
5. For now just rename `SymbolRef` alias as the beggining of the story in scope 
of 2nd option.

What do you think?




Comment at: clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymExpr.h:111
+using SymExprRef = const SymExpr *;
+using SymbolRefSmallVectorTy = SmallVector;
 using SymbolID = unsigned;

steakhal wrote:
> `SymbolRefSmallVectorTy` -> `SymExprRefSmallVectorTy`
Thanks for a reasonable remark!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89987

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


[PATCH] D90042: [clang-tidy] performance-unnecessary-copy-initialization: Check for const reference arguments that are replaced template parameter type.

2020-10-23 Thread Felix Berger via Phabricator via cfe-commits
flx created this revision.
flx added reviewers: aaron.ballman, gribozavr2.
Herald added subscribers: cfe-commits, xazax.hun.
Herald added a project: clang.
flx requested review of this revision.

This fixes false positive cases where a non-const reference is passed to a
std::function but interpreted as a const reference.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D90042

Files:
  clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
  
clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s performance-unnecessary-copy-initialization %t
+// RUN: %check_clang_tidy -std=c++17 %s 
performance-unnecessary-copy-initialization %t
 
 struct ExpensiveToCopyType {
   ExpensiveToCopyType();
@@ -411,12 +411,12 @@
 
 template 
 class function;
-template 
-class function {
+template 
+class function {
 public:
   function();
-  function(const function &other);
-  R operator()(Args &&...args) const;
+  function(const function &Other);
+  R operator()(ArgTypes &&...Args) const;
 };
 
 } // namespace __1
@@ -460,3 +460,19 @@
 }
 
 } // namespace fake
+
+void positiveInvokedOnStdFunction(
+std::function Update,
+const ExpensiveToCopyType Orig) {
+  auto Copy = Orig.reference();
+  // CHECK-MESSAGES: [[@LINE-1]]:8: warning: the variable 'Copy' is 
copy-constructed from a const reference
+  // CHECK-FIXES: const auto& Copy = Orig.reference();
+  Update(Copy);
+}
+
+void negativeInvokedOnStdFunction(
+std::function Update,
+const ExpensiveToCopyType Orig) {
+  auto Copy = Orig.reference();
+  Update(Copy);
+}
Index: clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
===
--- clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
+++ clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
@@ -57,11 +57,15 @@
   Stmt, Context);
   SmallPtrSet DeclRefs;
   extractNodesByIdTo(Matches, "declRef", DeclRefs);
-  auto ConstReferenceOrValue =
-  qualType(anyOf(referenceType(pointee(qualType(isConstQualified(,
- unless(anyOf(referenceType(), pointerType();
+  auto ConstReferenceOrValue = qualType(
+  anyOf(referenceType(pointee(qualType(isConstQualified(,
+unless(anyOf(referenceType(),
+ pointerType() /*, substTemplateTypeParmType()*/;
+  auto ConstReferenceOrValueOrReplaced = qualType(anyOf(
+  ConstReferenceOrValue,
+  substTemplateTypeParmType(hasReplacementType(ConstReferenceOrValue;
   auto UsedAsConstRefOrValueArg = forEachArgumentWithParam(
-  DeclRefToVar, parmVarDecl(hasType(ConstReferenceOrValue)));
+  DeclRefToVar, parmVarDecl(hasType(ConstReferenceOrValueOrReplaced)));
   Matches = match(findAll(callExpr(UsedAsConstRefOrValueArg)), Stmt, Context);
   extractNodesByIdTo(Matches, "declRef", DeclRefs);
   Matches =


Index: clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s performance-unnecessary-copy-initialization %t
+// RUN: %check_clang_tidy -std=c++17 %s performance-unnecessary-copy-initialization %t
 
 struct ExpensiveToCopyType {
   ExpensiveToCopyType();
@@ -411,12 +411,12 @@
 
 template 
 class function;
-template 
-class function {
+template 
+class function {
 public:
   function();
-  function(const function &other);
-  R operator()(Args &&...args) const;
+  function(const function &Other);
+  R operator()(ArgTypes &&...Args) const;
 };
 
 } // namespace __1
@@ -460,3 +460,19 @@
 }
 
 } // namespace fake
+
+void positiveInvokedOnStdFunction(
+std::function Update,
+const ExpensiveToCopyType Orig) {
+  auto Copy = Orig.reference();
+  // CHECK-MESSAGES: [[@LINE-1]]:8: warning: the variable 'Copy' is copy-constructed from a const reference
+  // CHECK-FIXES: const auto& Copy = Orig.reference();
+  Update(Copy);
+}
+
+void negativeInvokedOnStdFunction(
+std::function Update,
+const ExpensiveToCopyType Orig) {
+  auto Copy = Orig.reference();
+  Update(Copy);
+}
Index: clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
===
--- clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
+++ clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
@@ -57,11 +57

[PATCH] D90042: [clang-tidy] performance-unnecessary-copy-initialization: Check for const reference arguments that are replaced template parameter type.

2020-10-23 Thread Felix Berger via Phabricator via cfe-commits
flx updated this revision to Diff 300274.
flx added a comment.

Remove code comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90042

Files:
  clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
  
clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s performance-unnecessary-copy-initialization %t
+// RUN: %check_clang_tidy -std=c++17 %s 
performance-unnecessary-copy-initialization %t
 
 struct ExpensiveToCopyType {
   ExpensiveToCopyType();
@@ -411,12 +411,12 @@
 
 template 
 class function;
-template 
-class function {
+template 
+class function {
 public:
   function();
-  function(const function &other);
-  R operator()(Args &&...args) const;
+  function(const function &Other);
+  R operator()(ArgTypes &&...Args) const;
 };
 
 } // namespace __1
@@ -460,3 +460,19 @@
 }
 
 } // namespace fake
+
+void positiveInvokedOnStdFunction(
+std::function Update,
+const ExpensiveToCopyType Orig) {
+  auto Copy = Orig.reference();
+  // CHECK-MESSAGES: [[@LINE-1]]:8: warning: the variable 'Copy' is 
copy-constructed from a const reference
+  // CHECK-FIXES: const auto& Copy = Orig.reference();
+  Update(Copy);
+}
+
+void negativeInvokedOnStdFunction(
+std::function Update,
+const ExpensiveToCopyType Orig) {
+  auto Copy = Orig.reference();
+  Update(Copy);
+}
Index: clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
===
--- clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
+++ clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
@@ -59,9 +59,13 @@
   extractNodesByIdTo(Matches, "declRef", DeclRefs);
   auto ConstReferenceOrValue =
   qualType(anyOf(referenceType(pointee(qualType(isConstQualified(,
- unless(anyOf(referenceType(), pointerType();
+ unless(anyOf(referenceType(), pointerType(),
+  substTemplateTypeParmType();
+  auto ConstReferenceOrValueOrReplaced = qualType(anyOf(
+  ConstReferenceOrValue,
+  substTemplateTypeParmType(hasReplacementType(ConstReferenceOrValue;
   auto UsedAsConstRefOrValueArg = forEachArgumentWithParam(
-  DeclRefToVar, parmVarDecl(hasType(ConstReferenceOrValue)));
+  DeclRefToVar, parmVarDecl(hasType(ConstReferenceOrValueOrReplaced)));
   Matches = match(findAll(callExpr(UsedAsConstRefOrValueArg)), Stmt, Context);
   extractNodesByIdTo(Matches, "declRef", DeclRefs);
   Matches =


Index: clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s performance-unnecessary-copy-initialization %t
+// RUN: %check_clang_tidy -std=c++17 %s performance-unnecessary-copy-initialization %t
 
 struct ExpensiveToCopyType {
   ExpensiveToCopyType();
@@ -411,12 +411,12 @@
 
 template 
 class function;
-template 
-class function {
+template 
+class function {
 public:
   function();
-  function(const function &other);
-  R operator()(Args &&...args) const;
+  function(const function &Other);
+  R operator()(ArgTypes &&...Args) const;
 };
 
 } // namespace __1
@@ -460,3 +460,19 @@
 }
 
 } // namespace fake
+
+void positiveInvokedOnStdFunction(
+std::function Update,
+const ExpensiveToCopyType Orig) {
+  auto Copy = Orig.reference();
+  // CHECK-MESSAGES: [[@LINE-1]]:8: warning: the variable 'Copy' is copy-constructed from a const reference
+  // CHECK-FIXES: const auto& Copy = Orig.reference();
+  Update(Copy);
+}
+
+void negativeInvokedOnStdFunction(
+std::function Update,
+const ExpensiveToCopyType Orig) {
+  auto Copy = Orig.reference();
+  Update(Copy);
+}
Index: clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
===
--- clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
+++ clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
@@ -59,9 +59,13 @@
   extractNodesByIdTo(Matches, "declRef", DeclRefs);
   auto ConstReferenceOrValue =
   qualType(anyOf(referenceType(pointee(qualType(isConstQualified(,
- unless(anyOf(referenceType(), pointerType();
+ unless(anyOf(referenceType(), pointerType(),
+   

[PATCH] D90042: [clang-tidy] performance-unnecessary-copy-initialization: Check for const reference arguments that are replaced template parameter type.

2020-10-23 Thread Felix Berger via Phabricator via cfe-commits
flx updated this revision to Diff 300276.
flx added a comment.

Revert -std=c++17 change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90042

Files:
  clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
  
clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
@@ -411,12 +411,12 @@
 
 template 
 class function;
-template 
-class function {
+template 
+class function {
 public:
   function();
-  function(const function &other);
-  R operator()(Args &&...args) const;
+  function(const function &Other);
+  R operator()(ArgTypes &&...Args) const;
 };
 
 } // namespace __1
@@ -460,3 +460,19 @@
 }
 
 } // namespace fake
+
+void positiveInvokedOnStdFunction(
+std::function Update,
+const ExpensiveToCopyType Orig) {
+  auto Copy = Orig.reference();
+  // CHECK-MESSAGES: [[@LINE-1]]:8: warning: the variable 'Copy' is 
copy-constructed from a const reference
+  // CHECK-FIXES: const auto& Copy = Orig.reference();
+  Update(Copy);
+}
+
+void negativeInvokedOnStdFunction(
+std::function Update,
+const ExpensiveToCopyType Orig) {
+  auto Copy = Orig.reference();
+  Update(Copy);
+}
Index: clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
===
--- clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
+++ clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
@@ -59,9 +59,13 @@
   extractNodesByIdTo(Matches, "declRef", DeclRefs);
   auto ConstReferenceOrValue =
   qualType(anyOf(referenceType(pointee(qualType(isConstQualified(,
- unless(anyOf(referenceType(), pointerType();
+ unless(anyOf(referenceType(), pointerType(),
+  substTemplateTypeParmType();
+  auto ConstReferenceOrValueOrReplaced = qualType(anyOf(
+  ConstReferenceOrValue,
+  substTemplateTypeParmType(hasReplacementType(ConstReferenceOrValue;
   auto UsedAsConstRefOrValueArg = forEachArgumentWithParam(
-  DeclRefToVar, parmVarDecl(hasType(ConstReferenceOrValue)));
+  DeclRefToVar, parmVarDecl(hasType(ConstReferenceOrValueOrReplaced)));
   Matches = match(findAll(callExpr(UsedAsConstRefOrValueArg)), Stmt, Context);
   extractNodesByIdTo(Matches, "declRef", DeclRefs);
   Matches =


Index: clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
@@ -411,12 +411,12 @@
 
 template 
 class function;
-template 
-class function {
+template 
+class function {
 public:
   function();
-  function(const function &other);
-  R operator()(Args &&...args) const;
+  function(const function &Other);
+  R operator()(ArgTypes &&...Args) const;
 };
 
 } // namespace __1
@@ -460,3 +460,19 @@
 }
 
 } // namespace fake
+
+void positiveInvokedOnStdFunction(
+std::function Update,
+const ExpensiveToCopyType Orig) {
+  auto Copy = Orig.reference();
+  // CHECK-MESSAGES: [[@LINE-1]]:8: warning: the variable 'Copy' is copy-constructed from a const reference
+  // CHECK-FIXES: const auto& Copy = Orig.reference();
+  Update(Copy);
+}
+
+void negativeInvokedOnStdFunction(
+std::function Update,
+const ExpensiveToCopyType Orig) {
+  auto Copy = Orig.reference();
+  Update(Copy);
+}
Index: clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
===
--- clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
+++ clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
@@ -59,9 +59,13 @@
   extractNodesByIdTo(Matches, "declRef", DeclRefs);
   auto ConstReferenceOrValue =
   qualType(anyOf(referenceType(pointee(qualType(isConstQualified(,
- unless(anyOf(referenceType(), pointerType();
+ unless(anyOf(referenceType(), pointerType(),
+  substTemplateTypeParmType();
+  auto ConstReferenceOrValueOrReplaced = qualType(anyOf(
+  ConstReferenceOrValue,
+  substTemplateTypeParmType(hasReplacementType(ConstReferenceOrValue;
   auto UsedAsConstRefOrValueArg = forEachArgumentWithParam(
-  DeclRefToVar, parmVarDecl(hasType(ConstReferenceOrValue)));
+  DeclRefToVar, parmVarDecl(hasType(ConstReferenceOrValueOrReplaced)));
   Matches = match(findAll(callExpr(UsedAsCons

[PATCH] D90042: [clang-tidy] performance-unnecessary-copy-initialization: Check for const reference arguments that are replaced template parameter type.

2020-10-23 Thread Felix Berger via Phabricator via cfe-commits
flx added a comment.

I should note that I was only able to reproduce the false positive with the 
actual implementation std::function and not our fake version here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90042

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


[PATCH] D89920: Export TemplateArgumentMatcher so clients defining custom matchers don't need to use the internal namespace

2020-10-23 Thread Sam McCall via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf55eeea4024c: Export TemplateArgumentMatcher so clients 
defining custom matchers don't need… (authored by davidvancleve, committed 
by sammccall).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89920

Files:
  clang/include/clang/ASTMatchers/ASTMatchers.h


Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -145,6 +145,7 @@
 using NestedNameSpecifierMatcher = internal::Matcher;
 using NestedNameSpecifierLocMatcher = 
internal::Matcher;
 using CXXCtorInitializerMatcher = internal::Matcher;
+using TemplateArgumentMatcher = internal::Matcher;
 using TemplateArgumentLocMatcher = internal::Matcher;
 /// @}
 


Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -145,6 +145,7 @@
 using NestedNameSpecifierMatcher = internal::Matcher;
 using NestedNameSpecifierLocMatcher = internal::Matcher;
 using CXXCtorInitializerMatcher = internal::Matcher;
+using TemplateArgumentMatcher = internal::Matcher;
 using TemplateArgumentLocMatcher = internal::Matcher;
 /// @}
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] f55eeea - Export TemplateArgumentMatcher so clients defining custom matchers don't need to use the internal namespace

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

Author: David Van Cleve
Date: 2020-10-23T16:13:56+02:00
New Revision: f55eeea4024cb05bff2c9f72968f23183e992a32

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

LOG: Export TemplateArgumentMatcher so clients defining custom matchers don't 
need to use the internal namespace

This change adds another export, `using TemplateArgumentMatcher = 
internal::Matcher;`, to the collection of exports that put 
instantiations of the `clang::ast_matchers::internal::Matcher` into the 
`clang::ast_matchers` namespace. This makes it possible to define custom 
TemplateArgument matchers without reaching into the `internal` namespace.

Reviewed By: klimek

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

Added: 


Modified: 
clang/include/clang/ASTMatchers/ASTMatchers.h

Removed: 




diff  --git a/clang/include/clang/ASTMatchers/ASTMatchers.h 
b/clang/include/clang/ASTMatchers/ASTMatchers.h
index 51d51d707de4..11886dcafa61 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -145,6 +145,7 @@ using TypeLocMatcher = internal::Matcher;
 using NestedNameSpecifierMatcher = internal::Matcher;
 using NestedNameSpecifierLocMatcher = 
internal::Matcher;
 using CXXCtorInitializerMatcher = internal::Matcher;
+using TemplateArgumentMatcher = internal::Matcher;
 using TemplateArgumentLocMatcher = internal::Matcher;
 /// @}
 



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


[clang] 876af26 - [TableGen] Change !getop and !setop to !getdagop and !setdagop.

2020-10-23 Thread Paul C. Anagnostopoulos via cfe-commits

Author: Paul C. Anagnostopoulos
Date: 2020-10-23T10:36:05-04:00
New Revision: 876af264c118c6ebcb8d79ab1a25d061f98fde82

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

LOG: [TableGen] Change !getop and !setop to !getdagop and !setdagop.

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

Added: 


Modified: 
clang/include/clang/Basic/arm_mve.td
llvm/docs/TableGen/ProgRef.rst
llvm/include/llvm/TableGen/Record.h
llvm/lib/TableGen/Record.cpp
llvm/lib/TableGen/TGLexer.cpp
llvm/lib/TableGen/TGLexer.h
llvm/lib/TableGen/TGParser.cpp
llvm/lib/Target/ARM/ARMInstrMVE.td
llvm/test/TableGen/getsetop.td

Removed: 




diff  --git a/clang/include/clang/Basic/arm_mve.td 
b/clang/include/clang/Basic/arm_mve.td
index 94f76dd729b0..8106f9a5a9de 100644
--- a/clang/include/clang/Basic/arm_mve.td
+++ b/clang/include/clang/Basic/arm_mve.td
@@ -545,8 +545,8 @@ multiclass Reduction basetypes,
   defvar intArgsUnpred = !con(intArgsBase,
   !if(needSign, (? (unsignedflag Scalar)), (?)));
   defvar intArgsPred   = !con(intArgsUnpred, (? $pred));
-  defvar intUnpred = !setop(intArgsUnpred, IRInt);
-  defvar intPred   = !setop(intArgsPred, IRInt<
+  defvar intUnpred = !setdagop(intArgsUnpred, IRInt);
+  defvar intPred   = !setdagop(intArgsPred, IRInt<
 basename#"_predicated", !listconcat(basetypes, [Predicate])>);
 
   def "": Intrinsic<

diff  --git a/llvm/docs/TableGen/ProgRef.rst b/llvm/docs/TableGen/ProgRef.rst
index fa9989d77a24..f1179f076d9d 100644
--- a/llvm/docs/TableGen/ProgRef.rst
+++ b/llvm/docs/TableGen/ProgRef.rst
@@ -206,13 +206,13 @@ TableGen provides "bang operators" that have a wide 
variety of uses:
 
 .. productionlist::
BangOperator: one of
-   : !add !and !cast!con !dag
-   : !empty   !eq  !foldl   !foreach !ge
-   : !getop   !gt  !head!if  !isa
-   : !le  !listconcat  !listsplat   !lt  !mul
-   : !ne  !not !or  !setop   !shl
-   : !size!sra !srl !strconcat   !subst
-   : !tail!xor
+   : !add!and !cast!con !dag
+   : !empty  !eq  !foldl   !foreach !ge
+   : !getdagop   !gt  !head!if  !isa
+   : !le !listconcat  !listsplat   !lt  !mul
+   : !ne !not !or  !setdagop!shl
+   : !size   !sra !srl !strconcat   !subst
+   : !tail   !xor
 
 The ``!cond`` operator has a slightly 
diff erent
 syntax compared to other bang operators, so it is defined separately:
@@ -1243,7 +1243,7 @@ or to associate an argument in one DAG with a like-named 
argument in another
 DAG.
 
 The following bang operators are useful for working with DAGs:
-``!con``, ``!dag``, ``!empty``, ``!foreach``, ``!getop``, ``!setop``, 
``!size``.
+``!con``, ``!dag``, ``!empty``, ``!foreach``, ``!getdagop``, ``!setdagop``, 
``!size``.
 
 Defvar in a record body
 ---
@@ -1445,6 +1445,10 @@ operator produces a boolean result, the result value 
will be 1 for true or 0
 for false. When an operator tests a boolean argument, it interprets 0 as false
 and non-0 as true.
 
+.. warning::
+  The ``!getop`` and ``!setop`` bang operators are deprecated in favor of
+  ``!getdagop`` and ``!setdagop``.
+
 ``!add(``\ *a*\ ``,`` *b*\ ``, ...)``
 This operator adds *a*, *b*, etc., and produces the sum.
 
@@ -1544,26 +1548,27 @@ and non-0 as true.
 The arguments must be ``bit``, ``int``, or ``string`` values.
 Use ``!cast`` to compare other types of objects.
 
-``!getop(``\ *dag*\ ``)`` --or-- ``!getop<``\ *type*\ ``>(``\ *dag*\ ``)``
+``!getdagop(``\ *dag*\ ``)`` --or-- ``!getdagop<``\ *type*\ ``>(``\ *dag*\ 
``)``
 This operator produces the operator of the given *dag* node.
-Example: ``!getop((foo 1, 2))`` results in ``foo``.
+Example: ``!getdagop((foo 1, 2))`` results in ``foo``. Recall that
+DAG operators are always records.
 
-The result of ``!getop`` can be used directly in a context where
-any record value at all is acceptable (typically placing it into
+The result of ``!getdagop`` can be used directly in a context where
+any record class at all is acceptable (typically placing it into
 another dag value). But in other contexts, it must be explicitly
-cast to a particular class type. The ``<``\ *type*\ ``>`` syntax is
+cast to a particular class. The ``<``\ *type*\ ``>`` syntax is
 provided to make this easy.
 
 For example, to assig

[PATCH] D89814: [TableGen] Change !getop and !setop to !getdagop and !setdagop

2020-10-23 Thread Paul C. Anagnostopoulos via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG876af264c118: [TableGen] Change !getop and !setop to 
!getdagop and !setdagop. (authored by Paul-C-Anagnostopoulos).

Changed prior to commit:
  https://reviews.llvm.org/D89814?vs=299428&id=300289#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89814

Files:
  clang/include/clang/Basic/arm_mve.td
  llvm/docs/TableGen/ProgRef.rst
  llvm/include/llvm/TableGen/Record.h
  llvm/lib/TableGen/Record.cpp
  llvm/lib/TableGen/TGLexer.cpp
  llvm/lib/TableGen/TGLexer.h
  llvm/lib/TableGen/TGParser.cpp
  llvm/lib/Target/ARM/ARMInstrMVE.td
  llvm/test/TableGen/getsetop.td

Index: llvm/test/TableGen/getsetop.td
===
--- llvm/test/TableGen/getsetop.td
+++ llvm/test/TableGen/getsetop.td
@@ -3,6 +3,9 @@
 // RUN: not llvm-tblgen -DERROR2 %s 2>&1 | FileCheck --check-prefix=ERROR2 %s
 // RUN: not llvm-tblgen -DERROR3 %s 2>&1 | FileCheck --check-prefix=ERROR3 %s
 
+// !setop and !getop are deprecated in favor of !setdagop and !getdagop.
+// Two tests retain the old names just to be sure they are still supported.
+
 class Base;
 class OtherBase;
 
@@ -18,28 +21,28 @@
   dag replaceWithBar = !setop(orig, bar);
 
   // CHECK: dag replaceWithBaz = (qux 1, 2:$a, ?:$b);
-  dag replaceWithBaz = !setop(orig, qux);
+  dag replaceWithBaz = !setdagop(orig, qux);
 
   // CHECK: Base getopWithCast = foo;
   Base getopWithCast = !getop(orig);
 
   // CHECK: dag getopToSetop = (foo "hello", ?:$world);
-  dag getopToSetop = !setop(another, !getop(orig));
+  dag getopToSetop = !setdagop(another, !getdagop(orig));
 
   // CHECK: dag getopToBangDag = (foo 1:$a, 2:$b, 3:$c);
-  dag getopToBangDag = !dag(!getop(orig), [1, 2, 3], ["a", "b", "c"]);
+  dag getopToBangDag = !dag(!getdagop(orig), [1, 2, 3], ["a", "b", "c"]);
 
   // CHECK: dag getopToDagInit = (foo "it worked");
-  dag getopToDagInit = (!getop(orig) "it worked");
+  dag getopToDagInit = (!getdagop(orig) "it worked");
 
 #ifdef ERROR1
-  // !getop(...) has a static type of 'any record at all, with no
+  // !getdagop(...) has a static type of 'any record at all, with no
   // required superclasses'. That's too general to use in an
   // assignment whose LHS demands an instance of Base, so we expect a
   // static (parse-time) type-checking error.
 
-  // ERROR1: error: Field 'noCast' of type 'Base' is incompatible with value '!getop(orig)' of type '{}'
-  Base noCast = !getop(orig);
+  // ERROR1: error: Field 'noCast' of type 'Base' is incompatible with value '!getdagop(orig)' of type '{}'
+  Base noCast = !getdagop(orig);
 #endif
 
 #ifdef ERROR2
@@ -47,15 +50,15 @@
   // evaluation time that the operator of 'another' is a record that
   // isn't an instance of the specified base class.
 
-  // ERROR2: error: Expected type 'Base', got 'OtherBase' in: !getop((qux "hello", ?:$world))
-  Base badCast = !getop(another);
+  // ERROR2: error: Expected type 'Base', got 'OtherBase' in: !getdagop((qux "hello", ?:$world))
+  Base badCast = !getdagop(another);
 #endif
 
 #ifdef ERROR3
-  // Obviously, you shouldn't be able to give any type to !getop that
+  // Obviously, you shouldn't be able to give any type to !getdagop that
   // isn't a class type.
 
-  // ERROR3: error: type for !getop must be a record type
-  int ridiculousCast = !getop(orig);
+  // ERROR3: error: type for !getdagop must be a record type
+  int ridiculousCast = !getdagop(orig);
 #endif
 }
Index: llvm/lib/Target/ARM/ARMInstrMVE.td
===
--- llvm/lib/Target/ARM/ARMInstrMVE.td
+++ llvm/lib/Target/ARM/ARMInstrMVE.td
@@ -3033,7 +3033,7 @@
   defvar outparams = (inst (OutVTI.Vec MQPR:$QdSrc), (InVTI.Vec MQPR:$Qm),
(imm:$imm));
 
-  def : Pat<(OutVTI.Vec !setop(inparams, int_arm_mve_vshrn)),
+  def : Pat<(OutVTI.Vec !setdagop(inparams, int_arm_mve_vshrn)),
 (OutVTI.Vec outparams)>;
   def : Pat<(OutVTI.Vec !con(inparams, (int_arm_mve_vshrn_predicated
(InVTI.Pred VCCR:$pred,
@@ -3235,7 +3235,7 @@
   defvar unpred_int = !cast("int_arm_mve_" # name);
   defvar pred_int = !cast("int_arm_mve_" # name # "_predicated");
 
-  def : Pat<(VTI.Vec !setop(inparams, unpred_int)),
+  def : Pat<(VTI.Vec !setdagop(inparams, unpred_int)),
 (VTI.Vec outparams)>;
   def : Pat<(VTI.Vec !con(inparams, (pred_int (VTI.Pred VCCR:$pred,
 (VTI.Vec !con(outparams, (? ARMVCCThen, VCCR:$pred)))>;
Index: llvm/lib/TableGen/TGParser.cpp
===
--- llvm/lib/TableGen/TGParser.cpp
+++ llvm/lib/TableGen/TGParser.cpp
@@ -813,12 +813,12 @@
   TokError("expected '<' after bits type");
   return nullptr;
 }
-if (Lex.Lex() != tg

[PATCH] D90047: [clangd] Fix remote-server build and add it to check-clangd

2020-10-23 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added reviewers: sammccall, kbobyrev.
Herald added subscribers: cfe-commits, usaxena95, arphaman, mgorny.
Herald added a project: clang.
kadircet requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D90047

Files:
  clang-tools-extra/clangd/index/remote/server/Server.cpp
  clang-tools-extra/clangd/test/CMakeLists.txt


Index: clang-tools-extra/clangd/test/CMakeLists.txt
===
--- clang-tools-extra/clangd/test/CMakeLists.txt
+++ clang-tools-extra/clangd/test/CMakeLists.txt
@@ -21,6 +21,10 @@
   list(APPEND CLANGD_TEST_DEPS ClangdXpcUnitTests)
 endif()
 
+if(CLANGD_ENABLE_REMOTE)
+  list(APPEND CLANGD_TEST_DEPS clangd-index-server)
+endif()
+
 foreach(dep FileCheck count not llvm-config)
   if(TARGET ${dep})
 list(APPEND CLANGD_TEST_DEPS ${dep})
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
@@ -33,8 +33,6 @@
 #include 
 #include 
 
-#include "Index.grpc.pb.h"
-
 namespace clang {
 namespace clangd {
 namespace remote {


Index: clang-tools-extra/clangd/test/CMakeLists.txt
===
--- clang-tools-extra/clangd/test/CMakeLists.txt
+++ clang-tools-extra/clangd/test/CMakeLists.txt
@@ -21,6 +21,10 @@
   list(APPEND CLANGD_TEST_DEPS ClangdXpcUnitTests)
 endif()
 
+if(CLANGD_ENABLE_REMOTE)
+  list(APPEND CLANGD_TEST_DEPS clangd-index-server)
+endif()
+
 foreach(dep FileCheck count not llvm-config)
   if(TARGET ${dep})
 list(APPEND CLANGD_TEST_DEPS ${dep})
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
@@ -33,8 +33,6 @@
 #include 
 #include 
 
-#include "Index.grpc.pb.h"
-
 namespace clang {
 namespace clangd {
 namespace remote {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D90047: [clangd] Fix remote-server build and add it to check-clangd

2020-10-23 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev accepted this revision.
kbobyrev added a comment.
This revision is now accepted and ready to land.

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90047

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


[PATCH] D82756: Port some floating point options to new option marshalling infrastructure

2020-10-23 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

@dexonsmith, thanks for sharing your idea. Overall, I like the simplicity.

As you say, not every command line option has an associated `CodeGenOptions` or 
`LangOptions` field. For this patch only, we'd need to create the following 
fields:

- `CLUnsafeOptimizations` for `OPT_cl_unsafe_math_optimizations`
- `CLFiniteMathOnly` for `OPT_cl_finite_math_only`
- `CLNoSignedZeros` for `OPT_cl_no_signed_zeros`

I'm not sure how many other cases there are outside of what this patch touches.

Introducing ordering-sensitivity is not ideal, but if all options are defined 
in close proximity to each other, it should be relatively easy to reason about.

Correct me if I'm wrong, but when generating the command line, all "implied" 
flags would be hidden, even if they were explicit in the original comand line:

- original command line:  `clang -cc1 -cl-unsafe-math-optimizations 
-cl-mad-enable -menable-unsafe-fp-math -mreassociate -fno-signed-zeros 
-freciprocal-math -fapprox-func [...]`
- generated command line: `clang -cc1 -cl-unsafe-math-optimizations [...]`

This might be a bit surprising, but I don't think this would cause issues for 
explicit modules. What are your thoughts?

Formalizing the "implies" relationships would make it possible to remove the 
ordering-sensitivity and possibly generate implied flags even when explicitly 
passed to `cc1`. It would complicate the TableGen backend, which I'd prefer to 
keep as simple as possible.


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

https://reviews.llvm.org/D82756

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


[PATCH] D83088: Introduce CfgTraits abstraction

2020-10-23 Thread Nicolai Hähnle via Phabricator via cfe-commits
nhaehnle added a comment.

Hi Mehdi, this is not an appropriate place for this discussion. Yes, we have a 
general rule that patches can be reverted if they're obviously broken (e.g. 
build bot problems) or clearly violate some other standard. This is a good 
rule, but it doesn't apply here. If you think it does, please state your case 
in the email thread that I've started on llvm-dev for this very purpose. Just 
one thing:

> - the burden of convincing of the approach is on the patch author, reverting 
> is forcing the discussion here.

I was trying to have this conversation. I am more than happy to have it, and I 
would be happy for me people to participate! But what can I do if the only(!) 
person who voices concerns just goes into radio silence, and the total number 
of people who participate is small in any case, despite raising it on llvm-dev 
as well?

It is in fact the decision to **not** revert the change which is apparently 
required to force the discussion!

P.S.: It's easy to miss on Phabricator, but there is already a long stack of 
patches which build on this. In a way this is a good thing because it can 
inform the discussion, but I will hold off from pushing more for now even 
though many of them have already been accepted.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83088

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


[PATCH] D83088: Introduce CfgTraits abstraction

2020-10-23 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

In D83088#2348641 , @mehdi_amini wrote:

> In D83088#2347111 , @arsenm wrote:
>
>> In D83088#2346322 , @mehdi_amini 
>> wrote:
>>
>>> In D83088#2345540 , @nhaehnle 
>>> wrote:
>>>
 David, I don't think this is appropriate here. Let's take the discussion 
 to llvm-dev.
>>>
>>> Seems like David asked to revert in the meantime?
>>
>> -1 to reverting, which will just make the history messier with no tangible 
>> benefit
>
> This is the usual LLVM policy I believe: someone expressed a concern and ask 
> to revert. We revert and discuss first.
> So again: please revert.
>
> The messier history is not an argument: we revert so many times for any 
> random bot failures already, and our contribution guidelines still tell 
> people to push a "fake commit" with a whitespace change to test their access.

Unrelated, but I think the test commit process should be dropped

> I also see tangile benefits:
>
> - we don't start building dependencies on newly introduced API making a 
> revert more difficult later.
> - the burden of convincing of the approach is on the patch author, reverting 
> is forcing the discussion here.

This patch has been up for review for almost 4 months, with a corresponding RFC 
on llvm-dev. The last review comments were over 2 months ago. Coming back to 
this so long after to ask for a revert is an unworkable level of review 
paralysis


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83088

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


[PATCH] D89994: [libomptarget][nvptx] Undef, internal shared variables

2020-10-23 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added inline comments.



Comment at: clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp:2858
 TransferMedium = new llvm::GlobalVariable(
-M, Ty, /*isConstant=*/false, llvm::GlobalVariable::CommonLinkage,
-llvm::Constant::getNullValue(Ty), TransferMediumName,
+M, Ty, /*isConstant=*/false, llvm::GlobalVariable::InternalLinkage,
+llvm::UndefValue::get(Ty), TransferMediumName,

ABataev wrote:
> "Internalization" is not the best option, it increases mem pressure. Common 
> linkage is a better choice, allows to "squash" the same objects, defined in 
> different units. Make it arch dependable, maybe?
> For NVPTX zero initialization is not a problem, it is resolved when PTX is 
> generated.
FWIW, if we do not depend on the zero initialization, we should go with undef.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89994

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


[PATCH] D89994: [libomptarget][nvptx] Undef, internal shared variables

2020-10-23 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp:2858
 TransferMedium = new llvm::GlobalVariable(
-M, Ty, /*isConstant=*/false, llvm::GlobalVariable::CommonLinkage,
-llvm::Constant::getNullValue(Ty), TransferMediumName,
+M, Ty, /*isConstant=*/false, llvm::GlobalVariable::InternalLinkage,
+llvm::UndefValue::get(Ty), TransferMediumName,

jdoerfert wrote:
> ABataev wrote:
> > "Internalization" is not the best option, it increases mem pressure. Common 
> > linkage is a better choice, allows to "squash" the same objects, defined in 
> > different units. Make it arch dependable, maybe?
> > For NVPTX zero initialization is not a problem, it is resolved when PTX is 
> > generated.
> FWIW, if we do not depend on the zero initialization, we should go with undef.
> 
Sure.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89994

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


[PATCH] D90053: Serialization: Change InputFile to use FileEntryRef and add getVirtualFileRef, NFC

2020-10-23 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith created this revision.
dexonsmith added reviewers: arphaman, JDevlieghere, teemperor.
Herald added a subscriber: ributzka.
dexonsmith requested review of this revision.

Change the `InputFile` class to store a `MaybeFileEntryRef` instead of
`FileEntry*`. This paged in a few API changes:

- Added `FileManager::getVirtualFileRef`, and converted `getVirtualFile` to a 
wrapper of it.
- Added `{Maybe,}FileEntryRef::getMapEntry`, which gives access to the 
underlying `StringMapEntry*` pointer, to enable clients (`InputFile`) to store 
a `FileEntryRef` in a `PointerIntPair`.
- Updated `SourceManager::bypassFileContentsOverride` to take `FileEntryRef` 
and return `MaybeFileEntry` (`ASTReader::getInputFile` is the only caller).


https://reviews.llvm.org/D90053

Files:
  clang/include/clang/Basic/FileEntry.h
  clang/include/clang/Basic/FileManager.h
  clang/include/clang/Basic/SourceManager.h
  clang/include/clang/Serialization/ModuleFile.h
  clang/lib/Basic/FileManager.cpp
  clang/lib/Basic/SourceManager.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/unittests/Basic/FileEntryTest.cpp

Index: clang/unittests/Basic/FileEntryTest.cpp
===
--- clang/unittests/Basic/FileEntryTest.cpp
+++ clang/unittests/Basic/FileEntryTest.cpp
@@ -112,6 +112,7 @@
   FileEntryRef R1Also = addRef(Refs, "1-also", E1);
 
   EXPECT_TRUE(R1.isSameRef(FileEntryRef(R1)));
+  EXPECT_TRUE(R1.isSameRef(FileEntryRef(R1.getMapEntry(;
   EXPECT_FALSE(R1.isSameRef(R2));
   EXPECT_FALSE(R1.isSameRef(R1Also));
 
@@ -123,6 +124,7 @@
   EXPECT_FALSE(M0.isSameRef(M1));
   EXPECT_FALSE(M1.isSameRef(M0));
   EXPECT_TRUE(M1.isSameRef(MaybeFileEntryRef(M1)));
+  EXPECT_TRUE(M1.isSameRef(MaybeFileEntryRef(M1.getMapEntry(;
   EXPECT_FALSE(M1.isSameRef(M1Also));
   EXPECT_FALSE(M1.isSameRef(M2));
   EXPECT_TRUE(M1.isSameRef(R1));
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -2312,27 +2312,25 @@
   StringRef Filename = FI.Filename;
   uint64_t StoredContentHash = FI.ContentHash;
 
-  const FileEntry *File = nullptr;
-  if (auto FE = FileMgr.getFile(Filename, /*OpenFile=*/false))
-File = *FE;
+  MaybeFileEntryRef File =
+  expectedToOptional(FileMgr.getFileRef(Filename, /*OpenFile=*/false));
 
   // If we didn't find the file, resolve it relative to the
   // original directory from which this AST file was created.
-  if (File == nullptr && !F.OriginalDir.empty() && !F.BaseDirectory.empty() &&
+  if (!File && !F.OriginalDir.empty() && !F.BaseDirectory.empty() &&
   F.OriginalDir != F.BaseDirectory) {
 std::string Resolved = resolveFileRelativeToOriginalDir(
 std::string(Filename), F.OriginalDir, F.BaseDirectory);
 if (!Resolved.empty())
-  if (auto FE = FileMgr.getFile(Resolved))
-File = *FE;
+  File = expectedToOptional(FileMgr.getFileRef(Resolved));
   }
 
   // For an overridden file, create a virtual file with the stored
   // size/timestamp.
-  if ((Overridden || Transient) && File == nullptr)
-File = FileMgr.getVirtualFile(Filename, StoredSize, StoredTime);
+  if ((Overridden || Transient) && !File)
+File = FileMgr.getVirtualFileRef(Filename, StoredSize, StoredTime);
 
-  if (File == nullptr) {
+  if (!File) {
 if (Complain) {
   std::string ErrorStr = "could not find file '";
   ErrorStr += Filename;
@@ -2443,7 +2441,7 @@
   // FIXME: If the file is overridden and we've already opened it,
   // issue an error (or split it into a separate FileEntry).
 
-  InputFile IF = InputFile(File, Overridden || Transient, IsOutOfDate);
+  InputFile IF = InputFile(*File, Overridden || Transient, IsOutOfDate);
 
   // Note that we've loaded this input file.
   F.InputFilesLoaded[ID-1] = IF;
@@ -9195,7 +9193,7 @@
 InputFileInfo IFI = readInputFileInfo(MF, I + 1);
 if (IFI.TopLevelModuleMap)
   // FIXME: This unnecessarily re-reads the InputFileInfo.
-  if (auto *FE = getInputFile(MF, I + 1).getFile())
+  if (auto FE = getInputFile(MF, I + 1).getFile())
 Visitor(FE);
   }
 }
Index: clang/lib/Basic/SourceManager.cpp
===
--- clang/lib/Basic/SourceManager.cpp
+++ clang/lib/Basic/SourceManager.cpp
@@ -703,19 +703,16 @@
   getOverriddenFilesInfo().OverriddenFiles[SourceFile] = NewFile;
 }
 
-const FileEntry *
-SourceManager::bypassFileContentsOverride(const FileEntry &File) {
-  assert(isFileOverridden(&File));
-  llvm::Optional BypassFile =
-  FileMgr.getBypassFile(File.getLastRef());
+MaybeFileEntryRef SourceManager::bypassFileContentsOverride(FileEntryRef File) {
+  assert(isFileOverridden(&File.getFileEntry()));
+  llvm::Optional BypassFile = FileMgr.getBypassFile(File);
 
   // If the file can't be found in the FS, give up.
   if (!BypassFile)
-return nullptr;
+return Non

[PATCH] D90054: Added remotely ran compiler-rt tests.

2020-10-23 Thread Alex Orlov via Phabricator via cfe-commits
aorlov created this revision.
aorlov added reviewers: vvereschaka, broadwaylamb.
aorlov added a project: LLVM.
Herald added subscribers: cfe-commits, mgorny, dberris.
Herald added a project: clang.
aorlov requested review of this revision.

Use LLVM/utils/remote-exec.py to run compiler-rt tests remotely on the target.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D90054

Files:
  clang/cmake/caches/CrossWinToARMLinux.cmake


Index: clang/cmake/caches/CrossWinToARMLinux.cmake
===
--- clang/cmake/caches/CrossWinToARMLinux.cmake
+++ clang/cmake/caches/CrossWinToARMLinux.cmake
@@ -72,6 +72,7 @@
 set(COMPILER_RT_BUILD_LIBFUZZER OFF CACHE BOOL "")
 set(COMPILER_RT_BUILD_PROFILE   OFF CACHE BOOL "")
 set(COMPILER_RT_DEFAULT_TARGET_ONLY ON CACHE BOOL "")
+set(COMPILER_RT_INCLUDE_TESTS   ON CACHE BOOL "")
 
 set(LIBUNWIND_USE_COMPILER_RT   ON CACHE BOOL "")
 set(LIBUNWIND_TARGET_TRIPLE "${CMAKE_C_COMPILER_TARGET}" CACHE 
STRING "")
@@ -108,6 +109,9 @@
   set(DEFAULT_TEST_TARGET_INFO  
"libcxx.test.target_info.LinuxRemoteTI")
 
   # Allow override with the custom values.
+  if(NOT DEFINED COMPILER_RT_EMULATOR)
+set(COMPILER_RT_EMULATOR"\\\"${Python3_EXECUTABLE}\\\" 
\\\"${LLVM_PROJECT_DIR}/llvm/utils/remote-exec.py\\\" --execdir %%T 
--exec-pattern='.*\\.c.*\\.tmp.*' 
--host='${REMOTE_TEST_USER}@${REMOTE_TEST_HOST}'" CACHE STRING "")
+  endif()
   if(NOT DEFINED LIBUNWIND_TARGET_INFO)
 set(LIBUNWIND_TARGET_INFO   "${DEFAULT_TEST_TARGET_INFO}" 
CACHE STRING "")
   endif()


Index: clang/cmake/caches/CrossWinToARMLinux.cmake
===
--- clang/cmake/caches/CrossWinToARMLinux.cmake
+++ clang/cmake/caches/CrossWinToARMLinux.cmake
@@ -72,6 +72,7 @@
 set(COMPILER_RT_BUILD_LIBFUZZER OFF CACHE BOOL "")
 set(COMPILER_RT_BUILD_PROFILE   OFF CACHE BOOL "")
 set(COMPILER_RT_DEFAULT_TARGET_ONLY ON CACHE BOOL "")
+set(COMPILER_RT_INCLUDE_TESTS   ON CACHE BOOL "")
 
 set(LIBUNWIND_USE_COMPILER_RT   ON CACHE BOOL "")
 set(LIBUNWIND_TARGET_TRIPLE "${CMAKE_C_COMPILER_TARGET}" CACHE STRING "")
@@ -108,6 +109,9 @@
   set(DEFAULT_TEST_TARGET_INFO  "libcxx.test.target_info.LinuxRemoteTI")
 
   # Allow override with the custom values.
+  if(NOT DEFINED COMPILER_RT_EMULATOR)
+set(COMPILER_RT_EMULATOR"\\\"${Python3_EXECUTABLE}\\\" \\\"${LLVM_PROJECT_DIR}/llvm/utils/remote-exec.py\\\" --execdir %%T --exec-pattern='.*\\.c.*\\.tmp.*' --host='${REMOTE_TEST_USER}@${REMOTE_TEST_HOST}'" CACHE STRING "")
+  endif()
   if(NOT DEFINED LIBUNWIND_TARGET_INFO)
 set(LIBUNWIND_TARGET_INFO   "${DEFAULT_TEST_TARGET_INFO}" CACHE STRING "")
   endif()
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 5dd3992 - [clangd] Fix remote-server build and add it to check-clangd

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

Author: Kadir Cetinkaya
Date: 2020-10-23T18:08:02+02:00
New Revision: 5dd39923a09ec284d30083e5fadaa29e618d4446

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

LOG: [clangd] Fix remote-server build and add it to check-clangd

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

Added: 


Modified: 
clang-tools-extra/clangd/index/remote/server/Server.cpp
clang-tools-extra/clangd/test/CMakeLists.txt

Removed: 




diff  --git a/clang-tools-extra/clangd/index/remote/server/Server.cpp 
b/clang-tools-extra/clangd/index/remote/server/Server.cpp
index 750c659381af..7b68549a4afd 100644
--- a/clang-tools-extra/clangd/index/remote/server/Server.cpp
+++ b/clang-tools-extra/clangd/index/remote/server/Server.cpp
@@ -33,8 +33,6 @@
 #include 
 #include 
 
-#include "Index.grpc.pb.h"
-
 namespace clang {
 namespace clangd {
 namespace remote {

diff  --git a/clang-tools-extra/clangd/test/CMakeLists.txt 
b/clang-tools-extra/clangd/test/CMakeLists.txt
index 878408cc5483..ade42ac457e0 100644
--- a/clang-tools-extra/clangd/test/CMakeLists.txt
+++ b/clang-tools-extra/clangd/test/CMakeLists.txt
@@ -21,6 +21,10 @@ if(CLANGD_BUILD_XPC)
   list(APPEND CLANGD_TEST_DEPS ClangdXpcUnitTests)
 endif()
 
+if(CLANGD_ENABLE_REMOTE)
+  list(APPEND CLANGD_TEST_DEPS clangd-index-server)
+endif()
+
 foreach(dep FileCheck count not llvm-config)
   if(TARGET ${dep})
 list(APPEND CLANGD_TEST_DEPS ${dep})



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


[PATCH] D90047: [clangd] Fix remote-server build and add it to check-clangd

2020-10-23 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5dd39923a09e: [clangd] Fix remote-server build and add it to 
check-clangd (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90047

Files:
  clang-tools-extra/clangd/index/remote/server/Server.cpp
  clang-tools-extra/clangd/test/CMakeLists.txt


Index: clang-tools-extra/clangd/test/CMakeLists.txt
===
--- clang-tools-extra/clangd/test/CMakeLists.txt
+++ clang-tools-extra/clangd/test/CMakeLists.txt
@@ -21,6 +21,10 @@
   list(APPEND CLANGD_TEST_DEPS ClangdXpcUnitTests)
 endif()
 
+if(CLANGD_ENABLE_REMOTE)
+  list(APPEND CLANGD_TEST_DEPS clangd-index-server)
+endif()
+
 foreach(dep FileCheck count not llvm-config)
   if(TARGET ${dep})
 list(APPEND CLANGD_TEST_DEPS ${dep})
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
@@ -33,8 +33,6 @@
 #include 
 #include 
 
-#include "Index.grpc.pb.h"
-
 namespace clang {
 namespace clangd {
 namespace remote {


Index: clang-tools-extra/clangd/test/CMakeLists.txt
===
--- clang-tools-extra/clangd/test/CMakeLists.txt
+++ clang-tools-extra/clangd/test/CMakeLists.txt
@@ -21,6 +21,10 @@
   list(APPEND CLANGD_TEST_DEPS ClangdXpcUnitTests)
 endif()
 
+if(CLANGD_ENABLE_REMOTE)
+  list(APPEND CLANGD_TEST_DEPS clangd-index-server)
+endif()
+
 foreach(dep FileCheck count not llvm-config)
   if(TARGET ${dep})
 list(APPEND CLANGD_TEST_DEPS ${dep})
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
@@ -33,8 +33,6 @@
 #include 
 #include 
 
-#include "Index.grpc.pb.h"
-
 namespace clang {
 namespace clangd {
 namespace remote {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D89987: [analyzer] [NFC] Rename SymbolRef to SymExprRef

2020-10-23 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

In D89987#2349959 , @ASDenysPetrov 
wrote:

> @OikawaKirie
>
>> Different from ProgramStateRef which is an alias to IntrusiveRefCntPtr, or 
>> StoreRef which is a wrapper object, an alias to a const SymExpr * makes no 
>> sense to me.
>
> Yes. I omit this, because in such case we should go further and rename all 
> those which are not real `Ref` to `Ptr` or smth that would emphasise that 
> it's just a pointer alias, not a wrapper or another class.
> That's why I prefered to change the name a little in favor of complex 
> approach of renaming all the rest.
>
>> And this is also where I have been confused for a long while.
>
> So have been I. The patch is called to make it more clear :)
>
> Thanks to @steakhal comment I investigated more in terms of what other names 
> use `Symbol` but mean `SymExpr`. They are:
>
>   class SymbolManager;
>   using SymbolID;
>   using SymbolDependTy;
>   class SymbolData;
>   class SymbolMetadata;
>   class SymbolReaper;
>   enum SymbolStatus;
>   using SymbolSetTy;
>   using SymbolMapTy;
>   class SymbolCast;
>   class SymbolVal;
>   class symbol_iterator;
>   etc.
>
> This is not a full list! I also didn't count //methods// and //file names//.
> There is also a list of objects names which straightly use `SymExpr`. They 
> are less spread. Mostly they are derived classes:
>
>   class BinarySymExprImpl;
>   class SymIntExpr;
>   class IntSymExpr;
>   class SymSymExpr;
>   some enums, several methods, etc.
>
> As a result we should accurately define the difference between `Symbol` and 
> `SymExpr`.

There are some cases, when `Symbol` refers to the base-class of the inheritance 
hierachy. In those cases the renaming would be appropiate.
Though, I'm sure there are cases, when the `Symbol` refers simply to 
`SymbolData` - in which cases we should rename accordingly.

At the previous LLVM SA round table @xazax.hun also mentioned that we could 
have chosen better names. Maybe it's the time to have consensus about this.

> I see the next options:
>
> 1. `Symbol` and `SymExpr` are different. Leave the names as are. Fix minor 
> mismatches if presented. And follow that definitions.
> 2. `Symbol` and `SymExpr` are the same. `SymExpr` is a dominant one. Change 
> all the names from `Symbol` to `SymExpr` and get rid of `Symbol`.
> 3. `Symbol` and `SymExpr` are the same. `Symbol` is a dominant one. Change 
> all the names from `SymExpr` to `Symbol` and get rid of `SymExpr`.
> 4. Ignore the naming due to loss of **git blame** (or any other reason) like 
> in an llvm naming rules topic.

Losing **git blame** would have a signifficant impact in deed, however we 
always have the option to add the renaming commit to the 
`.git-blame-ignore-revs`.
To achieve that, we should probably have a better reason behind it besides 
simply //renaming// stuff.

> 5. For now just rename `SymbolRef` alias as the beggining of the story in 
> scope of 2nd option.
>
> What do you think?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89987

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


[PATCH] D89832: [CUDA] Extract CUDA version from cuda.h if version.txt is not found

2020-10-23 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

In D89832#2349915 , @emankov wrote:

> I confirm that D89752  eliminates 47332 
>  on Windows. Tested against the 
> following CUDA versions: 7.0, 7,5, 9,2, 10.0, 10,1, 10.2, 11.0 Update 1, 11.1.

Thank you! I appreciate your help testing this patch. I'll land the patches 
shortly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89832

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


[PATCH] D89554: SourceManager: Clarify that FileInfo always has a ContentCache, NFC

2020-10-23 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG74a878348021: SourceManager: Clarify that FileInfo always 
has a ContentCache, NFC (authored by dexonsmith).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D89554?vs=298634&id=300329#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89554

Files:
  clang/include/clang/Basic/SourceManager.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/Basic/SourceManager.cpp
  clang/lib/Lex/ScratchBuffer.cpp
  clang/lib/Rewrite/Rewriter.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/tools/libclang/CIndexInclusionStack.cpp

Index: clang/tools/libclang/CIndexInclusionStack.cpp
===
--- clang/tools/libclang/CIndexInclusionStack.cpp
+++ clang/tools/libclang/CIndexInclusionStack.cpp
@@ -35,7 +35,7 @@
   continue;
 
 const SrcMgr::FileInfo &FI = SL.getFile();
-if (!FI.getContentCache()->OrigEntry)
+if (!FI.getContentCache().OrigEntry)
   continue;
 
 // If this is the main file, and there is a preamble, skip this SLoc. The
@@ -60,7 +60,7 @@
 // Callback to the client.
 // FIXME: We should have a function to construct CXFiles.
 CB(static_cast(
-   const_cast(FI.getContentCache()->OrigEntry)),
+   const_cast(FI.getContentCache().OrigEntry)),
InclusionStack.data(), InclusionStack.size(), clientData);
   }
 }
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -1452,7 +1452,7 @@
 if (!SLoc->isFile())
   continue;
 const SrcMgr::FileInfo &File = SLoc->getFile();
-const SrcMgr::ContentCache *Cache = File.getContentCache();
+const SrcMgr::ContentCache *Cache = &File.getContentCache();
 if (!Cache->OrigEntry)
   continue;
 
@@ -1952,7 +1952,7 @@
 // Figure out which record code to use.
 unsigned Code;
 if (SLoc->isFile()) {
-  const SrcMgr::ContentCache *Cache = SLoc->getFile().getContentCache();
+  const SrcMgr::ContentCache *Cache = &SLoc->getFile().getContentCache();
   if (Cache->OrigEntry) {
 Code = SM_SLOC_FILE_ENTRY;
   } else
@@ -1970,7 +1970,7 @@
   Record.push_back(File.getFileCharacteristic()); // FIXME: stable encoding
   Record.push_back(File.hasLineDirectives());
 
-  const SrcMgr::ContentCache *Content = File.getContentCache();
+  const SrcMgr::ContentCache *Content = &File.getContentCache();
   bool EmitBlob = false;
   if (Content->OrigEntry) {
 assert(Content->OrigEntry == Content->ContentsEntry &&
Index: clang/lib/Rewrite/Rewriter.cpp
===
--- clang/lib/Rewrite/Rewriter.cpp
+++ clang/lib/Rewrite/Rewriter.cpp
@@ -263,8 +263,8 @@
 StringRef MB = SourceMgr->getBufferData(FID);
 
 unsigned lineNo = SourceMgr->getLineNumber(FID, StartOffs) - 1;
-const SrcMgr::ContentCache *
-Content = SourceMgr->getSLocEntry(FID).getFile().getContentCache();
+const SrcMgr::ContentCache *Content =
+&SourceMgr->getSLocEntry(FID).getFile().getContentCache();
 unsigned lineOffs = Content->SourceLineCache[lineNo];
 
 // Find the whitespace at the start of the line.
@@ -367,8 +367,8 @@
   unsigned startLineNo = SourceMgr->getLineNumber(FID, StartOff) - 1;
   unsigned endLineNo = SourceMgr->getLineNumber(FID, EndOff) - 1;
 
-  const SrcMgr::ContentCache *
-  Content = SourceMgr->getSLocEntry(FID).getFile().getContentCache();
+  const SrcMgr::ContentCache *Content =
+  &SourceMgr->getSLocEntry(FID).getFile().getContentCache();
 
   // Find where the lines start.
   unsigned parentLineOffs = Content->SourceLineCache[parentLineNo];
Index: clang/lib/Lex/ScratchBuffer.cpp
===
--- clang/lib/Lex/ScratchBuffer.cpp
+++ clang/lib/Lex/ScratchBuffer.cpp
@@ -38,8 +38,9 @@
 // Clear out the source line cache if it's already been computed.
 // FIXME: Allow this to be incrementally extended.
 auto *ContentCache = const_cast(
-SourceMgr.getSLocEntry(SourceMgr.getFileID(BufferStartLoc))
- .getFile().getContentCache());
+&SourceMgr.getSLocEntry(SourceMgr.getFileID(BufferStartLoc))
+ .getFile()
+ .getContentCache());
 ContentCache->SourceLineCache = nullptr;
   }
 
Index: clang/lib/Basic/SourceManager.cpp
===
--- clang/lib/Basic/SourceManager.cpp
+++ clang/lib/Basic/SourceManager.cpp
@@ -437,7 +437,7 @@
 if (!SLocEntryLoaded[Index]) {
   // Try to recover; create a SLocEntry so the rest of clang can handle it.
   LoadedSLocEntryTable[Index] = SLocEntry::get(
-  0, Fi

[clang] 74a8783 - SourceManager: Clarify that FileInfo always has a ContentCache, NFC

2020-10-23 Thread Duncan P . N . Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-10-23T12:38:53-04:00
New Revision: 74a8783480219f5f0e5c4673a6d0e29b4ad99877

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

LOG: SourceManager: Clarify that FileInfo always has a ContentCache, NFC

It turns out that `FileInfo` *always* has a ContentCache. Clarify that
in the code:
- Update the private version of `SourceManager::createFileID` to take a
  `ContentCache&` instead of `ContentCache*`, and rename it to
  `createFileIDImpl` for clarity.
- Change `FileInfo::getContentCache` to return a reference.

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

Added: 


Modified: 
clang/include/clang/Basic/SourceManager.h
clang/lib/AST/ASTImporter.cpp
clang/lib/Basic/SourceManager.cpp
clang/lib/Lex/ScratchBuffer.cpp
clang/lib/Rewrite/Rewriter.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/tools/libclang/CIndexInclusionStack.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/SourceManager.h 
b/clang/include/clang/Basic/SourceManager.h
index 5035326297f7..06bec09cda98 100644
--- a/clang/include/clang/Basic/SourceManager.h
+++ b/clang/include/clang/Basic/SourceManager.h
@@ -275,13 +275,13 @@ namespace SrcMgr {
 
   public:
 /// Return a FileInfo object.
-static FileInfo get(SourceLocation IL, const ContentCache *Con,
+static FileInfo get(SourceLocation IL, const ContentCache &Con,
 CharacteristicKind FileCharacter, StringRef Filename) {
   FileInfo X;
   X.IncludeLoc = IL.getRawEncoding();
   X.NumCreatedFIDs = 0;
   X.HasLineDirectives = false;
-  X.ContentAndKind.setPointer(Con);
+  X.ContentAndKind.setPointer(&Con);
   X.ContentAndKind.setInt(FileCharacter);
   X.Filename = Filename;
   return X;
@@ -291,8 +291,8 @@ namespace SrcMgr {
   return SourceLocation::getFromRawEncoding(IncludeLoc);
 }
 
-const ContentCache *getContentCache() const {
-  return ContentAndKind.getPointer();
+const ContentCache &getContentCache() const {
+  return *ContentAndKind.getPointer();
 }
 
 /// Return whether this is a system header or not.
@@ -973,7 +973,7 @@ class SourceManager : public RefCountedBase {
   llvm::Optional
   getBufferOrNone(FileID FID, SourceLocation Loc = SourceLocation()) const {
 if (auto *Entry = getSLocEntryForFile(FID))
-  return Entry->getFile().getContentCache()->getBufferOrNone(
+  return Entry->getFile().getContentCache().getBufferOrNone(
   Diag, getFileManager(), Loc);
 return None;
   }
@@ -992,8 +992,7 @@ class SourceManager : public RefCountedBase {
   /// Returns the FileEntry record for the provided FileID.
   const FileEntry *getFileEntryForID(FileID FID) const {
 if (auto *Entry = getSLocEntryForFile(FID))
-  if (auto *Content = Entry->getFile().getContentCache())
-return Content->OrigEntry;
+  return Entry->getFile().getContentCache().OrigEntry;
 return nullptr;
   }
 
@@ -1006,10 +1005,7 @@ class SourceManager : public 
RefCountedBase {
   /// Returns the FileEntry record for the provided SLocEntry.
   const FileEntry *getFileEntryForSLocEntry(const SrcMgr::SLocEntry &sloc) 
const
   {
-const SrcMgr::ContentCache *Content = sloc.getFile().getContentCache();
-if (!Content)
-  return nullptr;
-return Content->OrigEntry;
+return sloc.getFile().getContentCache().OrigEntry;
   }
 
   /// Return a StringRef to the source buffer data for the
@@ -1793,10 +1789,10 @@ class SourceManager : public 
RefCountedBase {
   ///
   /// This works regardless of whether the ContentCache corresponds to a
   /// file or some other input source.
-  FileID createFileID(const SrcMgr::ContentCache *File, StringRef Filename,
-  SourceLocation IncludePos,
-  SrcMgr::CharacteristicKind DirCharacter, int LoadedID,
-  unsigned LoadedOffset);
+  FileID createFileIDImpl(const SrcMgr::ContentCache &File, StringRef Filename,
+  SourceLocation IncludePos,
+  SrcMgr::CharacteristicKind DirCharacter, int 
LoadedID,
+  unsigned LoadedOffset);
 
   const SrcMgr::ContentCache *
 getOrCreateContentCache(const FileEntry *SourceFile,

diff  --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index ce79b99d7043..f15be09f0e5d 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -8654,7 +8654,7 @@ Expected ASTImporter::Import(FileID FromID, bool 
IsBuiltin) {
 }
 ToID = ToSM.getFileID(MLoc);
   } else {
-const SrcMgr::ContentCache *Cache = FromSLoc.getFile().getContentCache();
+const SrcMgr::ContentCache *Cache = &FromSLoc.getFile().getContentCache();
 
 if (

[PATCH] D89580: SourceManager: Fix an SLocEntry memory regression introduced with FileEntryRef

2020-10-23 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith planned changes to this revision.
dexonsmith added inline comments.



Comment at: clang/include/clang/Basic/SourceManager.h:293
   X.ContentAndKind.setInt(FileCharacter);
-  X.Filename = Filename;
+  const_cast(Con).Filename = Filename;
   return X;

JDevlieghere wrote:
> Would it possibly make more sense to drop the `const` qualifier from the 
> argument? 
Yes, that's probably better. I'll make a prep commit that changes 
`getOrCreateContentCache()` to return non-`const` and thread that through to 
here, and then this is just `Con.Filename = Filename`.


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

https://reviews.llvm.org/D89580

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


[PATCH] D89913: SourceManager: Encapsulate line number mapping into SrcMgr::LineOffsetMapping

2020-10-23 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added inline comments.



Comment at: clang/include/clang/Basic/SourceManager.h:118
+  private:
+unsigned *Storage = nullptr;
+  };

JDevlieghere wrote:
> I guess it's implicit in the implementation, but maybe it's worth adding a 
> comment describing the layout (first element is the size, elements at index i 
> are at index i+1. 
Thanks, good idea; I'll have that in the commit.


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

https://reviews.llvm.org/D89913

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


[clang] dbbc4f4 - SourceManager: Encapsulate line number mapping into SrcMgr::LineOffsetMapping

2020-10-23 Thread Duncan P . N . Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-10-23T12:55:51-04:00
New Revision: dbbc4f4e226be44e484f448be2d308d205c81038

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

LOG: SourceManager: Encapsulate line number mapping into 
SrcMgr::LineOffsetMapping

Put the guts of `ComputeLineNumbers` into `LineOffsetMapping::get` and
`LineOffsetMapping::LineOffsetMapping`.  As a drive-by, store the number
of lines directly in the bump-ptr-allocated array.

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

Added: 
clang/unittests/Basic/LineOffsetMappingTest.cpp

Modified: 
clang/include/clang/Basic/SourceManager.h
clang/lib/Basic/SourceManager.cpp
clang/lib/Lex/ScratchBuffer.cpp
clang/unittests/Basic/CMakeLists.txt

Removed: 




diff  --git a/clang/include/clang/Basic/SourceManager.h 
b/clang/include/clang/Basic/SourceManager.h
index 06bec09cda98..00a790038dbf 100644
--- a/clang/include/clang/Basic/SourceManager.h
+++ b/clang/include/clang/Basic/SourceManager.h
@@ -90,6 +90,35 @@ namespace SrcMgr {
 return CK == C_User_ModuleMap || CK == C_System_ModuleMap;
   }
 
+  /// Mapping of line offsets into a source file. This does not own the storage
+  /// for the line numbers.
+  class LineOffsetMapping {
+  public:
+explicit operator bool() const { return Storage; }
+unsigned size() const {
+  assert(Storage);
+  return Storage[0];
+}
+ArrayRef getLines() const {
+  assert(Storage);
+  return ArrayRef(Storage + 1, Storage + 1 + size());
+}
+const unsigned *begin() const { return getLines().begin(); }
+const unsigned *end() const { return getLines().end(); }
+const unsigned &operator[](int I) const { return getLines()[I]; }
+
+static LineOffsetMapping get(llvm::MemoryBufferRef Buffer,
+ llvm::BumpPtrAllocator &Alloc);
+
+LineOffsetMapping() = default;
+LineOffsetMapping(ArrayRef LineOffsets,
+  llvm::BumpPtrAllocator &Alloc);
+
+  private:
+/// First element is the size, followed by elements at off-by-one indexes.
+unsigned *Storage = nullptr;
+  };
+
   /// One instance of this struct is kept for every file loaded or used.
   ///
   /// This object owns the MemoryBuffer object.
@@ -115,14 +144,9 @@ namespace SrcMgr {
 
 /// A bump pointer allocated array of offsets for each source line.
 ///
-/// This is lazily computed.  This is owned by the SourceManager
+/// This is lazily computed.  The lines are owned by the SourceManager
 /// BumpPointerAllocator object.
-unsigned *SourceLineCache = nullptr;
-
-/// The number of lines in this ContentCache.
-///
-/// This is only valid if SourceLineCache is non-null.
-unsigned NumLines = 0;
+LineOffsetMapping SourceLineCache;
 
 /// Indicates whether the buffer itself was provided to override
 /// the actual file contents.
@@ -157,10 +181,8 @@ namespace SrcMgr {
   OrigEntry = RHS.OrigEntry;
   ContentsEntry = RHS.ContentsEntry;
 
-  assert(!RHS.Buffer && RHS.SourceLineCache == nullptr &&
+  assert(!RHS.Buffer && !RHS.SourceLineCache &&
  "Passed ContentCache object cannot own a buffer.");
-
-  NumLines = RHS.NumLines;
 }
 
 ContentCache &operator=(const ContentCache& RHS) = delete;

diff  --git a/clang/lib/Basic/SourceManager.cpp 
b/clang/lib/Basic/SourceManager.cpp
index d2015b55c03f..778fd0dca329 100644
--- a/clang/lib/Basic/SourceManager.cpp
+++ b/clang/lib/Basic/SourceManager.cpp
@@ -1200,10 +1200,10 @@ unsigned SourceManager::getColumnNumber(FileID FID, 
unsigned FilePos,
   const char *Buf = MemBuf->getBufferStart();
   // See if we just calculated the line number for this FilePos and can use
   // that to lookup the start of the line instead of searching for it.
-  if (LastLineNoFileIDQuery == FID &&
-  LastLineNoContentCache->SourceLineCache != nullptr &&
-  LastLineNoResult < LastLineNoContentCache->NumLines) {
-unsigned *SourceLineCache = LastLineNoContentCache->SourceLineCache;
+  if (LastLineNoFileIDQuery == FID && LastLineNoContentCache->SourceLineCache 
&&
+  LastLineNoResult < LastLineNoContentCache->SourceLineCache.size()) {
+const unsigned *SourceLineCache =
+LastLineNoContentCache->SourceLineCache.begin();
 unsigned LineStart = SourceLineCache[LastLineNoResult - 1];
 unsigned LineEnd = SourceLineCache[LastLineNoResult];
 if (FilePos >= LineStart && FilePos < LineEnd) {
@@ -1274,6 +1274,11 @@ static void ComputeLineNumbers(DiagnosticsEngine &Diag, 
ContentCache *FI,
   if (Invalid)
 return;
 
+  FI->SourceLineCache = LineOffsetMapping::get(*Buffer, Alloc);
+}
+
+LineOffsetMapping LineOffsetMapping::get(llvm::MemoryBufferRef Buffer,
+   

[PATCH] D89913: SourceManager: Encapsulate line number mapping into SrcMgr::LineOffsetMapping

2020-10-23 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGdbbc4f4e226b: SourceManager: Encapsulate line number mapping 
into SrcMgr::LineOffsetMapping (authored by dexonsmith).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D89913?vs=27&id=300333#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89913

Files:
  clang/include/clang/Basic/SourceManager.h
  clang/lib/Basic/SourceManager.cpp
  clang/lib/Lex/ScratchBuffer.cpp
  clang/unittests/Basic/CMakeLists.txt
  clang/unittests/Basic/LineOffsetMappingTest.cpp

Index: clang/unittests/Basic/LineOffsetMappingTest.cpp
===
--- /dev/null
+++ clang/unittests/Basic/LineOffsetMappingTest.cpp
@@ -0,0 +1,79 @@
+//===- unittests/Basic/LineOffsetMappingTest.cpp - Test LineOffsetMapping -===//
+//
+// 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 "clang/Basic/SourceManager.h"
+#include "gtest/gtest.h"
+
+using namespace clang;
+using namespace clang::SrcMgr;
+using namespace llvm;
+
+namespace {
+
+TEST(LineOffsetMappingTest, empty) {
+  LineOffsetMapping Mapping;
+  EXPECT_FALSE(Mapping);
+
+#if !defined(NDEBUG) && GTEST_HAS_DEATH_TEST
+  EXPECT_DEATH((void)Mapping.getLines(), "Assertion");
+#endif
+}
+
+TEST(LineOffsetMappingTest, construct) {
+  BumpPtrAllocator Alloc;
+  unsigned Offsets[] = {0, 10, 20};
+  LineOffsetMapping Mapping(Offsets, Alloc);
+  EXPECT_EQ(3u, Mapping.size());
+  EXPECT_EQ(0u, Mapping[0]);
+  EXPECT_EQ(10u, Mapping[1]);
+  EXPECT_EQ(20u, Mapping[2]);
+
+#if !defined(NDEBUG) && GTEST_HAS_DEATH_TEST
+  EXPECT_DEATH((void)Mapping[3], "Assertion");
+#endif
+}
+
+TEST(LineOffsetMappingTest, constructTwo) {
+  // Confirm allocation size is big enough, convering an off-by-one bug.
+  BumpPtrAllocator Alloc;
+  unsigned Offsets1[] = {0, 10};
+  unsigned Offsets2[] = {0, 20};
+  LineOffsetMapping Mapping1(Offsets1, Alloc);
+  LineOffsetMapping Mapping2(Offsets2, Alloc);
+
+  // Need to check Mapping1 *after* building Mapping2.
+  EXPECT_EQ(2u, Mapping1.size());
+  EXPECT_EQ(0u, Mapping1[0]);
+  EXPECT_EQ(10u, Mapping1[1]);
+  EXPECT_EQ(2u, Mapping2.size());
+  EXPECT_EQ(0u, Mapping2[0]);
+  EXPECT_EQ(20u, Mapping2[1]);
+}
+
+TEST(LineOffsetMappingTest, get) {
+  BumpPtrAllocator Alloc;
+  StringRef Source = "first line\n"
+ "second line\n";
+  auto Mapping = LineOffsetMapping::get(MemoryBufferRef(Source, ""), Alloc);
+  EXPECT_EQ(3u, Mapping.size());
+  EXPECT_EQ(0u, Mapping[0]);
+  EXPECT_EQ(11u, Mapping[1]);
+  EXPECT_EQ(23u, Mapping[2]);
+}
+
+TEST(LineOffsetMappingTest, getMissingFinalNewline) {
+  BumpPtrAllocator Alloc;
+  StringRef Source = "first line\n"
+ "second line";
+  auto Mapping = LineOffsetMapping::get(MemoryBufferRef(Source, ""), Alloc);
+  EXPECT_EQ(2u, Mapping.size());
+  EXPECT_EQ(0u, Mapping[0]);
+  EXPECT_EQ(11u, Mapping[1]);
+}
+
+} // end namespace
Index: clang/unittests/Basic/CMakeLists.txt
===
--- clang/unittests/Basic/CMakeLists.txt
+++ clang/unittests/Basic/CMakeLists.txt
@@ -6,6 +6,7 @@
   CharInfoTest.cpp
   DiagnosticTest.cpp
   FileManagerTest.cpp
+  LineOffsetMappingTest.cpp
   SourceManagerTest.cpp
   )
 
Index: clang/lib/Lex/ScratchBuffer.cpp
===
--- clang/lib/Lex/ScratchBuffer.cpp
+++ clang/lib/Lex/ScratchBuffer.cpp
@@ -41,7 +41,7 @@
 &SourceMgr.getSLocEntry(SourceMgr.getFileID(BufferStartLoc))
  .getFile()
  .getContentCache());
-ContentCache->SourceLineCache = nullptr;
+ContentCache->SourceLineCache = SrcMgr::LineOffsetMapping();
   }
 
   // Prefix the token with a \n, so that it looks like it is the first thing on
Index: clang/lib/Basic/SourceManager.cpp
===
--- clang/lib/Basic/SourceManager.cpp
+++ clang/lib/Basic/SourceManager.cpp
@@ -1200,10 +1200,10 @@
   const char *Buf = MemBuf->getBufferStart();
   // See if we just calculated the line number for this FilePos and can use
   // that to lookup the start of the line instead of searching for it.
-  if (LastLineNoFileIDQuery == FID &&
-  LastLineNoContentCache->SourceLineCache != nullptr &&
-  LastLineNoResult < LastLineNoContentCache->NumLines) {
-unsigned *SourceLineCache = LastLineNoContentCache->SourceLineCache;
+  if (LastLineNoFileIDQuery == FID && LastLineNoContentCache->SourceLineCache &&
+  LastLineNoResult < LastLineNoContentCache->SourceLineCache.size()) {
+const unsigned *SourceLineCache =
+   

[clang] 65d2064 - [CUDA] Improve clang's ability to detect recent CUDA versions.

2020-10-23 Thread Artem Belevich via cfe-commits

Author: Artem Belevich
Date: 2020-10-23T10:03:29-07:00
New Revision: 65d206484c54177641d4b11d42cab1f1acc8c0c7

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

LOG: [CUDA] Improve clang's ability to detect recent CUDA versions.

CUDA-11.1 does not carry version.txt which causes clang to assume that it's
CUDA-7.0, which used to be the only CUDA version w/o version.txt.

In order to tell CUDA-7.0 apart from the new versions, clang now probes for the
presence of libdevice.10.bc which is not present in the old CUDA versions.

This should keep Clang working for CUDA-11.1.

PR47332: https://bugs.llvm.org/show_bug.cgi?id=47332

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

Added: 
clang/test/Driver/Inputs/CUDA_111/usr/local/cuda/bin/.keep
clang/test/Driver/Inputs/CUDA_111/usr/local/cuda/include/.keep
clang/test/Driver/Inputs/CUDA_111/usr/local/cuda/lib/.keep
clang/test/Driver/Inputs/CUDA_111/usr/local/cuda/lib64/.keep

clang/test/Driver/Inputs/CUDA_111/usr/local/cuda/nvvm/libdevice/libdevice.10.bc

Modified: 
clang/lib/Driver/ToolChains/Cuda.cpp
clang/test/Driver/cuda-version-check.cu

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Cuda.cpp 
b/clang/lib/Driver/ToolChains/Cuda.cpp
index 217a0155a52d..197685b51df4 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -155,9 +155,14 @@ CudaInstallationDetector::CudaInstallationDetector(
 llvm::ErrorOr> VersionFile =
 FS.getBufferForFile(InstallPath + "/version.txt");
 if (!VersionFile) {
-  // CUDA 7.0 doesn't have a version.txt, so guess that's our version if
-  // version.txt isn't present.
-  Version = CudaVersion::CUDA_70;
+  // CUDA 7.0 and CUDA 11.1+ do not have version.txt file.
+  // Use libdevice file to distinguish 7.0 from the new versions.
+  if (FS.exists(LibDevicePath + "/libdevice.10.bc")) {
+Version = CudaVersion::LATEST;
+DetectedVersionIsNotSupported = Version > 
CudaVersion::LATEST_SUPPORTED;
+  } else {
+Version = CudaVersion::CUDA_70;
+  }
 } else {
   ParseCudaVersionFile((*VersionFile)->getBuffer());
 }

diff  --git a/clang/test/Driver/Inputs/CUDA_111/usr/local/cuda/bin/.keep 
b/clang/test/Driver/Inputs/CUDA_111/usr/local/cuda/bin/.keep
new file mode 100644
index ..e69de29bb2d1

diff  --git a/clang/test/Driver/Inputs/CUDA_111/usr/local/cuda/include/.keep 
b/clang/test/Driver/Inputs/CUDA_111/usr/local/cuda/include/.keep
new file mode 100644
index ..e69de29bb2d1

diff  --git a/clang/test/Driver/Inputs/CUDA_111/usr/local/cuda/lib/.keep 
b/clang/test/Driver/Inputs/CUDA_111/usr/local/cuda/lib/.keep
new file mode 100644
index ..e69de29bb2d1

diff  --git a/clang/test/Driver/Inputs/CUDA_111/usr/local/cuda/lib64/.keep 
b/clang/test/Driver/Inputs/CUDA_111/usr/local/cuda/lib64/.keep
new file mode 100644
index ..e69de29bb2d1

diff  --git 
a/clang/test/Driver/Inputs/CUDA_111/usr/local/cuda/nvvm/libdevice/libdevice.10.bc
 
b/clang/test/Driver/Inputs/CUDA_111/usr/local/cuda/nvvm/libdevice/libdevice.10.bc
new file mode 100644
index ..e69de29bb2d1

diff  --git a/clang/test/Driver/cuda-version-check.cu 
b/clang/test/Driver/cuda-version-check.cu
index a09b248304f2..1e6af029202f 100644
--- a/clang/test/Driver/cuda-version-check.cu
+++ b/clang/test/Driver/cuda-version-check.cu
@@ -10,6 +10,11 @@
 // RUN:FileCheck %s --check-prefix=OK
 // RUN: %clang --target=x86_64-linux -v -### --cuda-gpu-arch=sm_60 
--cuda-path=%S/Inputs/CUDA-unknown/usr/local/cuda 2>&1 %s | \
 // RUN:FileCheck %s --check-prefix=UNKNOWN_VERSION
+// CUDA versions after 11.0 (update 1) do not carry version.txt file. Make sure
+// we still detect them as a new version and handle them the same as we handle
+// other new CUDA versions.
+// RUN: %clang --target=x86_64-linux -v -### --cuda-gpu-arch=sm_60 
--cuda-path=%S/Inputs/CUDA_111/usr/local/cuda 2>&1 %s | \
+// RUN:FileCheck %s --check-prefix=UNKNOWN_VERSION
 // Make sure that we don't warn about CUDA version during C++ compilation.
 // RUN: %clang --target=x86_64-linux -v -### -x c++ --cuda-gpu-arch=sm_60 \
 // RUN:--cuda-path=%S/Inputs/CUDA-unknown/usr/local/cuda 2>&1 %s | \
@@ -65,5 +70,5 @@
 // ERR_SM61: error: GPU arch sm_61 {{.*}}
 // ERR_SM61-NOT: error: GPU arch sm_61
 
-// UNKNOWN_VERSION: Unknown CUDA version 999.999. Assuming the latest 
supported version
+// UNKNOWN_VERSION: Unknown CUDA version {{.*}}. Assuming the latest supported 
version
 // UNKNOWN_VERSION_CXX-NOT: Unknown CUDA version



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


[PATCH] D89752: [CUDA] Improve clang's ability to detect recent CUDA versions.

2020-10-23 Thread Artem Belevich via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG65d206484c54: [CUDA] Improve clang's ability to detect 
recent CUDA versions. (authored by tra).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89752

Files:
  clang/lib/Driver/ToolChains/Cuda.cpp
  clang/test/Driver/Inputs/CUDA_111/usr/local/cuda/bin/.keep
  clang/test/Driver/Inputs/CUDA_111/usr/local/cuda/include/.keep
  clang/test/Driver/Inputs/CUDA_111/usr/local/cuda/lib/.keep
  clang/test/Driver/Inputs/CUDA_111/usr/local/cuda/lib64/.keep
  
clang/test/Driver/Inputs/CUDA_111/usr/local/cuda/nvvm/libdevice/libdevice.10.bc
  clang/test/Driver/cuda-version-check.cu


Index: clang/test/Driver/cuda-version-check.cu
===
--- clang/test/Driver/cuda-version-check.cu
+++ clang/test/Driver/cuda-version-check.cu
@@ -10,6 +10,11 @@
 // RUN:FileCheck %s --check-prefix=OK
 // RUN: %clang --target=x86_64-linux -v -### --cuda-gpu-arch=sm_60 
--cuda-path=%S/Inputs/CUDA-unknown/usr/local/cuda 2>&1 %s | \
 // RUN:FileCheck %s --check-prefix=UNKNOWN_VERSION
+// CUDA versions after 11.0 (update 1) do not carry version.txt file. Make sure
+// we still detect them as a new version and handle them the same as we handle
+// other new CUDA versions.
+// RUN: %clang --target=x86_64-linux -v -### --cuda-gpu-arch=sm_60 
--cuda-path=%S/Inputs/CUDA_111/usr/local/cuda 2>&1 %s | \
+// RUN:FileCheck %s --check-prefix=UNKNOWN_VERSION
 // Make sure that we don't warn about CUDA version during C++ compilation.
 // RUN: %clang --target=x86_64-linux -v -### -x c++ --cuda-gpu-arch=sm_60 \
 // RUN:--cuda-path=%S/Inputs/CUDA-unknown/usr/local/cuda 2>&1 %s | \
@@ -65,5 +70,5 @@
 // ERR_SM61: error: GPU arch sm_61 {{.*}}
 // ERR_SM61-NOT: error: GPU arch sm_61
 
-// UNKNOWN_VERSION: Unknown CUDA version 999.999. Assuming the latest 
supported version
+// UNKNOWN_VERSION: Unknown CUDA version {{.*}}. Assuming the latest supported 
version
 // UNKNOWN_VERSION_CXX-NOT: Unknown CUDA version
Index: clang/lib/Driver/ToolChains/Cuda.cpp
===
--- clang/lib/Driver/ToolChains/Cuda.cpp
+++ clang/lib/Driver/ToolChains/Cuda.cpp
@@ -155,9 +155,14 @@
 llvm::ErrorOr> VersionFile =
 FS.getBufferForFile(InstallPath + "/version.txt");
 if (!VersionFile) {
-  // CUDA 7.0 doesn't have a version.txt, so guess that's our version if
-  // version.txt isn't present.
-  Version = CudaVersion::CUDA_70;
+  // CUDA 7.0 and CUDA 11.1+ do not have version.txt file.
+  // Use libdevice file to distinguish 7.0 from the new versions.
+  if (FS.exists(LibDevicePath + "/libdevice.10.bc")) {
+Version = CudaVersion::LATEST;
+DetectedVersionIsNotSupported = Version > 
CudaVersion::LATEST_SUPPORTED;
+  } else {
+Version = CudaVersion::CUDA_70;
+  }
 } else {
   ParseCudaVersionFile((*VersionFile)->getBuffer());
 }


Index: clang/test/Driver/cuda-version-check.cu
===
--- clang/test/Driver/cuda-version-check.cu
+++ clang/test/Driver/cuda-version-check.cu
@@ -10,6 +10,11 @@
 // RUN:FileCheck %s --check-prefix=OK
 // RUN: %clang --target=x86_64-linux -v -### --cuda-gpu-arch=sm_60 --cuda-path=%S/Inputs/CUDA-unknown/usr/local/cuda 2>&1 %s | \
 // RUN:FileCheck %s --check-prefix=UNKNOWN_VERSION
+// CUDA versions after 11.0 (update 1) do not carry version.txt file. Make sure
+// we still detect them as a new version and handle them the same as we handle
+// other new CUDA versions.
+// RUN: %clang --target=x86_64-linux -v -### --cuda-gpu-arch=sm_60 --cuda-path=%S/Inputs/CUDA_111/usr/local/cuda 2>&1 %s | \
+// RUN:FileCheck %s --check-prefix=UNKNOWN_VERSION
 // Make sure that we don't warn about CUDA version during C++ compilation.
 // RUN: %clang --target=x86_64-linux -v -### -x c++ --cuda-gpu-arch=sm_60 \
 // RUN:--cuda-path=%S/Inputs/CUDA-unknown/usr/local/cuda 2>&1 %s | \
@@ -65,5 +70,5 @@
 // ERR_SM61: error: GPU arch sm_61 {{.*}}
 // ERR_SM61-NOT: error: GPU arch sm_61
 
-// UNKNOWN_VERSION: Unknown CUDA version 999.999. Assuming the latest supported version
+// UNKNOWN_VERSION: Unknown CUDA version {{.*}}. Assuming the latest supported version
 // UNKNOWN_VERSION_CXX-NOT: Unknown CUDA version
Index: clang/lib/Driver/ToolChains/Cuda.cpp
===
--- clang/lib/Driver/ToolChains/Cuda.cpp
+++ clang/lib/Driver/ToolChains/Cuda.cpp
@@ -155,9 +155,14 @@
 llvm::ErrorOr> VersionFile =
 FS.getBufferForFile(InstallPath + "/version.txt");
 if (!VersionFile) {
-  // CUDA 7.0 doesn't have a version.txt, so guess that's our version if
-  // version.txt isn't present.
-  Version = CudaVersion::CUDA_70;
+  // CUDA 7.0 and CUDA 11.1+ do not h

[clang] e7fe125 - [CUDA] Extract CUDA version from cuda.h if version.txt is not found

2020-10-23 Thread Artem Belevich via cfe-commits

Author: Artem Belevich
Date: 2020-10-23T10:03:30-07:00
New Revision: e7fe125b776bf08d95e60ff3354a5c836218a0e6

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

LOG: [CUDA] Extract CUDA version from cuda.h if version.txt is not found

If CUDA version can not be determined based on version.txt file, attempt to find
CUDA_VERSION macro in cuda.h.

This is a follow-up to D89752,

Differntial Revision: https://reviews.llvm.org/D89832

Added: 
clang/test/Driver/Inputs/CUDA_102/usr/local/cuda/bin/.keep
clang/test/Driver/Inputs/CUDA_102/usr/local/cuda/include/.keep
clang/test/Driver/Inputs/CUDA_102/usr/local/cuda/lib/.keep
clang/test/Driver/Inputs/CUDA_102/usr/local/cuda/lib64/.keep

clang/test/Driver/Inputs/CUDA_102/usr/local/cuda/nvvm/libdevice/libdevice.10.bc
clang/test/Driver/Inputs/CUDA_102/usr/local/cuda/version.txt
clang/test/Driver/Inputs/CUDA_111/usr/local/cuda/include/cuda.h

Modified: 
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/lib/Driver/ToolChains/Cuda.cpp
clang/lib/Driver/ToolChains/Cuda.h
clang/test/Driver/cuda-version-check.cu

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index ced2d4435cfe..5336e7648001 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -69,7 +69,7 @@ def err_drv_cuda_version_unsupported : Error<
   "install, pass a 
diff erent GPU arch with --cuda-gpu-arch, or pass "
   "--no-cuda-version-check.">;
 def warn_drv_unknown_cuda_version: Warning<
-  "Unknown CUDA version %0. Assuming the latest supported version %1">,
+  "Unknown CUDA version. %0 Assuming the latest supported version %1">,
   InGroup;
 def err_drv_cuda_host_arch : Error<"unsupported architecture '%0' for host 
compilation.">;
 def err_drv_mix_cuda_hip : Error<"Mixed Cuda and HIP compilation is not 
supported.">;

diff  --git a/clang/lib/Driver/ToolChains/Cuda.cpp 
b/clang/lib/Driver/ToolChains/Cuda.cpp
index 197685b51df4..58178d5d11bc 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -16,6 +16,7 @@
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/Options.h"
+#include "llvm/ADT/Optional.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Host.h"
@@ -32,29 +33,80 @@ using namespace clang::driver::tools;
 using namespace clang;
 using namespace llvm::opt;
 
+namespace {
+struct CudaVersionInfo {
+  std::string DetectedVersion;
+  CudaVersion Version;
+};
 // Parses the contents of version.txt in an CUDA installation.  It should
 // contain one line of the from e.g. "CUDA Version 7.5.2".
-void CudaInstallationDetector::ParseCudaVersionFile(llvm::StringRef V) {
-  Version = CudaVersion::UNKNOWN;
+CudaVersionInfo parseCudaVersionFile(llvm::StringRef V) {
+  V = V.trim();
   if (!V.startswith("CUDA Version "))
-return;
+return {V.str(), CudaVersion::UNKNOWN};
   V = V.substr(strlen("CUDA Version "));
   SmallVector VersionParts;
   V.split(VersionParts, '.');
-  if (VersionParts.size() < 2)
-return;
-  DetectedVersion = join_items(".", VersionParts[0], VersionParts[1]);
-  Version = CudaStringToVersion(DetectedVersion);
-  if (Version != CudaVersion::UNKNOWN) {
-// TODO(tra): remove the warning once we have all features of 10.2 and 11.0
-// implemented.
-DetectedVersionIsNotSupported = Version > CudaVersion::LATEST_SUPPORTED;
-return;
-  }
+  return {"version.txt: " + V.str() + ".",
+  VersionParts.size() < 2
+  ? CudaVersion::UNKNOWN
+  : CudaStringToVersion(
+join_items(".", VersionParts[0], VersionParts[1]))};
+}
+
+CudaVersion getCudaVersion(uint32_t raw_version) {
+  if (raw_version < 7050)
+return CudaVersion::CUDA_70;
+  if (raw_version < 8000)
+return CudaVersion::CUDA_75;
+  if (raw_version < 9000)
+return CudaVersion::CUDA_80;
+  if (raw_version < 9010)
+return CudaVersion::CUDA_90;
+  if (raw_version < 9020)
+return CudaVersion::CUDA_91;
+  if (raw_version < 1)
+return CudaVersion::CUDA_92;
+  if (raw_version < 10010)
+return CudaVersion::CUDA_100;
+  if (raw_version < 10020)
+return CudaVersion::CUDA_101;
+  if (raw_version < 11000)
+return CudaVersion::CUDA_102;
+  if (raw_version < 11010)
+return CudaVersion::CUDA_110;
+  return CudaVersion::LATEST;
+}
 
-  Version = CudaVersion::LATEST_SUPPORTED;
-  DetectedVersionIsNotSupported = true;
+CudaVersionInfo parseCudaHFile(llvm::StringRef Input) {
+  // Helper lambda which skips the words if the line starts with them or 
returns
+  // None otherwise.
+  auto Starts

[PATCH] D82756: Port some floating point options to new option marshalling infrastructure

2020-10-23 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added a comment.

In D82756#2350233 , @jansvoboda11 
wrote:

> Correct me if I'm wrong, but when generating the command line, all "implied" 
> flags would be hidden, even if they were explicit in the original comand line:
>
> - original command line:  `clang -cc1 -cl-unsafe-math-optimizations 
> -cl-mad-enable -menable-unsafe-fp-math -mreassociate -fno-signed-zeros 
> -freciprocal-math -fapprox-func [...]`
> - generated command line: `clang -cc1 -cl-unsafe-math-optimizations [...]`
>
> This might be a bit surprising, but I don't think this would cause issues for 
> explicit modules. What are your thoughts?

I think this is fine. It's similar to a case where the caller might explicitly 
specify the default value, and it'll get canonicalized out.

> Formalizing the "implies" relationships would make it possible to remove the 
> ordering-sensitivity and possibly generate implied flags even when explicitly 
> passed to `cc1`. It would complicate the TableGen backend, which I'd prefer 
> to keep as simple as possible.

I was't thinking of dropping the ordering-sensitivity. Instead, you could just 
error if the referenced option hadn't declared already. One idea would be to 
change the tablegen to something like:

  MarshallingInfoFlag<
  "CodeGenOpts.LessPreciseFPMAD",
  DefaultAnyOf<[cl_unsafe_math_optimizations, cl_fast_relaxed_math]>>;

in the definition of `cl_mad_enable`, then:

- error if they aren't defined first; and
- construct a default value out of the key-paths.

I think this would less error-prone for maintenance, since it designs away some 
really subtle bugs.


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

https://reviews.llvm.org/D82756

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


[PATCH] D82756: Port some floating point options to new option marshalling infrastructure

2020-10-23 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added a comment.

IOW, the goal of formalizing would just be to:

- error if the `.td` file defined options in the wrong order to get correct 
parsing
- automatically generate the code for default value, instead of having to 
re-type the name of the keypath


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

https://reviews.llvm.org/D82756

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


[PATCH] D69844: [clang][Basic] Integrate SourceLocation with FoldingSet, NFCI

2020-10-23 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added inline comments.



Comment at: clang/lib/Analysis/PathDiagnostic.cpp:1088
+  ID.Add(Range.getEnd());
+  ID.Add(static_cast(Loc));
 }

I'm surprised you need this `static_cast`, can you explain why it was necessary?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69844

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


[PATCH] D89914: SourceManager: Make LastLineNoContentCache and ContentCache::SourceLineCache mutable, NFC

2020-10-23 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5431c37b55e2: SourceManager: Make LastLineNoContentCache and 
ContentCache::SourceLineCache… (authored by dexonsmith).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D89914?vs=299812&id=300339#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89914

Files:
  clang/include/clang/Basic/SourceManager.h
  clang/lib/Basic/SourceManager.cpp
  clang/lib/Lex/ScratchBuffer.cpp

Index: clang/lib/Lex/ScratchBuffer.cpp
===
--- clang/lib/Lex/ScratchBuffer.cpp
+++ clang/lib/Lex/ScratchBuffer.cpp
@@ -37,11 +37,10 @@
   else {
 // Clear out the source line cache if it's already been computed.
 // FIXME: Allow this to be incrementally extended.
-auto *ContentCache = const_cast(
-&SourceMgr.getSLocEntry(SourceMgr.getFileID(BufferStartLoc))
- .getFile()
- .getContentCache());
-ContentCache->SourceLineCache = SrcMgr::LineOffsetMapping();
+SourceMgr.getSLocEntry(SourceMgr.getFileID(BufferStartLoc))
+.getFile()
+.getContentCache()
+.SourceLineCache = SrcMgr::LineOffsetMapping();
   }
 
   // Prefix the token with a \n, so that it looks like it is the first thing on
Index: clang/lib/Basic/SourceManager.cpp
===
--- clang/lib/Basic/SourceManager.cpp
+++ clang/lib/Basic/SourceManager.cpp
@@ -1261,20 +1261,20 @@
 #endif
 
 static LLVM_ATTRIBUTE_NOINLINE void
-ComputeLineNumbers(DiagnosticsEngine &Diag, ContentCache *FI,
+ComputeLineNumbers(DiagnosticsEngine &Diag, const ContentCache &FI,
llvm::BumpPtrAllocator &Alloc,
const SourceManager &SM, bool &Invalid);
-static void ComputeLineNumbers(DiagnosticsEngine &Diag, ContentCache *FI,
+static void ComputeLineNumbers(DiagnosticsEngine &Diag, const ContentCache &FI,
llvm::BumpPtrAllocator &Alloc,
const SourceManager &SM, bool &Invalid) {
   // Note that calling 'getBuffer()' may lazily page in the file.
   llvm::Optional Buffer =
-  FI->getBufferOrNone(Diag, SM.getFileManager(), SourceLocation());
+  FI.getBufferOrNone(Diag, SM.getFileManager(), SourceLocation());
   Invalid = !Buffer;
   if (Invalid)
 return;
 
-  FI->SourceLineCache = LineOffsetMapping::get(*Buffer, Alloc);
+  FI.SourceLineCache = LineOffsetMapping::get(*Buffer, Alloc);
 }
 
 LineOffsetMapping LineOffsetMapping::get(llvm::MemoryBufferRef Buffer,
@@ -1324,7 +1324,7 @@
 return 1;
   }
 
-  ContentCache *Content;
+  const ContentCache *Content;
   if (LastLineNoFileIDQuery == FID)
 Content = LastLineNoContentCache;
   else {
@@ -1336,14 +1336,14 @@
   return 1;
 }
 
-Content = const_cast(&Entry.getFile().getContentCache());
+Content = &Entry.getFile().getContentCache();
   }
 
   // If this is the first use of line information for this buffer, compute the
   /// SourceLineCache for it on demand.
   if (!Content->SourceLineCache) {
 bool MyInvalid = false;
-ComputeLineNumbers(Diag, Content, ContentCacheAlloc, *this, MyInvalid);
+ComputeLineNumbers(Diag, *Content, ContentCacheAlloc, *this, MyInvalid);
 if (Invalid)
   *Invalid = MyInvalid;
 if (MyInvalid)
@@ -1685,14 +1685,13 @@
   if (Line == 1 && Col == 1)
 return FileLoc;
 
-  ContentCache *Content =
-  const_cast(&Entry.getFile().getContentCache());
+  const ContentCache *Content = &Entry.getFile().getContentCache();
 
   // If this is the first use of line information for this buffer, compute the
   // SourceLineCache for it on demand.
   if (!Content->SourceLineCache) {
 bool MyInvalid = false;
-ComputeLineNumbers(Diag, Content, ContentCacheAlloc, *this, MyInvalid);
+ComputeLineNumbers(Diag, *Content, ContentCacheAlloc, *this, MyInvalid);
 if (MyInvalid)
   return SourceLocation();
   }
Index: clang/include/clang/Basic/SourceManager.h
===
--- clang/include/clang/Basic/SourceManager.h
+++ clang/include/clang/Basic/SourceManager.h
@@ -146,7 +146,7 @@
 ///
 /// This is lazily computed.  The lines are owned by the SourceManager
 /// BumpPointerAllocator object.
-LineOffsetMapping SourceLineCache;
+mutable LineOffsetMapping SourceLineCache;
 
 /// Indicates whether the buffer itself was provided to override
 /// the actual file contents.
@@ -719,7 +719,7 @@
   /// These ivars serve as a cache used in the getLineNumber
   /// method which is used to speedup getLineNumber calls to nearby locations.
   mutable FileID LastLineNoFileIDQuery;
-  mutable SrcMgr::ContentCache *LastLineNoContentCache;
+  mutable const SrcMgr::ContentCache *LastLineNoContentCache;
   mutable unsigned LastLine

[clang] 5431c37 - SourceManager: Make LastLineNoContentCache and ContentCache::SourceLineCache mutable, NFC

2020-10-23 Thread Duncan P . N . Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-10-23T13:22:47-04:00
New Revision: 5431c37b55e2c2952b6b56c9690bd1ce05b23c7e

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

LOG: SourceManager: Make LastLineNoContentCache and 
ContentCache::SourceLineCache mutable, NFC

Avoid some noisy `const_cast`s by making `ContentCache::SourceLineCache`
and `SourceManager::LastLineNoContentCache` both mutable.

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

Added: 


Modified: 
clang/include/clang/Basic/SourceManager.h
clang/lib/Basic/SourceManager.cpp
clang/lib/Lex/ScratchBuffer.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/SourceManager.h 
b/clang/include/clang/Basic/SourceManager.h
index 00a790038dbf..a458ef7e72a8 100644
--- a/clang/include/clang/Basic/SourceManager.h
+++ b/clang/include/clang/Basic/SourceManager.h
@@ -146,7 +146,7 @@ namespace SrcMgr {
 ///
 /// This is lazily computed.  The lines are owned by the SourceManager
 /// BumpPointerAllocator object.
-LineOffsetMapping SourceLineCache;
+mutable LineOffsetMapping SourceLineCache;
 
 /// Indicates whether the buffer itself was provided to override
 /// the actual file contents.
@@ -719,7 +719,7 @@ class SourceManager : public RefCountedBase {
   /// These ivars serve as a cache used in the getLineNumber
   /// method which is used to speedup getLineNumber calls to nearby locations.
   mutable FileID LastLineNoFileIDQuery;
-  mutable SrcMgr::ContentCache *LastLineNoContentCache;
+  mutable const SrcMgr::ContentCache *LastLineNoContentCache;
   mutable unsigned LastLineNoFilePos;
   mutable unsigned LastLineNoResult;
 

diff  --git a/clang/lib/Basic/SourceManager.cpp 
b/clang/lib/Basic/SourceManager.cpp
index 778fd0dca329..f8607b0d4c24 100644
--- a/clang/lib/Basic/SourceManager.cpp
+++ b/clang/lib/Basic/SourceManager.cpp
@@ -1261,20 +1261,20 @@ unsigned 
SourceManager::getPresumedColumnNumber(SourceLocation Loc,
 #endif
 
 static LLVM_ATTRIBUTE_NOINLINE void
-ComputeLineNumbers(DiagnosticsEngine &Diag, ContentCache *FI,
+ComputeLineNumbers(DiagnosticsEngine &Diag, const ContentCache &FI,
llvm::BumpPtrAllocator &Alloc,
const SourceManager &SM, bool &Invalid);
-static void ComputeLineNumbers(DiagnosticsEngine &Diag, ContentCache *FI,
+static void ComputeLineNumbers(DiagnosticsEngine &Diag, const ContentCache &FI,
llvm::BumpPtrAllocator &Alloc,
const SourceManager &SM, bool &Invalid) {
   // Note that calling 'getBuffer()' may lazily page in the file.
   llvm::Optional Buffer =
-  FI->getBufferOrNone(Diag, SM.getFileManager(), SourceLocation());
+  FI.getBufferOrNone(Diag, SM.getFileManager(), SourceLocation());
   Invalid = !Buffer;
   if (Invalid)
 return;
 
-  FI->SourceLineCache = LineOffsetMapping::get(*Buffer, Alloc);
+  FI.SourceLineCache = LineOffsetMapping::get(*Buffer, Alloc);
 }
 
 LineOffsetMapping LineOffsetMapping::get(llvm::MemoryBufferRef Buffer,
@@ -1324,7 +1324,7 @@ unsigned SourceManager::getLineNumber(FileID FID, 
unsigned FilePos,
 return 1;
   }
 
-  ContentCache *Content;
+  const ContentCache *Content;
   if (LastLineNoFileIDQuery == FID)
 Content = LastLineNoContentCache;
   else {
@@ -1336,14 +1336,14 @@ unsigned SourceManager::getLineNumber(FileID FID, 
unsigned FilePos,
   return 1;
 }
 
-Content = const_cast(&Entry.getFile().getContentCache());
+Content = &Entry.getFile().getContentCache();
   }
 
   // If this is the first use of line information for this buffer, compute the
   /// SourceLineCache for it on demand.
   if (!Content->SourceLineCache) {
 bool MyInvalid = false;
-ComputeLineNumbers(Diag, Content, ContentCacheAlloc, *this, MyInvalid);
+ComputeLineNumbers(Diag, *Content, ContentCacheAlloc, *this, MyInvalid);
 if (Invalid)
   *Invalid = MyInvalid;
 if (MyInvalid)
@@ -1685,14 +1685,13 @@ SourceLocation SourceManager::translateLineCol(FileID 
FID,
   if (Line == 1 && Col == 1)
 return FileLoc;
 
-  ContentCache *Content =
-  const_cast(&Entry.getFile().getContentCache());
+  const ContentCache *Content = &Entry.getFile().getContentCache();
 
   // If this is the first use of line information for this buffer, compute the
   // SourceLineCache for it on demand.
   if (!Content->SourceLineCache) {
 bool MyInvalid = false;
-ComputeLineNumbers(Diag, Content, ContentCacheAlloc, *this, MyInvalid);
+ComputeLineNumbers(Diag, *Content, ContentCacheAlloc, *this, MyInvalid);
 if (MyInvalid)
   return SourceLocation();
   }

diff  --git a/clang/lib/Lex/ScratchBuffer.cpp b/clang/lib/Lex/ScratchBuffer.cpp
index 56ea9b71fd02..51435225a676 100644
--- a/clang/lib/Lex/Scra

[PATCH] D83448: [CodeGen] Emit destructor calls to destruct non-trivial C struct temporaries created by conditional and assignment operators

2020-10-23 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83448

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


[PATCH] D89987: [analyzer] [NFC] Rename SymbolRef to SymExprRef

2020-10-23 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Honestly i'd rather eliminate `SymExpr` and go with `Symbol` everywhere. It's 
an overloaded term but appending "Expr" to it doesn't really make it 
significantly less overloaded. We're also properly namespaced so there wouldn't 
be any linking issues with the rest of LLVM. "Symbol" is catchy and it's one of 
the most important concepts to grasp in the static analyzer, i'd love to keep 
it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89987

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


[PATCH] D89982: [analyzer] [NFC] Simplify SVal::getAsLocSymbol function using existing functions

2020-10-23 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.
This revision is now accepted and ready to land.

Looks correct, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89982

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


[PATCH] D89909: [SYCL] Implement SYCL address space attributes handling

2020-10-23 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: clang/lib/Basic/Targets/AMDGPU.cpp:57
+Constant, // sycl_constant
+Private,  // sycl_private
 Generic,  // ptr32_sptr

I feel like we may be outgrowing these address-space map arrays.



Comment at: clang/lib/CodeGen/CGCall.cpp:4596
+
IRFuncTy->getParamType(FirstIRArg));
+}
+

This seems problematic; code like this shouldn't be necessary in every place 
that uses a pointer value.  The general rule needs to be that expression 
emission produces a value of its expected type, so the places that emit 
pointers need to be casting to the generic address space.  We can avoid that in 
some special expression emitters, like maybe EmitLValue, as long as the LValue 
records what happened and can apply the appropriate transform later.

Also, in IRGen we work as much as possible with AST address spaces rather than 
IR address spaces.  That is, code like this that's checking for address space 
mismatches needs to be comparing the source AST address space with the 
destination AST address space and calling a method on the TargetInfo when a 
mismatch is detected, rather than comparing IR address spaces and directly 
building an `addrspacecast`.  The idea is that in principle a target should be 
able to have two logical address spaces that are actually implemented in IR 
with the same underlying address space, with some arbitrary transform between 
them.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89909

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


[PATCH] D90023: [Syntax] Add iterators over children of syntax trees.

2020-10-23 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas added a comment.

Thanks Sam! I learned a lot from your patch ^^




Comment at: clang/include/clang/Tooling/Syntax/Tree.h:157-184
+  /// Iterator over children (common base for const/non-const).
+  /// Not invalidated by tree mutations (holds a stable node pointer).
+  template 
+  class child_iterator_base
+  : public llvm::iterator_facade_base {
+  protected:

I think we should only have an iterator through `Node`s, not a general one like 
this.

In general `Tree` has *heterogeneous* children:
For instance, `1+2` yields the syntax tree:
```
BinaryOperatorExpression
|-  IntegerLiteralExpression
|-  Leaf
`- IntegerLiteralExpression
```

Very rarely will syntax trees have all their children of the same kind, so I 
don't think it makes sense to try an provide an iterator template. That makes 
sense for lists , because generally they *have* the same kind. But in that case 
we provide special iterators for lists only.




Comment at: clang/include/clang/Tooling/Syntax/Tree.h:202-219
+  /// child_iterator is not invalidated by mutations.
+  struct child_iterator : child_iterator_base {
+using Base::Base;
+  };
+  struct const_child_iterator
+  : child_iterator_base {
+using Base::Base;

TL;DR:
`child_iterator` -> `ChildIterator`
`const_child_iterator` -> `ConstChildIterator`
`children` -> `getChildren`

I see you followed the naming convention of the ClangAST, which makes loads of 
sense. 

In syntax trees we follow the naming conventions of the [conding 
standard](https://llvm.org/docs/CodingStandards.html#name-types-functions-variables-and-enumerators-properly)
 -- just because we want consistency and we had to pick a guideline to follow 
-- according to that, functions should be verb like and names should be camel 
case.

If like us you chose `const_child_iterator` and `children` kind of "just 
because", could you change it to follow `ConstChildIterator` and `getChildren` 
respectively. 



Comment at: clang/lib/Tooling/Syntax/Tree.cpp:22-23
   if (auto *T = dyn_cast(N)) {
-for (const auto *C = T->getFirstChild(); C; C = C->getNextSibling())
-  traverse(C, Visit);
+for (const syntax::Node &C : T->children())
+  traverse(&C, Visit);
   }

Hmm... 
That looks funny, if the user uses a range-based for loop and forgets the `&`, 
then we would be copying the Node???

Also in many places we had to get the address to the node. That is not really 
consistent with how the syntax trees API's were designed, they generally take 
pointers instead of references. (that said we could obviously reconsider those 
design choices)



Comment at: clang/unittests/Tooling/Syntax/TreeTest.cpp:129
 
+TEST_F(TreeTest, Iterators) {
+  buildTree("", allTestClangConfigs().front());

Suggestion:
I would split this into `Iterators` and `ConstIterators`.



Comment at: clang/unittests/Tooling/Syntax/TreeTest.cpp:139
+  NodeKind::TranslationUnit);
+  const syntax::Tree *ConstTree = Tree;
+

nit, feel free to ignore.



Comment at: clang/unittests/Tooling/Syntax/TreeTest.cpp:159-169
+  for (unsigned I = 0; I < 3; ++I) {
+EXPECT_EQ(It, CIt);
+EXPECT_TRUE(It);
+EXPECT_TRUE(CIt);
+EXPECT_EQ(It.asPointer(), Children[I]);
+EXPECT_EQ(CIt.asPointer(), Children[I]);
+EXPECT_EQ(&*It, Children[I]);

Is there a reason why you didn't use a range-based for loop over Children?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90023

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


[PATCH] D71726: Let clang atomic builtins fetch add/sub support floating point types

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

In D71726#2207700 , @yaxunl wrote:

> clang does not always emit atomic instructions for atomic builtins. Clang may 
> emit lib calls for atomic builtins. Basically clang checks target info about 
> max atomic inline width and if the desired atomic operation exceeds the 
> supported atomic inline width, clang will emit lib calls for atomic builtins. 
> The rationale is that the lib calls may be faster than the IR generated by 
> the LLVM pass. This behavior has long existed and it also applies to fp 
> atomics. I don't think emitting lib calls for atomic builtins is a bug. 
> However, this does introduce the issue about whether the library functions 
> for atomics are available for a specific target. As I said, only the target 
> owners have the answer and therefore I introduced the target hook.

If we want the frontend to emit an error when the target doesn't support 
library-based atomics, that seems fine, but there's no reason to only do so for 
floating-point types.  That is, we should have a TargetInfo method that asks 
whether atomics at a given size and alignment are supported at all, similar to 
what we have for "builtin" (lock-free) atomics, and we should check it for all 
the atomic types and operations.

Actually, maybe we should take the existing hook and have it return one of { 
LockFree, Library, Unsupported }.


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

https://reviews.llvm.org/D71726

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


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

2020-10-23 Thread Kevin P. Neal via Phabricator via cfe-commits
kpn added inline comments.



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

sepavloff wrote:
> This check can be lifted to just after the definition of `OldFPFeatures`.
Actually, no, because this leaves OldExcept and OldRounding uninitialized when 
they get used by the destructor.



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

sepavloff wrote:
> kpn wrote:
> > sepavloff wrote:
> > > Why they are wrong?
> > Because the #pragma covers the entire file and sets exception handling to 
> > "strict". Thus all constrained intrinsic calls should be "strict", and if 
> > they are "maytrap" or "ignore" then we have a bug.
> What is the reason for that? Does `#pragma float_control` work incorrectly? 
> Why  in `clang/test/CodeGen/complex-math-strictfp.c` exception handling is 
> correct?
The #pragma works just fine. The problem is that we need to get the strictfp 
bits from the AST to the IRBuilder, and we haven't finished implementing that. 
So sometimes it works, like in complex-math-strictfp.c, and sometimes it 
doesn't. As you can see in the tests in this patch.


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

https://reviews.llvm.org/D88913

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


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

2020-10-23 Thread Kevin P. Neal via Phabricator via cfe-commits
kpn added inline comments.



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

kpn wrote:
> sepavloff wrote:
> > kpn wrote:
> > > sepavloff wrote:
> > > > Why they are wrong?
> > > Because the #pragma covers the entire file and sets exception handling to 
> > > "strict". Thus all constrained intrinsic calls should be "strict", and if 
> > > they are "maytrap" or "ignore" then we have a bug.
> > What is the reason for that? Does `#pragma float_control` work incorrectly? 
> > Why  in `clang/test/CodeGen/complex-math-strictfp.c` exception handling is 
> > correct?
> The #pragma works just fine. The problem is that we need to get the strictfp 
> bits from the AST to the IRBuilder, and we haven't finished implementing 
> that. So sometimes it works, like in complex-math-strictfp.c, and sometimes 
> it doesn't. As you can see in the tests in this patch.
I forgot to mention that complex-math-strictfp.c gets a correct BinOpInfo 
passed down to get the IRBuilder set correctly. But there are other places that 
don't correctly set BinOpInfo and so we get inconsistent behavior despite the 
call to the IRBuilder being wrapped in FPOptsRAII. And _that's_ why I 
structured this patch the way I did.


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

https://reviews.llvm.org/D88913

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


[PATCH] D90063: [AIX] Also error on -G for link-only step

2020-10-23 Thread Xiangling Liao via Phabricator via cfe-commits
Xiangling_L created this revision.
Xiangling_L added reviewers: hubert.reinterpretcast, daltenty, jasonliu.
Herald added subscribers: cfe-commits, kbarton, nemanjai.
Herald added a project: clang.
Xiangling_L requested review of this revision.

The change in [[ https://reviews.llvm.org/D89897 | [AIX] Emit error for -G 
option on AIX ]] didn't issue an error for link-only steps. The patch fixes 
that problem and also update related testcases.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D90063

Files:
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/Inputs/aix_ppc_tree/dummy0.o
  clang/test/Driver/aix-err-options.c


Index: clang/test/Driver/aix-err-options.c
===
--- clang/test/Driver/aix-err-options.c
+++ clang/test/Driver/aix-err-options.c
@@ -1,7 +1,28 @@
-// RUN: %clang -target powerpc32-ibm-aix-xcoff -### -S -emit-llvm -G 0 2>&1 %s 
| \
+// RUN: %clang -target powerpc-ibm-aix-xcoff -### -E -G 0 2>&1 %s | \
 // RUN:   FileCheck --check-prefix=CHECK32 %s
+// RUN: %clang -target powerpc-ibm-aix-xcoff -### -S -emit-llvm -G 0 2>&1 %s | 
\
+// RUN:   FileCheck --check-prefix=CHECK32 %s
+// RUN: %clang -target powerpc-ibm-aix-xcoff -### -c -G 0 2>&1 %s | \
+// RUN:   FileCheck --check-prefix=CHECK32 %s
+// RUN: %clang -target powerpc-ibm-aix-xcoff -### -c \
+// RUN: %S/Inputs/aix_ppc_tree/dummy0.s -G 0 2>&1 | \
+// RUN:   FileCheck --check-prefix=CHECK32 %s
+// RUN: %clang -target powerpc-ibm-aix-xcoff -### -o dummy.so \
+// RUN: %S/Inputs/aix_ppc_tree/dummy0.o -G 0 2>&1 | \
+// RUN:   FileCheck --check-prefix=CHECK32 %s
+
 // RUN: %clang -target powerpc64-ibm-aix-xcoff -### -S -emit-llvm -G 0 2>&1 %s 
| \
 // RUN:   FileCheck --check-prefix=CHECK64 %s
+// RUN: %clang -target powerpc64-ibm-aix-xcoff -### -S -emit-llvm -G 0 2>&1 %s 
| \
+// RUN:   FileCheck --check-prefix=CHECK64 %s
+// RUN: %clang -target powerpc64-ibm-aix-xcoff -### -c -G 0 2>&1 %s | \
+// RUN:   FileCheck --check-prefix=CHECK64 %s
+// RUN: %clang -target powerpc64-ibm-aix-xcoff -### -c \
+// RUN: %S/Inputs/aix_ppc_tree/dummy0.s -G 0 2>&1 | \
+// RUN:   FileCheck --check-prefix=CHECK64 %s
+// RUN: %clang -target powerpc64-ibm-aix-xcoff -### -o dummy.so \
+// RUN: %S/Inputs/aix_ppc_tree/dummy0.o -G 0 2>&1 | \
+// RUN:   FileCheck --check-prefix=CHECK64 %s
 
-// CHECK32: error: unsupported option '-G' for target 'powerpc32-ibm-aix-xcoff'
+// CHECK32: error: unsupported option '-G' for target 'powerpc-ibm-aix-xcoff'
 // CHECK64: error: unsupported option '-G' for target 'powerpc64-ibm-aix-xcoff'
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -4958,11 +4958,6 @@
   if (D.CCGenDiagnostics)
 CmdArgs.push_back("-disable-pragma-debug-crash");
 
-  if (RawTriple.isOSAIX())
-if (Arg *A = Args.getLastArg(options::OPT_G))
-  D.Diag(diag::err_drv_unsupported_opt_for_target)
-  << A->getSpelling() << RawTriple.str();
-
   bool UseSeparateSections = isUseSeparateSections(Triple);
 
   if (Args.hasFlag(options::OPT_ffunction_sections,
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -3876,9 +3876,15 @@
 }
   }
 
+  const llvm::Triple &RawTriple = C.getDefaultToolChain().getTriple();
+  if (RawTriple.isOSAIX())
+if (Arg *A = C.getArgs().getLastArg(options::OPT_G))
+  Diag(diag::err_drv_unsupported_opt_for_target)
+  << A->getSpelling() << RawTriple.str();
+
   // Collect the list of architectures.
   llvm::StringSet<> ArchNames;
-  if (C.getDefaultToolChain().getTriple().isOSBinFormatMachO())
+  if (RawTriple.isOSBinFormatMachO())
 for (const Arg *A : C.getArgs())
   if (A->getOption().matches(options::OPT_arch))
 ArchNames.insert(A->getValue());


Index: clang/test/Driver/aix-err-options.c
===
--- clang/test/Driver/aix-err-options.c
+++ clang/test/Driver/aix-err-options.c
@@ -1,7 +1,28 @@
-// RUN: %clang -target powerpc32-ibm-aix-xcoff -### -S -emit-llvm -G 0 2>&1 %s | \
+// RUN: %clang -target powerpc-ibm-aix-xcoff -### -E -G 0 2>&1 %s | \
 // RUN:   FileCheck --check-prefix=CHECK32 %s
+// RUN: %clang -target powerpc-ibm-aix-xcoff -### -S -emit-llvm -G 0 2>&1 %s | \
+// RUN:   FileCheck --check-prefix=CHECK32 %s
+// RUN: %clang -target powerpc-ibm-aix-xcoff -### -c -G 0 2>&1 %s | \
+// RUN:   FileCheck --check-prefix=CHECK32 %s
+// RUN: %clang -target powerpc-ibm-aix-xcoff -### -c \
+// RUN: %S/Inputs/aix_ppc_tree/dummy0.s -G 0 2>&1 | \
+// RUN:   FileCheck --check-prefix=CHECK32 %s
+// RUN: %clang -target powerpc-ibm-aix-xcoff -### -o dummy.so \
+// RUN: %S/Inputs/aix_ppc_tree/dummy0.o -G 0 2>&1 | \
+// RUN:   FileCheck -

  1   2   >