[PATCH] D51567: CMake: Consolidate gtest detection code

2018-08-31 Thread Tom Stellard via Phabricator via cfe-commits
tstellar created this revision.
tstellar added reviewers: chandlerc, beanz.
Herald added a subscriber: mgorny.

This makes it possible to build the unittests with only the gtest sources
and without a full LLVM source tree.


Repository:
  rC Clang

https://reviews.llvm.org/D51567

Files:
  CMakeLists.txt


Index: CMakeLists.txt
===
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -142,12 +142,6 @@
 set(LLVM_UTILS_PROVIDED ON)
 set(CLANG_TEST_DEPS FileCheck count not)
   endif()
-  set(UNITTEST_DIR ${LLVM_MAIN_SRC_DIR}/utils/unittest)
-  if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h
-  AND NOT EXISTS 
${LLVM_LIBRARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX}
-  AND EXISTS ${UNITTEST_DIR}/CMakeLists.txt)
-add_subdirectory(${UNITTEST_DIR} utils/unittest)
-  endif()
 else()
   # Seek installed Lit.
   find_program(LLVM_LIT
@@ -486,12 +480,18 @@
 
 
 if( CLANG_INCLUDE_TESTS )
-  if(EXISTS 
${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include/gtest/gtest.h)
+  set(UNITTEST_DIR ${LLVM_MAIN_SRC_DIR}/utils/unittest)
+  if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h)
 add_subdirectory(unittests)
 list(APPEND CLANG_TEST_DEPS ClangUnitTests)
 list(APPEND CLANG_TEST_PARAMS
   clang_unit_site_config=${CMAKE_CURRENT_BINARY_DIR}/test/Unit/lit.site.cfg
   )
+if (CLANG_BUILT_STANDALONE
+AND NOT EXISTS 
${LLVM_LIBRARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX}
+AND EXISTS ${UNITTEST_DIR}/CMakeLists.txt)
+  add_subdirectory(${UNITTEST_DIR} utils/unittest)
+endif()
   endif()
   add_subdirectory(test)
 


Index: CMakeLists.txt
===
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -142,12 +142,6 @@
 set(LLVM_UTILS_PROVIDED ON)
 set(CLANG_TEST_DEPS FileCheck count not)
   endif()
-  set(UNITTEST_DIR ${LLVM_MAIN_SRC_DIR}/utils/unittest)
-  if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h
-  AND NOT EXISTS ${LLVM_LIBRARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX}
-  AND EXISTS ${UNITTEST_DIR}/CMakeLists.txt)
-add_subdirectory(${UNITTEST_DIR} utils/unittest)
-  endif()
 else()
   # Seek installed Lit.
   find_program(LLVM_LIT
@@ -486,12 +480,18 @@
 
 
 if( CLANG_INCLUDE_TESTS )
-  if(EXISTS ${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include/gtest/gtest.h)
+  set(UNITTEST_DIR ${LLVM_MAIN_SRC_DIR}/utils/unittest)
+  if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h)
 add_subdirectory(unittests)
 list(APPEND CLANG_TEST_DEPS ClangUnitTests)
 list(APPEND CLANG_TEST_PARAMS
   clang_unit_site_config=${CMAKE_CURRENT_BINARY_DIR}/test/Unit/lit.site.cfg
   )
+if (CLANG_BUILT_STANDALONE
+AND NOT EXISTS ${LLVM_LIBRARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX}
+AND EXISTS ${UNITTEST_DIR}/CMakeLists.txt)
+  add_subdirectory(${UNITTEST_DIR} utils/unittest)
+endif()
   endif()
   add_subdirectory(test)
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D51539: [clangd] Add symbol slab size to index memory consumption estimates

2018-08-31 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/index/FileIndex.cpp:91
+  for (const auto  : FileToSlabs)
+Result += P.second->size();
+  return Result;

Why not `bytes` here as well?


https://reviews.llvm.org/D51539



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


[PATCH] D51539: [clangd] Add symbol slab size to index memory consumption estimates

2018-08-31 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/index/dex/DexIndex.cpp:184
+  size_t Bytes = PairedSlabSize;
+  Bytes += LookupTable.size() * sizeof(std::pair);
   Bytes += SymbolQuality.size() * sizeof(std::pair);

Why not use `LookupTable.getMemorySize()` directly? Is it intentionally for not 
counting non-used but allocated buckets? Same for the below two as well.


https://reviews.llvm.org/D51539



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


[PATCH] D51510: Move AESNI generation to Skylake and Goldmont

2018-08-31 Thread Thiago Macieira via Phabricator via cfe-commits
thiagomacieira added a comment.

See https://reviews.llvm.org/D51565


Repository:
  rC Clang

https://reviews.llvm.org/D51510



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


[PATCH] D51510: Move AESNI generation to Skylake and Goldmont

2018-08-31 Thread Thiago Macieira via Phabricator via cfe-commits
thiagomacieira added a comment.

Sure. Hadn't seen that file.


Repository:
  rC Clang

https://reviews.llvm.org/D51510



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


[PATCH] D45898: [SemaCXX] Mark destructor as referenced

2018-08-31 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added inline comments.
This revision is now accepted and ready to land.



Comment at: lib/Sema/SemaInit.cpp:1827-1829
+  if (SemaRef.DiagnoseUseOfDecl(Destructor, Loc))
+return false;
+  return true;

Usual Clang convention is to return `true` on error.



Comment at: lib/Sema/SemaInit.cpp:1856
+if (auto *CXXRD = DeclType->getAsCXXRecordDecl()) {
+  SourceLocation Loc = IList->getBeginLoc();
+  for (auto  : Bases)

It's a minor thing, but I think it'd be preferable to point the diagnostic at 
the relevant init list element, or at the close brace if the initializer was 
omitted.



Comment at: lib/Sema/SemaInit.cpp:1875
+
   if (DeclType->isUnionType() && IList->getNumInits() == 0) {
 RecordDecl *RD = DeclType->getAs()->getDecl();

Hmm, I don't think we considered this case when working on the relevant DR. It 
doesn't make much sense to check the destructors of the inactive union members. 
I'll take this back to WG21, but let's go with the wording as-is for now.


Repository:
  rC Clang

https://reviews.llvm.org/D45898



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


[PATCH] D51564: Distinguish `__block` variables that are captured by escaping blocks from those that aren't

2018-08-31 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak created this revision.
ahatanak added a reviewer: rjmccall.
Herald added a subscriber: dexonsmith.

This patch changes the way `__block` variables that aren't captured by escaping 
blocks are handled:

- Since non-escaping blocks on the stack never get copied to the heap (see 
https://reviews.llvm.org/D49303), Sema shouldn't error out when the type of a 
non-escaping `__block` variable doesn't have an accessible copy constructor.

- IRGen doesn't have to use the specialized byref structure (see 
https://clang.llvm.org/docs/Block-ABI-Apple.html#id8) for a non-escaping 
`__block` variable anymore. Instead IRGen can emit the variable as a normal 
variable and copy the reference to the block literal . Byref copy/dispose 
helpers aren't needed either.

rdar://problem/39352313


Repository:
  rC Clang

https://reviews.llvm.org/D51564

Files:
  include/clang/AST/Decl.h
  include/clang/Sema/ScopeInfo.h
  lib/AST/Decl.cpp
  lib/CodeGen/CGBlocks.cpp
  lib/CodeGen/CGClass.cpp
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/Sema/ScopeInfo.cpp
  lib/Sema/Sema.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaExprObjC.cpp
  lib/Serialization/ASTReaderDecl.cpp
  lib/Serialization/ASTWriterDecl.cpp
  test/CodeGen/block-byref-aggr.c
  test/CodeGen/blocks-seq.c
  test/CodeGen/exceptions.c
  test/CodeGen/personality.c
  test/CodeGenCXX/block-capture.cpp
  test/CodeGenCXX/blocks.cpp
  test/CodeGenCXX/debug-info-blocks.cpp
  test/CodeGenObjC/arc-no-arc-exceptions.m
  test/CodeGenObjC/arc-unoptimized-byref-var.m
  test/CodeGenObjC/blocks-1.m
  test/CodeGenObjC/noescape.m
  test/CodeGenObjCXX/arc-blocks.mm
  test/PCH/block-helpers.cpp
  test/SemaObjCXX/blocks.mm
  test/SemaObjCXX/noescape.mm

Index: test/SemaObjCXX/noescape.mm
===
--- test/SemaObjCXX/noescape.mm
+++ test/SemaObjCXX/noescape.mm
@@ -8,6 +8,7 @@
   void m();
 };
 
+void escapingFunc0(BlockTy);
 void noescapeFunc0(id, __attribute__((noescape)) BlockTy);
 void noescapeFunc1(id, [[clang::noescape]] BlockTy);
 void noescapeFunc2(__attribute__((noescape)) int *); // expected-note {{previous declaration is here}}
@@ -127,3 +128,27 @@
 -(void) m1:(int*) p {
 }
 @end
+
+struct S6 {
+  S6();
+  S6(const S6 &) = delete; // expected-note 3 {{'S6' has been explicitly marked deleted here}}
+  int f;
+};
+
+void test1() {
+  id a;
+  // __block variables that are not captured by escaping blocks don't
+  // necessitate having accessible copy constructors.
+  __block S6 b0;
+  __block S6 b1; // expected-error {{call to deleted constructor of 'S6'}}
+  __block S6 b2; // expected-error {{call to deleted constructor of 'S6'}}
+  __block S6 b3; // expected-error {{call to deleted constructor of 'S6'}}
+
+  noescapeFunc0(a, ^{ (void)b0; });
+  escapingFunc0(^{ (void)b1; });
+  {
+noescapeFunc0(a, ^{ (void)b0; (void)b1; });
+  }
+  noescapeFunc0(a, ^{ escapingFunc0(^{ (void)b2; }); });
+  escapingFunc0(^{ noescapeFunc0(a, ^{ (void)b3; }); });
+}
Index: test/SemaObjCXX/blocks.mm
===
--- test/SemaObjCXX/blocks.mm
+++ test/SemaObjCXX/blocks.mm
@@ -76,21 +76,27 @@
 }
 
 // Make sure we successfully instantiate the copy constructor of a
-// __block variable's type.
+// __block variable's type when the variable is captured by an escaping block.
 namespace N2 {
   template  struct A {
 A() {}
 A(const A ) {
   int invalid[-n]; // expected-error 2 {{array with a negative size}}
 }
+void m() {}
   };
 
+  typedef void (^BlockFnTy)();
+  void func(BlockFnTy);
+
   void test1() {
 __block A<1> x; // expected-note {{requested here}}
+func(^{ x.m(); });
   }
 
   template  void test2() {
 __block A x; // expected-note {{requested here}}
+func(^{ x.m(); });
   }
   template void test2<2>();
 }
Index: test/PCH/block-helpers.cpp
===
--- test/PCH/block-helpers.cpp
+++ test/PCH/block-helpers.cpp
@@ -1,6 +1,26 @@
 // RUN: %clang_cc1 -x c++-header -triple x86_64-apple-darwin11 -emit-pch -fblocks -fexceptions -o %t %S/block-helpers.h
 // RUN: %clang_cc1 -triple x86_64-apple-darwin11 -include-pch %t -emit-llvm -fblocks -fexceptions -o - %s | FileCheck %s
 
+// CHECK: %[[STRUCT_BLOCK_BYREF_X:.*]] = type { i8*, %[[STRUCT_BLOCK_BYREF_X]]*, i32, i32, i8*, i8*, %[[STRUCT_S0:.*]] }
+// CHECK: %[[STRUCT_S0]] = type { i32 }
+// CHECK: %[[STRUCT_BLOCK_BYREF_Y:.*]] = type { i8*, %[[STRUCT_BLOCK_BYREF_Y]]*, i32, i32, i8*, i8*, %[[STRUCT_S0]] }
+// CHECK: %[[STRUCT_BLOCK_DESCRIPTOR:.*]] = type { i64, i64 }
+
+// Check that byref structs are allocated for x and y.
+
+// CHECK-LABEL: define linkonce_odr void @_ZN1S1mEv(
+// CHECK: %[[X:.*]] = alloca %[[STRUCT_BLOCK_BYREF_X]], align 8
+// CHECK: %[[Y:.*]] = alloca %[[STRUCT_BLOCK_BYREF_Y]], align 8
+// CHECK: %[[BLOCK:.*]] = alloca <{ i8*, i32, i32, i8*, 

[PATCH] D45898: [SemaCXX] Mark destructor as referenced

2018-08-31 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 163612.
ahatanak marked 3 inline comments as done.
ahatanak added a comment.

Move the call that checks the element's destructor into 
InitListChecker::CheckStructUnionTypes.


Repository:
  rC Clang

https://reviews.llvm.org/D45898

Files:
  lib/Sema/SemaInit.cpp
  test/CodeGenObjCXX/arc-list-init-destruct.mm
  test/SemaCXX/aggregate-initialization.cpp

Index: test/SemaCXX/aggregate-initialization.cpp
===
--- test/SemaCXX/aggregate-initialization.cpp
+++ test/SemaCXX/aggregate-initialization.cpp
@@ -186,3 +186,51 @@
   // amount of time.
   struct A { int n; int arr[1000 * 1000 * 1000]; } a = {1, {2}};
 }
+
+namespace ElementDestructor {
+  // The destructor for each element of class type is potentially invoked
+  // (15.4 [class.dtor]) from the context where the aggregate initialization
+  // occurs. Produce a diagnostic if an element's destructor isn't accessible.
+
+  class X { int f; ~X(); }; // expected-note {{implicitly declared private here}}
+  struct Y { X x; };
+
+  void test0() {
+auto *y = new Y {}; // expected-error {{temporary of type 'ElementDestructor::X' has private destructor}}
+  }
+
+  struct S0 { int f; ~S0() = delete; }; // expected-note 3 {{'~S0' has been explicitly marked deleted here}}
+  struct S1 { S0 s0; int f; };
+
+  S1 test1() {
+auto *t = new S1 { .f = 1 }; // expected-error {{attempt to use a deleted function}}
+return {2}; // expected-error {{attempt to use a deleted function}}
+  }
+
+  // Check if the type of an array element has a destructor.
+  struct S2 { S0 a[4]; };
+
+  void test2() {
+auto *t = new S2 {1,2,3,4}; // expected-error {{attempt to use a deleted function}}
+  }
+
+#if __cplusplus >= 201703L
+  namespace BaseDestructor {
+ struct S0 { int f; ~S0() = delete; }; // expected-note {{'~S0' has been explicitly marked deleted here}}
+
+// Check destructor of base class.
+struct S3 : S0 {};
+
+void test3() {
+  S3 s3 = {1}; // expected-error {{attempt to use a deleted function}}
+}
+  }
+#endif
+
+  // A's destructor doesn't have to be accessible from the context of C's
+  // initialization.
+  struct A { friend struct B; private: ~A(); };
+  struct B { B(); A a; };
+  struct C { B b; };
+  C c = { B() };
+}
Index: test/CodeGenObjCXX/arc-list-init-destruct.mm
===
--- /dev/null
+++ test/CodeGenObjCXX/arc-list-init-destruct.mm
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.13.0 -std=c++1z -fobjc-arc -fobjc-exceptions -fcxx-exceptions -fexceptions -emit-llvm -o - %s | FileCheck %s
+
+// CHECK: %[[V0:.*]] = type opaque
+// CHECK: %[[STRUCT_CLASS1:.*]] = type { %[[V0]]* }
+
+@interface Class0;
+@end
+
+struct Class1 {
+  Class0 *f;
+};
+
+struct Container {
+  Class1 a;
+  bool b;
+};
+
+bool getBool() {
+  return false;
+}
+
+Class0 *g;
+
+// CHECK: define {{.*}} @_Z4testv()
+// CHECK: invoke zeroext i1 @_Z7getBoolv()
+// CHECK: landingpad { i8*, i32 }
+// CHECK: call void @_ZN6Class1D1Ev(%[[STRUCT_CLASS1]]* %{{.*}})
+// CHECK: br label
+
+// CHECK: define linkonce_odr void @_ZN6Class1D1Ev(
+
+Container test() {
+  return {{g}, getBool()};
+}
Index: lib/Sema/SemaInit.cpp
===
--- lib/Sema/SemaInit.cpp
+++ lib/Sema/SemaInit.cpp
@@ -1818,6 +1818,17 @@
   return FlexArrayDiag != diag::ext_flexible_array_init;
 }
 
+static bool checkElementDestructor(CXXRecordDecl *CXXRD, QualType RecType,
+   SourceLocation Loc, Sema ) {
+  CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(CXXRD);
+  SemaRef.CheckDestructorAccess(
+  Loc, Destructor, SemaRef.PDiag(diag::err_access_dtor_temp) << RecType);
+  SemaRef.MarkFunctionReferenced(Loc, Destructor);
+  if (SemaRef.DiagnoseUseOfDecl(Destructor, Loc))
+return false;
+  return true;
+}
+
 void InitListChecker::CheckStructUnionTypes(
 const InitializedEntity , InitListExpr *IList, QualType DeclType,
 CXXRecordDecl::base_class_range Bases, RecordDecl::field_iterator Field,
@@ -1835,6 +1846,32 @@
 return;
   }
 
+  // Check if destructors of base classes and members are accessible.
+  //
+  // The destructor for each element of class type is potentially invoked
+  // (15.4 [class.dtor]) from the context where the aggregate
+  // initialization occurs.
+  if (!VerifyOnly)
+if (auto *CXXRD = DeclType->getAsCXXRecordDecl()) {
+  SourceLocation Loc = IList->getBeginLoc();
+  for (auto  : Bases)
+if (auto *CXXRDMember = Base.getType()->getAsCXXRecordDecl())
+  if (!checkElementDestructor(CXXRDMember, Base.getType(), Loc,
+  SemaRef)) {
+hadError = true;
+return;
+  }
+
+  for (FieldDecl *FD : CXXRD->fields()) {
+QualType ET = SemaRef.Context.getBaseElementType(FD->getType());
+if 

[PATCH] D51329: [Attribute/Diagnostics] Print macro instead of whole attribute for address_space

2018-08-31 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan added inline comments.



Comment at: lib/AST/TypePrinter.cpp:1370
+
+// Remove the underlying address space so it won't be printed.
+SplitQualType SplitTy = T->getModifiedType().split();

rsmith wrote:
> leonardchan wrote:
> > rsmith wrote:
> > > leonardchan wrote:
> > > > rsmith wrote:
> > > > > This is unnecessary; just print the modified type here. (The modified 
> > > > > type by definition does not have the attribute applied to it.)
> > > > When you say the modified type, do you mean just the type without it's 
> > > > qualifiers? I wasn't sure if removing all the qualifiers would suffice 
> > > > since there were also other  non-address_space qualifiers that could be 
> > > > printed.
> > > I mean `T->getModifiedType()`, which tracks what the type was before the 
> > > attribute was applied.
> > Oh, I understand that you meant `T->getModifiedType()`. This is a special 
> > case when printing the `address_space` since even though the attribute is 
> > applied and printed here, when we reach the qualifiers of the modified 
> > type, the address space will still be printed unless we remove it here.
> > 
> > I'm not sure if there's a better way to do this though.
> If the address space qualifiers are present on the modified type, then that's 
> a bug in the creation of the `AttributedType`. And indeed looking at r340765, 
> I see we are passing the wrong type in as the modified type when creating the 
> `AttributedType`. Please fix that, and then just use `getModifiedType` here.
Making another patch for this.



Comment at: lib/Lex/PPDirectives.cpp:2584
+// one token for the attribute itself.
+static constexpr unsigned kMinAttrTokens = 6;
+

aaron.ballman wrote:
> This count is specific to GNU spellings. For instance, a C++ spelling might 
> have 5 tokens (two square brackets, attribute-token, two more square 
> brackets) or more and a declspec spelling might have 4 tokens (__declspec 
> keyword, paren, attribute token, paren).
See comment below



Comment at: lib/Lex/PPDirectives.cpp:2586-2588
+/// This only catches macros whose whole definition is an attribute. That is, 
it
+/// starts with the attribute keyword and 2 opening parentheses, and ends with
+/// the 2 closing parentheses.

aaron.ballman wrote:
> Why does this need to be specific to GNU-style spellings?
Similar to the `noderef` patch I sent out, this is initially only meant for 
GNU-style attributes but can be expanded on later.

The main goal for our side was to change the diagnostics relating to 
address_spaces to instead print the macro if the attribute was defined in a 
macro. This was initially discussed in 
http://lists.llvm.org/pipermail/cfe-dev/2018-August/058702.html, but eventually 
decided on not using a pragma and instead redirecting diagnostics 
(http://lists.llvm.org/pipermail/cfe-dev/2018-August/058732.html).

Essentially, this was meant specifically for just the `address_space` 
attribute, which I believe only has GNU-style support, but Richard Smith 
thought that this would be useful to apply to other attributes. For our use 
case alone, we just need it to work for GNU-style, but we can expand on this 
afterwards for other attribute spellings.



Comment at: lib/Lex/PPDirectives.cpp:2720-2721
 
+  // If the macro is an attribute that contains address_space(), save this for
+  // diagnosing later.
+  SourceRange Range;

aaron.ballman wrote:
> This should not be specific to `address_space`, but even if it were, this is 
> wrong as it can be spelled `[[clang::address_space(0)]]`.
Removed code relating to the processor since we don't need it anymore



Comment at: lib/Parse/ParseDecl.cpp:116
+/// they were defined in.
+static void ApplyMacroIIToParsedAttrs(ParsedAttributes , unsigned N,
+  IdentifierInfo *MacroII) {

aaron.ballman wrote:
> `attrs` doesn't meet the usual naming conventions. Same with `i` below.
Removed



Comment at: lib/Parse/ParseDecl.cpp:119
+  assert(attrs.size() >= N);
+  for (unsigned i = attrs.size() - N; i < N; ++i)
+attrs[i].setMacroII(MacroII);

aaron.ballman wrote:
> You can use a range-based for loop here instead.
The condition should instead be `i < attrs.size()`, sorry.

I don't know if `ParsedAttributesView` has a reverse iterator though or I can 
start with an iterator in the middle of the view.



Comment at: lib/Parse/ParseDecl.cpp:246-252
+for (const auto  : PP.getAttributeMacros()) {
+  if (SourceLocInSourceRange(AttrTok.getLocation(), MacroPair.first,
+ PP.getSourceManager())) {
+ApplyMacroIIToParsedAttrs(attrs, NumParsedAttrs, MacroPair.second);
+break;
+  }
+}

rsmith wrote:
> From my earlier comment: "look through the source location information 

[PATCH] D51329: [Attribute/Diagnostics] Print macro instead of whole attribute for address_space

2018-08-31 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan updated this revision to Diff 163604.
leonardchan marked 8 inline comments as done.
leonardchan added a comment.

- Removed default value for `getAttributedType` and added any macro identifier 
necessary as a fourth argument to `getAttributedType`
- Added tracking for `LateAttr`s to keep any found macro identifier, although I 
don't quite know how I can test this in the same fashion that I test with 
`address_space` since it doesn't get printed in the type.


Repository:
  rC Clang

https://reviews.llvm.org/D51329

Files:
  include/clang/AST/ASTContext.h
  include/clang/AST/Type.h
  include/clang/Parse/Parser.h
  include/clang/Sema/ParsedAttr.h
  lib/AST/ASTContext.cpp
  lib/AST/ASTDiagnostic.cpp
  lib/AST/ASTImporter.cpp
  lib/AST/Type.cpp
  lib/AST/TypePrinter.cpp
  lib/Parse/ParseDecl.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclObjC.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaExprObjC.cpp
  lib/Sema/SemaObjCProperty.cpp
  lib/Sema/SemaType.cpp
  lib/Sema/TreeTransform.h
  lib/Serialization/ASTReader.cpp
  lib/Serialization/ASTWriter.cpp
  test/Sema/address_space_print_macro.c
  test/Sema/address_spaces.c

Index: test/Sema/address_spaces.c
===
--- test/Sema/address_spaces.c
+++ test/Sema/address_spaces.c
@@ -71,5 +71,5 @@
 
 // Clang extension doesn't forbid operations on pointers to different address spaces.
 char* cmp(_AS1 char *x,  _AS2 char *y) {
-  return x < y ? x : y; // expected-error{{conditional operator with the second and third operands of type  ('__attribute__((address_space(1))) char *' and '__attribute__((address_space(2))) char *') which are pointers to non-overlapping address spaces}}
+  return x < y ? x : y; // expected-error{{conditional operator with the second and third operands of type  ('_AS1 char *' and '_AS2 char *') which are pointers to non-overlapping address spaces}}
 }
Index: test/Sema/address_space_print_macro.c
===
--- /dev/null
+++ test/Sema/address_space_print_macro.c
@@ -0,0 +1,39 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify
+
+#define AS1 __attribute__((address_space(1)))
+#define AS2 __attribute__((address_space(2), annotate("foo")))
+
+#define AS(i) address_space(i)
+#define AS3 __attribute__((AS(3)))
+
+#define ATTR __attribute__
+#define AS4 ATTR((AS(4)))
+#define AS5 __attribute__((address_space(5))) char
+
+char *cmp(AS1 char *x, AS2 char *y) {
+  return x < y ? x : y; // expected-error{{conditional operator with the second and third operands of type  ('AS1 char *' and 'AS2 char *') which are pointers to non-overlapping address spaces}}
+}
+
+__attribute__((address_space(1))) char test_array[10];
+void test3(void) {
+  extern void test3_helper(char *p); // expected-note{{passing argument to parameter 'p' here}}
+  test3_helper(test_array);  // expected-error{{passing '__attribute__((address_space(1))) char *' to parameter of type 'char *' changes address space of pointer}}
+}
+
+char AS2 *test4_array;
+void test4(void) {
+  extern void test3_helper(char *p); // expected-note{{passing argument to parameter 'p' here}}
+  test3_helper(test4_array); // expected-error{{passing 'AS2 char *' to parameter of type 'char *' changes address space of pointer}}
+}
+
+void func() {
+  char AS1 *x;
+  char AS3 *x2;
+  AS4 char *x3;
+  AS5 *x4;
+  char *y;
+  y = x;  // expected-error{{assigning 'AS1 char *' to 'char *' changes address space of pointer}}
+  y = x2; // expected-error{{assigning 'AS3 char *' to 'char *' changes address space of pointer}}
+  y = x3; // expected-error{{assigning 'AS4 char *' to 'char *' changes address space of pointer}}
+  y = x4; // expected-error{{assigning '__attribute__((address_space(5))) char *' to 'char *' changes address space of pointer}}
+}
Index: lib/Serialization/ASTWriter.cpp
===
--- lib/Serialization/ASTWriter.cpp
+++ lib/Serialization/ASTWriter.cpp
@@ -404,6 +404,7 @@
   Record.AddTypeRef(T->getModifiedType());
   Record.AddTypeRef(T->getEquivalentType());
   Record.push_back(T->getAttrKind());
+  Record.AddIdentifierRef(T->getMacroIdentifier());
   Code = TYPE_ATTRIBUTED;
 }
 
Index: lib/Serialization/ASTReader.cpp
===
--- lib/Serialization/ASTReader.cpp
+++ lib/Serialization/ASTReader.cpp
@@ -6168,14 +6168,16 @@
   }
 
   case TYPE_ATTRIBUTED: {
-if (Record.size() != 3) {
+if (Record.size() != 4) {
   Error("incorrect encoding of attributed type");
   return QualType();
 }
 QualType modifiedType = readType(*Loc.F, Record, Idx);
 QualType equivalentType = readType(*Loc.F, Record, Idx);
 AttributedType::Kind kind = static_cast(Record[2]);
-return Context.getAttributedType(kind, modifiedType, equivalentType);
+IdentifierInfo *MacroII = GetIdentifierInfo(*Loc.F, Record, Idx);
+return 

[PATCH] D51333: Diagnose likely typos in include statements

2018-08-31 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

In https://reviews.llvm.org/D51333#1220878, @christylee wrote:

> In https://reviews.llvm.org/D51333#1219938, @rsmith wrote:
>
> > Instead of guessing whether the corrected filename would be valid, why not 
> > strip off the leading and trailing non-alphanumeric characters, look up the 
> > resulting filename, and find out? If we did that, then not only could we be 
> > a lot more confident that we'd found the file that was intended, but we 
> > could also recover from the error by including the trimmed filename.
>
>
> Should we lookup the stripped filename and then error out on a warning along 
> the lines of "'' file not found, did you mean 'hello,h'",  or 
> attempt to continue to compile using the file we found (i.e. "hello.h").  I'm 
> learning towards the former because I'm worried the latter might be "too 
> clever", in case the developers actually think  and hello.h are two 
> different files.


I think we should issue a (non-fatal) error along the lines of " not 
found; did you mean "hello.h"?" with a `FixItHint`, and carry on by including 
the file we believe they meant. The chance of hitting a false positive by doing 
this seems extremely remote to me, so I'm not worried about it being "too 
clever" and doing the wrong thing. (You'd not only need for the developer to 
intend to use a file whose name starts or ends with an odd character, but also 
for that file to not exist and a file whose name is the same but with said 
character(s) removed to actually exist.)


https://reviews.llvm.org/D51333



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


r341265 - [X86] Add ktest intrinsics to match gcc and icc.

2018-08-31 Thread Craig Topper via cfe-commits
Author: ctopper
Date: Fri Aug 31 15:29:56 2018
New Revision: 341265

URL: http://llvm.org/viewvc/llvm-project?rev=341265=rev
Log:
[X86] Add ktest intrinsics to match gcc and icc.

These aren't documented in the Intel Intrinsics Guide, but are supported by gcc 
and icc.

Includes these intrinsics:
_ktestc_mask8_u8, _ktestz_mask8_u8, _ktest_mask8_u8
_ktestc_mask16_u8, _ktestz_mask16_u8, _ktest_mask16_u8
_ktestc_mask32_u8, _ktestz_mask32_u8, _ktest_mask32_u8
_ktestc_mask64_u8, _ktestz_mask64_u8, _ktest_mask64_u8

Modified:
cfe/trunk/include/clang/Basic/BuiltinsX86.def
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/lib/Headers/avx512bwintrin.h
cfe/trunk/lib/Headers/avx512dqintrin.h
cfe/trunk/test/CodeGen/avx512bw-builtins.c
cfe/trunk/test/CodeGen/avx512dq-builtins.c

Modified: cfe/trunk/include/clang/Basic/BuiltinsX86.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsX86.def?rev=341265=341264=341265=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsX86.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsX86.def Fri Aug 31 15:29:56 2018
@@ -1761,6 +1761,14 @@ TARGET_BUILTIN(__builtin_ia32_kortestcsi
 TARGET_BUILTIN(__builtin_ia32_kortestzsi, "iUiUi", "nc", "avx512bw")
 TARGET_BUILTIN(__builtin_ia32_kortestcdi, "iULLiULLi", "nc", "avx512bw")
 TARGET_BUILTIN(__builtin_ia32_kortestzdi, "iULLiULLi", "nc", "avx512bw")
+TARGET_BUILTIN(__builtin_ia32_ktestcqi, "iUcUc", "nc", "avx512dq")
+TARGET_BUILTIN(__builtin_ia32_ktestzqi, "iUcUc", "nc", "avx512dq")
+TARGET_BUILTIN(__builtin_ia32_ktestchi, "iUsUs", "nc", "avx512dq")
+TARGET_BUILTIN(__builtin_ia32_ktestzhi, "iUsUs", "nc", "avx512dq")
+TARGET_BUILTIN(__builtin_ia32_ktestcsi, "iUiUi", "nc", "avx512bw")
+TARGET_BUILTIN(__builtin_ia32_ktestzsi, "iUiUi", "nc", "avx512bw")
+TARGET_BUILTIN(__builtin_ia32_ktestcdi, "iULLiULLi", "nc", "avx512bw")
+TARGET_BUILTIN(__builtin_ia32_ktestzdi, "iULLiULLi", "nc", "avx512bw")
 TARGET_BUILTIN(__builtin_ia32_kunpckhi, "UsUsUs", "nc", "avx512f")
 TARGET_BUILTIN(__builtin_ia32_kxnorqi, "UcUcUc", "nc", "avx512dq")
 TARGET_BUILTIN(__builtin_ia32_kxnorhi, "UsUsUs", "nc", "avx512f")

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=341265=341264=341265=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Fri Aug 31 15:29:56 2018
@@ -10075,6 +10075,50 @@ Value *CodeGenFunction::EmitX86BuiltinEx
 return Builder.CreateZExt(Cmp, ConvertType(E->getType()));
   }
 
+  case X86::BI__builtin_ia32_ktestcqi:
+  case X86::BI__builtin_ia32_ktestzqi:
+  case X86::BI__builtin_ia32_ktestchi:
+  case X86::BI__builtin_ia32_ktestzhi:
+  case X86::BI__builtin_ia32_ktestcsi:
+  case X86::BI__builtin_ia32_ktestzsi:
+  case X86::BI__builtin_ia32_ktestcdi:
+  case X86::BI__builtin_ia32_ktestzdi: {
+Intrinsic::ID IID;
+switch (BuiltinID) {
+default: llvm_unreachable("Unsupported intrinsic!");
+case X86::BI__builtin_ia32_ktestcqi:
+  IID = Intrinsic::x86_avx512_ktestc_b;
+  break;
+case X86::BI__builtin_ia32_ktestzqi:
+  IID = Intrinsic::x86_avx512_ktestz_b;
+  break;
+case X86::BI__builtin_ia32_ktestchi:
+  IID = Intrinsic::x86_avx512_ktestc_w;
+  break;
+case X86::BI__builtin_ia32_ktestzhi:
+  IID = Intrinsic::x86_avx512_ktestz_w;
+  break;
+case X86::BI__builtin_ia32_ktestcsi:
+  IID = Intrinsic::x86_avx512_ktestc_d;
+  break;
+case X86::BI__builtin_ia32_ktestzsi:
+  IID = Intrinsic::x86_avx512_ktestz_d;
+  break;
+case X86::BI__builtin_ia32_ktestcdi:
+  IID = Intrinsic::x86_avx512_ktestc_q;
+  break;
+case X86::BI__builtin_ia32_ktestzdi:
+  IID = Intrinsic::x86_avx512_ktestz_q;
+  break;
+}
+
+unsigned NumElts = Ops[0]->getType()->getIntegerBitWidth();
+Value *LHS = getMaskVecValue(*this, Ops[0], NumElts);
+Value *RHS = getMaskVecValue(*this, Ops[1], NumElts);
+Function *Intr = CGM.getIntrinsic(IID);
+return Builder.CreateCall(Intr, {LHS, RHS});
+  }
+
   case X86::BI__builtin_ia32_kaddqi:
   case X86::BI__builtin_ia32_kaddhi:
   case X86::BI__builtin_ia32_kaddsi:

Modified: cfe/trunk/lib/Headers/avx512bwintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/avx512bwintrin.h?rev=341265=341264=341265=diff
==
--- cfe/trunk/lib/Headers/avx512bwintrin.h (original)
+++ cfe/trunk/lib/Headers/avx512bwintrin.h Fri Aug 31 15:29:56 2018
@@ -143,6 +143,42 @@ _kortest_mask64_u8(__mmask64 __A, __mmas
   return (unsigned char)__builtin_ia32_kortestzdi(__A, __B);
 }
 
+static __inline__ unsigned char __DEFAULT_FN_ATTRS
+_ktestc_mask32_u8(__mmask32 __A, __mmask32 __B)
+{
+  return (unsigned 

[PATCH] D51554: [CUDA][OPENMP][NVPTX]Improve logic of the debug info support.

2018-08-31 Thread Artem Belevich via Phabricator via cfe-commits
tra accepted this revision.
tra added a comment.
This revision is now accepted and ready to land.

Nice. So, in effect, for optimized builds we'll generate pre-DWARF line info 
only, unless --cuda-noopt-device-debug is specified.
Will this deal with the warnings about back-end being unable to handle 
particular debug options?

On a side note, when DWARF is functional in NVPTX we need to seriously consider 
per-GPU control for it. Enabling debug info blows up cubin size (ptxas 
apparently packs compressed PTX inside *cubin*) and we run into ELF reloc 
overflows in some tensorflow builds if all GPU variants carry it.


Repository:
  rC Clang

https://reviews.llvm.org/D51554



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


[PATCH] D51448: [WebAssembly] clang-format (NFC)

2018-08-31 Thread Heejin Ahn via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL341254: [WebAssembly] clang-format (NFC) (authored by 
aheejin, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D51448

Files:
  cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
  cfe/trunk/lib/Driver/ToolChains/WebAssembly.h
  cfe/trunk/test/CodeGen/builtins-wasm.c
  cfe/trunk/test/CodeGen/wasm-arguments.c
  cfe/trunk/test/CodeGen/wasm-varargs.c
  cfe/trunk/test/CodeGenCXX/static-init-wasm.cpp
  cfe/trunk/test/CodeGenCXX/wasm-args-returns.cpp
  cfe/trunk/test/Driver/wasm32-unknown-unknown.cpp
  cfe/trunk/test/Driver/wasm64-unknown-unknown.cpp

Index: cfe/trunk/lib/Driver/ToolChains/WebAssembly.h
===
--- cfe/trunk/lib/Driver/ToolChains/WebAssembly.h
+++ cfe/trunk/lib/Driver/ToolChains/WebAssembly.h
@@ -51,14 +51,15 @@
   bool hasBlocksRuntime() const override;
   bool SupportsProfiling() const override;
   bool HasNativeLLVMSupport() const override;
-  void addClangTargetOptions(const llvm::opt::ArgList ,
- llvm::opt::ArgStringList ,
- Action::OffloadKind DeviceOffloadKind) const override;
+  void
+  addClangTargetOptions(const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ,
+Action::OffloadKind DeviceOffloadKind) const override;
   RuntimeLibType GetDefaultRuntimeLibType() const override;
   CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList ) const override;
-  void AddClangSystemIncludeArgs(
-  const llvm::opt::ArgList ,
-  llvm::opt::ArgStringList ) const override;
+  void
+  AddClangSystemIncludeArgs(const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ) const override;
   void AddClangCXXStdlibIncludeArgs(
   const llvm::opt::ArgList ,
   llvm::opt::ArgStringList ) const override;
Index: cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
+++ cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
@@ -22,15 +22,11 @@
 using namespace llvm::opt;
 
 wasm::Linker::Linker(const ToolChain )
-  : GnuTool("wasm::Linker", "lld", TC) {}
+: GnuTool("wasm::Linker", "lld", TC) {}
 
-bool wasm::Linker::isLinkJob() const {
-  return true;
-}
+bool wasm::Linker::isLinkJob() const { return true; }
 
-bool wasm::Linker::hasIntegratedCPP() const {
-  return false;
-}
+bool wasm::Linker::hasIntegratedCPP() const { return false; }
 
 void wasm::Linker::ConstructJob(Compilation , const JobAction ,
 const InputInfo ,
@@ -73,7 +69,7 @@
 
 WebAssembly::WebAssembly(const Driver , const llvm::Triple ,
  const llvm::opt::ArgList )
-  : ToolChain(D, Triple, Args) {
+: ToolChain(D, Triple, Args) {
 
   assert(Triple.isArch32Bit() != Triple.isArch64Bit());
 
@@ -115,7 +111,8 @@
   return ToolChain::RLT_CompilerRT;
 }
 
-ToolChain::CXXStdlibType WebAssembly::GetCXXStdlibType(const ArgList ) const {
+ToolChain::CXXStdlibType
+WebAssembly::GetCXXStdlibType(const ArgList ) const {
   if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) {
 StringRef Value = A->getValue();
 if (Value != "libc++")
Index: cfe/trunk/test/CodeGenCXX/static-init-wasm.cpp
===
--- cfe/trunk/test/CodeGenCXX/static-init-wasm.cpp
+++ cfe/trunk/test/CodeGenCXX/static-init-wasm.cpp
@@ -38,7 +38,7 @@
 
 // Test various aspects of static constructor calls.
 struct A {
-A();
+  A();
 };
 
 A theA;
Index: cfe/trunk/test/CodeGenCXX/wasm-args-returns.cpp
===
--- cfe/trunk/test/CodeGenCXX/wasm-args-returns.cpp
+++ cfe/trunk/test/CodeGenCXX/wasm-args-returns.cpp
@@ -3,16 +3,18 @@
 // RUN: %clang_cc1 -O1 -triple wasm64-unknown-unknown -emit-llvm -o - %s \
 // RUN:   | FileCheck %s
 
-#define concat_(x, y) x ## y
+#define concat_(x, y) x##y
 #define concat(x, y) concat_(x, y)
 
-#define test(T) \
+#define test(T)\
   T forward(T x) { return x; } \
-  void use(T x); \
-  T concat(def_, T)(void); \
+  void use(T x);   \
+  T concat(def_, T)(void); \
   void concat(test_, T)(void) { use(concat(def_, T)()); }
 
-struct one_field { double d; };
+struct one_field {
+  double d;
+};
 test(one_field);
 // CHECK: define double @_Z7forward9one_field(double returned %{{.*}})
 //
@@ -24,7 +26,9 @@
 // CHECK: declare void @_Z3use9one_field(double)
 // CHECK: declare double @_Z13def_one_fieldv()
 
-struct two_fields { double d, e; };
+struct two_fields {
+  double d, e;
+};
 test(two_fields);
 // CHECK: define void @_Z7forward10two_fields(%struct.two_fields* noalias nocapture sret %{{.*}}, %struct.two_fields* byval nocapture readonly align 8 %{{.*}})
 //
@@ -38,8 +42,8 @@
 // CHECK: 

r341254 - [WebAssembly] clang-format (NFC)

2018-08-31 Thread Heejin Ahn via cfe-commits
Author: aheejin
Date: Fri Aug 31 13:57:00 2018
New Revision: 341254

URL: http://llvm.org/viewvc/llvm-project?rev=341254=rev
Log:
[WebAssembly] clang-format (NFC)

Summary: This patch runs clang-format on all wasm-only files.

Subscribers: dschuff, sbc100, jgravelle-google, sunfish, jfb, cfe-commits

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

Modified:
cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
cfe/trunk/lib/Driver/ToolChains/WebAssembly.h
cfe/trunk/test/CodeGen/builtins-wasm.c
cfe/trunk/test/CodeGen/wasm-arguments.c
cfe/trunk/test/CodeGen/wasm-varargs.c
cfe/trunk/test/CodeGenCXX/static-init-wasm.cpp
cfe/trunk/test/CodeGenCXX/wasm-args-returns.cpp
cfe/trunk/test/Driver/wasm32-unknown-unknown.cpp
cfe/trunk/test/Driver/wasm64-unknown-unknown.cpp

Modified: cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp?rev=341254=341253=341254=diff
==
--- cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp Fri Aug 31 13:57:00 2018
@@ -22,15 +22,11 @@ using namespace clang;
 using namespace llvm::opt;
 
 wasm::Linker::Linker(const ToolChain )
-  : GnuTool("wasm::Linker", "lld", TC) {}
+: GnuTool("wasm::Linker", "lld", TC) {}
 
-bool wasm::Linker::isLinkJob() const {
-  return true;
-}
+bool wasm::Linker::isLinkJob() const { return true; }
 
-bool wasm::Linker::hasIntegratedCPP() const {
-  return false;
-}
+bool wasm::Linker::hasIntegratedCPP() const { return false; }
 
 void wasm::Linker::ConstructJob(Compilation , const JobAction ,
 const InputInfo ,
@@ -73,7 +69,7 @@ void wasm::Linker::ConstructJob(Compilat
 
 WebAssembly::WebAssembly(const Driver , const llvm::Triple ,
  const llvm::opt::ArgList )
-  : ToolChain(D, Triple, Args) {
+: ToolChain(D, Triple, Args) {
 
   assert(Triple.isArch32Bit() != Triple.isArch64Bit());
 
@@ -115,7 +111,8 @@ ToolChain::RuntimeLibType WebAssembly::G
   return ToolChain::RLT_CompilerRT;
 }
 
-ToolChain::CXXStdlibType WebAssembly::GetCXXStdlibType(const ArgList ) 
const {
+ToolChain::CXXStdlibType
+WebAssembly::GetCXXStdlibType(const ArgList ) const {
   if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) {
 StringRef Value = A->getValue();
 if (Value != "libc++")

Modified: cfe/trunk/lib/Driver/ToolChains/WebAssembly.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/WebAssembly.h?rev=341254=341253=341254=diff
==
--- cfe/trunk/lib/Driver/ToolChains/WebAssembly.h (original)
+++ cfe/trunk/lib/Driver/ToolChains/WebAssembly.h Fri Aug 31 13:57:00 2018
@@ -51,14 +51,15 @@ private:
   bool hasBlocksRuntime() const override;
   bool SupportsProfiling() const override;
   bool HasNativeLLVMSupport() const override;
-  void addClangTargetOptions(const llvm::opt::ArgList ,
- llvm::opt::ArgStringList ,
- Action::OffloadKind DeviceOffloadKind) const 
override;
+  void
+  addClangTargetOptions(const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ,
+Action::OffloadKind DeviceOffloadKind) const override;
   RuntimeLibType GetDefaultRuntimeLibType() const override;
   CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList ) const 
override;
-  void AddClangSystemIncludeArgs(
-  const llvm::opt::ArgList ,
-  llvm::opt::ArgStringList ) const override;
+  void
+  AddClangSystemIncludeArgs(const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ) const override;
   void AddClangCXXStdlibIncludeArgs(
   const llvm::opt::ArgList ,
   llvm::opt::ArgStringList ) const override;

Modified: cfe/trunk/test/CodeGen/builtins-wasm.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtins-wasm.c?rev=341254=341253=341254=diff
==
--- cfe/trunk/test/CodeGen/builtins-wasm.c (original)
+++ cfe/trunk/test/CodeGen/builtins-wasm.c Fri Aug 31 13:57:00 2018
@@ -5,66 +5,66 @@
 
 __SIZE_TYPE__ f0(void) {
   return __builtin_wasm_memory_size(0);
-// WEBASSEMBLY32: call {{i.*}} @llvm.wasm.memory.size.i32(i32 0)
-// WEBASSEMBLY64: call {{i.*}} @llvm.wasm.memory.size.i64(i32 0)
+  // WEBASSEMBLY32: call {{i.*}} @llvm.wasm.memory.size.i32(i32 0)
+  // WEBASSEMBLY64: call {{i.*}} @llvm.wasm.memory.size.i64(i32 0)
 }
 
 __SIZE_TYPE__ f1(__SIZE_TYPE__ delta) {
   return __builtin_wasm_memory_grow(0, delta);
-// WEBASSEMBLY32: call i32 @llvm.wasm.memory.grow.i32(i32 0, i32 %{{.*}})
-// WEBASSEMBLY64: call i64 @llvm.wasm.memory.grow.i64(i32 0, i64 %{{.*}})
+  // WEBASSEMBLY32: call i32 @llvm.wasm.memory.grow.i32(i32 0, i32 %{{.*}})
+  // WEBASSEMBLY64: call i64 

[PATCH] D51448: [WebAssembly] clang-format (NFC)

2018-08-31 Thread Heejin Ahn via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC341254: [WebAssembly] clang-format (NFC) (authored by 
aheejin, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D51448?vs=163152=163590#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D51448

Files:
  lib/Driver/ToolChains/WebAssembly.cpp
  lib/Driver/ToolChains/WebAssembly.h
  test/CodeGen/builtins-wasm.c
  test/CodeGen/wasm-arguments.c
  test/CodeGen/wasm-varargs.c
  test/CodeGenCXX/static-init-wasm.cpp
  test/CodeGenCXX/wasm-args-returns.cpp
  test/Driver/wasm32-unknown-unknown.cpp
  test/Driver/wasm64-unknown-unknown.cpp

Index: test/Driver/wasm64-unknown-unknown.cpp
===
--- test/Driver/wasm64-unknown-unknown.cpp
+++ test/Driver/wasm64-unknown-unknown.cpp
@@ -29,7 +29,7 @@
 int align_ll = __alignof(long long);
 
 // CHECK: @align_p = hidden global i32 8
-int align_p = __alignof(void*);
+int align_p = __alignof(void *);
 
 // CHECK: @align_f = hidden global i32 4
 int align_f = __alignof(float);
@@ -99,17 +99,20 @@
 
 // CHECK: fp128 @check_longdouble()
 long double check_longdouble() { return 0; }
-
 }
 
-template void Switch();
-template<> void Switch<4>();
-template<> void Switch<8>();
-template<> void Switch<16>();
+template 
+void Switch();
+template <>
+void Switch<4>();
+template <>
+void Switch<8>();
+template <>
+void Switch<16>();
 
 void check_pointer_size() {
   // CHECK: SwitchILi8
-  Switch();
+  Switch();
 
   // CHECK: SwitchILi8
   Switch();
Index: test/Driver/wasm32-unknown-unknown.cpp
===
--- test/Driver/wasm32-unknown-unknown.cpp
+++ test/Driver/wasm32-unknown-unknown.cpp
@@ -29,7 +29,7 @@
 int align_ll = __alignof(long long);
 
 // CHECK: @align_p = hidden global i32 4
-int align_p = __alignof(void*);
+int align_p = __alignof(void *);
 
 // CHECK: @align_f = hidden global i32 4
 int align_f = __alignof(float);
@@ -99,17 +99,20 @@
 
 // CHECK: fp128 @check_longdouble()
 long double check_longdouble() { return 0; }
-
 }
 
-template void Switch();
-template<> void Switch<4>();
-template<> void Switch<8>();
-template<> void Switch<16>();
+template 
+void Switch();
+template <>
+void Switch<4>();
+template <>
+void Switch<8>();
+template <>
+void Switch<16>();
 
 void check_pointer_size() {
   // CHECK: SwitchILi4
-  Switch();
+  Switch();
 
   // CHECK: SwitchILi8
   Switch();
Index: test/CodeGenCXX/static-init-wasm.cpp
===
--- test/CodeGenCXX/static-init-wasm.cpp
+++ test/CodeGenCXX/static-init-wasm.cpp
@@ -38,7 +38,7 @@
 
 // Test various aspects of static constructor calls.
 struct A {
-A();
+  A();
 };
 
 A theA;
Index: test/CodeGenCXX/wasm-args-returns.cpp
===
--- test/CodeGenCXX/wasm-args-returns.cpp
+++ test/CodeGenCXX/wasm-args-returns.cpp
@@ -3,16 +3,18 @@
 // RUN: %clang_cc1 -O1 -triple wasm64-unknown-unknown -emit-llvm -o - %s \
 // RUN:   | FileCheck %s
 
-#define concat_(x, y) x ## y
+#define concat_(x, y) x##y
 #define concat(x, y) concat_(x, y)
 
-#define test(T) \
+#define test(T)\
   T forward(T x) { return x; } \
-  void use(T x); \
-  T concat(def_, T)(void); \
+  void use(T x);   \
+  T concat(def_, T)(void); \
   void concat(test_, T)(void) { use(concat(def_, T)()); }
 
-struct one_field { double d; };
+struct one_field {
+  double d;
+};
 test(one_field);
 // CHECK: define double @_Z7forward9one_field(double returned %{{.*}})
 //
@@ -24,7 +26,9 @@
 // CHECK: declare void @_Z3use9one_field(double)
 // CHECK: declare double @_Z13def_one_fieldv()
 
-struct two_fields { double d, e; };
+struct two_fields {
+  double d, e;
+};
 test(two_fields);
 // CHECK: define void @_Z7forward10two_fields(%struct.two_fields* noalias nocapture sret %{{.*}}, %struct.two_fields* byval nocapture readonly align 8 %{{.*}})
 //
@@ -38,8 +42,8 @@
 // CHECK: declare void @_Z14def_two_fieldsv(%struct.two_fields* sret)
 
 struct copy_ctor {
-double d;
-copy_ctor(copy_ctor const&);
+  double d;
+  copy_ctor(copy_ctor const &);
 };
 test(copy_ctor);
 // CHECK: define void @_Z7forward9copy_ctor(%struct.copy_ctor* noalias sret %{{.*}}, %struct.copy_ctor* %{{.*}})
@@ -56,8 +60,8 @@
 // CHECK: declare void @_Z13def_copy_ctorv(%struct.copy_ctor* sret)
 
 struct __attribute__((aligned(16))) aligned_copy_ctor {
-double d, e;
-aligned_copy_ctor(aligned_copy_ctor const&);
+  double d, e;
+  aligned_copy_ctor(aligned_copy_ctor const &);
 };
 test(aligned_copy_ctor);
 // CHECK: define void @_Z7forward17aligned_copy_ctor(%struct.aligned_copy_ctor* noalias sret %{{.*}}, %struct.aligned_copy_ctor* %{{.*}})
@@ -86,7 +90,7 @@
 // CHECK: declare void @_Z9def_emptyv()
 
 struct one_bitfield {
-int d:3;
+  int d : 3;
 };
 test(one_bitfield);
 // CHECK: define i32 

r341251 - [X86] Add k-mask conversion and load/store instrinsics to match gcc and icc.

2018-08-31 Thread Craig Topper via cfe-commits
Author: ctopper
Date: Fri Aug 31 13:41:06 2018
New Revision: 341251

URL: http://llvm.org/viewvc/llvm-project?rev=341251=rev
Log:
[X86] Add k-mask conversion and load/store instrinsics to match gcc and icc.

This adds:
_cvtmask8_u32, _cvtmask16_u32, _cvtmask32_u32, _cvtmask64_u64
_cvtu32_mask8, _cvtu32_mask16, _cvtu32_mask32, _cvtu64_mask64
_load_mask8, _load_mask16, _load_mask32, _load_mask64
_store_mask8, _store_mask16, _store_mask32, _store_mask64

These are currently missing from the Intel Intrinsics Guide webpage.

Modified:
cfe/trunk/include/clang/Basic/BuiltinsX86.def
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/lib/Headers/avx512bwintrin.h
cfe/trunk/lib/Headers/avx512dqintrin.h
cfe/trunk/lib/Headers/avx512fintrin.h
cfe/trunk/test/CodeGen/avx512bw-builtins.c
cfe/trunk/test/CodeGen/avx512dq-builtins.c
cfe/trunk/test/CodeGen/avx512f-builtins.c

Modified: cfe/trunk/include/clang/Basic/BuiltinsX86.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsX86.def?rev=341251=341250=341251=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsX86.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsX86.def Fri Aug 31 13:41:06 2018
@@ -1778,6 +1778,10 @@ TARGET_BUILTIN(__builtin_ia32_kshiftriqi
 TARGET_BUILTIN(__builtin_ia32_kshiftrihi, "UsUsIUi", "nc", "avx512f")
 TARGET_BUILTIN(__builtin_ia32_kshiftrisi, "UiUiIUi", "nc", "avx512bw")
 TARGET_BUILTIN(__builtin_ia32_kshiftridi, "ULLiULLiIUi", "nc", "avx512bw")
+TARGET_BUILTIN(__builtin_ia32_kmovb, "UcUc", "nc", "avx512dq")
+TARGET_BUILTIN(__builtin_ia32_kmovw, "UsUs", "nc", "avx512f")
+TARGET_BUILTIN(__builtin_ia32_kmovd, "UiUi", "nc", "avx512bw")
+TARGET_BUILTIN(__builtin_ia32_kmovq, "ULLiULLi", "nc", "avx512bw")
 TARGET_BUILTIN(__builtin_ia32_palignr512, "V64cV64cV64cIi", "ncV:512:", 
"avx512bw")
 TARGET_BUILTIN(__builtin_ia32_dbpsadbw128, "V8sV16cV16cIi", "ncV:128:", 
"avx512bw,avx512vl")
 TARGET_BUILTIN(__builtin_ia32_dbpsadbw256, "V16sV32cV32cIi", "ncV:256:", 
"avx512bw,avx512vl")

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=341251=341250=341251=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Fri Aug 31 13:41:06 2018
@@ -10137,6 +10137,17 @@ Value *CodeGenFunction::EmitX86BuiltinEx
 return Builder.CreateBitCast(Builder.CreateNot(Res),
  Ops[0]->getType());
   }
+  case X86::BI__builtin_ia32_kmovb:
+  case X86::BI__builtin_ia32_kmovw:
+  case X86::BI__builtin_ia32_kmovd:
+  case X86::BI__builtin_ia32_kmovq: {
+// Bitcast to vXi1 type and then back to integer. This gets the mask
+// register type into the IR, but might be optimized out depending on
+// what's around it.
+unsigned NumElts = Ops[0]->getType()->getIntegerBitWidth();
+Value *Res = getMaskVecValue(*this, Ops[0], NumElts);
+return Builder.CreateBitCast(Res, Ops[0]->getType());
+  }
 
   case X86::BI__builtin_ia32_kunpckdi:
   case X86::BI__builtin_ia32_kunpcksi:

Modified: cfe/trunk/lib/Headers/avx512bwintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/avx512bwintrin.h?rev=341251=341250=341251=diff
==
--- cfe/trunk/lib/Headers/avx512bwintrin.h (original)
+++ cfe/trunk/lib/Headers/avx512bwintrin.h Fri Aug 31 13:41:06 2018
@@ -167,6 +167,46 @@ _kadd_mask64(__mmask64 __A, __mmask64 __
 #define _kshiftri_mask64(A, I) \
   (__mmask64)__builtin_ia32_kshiftridi((__mmask64)(A), (unsigned int)(I))
 
+static __inline__ unsigned int __DEFAULT_FN_ATTRS
+_cvtmask32_u32(__mmask32 __A) {
+  return (unsigned int)__builtin_ia32_kmovd((__mmask32)__A);
+}
+
+static __inline__ unsigned long long __DEFAULT_FN_ATTRS
+_cvtmask64_u64(__mmask64 __A) {
+  return (unsigned long long)__builtin_ia32_kmovq((__mmask64)__A);
+}
+
+static __inline__ __mmask32 __DEFAULT_FN_ATTRS
+_cvtu32_mask32(unsigned int __A) {
+  return (__mmask32)__builtin_ia32_kmovd((__mmask32)__A);
+}
+
+static __inline__ __mmask64 __DEFAULT_FN_ATTRS
+_cvtu64_mask64(unsigned long long __A) {
+  return (__mmask64)__builtin_ia32_kmovq((__mmask64)__A);
+}
+
+static __inline__ __mmask32 __DEFAULT_FN_ATTRS
+_load_mask32(__mmask32 *__A) {
+  return (__mmask32)__builtin_ia32_kmovd(*(__mmask32 *)__A);
+}
+
+static __inline__ __mmask64 __DEFAULT_FN_ATTRS
+_load_mask64(__mmask64 *__A) {
+  return (__mmask64)__builtin_ia32_kmovq(*(__mmask64 *)__A);
+}
+
+static __inline__ void __DEFAULT_FN_ATTRS
+_store_mask32(__mmask32 *__A, __mmask32 __B) {
+  *(__mmask32 *)__A = __builtin_ia32_kmovd((__mmask32)__B);
+}
+
+static __inline__ void __DEFAULT_FN_ATTRS
+_store_mask64(__mmask64 *__A, __mmask64 __B) {
+  *(__mmask64 *)__A = __builtin_ia32_kmovq((__mmask64)__B);
+}
+
 /* 

[PATCH] D51507: Allow all supportable attributes to be used with #pragma clang attribute.

2018-08-31 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith updated this revision to Diff 163584.
rsmith added a comment.

Don't add #pragma clang attribute support for 'mode' and 'ext_vector_type'.


Repository:
  rC Clang

https://reviews.llvm.org/D51507

Files:
  include/clang/Basic/Attr.td
  test/Misc/pragma-attribute-supported-attributes-list.test
  test/Parser/pragma-attribute.cpp

Index: test/Parser/pragma-attribute.cpp
===
--- test/Parser/pragma-attribute.cpp
+++ test/Parser/pragma-attribute.cpp
@@ -123,7 +123,9 @@
 #pragma clang attribute push (__attribute__((annotate)), apply_to=function foo) // expected-error {{extra tokens after attribute in a '#pragma clang attribute push'}}
 
 #pragma clang attribute push (__attribute__((objc_bridge_related)), apply_to=function)
-// expected-error@-1 {{attribute 'objc_bridge_related' is not supported by '#pragma clang attribute'}}
+// expected-error@-1 {{attribute 'objc_bridge_related' can't be applied to 'function'}}
+#pragma clang attribute pop
+
 #pragma clang attribute push (__attribute__((objc_bridge_related(1))), apply_to=function) // expected-error {{expected a related ObjectiveC class name, e.g., 'NSColor'}}
 
 #pragma clang attribute push (__attribute__((used)), apply_to=function) // expected-error {{attribute 'used' is not supported by '#pragma clang attribute'}}
Index: test/Misc/pragma-attribute-supported-attributes-list.test
===
--- test/Misc/pragma-attribute-supported-attributes-list.test
+++ test/Misc/pragma-attribute-supported-attributes-list.test
@@ -2,57 +2,100 @@
 
 // The number of supported attributes should never go down!
 
-// CHECK: #pragma clang attribute supports 75 attributes:
+// CHECK: #pragma clang attribute supports 128 attributes:
 // CHECK-NEXT: AMDGPUFlatWorkGroupSize (SubjectMatchRule_function)
 // CHECK-NEXT: AMDGPUNumSGPR (SubjectMatchRule_function)
 // CHECK-NEXT: AMDGPUNumVGPR (SubjectMatchRule_function)
 // CHECK-NEXT: AMDGPUWavesPerEU (SubjectMatchRule_function)
 // CHECK-NEXT: AVRSignal (SubjectMatchRule_function)
 // CHECK-NEXT: AbiTag (SubjectMatchRule_record_not_is_union, SubjectMatchRule_variable, SubjectMatchRule_function, SubjectMatchRule_namespace)
+// CHECK-NEXT: Alias (SubjectMatchRule_function, SubjectMatchRule_variable_is_global)
 // CHECK-NEXT: AlignValue (SubjectMatchRule_variable, SubjectMatchRule_type_alias)
 // CHECK-NEXT: AllocSize (SubjectMatchRule_function)
 // CHECK-NEXT: AlwaysDestroy (SubjectMatchRule_variable)
+// CHECK-NEXT: AlwaysInline (SubjectMatchRule_function)
 // CHECK-NEXT: Annotate ()
 // CHECK-NEXT: AnyX86NoCfCheck (SubjectMatchRule_hasType_functionType)
+// CHECK-NEXT: ArcWeakrefUnavailable (SubjectMatchRule_objc_interface)
 // CHECK-NEXT: AssumeAligned (SubjectMatchRule_objc_method, SubjectMatchRule_function)
 // CHECK-NEXT: Availability ((SubjectMatchRule_record, SubjectMatchRule_enum, SubjectMatchRule_enum_constant, SubjectMatchRule_field, SubjectMatchRule_function, SubjectMatchRule_namespace, SubjectMatchRule_objc_category, SubjectMatchRule_objc_interface, SubjectMatchRule_objc_method, SubjectMatchRule_objc_property, SubjectMatchRule_objc_protocol, SubjectMatchRule_record, SubjectMatchRule_type_alias, SubjectMatchRule_variable))
+// CHECK-NEXT: CFAuditedTransfer (SubjectMatchRule_function)
+// CHECK-NEXT: CFConsumed (SubjectMatchRule_variable_is_parameter)
+// CHECK-NEXT: CFUnknownTransfer (SubjectMatchRule_function)
 // CHECK-NEXT: CPUDispatch (SubjectMatchRule_function)
 // CHECK-NEXT: CPUSpecific (SubjectMatchRule_function)
+// CHECK-NEXT: CUDAConstant (SubjectMatchRule_variable)
+// CHECK-NEXT: CUDADevice (SubjectMatchRule_function, SubjectMatchRule_variable)
+// CHECK-NEXT: CUDAGlobal (SubjectMatchRule_function)
+// CHECK-NEXT: CUDAHost (SubjectMatchRule_function)
+// CHECK-NEXT: CUDALaunchBounds (SubjectMatchRule_objc_method, SubjectMatchRule_hasType_functionType)
+// CHECK-NEXT: CUDAShared (SubjectMatchRule_variable)
 // CHECK-NEXT: CXX11NoReturn (SubjectMatchRule_function)
 // CHECK-NEXT: CallableWhen (SubjectMatchRule_function_is_member)
+// CHECK-NEXT: Capability (SubjectMatchRule_record, SubjectMatchRule_type_alias)
 // CHECK-NEXT: CarriesDependency (SubjectMatchRule_variable_is_parameter, SubjectMatchRule_objc_method, SubjectMatchRule_function)
+// CHECK-NEXT: Cold (SubjectMatchRule_function)
+// CHECK-NEXT: Common (SubjectMatchRule_variable)
+// CHECK-NEXT: Constructor (SubjectMatchRule_function)
 // CHECK-NEXT: Consumable (SubjectMatchRule_record)
+// CHECK-NEXT: ConsumableAutoCast (SubjectMatchRule_record)
+// CHECK-NEXT: ConsumableSetOnRead (SubjectMatchRule_record)
 // CHECK-NEXT: Convergent (SubjectMatchRule_function)
 // CHECK-NEXT: DLLExport (SubjectMatchRule_function, SubjectMatchRule_variable, SubjectMatchRule_record, SubjectMatchRule_objc_interface)
 // CHECK-NEXT: DLLImport (SubjectMatchRule_function, SubjectMatchRule_variable, SubjectMatchRule_record, 

Re: r341117 - [MS ABI] Fix mangling issue with dynamic initializer stubs.

2018-08-31 Thread Galina Kistanova via cfe-commits
The builder is just fixed, so I am wrong. Sorry to bother you.

Thanks

Galina

On Fri, Aug 31, 2018 at 1:08 PM Zachary Turner  wrote:

> Are we sure it was my commit?  Because this seems like a very unusual
> failure given the nature of the commit.  I'll try to reproduce it locally
> and report back.
>
> On Fri, Aug 31, 2018 at 11:49 AM Galina Kistanova 
> wrote:
>
>> Hello Zachary,
>>
>> It looks like this commit added broken tests on one of our builders:
>>
>> http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast/builds/19508
>>
>> . . .
>> Failing Tests (2):
>> LLVM-Unit :: ADT/./ADTTests.exe/HashingTest.HashCombineRangeGoldenTest
>> Clang :: CodeGenCXX/catch-undef-behavior.cpp
>>
>> Please have a look?
>> The builder was already red and did not send notifications on this.
>>
>> Thanks
>>
>> Galina
>>
>> On Thu, Aug 30, 2018 at 1:54 PM Zachary Turner via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>> Author: zturner
>>> Date: Thu Aug 30 13:53:11 2018
>>> New Revision: 341117
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=341117=rev
>>> Log:
>>> [MS ABI] Fix mangling issue with dynamic initializer stubs.
>>>
>>> There are two types of dynamic initializer stubs.  There's
>>>
>>>   `dynamic initializer for 'x''(void)
>>>
>>> and
>>>
>>>   `dynamic initializer for `static Foo::Bar StaticDataMember''(void)
>>>
>>> The second case is disambiguated from the first by the presence of
>>> a ? after the operator code.  So the first will appear something like
>>> ?__E while the second will appear something like ?__E?.
>>> clang-cl was mangling these both the same though.  This patch
>>> matches behavior with cl.
>>>
>>> Differential Revision: https://reviews.llvm.org/D51500
>>>
>>> Modified:
>>> cfe/trunk/lib/AST/MicrosoftMangle.cpp
>>> cfe/trunk/test/CodeGenCXX/microsoft-abi-static-initializers.cpp
>>> cfe/trunk/test/CodeGenCXX/pragma-init_seg.cpp
>>>
>>> Modified: cfe/trunk/lib/AST/MicrosoftMangle.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftMangle.cpp?rev=341117=341116=341117=diff
>>>
>>> ==
>>> --- cfe/trunk/lib/AST/MicrosoftMangle.cpp (original)
>>> +++ cfe/trunk/lib/AST/MicrosoftMangle.cpp Thu Aug 30 13:53:11 2018
>>> @@ -3217,10 +3217,13 @@ void MicrosoftMangleContextImpl::mangleI
>>>msvc_hashing_ostream MHO(Out);
>>>MicrosoftCXXNameMangler Mangler(*this, MHO);
>>>Mangler.getStream() << "??__" << CharCode;
>>> -  Mangler.mangleName(D);
>>>if (D->isStaticDataMember()) {
>>> +Mangler.getStream() << '?';
>>> +Mangler.mangleName(D);
>>>  Mangler.mangleVariableEncoding(D);
>>> -Mangler.getStream() << '@';
>>> +Mangler.getStream() << "@@";
>>> +  } else {
>>> +Mangler.mangleName(D);
>>>}
>>>// This is the function class mangling.  These stubs are global,
>>> non-variadic,
>>>// cdecl functions that return void and take no args.
>>>
>>> Modified: cfe/trunk/test/CodeGenCXX/microsoft-abi-static-initializers.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/microsoft-abi-static-initializers.cpp?rev=341117=341116=341117=diff
>>>
>>> ==
>>> --- cfe/trunk/test/CodeGenCXX/microsoft-abi-static-initializers.cpp
>>> (original)
>>> +++ cfe/trunk/test/CodeGenCXX/microsoft-abi-static-initializers.cpp Thu
>>> Aug 30 13:53:11 2018
>>> @@ -3,8 +3,8 @@
>>>  // CHECK: @llvm.global_ctors = appending global [5 x { i32, void ()*,
>>> i8* }] [
>>>  // CHECK: { i32, void ()*, i8* } { i32 65535, void ()*
>>> @"??__Eselectany1@@YAXXZ", i8* getelementptr inbounds (%struct.S,
>>> %struct.S* @"?selectany1@@3US@@A", i32 0, i32 0) },
>>>  // CHECK: { i32, void ()*, i8* } { i32 65535, void ()*
>>> @"??__Eselectany2@@YAXXZ", i8* getelementptr inbounds (%struct.S,
>>> %struct.S* @"?selectany2@@3US@@A", i32 0, i32 0) },
>>> -// CHECK: { i32, void ()*, i8* } { i32 65535, void ()* @"??__Es@
>>> ?$ExportedTemplate@H@@2US@@A@YAXXZ", i8* getelementptr inbounds
>>> (%struct.S, %struct.S* @"?s@?$ExportedTemplate@H@@2US@@A", i32 0, i32
>>> 0) },
>>> -// CHECK: { i32, void ()*, i8* } { i32 65535, void ()* @"??__Efoo@?$B@H
>>> @@2VA@@A@YAXXZ", i8* bitcast (%class.A* @"?foo@?$B@H@@2VA@@A" to i8*) },
>>> +// CHECK: { i32, void ()*, i8* } { i32 65535, void ()* @"??__E?s@
>>> ?$ExportedTemplate@H@@2US@@A@@YAXXZ", i8* getelementptr inbounds
>>> (%struct.S, %struct.S* @"?s@?$ExportedTemplate@H@@2US@@A", i32 0, i32
>>> 0) },
>>> +// CHECK: { i32, void ()*, i8* } { i32 65535, void ()* @"??__E?foo@
>>> ?$B@H@@2VA@@A@@YAXXZ", i8* bitcast (%class.A* @"?foo@?$B@H@@2VA@@A" to
>>> i8*) },
>>>  // CHECK: { i32, void ()*, i8* } { i32 65535, void ()*
>>> @_GLOBAL__sub_I_microsoft_abi_static_initializers.cpp, i8* null }
>>>  // CHECK: ]
>>>
>>> @@ -231,18 +231,18 @@ void force_usage() {
>>>DynamicDLLImportInitVSMangling::switch_test3();
>>>  

Re: r341117 - [MS ABI] Fix mangling issue with dynamic initializer stubs.

2018-08-31 Thread Zachary Turner via cfe-commits
It looks like tnorthover has fixed these in r341240

On Fri, Aug 31, 2018 at 1:08 PM Zachary Turner  wrote:

> Are we sure it was my commit?  Because this seems like a very unusual
> failure given the nature of the commit.  I'll try to reproduce it locally
> and report back.
>
> On Fri, Aug 31, 2018 at 11:49 AM Galina Kistanova 
> wrote:
>
>> Hello Zachary,
>>
>> It looks like this commit added broken tests on one of our builders:
>>
>> http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast/builds/19508
>>
>> . . .
>> Failing Tests (2):
>> LLVM-Unit :: ADT/./ADTTests.exe/HashingTest.HashCombineRangeGoldenTest
>> Clang :: CodeGenCXX/catch-undef-behavior.cpp
>>
>> Please have a look?
>> The builder was already red and did not send notifications on this.
>>
>> Thanks
>>
>> Galina
>>
>> On Thu, Aug 30, 2018 at 1:54 PM Zachary Turner via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>> Author: zturner
>>> Date: Thu Aug 30 13:53:11 2018
>>> New Revision: 341117
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=341117=rev
>>> Log:
>>> [MS ABI] Fix mangling issue with dynamic initializer stubs.
>>>
>>> There are two types of dynamic initializer stubs.  There's
>>>
>>>   `dynamic initializer for 'x''(void)
>>>
>>> and
>>>
>>>   `dynamic initializer for `static Foo::Bar StaticDataMember''(void)
>>>
>>> The second case is disambiguated from the first by the presence of
>>> a ? after the operator code.  So the first will appear something like
>>> ?__E while the second will appear something like ?__E?.
>>> clang-cl was mangling these both the same though.  This patch
>>> matches behavior with cl.
>>>
>>> Differential Revision: https://reviews.llvm.org/D51500
>>>
>>> Modified:
>>> cfe/trunk/lib/AST/MicrosoftMangle.cpp
>>> cfe/trunk/test/CodeGenCXX/microsoft-abi-static-initializers.cpp
>>> cfe/trunk/test/CodeGenCXX/pragma-init_seg.cpp
>>>
>>> Modified: cfe/trunk/lib/AST/MicrosoftMangle.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftMangle.cpp?rev=341117=341116=341117=diff
>>>
>>> ==
>>> --- cfe/trunk/lib/AST/MicrosoftMangle.cpp (original)
>>> +++ cfe/trunk/lib/AST/MicrosoftMangle.cpp Thu Aug 30 13:53:11 2018
>>> @@ -3217,10 +3217,13 @@ void MicrosoftMangleContextImpl::mangleI
>>>msvc_hashing_ostream MHO(Out);
>>>MicrosoftCXXNameMangler Mangler(*this, MHO);
>>>Mangler.getStream() << "??__" << CharCode;
>>> -  Mangler.mangleName(D);
>>>if (D->isStaticDataMember()) {
>>> +Mangler.getStream() << '?';
>>> +Mangler.mangleName(D);
>>>  Mangler.mangleVariableEncoding(D);
>>> -Mangler.getStream() << '@';
>>> +Mangler.getStream() << "@@";
>>> +  } else {
>>> +Mangler.mangleName(D);
>>>}
>>>// This is the function class mangling.  These stubs are global,
>>> non-variadic,
>>>// cdecl functions that return void and take no args.
>>>
>>> Modified: cfe/trunk/test/CodeGenCXX/microsoft-abi-static-initializers.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/microsoft-abi-static-initializers.cpp?rev=341117=341116=341117=diff
>>>
>>> ==
>>> --- cfe/trunk/test/CodeGenCXX/microsoft-abi-static-initializers.cpp
>>> (original)
>>> +++ cfe/trunk/test/CodeGenCXX/microsoft-abi-static-initializers.cpp Thu
>>> Aug 30 13:53:11 2018
>>> @@ -3,8 +3,8 @@
>>>  // CHECK: @llvm.global_ctors = appending global [5 x { i32, void ()*,
>>> i8* }] [
>>>  // CHECK: { i32, void ()*, i8* } { i32 65535, void ()*
>>> @"??__Eselectany1@@YAXXZ", i8* getelementptr inbounds (%struct.S,
>>> %struct.S* @"?selectany1@@3US@@A", i32 0, i32 0) },
>>>  // CHECK: { i32, void ()*, i8* } { i32 65535, void ()*
>>> @"??__Eselectany2@@YAXXZ", i8* getelementptr inbounds (%struct.S,
>>> %struct.S* @"?selectany2@@3US@@A", i32 0, i32 0) },
>>> -// CHECK: { i32, void ()*, i8* } { i32 65535, void ()* @"??__Es@
>>> ?$ExportedTemplate@H@@2US@@A@YAXXZ", i8* getelementptr inbounds
>>> (%struct.S, %struct.S* @"?s@?$ExportedTemplate@H@@2US@@A", i32 0, i32
>>> 0) },
>>> -// CHECK: { i32, void ()*, i8* } { i32 65535, void ()* @"??__Efoo@?$B@H
>>> @@2VA@@A@YAXXZ", i8* bitcast (%class.A* @"?foo@?$B@H@@2VA@@A" to i8*) },
>>> +// CHECK: { i32, void ()*, i8* } { i32 65535, void ()* @"??__E?s@
>>> ?$ExportedTemplate@H@@2US@@A@@YAXXZ", i8* getelementptr inbounds
>>> (%struct.S, %struct.S* @"?s@?$ExportedTemplate@H@@2US@@A", i32 0, i32
>>> 0) },
>>> +// CHECK: { i32, void ()*, i8* } { i32 65535, void ()* @"??__E?foo@
>>> ?$B@H@@2VA@@A@@YAXXZ", i8* bitcast (%class.A* @"?foo@?$B@H@@2VA@@A" to
>>> i8*) },
>>>  // CHECK: { i32, void ()*, i8* } { i32 65535, void ()*
>>> @_GLOBAL__sub_I_microsoft_abi_static_initializers.cpp, i8* null }
>>>  // CHECK: ]
>>>
>>> @@ -231,18 +231,18 @@ void force_usage() {
>>>DynamicDLLImportInitVSMangling::switch_test3();
>>>  }
>>>
>>> -// CHECK: 

Re: r341117 - [MS ABI] Fix mangling issue with dynamic initializer stubs.

2018-08-31 Thread Zachary Turner via cfe-commits
Are we sure it was my commit?  Because this seems like a very unusual
failure given the nature of the commit.  I'll try to reproduce it locally
and report back.

On Fri, Aug 31, 2018 at 11:49 AM Galina Kistanova 
wrote:

> Hello Zachary,
>
> It looks like this commit added broken tests on one of our builders:
>
> http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast/builds/19508
>
> . . .
> Failing Tests (2):
> LLVM-Unit :: ADT/./ADTTests.exe/HashingTest.HashCombineRangeGoldenTest
> Clang :: CodeGenCXX/catch-undef-behavior.cpp
>
> Please have a look?
> The builder was already red and did not send notifications on this.
>
> Thanks
>
> Galina
>
> On Thu, Aug 30, 2018 at 1:54 PM Zachary Turner via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: zturner
>> Date: Thu Aug 30 13:53:11 2018
>> New Revision: 341117
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=341117=rev
>> Log:
>> [MS ABI] Fix mangling issue with dynamic initializer stubs.
>>
>> There are two types of dynamic initializer stubs.  There's
>>
>>   `dynamic initializer for 'x''(void)
>>
>> and
>>
>>   `dynamic initializer for `static Foo::Bar StaticDataMember''(void)
>>
>> The second case is disambiguated from the first by the presence of
>> a ? after the operator code.  So the first will appear something like
>> ?__E while the second will appear something like ?__E?.
>> clang-cl was mangling these both the same though.  This patch
>> matches behavior with cl.
>>
>> Differential Revision: https://reviews.llvm.org/D51500
>>
>> Modified:
>> cfe/trunk/lib/AST/MicrosoftMangle.cpp
>> cfe/trunk/test/CodeGenCXX/microsoft-abi-static-initializers.cpp
>> cfe/trunk/test/CodeGenCXX/pragma-init_seg.cpp
>>
>> Modified: cfe/trunk/lib/AST/MicrosoftMangle.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftMangle.cpp?rev=341117=341116=341117=diff
>>
>> ==
>> --- cfe/trunk/lib/AST/MicrosoftMangle.cpp (original)
>> +++ cfe/trunk/lib/AST/MicrosoftMangle.cpp Thu Aug 30 13:53:11 2018
>> @@ -3217,10 +3217,13 @@ void MicrosoftMangleContextImpl::mangleI
>>msvc_hashing_ostream MHO(Out);
>>MicrosoftCXXNameMangler Mangler(*this, MHO);
>>Mangler.getStream() << "??__" << CharCode;
>> -  Mangler.mangleName(D);
>>if (D->isStaticDataMember()) {
>> +Mangler.getStream() << '?';
>> +Mangler.mangleName(D);
>>  Mangler.mangleVariableEncoding(D);
>> -Mangler.getStream() << '@';
>> +Mangler.getStream() << "@@";
>> +  } else {
>> +Mangler.mangleName(D);
>>}
>>// This is the function class mangling.  These stubs are global,
>> non-variadic,
>>// cdecl functions that return void and take no args.
>>
>> Modified: cfe/trunk/test/CodeGenCXX/microsoft-abi-static-initializers.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/microsoft-abi-static-initializers.cpp?rev=341117=341116=341117=diff
>>
>> ==
>> --- cfe/trunk/test/CodeGenCXX/microsoft-abi-static-initializers.cpp
>> (original)
>> +++ cfe/trunk/test/CodeGenCXX/microsoft-abi-static-initializers.cpp Thu
>> Aug 30 13:53:11 2018
>> @@ -3,8 +3,8 @@
>>  // CHECK: @llvm.global_ctors = appending global [5 x { i32, void ()*,
>> i8* }] [
>>  // CHECK: { i32, void ()*, i8* } { i32 65535, void ()* 
>> @"??__Eselectany1@@YAXXZ",
>> i8* getelementptr inbounds (%struct.S, %struct.S* @"?selectany1@@3US@@A",
>> i32 0, i32 0) },
>>  // CHECK: { i32, void ()*, i8* } { i32 65535, void ()* 
>> @"??__Eselectany2@@YAXXZ",
>> i8* getelementptr inbounds (%struct.S, %struct.S* @"?selectany2@@3US@@A",
>> i32 0, i32 0) },
>> -// CHECK: { i32, void ()*, i8* } { i32 65535, void ()* @"??__Es@
>> ?$ExportedTemplate@H@@2US@@A@YAXXZ", i8* getelementptr inbounds
>> (%struct.S, %struct.S* @"?s@?$ExportedTemplate@H@@2US@@A", i32 0, i32 0)
>> },
>> -// CHECK: { i32, void ()*, i8* } { i32 65535, void ()* @"??__Efoo@?$B@H
>> @@2VA@@A@YAXXZ", i8* bitcast (%class.A* @"?foo@?$B@H@@2VA@@A" to i8*) },
>> +// CHECK: { i32, void ()*, i8* } { i32 65535, void ()* @"??__E?s@
>> ?$ExportedTemplate@H@@2US@@A@@YAXXZ", i8* getelementptr inbounds
>> (%struct.S, %struct.S* @"?s@?$ExportedTemplate@H@@2US@@A", i32 0, i32 0)
>> },
>> +// CHECK: { i32, void ()*, i8* } { i32 65535, void ()* @"??__E?foo@?$B@H
>> @@2VA@@A@@YAXXZ", i8* bitcast (%class.A* @"?foo@?$B@H@@2VA@@A" to i8*) },
>>  // CHECK: { i32, void ()*, i8* } { i32 65535, void ()*
>> @_GLOBAL__sub_I_microsoft_abi_static_initializers.cpp, i8* null }
>>  // CHECK: ]
>>
>> @@ -231,18 +231,18 @@ void force_usage() {
>>DynamicDLLImportInitVSMangling::switch_test3();
>>  }
>>
>> -// CHECK: define linkonce_odr dso_local void @"??__Efoo@?$B@H@@2VA@
>> @A@YAXXZ"() {{.*}} comdat
>> +// CHECK: define linkonce_odr dso_local void 
>> @"??__E?foo@?$B@H@@2VA@@A@@YAXXZ"()
>> {{.*}} comdat
>>  // CHECK-NOT: and
>>  // CHECK-NOT: 

[PATCH] D51279: [clangd] Implement findOccurrences interface in dynamic index.

2018-08-31 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE341242: [clangd] Implement findOccurrences interface in 
dynamic index. (authored by hokein, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D51279?vs=163539=163580#toc

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D51279

Files:
  clangd/index/FileIndex.cpp
  clangd/index/FileIndex.h
  clangd/index/Index.h
  clangd/index/MemIndex.cpp
  clangd/index/MemIndex.h
  clangd/index/Merge.cpp
  clangd/index/Merge.h
  clangd/tool/ClangdMain.cpp
  unittests/clangd/CodeCompleteTests.cpp
  unittests/clangd/FileIndexTests.cpp
  unittests/clangd/IndexTests.cpp
  unittests/clangd/TestTU.cpp

Index: clangd/index/FileIndex.cpp
===
--- clangd/index/FileIndex.cpp
+++ clangd/index/FileIndex.cpp
@@ -16,9 +16,10 @@
 namespace clang {
 namespace clangd {
 
-SymbolSlab indexAST(ASTContext , std::shared_ptr PP,
-llvm::Optional> TopLevelDecls,
-llvm::ArrayRef URISchemes) {
+std::pair
+indexAST(ASTContext , std::shared_ptr PP,
+ llvm::Optional> TopLevelDecls,
+ llvm::ArrayRef URISchemes) {
   SymbolCollector::Options CollectorOpts;
   // FIXME(ioeric): we might also want to collect include headers. We would need
   // to make sure all includes are canonicalized (with CanonicalIncludes), which
@@ -31,8 +32,6 @@
 CollectorOpts.URISchemes = URISchemes;
   CollectorOpts.Origin = SymbolOrigin::Dynamic;
 
-  SymbolCollector Collector(std::move(CollectorOpts));
-  Collector.setPreprocessor(PP);
   index::IndexingOptions IndexOpts;
   // We only need declarations, because we don't count references.
   IndexOpts.SystemSymbolFilter =
@@ -46,20 +45,45 @@
 DeclsToIndex.assign(AST.getTranslationUnitDecl()->decls().begin(),
 AST.getTranslationUnitDecl()->decls().end());
 
+  // We only collect occurrences when indexing main AST.
+  // FIXME: this is a hacky way to detect whether we are indexing preamble AST
+  // or main AST, we should make it explicitly.
+  bool IsIndexMainAST = TopLevelDecls.hasValue();
+  if (IsIndexMainAST)
+CollectorOpts.OccurrenceFilter = AllOccurrenceKinds;
+
+  SymbolCollector Collector(std::move(CollectorOpts));
+  Collector.setPreprocessor(PP);
   index::indexTopLevelDecls(AST, DeclsToIndex, Collector, IndexOpts);
 
-  return Collector.takeSymbols();
+  const auto  = AST.getSourceManager();
+  const auto *MainFileEntry = SM.getFileEntryForID(SM.getMainFileID());
+  std::string FileName = MainFileEntry ? MainFileEntry->getName() : "";
+
+  auto Syms = Collector.takeSymbols();
+  auto Occurrences = Collector.takeOccurrences();
+  vlog("index {0}AST for {1}: \n"
+   "  symbol slab: {2} symbols, {3} bytes\n"
+   "  occurrence slab: {4} symbols, {5} bytes",
+   IsIndexMainAST ? "Main" : "Preamble", FileName, Syms.size(),
+   Syms.bytes(), Occurrences.size(), Occurrences.bytes());
+  return {std::move(Syms), std::move(Occurrences)};
 }
 
 FileIndex::FileIndex(std::vector URISchemes)
 : URISchemes(std::move(URISchemes)) {}
 
-void FileSymbols::update(PathRef Path, std::unique_ptr Slab) {
+void FileSymbols::update(PathRef Path, std::unique_ptr Slab,
+ std::unique_ptr Occurrences) {
   std::lock_guard Lock(Mutex);
   if (!Slab)
 FileToSlabs.erase(Path);
   else
 FileToSlabs[Path] = std::move(Slab);
+  if (!Occurrences)
+FileToOccurrenceSlabs.erase(Path);
+  else
+FileToOccurrenceSlabs[Path] = std::move(Occurrences);
 }
 
 std::shared_ptr> FileSymbols::allSymbols() {
@@ -85,19 +109,47 @@
   return {std::move(Snap), Pointers};
 }
 
+std::shared_ptr FileSymbols::allOccurrences() const {
+  // The snapshot manages life time of symbol occurrence slabs and provides
+  // pointers to all occurrences in all occurrence slabs.
+  struct Snapshot {
+MemIndex::OccurrenceMap Occurrences; // ID => {Occurrence}
+std::vector> KeepAlive;
+  };
+
+  auto Snap = std::make_shared();
+  {
+std::lock_guard Lock(Mutex);
+
+for (const auto  : FileToOccurrenceSlabs) {
+  Snap->KeepAlive.push_back(FileAndSlab.second);
+  for (const auto  : *FileAndSlab.second) {
+auto  = Snap->Occurrences[IDAndOccurrences.first];
+for (const auto  : IDAndOccurrences.second)
+  Occurrences.push_back();
+  }
+}
+  }
+
+  return {std::move(Snap), >Occurrences};
+}
+
 void FileIndex::update(PathRef Path, ASTContext *AST,
std::shared_ptr PP,
llvm::Optional> TopLevelDecls) {
   if (!AST) {
-FSymbols.update(Path, nullptr);
+FSymbols.update(Path, nullptr, nullptr);
   } else {
 assert(PP);
 auto Slab = llvm::make_unique();
-*Slab = indexAST(*AST, PP, TopLevelDecls, URISchemes);
-FSymbols.update(Path, std::move(Slab));
+auto OccurrenceSlab = llvm::make_unique();
+auto IndexResults = indexAST(*AST, PP, 

[clang-tools-extra] r341242 - [clangd] Implement findOccurrences interface in dynamic index.

2018-08-31 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Fri Aug 31 12:53:37 2018
New Revision: 341242

URL: http://llvm.org/viewvc/llvm-project?rev=341242=rev
Log:
[clangd] Implement findOccurrences interface in dynamic index.

Summary:
Implement the interface in
  - FileIndex
  - MemIndex
  - MergeIndex

Depends on https://reviews.llvm.org/D50385.

Reviewers: sammccall, ilya-biryukov

Reviewed By: sammccall

Subscribers: mgrang, ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, 
kadircet, cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/index/FileIndex.cpp
clang-tools-extra/trunk/clangd/index/FileIndex.h
clang-tools-extra/trunk/clangd/index/Index.h
clang-tools-extra/trunk/clangd/index/MemIndex.cpp
clang-tools-extra/trunk/clangd/index/MemIndex.h
clang-tools-extra/trunk/clangd/index/Merge.cpp
clang-tools-extra/trunk/clangd/index/Merge.h
clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp
clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp
clang-tools-extra/trunk/unittests/clangd/TestTU.cpp

Modified: clang-tools-extra/trunk/clangd/index/FileIndex.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/FileIndex.cpp?rev=341242=341241=341242=diff
==
--- clang-tools-extra/trunk/clangd/index/FileIndex.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/FileIndex.cpp Fri Aug 31 12:53:37 2018
@@ -16,9 +16,10 @@
 namespace clang {
 namespace clangd {
 
-SymbolSlab indexAST(ASTContext , std::shared_ptr PP,
-llvm::Optional> TopLevelDecls,
-llvm::ArrayRef URISchemes) {
+std::pair
+indexAST(ASTContext , std::shared_ptr PP,
+ llvm::Optional> TopLevelDecls,
+ llvm::ArrayRef URISchemes) {
   SymbolCollector::Options CollectorOpts;
   // FIXME(ioeric): we might also want to collect include headers. We would 
need
   // to make sure all includes are canonicalized (with CanonicalIncludes), 
which
@@ -31,8 +32,6 @@ SymbolSlab indexAST(ASTContext , std
 CollectorOpts.URISchemes = URISchemes;
   CollectorOpts.Origin = SymbolOrigin::Dynamic;
 
-  SymbolCollector Collector(std::move(CollectorOpts));
-  Collector.setPreprocessor(PP);
   index::IndexingOptions IndexOpts;
   // We only need declarations, because we don't count references.
   IndexOpts.SystemSymbolFilter =
@@ -46,20 +45,45 @@ SymbolSlab indexAST(ASTContext , std
 DeclsToIndex.assign(AST.getTranslationUnitDecl()->decls().begin(),
 AST.getTranslationUnitDecl()->decls().end());
 
+  // We only collect occurrences when indexing main AST.
+  // FIXME: this is a hacky way to detect whether we are indexing preamble AST
+  // or main AST, we should make it explicitly.
+  bool IsIndexMainAST = TopLevelDecls.hasValue();
+  if (IsIndexMainAST)
+CollectorOpts.OccurrenceFilter = AllOccurrenceKinds;
+
+  SymbolCollector Collector(std::move(CollectorOpts));
+  Collector.setPreprocessor(PP);
   index::indexTopLevelDecls(AST, DeclsToIndex, Collector, IndexOpts);
 
-  return Collector.takeSymbols();
+  const auto  = AST.getSourceManager();
+  const auto *MainFileEntry = SM.getFileEntryForID(SM.getMainFileID());
+  std::string FileName = MainFileEntry ? MainFileEntry->getName() : "";
+
+  auto Syms = Collector.takeSymbols();
+  auto Occurrences = Collector.takeOccurrences();
+  vlog("index {0}AST for {1}: \n"
+   "  symbol slab: {2} symbols, {3} bytes\n"
+   "  occurrence slab: {4} symbols, {5} bytes",
+   IsIndexMainAST ? "Main" : "Preamble", FileName, Syms.size(),
+   Syms.bytes(), Occurrences.size(), Occurrences.bytes());
+  return {std::move(Syms), std::move(Occurrences)};
 }
 
 FileIndex::FileIndex(std::vector URISchemes)
 : URISchemes(std::move(URISchemes)) {}
 
-void FileSymbols::update(PathRef Path, std::unique_ptr Slab) {
+void FileSymbols::update(PathRef Path, std::unique_ptr Slab,
+ std::unique_ptr Occurrences) {
   std::lock_guard Lock(Mutex);
   if (!Slab)
 FileToSlabs.erase(Path);
   else
 FileToSlabs[Path] = std::move(Slab);
+  if (!Occurrences)
+FileToOccurrenceSlabs.erase(Path);
+  else
+FileToOccurrenceSlabs[Path] = std::move(Occurrences);
 }
 
 std::shared_ptr> FileSymbols::allSymbols() {
@@ -85,19 +109,47 @@ std::shared_ptr FileSymbols::allOccurrences() const {
+  // The snapshot manages life time of symbol occurrence slabs and provides
+  // pointers to all occurrences in all occurrence slabs.
+  struct Snapshot {
+MemIndex::OccurrenceMap Occurrences; // ID => {Occurrence}
+std::vector> KeepAlive;
+  };
+
+  auto Snap = std::make_shared();
+  {
+std::lock_guard Lock(Mutex);
+
+for (const auto  : FileToOccurrenceSlabs) {
+  Snap->KeepAlive.push_back(FileAndSlab.second);
+  for (const auto  

[PATCH] D51554: [CUDA][OPENMP][NVPTX]Improve logic of the debug info support.

2018-08-31 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev created this revision.
ABataev added reviewers: tra, echristo.
Herald added subscribers: JDevlieghere, guansong, aprantl.

Added support for the -gline-directives-only option + fixed logic of the
debug info for CUDA devices. If optimization level is O0, then options
--[no-]cuda-noopt-device-debug do not affect the debug info level. If
the optimization level is >O0, debug info options are used +
--no-cuda-noopt-device-debug is used or no --cuda-noopt-device-debug is
used, the optimization level for the device code is kept and the
emission of the debug directives is used.
If the opt level is > O0, debug info is requested +
--cuda-noopt-device-debug option is used, the optimization is disabled
for the device code + required debug info is emitted.


Repository:
  rC Clang

https://reviews.llvm.org/D51554

Files:
  include/clang/Driver/ToolChain.h
  lib/Driver/ToolChains/Clang.cpp
  lib/Driver/ToolChains/Cuda.cpp
  lib/Driver/ToolChains/Cuda.h
  test/Driver/cuda-dwarf-2.cu
  test/Driver/openmp-offload-gpu.c

Index: test/Driver/openmp-offload-gpu.c
===
--- test/Driver/openmp-offload-gpu.c
+++ test/Driver/openmp-offload-gpu.c
@@ -167,29 +167,39 @@
 // CHK-BCLIB-WARN: No library 'libomptarget-nvptx-sm_20.bc' found in the default clang lib directory or in LIBRARY_PATH. Expect degraded performance due to no inlining of runtime functions on target devices.
 
 /// Check that debug info is emitted in dwarf-2
-// RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -g -O0 --no-cuda-noopt-device-debug 2>&1 \
-// RUN:   | FileCheck -check-prefix=NO_DEBUG %s
+// RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -g -O1 --no-cuda-noopt-device-debug 2>&1 \
+// RUN:   | FileCheck -check-prefix=LINE_TABLE %s
 // RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -g -O3 2>&1 \
-// RUN:   | FileCheck -check-prefix=NO_DEBUG %s
+// RUN:   | FileCheck -check-prefix=LINE_TABLE %s
 // RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -g -O3 --no-cuda-noopt-device-debug 2>&1 \
-// RUN:   | FileCheck -check-prefix=NO_DEBUG %s
+// RUN:   | FileCheck -check-prefix=LINE_TABLE %s
 // RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -g0 2>&1 \
 // RUN:   | FileCheck -check-prefix=NO_DEBUG %s
 // RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -ggdb0 -O3 --cuda-noopt-device-debug 2>&1 \
 // RUN:   | FileCheck -check-prefix=NO_DEBUG %s
 // RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -gline-tables-only 2>&1 \
-// RUN:   | FileCheck -check-prefix=NO_DEBUG -check-prefix=LINE_TABLE %s
+// RUN:   | FileCheck -check-prefix=LINE_TABLE %s
+// RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -gline-directives-only 2>&1 \
+// RUN:   | FileCheck -check-prefix=LINE_TABLE %s
 // RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -ggdb1 -O2 --cuda-noopt-device-debug 2>&1 \
-// RUN:   | FileCheck -check-prefix=NO_DEBUG -check-prefix=LINE_TABLE %s
+// RUN:   | FileCheck -check-prefix=LINE_TABLE %s
 
 // LINE_TABLE-NOT: warning: debug
 // NO_DEBUG-NOT: warning: debug
+// NO_DEBUG: "-fopenmp-is-device"
+// NO_DEBUG-NOT: "-debug-info-kind=
 // NO_DEBUG: ptxas
+// LINE_TABLE: "-triple" "nvptx64-nvidia-cuda"
+// LINE_TABLE-SAME: "-debug-info-kind=line-directives-only"
+// LINE_TABLE-SAME: "-fopenmp-is-device"
+// LINE_TABLE: ptxas
 // LINE_TABLE: "-lineinfo"
 // NO_DEBUG-NOT: "-g"
 // NO_DEBUG: nvlink
 // NO_DEBUG-NOT: "-g"
 
+// RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -g -O0 --no-cuda-noopt-device-debug 2>&1 \
+// RUN:   | FileCheck -check-prefix=HAS_DEBUG %s
 // RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -g 2>&1 \
 // RUN:   | FileCheck -check-prefix=HAS_DEBUG %s
 // RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -g -O0 --cuda-noopt-device-debug 2>&1 \
@@ -207,6 +217,7 @@
 
 // HAS_DEBUG-NOT: warning: debug
 // HAS_DEBUG: "-triple" "nvptx64-nvidia-cuda"
+// HAS_DEBUG-SAME: "-debug-info-kind=limited"
 // HAS_DEBUG-SAME: "-dwarf-version=2"
 // HAS_DEBUG-SAME: "-fopenmp-is-device"
 // HAS_DEBUG: ptxas
Index: test/Driver/cuda-dwarf-2.cu

[PATCH] D51084: Implement -Watomic-implicit-seq-cst

2018-08-31 Thread JF Bastien via Phabricator via cfe-commits
jfb updated this revision to Diff 163577.
jfb added a comment.

- Don't diagnose initialization, only assignment.


Repository:
  rC Clang

https://reviews.llvm.org/D51084

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaChecking.cpp
  test/Sema/atomic-implicit-seq_cst.c
  test/Sema/sync-implicit-seq_cst.c

Index: test/Sema/sync-implicit-seq_cst.c
===
--- /dev/null
+++ test/Sema/sync-implicit-seq_cst.c
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 %s -verify -ffreestanding -fsyntax-only -triple=i686-linux-gnu -std=c11 -Watomic-implicit-seq-cst -Wno-sync-fetch-and-nand-semantics-changed
+
+// __sync_* operations are implicitly sequentially-consistent. Some codebases
+// want to force explicit usage of memory order instead.
+
+void fetch_and_add(int *ptr, int val) { __sync_fetch_and_add(ptr, val); }   // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
+void fetch_and_sub(int *ptr, int val) { __sync_fetch_and_sub(ptr, val); }   // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
+void fetch_and_or(int *ptr, int val) { __sync_fetch_and_or(ptr, val); } // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
+void fetch_and_and(int *ptr, int val) { __sync_fetch_and_and(ptr, val); }   // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
+void fetch_and_xor(int *ptr, int val) { __sync_fetch_and_xor(ptr, val); }   // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
+void fetch_and_nand(int *ptr, int val) { __sync_fetch_and_nand(ptr, val); } // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
+
+void add_and_fetch(int *ptr, int val) { __sync_add_and_fetch(ptr, val); }   // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
+void sub_and_fetch(int *ptr, int val) { __sync_sub_and_fetch(ptr, val); }   // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
+void or_and_fetch(int *ptr, int val) { __sync_or_and_fetch(ptr, val); } // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
+void and_and_fetch(int *ptr, int val) { __sync_and_and_fetch(ptr, val); }   // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
+void xor_and_fetch(int *ptr, int val) { __sync_xor_and_fetch(ptr, val); }   // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
+void nand_and_fetch(int *ptr, int val) { __sync_nand_and_fetch(ptr, val); } // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
+
+void bool_compare_and_swap(int *ptr, int oldval, int newval) { __sync_bool_compare_and_swap(ptr, oldval, newval); } // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
+void val_compare_and_swap(int *ptr, int oldval, int newval) { __sync_val_compare_and_swap(ptr, oldval, newval); }   // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
+
+void synchronize(void) { __sync_synchronize(); } // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
+
+void lock_test_and_set(int *ptr, int val) { __sync_lock_test_and_set(ptr, val); } // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
+void lock_release(int *ptr) { __sync_lock_release(ptr); } // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
Index: test/Sema/atomic-implicit-seq_cst.c
===
--- /dev/null
+++ test/Sema/atomic-implicit-seq_cst.c
@@ -0,0 +1,325 @@
+// RUN: %clang_cc1 %s -verify -ffreestanding -fsyntax-only -triple=i686-linux-gnu -std=c11 -Watomic-implicit-seq-cst
+
+// _Atomic operations are implicitly sequentially-consistent. Some codebases
+// want to force explicit usage of memory order instead.
+
+_Atomic(int) atom;
+void gimme_int(int);
+
+void bad_pre_inc(void) {
+  ++atom; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
+}
+
+void bad_pre_dec(void) {
+  --atom; // expected-warning {{implicit use of sequentially-consistent 

r341240 - Tests: fix tests encoding specific hash values for 32-bit systems.

2018-08-31 Thread Tim Northover via cfe-commits
Author: tnorthover
Date: Fri Aug 31 12:24:37 2018
New Revision: 341240

URL: http://llvm.org/viewvc/llvm-project?rev=341240=rev
Log:
Tests: fix tests encoding specific hash values for 32-bit systems.

I changed the seed slightly, but forgot to run the tests on a 32-bit system, so
tests which hard-code a specific hash value started breaking.

Modified:
cfe/trunk/test/CodeGenCXX/catch-undef-behavior.cpp

Modified: cfe/trunk/test/CodeGenCXX/catch-undef-behavior.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/catch-undef-behavior.cpp?rev=341240=341239=341240=diff
==
--- cfe/trunk/test/CodeGenCXX/catch-undef-behavior.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/catch-undef-behavior.cpp Fri Aug 31 12:24:37 2018
@@ -72,7 +72,7 @@ void member_access(S *p) {
   // The two hash values are for 64- and 32-bit Clang binaries, respectively.
   // FIXME: We should produce a 64-bit value either way.
   //
-  // CHECK-NEXT: xor i64 {{-4030275160588942838|2562089159}}, %[[VPTR]]
+  // CHECK-NEXT: xor i64 {{-4030275160588942838|1107558922}}, %[[VPTR]]
   // CHECK-NEXT: mul i64 {{.*}}, -7070675565921424023
   // CHECK-NEXT: lshr i64 {{.*}}, 47
   // CHECK-NEXT: xor i64
@@ -121,7 +121,7 @@ void member_access(S *p) {
   // (3b) Check that 'p' actually points to an 'S'
 
   // CHECK: load i64, i64*
-  // CHECK-NEXT: xor i64 {{-4030275160588942838|2562089159}},
+  // CHECK-NEXT: xor i64 {{-4030275160588942838|1107558922}},
   // [...]
   // CHECK: getelementptr inbounds [128 x i64], [128 x i64]* 
@__ubsan_vptr_type_cache, i32 0, i64 %
   // CHECK: br i1


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


Re: [PATCH] D51507: Allow all supportable attributes to be used with #pragma clang attribute.

2018-08-31 Thread Richard Smith via cfe-commits
On Fri, 31 Aug 2018 at 06:35, Aaron Ballman via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> My reasoning is because type attributes have more impact than variable
> attributes and types appear more frequently. Consider using
> address_space where the region includes function definitions. Should
> that apply to the parameters and return types of the function as well
> as the code within the function? Will that be intuitive for users?
>

I think there's actually an easy answer for this: the #pragma clang
attribute mechanism does not support type attributes at all. Calling
conventions, address_space attributes, and the like are not affected by
this patch. So, while we should figure out whether we want to support
injecting type attributes with this pragma, the status quo is that we do
not and cannot.

However... there are some attributes that (for historical reasons, I think)
are not classified as type attribtues, despite clearly being type
attributes in principle, and that this patch would allow usage of with
#pragma clang attribute:

 * ext_vector_type: We handle this as a type attribute but classify it as a
type alias attribute. This just seems to be a bug in the .td file. (We do
*have* type alias handling for it, but that seems wrong to me: all we do
when we see the attribute applied to an alias is to remember the type for
later, and it would make a lot more sense to do that when building the
alias declaration itself rather than pretending the attribute is a
declaration attribute to support this.)

 * mode: We model and handle this as a declaration attribute, but it's
really notionally a type attribute. I expect we model it as a declaration
attribute for GCC compatibility.

(The other type_alias attributes really do apply to the alias and not to
the type, typically transforming the alias declaration into a declaration
of a new type that is different from the original type in some way but that
is canonically equivalent to the original. As such, introducing an
attribute for a block of such aliases seems reasonable and useful.)

I'm going to blacklist those two attributes in this patch. We can decide at
some later time if we want to support type attributes with this pragma or
not, but I think for now we have consensus on the changes herein for all
non-type attributes, and we should go ahead with that part of the change.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r341117 - [MS ABI] Fix mangling issue with dynamic initializer stubs.

2018-08-31 Thread Galina Kistanova via cfe-commits
Hello Zachary,

It looks like this commit added broken tests on one of our builders:
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast/builds/19508

. . .
Failing Tests (2):
LLVM-Unit :: ADT/./ADTTests.exe/HashingTest.HashCombineRangeGoldenTest
Clang :: CodeGenCXX/catch-undef-behavior.cpp

Please have a look?
The builder was already red and did not send notifications on this.

Thanks

Galina

On Thu, Aug 30, 2018 at 1:54 PM Zachary Turner via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: zturner
> Date: Thu Aug 30 13:53:11 2018
> New Revision: 341117
>
> URL: http://llvm.org/viewvc/llvm-project?rev=341117=rev
> Log:
> [MS ABI] Fix mangling issue with dynamic initializer stubs.
>
> There are two types of dynamic initializer stubs.  There's
>
>   `dynamic initializer for 'x''(void)
>
> and
>
>   `dynamic initializer for `static Foo::Bar StaticDataMember''(void)
>
> The second case is disambiguated from the first by the presence of
> a ? after the operator code.  So the first will appear something like
> ?__E while the second will appear something like ?__E?.
> clang-cl was mangling these both the same though.  This patch
> matches behavior with cl.
>
> Differential Revision: https://reviews.llvm.org/D51500
>
> Modified:
> cfe/trunk/lib/AST/MicrosoftMangle.cpp
> cfe/trunk/test/CodeGenCXX/microsoft-abi-static-initializers.cpp
> cfe/trunk/test/CodeGenCXX/pragma-init_seg.cpp
>
> Modified: cfe/trunk/lib/AST/MicrosoftMangle.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftMangle.cpp?rev=341117=341116=341117=diff
>
> ==
> --- cfe/trunk/lib/AST/MicrosoftMangle.cpp (original)
> +++ cfe/trunk/lib/AST/MicrosoftMangle.cpp Thu Aug 30 13:53:11 2018
> @@ -3217,10 +3217,13 @@ void MicrosoftMangleContextImpl::mangleI
>msvc_hashing_ostream MHO(Out);
>MicrosoftCXXNameMangler Mangler(*this, MHO);
>Mangler.getStream() << "??__" << CharCode;
> -  Mangler.mangleName(D);
>if (D->isStaticDataMember()) {
> +Mangler.getStream() << '?';
> +Mangler.mangleName(D);
>  Mangler.mangleVariableEncoding(D);
> -Mangler.getStream() << '@';
> +Mangler.getStream() << "@@";
> +  } else {
> +Mangler.mangleName(D);
>}
>// This is the function class mangling.  These stubs are global,
> non-variadic,
>// cdecl functions that return void and take no args.
>
> Modified: cfe/trunk/test/CodeGenCXX/microsoft-abi-static-initializers.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/microsoft-abi-static-initializers.cpp?rev=341117=341116=341117=diff
>
> ==
> --- cfe/trunk/test/CodeGenCXX/microsoft-abi-static-initializers.cpp
> (original)
> +++ cfe/trunk/test/CodeGenCXX/microsoft-abi-static-initializers.cpp Thu
> Aug 30 13:53:11 2018
> @@ -3,8 +3,8 @@
>  // CHECK: @llvm.global_ctors = appending global [5 x { i32, void ()*, i8*
> }] [
>  // CHECK: { i32, void ()*, i8* } { i32 65535, void ()* 
> @"??__Eselectany1@@YAXXZ",
> i8* getelementptr inbounds (%struct.S, %struct.S* @"?selectany1@@3US@@A",
> i32 0, i32 0) },
>  // CHECK: { i32, void ()*, i8* } { i32 65535, void ()* 
> @"??__Eselectany2@@YAXXZ",
> i8* getelementptr inbounds (%struct.S, %struct.S* @"?selectany2@@3US@@A",
> i32 0, i32 0) },
> -// CHECK: { i32, void ()*, i8* } { i32 65535, void ()* @"??__Es@
> ?$ExportedTemplate@H@@2US@@A@YAXXZ", i8* getelementptr inbounds
> (%struct.S, %struct.S* @"?s@?$ExportedTemplate@H@@2US@@A", i32 0, i32 0)
> },
> -// CHECK: { i32, void ()*, i8* } { i32 65535, void ()* @"??__Efoo@?$B@H
> @@2VA@@A@YAXXZ", i8* bitcast (%class.A* @"?foo@?$B@H@@2VA@@A" to i8*) },
> +// CHECK: { i32, void ()*, i8* } { i32 65535, void ()* @"??__E?s@
> ?$ExportedTemplate@H@@2US@@A@@YAXXZ", i8* getelementptr inbounds
> (%struct.S, %struct.S* @"?s@?$ExportedTemplate@H@@2US@@A", i32 0, i32 0)
> },
> +// CHECK: { i32, void ()*, i8* } { i32 65535, void ()* @"??__E?foo@?$B@H
> @@2VA@@A@@YAXXZ", i8* bitcast (%class.A* @"?foo@?$B@H@@2VA@@A" to i8*) },
>  // CHECK: { i32, void ()*, i8* } { i32 65535, void ()*
> @_GLOBAL__sub_I_microsoft_abi_static_initializers.cpp, i8* null }
>  // CHECK: ]
>
> @@ -231,18 +231,18 @@ void force_usage() {
>DynamicDLLImportInitVSMangling::switch_test3();
>  }
>
> -// CHECK: define linkonce_odr dso_local void @"??__Efoo@?$B@H@@2VA@
> @A@YAXXZ"() {{.*}} comdat
> +// CHECK: define linkonce_odr dso_local void 
> @"??__E?foo@?$B@H@@2VA@@A@@YAXXZ"()
> {{.*}} comdat
>  // CHECK-NOT: and
>  // CHECK-NOT: ?_Bfoo@
>  // CHECK: call x86_thiscallcc %class.A* @"??0A@@QAE@XZ"
> -// CHECK: call i32 @atexit(void ()* @"??__Ffoo@?$B@H@@2VA@@A@YAXXZ")
> +// CHECK: call i32 @atexit(void ()* @"??__F?foo@?$B@H@@2VA@@A@@YAXXZ")
>  // CHECK: ret void
>
>  // CHECK: define linkonce_odr dso_local x86_thiscallcc %class.A* @"??0A@
> @QAE@XZ"({{.*}}) {{.*}} comdat
>
>  // CHECK: 

[PATCH] D50783: [CodeGen] Merge identical block descriptor global variables

2018-08-31 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added a comment.

The GNUstep documentation I found replaces '@' with '\1'. Would that fix the 
problem?

https://github.com/gnustep/libobjc2/blob/master/ABIDoc/abi.tex


Repository:
  rC Clang

https://reviews.llvm.org/D50783



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


r341234 - [X86] Add kshift intrinsics to match gcc and icc.

2018-08-31 Thread Craig Topper via cfe-commits
Author: ctopper
Date: Fri Aug 31 11:22:52 2018
New Revision: 341234

URL: http://llvm.org/viewvc/llvm-project?rev=341234=rev
Log:
[X86] Add kshift intrinsics to match gcc and icc.

This adds the following intrinsics:
_kshiftli_mask8
_kshiftli_mask16
_kshiftli_mask32
_kshiftli_mask64
_kshiftri_mask8
_kshiftri_mask16
_kshiftri_mask32
_kshiftri_mask64

Modified:
cfe/trunk/include/clang/Basic/BuiltinsX86.def
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/lib/Headers/avx512bwintrin.h
cfe/trunk/lib/Headers/avx512dqintrin.h
cfe/trunk/lib/Headers/avx512fintrin.h
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/CodeGen/avx512bw-builtins.c
cfe/trunk/test/CodeGen/avx512dq-builtins.c
cfe/trunk/test/CodeGen/avx512f-builtins.c

Modified: cfe/trunk/include/clang/Basic/BuiltinsX86.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsX86.def?rev=341234=341233=341234=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsX86.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsX86.def Fri Aug 31 11:22:52 2018
@@ -1770,6 +1770,14 @@ TARGET_BUILTIN(__builtin_ia32_kxorqi, "U
 TARGET_BUILTIN(__builtin_ia32_kxorhi, "UsUsUs", "nc", "avx512f")
 TARGET_BUILTIN(__builtin_ia32_kxorsi, "UiUiUi", "nc", "avx512bw")
 TARGET_BUILTIN(__builtin_ia32_kxordi, "ULLiULLiULLi", "nc", "avx512bw")
+TARGET_BUILTIN(__builtin_ia32_kshiftliqi, "UcUcIUi", "nc", "avx512dq")
+TARGET_BUILTIN(__builtin_ia32_kshiftlihi, "UsUsIUi", "nc", "avx512f")
+TARGET_BUILTIN(__builtin_ia32_kshiftlisi, "UiUiIUi", "nc", "avx512bw")
+TARGET_BUILTIN(__builtin_ia32_kshiftlidi, "ULLiULLiIUi", "nc", "avx512bw")
+TARGET_BUILTIN(__builtin_ia32_kshiftriqi, "UcUcIUi", "nc", "avx512dq")
+TARGET_BUILTIN(__builtin_ia32_kshiftrihi, "UsUsIUi", "nc", "avx512f")
+TARGET_BUILTIN(__builtin_ia32_kshiftrisi, "UiUiIUi", "nc", "avx512bw")
+TARGET_BUILTIN(__builtin_ia32_kshiftridi, "ULLiULLiIUi", "nc", "avx512bw")
 TARGET_BUILTIN(__builtin_ia32_palignr512, "V64cV64cV64cIi", "ncV:512:", 
"avx512bw")
 TARGET_BUILTIN(__builtin_ia32_dbpsadbw128, "V8sV16cV16cIi", "ncV:128:", 
"avx512bw,avx512vl")
 TARGET_BUILTIN(__builtin_ia32_dbpsadbw256, "V16sV32cV32cIi", "ncV:256:", 
"avx512bw,avx512vl")

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=341234=341233=341234=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Fri Aug 31 11:22:52 2018
@@ -9929,6 +9929,50 @@ Value *CodeGenFunction::EmitX86BuiltinEx
 "psrldq");
 return Builder.CreateBitCast(SV, ResultType, "cast");
   }
+  case X86::BI__builtin_ia32_kshiftliqi:
+  case X86::BI__builtin_ia32_kshiftlihi:
+  case X86::BI__builtin_ia32_kshiftlisi:
+  case X86::BI__builtin_ia32_kshiftlidi: {
+unsigned ShiftVal = cast(Ops[1])->getZExtValue() & 0xff;
+unsigned NumElts = Ops[0]->getType()->getIntegerBitWidth();
+
+if (ShiftVal >= NumElts)
+  return llvm::Constant::getNullValue(Ops[0]->getType());
+
+Value *In = getMaskVecValue(*this, Ops[0], NumElts);
+
+uint32_t Indices[64];
+for (unsigned i = 0; i != NumElts; ++i)
+  Indices[i] = NumElts + i - ShiftVal;
+
+Value *Zero = llvm::Constant::getNullValue(In->getType());
+Value *SV = Builder.CreateShuffleVector(Zero, In,
+makeArrayRef(Indices, NumElts),
+"kshiftl");
+return Builder.CreateBitCast(SV, Ops[0]->getType());
+  }
+  case X86::BI__builtin_ia32_kshiftriqi:
+  case X86::BI__builtin_ia32_kshiftrihi:
+  case X86::BI__builtin_ia32_kshiftrisi:
+  case X86::BI__builtin_ia32_kshiftridi: {
+unsigned ShiftVal = cast(Ops[1])->getZExtValue() & 0xff;
+unsigned NumElts = Ops[0]->getType()->getIntegerBitWidth();
+
+if (ShiftVal >= NumElts)
+  return llvm::Constant::getNullValue(Ops[0]->getType());
+
+Value *In = getMaskVecValue(*this, Ops[0], NumElts);
+
+uint32_t Indices[64];
+for (unsigned i = 0; i != NumElts; ++i)
+  Indices[i] = i + ShiftVal;
+
+Value *Zero = llvm::Constant::getNullValue(In->getType());
+Value *SV = Builder.CreateShuffleVector(In, Zero,
+makeArrayRef(Indices, NumElts),
+"kshiftr");
+return Builder.CreateBitCast(SV, Ops[0]->getType());
+  }
   case X86::BI__builtin_ia32_movnti:
   case X86::BI__builtin_ia32_movnti64:
   case X86::BI__builtin_ia32_movntsd:

Modified: cfe/trunk/lib/Headers/avx512bwintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/avx512bwintrin.h?rev=341234=341233=341234=diff
==
--- cfe/trunk/lib/Headers/avx512bwintrin.h (original)
+++ 

[PATCH] D51508: Export public functions implemented in assembly on Windows.

2018-08-31 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL341232: Export public functions implemented in assembly on 
Windows. (authored by cdavis, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D51508

Files:
  libunwind/trunk/src/assembly.h


Index: libunwind/trunk/src/assembly.h
===
--- libunwind/trunk/src/assembly.h
+++ libunwind/trunk/src/assembly.h
@@ -44,6 +44,7 @@
 #if defined(__APPLE__)
 
 #define SYMBOL_IS_FUNC(name)
+#define EXPORT_SYMBOL(name)
 #define HIDDEN_SYMBOL(name) .private_extern name
 #define NO_EXEC_STACK_DIRECTIVE
 
@@ -54,6 +55,7 @@
 #else
 #define SYMBOL_IS_FUNC(name) .type name,@function
 #endif
+#define EXPORT_SYMBOL(name)
 #define HIDDEN_SYMBOL(name) .hidden name
 
 #if defined(__GNU__) || defined(__FreeBSD__) || defined(__Fuchsia__) || \
@@ -70,6 +72,11 @@
 .scl 2 SEPARATOR   
\
 .type 32 SEPARATOR 
\
   .endef
+#define EXPORT_SYMBOL2(name)  \
+  .section .drectve,"yn" SEPARATOR\
+  .ascii "-export:", #name, "\0" SEPARATOR\
+  .text
+#define EXPORT_SYMBOL(name) EXPORT_SYMBOL2(name)
 #define HIDDEN_SYMBOL(name)
 
 #define NO_EXEC_STACK_DIRECTIVE
@@ -82,6 +89,7 @@
 
 #define DEFINE_LIBUNWIND_FUNCTION(name)   \
   .globl SYMBOL_NAME(name) SEPARATOR  \
+  EXPORT_SYMBOL(name) SEPARATOR   \
   SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
   SYMBOL_NAME(name):
 


Index: libunwind/trunk/src/assembly.h
===
--- libunwind/trunk/src/assembly.h
+++ libunwind/trunk/src/assembly.h
@@ -44,6 +44,7 @@
 #if defined(__APPLE__)
 
 #define SYMBOL_IS_FUNC(name)
+#define EXPORT_SYMBOL(name)
 #define HIDDEN_SYMBOL(name) .private_extern name
 #define NO_EXEC_STACK_DIRECTIVE
 
@@ -54,6 +55,7 @@
 #else
 #define SYMBOL_IS_FUNC(name) .type name,@function
 #endif
+#define EXPORT_SYMBOL(name)
 #define HIDDEN_SYMBOL(name) .hidden name
 
 #if defined(__GNU__) || defined(__FreeBSD__) || defined(__Fuchsia__) || \
@@ -70,6 +72,11 @@
 .scl 2 SEPARATOR   \
 .type 32 SEPARATOR \
   .endef
+#define EXPORT_SYMBOL2(name)  \
+  .section .drectve,"yn" SEPARATOR\
+  .ascii "-export:", #name, "\0" SEPARATOR\
+  .text
+#define EXPORT_SYMBOL(name) EXPORT_SYMBOL2(name)
 #define HIDDEN_SYMBOL(name)
 
 #define NO_EXEC_STACK_DIRECTIVE
@@ -82,6 +89,7 @@
 
 #define DEFINE_LIBUNWIND_FUNCTION(name)   \
   .globl SYMBOL_NAME(name) SEPARATOR  \
+  EXPORT_SYMBOL(name) SEPARATOR   \
   SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
   SYMBOL_NAME(name):
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libunwind] r341232 - Export public functions implemented in assembly on Windows.

2018-08-31 Thread Charles Davis via cfe-commits
Author: cdavis
Date: Fri Aug 31 11:11:48 2018
New Revision: 341232

URL: http://llvm.org/viewvc/llvm-project?rev=341232=rev
Log:
Export public functions implemented in assembly on Windows.

Summary:
By default, symbols aren't visible outside of the module that defines
them. To make them visible, they must be exported. The easiest way to do
that is to embed an `-export:symname` directive into the object file.

Reviewers: mstorsjo, rnk

Subscribers: christof, cfe-commits

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

Modified:
libunwind/trunk/src/assembly.h

Modified: libunwind/trunk/src/assembly.h
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/assembly.h?rev=341232=341231=341232=diff
==
--- libunwind/trunk/src/assembly.h (original)
+++ libunwind/trunk/src/assembly.h Fri Aug 31 11:11:48 2018
@@ -44,6 +44,7 @@
 #if defined(__APPLE__)
 
 #define SYMBOL_IS_FUNC(name)
+#define EXPORT_SYMBOL(name)
 #define HIDDEN_SYMBOL(name) .private_extern name
 #define NO_EXEC_STACK_DIRECTIVE
 
@@ -54,6 +55,7 @@
 #else
 #define SYMBOL_IS_FUNC(name) .type name,@function
 #endif
+#define EXPORT_SYMBOL(name)
 #define HIDDEN_SYMBOL(name) .hidden name
 
 #if defined(__GNU__) || defined(__FreeBSD__) || defined(__Fuchsia__) || \
@@ -70,6 +72,11 @@
 .scl 2 SEPARATOR   
\
 .type 32 SEPARATOR 
\
   .endef
+#define EXPORT_SYMBOL2(name)  \
+  .section .drectve,"yn" SEPARATOR\
+  .ascii "-export:", #name, "\0" SEPARATOR\
+  .text
+#define EXPORT_SYMBOL(name) EXPORT_SYMBOL2(name)
 #define HIDDEN_SYMBOL(name)
 
 #define NO_EXEC_STACK_DIRECTIVE
@@ -82,6 +89,7 @@
 
 #define DEFINE_LIBUNWIND_FUNCTION(name)   \
   .globl SYMBOL_NAME(name) SEPARATOR  \
+  EXPORT_SYMBOL(name) SEPARATOR   \
   SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
   SYMBOL_NAME(name):
 


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


[PATCH] D51508: Export public functions implemented in assembly on Windows.

2018-08-31 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

lgtm




Comment at: src/assembly.h:76-78
+  .section .drectve,"yn" SEPARATOR\
+  .ascii "-export:", #name, "\0" SEPARATOR\
+  .text

cdavis5x wrote:
> rnk wrote:
> > Maybe .pushsection / .popsection is better than assuming you were in .text.
> I initially wanted to do that, but those directives aren't supported by COFF. 
> Neither, by the way, is `.previous`. Perhaps this needs to be fixed in LLVM.
Huh, I guess neither does gas. .text is fine then. I'll file a bug to implement 
those directives for COFF. They're pretty handy, especially for an object file 
format that uses comdat sections so frequently.


Repository:
  rUNW libunwind

https://reviews.llvm.org/D51508



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


[PATCH] D51521: Refactor Addlibgcc to make the when and what logic more straightfoward.

2018-08-31 Thread Sterling Augustine via Phabricator via cfe-commits
saugustine closed this revision.
saugustine added a comment.

commited as r341231.


Repository:
  rC Clang

https://reviews.llvm.org/D51521



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


r341231 - Refactor Addlibgcc to make the when and what logic more straightfoward.

2018-08-31 Thread Sterling Augustine via cfe-commits
Author: saugustine
Date: Fri Aug 31 10:59:03 2018
New Revision: 341231

URL: http://llvm.org/viewvc/llvm-project?rev=341231=rev
Log:
Refactor Addlibgcc to make the when and what logic more straightfoward.

Add Android tests.


Modified:
cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp
cfe/trunk/test/Driver/linux-ld.c

Modified: cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp?rev=341231=341230=341231=diff
==
--- cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp Fri Aug 31 10:59:03 2018
@@ -1126,23 +1126,42 @@ static void AddLibgcc(const llvm::Triple
   bool IsIAMCU = Triple.isOSIAMCU();
   bool StaticLibgcc = Args.hasArg(options::OPT_static_libgcc) ||
   Args.hasArg(options::OPT_static);
-  if (!D.CCCIsCXX())
+
+  // The driver ignores -shared-libgcc and therefore treats such cases as
+  // unspecified.  Breaking out the two variables as below makes the current
+  // behavior explicit.
+  bool UnspecifiedLibgcc = !StaticLibgcc;
+  bool SharedLibgcc = !StaticLibgcc;
+
+  // Gcc adds libgcc arguments in various ways:
+  //
+  // gcc : -lgcc --as-needed -lgcc_s --no-as-needed
+  // g++ :   -lgcc_s   -lgcc
+  // gcc shared:   -lgcc_s   -lgcc
+  // g++ shared:   -lgcc_s   -lgcc
+  // gcc static: -lgcc -lgcc_eh
+  // g++ static: -lgcc -lgcc_eh
+  //
+  // Also, certain targets need additional adjustments.
+
+  bool LibGccFirst = (D.CCCIsCC() && UnspecifiedLibgcc) || StaticLibgcc;
+  if (LibGccFirst)
 CmdArgs.push_back("-lgcc");
 
-  if (StaticLibgcc || isAndroid) {
-if (D.CCCIsCXX())
-  CmdArgs.push_back("-lgcc");
-  } else {
-if (!D.CCCIsCXX() && !isCygMing)
-  CmdArgs.push_back("--as-needed");
+  bool AsNeeded = D.CCCIsCC() && !StaticLibgcc && !isAndroid && !isCygMing;
+  if (AsNeeded)
+CmdArgs.push_back("--as-needed");
+
+  if ((UnspecifiedLibgcc || SharedLibgcc) && !isAndroid)
 CmdArgs.push_back("-lgcc_s");
-if (!D.CCCIsCXX() && !isCygMing)
-  CmdArgs.push_back("--no-as-needed");
-  }
 
-  if (StaticLibgcc && !isAndroid && !IsIAMCU)
+  else if (StaticLibgcc && !isAndroid && !IsIAMCU)
 CmdArgs.push_back("-lgcc_eh");
-  else if (!Args.hasArg(options::OPT_shared) && D.CCCIsCXX())
+
+  if (AsNeeded)
+CmdArgs.push_back("--no-as-needed");
+
+  if (!LibGccFirst)
 CmdArgs.push_back("-lgcc");
 
   // According to Android ABI, we have to link with libdl if we are

Modified: cfe/trunk/test/Driver/linux-ld.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/linux-ld.c?rev=341231=341230=341231=diff
==
--- cfe/trunk/test/Driver/linux-ld.c (original)
+++ cfe/trunk/test/Driver/linux-ld.c Fri Aug 31 10:59:03 2018
@@ -230,6 +230,30 @@
 // SKIP-CHECK-CLANG-SHARED-LIBGCC-DYNAMIC: "-lc"
 // SKIP-CHECK-CLANG-SHARED-LIBGCC-DYNAMIC: "-lgcc_s" "-lgcc"
 //
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: --target=aarch64-linux-android -rtlib=platform \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-CLANG-ANDROID-NONE %s
+// CHECK-CLANG-ANDROID-NONE: "{{.*}}ld{{(.exe)?}}" 
"--sysroot=[[SYSROOT:[^"]+]]"
+// CHECK-CLANG-ANDROID-NONE: "-lgcc" "-ldl" "-lc"
+//
+// RUN: %clang -shared -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: --target=aarch64-linux-android -rtlib=platform \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-CLANG-ANDROID-SHARED %s
+// CHECK-CLANG-ANDROID-SHARED: "{{.*}}ld{{(.exe)?}}" 
"--sysroot=[[SYSROOT:[^"]+]]"
+// CHECK-CLANG-ANDROID-SHARED: "-lgcc" "-ldl" "-lc"
+//
+// RUN: %clang -static -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: --target=aarch64-linux-android -rtlib=platform \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-CLANG-ANDROID-STATIC %s
+// CHECK-CLANG-ANDROID-STATIC: "{{.*}}ld{{(.exe)?}}" 
"--sysroot=[[SYSROOT:[^"]+]]"
+// CHECK-CLANG-ANDROID-STATIC: "--start-group" "-lgcc" "-lc" "--end-group"
+//
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1  \
 // RUN: --target=x86_64-unknown-linux -rtlib=platform \
 // RUN: -static \


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


[PATCH] D51359: Adding HardLink Support to VirtualFileSystem.

2018-08-31 Thread UTKARSH SAXENA via Phabricator via cfe-commits
usaxena95 added a comment.

Made the suggested changes.




Comment at: include/clang/Basic/VirtualFileSystem.h:359
+  public:
+  /// Add a HardLink to a File.
+  /// The To path must be an existing file or a hardlink. The From file must 
not

ilya-biryukov wrote:
> Maybe document that it does nothing for directories?
> Also, any reason to not support directories at this point? The limitation 
> seem artificial at this point.
Links to directories cannot be  added with the current logic. Resolving paths 
and iterating directories becomes non trivial. Current implementation supports 
the use case of "file with multiple names" which is mostly sufficient to mimic 
the compilation.



Comment at: lib/Basic/VirtualFileSystem.cpp:529
+public:
+  InMemoryHardLink(Status Stat, InMemoryNode *ResolvedNode)
+  : InMemoryNode(std::move(Stat), IME_HARD_LINK),

ilya-biryukov wrote:
> usaxena95 wrote:
> > ilya-biryukov wrote:
> > > ilya-biryukov wrote:
> > > > Why do we need the Stat?
> > > > We can get it from `ResolveNode` if we want to store a copy. Any reason 
> > > > why it would be different?
> > > ResolveNode can't be `null`, right? Maybe use a reference instead?
> > > Also, maybe make it const?
> > Changed it to reference. Can't make it const as the there it is involved in 
> > methods that are non const (like getResolvedFile returns a pointer, 
> > getBuffer is not const)
> Both methods could be made const, though, right?
> It looks like the buffers are always copied when returned from the file 
> system (because the VFS interface returns a `unique_ptr`).
> `getResolvedFile` can also return a const node.
Since a raw pointer to the resolved file is returned by getResolvedNode (used 
by for lookup) , I have also changed some other raw pointer type to const 
pointer tpye.


Repository:
  rC Clang

https://reviews.llvm.org/D51359



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


[PATCH] D51521: Refactor Addlibgcc to make the when and what logic more straightfoward.

2018-08-31 Thread Stephen Hines via Phabricator via cfe-commits
srhines accepted this revision.
srhines added a comment.
This revision is now accepted and ready to land.

Thanks for cleaning this up and adding better checks for Android. :)


Repository:
  rC Clang

https://reviews.llvm.org/D51521



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


[PATCH] D51359: Adding HardLink Support to VirtualFileSystem.

2018-08-31 Thread UTKARSH SAXENA via Phabricator via cfe-commits
usaxena95 updated this revision to Diff 163549.
usaxena95 marked 15 inline comments as done.
usaxena95 added a comment.

- Made suggested changes.


Repository:
  rC Clang

https://reviews.llvm.org/D51359

Files:
  include/clang/Basic/VirtualFileSystem.h
  lib/Basic/VirtualFileSystem.cpp
  unittests/Basic/VirtualFileSystemTest.cpp

Index: unittests/Basic/VirtualFileSystemTest.cpp
===
--- unittests/Basic/VirtualFileSystemTest.cpp
+++ unittests/Basic/VirtualFileSystemTest.cpp
@@ -16,7 +16,9 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/SourceMgr.h"
 #include "gtest/gtest.h"
+#include "gmock/gmock.h"
 #include 
+#include 
 
 using namespace clang;
 using namespace llvm;
@@ -697,6 +699,29 @@
 NormalizedFS(/*UseNormalizedPaths=*/true) {}
 };
 
+MATCHER_P3(IsHardLinktTo, FS, Target, ExpectedBuffer, "") {
+  Twine From = arg;
+  Twine To = Target;
+  auto OpenedFrom = FS->openFileForRead(From);
+  if (OpenedFrom.getError())
+return false;
+  auto OpenedTo = FS->openFileForRead(To);
+  if (OpenedTo.getError())
+return false;
+  if ((*OpenedFrom)->status()->getSize() != (*OpenedTo)->status()->getSize())
+return false;
+  if ((*OpenedFrom)->status()->getUniqueID() !=
+  (*OpenedTo)->status()->getUniqueID())
+return false;
+  if ((*OpenedFrom)->getBuffer(From)->get()->getBuffer().data() !=
+  ExpectedBuffer)
+return false;
+  if ((*OpenedFrom)->getBuffer(From)->get()->getBuffer().data() !=
+  ExpectedBuffer)
+return false;
+  return true;
+}
+
 TEST_F(InMemoryFileSystemTest, IsEmpty) {
   auto Stat = FS.status("/a");
   ASSERT_EQ(Stat.getError(),errc::no_such_file_or_directory) << FS.toString();
@@ -958,6 +983,126 @@
   ASSERT_EQ("../b/c", getPosixPath(It->getName()));
 }
 
+TEST_F(InMemoryFileSystemTest, AddHardLinkToFile) {
+  Twine FromLink = "/path/to/FROM/link";
+  Twine Target = "/path/to/TO/file";
+  StringRef content = "content of target";
+  FS.addFile(Target, 0, MemoryBuffer::getMemBuffer(content));
+  EXPECT_TRUE(FS.addHardLink(FromLink, Target));
+  EXPECT_THAT(FromLink, IsHardLinktTo(, Target, content.data()));
+}
+
+TEST_F(InMemoryFileSystemTest, AddHardLinkInChainPattern) {
+  StringRef content = "content of target file";
+  Twine link0 = "/path/to/0/link";
+  Twine link1 = "/path/to/1/link";
+  Twine link2 = "/path/to/2/link";
+  Twine target = "/path/to/target";
+  FS.addFile(target, 0, MemoryBuffer::getMemBuffer(content));
+  EXPECT_TRUE(FS.addHardLink(link2, target));
+  EXPECT_TRUE(FS.addHardLink(link1, link2));
+  EXPECT_TRUE(FS.addHardLink(link0, link1));
+  EXPECT_THAT(link0, IsHardLinktTo(, target, content.data()));
+  EXPECT_THAT(link1, IsHardLinktTo(, target, content.data()));
+  EXPECT_THAT(link2, IsHardLinktTo(, target, content.data()));
+}
+
+TEST_F(InMemoryFileSystemTest, AddHardLinkToAFileThatWasNotAddedBefore) {
+  Twine link = "/path/to/link";
+  Twine target = "/path/to/target";
+  EXPECT_FALSE(FS.addHardLink(link, target));
+}
+
+TEST_F(InMemoryFileSystemTest, AddHardLinkFromAFileThatWasAddedBefore) {
+  Twine link = "/path/to/link";
+  StringRef content_link = "content of link";
+  Twine target = "/path/to/target";
+  StringRef content = "content of target";
+  FS.addFile(target, 0, MemoryBuffer::getMemBuffer(content));
+  FS.addFile(link, 0, MemoryBuffer::getMemBuffer(content_link));
+  EXPECT_FALSE(FS.addHardLink(link, target));
+}
+
+TEST_F(InMemoryFileSystemTest, AddSameHardLinkMoreThanOnce) {
+  Twine link = "/path/to/link";
+  Twine target = "/path/to/target";
+  StringRef content = "content of target";
+  FS.addFile(target, 0, MemoryBuffer::getMemBuffer(content));
+  EXPECT_TRUE(FS.addHardLink(link, target));
+  EXPECT_FALSE(FS.addHardLink(link, target));
+}
+
+TEST_F(InMemoryFileSystemTest, AddFileInPlaceOfAHardLinkWithSameContent) {
+  Twine link = "/path/to/link";
+  Twine target = "/path/to/target";
+  StringRef content = "content of target";
+  EXPECT_TRUE(FS.addFile(target, 0, MemoryBuffer::getMemBuffer(content)));
+  EXPECT_TRUE(FS.addHardLink(link, target));
+  EXPECT_TRUE(FS.addFile(link, 0, MemoryBuffer::getMemBuffer(content)));
+}
+
+TEST_F(InMemoryFileSystemTest, AddFileInPlaceOfAHardLinkWithDifferentContent) {
+  Twine link = "/path/to/link";
+  Twine target = "/path/to/target";
+  StringRef content = "content of target";
+  StringRef link_content = "different content of link";
+  EXPECT_TRUE(FS.addFile(target, 0, MemoryBuffer::getMemBuffer(content)));
+  EXPECT_TRUE(FS.addHardLink(link, target));
+  EXPECT_FALSE(FS.addFile(link, 0, MemoryBuffer::getMemBuffer(link_content)));
+}
+
+TEST_F(InMemoryFileSystemTest, AddHardLinkToADirectory) {
+  Twine dir = "path/to/dummy/dir";
+  Twine link = "/path/to/link";
+  Twine dummy_file = dir + "/target";
+  StringRef content = "content of target";
+  EXPECT_TRUE(FS.addFile(dummy_file, 0, MemoryBuffer::getMemBuffer(content)));
+  EXPECT_FALSE(FS.addHardLink(link, dir));
+}
+

[PATCH] D51545: Enable -Wtautological-unsigned-zero-compare under -Wextra

2018-08-31 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added reviewers: thakis, vsk, phosek.
lebedev.ri added a comment.

In https://reviews.llvm.org/D51545#1220967, @eandrews wrote:

> @lebedev.ri is there a specific reason -Wtautological-unsigned-zero-compare 
> was removed? All the issues I am aware of talks about comparisons with 
> min/max.


Dunno.
Comparison with zero, i would imagine, has the same problem as comparisons with 
min/max, since comparisons with min == comparison with zero, for unsigned types.


https://reviews.llvm.org/D51545



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


[PATCH] D51545: Enable -Wtautological-unsigned-zero-compare under -Wextra

2018-08-31 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added a comment.

@lebedev.ri is there a specific reason -Wtautological-unsigned-zero-compare was 
removed? All the issues I am aware of talks about comparisons with min/max.


https://reviews.llvm.org/D51545



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


[PATCH] D51531: [analyzer][UninitializedObjectChecker] Uninit regions are only reported once

2018-08-31 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus updated this revision to Diff 163542.

https://reviews.llvm.org/D51531

Files:
  lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h
  lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
  lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
  test/Analysis/cxx-uninitialized-object-ptr-ref.cpp

Index: test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
===
--- test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
+++ test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
@@ -809,3 +809,44 @@
   ReferenceTest4::RecordType c, d{37, 38};
   ReferenceTest4(d, c);
 }
+
+//===--===//
+// Tests for objects containing multiple references to the same object.
+//===--===//
+
+struct IntMultipleReferenceToSameObjectTest {
+  int *iptr; // expected-note{{uninitialized pointee 'this->iptr'}}
+  int  // no-note, pointee of this->iref was already reported
+
+  int dontGetFilteredByNonPedanticMode = 0;
+
+  IntMultipleReferenceToSameObjectTest(int *i) : iptr(i), iref(*i) {} // expected-warning{{1 uninitialized field}}
+};
+
+void fIntMultipleReferenceToSameObjectTest() {
+  int a;
+  IntMultipleReferenceToSameObjectTest Test();
+}
+
+struct IntReferenceWrapper1 {
+  int  // expected-note{{uninitialized pointee 'this->a'}}
+
+  int dontGetFilteredByNonPedanticMode = 0;
+
+  IntReferenceWrapper1(int ) : a(a) {} // expected-warning{{1 uninitialized field}}
+};
+
+struct IntReferenceWrapper2 {
+  int  // no-note, pointee of this->a was already reported
+
+  int dontGetFilteredByNonPedanticMode = 0;
+
+  IntReferenceWrapper2(int ) : a(a) {} // no-warning
+};
+
+void fMultipleObjectsReferencingTheSameObjectTest() {
+  int a;
+
+  IntReferenceWrapper1 T1(a);
+  IntReferenceWrapper2 T2(a);
+}
Index: lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
===
--- lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
+++ lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
@@ -126,7 +126,7 @@
 assert(!FR->getDecl()->getType()->isReferenceType() &&
"References must be initialized!");
 return addFieldToUninits(
-LocalChain.add(LocField(FR, /*IsDereferenced*/ false)));
+LocalChain.add(LocField(FR, /*IsDereferenced*/ false)), FR);
   }
 
   if (!CheckPointeeInitialization) {
@@ -157,8 +157,9 @@
   if (PointeeT->isUnionType()) {
 if (isUnionUninit(R)) {
   if (NeedsCastBack)
-return addFieldToUninits(LocalChain.add(NeedsCastLocField(FR, DynT)));
-  return addFieldToUninits(LocalChain.add(LocField(FR)));
+return addFieldToUninits(LocalChain.add(NeedsCastLocField(FR, DynT)),
+ R);
+  return addFieldToUninits(LocalChain.add(LocField(FR)), R);
 } else {
   IsAnyFieldInitialized = true;
   return false;
@@ -178,8 +179,8 @@
 
   if (isPrimitiveUninit(PointeeV)) {
 if (NeedsCastBack)
-  return addFieldToUninits(LocalChain.add(NeedsCastLocField(FR, DynT)));
-return addFieldToUninits(LocalChain.add(LocField(FR)));
+  return addFieldToUninits(LocalChain.add(NeedsCastLocField(FR, DynT)), R);
+return addFieldToUninits(LocalChain.add(LocField(FR)), R);
   }
 
   IsAnyFieldInitialized = true;
Index: lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
+++ lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
@@ -56,9 +56,14 @@
 using namespace clang;
 using namespace clang::ento;
 
+/// We'll mark fields (and pointee of fields) that are confirmed to be
+/// uninitialized as already analyzed.
+REGISTER_SET_WITH_PROGRAMSTATE(AnalyzedRegions, const MemRegion *)
+
 namespace {
 
-class UninitializedObjectChecker : public Checker {
+class UninitializedObjectChecker
+: public Checker {
   std::unique_ptr BT_uninitField;
 
 public:
@@ -69,7 +74,9 @@
 
   UninitializedObjectChecker()
   : BT_uninitField(new BuiltinBug(this, "Uninitialized fields")) {}
+
   void checkEndFunction(const ReturnStmt *RS, CheckerContext ) const;
+  void checkDeadSymbols(SymbolReaper , CheckerContext ) const;
 };
 
 /// A basic field type, that is not a pointer or a reference, it's dynamic and
@@ -166,20 +173,28 @@
   FindUninitializedFields F(Context.getState(), Object->getRegion(),
 CheckPointeeInitialization);
 
-  const UninitFieldMap  = F.getUninitFields();
+  std::pair UninitInfo =
+  F.getResults();
+
+  ProgramStateRef UpdatedState = UninitInfo.first;
+  const UninitFieldMap  = UninitInfo.second;
 
-  if (UninitFields.empty())

[PATCH] D51545: Enable -Wtautological-unsigned-zero-compare under -Wextra

2018-08-31 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews created this revision.
eandrews added reviewers: lebedev.ri, rsmith, rjmccall, rnk, mclow.lists, 
erichkeane.

GCC enables -Wtype-limits under -Wextra. Warnings under GCC's -Wtype-limits is 
covered in Clang by -Wtautological-type-limit-compare and 
-Wtautological-unsigned-zero-compare.

Since -Wtautological-type-limit-compare can fire spuriously when a type's size 
is platform-dependent (as detailed in D41512 
), I am adding only 
-Wtautological-unsigned-zero-compare to -Wextra.

I should point out that GCC does not throw warnings on pointless unsigned 
expression comparisons inside templates while 
-Wtautological-unsigned-zero-compare does. I figure this is a limitation in 
GCC's implementation and don't think this is an issue but please feel free to 
let me know if I am mistaken.


https://reviews.llvm.org/D51545

Files:
  include/clang/Basic/DiagnosticGroups.td
  test/Sema/tautological-unsigned-zero-compare.c


Index: test/Sema/tautological-unsigned-zero-compare.c
===
--- test/Sema/tautological-unsigned-zero-compare.c
+++ test/Sema/tautological-unsigned-zero-compare.c
@@ -8,6 +8,12 @@
 // RUN:-verify -x c++ %s
 // RUN: %clang_cc1 -fsyntax-only \
 // RUN:-verify=silence -x c++ %s
+// RUN: %clang_cc1 -fsyntax-only \
+// RUN:-Wextra -Wno-sign-compare\
+// RUN:-verify %s
+// RUN: %clang_cc1 -fsyntax-only \
+// RUN:-Wextra -Wno-sign-compare\
+// RUN:-verify -x c++ %s
 
 unsigned uvalue(void);
 signed int svalue(void);
Index: include/clang/Basic/DiagnosticGroups.td
===
--- include/clang/Basic/DiagnosticGroups.td
+++ include/clang/Basic/DiagnosticGroups.td
@@ -763,7 +763,8 @@
 MissingMethodReturnType,
 SignCompare,
 UnusedParameter,
-NullPointerArithmetic
+NullPointerArithmetic,
+TautologicalUnsignedZeroCompare
   ]>;
 
 def Most : DiagGroup<"most", [


Index: test/Sema/tautological-unsigned-zero-compare.c
===
--- test/Sema/tautological-unsigned-zero-compare.c
+++ test/Sema/tautological-unsigned-zero-compare.c
@@ -8,6 +8,12 @@
 // RUN:-verify -x c++ %s
 // RUN: %clang_cc1 -fsyntax-only \
 // RUN:-verify=silence -x c++ %s
+// RUN: %clang_cc1 -fsyntax-only \
+// RUN:-Wextra -Wno-sign-compare\
+// RUN:-verify %s
+// RUN: %clang_cc1 -fsyntax-only \
+// RUN:-Wextra -Wno-sign-compare\
+// RUN:-verify -x c++ %s
 
 unsigned uvalue(void);
 signed int svalue(void);
Index: include/clang/Basic/DiagnosticGroups.td
===
--- include/clang/Basic/DiagnosticGroups.td
+++ include/clang/Basic/DiagnosticGroups.td
@@ -763,7 +763,8 @@
 MissingMethodReturnType,
 SignCompare,
 UnusedParameter,
-NullPointerArithmetic
+NullPointerArithmetic,
+TautologicalUnsignedZeroCompare
   ]>;
 
 def Most : DiagGroup<"most", [
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D51539: [clangd] Add symbol slab size to index memory consumption estimates

2018-08-31 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev planned changes to this revision.
kbobyrev added a comment.

I'll rebase it on top of https://reviews.llvm.org/D51422 and address the last 
comment before proceeding to the review.


https://reviews.llvm.org/D51539



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


[PATCH] D51544: [OpenCL] Split opencl-c.h header

2018-08-31 Thread Andrew Savonichev via Phabricator via cfe-commits
asavonic created this revision.
asavonic added reviewers: Anastasia, yaxunl, bader.
Herald added subscribers: cfe-commits, jfb, mgorny.

TL;DR
-

This patch splits huge opencl-c.h header into multiple headers to
support efficient use of Precompiled Headers (or Modules):

- opencl-c-defs.h contains all preprocessor macros. Macros are not saved in 
PCHs.
- opencl-c-common.h contains builtins which do not depend on any preprocessor 
macro (extensions, OpenCL C version).
- opencl-c-fp16.h and opencl-c-fp64.h contain builtins which require either 
cl_khr_fp16 or cl_khr_fp64 macros, but they do not depend on other extensions 
and OpenCL C version.
- opencl-c-platform.h (looking for a better name! 'target' maybe?) contains all 
other builtins which have more complicated requirements.

Umbrella header opencl-c.h includes all headers above, so this change
is backward compatible with the original design.

Details
---

Typical OpenCL compiler implicitly includes opencl-c.h before
compiling user code:

  #include "opencl-c.h"
  __kernel void k() { printf("hello world\n"); }

With this approach, even for tiny programs compiler spends most of its
time on parsing of opencl-c.h header (which has more than 16000 LOC),
so it takes ~1s to compile our hello world example into LLVM IR.

Obvious solution for this problem is to compile opencl-c.h into an AST
only once, and then use this AST to compile user code. This feature
can be implemented using Precompiled Headers or Clang Modules, but it
has one major drawback: AST must be built with the same set of
preprocessor macros and the same target triple as the the user
code. Consider the following example:

opencl-c.h:

  #if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
float fract(float x, float *iptr);
  #else
float fract(float x, __global float *iptr);
  #endif

If we compile this opencl-c.h into an AST, only one of these two
functions will be present. We cannot use this AST to compile for both
OpenCL C 1.2 and 2.0.

Another example: if we compile opencl-c.h into an AST with
spir-unknown-unknown (32bit) target triple, AST will have 'int'
instead of 'size_t':

opencl-c.h:

  typedef __SIZE_TYPE__ size_t; // __SIZE_TYPE__ is defined to int by clang
  size_t get_global_size(uint dimindx);

This makes the AST non-portable, and it cannot be used to compile for
spir64 triple (where size_t is 64bit integer).

If we want compiler to support CL1.2/CL2.0 for spir/spir64 triple,
we'll need to use 4 different PCHs compiled with different flags:

  -cl-std=CL1.2 + -triple spir
  -cl-std=CL1.2 + -triple spir64
  -cl-std=CL2.0 + -triple spir
  -cl-std=CL2.0 + -triple spir64

Things are getting worse if we want to support multiple devices, which
have different sets of OpenCL extensions. For example, if we want to
support both CPU (which supports cl_khr_fp64) and GPU (which supports
cl_khr_fp16), we must compile opencl-c.h using different options,
because it has the following code all over the place:

  #ifdef cl_khr_fp64
uchar __ovld __cnfn convert_uchar(double);
  #endif
  #ifdef cl_khr_fp16
uchar __ovld __cnfn convert_uchar(half);
  #endif

So if we want to add these 2 devices, we now need 4*2 different PCHs,
since every combination of -cl-std and -triple must be compiled twice
with different OpenCL extensions defines.

Size of each PCH is 2.5M, so we need ~20M of memory to store our
PCHs. If we want to add more devices or support another OpenCL C
version, the size will double.

For a C/C++ compiler this is not a problem: clang maintains a cache so
that only combinations which are actually used are saved to a
disk. OpenCL compilers are different, because they are often
distributed as a shared library. Being a library, it is not expected
to write something on a disk, because it rises a number of questions,
such as: "where do we have a writable temporary directory?" and "how
much space we can consume for PCHs?". For some targets (say, embedded
devices) it is better to avoid this approach.

To solve this problem, the patch splits opencl-c.h header into
multiple headers.

First, we split out 'common' functions, which should be present
regardless of OpenCL C version or extensions. All builtins which have
'core' types, such as convert, math and simple image builtins are
moved into opencl-c-common.h (8K LOC).

Second, split out all functions which are 'common' between OpenCL
version, but require either cl_khr_fp16 or cl_khr_fp64 (not both at
the same time!). Two headers (opencl-c-fp16.h and opencl-c-fp64.h)
have 2K LOC each.

Everything else goes into opencl-c-platform.h (5K LOC).

All macros go in opencl-c-defs.h, because macros cannot be
pre-compiled into AST.

With this setup, we can compile opencl-c-common.h, opencl-c-fp16.h and
opencl-c-fp64.h into PCHs with one set of extensions/OpenCL version,
and use them for any other set of extensions/OpenCL version. Clang
will detect this and throw out an error, which can be safely disabled
by -fno-validate-pch option.


[PATCH] D51440: [ToolChains] Link to compiler-rt with -L + -l when possible

2018-08-31 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

In https://reviews.llvm.org/D51440#1220925, @phosek wrote:

> In https://reviews.llvm.org/D51440#1218859, @mstorsjo wrote:
>
> > I'll see if I can get to looking at that sometime soon. I had this patch 
> > lying around as an attempt to work around the libtool issue in 
> > https://debbugs.gnu.org/cgi/bugreport.cgi?bug=27866 which doesn't seem to 
> > be going anywhere (and even if it did, it probably takes quite a bit of 
> > time before a new libtool release is made and it gets propagated to most 
> > places where I'd like to use this), and was curious if there was any 
> > specific reason for having this the way it was, or just the usual; 
> > historical reasons that it has started out like this and haven't had a need 
> > to change until now. If you otherwise would happen to be touching the same 
> > areas, feel free to pick it up ;-) otherwise I'll try to look at addressing 
> > your points in a few days.
>
>
> I'd be happy to pick this up. I already planned to do more 
> refactoring/cleanup of this part of the driver. @beanz is improving the 
> Darwin toolchain driver to make more like other Clang drivers, so I want to 
> first sync up with him to make sure this is also going to work for them.


Oh, great - thanks a lot!


Repository:
  rC Clang

https://reviews.llvm.org/D51440



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


[PATCH] D51481: [clangd] Implement proximity path boosting for Dex

2018-08-31 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev added inline comments.



Comment at: clang-tools-extra/clangd/index/dex/Token.h:54
 Scope,
+/// Path to symbol declaration.
+///

ioeric wrote:
> As this is called `Path`, I'd try to decouple it from URIs, so that we don't 
> need special handling of `scheme` etc in the implementation. We might want to 
> canonicalize URI to "path" like `/file:/path/to/something/` so that we could 
> simply treat it as normal paths, and the token could potentially handle 
> actual actual file paths.
Should probably rename it to URI and be more explicit about its nature.


https://reviews.llvm.org/D51481



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


[PATCH] D51279: [clangd] Implement findOccurrences interface in dynamic index.

2018-08-31 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 163539.
hokein marked 3 inline comments as done.
hokein added a comment.

address review comments:

- build memindex with symbol slab and occurrence slab
- remove withAllCode in TestTU


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D51279

Files:
  clangd/index/FileIndex.cpp
  clangd/index/FileIndex.h
  clangd/index/Index.h
  clangd/index/MemIndex.cpp
  clangd/index/MemIndex.h
  clangd/index/Merge.cpp
  clangd/index/Merge.h
  clangd/tool/ClangdMain.cpp
  unittests/clangd/CodeCompleteTests.cpp
  unittests/clangd/FileIndexTests.cpp
  unittests/clangd/IndexTests.cpp
  unittests/clangd/TestTU.cpp

Index: unittests/clangd/TestTU.cpp
===
--- unittests/clangd/TestTU.cpp
+++ unittests/clangd/TestTU.cpp
@@ -45,11 +45,12 @@
 
 SymbolSlab TestTU::headerSymbols() const {
   auto AST = build();
-  return indexAST(AST.getASTContext(), AST.getPreprocessorPtr());
+  return indexAST(AST.getASTContext(), AST.getPreprocessorPtr()).first;
 }
 
 std::unique_ptr TestTU::index() const {
-  return MemIndex::build(headerSymbols());
+  // FIXME: we should generate proper occurrences for TestTU.
+  return MemIndex::build(headerSymbols(), SymbolOccurrenceSlab::createEmpty());
 }
 
 const Symbol (const SymbolSlab , llvm::StringRef QName) {
Index: unittests/clangd/IndexTests.cpp
===
--- unittests/clangd/IndexTests.cpp
+++ unittests/clangd/IndexTests.cpp
@@ -7,21 +7,36 @@
 //
 //===--===//
 
+#include "Annotations.h"
 #include "TestIndex.h"
+#include "TestTU.h"
+#include "gmock/gmock.h"
+#include "index/FileIndex.h"
 #include "index/Index.h"
 #include "index/MemIndex.h"
 #include "index/Merge.h"
-#include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
 using testing::Pointee;
 using testing::UnorderedElementsAre;
+using testing::AllOf;
 
 namespace clang {
 namespace clangd {
 namespace {
 
+std::shared_ptr emptyOccurrences() {
+  return llvm::make_unique();
+}
+
 MATCHER_P(Named, N, "") { return arg.Name == N; }
+MATCHER_P(OccurrenceRange, Range, "") {
+  return std::tie(arg.Location.Start.Line, arg.Location.Start.Column,
+  arg.Location.End.Line, arg.Location.End.Column) ==
+ std::tie(Range.start.line, Range.start.character, Range.end.line,
+  Range.end.character);
+}
+MATCHER_P(FileURI, F, "") { return arg.Location.FileURI == F; }
 
 TEST(SymbolSlab, FindAndIterate) {
   SymbolSlab::Builder B;
@@ -42,14 +57,14 @@
 TEST(MemIndexTest, MemIndexSymbolsRecycled) {
   MemIndex I;
   std::weak_ptr Symbols;
-  I.build(generateNumSymbols(0, 10, ));
+  I.build(generateNumSymbols(0, 10, ), emptyOccurrences());
   FuzzyFindRequest Req;
   Req.Query = "7";
   EXPECT_THAT(match(I, Req), UnorderedElementsAre("7"));
 
   EXPECT_FALSE(Symbols.expired());
   // Release old symbols.
-  I.build(generateNumSymbols(0, 0));
+  I.build(generateNumSymbols(0, 0), emptyOccurrences());
   EXPECT_TRUE(Symbols.expired());
 }
 
@@ -65,14 +80,14 @@
   FuzzyFindRequest Req;
   Req.Query = "7";
   MemIndex I;
-  I.build(std::move(Symbols));
+  I.build(std::move(Symbols), emptyOccurrences());
   auto Matches = match(I, Req);
   EXPECT_EQ(Matches.size(), 1u);
 }
 
 TEST(MemIndexTest, MemIndexLimitedNumMatches) {
   MemIndex I;
-  I.build(generateNumSymbols(0, 100));
+  I.build(generateNumSymbols(0, 100), emptyOccurrences());
   FuzzyFindRequest Req;
   Req.Query = "5";
   Req.MaxCandidateCount = 3;
@@ -85,7 +100,8 @@
 TEST(MemIndexTest, FuzzyMatch) {
   MemIndex I;
   I.build(
-  generateSymbols({"LaughingOutLoud", "LionPopulation", "LittleOldLady"}));
+  generateSymbols({"LaughingOutLoud", "LionPopulation", "LittleOldLady"}),
+  emptyOccurrences());
   FuzzyFindRequest Req;
   Req.Query = "lol";
   Req.MaxCandidateCount = 2;
@@ -95,60 +111,62 @@
 
 TEST(MemIndexTest, MatchQualifiedNamesWithoutSpecificScope) {
   MemIndex I;
-  I.build(generateSymbols({"a::y1", "b::y2", "y3"}));
+  I.build(generateSymbols({"a::y1", "b::y2", "y3"}), emptyOccurrences());
   FuzzyFindRequest Req;
   Req.Query = "y";
   EXPECT_THAT(match(I, Req), UnorderedElementsAre("a::y1", "b::y2", "y3"));
 }
 
 TEST(MemIndexTest, MatchQualifiedNamesWithGlobalScope) {
   MemIndex I;
-  I.build(generateSymbols({"a::y1", "b::y2", "y3"}));
+  I.build(generateSymbols({"a::y1", "b::y2", "y3"}), emptyOccurrences());
   FuzzyFindRequest Req;
   Req.Query = "y";
   Req.Scopes = {""};
   EXPECT_THAT(match(I, Req), UnorderedElementsAre("y3"));
 }
 
 TEST(MemIndexTest, MatchQualifiedNamesWithOneScope) {
   MemIndex I;
-  I.build(generateSymbols({"a::y1", "a::y2", "a::x", "b::y2", "y3"}));
+  I.build(generateSymbols({"a::y1", "a::y2", "a::x", "b::y2", "y3"}),
+  emptyOccurrences());
   FuzzyFindRequest Req;
   Req.Query = "y";
   Req.Scopes = {"a::"};
   EXPECT_THAT(match(I, Req), UnorderedElementsAre("a::y1", 

[PATCH] D51481: [clangd] Implement proximity path boosting for Dex

2018-08-31 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 163538.
kbobyrev marked an inline comment as not done.
kbobyrev added a comment.

Fix tests


https://reviews.llvm.org/D51481

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/index/dex/DexIndex.cpp
  clang-tools-extra/clangd/index/dex/DexIndex.h
  clang-tools-extra/clangd/index/dex/Token.cpp
  clang-tools-extra/clangd/index/dex/Token.h
  clang-tools-extra/clangd/tool/ClangdMain.cpp
  clang-tools-extra/unittests/clangd/DexIndexTests.cpp
  clang-tools-extra/unittests/clangd/TestFS.cpp
  clang-tools-extra/unittests/clangd/TestFS.h

Index: clang-tools-extra/unittests/clangd/TestFS.h
===
--- clang-tools-extra/unittests/clangd/TestFS.h
+++ clang-tools-extra/unittests/clangd/TestFS.h
@@ -59,7 +59,7 @@
 };
 
 // Returns an absolute (fake) test directory for this OS.
-const char *testRoot();
+std::string testRoot();
 
 // Returns a suitable absolute path for this OS.
 std::string testPath(PathRef File);
Index: clang-tools-extra/unittests/clangd/TestFS.cpp
===
--- clang-tools-extra/unittests/clangd/TestFS.cpp
+++ clang-tools-extra/unittests/clangd/TestFS.cpp
@@ -64,7 +64,7 @@
   FileName, std::move(CommandLine), "")};
 }
 
-const char *testRoot() {
+std::string testRoot() {
 #ifdef _WIN32
   return "C:\\clangd-test";
 #else
Index: clang-tools-extra/unittests/clangd/DexIndexTests.cpp
===
--- clang-tools-extra/unittests/clangd/DexIndexTests.cpp
+++ clang-tools-extra/unittests/clangd/DexIndexTests.cpp
@@ -7,6 +7,8 @@
 //
 //===--===//
 
+#include "FuzzyMatch.h"
+#include "TestFS.h"
 #include "TestIndex.h"
 #include "index/Index.h"
 #include "index/Merge.h"
@@ -29,6 +31,8 @@
 namespace dex {
 namespace {
 
+std::vector URISchemes = {"unittest"};
+
 std::vector consumeIDs(Iterator ) {
   auto IDAndScore = consume(It);
   std::vector IDs(IDAndScore.size());
@@ -325,14 +329,33 @@
 }
 
 testing::Matcher>
-trigramsAre(std::initializer_list Trigrams) {
+tokensAre(std::initializer_list Strings, Token::Kind Kind) {
   std::vector Tokens;
-  for (const auto  : Trigrams) {
-Tokens.push_back(Token(Token::Kind::Trigram, Symbols));
+  for (const auto  : Strings) {
+Tokens.push_back(Token(Kind, TokenData));
   }
   return testing::UnorderedElementsAreArray(Tokens);
 }
 
+testing::Matcher>
+trigramsAre(std::initializer_list Trigrams) {
+  return tokensAre(Trigrams, Token::Kind::Trigram);
+}
+
+testing::Matcher>
+pathsAre(std::initializer_list Paths) {
+  return tokensAre(Paths, Token::Kind::Path);
+}
+
+testing::Matcher>> proximityPathsAre(
+std::initializer_list> ProximityPaths) {
+  std::vector> Result;
+  for (const auto  : ProximityPaths) {
+Result.push_back({Token(Token::Kind::Path, P.first), P.second});
+  }
+  return testing::UnorderedElementsAreArray(Result);
+}
+
 TEST(DexIndexTrigrams, IdentifierTrigrams) {
   EXPECT_THAT(generateIdentifierTrigrams("X86"),
   trigramsAre({"x86", "x$$", "x8$"}));
@@ -407,8 +430,28 @@
"hij", "ijk", "jkl", "klm"}));
 }
 
+TEST(DexSearchTokens, SymbolPath) {
+  EXPECT_THAT(generateProximityPaths(
+  "unittest:///clang-tools-extra/clangd/index/dex/Token.h"),
+  pathsAre({"unittest:///clang-tools-extra/clangd/index/dex",
+"unittest:///clang-tools-extra/clangd/index",
+"unittest:///clang-tools-extra/clangd",
+"unittest:///clang-tools-extra",
+"unittest:///"}));
+}
+
+TEST(DexSearchTokens, QueryProximityDistances) {
+  EXPECT_THAT(
+  generateQueryProximityPaths(testRoot() + "/a/b/c/d/e/f/g.h", URISchemes),
+  proximityPathsAre({{"unittest:///a/b/c/d/e/f", 0},
+ {"unittest:///a/b/c/d/e", 1},
+ {"unittest:///a/b/c/d", 2},
+ {"unittest:///a/b/c", 3},
+ {"unittest:///a/b", 4}}));
+}
+
 TEST(DexIndex, Lookup) {
-  DexIndex I;
+  DexIndex I(URISchemes);
   I.build(generateSymbols({"ns::abc", "ns::xyz"}));
   EXPECT_THAT(lookup(I, SymbolID("ns::abc")), UnorderedElementsAre("ns::abc"));
   EXPECT_THAT(lookup(I, {SymbolID("ns::abc"), SymbolID("ns::xyz")}),
@@ -419,9 +462,10 @@
 }
 
 TEST(DexIndex, FuzzyFind) {
-  DexIndex Index;
+  DexIndex Index(URISchemes);
   Index.build(generateSymbols({"ns::ABC", "ns::BCD", "::ABC", "ns::nested::ABC",
-   "other::ABC", "other::A"}));
+   "other::ABC", "other::A"})
+  );
   FuzzyFindRequest Req;
   Req.Query = "ABC";
   Req.Scopes = {"ns::"};
@@ -442,7 +486,7 @@
 }
 
 TEST(DexIndexTest, FuzzyMatchQ) {
-  DexIndex I;
+  DexIndex I(URISchemes);
   I.build(
   generateSymbols({"LaughingOutLoud", 

[PATCH] D51440: [ToolChains] Link to compiler-rt with -L + -l when possible

2018-08-31 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

In https://reviews.llvm.org/D51440#1218859, @mstorsjo wrote:

> I'll see if I can get to looking at that sometime soon. I had this patch 
> lying around as an attempt to work around the libtool issue in 
> https://debbugs.gnu.org/cgi/bugreport.cgi?bug=27866 which doesn't seem to be 
> going anywhere (and even if it did, it probably takes quite a bit of time 
> before a new libtool release is made and it gets propagated to most places 
> where I'd like to use this), and was curious if there was any specific reason 
> for having this the way it was, or just the usual; historical reasons that it 
> has started out like this and haven't had a need to change until now. If you 
> otherwise would happen to be touching the same areas, feel free to pick it up 
> ;-) otherwise I'll try to look at addressing your points in a few days.


I'd be happy to pick this up. I already planned to do more refactoring/cleanup 
of this part of the driver. @beanz is improving the Darwin toolchain driver to 
make more like other Clang drivers, so I want to first sync up with him to make 
sure this is also going to work for them.


Repository:
  rC Clang

https://reviews.llvm.org/D51440



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


[PATCH] D51481: [clangd] Implement proximity path boosting for Dex

2018-08-31 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 163537.
kbobyrev marked 14 inline comments as done.

https://reviews.llvm.org/D51481

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/index/dex/DexIndex.cpp
  clang-tools-extra/clangd/index/dex/DexIndex.h
  clang-tools-extra/clangd/index/dex/Token.cpp
  clang-tools-extra/clangd/index/dex/Token.h
  clang-tools-extra/clangd/tool/ClangdMain.cpp
  clang-tools-extra/unittests/clangd/DexIndexTests.cpp
  clang-tools-extra/unittests/clangd/TestFS.cpp
  clang-tools-extra/unittests/clangd/TestFS.h

Index: clang-tools-extra/unittests/clangd/TestFS.h
===
--- clang-tools-extra/unittests/clangd/TestFS.h
+++ clang-tools-extra/unittests/clangd/TestFS.h
@@ -59,7 +59,7 @@
 };
 
 // Returns an absolute (fake) test directory for this OS.
-const char *testRoot();
+std::string testRoot();
 
 // Returns a suitable absolute path for this OS.
 std::string testPath(PathRef File);
Index: clang-tools-extra/unittests/clangd/TestFS.cpp
===
--- clang-tools-extra/unittests/clangd/TestFS.cpp
+++ clang-tools-extra/unittests/clangd/TestFS.cpp
@@ -64,7 +64,7 @@
   FileName, std::move(CommandLine), "")};
 }
 
-const char *testRoot() {
+std::string testRoot() {
 #ifdef _WIN32
   return "C:\\clangd-test";
 #else
Index: clang-tools-extra/unittests/clangd/DexIndexTests.cpp
===
--- clang-tools-extra/unittests/clangd/DexIndexTests.cpp
+++ clang-tools-extra/unittests/clangd/DexIndexTests.cpp
@@ -7,6 +7,8 @@
 //
 //===--===//
 
+#include "FuzzyMatch.h"
+#include "TestFS.h"
 #include "TestIndex.h"
 #include "index/Index.h"
 #include "index/Merge.h"
@@ -29,6 +31,8 @@
 namespace dex {
 namespace {
 
+std::vector URISchemes = {"unittest"};
+
 std::vector consumeIDs(Iterator ) {
   auto IDAndScore = consume(It);
   std::vector IDs(IDAndScore.size());
@@ -325,14 +329,33 @@
 }
 
 testing::Matcher>
-trigramsAre(std::initializer_list Trigrams) {
+tokensAre(std::initializer_list Strings, Token::Kind Kind) {
   std::vector Tokens;
-  for (const auto  : Trigrams) {
-Tokens.push_back(Token(Token::Kind::Trigram, Symbols));
+  for (const auto  : Strings) {
+Tokens.push_back(Token(Kind, TokenData));
   }
   return testing::UnorderedElementsAreArray(Tokens);
 }
 
+testing::Matcher>
+trigramsAre(std::initializer_list Trigrams) {
+  return tokensAre(Trigrams, Token::Kind::Trigram);
+}
+
+testing::Matcher>
+pathsAre(std::initializer_list Paths) {
+  return tokensAre(Paths, Token::Kind::Path);
+}
+
+testing::Matcher>> proximityPathsAre(
+std::initializer_list> ProximityPaths) {
+  std::vector> Result;
+  for (const auto  : ProximityPaths) {
+Result.push_back({Token(Token::Kind::Path, P.first), P.second});
+  }
+  return testing::UnorderedElementsAreArray(Result);
+}
+
 TEST(DexIndexTrigrams, IdentifierTrigrams) {
   EXPECT_THAT(generateIdentifierTrigrams("X86"),
   trigramsAre({"x86", "x$$", "x8$"}));
@@ -407,8 +430,28 @@
"hij", "ijk", "jkl", "klm"}));
 }
 
+TEST(DexSearchTokens, SymbolPath) {
+  EXPECT_THAT(generateProximityPaths(
+  "unittest:///clang-tools-extra/clangd/index/dex/Token.h"),
+  pathsAre({"unittest:///clang-tools-extra/clangd/index/dex/",
+"unittest:///clang-tools-extra/clangd/index/",
+"unittest:///clang-tools-extra/clangd/",
+"unittest:///clang-tools-extra/",
+"unittest:///"}));
+}
+
+TEST(DexSearchTokens, QueryProximityDistances) {
+  EXPECT_THAT(
+  generateQueryProximityPaths(testRoot() + "/a/b/c/d/e/f/g.h", URISchemes),
+  proximityPathsAre({{"unittest:///a/b/c/d/e/f/", 0},
+ {"unittest:///a/b/c/d/e/", 1},
+ {"unittest:///a/b/c/d/", 2},
+ {"unittest:///a/b/c/", 3},
+ {"unittest:///a/b/", 4}}));
+}
+
 TEST(DexIndex, Lookup) {
-  DexIndex I;
+  DexIndex I(URISchemes);
   I.build(generateSymbols({"ns::abc", "ns::xyz"}));
   EXPECT_THAT(lookup(I, SymbolID("ns::abc")), UnorderedElementsAre("ns::abc"));
   EXPECT_THAT(lookup(I, {SymbolID("ns::abc"), SymbolID("ns::xyz")}),
@@ -419,9 +462,10 @@
 }
 
 TEST(DexIndex, FuzzyFind) {
-  DexIndex Index;
+  DexIndex Index(URISchemes);
   Index.build(generateSymbols({"ns::ABC", "ns::BCD", "::ABC", "ns::nested::ABC",
-   "other::ABC", "other::A"}));
+   "other::ABC", "other::A"})
+  );
   FuzzyFindRequest Req;
   Req.Query = "ABC";
   Req.Scopes = {"ns::"};
@@ -442,7 +486,7 @@
 }
 
 TEST(DexIndexTest, FuzzyMatchQ) {
-  DexIndex I;
+  DexIndex I(URISchemes);
   I.build(
   generateSymbols({"LaughingOutLoud", "LionPopulation", 

[PATCH] D51422: [clangd] Factor out the data-swapping functionality from MemIndex/DexIndex.

2018-08-31 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clangd/index/FileIndex.h:47
+  // The shared_ptr keeps the symbols alive.
+  std::shared_ptr buildMemIndex();
 

ioeric wrote:
> Maybe avoid hardcoding the index name, so that we could potentially switch to 
> use a different index implementation?
> 
> We might also want to allow user to specify different index implementations 
> for file index e.g. main file dynamic index might prefer MemIndex while Dex 
> might be a better choice for the preamble index. 
I don't think "returns an index of unspecified implementation" is the best 
contract. MemIndex and DexIndex will both continue to exist, and they have 
different performance characteristics (roughly fast build vs fast query). So it 
should be up to the caller, no?



Comment at: clangd/index/MemIndex.h:30
+  /// Builds an index from a slab. The shared_ptr manages the slab's lifetime.
+  static std::shared_ptr build(SymbolSlab Slab);
 

ioeric wrote:
> sammccall wrote:
> > ioeric wrote:
> > > (It's a bit unfortunate that this has to return `shared_ptr` now)
> > Since some of the resources it owns has a shared lifetime, this is really 
> > just reflecting reality I think. Whether that's visible or invisible seems 
> > like a wash to me.
> This is only true when this is used with `SwapIndex` right? For example, a 
> static Dex/Mem index would probbaly have `unique_ptr` ownership.
Dex and MemIndex don't own the symbols.

If S is a SymbolSlab:
 - `MemIndex(S)` (or `make_unique(S)`) is a MemIndex that doesn't 
know about the storage and doesn't own the symbols
 - `MemIndex::build(move(S))` is a `shared_ptr` that owns the 
storage. It's the `shared_ptr`, not the `MemIndex`, that manages the storage.

So for a static index, you could either hand off the ownership of the slab by 
calling build(), or keep it yourself and call the constructor. The former seems 
more convenient in ClangdMain.

We could write this differently, e.g. as `std::shared_ptr = 
tieStorageToIndex(std::move(S), make_unique(S));`. The API here 
(`MemIndex::build()`) is intended to make common use cases easy, and keep it 
fairly similar to before for migration purposes. Is it too confusing?



Comment at: clangd/index/dex/DexIndex.h:42
+  // All symbols must outlive this index.
+  template  DexIndex(Range &) {
+for (auto & : Symbols)

ioeric wrote:
> sammccall wrote:
> > ioeric wrote:
> > > Why is this constructor needed? I think this could restrict the 
> > > flexibility of DexIndex initialization, in case we need to pass in extra 
> > > parameters here.
> > I'm not sure exactly what you mean here.
> > 
> > We need a way to specify the symbols to be indexed.
> > Because these are now immutable, doing that in the constructor if possible 
> > is best.
> > 
> > Previously this was a vector, but that sometimes required us 
> > to construct that big vector, dereference all those pointers, and throw 
> > away the vector. This signature is strictly more general (if you have a 
> > vector of pointers, you can pass `make_pointee_range`)
> > 
> > > in case we need to pass in extra parameters here.
> > What stops us adding more parameters?
> > What stops us adding more parameters?
> I thought this template was added so that we could use it as a drop-in 
> replacement of `MemIndex` (with the same signature) e.g. in `FileIndex`? I 
> might have overthought though.
> 
> Thanks for the explanation!
Sure, Dex and MemIndex had the same constructor signatures as each other before 
this patch, and they have the same as each other after this patch.

That makes it convenient to use them interchangeably, but there's no hard 
requirement (no construction from templates etc).


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D51422



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


[PATCH] D51543: [Sema] Fix uninitialized OverloadCandidate::FoundDecl member

2018-08-31 Thread Jan Korous via Phabricator via cfe-commits
jkorous created this revision.
jkorous added reviewers: arphaman, vsapsai, dexonsmith, rsmith.
jkorous added a project: clang.
Herald added subscribers: cfe-commits, mgorny.

It's rather error-prone to leave that member variable uninitialized. The 
DeclAccessPair seems to be intentionally POD and it seems the make() method is 
supposed to be called as a constructor.

I take DeclAccessPair interface as given so the only options are to either 
change OverloadCandidate interface or actually initialize the member variable 
it to some sane default. I suggest the easiest option.


Repository:
  rC Clang

https://reviews.llvm.org/D51543

Files:
  Sema/CMakeLists.txt
  Sema/OverloadTest.cpp
  clang/Sema/Overload.h


Index: Sema/OverloadTest.cpp
===
--- /dev/null
+++ Sema/OverloadTest.cpp
@@ -0,0 +1,21 @@
+//=== unittests/Sema/CodeCompleteTest.cpp - Code Complete tests 
==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "clang/Sema/Overload.h"
+#include "gtest/gtest.h"
+
+namespace {
+
+TEST(SemaOverloadTest, FoundDeclIsInitializedInOverloadCandidate) {
+  clang::OverloadCandidate foo;
+  EXPECT_EQ(foo.FoundDecl.getDecl(), nullptr);
+  EXPECT_EQ(foo.FoundDecl.getAccess(), clang::AS_none);
+}
+
+} // namespace
Index: Sema/CMakeLists.txt
===
--- Sema/CMakeLists.txt
+++ Sema/CMakeLists.txt
@@ -5,6 +5,7 @@
 add_clang_unittest(SemaTests
   ExternalSemaSourceTest.cpp
   CodeCompleteTest.cpp
+  OverloadTest.cpp
   )
 
 target_link_libraries(SemaTests
Index: clang/Sema/Overload.h
===
--- clang/Sema/Overload.h
+++ clang/Sema/Overload.h
@@ -728,6 +728,11 @@
 
   /// OverloadCandidate - A single candidate in an overload set (C++ 13.3).
   struct OverloadCandidate {
+
+OverloadCandidate()
+: FoundDecl( DeclAccessPair::make(nullptr, AS_none))
+{ }
+
 /// Function - The actual function that this candidate
 /// represents. When NULL, this is a built-in candidate
 /// (C++ [over.oper]) or a surrogate for a conversion to a


Index: Sema/OverloadTest.cpp
===
--- /dev/null
+++ Sema/OverloadTest.cpp
@@ -0,0 +1,21 @@
+//=== unittests/Sema/CodeCompleteTest.cpp - Code Complete tests ==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "clang/Sema/Overload.h"
+#include "gtest/gtest.h"
+
+namespace {
+
+TEST(SemaOverloadTest, FoundDeclIsInitializedInOverloadCandidate) {
+  clang::OverloadCandidate foo;
+  EXPECT_EQ(foo.FoundDecl.getDecl(), nullptr);
+  EXPECT_EQ(foo.FoundDecl.getAccess(), clang::AS_none);
+}
+
+} // namespace
Index: Sema/CMakeLists.txt
===
--- Sema/CMakeLists.txt
+++ Sema/CMakeLists.txt
@@ -5,6 +5,7 @@
 add_clang_unittest(SemaTests
   ExternalSemaSourceTest.cpp
   CodeCompleteTest.cpp
+  OverloadTest.cpp
   )
 
 target_link_libraries(SemaTests
Index: clang/Sema/Overload.h
===
--- clang/Sema/Overload.h
+++ clang/Sema/Overload.h
@@ -728,6 +728,11 @@
 
   /// OverloadCandidate - A single candidate in an overload set (C++ 13.3).
   struct OverloadCandidate {
+
+OverloadCandidate()
+: FoundDecl( DeclAccessPair::make(nullptr, AS_none))
+{ }
+
 /// Function - The actual function that this candidate
 /// represents. When NULL, this is a built-in candidate
 /// (C++ [over.oper]) or a surrogate for a conversion to a
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D51530: [libunwind] Fix existing code for SEH on ARM to compile correctly

2018-08-31 Thread Martin Storsjö via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL341217: Fix existing code for SEH on ARM to compile 
correctly (authored by mstorsjo, committed by ).
Herald added subscribers: llvm-commits, christof.

Changed prior to commit:
  https://reviews.llvm.org/D51530?vs=163487=163534#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D51530

Files:
  libunwind/trunk/include/__libunwind_config.h
  libunwind/trunk/src/Unwind-seh.cpp
  libunwind/trunk/src/UnwindCursor.hpp


Index: libunwind/trunk/src/Unwind-seh.cpp
===
--- libunwind/trunk/src/Unwind-seh.cpp
+++ libunwind/trunk/src/Unwind-seh.cpp
@@ -164,17 +164,22 @@
 // This should never happen in phase 1.
 if (!IS_UNWINDING(ms_exc->ExceptionFlags))
   _LIBUNWIND_ABORT("Personality installed context during phase 1!");
-exc->private_[2] = disp->TargetIp;
 #ifdef __x86_64__
+exc->private_[2] = disp->TargetIp;
 unw_get_reg(, UNW_X86_64_RAX, );
 unw_get_reg(, UNW_X86_64_RDX, >private_[3]);
 #elif defined(__arm__)
+exc->private_[2] = disp->TargetPc;
 unw_get_reg(, UNW_ARM_R0, );
 unw_get_reg(, UNW_ARM_R1, >private_[3]);
 #endif
 unw_get_reg(, UNW_REG_IP, );
 ms_exc->ExceptionCode = STATUS_GCC_UNWIND;
+#ifdef __x86_64__
 ms_exc->ExceptionInformation[2] = disp->TargetIp;
+#elif defined(__arm__)
+ms_exc->ExceptionInformation[2] = disp->TargetPc;
+#endif
 ms_exc->ExceptionInformation[3] = exc->private_[3];
 // Give NTRTL some scratch space to keep track of the collided unwind.
 // Don't use the one that was passed in; we don't want to overwrite the
Index: libunwind/trunk/src/UnwindCursor.hpp
===
--- libunwind/trunk/src/UnwindCursor.hpp
+++ libunwind/trunk/src/UnwindCursor.hpp
@@ -606,14 +606,14 @@
   _msContext.R12 = r.getRegister(UNW_ARM_R12);
   _msContext.Sp = r.getRegister(UNW_ARM_SP);
   _msContext.Lr = r.getRegister(UNW_ARM_LR);
-  _msContext.Pc = r.getRegister(UNW_ARM_PC);
-  for (int r = UNW_ARM_D0; r <= UNW_ARM_D31; ++r) {
+  _msContext.Pc = r.getRegister(UNW_ARM_IP);
+  for (int i = UNW_ARM_D0; i <= UNW_ARM_D31; ++i) {
 union {
   uint64_t w;
   double d;
 } d;
-d.d = r.getFloatRegister(r);
-_msContext.D[r - UNW_ARM_D0] = d.w;
+d.d = r.getFloatRegister(i);
+_msContext.D[i - UNW_ARM_D0] = d.w;
   }
 #endif
 }
@@ -682,7 +682,7 @@
   case UNW_ARM_SP: return _msContext.Sp;
   case UNW_ARM_LR: return _msContext.Lr;
   case UNW_REG_IP:
-  case UNW_ARM_PC: return _msContext.Pc;
+  case UNW_ARM_IP: return _msContext.Pc;
 #endif
   }
   _LIBUNWIND_ABORT("unsupported register");
@@ -728,7 +728,7 @@
   case UNW_ARM_SP: _msContext.Sp = value; break;
   case UNW_ARM_LR: _msContext.Lr = value; break;
   case UNW_REG_IP:
-  case UNW_ARM_PC: _msContext.Pc = value; break;
+  case UNW_ARM_IP: _msContext.Pc = value; break;
 #endif
   default:
 _LIBUNWIND_ABORT("unsupported register");
@@ -842,7 +842,7 @@
   case UNW_ARM_SP: return "sp";
   case UNW_ARM_LR: return "lr";
   case UNW_REG_IP:
-  case UNW_ARM_PC: return "pc";
+  case UNW_ARM_IP: return "pc";
   case UNW_ARM_S0: return "s0";
   case UNW_ARM_S1: return "s1";
   case UNW_ARM_S2: return "s2";
Index: libunwind/trunk/include/__libunwind_config.h
===
--- libunwind/trunk/include/__libunwind_config.h
+++ libunwind/trunk/include/__libunwind_config.h
@@ -63,7 +63,7 @@
 #  define _LIBUNWIND_TARGET_ARM 1
 #  if defined(__SEH__)
 #define _LIBUNWIND_CONTEXT_SIZE 42
-#define _LIBUNWIND_CURSOR_SIZE 85
+#define _LIBUNWIND_CURSOR_SIZE 80
 #  elif defined(__ARM_WMMX)
 #define _LIBUNWIND_CONTEXT_SIZE 61
 #define _LIBUNWIND_CURSOR_SIZE 68


Index: libunwind/trunk/src/Unwind-seh.cpp
===
--- libunwind/trunk/src/Unwind-seh.cpp
+++ libunwind/trunk/src/Unwind-seh.cpp
@@ -164,17 +164,22 @@
 // This should never happen in phase 1.
 if (!IS_UNWINDING(ms_exc->ExceptionFlags))
   _LIBUNWIND_ABORT("Personality installed context during phase 1!");
-exc->private_[2] = disp->TargetIp;
 #ifdef __x86_64__
+exc->private_[2] = disp->TargetIp;
 unw_get_reg(, UNW_X86_64_RAX, );
 unw_get_reg(, UNW_X86_64_RDX, >private_[3]);
 #elif defined(__arm__)
+exc->private_[2] = disp->TargetPc;
 unw_get_reg(, UNW_ARM_R0, );
 unw_get_reg(, UNW_ARM_R1, >private_[3]);
 #endif
 unw_get_reg(, UNW_REG_IP, );
 ms_exc->ExceptionCode = STATUS_GCC_UNWIND;
+#ifdef __x86_64__
 ms_exc->ExceptionInformation[2] = disp->TargetIp;
+#elif defined(__arm__)
+ms_exc->ExceptionInformation[2] = disp->TargetPc;
+#endif
 ms_exc->ExceptionInformation[3] = exc->private_[3];
 // Give NTRTL some scratch space to keep track of the collided unwind.
 // Don't use the one that was passed in; we don't want to overwrite the

[libunwind] r341217 - Fix existing code for SEH on ARM to compile correctly

2018-08-31 Thread Martin Storsjo via cfe-commits
Author: mstorsjo
Date: Fri Aug 31 07:56:55 2018
New Revision: 341217

URL: http://llvm.org/viewvc/llvm-project?rev=341217=rev
Log:
Fix existing code for SEH on ARM to compile correctly

Even though SEH for ARM is incomplete, make what code already exists
at least compile correctly.

The _LIBUNWIND_CURSOR_SIZE wasn't correct.

ARM (and AArch64) have a DISPATCHER_CONTEXT field named TargetPc
instead of TargetIp.

For the libunwind.h UNW_* constants, there is no UNW_ARM_PC, only
UNW_ARM_IP.

Don't use 'r' as loop variable when 'r' already is a Registers_arm
member.

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

Modified:
libunwind/trunk/include/__libunwind_config.h
libunwind/trunk/src/Unwind-seh.cpp
libunwind/trunk/src/UnwindCursor.hpp

Modified: libunwind/trunk/include/__libunwind_config.h
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/include/__libunwind_config.h?rev=341217=341216=341217=diff
==
--- libunwind/trunk/include/__libunwind_config.h (original)
+++ libunwind/trunk/include/__libunwind_config.h Fri Aug 31 07:56:55 2018
@@ -63,7 +63,7 @@
 #  define _LIBUNWIND_TARGET_ARM 1
 #  if defined(__SEH__)
 #define _LIBUNWIND_CONTEXT_SIZE 42
-#define _LIBUNWIND_CURSOR_SIZE 85
+#define _LIBUNWIND_CURSOR_SIZE 80
 #  elif defined(__ARM_WMMX)
 #define _LIBUNWIND_CONTEXT_SIZE 61
 #define _LIBUNWIND_CURSOR_SIZE 68

Modified: libunwind/trunk/src/Unwind-seh.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/Unwind-seh.cpp?rev=341217=341216=341217=diff
==
--- libunwind/trunk/src/Unwind-seh.cpp (original)
+++ libunwind/trunk/src/Unwind-seh.cpp Fri Aug 31 07:56:55 2018
@@ -164,17 +164,22 @@ _GCC_specific_handler(PEXCEPTION_RECORD
 // This should never happen in phase 1.
 if (!IS_UNWINDING(ms_exc->ExceptionFlags))
   _LIBUNWIND_ABORT("Personality installed context during phase 1!");
-exc->private_[2] = disp->TargetIp;
 #ifdef __x86_64__
+exc->private_[2] = disp->TargetIp;
 unw_get_reg(, UNW_X86_64_RAX, );
 unw_get_reg(, UNW_X86_64_RDX, >private_[3]);
 #elif defined(__arm__)
+exc->private_[2] = disp->TargetPc;
 unw_get_reg(, UNW_ARM_R0, );
 unw_get_reg(, UNW_ARM_R1, >private_[3]);
 #endif
 unw_get_reg(, UNW_REG_IP, );
 ms_exc->ExceptionCode = STATUS_GCC_UNWIND;
+#ifdef __x86_64__
 ms_exc->ExceptionInformation[2] = disp->TargetIp;
+#elif defined(__arm__)
+ms_exc->ExceptionInformation[2] = disp->TargetPc;
+#endif
 ms_exc->ExceptionInformation[3] = exc->private_[3];
 // Give NTRTL some scratch space to keep track of the collided unwind.
 // Don't use the one that was passed in; we don't want to overwrite the

Modified: libunwind/trunk/src/UnwindCursor.hpp
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/UnwindCursor.hpp?rev=341217=341216=341217=diff
==
--- libunwind/trunk/src/UnwindCursor.hpp (original)
+++ libunwind/trunk/src/UnwindCursor.hpp Fri Aug 31 07:56:55 2018
@@ -606,14 +606,14 @@ UnwindCursor::UnwindCursor(unw_con
   _msContext.R12 = r.getRegister(UNW_ARM_R12);
   _msContext.Sp = r.getRegister(UNW_ARM_SP);
   _msContext.Lr = r.getRegister(UNW_ARM_LR);
-  _msContext.Pc = r.getRegister(UNW_ARM_PC);
-  for (int r = UNW_ARM_D0; r <= UNW_ARM_D31; ++r) {
+  _msContext.Pc = r.getRegister(UNW_ARM_IP);
+  for (int i = UNW_ARM_D0; i <= UNW_ARM_D31; ++i) {
 union {
   uint64_t w;
   double d;
 } d;
-d.d = r.getFloatRegister(r);
-_msContext.D[r - UNW_ARM_D0] = d.w;
+d.d = r.getFloatRegister(i);
+_msContext.D[i - UNW_ARM_D0] = d.w;
   }
 #endif
 }
@@ -682,7 +682,7 @@ unw_word_t UnwindCursor::getReg(in
   case UNW_ARM_SP: return _msContext.Sp;
   case UNW_ARM_LR: return _msContext.Lr;
   case UNW_REG_IP:
-  case UNW_ARM_PC: return _msContext.Pc;
+  case UNW_ARM_IP: return _msContext.Pc;
 #endif
   }
   _LIBUNWIND_ABORT("unsupported register");
@@ -728,7 +728,7 @@ void UnwindCursor::setReg(int regN
   case UNW_ARM_SP: _msContext.Sp = value; break;
   case UNW_ARM_LR: _msContext.Lr = value; break;
   case UNW_REG_IP:
-  case UNW_ARM_PC: _msContext.Pc = value; break;
+  case UNW_ARM_IP: _msContext.Pc = value; break;
 #endif
   default:
 _LIBUNWIND_ABORT("unsupported register");
@@ -842,7 +842,7 @@ const char *UnwindCursor::getRegis
   case UNW_ARM_SP: return "sp";
   case UNW_ARM_LR: return "lr";
   case UNW_REG_IP:
-  case UNW_ARM_PC: return "pc";
+  case UNW_ARM_IP: return "pc";
   case UNW_ARM_S0: return "s0";
   case UNW_ARM_S1: return "s1";
   case UNW_ARM_S2: return "s2";


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


[PATCH] D51279: [clangd] Implement findOccurrences interface in dynamic index.

2018-08-31 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: unittests/clangd/TestTU.h:41
 
+  static TestTU withAllCode(llvm::StringRef HeaderCode, llvm::StringRef Code,
+llvm::StringRef Filename = "") {

hokein wrote:
> sammccall wrote:
> > We've avoided adding this in the past because it's less readable. Please 
> > assign the fields separately instead.
> I'm tempted to keep it here, while it's less readable, it does more things, 
> and can make client code more readable (see newly-added tests), otherwise we 
> have to repeat these statements in a few places.
That's what I mean, I find the newly-added tests hard to read, because 
"allcode" isn't clear (particularly when one of the params is a filename) and 
the order of parameters is not obvious.
I think they would be much clearer with the fields assigned individually as the 
existing tests do.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D51279



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


[PATCH] D51333: Diagnose likely typos in include statements

2018-08-31 Thread Christy Lee via Phabricator via cfe-commits
christylee marked 2 inline comments as done.
christylee added a comment.

In https://reviews.llvm.org/D51333#1219938, @rsmith wrote:

> Instead of guessing whether the corrected filename would be valid, why not 
> strip off the leading and trailing non-alphanumeric characters, look up the 
> resulting filename, and find out? If we did that, then not only could we be a 
> lot more confident that we'd found the file that was intended, but we could 
> also recover from the error by including the trimmed filename.


Should we lookup the stripped filename and then error out on a warning along 
the lines of "'' file not found, did you mean 'hello,h'",  or attempt 
to continue to compile using the file we found (i.e. "hello.h").  I'm learning 
towards the former because I'm worried the latter might be "too clever", in 
case the developers actually think  and hello.h are two different 
files.


https://reviews.llvm.org/D51333



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


[PATCH] D51422: [clangd] Factor out the data-swapping functionality from MemIndex/DexIndex.

2018-08-31 Thread Eric Liu via Phabricator via cfe-commits
ioeric added inline comments.



Comment at: clangd/index/MemIndex.h:30
+  /// Builds an index from a slab. The shared_ptr manages the slab's lifetime.
+  static std::shared_ptr build(SymbolSlab Slab);
 

sammccall wrote:
> ioeric wrote:
> > (It's a bit unfortunate that this has to return `shared_ptr` now)
> Since some of the resources it owns has a shared lifetime, this is really 
> just reflecting reality I think. Whether that's visible or invisible seems 
> like a wash to me.
This is only true when this is used with `SwapIndex` right? For example, a 
static Dex/Mem index would probbaly have `unique_ptr` ownership.



Comment at: clangd/index/dex/DexIndex.h:42
+  // All symbols must outlive this index.
+  template  DexIndex(Range &) {
+for (auto & : Symbols)

sammccall wrote:
> ioeric wrote:
> > Why is this constructor needed? I think this could restrict the flexibility 
> > of DexIndex initialization, in case we need to pass in extra parameters 
> > here.
> I'm not sure exactly what you mean here.
> 
> We need a way to specify the symbols to be indexed.
> Because these are now immutable, doing that in the constructor if possible is 
> best.
> 
> Previously this was a vector, but that sometimes required us 
> to construct that big vector, dereference all those pointers, and throw away 
> the vector. This signature is strictly more general (if you have a vector of 
> pointers, you can pass `make_pointee_range`)
> 
> > in case we need to pass in extra parameters here.
> What stops us adding more parameters?
> What stops us adding more parameters?
I thought this template was added so that we could use it as a drop-in 
replacement of `MemIndex` (with the same signature) e.g. in `FileIndex`? I 
might have overthought though.

Thanks for the explanation!


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D51422



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


[PATCH] D51279: [clangd] Implement findOccurrences interface in dynamic index.

2018-08-31 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 163532.
hokein added a comment.

Minor cleanup.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D51279

Files:
  clangd/index/FileIndex.cpp
  clangd/index/FileIndex.h
  clangd/index/Index.h
  clangd/index/MemIndex.cpp
  clangd/index/MemIndex.h
  clangd/index/Merge.cpp
  clangd/index/Merge.h
  unittests/clangd/FileIndexTests.cpp
  unittests/clangd/IndexTests.cpp
  unittests/clangd/TestTU.cpp
  unittests/clangd/TestTU.h

Index: unittests/clangd/TestTU.h
===
--- unittests/clangd/TestTU.h
+++ unittests/clangd/TestTU.h
@@ -38,6 +38,16 @@
 return TU;
   }
 
+  static TestTU withAllCode(llvm::StringRef HeaderCode, llvm::StringRef Code,
+llvm::StringRef Filename) {
+TestTU TU;
+TU.HeaderCode = HeaderCode;
+TU.Code = Code;
+if (!Filename.empty())
+  TU.Filename = Filename;
+return TU;
+  }
+
   // The code to be compiled.
   std::string Code;
   std::string Filename = "TestTU.cpp";
Index: unittests/clangd/TestTU.cpp
===
--- unittests/clangd/TestTU.cpp
+++ unittests/clangd/TestTU.cpp
@@ -45,7 +45,7 @@
 
 SymbolSlab TestTU::headerSymbols() const {
   auto AST = build();
-  return indexAST(AST.getASTContext(), AST.getPreprocessorPtr());
+  return indexAST(AST.getASTContext(), AST.getPreprocessorPtr()).first;
 }
 
 std::unique_ptr TestTU::index() const {
Index: unittests/clangd/IndexTests.cpp
===
--- unittests/clangd/IndexTests.cpp
+++ unittests/clangd/IndexTests.cpp
@@ -7,21 +7,36 @@
 //
 //===--===//
 
+#include "Annotations.h"
 #include "TestIndex.h"
+#include "TestTU.h"
+#include "gmock/gmock.h"
+#include "index/FileIndex.h"
 #include "index/Index.h"
 #include "index/MemIndex.h"
 #include "index/Merge.h"
-#include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
 using testing::Pointee;
 using testing::UnorderedElementsAre;
+using testing::AllOf;
 
 namespace clang {
 namespace clangd {
 namespace {
 
+std::shared_ptr emptyOccurrences() {
+  return llvm::make_unique();
+}
+
 MATCHER_P(Named, N, "") { return arg.Name == N; }
+MATCHER_P(OccurrenceRange, Range, "") {
+  return std::tie(arg.Location.Start.Line, arg.Location.Start.Column,
+  arg.Location.End.Line, arg.Location.End.Column) ==
+ std::tie(Range.start.line, Range.start.character, Range.end.line,
+  Range.end.character);
+}
+MATCHER_P(FileURI, F, "") { return arg.Location.FileURI == F; }
 
 TEST(SymbolSlab, FindAndIterate) {
   SymbolSlab::Builder B;
@@ -42,14 +57,14 @@
 TEST(MemIndexTest, MemIndexSymbolsRecycled) {
   MemIndex I;
   std::weak_ptr Symbols;
-  I.build(generateNumSymbols(0, 10, ));
+  I.build(generateNumSymbols(0, 10, ), emptyOccurrences());
   FuzzyFindRequest Req;
   Req.Query = "7";
   EXPECT_THAT(match(I, Req), UnorderedElementsAre("7"));
 
   EXPECT_FALSE(Symbols.expired());
   // Release old symbols.
-  I.build(generateNumSymbols(0, 0));
+  I.build(generateNumSymbols(0, 0), emptyOccurrences());
   EXPECT_TRUE(Symbols.expired());
 }
 
@@ -65,14 +80,14 @@
   FuzzyFindRequest Req;
   Req.Query = "7";
   MemIndex I;
-  I.build(std::move(Symbols));
+  I.build(std::move(Symbols), emptyOccurrences());
   auto Matches = match(I, Req);
   EXPECT_EQ(Matches.size(), 1u);
 }
 
 TEST(MemIndexTest, MemIndexLimitedNumMatches) {
   MemIndex I;
-  I.build(generateNumSymbols(0, 100));
+  I.build(generateNumSymbols(0, 100), emptyOccurrences());
   FuzzyFindRequest Req;
   Req.Query = "5";
   Req.MaxCandidateCount = 3;
@@ -85,7 +100,8 @@
 TEST(MemIndexTest, FuzzyMatch) {
   MemIndex I;
   I.build(
-  generateSymbols({"LaughingOutLoud", "LionPopulation", "LittleOldLady"}));
+  generateSymbols({"LaughingOutLoud", "LionPopulation", "LittleOldLady"}),
+  emptyOccurrences());
   FuzzyFindRequest Req;
   Req.Query = "lol";
   Req.MaxCandidateCount = 2;
@@ -95,60 +111,62 @@
 
 TEST(MemIndexTest, MatchQualifiedNamesWithoutSpecificScope) {
   MemIndex I;
-  I.build(generateSymbols({"a::y1", "b::y2", "y3"}));
+  I.build(generateSymbols({"a::y1", "b::y2", "y3"}), emptyOccurrences());
   FuzzyFindRequest Req;
   Req.Query = "y";
   EXPECT_THAT(match(I, Req), UnorderedElementsAre("a::y1", "b::y2", "y3"));
 }
 
 TEST(MemIndexTest, MatchQualifiedNamesWithGlobalScope) {
   MemIndex I;
-  I.build(generateSymbols({"a::y1", "b::y2", "y3"}));
+  I.build(generateSymbols({"a::y1", "b::y2", "y3"}), emptyOccurrences());
   FuzzyFindRequest Req;
   Req.Query = "y";
   Req.Scopes = {""};
   EXPECT_THAT(match(I, Req), UnorderedElementsAre("y3"));
 }
 
 TEST(MemIndexTest, MatchQualifiedNamesWithOneScope) {
   MemIndex I;
-  I.build(generateSymbols({"a::y1", "a::y2", "a::x", "b::y2", "y3"}));
+  I.build(generateSymbols({"a::y1", "a::y2", "a::x", "b::y2", "y3"}),
+  

[PATCH] D51279: [clangd] Implement findOccurrences interface in dynamic index.

2018-08-31 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clangd/index/MemIndex.cpp:35
 
 std::unique_ptr MemIndex::build(SymbolSlab Slab) {
   auto Idx = llvm::make_unique();

sammccall wrote:
> This is still implicitly creating an index with no occurrences. Did you mean 
> to accept a SymbolOccurrencesSlab here?
This is intended, this function only cares about symbol, no occurrences.



Comment at: unittests/clangd/TestTU.h:41
 
+  static TestTU withAllCode(llvm::StringRef HeaderCode, llvm::StringRef Code,
+llvm::StringRef Filename = "") {

sammccall wrote:
> We've avoided adding this in the past because it's less readable. Please 
> assign the fields separately instead.
I'm tempted to keep it here, while it's less readable, it does more things, and 
can make client code more readable (see newly-added tests), otherwise we have 
to repeat these statements in a few places.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D51279



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


[PATCH] D51279: [clangd] Implement findOccurrences interface in dynamic index.

2018-08-31 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 163531.
hokein marked 4 inline comments as done.
hokein added a comment.

- rebase
- address review comments


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D51279

Files:
  clangd/index/FileIndex.cpp
  clangd/index/FileIndex.h
  clangd/index/Index.cpp
  clangd/index/Index.h
  clangd/index/MemIndex.cpp
  clangd/index/MemIndex.h
  clangd/index/Merge.cpp
  clangd/index/Merge.h
  unittests/clangd/FileIndexTests.cpp
  unittests/clangd/IndexTests.cpp
  unittests/clangd/TestTU.cpp
  unittests/clangd/TestTU.h

Index: unittests/clangd/TestTU.h
===
--- unittests/clangd/TestTU.h
+++ unittests/clangd/TestTU.h
@@ -38,6 +38,16 @@
 return TU;
   }
 
+  static TestTU withAllCode(llvm::StringRef HeaderCode, llvm::StringRef Code,
+llvm::StringRef Filename) {
+TestTU TU;
+TU.HeaderCode = HeaderCode;
+TU.Code = Code;
+if (!Filename.empty())
+  TU.Filename = Filename;
+return TU;
+  }
+
   // The code to be compiled.
   std::string Code;
   std::string Filename = "TestTU.cpp";
Index: unittests/clangd/TestTU.cpp
===
--- unittests/clangd/TestTU.cpp
+++ unittests/clangd/TestTU.cpp
@@ -45,7 +45,7 @@
 
 SymbolSlab TestTU::headerSymbols() const {
   auto AST = build();
-  return indexAST(AST.getASTContext(), AST.getPreprocessorPtr());
+  return indexAST(AST.getASTContext(), AST.getPreprocessorPtr()).first;
 }
 
 std::unique_ptr TestTU::index() const {
Index: unittests/clangd/IndexTests.cpp
===
--- unittests/clangd/IndexTests.cpp
+++ unittests/clangd/IndexTests.cpp
@@ -7,21 +7,36 @@
 //
 //===--===//
 
+#include "Annotations.h"
 #include "TestIndex.h"
+#include "TestTU.h"
+#include "gmock/gmock.h"
+#include "index/FileIndex.h"
 #include "index/Index.h"
 #include "index/MemIndex.h"
 #include "index/Merge.h"
-#include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
 using testing::Pointee;
 using testing::UnorderedElementsAre;
+using testing::AllOf;
 
 namespace clang {
 namespace clangd {
 namespace {
 
+std::shared_ptr emptyOccurrences() {
+  return llvm::make_unique();
+}
+
 MATCHER_P(Named, N, "") { return arg.Name == N; }
+MATCHER_P(OccurrenceRange, Range, "") {
+  return std::tie(arg.Location.Start.Line, arg.Location.Start.Column,
+  arg.Location.End.Line, arg.Location.End.Column) ==
+ std::tie(Range.start.line, Range.start.character, Range.end.line,
+  Range.end.character);
+}
+MATCHER_P(FileURI, F, "") { return arg.Location.FileURI == F; }
 
 TEST(SymbolSlab, FindAndIterate) {
   SymbolSlab::Builder B;
@@ -42,14 +57,14 @@
 TEST(MemIndexTest, MemIndexSymbolsRecycled) {
   MemIndex I;
   std::weak_ptr Symbols;
-  I.build(generateNumSymbols(0, 10, ));
+  I.build(generateNumSymbols(0, 10, ), emptyOccurrences());
   FuzzyFindRequest Req;
   Req.Query = "7";
   EXPECT_THAT(match(I, Req), UnorderedElementsAre("7"));
 
   EXPECT_FALSE(Symbols.expired());
   // Release old symbols.
-  I.build(generateNumSymbols(0, 0));
+  I.build(generateNumSymbols(0, 0), emptyOccurrences());
   EXPECT_TRUE(Symbols.expired());
 }
 
@@ -65,14 +80,14 @@
   FuzzyFindRequest Req;
   Req.Query = "7";
   MemIndex I;
-  I.build(std::move(Symbols));
+  I.build(std::move(Symbols), emptyOccurrences());
   auto Matches = match(I, Req);
   EXPECT_EQ(Matches.size(), 1u);
 }
 
 TEST(MemIndexTest, MemIndexLimitedNumMatches) {
   MemIndex I;
-  I.build(generateNumSymbols(0, 100));
+  I.build(generateNumSymbols(0, 100), emptyOccurrences());
   FuzzyFindRequest Req;
   Req.Query = "5";
   Req.MaxCandidateCount = 3;
@@ -85,7 +100,8 @@
 TEST(MemIndexTest, FuzzyMatch) {
   MemIndex I;
   I.build(
-  generateSymbols({"LaughingOutLoud", "LionPopulation", "LittleOldLady"}));
+  generateSymbols({"LaughingOutLoud", "LionPopulation", "LittleOldLady"}),
+  emptyOccurrences());
   FuzzyFindRequest Req;
   Req.Query = "lol";
   Req.MaxCandidateCount = 2;
@@ -95,60 +111,62 @@
 
 TEST(MemIndexTest, MatchQualifiedNamesWithoutSpecificScope) {
   MemIndex I;
-  I.build(generateSymbols({"a::y1", "b::y2", "y3"}));
+  I.build(generateSymbols({"a::y1", "b::y2", "y3"}), emptyOccurrences());
   FuzzyFindRequest Req;
   Req.Query = "y";
   EXPECT_THAT(match(I, Req), UnorderedElementsAre("a::y1", "b::y2", "y3"));
 }
 
 TEST(MemIndexTest, MatchQualifiedNamesWithGlobalScope) {
   MemIndex I;
-  I.build(generateSymbols({"a::y1", "b::y2", "y3"}));
+  I.build(generateSymbols({"a::y1", "b::y2", "y3"}), emptyOccurrences());
   FuzzyFindRequest Req;
   Req.Query = "y";
   Req.Scopes = {""};
   EXPECT_THAT(match(I, Req), UnorderedElementsAre("y3"));
 }
 
 TEST(MemIndexTest, MatchQualifiedNamesWithOneScope) {
   MemIndex I;
-  I.build(generateSymbols({"a::y1", "a::y2", "a::x", "b::y2", 

[PATCH] D51177: [DEBUGINFO] Add support for emission of the debug directives only.

2018-08-31 Thread Alexey Bataev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL341212: [DEBUGINFO] Add support for emission of the debug 
directives only. (authored by ABataev, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D51177

Files:
  cfe/trunk/include/clang/Basic/DebugInfoOptions.h
  cfe/trunk/include/clang/Driver/Options.td
  cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
  cfe/trunk/lib/Driver/ToolChains/Clang.cpp
  cfe/trunk/lib/Frontend/CompilerInvocation.cpp
  cfe/trunk/test/CodeGen/debug-info-gline-tables-only.c
  cfe/trunk/test/CodeGen/debug-info-gline-tables-only2.c
  cfe/trunk/test/CodeGen/debug-info-line.c
  cfe/trunk/test/CodeGen/debug-info-macro.c
  cfe/trunk/test/CodeGen/debug-info-scope.c
  cfe/trunk/test/CodeGen/lifetime-debuginfo-1.c
  cfe/trunk/test/CodeGen/lifetime-debuginfo-2.c
  cfe/trunk/test/CodeGenCXX/crash.cpp
  cfe/trunk/test/CodeGenCXX/debug-info-blocks.cpp
  cfe/trunk/test/CodeGenCXX/debug-info-gline-tables-only.cpp
  cfe/trunk/test/CodeGenCXX/debug-info-line.cpp
  cfe/trunk/test/CodeGenCXX/debug-info-ms-dtor-thunks.cpp
  cfe/trunk/test/CodeGenCXX/debug-info-namespace.cpp
  cfe/trunk/test/CodeGenCXX/debug-info-template-explicit-specialization.cpp
  cfe/trunk/test/CodeGenCXX/debug-info-windows-dtor.cpp
  cfe/trunk/test/CodeGenCXX/linetable-virtual-variadic.cpp
  cfe/trunk/test/CodeGenObjCXX/debug-info-line.mm
  cfe/trunk/test/CodeGenObjCXX/pr14474-gline-tables-only.mm
  cfe/trunk/test/Driver/debug-options.c

Index: cfe/trunk/include/clang/Basic/DebugInfoOptions.h
===
--- cfe/trunk/include/clang/Basic/DebugInfoOptions.h
+++ cfe/trunk/include/clang/Basic/DebugInfoOptions.h
@@ -21,6 +21,7 @@
/// locations for instructions without actually
/// emitting debug info for them (e.g., when -Rpass
/// is used).
+  DebugDirectivesOnly, /// Emit only debug directives with the line numbers data
   DebugLineTablesOnly, /// Emit only debug info necessary for generating
/// line number tables (-gline-tables-only).
   LimitedDebugInfo,/// Limit generated debug info to reduce size
Index: cfe/trunk/include/clang/Driver/Options.td
===
--- cfe/trunk/include/clang/Driver/Options.td
+++ cfe/trunk/include/clang/Driver/Options.td
@@ -1777,6 +1777,8 @@
   HelpText<"Generate source-level debug information">;
 def gline_tables_only : Flag<["-"], "gline-tables-only">, Group,
   Flags<[CoreOption]>, HelpText<"Emit debug line number tables only">;
+def gline_directives_only : Flag<["-"], "gline-directives-only">, Group,
+  Flags<[CoreOption]>, HelpText<"Emit debug line info directives only">;
 def gmlt : Flag<["-"], "gmlt">, Alias;
 def g0 : Flag<["-"], "g0">, Group;
 def g1 : Flag<["-"], "g1">, Group, Alias;
Index: cfe/trunk/test/CodeGen/debug-info-line.c
===
--- cfe/trunk/test/CodeGen/debug-info-line.c
+++ cfe/trunk/test/CodeGen/debug-info-line.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -w -debug-info-kind=line-tables-only -fexceptions -fcxx-exceptions -S -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -w -debug-info-kind=line-directives-only -fexceptions -fcxx-exceptions -S -emit-llvm %s -o - | FileCheck %s
 
 int f1(int a, int b) {
   // CHECK: icmp {{.*}}, !dbg [[DBG_F1:!.*]]
Index: cfe/trunk/test/CodeGen/debug-info-gline-tables-only.c
===
--- cfe/trunk/test/CodeGen/debug-info-gline-tables-only.c
+++ cfe/trunk/test/CodeGen/debug-info-gline-tables-only.c
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 %s -debug-info-kind=line-tables-only -S -emit-llvm -o - | FileCheck %s
-// Checks that clang with "-gline-tables-only" doesn't emit debug info
+// RUN: %clang_cc1 %s -debug-info-kind=line-directives-only -S -emit-llvm -o - | FileCheck %s
+// Checks that clang with "-gline-tables-only" or "-gline-directives-only" doesn't emit debug info
 // for variables and types.
 
 // CHECK-NOT: DW_TAG_variable
Index: cfe/trunk/test/CodeGen/lifetime-debuginfo-2.c
===
--- cfe/trunk/test/CodeGen/lifetime-debuginfo-2.c
+++ cfe/trunk/test/CodeGen/lifetime-debuginfo-2.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -O1 -triple x86_64-none-linux-gnu -emit-llvm -debug-info-kind=line-tables-only %s -o - | FileCheck %s
+// RUN: %clang_cc1 -O1 -triple x86_64-none-linux-gnu -emit-llvm -debug-info-kind=line-directives-only %s -o - | FileCheck %s
 
 // Inserting lifetime markers should not affect debuginfo: lifetime.end is not
 // a destructor, but instrumentation for the compiler. Ensure the debug info for
Index: cfe/trunk/test/CodeGen/lifetime-debuginfo-1.c
===
--- cfe/trunk/test/CodeGen/lifetime-debuginfo-1.c

r341212 - [DEBUGINFO] Add support for emission of the debug directives only.

2018-08-31 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Fri Aug 31 06:56:14 2018
New Revision: 341212

URL: http://llvm.org/viewvc/llvm-project?rev=341212=rev
Log:
[DEBUGINFO] Add support for emission of the debug directives only.

Summary:
Added option -gline-directives-only to support emission of the debug directives
only. It behaves very similar to -gline-tables-only, except that it sets
llvm debug info emission kind to
llvm::DICompileUnit::DebugDirectivesOnly.

Reviewers: echristo

Subscribers: aprantl, fedor.sergeev, JDevlieghere, cfe-commits

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

Modified:
cfe/trunk/include/clang/Basic/DebugInfoOptions.h
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/test/CodeGen/debug-info-gline-tables-only.c
cfe/trunk/test/CodeGen/debug-info-gline-tables-only2.c
cfe/trunk/test/CodeGen/debug-info-line.c
cfe/trunk/test/CodeGen/debug-info-macro.c
cfe/trunk/test/CodeGen/debug-info-scope.c
cfe/trunk/test/CodeGen/lifetime-debuginfo-1.c
cfe/trunk/test/CodeGen/lifetime-debuginfo-2.c
cfe/trunk/test/CodeGenCXX/crash.cpp
cfe/trunk/test/CodeGenCXX/debug-info-blocks.cpp
cfe/trunk/test/CodeGenCXX/debug-info-gline-tables-only.cpp
cfe/trunk/test/CodeGenCXX/debug-info-line.cpp
cfe/trunk/test/CodeGenCXX/debug-info-ms-dtor-thunks.cpp
cfe/trunk/test/CodeGenCXX/debug-info-namespace.cpp
cfe/trunk/test/CodeGenCXX/debug-info-template-explicit-specialization.cpp
cfe/trunk/test/CodeGenCXX/debug-info-windows-dtor.cpp
cfe/trunk/test/CodeGenCXX/linetable-virtual-variadic.cpp
cfe/trunk/test/CodeGenObjCXX/debug-info-line.mm
cfe/trunk/test/CodeGenObjCXX/pr14474-gline-tables-only.mm
cfe/trunk/test/Driver/debug-options.c

Modified: cfe/trunk/include/clang/Basic/DebugInfoOptions.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DebugInfoOptions.h?rev=341212=341211=341212=diff
==
--- cfe/trunk/include/clang/Basic/DebugInfoOptions.h (original)
+++ cfe/trunk/include/clang/Basic/DebugInfoOptions.h Fri Aug 31 06:56:14 2018
@@ -21,6 +21,7 @@ enum DebugInfoKind {
/// locations for instructions without actually
/// emitting debug info for them (e.g., when -Rpass
/// is used).
+  DebugDirectivesOnly, /// Emit only debug directives with the line numbers 
data
   DebugLineTablesOnly, /// Emit only debug info necessary for generating
/// line number tables (-gline-tables-only).
   LimitedDebugInfo,/// Limit generated debug info to reduce size

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=341212=341211=341212=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Fri Aug 31 06:56:14 2018
@@ -1777,6 +1777,8 @@ def g_Flag : Flag<["-"], "g">, Group;
 def gline_tables_only : Flag<["-"], "gline-tables-only">, Group,
   Flags<[CoreOption]>, HelpText<"Emit debug line number tables only">;
+def gline_directives_only : Flag<["-"], "gline-directives-only">, 
Group,
+  Flags<[CoreOption]>, HelpText<"Emit debug line info directives only">;
 def gmlt : Flag<["-"], "gmlt">, Alias;
 def g0 : Flag<["-"], "g0">, Group;
 def g1 : Flag<["-"], "g1">, Group, Alias;

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=341212=341211=341212=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Fri Aug 31 06:56:14 2018
@@ -557,6 +557,9 @@ void CGDebugInfo::CreateCompileUnit() {
   case codegenoptions::DebugLineTablesOnly:
 EmissionKind = llvm::DICompileUnit::LineTablesOnly;
 break;
+  case codegenoptions::DebugDirectivesOnly:
+EmissionKind = llvm::DICompileUnit::DebugDirectivesOnly;
+break;
   case codegenoptions::LimitedDebugInfo:
   case codegenoptions::FullDebugInfo:
 EmissionKind = llvm::DICompileUnit::FullDebug;

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=341212=341211=341212=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Fri Aug 31 06:56:14 2018
@@ -493,6 +493,8 @@ static codegenoptions::DebugInfoKind Deb
   if (A.getOption().matches(options::OPT_gline_tables_only) ||
   A.getOption().matches(options::OPT_ggdb1))
 return codegenoptions::DebugLineTablesOnly;
+  

[PATCH] D51508: Export public functions implemented in assembly on Windows.

2018-08-31 Thread Charles Davis via Phabricator via cfe-commits
cdavis5x added inline comments.



Comment at: src/assembly.h:76-78
+  .section .drectve,"yn" SEPARATOR\
+  .ascii "-export:", #name, "\0" SEPARATOR\
+  .text

rnk wrote:
> Maybe .pushsection / .popsection is better than assuming you were in .text.
I initially wanted to do that, but those directives aren't supported by COFF. 
Neither, by the way, is `.previous`. Perhaps this needs to be fixed in LLVM.


Repository:
  rUNW libunwind

https://reviews.llvm.org/D51508



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


[clang-tools-extra] r341211 - [clangd] Flatten out Symbol::Details. It was ill-conceived, sorry.

2018-08-31 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Fri Aug 31 06:55:01 2018
New Revision: 341211

URL: http://llvm.org/viewvc/llvm-project?rev=341211=rev
Log:
[clangd] Flatten out Symbol::Details. It was ill-conceived, sorry.

Reviewers: ioeric

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

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

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

clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
clang-tools-extra/trunk/clangd/index/Index.cpp
clang-tools-extra/trunk/clangd/index/Index.h
clang-tools-extra/trunk/clangd/index/Merge.cpp
clang-tools-extra/trunk/clangd/index/Merge.h
clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp
clang-tools-extra/trunk/clangd/index/SymbolYAML.h
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp
clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp
clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp

Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=341211=341210=341211=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Fri Aug 31 06:55:01 2018
@@ -285,8 +285,7 @@ struct CompletionCandidate {
   }
 
   llvm::Optional headerToInsertIfNotPresent() const {
-if (!IndexResult || !IndexResult->Detail ||
-IndexResult->Detail->IncludeHeader.empty())
+if (!IndexResult || IndexResult->IncludeHeader.empty())
   return llvm::None;
 if (SemaResult && SemaResult->Declaration) {
   // Avoid inserting new #include if the declaration is found in the 
current
@@ -296,7 +295,7 @@ struct CompletionCandidate {
 if (SM.isInMainFile(SM.getExpansionLoc(RD->getBeginLoc(
   return llvm::None;
 }
-return IndexResult->Detail->IncludeHeader;
+return IndexResult->IncludeHeader;
   }
 
   using Bundle = llvm::SmallVector;
@@ -382,7 +381,7 @@ struct CodeCompletionBuilder {
 log("Failed to generate include insertion edits for adding header "
 "(FileURI='{0}', IncludeHeader='{1}') into {2}",
 C.IndexResult->CanonicalDeclaration.FileURI,
-C.IndexResult->Detail->IncludeHeader, FileName);
+C.IndexResult->IncludeHeader, FileName);
 }
   }
 
@@ -397,12 +396,11 @@ struct CodeCompletionBuilder {
 } else if (C.IndexResult) {
   S.Signature = C.IndexResult->Signature;
   S.SnippetSuffix = C.IndexResult->CompletionSnippetSuffix;
-  if (auto *D = C.IndexResult->Detail)
-S.ReturnType = D->ReturnType;
+  S.ReturnType = C.IndexResult->ReturnType;
 }
 if (ExtractDocumentation && Completion.Documentation.empty()) {
-  if (C.IndexResult && C.IndexResult->Detail)
-Completion.Documentation = C.IndexResult->Detail->Documentation;
+  if (C.IndexResult)
+Completion.Documentation = C.IndexResult->Documentation;
   else if (C.SemaResult)
 Completion.Documentation = getDocComment(ASTCtx, *C.SemaResult,
  /*CommentsFromHeader=*/false);
@@ -846,9 +844,8 @@ public:
 IndexRequest.IDs.insert(*S.IDForDoc);
   }
   Index->lookup(IndexRequest, [&](const Symbol ) {
-if (!S.Detail || S.Detail->Documentation.empty())
-  return;
-FetchedDocs[S.ID] = S.Detail->Documentation;
+if (!S.Documentation.empty())
+  FetchedDocs[S.ID] = S.Documentation;
   });
   log("SigHelp: requested docs for {0} symbols from the index, got {1} "
   "symbols with non-empty docs in the response",

Modified: 
clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp?rev=341211=341210=341211=diff
==
--- 
clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
 (original)
+++ 
clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
 Fri Aug 31 06:55:01 2018
@@ -160,17 +160,14 @@ public:
 
   SymbolSlab mergeResults() override {
 SymbolSlab::Builder UniqueSymbols;
-llvm::BumpPtrAllocator Arena;
-Symbol::Details Scratch;
 Executor.getToolResults()->forEachResult(
 [&](llvm::StringRef Key, llvm::StringRef Value) {
-  Arena.Reset();
-  llvm::yaml::Input Yin(Value, );
-  auto Sym = clang::clangd::SymbolFromYAML(Yin, Arena);
+  llvm::yaml::Input Yin(Value);
+  auto Sym = clang::clangd::SymbolFromYAML(Yin);
 

[PATCH] D51504: [clangd] Flatten out Symbol::Details. It was ill-conceived, sorry.

2018-08-31 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL341211: [clangd] Flatten out Symbol::Details. It was 
ill-conceived, sorry. (authored by sammccall, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D51504

Files:
  clang-tools-extra/trunk/clangd/CodeComplete.cpp
  
clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
  clang-tools-extra/trunk/clangd/index/Index.cpp
  clang-tools-extra/trunk/clangd/index/Index.h
  clang-tools-extra/trunk/clangd/index/Merge.cpp
  clang-tools-extra/trunk/clangd/index/Merge.h
  clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
  clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp
  clang-tools-extra/trunk/clangd/index/SymbolYAML.h
  clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
  clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp
  clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp
  clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp

Index: clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp
===
--- clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp
+++ clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp
@@ -177,7 +177,7 @@
   Req.Query = "";
   bool SeenSymbol = false;
   M.fuzzyFind(Req, [&](const Symbol ) {
-EXPECT_TRUE(Sym.Detail->IncludeHeader.empty());
+EXPECT_TRUE(Sym.IncludeHeader.empty());
 SeenSymbol = true;
   });
   EXPECT_TRUE(SeenSymbol);
Index: clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp
===
--- clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp
+++ clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp
@@ -198,46 +198,37 @@
   R.References = 2;
   L.Signature = "()";   // present in left only
   R.CompletionSnippetSuffix = "{$1:0}"; // present in right only
-  Symbol::Details DetL, DetR;
-  DetL.ReturnType = "DetL";
-  DetR.ReturnType = "DetR";
-  DetR.Documentation = "--doc--";
-  L.Detail = 
-  R.Detail = 
+  R.Documentation = "--doc--";
   L.Origin = SymbolOrigin::Dynamic;
   R.Origin = SymbolOrigin::Static;
 
-  Symbol::Details Scratch;
-  Symbol M = mergeSymbol(L, R, );
+  Symbol M = mergeSymbol(L, R);
   EXPECT_EQ(M.Name, "Foo");
   EXPECT_EQ(M.CanonicalDeclaration.FileURI, "file:///left.h");
   EXPECT_EQ(M.References, 3u);
   EXPECT_EQ(M.Signature, "()");
   EXPECT_EQ(M.CompletionSnippetSuffix, "{$1:0}");
-  ASSERT_TRUE(M.Detail);
-  EXPECT_EQ(M.Detail->ReturnType, "DetL");
-  EXPECT_EQ(M.Detail->Documentation, "--doc--");
+  EXPECT_EQ(M.Documentation, "--doc--");
   EXPECT_EQ(M.Origin,
 SymbolOrigin::Dynamic | SymbolOrigin::Static | SymbolOrigin::Merge);
 }
 
 TEST(MergeTest, PreferSymbolWithDefn) {
   Symbol L, R;
-  Symbol::Details Scratch;
 
   L.ID = R.ID = SymbolID("hello");
   L.CanonicalDeclaration.FileURI = "file:/left.h";
   R.CanonicalDeclaration.FileURI = "file:/right.h";
   L.Name = "left";
   R.Name = "right";
 
-  Symbol M = mergeSymbol(L, R, );
+  Symbol M = mergeSymbol(L, R);
   EXPECT_EQ(M.CanonicalDeclaration.FileURI, "file:/left.h");
   EXPECT_EQ(M.Definition.FileURI, "");
   EXPECT_EQ(M.Name, "left");
 
   R.Definition.FileURI = "file:/right.cpp"; // Now right will be favored.
-  M = mergeSymbol(L, R, );
+  M = mergeSymbol(L, R);
   EXPECT_EQ(M.CanonicalDeclaration.FileURI, "file:/right.h");
   EXPECT_EQ(M.Definition.FileURI, "file:/right.cpp");
   EXPECT_EQ(M.Name, "right");
Index: clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp
===
--- clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp
+++ clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp
@@ -45,22 +45,16 @@
 MATCHER_P(Labeled, Label, "") {
   return (arg.Name + arg.Signature).str() == Label;
 }
-MATCHER(HasReturnType, "") {
-  return arg.Detail && !arg.Detail->ReturnType.empty();
-}
-MATCHER_P(ReturnType, D, "") {
-  return arg.Detail && arg.Detail->ReturnType == D;
-}
-MATCHER_P(Doc, D, "") { return arg.Detail && arg.Detail->Documentation == D; }
+MATCHER(HasReturnType, "") { return !arg.ReturnType.empty(); }
+MATCHER_P(ReturnType, D, "") { return arg.ReturnType == D; }
+MATCHER_P(Doc, D, "") { return arg.Documentation == D; }
 MATCHER_P(Snippet, S, "") {
   return (arg.Name + arg.CompletionSnippetSuffix).str() == S;
 }
 MATCHER_P(QName, Name, "") { return (arg.Scope + arg.Name).str() == Name; }
 MATCHER_P(DeclURI, P, "") { return arg.CanonicalDeclaration.FileURI == P; }
 MATCHER_P(DefURI, P, "") { return arg.Definition.FileURI == P; }
-MATCHER_P(IncludeHeader, P, "") {
-  return arg.Detail && arg.Detail->IncludeHeader == P;
-}
+MATCHER_P(IncludeHeader, P, "") { return arg.IncludeHeader == P; }
 MATCHER_P(DeclRange, Pos, "") {
   return std::tie(arg.CanonicalDeclaration.Start.Line,

[PATCH] D51539: [clangd] Add symbol slab size to index memory consumption estimates

2018-08-31 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

This looks reasonable!
This is going to conflict with https://reviews.llvm.org/D51422, you might want 
to rebase.




Comment at: clang-tools-extra/clangd/index/MemIndex.h:26
+  void build(std::shared_ptr> Symbols,
+ size_t SlabSize=0);
 

could you make these names somewhat more abstract (e.g. BackingMemory rather 
than SlabSize)?
The index shouldn't know/care which configuration of slabs it's built from.


https://reviews.llvm.org/D51539



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


[PATCH] D51539: [clangd] Add symbol slab size to index memory consumption estimates

2018-08-31 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 163523.
kbobyrev added a comment.

Resolved the issues. Measurements show that static Dex index for LLVM takes 
~140 MB,  ~80 MB of which is the size of `SymbolSlab`.


https://reviews.llvm.org/D51539

Files:
  clang-tools-extra/clangd/index/FileIndex.cpp
  clang-tools-extra/clangd/index/FileIndex.h
  clang-tools-extra/clangd/index/MemIndex.cpp
  clang-tools-extra/clangd/index/MemIndex.h
  clang-tools-extra/clangd/index/dex/DexIndex.cpp
  clang-tools-extra/clangd/index/dex/DexIndex.h

Index: clang-tools-extra/clangd/index/dex/DexIndex.h
===
--- clang-tools-extra/clangd/index/dex/DexIndex.h
+++ clang-tools-extra/clangd/index/dex/DexIndex.h
@@ -41,7 +41,8 @@
 public:
   /// \brief (Re-)Build index for `Symbols`. All symbol pointers must remain
   /// accessible as long as `Symbols` is kept alive.
-  void build(std::shared_ptr> Syms);
+  void build(std::shared_ptr> Syms,
+ size_t SlabSize=0);
 
   /// \brief Build index from a symbol slab.
   static std::unique_ptr build(SymbolSlab Slab);
@@ -73,6 +74,12 @@
   // Inverted index is used to retrieve posting lists which are processed during
   // the fuzzyFind process.
   llvm::DenseMap InvertedIndex /*GUARDED_BY(Mutex)*/;
+
+  // Stores size of the symbol slab which is referred by the Symbols stored in
+  // Dex. This is necessary for memory consumption estimation, because Dex only
+  // stores symbols and the actual link to the underlying symbol slab is lost as
+  // soon as it is constructed.
+  size_t PairedSlabSize;
 };
 
 } // namespace dex
Index: clang-tools-extra/clangd/index/dex/DexIndex.cpp
===
--- clang-tools-extra/clangd/index/dex/DexIndex.cpp
+++ clang-tools-extra/clangd/index/dex/DexIndex.cpp
@@ -36,7 +36,8 @@
 
 } // namespace
 
-void DexIndex::build(std::shared_ptr> Syms) {
+void DexIndex::build(std::shared_ptr> Syms,
+ size_t SlabSize) {
   llvm::DenseMap TempLookupTable;
   llvm::DenseMap TempSymbolQuality;
   for (const Symbol *Sym : *Syms) {
@@ -66,15 +67,17 @@
 Symbols = std::move(Syms);
 InvertedIndex = std::move(TempInvertedIndex);
 SymbolQuality = std::move(TempSymbolQuality);
+PairedSlabSize = SlabSize;
   }
 
   vlog("Built DexIndex with estimated memory usage {0} bytes.",
estimateMemoryUsage());
 }
 
 std::unique_ptr DexIndex::build(SymbolSlab Slab) {
   auto Idx = llvm::make_unique();
-  Idx->build(getSymbolsFromSlab(std::move(Slab)));
+  size_t SlabSize = Slab.bytes();
+  Idx->build(getSymbolsFromSlab(std::move(Slab)), SlabSize);
   return std::move(Idx);
 }
 
@@ -177,14 +180,15 @@
 size_t DexIndex::estimateMemoryUsage() const {
   std::lock_guard Lock(Mutex);
 
-  size_t Bytes =
-  LookupTable.size() * sizeof(std::pair);
+  size_t Bytes = PairedSlabSize;
+  Bytes += LookupTable.size() * sizeof(std::pair);
   Bytes += SymbolQuality.size() * sizeof(std::pair);
   Bytes += InvertedIndex.size() * sizeof(Token);
 
   for (const auto  : InvertedIndex) {
 Bytes += P.second.size() * sizeof(DocID);
   }
+
   return Bytes;
 }
 
Index: clang-tools-extra/clangd/index/MemIndex.h
===
--- clang-tools-extra/clangd/index/MemIndex.h
+++ clang-tools-extra/clangd/index/MemIndex.h
@@ -22,7 +22,8 @@
 public:
   /// \brief (Re-)Build index for `Symbols`. All symbol pointers must remain
   /// accessible as long as `Symbols` is kept alive.
-  void build(std::shared_ptr> Symbols);
+  void build(std::shared_ptr> Symbols,
+ size_t SlabSize=0);
 
   /// \brief Build index from a symbol slab.
   static std::unique_ptr build(SymbolSlab Slab);
@@ -47,6 +48,13 @@
   // Index is a set of symbols that are deduplicated by symbol IDs.
   // FIXME: build smarter index structure.
   llvm::DenseMap Index;
+
+  // Stores size of the symbol slab which is referred by the Symbols stored in
+  // Mem. This is necessary for memory consumption estimation, because Mem only
+  // stores symbols and the actual link to the underlying symbol slab is lost as
+  // soon as it is constructed.
+  size_t PairedSlabSize;
+
   mutable std::mutex Mutex;
 };
 
Index: clang-tools-extra/clangd/index/MemIndex.cpp
===
--- clang-tools-extra/clangd/index/MemIndex.cpp
+++ clang-tools-extra/clangd/index/MemIndex.cpp
@@ -15,7 +15,8 @@
 namespace clang {
 namespace clangd {
 
-void MemIndex::build(std::shared_ptr> Syms) {
+void MemIndex::build(std::shared_ptr> Syms,
+ size_t SlabSize) {
   llvm::DenseMap TempIndex;
   for (const Symbol *Sym : *Syms)
 TempIndex[Sym->ID] = Sym;
@@ -25,15 +26,17 @@
 std::lock_guard Lock(Mutex);
 Index = std::move(TempIndex);
 Symbols = std::move(Syms); // Relase old symbols.
+PairedSlabSize = SlabSize;
   }
 
   vlog("Built MemIndex with estimated memory usage {0} 

[PATCH] D51481: [clangd] Implement proximity path boosting for Dex

2018-08-31 Thread Eric Liu via Phabricator via cfe-commits
ioeric added inline comments.



Comment at: clang-tools-extra/clangd/index/dex/DexIndex.cpp:137
+  BoostingIterators.push_back(
+  createBoost(create(It->second), P.second + 10));
+  }

Could you comment on `P.second + 10` here? It sounds like a lot of boost.



Comment at: clang-tools-extra/clangd/index/dex/DexIndex.cpp:157
+const size_t ItemsToRetrieve =
+getRetrievalItemsMultiplier() * Req.MaxCandidateCount;
 auto Root = createLimit(move(QueryIterator), ItemsToRetrieve);

Again, the multiplier change seems irrelevant in this patch.



Comment at: clang-tools-extra/clangd/index/dex/DexIndex.cpp:163
+// Sort items using boosting score as the key.
+std::sort(begin(SymbolDocIDs), end(SymbolDocIDs),
+  [](const std::pair ,

Shouldn't we sort them by `Quality * boost`?



Comment at: clang-tools-extra/clangd/index/dex/DexIndex.h:64
 
-private:
+  /// For fuzzyFind() Dex retrieves getRetrievalItemsMultiplier() more items
+  /// than requested via Req.MaxCandidateCount in the first stage of filtering.

kbobyrev wrote:
> ioeric wrote:
> > Why are values of multipliers interesting to users? Could these be 
> > implementation details in the cpp file?
> Actually, my understanding is that users might want to have full access to 
> the multipliers at some point to control the performance/quality ratio.
> 
> And it's also useful for the tests: otherwise the last one would have to 
> hard-code number of generated symbols to ensure only boosted ones are in the 
> returned list. It would have to be updated each time these internal 
> multipliers are and we might update them often/make logic less clear (by 
> allowing users to control these parameters).
> 
> What do you think?
I'm not sure if users can usefully control this multipliers without 
understanding the whole implementation.  Do we have a use case for these APIs 
now? If not, I'd suggesting removing them from this patch. It also seems to be 
out of the scope of this patch.



Comment at: clang-tools-extra/clangd/index/dex/DexIndex.h:73
+private:
+private:
   mutable std::mutex Mutex;

Double `private`?



Comment at: clang-tools-extra/clangd/index/dex/DexIndex.h:87
+
+  std::vector URISchemes /*GUARDED BY(Mutex)*/;
+

I think `URISchemes` should be initialized when creating a `DexIndex` and 
remain the same. So this could be `const` without mutex guard.



Comment at: clang-tools-extra/clangd/index/dex/Token.h:54
 Scope,
+/// Path to symbol declaration.
+///

As this is called `Path`, I'd try to decouple it from URIs, so that we don't 
need special handling of `scheme` etc in the implementation. We might want to 
canonicalize URI to "path" like `/file:/path/to/something/` so that we could 
simply treat it as normal paths, and the token could potentially handle actual 
actual file paths.



Comment at: clang-tools-extra/clangd/index/dex/Token.h:97
 
+/// Returns Search Token for each parent directory of given Path. Should be 
used
+/// within the index build process.

I couldn't find implementations of these two functions in this patch?


https://reviews.llvm.org/D51481



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


[PATCH] D51422: [clangd] Factor out the data-swapping functionality from MemIndex/DexIndex.

2018-08-31 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clangd/index/Index.h:416
+  // until the call returns (even if reset() is called).
+  bool fuzzyFind(const FuzzyFindRequest &,
+ llvm::function_ref) const override;

kbobyrev wrote:
> Do we want these functions to be `final`? Since `SwapIndex` is a wrapper 
> around an immutable index structure, I believe it would be unlikely that 
> anything would derive from it.
Maybe unlikely but I don't see a strong reason to enforce one way or the other. 
(We rarely use final).

One example of where we'll do it: FileIndex inherits SwapIndex, but it should 
override `estimateMemoryUsage` once that's fixed to incorporate backing symbols.



Comment at: clangd/index/MemIndex.h:30
+  /// Builds an index from a slab. The shared_ptr manages the slab's lifetime.
+  static std::shared_ptr build(SymbolSlab Slab);
 

ioeric wrote:
> (It's a bit unfortunate that this has to return `shared_ptr` now)
Since some of the resources it owns has a shared lifetime, this is really just 
reflecting reality I think. Whether that's visible or invisible seems like a 
wash to me.



Comment at: clangd/index/dex/DexIndex.h:42
+  // All symbols must outlive this index.
+  template  DexIndex(Range &) {
+for (auto & : Symbols)

ioeric wrote:
> Why is this constructor needed? I think this could restrict the flexibility 
> of DexIndex initialization, in case we need to pass in extra parameters here.
I'm not sure exactly what you mean here.

We need a way to specify the symbols to be indexed.
Because these are now immutable, doing that in the constructor if possible is 
best.

Previously this was a vector, but that sometimes required us to 
construct that big vector, dereference all those pointers, and throw away the 
vector. This signature is strictly more general (if you have a vector of 
pointers, you can pass `make_pointee_range`)

> in case we need to pass in extra parameters here.
What stops us adding more parameters?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D51422



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


[PATCH] D51509: [AddressSpace] Use the macro to set hidden visibility on LocalAddressSpace.

2018-08-31 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL341210: [AddressSpace] Use the macro to set hidden 
visibility on LocalAddressSpace. (authored by cdavis, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D51509

Files:
  libunwind/trunk/src/AddressSpace.hpp


Index: libunwind/trunk/src/AddressSpace.hpp
===
--- libunwind/trunk/src/AddressSpace.hpp
+++ libunwind/trunk/src/AddressSpace.hpp
@@ -180,7 +180,7 @@
 /// LocalAddressSpace is used as a template parameter to UnwindCursor when
 /// unwinding a thread in the same process.  The wrappers compile away,
 /// making local unwinds fast.
-class __attribute__((visibility("hidden"))) LocalAddressSpace {
+class _LIBUNWIND_HIDDEN LocalAddressSpace {
 public:
   typedef uintptr_t pint_t;
   typedef intptr_t  sint_t;


Index: libunwind/trunk/src/AddressSpace.hpp
===
--- libunwind/trunk/src/AddressSpace.hpp
+++ libunwind/trunk/src/AddressSpace.hpp
@@ -180,7 +180,7 @@
 /// LocalAddressSpace is used as a template parameter to UnwindCursor when
 /// unwinding a thread in the same process.  The wrappers compile away,
 /// making local unwinds fast.
-class __attribute__((visibility("hidden"))) LocalAddressSpace {
+class _LIBUNWIND_HIDDEN LocalAddressSpace {
 public:
   typedef uintptr_t pint_t;
   typedef intptr_t  sint_t;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libunwind] r341210 - [AddressSpace] Use the macro to set hidden visibility on LocalAddressSpace.

2018-08-31 Thread Charles Davis via cfe-commits
Author: cdavis
Date: Fri Aug 31 06:41:05 2018
New Revision: 341210

URL: http://llvm.org/viewvc/llvm-project?rev=341210=rev
Log:
[AddressSpace] Use the macro to set hidden visibility on LocalAddressSpace.

Summary:
That attribute has no effect on Windows anyway--classes are hidden by
default.

Reviewers: mstorsjo, rnk

Subscribers: christof, cfe-commits

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

Modified:
libunwind/trunk/src/AddressSpace.hpp

Modified: libunwind/trunk/src/AddressSpace.hpp
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/AddressSpace.hpp?rev=341210=341209=341210=diff
==
--- libunwind/trunk/src/AddressSpace.hpp (original)
+++ libunwind/trunk/src/AddressSpace.hpp Fri Aug 31 06:41:05 2018
@@ -180,7 +180,7 @@ struct UnwindInfoSections {
 /// LocalAddressSpace is used as a template parameter to UnwindCursor when
 /// unwinding a thread in the same process.  The wrappers compile away,
 /// making local unwinds fast.
-class __attribute__((visibility("hidden"))) LocalAddressSpace {
+class _LIBUNWIND_HIDDEN LocalAddressSpace {
 public:
   typedef uintptr_t pint_t;
   typedef intptr_t  sint_t;


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


[PATCH] D51291: [clangd] Support multiple #include headers in one symbol.

2018-08-31 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clangd/CodeComplete.cpp:396
+// Prefer includes that do not need edits (i.e. already exist).
+std::stable_sort(Completion.Includes.begin(), Completion.Includes.end(),
+ [](const CodeCompletion::IncludeCandidate ,

nit: this could be std::stable_partition. Not sure if faster, but maybe clearer.



Comment at: clangd/CodeComplete.h:145
+  // All possible include headers ranked by preference. By default, the first
+  // include is used.
+  llvm::SmallVector Includes;

if we've bundled together overloads that have different sets of providing 
headers, these includes may not be accurate for all of them. Maybe comment this 
limitation?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D51291



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


Re: [PATCH] D51507: Allow all supportable attributes to be used with #pragma clang attribute.

2018-08-31 Thread Aaron Ballman via cfe-commits
On Fri, Aug 31, 2018 at 9:23 AM, Duncan P. N. Exon Smith via
Phabricator  wrote:
> dexonsmith added inline comments.
>
>
> 
> Comment at: test/Misc/pragma-attribute-supported-attributes-list.test:50
>  // CHECK-NEXT: EnumExtensibility (SubjectMatchRule_enum)
> +// CHECK-NEXT: ExtVectorType (SubjectMatchRule_type_alias)
>  // CHECK-NEXT: ExternalSourceSymbol ((SubjectMatchRule_record, 
> SubjectMatchRule_enum, SubjectMatchRule_enum_constant, 
> SubjectMatchRule_field, SubjectMatchRule_function, 
> SubjectMatchRule_namespace, SubjectMatchRule_objc_category, 
> SubjectMatchRule_objc_interface, SubjectMatchRule_objc_method, 
> SubjectMatchRule_objc_property, SubjectMatchRule_objc_protocol, 
> SubjectMatchRule_record, SubjectMatchRule_type_alias, 
> SubjectMatchRule_variable))
> 
> aaron.ballman wrote:
>> dexonsmith wrote:
>> > rsmith wrote:
>> > > I think `__attribute__((ext_vector_type))` is a good candidate to *not* 
>> > > have `#pragma clang attribute` support. A type modifier like this really 
>> > > should only be declared as part of declaring the type. Opinions?
>> > The same argument might hold for most type attributes.  I have trouble 
>> > imagining someone using this, but it's also hard to see how supporting it 
>> > would lead to bugs in user code.  It seems a bit simpler to support 
>> > everything.
>> >
>> > I don't have a strong opinion though.
>> I don't think `#pragma clang attribute` should apply to types -- types show 
>> up in far too many places and attributes on types changes the fundamental 
>> meaning of types a bit too much for my tastes. I'd prefer users annotate the 
>> type directly.
>> types show up in far too many places and attributes on types changes the 
>> fundamental meaning of types a bit too much for my tastes
>
> I don't see how region-based attributes on type aliases is really any 
> different from region-based annotations on variables.

My reasoning is because type attributes have more impact than variable
attributes and types appear more frequently. Consider using
address_space where the region includes function definitions. Should
that apply to the parameters and return types of the function as well
as the code within the function? Will that be intuitive for users?
What about using a calling convention before defining a structure --
will users expect the calling convention to apply to the member
function types? (The latter is a bit confused though since calling
conventions are declaration *and* type attributes at the same time.)

> Moreover, I'm strongly against disallowing use of this pragma on type aliases 
> in general: as a vendor, we've already shipped that support for a number of 
> attributes.  Most critically, ExternalSourceSymbol applies to type aliases, 
> and handling ExternalSourceSymbol was our primary motivation for adding this 
> feature (the alternative was to add yet-another-attribute-specific-`#pragma`).

ExternalSourceSymbol appertains to named declarations, not types, so
I'm a bit confused where the concern is there.

~Aaron

>
>
> 
> Comment at: test/Misc/pragma-attribute-supported-attributes-list.test:100
> +// CHECK-NEXT: ObjCReturnsInnerPointer (SubjectMatchRule_objc_method, 
> SubjectMatchRule_objc_property)
> +// CHECK-NEXT: ObjCRootClass (SubjectMatchRule_objc_interface)
>  // CHECK-NEXT: ObjCRuntimeName (SubjectMatchRule_objc_interface, 
> SubjectMatchRule_objc_protocol)
> 
> kristina wrote:
>> rsmith wrote:
>> > kristina wrote:
>> > > There is only one root class in a given runtime (ie. NSObject for objc4, 
>> > > or Object for older Apple runtimes, ObjFW also has a different root 
>> > > class). Having more than one makes no sense especially in the same 
>> > > lexical context as there are no use cases I can think of where you would 
>> > > have more than one active ObjC runtime within a process.
>> > Thanks. Yes, this attribute probably doesn't make very much sense to use 
>> > in conjunction with the pragma.
>> >
>> > So, do we explicitly disallow it, or do we allow it with the expectation 
>> > that it's likely that no-one will ever want to use it? (That is, do we 
>> > want to disallow cases that are not useful, or merely cases that are not 
>> > meaningful?) I don't have a strong opinion here, but I'm mildly inclined 
>> > towards allowing the pragma on any attribute where it's meaningful, as 
>> > there may be useful uses that we just didn't think of, and it costs 
>> > nothing to permit.
>> Yes in theory it could only be used on a single interface in which case it 
>> would be perfectly valid. Otherwise when used incorrectly it would issue a 
>> diagnostic. As per your inclination of allowing it for all attributes I 
>> would say leave it allowed, as it **can** be used in a correct way. 
>> Diagnostics are sufficient enough to point out when it happens to apply the 
>> attribute to more than one interface.
>>
>> So given your comment, I would say leave it as allowed.

[PATCH] D51422: [clangd] Factor out the data-swapping functionality from MemIndex/DexIndex.

2018-08-31 Thread Eric Liu via Phabricator via cfe-commits
ioeric added inline comments.



Comment at: clangd/index/dex/DexIndex.h:42
+  // All symbols must outlive this index.
+  template  DexIndex(Range &) {
+for (auto & : Symbols)

Why is this constructor needed? I think this could restrict the flexibility of 
DexIndex initialization, in case we need to pass in extra parameters here.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D51422



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


[PATCH] D51539: [clangd] Add symbol slab size to index memory consumption estimates

2018-08-31 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev planned changes to this revision.
kbobyrev added a comment.

I should use `SymbolSlab.bytes()` instead of `SymbolSlab.size()`. Either way, 
something seems to be wrong, because manually checking the `PairedSlabSize` 
made me suspicious.


https://reviews.llvm.org/D51539



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


[PATCH] D51507: Allow all supportable attributes to be used with #pragma clang attribute.

2018-08-31 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added inline comments.



Comment at: test/Misc/pragma-attribute-supported-attributes-list.test:50
 // CHECK-NEXT: EnumExtensibility (SubjectMatchRule_enum)
+// CHECK-NEXT: ExtVectorType (SubjectMatchRule_type_alias)
 // CHECK-NEXT: ExternalSourceSymbol ((SubjectMatchRule_record, 
SubjectMatchRule_enum, SubjectMatchRule_enum_constant, SubjectMatchRule_field, 
SubjectMatchRule_function, SubjectMatchRule_namespace, 
SubjectMatchRule_objc_category, SubjectMatchRule_objc_interface, 
SubjectMatchRule_objc_method, SubjectMatchRule_objc_property, 
SubjectMatchRule_objc_protocol, SubjectMatchRule_record, 
SubjectMatchRule_type_alias, SubjectMatchRule_variable))

aaron.ballman wrote:
> dexonsmith wrote:
> > rsmith wrote:
> > > I think `__attribute__((ext_vector_type))` is a good candidate to *not* 
> > > have `#pragma clang attribute` support. A type modifier like this really 
> > > should only be declared as part of declaring the type. Opinions?
> > The same argument might hold for most type attributes.  I have trouble 
> > imagining someone using this, but it's also hard to see how supporting it 
> > would lead to bugs in user code.  It seems a bit simpler to support 
> > everything.
> > 
> > I don't have a strong opinion though.
> I don't think `#pragma clang attribute` should apply to types -- types show 
> up in far too many places and attributes on types changes the fundamental 
> meaning of types a bit too much for my tastes. I'd prefer users annotate the 
> type directly.
> types show up in far too many places and attributes on types changes the 
> fundamental meaning of types a bit too much for my tastes

I don't see how region-based attributes on type aliases is really any different 
from region-based annotations on variables.

Moreover, I'm strongly against disallowing use of this pragma on type aliases 
in general: as a vendor, we've already shipped that support for a number of 
attributes.  Most critically, ExternalSourceSymbol applies to type aliases, and 
handling ExternalSourceSymbol was our primary motivation for adding this 
feature (the alternative was to add yet-another-attribute-specific-`#pragma`).



Comment at: test/Misc/pragma-attribute-supported-attributes-list.test:100
+// CHECK-NEXT: ObjCReturnsInnerPointer (SubjectMatchRule_objc_method, 
SubjectMatchRule_objc_property)
+// CHECK-NEXT: ObjCRootClass (SubjectMatchRule_objc_interface)
 // CHECK-NEXT: ObjCRuntimeName (SubjectMatchRule_objc_interface, 
SubjectMatchRule_objc_protocol)

kristina wrote:
> rsmith wrote:
> > kristina wrote:
> > > There is only one root class in a given runtime (ie. NSObject for objc4, 
> > > or Object for older Apple runtimes, ObjFW also has a different root 
> > > class). Having more than one makes no sense especially in the same 
> > > lexical context as there are no use cases I can think of where you would 
> > > have more than one active ObjC runtime within a process.
> > Thanks. Yes, this attribute probably doesn't make very much sense to use in 
> > conjunction with the pragma.
> > 
> > So, do we explicitly disallow it, or do we allow it with the expectation 
> > that it's likely that no-one will ever want to use it? (That is, do we want 
> > to disallow cases that are not useful, or merely cases that are not 
> > meaningful?) I don't have a strong opinion here, but I'm mildly inclined 
> > towards allowing the pragma on any attribute where it's meaningful, as 
> > there may be useful uses that we just didn't think of, and it costs nothing 
> > to permit.
> Yes in theory it could only be used on a single interface in which case it 
> would be perfectly valid. Otherwise when used incorrectly it would issue a 
> diagnostic. As per your inclination of allowing it for all attributes I would 
> say leave it allowed, as it **can** be used in a correct way. Diagnostics are 
> sufficient enough to point out when it happens to apply the attribute to more 
> than one interface.
> 
> So given your comment, I would say leave it as allowed.
> So, do we explicitly disallow it, or do we allow it with the expectation that 
> it's likely that no-one will ever want to use it? (That is, do we want to 
> disallow cases that are not useful, or merely cases that are not meaningful?) 

I'd prefer to only disallow cases that are not meaningful.


Repository:
  rC Clang

https://reviews.llvm.org/D51507



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


[PATCH] D32845: [Analyzer] Iterator Checker - Part 4: Mismatched iterator checker for function parameters

2018-08-31 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 163517.
baloghadamsoftware removed a reviewer: george.karpenkov.
baloghadamsoftware added a comment.
Herald added a reviewer: george.karpenkov.

Since https://reviews.llvm.org/rL338263 fixed a bug in the cleanup phase the 
tests for mismatched iterator checker did not pass. The reason for this is that 
the region of some `LazyCompoundVal`s are cleaned up while there are still 
iterator positions connected to the `LazyCompoundVal` itself. This happens 
typically for arguments which are constructed in-place (e.g. `begin()` or 
`end()` of a container is invoked in the argument itself).

We applied a fix here that defers cleanup of such iterator positions. No other 
solution comes to my mind at the moment.

I wanted to upload this fix in a separate patch but I could not create tests 
for it.

@NoQ please review this fix before I commit the patch.


https://reviews.llvm.org/D32845

Files:
  include/clang/StaticAnalyzer/Checkers/Checkers.td
  lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
  test/Analysis/Inputs/system-header-simulator-cxx.h
  test/Analysis/invalidated-iterator.cpp
  test/Analysis/mismatched-iterator.cpp

Index: test/Analysis/mismatched-iterator.cpp
===
--- /dev/null
+++ test/Analysis/mismatched-iterator.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,cplusplus,alpha.cplusplus.MismatchedIterator -analyzer-config aggressive-binary-operation-simplification=true -analyzer-config c++-container-inlining=false %s -verify
+// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,cplusplus,alpha.cplusplus.MismatchedIterator -analyzer-config aggressive-binary-operation-simplification=true -analyzer-config c++-container-inlining=true -DINLINE=1 %s -verify
+
+#include "Inputs/system-header-simulator-cxx.h"
+
+void good_find(std::vector , int n) {
+  std::find(v.cbegin(), v.cend(), n); // no-warning
+}
+
+void good_find_first_of(std::vector , std::vector ) {
+  std::find_first_of(v1.cbegin(), v1.cend(), v2.cbegin(), v2.cend()); // no-warning
+}
+
+void good_copy(std::vector , std::vector , int n) {
+  std::copy(v1.cbegin(), v1.cend(), v2.begin()); // no-warning
+}
+
+void bad_find(std::vector , std::vector , int n) {
+  std::find(v1.cbegin(), v2.cend(), n); // expected-warning{{Iterators of different containers used where the same container is expected}}
+}
+
+void bad_find_first_of(std::vector , std::vector ) {
+  std::find_first_of(v1.cbegin(), v2.cend(), v2.cbegin(), v2.cend()); // expected-warning{{Iterators of different containers used where the same container is expected}}
+  std::find_first_of(v1.cbegin(), v1.cend(), v2.cbegin(), v1.cend()); // expected-warning{{Iterators of different containers used where the same container is expected}}
+}
Index: test/Analysis/invalidated-iterator.cpp
===
--- test/Analysis/invalidated-iterator.cpp
+++ test/Analysis/invalidated-iterator.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,cplusplus,alpha.cplusplus.InvalidatedIterator -analyzer-config aggressive-relational-comparison-simplification=true -analyzer-config c++-container-inlining=false %s -verify
-// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,cplusplus,alpha.cplusplus.InvalidatedIterator -analyzer-config aggressive-relational-comparison-simplification=true -analyzer-config c++-container-inlining=true -DINLINE=1 %s -verify
+// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,cplusplus,alpha.cplusplus.InvalidatedIterator -analyzer-config aggressive-binary-operation-simplification=true -analyzer-config c++-container-inlining=false %s -verify
+// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,cplusplus,alpha.cplusplus.InvalidatedIterator -analyzer-config aggressive-binary-operation-simplification=true -analyzer-config c++-container-inlining=true -DINLINE=1 %s -verify
 
 #include "Inputs/system-header-simulator-cxx.h"
 
Index: test/Analysis/Inputs/system-header-simulator-cxx.h
===
--- test/Analysis/Inputs/system-header-simulator-cxx.h
+++ test/Analysis/Inputs/system-header-simulator-cxx.h
@@ -642,6 +642,12 @@
   template 
   InputIterator find(InputIterator first, InputIterator last, const T );
 
+  template 
+  ForwardIterator1 find_first_of(ForwardIterator1 first1,
+ ForwardIterator1 last1,
+ ForwardIterator2 first2,
+ ForwardIterator2 last2);
+
   template 
   OutputIterator copy(InputIterator first, InputIterator last,
   OutputIterator result);
Index: lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
+++ 

[PATCH] D51539: [clangd] Add symbol slab size to index memory consumption estimates

2018-08-31 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev created this revision.
kbobyrev added reviewers: ioeric, sammccall.
kbobyrev added a project: clang-tools-extra.
Herald added subscribers: kadircet, arphaman, jkorous, MaskRay.

Currently, `SymbolIndex::estimateMemoryUsage()` returns the "overhead" 
estimate, i.e. the estimate of the Index data structure excluding `SymbolSlab` 
size. This patch propagates information about paired `SymbolSlab` size where 
necessary.


https://reviews.llvm.org/D51539

Files:
  clang-tools-extra/clangd/index/FileIndex.cpp
  clang-tools-extra/clangd/index/FileIndex.h
  clang-tools-extra/clangd/index/MemIndex.cpp
  clang-tools-extra/clangd/index/MemIndex.h
  clang-tools-extra/clangd/index/dex/DexIndex.cpp
  clang-tools-extra/clangd/index/dex/DexIndex.h

Index: clang-tools-extra/clangd/index/dex/DexIndex.h
===
--- clang-tools-extra/clangd/index/dex/DexIndex.h
+++ clang-tools-extra/clangd/index/dex/DexIndex.h
@@ -41,7 +41,8 @@
 public:
   /// \brief (Re-)Build index for `Symbols`. All symbol pointers must remain
   /// accessible as long as `Symbols` is kept alive.
-  void build(std::shared_ptr> Syms);
+  void build(std::shared_ptr> Syms,
+ size_t SlabSize=0);
 
   /// \brief Build index from a symbol slab.
   static std::unique_ptr build(SymbolSlab Slab);
@@ -73,6 +74,12 @@
   // Inverted index is used to retrieve posting lists which are processed during
   // the fuzzyFind process.
   llvm::DenseMap InvertedIndex /*GUARDED_BY(Mutex)*/;
+
+  // Stores size of the symbol slab which is referred by the Symbols stored in
+  // Dex. This is necessary for memory consumption estimation, because Dex only
+  // stores symbols and the actual link to the underlying symbol slab is lost as
+  // soon as it is constructed.
+  size_t PairedSlabSize;
 };
 
 } // namespace dex
Index: clang-tools-extra/clangd/index/dex/DexIndex.cpp
===
--- clang-tools-extra/clangd/index/dex/DexIndex.cpp
+++ clang-tools-extra/clangd/index/dex/DexIndex.cpp
@@ -36,7 +36,8 @@
 
 } // namespace
 
-void DexIndex::build(std::shared_ptr> Syms) {
+void DexIndex::build(std::shared_ptr> Syms,
+ size_t SlabSize) {
   llvm::DenseMap TempLookupTable;
   llvm::DenseMap TempSymbolQuality;
   for (const Symbol *Sym : *Syms) {
@@ -66,15 +67,16 @@
 Symbols = std::move(Syms);
 InvertedIndex = std::move(TempInvertedIndex);
 SymbolQuality = std::move(TempSymbolQuality);
+PairedSlabSize = SlabSize;
   }
 
   vlog("Built DexIndex with estimated memory usage {0} bytes.",
estimateMemoryUsage());
 }
 
 std::unique_ptr DexIndex::build(SymbolSlab Slab) {
   auto Idx = llvm::make_unique();
-  Idx->build(getSymbolsFromSlab(std::move(Slab)));
+  Idx->build(getSymbolsFromSlab(std::move(Slab)), Slab.size());
   return std::move(Idx);
 }
 
@@ -177,8 +179,8 @@
 size_t DexIndex::estimateMemoryUsage() const {
   std::lock_guard Lock(Mutex);
 
-  size_t Bytes =
-  LookupTable.size() * sizeof(std::pair);
+  size_t Bytes = PairedSlabSize;
+  Bytes += LookupTable.size() * sizeof(std::pair);
   Bytes += SymbolQuality.size() * sizeof(std::pair);
   Bytes += InvertedIndex.size() * sizeof(Token);
 
Index: clang-tools-extra/clangd/index/MemIndex.h
===
--- clang-tools-extra/clangd/index/MemIndex.h
+++ clang-tools-extra/clangd/index/MemIndex.h
@@ -22,7 +22,8 @@
 public:
   /// \brief (Re-)Build index for `Symbols`. All symbol pointers must remain
   /// accessible as long as `Symbols` is kept alive.
-  void build(std::shared_ptr> Symbols);
+  void build(std::shared_ptr> Symbols,
+ size_t SlabSize=0);
 
   /// \brief Build index from a symbol slab.
   static std::unique_ptr build(SymbolSlab Slab);
@@ -47,6 +48,13 @@
   // Index is a set of symbols that are deduplicated by symbol IDs.
   // FIXME: build smarter index structure.
   llvm::DenseMap Index;
+
+  // Stores size of the symbol slab which is referred by the Symbols stored in
+  // Mem. This is necessary for memory consumption estimation, because Mem only
+  // stores symbols and the actual link to the underlying symbol slab is lost as
+  // soon as it is constructed.
+  size_t PairedSlabSize;
+
   mutable std::mutex Mutex;
 };
 
Index: clang-tools-extra/clangd/index/MemIndex.cpp
===
--- clang-tools-extra/clangd/index/MemIndex.cpp
+++ clang-tools-extra/clangd/index/MemIndex.cpp
@@ -15,7 +15,8 @@
 namespace clang {
 namespace clangd {
 
-void MemIndex::build(std::shared_ptr> Syms) {
+void MemIndex::build(std::shared_ptr> Syms,
+ size_t SlabSize) {
   llvm::DenseMap TempIndex;
   for (const Symbol *Sym : *Syms)
 TempIndex[Sym->ID] = Sym;
@@ -25,15 +26,16 @@
 std::lock_guard Lock(Mutex);
 Index = std::move(TempIndex);
 Symbols = std::move(Syms); // Relase old symbols.
+PairedSlabSize = 

[PATCH] D50385: [clangd] Collect symbol occurrences in SymbolCollector

2018-08-31 Thread Haojian Wu via Phabricator via cfe-commits
hokein closed this revision.
hokein added a comment.

Committed in https://reviews.llvm.org/rL341208.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50385



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


[clang-tools-extra] r341208 - [clangd] Collect symbol occurrences in SymbolCollector.

2018-08-31 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Fri Aug 31 05:54:13 2018
New Revision: 341208

URL: http://llvm.org/viewvc/llvm-project?rev=341208=rev
Log:
[clangd] Collect symbol occurrences in SymbolCollector.

SymbolCollector will be used for two cases:
 - collect Symbol type only, used for indexing preamble AST.
 - collect Symbol and SymbolOccurrences, used for indexing main AST.

For finding local references from the AST, we will implement it in other ways.

Modified:
clang-tools-extra/trunk/clangd/index/Index.cpp
clang-tools-extra/trunk/clangd/index/Index.h
clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
clang-tools-extra/trunk/clangd/index/SymbolCollector.h
clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp

Modified: clang-tools-extra/trunk/clangd/index/Index.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Index.cpp?rev=341208=341207=341208=diff
==
--- clang-tools-extra/trunk/clangd/index/Index.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Index.cpp Fri Aug 31 05:54:13 2018
@@ -128,5 +128,48 @@ SymbolSlab SymbolSlab::Builder::build()
   return SymbolSlab(std::move(NewArena), std::move(Symbols));
 }
 
+raw_ostream <<(raw_ostream , SymbolOccurrenceKind K) {
+  if (K == SymbolOccurrenceKind::Unknown)
+return OS << "Unknown";
+  static const std::vector Messages = {"Decl", "Def", "Ref"};
+  bool VisitedOnce = false;
+  for (unsigned I = 0; I < Messages.size(); ++I) {
+if (static_cast(K) & 1u << I) {
+  if (VisitedOnce)
+OS << ", ";
+  OS << Messages[I];
+  VisitedOnce = true;
+}
+  }
+  return OS;
+}
+
+llvm::raw_ostream <<(llvm::raw_ostream ,
+  const SymbolOccurrence ) {
+  OS << Occurrence.Location << ":" << Occurrence.Kind;
+  return OS;
+}
+
+void SymbolOccurrenceSlab::insert(const SymbolID ,
+  const SymbolOccurrence ) {
+  assert(!Frozen &&
+ "Can't insert a symbol occurrence after the slab has been frozen!");
+  auto  = Occurrences[SymID];
+  SymOccurrences.push_back(Occurrence);
+  SymOccurrences.back().Location.FileURI =
+  UniqueStrings.save(Occurrence.Location.FileURI);
+}
+
+void SymbolOccurrenceSlab::freeze() {
+  // Deduplicate symbol occurrenes.
+  for (auto  : Occurrences) {
+auto  = IDAndOccurrence.getSecond();
+std::sort(Occurrence.begin(), Occurrence.end());
+Occurrence.erase(std::unique(Occurrence.begin(), Occurrence.end()),
+ Occurrence.end());
+  }
+  Frozen = true;
+}
+
 } // namespace clangd
 } // namespace clang

Modified: clang-tools-extra/trunk/clangd/index/Index.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Index.h?rev=341208=341207=341208=diff
==
--- clang-tools-extra/trunk/clangd/index/Index.h (original)
+++ clang-tools-extra/trunk/clangd/index/Index.h Fri Aug 31 05:54:13 2018
@@ -32,9 +32,6 @@ struct SymbolLocation {
 uint32_t Line = 0; // 0-based
 // Using UTF-16 code units.
 uint32_t Column = 0; // 0-based
-bool operator==(const Position& P) const {
-  return Line == P.Line && Column == P.Column;
-}
   };
 
   // The URI of the source file where a symbol occurs.
@@ -45,11 +42,23 @@ struct SymbolLocation {
   Position End;
 
   explicit operator bool() const { return !FileURI.empty(); }
-  bool operator==(const SymbolLocation& Loc) const {
-return std::tie(FileURI, Start, End) ==
-   std::tie(Loc.FileURI, Loc.Start, Loc.End);
-  }
 };
+inline bool operator==(const SymbolLocation::Position ,
+   const SymbolLocation::Position ) {
+  return std::tie(L.Line, L.Column) == std::tie(R.Line, R.Column);
+}
+inline bool operator<(const SymbolLocation::Position ,
+  const SymbolLocation::Position ) {
+  return std::tie(L.Line, L.Column) < std::tie(R.Line, R.Column);
+}
+inline bool operator==(const SymbolLocation , const SymbolLocation ) {
+  return std::tie(L.FileURI, L.Start, L.End) ==
+ std::tie(R.FileURI, R.Start, R.End);
+}
+inline bool operator<(const SymbolLocation , const SymbolLocation ) {
+  return std::tie(L.FileURI, L.Start, L.End) <
+ std::tie(R.FileURI, R.Start, R.End);
+}
 llvm::raw_ostream <<(llvm::raw_ostream &, const SymbolLocation &);
 
 // The class identifies a particular C++ symbol (class, function, method, etc).
@@ -314,6 +323,9 @@ inline SymbolOccurrenceKind operator&(Sy
   return static_cast(static_cast(A) &
static_cast(B));
 }
+static const SymbolOccurrenceKind AllOccurrenceKinds =
+SymbolOccurrenceKind::Declaration | SymbolOccurrenceKind::Definition |
+SymbolOccurrenceKind::Reference;
 
 // Represents a symbol occurrence in the source file. It could be a
 // declaration/definition/reference occurrence.
@@ -324,6 +336,61 @@ struct 

[PATCH] D51329: [Attribute/Diagnostics] Print macro instead of whole attribute for address_space

2018-08-31 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: include/clang/AST/Type.h:4343
   QualType getEquivalentType() const { return EquivalentType; }
+  IdentifierInfo *getAddressSpaceMacroII() const { return AddressSpaceMacroII; 
}
+  bool hasAddressSpaceMacroII() const { return AddressSpaceMacroII != nullptr; 
}

rsmith wrote:
> Likewise.
Given that this function is `const`, I think the returned pointer should be as 
well.



Comment at: lib/Lex/PPDirectives.cpp:2584
+// one token for the attribute itself.
+static constexpr unsigned kMinAttrTokens = 6;
+

This count is specific to GNU spellings. For instance, a C++ spelling might 
have 5 tokens (two square brackets, attribute-token, two more square brackets) 
or more and a declspec spelling might have 4 tokens (__declspec keyword, paren, 
attribute token, paren).



Comment at: lib/Lex/PPDirectives.cpp:2586-2588
+/// This only catches macros whose whole definition is an attribute. That is, 
it
+/// starts with the attribute keyword and 2 opening parentheses, and ends with
+/// the 2 closing parentheses.

Why does this need to be specific to GNU-style spellings?



Comment at: lib/Lex/PPDirectives.cpp:2720-2721
 
+  // If the macro is an attribute that contains address_space(), save this for
+  // diagnosing later.
+  SourceRange Range;

This should not be specific to `address_space`, but even if it were, this is 
wrong as it can be spelled `[[clang::address_space(0)]]`.



Comment at: lib/Parse/ParseDecl.cpp:116
+/// they were defined in.
+static void ApplyMacroIIToParsedAttrs(ParsedAttributes , unsigned N,
+  IdentifierInfo *MacroII) {

`attrs` doesn't meet the usual naming conventions. Same with `i` below.



Comment at: lib/Parse/ParseDecl.cpp:119
+  assert(attrs.size() >= N);
+  for (unsigned i = attrs.size() - N; i < N; ++i)
+attrs[i].setMacroII(MacroII);

You can use a range-based for loop here instead.


Repository:
  rC Clang

https://reviews.llvm.org/D51329



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


[PATCH] D51279: [clangd] Implement findOccurrences interface in dynamic index.

2018-08-31 Thread Haojian Wu via Phabricator via cfe-commits
hokein marked 3 inline comments as done.
hokein added a comment.

Sorry! Just realised I messed up this patch with 
https://reviews.llvm.org/D50385 (mostly SymbolCollector changes), all the 
comments about `SymbolCollector` are fixed in https://reviews.llvm.org/D50385.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D51279



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


[PATCH] D50385: [clangd] Collect symbol occurrences in SymbolCollector

2018-08-31 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 163512.
hokein added a comment.

Address review comments in https://reviews.llvm.org/D51279.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50385

Files:
  clangd/index/Index.cpp
  clangd/index/Index.h
  clangd/index/SymbolCollector.cpp
  clangd/index/SymbolCollector.h
  unittests/clangd/SymbolCollectorTests.cpp

Index: unittests/clangd/SymbolCollectorTests.cpp
===
--- unittests/clangd/SymbolCollectorTests.cpp
+++ unittests/clangd/SymbolCollectorTests.cpp
@@ -28,9 +28,15 @@
 #include 
 #include 
 
+namespace clang {
+namespace clangd {
+
+namespace {
+
 using testing::AllOf;
 using testing::Eq;
 using testing::Field;
+using testing::IsEmpty;
 using testing::Not;
 using testing::UnorderedElementsAre;
 using testing::UnorderedElementsAreArray;
@@ -74,11 +80,18 @@
 MATCHER_P(ForCodeCompletion, IsIndexedForCodeCompletion, "") {
   return arg.IsIndexedForCodeCompletion == IsIndexedForCodeCompletion;
 }
-
-namespace clang {
-namespace clangd {
-
-namespace {
+MATCHER(OccurrenceRange, "") {
+  const SymbolOccurrence  = testing::get<0>(arg);
+  const Range  = testing::get<1>(arg);
+  return std::tie(Pos.Location.Start.Line, Pos.Location.Start.Column,
+  Pos.Location.End.Line, Pos.Location.End.Column) ==
+ std::tie(Range.start.line, Range.start.character, Range.end.line,
+  Range.end.character);
+}
+testing::Matcher &>
+HaveRanges(const std::vector Ranges) {
+  return testing::UnorderedPointwise(OccurrenceRange(), Ranges);
+}
 
 class ShouldCollectSymbolTest : public ::testing::Test {
 public:
@@ -237,6 +250,7 @@
 llvm::MemoryBuffer::getMemBuffer(MainCode));
 Invocation.run();
 Symbols = Factory->Collector->takeSymbols();
+SymbolOccurrences = Factory->Collector->takeOccurrences();
 return true;
   }
 
@@ -247,6 +261,7 @@
   std::string TestFileName;
   std::string TestFileURI;
   SymbolSlab Symbols;
+  SymbolOccurrenceSlab SymbolOccurrences;
   SymbolCollector::Options CollectorOpts;
   std::unique_ptr PragmaHandler;
 };
@@ -413,6 +428,59 @@
   ));
 }
 
+TEST_F(SymbolCollectorTest, Occurrences) {
+  Annotations Header(R"(
+  class $foo[[Foo]] {
+  public:
+$foo[[Foo]]() {}
+$foo[[Foo]](int);
+  };
+  class $bar[[Bar]];
+  void $func[[func]]();
+  )");
+  Annotations Main(R"(
+  class $bar[[Bar]] {};
+
+  void $func[[func]]();
+
+  void fff() {
+$foo[[Foo]] foo;
+$bar[[Bar]] bar;
+$func[[func]]();
+int abc = 0;
+$foo[[Foo]] foo2 = abc;
+  }
+  )");
+  Annotations SymbolsOnlyInMainCode(R"(
+  int a;
+  void b() {}
+  static const int c = 0;
+  class d {};
+  )");
+  CollectorOpts.OccurrenceFilter = AllOccurrenceKinds;
+  runSymbolCollector(Header.code(),
+ (Main.code() + SymbolsOnlyInMainCode.code()).str());
+  auto HeaderSymbols = TestTU::withHeaderCode(Header.code()).headerSymbols();
+
+  EXPECT_THAT(SymbolOccurrences.find(findSymbol(Symbols, "Foo").ID),
+  HaveRanges(Main.ranges("foo")));
+  EXPECT_THAT(SymbolOccurrences.find(findSymbol(Symbols, "Bar").ID),
+  HaveRanges(Main.ranges("bar")));
+  EXPECT_THAT(SymbolOccurrences.find(findSymbol(Symbols, "func").ID),
+  HaveRanges(Main.ranges("func")));
+
+  // Retrieve IDs for symbols *only* in the main file, and verify these symbols
+  // are not collected.
+  auto MainSymbols =
+  TestTU::withHeaderCode(SymbolsOnlyInMainCode.code()).headerSymbols();
+  EXPECT_THAT(SymbolOccurrences.find(findSymbol(MainSymbols, "a").ID),
+  IsEmpty());
+  EXPECT_THAT(SymbolOccurrences.find(findSymbol(MainSymbols, "b").ID),
+  IsEmpty());
+  EXPECT_THAT(SymbolOccurrences.find(findSymbol(MainSymbols, "c").ID),
+  IsEmpty());
+}
+
 TEST_F(SymbolCollectorTest, References) {
   const std::string Header = R"(
 class W;
Index: clangd/index/SymbolCollector.h
===
--- clangd/index/SymbolCollector.h
+++ clangd/index/SymbolCollector.h
@@ -52,6 +52,10 @@
 const CanonicalIncludes *Includes = nullptr;
 // Populate the Symbol.References field.
 bool CountReferences = false;
+/// The symbol occurrence kind that will be collected.
+/// If not set (Unknown), SymbolCollector will not collect any symbol
+/// occurrences.
+SymbolOccurrenceKind OccurrenceFilter = SymbolOccurrenceKind::Unknown;
 // Every symbol collected will be stamped with this origin.
 SymbolOrigin Origin = SymbolOrigin::Unknown;
 /// Collect macros.
@@ -86,22 +90,34 @@
 
   SymbolSlab takeSymbols() { return std::move(Symbols).build(); }
 
+  SymbolOccurrenceSlab takeOccurrences() {
+SymbolOccurrences.freeze();
+return std::move(SymbolOccurrences);
+  }
+
   void finish() override;
 
 private:
   const Symbol *addDeclaration(const NamedDecl &, SymbolID);
   void addDefinition(const 

[PATCH] D51507: Allow all supportable attributes to be used with #pragma clang attribute.

2018-08-31 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: test/Misc/pragma-attribute-supported-attributes-list.test:50
 // CHECK-NEXT: EnumExtensibility (SubjectMatchRule_enum)
+// CHECK-NEXT: ExtVectorType (SubjectMatchRule_type_alias)
 // CHECK-NEXT: ExternalSourceSymbol ((SubjectMatchRule_record, 
SubjectMatchRule_enum, SubjectMatchRule_enum_constant, SubjectMatchRule_field, 
SubjectMatchRule_function, SubjectMatchRule_namespace, 
SubjectMatchRule_objc_category, SubjectMatchRule_objc_interface, 
SubjectMatchRule_objc_method, SubjectMatchRule_objc_property, 
SubjectMatchRule_objc_protocol, SubjectMatchRule_record, 
SubjectMatchRule_type_alias, SubjectMatchRule_variable))

dexonsmith wrote:
> rsmith wrote:
> > I think `__attribute__((ext_vector_type))` is a good candidate to *not* 
> > have `#pragma clang attribute` support. A type modifier like this really 
> > should only be declared as part of declaring the type. Opinions?
> The same argument might hold for most type attributes.  I have trouble 
> imagining someone using this, but it's also hard to see how supporting it 
> would lead to bugs in user code.  It seems a bit simpler to support 
> everything.
> 
> I don't have a strong opinion though.
I don't think `#pragma clang attribute` should apply to types -- types show up 
in far too many places and attributes on types changes the fundamental meaning 
of types a bit too much for my tastes. I'd prefer users annotate the type 
directly.


Repository:
  rC Clang

https://reviews.llvm.org/D51507



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


[PATCH] D51192: Fix reported range of partial token replacement

2018-08-31 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

I think the fix generally looks good, but can you please add some test coverage 
for the change?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D51192



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


Re: [PATCH] D51473: Improve attribute documentation to list which spellings are used in which syntaxes.

2018-08-31 Thread Aaron Ballman via cfe-commits
On Thu, Aug 30, 2018 at 4:12 PM, Richard Smith  wrote:
> On Thu, 30 Aug 2018 at 12:27, Aaron Ballman via cfe-commits
>  wrote:
>>
>> On Thu, Aug 30, 2018 at 3:21 PM, Richard Smith - zygoloid via
>> Phabricator  wrote:
>> > rsmith marked an inline comment as done.
>> > rsmith added inline comments.
>> >
>> >
>> > 
>> > Comment at: utils/TableGen/ClangAttrEmitter.cpp:3881
>> > +SpellingKind K = (SpellingKind)Kind;
>> > +// FIXME: Why are Microsoft spellings not listed?
>> > +if (K == SpellingKind::Microsoft)
>> > 
>> > aaron.ballman wrote:
>> >> We don't actually support Microsoft's attribute spellings currently and
>> >> have no attributes there to document. I think the fixme should probably 
>> >> read
>> >> "TODO: support documenting Microsoft spellings" or something more 
>> >> concrete.
>> > Done. (I accidentally pushed the old version, so this is done in
>> > r341100.)
>> >
>> > For what it's worth, we have one `Microsoft` spelling listed in the .td
>> > file already (but I assume this has no effect):
>> >
>> > ```
>> > def Uuid : InheritableAttr {
>> >   let Spellings = [Declspec<"uuid">, Microsoft<"uuid">];
>> > ```
>>
>> Hmm, I take it back, we do support a Microsoft attribute, only to warn
>> about it being deprecated and telling users to use __declspec instead:
>> https://godbolt.org/z/_0ZxWq
>>
>> I remember when we tried to add more support for parsing Microsoft
>> attributes, but I had the impression we didn't support them beyond the
>> very basics of parsing. Perhaps we do want to document them though,
>> since there's at least one?
>
>
> Given that doing so will make the "supported syntaxes" table wider for all
> attributes, and it's already about as wide as seems reasonable, and we
> consider all attributes of this form to be deprecated, I don't think it's
> worth it. Maybe if we only included non-empty columns in the syntax table?

I think for right now I'd prefer to keep a consistent syntax table
layout. It makes it easier to visually scan for information when all
the columns roughly line up vertically, and we only support this one
spelling just to tell users not to use it anyway. We can try out the
column approach later if we find need.

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


[PATCH] D51333: Diagnose likely typos in include statements

2018-08-31 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In https://reviews.llvm.org/D51333#1219938, @rsmith wrote:

> Instead of guessing whether the corrected filename would be valid, why not 
> strip off the leading and trailing non-alphanumeric characters, look up the 
> resulting filename, and find out? If we did that, then not only could we be a 
> lot more confident that we'd found the file that was intended, but we could 
> also recover from the error by including the trimmed filename.


I was contemplating that approach, but I was also a bit worried about reaching 
out to the filesystem again. We already reach out once for angled vs quoted 
include path issues, and I don't think these two tests can be combined easily. 
However, this is on an error path and so performance isn't super important, so 
I think I've convinced myself this is a good approach to try.


https://reviews.llvm.org/D51333



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


[PATCH] D51481: [clangd] Implement proximity path boosting for Dex

2018-08-31 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 163507.
kbobyrev added a comment.

Canonicalize URIs, slightly simplify code structure.


https://reviews.llvm.org/D51481

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/index/dex/DexIndex.cpp
  clang-tools-extra/clangd/index/dex/DexIndex.h
  clang-tools-extra/clangd/index/dex/Token.h
  clang-tools-extra/clangd/tool/ClangdMain.cpp
  clang-tools-extra/unittests/clangd/DexIndexTests.cpp
  clang-tools-extra/unittests/clangd/TestFS.cpp
  clang-tools-extra/unittests/clangd/TestFS.h

Index: clang-tools-extra/unittests/clangd/TestFS.h
===
--- clang-tools-extra/unittests/clangd/TestFS.h
+++ clang-tools-extra/unittests/clangd/TestFS.h
@@ -59,7 +59,7 @@
 };
 
 // Returns an absolute (fake) test directory for this OS.
-const char *testRoot();
+std::string testRoot();
 
 // Returns a suitable absolute path for this OS.
 std::string testPath(PathRef File);
Index: clang-tools-extra/unittests/clangd/TestFS.cpp
===
--- clang-tools-extra/unittests/clangd/TestFS.cpp
+++ clang-tools-extra/unittests/clangd/TestFS.cpp
@@ -64,7 +64,7 @@
   FileName, std::move(CommandLine), "")};
 }
 
-const char *testRoot() {
+std::string testRoot() {
 #ifdef _WIN32
   return "C:\\clangd-test";
 #else
Index: clang-tools-extra/unittests/clangd/DexIndexTests.cpp
===
--- clang-tools-extra/unittests/clangd/DexIndexTests.cpp
+++ clang-tools-extra/unittests/clangd/DexIndexTests.cpp
@@ -7,6 +7,8 @@
 //
 //===--===//
 
+#include "FuzzyMatch.h"
+#include "TestFS.h"
 #include "TestIndex.h"
 #include "index/Index.h"
 #include "index/Merge.h"
@@ -29,6 +31,8 @@
 namespace dex {
 namespace {
 
+std::vector URISchemes = {"unittest"};
+
 std::vector consumeIDs(Iterator ) {
   auto IDAndScore = consume(It);
   std::vector IDs(IDAndScore.size());
@@ -325,14 +329,33 @@
 }
 
 testing::Matcher>
-trigramsAre(std::initializer_list Trigrams) {
+tokensAre(std::initializer_list Strings, Token::Kind Kind) {
   std::vector Tokens;
-  for (const auto  : Trigrams) {
-Tokens.push_back(Token(Token::Kind::Trigram, Symbols));
+  for (const auto  : Strings) {
+Tokens.push_back(Token(Kind, TokenData));
   }
   return testing::UnorderedElementsAreArray(Tokens);
 }
 
+testing::Matcher>
+trigramsAre(std::initializer_list Trigrams) {
+  return tokensAre(Trigrams, Token::Kind::Trigram);
+}
+
+testing::Matcher>
+pathsAre(std::initializer_list Paths) {
+  return tokensAre(Paths, Token::Kind::Path);
+}
+
+testing::Matcher>> proximityPathsAre(
+std::initializer_list> ProximityPaths) {
+  std::vector> Result;
+  for (const auto  : ProximityPaths) {
+Result.push_back({Token(Token::Kind::Path, P.first), P.second});
+  }
+  return testing::UnorderedElementsAreArray(Result);
+}
+
 TEST(DexIndexTrigrams, IdentifierTrigrams) {
   EXPECT_THAT(generateIdentifierTrigrams("X86"),
   trigramsAre({"x86", "x$$", "x8$"}));
@@ -407,9 +430,29 @@
"hij", "ijk", "jkl", "klm"}));
 }
 
+TEST(DexSearchTokens, SymbolPath) {
+  EXPECT_THAT(generateProximityPaths(
+  "unittest:///clang-tools-extra/clangd/index/dex/Token.h"),
+  pathsAre({"unittest:clang-tools-extra/clangd/index/dex/",
+"unittest:clang-tools-extra/clangd/index/",
+"unittest:clang-tools-extra/clangd/",
+"unittest:clang-tools-extra/",
+"unittest:"}));
+}
+
+TEST(DexSearchTokens, QueryProximityDistances) {
+  EXPECT_THAT(
+  generateQueryProximityPaths(testRoot() + "/a/b/c/d/e/f/g.h", URISchemes),
+  proximityPathsAre({{"unittest:a/b/c/d/e/f/", 0},
+ {"unittest:a/b/c/d/e/", 1},
+ {"unittest:a/b/c/d/", 2},
+ {"unittest:a/b/c/", 3},
+ {"unittest:a/b/", 4}}));
+}
+
 TEST(DexIndex, Lookup) {
   DexIndex I;
-  I.build(generateSymbols({"ns::abc", "ns::xyz"}));
+  I.build(generateSymbols({"ns::abc", "ns::xyz"}), URISchemes);
   EXPECT_THAT(lookup(I, SymbolID("ns::abc")), UnorderedElementsAre("ns::abc"));
   EXPECT_THAT(lookup(I, {SymbolID("ns::abc"), SymbolID("ns::xyz")}),
   UnorderedElementsAre("ns::abc", "ns::xyz"));
@@ -421,7 +464,8 @@
 TEST(DexIndex, FuzzyFind) {
   DexIndex Index;
   Index.build(generateSymbols({"ns::ABC", "ns::BCD", "::ABC", "ns::nested::ABC",
-   "other::ABC", "other::A"}));
+   "other::ABC", "other::A"}),
+  URISchemes);
   FuzzyFindRequest Req;
   Req.Query = "ABC";
   Req.Scopes = {"ns::"};
@@ -444,7 +488,8 @@
 TEST(DexIndexTest, FuzzyMatchQ) {
   DexIndex I;
   I.build(
-  generateSymbols({"LaughingOutLoud", "LionPopulation", 

[PATCH] D51356: [docs][mips] Clang 7.0 Release notes

2018-08-31 Thread Simon Atanasyan via Phabricator via cfe-commits
atanasyan added a comment.

Thanks for review.


Repository:
  rL LLVM

https://reviews.llvm.org/D51356



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


[PATCH] D51356: [docs][mips] Clang 7.0 Release notes

2018-08-31 Thread Simon Atanasyan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL341201: [docs][mips] Clang 7.0 Release notes (authored by 
atanasyan, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D51356?vs=162850=163501#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D51356

Files:
  cfe/branches/release_70/docs/ReleaseNotes.rst


Index: cfe/branches/release_70/docs/ReleaseNotes.rst
===
--- cfe/branches/release_70/docs/ReleaseNotes.rst
+++ cfe/branches/release_70/docs/ReleaseNotes.rst
@@ -114,6 +114,12 @@
   relocation scanning. The ``-faddrsig`` and ``-fno-addrsig`` flags can be
   used to control whether to emit the address-significance table.
 
+- Integrated assembler is enabled by default on OpenBSD / FreeBSD
+  for MIPS 64-bit targets.
+
+- On MIPS FreeBSD default CPUs have been changed to ``mips2``
+  for 32-bit targets and ``mips3`` for 64-bit targets.
+
 - ...
 
 New Compiler Flags
@@ -133,6 +139,15 @@
modules where it isn't necessary. It causes more inline virtual functions
to be emitted.
 
+- Added the``-mcrc`` and ``-mno-crc`` flags to enable/disable using
+  of MIPS Cyclic Redundancy Check instructions.
+
+- Added the``-mvirt`` and ``-mno-virt`` flags to enable/disable using
+  of MIPS Virtualization instructions.
+
+- Added the``-mginv`` and ``-mno-ginv`` flags to enable/disable using
+  of MIPS Global INValidate instructions.
+
 - ...
 
 Deprecated Compiler Flags


Index: cfe/branches/release_70/docs/ReleaseNotes.rst
===
--- cfe/branches/release_70/docs/ReleaseNotes.rst
+++ cfe/branches/release_70/docs/ReleaseNotes.rst
@@ -114,6 +114,12 @@
   relocation scanning. The ``-faddrsig`` and ``-fno-addrsig`` flags can be
   used to control whether to emit the address-significance table.
 
+- Integrated assembler is enabled by default on OpenBSD / FreeBSD
+  for MIPS 64-bit targets.
+
+- On MIPS FreeBSD default CPUs have been changed to ``mips2``
+  for 32-bit targets and ``mips3`` for 64-bit targets.
+
 - ...
 
 New Compiler Flags
@@ -133,6 +139,15 @@
modules where it isn't necessary. It causes more inline virtual functions
to be emitted.
 
+- Added the``-mcrc`` and ``-mno-crc`` flags to enable/disable using
+  of MIPS Cyclic Redundancy Check instructions.
+
+- Added the``-mvirt`` and ``-mno-virt`` flags to enable/disable using
+  of MIPS Virtualization instructions.
+
+- Added the``-mginv`` and ``-mno-ginv`` flags to enable/disable using
+  of MIPS Global INValidate instructions.
+
 - ...
 
 Deprecated Compiler Flags
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D51057: [analyzer][UninitializedObjectChecker] Fixed dereferencing

2018-08-31 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus updated this revision to Diff 163499.
Szelethus added a comment.

Reuploaded with `-U9`. Oops.


https://reviews.llvm.org/D51057

Files:
  lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h
  lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
  lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
  test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
  test/Analysis/objcpp-uninitialized-object.mm

Index: test/Analysis/objcpp-uninitialized-object.mm
===
--- test/Analysis/objcpp-uninitialized-object.mm
+++ test/Analysis/objcpp-uninitialized-object.mm
@@ -4,7 +4,7 @@
 
 struct StructWithBlock {
   int a;
-  myBlock z; // expected-note{{uninitialized pointer 'this->z'}}
+  myBlock z; // expected-note{{uninitialized field 'this->z'}}
 
   StructWithBlock() : a(0), z(^{}) {}
 
Index: test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
===
--- test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
+++ test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
@@ -46,6 +46,50 @@
 }
 
 //===--===//
+// Alloca tests.
+//===--===//
+
+struct UntypedAllocaTest {
+  void *allocaPtr;
+  int dontGetFilteredByNonPedanticMode = 0;
+
+  UntypedAllocaTest() : allocaPtr(__builtin_alloca(sizeof(int))) {
+// All good!
+  }
+};
+
+void fUntypedAllocaTest() {
+  UntypedAllocaTest();
+}
+
+struct TypedAllocaTest1 {
+  int *allocaPtr; // expected-note{{uninitialized pointee 'this->allocaPtr'}}
+  int dontGetFilteredByNonPedanticMode = 0;
+
+  TypedAllocaTest1() // expected-warning{{1 uninitialized field}}
+  : allocaPtr(static_cast(__builtin_alloca(sizeof(int {}
+};
+
+void fTypedAllocaTest1() {
+  TypedAllocaTest1();
+}
+
+struct TypedAllocaTest2 {
+  int *allocaPtr;
+  int dontGetFilteredByNonPedanticMode = 0;
+
+  TypedAllocaTest2()
+  : allocaPtr(static_cast(__builtin_alloca(sizeof(int {
+*allocaPtr = 5;
+// All good!
+  }
+};
+
+void fTypedAllocaTest2() {
+  TypedAllocaTest2();
+}
+
+//===--===//
 // Heap pointer tests.
 //===--===//
 
@@ -203,18 +247,14 @@
   CyclicPointerTest1();
 }
 
-// TODO: Currently, the checker ends up in an infinite loop for the following
-// test case.
-/*
 struct CyclicPointerTest2 {
-  int **pptr;
+  int **pptr; // no-crash
   CyclicPointerTest2() : pptr(reinterpret_cast()) {}
 };
 
 void fCyclicPointerTest2() {
   CyclicPointerTest2();
 }
-*/
 
 //===--===//
 // Void pointer tests.
@@ -471,6 +511,39 @@
 }
 
 //===--===//
+// Incomplete pointee tests.
+//===--===//
+
+class IncompleteType;
+
+struct IncompletePointeeTypeTest {
+  IncompleteType *pImpl; //no-crash
+  int dontGetFilteredByNonPedanticMode = 0;
+
+  IncompletePointeeTypeTest(IncompleteType *A) : pImpl(A) {}
+};
+
+void fIncompletePointeeTypeTest(void *ptr) {
+  IncompletePointeeTypeTest(reinterpret_cast(ptr));
+}
+
+//===--===//
+// Function pointer tests.
+//===--===//
+
+struct FunctionPointerWithDifferentDynTypeTest {
+  using Func1 = void *(*)();
+  using Func2 = int *(*)();
+
+  Func1 f; // no-crash
+  FunctionPointerWithDifferentDynTypeTest(Func2 f) : f((Func1)f) {}
+};
+
+// Note that there isn't a function calling the constructor of
+// FunctionPointerWithDifferentDynTypeTest, because a crash could only be
+// reproduced without it.
+
+//===--===//
 // Member pointer tests.
 //===--===//
 
@@ -645,6 +718,15 @@
   CyclicList(, int());
 }
 
+struct RingListTest {
+  RingListTest *next; // no-crash
+  RingListTest() : next(this) {}
+};
+
+void fRingListTest() {
+  RingListTest();
+}
+
 //===--===//
 // Tests for classes containing references.
 //===--===//
Index: lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
===
--- lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
+++ lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
@@ -95,11 +95,13 @@
 /// known, and thus FD can not be analyzed.
 static bool 

[PATCH] D51279: [clangd] Implement findOccurrences interface in dynamic index.

2018-08-31 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

This basically looks good to go (some fixes needed but they're pretty clear I 
think let me know if not!)




Comment at: clangd/index/FileIndex.cpp:63
+  auto Occurrences = Collector.takeOccurrences();
+  vlog("index for AST: \n"
+   "  symbol slab: {0} symbols, {1} bytes\n"

for this log to be useful, you might want to include the filename.
You can get it from the sourcemanager on the ASTContext.



Comment at: clangd/index/MemIndex.cpp:35
 
 std::unique_ptr MemIndex::build(SymbolSlab Slab) {
   auto Idx = llvm::make_unique();

This is still implicitly creating an index with no occurrences. Did you mean to 
accept a SymbolOccurrencesSlab here?



Comment at: clangd/index/MemIndex.h:23
 public:
-  /// \brief (Re-)Build index for `Symbols`. All symbol pointers must remain
-  /// accessible as long as `Symbols` is kept alive.
-  void build(std::shared_ptr> Symbols);
+  using OccurrenceMap =
+  llvm::DenseMap>;

can you add an explanation to this?



Comment at: clangd/index/Merge.cpp:94
+// instead.
+llvm::DenseSet DynamicIndexFileURIs;
+Dynamic->findOccurrences(Req, [&](const SymbolOccurrence ) {

Unfortunately this is not safe, the backing strings may not live long enough.
This should be a StringSet (by value) instead.



Comment at: clangd/index/Merge.cpp:100
+Static->findOccurrences(Req, [&](const SymbolOccurrence ) {
+  if (DynamicIndexFileURIs.find(O.Location.FileURI) !=
+  DynamicIndexFileURIs.end())

or just DynamicIndexFileURIs.count(O.Location.FileURI) and rely on the implicit 
conversion to bool



Comment at: clangd/index/SymbolCollector.cpp:227
 
+SymbolOccurrenceKind ToOccurrenceKind(index::SymbolRoleSet Roles) {
+  SymbolOccurrenceKind Kind;

toOccurrenceKind

isn't this just 

`return Roles & AllOccurrenceKinds` with some casts?
(I'd put AllOccurrenceKinds into the header, but it could also be a constant 
here)



Comment at: clangd/index/SymbolCollector.h:120
+
+  using DeclOccurrence = std::pair;
+  llvm::DenseMap> 
DeclOccurrences;

move these up next to ReferencedDecls and ReferencedMacros so the comment 
applies to them too?

Similarly, move SymbolOccurrenceSlab next to the SymbolSlab::Builder? These 
have strong parallels.



Comment at: clangd/index/SymbolCollector.h:122
+  llvm::DenseMap> 
DeclOccurrences;
+  // All symbol occurrences collected from the AST, assembled on finish().
+  // Only symbols declared in preamble (from #inclues) and references from the

I'm not sure this works - IIRC can use a SymbolCollector for multiple TUs, with 
finish() called at the end of each one.
I think you need to (incrementally) build in finish(), and freeze in 
takeOccurrences().



Comment at: unittests/clangd/TestTU.h:41
 
+  static TestTU withAllCode(llvm::StringRef HeaderCode, llvm::StringRef Code,
+llvm::StringRef Filename = "") {

We've avoided adding this in the past because it's less readable. Please assign 
the fields separately instead.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D51279



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


[PATCH] D51507: Allow all supportable attributes to be used with #pragma clang attribute.

2018-08-31 Thread Kristina Brooks via Phabricator via cfe-commits
kristina added a comment.

Giving it a second glance, just as an idea, maybe it's better to leave ObjC 
pragmas out for now, for another more narrower-scope revision/review specific 
to ObjC(/Swift)? Since they could cause incorrect code generation if combined 
in odd ways (as well as making no sense) especially with Automatic Reference 
Counting. For example a function annotated as returning a retained object while 
at the same time returning with release, and also a bridge annotation, may just 
miss the sema check and fail at runtime instead, which could be fairly erratic 
as it may vary depending on the `autoreleasepool` state as well as the runtime 
being used and could turn into a difficult bug to debug if it ever happened in 
the wild. I think semantic checker should catch the non-ObjC cases but only 
some ObjC cases. Another concern is Swift with Apple runtime and ObjC <=> Swift 
bridged objects (when Swift classes inherit ObjC classes or even interact with 
them) may introduce even more complications, and Swift patches and integration 
doesn't happen as part of mainline LLVM development, which complicates code 
review. Rest of it looks good however, not sure what you want to to do with the 
ObjC pragmas, they could be left in and re-reviewed later since that would mean 
they would end up in Swift development integration tree too.


Repository:
  rC Clang

https://reviews.llvm.org/D51507



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


[PATCH] D50783: [CodeGen] Merge identical block descriptor global variables

2018-08-31 Thread David Chisnall via Phabricator via cfe-commits
theraven added inline comments.



Comment at: lib/CodeGen/CGBlocks.cpp:163
+  std::string TypeAtEncoding =
+  CGM.getContext().getObjCEncodingForBlock(BlockInfo.getBlockExpr());
+  Name += "e" + llvm::to_string(TypeAtEncoding.size()) + "_" + TypeAtEncoding;

Specifically, this line.  It is unsafe to use an Objective-C encoding directly 
as a symbol name on ELF.


Repository:
  rC Clang

https://reviews.llvm.org/D50783



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


[PATCH] D50783: [CodeGen] Merge identical block descriptor global variables

2018-08-31 Thread David Chisnall via Phabricator via cfe-commits
theraven added a comment.

This revision broke blocks on all ELF targets.  The block descriptors' symbol 
names can now include the @ character, which is reserved on ELF platforms as a 
separator between symbol name and symbol version.  As a result, nothing 
containing a block that has an Objective-C object argument will link.  Please 
add mangling similar to that in the GNUstep runtime to avoid this.


Repository:
  rC Clang

https://reviews.llvm.org/D50783



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


[PATCH] D51422: [clangd] Factor out the data-swapping functionality from MemIndex/DexIndex.

2018-08-31 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev added inline comments.



Comment at: clangd/index/Index.h:416
+  // until the call returns (even if reset() is called).
+  bool fuzzyFind(const FuzzyFindRequest &,
+ llvm::function_ref) const override;

Do we want these functions to be `final`? Since `SwapIndex` is a wrapper around 
an immutable index structure, I believe it would be unlikely that anything 
would derive from it.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D51422



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


[PATCH] D51533: [ASTImporter] Merge ExprBits

2018-08-31 Thread Gabor Marton via Phabricator via cfe-commits
martong created this revision.
martong added reviewers: a_sidorin, r.stahl, xazax.hun.
Herald added subscribers: cfe-commits, dkrupp, rnkovacs.
Herald added a reviewer: a.sidorin.

Some `Expr` classes set up default values for the `ExprBits` of `Stmt`.  These
default values are then overwritten by the parser sometimes.  One example is
`InitListExpr` which sets the value kind to be an rvalue in the ctor.  However,
this bit may change after the `InitListExpr` is created.  There may be other
expressions similar to `InitListExpr` in this sense, thus the safest solution
is to copy the expression bits.

The lack of copying `ExprBits` causes an assertion in the analyzer engine in a
specific case: Since the value kind is not imported, the analyzer engine
believes that the given InitListExpr is an rvalue, thus it creates a
nonloc::CompoundVal instead of creating memory region (as in case of an lvalue
reference).


Repository:
  rC Clang

https://reviews.llvm.org/D51533

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


Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -3225,6 +3225,25 @@
   
unless(classTemplatePartialSpecializationDecl();
 }
 
+TEST_P(ASTImporterTestBase, InitListExprValueKindShouldBeImported) {
+  Decl *TU = getTuDecl(
+  R"(
+  const int ();
+  void foo() { const int {init()}; }
+  )", Lang_CXX11, "input0.cc");
+  auto *FromD = FirstDeclMatcher().match(TU, varDecl(hasName("a")));
+  ASSERT_TRUE(FromD->getAnyInitializer());
+  auto *InitExpr = FromD->getAnyInitializer();
+  ASSERT_TRUE(InitExpr);
+  ASSERT_TRUE(InitExpr->isGLValue());
+
+  auto *ToD = Import(FromD, Lang_CXX11);
+  ASSERT_TRUE(ToD);
+  auto *ToInitExpr = cast(ToD)->getAnyInitializer();
+  ASSERT_TRUE(ToInitExpr);
+  EXPECT_TRUE(ToInitExpr->isGLValue());
+}
+
 struct DeclContextTest : ASTImporterTestBase {};
 
 TEST_P(DeclContextTest, removeDeclOfClassTemplateSpecialization) {
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -6849,9 +6849,9 @@
 To->setSyntacticForm(ToSyntForm);
   }
 
+  // Copy InitListExprBitfields, which are not handled in the ctor of
+  // InitListExpr.
   To->sawArrayRangeDesignator(ILE->hadArrayRangeDesignator());
-  To->setValueDependent(ILE->isValueDependent());
-  To->setInstantiationDependent(ILE->isInstantiationDependent());
 
   return To;
 }
@@ -7196,6 +7196,19 @@
   if (!ToS)
 return nullptr;
 
+  if (auto *ToE = dyn_cast(ToS)) {
+auto *FromE = cast(FromS);
+// Copy ExprBitfields, which may not be handled in Expr subclasses
+// constructors.
+ToE->setValueKind(FromE->getValueKind());
+ToE->setObjectKind(FromE->getObjectKind());
+ToE->setTypeDependent(FromE->isTypeDependent());
+ToE->setValueDependent(FromE->isValueDependent());
+ToE->setInstantiationDependent(FromE->isInstantiationDependent());
+ToE->setContainsUnexpandedParameterPack(
+FromE->containsUnexpandedParameterPack());
+  }
+
   // Record the imported declaration.
   ImportedStmts[FromS] = ToS;
   return ToS;


Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -3225,6 +3225,25 @@
   unless(classTemplatePartialSpecializationDecl();
 }
 
+TEST_P(ASTImporterTestBase, InitListExprValueKindShouldBeImported) {
+  Decl *TU = getTuDecl(
+  R"(
+  const int ();
+  void foo() { const int {init()}; }
+  )", Lang_CXX11, "input0.cc");
+  auto *FromD = FirstDeclMatcher().match(TU, varDecl(hasName("a")));
+  ASSERT_TRUE(FromD->getAnyInitializer());
+  auto *InitExpr = FromD->getAnyInitializer();
+  ASSERT_TRUE(InitExpr);
+  ASSERT_TRUE(InitExpr->isGLValue());
+
+  auto *ToD = Import(FromD, Lang_CXX11);
+  ASSERT_TRUE(ToD);
+  auto *ToInitExpr = cast(ToD)->getAnyInitializer();
+  ASSERT_TRUE(ToInitExpr);
+  EXPECT_TRUE(ToInitExpr->isGLValue());
+}
+
 struct DeclContextTest : ASTImporterTestBase {};
 
 TEST_P(DeclContextTest, removeDeclOfClassTemplateSpecialization) {
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -6849,9 +6849,9 @@
 To->setSyntacticForm(ToSyntForm);
   }
 
+  // Copy InitListExprBitfields, which are not handled in the ctor of
+  // InitListExpr.
   To->sawArrayRangeDesignator(ILE->hadArrayRangeDesignator());
-  To->setValueDependent(ILE->isValueDependent());
-  To->setInstantiationDependent(ILE->isInstantiationDependent());
 
   return To;
 }
@@ -7196,6 +7196,19 @@
   if (!ToS)
 return nullptr;
 
+  if (auto *ToE = dyn_cast(ToS)) {
+auto *FromE = cast(FromS);
+// Copy 

[PATCH] D51475: [clangd] Load YAML static index asynchronously.

2018-08-31 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev added inline comments.



Comment at: clangd/tool/ClangdMain.cpp:48
+// loading.
+class AsyncLoadIndex : public SymbolIndex {
+public:

Also, do we want only static index to be built asynchronously? Do we want it to 
be used only in our Clangd tool driver? Loading dynamic index might also be 
useful if we have this kind of behavior for the static one. I'm not completely 
sure about that, though.



Comment at: clangd/tool/ClangdMain.cpp:78
 
-  return UseDex ? dex::DexIndex::build(std::move(SymsBuilder).build())
-: MemIndex::build(std::move(SymsBuilder).build());
+  size_t estimateMemoryUsage() const override { return 0; }
+

Shouldn't this `index()->estimateMemoryUsage()` when the index is built?



Comment at: clangd/tool/ClangdMain.cpp:102
+// that all symbols can be managed in memory.
+std::unique_ptr buildStaticIndex(llvm::StringRef YamlSymbolFile) {
+  return llvm::make_unique(

Do we want to be more explicit about loading index asynchronously? If we're not 
that fact might be implicit to the user (e.g. "my Clangd is not frozen, but 
global completion doesn't work"), CLI flag/documentation entry might solve that 
issue. Introducing tons of not-so-useful flags is not optimal, though, and I'm 
also not sure about that.

What do you think?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D51475



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


[PATCH] D51528: [NFC] Cleanup Dex

2018-08-31 Thread Kirill Bobyrev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL341190: [NFC] Cleanup Dex (authored by omtcyfz, committed by 
).
Herald added subscribers: llvm-commits, ilya-biryukov.

Changed prior to commit:
  https://reviews.llvm.org/D51528?vs=163485=163489#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D51528

Files:
  clang-tools-extra/trunk/clangd/index/dex/DexIndex.cpp
  clang-tools-extra/trunk/clangd/index/dex/DexIndex.h
  clang-tools-extra/trunk/clangd/index/dex/Iterator.cpp
  clang-tools-extra/trunk/clangd/index/dex/Trigram.cpp

Index: clang-tools-extra/trunk/clangd/index/dex/DexIndex.h
===
--- clang-tools-extra/trunk/clangd/index/dex/DexIndex.h
+++ clang-tools-extra/trunk/clangd/index/dex/DexIndex.h
@@ -41,7 +41,7 @@
 public:
   /// \brief (Re-)Build index for `Symbols`. All symbol pointers must remain
   /// accessible as long as `Symbols` is kept alive.
-  void build(std::shared_ptr> Symbols);
+  void build(std::shared_ptr> Syms);
 
   /// \brief Build index from a symbol slab.
   static std::unique_ptr build(SymbolSlab Slab);
Index: clang-tools-extra/trunk/clangd/index/dex/Iterator.cpp
===
--- clang-tools-extra/trunk/clangd/index/dex/Iterator.cpp
+++ clang-tools-extra/trunk/clangd/index/dex/Iterator.cpp
@@ -30,23 +30,26 @@
 
   /// Advances cursor to the next item.
   void advance() override {
-assert(!reachedEnd() && "DocumentIterator can't advance at the end.");
+assert(!reachedEnd() && "DOCUMENT iterator can't advance() at the end.");
 ++Index;
   }
 
   /// Applies binary search to advance cursor to the next item with DocID equal
   /// or higher than the given one.
   void advanceTo(DocID ID) override {
-assert(!reachedEnd() && "DocumentIterator can't advance at the end.");
+assert(!reachedEnd() && "DOCUMENT iterator can't advance() at the end.");
 Index = std::lower_bound(Index, std::end(Documents), ID);
   }
 
   DocID peek() const override {
-assert(!reachedEnd() && "DocumentIterator can't call peek() at the end.");
+assert(!reachedEnd() && "DOCUMENT iterator can't peek() at the end.");
 return *Index;
   }
 
-  float consume() override { return DEFAULT_BOOST_SCORE; }
+  float consume() override {
+assert(!reachedEnd() && "DOCUMENT iterator can't consume() at the end.");
+return DEFAULT_BOOST_SCORE;
+  }
 
   size_t estimateSize() const override { return Documents.size(); }
 
@@ -84,7 +87,7 @@
 public:
   AndIterator(std::vector> AllChildren)
   : Children(std::move(AllChildren)) {
-assert(!Children.empty() && "AndIterator should have at least one child.");
+assert(!Children.empty() && "AND iterator should have at least one child.");
 // Establish invariants.
 sync();
 // When children are sorted by the estimateSize(), sync() calls are more
@@ -105,22 +108,22 @@
 
   /// Advances all children to the next common item.
   void advance() override {
-assert(!reachedEnd() && "AndIterator can't call advance() at the end.");
+assert(!reachedEnd() && "AND iterator can't advance() at the end.");
 Children.front()->advance();
 sync();
   }
 
   /// Advances all children to the next common item with DocumentID >= ID.
   void advanceTo(DocID ID) override {
-assert(!reachedEnd() && "AndIterator can't call advanceTo() at the end.");
+assert(!reachedEnd() && "AND iterator can't advanceTo() at the end.");
 Children.front()->advanceTo(ID);
 sync();
   }
 
   DocID peek() const override { return Children.front()->peek(); }
 
   float consume() override {
-assert(!reachedEnd() && "AndIterator can't consume() at the end.");
+assert(!reachedEnd() && "AND iterator can't consume() at the end.");
 return std::accumulate(
 begin(Children), end(Children), DEFAULT_BOOST_SCORE,
 [&](float Current, const std::unique_ptr ) {
@@ -192,7 +195,7 @@
 public:
   OrIterator(std::vector> AllChildren)
   : Children(std::move(AllChildren)) {
-assert(Children.size() > 0 && "Or Iterator must have at least one child.");
+assert(Children.size() > 0 && "OR iterator must have at least one child.");
   }
 
   /// Returns true if all children are exhausted.
@@ -205,27 +208,25 @@
 
   /// Moves each child pointing to the smallest DocID to the next item.
   void advance() override {
-assert(!reachedEnd() &&
-   "OrIterator can't call advance() after it reached the end.");
+assert(!reachedEnd() && "OR iterator can't advance() at the end.");
 const auto SmallestID = peek();
 for (const auto  : Children)
   if (!Child->reachedEnd() && Child->peek() == SmallestID)
 Child->advance();
   }
 
   /// Advances each child to the next existing element with DocumentID >= ID.
   void advanceTo(DocID ID) override {
-assert(!reachedEnd() && "Can't advance iterator after it reached the end.");
+

[clang-tools-extra] r341190 - [NFC] Cleanup Dex

2018-08-31 Thread Kirill Bobyrev via cfe-commits
Author: omtcyfz
Date: Fri Aug 31 02:17:02 2018
New Revision: 341190

URL: http://llvm.org/viewvc/llvm-project?rev=341190=rev
Log:
[NFC] Cleanup Dex

* Use consistent assertion messages in iterators implementations
* Silence a bunch of clang-tidy warnings: use `emplace_back` instead of
  `push_back` where possible, make sure arguments have the same name in
  header and implementation file, use for loop over ranges where possible

Reviewed by: ioeric

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

Modified:
clang-tools-extra/trunk/clangd/index/dex/DexIndex.cpp
clang-tools-extra/trunk/clangd/index/dex/DexIndex.h
clang-tools-extra/trunk/clangd/index/dex/Iterator.cpp
clang-tools-extra/trunk/clangd/index/dex/Trigram.cpp

Modified: clang-tools-extra/trunk/clangd/index/dex/DexIndex.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/dex/DexIndex.cpp?rev=341190=341189=341190=diff
==
--- clang-tools-extra/trunk/clangd/index/dex/DexIndex.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/dex/DexIndex.cpp Fri Aug 31 02:17:02 
2018
@@ -30,7 +30,7 @@ namespace {
 // * Types
 std::vector generateSearchTokens(const Symbol ) {
   std::vector Result = generateIdentifierTrigrams(Sym.Name);
-  Result.push_back(Token(Token::Kind::Scope, Sym.Scope));
+  Result.emplace_back(Token::Kind::Scope, Sym.Scope);
   return Result;
 }
 

Modified: clang-tools-extra/trunk/clangd/index/dex/DexIndex.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/dex/DexIndex.h?rev=341190=341189=341190=diff
==
--- clang-tools-extra/trunk/clangd/index/dex/DexIndex.h (original)
+++ clang-tools-extra/trunk/clangd/index/dex/DexIndex.h Fri Aug 31 02:17:02 2018
@@ -41,7 +41,7 @@ class DexIndex : public SymbolIndex {
 public:
   /// \brief (Re-)Build index for `Symbols`. All symbol pointers must remain
   /// accessible as long as `Symbols` is kept alive.
-  void build(std::shared_ptr> Symbols);
+  void build(std::shared_ptr> Syms);
 
   /// \brief Build index from a symbol slab.
   static std::unique_ptr build(SymbolSlab Slab);

Modified: clang-tools-extra/trunk/clangd/index/dex/Iterator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/dex/Iterator.cpp?rev=341190=341189=341190=diff
==
--- clang-tools-extra/trunk/clangd/index/dex/Iterator.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/dex/Iterator.cpp Fri Aug 31 02:17:02 
2018
@@ -30,23 +30,26 @@ public:
 
   /// Advances cursor to the next item.
   void advance() override {
-assert(!reachedEnd() && "DocumentIterator can't advance at the end.");
+assert(!reachedEnd() && "DOCUMENT iterator can't advance() at the end.");
 ++Index;
   }
 
   /// Applies binary search to advance cursor to the next item with DocID equal
   /// or higher than the given one.
   void advanceTo(DocID ID) override {
-assert(!reachedEnd() && "DocumentIterator can't advance at the end.");
+assert(!reachedEnd() && "DOCUMENT iterator can't advance() at the end.");
 Index = std::lower_bound(Index, std::end(Documents), ID);
   }
 
   DocID peek() const override {
-assert(!reachedEnd() && "DocumentIterator can't call peek() at the end.");
+assert(!reachedEnd() && "DOCUMENT iterator can't peek() at the end.");
 return *Index;
   }
 
-  float consume() override { return DEFAULT_BOOST_SCORE; }
+  float consume() override {
+assert(!reachedEnd() && "DOCUMENT iterator can't consume() at the end.");
+return DEFAULT_BOOST_SCORE;
+  }
 
   size_t estimateSize() const override { return Documents.size(); }
 
@@ -84,7 +87,7 @@ class AndIterator : public Iterator {
 public:
   AndIterator(std::vector> AllChildren)
   : Children(std::move(AllChildren)) {
-assert(!Children.empty() && "AndIterator should have at least one child.");
+assert(!Children.empty() && "AND iterator should have at least one 
child.");
 // Establish invariants.
 sync();
 // When children are sorted by the estimateSize(), sync() calls are more
@@ -105,14 +108,14 @@ public:
 
   /// Advances all children to the next common item.
   void advance() override {
-assert(!reachedEnd() && "AndIterator can't call advance() at the end.");
+assert(!reachedEnd() && "AND iterator can't advance() at the end.");
 Children.front()->advance();
 sync();
   }
 
   /// Advances all children to the next common item with DocumentID >= ID.
   void advanceTo(DocID ID) override {
-assert(!reachedEnd() && "AndIterator can't call advanceTo() at the end.");
+assert(!reachedEnd() && "AND iterator can't advanceTo() at the end.");
 Children.front()->advanceTo(ID);
 sync();
   }
@@ -120,7 +123,7 @@ public:
   DocID peek() const override { return 

  1   2   >