[PATCH] D41458: [libc++][C++17] Elementary string conversions for integral types

2017-12-23 Thread Zhihao Yuan via Phabricator via cfe-commits
lichray updated this revision to Diff 128071.
lichray added a comment.

Use Marshall's method to generate digits in reversed order in generic to_chars.


Repository:
  rCXX libc++

https://reviews.llvm.org/D41458

Files:
  .gitignore
  include/charconv
  include/support/itoa/
  include/support/itoa/itoa.h
  lib/CMakeLists.txt
  src/support/itoa/
  src/support/itoa/itoa.cpp
  test/std/utilities/charconv/
  test/std/utilities/charconv/charconv.from.chars/
  test/std/utilities/charconv/charconv.from.chars/integral.bool.fail.cpp
  test/std/utilities/charconv/charconv.from.chars/integral.pass.cpp
  test/std/utilities/charconv/charconv.to.chars/
  test/std/utilities/charconv/charconv.to.chars/integral.bool.fail.cpp
  test/std/utilities/charconv/charconv.to.chars/integral.pass.cpp
  test/support/charconv_test_helpers.h

Index: test/support/charconv_test_helpers.h
===
--- /dev/null
+++ test/support/charconv_test_helpers.h
@@ -0,0 +1,233 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef SUPPORT_CHARCONV_TEST_HELPERS_H
+#define SUPPORT_CHARCONV_TEST_HELPERS_H
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "test_macros.h"
+
+using std::false_type;
+using std::true_type;
+
+template 
+constexpr auto
+is_non_narrowing(From a) -> decltype(To{a}, true_type())
+{
+return {};
+}
+
+template 
+constexpr auto
+is_non_narrowing(...) -> false_type
+{
+return {};
+}
+
+template 
+constexpr bool
+_fits_in(T, true_type /* non-narrowing*/, ...)
+{
+return true;
+}
+
+template >
+constexpr bool
+_fits_in(T v, false_type, true_type /* T signed*/, true_type /* X signed */)
+{
+return xl::lowest() <= v && v <= (xl::max)();
+}
+
+template >
+constexpr bool
+_fits_in(T v, false_type, true_type /* T signed */, false_type /* X unsigned*/)
+{
+return 0 <= v && typename std::make_unsigned::type(v) <= (xl::max)();
+}
+
+template >
+constexpr bool
+_fits_in(T v, false_type, false_type /* T unsigned */, ...)
+{
+return v <= typename std::make_unsigned::type((xl::max)());
+}
+
+template 
+constexpr bool
+fits_in(T v)
+{
+return _fits_in(v, is_non_narrowing(v), std::is_signed(),
+   std::is_signed());
+}
+
+template 
+struct to_chars_test_base
+{
+template 
+void test(T v, char const (&expect)[N], Ts... args)
+{
+using std::to_chars;
+std::to_chars_result r;
+
+constexpr size_t len = N - 1;
+static_assert(len > 0, "expected output won't be empty");
+
+if (!fits_in(v))
+return;
+
+r = to_chars(buf, buf + len - 1, X(v), args...);
+LIBCPP_ASSERT(r.ptr == buf + len - 1);
+LIBCPP_ASSERT(r.ec == std::errc::value_too_large);
+
+r = to_chars(buf, buf + sizeof(buf), X(v), args...);
+LIBCPP_ASSERT(r.ptr == buf + len);
+LIBCPP_ASSERT(r.ec == std::errc{});
+LIBCPP_ASSERT(memcmp(buf, expect, len) == 0);
+}
+
+template 
+void test_value(X v, Ts... args)
+{
+using std::to_chars;
+std::to_chars_result r;
+
+r = to_chars(buf, buf + sizeof(buf), v, args...);
+LIBCPP_ASSERT(r.ec == std::errc{});
+*r.ptr = '\0';
+
+auto a = fromchars(buf, r.ptr, args...);
+LIBCPP_ASSERT(v == a);
+
+auto ep = r.ptr - 1;
+r = to_chars(buf, ep, v, args...);
+LIBCPP_ASSERT(r.ptr == ep);
+LIBCPP_ASSERT(r.ec == std::errc::value_too_large);
+}
+
+private:
+using max_t = typename std::conditional::value, long long,
+unsigned long long>::type;
+
+static auto fromchars(char const* p, char const* ep, int base, true_type)
+-> long long
+{
+char* last;
+auto r = strtoll(p, &last, base);
+LIBCPP_ASSERT(last == ep);
+
+return r;
+}
+
+static auto fromchars(char const* p, char const* ep, int base, false_type)
+-> unsigned long long
+{
+char* last;
+auto r = strtoull(p, &last, base);
+LIBCPP_ASSERT(last == ep);
+
+return r;
+}
+
+static auto fromchars(char const* p, char const* ep, int base = 10) -> max_t
+{
+return fromchars(p, ep, base, std::is_signed());
+}
+
+char buf[100];
+};
+
+template 
+struct roundtrip_test_base
+{
+template 
+void test(T v, Ts... args)
+{
+using std::from_chars;
+using std::to_chars;
+std::from_chars_result r2;
+std::to_chars_result r;
+X x = 0xc;
+
+if (fits_in(v))
+{
+r = to_chars(buf, buf + sizeof(buf), v, args...);
+LIBCPP_ASSE

[PATCH] D41546: [clang-tidy] Adding Fuchsia checker for statically constructed objects

2017-12-23 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

Is the singleton allowed, that uses a static object in the `instance` method?


https://reviews.llvm.org/D41546



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


[PATCH] D41546: [clang-tidy] Adding Fuchsia checker for statically constructed objects

2017-12-23 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

What happens for c++98? I realize that fuchsia is c++14 but we might still 
think about not having `constexpr`.
If we just assume c++11 you can do the matching only for it. (`getLangOpts` or 
similar, see other checks for it.)


https://reviews.llvm.org/D41546



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


[PATCH] D41546: [clang-tidy] Adding Fuchsia checker for statically constructed objects

2017-12-23 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang-tidy/fuchsia/StaticallyConstructedObjectsCheck.cpp:23
+  // Match statically stored objects...
+  hasStaticStorageDuration(),
+  // ... which have C++ constructors...

The coding standard document is not very clear about what is and is not covered 
by this check. For instance, it seems it would also cover `static int i;` 
(because `i` is an object that is statically constructed).

Do you intend to cover code that has implicit static storage duration, or only 
if it's explicitly declared with the static storage specifier? For instance, 
this check currently will flag:
```
struct S { S(); }

static S s1; // Expected
S s2; // Is this expected?
extern S s3; // How about this?
```



Comment at: clang-tidy/fuchsia/StaticallyConstructedObjectsCheck.cpp:25
+  // ... which have C++ constructors...
+  hasDescendant(cxxConstructExpr(unless(
+  // ... that are not constexpr.

So things with implicit constructors that are not constexpr should also be 
caught, or only with explicit non-constexpr constructors?



Comment at: clang-tidy/fuchsia/StaticallyConstructedObjectsCheck.cpp:36
+diag(D->getLocStart(), "statically constructed objects are disallowed");
+diag(D->getLocStart(), "if possible, use a constexpr constructor instead",
+ DiagnosticIDs::Note);

This doesn't seem like a good use of a note (it would make more sense as part 
of the diagnostic). Also, shouldn't the guidance be to not use the static 
object in the first place?


https://reviews.llvm.org/D41546



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


[PATCH] D41553: Support parsing double square-bracket attributes in ObjC

2017-12-23 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman created this revision.
aaron.ballman added a reviewer: rsmith.

One plausible use for the new double square-bracket attribute support in C are 
attributes appertaining to Objective-C constructs. This patch adds parsing 
support for such attributes and exposes a handful of ObjC attributes under the 
new syntax.


https://reviews.llvm.org/D41553

Files:
  include/clang/Basic/Attr.td
  include/clang/Sema/Sema.h
  lib/Parse/ParseObjc.cpp
  lib/Sema/SemaObjCProperty.cpp
  test/Misc/ast-dump-attr.m
  test/Parser/objc-attr.m
  test/Sema/annotate.c
  utils/TableGen/ClangAttrEmitter.cpp

Index: utils/TableGen/ClangAttrEmitter.cpp
===
--- utils/TableGen/ClangAttrEmitter.cpp
+++ utils/TableGen/ClangAttrEmitter.cpp
@@ -87,6 +87,8 @@
 } else if (Variety == "Clang") {
   Ret.emplace_back("GNU", Name, "", false);
   Ret.emplace_back("CXX11", Name, "clang", false);
+  if (Spelling->getValueAsBit("IncludeC"))
+Ret.emplace_back("C2x", Name, "clang", false);
 } else
   Ret.push_back(FlattenedSpelling(*Spelling));
   }
Index: test/Sema/annotate.c
===
--- test/Sema/annotate.c
+++ test/Sema/annotate.c
@@ -1,9 +1,13 @@
-// RUN: %clang_cc1 %s -fsyntax-only -verify
+// RUN: %clang_cc1 %s -fsyntax-only -fdouble-square-bracket-attributes -verify
 
 void __attribute__((annotate("foo"))) foo(float *a) {
   __attribute__((annotate("bar"))) int x;
+  [[clang::annotate("bar")]] int x2;
   __attribute__((annotate(1))) int y; // expected-error {{'annotate' attribute requires a string}}
+  [[clang::annotate(1)]] int y2; // expected-error {{'annotate' attribute requires a string}}
   __attribute__((annotate("bar", 1))) int z; // expected-error {{'annotate' attribute takes one argument}}
+  [[clang::annotate("bar", 1)]] int z2; // expected-error {{'annotate' attribute takes one argument}}
+
   int u = __builtin_annotation(z, (char*) 0); // expected-error {{second argument to __builtin_annotation must be a non-wide string constant}}
   int v = __builtin_annotation(z, (char*) L"bar"); // expected-error {{second argument to __builtin_annotation must be a non-wide string constant}}
   int w = __builtin_annotation(z, "foo");
Index: test/Parser/objc-attr.m
===
--- test/Parser/objc-attr.m
+++ test/Parser/objc-attr.m
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -fsyntax-only -fdouble-square-bracket-attributes -triple x86_64-apple-macosx10.10.0 -verify %s
+// expected-no-diagnostics
+
+@interface NSObject
+@end
+
+@interface [[clang::objc_exception]] Foo {
+  [[clang::iboutlet]] NSObject *h;
+}
+@property [[clang::objc_returns_inner_pointer]] (readonly) void *i, *j;
+@property [[clang::iboutlet]] (readonly) NSObject *k;
+@end
+
+@protocol [[clang::objc_runtime_name("name")]] Bar;
+
+@protocol [[clang::objc_protocol_requires_explicit_implementation]] Baz
+@end
+
+@interface Quux
+-(void)g [[clang::ns_consumes_self]];
+-(void)h [[clang::ns_consumes_self]]: (int)x;
+-(void)i [[clang::ns_consumes_self]]: (int *)x [[clang::noescape]] to:(int)y;
+@end
Index: test/Misc/ast-dump-attr.m
===
--- test/Misc/ast-dump-attr.m
+++ test/Misc/ast-dump-attr.m
@@ -0,0 +1,56 @@
+// RUN: %clang_cc1 -fdouble-square-bracket-attributes -triple x86_64-apple-macosx10.10.0 -ast-dump -ast-dump-filter Test %s | FileCheck --strict-whitespace %s
+
+@interface NSObject
+@end
+
+@interface [[clang::objc_exception]] Test1 {
+// CHECK: ObjCInterfaceDecl{{.*}} Test1
+// CHECK-NEXT: ObjCExceptionAttr{{.*}}
+  [[clang::iboutlet]] NSObject *Test2;
+// CHECK: ObjCIvarDecl{{.*}} Test2
+// CHECK-NEXT: IBOutletAttr
+}
+@property [[clang::objc_returns_inner_pointer]] (readonly) void *Test3, *Test4;
+// CHECK: ObjCPropertyDecl{{.*}} Test3 'void *' readonly
+// CHECK-NEXT: ObjCReturnsInnerPointerAttr
+// CHECK-NEXT: ObjCPropertyDecl{{.*}} Test4 'void *' readonly
+// CHECK-NEXT: ObjCReturnsInnerPointerAttr
+
+@property [[clang::iboutlet]] (readonly) NSObject *Test5;
+// CHECK: ObjCPropertyDecl{{.*}} Test5 'NSObject *' readonly
+// CHECK-NEXT: IBOutletAttr
+
+// CHECK: ObjCMethodDecl{{.*}} implicit{{.*}} Test3
+// CHECK-NEXT: ObjCReturnsInnerPointerAttr
+// CHECK: ObjCMethodDecl{{.*}} implicit{{.*}} Test4
+// CHECK-NEXT: ObjCReturnsInnerPointerAttr
+// CHECK: ObjCMethodDecl{{.*}} implicit{{.*}} Test5
+// CHECK-NOT: IBOutletAttr
+@end
+
+@protocol [[clang::objc_runtime_name("name")]] Test6;
+// CHECK: ObjCProtocolDecl{{.*}} Test6
+// CHECK-NEXT: ObjCRuntimeNameAttr{{.*}} "name"
+
+@protocol [[clang::objc_protocol_requires_explicit_implementation]] Test7
+// CHECK: ObjCProtocolDecl{{.*}} Test7
+// CHECK-NEXT: ObjCExplicitProtocolImplAttr
+@end
+
+@interface Test8
+// CHECK: ObjCInterfaceDecl{{.*}} Test8
+-(void)Test9 [[clang::ns_consumes_self]];
+// CHECK: ObjCMethodDecl{{.*}} Test9 'void'
+// CHECK-NEXT: NSConsu

[PATCH] D41553: Support parsing double square-bracket attributes in ObjC

2017-12-23 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

This patch depends on https://reviews.llvm.org/D41317 for the modifications to 
the Clang<> attribute spelling.


https://reviews.llvm.org/D41553



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


[PATCH] D41553: Support parsing double square-bracket attributes in ObjC

2017-12-23 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

This appears to add attributes on some Obj-C constructs as an on-by-default 
feature in Obj-C++11 onwards; it needs review by folks more heavily involved in 
the Obj-C language design and direction to confirm that this makes sense and 
(ideally) to update the Obj-C documentation to cover this new feature.

To me, the grammar changes you're proposing look appropriate.


https://reviews.llvm.org/D41553



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


[PATCH] D40381: Parse concept definition

2017-12-23 Thread Faisal Vali via Phabricator via cfe-commits
faisalv added inline comments.



Comment at: lib/Sema/SemaTemplate.cpp:7735
+  ActOnDocumentableDecl(NewDecl);
+  CurContext->addDecl(NewDecl);
+  return NewDecl;

changyu wrote:
> faisalv wrote:
> > Why not use 'PushOnScopeChains' onto the enclosing scope?
> > Something along these lines:
> >assert(S->isTemplateParamScope() && S->getParent() && 
> > !S->getParent()->isTemplateParamScope() && "...");
> >PushOnScopeChains(NewDecl, S->getParent(),/*AddToContext*/true);
> The condition
> ```
> S->isTemplateParamScope()
> ```
> fails in this case
> ```
> template concept D1 = true; // expected-error {{expected template 
> parameter}}
> ```
> 
> `ParseTemplateDeclarationOrSpecialization` calls `ParseTemplateParameters` 
> which eventually calls `ParseNonTypeTemplateParameter`. 
> `ParseNonTypeTemplateParameter` prints the diag and fails but does not cause 
> `ParseTemplateParameters` to fail (I'm not sure why).  
> `ParseTemplateDeclarationOrSpecialization` proceeds to parse the concept 
> definition, and we get this
> 
> ```
> /home/changyu/test.cpp:1:10: error: expected template parameter
> template concept D1 = true; // expected-error {{expected template 
> parameter}}
>  ^
> clang: /home/changyu/git/llvm/tools/clang/lib/Sema/SemaTemplate.cpp:7747: 
> clang::Decl* clang::Sema::ActOnConceptDefinition(clang::Scope*, 
> clang::MultiTemplateParamsArg, clang::IdentifierInfo*, clang::SourceLocation, 
> clang::Expr*): Assertion `S->isTemplateParamScope() && "Not in template param 
> scope?"' failed.
> ```
> 
> What should we do?
I think this occurs because our template parameter list is incorrectly 
perceived as empty - i.e. once the error occurs - to continue processing errors 
clang assumes this case is an explicit-specialization and replaces the template 
parameter scope with the outer scope.  I think the thing to do here - which 
might also address the case where folks actually write 'template<> concept' is 
to actually check if template-parameter-list is empty - and emit a diagnostic 
about concepts can not be explicit specializations or some such ...

On a somewhat related note - i think the logic for signaling, handling and 
propagating failures of parsing the template parameter list might be a little 
broken (fixing which, might avoid triggering the assertion in template 
but not template<>).  I might submit a patch to fix that error handling-issue 
separately - but either way I think we should handle the 
explicit-specialization error?

Thoughts?


https://reviews.llvm.org/D40381



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


[PATCH] D41553: Support parsing double square-bracket attributes in ObjC

2017-12-23 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added reviewers: rjmccall, arphaman, ahatanak.
aaron.ballman added a comment.

In https://reviews.llvm.org/D41553#963536, @rsmith wrote:

> This appears to add attributes on some Obj-C constructs as an on-by-default 
> feature in Obj-C++11 onwards; it needs review by folks more heavily involved 
> in the Obj-C language design and direction to confirm that this makes sense 
> and (ideally) to update the Obj-C documentation to cover this new feature.


Agreed -- adding some reviewers for this language extension.


https://reviews.llvm.org/D41553



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


[PATCH] D41514: [Index] Reduce size of SymbolInfo struct.

2017-12-23 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi accepted this revision.
akyrtzi added a comment.
This revision is now accepted and ready to land.

LGTM!


Repository:
  rC Clang

https://reviews.llvm.org/D41514



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


r321409 - [NFC] Update the template-parameter parsers and analyzers to return NamedDecl (vs Decl)

2017-12-23 Thread Faisal Vali via cfe-commits
Author: faisalv
Date: Sat Dec 23 10:56:34 2017
New Revision: 321409

URL: http://llvm.org/viewvc/llvm-project?rev=321409&view=rev
Log:
[NFC] Update the template-parameter parsers and analyzers to return NamedDecl 
(vs Decl)

This patch addresses a FIXME and has the template-parameter processing 
functions return a more derived common type NamedDecl (as opposed to a type 
needlessly higher up in the inheritance hierarchy : Decl).  

Modified:
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Parse/ParseTemplate.cpp
cfe/trunk/lib/Sema/SemaTemplate.cpp

Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=321409&r1=321408&r2=321409&view=diff
==
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Sat Dec 23 10:56:34 2017
@@ -2748,10 +2748,10 @@ private:
   bool ParseTemplateParameterList(unsigned Depth,
   SmallVectorImpl &TemplateParams);
   bool isStartOfTemplateTypeParameter();
-  Decl *ParseTemplateParameter(unsigned Depth, unsigned Position);
-  Decl *ParseTypeParameter(unsigned Depth, unsigned Position);
-  Decl *ParseTemplateTemplateParameter(unsigned Depth, unsigned Position);
-  Decl *ParseNonTypeTemplateParameter(unsigned Depth, unsigned Position);
+  NamedDecl *ParseTemplateParameter(unsigned Depth, unsigned Position);
+  NamedDecl *ParseTypeParameter(unsigned Depth, unsigned Position);
+  NamedDecl *ParseTemplateTemplateParameter(unsigned Depth, unsigned Position);
+  NamedDecl *ParseNonTypeTemplateParameter(unsigned Depth, unsigned Position);
   void DiagnoseMisplacedEllipsis(SourceLocation EllipsisLoc,
  SourceLocation CorrectLoc,
  bool AlreadyHasEllipsis,

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=321409&r1=321408&r2=321409&view=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Sat Dec 23 10:56:34 2017
@@ -6064,7 +6064,7 @@ public:
   void DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl);
   TemplateDecl *AdjustDeclIfTemplate(Decl *&Decl);
 
-  Decl *ActOnTypeParameter(Scope *S, bool Typename,
+  NamedDecl *ActOnTypeParameter(Scope *S, bool Typename,
SourceLocation EllipsisLoc,
SourceLocation KeyLoc,
IdentifierInfo *ParamName,
@@ -6077,12 +6077,12 @@ public:
  SourceLocation Loc);
   QualType CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc);
 
-  Decl *ActOnNonTypeTemplateParameter(Scope *S, Declarator &D,
+  NamedDecl *ActOnNonTypeTemplateParameter(Scope *S, Declarator &D,
   unsigned Depth,
   unsigned Position,
   SourceLocation EqualLoc,
   Expr *DefaultArg);
-  Decl *ActOnTemplateTemplateParameter(Scope *S,
+  NamedDecl *ActOnTemplateTemplateParameter(Scope *S,
SourceLocation TmpLoc,
TemplateParameterList *Params,
SourceLocation EllipsisLoc,

Modified: cfe/trunk/lib/Parse/ParseTemplate.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseTemplate.cpp?rev=321409&r1=321408&r2=321409&view=diff
==
--- cfe/trunk/lib/Parse/ParseTemplate.cpp (original)
+++ cfe/trunk/lib/Parse/ParseTemplate.cpp Sat Dec 23 10:56:34 2017
@@ -372,8 +372,8 @@ bool
 Parser::ParseTemplateParameterList(unsigned Depth,
  SmallVectorImpl &TemplateParams) {
   while (1) {
-// FIXME: ParseTemplateParameter should probably just return a NamedDecl.
-if (Decl *TmpParam
+
+if (NamedDecl *TmpParam
   = ParseTemplateParameter(Depth, TemplateParams.size())) {
   TemplateParams.push_back(dyn_cast(TmpParam));
 } else {
@@ -480,7 +480,7 @@ bool Parser::isStartOfTemplateTypeParame
 ///   'class' ...[opt] identifier[opt]
 /// 'template' '<' template-parameter-list '>' 'class' identifier[opt]
 ///   = id-expression
-Decl *Parser::ParseTemplateParameter(unsigned Depth, unsigned Position) {
+NamedDecl *Parser::ParseTemplateParameter(unsigned Depth, unsigned Position) {
   if (isStartOfTemplateTypeParameter())
 return ParseTypeParameter(Depth, Position);
 
@@ -502,7 +502,7 @@ Decl *Parser::ParseTemplateParameter(uns
 /// 'class' identifier[opt] '=' type-id
 /// 'typ

r321410 - [NFC] Remove a cast rendered unnecessary by r321409

2017-12-23 Thread Faisal Vali via cfe-commits
Author: faisalv
Date: Sat Dec 23 11:27:07 2017
New Revision: 321410

URL: http://llvm.org/viewvc/llvm-project?rev=321410&view=rev
Log:
[NFC] Remove a cast rendered unnecessary by r321409

See https://reviews.llvm.org/rC321409 for additional context.


Modified:
cfe/trunk/lib/Parse/ParseTemplate.cpp

Modified: cfe/trunk/lib/Parse/ParseTemplate.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseTemplate.cpp?rev=321410&r1=321409&r2=321410&view=diff
==
--- cfe/trunk/lib/Parse/ParseTemplate.cpp (original)
+++ cfe/trunk/lib/Parse/ParseTemplate.cpp Sat Dec 23 11:27:07 2017
@@ -375,7 +375,7 @@ Parser::ParseTemplateParameterList(unsig
 
 if (NamedDecl *TmpParam
   = ParseTemplateParameter(Depth, TemplateParams.size())) {
-  TemplateParams.push_back(dyn_cast(TmpParam));
+  TemplateParams.push_back(TmpParam);
 } else {
   // If we failed to parse a template parameter, skip until we find
   // a comma or closing brace.


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


r321411 - [Index] Reduce size of SymbolInfo struct.

2017-12-23 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Sat Dec 23 11:31:24 2017
New Revision: 321411

URL: http://llvm.org/viewvc/llvm-project?rev=321411&view=rev
Log:
[Index] Reduce size of SymbolInfo struct.

Summary:
This is currently 16 bytes, the patch reduces it to 4.
(Building with clang on linux x84, I guess others are similar)

The only subfield that might need a bigger type is SymbolPropertySet,
I've moved it to the end of the struct so if it grows, SymbolInfo will
only be 8 bytes.

With a full index of namespace-scope symbols from the LLVM project (200k)
loaded into clangd, this saves ~2MB of RAM.

Reviewers: akyrtzi

Subscribers: ilya-biryukov, cfe-commits

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

Modified:
cfe/trunk/include/clang/Index/IndexSymbol.h
cfe/trunk/lib/Index/IndexSymbol.cpp
cfe/trunk/tools/libclang/CXIndexDataConsumer.cpp

Modified: cfe/trunk/include/clang/Index/IndexSymbol.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Index/IndexSymbol.h?rev=321411&r1=321410&r2=321411&view=diff
==
--- cfe/trunk/include/clang/Index/IndexSymbol.h (original)
+++ cfe/trunk/include/clang/Index/IndexSymbol.h Sat Dec 23 11:31:24 2017
@@ -56,7 +56,7 @@ enum class SymbolKind : uint8_t {
   Using,
 };
 
-enum class SymbolLanguage {
+enum class SymbolLanguage : uint8_t {
   C,
   ObjC,
   CXX,
@@ -64,7 +64,7 @@ enum class SymbolLanguage {
 };
 
 /// Language specific sub-kinds.
-enum class SymbolSubKind {
+enum class SymbolSubKind : uint8_t {
   None,
   CXXCopyConstructor,
   CXXMoveConstructor,
@@ -74,8 +74,9 @@ enum class SymbolSubKind {
   UsingValue,
 };
 
+typedef uint8_t SymbolPropertySet;
 /// Set of properties that provide additional info about a symbol.
-enum class SymbolProperty : uint8_t {
+enum class SymbolProperty : SymbolPropertySet {
   Generic   = 1 << 0,
   TemplatePartialSpecialization = 1 << 1,
   TemplateSpecialization= 1 << 2,
@@ -86,7 +87,6 @@ enum class SymbolProperty : uint8_t {
   Local = 1 << 7,
 };
 static const unsigned SymbolPropertyBitNum = 8;
-typedef unsigned SymbolPropertySet;
 
 /// Set of roles that are attributed to symbol occurrences.
 enum class SymbolRole : uint32_t {
@@ -127,8 +127,8 @@ struct SymbolRelation {
 struct SymbolInfo {
   SymbolKind Kind;
   SymbolSubKind SubKind;
-  SymbolPropertySet Properties;
   SymbolLanguage Lang;
+  SymbolPropertySet Properties;
 };
 
 SymbolInfo getSymbolInfo(const Decl *D);

Modified: cfe/trunk/lib/Index/IndexSymbol.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexSymbol.cpp?rev=321411&r1=321410&r2=321411&view=diff
==
--- cfe/trunk/lib/Index/IndexSymbol.cpp (original)
+++ cfe/trunk/lib/Index/IndexSymbol.cpp Sat Dec 23 11:31:24 2017
@@ -42,10 +42,10 @@ static bool isUnitTest(const ObjCMethodD
 
 static void checkForIBOutlets(const Decl *D, SymbolPropertySet &PropSet) {
   if (D->hasAttr()) {
-PropSet |= (unsigned)SymbolProperty::IBAnnotated;
+PropSet |= (SymbolPropertySet)SymbolProperty::IBAnnotated;
   } else if (D->hasAttr()) {
-PropSet |= (unsigned)SymbolProperty::IBAnnotated;
-PropSet |= (unsigned)SymbolProperty::IBOutletCollection;
+PropSet |= (SymbolPropertySet)SymbolProperty::IBAnnotated;
+PropSet |= (SymbolPropertySet)SymbolProperty::IBOutletCollection;
   }
 }
 
@@ -93,7 +93,7 @@ SymbolInfo index::getSymbolInfo(const De
   Info.Lang = SymbolLanguage::C;
 
   if (isFunctionLocalSymbol(D)) {
-Info.Properties |= (unsigned)SymbolProperty::Local;
+Info.Properties |= (SymbolPropertySet)SymbolProperty::Local;
   }
 
   if (const TagDecl *TD = dyn_cast(D)) {
@@ -118,17 +118,19 @@ SymbolInfo index::getSymbolInfo(const De
   if (!CXXRec->isCLike()) {
 Info.Lang = SymbolLanguage::CXX;
 if (CXXRec->getDescribedClassTemplate()) {
-  Info.Properties |= (unsigned)SymbolProperty::Generic;
+  Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic;
 }
   }
 }
 
 if (isa(D)) {
-  Info.Properties |= (unsigned)SymbolProperty::Generic;
-  Info.Properties |= 
(unsigned)SymbolProperty::TemplatePartialSpecialization;
+  Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic;
+  Info.Properties |=
+  (SymbolPropertySet)SymbolProperty::TemplatePartialSpecialization;
 } else if (isa(D)) {
-  Info.Properties |= (unsigned)SymbolProperty::Generic;
-  Info.Properties |= (unsigned)SymbolProperty::TemplateSpecialization;
+  Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic;
+  Info.Properties |=
+  (SymbolPropertySet)SymbolProperty::TemplateSpecialization;
 }
 
   } else if (auto *VD = dyn_cast(D)) {
@@ -142,15 +144,17 @@ SymbolInfo index::getSymbolInfo(const De
 
 if (isa(D)) {
   Info.Lang = SymbolLanguage::CXX;
-  Info.Properties |= (un

[PATCH] D41514: [Index] Reduce size of SymbolInfo struct.

2017-12-23 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL321411: [Index] Reduce size of SymbolInfo struct. (authored 
by sammccall, committed by ).

Repository:
  rL LLVM

https://reviews.llvm.org/D41514

Files:
  cfe/trunk/include/clang/Index/IndexSymbol.h
  cfe/trunk/lib/Index/IndexSymbol.cpp
  cfe/trunk/tools/libclang/CXIndexDataConsumer.cpp

Index: cfe/trunk/tools/libclang/CXIndexDataConsumer.cpp
===
--- cfe/trunk/tools/libclang/CXIndexDataConsumer.cpp
+++ cfe/trunk/tools/libclang/CXIndexDataConsumer.cpp
@@ -1304,11 +1304,11 @@
 
 static CXIdxEntityCXXTemplateKind
 getEntityKindFromSymbolProperties(SymbolPropertySet K) {
-  if (K & (unsigned)SymbolProperty::TemplatePartialSpecialization)
+  if (K & (SymbolPropertySet)SymbolProperty::TemplatePartialSpecialization)
 return CXIdxEntity_TemplatePartialSpecialization;
-  if (K & (unsigned)SymbolProperty::TemplateSpecialization)
+  if (K & (SymbolPropertySet)SymbolProperty::TemplateSpecialization)
 return CXIdxEntity_TemplateSpecialization;
-  if (K & (unsigned)SymbolProperty::Generic)
+  if (K & (SymbolPropertySet)SymbolProperty::Generic)
 return CXIdxEntity_Template;
   return CXIdxEntity_NonTemplate;
 }
Index: cfe/trunk/include/clang/Index/IndexSymbol.h
===
--- cfe/trunk/include/clang/Index/IndexSymbol.h
+++ cfe/trunk/include/clang/Index/IndexSymbol.h
@@ -56,15 +56,15 @@
   Using,
 };
 
-enum class SymbolLanguage {
+enum class SymbolLanguage : uint8_t {
   C,
   ObjC,
   CXX,
   Swift,
 };
 
 /// Language specific sub-kinds.
-enum class SymbolSubKind {
+enum class SymbolSubKind : uint8_t {
   None,
   CXXCopyConstructor,
   CXXMoveConstructor,
@@ -74,8 +74,9 @@
   UsingValue,
 };
 
+typedef uint8_t SymbolPropertySet;
 /// Set of properties that provide additional info about a symbol.
-enum class SymbolProperty : uint8_t {
+enum class SymbolProperty : SymbolPropertySet {
   Generic   = 1 << 0,
   TemplatePartialSpecialization = 1 << 1,
   TemplateSpecialization= 1 << 2,
@@ -86,7 +87,6 @@
   Local = 1 << 7,
 };
 static const unsigned SymbolPropertyBitNum = 8;
-typedef unsigned SymbolPropertySet;
 
 /// Set of roles that are attributed to symbol occurrences.
 enum class SymbolRole : uint32_t {
@@ -127,8 +127,8 @@
 struct SymbolInfo {
   SymbolKind Kind;
   SymbolSubKind SubKind;
-  SymbolPropertySet Properties;
   SymbolLanguage Lang;
+  SymbolPropertySet Properties;
 };
 
 SymbolInfo getSymbolInfo(const Decl *D);
Index: cfe/trunk/lib/Index/IndexSymbol.cpp
===
--- cfe/trunk/lib/Index/IndexSymbol.cpp
+++ cfe/trunk/lib/Index/IndexSymbol.cpp
@@ -42,10 +42,10 @@
 
 static void checkForIBOutlets(const Decl *D, SymbolPropertySet &PropSet) {
   if (D->hasAttr()) {
-PropSet |= (unsigned)SymbolProperty::IBAnnotated;
+PropSet |= (SymbolPropertySet)SymbolProperty::IBAnnotated;
   } else if (D->hasAttr()) {
-PropSet |= (unsigned)SymbolProperty::IBAnnotated;
-PropSet |= (unsigned)SymbolProperty::IBOutletCollection;
+PropSet |= (SymbolPropertySet)SymbolProperty::IBAnnotated;
+PropSet |= (SymbolPropertySet)SymbolProperty::IBOutletCollection;
   }
 }
 
@@ -93,7 +93,7 @@
   Info.Lang = SymbolLanguage::C;
 
   if (isFunctionLocalSymbol(D)) {
-Info.Properties |= (unsigned)SymbolProperty::Local;
+Info.Properties |= (SymbolPropertySet)SymbolProperty::Local;
   }
 
   if (const TagDecl *TD = dyn_cast(D)) {
@@ -118,17 +118,19 @@
   if (!CXXRec->isCLike()) {
 Info.Lang = SymbolLanguage::CXX;
 if (CXXRec->getDescribedClassTemplate()) {
-  Info.Properties |= (unsigned)SymbolProperty::Generic;
+  Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic;
 }
   }
 }
 
 if (isa(D)) {
-  Info.Properties |= (unsigned)SymbolProperty::Generic;
-  Info.Properties |= (unsigned)SymbolProperty::TemplatePartialSpecialization;
+  Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic;
+  Info.Properties |=
+  (SymbolPropertySet)SymbolProperty::TemplatePartialSpecialization;
 } else if (isa(D)) {
-  Info.Properties |= (unsigned)SymbolProperty::Generic;
-  Info.Properties |= (unsigned)SymbolProperty::TemplateSpecialization;
+  Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic;
+  Info.Properties |=
+  (SymbolPropertySet)SymbolProperty::TemplateSpecialization;
 }
 
   } else if (auto *VD = dyn_cast(D)) {
@@ -142,15 +144,17 @@
 
 if (isa(D)) {
   Info.Lang = SymbolLanguage::CXX;
-  Info.Properties |= (unsigned)SymbolProperty::Generic;
-  Info.Properties |= (unsigned)SymbolProperty::TemplatePartialSpecialization;
+  Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic;
+  Info.Properties |=
+  (SymbolPropertySe

[clang-tools-extra] r321412 - [clangd] Use Builder for symbol slabs, and use sorted-vector for storage

2017-12-23 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Sat Dec 23 11:38:03 2017
New Revision: 321412

URL: http://llvm.org/viewvc/llvm-project?rev=321412&view=rev
Log:
[clangd] Use Builder for symbol slabs, and use sorted-vector for storage

Summary:
This improves a few things:
 - the insert -> freeze -> read sequence is now enforced/communicated by the
   type system
 - SymbolSlab::const_iterator iterates over symbols, not over id-symbol pairs
 - we avoid permanently storing a second copy of the IDs, and the
   string map's hashtable

The slab size is now down to 21.8MB for the LLVM project.
Of this only 2.7MB is strings, the rest is #symbols * `sizeof(Symbol)`.
`sizeof(Symbol)` is currently 96, which seems too big - I think
SymbolInfo isn't efficiently packed. That's a topic for another patch!

Also added simple API to see the memory usage/#symbols of a slab, since
it seems likely we will continue to care about this.

Reviewers: ilya-biryukov

Subscribers: klimek, mgrang, cfe-commits

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

Modified:

clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
clang-tools-extra/trunk/clangd/index/FileIndex.cpp
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/clangd/index/SymbolYAML.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/SymbolCollectorTests.cpp

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=321412&r1=321411&r2=321412&view=diff
==
--- 
clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
 (original)
+++ 
clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
 Sat Dec 23 11:38:03 2017
@@ -80,16 +80,16 @@ int main(int argc, const char **argv) {
 
   // Found compilation database, we iterate all TUs from database to get all
   // symbols, and then merge them into a single SymbolSlab.
-  SymbolSlab GlobalSymbols;
+  SymbolSlab::Builder GlobalSymbols;
   std::mutex SymbolMutex;
   auto AddSymbols = [&](const SymbolSlab& NewSymbols) {
 // Synchronize set accesses.
 std::unique_lock LockGuard(SymbolMutex);
-for (auto It : NewSymbols) {
+for (auto Sym : NewSymbols) {
   // FIXME: Better handling the overlap symbols, currently we overwrite it
   // with the latest one, but we always want to good declarations (class
   // definitions, instead of forward declarations).
-  GlobalSymbols.insert(It.second);
+  GlobalSymbols.insert(Sym);
 }
   };
 
@@ -105,6 +105,6 @@ int main(int argc, const char **argv) {
 }
   }
 
-  llvm::outs() << SymbolToYAML(GlobalSymbols);
+  llvm::outs() << SymbolToYAML(std::move(GlobalSymbols).build());
   return 0;
 }

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=321412&r1=321411&r2=321412&view=diff
==
--- clang-tools-extra/trunk/clangd/index/FileIndex.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/FileIndex.cpp Sat Dec 23 11:38:03 2017
@@ -54,7 +54,7 @@ std::shared_ptrKeepAlive.push_back(FileAndSlab.second);
   for (const auto &Iter : *FileAndSlab.second)
-Snap->Pointers.push_back(&Iter.second);
+Snap->Pointers.push_back(&Iter);
 }
   }
   auto *Pointers = &Snap->Pointers;

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=321412&r1=321411&r2=321412&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Index.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Index.cpp Sat Dec 23 11:38:03 2017
@@ -13,16 +13,17 @@
 
 namespace clang {
 namespace clangd {
+using namespace llvm;
 
-SymbolID::SymbolID(llvm::StringRef USR)
-: HashValue(llvm::SHA1::hash(arrayRefFromStringRef(USR))) {}
+SymbolID::SymbolID(StringRef USR)
+: HashValue(SHA1::hash(arrayRefFromStringRef(USR))) {}
 
-llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const SymbolID &ID) {
-  OS << toHex(llvm::toStringRef(ID.HashValue));
+raw_ostream &operator<<(raw_ostream &OS, const SymbolID &ID) {
+  OS << toHex(toStringRef(ID.HashValue));
   return OS;
 }
 
-void operator>>(llvm::StringRef Str, SymbolID &ID) {
+void operator>>(StringRef Str, SymbolID 

[PATCH] D41506: [clangd] Use Builder for symbol slabs, and use sorted-vector for storage

2017-12-23 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL321412: [clangd] Use Builder for symbol slabs, and use 
sorted-vector for storage (authored by sammccall, committed by ).

Repository:
  rL LLVM

https://reviews.llvm.org/D41506

Files:
  
clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
  clang-tools-extra/trunk/clangd/index/FileIndex.cpp
  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/clangd/index/SymbolYAML.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/SymbolCollectorTests.cpp

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
@@ -32,8 +32,7 @@
 
 // GMock helpers for matching Symbol.
 MATCHER_P(QName, Name, "") {
-  return (arg.second.Scope + (arg.second.Scope.empty() ? "" : "::") +
-  arg.second.Name).str() == Name;
+  return (arg.Scope + (arg.Scope.empty() ? "" : "::") + arg.Name).str() == Name;
 }
 
 namespace clang {
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
@@ -13,10 +13,10 @@
 #include "gtest/gtest.h"
 
 using testing::UnorderedElementsAre;
+using testing::Pointee;
 
 namespace clang {
 namespace clangd {
-
 namespace {
 
 Symbol symbol(llvm::StringRef QName) {
@@ -33,6 +33,24 @@
   return Sym;
 }
 
+MATCHER_P(Named, N, "") { return arg.Name == N; }
+
+TEST(SymbolSlab, FindAndIterate) {
+  SymbolSlab::Builder B;
+  B.insert(symbol("Z"));
+  B.insert(symbol("Y"));
+  B.insert(symbol("X"));
+  EXPECT_EQ(nullptr, B.find(SymbolID("W")));
+  for (const char *Sym : {"X", "Y", "Z"})
+EXPECT_THAT(B.find(SymbolID(Sym)), Pointee(Named(Sym)));
+
+  SymbolSlab S = std::move(B).build();
+  EXPECT_THAT(S, UnorderedElementsAre(Named("X"), Named("Y"), Named("Z")));
+  EXPECT_EQ(S.end(), S.find(SymbolID("W")));
+  for (const char *Sym : {"X", "Y", "Z"})
+EXPECT_THAT(*S.find(SymbolID(Sym)), Named(Sym));
+}
+
 struct SlabAndPointers {
   SymbolSlab Slab;
   std::vector Pointers;
@@ -45,18 +63,18 @@
 std::shared_ptr>
 generateSymbols(std::vector QualifiedNames,
 std::weak_ptr *WeakSymbols = nullptr) {
-  auto Slab = std::make_shared();
-  if (WeakSymbols)
-*WeakSymbols = Slab;
-
+  SymbolSlab::Builder Slab;
   for (llvm::StringRef QName : QualifiedNames)
-Slab->Slab.insert(symbol(QName));
+Slab.insert(symbol(QName));
 
-  for (const auto &Sym : Slab->Slab)
-Slab->Pointers.push_back(&Sym.second);
-
-  auto *Pointers = &Slab->Pointers;
-  return {std::move(Slab), Pointers};
+  auto Storage = std::make_shared();
+  Storage->Slab = std::move(Slab).build();
+  for (const auto &Sym : Storage->Slab)
+Storage->Pointers.push_back(&Sym);
+  if (WeakSymbols)
+*WeakSymbols = Storage;
+  auto *Pointers = &Storage->Pointers;
+  return {std::move(Storage), Pointers};
 }
 
 // Create a slab of symbols with IDs and names [Begin, End], otherwise identical
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
@@ -28,9 +28,11 @@
   return Sym;
 }
 
-void addNumSymbolsToSlab(int Begin, int End, SymbolSlab *Slab) {
+std::unique_ptr numSlab(int Begin, int End) {
+  SymbolSlab::Builder Slab;
   for (int i = Begin; i <= End; i++)
-Slab->insert(symbol(std::to_string(i)));
+Slab.insert(symbol(std::to_string(i)));
+  return llvm::make_unique(std::move(Slab).build());
 }
 
 std::vector
@@ -45,46 +47,29 @@
   FileSymbols FS;
   EXPECT_THAT(getSymbolNames(*FS.allSymbols()), UnorderedElementsAre());
 
-  auto Slab = llvm::make_unique();
-  addNumSymbolsToSlab(1, 3, Slab.get());
-
-  FS.update("f1", std::move(Slab));
-
+  FS.update("f1", numSlab(1, 3));
   EXPECT_THAT(getSymbolNames(*FS.allSymbols()),
   UnorderedElementsAre("1", "2", "3"));
 }
 
 TEST(FileSymbolsTest, Overlap) {
   FileSymbols FS;
-
-  auto Slab = llvm::make_unique();
-  addNumSymbolsToSlab(1, 3, Slab.get());
-
-  FS.update("f1", std::move(Slab));
-
-  Slab = llvm::make_unique();
-  addNumSymbolsToSlab(3, 5, Slab.get());
-
-  FS.update("f2", std::move(Slab));
-
+  FS.update("f1", numSlab(1, 3));
+  FS.update("f2", numSlab(3, 5))

[PATCH] D41557: [x86][icelake][vbmi2]

2017-12-23 Thread coby via Phabricator via cfe-commits
coby created this revision.
Herald added subscribers: cfe-commits, mgorny.

added intrinsics support for (while of) vbmi2 instructions, matching a similar 
work on the backend


Repository:
  rC Clang

https://reviews.llvm.org/D41557

Files:
  include/clang/Basic/BuiltinsX86.def
  include/clang/Driver/Options.td
  lib/Basic/Targets/X86.cpp
  lib/Basic/Targets/X86.h
  lib/Headers/CMakeLists.txt
  lib/Headers/avx512vbmi2intrin.h
  lib/Headers/avx512vlvbmi2intrin.h
  lib/Headers/immintrin.h
  test/CodeGen/attr-target-x86.c
  test/CodeGen/avx512vbmi2-builtins.c
  test/CodeGen/avx512vlvbmi2-builtins.c
  test/Driver/x86-target-features.c

Index: lib/Headers/avx512vbmi2intrin.h
===
--- lib/Headers/avx512vbmi2intrin.h
+++ lib/Headers/avx512vbmi2intrin.h
@@ -0,0 +1,391 @@
+/*===- avx512vbmi2intrin.h - VBMI2 intrinsics --===
+ *
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ *===---===
+ */
+#ifndef __IMMINTRIN_H
+#error "Never use  directly; include  instead."
+#endif
+
+#ifndef __AVX512VBMI2INTRIN_H
+#define __AVX512VBMI2INTRIN_H
+
+/* Define the default attributes for the functions in this file. */
+#define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("avx512vbmi2")))
+
+
+static __inline__ __m512i __DEFAULT_FN_ATTRS
+_mm512_mask_compress_epi16(__m512i __S, __mmask32 __U, __m512i __D)
+{
+  return (__m512i) __builtin_ia32_compresshi512_mask ((__v32hi) __D,
+  (__v32hi) __S,
+  __U);
+}
+
+static __inline__ __m512i __DEFAULT_FN_ATTRS
+_mm512_maskz_compress_epi16(__mmask32 __U, __m512i __D)
+{
+  return (__m512i) __builtin_ia32_compresshi512_mask ((__v32hi) __D,
+  (__v32hi) _mm512_setzero_hi(),
+  __U);
+}
+
+static __inline__ __m512i __DEFAULT_FN_ATTRS
+_mm512_mask_compress_epi8(__m512i __S, __mmask64 __U, __m512i __D)
+{
+  return (__m512i) __builtin_ia32_compressqi512_mask ((__v64qi) __D,
+  (__v64qi) __S,
+  __U);
+}
+
+static __inline__ __m512i __DEFAULT_FN_ATTRS
+_mm512_maskz_compress_epi8(__mmask64 __U, __m512i __D)
+{
+  return (__m512i) __builtin_ia32_compressqi512_mask ((__v64qi) __D,
+  (__v64qi) _mm512_setzero_qi(),
+  __U);
+}
+
+static __inline__ void __DEFAULT_FN_ATTRS
+_mm512_mask_compressstoreu_epi16(void *__P, __mmask32 __U, __m512i __D)
+{
+  __builtin_ia32_compressstorehi512_mask ((__v32hi *) __P, (__v32hi) __D,
+  __U);
+}
+
+static __inline__ void __DEFAULT_FN_ATTRS
+_mm512_mask_compressstoreu_epi8(void *__P, __mmask64 __U, __m512i __D)
+{
+  __builtin_ia32_compressstoreqi512_mask ((__v64qi *) __P, (__v64qi) __D,
+  __U);
+}
+
+static __inline__ __m512i __DEFAULT_FN_ATTRS
+_mm512_mask_expand_epi16(__m512i __S, __mmask32 __U, __m512i __D)
+{
+  return (__m512i) __builtin_ia32_expandhi512_mask ((__v32hi) __D,
+  (__v32hi) __S,
+  __U);
+}
+
+static __inline__ __m512i __DEFAULT_FN_ATTRS
+_mm512_maskz_expand_epi16(__mmask32 __U, __m512i __D)
+{
+  return (__m512i) __builtin_ia32_expandhi512_mask ((__v32hi) __D,
+  (__v32hi) _mm512_setzero_hi(),
+  __U);
+}
+
+static __inline__ __m512i __DEFAULT_FN_ATTRS
+_mm512_mask_expand_epi8(__m512i __S, __mmask64 __U, __m512i __D)
+{
+  return (__m512i) __builtin_ia32_expandqi512_mask ((__v64qi) __D,
+  (__v64qi) __S,
+  __U);
+}
+
+static __inline__ __m512i __DEFAULT_FN_ATTRS
+_mm512_maskz_expand_epi8(__mmask64 __U, __m512i __D)
+{
+  return (__m512i) __builtin_ia32_expandqi512_mask ((__v64qi) __D,
+  (__v64qi) _mm512_setzero_qi(),
+  __U);
+}
+
+static __inline__ __m512i __DEFAULT_FN_ATTRS
+_mm512_mask_expandloadu_epi16(__m512i __S, __mmask32 __U, void const *__P)
+{
+  return (__m512i) __builtin_ia32_expandloadhi512_mask ((c

[PATCH] D41326: [clang-tidy] Added diagnostics about incorrect usage of NOLINT comment

2017-12-23 Thread Anton via Phabricator via cfe-commits
xgsa marked 13 inline comments as done.
xgsa added a comment.

Aaron, thank you for your review and sorry for the coding convention mistakes 
-- I still cannot get used to the llvm coding convention, because it quite 
differs from the one I have been using in my projects.




Comment at: clang-tidy/ClangTidyDiagnosticConsumer.cpp:276
+
+  using NolintMap = std::unordered_map Is there a better LLVM ADT to use here?
This data structure provides the fast lookup by check name+line number and it's 
exactly what is necessary. What are the concerns about this data structure?



Comment at: clang-tidy/ClangTidyDiagnosticConsumer.cpp:316
+  Context->diag(NolintCheckName, NolintLoc,
+  "unknown check name '%0' is specified for %1 comment")
+  << CheckName << CommentName;

aaron.ballman wrote:
> I'd reword this slightly to: "unknown check name '%0' specified in %1 
> directive"
I'd used the word "comment" instead of "directive" for consistency with 
documentation and the other messages. The rest is applied.



Comment at: clang-tidy/ClangTidyDiagnosticConsumer.cpp:424
+// This method is not const, because it fills cache on first demand.
+// It is possible to fill cache in constructor or make cache volatile
+// and make this method const, but they seem like worse solutions.

aaron.ballman wrote:
> Making the cache volatile will have no impact on this.
> 
> Any reason not to make the cache `mutable`, however? That's quite common for 
> implementation details.
Sorry, certainly, instead of "volatile" I meant "mutable".

Actually, using of "mutable" violates a constancy contract, as the field is get 
modified in a const method. Thus I'd tend to avoid using `mutable`, if 
possible, because e.g. in multi-threaded applications these fields require 
additional protection/synchronization. Moreover, I see that using of  `mutable` 
is not very spread in clang-tidy. Thus as, currently, `hasCheck` is called from 
the non-constant context, I'd prefer leaving it non-const instead of making 
cache `mutable`. Please, let me know if you insist on the `mutable` option.



Comment at: clang-tidy/ClangTidyDiagnosticConsumer.cpp:839-840
+case NolintCommentType::Nolint:
+  Message = "there is no diagnostics on this line, "
+"the NOLINT comment is redundant";
+  break;

aaron.ballman wrote:
> I don't think the user is going to care about the distinction between no 
> diagnostics being triggered and the expected diagnostic not being triggered. 
> Also, it's dangerous to claim the lint comment is redundant because it's 
> possible the user has NOLINT(foo, bar) and while foo is not triggered, bar 
> still is. The NOLINT comment itself isn't redundant, it's that the check 
> specified doesn't occur.
> 
> I would consolidate those scenarios into a single diagnostic: "expected 
> diagnostic '%0' not generated" and "expected diagnostic '%0' not generated 
> for the following line".
> 
> One concern I have with this functionality is: how should users silence a 
> lint diagnostic that's target sensitive? e.g., a diagnostic that triggers 
> based on the underlying type of size_t or the signedness of plain char. In 
> that case, the diagnostic may trigger for some targets but not others, but on 
> the targets where the diagnostic is not triggered, they now get a diagnostic 
> they cannot silence. There should be a way to silence the "bad NOLINT" 
> diagnostics.
> I don't think the user is going to care about the distinction between no 
> diagnostics being triggered and the expected diagnostic not being triggered. 
> Also, it's dangerous to claim the lint comment is redundant because it's 
> possible the user has NOLINT(foo, bar) and while foo is not triggered, bar 
> still is. The NOLINT comment itself isn't redundant, it's that the check 
> specified doesn't occur.
> 
> I would consolidate those scenarios into a single diagnostic: "expected 
> diagnostic '%0' not generated" and "expected diagnostic '%0' not generated 
> for the following line".

This branch of `if (NolintEntry.first.CheckName == 
NolintCommentsCollector::AnyCheck)` reports only about 
`NOLINT`/`NOLINTNEXTLINE` comments without check list, so I suppose it's fair 
to claim that this comment is redundant (we have already checked that no single 
check reported diagnostics on the line). The `else`-branch reports the 
diagnostics for the definite check in a list in case of `NOLINT(foo, bar)` 
(actually, if neither `foo` nor `bar` checks reported diagnostics for the line, 
there will be a few diagnostics from `nolint-usage` - not sure if it's good, 
but it seems acceptable). That is why, I suppose, it is necessary to distinct 
these cases.

> One concern I have with this functionality is: how should users silence a 
> lint diagnostic that's target sensitive? e.g., a diagnostic that triggers 
> based on 

[PATCH] D41326: [clang-tidy] Added diagnostics about incorrect usage of NOLINT comment

2017-12-23 Thread Anton via Phabricator via cfe-commits
xgsa updated this revision to Diff 128091.
xgsa marked an inline comment as done.
xgsa added a comment.

Review comments applied.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41326

Files:
  clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tidy/ClangTidyDiagnosticConsumer.h
  test/clang-tidy/nolint-usage.cpp

Index: test/clang-tidy/nolint-usage.cpp
===
--- test/clang-tidy/nolint-usage.cpp
+++ test/clang-tidy/nolint-usage.cpp
@@ -22,19 +22,19 @@
 // Case: NO_LINT for unknown check on line with an error on some check.
 class A6 { A6(int i); }; // NOLINT(unknown-check)
 // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: single-argument constructors must be marked explicit
-// CHECK-MESSAGES: :[[@LINE-2]]:29: warning: unknown check name 'unknown-check' is specified for NOLINT comment
+// CHECK-MESSAGES: :[[@LINE-2]]:29: warning: unknown check name 'unknown-check' specified in NOLINT comment
 
 // Case: NO_LINT for unknown check on line without errors.
 class A7 { explicit A7(int i); }; // NOLINT(unknown-check)
-// CHECK-MESSAGES: :[[@LINE-1]]:38: warning: unknown check name 'unknown-check' is specified for NOLINT comment
+// CHECK-MESSAGES: :[[@LINE-1]]:38: warning: unknown check name 'unknown-check' specified in NOLINT comment
 
 // Case: NO_LINT with not closed parenthesis without check names.
 class A8 { A8(int i); }; // NOLINT(
-// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: NOLINT comment has an opening parenthesis and no closing one, so all the diagnostics will be silenced for the line
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: unbalanced parentheses in NOLINT comment; all diagnostics silenced for this line
 
 // Case: NO_LINT with not closed parenthesis with check names.
 class A9 { A9(int i); }; // NOLINT(unknown-check
-// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: NOLINT comment has an opening parenthesis and no closing one, so all the diagnostics will be silenced for the line
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: unbalanced parentheses in NOLINT comment; all diagnostics silenced for this line
 
 // Case: NO_LINT with clang diagnostics
 int f() {
@@ -102,23 +102,23 @@
 // Case: NO_LINT_NEXT_LINE for unknown check before line with an error on some check.
 // NOLINTNEXTLINE(unknown-check)
 class C6 { C6(int i); };
-// CHECK-MESSAGES: :[[@LINE-2]]:4: warning: unknown check name 'unknown-check' is specified for NOLINTNEXTLINE comment
+// CHECK-MESSAGES: :[[@LINE-2]]:4: warning: unknown check name 'unknown-check' specified in NOLINTNEXTLINE comment
 // CHECK-MESSAGES: :[[@LINE-2]]:12: warning: single-argument constructors must be marked explicit
 
 // Case: NO_LINT_NEXT_LINE for unknown check before line without errors.
 // NOLINTNEXTLINE(unknown-check)
 class C7 { explicit C7(int i); };
-// CHECK-MESSAGES: :[[@LINE-2]]:4: warning: unknown check name 'unknown-check' is specified for NOLINTNEXTLINE comment
+// CHECK-MESSAGES: :[[@LINE-2]]:4: warning: unknown check name 'unknown-check' specified in NOLINTNEXTLINE comment
 
 // Case: NO_LINT_NEXT_LINE with not closed parenthesis without check names.
 // NOLINTNEXTLINE(
 class C8 { C8(int i); };
-// CHECK-MESSAGES: :[[@LINE-2]]:4: warning: NOLINTNEXTLINE comment has an opening parenthesis and no closing one, so all the diagnostics will be silenced for the line
+// CHECK-MESSAGES: :[[@LINE-2]]:4: warning: unbalanced parentheses in NOLINTNEXTLINE comment; all diagnostics silenced for this line
 
 // Case: NO_LINT_NEXT_LINE with not closed parenthesis with check names.
 // NOLINTNEXTLINE(unknown-check
 class C9 { C9(int i); };
-// CHECK-MESSAGES: :[[@LINE-2]]:4: warning: NOLINTNEXTLINE comment has an opening parenthesis and no closing one, so all the diagnostics will be silenced for the line
+// CHECK-MESSAGES: :[[@LINE-2]]:4: warning: unbalanced parentheses in NOLINTNEXTLINE comment; all diagnostics silenced for this line
 
 // Case: NO_LINT_NEXT_LINE with clang diagnostics
 int g() {
Index: clang-tidy/ClangTidyDiagnosticConsumer.h
===
--- clang-tidy/ClangTidyDiagnosticConsumer.h
+++ clang-tidy/ClangTidyDiagnosticConsumer.h
@@ -27,6 +27,7 @@
 class ASTContext;
 class CompilerInstance;
 class Preprocessor;
+
 namespace ast_matchers {
 class MatchFinder;
 }
@@ -202,7 +203,7 @@
   }
 
 private:
-  // Calls setDiagnosticsEngine(), storeError() and getNolintCollector().
+  // Calls setDiagnosticsEngine(), storeError(), and getNolintCollector().
   friend class ClangTidyDiagnosticConsumer;
   friend class ClangTidyPluginAction;
 
Index: clang-tidy/ClangTidyDiagnosticConsumer.cpp
===
--- clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -16,15 +16,16 @@
 ///
 //===--===//
 
-#include "ClangTidyDiagnosticConsumer.h"
-#include "ClangTidyOptions.h"
 

[PATCH] D41326: [clang-tidy] Added diagnostics about incorrect usage of NOLINT comment

2017-12-23 Thread Anton via Phabricator via cfe-commits
xgsa updated this revision to Diff 128092.
xgsa added a comment.

The full diff (but not only the incremental one) was uploaded. Please, skip 
previous revision. Sorry.


https://reviews.llvm.org/D41326

Files:
  clang-tidy/ClangTidy.cpp
  clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tidy/ClangTidyDiagnosticConsumer.h
  test/clang-tidy/nolint-usage.cpp
  test/clang-tidy/nolint.cpp
  test/clang-tidy/nolintnextline.cpp

Index: test/clang-tidy/nolintnextline.cpp
===
--- test/clang-tidy/nolintnextline.cpp
+++ test/clang-tidy/nolintnextline.cpp
@@ -24,6 +24,18 @@
 class C5 { C5(int i); };
 
 
+void f() {
+  int i;
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: unused variable 'i' [clang-diagnostic-unused-variable]
+  // NOLINTNEXTLINE
+  int j;
+  // NOLINTNEXTLINE(clang-diagnostic-unused-variable)
+  int k;
+  // NOLINTNEXTLINE(clang-diagnostic-literal-conversion)
+  int l;
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: unused variable 'l' [clang-diagnostic-unused-variable]
+}
+
 // NOLINTNEXTLINE
 
 class D { D(int i); };
@@ -44,6 +56,6 @@
 // NOLINTNEXTLINE
 MACRO_NOARG
 
-// CHECK-MESSAGES: Suppressed 8 warnings (8 NOLINT)
+// CHECK-MESSAGES: Suppressed 10 warnings (10 NOLINT)
 
-// RUN: %check_clang_tidy %s google-explicit-constructor %t --
+// RUN: %check_clang_tidy %s google-explicit-constructor,clang-diagnostic-unused-variable %t -- -extra-arg=-Wunused-variable --
Index: test/clang-tidy/nolint.cpp
===
--- test/clang-tidy/nolint.cpp
+++ test/clang-tidy/nolint.cpp
@@ -30,6 +30,9 @@
   int i;
 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: unused variable 'i' [clang-diagnostic-unused-variable]
   int j; // NOLINT
+  int k; // NOLINT(clang-diagnostic-unused-variable)
+  int l; // NOLINT(clang-diagnostic-literal-conversion)
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: unused variable 'l' [clang-diagnostic-unused-variable]
 }
 
 #define MACRO(X) class X { X(int i); };
@@ -46,4 +49,4 @@
 #define DOUBLE_MACRO MACRO(H) // NOLINT
 DOUBLE_MACRO
 
-// CHECK-MESSAGES: Suppressed 12 warnings (12 NOLINT)
+// CHECK-MESSAGES: Suppressed 13 warnings (13 NOLINT)
Index: test/clang-tidy/nolint-usage.cpp
===
--- /dev/null
+++ test/clang-tidy/nolint-usage.cpp
@@ -0,0 +1,171 @@
+// RUN: %check_clang_tidy %s nolint-usage,google-explicit-constructor,misc-unused-parameters %t --
+
+// Case: NO_LINT on line with an error.
+class A1 { A1(int i); }; // NOLINT
+
+// Case: NO_LINT on line without errors.
+class A2 { explicit A2(int i); }; // NOLINT
+// CHECK-MESSAGES: :[[@LINE-1]]:38: warning: there is no diagnostics on this line, the NOLINT comment is redundant
+
+// Case: NO_LINT for the specific check on line with an error on it.
+class A3 { A3(int i); }; // NOLINT(google-explicit-constructor)
+
+// Case: NO_LINT for the specific check on line with an error on another check.
+class A4 { A4(int i); }; // NOLINT(misc-unused-parameters)
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: single-argument constructors must be marked explicit
+// CHECK-MESSAGES: :[[@LINE-2]]:29: warning: there is no diagnostics for the 'misc-unused-parameters' check on this line, the NOLINT comment is redundant
+
+// Case: NO_LINT for the specific check on line without errors.
+class A5 { explicit A5(int i); }; // NOLINT(google-explicit-constructor)
+// CHECK-MESSAGES: :[[@LINE-1]]:38: warning: there is no diagnostics for the 'google-explicit-constructor' check on this line, the NOLINT comment is redundant
+
+// Case: NO_LINT for unknown check on line with an error on some check.
+class A6 { A6(int i); }; // NOLINT(unknown-check)
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: single-argument constructors must be marked explicit
+// CHECK-MESSAGES: :[[@LINE-2]]:29: warning: unknown check name 'unknown-check' specified in NOLINT comment
+
+// Case: NO_LINT for unknown check on line without errors.
+class A7 { explicit A7(int i); }; // NOLINT(unknown-check)
+// CHECK-MESSAGES: :[[@LINE-1]]:38: warning: unknown check name 'unknown-check' specified in NOLINT comment
+
+// Case: NO_LINT with not closed parenthesis without check names.
+class A8 { A8(int i); }; // NOLINT(
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: unbalanced parentheses in NOLINT comment; all diagnostics silenced for this line
+
+// Case: NO_LINT with not closed parenthesis with check names.
+class A9 { A9(int i); }; // NOLINT(unknown-check
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: unbalanced parentheses in NOLINT comment; all diagnostics silenced for this line
+
+// Case: NO_LINT with clang diagnostics
+int f() {
+  int i = 0; // NOLINT
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: there is no diagnostics on this line, the NOLINT comment is redundant
+  int j = 0; // NOLINT(clang-diagnostic-unused-variable)
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: there is no diagnostics for the 'clang-diagnostic-unus

[PATCH] D41557: [x86][icelake][vbmi2]

2017-12-23 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

Update the ICL macros in test/Preprocessor/predefined-arch-macros.c




Comment at: include/clang/Basic/BuiltinsX86.def:1254
+TARGET_BUILTIN(__builtin_ia32_vpshldd512_mask, "V16iV16iV16iiV16iUs", "", 
"avx512vbmi2")
+TARGET_BUILTIN(__builtin_ia32_vpshldq128_mask, "V2LLiV2LLiV2LLiiV2LLiUc", "", 
"avx512vl,avx512vbmi2")
+TARGET_BUILTIN(__builtin_ia32_vpshldq256_mask, "V4LLiV4LLiV4LLiiV4LLiUc", "", 
"avx512vl,avx512vbmi2")

Arguments corresponding to immediates need a capital 'I' in front of them so 
clang will error if they are a compile time constant.



Comment at: lib/Basic/Targets/X86.cpp:135
   case CK_Icelake:
-// TODO: Add icelake features here.
 LLVM_FALLTHROUGH;

Dont' remove the TODO until all features are added.



Comment at: lib/Basic/Targets/X86.cpp:589
+// Enable BWI instruction if VBMI/VBMI2 is being enabled.
+if (Name.startswith("avx512vbmi") && Enabled)
   Features["avx512bw"] = true;

Do two equality checks ORed together. I think bad target attributes on 
functions only issue a warning and are discarded in codegen. So strings like 
avx512vbmifoo can get here and we should ignore them.


Repository:
  rC Clang

https://reviews.llvm.org/D41557



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


[PATCH] D41557: [x86][icelake][vbmi2]

2017-12-23 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

Add tests for -mavx512vbmi2 and -mno-avx512vbmi2 to 
test/Driver/x86-target-features.c

Add a test for -mno-avx512bw also disabling avx512vbmi2 to 
test/Preprocessor/x86_target_features.c. Look for AVX512VBMINOAVX512BW for the 
existing test for avx512vbmi. Also add the test -mavx512vbmi2.


Repository:
  rC Clang

https://reviews.llvm.org/D41557



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


[PATCH] D40381: Parse concept definition

2017-12-23 Thread changyu via Phabricator via cfe-commits
changyu marked 27 inline comments as done.
changyu added inline comments.



Comment at: lib/Sema/SemaTemplate.cpp:7713
+
+  if (!ConstraintExpr->isTypeDependent() &&
+  ConstraintExpr->getType() != Context.BoolTy) {

faisalv wrote:
> saar.raz wrote:
> > faisalv wrote:
> > > Consider refactoring these checks on constraint expressions into a 
> > > separate function checkConstraintExpression (that we can also call from 
> > > other contexts such as requires-clauses and nested requires expressions)?
> > I did that in the upcoming patches, no need to do it here as well.
> Once again - relying on a future patch (especially without a clear FIXME) to 
> tweak the architectural/factorization issues that you have been made aware of 
> (and especially those, such as this, that do not require too much effort), is 
> not practice I would generally encourage.  
> 
> So changyu, if you agree that these suggestions would improve the quality of 
> the patch and leave clang in a more robust state (maintenance-wise or 
> execution-wise), then please make the changes.  If not, please share your 
> thoughts as to why these suggestions would either not be an improvement or be 
> inconsistent with the theme of this patch.
> 
> Thanks!
I removed it here since Saar fixed it in his patch.


https://reviews.llvm.org/D40381



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


[PATCH] D40381: Parse concept definition

2017-12-23 Thread changyu via Phabricator via cfe-commits
changyu updated this revision to Diff 128094.
changyu marked an inline comment as done.

https://reviews.llvm.org/D40381

Files:
  include/clang/AST/DeclTemplate.h
  include/clang/AST/RecursiveASTVisitor.h
  include/clang/Basic/DeclNodes.td
  include/clang/Basic/DiagnosticParseKinds.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/TemplateKinds.h
  include/clang/Parse/Parser.h
  include/clang/Sema/Sema.h
  include/clang/Serialization/ASTBitCodes.h
  lib/AST/ASTDumper.cpp
  lib/AST/DeclBase.cpp
  lib/AST/DeclTemplate.cpp
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/Parse/ParseTemplate.cpp
  lib/Sema/SemaTemplate.cpp
  lib/Sema/SemaTemplateInstantiateDecl.cpp
  lib/Serialization/ASTCommon.cpp
  lib/Serialization/ASTReaderDecl.cpp
  lib/Serialization/ASTWriter.cpp
  lib/Serialization/ASTWriterDecl.cpp
  test/CXX/concepts-ts/expr/expr.prim/expr.prim.id/p3.cpp
  test/Parser/cxx-concept-declaration.cpp
  test/Parser/cxx2a-concept-declaration.cpp
  tools/libclang/CIndex.cpp

Index: tools/libclang/CIndex.cpp
===
--- tools/libclang/CIndex.cpp
+++ tools/libclang/CIndex.cpp
@@ -5906,6 +5906,7 @@
   case Decl::PragmaComment:
   case Decl::PragmaDetectMismatch:
   case Decl::UsingPack:
+  case Decl::Concept:
 return C;
 
   // Declaration kinds that don't make any sense here, but are
Index: test/Parser/cxx2a-concept-declaration.cpp
===
--- /dev/null
+++ test/Parser/cxx2a-concept-declaration.cpp
@@ -0,0 +1,37 @@
+
+// Support parsing of concepts
+
+// RUN:  %clang_cc1 -std=c++2a -fconcepts-ts -verify %s
+template concept C1 = true;
+
+template concept C1 = true; // expected-error {{redefinition of 'C1'}}
+
+template concept D1 = true; // expected-error {{expected template parameter}}
+
+template<> concept D1 = true;  // expected-error {{expected template parameter}}
+
+// TODO:
+// template concept C2 = 0.f; // expected error {{constraint expression must be 'bool'}}
+
+struct S1 {
+  template concept C1 = true; // expected-error {{concept declarations may only appear in global or namespace scope}}
+};
+
+template
+template
+concept C4 = true; // expected-error {{extraneous template parameter list in concept definition}}
+
+template concept C5 = true; // expected-note {{previous}} expected-note {{previous}}
+int C5; // expected-error {{redefinition}}
+struct C5 {}; // expected-error {{redefinition}}
+
+struct C6 {};
+template concept C6 = true; // expected-error {{redefinition of 'C6' as different kind of symbol}}
+
+namespace thing {};
+
+template concept thing::C7 = true;  // expected-error {{concepts must be defined within their namespace}}
+
+
+// TODO: Add test to prevent explicit specialization, partial specialization
+// and explicit instantiation of concepts.
Index: test/Parser/cxx-concept-declaration.cpp
===
--- test/Parser/cxx-concept-declaration.cpp
+++ /dev/null
@@ -1,7 +0,0 @@
-
-// Support parsing of concepts
-// Disabled for now.
-// expected-no-diagnostics
-
-// RUN:  %clang_cc1 -std=c++14 -fconcepts-ts -x c++ -verify %s
-// template concept C1 = true;
Index: test/CXX/concepts-ts/expr/expr.prim/expr.prim.id/p3.cpp
===
--- /dev/null
+++ test/CXX/concepts-ts/expr/expr.prim/expr.prim.id/p3.cpp
@@ -0,0 +1,6 @@
+// RUN:  %clang_cc1 -std=c++2a -fconcepts-ts -verify %s
+// expected-no-diagnostics
+
+// TODO: Make this work.
+// template concept C = true;
+// static_assert(C);
Index: lib/Serialization/ASTWriterDecl.cpp
===
--- lib/Serialization/ASTWriterDecl.cpp
+++ lib/Serialization/ASTWriterDecl.cpp
@@ -101,6 +101,7 @@
 void VisitBindingDecl(BindingDecl *D);
 void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
 void VisitTemplateDecl(TemplateDecl *D);
+void VisitConceptDecl(ConceptDecl *D);
 void VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D);
 void VisitClassTemplateDecl(ClassTemplateDecl *D);
 void VisitVarTemplateDecl(VarTemplateDecl *D);
@@ -1385,6 +1386,12 @@
   Record.AddTemplateParameterList(D->getTemplateParameters());
 }
 
+void ASTDeclWriter::VisitConceptDecl(ConceptDecl *D) {
+  VisitTemplateDecl(D);
+  Record.AddStmt(D->getConstraintExpr());
+  Code = serialization::DECL_CONCEPT;
+}
+
 void ASTDeclWriter::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) {
   VisitRedeclarable(D);
 
Index: lib/Serialization/ASTWriter.cpp
===
--- lib/Serialization/ASTWriter.cpp
+++ lib/Serialization/ASTWriter.cpp
@@ -1277,6 +1277,7 @@
   RECORD(DECL_TEMPLATE_TYPE_PARM);
   RECORD(DECL_NON_TYPE_TEMPLATE_PARM);
   RECORD(DECL_TEMPLATE_TEMPLATE_PARM);
+  RECORD(DECL_CONCEPT);
   RECORD(DECL_TYPE_ALIAS_TEMPLATE);
   RECORD(DECL_STATIC_ASSERT);

[PATCH] D41558: [x86][icelake][vbmi2]

2017-12-23 Thread coby via Phabricator via cfe-commits
coby created this revision.
coby added a reviewer: craig.topper.
Herald added a subscriber: mgorny.

added intrinsics support for VNNI instructions, matching a similar work on the 
backend (https://reviews.llvm.org/D40208)


Repository:
  rC Clang

https://reviews.llvm.org/D41558

Files:
  include/clang/Basic/BuiltinsX86.def
  include/clang/Driver/Options.td
  lib/Basic/Targets/X86.cpp
  lib/Basic/Targets/X86.h
  lib/Headers/CMakeLists.txt
  lib/Headers/avx512vlvnniintrin.h
  lib/Headers/avx512vnniintrin.h
  lib/Headers/immintrin.h
  test/CodeGen/attr-target-x86.c
  test/CodeGen/avx512vlvnni-builtins.c
  test/CodeGen/avx512vnni-builtins.c
  test/Driver/x86-target-features.c
  test/Preprocessor/predefined-arch-macros.c

Index: lib/Headers/CMakeLists.txt
===
--- lib/Headers/CMakeLists.txt
+++ lib/Headers/CMakeLists.txt
@@ -22,6 +22,8 @@
   avx512vldqintrin.h
   avx512vlintrin.h
   avx512vpopcntdqvlintrin.h
+  avx512vnniintrin.h
+  avx512vlvnniintrin.h
   avxintrin.h
   bmi2intrin.h
   bmiintrin.h
Index: lib/Headers/immintrin.h
===
--- lib/Headers/immintrin.h
+++ lib/Headers/immintrin.h
@@ -159,6 +159,15 @@
 #include 
 #endif
 
+#if !defined(_MSC_VER) || __has_feature(modules) || defined(__AVX512VNNI__)
+#include 
+#endif
+
+#if !defined(_MSC_VER) || __has_feature(modules) || \
+(defined(__AVX512VL__) && defined(__AVX512VNNI__))
+#include 
+#endif
+
 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__AVX512DQ__)
 #include 
 #endif
Index: lib/Headers/avx512vnniintrin.h
===
--- lib/Headers/avx512vnniintrin.h
+++ lib/Headers/avx512vnniintrin.h
@@ -0,0 +1,146 @@
+/*===- avx512vnniintrin.h - VNNI intrinsics --===
+ *
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ *===---===
+ */
+#ifndef __IMMINTRIN_H
+#error "Never use  directly; include  instead."
+#endif
+
+#ifndef __AVX512VNNIINTRIN_H
+#define __AVX512VNNIINTRIN_H
+
+/* Define the default attributes for the functions in this file. */
+#define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("avx512vnni")))
+
+
+static __inline__ __m512i __DEFAULT_FN_ATTRS
+_mm512_mask_dpbusd_epi32(__m512i __S, __mmask16 __U, __m512i __A, __m512i __B)
+{
+  return (__m512i) __builtin_ia32_vpdpbusd512_mask ((__v16si) __S,
+  (__v16si) __A,
+  (__v16si) __B,
+  (__mmask16) __U);
+}
+
+static __inline__ __m512i __DEFAULT_FN_ATTRS
+_mm512_maskz_dpbusd_epi32(__mmask16 __U, __m512i __S, __m512i __A, __m512i __B)
+{
+  return (__m512i) __builtin_ia32_vpdpbusd512_maskz ((__v16si) __S,
+  (__v16si) __A,
+  (__v16si) __B,
+  (__mmask16) __U);
+}
+
+static __inline__ __m512i __DEFAULT_FN_ATTRS
+_mm512_dpbusd_epi32(__m512i __S, __m512i __A, __m512i __B)
+{
+  return (__m512i) __builtin_ia32_vpdpbusd512_mask ((__v16si) __S,
+  (__v16si) __A,
+  (__v16si) __B,
+  (__mmask16) -1);
+}
+
+static __inline__ __m512i __DEFAULT_FN_ATTRS
+_mm512_mask_dpbusds_epi32(__m512i __S, __mmask16 __U, __m512i __A, __m512i __B)
+{
+  return (__m512i) __builtin_ia32_vpdpbusds512_mask ((__v16si) __S,
+  (__v16si) __A,
+  (__v16si) __B,
+  (__mmask16) __U);
+}
+
+static __inline__ __m512i __DEFAULT_FN_ATTRS
+_mm512_maskz_dpbusds_epi32(__mmask16 __U, __m512i __S, __m512i __A, __m512i __B)
+{
+  return (__m512i) __builtin_ia32_vpdpbusds512_maskz ((__v16si) __S,
+  (__v16si) __A,
+  (__v16si) __B,
+  (__mmask16) __U);
+}
+
+static __inline__ __m512i __DEFAULT_FN_ATTRS
+_mm512_dpbusds_epi32(__m512i __S, __m512i __A, __m512i __B)
+{
+  return (__m512i) __builtin_ia32_vpdpbusds512_mask