[PATCH] D28226: threading_support: introduce __libcpp_recursive_mutex_t

2017-01-03 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF added inline comments.



Comment at: include/__threading_support:79
+
+  template (__value);
+  }

Wouldn't a `static_cast` be valid here?



Comment at: include/__threading_support:110
+int __libcpp_mutex_lock(__libcpp_mutex_reference&& __m);
 
 _LIBCPP_THREAD_ABI_VISIBILITY

This uses C++11 features but is limited to C++03. Although we can technically 
cheat and use Clang extended rvalue references here.



Comment at: include/__threading_support:112
 _LIBCPP_THREAD_ABI_VISIBILITY
-int __libcpp_mutex_trylock(__libcpp_mutex_t *__m);
+int __libcpp_mutex_trylock(__libcpp_mutex_reference&& __m);
 

Won't we ever want to pass an lvalue here?


Repository:
  rL LLVM

https://reviews.llvm.org/D28226



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


[PATCH] D28207: Add second fast path for DiagnosticsEngine::GetDiagStatePointForLoc

2017-01-03 Thread Daniel Jasper via Phabricator via cfe-commits
djasper added inline comments.



Comment at: lib/Basic/Diagnostic.cpp:179
+
+  // 2nd most frequent case: L is before the first diag state change.
+  FullSourceLoc FirstStateChangePos = DiagStatePoints[1].Loc;

rsmith wrote:
> It's surprising to me that this would be particularly frequent.
> 
> I suspect what you're actually seeing is a consequence of a bug in how we 
> manage `DiagStatePoint`s with modules. It looks like 
> `ASTReader::InitializeContext` is called once per top-level PCM file that we 
> load, and its call to `ReadPragmaDiagnosticMappings` adds entries to the 
> `DiagStatePoints` list regardless of whether they've already been added. So, 
> we'll end up with duplicates in the `DiagStatePoints` list, and it won't even 
> be in translation unit order.
> 
> Can you take a look at the `DiagStatePoints` list for a translation unit 
> where you see a performance problem and check whether it seems reasonable?
I looked at the DiagStatePoints and they do look somewhat sane but suspicious.

The translation unit I am looking at has (AFAICT) only includes that get 
translated to modules. DiagStatePoints only has entries for the translation 
unit itself, not a single one coming from any of the modules. So 
DiagStatePoints looks like:

  [0]: <>  (for the command line)
  [1]: myfile.cc:100
  [2]: myfile.cc:100
  ...
  [2500]: myfile.cc:2800

And because of that, the new fast path is hit every single time when a source 
location coming from a module is queried. There are always two entries for a 
line of myfile.cc which always seem to denote entering and exiting a macro.

So, specific questions:
- Should there by DiagStatePoints from modules?
- Should there really be a DiagStatePoint entry (or actually two) for every 
macro invocation in myfile.cc?


https://reviews.llvm.org/D28207



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


[PATCH] D28220: provide Win32 native threading

2017-01-03 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF added inline comments.



Comment at: include/__threading_support:44
+#define WIN32_LEAN_AND_MEAN
+#define VC_EXTRA_LEAN
+#include 

compnerd wrote:
> EricWF wrote:
> > Do these definitions have any affect when `` has already been 
> > included?
> > Also are these definitions required before including the header, or merely 
> > beneficial? If they are required this will make the `` header a 
> > pain to use with modules.
> > 
> > 
> No, they dont effect it once it has been included.  They are beneficial since 
> they reduce the amount of stuff that gets included (including things which, 
> at least when I last checked, can cause clang to choke).
And can users re-include `` afterwards in the same TU and get all of 
the symbols?


Repository:
  rL LLVM

https://reviews.llvm.org/D28220



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


[PATCH] D28222: [libcxx] Re-implement LWG 2770 again: Fix tuple_size to work with structured bindings

2017-01-03 Thread Richard Smith via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added a comment.
This revision is now accepted and ready to land.

LGTM, but a minor simplification seems possible.




Comment at: include/__tuple:32
 template 
-class _LIBCPP_TYPE_VIS_ONLY tuple_size
-: public __tuple_size_base_type<_Tp>::type {};
+class _LIBCPP_TYPE_VIS_ONLY tuple_size<__enable_if_tuple_size_imp::type>::value)>>
+: public integral_constant::value> {};

remove_cv looks redundant here, deduction already stripped the cv qualifiers.


https://reviews.llvm.org/D28222



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


[PATCH] D28222: [libcxx] Re-implement LWG 2770 again: Fix tuple_size to work with structured bindings

2017-01-03 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF added inline comments.



Comment at: include/__tuple:32
 template 
-class _LIBCPP_TYPE_VIS_ONLY tuple_size
-: public __tuple_size_base_type<_Tp>::type {};
+class _LIBCPP_TYPE_VIS_ONLY tuple_size<__enable_if_tuple_size_imp::type>::value)>>
+: public integral_constant::value> {};

rsmith wrote:
> remove_cv looks redundant here, deduction already stripped the cv qualifiers.
The `remove_cv` should be redundant, but without it Clang segfaults in 
`clang::TreeTransform<(anonymous 
namespace)::TemplateInstantiator>::TransformTemplateSpecializationType(clang::TypeLocBuilder&,
 clang::TemplateSpecializationTypeLoc, clang::TemplateName)`. 

I haven't had time to file a Clang bug yet.


https://reviews.llvm.org/D28222



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


[clang-tools-extra] r290873 - [clang-move] Only move used helper declarations.

2017-01-03 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Tue Jan  3 03:00:51 2017
New Revision: 290873

URL: http://llvm.org/viewvc/llvm-project?rev=290873&view=rev
Log:
[clang-move] Only move used helper declarations.

Summary:
Instead of moving all the helper declarations blindly, this patch
implements an AST-based call graph solution to make clang-move only move used
helper decls to new.cc and remove unused decls in old.cc.

Depends on D27674.

Reviewers: ioeric

Subscribers: mgorny, cfe-commits

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

Added:
clang-tools-extra/trunk/clang-move/HelperDeclRefGraph.cpp
clang-tools-extra/trunk/clang-move/HelperDeclRefGraph.h
clang-tools-extra/trunk/test/clang-move/Inputs/helper_decls_test.cpp
clang-tools-extra/trunk/test/clang-move/Inputs/helper_decls_test.h
clang-tools-extra/trunk/test/clang-move/move-used-helper-decls.cpp
Modified:
clang-tools-extra/trunk/clang-move/CMakeLists.txt
clang-tools-extra/trunk/clang-move/ClangMove.cpp
clang-tools-extra/trunk/clang-move/ClangMove.h
clang-tools-extra/trunk/test/clang-move/Inputs/multiple_class_test.cpp
clang-tools-extra/trunk/test/clang-move/move-multiple-classes.cpp
clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp

Modified: clang-tools-extra/trunk/clang-move/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-move/CMakeLists.txt?rev=290873&r1=290872&r2=290873&view=diff
==
--- clang-tools-extra/trunk/clang-move/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-move/CMakeLists.txt Tue Jan  3 03:00:51 2017
@@ -4,8 +4,10 @@ set(LLVM_LINK_COMPONENTS
 
 add_clang_library(clangMove
   ClangMove.cpp
+  HelperDeclRefGraph.cpp
 
   LINK_LIBS
+  clangAnalysis
   clangAST
   clangASTMatchers
   clangBasic

Modified: clang-tools-extra/trunk/clang-move/ClangMove.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-move/ClangMove.cpp?rev=290873&r1=290872&r2=290873&view=diff
==
--- clang-tools-extra/trunk/clang-move/ClangMove.cpp (original)
+++ clang-tools-extra/trunk/clang-move/ClangMove.cpp Tue Jan  3 03:00:51 2017
@@ -8,6 +8,7 @@
 
//===--===//
 
 #include "ClangMove.h"
+#include "HelperDeclRefGraph.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Format/Format.h"
@@ -16,8 +17,11 @@
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Rewrite/Core/Rewriter.h"
 #include "clang/Tooling/Core/Replacement.h"
+#include "llvm/Support/Debug.h"
 #include "llvm/Support/Path.h"
 
+#define DEBUG_TYPE "clang-move"
+
 using namespace clang::ast_matchers;
 
 namespace clang {
@@ -394,6 +398,25 @@ createInsertedReplacements(const std::ve
   clang::tooling::Replacement(FileName, 0, 0, NewCode));
 }
 
+// Return a set of all decls which are used/referenced by the given Decls.
+// Specically, given a class member declaration, this method will return all
+// decls which are used by the whole class.
+llvm::DenseSet
+getUsedDecls(const HelperDeclRefGraph *RG,
+ const std::vector &Decls) {
+  assert(RG);
+  llvm::DenseSet Nodes;
+  for (const auto *D : Decls) {
+auto Result = RG->getReachableNodes(
+HelperDeclRGBuilder::getOutmostClassOrFunDecl(D));
+Nodes.insert(Result.begin(), Result.end());
+  }
+  llvm::DenseSet Results;
+  for (const auto *Node : Nodes)
+Results.insert(Node->getDecl());
+  return Results;
+}
+
 } // namespace
 
 std::unique_ptr
@@ -455,24 +478,18 @@ void ClangMoveTool::registerMatchers(ast
   
//
   // Matchers for old cc
   
//
-  auto InOldCCNamedOrGlobalNamespace =
-  allOf(hasParent(decl(anyOf(namespaceDecl(unless(isAnonymous())),
- translationUnitDecl(,
-InOldCC);
-  // Matching using decls/type alias decls which are in named namespace or
-  // global namespace. Those in classes, functions and anonymous namespaces are
-  // covered in other matchers.
+  auto IsOldCCTopLevelDecl = allOf(
+  hasParent(decl(anyOf(namespaceDecl(), translationUnitDecl(, InOldCC);
+  // Matching using decls/type alias decls which are in named/anonymous/global
+  // namespace, these decls are always copied to new.h/cc. Those in classes,
+  // functions are covered in other matchers.
   Finder->addMatcher(
-  namedDecl(anyOf(usingDecl(InOldCCNamedOrGlobalNamespace),
-  usingDirectiveDecl(InOldCCNamedOrGlobalNamespace),
-  typeAliasDecl( InOldCCNamedOrGlobalNamespace)))
+  namedDecl(anyOf(usingDecl(IsOldCCTopLevelDecl),
+  usingDirectiveDecl(IsOldCCTopLevelDecl),
+

[PATCH] D27673: [clang-move] Only move used helper declarations.

2017-01-03 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL290873: [clang-move] Only move used helper declarations. 
(authored by hokein).

Changed prior to commit:
  https://reviews.llvm.org/D27673?vs=82804&id=82847#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D27673

Files:
  clang-tools-extra/trunk/clang-move/CMakeLists.txt
  clang-tools-extra/trunk/clang-move/ClangMove.cpp
  clang-tools-extra/trunk/clang-move/ClangMove.h
  clang-tools-extra/trunk/clang-move/HelperDeclRefGraph.cpp
  clang-tools-extra/trunk/clang-move/HelperDeclRefGraph.h
  clang-tools-extra/trunk/test/clang-move/Inputs/helper_decls_test.cpp
  clang-tools-extra/trunk/test/clang-move/Inputs/helper_decls_test.h
  clang-tools-extra/trunk/test/clang-move/Inputs/multiple_class_test.cpp
  clang-tools-extra/trunk/test/clang-move/move-multiple-classes.cpp
  clang-tools-extra/trunk/test/clang-move/move-used-helper-decls.cpp
  clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp

Index: clang-tools-extra/trunk/test/clang-move/Inputs/multiple_class_test.cpp
===
--- clang-tools-extra/trunk/test/clang-move/Inputs/multiple_class_test.cpp
+++ clang-tools-extra/trunk/test/clang-move/Inputs/multiple_class_test.cpp
@@ -15,7 +15,7 @@
 using a::Move1;
 using namespace a;
 static int k = 0;
-} // anonymous namespace
+} // namespace
 
 namespace b {
 using a::Move1;
@@ -34,19 +34,19 @@
 }
 
 int Move4::f() {
-  return 0;
+  return k;
 }
 
 int EnclosingMove5::a = 1;
 
 int EnclosingMove5::Nested::f() {
-  return 0;
+  return g;
 }
 
 int EnclosingMove5::Nested::b = 1;
 
 int NoMove::f() {
   static int F = 0;
-  return 0;
+  return g;
 }
 } // namespace c
Index: clang-tools-extra/trunk/test/clang-move/Inputs/helper_decls_test.h
===
--- clang-tools-extra/trunk/test/clang-move/Inputs/helper_decls_test.h
+++ clang-tools-extra/trunk/test/clang-move/Inputs/helper_decls_test.h
@@ -0,0 +1,35 @@
+namespace a {
+class Class1 {
+  void f();
+};
+
+class Class2 {
+  void f();
+};
+
+class Class3 {
+  void f();
+};
+
+class Class4 {
+  void f();
+};
+
+class Class5 {
+  void f();
+};
+
+class Class6 {
+  int f();
+};
+
+class Class7 {
+  int f();
+  int g();
+};
+
+void Fun1();
+
+inline void Fun2() {}
+
+} // namespace a
Index: clang-tools-extra/trunk/test/clang-move/Inputs/helper_decls_test.cpp
===
--- clang-tools-extra/trunk/test/clang-move/Inputs/helper_decls_test.cpp
+++ clang-tools-extra/trunk/test/clang-move/Inputs/helper_decls_test.cpp
@@ -0,0 +1,78 @@
+#include "helper_decls_test.h"
+
+namespace {
+class HelperC1 {
+public:
+  static int I;
+};
+
+int HelperC1::I = 0;
+
+class HelperC2 {};
+
+class HelperC3 {
+ public:
+  static int I;
+};
+
+int HelperC3::I = 0;
+
+void HelperFun1() {}
+
+void HelperFun2() { HelperFun1(); }
+
+const int K1 = 1;
+} // namespace
+
+static const int K2 = 2;
+static void HelperFun3() { K2; }
+
+namespace a {
+
+static const int K3 = 3;
+static const int K4 = HelperC3::I;
+static const int K5 = 5;
+static const int K6 = 6;
+
+static void HelperFun4() {}
+static void HelperFun6() {}
+
+void Class1::f() { HelperFun2(); }
+
+void Class2::f() {
+  HelperFun1();
+  HelperFun3();
+}
+
+void Class3::f() { HelperC1::I; }
+
+void Class4::f() { HelperC2 c2; }
+
+void Class5::f() {
+  int Result = K1 + K2 + K3;
+  HelperFun4();
+}
+
+int Class6::f() {
+  int R = K4;
+  return R;
+}
+
+int Class7::f() {
+  int R = K6;
+  return R;
+}
+
+int Class7::g() {
+  HelperFun6();
+  return 1;
+}
+
+static int HelperFun5() {
+  int R = K5;
+  return R;
+}
+
+void Fun1() { HelperFun5(); }
+
+} // namespace a
Index: clang-tools-extra/trunk/test/clang-move/move-multiple-classes.cpp
===
--- clang-tools-extra/trunk/test/clang-move/move-multiple-classes.cpp
+++ clang-tools-extra/trunk/test/clang-move/move-multiple-classes.cpp
@@ -25,17 +25,16 @@
 // CHECK-OLD-TEST-CPP: namespace {
 // CHECK-OLD-TEST-CPP: using a::Move1;
 // CHECK-OLD-TEST-CPP: using namespace a;
-// CHECK-OLD-TEST-CPP: static int k = 0;
-// CHECK-OLD-TEST-CPP: } // anonymous namespace
+// CHECK-OLD-TEST-CPP: } // namespace
 // CHECK-OLD-TEST-CPP: namespace b {
 // CHECK-OLD-TEST-CPP: using a::Move1;
 // CHECK-OLD-TEST-CPP: using namespace a;
 // CHECK-OLD-TEST-CPP: using T = a::Move1;
 // CHECK-OLD-TEST-CPP: } // namespace b
 // CHECK-OLD-TEST-CPP: namespace c {
 // CHECK-OLD-TEST-CPP: int NoMove::f() {
 // CHECK-OLD-TEST-CPP:   static int F = 0;
-// CHECK-OLD-TEST-CPP:   return 0;
+// CHECK-OLD-TEST-CPP:   return g;
 // CHECK-OLD-TEST-CPP: }
 // CHECK-OLD-TEST-CPP: } // namespace c
 
@@ -85,7 +84,7 @@
 // CHECK-NEW-TEST-CPP: using a::Move1;
 // CHECK-NEW-TEST-CPP: using namespace a;
 // CHECK-NEW-TEST-CPP: static int k = 0;
-// CHECK-NEW-TEST-CPP: } // anonymous namespace
+// CHECK-NEW-TES

[PATCH] D28081: Make GetStyle return Expected instead of FormatStyle

2017-01-03 Thread Eric Liu via Phabricator via cfe-commits
ioeric added a comment.

The patch LGTM now. I'll accept both this and the one for clang-tool-extra when 
it is ready.

Regarding builbots, we have bots that continually run builds/tests 
(http://lab.llvm.org:8011/). Many buildbots test llvm and clang as well as 
clang-tools-extra (e.g. with `ninja check-all`) at some revision. Also note 
that although llvm/clang and clang-tools-extra are different repos, they do 
share the same revision sequence. So if clang-tools-extra is in a inconsistent 
state, many buildbots can fail and affect llvm/clang builds. Unfortunately, 
there is no atomic way to commit two revisions to two repositories, so we just 
commit them quickly one after another so that we do less damage. Do you have 
commit access to LLVM btw?




Comment at: lib/Format/Format.cpp:1900
 
-  if (!getPredefinedStyle(FallbackStyle, Style.Language, &Style)) {
-llvm::errs() << "Invalid fallback style \"" << FallbackStyle
- << "\" using LLVM style\n";
-return Style;
-  }
+  // FIXME: If FallbackStyle is explicitly "none", replacements are disabled.
+  if (!getPredefinedStyle(FallbackStyle, Style.Language, &Style))

maybe "format is disabled" is clearer? 



Comment at: lib/Tooling/Refactoring.cpp:86
 
-format::FormatStyle CurStyle = format::getStyle(Style, FilePath, "LLVM");
+llvm::Expected FormatStyleOrError =
+format::getStyle(Style, FilePath, "LLVM");

amaiorano wrote:
> ioeric wrote:
> > There is a `NewReplacements` below which is also `llvm::Expected`. 
> > `FormatStyleOrError` is  a fine name, but to be we have been naming 
> > `Expected` types without `OrError` postfix, so I'd go without `OrError` 
> > postfix for consistency append `OrError` postfix to other expected 
> > variables. Personally, I find expected variables without `OrError` postfix 
> > easier to understand, especially in error checking. For example, `if 
> > (!FormatStyleOrError)` is a bit awkward to read while `if (!FormatStyle)` 
> > is more straight-forward IMO.
> > 
> > Same for other changes.
> Agreed. For consistency, would you prefer I also use 'auto' for the return 
> type rather than llvm::Expected as is done for 
> NewReplacements?
`auto` is fine.



Comment at: unittests/Format/FormatTestObjC.cpp:72
 TEST_F(FormatTestObjC, DetectsObjCInHeaders) {
-  Style = getStyle("LLVM", "a.h", "none", "@interface\n"
+  Style = *getStyle("LLVM", "a.h", "none", "@interface\n"
   "- (id)init;");

amaiorano wrote:
> amaiorano wrote:
> > ioeric wrote:
> > > amaiorano wrote:
> > > > In these tests, I'm assuming getStyle returns a valid FormatSyle. I 
> > > > could add the same types of validation as in the 
> > > > FormatStyle.GetStyleOfFile tests.
> > > Please add proper checking as above for returned values.
> > Hmm, so I could replace the Style member of the fixture class with 
> > Expected, and then change all "Style." with "Style->" in the 
> > rest of the test file, or only in this specific test, I could store the 
> > result in a local Expected, check that it's valid, and then 
> > assign to Style. The latter is simpler; only question I have is how to name 
> > the local variable - can I go with StyleOrError? Style2?
> Another option here is to make this a non-fixture TEST and just declare a 
> local Expected Style for this specific test, which would work 
> fine.
Yeah, making this non-fixture sounds like a better idea.  `StyleOrError` is 
fine here.


https://reviews.llvm.org/D28081



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


[PATCH] D28223: clean up use of _WIN32

2017-01-03 Thread Kim Gräsman via Phabricator via cfe-commits
kimgr added a comment.

I don't think wchar_t is UCS-2 anymore, I read somewhere that they switched to 
UTF-16 as of Windows 2000.

Is it the actual encoding you're interested in, or the element size? Judging 
from the diff, it looks like both, but the code appears to assume UCS-2, so it 
could already be broken.

Maybe you could phrase it as `_LIBCPP_16BIT_WCHAR` or `_LIBCPP_SHORT_WCHAR` 
instead?


Repository:
  rL LLVM

https://reviews.llvm.org/D28223



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


[PATCH] D28148: [Sema] Suppress warnings for C's zero initializer

2017-01-03 Thread S. Gilles via Phabricator via cfe-commits
sgilles updated this revision to Diff 82849.
sgilles marked 2 inline comments as done.
sgilles added a comment.

Address danielmarjamaki's and rsmith's comments (creating 
`InitListExpr::isSyntactic()` since it didn't already exist), as well as 
correct syntax of test so that it actually runs.


https://reviews.llvm.org/D28148

Files:
  include/clang/AST/Expr.h
  lib/AST/Expr.cpp
  lib/Sema/SemaInit.cpp
  test/Sema/zero-initializer.c

Index: test/Sema/zero-initializer.c
===
--- /dev/null
+++ test/Sema/zero-initializer.c
@@ -0,0 +1,38 @@
+// RUN: %clang_cc1 -std=c99 -Wmissing-field-initializers -Wmissing-braces -verify %s
+
+// Tests that using {0} in struct initialization or assignment is supported
+struct foo { int x; int y; };
+struct bar { struct foo a; struct foo b; };
+struct A { int a; };
+struct B { struct A a; };
+struct C { struct B b; };
+
+int main(void)
+{
+  struct foo f = { 0 }; // no-warning
+  struct foo g = { 9 }; // expected-warning {{missing field 'y' initializer}}
+  struct foo h = { 9, 9 }; // no-warning
+  struct bar i = { 0 }; // no-warning
+  struct bar j = { 0, 0 }; // expected-warning {{suggest braces around initialization of subobject}} expected-warning {{missing field 'b' initializer}}
+  struct bar k = { { 9, 9 }, { 9, 9 } }; // no-warning
+  struct bar l = { { 9, 9 }, { 0 } }; // no-warning
+  struct bar m = { { 0 }, { 0 } }; // no-warning
+  struct bar n = { { 0 }, { 9, 9 } }; // no-warning
+  struct bar o = { { 9 }, { 9, 9 } }; // expected-warning {{missing field 'y' initializer}}
+  struct C p = { 0 }; // no-warning
+  struct C q = { 9 }; // expected-warning {{suggest braces around initialization of subobject}} expected-warning {{suggest braces around initialization of subobject}}
+  f = (struct foo ) { 0 }; // no-warning
+  g = (struct foo ) { 9 }; // expected-warning {{missing field 'y' initializer}}
+  h = (struct foo ) { 9, 9 }; // no-warning
+  i = (struct bar) { 0 }; // no-warning
+  j = (struct bar) { 0, 0 }; // expected-warning {{suggest braces around initialization of subobject}} expected-warning {{missing field 'b' initializer}}
+  k = (struct bar) { { 9, 9 }, { 9, 9 } }; // no-warning
+  l = (struct bar) { { 9, 9 }, { 0 } }; // no-warning
+  m = (struct bar) { { 0 }, { 0 } }; // no-warning
+  n = (struct bar) { { 0 }, { 9, 9 } }; // no-warning
+  o = (struct bar) { { 9 }, { 9, 9 } }; // expected-warning {{missing field 'y' initializer}}
+  p = (struct C) { 0 }; // no-warning
+  q = (struct C) { 9 }; // expected-warning {{suggest braces around initialization of subobject}} expected-warning {{suggest braces around initialization of subobject}}
+
+  return 0;
+}
Index: lib/Sema/SemaInit.cpp
===
--- lib/Sema/SemaInit.cpp
+++ lib/Sema/SemaInit.cpp
@@ -881,7 +881,8 @@
 }
 
 // Complain about missing braces.
-if (T->isArrayType() || T->isRecordType()) {
+if ((T->isArrayType() || T->isRecordType()) &&
+!ParentIList->isIdiomaticZeroInitializer(SemaRef.getLangOpts())) {
   SemaRef.Diag(StructuredSubobjectInitList->getLocStart(),
diag::warn_missing_braces)
   << StructuredSubobjectInitList->getSourceRange()
@@ -1827,7 +1828,9 @@
   // worthwhile to skip over the rest of the initializer, though.
   RecordDecl *RD = DeclType->getAs()->getDecl();
   RecordDecl::field_iterator FieldEnd = RD->field_end();
-  bool CheckForMissingFields = true;
+  bool CheckForMissingFields =
+!IList->isIdiomaticZeroInitializer(SemaRef.getLangOpts());
+
   while (Index < IList->getNumInits()) {
 Expr *Init = IList->getInit(Index);
 
Index: lib/AST/Expr.cpp
===
--- lib/AST/Expr.cpp
+++ lib/AST/Expr.cpp
@@ -1883,6 +1883,17 @@
  getInit(0)->getType().getCanonicalType();
 }
 
+bool InitListExpr::isIdiomaticZeroInitializer(const LangOptions &LangOpts) const {
+  assert(isSyntacticForm() && "only test syntactic form as zero initializer");
+
+  if (LangOpts.CPlusPlus || getNumInits() != 1) {
+return false;
+  }
+
+  const IntegerLiteral *Lit = dyn_cast(getInit(0));
+  return Lit && Lit->getValue() == 0;
+}
+
 SourceLocation InitListExpr::getLocStart() const {
   if (InitListExpr *SyntacticForm = getSyntacticForm())
 return SyntacticForm->getLocStart();
Index: include/clang/AST/Expr.h
===
--- include/clang/AST/Expr.h
+++ include/clang/AST/Expr.h
@@ -3899,6 +3899,10 @@
   /// initializer)?
   bool isTransparent() const;
 
+  /// Is this the zero initializer {0} in a language which considers it
+  /// idiomatic?
+  bool isIdiomaticZeroInitializer(const LangOptions &LangOpts) const;
+
   SourceLocation getLBraceLoc() const { return LBraceLoc; }
   void setLBraceLoc(SourceLocation Loc) { LBraceLoc = Loc; }
   SourceLocation getRBraceLoc() const { return RBraceLoc; }
@@ -3908,6 +3

[PATCH] D28220: provide Win32 native threading

2017-01-03 Thread Kim Gräsman via Phabricator via cfe-commits
kimgr added a comment.

Re Eric's windows.h concern.




Comment at: include/__threading_support:44
+#define WIN32_LEAN_AND_MEAN
+#define VC_EXTRA_LEAN
+#include 

EricWF wrote:
> compnerd wrote:
> > EricWF wrote:
> > > Do these definitions have any affect when `` has already been 
> > > included?
> > > Also are these definitions required before including the header, or 
> > > merely beneficial? If they are required this will make the `` 
> > > header a pain to use with modules.
> > > 
> > > 
> > No, they dont effect it once it has been included.  They are beneficial 
> > since they reduce the amount of stuff that gets included (including things 
> > which, at least when I last checked, can cause clang to choke).
> And can users re-include `` afterwards in the same TU and get all 
> of the symbols?
I don't think so.

We've recently switched to defining these two symbols in our build system, and 
I think that's basically the only way to make this work in a project composed 
of headers from various authors. I think you're right that libc++ should not 
define them.


Repository:
  rL LLVM

https://reviews.llvm.org/D28220



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


[PATCH] D28148: [Sema] Suppress warnings for C's zero initializer

2017-01-03 Thread S. Gilles via Phabricator via cfe-commits
sgilles marked an inline comment as done.
sgilles added a comment.

Thanks to danielmarjamaki and rsmith for comments, which I think this diff 
addresses.  I have not done an extensive search of the codebase for places 
where `isSyntacticForm()` would be useful, but there don't seem to be any 
callers of `getSyntacticForm()` which used it in the way I did, so I believe 
that is okay.




Comment at: lib/AST/Expr.cpp:1887
+bool InitListExpr::isIdiomaticZeroInitializer(const LangOptions &LangOpts) 
const {
+  assert(!getSyntacticForm() && "only test syntactic form as zero 
initializer");
+

rsmith wrote:
> `!isSyntacticForm()` would be preferable here instead of 
> `!getSyntacticForm()`.
I believe `isSyntacticForm()` makes sense here - please correct me if I've 
misunderstood.


https://reviews.llvm.org/D28148



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


[PATCH] D28222: [libcxx] Re-implement LWG 2770 again: Fix tuple_size to work with structured bindings

2017-01-03 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF planned changes to this revision.
EricWF added a comment.

I thought this formulation worked for GCC and Clang but it appears it does not. 
I'll update with another attempt.


https://reviews.llvm.org/D28222



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


[PATCH] D28222: [libcxx] Re-implement LWG 2770 again: Fix tuple_size to work with structured bindings

2017-01-03 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF updated this revision to Diff 82850.
EricWF added a comment.
This revision is now accepted and ready to land.

@rsmith Could you re-review this please? It's a mostly different implementation.


https://reviews.llvm.org/D28222

Files:
  include/__tuple
  test/libcxx/test/config.py
  test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size.pass.cpp
  
test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_incomplete.fail.cpp
  
test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_incomplete.pass.cpp
  
test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_structured_bindings.pass.cpp
  
test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_value_sfinae.pass.cpp

Index: test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_value_sfinae.pass.cpp
===
--- /dev/null
+++ test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_value_sfinae.pass.cpp
@@ -0,0 +1,39 @@
+//===--===//
+//
+// 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.
+//
+//===--===//
+
+// 
+
+// template  class tuple;
+
+// template 
+//   class tuple_size>
+// : public integral_constant { };
+
+// XFAIL: gcc-4.9
+// UNSUPPORTED: c++98, c++03
+
+#include 
+#include 
+
+template ::value)>
+constexpr bool has_value(int) { return true; }
+template  constexpr bool has_value(long) { return false; }
+template  constexpr bool has_value() { return has_value(0); }
+
+struct Dummy {};
+
+int main() {
+  // Test that the ::value member does not exist
+  static_assert(has_value const>(), "");
+  static_assert(has_value volatile>(), "");
+  static_assert(!has_value(), "");
+  static_assert(!has_value(), "");
+  static_assert(!has_value(), "");
+  static_assert(!has_value&>(), "");
+}
Index: test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_structured_bindings.pass.cpp
===
--- /dev/null
+++ test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_structured_bindings.pass.cpp
@@ -0,0 +1,105 @@
+//===--===//
+//
+// 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.
+//
+//===--===//
+
+// 
+
+// template  class tuple;
+
+// template 
+//   class tuple_size>
+// : public integral_constant { };
+
+// UNSUPPORTED: c++98, c++03, c++11, c++14
+// XFAIL: libcpp-no-structured-bindings
+
+#include 
+#include 
+#include 
+#include 
+
+struct S { int x; };
+
+void test_decomp_user_type() {
+  {
+S s{99};
+auto [m1] = s;
+auto& [r1] = s;
+assert(m1 == 99);
+assert(&r1 == &s.x);
+  }
+  {
+S const s{99};
+auto [m1] = s;
+auto& [r1] = s;
+assert(m1 == 99);
+assert(&r1 == &s.x);
+  }
+}
+
+void test_decomp_tuple() {
+  typedef std::tuple T;
+  {
+T s{99};
+auto [m1] = s;
+auto& [r1] = s;
+assert(m1 == 99);
+assert(&r1 == &std::get<0>(s));
+  }
+  {
+T const s{99};
+auto [m1] = s;
+auto& [r1] = s;
+assert(m1 == 99);
+assert(&r1 == &std::get<0>(s));
+  }
+}
+
+
+void test_decomp_pair() {
+  typedef std::pair T;
+  {
+T s{99, 42.1};
+auto [m1, m2] = s;
+auto& [r1, r2] = s;
+assert(m1 == 99);
+assert(&r1 == &std::get<0>(s));
+  }
+  {
+T const s{99, 42.1};
+auto [m1, m2] = s;
+auto& [r1, r2] = s;
+assert(m1 == 99);
+assert(&r1 == &std::get<0>(s));
+  }
+}
+
+void test_decomp_array() {
+  typedef std::array T;
+  {
+T s{{99, 42, -1}};
+auto [m1, m2, m3] = s;
+auto& [r1, r2, r3] = s;
+assert(m1 == 99);
+assert(&r1 == &std::get<0>(s));
+  }
+  {
+T const s{{99, 42, -1}};
+auto [m1, m2, m3] = s;
+auto& [r1, r2, r3] = s;
+assert(m1 == 99);
+assert(&r1 == &std::get<0>(s));
+  }
+}
+
+int main() {
+  test_decomp_user_type();
+  test_decomp_tuple();
+  test_decomp_pair();
+  test_decomp_array();
+}
Index: test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_incomplete.pass.cpp
===
--- /dev/null
+++ test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_incomplete.pass.cpp
@@ -0,0 +1,67 @@
+//===--===//
+//
+// 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.
+//
+//===--

[PATCH] D28222: [libcxx] Re-implement LWG 2770 again: Fix tuple_size to work with structured bindings

2017-01-03 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF updated this revision to Diff 82851.
EricWF added a comment.

- Remove redundant SFINAE.


https://reviews.llvm.org/D28222

Files:
  include/__tuple
  test/libcxx/test/config.py
  test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size.pass.cpp
  
test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_incomplete.fail.cpp
  
test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_incomplete.pass.cpp
  
test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_structured_bindings.pass.cpp
  
test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_value_sfinae.pass.cpp

Index: test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_value_sfinae.pass.cpp
===
--- /dev/null
+++ test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_value_sfinae.pass.cpp
@@ -0,0 +1,39 @@
+//===--===//
+//
+// 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.
+//
+//===--===//
+
+// 
+
+// template  class tuple;
+
+// template 
+//   class tuple_size>
+// : public integral_constant { };
+
+// XFAIL: gcc-4.9
+// UNSUPPORTED: c++98, c++03
+
+#include 
+#include 
+
+template ::value)>
+constexpr bool has_value(int) { return true; }
+template  constexpr bool has_value(long) { return false; }
+template  constexpr bool has_value() { return has_value(0); }
+
+struct Dummy {};
+
+int main() {
+  // Test that the ::value member does not exist
+  static_assert(has_value const>(), "");
+  static_assert(has_value volatile>(), "");
+  static_assert(!has_value(), "");
+  static_assert(!has_value(), "");
+  static_assert(!has_value(), "");
+  static_assert(!has_value&>(), "");
+}
Index: test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_structured_bindings.pass.cpp
===
--- /dev/null
+++ test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_structured_bindings.pass.cpp
@@ -0,0 +1,105 @@
+//===--===//
+//
+// 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.
+//
+//===--===//
+
+// 
+
+// template  class tuple;
+
+// template 
+//   class tuple_size>
+// : public integral_constant { };
+
+// UNSUPPORTED: c++98, c++03, c++11, c++14
+// XFAIL: libcpp-no-structured-bindings
+
+#include 
+#include 
+#include 
+#include 
+
+struct S { int x; };
+
+void test_decomp_user_type() {
+  {
+S s{99};
+auto [m1] = s;
+auto& [r1] = s;
+assert(m1 == 99);
+assert(&r1 == &s.x);
+  }
+  {
+S const s{99};
+auto [m1] = s;
+auto& [r1] = s;
+assert(m1 == 99);
+assert(&r1 == &s.x);
+  }
+}
+
+void test_decomp_tuple() {
+  typedef std::tuple T;
+  {
+T s{99};
+auto [m1] = s;
+auto& [r1] = s;
+assert(m1 == 99);
+assert(&r1 == &std::get<0>(s));
+  }
+  {
+T const s{99};
+auto [m1] = s;
+auto& [r1] = s;
+assert(m1 == 99);
+assert(&r1 == &std::get<0>(s));
+  }
+}
+
+
+void test_decomp_pair() {
+  typedef std::pair T;
+  {
+T s{99, 42.1};
+auto [m1, m2] = s;
+auto& [r1, r2] = s;
+assert(m1 == 99);
+assert(&r1 == &std::get<0>(s));
+  }
+  {
+T const s{99, 42.1};
+auto [m1, m2] = s;
+auto& [r1, r2] = s;
+assert(m1 == 99);
+assert(&r1 == &std::get<0>(s));
+  }
+}
+
+void test_decomp_array() {
+  typedef std::array T;
+  {
+T s{{99, 42, -1}};
+auto [m1, m2, m3] = s;
+auto& [r1, r2, r3] = s;
+assert(m1 == 99);
+assert(&r1 == &std::get<0>(s));
+  }
+  {
+T const s{{99, 42, -1}};
+auto [m1, m2, m3] = s;
+auto& [r1, r2, r3] = s;
+assert(m1 == 99);
+assert(&r1 == &std::get<0>(s));
+  }
+}
+
+int main() {
+  test_decomp_user_type();
+  test_decomp_tuple();
+  test_decomp_pair();
+  test_decomp_array();
+}
Index: test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_incomplete.pass.cpp
===
--- /dev/null
+++ test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_incomplete.pass.cpp
@@ -0,0 +1,67 @@
+//===--===//
+//
+// 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.
+//
+//===--===//
+
+// 
+
+// template  class tuple;
+
+// template 
+//   class tuple_siz

[PATCH] D27621: [clang-tidy] check to find declarations declaring more than one name

2017-01-03 Thread Firat Kasmis via Phabricator via cfe-commits
firolino marked 5 inline comments as done.
firolino added inline comments.



Comment at: clang-tidy/readability/OneNamePerDeclarationCheck.cpp:34
+  // a tag declaration (e.g. struct, class etc.):
+  // class A { } Object1, Object2;  <-- won't be matched
+  Finder->addMatcher(

aaron.ballman wrote:
> firolino wrote:
> > firolino wrote:
> > > firolino wrote:
> > > > firolino wrote:
> > > > > aaron.ballman wrote:
> > > > > > firolino wrote:
> > > > > > > aaron.ballman wrote:
> > > > > > > > Why do we not want to match this?
> > > > > > > If we decide, whether we transform 
> > > > > > > ```
> > > > > > > class A { 
> > > > > > > } Object1, Object2;
> > > > > > > ``` 
> > > > > > > to
> > > > > > > ```
> > > > > > > class A { 
> > > > > > > } Object1, 
> > > > > > > Object2;
> > > > > > > ``` 
> > > > > > > or
> > > > > > > ```
> > > > > > > class A { 
> > > > > > > } 
> > > > > > > Object1, 
> > > > > > > Object2;
> > > > > > > ``` 
> > > > > > > I might consider adding support for it. Moreover, this kind of 
> > > > > > > definition is usually seen globally and I don't know how to 
> > > > > > > handle globals yet. See 
> > > > > > > http://lists.llvm.org/pipermail/cfe-dev/2015-November/046262.html
> > > > > > I think this should be handled. It can be handled in either of the 
> > > > > > forms you show, or by saying:
> > > > > > ```
> > > > > > A Object1;
> > > > > > A Object2;
> > > > > > ```
> > > > > > If all of these turn out to be a problem, we can still diagnose 
> > > > > > without providing a fixit.
> > > > > > 
> > > > > > As for globals in general, they can be handled in a separate patch 
> > > > > > once we figure out the declaration grouping.
> > > > > OK. I will try to split the object definition from the class 
> > > > > definition, as you have suggested. Thus, I can kick out the 
> > > > > tagDecl-matcher as well. If there is no easy way to do this, it will 
> > > > > be reported anyway but without a fixit.
> > > > > 
> > > > > Note for me: Update documentation!
> > > > What about
> > > > ```
> > > > struct S {
> > > > } S1;
> > > > ```
> > > > I would like to report this too, since two names are being declared 
> > > > here. `S` and `S1`. What do you think?
> > > ```
> > > struct {
> > > } nn1, nn2;
> > > ```
> > > Shall we ignore anonymous definitions?
> > To be more precise: Warn and provide a fixit for `struct S {} S1`. Only 
> > warn for `struct {} nn1, nn2`.
> > What about
> > 
> > ```
> > struct S {
> > } S1;
> > ```
> > I would like to report this too, since two names are being declared here. S 
> > and S1. What do you think?
> 
> I don't think that this should be diagnosed. For one, this is a relatively 
> common pattern (arguably more common than `struct S { } S1, S2;`), but also, 
> it names two very distinct entities (a type and a variable).
> 
> > ```
> > struct {
> > } nn1, nn2;
> >```
> > Shall we ignore anonymous definitions?
> 
> Yes, we basically have to.
> 
Transforming
```
typedef struct X { int t; } X, Y;
```
to
```
typedef struct X { int t; };
typedef X X;
typedef X Y;
```
will be valid, but looks odd.


https://reviews.llvm.org/D27621



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


[PATCH] D28223: clean up use of _WIN32

2017-01-03 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF added inline comments.



Comment at: include/__config:158
+#if defined(_WIN32)
+#  define _LIBCPP_WIN32 1
 #  define _LIBCPP_LITTLE_ENDIAN 1

smeenai wrote:
> Perhaps `_LIBCPP_WIN32API` instead, to be clear that this is specific to the 
> usage of Win32 APIs, rather than just a general catch-all libc++ on Windows 
> macro?
+1 for that name, since it is self documenting.



Comment at: include/__config:791
 // Most unix variants have catopen.  These are the specific ones that don't.
-#if !defined(_WIN32) && !defined(__BIONIC__) && !defined(_NEWLIB_VERSION)
+#if !defined(__BIONIC__) && !defined(_NEWLIB_VERSION)
 #define _LIBCPP_HAS_CATOPEN 1

smeenai wrote:
> Windows has `catopen`?
This is nested in a block that already excludes windows.



Comment at: include/type_traits:1684
 // PE/COFF does not support alignment beyond 8192 (=0x2000)
-#if !defined(_WIN32)
+#if !defined(__ELF__) && !defined(__MACH__)
 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x4000);

smeenai wrote:
> Might be cleaner to have a `_LIBCPP_COFF` macro (both here and for the 
> similar `__config` change), to make the intent clearer?
+1 for `_LIBCPP_COFF` or similar. I would rather explicitly exclude coff than 
include a list of supported formats.



Comment at: src/thread.cpp:27
 
-#if !defined(_WIN32)
+#if defined(__unix__) || defined(__APPLE__)
 # include 

I wonder if the drivers on solaris define `__unix__`. 


Repository:
  rL LLVM

https://reviews.llvm.org/D28223



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


[PATCH] D27621: [clang-tidy] check to find declarations declaring more than one name

2017-01-03 Thread Firat Kasmis via Phabricator via cfe-commits
firolino updated the summary for this revision.
firolino updated this revision to Diff 82855.
firolino marked an inline comment as done.
firolino added a comment.

- applied suggestions from Aaron
- added support and test cases for TagDecl e.g.

  struct S {} S1, S2;


https://reviews.llvm.org/D27621

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/OneNamePerDeclarationCheck.cpp
  clang-tidy/readability/OneNamePerDeclarationCheck.h
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/utils/LexerUtils.cpp
  clang-tidy/utils/LexerUtils.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-one-name-per-declaration.rst
  test/clang-tidy/readability-one-name-per-declaration-complex.cpp
  test/clang-tidy/readability-one-name-per-declaration-modern.cpp
  test/clang-tidy/readability-one-name-per-declaration-simple.cpp

Index: test/clang-tidy/readability-one-name-per-declaration-simple.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-one-name-per-declaration-simple.cpp
@@ -0,0 +1,176 @@
+// RUN: %check_clang_tidy %s readability-one-name-per-declaration %t
+
+int cantTouchA, cantTouchB;
+
+void simple() 
+{
+int dontTouchC;
+
+long empty;
+long long1 = 11, *long2 = &empty, * long3 = ∅
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: multiple declarations should be split
+// CHECK-FIXES: {{^}}long long1 = 11;
+// CHECK-FIXES: {{^}}long *long2 = ∅
+// CHECK-FIXES: {{^}}long * long3 = ∅
+
+long ** lint1, lint2 = 0, * lint3, **linn;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: multiple declarations should be split
+// CHECK-FIXES: {{^}}long ** lint1;
+// CHECK-FIXES: {{^}}long lint2 = 0;
+// CHECK-FIXES: {{^}}long * lint3;
+// CHECK-FIXES: {{^}}long **linn;
+
+	long int* lint4, *lint5,  lint6;
+	// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: multiple declarations should be split
+	// CHECK-FIXES: {{^	}}long int* lint4;
+	// CHECK-FIXES: {{^	}}long int *lint5;
+	// CHECK-FIXES: {{^	}}long int lint6;
+
+/* *& */ int /* *& */ ** /* *& */ pp,*xx;
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: multiple declarations should be split
+// CHECK-FIXES: {{^}}/* *& */ int /* *& */ ** /* *& */ pp;
+// CHECK-FIXES: {{^}}int *xx;
+
+unsigned int uint1 = 0,uint2 = 44u, uint3, uint4=4;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: multiple declarations should be split
+// CHECK-FIXES: {{^}}unsigned int uint1 = 0;
+// CHECK-FIXES: {{^}}unsigned int uint2 = 44u;
+// CHECK-FIXES: {{^}}unsigned int uint3;
+// CHECK-FIXES: {{^}}unsigned int uint4=4;
+
+const int * const cpc = &dontTouchC, simple = 0;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: multiple declarations should be split
+// CHECK-FIXES: {{^}}const int * const cpc = &dontTouchC;
+// CHECK-FIXES: {{^}}const int simple = 0;
+
+double darray1[] = {}, darray2[] = {1,	2},dv1 = 3,dv2;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: multiple declarations should be split
+// CHECK-FIXES: {{^}}double darray1[] = {};
+// CHECK-FIXES: {{^}}double darray2[] = {1,	2};
+// CHECK-FIXES: {{^}}double dv1 = 3;
+// CHECK-FIXES: {{^}}double dv2;
+
+int notransform[] =   {
+  1,
+  2
+  };
+
+const int cx = 1, cy = 2;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: multiple declarations should be split
+// CHECK-FIXES: {{^}}const int cx = 1;
+// CHECK-FIXES: {{^}}const int cy = 2;
+
+volatile int vx, vy;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: multiple declarations should be split
+// CHECK-FIXES: {{^}}volatile int vx;
+// CHECK-FIXES: {{^}}volatile int vy;
+
+signed char sc1 = 'h', sc2;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: multiple declarations should be split
+// CHECK-FIXES: {{^}}signed char sc1 = 'h';
+// CHECK-FIXES: {{^}}signed char sc2;
+
+long long ll1, ll2, ***ft;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: multiple declarations should be split
+// CHECK-FIXES: {{^}}long long ll1;
+// CHECK-FIXES: {{^}}long long ll2;
+// CHECK-FIXES: {{^}}long long ***ft;
+
+const char *cstr1 = "str1", *cstr2="str2";
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: multiple declarations should be split
+// CHECK-FIXES: {{^}}const char *cstr1 = "str1";
+// CHECK-FIXES: {{^}}const char *cstr2="str2";
+
+const char *literal1 = "clang"		"test" \
+   "one",
+   *literal2 = "empty", literal3[] = "three";
+// CHECK-MESSAGES: :[[@LINE-3]]:5: warning: multiple declarations should be split
+// CHECK-FIXES: {{^}}const char *literal

[PATCH] D26830: [libcxx] Add string_view literals

2017-01-03 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF added inline comments.



Comment at: 
test/std/strings/string.view/string.view.literals/literal3.pass.cpp:16
+
+int main()
+{

You can move this test into `literal.pass.cpp` but putting it at another 
function scope.


https://reviews.llvm.org/D26830



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


[PATCH] D28228: [clang-move] Support moving enum declarations.

2017-01-03 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: ioeric.
hokein added a subscriber: cfe-commits.

https://reviews.llvm.org/D28228

Files:
  clang-move/ClangMove.cpp
  test/clang-move/Inputs/enum.h
  test/clang-move/move-enum-decl.cpp
  unittests/clang-move/ClangMoveTests.cpp

Index: unittests/clang-move/ClangMoveTests.cpp
===
--- unittests/clang-move/ClangMoveTests.cpp
+++ unittests/clang-move/ClangMoveTests.cpp
@@ -370,7 +370,6 @@
   std::vector TestHeaders = {
   "typedef int Int;\nclass A {\npublic:\n  int f();\n};\n",
   "using Int = int;\nclass A {\npublic:\n  int f();\n};\n",
-  "enum Color { RED };\nclass A {\npublic:\n  int f();\n};\n",
   };
   move::MoveDefinitionSpec Spec;
   Spec.Names.push_back("A");
Index: test/clang-move/move-enum-decl.cpp
===
--- /dev/null
+++ test/clang-move/move-enum-decl.cpp
@@ -0,0 +1,44 @@
+// RUN: mkdir -p %T/move-enum
+// RUN: cp %S/Inputs/enum.h  %T/move-enum/enum.h
+// RUN: echo '#include "enum.h"' > %T/move-enum/enum.cpp
+// RUN: cd %T/move-enum
+//
+// -
+// Test moving enum declarations.
+// -
+// RUN: clang-move -names="a::E1" -new_cc=%T/move-enum/new_test.cpp -new_header=%T/move-enum/new_test.h -old_cc=%T/move-enum/enum.cpp -old_header=%T/move-enum/enum.h %T/move-enum/enum.cpp -- -std=c++11
+// RUN: FileCheck -input-file=%T/move-enum/new_test.h -check-prefix=CHECK-NEW-TEST-H-CASE1 %s
+// RUN: FileCheck -input-file=%T/move-enum/enum.h -check-prefix=CHECK-OLD-TEST-H-CASE1 %s
+//
+// CHECK-NEW-TEST-H-CASE1: namespace a {
+// CHECK-NEW-TEST-H-CASE1-NEXT: enum E1 { Green, Red };
+// CHECK-NEW-TEST-H-CASE1-NEXT: }
+
+// CHECK-OLD-TEST-H-CASE1-NOT: enum E1 { Green, Red };
+
+
+// -
+// Test moving scoped enum declarations.
+// -
+// RUN: cp %S/Inputs/enum.h  %T/move-enum/enum.h
+// RUN: echo '#include "enum.h"' > %T/move-enum/enum.cpp
+// RUN: clang-move -names="a::E2" -new_cc=%T/move-enum/new_test.cpp -new_header=%T/move-enum/new_test.h -old_cc=%T/move-enum/enum.cpp -old_header=%T/move-enum/enum.h %T/move-enum/enum.cpp -- -std=c++11
+// RUN: FileCheck -input-file=%T/move-enum/new_test.h -check-prefix=CHECK-NEW-TEST-H-CASE2 %s
+// RUN: FileCheck -input-file=%T/move-enum/enum.h -check-prefix=CHECK-OLD-TEST-H-CASE2 %s
+
+// CHECK-NEW-TEST-H-CASE2: namespace a {
+// CHECK-NEW-TEST-H-CASE2-NEXT: enum class E2 { Yellow };
+// CHECK-NEW-TEST-H-CASE2-NEXT: }
+
+// CHECK-OLD-TEST-H-CASE2-NOT: enum class E2 { Yellow };
+
+
+// -
+// Test not moving class-insided enum declarations.
+// -
+// RUN: cp %S/Inputs/enum.h  %T/move-enum/enum.h
+// RUN: echo '#include "enum.h"' > %T/move-enum/enum.cpp
+// RUN: clang-move -names="a::C::E3" -new_cc=%T/move-enum/new_test.cpp -new_header=%T/move-enum/new_test.h -old_cc=%T/move-enum/enum.cpp -old_header=%T/move-enum/enum.h %T/move-enum/enum.cpp -- -std=c++11
+// RUN: FileCheck -input-file=%T/move-enum/new_test.h -allow-empty -check-prefix=CHECK-EMPTY %s
+
+// CHECK-EMPTY: {{^}}{{$}}
Index: test/clang-move/Inputs/enum.h
===
--- /dev/null
+++ test/clang-move/Inputs/enum.h
@@ -0,0 +1,9 @@
+namespace a {
+enum E1 { Green, Red };
+
+enum class E2 { Yellow };
+
+class C {
+  enum E3 { Blue };
+};
+} // namespace a
Index: clang-move/ClangMove.cpp
===
--- clang-move/ClangMove.cpp
+++ clang-move/ClangMove.cpp
@@ -160,6 +160,23 @@
   ClangMoveTool *MoveTool;
 };
 
+class EnumDeclarationMatch : public MatchFinder::MatchCallback {
+public:
+  explicit EnumDeclarationMatch(ClangMoveTool *MoveTool)
+  : MoveTool(MoveTool) {}
+
+  void run(const MatchFinder::MatchResult &Result) override {
+const auto *ED = Result.Nodes.getNodeAs("enum");
+assert(ED);
+MoveTool->getMovedDecls().push_back(ED);
+MoveTool->getUnremovedDeclsInOldHeader().erase(ED);
+MoveTool->addRemovedDecl(ED);
+  }
+
+private:
+  ClangMoveTool *MoveTool;
+};
+
 class ClassDeclarationMatch : public MatchFinder::MatchCallback {
 public:
   explicit ClassDeclarationMatch(ClangMoveTool *MoveTool)
@@ -449,6 +466,8 @@
   auto InOldFiles = anyOf(InOldHeader, InOldCC);
   auto ForwardDecls =
   cxxRecordDecl(unless(anyOf(isImplicit(), isDefinition(;
+  auto TopLevelDecl =
+  hasDeclContext(anyOf(namespaceDecl(), translationUnitDecl()));
 
   //
   // Matchers for old head

[PATCH] D26830: [libcxx] Add string_view literals

2017-01-03 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF added a comment.

This LGTM. I'll approve once I see the inline comments addressed.




Comment at: 
test/std/strings/string.view/string.view.literals/literal.pass.cpp:10
+//===--===//
+
+// UNSUPPORTED: c++98, c++03, c++11, c++14

This needs a `// XFAIL: clang-3, gcc-4, apple-clang-7, apple-clang-8`


https://reviews.llvm.org/D26830



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


[libcxx] r290875 - Simplify CMake target for the __generated_config header

2017-01-03 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Tue Jan  3 05:18:17 2017
New Revision: 290875

URL: http://llvm.org/viewvc/llvm-project?rev=290875&view=rev
Log:
Simplify CMake target for the __generated_config header

Modified:
libcxx/trunk/include/CMakeLists.txt

Modified: libcxx/trunk/include/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/CMakeLists.txt?rev=290875&r1=290874&r2=290875&view=diff
==
--- libcxx/trunk/include/CMakeLists.txt (original)
+++ libcxx/trunk/include/CMakeLists.txt Tue Jan  3 05:18:17 2017
@@ -31,11 +31,8 @@ if (LIBCXX_INSTALL_HEADERS)
 # Generate and install a custom __config header. The new header is created
 # by  prepending __config_site to the current __config header.
 add_custom_command(OUTPUT ${LIBCXX_BINARY_DIR}/__generated_config
-  COMMAND ${CMAKE_COMMAND} -E copy
-${LIBCXX_BINARY_DIR}/__config_site
-${LIBCXX_BINARY_DIR}/__generated_config
   COMMAND ${PYTHON_EXECUTABLE} ${LIBCXX_SOURCE_DIR}/utils/cat_files.py
-${LIBCXX_BINARY_DIR}/__generated_config
+${LIBCXX_BINARY_DIR}/__config_site
 ${LIBCXX_SOURCE_DIR}/include/__config
 -o ${LIBCXX_BINARY_DIR}/__generated_config
   DEPENDS ${LIBCXX_SOURCE_DIR}/include/__config


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


[libcxx] r290876 - Update year to 2017

2017-01-03 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Tue Jan  3 05:20:43 2017
New Revision: 290876

URL: http://llvm.org/viewvc/llvm-project?rev=290876&view=rev
Log:
Update year to 2017

Modified:
libcxx/trunk/LICENSE.TXT
libcxx/trunk/docs/conf.py
libcxx/trunk/www/cxx1z_status.html

Modified: libcxx/trunk/LICENSE.TXT
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/LICENSE.TXT?rev=290876&r1=290875&r2=290876&view=diff
==
--- libcxx/trunk/LICENSE.TXT (original)
+++ libcxx/trunk/LICENSE.TXT Tue Jan  3 05:20:43 2017
@@ -14,7 +14,7 @@ Full text of the relevant licenses is in
 University of Illinois/NCSA
 Open Source License
 
-Copyright (c) 2009-2016 by the contributors listed in CREDITS.TXT
+Copyright (c) 2009-2017 by the contributors listed in CREDITS.TXT
 
 All rights reserved.
 

Modified: libcxx/trunk/docs/conf.py
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/docs/conf.py?rev=290876&r1=290875&r2=290876&view=diff
==
--- libcxx/trunk/docs/conf.py (original)
+++ libcxx/trunk/docs/conf.py Tue Jan  3 05:20:43 2017
@@ -40,7 +40,7 @@ master_doc = 'index'
 
 # General information about the project.
 project = u'libc++'
-copyright = u'2011-2016, LLVM Project'
+copyright = u'2011-2017, LLVM Project'
 
 # The version info for the project you're documenting, acts as replacement for
 # |version| and |release|, also used in various other places throughout the

Modified: libcxx/trunk/www/cxx1z_status.html
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/www/cxx1z_status.html?rev=290876&r1=290875&r2=290876&view=diff
==
--- libcxx/trunk/www/cxx1z_status.html (original)
+++ libcxx/trunk/www/cxx1z_status.html Tue Jan  3 05:20:43 2017
@@ -417,7 +417,7 @@
 
   
 
-  Last Updated: 14-Nov-2016
+  Last Updated: 3-Jan-2017
 
 
 


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


[PATCH] D28228: [clang-move] Support moving enum declarations.

2017-01-03 Thread Eric Liu via Phabricator via cfe-commits
ioeric added a comment.

Do we consider enum helpers?




Comment at: clang-move/ClangMove.cpp:171
+assert(ED);
+MoveTool->getMovedDecls().push_back(ED);
+MoveTool->getUnremovedDeclsInOldHeader().erase(ED);

These 3 lines seen to be repeated. Maybe pull them out as a `MoveTool` method?


https://reviews.llvm.org/D28228



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


[PATCH] D28229: [libcxx] Fix testing of the externally-threaded library build after r290850

2017-01-03 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath created this revision.
rmaprath added reviewers: compnerd, EricWF.
rmaprath added a subscriber: cfe-commits.

Before r290850, building libcxx with `-DLIBCXX_HAS_EXTERNAL_THREAD_API=ON` had 
two uses:

- Allow platform vendors to plug-in an `__external_threading` header which 
should take care of the entire threading infrastructure of libcxx
- Allow testing of an externally-threaded library build; where the thread API 
is declared using pthread data structures, and the implementation of this API 
is provided as a separate library (`test/support/external_threads.cpp`) and 
linked-in when running the test suite.

r290850 breaks the second use case (pthread data structures are no longer 
available). This patch re-stores the ability to build+test an 
externally-threaded library variant on a pthread based system.

This wasn't caught on any of the official bots because we don't have any builds 
of the externally-threaded library build at the moment (apart from my 
downstream one).


https://reviews.llvm.org/D28229

Files:
  include/__threading_support
  test/support/external_threads.cpp


Index: test/support/external_threads.cpp
===
--- test/support/external_threads.cpp
+++ test/support/external_threads.cpp
@@ -6,5 +6,5 @@
 // Source Licenses. See LICENSE.TXT for details.
 //
 
//===--===//
-#define _LIBCPP_HAS_THREAD_API_PTHREAD
+#define _LIBCPP_BUILDING_THREAD_API_EXTERNAL_PTHREAD
 #include <__threading_support>
Index: include/__threading_support
===
--- include/__threading_support
+++ include/__threading_support
@@ -28,11 +28,23 @@
 #endif
 
 #if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) && \
+!__libcpp_has_include(<__external_threading>)
+// If the <__external_threading> header is absent, build libc++ against a
+// pthread-oriented thread api but leave out its implementation. This setup
+// allows building+testing of an externally-threaded library variant (on any
+// platform that supports pthreads). Here, an 'externally-threaded' library
+// variant is one where the implementation of the libc++ thread api is provided
+// as a separate library.
+#define _LIBCPP_HAS_THREAD_API_EXTERNAL_PTHREAD
+#endif
+
+#if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) && \
 __libcpp_has_include(<__external_threading>)
 #include <__external_threading>
 #else
 
-#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
+#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) || \
+defined(_LIBCPP_HAS_THREAD_API_EXTERNAL_PTHREAD)
 #include 
 #include 
 #endif
@@ -45,7 +57,8 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
+#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) || \
+defined(_LIBCPP_HAS_THREAD_API_EXTERNAL_PTHREAD)
 // Mutex
 typedef pthread_mutex_t __libcpp_mutex_t;
 #define _LIBCPP_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
@@ -134,7 +147,8 @@
 _LIBCPP_THREAD_ABI_VISIBILITY
 void __libcpp_tls_set(__libcpp_tls_key __key, void *__p);
 
-#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
+#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) || \
+defined(_LIBCPP_BUILDING_THREAD_API_EXTERNAL_PTHREAD)
 
 int __libcpp_recursive_mutex_init(__libcpp_mutex_t *__m)
 {


Index: test/support/external_threads.cpp
===
--- test/support/external_threads.cpp
+++ test/support/external_threads.cpp
@@ -6,5 +6,5 @@
 // Source Licenses. See LICENSE.TXT for details.
 //
 //===--===//
-#define _LIBCPP_HAS_THREAD_API_PTHREAD
+#define _LIBCPP_BUILDING_THREAD_API_EXTERNAL_PTHREAD
 #include <__threading_support>
Index: include/__threading_support
===
--- include/__threading_support
+++ include/__threading_support
@@ -28,11 +28,23 @@
 #endif
 
 #if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) && \
+!__libcpp_has_include(<__external_threading>)
+// If the <__external_threading> header is absent, build libc++ against a
+// pthread-oriented thread api but leave out its implementation. This setup
+// allows building+testing of an externally-threaded library variant (on any
+// platform that supports pthreads). Here, an 'externally-threaded' library
+// variant is one where the implementation of the libc++ thread api is provided
+// as a separate library.
+#define _LIBCPP_HAS_THREAD_API_EXTERNAL_PTHREAD
+#endif
+
+#if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) && \
 __libcpp_has_include(<__external_threading>)
 #include <__external_threading>
 #else
 
-#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
+#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) || \
+defined(_LIBCPP_HAS_THREAD_API_EXTERNAL_PTHREAD)
 #include 
 #include 
 #endif
@@ -45,7 +57,8 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
+#if defined(_LIBCPP_HAS_THREAD_A

[libcxxabi] r290877 - Update LICENSE.TXT to 2017

2017-01-03 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Tue Jan  3 05:21:43 2017
New Revision: 290877

URL: http://llvm.org/viewvc/llvm-project?rev=290877&view=rev
Log:
Update LICENSE.TXT to 2017

Modified:
libcxxabi/trunk/LICENSE.TXT

Modified: libcxxabi/trunk/LICENSE.TXT
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/LICENSE.TXT?rev=290877&r1=290876&r2=290877&view=diff
==
--- libcxxabi/trunk/LICENSE.TXT (original)
+++ libcxxabi/trunk/LICENSE.TXT Tue Jan  3 05:21:43 2017
@@ -14,7 +14,7 @@ Full text of the relevant licenses is in
 University of Illinois/NCSA
 Open Source License
 
-Copyright (c) 2009-2016 by the contributors listed in CREDITS.TXT
+Copyright (c) 2009-2017 by the contributors listed in CREDITS.TXT
 
 All rights reserved.
 


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


[PATCH] D28229: [libcxx] Fix testing of the externally-threaded library build after r290850

2017-01-03 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath added a comment.

I will commit this now to get the testing working again. Thought of putting up 
the patch for review in case if there is a better way to do this.

@compnerd: I wondered, for windows threading support, why not do something 
similar to `__external_threading` (and how it is handled in 
`__threading_support`) and offload the entire implementation to a separate 
windows-only header?


https://reviews.llvm.org/D28229



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


[PATCH] D26137: [clang-tidy] Add check name to YAML export

2017-01-03 Thread Alpha Abdoulaye via Phabricator via cfe-commits
Alpha updated this revision to Diff 82860.
Alpha added a comment.

Rebase on top of HEAD.
Ping.


Repository:
  rL LLVM

https://reviews.llvm.org/D26137

Files:
  include/clang/Tooling/Core/Diagnostic.h
  include/clang/Tooling/Core/Replacement.h
  include/clang/Tooling/DiagnosticsYaml.h
  include/clang/Tooling/ReplacementsYaml.h
  lib/Tooling/Core/CMakeLists.txt
  lib/Tooling/Core/Diagnostic.cpp
  
tools/extra/clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h
  tools/extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
  tools/extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
  tools/extra/clang-tidy/ClangTidy.cpp
  tools/extra/clang-tidy/ClangTidy.h
  tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.h
  tools/extra/clang-tidy/tool/ClangTidyMain.cpp
  tools/extra/test/clang-apply-replacements/Inputs/basic/file1.yaml
  tools/extra/test/clang-apply-replacements/Inputs/basic/file2.yaml
  tools/extra/test/clang-apply-replacements/Inputs/conflict/file1.yaml
  tools/extra/test/clang-apply-replacements/Inputs/conflict/file2.yaml
  tools/extra/test/clang-apply-replacements/Inputs/conflict/file3.yaml
  tools/extra/test/clang-apply-replacements/Inputs/crlf/file1.yaml
  tools/extra/test/clang-apply-replacements/Inputs/format/no.yaml
  tools/extra/test/clang-apply-replacements/Inputs/format/yes.yaml
  unittests/Tooling/ReplacementsYamlTest.cpp

Index: unittests/Tooling/ReplacementsYamlTest.cpp
===
--- unittests/Tooling/ReplacementsYamlTest.cpp
+++ unittests/Tooling/ReplacementsYamlTest.cpp
@@ -22,11 +22,10 @@
   TranslationUnitReplacements Doc;
 
   Doc.MainSourceFile = "/path/to/source.cpp";
-  Doc.Context = "some context";
-  Doc.Replacements
-  .push_back(Replacement("/path/to/file1.h", 232, 56, "replacement #1"));
-  Doc.Replacements
-  .push_back(Replacement("/path/to/file2.h", 301, 2, "replacement #2"));
+  Doc.Replacements.push_back(
+  Replacement("/path/to/file1.h", 232, 56, "replacement #1"));
+  Doc.Replacements.push_back(
+  Replacement("/path/to/file2.h", 301, 2, "replacement #2"));
 
   std::string YamlContent;
   llvm::raw_string_ostream YamlContentStream(YamlContent);
@@ -37,7 +36,6 @@
   // NOTE: If this test starts to fail for no obvious reason, check whitespace.
   ASSERT_STREQ("---\n"
"MainSourceFile:  /path/to/source.cpp\n"
-   "Context: some context\n"
"Replacements:\n" // Extra whitespace here!
"  - FilePath:/path/to/file1.h\n"
"Offset:  232\n"
@@ -54,7 +52,6 @@
 TEST(ReplacementsYamlTest, deserializesReplacements) {
   std::string YamlContent = "---\n"
 "MainSourceFile:  /path/to/source.cpp\n"
-"Context: some context\n"
 "Replacements:\n"
 "  - FilePath:/path/to/file1.h\n"
 "Offset:  232\n"
@@ -71,7 +68,6 @@
   ASSERT_FALSE(YAML.error());
   ASSERT_EQ(2u, DocActual.Replacements.size());
   ASSERT_EQ("/path/to/source.cpp", DocActual.MainSourceFile);
-  ASSERT_EQ("some context", DocActual.Context);
   ASSERT_EQ("/path/to/file1.h", DocActual.Replacements[0].getFilePath());
   ASSERT_EQ(232u, DocActual.Replacements[0].getOffset());
   ASSERT_EQ(56u, DocActual.Replacements[0].getLength());
@@ -98,7 +94,6 @@
   ASSERT_FALSE(YAML.error());
   ASSERT_EQ("/path/to/source.cpp", DocActual.MainSourceFile);
   ASSERT_EQ(1u, DocActual.Replacements.size());
-  ASSERT_EQ(std::string(), DocActual.Context);
   ASSERT_EQ("target_file.h", DocActual.Replacements[0].getFilePath());
   ASSERT_EQ(1u, DocActual.Replacements[0].getOffset());
   ASSERT_EQ(10u, DocActual.Replacements[0].getLength());
Index: lib/Tooling/Core/Diagnostic.cpp
===
--- lib/Tooling/Core/Diagnostic.cpp
+++ lib/Tooling/Core/Diagnostic.cpp
@@ -0,0 +1,46 @@
+//===--- Diagnostic.cpp - Framework for clang diagnostics tools --===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+//  Implements classes to support/store diagnostics refactoring.
+//
+//===--===//
+
+#include "clang/Tooling/Core/Diagnostic.h"
+#include "clang/Basic/SourceManager.h"
+
+namespace clang {
+namespace tooling {
+
+DiagnosticMessage::DiagnosticMessage(llvm::StringRef Message)
+: Message(Message), FileOffset(0) {}
+
+DiagnosticMessage::DiagnosticMessage(llvm::StringRef Message,
+ const SourceManager &Sour

[libcxx] r290878 - [libcxx] Fix testing of the externally-threaded library build

2017-01-03 Thread Asiri Rathnayake via cfe-commits
Author: asiri
Date: Tue Jan  3 05:32:31 2017
New Revision: 290878

URL: http://llvm.org/viewvc/llvm-project?rev=290878&view=rev
Log:
[libcxx] Fix testing of the externally-threaded library build
 after r290850

Before r290850, building libcxx with -DLIBCXX_HAS_EXTERNAL_THREAD_API=ON had two
uses:
  - Allow platform vendors to plug-in an __external_threading header which
should take care of the entire threading infrastructure of libcxx

  - Allow testing of an externally-threaded library build; where the thread API
is declared using pthread data structures, and the implementation of this
API is provided as a separate library (test/support/external_threads.cpp)
   and linked-in when running the test suite.

r290850 breaks the second use case (pthread data structures are no longer
available). This patch re-stores the ability to build+test an
externally-threaded library variant on a pthread based system.

Modified:
libcxx/trunk/include/__threading_support
libcxx/trunk/test/support/external_threads.cpp

Modified: libcxx/trunk/include/__threading_support
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__threading_support?rev=290878&r1=290877&r2=290878&view=diff
==
--- libcxx/trunk/include/__threading_support (original)
+++ libcxx/trunk/include/__threading_support Tue Jan  3 05:32:31 2017
@@ -28,11 +28,23 @@
 #endif
 
 #if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) && \
+!__libcpp_has_include(<__external_threading>)
+// If the <__external_threading> header is absent, build libc++ against a
+// pthread-oriented thread api but leave out its implementation. This setup
+// allows building+testing of an externally-threaded library variant (on any
+// platform that supports pthreads). Here, an 'externally-threaded' library
+// variant is one where the implementation of the libc++ thread api is provided
+// as a separate library.
+#define _LIBCPP_HAS_THREAD_API_EXTERNAL_PTHREAD
+#endif
+
+#if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) && \
 __libcpp_has_include(<__external_threading>)
 #include <__external_threading>
 #else
 
-#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
+#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) || \
+defined(_LIBCPP_HAS_THREAD_API_EXTERNAL_PTHREAD)
 #include 
 #include 
 #endif
@@ -45,7 +57,8 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
+#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) || \
+defined(_LIBCPP_HAS_THREAD_API_EXTERNAL_PTHREAD)
 // Mutex
 typedef pthread_mutex_t __libcpp_mutex_t;
 #define _LIBCPP_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
@@ -134,7 +147,8 @@ void *__libcpp_tls_get(__libcpp_tls_key
 _LIBCPP_THREAD_ABI_VISIBILITY
 void __libcpp_tls_set(__libcpp_tls_key __key, void *__p);
 
-#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
+#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) || \
+defined(_LIBCPP_BUILDING_THREAD_API_EXTERNAL_PTHREAD)
 
 int __libcpp_recursive_mutex_init(__libcpp_mutex_t *__m)
 {

Modified: libcxx/trunk/test/support/external_threads.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/support/external_threads.cpp?rev=290878&r1=290877&r2=290878&view=diff
==
--- libcxx/trunk/test/support/external_threads.cpp (original)
+++ libcxx/trunk/test/support/external_threads.cpp Tue Jan  3 05:32:31 2017
@@ -6,5 +6,5 @@
 // Source Licenses. See LICENSE.TXT for details.
 //
 
//===--===//
-#define _LIBCPP_HAS_THREAD_API_PTHREAD
+#define _LIBCPP_BUILDING_THREAD_API_EXTERNAL_PTHREAD
 #include <__threading_support>


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


Re: [PATCH] Add missing Decl::Kind for -print-decl-contexts

2017-01-03 Thread Alex L via cfe-commits
Thanks for working on this patch! I'm sorry to say but I had an earlier
patch in review that fixes this issue (https://reviews.llvm.org/D26964). I
think my patch covers all of the decl kinds that are fixed by this patch. I
plan on committing my patch today.

Alex

On 29 December 2016 at 23:35, Fangrui Song via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> ---
>  lib/Frontend/ASTConsumers.cpp | 37 -
>  1 file changed, 32 insertions(+), 5 deletions(-)
>
> diff --git a/lib/Frontend/ASTConsumers.cpp b/lib/Frontend/ASTConsumers.cpp
> index bd2ee06d16..987b8ca398 100644
> --- a/lib/Frontend/ASTConsumers.cpp
> +++ b/lib/Frontend/ASTConsumers.cpp
> @@ -405,6 +405,22 @@ void DeclContextPrinter::PrintDeclContext(const
> DeclContext* DC,
>PrintDeclContext(DC, Indentation+2);
>break;
>  }
> +case Decl::AccessSpec: {
> +  Out << "\n";
> +  break;
> +}
> +case Decl::ClassTemplate: {
> +  Out << " " << *cast(I) << '\n';
> +  break;
> +}
> +case Decl::ClassTemplateSpecialization: {
> +  Out << " " << *cast<
> ClassTemplateSpecializationDecl>(I) << '\n';
> +  break;
> +}
> +case Decl::ClassTemplatePartialSpecialization: {
> +  Out << " " << *cast<
> ClassTemplatePartialSpecializationDecl>(I) << '\n';
> +  break;
> +}
>  case Decl::IndirectField: {
>IndirectFieldDecl* IFD = cast(I);
>Out << " " << *IFD << '\n';
> @@ -420,6 +436,10 @@ void DeclContextPrinter::PrintDeclContext(const
> DeclContext* DC,
>Out << " " << *FD << '\n';
>break;
>  }
> +case Decl::Friend: {
> +  Out << "\n";
> +  break;
> +}
>  case Decl::Typedef:
>  case Decl::TypeAlias: {
>TypedefNameDecl* TD = cast(I);
> @@ -460,6 +480,14 @@ void DeclContextPrinter::PrintDeclContext(const
> DeclContext* DC,
>Out << "\n";
>break;
>  }
> +case Decl::Using: {
> +  Out << " " << *cast(I) << '\n';
> +  break;
> +}
> +case Decl::UsingShadow: {
> +  Out << " " << *cast(I) << '\n';
> +  break;
> +}
>  case Decl::UsingDirective: {
>Out << "\n";
>break;
> @@ -469,15 +497,14 @@ void DeclContextPrinter::PrintDeclContext(const
> DeclContext* DC,
>Out << " " << *NAD << '\n';
>break;
>  }
> -case Decl::ClassTemplate: {
> -  ClassTemplateDecl *CTD = cast(I);
> -  Out << " " << *CTD << '\n';
> -  break;
> -}
>  case Decl::OMPThreadPrivate: {
>Out << " " << '"' << I << "\"\n";
>break;
>  }
> +case Decl::VarTemplate: {
> +  Out << " " << *cast(I) << '\n';
> +  break;
> +}
>  default:
>Out << "DeclKind: " << DK << '"' << I << "\"\n";
>llvm_unreachable("decl unhandled");
> --
> 2.11.0
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D20689: [clang-tidy] Suspicious Call Argument checker

2017-01-03 Thread Varju Janos via Phabricator via cfe-commits
varjujan updated this revision to Diff 82859.
varjujan added a comment.
Herald added subscribers: JDevlieghere, mgorny.

I have implemented some more heuristics to achieve better results.


https://reviews.llvm.org/D20689

Files:
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/MiscTidyModule.cpp
  clang-tidy/misc/SuspiciousCallArgumentCheck.cpp
  clang-tidy/misc/SuspiciousCallArgumentCheck.h
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-suspicious-call-argument.rst
  test/clang-tidy/misc-suspicious-call-argument.cpp

Index: test/clang-tidy/misc-suspicious-call-argument.cpp
===
--- /dev/null
+++ test/clang-tidy/misc-suspicious-call-argument.cpp
@@ -0,0 +1,87 @@
+// RUN: %check_clang_tidy %s misc-suspicious-call-argument %t -- -- -std=c++11
+
+void foo_1(int aa, int bb) { }
+
+void foo_2(int source, int aa) { }
+
+void foo_3(int valToRet, int aa) { }
+
+void foo_4(int pointer, int aa) { }
+
+void foo_5(int aa, int bb, int cc, ...) { }
+
+void foo_6(const int dd, bool& ee) { }
+
+class TestClass {
+public:
+  void thisFunction(int integerParam, int thisIsPARAM) {}
+};
+
+int main() {
+
+	// Equality test.
+  int aa, cc = 0;  
+  foo_1(cc, aa); // Should fail.
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: cc (aa) is swapped with aa (bb). [misc-suspicious-call-argument]  
+
+  // Abbreviation test.
+  int src = 0;
+  foo_2(aa, src); // Should fail.
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: aa (source) is swapped with src (aa). [misc-suspicious-call-argument]
+  
+  // Levenshtein test.
+  int bb = 0;
+  foo_1(cc, bb); // Should fail.
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: cc (aa) is swapped with bb (bb). [misc-suspicious-call-argument]
+  
+  // Prefix test.
+  int  = 0;
+  foo_1(cc, ); // Should fail.
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: cc (aa) is swapped with  (bb). [misc-suspicious-call-argument]
+  
+  // Suffix test.
+  int urce = 0;
+  foo_2(cc, urce); // Should fail.
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: cc (source) is swapped with urce (aa). [misc-suspicious-call-argument]
+  
+  // Substring test.
+  int ourc = 0;
+  foo_2(cc, ourc); // Should fail.
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: cc (source) is swapped with ourc (aa). [misc-suspicious-call-argument]
+  
+  // Jaro-Winkler test.
+  int iPonter = 0;
+  foo_4(cc, iPonter); // Should fail.
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: cc (pointer) is swapped with iPonter (aa). [misc-suspicious-call-argument]
+  
+  // Dice test.
+  int aaabaa = 0;
+  foo_1(cc, aaabaa); // Should fail.
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: cc (aa) is swapped with aaabaa (bb). [misc-suspicious-call-argument]
+   
+  // Variadic function test.
+  int bb = 0;
+  foo_5(src, bb, cc, aa); // Should pass.
+  foo_5(cc, bb, aa, src); // Should fail.
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: cc (aa) is swapped with aa (cc). [misc-suspicious-call-argument]
+  
+  //Type match
+  bool dd = false;
+  int ee = 0;
+  auto szam = 0;
+  foo_6(ee, dd); // Should pass.
+  foo_1(szam, aa); // Should fail.
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: szam (aa) is swapped with aa (bb). [misc-suspicious-call-argument]
+  
+  // Test lambda.
+  auto testMethod = [&](int method, int randomParam) { return 0; };
+  int method = 0;
+  testMethod(method, 0); // Should pass.
+
+  // Member function test
+  TestClass test;
+  int integ, thisIsAnArg = 0;
+  test.thisFunction(integ, thisIsAnArg); // Should pass.
+
+  return 0;
+}
Index: docs/clang-tidy/checks/misc-suspicious-call-argument.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/misc-suspicious-call-argument.rst
@@ -0,0 +1,9 @@
+misc-suspicious-call-argument
+=
+
+This checker finds those function calls where the function arguments are 
+provided in an incorrect order. It compares the name of the given variable 
+to the argument name in the function definition.
+
+It issues a message if the given variable name is similar to an another 
+function argument in a function call. It uses case insensitive comparison.
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -81,6 +81,7 @@
misc-string-constructor
misc-string-integer-assignment
misc-string-literal-with-embedded-nul
+   misc-suspicious-call-argument
misc-suspicious-missing-comma
misc-suspicious-semicolon
misc-suspicious-string-compare
Index: clang-tidy/misc/SuspiciousCallArgumentCheck.h
==

r290879 - [CodeCompletion] Autocomplete NS_DESIGNATED_INITIALIZER in initializers

2017-01-03 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Tue Jan  3 05:56:40 2017
New Revision: 290879

URL: http://llvm.org/viewvc/llvm-project?rev=290879&view=rev
Log:
[CodeCompletion] Autocomplete NS_DESIGNATED_INITIALIZER in initializers
with arguments

rdar://21014571

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

Added:
cfe/trunk/test/Index/complete-designated-initializer.m
Modified:
cfe/trunk/lib/Sema/SemaCodeComplete.cpp

Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=290879&r1=290878&r2=290879&view=diff
==
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Tue Jan  3 05:56:40 2017
@@ -7471,6 +7471,23 @@ void Sema::CodeCompleteObjCMethodDeclSel
   }
   
   Results.ExitScope();
+
+  if (!AtParameterName && !SelIdents.empty() &&
+  SelIdents.front()->getName().startswith("init")) {
+for (const auto &M : PP.macros()) {
+  if (M.first->getName() != "NS_DESIGNATED_INITIALIZER")
+continue;
+  Results.EnterNewScope();
+  CodeCompletionBuilder Builder(Results.getAllocator(),
+Results.getCodeCompletionTUInfo());
+  Builder.AddTypedTextChunk(
+  Builder.getAllocator().CopyString(M.first->getName()));
+  Results.AddResult(CodeCompletionResult(Builder.TakeString(), CCP_Macro,
+ CXCursor_MacroDefinition));
+  Results.ExitScope();
+}
+  }
+
   HandleCodeCompleteResults(this, CodeCompleter, 
 CodeCompletionContext::CCC_Other,
 Results.data(),Results.size());

Added: cfe/trunk/test/Index/complete-designated-initializer.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-designated-initializer.m?rev=290879&view=auto
==
--- cfe/trunk/test/Index/complete-designated-initializer.m (added)
+++ cfe/trunk/test/Index/complete-designated-initializer.m Tue Jan  3 05:56:40 
2017
@@ -0,0 +1,43 @@
+// Note: the run lines follow their respective tests, since line/column
+// matter in this test.
+
+// rdar://21014571
+
+#define NS_DESIGNATED_INITIALIZER __attribute__((objc_designated_initializer))
+
+@interface DesignatedInitializerCompletion
+
+- (instancetype)init ;
+- (instancetype)initWithFoo:(int)foo ;
+- (instancetype)initWithX:(int)x andY:(int)y ;
+
+@end
+
+@implementation DesignatedInitializerCompletion
+
+- (instancetype)init {
+}
+
+- (instancetype)initWithFoo:(int)foo {
+}
+
+- (instancetype)initWithX:(int)x andY:(int)y {
+}
+
+@end
+
+// RUN: c-index-test -code-completion-at=%s:10:22 %s | FileCheck %s
+// RUN: c-index-test -code-completion-at=%s:11:38 %s | FileCheck %s
+// RUN: c-index-test -code-completion-at=%s:11:29 %s | FileCheck 
-check-prefix=CHECK-NONE %s
+// RUN: c-index-test -code-completion-at=%s:11:34 %s | FileCheck 
-check-prefix=CHECK-NONE %s
+// RUN: c-index-test -code-completion-at=%s:12:34 %s | FileCheck %s
+// RUN: c-index-test -code-completion-at=%s:12:46 %s | FileCheck %s
+
+// RUN: c-index-test -code-completion-at=%s:18:22 %s | FileCheck %s
+// RUN: c-index-test -code-completion-at=%s:21:38 %s | FileCheck %s
+// RUN: c-index-test -code-completion-at=%s:24:34 %s | FileCheck %s
+// RUN: c-index-test -code-completion-at=%s:24:46 %s | FileCheck %s
+
+// CHECK: macro definition:{TypedText NS_DESIGNATED_INITIALIZER} (70)
+
+// CHECK-NONE-NOT: NS_DESIGNATED_INITIALIZER


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


[PATCH] D27039: [CodeCompletion] Autocomplete NS_DESIGNATED_INITIALIZER in initializers with arguments

2017-01-03 Thread Alex Lorenz via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL290879: [CodeCompletion] Autocomplete 
NS_DESIGNATED_INITIALIZER in initializers (authored by arphaman).

Changed prior to commit:
  https://reviews.llvm.org/D27039?vs=79049&id=82863#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D27039

Files:
  cfe/trunk/lib/Sema/SemaCodeComplete.cpp
  cfe/trunk/test/Index/complete-designated-initializer.m


Index: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
===
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp
@@ -7471,6 +7471,23 @@
   }
   
   Results.ExitScope();
+
+  if (!AtParameterName && !SelIdents.empty() &&
+  SelIdents.front()->getName().startswith("init")) {
+for (const auto &M : PP.macros()) {
+  if (M.first->getName() != "NS_DESIGNATED_INITIALIZER")
+continue;
+  Results.EnterNewScope();
+  CodeCompletionBuilder Builder(Results.getAllocator(),
+Results.getCodeCompletionTUInfo());
+  Builder.AddTypedTextChunk(
+  Builder.getAllocator().CopyString(M.first->getName()));
+  Results.AddResult(CodeCompletionResult(Builder.TakeString(), CCP_Macro,
+ CXCursor_MacroDefinition));
+  Results.ExitScope();
+}
+  }
+
   HandleCodeCompleteResults(this, CodeCompleter, 
 CodeCompletionContext::CCC_Other,
 Results.data(),Results.size());
Index: cfe/trunk/test/Index/complete-designated-initializer.m
===
--- cfe/trunk/test/Index/complete-designated-initializer.m
+++ cfe/trunk/test/Index/complete-designated-initializer.m
@@ -0,0 +1,43 @@
+// Note: the run lines follow their respective tests, since line/column
+// matter in this test.
+
+// rdar://21014571
+
+#define NS_DESIGNATED_INITIALIZER __attribute__((objc_designated_initializer))
+
+@interface DesignatedInitializerCompletion
+
+- (instancetype)init ;
+- (instancetype)initWithFoo:(int)foo ;
+- (instancetype)initWithX:(int)x andY:(int)y ;
+
+@end
+
+@implementation DesignatedInitializerCompletion
+
+- (instancetype)init {
+}
+
+- (instancetype)initWithFoo:(int)foo {
+}
+
+- (instancetype)initWithX:(int)x andY:(int)y {
+}
+
+@end
+
+// RUN: c-index-test -code-completion-at=%s:10:22 %s | FileCheck %s
+// RUN: c-index-test -code-completion-at=%s:11:38 %s | FileCheck %s
+// RUN: c-index-test -code-completion-at=%s:11:29 %s | FileCheck 
-check-prefix=CHECK-NONE %s
+// RUN: c-index-test -code-completion-at=%s:11:34 %s | FileCheck 
-check-prefix=CHECK-NONE %s
+// RUN: c-index-test -code-completion-at=%s:12:34 %s | FileCheck %s
+// RUN: c-index-test -code-completion-at=%s:12:46 %s | FileCheck %s
+
+// RUN: c-index-test -code-completion-at=%s:18:22 %s | FileCheck %s
+// RUN: c-index-test -code-completion-at=%s:21:38 %s | FileCheck %s
+// RUN: c-index-test -code-completion-at=%s:24:34 %s | FileCheck %s
+// RUN: c-index-test -code-completion-at=%s:24:46 %s | FileCheck %s
+
+// CHECK: macro definition:{TypedText NS_DESIGNATED_INITIALIZER} (70)
+
+// CHECK-NONE-NOT: NS_DESIGNATED_INITIALIZER


Index: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
===
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp
@@ -7471,6 +7471,23 @@
   }
   
   Results.ExitScope();
+
+  if (!AtParameterName && !SelIdents.empty() &&
+  SelIdents.front()->getName().startswith("init")) {
+for (const auto &M : PP.macros()) {
+  if (M.first->getName() != "NS_DESIGNATED_INITIALIZER")
+continue;
+  Results.EnterNewScope();
+  CodeCompletionBuilder Builder(Results.getAllocator(),
+Results.getCodeCompletionTUInfo());
+  Builder.AddTypedTextChunk(
+  Builder.getAllocator().CopyString(M.first->getName()));
+  Results.AddResult(CodeCompletionResult(Builder.TakeString(), CCP_Macro,
+ CXCursor_MacroDefinition));
+  Results.ExitScope();
+}
+  }
+
   HandleCodeCompleteResults(this, CodeCompleter, 
 CodeCompletionContext::CCC_Other,
 Results.data(),Results.size());
Index: cfe/trunk/test/Index/complete-designated-initializer.m
===
--- cfe/trunk/test/Index/complete-designated-initializer.m
+++ cfe/trunk/test/Index/complete-designated-initializer.m
@@ -0,0 +1,43 @@
+// Note: the run lines follow their respective tests, since line/column
+// matter in this test.
+
+// rdar://21014571
+
+#define NS_DESIGNATED_INITIALIZER __attribute__((objc_designated_initializer))
+
+@interface DesignatedInitializerCompletion
+
+- (instancetype)init ;
+- (instancetype)initWithFoo:(int)foo ;
+- (instancetype)initWithX:(int

[PATCH] D20689: [clang-tidy] Suspicious Call Argument checker

2017-01-03 Thread Varju Janos via Phabricator via cfe-commits
varjujan added a comment.

I ran the check on multiple projects and tried to categorize the warnings: real 
errors, false positives, naming errors and coincidences. The results are 
attached. I got no warnings on LLVM.

F2902037: postgres 

F2902036: linuxKernel 

F2902035: xerces 

F2902034: libreOffice 


https://reviews.llvm.org/D20689



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


r290880 - Handle FriendDecl in DeclContextPrinter

2017-01-03 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Tue Jan  3 06:07:20 2017
New Revision: 290880

URL: http://llvm.org/viewvc/llvm-project?rev=290880&view=rev
Log:
Handle FriendDecl in DeclContextPrinter

This commit fixes a crash that occurs when -print-decl-contexts AST consumer
tries to print an unhandled declaration.

rdar://19467234

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

Modified:
cfe/trunk/lib/Frontend/ASTConsumers.cpp
cfe/trunk/test/Coverage/cxx-language-features.inc

Modified: cfe/trunk/lib/Frontend/ASTConsumers.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTConsumers.cpp?rev=290880&r1=290879&r2=290880&view=diff
==
--- cfe/trunk/lib/Frontend/ASTConsumers.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTConsumers.cpp Tue Jan  3 06:07:20 2017
@@ -478,6 +478,13 @@ void DeclContextPrinter::PrintDeclContex
   Out << " " << '"' << I << "\"\n";
   break;
 }
+case Decl::Friend: {
+  Out << "";
+  if (const NamedDecl *ND = cast(I)->getFriendDecl())
+Out << ' ' << *ND;
+  Out << "\n";
+  break;
+}
 default:
   Out << "DeclKind: " << DK << '"' << I << "\"\n";
   llvm_unreachable("decl unhandled");

Modified: cfe/trunk/test/Coverage/cxx-language-features.inc
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Coverage/cxx-language-features.inc?rev=290880&r1=290879&r2=290880&view=diff
==
--- cfe/trunk/test/Coverage/cxx-language-features.inc (original)
+++ cfe/trunk/test/Coverage/cxx-language-features.inc Tue Jan  3 06:07:20 2017
@@ -25,3 +25,11 @@ enum E1 { EC1 };
 template  class C1 {};
 template  C1 f1() { return C1(); }
 void f2() { f1(); }
+
+// Friend declarations
+struct FriendlyStruct {
+  friend bool operator==(FriendlyStruct, FriendlyStruct) { return true; }
+  friend struct FriendedStruct;
+};
+
+struct FriendedStruct { };


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


[PATCH] D26964: Handle more declarations in DeclContextPrinter to fix -print-decl-contexts crashes

2017-01-03 Thread Alex Lorenz via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL290880: Handle FriendDecl in DeclContextPrinter (authored by 
arphaman).

Changed prior to commit:
  https://reviews.llvm.org/D26964?vs=78848&id=82864#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26964

Files:
  cfe/trunk/lib/Frontend/ASTConsumers.cpp
  cfe/trunk/test/Coverage/cxx-language-features.inc


Index: cfe/trunk/test/Coverage/cxx-language-features.inc
===
--- cfe/trunk/test/Coverage/cxx-language-features.inc
+++ cfe/trunk/test/Coverage/cxx-language-features.inc
@@ -25,3 +25,11 @@
 template  class C1 {};
 template  C1 f1() { return C1(); }
 void f2() { f1(); }
+
+// Friend declarations
+struct FriendlyStruct {
+  friend bool operator==(FriendlyStruct, FriendlyStruct) { return true; }
+  friend struct FriendedStruct;
+};
+
+struct FriendedStruct { };
Index: cfe/trunk/lib/Frontend/ASTConsumers.cpp
===
--- cfe/trunk/lib/Frontend/ASTConsumers.cpp
+++ cfe/trunk/lib/Frontend/ASTConsumers.cpp
@@ -478,6 +478,13 @@
   Out << " " << '"' << I << "\"\n";
   break;
 }
+case Decl::Friend: {
+  Out << "";
+  if (const NamedDecl *ND = cast(I)->getFriendDecl())
+Out << ' ' << *ND;
+  Out << "\n";
+  break;
+}
 default:
   Out << "DeclKind: " << DK << '"' << I << "\"\n";
   llvm_unreachable("decl unhandled");


Index: cfe/trunk/test/Coverage/cxx-language-features.inc
===
--- cfe/trunk/test/Coverage/cxx-language-features.inc
+++ cfe/trunk/test/Coverage/cxx-language-features.inc
@@ -25,3 +25,11 @@
 template  class C1 {};
 template  C1 f1() { return C1(); }
 void f2() { f1(); }
+
+// Friend declarations
+struct FriendlyStruct {
+  friend bool operator==(FriendlyStruct, FriendlyStruct) { return true; }
+  friend struct FriendedStruct;
+};
+
+struct FriendedStruct { };
Index: cfe/trunk/lib/Frontend/ASTConsumers.cpp
===
--- cfe/trunk/lib/Frontend/ASTConsumers.cpp
+++ cfe/trunk/lib/Frontend/ASTConsumers.cpp
@@ -478,6 +478,13 @@
   Out << " " << '"' << I << "\"\n";
   break;
 }
+case Decl::Friend: {
+  Out << "";
+  if (const NamedDecl *ND = cast(I)->getFriendDecl())
+Out << ' ' << *ND;
+  Out << "\n";
+  break;
+}
 default:
   Out << "DeclKind: " << DK << '"' << I << "\"\n";
   llvm_unreachable("decl unhandled");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r290881 - Handle UsingDecl and UsingShadowDecl in DeclContextPrinter

2017-01-03 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Tue Jan  3 06:08:40 2017
New Revision: 290881

URL: http://llvm.org/viewvc/llvm-project?rev=290881&view=rev
Log:
Handle UsingDecl and UsingShadowDecl in DeclContextPrinter

This commit fixes a crash that occurs when -print-decl-contexts AST consumer
tries to print an unhandled declaration.

rdar://19467234

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

Modified:
cfe/trunk/lib/Frontend/ASTConsumers.cpp
cfe/trunk/test/Coverage/cxx-language-features.inc

Modified: cfe/trunk/lib/Frontend/ASTConsumers.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTConsumers.cpp?rev=290881&r1=290880&r2=290881&view=diff
==
--- cfe/trunk/lib/Frontend/ASTConsumers.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTConsumers.cpp Tue Jan  3 06:08:40 2017
@@ -485,6 +485,14 @@ void DeclContextPrinter::PrintDeclContex
   Out << "\n";
   break;
 }
+case Decl::Using: {
+  Out << " " << *cast(I) << "\n";
+  break;
+}
+case Decl::UsingShadow: {
+  Out << " " << *cast(I) << "\n";
+  break;
+}
 default:
   Out << "DeclKind: " << DK << '"' << I << "\"\n";
   llvm_unreachable("decl unhandled");

Modified: cfe/trunk/test/Coverage/cxx-language-features.inc
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Coverage/cxx-language-features.inc?rev=290881&r1=290880&r2=290881&view=diff
==
--- cfe/trunk/test/Coverage/cxx-language-features.inc (original)
+++ cfe/trunk/test/Coverage/cxx-language-features.inc Tue Jan  3 06:08:40 2017
@@ -33,3 +33,11 @@ struct FriendlyStruct {
 };
 
 struct FriendedStruct { };
+
+// Using declaration
+namespace provider {
+  void foo();
+}
+namespace user {
+  using provider::foo;
+}


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


r290882 - Handle EmptyDecl in DeclContextPrinter

2017-01-03 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Tue Jan  3 06:09:39 2017
New Revision: 290882

URL: http://llvm.org/viewvc/llvm-project?rev=290882&view=rev
Log:
Handle EmptyDecl in DeclContextPrinter

This commit fixes a crash that occurs when -print-decl-contexts AST consumer
tries to print an unhandled declaration.

rdar://19467234

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

Modified:
cfe/trunk/lib/Frontend/ASTConsumers.cpp
cfe/trunk/test/Coverage/cxx-language-features.inc

Modified: cfe/trunk/lib/Frontend/ASTConsumers.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTConsumers.cpp?rev=290882&r1=290881&r2=290882&view=diff
==
--- cfe/trunk/lib/Frontend/ASTConsumers.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTConsumers.cpp Tue Jan  3 06:09:39 2017
@@ -493,6 +493,10 @@ void DeclContextPrinter::PrintDeclContex
   Out << " " << *cast(I) << "\n";
   break;
 }
+case Decl::Empty: {
+  Out << "\n";
+  break;
+}
 default:
   Out << "DeclKind: " << DK << '"' << I << "\"\n";
   llvm_unreachable("decl unhandled");

Modified: cfe/trunk/test/Coverage/cxx-language-features.inc
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Coverage/cxx-language-features.inc?rev=290882&r1=290881&r2=290882&view=diff
==
--- cfe/trunk/test/Coverage/cxx-language-features.inc (original)
+++ cfe/trunk/test/Coverage/cxx-language-features.inc Tue Jan  3 06:09:39 2017
@@ -41,3 +41,6 @@ namespace provider {
 namespace user {
   using provider::foo;
 }
+
+// Empty declaration
+;


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


[PATCH] D25406: Fix doubled whitespace in modernize-use-auto fixit

2017-01-03 Thread Malcolm Parsons via Phabricator via cfe-commits
malcolm.parsons abandoned this revision.
malcolm.parsons added a comment.

I'd prefer a -format option to clang-tidy.


https://reviews.llvm.org/D25406



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


r290884 - Handle ClassTemplateSpecializationDecl in DeclContextPrinter

2017-01-03 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Tue Jan  3 06:11:17 2017
New Revision: 290884

URL: http://llvm.org/viewvc/llvm-project?rev=290884&view=rev
Log:
Handle ClassTemplateSpecializationDecl in DeclContextPrinter

This commit fixes a crash that occurs when -print-decl-contexts AST consumer
tries to print an unhandled declaration.

rdar://19467234

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

Modified:
cfe/trunk/lib/Frontend/ASTConsumers.cpp
cfe/trunk/test/Coverage/cxx-language-features.inc

Modified: cfe/trunk/lib/Frontend/ASTConsumers.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTConsumers.cpp?rev=290884&r1=290883&r2=290884&view=diff
==
--- cfe/trunk/lib/Frontend/ASTConsumers.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTConsumers.cpp Tue Jan  3 06:11:17 2017
@@ -370,6 +370,26 @@ void DeclContextPrinter::PrintDeclContex
 break;
   }
 
+  case Decl::ClassTemplateSpecialization: {
+const auto *CTSD = cast(DC);
+if (CTSD->isCompleteDefinition())
+  Out << "[class template specialization] ";
+else
+  Out << " ";
+Out << *CTSD;
+break;
+  }
+
+  case Decl::ClassTemplatePartialSpecialization: {
+const auto *CTPSD = cast(DC);
+if (CTPSD->isCompleteDefinition())
+  Out << "[class template partial specialization] ";
+else
+  Out << " ";
+Out << *CTPSD;
+break;
+  }
+
   default:
 llvm_unreachable("a decl that inherits DeclContext isn't handled");
   }
@@ -400,7 +420,8 @@ void DeclContextPrinter::PrintDeclContex
 case Decl::CXXConstructor:
 case Decl::CXXDestructor:
 case Decl::CXXConversion:
-{
+case Decl::ClassTemplateSpecialization:
+case Decl::ClassTemplatePartialSpecialization: {
   DeclContext* DC = cast(I);
   PrintDeclContext(DC, Indentation+2);
   break;

Modified: cfe/trunk/test/Coverage/cxx-language-features.inc
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Coverage/cxx-language-features.inc?rev=290884&r1=290883&r2=290884&view=diff
==
--- cfe/trunk/test/Coverage/cxx-language-features.inc (original)
+++ cfe/trunk/test/Coverage/cxx-language-features.inc Tue Jan  3 06:11:17 2017
@@ -44,3 +44,14 @@ namespace user {
 
 // Empty declaration
 ;
+
+// Template specialization declarations
+template class ClassTemplateSpecialization;
+
+template<>
+class ClassTemplateSpecialization { };
+
+template struct ClassTemplatePartialSpecialization;
+
+template
+struct ClassTemplatePartialSpecialization { };


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


[clang-tools-extra] r290883 - [clang-tidy] Handle constructors in performance-unnecessary-value-param

2017-01-03 Thread Malcolm Parsons via cfe-commits
Author: malcolm.parsons
Date: Tue Jan  3 06:10:44 2017
New Revision: 290883

URL: http://llvm.org/viewvc/llvm-project?rev=290883&view=rev
Log:
[clang-tidy] Handle constructors in performance-unnecessary-value-param

Summary:
modernize-pass-by-value doesn't warn about value parameters that
cannot be moved, so performance-unnecessary-value-param should.

Reviewers: aaron.ballman, flx, alexfh

Subscribers: JDevlieghere, cfe-commits

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

Modified:

clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
clang-tools-extra/trunk/clang-tidy/utils/DeclRefExprUtils.cpp
clang-tools-extra/trunk/clang-tidy/utils/DeclRefExprUtils.h

clang-tools-extra/trunk/test/clang-tidy/performance-unnecessary-value-param-delayed.cpp

clang-tools-extra/trunk/test/clang-tidy/performance-unnecessary-value-param.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryValueParamCheck.cpp?rev=290883&r1=290882&r2=290883&view=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryValueParamCheck.cpp 
(original)
+++ 
clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryValueParamCheck.cpp 
Tue Jan  3 06:10:44 2017
@@ -47,14 +47,14 @@ bool isReferencedOutsideOfCallExpr(const
   return !Matches.empty();
 }
 
-bool hasLoopStmtAncestor(const DeclRefExpr &DeclRef, const Stmt &Stmt,
+bool hasLoopStmtAncestor(const DeclRefExpr &DeclRef, const Decl &Decl,
  ASTContext &Context) {
   auto Matches =
-  match(findAll(declRefExpr(
+  match(decl(forEachDescendant(declRefExpr(
 equalsNode(&DeclRef),
 unless(hasAncestor(stmt(anyOf(forStmt(), cxxForRangeStmt(),
-  whileStmt(), doStmt())),
-Stmt, Context);
+  whileStmt(), doStmt(,
+Decl, Context);
   return Matches.empty();
 }
 
@@ -72,7 +72,7 @@ void UnnecessaryValueParamCheck::registe
  unless(referenceType(),
   decl().bind("param"));
   Finder->addMatcher(
-  functionDecl(isDefinition(),
+  functionDecl(hasBody(stmt()), isDefinition(),
unless(cxxMethodDecl(anyOf(isOverride(), isFinal(,
unless(isInstantiated()),
has(typeLoc(forEach(ExpensiveValueParamDecl))),
@@ -89,22 +89,13 @@ void UnnecessaryValueParamCheck::check(c
   bool IsConstQualified =
   Param->getType().getCanonicalType().isConstQualified();
 
-  // Skip declarations delayed by late template parsing without a body.
-  if (!Function->getBody())
-return;
-
-  // Do not trigger on non-const value parameters when:
-  // 1. they are in a constructor definition since they can likely trigger
-  //modernize-pass-by-value which will suggest to move the argument.
-  if (!IsConstQualified && (llvm::isa(Function) ||
-!Function->doesThisDeclarationHaveABody()))
-return;
-
   auto AllDeclRefExprs = utils::decl_ref_expr::allDeclRefExprs(
-  *Param, *Function->getBody(), *Result.Context);
+  *Param, *Function, *Result.Context);
   auto ConstDeclRefExprs = utils::decl_ref_expr::constReferenceDeclRefExprs(
-  *Param, *Function->getBody(), *Result.Context);
-  // 2. they are not only used as const.
+  *Param, *Function, *Result.Context);
+
+  // Do not trigger on non-const value parameters when they are not only used 
as
+  // const.
   if (!isSubset(AllDeclRefExprs, ConstDeclRefExprs))
 return;
 
@@ -113,20 +104,18 @@ void UnnecessaryValueParamCheck::check(c
   // move assignment operator and is only referenced once when copy-assigned.
   // In this case wrap DeclRefExpr with std::move() to avoid the unnecessary
   // copy.
-  if (!IsConstQualified) {
+  if (!IsConstQualified && AllDeclRefExprs.size() == 1) {
 auto CanonicalType = Param->getType().getCanonicalType();
-if (AllDeclRefExprs.size() == 1 &&
-!hasLoopStmtAncestor(**AllDeclRefExprs.begin(), *Function->getBody(),
- *Result.Context) &&
+const auto &DeclRefExpr  = **AllDeclRefExprs.begin();
+
+if (!hasLoopStmtAncestor(DeclRefExpr, *Function, *Result.Context) &&
 ((utils::type_traits::hasNonTrivialMoveConstructor(CanonicalType) &&
   utils::decl_ref_expr::isCopyConstructorArgument(
-  **AllDeclRefExprs.begin(), *Function->getBody(),
-  *Result.Context)) ||
+  DeclRefExpr, *Function, *Result.Context)) ||
  (utils::type_traits::hasNonTrivialMoveAssignment(CanonicalType) &&
   utils::decl_ref_expr::isCopyAssignmentArgument(
-  **AllDeclRefExprs.begin(), *Function->getBody

[PATCH] D28022: [clang-tidy] Handle constructors in performance-unnecessary-value-param

2017-01-03 Thread Malcolm Parsons via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL290883: [clang-tidy] Handle constructors in 
performance-unnecessary-value-param (authored by malcolm.parsons).

Changed prior to commit:
  https://reviews.llvm.org/D28022?vs=82443&id=82865#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D28022

Files:
  clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
  clang-tools-extra/trunk/clang-tidy/utils/DeclRefExprUtils.cpp
  clang-tools-extra/trunk/clang-tidy/utils/DeclRefExprUtils.h
  
clang-tools-extra/trunk/test/clang-tidy/performance-unnecessary-value-param-delayed.cpp
  
clang-tools-extra/trunk/test/clang-tidy/performance-unnecessary-value-param.cpp

Index: clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
@@ -47,14 +47,14 @@
   return !Matches.empty();
 }
 
-bool hasLoopStmtAncestor(const DeclRefExpr &DeclRef, const Stmt &Stmt,
+bool hasLoopStmtAncestor(const DeclRefExpr &DeclRef, const Decl &Decl,
  ASTContext &Context) {
   auto Matches =
-  match(findAll(declRefExpr(
+  match(decl(forEachDescendant(declRefExpr(
 equalsNode(&DeclRef),
 unless(hasAncestor(stmt(anyOf(forStmt(), cxxForRangeStmt(),
-  whileStmt(), doStmt())),
-Stmt, Context);
+  whileStmt(), doStmt(,
+Decl, Context);
   return Matches.empty();
 }
 
@@ -72,7 +72,7 @@
  unless(referenceType(),
   decl().bind("param"));
   Finder->addMatcher(
-  functionDecl(isDefinition(),
+  functionDecl(hasBody(stmt()), isDefinition(),
unless(cxxMethodDecl(anyOf(isOverride(), isFinal(,
unless(isInstantiated()),
has(typeLoc(forEach(ExpensiveValueParamDecl))),
@@ -89,44 +89,33 @@
   bool IsConstQualified =
   Param->getType().getCanonicalType().isConstQualified();
 
-  // Skip declarations delayed by late template parsing without a body.
-  if (!Function->getBody())
-return;
-
-  // Do not trigger on non-const value parameters when:
-  // 1. they are in a constructor definition since they can likely trigger
-  //modernize-pass-by-value which will suggest to move the argument.
-  if (!IsConstQualified && (llvm::isa(Function) ||
-!Function->doesThisDeclarationHaveABody()))
-return;
-
   auto AllDeclRefExprs = utils::decl_ref_expr::allDeclRefExprs(
-  *Param, *Function->getBody(), *Result.Context);
+  *Param, *Function, *Result.Context);
   auto ConstDeclRefExprs = utils::decl_ref_expr::constReferenceDeclRefExprs(
-  *Param, *Function->getBody(), *Result.Context);
-  // 2. they are not only used as const.
+  *Param, *Function, *Result.Context);
+
+  // Do not trigger on non-const value parameters when they are not only used as
+  // const.
   if (!isSubset(AllDeclRefExprs, ConstDeclRefExprs))
 return;
 
   // If the parameter is non-const, check if it has a move constructor and is
   // only referenced once to copy-construct another object or whether it has a
   // move assignment operator and is only referenced once when copy-assigned.
   // In this case wrap DeclRefExpr with std::move() to avoid the unnecessary
   // copy.
-  if (!IsConstQualified) {
+  if (!IsConstQualified && AllDeclRefExprs.size() == 1) {
 auto CanonicalType = Param->getType().getCanonicalType();
-if (AllDeclRefExprs.size() == 1 &&
-!hasLoopStmtAncestor(**AllDeclRefExprs.begin(), *Function->getBody(),
- *Result.Context) &&
+const auto &DeclRefExpr  = **AllDeclRefExprs.begin();
+
+if (!hasLoopStmtAncestor(DeclRefExpr, *Function, *Result.Context) &&
 ((utils::type_traits::hasNonTrivialMoveConstructor(CanonicalType) &&
   utils::decl_ref_expr::isCopyConstructorArgument(
-  **AllDeclRefExprs.begin(), *Function->getBody(),
-  *Result.Context)) ||
+  DeclRefExpr, *Function, *Result.Context)) ||
  (utils::type_traits::hasNonTrivialMoveAssignment(CanonicalType) &&
   utils::decl_ref_expr::isCopyAssignmentArgument(
-  **AllDeclRefExprs.begin(), *Function->getBody(),
-  *Result.Context {
-  handleMoveFix(*Param, **AllDeclRefExprs.begin(), *Result.Context);
+  DeclRefExpr, *Function, *Result.Context {
+  handleMoveFix(*Param, DeclRefExpr, *Result.Context);
   return;
 }
   }
Index: clang-tools-extra/trunk/clang-tidy/utils/DeclRefExprUtils.cpp
===
--- 

r290885 - Handle AccessSpecDecl in DeclContextPrinter

2017-01-03 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Tue Jan  3 06:12:36 2017
New Revision: 290885

URL: http://llvm.org/viewvc/llvm-project?rev=290885&view=rev
Log:
Handle AccessSpecDecl in DeclContextPrinter

This commit fixes a crash that occurs when -print-decl-contexts AST consumer
tries to print an unhandled declaration.

rdar://19467234

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

Modified:
cfe/trunk/lib/Frontend/ASTConsumers.cpp
cfe/trunk/test/Coverage/cxx-language-features.inc

Modified: cfe/trunk/lib/Frontend/ASTConsumers.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTConsumers.cpp?rev=290885&r1=290884&r2=290885&view=diff
==
--- cfe/trunk/lib/Frontend/ASTConsumers.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTConsumers.cpp Tue Jan  3 06:12:36 2017
@@ -518,6 +518,10 @@ void DeclContextPrinter::PrintDeclContex
   Out << "\n";
   break;
 }
+case Decl::AccessSpec: {
+  Out << "\n";
+  break;
+}
 default:
   Out << "DeclKind: " << DK << '"' << I << "\"\n";
   llvm_unreachable("decl unhandled");

Modified: cfe/trunk/test/Coverage/cxx-language-features.inc
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Coverage/cxx-language-features.inc?rev=290885&r1=290884&r2=290885&view=diff
==
--- cfe/trunk/test/Coverage/cxx-language-features.inc (original)
+++ cfe/trunk/test/Coverage/cxx-language-features.inc Tue Jan  3 06:12:36 2017
@@ -55,3 +55,8 @@ template struct ClassT
 
 template
 struct ClassTemplatePartialSpecialization { };
+
+// Access specifier
+struct AccessSpec {
+private:
+};


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


r290886 - Handle VarTemplateDecl in DeclContextPrinter

2017-01-03 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Tue Jan  3 06:14:59 2017
New Revision: 290886

URL: http://llvm.org/viewvc/llvm-project?rev=290886&view=rev
Log:
Handle VarTemplateDecl in DeclContextPrinter

This commit fixes a crash that occurs when -print-decl-contexts AST consumer
tries to print an unhandled declaration.

rdar://19467234

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

Modified:
cfe/trunk/lib/Frontend/ASTConsumers.cpp
cfe/trunk/test/Coverage/ast-printing.cpp
cfe/trunk/test/Coverage/cxx-language-features.inc

Modified: cfe/trunk/lib/Frontend/ASTConsumers.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTConsumers.cpp?rev=290886&r1=290885&r2=290886&view=diff
==
--- cfe/trunk/lib/Frontend/ASTConsumers.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTConsumers.cpp Tue Jan  3 06:14:59 2017
@@ -522,6 +522,10 @@ void DeclContextPrinter::PrintDeclContex
   Out << "\n";
   break;
 }
+case Decl::VarTemplate: {
+  Out << " " << *cast(I) << "\n";
+  break;
+}
 default:
   Out << "DeclKind: " << DK << '"' << I << "\"\n";
   llvm_unreachable("decl unhandled");

Modified: cfe/trunk/test/Coverage/ast-printing.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Coverage/ast-printing.cpp?rev=290886&r1=290885&r2=290886&view=diff
==
--- cfe/trunk/test/Coverage/ast-printing.cpp (original)
+++ cfe/trunk/test/Coverage/ast-printing.cpp Tue Jan  3 06:14:59 2017
@@ -1,9 +1,9 @@
-// RUN: %clang_cc1 -fsyntax-only %s
-// RUN: %clang_cc1 -ast-print %s -o %t.1.cpp
-// RUN: %clang_cc1 -ast-print %t.1.cpp -o %t.2.cpp
+// RUN: %clang_cc1 -std=c++14 -fsyntax-only %s
+// RUN: %clang_cc1 -std=c++14 -ast-print %s -o %t.1.cpp
+// RUN: %clang_cc1 -std=c++14 -ast-print %t.1.cpp -o %t.2.cpp
 // RUN: diff %t.1.cpp %t.2.cpp
-// RUN: %clang_cc1 -ast-dump %s
-// RUN: %clang_cc1 -print-decl-contexts %s
-// RUN: %clang_cc1 -fdump-record-layouts %s
+// RUN: %clang_cc1 -std=c++14 -ast-dump %s
+// RUN: %clang_cc1 -std=c++14 -print-decl-contexts %s
+// RUN: %clang_cc1 -std=c++14 -fdump-record-layouts %s
 
 #include "cxx-language-features.inc"

Modified: cfe/trunk/test/Coverage/cxx-language-features.inc
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Coverage/cxx-language-features.inc?rev=290886&r1=290885&r2=290886&view=diff
==
--- cfe/trunk/test/Coverage/cxx-language-features.inc (original)
+++ cfe/trunk/test/Coverage/cxx-language-features.inc Tue Jan  3 06:14:59 2017
@@ -60,3 +60,6 @@ struct ClassTemplatePartialSpecializatio
 struct AccessSpec {
 private:
 };
+
+// Variable template
+template  T varTemplate = 0;


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


r290887 - Handle StaticAssertDecl in DeclContextPrinter

2017-01-03 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Tue Jan  3 06:16:02 2017
New Revision: 290887

URL: http://llvm.org/viewvc/llvm-project?rev=290887&view=rev
Log:
Handle StaticAssertDecl in DeclContextPrinter

This commit fixes a crash that occurs when -print-decl-contexts AST consumer
tries to print an unhandled declaration.

rdar://19467234

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

Modified:
cfe/trunk/lib/Frontend/ASTConsumers.cpp
cfe/trunk/test/Coverage/cxx-language-features.inc

Modified: cfe/trunk/lib/Frontend/ASTConsumers.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTConsumers.cpp?rev=290887&r1=290886&r2=290887&view=diff
==
--- cfe/trunk/lib/Frontend/ASTConsumers.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTConsumers.cpp Tue Jan  3 06:16:02 2017
@@ -526,6 +526,10 @@ void DeclContextPrinter::PrintDeclContex
   Out << " " << *cast(I) << "\n";
   break;
 }
+case Decl::StaticAssert: {
+  Out << "\n";
+  break;
+}
 default:
   Out << "DeclKind: " << DK << '"' << I << "\"\n";
   llvm_unreachable("decl unhandled");

Modified: cfe/trunk/test/Coverage/cxx-language-features.inc
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Coverage/cxx-language-features.inc?rev=290887&r1=290886&r2=290887&view=diff
==
--- cfe/trunk/test/Coverage/cxx-language-features.inc (original)
+++ cfe/trunk/test/Coverage/cxx-language-features.inc Tue Jan  3 06:16:02 2017
@@ -63,3 +63,5 @@ private:
 
 // Variable template
 template  T varTemplate = 0;
+
+static_assert(true, "");


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


[PATCH] D26034: [CodeCompletion] Block property setters: Use dynamic priority heuristic

2017-01-03 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a reviewer: manmanren.
arphaman updated this revision to Diff 82866.
arphaman added a comment.

I've rebased the patch


Repository:
  rL LLVM

https://reviews.llvm.org/D26034

Files:
  lib/Sema/SemaCodeComplete.cpp
  test/Index/complete-block-property-assignment.m


Index: test/Index/complete-block-property-assignment.m
===
--- test/Index/complete-block-property-assignment.m
+++ test/Index/complete-block-property-assignment.m
@@ -15,6 +15,7 @@
 @interface Test : Obj
 @property (readwrite, nonatomic, copy) FooBlock onEventHandler;
 @property (readonly, nonatomic, copy) void (^onReadonly)(int *someParameter);
+@property (readwrite, nonatomic, copy) int (^processEvent)(int eventCode);
 @property (readonly, nonatomic, strong) Obj *obj;
 @end
 
@@ -29,17 +30,19 @@
   SELFY.foo = 2
 }
 
-// RUN: c-index-test -code-completion-at=%s:26:8 %s | FileCheck 
-check-prefix=CHECK-CC1 %s
-// RUN: c-index-test -code-completion-at=%s:27:27 %s | FileCheck 
-check-prefix=CHECK-CC1 %s
-// RUN: c-index-test -code-completion-at=%s:28:22 %s | FileCheck 
-check-prefix=CHECK-CC1 %s
-// RUN: c-index-test -code-completion-at=%s:29:9 %s | FileCheck 
-check-prefix=CHECK-CC1 %s
+// RUN: c-index-test -code-completion-at=%s:27:8 %s | FileCheck 
-check-prefix=CHECK-CC1 %s
+// RUN: c-index-test -code-completion-at=%s:28:27 %s | FileCheck 
-check-prefix=CHECK-CC1 %s
+// RUN: c-index-test -code-completion-at=%s:29:22 %s | FileCheck 
-check-prefix=CHECK-CC1 %s
+// RUN: c-index-test -code-completion-at=%s:30:9 %s | FileCheck 
-check-prefix=CHECK-CC1 %s
 // CHECK-CC1: ObjCPropertyDecl:{ResultType int}{TypedText foo} (35)
 // CHECK-CC1-NEXT: ObjCPropertyDecl:{ResultType Obj *}{TypedText obj} (35)
 // CHECK-CC1-NEXT: ObjCPropertyDecl:{ResultType void}{TypedText 
onAction}{LeftParen (}{Placeholder Obj *object}{RightParen )} (35)
 // CHECK-CC1-NEXT: ObjCPropertyDecl:{ResultType void (^)(Obj *)}{TypedText 
onAction}{Equal  = }{Placeholder ^(Obj *object)} (38)
 // CHECK-CC1-NEXT: ObjCPropertyDecl:{ResultType void}{TypedText 
onEventHandler}{LeftParen (}{Placeholder Foo *someParameter}{RightParen )} (35)
 // CHECK-CC1-NEXT: ObjCPropertyDecl:{ResultType FooBlock}{TypedText 
onEventHandler}{Equal  = }{Placeholder ^(Foo *someParameter)} (38)
 // CHECK-CC1-NEXT: ObjCPropertyDecl:{ResultType void}{TypedText 
onReadonly}{LeftParen (}{Placeholder int *someParameter}{RightParen )} (35)
+// CHECK-CC1-NEXT: ObjCPropertyDecl:{ResultType int}{TypedText 
processEvent}{LeftParen (}{Placeholder int eventCode}{RightParen )} (35)
+// CHECK-CC1-NEXT: ObjCPropertyDecl:{ResultType int (^)(int)}{TypedText 
processEvent}{Equal  = }{Placeholder ^int(int eventCode)} (32)
 
 - (void) takeInt:(int)x { }
 
@@ -53,16 +56,17 @@
   return self.foo;
 }
 
-// RUN: c-index-test -code-completion-at=%s:47:9 %s | FileCheck 
-check-prefix=CHECK-NO %s
-// RUN: c-index-test -code-completion-at=%s:48:16 %s | FileCheck 
-check-prefix=CHECK-NO %s
-// RUN: c-index-test -code-completion-at=%s:49:23 %s | FileCheck 
-check-prefix=CHECK-NO %s
-// RUN: c-index-test -code-completion-at=%s:50:12 %s | FileCheck 
-check-prefix=CHECK-NO %s
-// RUN: c-index-test -code-completion-at=%s:51:15 %s | FileCheck 
-check-prefix=CHECK-NO %s
-// RUN: c-index-test -code-completion-at=%s:53:15 %s | FileCheck 
-check-prefix=CHECK-NO %s
+// RUN: c-index-test -code-completion-at=%s:50:9 %s | FileCheck 
-check-prefix=CHECK-NO %s
+// RUN: c-index-test -code-completion-at=%s:51:16 %s | FileCheck 
-check-prefix=CHECK-NO %s
+// RUN: c-index-test -code-completion-at=%s:52:23 %s | FileCheck 
-check-prefix=CHECK-NO %s
+// RUN: c-index-test -code-completion-at=%s:53:12 %s | FileCheck 
-check-prefix=CHECK-NO %s
+// RUN: c-index-test -code-completion-at=%s:54:15 %s | FileCheck 
-check-prefix=CHECK-NO %s
+// RUN: c-index-test -code-completion-at=%s:56:15 %s | FileCheck 
-check-prefix=CHECK-NO %s
 // CHECK-NO: ObjCPropertyDecl:{ResultType int}{TypedText foo} (35)
 // CHECK-NO-NEXT: ObjCPropertyDecl:{ResultType Obj *}{TypedText obj} (35)
 // CHECK-NO-NEXT: ObjCPropertyDecl:{ResultType void (^)(Obj *)}{TypedText 
onAction} (35)
 // CHECK-NO-NEXT: ObjCPropertyDecl:{ResultType FooBlock}{TypedText 
onEventHandler} (35)
 // CHECK-NO-NEXT: ObjCPropertyDecl:{ResultType void (^)(int *)}{TypedText 
onReadonly} (35)
+// CHECK-NO-NEXT: ObjCPropertyDecl:{ResultType int (^)(int)}{TypedText 
processEvent} (35)
 
 @end
Index: lib/Sema/SemaCodeComplete.cpp
===
--- lib/Sema/SemaCodeComplete.cpp
+++ lib/Sema/SemaCodeComplete.cpp
@@ -3720,9 +3720,17 @@
   Builder.AddPlaceholderChunk(
   Builder.getAllocator().CopyString(PlaceholderStr));
 
+  // When completing blocks properties that return void the default
+  // property completion result should show up before the setter,
+  // otherwise the setter completion should show up before the default
+  // property completion, as we normall

[PATCH] D28222: [libcxx] Re-implement LWG 2770 again: Fix tuple_size to work with structured bindings

2017-01-03 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF updated the summary for this revision.
EricWF updated this revision to Diff 82867.
EricWF added a comment.

- SFINAE the specializations on `sizeof(tuple_size)` instead of 
`decltype(tuple_size::value)`.


https://reviews.llvm.org/D28222

Files:
  include/__tuple
  test/libcxx/test/config.py
  test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size.pass.cpp
  
test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_incomplete.fail.cpp
  
test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_incomplete.pass.cpp
  
test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_structured_bindings.pass.cpp
  
test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_value_sfinae.pass.cpp

Index: test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_value_sfinae.pass.cpp
===
--- /dev/null
+++ test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_value_sfinae.pass.cpp
@@ -0,0 +1,39 @@
+//===--===//
+//
+// 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.
+//
+//===--===//
+
+// 
+
+// template  class tuple;
+
+// template 
+//   class tuple_size>
+// : public integral_constant { };
+
+// XFAIL: gcc-4.9
+// UNSUPPORTED: c++98, c++03
+
+#include 
+#include 
+
+template ::value)>
+constexpr bool has_value(int) { return true; }
+template  constexpr bool has_value(long) { return false; }
+template  constexpr bool has_value() { return has_value(0); }
+
+struct Dummy {};
+
+int main() {
+  // Test that the ::value member does not exist
+  static_assert(has_value const>(), "");
+  static_assert(has_value volatile>(), "");
+  static_assert(!has_value(), "");
+  static_assert(!has_value(), "");
+  static_assert(!has_value(), "");
+  static_assert(!has_value&>(), "");
+}
Index: test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_structured_bindings.pass.cpp
===
--- /dev/null
+++ test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_structured_bindings.pass.cpp
@@ -0,0 +1,138 @@
+//===--===//
+//
+// 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.
+//
+//===--===//
+
+// 
+
+// template  class tuple;
+
+// template 
+//   class tuple_size>
+// : public integral_constant { };
+
+// UNSUPPORTED: c++98, c++03, c++11, c++14
+// XFAIL: libcpp-no-structured-bindings
+
+#include 
+#include 
+#include 
+#include 
+
+struct S { int x; };
+
+void test_decomp_user_type() {
+  {
+S s{99};
+auto [m1] = s;
+auto& [r1] = s;
+assert(m1 == 99);
+assert(&r1 == &s.x);
+  }
+  {
+S const s{99};
+auto [m1] = s;
+auto& [r1] = s;
+assert(m1 == 99);
+assert(&r1 == &s.x);
+  }
+}
+
+void test_decomp_tuple() {
+  typedef std::tuple T;
+  {
+T s{99};
+auto [m1] = s;
+auto& [r1] = s;
+assert(m1 == 99);
+assert(&r1 == &std::get<0>(s));
+  }
+  {
+T const s{99};
+auto [m1] = s;
+auto& [r1] = s;
+assert(m1 == 99);
+assert(&r1 == &std::get<0>(s));
+  }
+}
+
+
+void test_decomp_pair() {
+  typedef std::pair T;
+  {
+T s{99, 42.1};
+auto [m1, m2] = s;
+auto& [r1, r2] = s;
+assert(m1 == 99);
+assert(&r1 == &std::get<0>(s));
+  }
+  {
+T const s{99, 42.1};
+auto [m1, m2] = s;
+auto& [r1, r2] = s;
+assert(m1 == 99);
+assert(&r1 == &std::get<0>(s));
+  }
+}
+
+void test_decomp_array() {
+  typedef std::array T;
+  {
+T s{{99, 42, -1}};
+auto [m1, m2, m3] = s;
+auto& [r1, r2, r3] = s;
+assert(m1 == 99);
+assert(&r1 == &std::get<0>(s));
+  }
+  {
+T const s{{99, 42, -1}};
+auto [m1, m2, m3] = s;
+auto& [r1, r2, r3] = s;
+assert(m1 == 99);
+assert(&r1 == &std::get<0>(s));
+  }
+}
+
+struct Test {
+  int x;
+};
+
+template 
+int get(Test const&) { static_assert(N == 0, ""); return -1; }
+
+template <>
+class std::tuple_element<0, Test> {
+public:
+  typedef int type;
+};
+
+void test_before_tuple_size_specialization() {
+  Test const t{99};
+  auto& [p] = t;
+  assert(p == 99);
+}
+
+template <>
+class std::tuple_size {
+public:
+  static const size_t value = 1;
+};
+
+void test_after_tuple_size_specialization() {
+  Test const t{99};
+  auto& [p] = t;
+  assert(p == -1);
+}
+
+int main() {
+  test_decomp_user_type();
+  test_decomp_tuple();
+  test_decomp_pair();
+  test_decomp_array();
+  test_before_tuple_size_specialization();
+  test_after_tuple_size_specialization();
+}
Ind

[libcxxabi] r290888 - [libcxxabi] Introduce an externally threaded libc++abi variant.

2017-01-03 Thread Asiri Rathnayake via cfe-commits
Author: asiri
Date: Tue Jan  3 06:58:34 2017
New Revision: 290888

URL: http://llvm.org/viewvc/llvm-project?rev=290888&view=rev
Log:
[libcxxabi] Introduce an externally threaded libc++abi variant.

r281179 Introduced an externally threaded variant of the libc++ library. This
patch adds support for a similar library variant for libc++abi.

Differential revision: https://reviews.llvm.org/D27575

Reviewers: EricWF

Removed:
libcxxabi/trunk/src/threading_support.h
Modified:
libcxxabi/trunk/CMakeLists.txt
libcxxabi/trunk/src/config.h
libcxxabi/trunk/src/cxa_exception.cpp
libcxxabi/trunk/src/cxa_exception_storage.cpp
libcxxabi/trunk/src/cxa_guard.cpp
libcxxabi/trunk/src/cxa_thread_atexit.cpp
libcxxabi/trunk/src/fallback_malloc.cpp
libcxxabi/trunk/test/CMakeLists.txt
libcxxabi/trunk/test/libcxxabi/test/config.py
libcxxabi/trunk/test/lit.site.cfg.in
libcxxabi/trunk/test/test_exception_storage.pass.cpp
libcxxabi/trunk/test/test_fallback_malloc.pass.cpp

Modified: libcxxabi/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/CMakeLists.txt?rev=290888&r1=290887&r2=290888&view=diff
==
--- libcxxabi/trunk/CMakeLists.txt (original)
+++ libcxxabi/trunk/CMakeLists.txt Tue Jan  3 06:58:34 2017
@@ -118,6 +118,9 @@ option(LIBCXXABI_USE_LLVM_UNWINDER "Buil
 option(LIBCXXABI_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF)
 option(LIBCXXABI_ENABLE_THREADS "Build with threads enabled" ON)
 option(LIBCXXABI_HAS_PTHREAD_API "Ignore auto-detection and force use of 
pthread API" OFF)
+option(LIBCXXABI_HAS_EXTERNAL_THREAD_API
+  "Build libc++abi with an externalized threading API.
+  This option may only be set to ON when LIBCXXABI_ENABLE_THREADS=ON." OFF)
 option(LIBCXXABI_BUILD_32_BITS "Build 32 bit libc++abi." ${LLVM_BUILD_32_BITS})
 set(LIBCXXABI_TARGET_TRIPLE "" CACHE STRING "Target triple for cross 
compiling.")
 set(LIBCXXABI_GCC_TOOLCHAIN "" CACHE PATH "GCC toolchain for cross compiling.")
@@ -347,20 +350,46 @@ if (NOT LIBCXXABI_ENABLE_SHARED)
   list(APPEND LIBCXXABI_COMPILE_FLAGS -D_LIBCPP_BUILD_STATIC)
 endif()
 
+# Threading
 if (NOT LIBCXXABI_ENABLE_THREADS)
   if (LIBCXXABI_HAS_PTHREAD_API)
 message(FATAL_ERROR "LIBCXXABI_HAS_PTHREAD_API can only"
 " be set to ON when LIBCXXABI_ENABLE_THREADS"
 " is also set to ON.")
   endif()
+  if (LIBCXXABI_HAS_EXTERNAL_THREAD_API)
+message(FATAL_ERROR "LIBCXXABI_HAS_EXTERNAL_THREAD_API can only"
+" be set to ON when LIBCXXABI_ENABLE_THREADS"
+" is also set to ON.")
+  endif()
   add_definitions(-D_LIBCXXABI_HAS_NO_THREADS)
 endif()
 
+if (LIBCXXABI_HAS_PTHREAD_API AND LIBCXXABI_HAS_EXTERNAL_THREAD_API)
+  message(FATAL_ERROR "The options LIBCXXABI_HAS_EXTERNAL_THREAD_API"
+  "and LIBCXXABI_HAS_PTHREAD_API cannot be both"
+  "set to ON at the same time.")
+endif()
+
+if (LIBCXXABI_HAS_EXTERNAL_THREAD_API AND LIBCXXABI_ENABLE_SHARED)
+  # Need to allow unresolved symbols if this is to work with shared library 
builds
+  if (APPLE)
+add_link_flags("-undefined dynamic_lookup")
+  else()
+# Relax this restriction from HandleLLVMOptions
+string(REPLACE "-Wl,-z,defs" "" CMAKE_SHARED_LINKER_FLAGS 
"${CMAKE_SHARED_LINKER_FLAGS}")
+  endif()
+endif()
+
 if (LIBCXXABI_HAS_PTHREAD_API)
   add_definitions(-D_LIBCPP_HAS_THREAD_API_PTHREAD)
   add_definitions(-D_LIBCXXABI_USE_THREAD_API_PTHREAD)
 endif()
 
+if (LIBCXXABI_HAS_EXTERNAL_THREAD_API)
+  add_definitions(-D_LIBCXXABI_HAS_THREAD_API_EXTERNAL)
+endif()
+
 if (MSVC)
   add_definitions(-D_CRT_SECURE_NO_WARNINGS)
 endif()

Modified: libcxxabi/trunk/src/config.h
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/config.h?rev=290888&r1=290887&r2=290888&view=diff
==
--- libcxxabi/trunk/src/config.h (original)
+++ libcxxabi/trunk/src/config.h Tue Jan  3 06:58:34 2017
@@ -42,6 +42,7 @@
 
 // Try and deduce a threading api if one has not been explicitly set.
 #if !defined(_LIBCXXABI_HAS_NO_THREADS) && \
+!defined(_LIBCXXABI_HAS_THREAD_API_EXTERNAL) && \
 !defined(_LIBCXXABI_USE_THREAD_API_PTHREAD)
   #if defined(_POSIX_THREADS) && _POSIX_THREADS >= 0
 #define _LIBCXXABI_USE_THREAD_API_PTHREAD

Modified: libcxxabi/trunk/src/cxa_exception.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_exception.cpp?rev=290888&r1=290887&r2=290888&view=diff
==
--- libcxxabi/trunk/src/cxa_exception.cpp (original)
+++ libcxxabi/trunk/src/cxa_exception.cpp Tue Jan  3 06:58:34 2017
@@ -12,7 +12,6 @@
 
//===--===//
 
 #include "config.h"
-#include "threading_support.h"
 #include "cxxabi.h"
 
 #incl

[PATCH] D27575: [libcxxabi] Introduce an externally threaded libc++abi variant (take-2)

2017-01-03 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL290888: [libcxxabi] Introduce an externally threaded 
libc++abi variant. (authored by asiri).

Changed prior to commit:
  https://reviews.llvm.org/D27575?vs=81062&id=82868#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D27575

Files:
  libcxxabi/trunk/CMakeLists.txt
  libcxxabi/trunk/src/config.h
  libcxxabi/trunk/src/cxa_exception.cpp
  libcxxabi/trunk/src/cxa_exception_storage.cpp
  libcxxabi/trunk/src/cxa_guard.cpp
  libcxxabi/trunk/src/cxa_thread_atexit.cpp
  libcxxabi/trunk/src/fallback_malloc.cpp
  libcxxabi/trunk/src/threading_support.h
  libcxxabi/trunk/test/CMakeLists.txt
  libcxxabi/trunk/test/libcxxabi/test/config.py
  libcxxabi/trunk/test/lit.site.cfg.in
  libcxxabi/trunk/test/test_exception_storage.pass.cpp
  libcxxabi/trunk/test/test_fallback_malloc.pass.cpp

Index: libcxxabi/trunk/CMakeLists.txt
===
--- libcxxabi/trunk/CMakeLists.txt
+++ libcxxabi/trunk/CMakeLists.txt
@@ -118,6 +118,9 @@
 option(LIBCXXABI_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF)
 option(LIBCXXABI_ENABLE_THREADS "Build with threads enabled" ON)
 option(LIBCXXABI_HAS_PTHREAD_API "Ignore auto-detection and force use of pthread API" OFF)
+option(LIBCXXABI_HAS_EXTERNAL_THREAD_API
+  "Build libc++abi with an externalized threading API.
+  This option may only be set to ON when LIBCXXABI_ENABLE_THREADS=ON." OFF)
 option(LIBCXXABI_BUILD_32_BITS "Build 32 bit libc++abi." ${LLVM_BUILD_32_BITS})
 set(LIBCXXABI_TARGET_TRIPLE "" CACHE STRING "Target triple for cross compiling.")
 set(LIBCXXABI_GCC_TOOLCHAIN "" CACHE PATH "GCC toolchain for cross compiling.")
@@ -347,20 +350,46 @@
   list(APPEND LIBCXXABI_COMPILE_FLAGS -D_LIBCPP_BUILD_STATIC)
 endif()
 
+# Threading
 if (NOT LIBCXXABI_ENABLE_THREADS)
   if (LIBCXXABI_HAS_PTHREAD_API)
 message(FATAL_ERROR "LIBCXXABI_HAS_PTHREAD_API can only"
 " be set to ON when LIBCXXABI_ENABLE_THREADS"
 " is also set to ON.")
   endif()
+  if (LIBCXXABI_HAS_EXTERNAL_THREAD_API)
+message(FATAL_ERROR "LIBCXXABI_HAS_EXTERNAL_THREAD_API can only"
+" be set to ON when LIBCXXABI_ENABLE_THREADS"
+" is also set to ON.")
+  endif()
   add_definitions(-D_LIBCXXABI_HAS_NO_THREADS)
 endif()
 
+if (LIBCXXABI_HAS_PTHREAD_API AND LIBCXXABI_HAS_EXTERNAL_THREAD_API)
+  message(FATAL_ERROR "The options LIBCXXABI_HAS_EXTERNAL_THREAD_API"
+  "and LIBCXXABI_HAS_PTHREAD_API cannot be both"
+  "set to ON at the same time.")
+endif()
+
+if (LIBCXXABI_HAS_EXTERNAL_THREAD_API AND LIBCXXABI_ENABLE_SHARED)
+  # Need to allow unresolved symbols if this is to work with shared library builds
+  if (APPLE)
+add_link_flags("-undefined dynamic_lookup")
+  else()
+# Relax this restriction from HandleLLVMOptions
+string(REPLACE "-Wl,-z,defs" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
+  endif()
+endif()
+
 if (LIBCXXABI_HAS_PTHREAD_API)
   add_definitions(-D_LIBCPP_HAS_THREAD_API_PTHREAD)
   add_definitions(-D_LIBCXXABI_USE_THREAD_API_PTHREAD)
 endif()
 
+if (LIBCXXABI_HAS_EXTERNAL_THREAD_API)
+  add_definitions(-D_LIBCXXABI_HAS_THREAD_API_EXTERNAL)
+endif()
+
 if (MSVC)
   add_definitions(-D_CRT_SECURE_NO_WARNINGS)
 endif()
Index: libcxxabi/trunk/src/cxa_exception_storage.cpp
===
--- libcxxabi/trunk/src/cxa_exception_storage.cpp
+++ libcxxabi/trunk/src/cxa_exception_storage.cpp
@@ -14,7 +14,7 @@
 #include "cxa_exception.hpp"
 
 #include "config.h"
-#include "threading_support.h"
+#include <__threading_support>
 
 #if defined(_LIBCXXABI_HAS_NO_THREADS)
 
@@ -54,17 +54,17 @@
 
 namespace __cxxabiv1 {
 namespace {
-__libcxxabi_tls_key key_;
-__libcxxabi_exec_once_flag flag_ = _LIBCXXABI_EXEC_ONCE_INITIALIZER;
+std::__libcpp_tls_key key_;
+std::__libcpp_exec_once_flag flag_ = _LIBCPP_EXEC_ONCE_INITIALIZER;
 
 void destruct_ (void *p) {
 __free_with_fallback ( p );
-if ( 0 != __libcxxabi_tls_set ( key_, NULL ) )	
+if ( 0 != std::__libcpp_tls_set ( key_, NULL ) )
 abort_message("cannot zero out thread value for __cxa_get_globals()");
 }
 
 void construct_ () {
-if ( 0 != __libcxxabi_tls_create ( &key_, destruct_ ) )
+if ( 0 != std::__libcpp_tls_create ( &key_, destruct_ ) )
 abort_message("cannot create thread specific key for __cxa_get_globals()");
 }
 }   
@@ -80,8 +80,8 @@
 (__calloc_with_fallback (1, sizeof (__cxa_eh_globals)));
 if ( NULL == retVal )
 abort_message("cannot allocate __cxa_eh_globals");
-if ( 0 != __libcxxabi_tls_set ( key_, retVal ) )
-   abort_message("__libcxxabi_tls_set failure in __cxa_get_globals()");
+if ( 0 != std::__li

[libcxx] r290889 - [libcxx] Add build/test support for the externally threaded libc++abi variant

2017-01-03 Thread Asiri Rathnayake via cfe-commits
Author: asiri
Date: Tue Jan  3 06:59:50 2017
New Revision: 290889

URL: http://llvm.org/viewvc/llvm-project?rev=290889&view=rev
Log:
[libcxx] Add build/test support for the externally threaded libc++abi variant

Differential revision: https://reviews.llvm.org/D27576

Reviewers: EricWF

Modified:
libcxx/trunk/CMakeLists.txt
libcxx/trunk/include/__threading_support
libcxx/trunk/test/CMakeLists.txt
libcxx/trunk/test/libcxx/test/config.py
libcxx/trunk/test/lit.site.cfg.in

Modified: libcxx/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/CMakeLists.txt?rev=290889&r1=290888&r2=290889&view=diff
==
--- libcxx/trunk/CMakeLists.txt (original)
+++ libcxx/trunk/CMakeLists.txt Tue Jan  3 06:59:50 2017
@@ -221,14 +221,21 @@ if(LIBCXX_ENABLE_THREADS AND NOT LIBCXX_
   " when LIBCXX_ENABLE_THREADS is also set to OFF.")
 endif()
 
-if(LIBCXX_HAS_PTHREAD_API AND NOT LIBCXX_ENABLE_THREADS)
-  message(FATAL_ERROR "LIBCXX_HAS_PTHREAD_API can only be set to ON"
-  " when LIBCXX_ENABLE_THREADS is also set to ON.")
+if(NOT LIBCXX_ENABLE_THREADS)
+  if(LIBCXX_HAS_PTHREAD_API)
+message(FATAL_ERROR "LIBCXX_HAS_PTHREAD_API can only be set to ON"
+" when LIBCXX_ENABLE_THREADS is also set to ON.")
+  endif()
+  if(LIBCXX_HAS_EXTERNAL_THREAD_API)
+message(FATAL_ERROR "LIBCXX_HAS_EXTERNAL_THREAD_API can only be set to ON"
+" when LIBCXX_ENABLE_THREADS is also set to ON.")
+  endif()
 endif()
 
-if(LIBCXX_HAS_EXTERNAL_THREAD_API AND NOT LIBCXX_ENABLE_THREADS)
-  message(FATAL_ERROR "LIBCXX_HAS_EXTERNAL_THREAD_API can only be set to ON"
-  " when LIBCXX_ENABLE_THREADS is also set to ON.")
+if(LIBCXX_HAS_PTHREAD_API AND LIBCXX_HAS_EXTERNAL_THREAD_API)
+  message(FATAL_ERROR "The options LIBCXX_HAS_EXTERNAL_THREAD_API"
+  "and LIBCXX_HAS_PTHREAD_API cannot be both"
+  "set to ON at the same time.")
 endif()
 
 # Ensure LLVM_USE_SANITIZER is not specified when LIBCXX_GENERATE_COVERAGE

Modified: libcxx/trunk/include/__threading_support
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__threading_support?rev=290889&r1=290888&r2=290889&view=diff
==
--- libcxx/trunk/include/__threading_support (original)
+++ libcxx/trunk/include/__threading_support Tue Jan  3 06:59:50 2017
@@ -67,7 +67,11 @@ typedef pthread_mutex_t __libcpp_mutex_t
 typedef pthread_cond_t __libcpp_condvar_t;
 #define _LIBCPP_CONDVAR_INITIALIZER PTHREAD_COND_INITIALIZER
 
-// THread ID
+// Execute once
+typedef pthread_once_t __libcpp_exec_once_flag;
+#define _LIBCPP_EXEC_ONCE_INITIALIZER PTHREAD_ONCE_INIT
+
+// Thread id
 typedef pthread_t __libcpp_thread_id;
 
 // Thread
@@ -110,7 +114,17 @@ int __libcpp_condvar_timedwait(__libcpp_
 _LIBCPP_THREAD_ABI_VISIBILITY
 int __libcpp_condvar_destroy(__libcpp_condvar_t* __cv);
 
-// Thread ID
+// Execute once
+_LIBCPP_THREAD_ABI_VISIBILITY
+int __libcpp_execute_once(__libcpp_exec_once_flag *flag,
+  void (*init_routine)(void));
+
+// Thread id
+#if defined(__APPLE__) && !defined(__arm__)
+_LIBCPP_THREAD_ABI_VISIBILITY
+mach_port_t __libcpp_thread_get_port();
+#endif
+
 _LIBCPP_THREAD_ABI_VISIBILITY
 bool __libcpp_thread_id_equal(__libcpp_thread_id t1, __libcpp_thread_id t2);
 
@@ -145,7 +159,7 @@ _LIBCPP_THREAD_ABI_VISIBILITY
 void *__libcpp_tls_get(__libcpp_tls_key __key);
 
 _LIBCPP_THREAD_ABI_VISIBILITY
-void __libcpp_tls_set(__libcpp_tls_key __key, void *__p);
+int __libcpp_tls_set(__libcpp_tls_key __key, void *__p);
 
 #if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) || \
 defined(_LIBCPP_BUILDING_THREAD_API_EXTERNAL_PTHREAD)
@@ -221,6 +235,19 @@ int __libcpp_condvar_destroy(__libcpp_co
   return pthread_cond_destroy(__cv);
 }
 
+// Execute once
+int __libcpp_execute_once(__libcpp_exec_once_flag *flag,
+  void (*init_routine)(void)) {
+  return pthread_once(flag, init_routine);
+}
+
+// Thread id
+#if defined(__APPLE__) && !defined(__arm__)
+mach_port_t __libcpp_thread_get_port() {
+return pthread_mach_thread_np(pthread_self());
+}
+#endif
+
 // Returns non-zero if the thread ids are equal, otherwise 0
 bool __libcpp_thread_id_equal(__libcpp_thread_id t1, __libcpp_thread_id t2)
 {
@@ -276,9 +303,9 @@ void *__libcpp_tls_get(__libcpp_tls_key
   return pthread_getspecific(__key);
 }
 
-void __libcpp_tls_set(__libcpp_tls_key __key, void *__p)
+int __libcpp_tls_set(__libcpp_tls_key __key, void *__p)
 {
-  pthread_setspecific(__key, __p);
+return pthread_setspecific(__key, __p);
 }
 
 #endif // _LIBCPP_HAS_THREAD_API_PTHREAD

Modified: libcxx/trunk/test/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/CMakeLists.txt?rev=290889&r1=290888&r2=290889&view=diff
===

[PATCH] D27576: [libcxx] libc++ changes necessary for the externally threaded libcxxabi variant

2017-01-03 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL290889: [libcxx] Add build/test support for the externally 
threaded libc++abi variant (authored by asiri).

Changed prior to commit:
  https://reviews.llvm.org/D27576?vs=81059&id=82869#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D27576

Files:
  libcxx/trunk/CMakeLists.txt
  libcxx/trunk/include/__threading_support
  libcxx/trunk/test/CMakeLists.txt
  libcxx/trunk/test/libcxx/test/config.py
  libcxx/trunk/test/lit.site.cfg.in

Index: libcxx/trunk/CMakeLists.txt
===
--- libcxx/trunk/CMakeLists.txt
+++ libcxx/trunk/CMakeLists.txt
@@ -221,14 +221,21 @@
   " when LIBCXX_ENABLE_THREADS is also set to OFF.")
 endif()
 
-if(LIBCXX_HAS_PTHREAD_API AND NOT LIBCXX_ENABLE_THREADS)
-  message(FATAL_ERROR "LIBCXX_HAS_PTHREAD_API can only be set to ON"
-  " when LIBCXX_ENABLE_THREADS is also set to ON.")
+if(NOT LIBCXX_ENABLE_THREADS)
+  if(LIBCXX_HAS_PTHREAD_API)
+message(FATAL_ERROR "LIBCXX_HAS_PTHREAD_API can only be set to ON"
+" when LIBCXX_ENABLE_THREADS is also set to ON.")
+  endif()
+  if(LIBCXX_HAS_EXTERNAL_THREAD_API)
+message(FATAL_ERROR "LIBCXX_HAS_EXTERNAL_THREAD_API can only be set to ON"
+" when LIBCXX_ENABLE_THREADS is also set to ON.")
+  endif()
 endif()
 
-if(LIBCXX_HAS_EXTERNAL_THREAD_API AND NOT LIBCXX_ENABLE_THREADS)
-  message(FATAL_ERROR "LIBCXX_HAS_EXTERNAL_THREAD_API can only be set to ON"
-  " when LIBCXX_ENABLE_THREADS is also set to ON.")
+if(LIBCXX_HAS_PTHREAD_API AND LIBCXX_HAS_EXTERNAL_THREAD_API)
+  message(FATAL_ERROR "The options LIBCXX_HAS_EXTERNAL_THREAD_API"
+  "and LIBCXX_HAS_PTHREAD_API cannot be both"
+  "set to ON at the same time.")
 endif()
 
 # Ensure LLVM_USE_SANITIZER is not specified when LIBCXX_GENERATE_COVERAGE
Index: libcxx/trunk/include/__threading_support
===
--- libcxx/trunk/include/__threading_support
+++ libcxx/trunk/include/__threading_support
@@ -67,7 +67,11 @@
 typedef pthread_cond_t __libcpp_condvar_t;
 #define _LIBCPP_CONDVAR_INITIALIZER PTHREAD_COND_INITIALIZER
 
-// THread ID
+// Execute once
+typedef pthread_once_t __libcpp_exec_once_flag;
+#define _LIBCPP_EXEC_ONCE_INITIALIZER PTHREAD_ONCE_INIT
+
+// Thread id
 typedef pthread_t __libcpp_thread_id;
 
 // Thread
@@ -110,7 +114,17 @@
 _LIBCPP_THREAD_ABI_VISIBILITY
 int __libcpp_condvar_destroy(__libcpp_condvar_t* __cv);
 
-// Thread ID
+// Execute once
+_LIBCPP_THREAD_ABI_VISIBILITY
+int __libcpp_execute_once(__libcpp_exec_once_flag *flag,
+  void (*init_routine)(void));
+
+// Thread id
+#if defined(__APPLE__) && !defined(__arm__)
+_LIBCPP_THREAD_ABI_VISIBILITY
+mach_port_t __libcpp_thread_get_port();
+#endif
+
 _LIBCPP_THREAD_ABI_VISIBILITY
 bool __libcpp_thread_id_equal(__libcpp_thread_id t1, __libcpp_thread_id t2);
 
@@ -145,7 +159,7 @@
 void *__libcpp_tls_get(__libcpp_tls_key __key);
 
 _LIBCPP_THREAD_ABI_VISIBILITY
-void __libcpp_tls_set(__libcpp_tls_key __key, void *__p);
+int __libcpp_tls_set(__libcpp_tls_key __key, void *__p);
 
 #if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) || \
 defined(_LIBCPP_BUILDING_THREAD_API_EXTERNAL_PTHREAD)
@@ -221,6 +235,19 @@
   return pthread_cond_destroy(__cv);
 }
 
+// Execute once
+int __libcpp_execute_once(__libcpp_exec_once_flag *flag,
+  void (*init_routine)(void)) {
+  return pthread_once(flag, init_routine);
+}
+
+// Thread id
+#if defined(__APPLE__) && !defined(__arm__)
+mach_port_t __libcpp_thread_get_port() {
+return pthread_mach_thread_np(pthread_self());
+}
+#endif
+
 // Returns non-zero if the thread ids are equal, otherwise 0
 bool __libcpp_thread_id_equal(__libcpp_thread_id t1, __libcpp_thread_id t2)
 {
@@ -276,9 +303,9 @@
   return pthread_getspecific(__key);
 }
 
-void __libcpp_tls_set(__libcpp_tls_key __key, void *__p)
+int __libcpp_tls_set(__libcpp_tls_key __key, void *__p)
 {
-  pthread_setspecific(__key, __p);
+return pthread_setspecific(__key, __p);
 }
 
 #endif // _LIBCPP_HAS_THREAD_API_PTHREAD
Index: libcxx/trunk/test/lit.site.cfg.in
===
--- libcxx/trunk/test/lit.site.cfg.in
+++ libcxx/trunk/test/lit.site.cfg.in
@@ -28,7 +28,7 @@
 config.use_libatomic= "@LIBCXX_HAVE_CXX_ATOMICS_WITH_LIB@"
 
 config.libcxxabi_shared = "@LIBCXXABI_ENABLE_SHARED@"
-config.libcxx_external_thread_api  = "@LIBCXX_HAS_EXTERNAL_THREAD_API@"
+config.cxx_ext_threads  = "@LIBCXX_HAS_EXTERNAL_THREAD_API@"
 
 # Let the main config do the real work.
 config.loaded_site_config = True
Index: libcxx/trunk/test/CMakeLists.txt
===
--- libcxx/trunk/test/CMakeLists.txt
+++ libcxx/trunk/test/CM

[PATCH] D28228: [clang-move] Support moving enum declarations.

2017-01-03 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 82872.
hokein marked an inline comment as done.
hokein added a comment.

Address review comment.


https://reviews.llvm.org/D28228

Files:
  clang-move/ClangMove.cpp
  clang-move/ClangMove.h
  test/clang-move/Inputs/enum.h
  test/clang-move/move-enum-decl.cpp
  unittests/clang-move/ClangMoveTests.cpp

Index: unittests/clang-move/ClangMoveTests.cpp
===
--- unittests/clang-move/ClangMoveTests.cpp
+++ unittests/clang-move/ClangMoveTests.cpp
@@ -370,7 +370,6 @@
   std::vector TestHeaders = {
   "typedef int Int;\nclass A {\npublic:\n  int f();\n};\n",
   "using Int = int;\nclass A {\npublic:\n  int f();\n};\n",
-  "enum Color { RED };\nclass A {\npublic:\n  int f();\n};\n",
   };
   move::MoveDefinitionSpec Spec;
   Spec.Names.push_back("A");
Index: test/clang-move/move-enum-decl.cpp
===
--- /dev/null
+++ test/clang-move/move-enum-decl.cpp
@@ -0,0 +1,44 @@
+// RUN: mkdir -p %T/move-enum
+// RUN: cp %S/Inputs/enum.h  %T/move-enum/enum.h
+// RUN: echo '#include "enum.h"' > %T/move-enum/enum.cpp
+// RUN: cd %T/move-enum
+//
+// -
+// Test moving enum declarations.
+// -
+// RUN: clang-move -names="a::E1" -new_cc=%T/move-enum/new_test.cpp -new_header=%T/move-enum/new_test.h -old_cc=%T/move-enum/enum.cpp -old_header=%T/move-enum/enum.h %T/move-enum/enum.cpp -- -std=c++11
+// RUN: FileCheck -input-file=%T/move-enum/new_test.h -check-prefix=CHECK-NEW-TEST-H-CASE1 %s
+// RUN: FileCheck -input-file=%T/move-enum/enum.h -check-prefix=CHECK-OLD-TEST-H-CASE1 %s
+//
+// CHECK-NEW-TEST-H-CASE1: namespace a {
+// CHECK-NEW-TEST-H-CASE1-NEXT: enum E1 { Green, Red };
+// CHECK-NEW-TEST-H-CASE1-NEXT: }
+
+// CHECK-OLD-TEST-H-CASE1-NOT: enum E1 { Green, Red };
+
+
+// -
+// Test moving scoped enum declarations.
+// -
+// RUN: cp %S/Inputs/enum.h  %T/move-enum/enum.h
+// RUN: echo '#include "enum.h"' > %T/move-enum/enum.cpp
+// RUN: clang-move -names="a::E2" -new_cc=%T/move-enum/new_test.cpp -new_header=%T/move-enum/new_test.h -old_cc=%T/move-enum/enum.cpp -old_header=%T/move-enum/enum.h %T/move-enum/enum.cpp -- -std=c++11
+// RUN: FileCheck -input-file=%T/move-enum/new_test.h -check-prefix=CHECK-NEW-TEST-H-CASE2 %s
+// RUN: FileCheck -input-file=%T/move-enum/enum.h -check-prefix=CHECK-OLD-TEST-H-CASE2 %s
+
+// CHECK-NEW-TEST-H-CASE2: namespace a {
+// CHECK-NEW-TEST-H-CASE2-NEXT: enum class E2 { Yellow };
+// CHECK-NEW-TEST-H-CASE2-NEXT: }
+
+// CHECK-OLD-TEST-H-CASE2-NOT: enum class E2 { Yellow };
+
+
+// -
+// Test not moving class-insided enum declarations.
+// -
+// RUN: cp %S/Inputs/enum.h  %T/move-enum/enum.h
+// RUN: echo '#include "enum.h"' > %T/move-enum/enum.cpp
+// RUN: clang-move -names="a::C::E3" -new_cc=%T/move-enum/new_test.cpp -new_header=%T/move-enum/new_test.h -old_cc=%T/move-enum/enum.cpp -old_header=%T/move-enum/enum.h %T/move-enum/enum.cpp -- -std=c++11
+// RUN: FileCheck -input-file=%T/move-enum/new_test.h -allow-empty -check-prefix=CHECK-EMPTY %s
+
+// CHECK-EMPTY: {{^}}{{$}}
Index: test/clang-move/Inputs/enum.h
===
--- /dev/null
+++ test/clang-move/Inputs/enum.h
@@ -0,0 +1,9 @@
+namespace a {
+enum E1 { Green, Red };
+
+enum class E2 { Yellow };
+
+class C {
+  enum E3 { Blue };
+};
+} // namespace a
Index: clang-move/ClangMove.h
===
--- clang-move/ClangMove.h
+++ clang-move/ClangMove.h
@@ -135,6 +135,10 @@
 
   std::vector &getMovedDecls() { return MovedDecls; }
 
+  /// Add declatrations which are being moved to new.h/cc and being deleted in
+  /// old.h/cc.
+  void addMovedAndDeletedDecl(const NamedDecl *Decl);
+
   /// Add declarations being removed from old.h/cc. For each declarations, the
   /// method also records the mapping relationship between the corresponding
   /// FilePath and its FileID.
@@ -153,6 +157,7 @@
   void moveDeclsToNewFiles();
   void moveAll(SourceManager& SM, StringRef OldFile, StringRef NewFile);
 
+
   // Stores all MatchCallbacks created by this tool.
   std::vector>
   MatchCallbacks;
Index: clang-move/ClangMove.cpp
===
--- clang-move/ClangMove.cpp
+++ clang-move/ClangMove.cpp
@@ -151,9 +151,22 @@
 const clang::NamedDecl *D = FD;
 if (const auto *FTD = FD->getDescribedFunctionTemplate())
   D = FTD;
-MoveTool->getMovedDecls().push_back(D);
-M

[PATCH] D28228: [clang-move] Support moving enum declarations.

2017-01-03 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

In https://reviews.llvm.org/D28228#633863, @ioeric wrote:

> Do we consider enum helpers?


This patch excludes enum helpers, only considers the enum declarations which 
are defined in old.h. 
Ideally, we should support enum helpers which are defined in old.cc, but that's 
another topic.




Comment at: clang-move/ClangMove.cpp:171
+assert(ED);
+MoveTool->getMovedDecls().push_back(ED);
+MoveTool->getUnremovedDeclsInOldHeader().erase(ED);

ioeric wrote:
> These 3 lines seen to be repeated. Maybe pull them out as a `MoveTool` method?
Done. I made a function for these repeated lines, but it seems hard to figure 
out a pretty name for it.


https://reviews.llvm.org/D28228



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


[PATCH] D28222: [libcxx] Re-implement LWG 2770 again: Fix tuple_size to work with structured bindings

2017-01-03 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF added inline comments.



Comment at: include/__tuple:34
+const _Tp,
+typename enable_if::value>::type,
+decltype(tuple_size<_Tp>::value)>>

Without this extra `enable_if`, GCC will diagnose each of these three 
specializations as ambiguous. 


https://reviews.llvm.org/D28222



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


[PATCH] D28228: [clang-move] Support moving enum declarations.

2017-01-03 Thread Eric Liu via Phabricator via cfe-commits
ioeric added a comment.

In https://reviews.llvm.org/D28228#633925, @hokein wrote:

> In https://reviews.llvm.org/D28228#633863, @ioeric wrote:
>
> > Do we consider enum helpers?
>
>
> This patch excludes enum helpers, only considers the enum declarations which 
> are defined in old.h. 
>  Ideally, we should support enum helpers which are defined in old.cc, but 
> that's another topic.


I mean, if a enum helper used in say only old cc, will it be moved? The 
question is related to https://reviews.llvm.org/D27673. You don't need to 
support enum helper now, but it would be nice to drop a comment somewhere.




Comment at: clang-move/ClangMove.h:140
+  /// old.h/cc.
+  void addMovedAndDeletedDecl(const NamedDecl *Decl);
+

Maybe just `addMovedDecl`? `move` indicates move and delete IMO. But you might 
need to explain what's really going on in the comment.


https://reviews.llvm.org/D28228



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


[PATCH] D26137: [clang-tidy] Add check name to YAML export

2017-01-03 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

Err, looks like I forgot to post comments I entered a few days ago.

Just a few nits.




Comment at: include/clang/Tooling/Core/Diagnostic.h:62
+  Diagnostic(llvm::StringRef DiagnosticName, DiagnosticMessage &Message,
+ llvm::StringMap &Fix,
+ SmallVector &Notes, Level DiagLevel,

nit: No need for `tooling::`.



Comment at: lib/Tooling/Core/Diagnostic.cpp:39
+   DiagnosticMessage &Message,
+   llvm::StringMap &Fix,
+   SmallVector &Notes,

nit: No need for `tooling::`.



Comment at: tools/extra/clang-tidy/ClangTidy.cpp:106
   void reportDiagnostic(const ClangTidyError &Error) {
-const ClangTidyMessage &Message = Error.Message;
+const ClangTidyMessage Message = Error.Message;
 SourceLocation Loc = getLocation(Message.FilePath, Message.FileOffset);

Why this change?



Comment at: tools/extra/clang-tidy/ClangTidy.h:245
 /// output stream.
-void exportReplacements(const std::vector &Errors,
+void exportReplacements(const StringRef MainFilePath,
+const std::vector &Errors,

Top-level const on function parameters in function declarations is useless 
(it's not a part of the function prototype and it tells nothing to the function 
users). It might make sense on a function definition, if used consistently 
(same way as on local variables). However, is not very common in LLVM/Clang.



Comment at: tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.h:45
 /// FIXME: Make Diagnostics flexible enough to support this directly.
-struct ClangTidyError {
-  enum Level {
-Warning = DiagnosticsEngine::Warning,
-Error = DiagnosticsEngine::Error
-  };
-
-  ClangTidyError(StringRef CheckName, Level DiagLevel, bool IsWarningAsError,
- StringRef BuildDirectory);
-
-  std::string CheckName;
-  ClangTidyMessage Message;
-  // Fixes grouped by file path.
-  llvm::StringMap Fix;
-  SmallVector Notes;
-
-  // A build directory of the diagnostic source file.
-  //
-  // It's an absolute path which is `directory` field of the source file in
-  // compilation database. If users don't specify the compilation database
-  // directory, it is the current directory where clang-tidy runs.
-  //
-  // Note: it is empty in unittest.
-  std::string BuildDirectory;
+struct ClangTidyError : clang::tooling::Diagnostic {
+  ClangTidyError(StringRef CheckName, Level DiagLevel, StringRef 
BuildDirectory,

nit: No need for `clang::`.



Comment at: tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.h:36
 
-/// \brief A message from a clang-tidy check.
-///
-/// Note that this is independent of a \c SourceManager.
-struct ClangTidyMessage {
-  ClangTidyMessage(StringRef Message = "");
-  ClangTidyMessage(StringRef Message, const SourceManager &Sources,
-   SourceLocation Loc);
-  std::string Message;
-  std::string FilePath;
-  unsigned FileOffset;
-};
+typedef clang::tooling::DiagnosticMessage ClangTidyMessage;
 

Do we actually need this typedef? How much is the old type name used?


Repository:
  rL LLVM

https://reviews.llvm.org/D26137



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


[PATCH] D28228: [clang-move] Support moving enum declarations.

2017-01-03 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 82874.
hokein marked an inline comment as done.
hokein added a comment.

Refine function name and add a comment for enum helpers.


https://reviews.llvm.org/D28228

Files:
  clang-move/ClangMove.cpp
  clang-move/ClangMove.h
  test/clang-move/Inputs/enum.h
  test/clang-move/move-enum-decl.cpp
  unittests/clang-move/ClangMoveTests.cpp

Index: unittests/clang-move/ClangMoveTests.cpp
===
--- unittests/clang-move/ClangMoveTests.cpp
+++ unittests/clang-move/ClangMoveTests.cpp
@@ -370,7 +370,6 @@
   std::vector TestHeaders = {
   "typedef int Int;\nclass A {\npublic:\n  int f();\n};\n",
   "using Int = int;\nclass A {\npublic:\n  int f();\n};\n",
-  "enum Color { RED };\nclass A {\npublic:\n  int f();\n};\n",
   };
   move::MoveDefinitionSpec Spec;
   Spec.Names.push_back("A");
Index: test/clang-move/move-enum-decl.cpp
===
--- /dev/null
+++ test/clang-move/move-enum-decl.cpp
@@ -0,0 +1,44 @@
+// RUN: mkdir -p %T/move-enum
+// RUN: cp %S/Inputs/enum.h  %T/move-enum/enum.h
+// RUN: echo '#include "enum.h"' > %T/move-enum/enum.cpp
+// RUN: cd %T/move-enum
+//
+// -
+// Test moving enum declarations.
+// -
+// RUN: clang-move -names="a::E1" -new_cc=%T/move-enum/new_test.cpp -new_header=%T/move-enum/new_test.h -old_cc=%T/move-enum/enum.cpp -old_header=%T/move-enum/enum.h %T/move-enum/enum.cpp -- -std=c++11
+// RUN: FileCheck -input-file=%T/move-enum/new_test.h -check-prefix=CHECK-NEW-TEST-H-CASE1 %s
+// RUN: FileCheck -input-file=%T/move-enum/enum.h -check-prefix=CHECK-OLD-TEST-H-CASE1 %s
+//
+// CHECK-NEW-TEST-H-CASE1: namespace a {
+// CHECK-NEW-TEST-H-CASE1-NEXT: enum E1 { Green, Red };
+// CHECK-NEW-TEST-H-CASE1-NEXT: }
+
+// CHECK-OLD-TEST-H-CASE1-NOT: enum E1 { Green, Red };
+
+
+// -
+// Test moving scoped enum declarations.
+// -
+// RUN: cp %S/Inputs/enum.h  %T/move-enum/enum.h
+// RUN: echo '#include "enum.h"' > %T/move-enum/enum.cpp
+// RUN: clang-move -names="a::E2" -new_cc=%T/move-enum/new_test.cpp -new_header=%T/move-enum/new_test.h -old_cc=%T/move-enum/enum.cpp -old_header=%T/move-enum/enum.h %T/move-enum/enum.cpp -- -std=c++11
+// RUN: FileCheck -input-file=%T/move-enum/new_test.h -check-prefix=CHECK-NEW-TEST-H-CASE2 %s
+// RUN: FileCheck -input-file=%T/move-enum/enum.h -check-prefix=CHECK-OLD-TEST-H-CASE2 %s
+
+// CHECK-NEW-TEST-H-CASE2: namespace a {
+// CHECK-NEW-TEST-H-CASE2-NEXT: enum class E2 { Yellow };
+// CHECK-NEW-TEST-H-CASE2-NEXT: }
+
+// CHECK-OLD-TEST-H-CASE2-NOT: enum class E2 { Yellow };
+
+
+// -
+// Test not moving class-insided enum declarations.
+// -
+// RUN: cp %S/Inputs/enum.h  %T/move-enum/enum.h
+// RUN: echo '#include "enum.h"' > %T/move-enum/enum.cpp
+// RUN: clang-move -names="a::C::E3" -new_cc=%T/move-enum/new_test.cpp -new_header=%T/move-enum/new_test.h -old_cc=%T/move-enum/enum.cpp -old_header=%T/move-enum/enum.h %T/move-enum/enum.cpp -- -std=c++11
+// RUN: FileCheck -input-file=%T/move-enum/new_test.h -allow-empty -check-prefix=CHECK-EMPTY %s
+
+// CHECK-EMPTY: {{^}}{{$}}
Index: test/clang-move/Inputs/enum.h
===
--- /dev/null
+++ test/clang-move/Inputs/enum.h
@@ -0,0 +1,9 @@
+namespace a {
+enum E1 { Green, Red };
+
+enum class E2 { Yellow };
+
+class C {
+  enum E3 { Blue };
+};
+} // namespace a
Index: clang-move/ClangMove.h
===
--- clang-move/ClangMove.h
+++ clang-move/ClangMove.h
@@ -153,6 +153,7 @@
   void moveDeclsToNewFiles();
   void moveAll(SourceManager& SM, StringRef OldFile, StringRef NewFile);
 
+
   // Stores all MatchCallbacks created by this tool.
   std::vector>
   MatchCallbacks;
Index: clang-move/ClangMove.cpp
===
--- clang-move/ClangMove.cpp
+++ clang-move/ClangMove.cpp
@@ -140,6 +140,14 @@
   ClangMoveTool *const MoveTool;
 };
 
+/// Add a declatration being moved to new.h/cc. Note that the declaration will
+/// also be deleted in old.h/cc.
+void MoveDeclFromOldFileToNewFile(ClangMoveTool *MoveTool, const NamedDecl *D) {
+  MoveTool->getMovedDecls().push_back(D);
+  MoveTool->addRemovedDecl(D);
+  MoveTool->getUnremovedDeclsInOldHeader().erase(D);
+}
+
 class FunctionDeclarationMatch : public MatchFinder::MatchCallback {
 public:
   explicit FunctionDeclarationMatch(ClangMoveTool *MoveTool)
@@ -151,9 +159,22 @@
 const clang::NamedDec

[PATCH] D28228: [clang-move] Support moving enum declarations.

2017-01-03 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

In https://reviews.llvm.org/D28228#633930, @ioeric wrote:

> I mean, if a enum helper used in say only old cc, will it be moved? The 
> question is related to https://reviews.llvm.org/D27673. You don't need to 
> support enum helper now, but it would be nice to drop a comment somewhere.


Done. Add a comment about this. Enum helpers will not moved whether they are 
used or not.




Comment at: clang-move/ClangMove.h:140
+  /// old.h/cc.
+  void addMovedAndDeletedDecl(const NamedDecl *Decl);
+

ioeric wrote:
> Maybe just `addMovedDecl`? `move` indicates move and delete IMO. But you 
> might need to explain what's really going on in the comment.
Instead of making an interface in the class, I put this function as a helper 
function in .cc, and named it as `MoveDeclFromOldFileToNewFile`. Hope this will 
make it clearer.


https://reviews.llvm.org/D28228



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


[PATCH] D28228: [clang-move] Support moving enum declarations.

2017-01-03 Thread Eric Liu via Phabricator via cfe-commits
ioeric accepted this revision.
ioeric added a comment.
This revision is now accepted and ready to land.

Lg




Comment at: clang-move/ClangMove.cpp:456
 
+void ClangMoveTool::addMovedAndDeletedDecl(const NamedDecl *D) {
+  MovedDecls.push_back(D);

Remove this?


https://reviews.llvm.org/D28228



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


[PATCH] D28231: -Wunreachable-code: Avoid multiple diagnostics that are triggered by the same source range and fix the unary operator fixit source range

2017-01-03 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman created this revision.
arphaman added reviewers: rsmith, bruno, ahatanak.
arphaman added a subscriber: cfe-commits.
arphaman set the repository for this revision to rL LLVM.

This patch fixes an issue with -Wunreachable-code diagnostic that happens with 
the following code sample:

  struct s {
void *p;
  };
  
  void fn(struct s *s) {
if (1 || !s->p)
  return;
fn(s);
  }

Currently, clang will emit two warnings (at `fn(s)` and at `!s->p`. As well as 
that, the fixits for the first warning (for `fn(s)`) has an incorrect source 
range: it suggests to wrap `!s->p` in parentheses when it should suggest to 
warp `1` instead.

The attached patch ensures that the fixits for the `fn(s)` warning suggest to 
wrap the correct expression (`1`). It also avoids the second warning that was 
previously shown for `!s->p` because that warning is caused by the same 
expression (`1`).

Thanks for taking a look.


Repository:
  rL LLVM

https://reviews.llvm.org/D28231

Files:
  lib/Analysis/ReachableCode.cpp
  lib/Sema/AnalysisBasedWarnings.cpp
  test/Sema/warn-unreachable.c


Index: test/Sema/warn-unreachable.c
===
--- test/Sema/warn-unreachable.c
+++ test/Sema/warn-unreachable.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -fsyntax-only -verify -fblocks 
-Wunreachable-code-aggressive -Wno-unused-value -Wno-covered-switch-default -I 
%S/Inputs
+// RUN: %clang_cc1 -fsyntax-only -fblocks -Wunreachable-code-aggressive 
-Wno-unused-value -Wno-covered-switch-default -fdiagnostics-parseable-fixits -I 
%S/Inputs %s 2>&1 | FileCheck %s
 
 #include "warn-unreachable.h"
 
@@ -396,3 +397,30 @@
   else
 calledFun();
 }
+
+// rdar://24570531
+
+struct StructWithPointer {
+  void *p;
+};
+
+void emitJustOneWarningForOr(struct StructWithPointer *s) {
+  if (1 || !s->p) // expected-note {{silence by adding parentheses to mark 
code as explicitly dead}}
+return; // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:7-[[@LINE-1]]:7}:"/* 
DISABLES CODE */ ("
+// CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:8-[[@LINE-2]]:8}:")"
+  emitJustOneWarningForOr(s); // expected-warning {{code will never be 
executed}}
+}
+
+void emitJustOneWarningForOrSilenced(struct StructWithPointer *s) {
+  if ((1) || !s->p)
+return;
+
+  emitJustOneWarningForOrSilenced(s); // no warning
+}
+
+void emitJustOneWarningForOr2(struct StructWithPointer *s) {
+  if (1 || !s->p) // expected-warning {{code will never be executed}}
+return; // expected-note@-1 {{silence by adding parentheses to mark code 
as explicitly dead}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:7-[[@LINE-2]]:7}:"/* DISABLES CODE */ 
("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:8-[[@LINE-3]]:8}:")"
+}
Index: lib/Sema/AnalysisBasedWarnings.cpp
===
--- lib/Sema/AnalysisBasedWarnings.cpp
+++ lib/Sema/AnalysisBasedWarnings.cpp
@@ -56,14 +56,24 @@
 namespace {
   class UnreachableCodeHandler : public reachable_code::Callback {
 Sema &S;
+SourceRange PreviousSilenceableCondVal;
+
   public:
 UnreachableCodeHandler(Sema &s) : S(s) {}
 
 void HandleUnreachable(reachable_code::UnreachableKind UK,
SourceLocation L,
SourceRange SilenceableCondVal,
SourceRange R1,
SourceRange R2) override {
+  // Avoid reporting multiple unreachable code diagnostics that are
+  // triggered by the same conditional value.
+  if (PreviousSilenceableCondVal.isValid() &&
+  SilenceableCondVal.isValid() &&
+  PreviousSilenceableCondVal == SilenceableCondVal)
+return;
+  PreviousSilenceableCondVal = SilenceableCondVal;
+
   unsigned diag = diag::warn_unreachable;
   switch (UK) {
 case reachable_code::UK_Break:
Index: lib/Analysis/ReachableCode.cpp
===
--- lib/Analysis/ReachableCode.cpp
+++ lib/Analysis/ReachableCode.cpp
@@ -218,8 +218,8 @@
 }
 case Stmt::UnaryOperatorClass: {
   const UnaryOperator *UO = cast(S);
-  if (SilenceableCondVal) 
-*SilenceableCondVal = UO->getSourceRange();  
+  if (SilenceableCondVal && !SilenceableCondVal->getBegin().isValid())
+*SilenceableCondVal = UO->getSourceRange();
   return UO->getOpcode() == UO_LNot &&
  isConfigurationValue(UO->getSubExpr(), PP, SilenceableCondVal,
   IncludeIntegers, WrappedInParens);


Index: test/Sema/warn-unreachable.c
===
--- test/Sema/warn-unreachable.c
+++ test/Sema/warn-unreachable.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -fsyntax-only -verify -fblocks -Wunreachable-code-aggressive -Wno-unused-value -Wno-covered-switch-default -I %S/Inputs
+// RUN: %clang_cc1 -fsyntax-only -fblocks -Wunreachable-code-aggressive -Wno-unused-value -Wn

[PATCH] D28228: [clang-move] Support moving enum declarations.

2017-01-03 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 82875.
hokein added a comment.

Remove forgot-deleted code.


https://reviews.llvm.org/D28228

Files:
  clang-move/ClangMove.cpp
  clang-move/ClangMove.h
  test/clang-move/Inputs/enum.h
  test/clang-move/move-enum-decl.cpp
  unittests/clang-move/ClangMoveTests.cpp

Index: unittests/clang-move/ClangMoveTests.cpp
===
--- unittests/clang-move/ClangMoveTests.cpp
+++ unittests/clang-move/ClangMoveTests.cpp
@@ -370,7 +370,6 @@
   std::vector TestHeaders = {
   "typedef int Int;\nclass A {\npublic:\n  int f();\n};\n",
   "using Int = int;\nclass A {\npublic:\n  int f();\n};\n",
-  "enum Color { RED };\nclass A {\npublic:\n  int f();\n};\n",
   };
   move::MoveDefinitionSpec Spec;
   Spec.Names.push_back("A");
Index: test/clang-move/move-enum-decl.cpp
===
--- /dev/null
+++ test/clang-move/move-enum-decl.cpp
@@ -0,0 +1,44 @@
+// RUN: mkdir -p %T/move-enum
+// RUN: cp %S/Inputs/enum.h  %T/move-enum/enum.h
+// RUN: echo '#include "enum.h"' > %T/move-enum/enum.cpp
+// RUN: cd %T/move-enum
+//
+// -
+// Test moving enum declarations.
+// -
+// RUN: clang-move -names="a::E1" -new_cc=%T/move-enum/new_test.cpp -new_header=%T/move-enum/new_test.h -old_cc=%T/move-enum/enum.cpp -old_header=%T/move-enum/enum.h %T/move-enum/enum.cpp -- -std=c++11
+// RUN: FileCheck -input-file=%T/move-enum/new_test.h -check-prefix=CHECK-NEW-TEST-H-CASE1 %s
+// RUN: FileCheck -input-file=%T/move-enum/enum.h -check-prefix=CHECK-OLD-TEST-H-CASE1 %s
+//
+// CHECK-NEW-TEST-H-CASE1: namespace a {
+// CHECK-NEW-TEST-H-CASE1-NEXT: enum E1 { Green, Red };
+// CHECK-NEW-TEST-H-CASE1-NEXT: }
+
+// CHECK-OLD-TEST-H-CASE1-NOT: enum E1 { Green, Red };
+
+
+// -
+// Test moving scoped enum declarations.
+// -
+// RUN: cp %S/Inputs/enum.h  %T/move-enum/enum.h
+// RUN: echo '#include "enum.h"' > %T/move-enum/enum.cpp
+// RUN: clang-move -names="a::E2" -new_cc=%T/move-enum/new_test.cpp -new_header=%T/move-enum/new_test.h -old_cc=%T/move-enum/enum.cpp -old_header=%T/move-enum/enum.h %T/move-enum/enum.cpp -- -std=c++11
+// RUN: FileCheck -input-file=%T/move-enum/new_test.h -check-prefix=CHECK-NEW-TEST-H-CASE2 %s
+// RUN: FileCheck -input-file=%T/move-enum/enum.h -check-prefix=CHECK-OLD-TEST-H-CASE2 %s
+
+// CHECK-NEW-TEST-H-CASE2: namespace a {
+// CHECK-NEW-TEST-H-CASE2-NEXT: enum class E2 { Yellow };
+// CHECK-NEW-TEST-H-CASE2-NEXT: }
+
+// CHECK-OLD-TEST-H-CASE2-NOT: enum class E2 { Yellow };
+
+
+// -
+// Test not moving class-insided enum declarations.
+// -
+// RUN: cp %S/Inputs/enum.h  %T/move-enum/enum.h
+// RUN: echo '#include "enum.h"' > %T/move-enum/enum.cpp
+// RUN: clang-move -names="a::C::E3" -new_cc=%T/move-enum/new_test.cpp -new_header=%T/move-enum/new_test.h -old_cc=%T/move-enum/enum.cpp -old_header=%T/move-enum/enum.h %T/move-enum/enum.cpp -- -std=c++11
+// RUN: FileCheck -input-file=%T/move-enum/new_test.h -allow-empty -check-prefix=CHECK-EMPTY %s
+
+// CHECK-EMPTY: {{^}}{{$}}
Index: test/clang-move/Inputs/enum.h
===
--- /dev/null
+++ test/clang-move/Inputs/enum.h
@@ -0,0 +1,9 @@
+namespace a {
+enum E1 { Green, Red };
+
+enum class E2 { Yellow };
+
+class C {
+  enum E3 { Blue };
+};
+} // namespace a
Index: clang-move/ClangMove.h
===
--- clang-move/ClangMove.h
+++ clang-move/ClangMove.h
@@ -153,6 +153,7 @@
   void moveDeclsToNewFiles();
   void moveAll(SourceManager& SM, StringRef OldFile, StringRef NewFile);
 
+
   // Stores all MatchCallbacks created by this tool.
   std::vector>
   MatchCallbacks;
Index: clang-move/ClangMove.cpp
===
--- clang-move/ClangMove.cpp
+++ clang-move/ClangMove.cpp
@@ -140,6 +140,14 @@
   ClangMoveTool *const MoveTool;
 };
 
+/// Add a declatration being moved to new.h/cc. Note that the declaration will
+/// also be deleted in old.h/cc.
+void MoveDeclFromOldFileToNewFile(ClangMoveTool *MoveTool, const NamedDecl *D) {
+  MoveTool->getMovedDecls().push_back(D);
+  MoveTool->addRemovedDecl(D);
+  MoveTool->getUnremovedDeclsInOldHeader().erase(D);
+}
+
 class FunctionDeclarationMatch : public MatchFinder::MatchCallback {
 public:
   explicit FunctionDeclarationMatch(ClangMoveTool *MoveTool)
@@ -151,9 +159,22 @@
 const clang::NamedDecl *D = FD;
 if (const auto *FTD = FD->getDescribedFunctionTemplate

[PATCH] D28228: [clang-move] Support moving enum declarations.

2017-01-03 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 82876.
hokein marked an inline comment as done.
hokein added a comment.

Not change in ClangMove.h


https://reviews.llvm.org/D28228

Files:
  clang-move/ClangMove.cpp
  test/clang-move/Inputs/enum.h
  test/clang-move/move-enum-decl.cpp
  unittests/clang-move/ClangMoveTests.cpp

Index: unittests/clang-move/ClangMoveTests.cpp
===
--- unittests/clang-move/ClangMoveTests.cpp
+++ unittests/clang-move/ClangMoveTests.cpp
@@ -370,7 +370,6 @@
   std::vector TestHeaders = {
   "typedef int Int;\nclass A {\npublic:\n  int f();\n};\n",
   "using Int = int;\nclass A {\npublic:\n  int f();\n};\n",
-  "enum Color { RED };\nclass A {\npublic:\n  int f();\n};\n",
   };
   move::MoveDefinitionSpec Spec;
   Spec.Names.push_back("A");
Index: test/clang-move/move-enum-decl.cpp
===
--- /dev/null
+++ test/clang-move/move-enum-decl.cpp
@@ -0,0 +1,44 @@
+// RUN: mkdir -p %T/move-enum
+// RUN: cp %S/Inputs/enum.h  %T/move-enum/enum.h
+// RUN: echo '#include "enum.h"' > %T/move-enum/enum.cpp
+// RUN: cd %T/move-enum
+//
+// -
+// Test moving enum declarations.
+// -
+// RUN: clang-move -names="a::E1" -new_cc=%T/move-enum/new_test.cpp -new_header=%T/move-enum/new_test.h -old_cc=%T/move-enum/enum.cpp -old_header=%T/move-enum/enum.h %T/move-enum/enum.cpp -- -std=c++11
+// RUN: FileCheck -input-file=%T/move-enum/new_test.h -check-prefix=CHECK-NEW-TEST-H-CASE1 %s
+// RUN: FileCheck -input-file=%T/move-enum/enum.h -check-prefix=CHECK-OLD-TEST-H-CASE1 %s
+//
+// CHECK-NEW-TEST-H-CASE1: namespace a {
+// CHECK-NEW-TEST-H-CASE1-NEXT: enum E1 { Green, Red };
+// CHECK-NEW-TEST-H-CASE1-NEXT: }
+
+// CHECK-OLD-TEST-H-CASE1-NOT: enum E1 { Green, Red };
+
+
+// -
+// Test moving scoped enum declarations.
+// -
+// RUN: cp %S/Inputs/enum.h  %T/move-enum/enum.h
+// RUN: echo '#include "enum.h"' > %T/move-enum/enum.cpp
+// RUN: clang-move -names="a::E2" -new_cc=%T/move-enum/new_test.cpp -new_header=%T/move-enum/new_test.h -old_cc=%T/move-enum/enum.cpp -old_header=%T/move-enum/enum.h %T/move-enum/enum.cpp -- -std=c++11
+// RUN: FileCheck -input-file=%T/move-enum/new_test.h -check-prefix=CHECK-NEW-TEST-H-CASE2 %s
+// RUN: FileCheck -input-file=%T/move-enum/enum.h -check-prefix=CHECK-OLD-TEST-H-CASE2 %s
+
+// CHECK-NEW-TEST-H-CASE2: namespace a {
+// CHECK-NEW-TEST-H-CASE2-NEXT: enum class E2 { Yellow };
+// CHECK-NEW-TEST-H-CASE2-NEXT: }
+
+// CHECK-OLD-TEST-H-CASE2-NOT: enum class E2 { Yellow };
+
+
+// -
+// Test not moving class-insided enum declarations.
+// -
+// RUN: cp %S/Inputs/enum.h  %T/move-enum/enum.h
+// RUN: echo '#include "enum.h"' > %T/move-enum/enum.cpp
+// RUN: clang-move -names="a::C::E3" -new_cc=%T/move-enum/new_test.cpp -new_header=%T/move-enum/new_test.h -old_cc=%T/move-enum/enum.cpp -old_header=%T/move-enum/enum.h %T/move-enum/enum.cpp -- -std=c++11
+// RUN: FileCheck -input-file=%T/move-enum/new_test.h -allow-empty -check-prefix=CHECK-EMPTY %s
+
+// CHECK-EMPTY: {{^}}{{$}}
Index: test/clang-move/Inputs/enum.h
===
--- /dev/null
+++ test/clang-move/Inputs/enum.h
@@ -0,0 +1,9 @@
+namespace a {
+enum E1 { Green, Red };
+
+enum class E2 { Yellow };
+
+class C {
+  enum E3 { Blue };
+};
+} // namespace a
Index: clang-move/ClangMove.cpp
===
--- clang-move/ClangMove.cpp
+++ clang-move/ClangMove.cpp
@@ -140,6 +140,14 @@
   ClangMoveTool *const MoveTool;
 };
 
+/// Add a declatration being moved to new.h/cc. Note that the declaration will
+/// also be deleted in old.h/cc.
+void MoveDeclFromOldFileToNewFile(ClangMoveTool *MoveTool, const NamedDecl *D) {
+  MoveTool->getMovedDecls().push_back(D);
+  MoveTool->addRemovedDecl(D);
+  MoveTool->getUnremovedDeclsInOldHeader().erase(D);
+}
+
 class FunctionDeclarationMatch : public MatchFinder::MatchCallback {
 public:
   explicit FunctionDeclarationMatch(ClangMoveTool *MoveTool)
@@ -151,9 +159,22 @@
 const clang::NamedDecl *D = FD;
 if (const auto *FTD = FD->getDescribedFunctionTemplate())
   D = FTD;
-MoveTool->getMovedDecls().push_back(D);
-MoveTool->getUnremovedDeclsInOldHeader().erase(D);
-MoveTool->addRemovedDecl(D);
+MoveDeclFromOldFileToNewFile(MoveTool, D);
+  }
+
+private:
+  ClangMoveTool *MoveTool;
+};
+
+class EnumDeclarationMatch : public MatchFinder::MatchCallback {
+public:
+  explicit EnumDeclarationMatc

[clang-tools-extra] r290891 - [clang-move] Support moving enum declarations.

2017-01-03 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Tue Jan  3 08:22:25 2017
New Revision: 290891

URL: http://llvm.org/viewvc/llvm-project?rev=290891&view=rev
Log:
[clang-move] Support moving enum declarations.

Reviewers: ioeric

Subscribers: cfe-commits

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

Added:
clang-tools-extra/trunk/test/clang-move/Inputs/enum.h
clang-tools-extra/trunk/test/clang-move/move-enum-decl.cpp
Modified:
clang-tools-extra/trunk/clang-move/ClangMove.cpp
clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp

Modified: clang-tools-extra/trunk/clang-move/ClangMove.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-move/ClangMove.cpp?rev=290891&r1=290890&r2=290891&view=diff
==
--- clang-tools-extra/trunk/clang-move/ClangMove.cpp (original)
+++ clang-tools-extra/trunk/clang-move/ClangMove.cpp Tue Jan  3 08:22:25 2017
@@ -140,6 +140,14 @@ private:
   ClangMoveTool *const MoveTool;
 };
 
+/// Add a declatration being moved to new.h/cc. Note that the declaration will
+/// also be deleted in old.h/cc.
+void MoveDeclFromOldFileToNewFile(ClangMoveTool *MoveTool, const NamedDecl *D) 
{
+  MoveTool->getMovedDecls().push_back(D);
+  MoveTool->addRemovedDecl(D);
+  MoveTool->getUnremovedDeclsInOldHeader().erase(D);
+}
+
 class FunctionDeclarationMatch : public MatchFinder::MatchCallback {
 public:
   explicit FunctionDeclarationMatch(ClangMoveTool *MoveTool)
@@ -151,9 +159,22 @@ public:
 const clang::NamedDecl *D = FD;
 if (const auto *FTD = FD->getDescribedFunctionTemplate())
   D = FTD;
-MoveTool->getMovedDecls().push_back(D);
-MoveTool->getUnremovedDeclsInOldHeader().erase(D);
-MoveTool->addRemovedDecl(D);
+MoveDeclFromOldFileToNewFile(MoveTool, D);
+  }
+
+private:
+  ClangMoveTool *MoveTool;
+};
+
+class EnumDeclarationMatch : public MatchFinder::MatchCallback {
+public:
+  explicit EnumDeclarationMatch(ClangMoveTool *MoveTool)
+  : MoveTool(MoveTool) {}
+
+  void run(const MatchFinder::MatchResult &Result) override {
+const auto *ED = Result.Nodes.getNodeAs("enum");
+assert(ED);
+MoveDeclFromOldFileToNewFile(MoveTool, ED);
   }
 
 private:
@@ -196,9 +217,7 @@ private:
 
   void MatchClassStaticVariable(const clang::NamedDecl *VD,
 clang::SourceManager* SM) {
-MoveTool->getMovedDecls().push_back(VD);
-MoveTool->addRemovedDecl(VD);
-MoveTool->getUnremovedDeclsInOldHeader().erase(VD);
+MoveDeclFromOldFileToNewFile(MoveTool, VD);
   }
 
   void MatchClassDeclaration(const clang::CXXRecordDecl *CD,
@@ -449,6 +468,8 @@ void ClangMoveTool::registerMatchers(ast
   auto InOldFiles = anyOf(InOldHeader, InOldCC);
   auto ForwardDecls =
   cxxRecordDecl(unless(anyOf(isImplicit(), isDefinition(;
+  auto TopLevelDecl =
+  hasDeclContext(anyOf(namespaceDecl(), translationUnitDecl()));
 
   
//
   // Matchers for old header
@@ -544,11 +565,9 @@ void ClangMoveTool::registerMatchers(ast
   // Create a MatchCallback for class declarations.
   MatchCallbacks.push_back(llvm::make_unique(this));
   // Match moved class declarations.
-  auto MovedClass =
-  cxxRecordDecl(
-  InOldFiles, *HasAnySymbolNames, isDefinition(),
-  hasDeclContext(anyOf(namespaceDecl(), translationUnitDecl(
-  .bind("moved_class");
+  auto MovedClass = cxxRecordDecl(InOldFiles, *HasAnySymbolNames,
+  isDefinition(), TopLevelDecl)
+.bind("moved_class");
   Finder->addMatcher(MovedClass, MatchCallbacks.back().get());
   // Match moved class methods (static methods included) which are defined
   // outside moved class declaration.
@@ -564,11 +583,17 @@ void ClangMoveTool::registerMatchers(ast
   MatchCallbacks.back().get());
 
   MatchCallbacks.push_back(llvm::make_unique(this));
-  Finder->addMatcher(functionDecl(InOldFiles, *HasAnySymbolNames,
-  anyOf(hasDeclContext(namespaceDecl()),
-hasDeclContext(translationUnitDecl(
+  Finder->addMatcher(functionDecl(InOldFiles, *HasAnySymbolNames, TopLevelDecl)
  .bind("function"),
  MatchCallbacks.back().get());
+
+  // Match enum definition in old.h. Enum helpers (which are definied in 
old.cc)
+  // will not be moved for now no matter whether they are used or not.
+  MatchCallbacks.push_back(llvm::make_unique(this));
+  Finder->addMatcher(
+  enumDecl(InOldHeader, *HasAnySymbolNames, isDefinition(), TopLevelDecl)
+  .bind("enum"),
+  MatchCallbacks.back().get());
 }
 
 void ClangMoveTool::run(const ast_matchers::MatchFinder::MatchResult &Result) {
@@ -802,6 +827,7 @@ void ClangMoveTool::onEndOfTranslationUn
 case Decl::Kind::FunctionTemplate:
 case Decl::Kind::ClassTemplate:
 case

[PATCH] D28228: [clang-move] Support moving enum declarations.

2017-01-03 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL290891: [clang-move] Support moving enum declarations. 
(authored by hokein).

Changed prior to commit:
  https://reviews.llvm.org/D28228?vs=82876&id=82879#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D28228

Files:
  clang-tools-extra/trunk/clang-move/ClangMove.cpp
  clang-tools-extra/trunk/test/clang-move/Inputs/enum.h
  clang-tools-extra/trunk/test/clang-move/move-enum-decl.cpp
  clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp

Index: clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp
===
--- clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp
+++ clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp
@@ -370,7 +370,6 @@
   std::vector TestHeaders = {
   "typedef int Int;\nclass A {\npublic:\n  int f();\n};\n",
   "using Int = int;\nclass A {\npublic:\n  int f();\n};\n",
-  "enum Color { RED };\nclass A {\npublic:\n  int f();\n};\n",
   };
   move::MoveDefinitionSpec Spec;
   Spec.Names.push_back("A");
Index: clang-tools-extra/trunk/clang-move/ClangMove.cpp
===
--- clang-tools-extra/trunk/clang-move/ClangMove.cpp
+++ clang-tools-extra/trunk/clang-move/ClangMove.cpp
@@ -140,6 +140,14 @@
   ClangMoveTool *const MoveTool;
 };
 
+/// Add a declatration being moved to new.h/cc. Note that the declaration will
+/// also be deleted in old.h/cc.
+void MoveDeclFromOldFileToNewFile(ClangMoveTool *MoveTool, const NamedDecl *D) {
+  MoveTool->getMovedDecls().push_back(D);
+  MoveTool->addRemovedDecl(D);
+  MoveTool->getUnremovedDeclsInOldHeader().erase(D);
+}
+
 class FunctionDeclarationMatch : public MatchFinder::MatchCallback {
 public:
   explicit FunctionDeclarationMatch(ClangMoveTool *MoveTool)
@@ -151,9 +159,22 @@
 const clang::NamedDecl *D = FD;
 if (const auto *FTD = FD->getDescribedFunctionTemplate())
   D = FTD;
-MoveTool->getMovedDecls().push_back(D);
-MoveTool->getUnremovedDeclsInOldHeader().erase(D);
-MoveTool->addRemovedDecl(D);
+MoveDeclFromOldFileToNewFile(MoveTool, D);
+  }
+
+private:
+  ClangMoveTool *MoveTool;
+};
+
+class EnumDeclarationMatch : public MatchFinder::MatchCallback {
+public:
+  explicit EnumDeclarationMatch(ClangMoveTool *MoveTool)
+  : MoveTool(MoveTool) {}
+
+  void run(const MatchFinder::MatchResult &Result) override {
+const auto *ED = Result.Nodes.getNodeAs("enum");
+assert(ED);
+MoveDeclFromOldFileToNewFile(MoveTool, ED);
   }
 
 private:
@@ -196,9 +217,7 @@
 
   void MatchClassStaticVariable(const clang::NamedDecl *VD,
 clang::SourceManager* SM) {
-MoveTool->getMovedDecls().push_back(VD);
-MoveTool->addRemovedDecl(VD);
-MoveTool->getUnremovedDeclsInOldHeader().erase(VD);
+MoveDeclFromOldFileToNewFile(MoveTool, VD);
   }
 
   void MatchClassDeclaration(const clang::CXXRecordDecl *CD,
@@ -449,6 +468,8 @@
   auto InOldFiles = anyOf(InOldHeader, InOldCC);
   auto ForwardDecls =
   cxxRecordDecl(unless(anyOf(isImplicit(), isDefinition(;
+  auto TopLevelDecl =
+  hasDeclContext(anyOf(namespaceDecl(), translationUnitDecl()));
 
   //
   // Matchers for old header
@@ -544,11 +565,9 @@
   // Create a MatchCallback for class declarations.
   MatchCallbacks.push_back(llvm::make_unique(this));
   // Match moved class declarations.
-  auto MovedClass =
-  cxxRecordDecl(
-  InOldFiles, *HasAnySymbolNames, isDefinition(),
-  hasDeclContext(anyOf(namespaceDecl(), translationUnitDecl(
-  .bind("moved_class");
+  auto MovedClass = cxxRecordDecl(InOldFiles, *HasAnySymbolNames,
+  isDefinition(), TopLevelDecl)
+.bind("moved_class");
   Finder->addMatcher(MovedClass, MatchCallbacks.back().get());
   // Match moved class methods (static methods included) which are defined
   // outside moved class declaration.
@@ -564,11 +583,17 @@
   MatchCallbacks.back().get());
 
   MatchCallbacks.push_back(llvm::make_unique(this));
-  Finder->addMatcher(functionDecl(InOldFiles, *HasAnySymbolNames,
-  anyOf(hasDeclContext(namespaceDecl()),
-hasDeclContext(translationUnitDecl(
+  Finder->addMatcher(functionDecl(InOldFiles, *HasAnySymbolNames, TopLevelDecl)
  .bind("function"),
  MatchCallbacks.back().get());
+
+  // Match enum definition in old.h. Enum helpers (which are definied in old.cc)
+  // will not be moved for now no matter whether they are used or not.
+  MatchCallbacks.push_back(llvm::make_unique(this));
+  Finder->addMatcher(
+  enumDecl(InOldHeader, *HasAnySymbolNames, isDefinition(), TopLevelDecl)
+  .bind("enum"),
+

[PATCH] D27621: [clang-tidy] check to find declarations declaring more than one name

2017-01-03 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang-tidy/readability/OneNamePerDeclarationCheck.cpp:34
+  // a tag declaration (e.g. struct, class etc.):
+  // class A { } Object1, Object2;  <-- won't be matched
+  Finder->addMatcher(

firolino wrote:
> aaron.ballman wrote:
> > firolino wrote:
> > > firolino wrote:
> > > > firolino wrote:
> > > > > firolino wrote:
> > > > > > aaron.ballman wrote:
> > > > > > > firolino wrote:
> > > > > > > > aaron.ballman wrote:
> > > > > > > > > Why do we not want to match this?
> > > > > > > > If we decide, whether we transform 
> > > > > > > > ```
> > > > > > > > class A { 
> > > > > > > > } Object1, Object2;
> > > > > > > > ``` 
> > > > > > > > to
> > > > > > > > ```
> > > > > > > > class A { 
> > > > > > > > } Object1, 
> > > > > > > > Object2;
> > > > > > > > ``` 
> > > > > > > > or
> > > > > > > > ```
> > > > > > > > class A { 
> > > > > > > > } 
> > > > > > > > Object1, 
> > > > > > > > Object2;
> > > > > > > > ``` 
> > > > > > > > I might consider adding support for it. Moreover, this kind of 
> > > > > > > > definition is usually seen globally and I don't know how to 
> > > > > > > > handle globals yet. See 
> > > > > > > > http://lists.llvm.org/pipermail/cfe-dev/2015-November/046262.html
> > > > > > > I think this should be handled. It can be handled in either of 
> > > > > > > the forms you show, or by saying:
> > > > > > > ```
> > > > > > > A Object1;
> > > > > > > A Object2;
> > > > > > > ```
> > > > > > > If all of these turn out to be a problem, we can still diagnose 
> > > > > > > without providing a fixit.
> > > > > > > 
> > > > > > > As for globals in general, they can be handled in a separate 
> > > > > > > patch once we figure out the declaration grouping.
> > > > > > OK. I will try to split the object definition from the class 
> > > > > > definition, as you have suggested. Thus, I can kick out the 
> > > > > > tagDecl-matcher as well. If there is no easy way to do this, it 
> > > > > > will be reported anyway but without a fixit.
> > > > > > 
> > > > > > Note for me: Update documentation!
> > > > > What about
> > > > > ```
> > > > > struct S {
> > > > > } S1;
> > > > > ```
> > > > > I would like to report this too, since two names are being declared 
> > > > > here. `S` and `S1`. What do you think?
> > > > ```
> > > > struct {
> > > > } nn1, nn2;
> > > > ```
> > > > Shall we ignore anonymous definitions?
> > > To be more precise: Warn and provide a fixit for `struct S {} S1`. Only 
> > > warn for `struct {} nn1, nn2`.
> > > What about
> > > 
> > > ```
> > > struct S {
> > > } S1;
> > > ```
> > > I would like to report this too, since two names are being declared here. 
> > > S and S1. What do you think?
> > 
> > I don't think that this should be diagnosed. For one, this is a relatively 
> > common pattern (arguably more common than `struct S { } S1, S2;`), but 
> > also, it names two very distinct entities (a type and a variable).
> > 
> > > ```
> > > struct {
> > > } nn1, nn2;
> > >```
> > > Shall we ignore anonymous definitions?
> > 
> > Yes, we basically have to.
> > 
> Transforming
> ```
> typedef struct X { int t; } X, Y;
> ```
> to
> ```
> typedef struct X { int t; };
> typedef X X;
> typedef X Y;
> ```
> will be valid, but looks odd.
I am on the fence about this transformation -- it does not declare new objects, 
but instead declares new types. A very common pattern in some libraries (such 
as the Win32 SDK) is to declare:
```
typedef struct Blah {

} Blah, *PBlah, **PPBlah;
```
Because of that pattern, diagnosing the above typedef is likely to be very 
chatty in some projects, and I don't know that the fixit provides much real 
benefit for types.

At least for the CERT DCL04-C version of this rule, that code should not be 
flagged. Do you think any of the variations of this check should flag it?


https://reviews.llvm.org/D27621



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


[PATCH] D26137: [clang-tidy] Add check name to YAML export

2017-01-03 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

Looks good.

Fixed the issues myself and running tests before committing this.

Thank you for working on this!




Comment at: tools/extra/clang-tidy/ClangTidy.cpp:106
   void reportDiagnostic(const ClangTidyError &Error) {
-const ClangTidyMessage &Message = Error.Message;
+const ClangTidyMessage Message = Error.Message;
 SourceLocation Loc = getLocation(Message.FilePath, Message.FileOffset);

alexfh wrote:
> Why this change?
Assuming, it was unintentional, changing back to reference.



Comment at: tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.h:36
 
-/// \brief A message from a clang-tidy check.
-///
-/// Note that this is independent of a \c SourceManager.
-struct ClangTidyMessage {
-  ClangTidyMessage(StringRef Message = "");
-  ClangTidyMessage(StringRef Message, const SourceManager &Sources,
-   SourceLocation Loc);
-  std::string Message;
-  std::string FilePath;
-  unsigned FileOffset;
-};
+typedef clang::tooling::DiagnosticMessage ClangTidyMessage;
 

alexfh wrote:
> Do we actually need this typedef? How much is the old type name used?
Removed.


Repository:
  rL LLVM

https://reviews.llvm.org/D26137



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


r290892 - [clang-tidy] Add check name to YAML export

2017-01-03 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Tue Jan  3 08:35:47 2017
New Revision: 290892

URL: http://llvm.org/viewvc/llvm-project?rev=290892&view=rev
Log:
[clang-tidy] Add check name to YAML export

Add a field indicating the associated check for every replacement to the YAML
report generated with the '-export-fixes' option.  Update
clang-apply-replacements to handle the new format.

Patch by Alpha Abdoulaye!

Differential revision: https://reviews.llvm.org/D26137

Added:
cfe/trunk/include/clang/Tooling/Core/Diagnostic.h
cfe/trunk/include/clang/Tooling/DiagnosticsYaml.h
cfe/trunk/lib/Tooling/Core/Diagnostic.cpp
Modified:
cfe/trunk/include/clang/Tooling/Core/Replacement.h
cfe/trunk/include/clang/Tooling/ReplacementsYaml.h
cfe/trunk/lib/Tooling/Core/CMakeLists.txt
cfe/trunk/unittests/Tooling/ReplacementsYamlTest.cpp

Added: cfe/trunk/include/clang/Tooling/Core/Diagnostic.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Core/Diagnostic.h?rev=290892&view=auto
==
--- cfe/trunk/include/clang/Tooling/Core/Diagnostic.h (added)
+++ cfe/trunk/include/clang/Tooling/Core/Diagnostic.h Tue Jan  3 08:35:47 2017
@@ -0,0 +1,100 @@
+//===--- Diagnostic.h - Framework for clang diagnostics tools --*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// \file
+//  Structures supporting diagnostics and refactorings that span multiple
+//  translation units. Indicate diagnostics reports and replacements
+//  suggestions for the analyzed sources.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLING_CORE_DIAGNOSTIC_H
+#define LLVM_CLANG_TOOLING_CORE_DIAGNOSTIC_H
+
+#include "Replacement.h"
+#include "clang/Basic/Diagnostic.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringMap.h"
+#include "llvm/ADT/StringRef.h"
+#include 
+
+namespace clang {
+namespace tooling {
+
+/// \brief Represents the diagnostic message with the error message associated
+/// and the information on the location of the problem.
+struct DiagnosticMessage {
+  DiagnosticMessage(llvm::StringRef Message = "");
+
+  /// \brief Constructs a diagnostic message with anoffset to the diagnostic
+  /// within the file where the problem occured.
+  ///
+  /// \param Loc Should be a file location, it is not meaningful for a macro
+  /// location.
+  ///
+  DiagnosticMessage(llvm::StringRef Message, const SourceManager &Sources,
+SourceLocation Loc);
+  std::string Message;
+  std::string FilePath;
+  unsigned FileOffset;
+};
+
+/// \brief Represents the diagnostic with the level of severity and possible
+/// fixes to be applied.
+struct Diagnostic {
+  enum Level {
+Warning = DiagnosticsEngine::Warning,
+Error = DiagnosticsEngine::Error
+  };
+
+  Diagnostic() = default;
+
+  Diagnostic(llvm::StringRef DiagnosticName, Level DiagLevel,
+ StringRef BuildDirectory);
+
+  Diagnostic(llvm::StringRef DiagnosticName, DiagnosticMessage &Message,
+ llvm::StringMap &Fix,
+ SmallVector &Notes, Level DiagLevel,
+ llvm::StringRef BuildDirectory);
+
+  /// \brief Name identifying the Diagnostic.
+  std::string DiagnosticName;
+
+  /// \brief Message associated to the diagnostic.
+  DiagnosticMessage Message;
+
+  /// \brief Fixes to apply, grouped by file path.
+  llvm::StringMap Fix;
+
+  /// \brief Potential notes about the diagnostic.
+  SmallVector Notes;
+
+  /// \brief Diagnostic level. Can indicate either an error or a warning.
+  Level DiagLevel;
+
+  /// \brief A build directory of the diagnostic source file.
+  ///
+  /// It's an absolute path which is `directory` field of the source file in
+  /// compilation database. If users don't specify the compilation database
+  /// directory, it is the current directory where clang-tidy runs.
+  ///
+  /// Note: it is empty in unittest.
+  std::string BuildDirectory;
+};
+
+/// \brief Collection of Diagnostics generated from a single translation unit.
+struct TranslationUnitDiagnostics {
+  /// Name of the main source for the translation unit.
+  std::string MainSourceFile;
+  std::vector Diagnostics;
+};
+
+} // end namespace tooling
+} // end namespace clang
+#endif // LLVM_CLANG_TOOLING_CORE_DIAGNOSTIC_H

Modified: cfe/trunk/include/clang/Tooling/Core/Replacement.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Core/Replacement.h?rev=290892&r1=290891&r2=290892&view=diff
==
--- cfe/trunk/include/clang/Tooling/Core/Replacement.h (original)
+++ cfe/trunk/include/clang/Tooling/Core/Replacement.h Tue Jan  3 08:35:47 2017
@@ -329,12 +329,6 @@ llvm

[PATCH] D26137: [clang-tidy] Add check name to YAML export

2017-01-03 Thread Alexander Kornienko via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL290892: [clang-tidy] Add check name to YAML export (authored 
by alexfh).

Changed prior to commit:
  https://reviews.llvm.org/D26137?vs=82860&id=82881#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26137

Files:
  cfe/trunk/include/clang/Tooling/Core/Diagnostic.h
  cfe/trunk/include/clang/Tooling/Core/Replacement.h
  cfe/trunk/include/clang/Tooling/DiagnosticsYaml.h
  cfe/trunk/include/clang/Tooling/ReplacementsYaml.h
  cfe/trunk/lib/Tooling/Core/CMakeLists.txt
  cfe/trunk/lib/Tooling/Core/Diagnostic.cpp
  cfe/trunk/unittests/Tooling/ReplacementsYamlTest.cpp

Index: cfe/trunk/include/clang/Tooling/ReplacementsYaml.h
===
--- cfe/trunk/include/clang/Tooling/ReplacementsYaml.h
+++ cfe/trunk/include/clang/Tooling/ReplacementsYaml.h
@@ -65,7 +65,6 @@
   static void mapping(IO &Io,
   clang::tooling::TranslationUnitReplacements &Doc) {
 Io.mapRequired("MainSourceFile", Doc.MainSourceFile);
-Io.mapOptional("Context", Doc.Context, std::string());
 Io.mapRequired("Replacements", Doc.Replacements);
   }
 };
Index: cfe/trunk/include/clang/Tooling/Core/Diagnostic.h
===
--- cfe/trunk/include/clang/Tooling/Core/Diagnostic.h
+++ cfe/trunk/include/clang/Tooling/Core/Diagnostic.h
@@ -0,0 +1,100 @@
+//===--- Diagnostic.h - Framework for clang diagnostics tools --*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// \file
+//  Structures supporting diagnostics and refactorings that span multiple
+//  translation units. Indicate diagnostics reports and replacements
+//  suggestions for the analyzed sources.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLING_CORE_DIAGNOSTIC_H
+#define LLVM_CLANG_TOOLING_CORE_DIAGNOSTIC_H
+
+#include "Replacement.h"
+#include "clang/Basic/Diagnostic.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringMap.h"
+#include "llvm/ADT/StringRef.h"
+#include 
+
+namespace clang {
+namespace tooling {
+
+/// \brief Represents the diagnostic message with the error message associated
+/// and the information on the location of the problem.
+struct DiagnosticMessage {
+  DiagnosticMessage(llvm::StringRef Message = "");
+
+  /// \brief Constructs a diagnostic message with anoffset to the diagnostic
+  /// within the file where the problem occured.
+  ///
+  /// \param Loc Should be a file location, it is not meaningful for a macro
+  /// location.
+  ///
+  DiagnosticMessage(llvm::StringRef Message, const SourceManager &Sources,
+SourceLocation Loc);
+  std::string Message;
+  std::string FilePath;
+  unsigned FileOffset;
+};
+
+/// \brief Represents the diagnostic with the level of severity and possible
+/// fixes to be applied.
+struct Diagnostic {
+  enum Level {
+Warning = DiagnosticsEngine::Warning,
+Error = DiagnosticsEngine::Error
+  };
+
+  Diagnostic() = default;
+
+  Diagnostic(llvm::StringRef DiagnosticName, Level DiagLevel,
+ StringRef BuildDirectory);
+
+  Diagnostic(llvm::StringRef DiagnosticName, DiagnosticMessage &Message,
+ llvm::StringMap &Fix,
+ SmallVector &Notes, Level DiagLevel,
+ llvm::StringRef BuildDirectory);
+
+  /// \brief Name identifying the Diagnostic.
+  std::string DiagnosticName;
+
+  /// \brief Message associated to the diagnostic.
+  DiagnosticMessage Message;
+
+  /// \brief Fixes to apply, grouped by file path.
+  llvm::StringMap Fix;
+
+  /// \brief Potential notes about the diagnostic.
+  SmallVector Notes;
+
+  /// \brief Diagnostic level. Can indicate either an error or a warning.
+  Level DiagLevel;
+
+  /// \brief A build directory of the diagnostic source file.
+  ///
+  /// It's an absolute path which is `directory` field of the source file in
+  /// compilation database. If users don't specify the compilation database
+  /// directory, it is the current directory where clang-tidy runs.
+  ///
+  /// Note: it is empty in unittest.
+  std::string BuildDirectory;
+};
+
+/// \brief Collection of Diagnostics generated from a single translation unit.
+struct TranslationUnitDiagnostics {
+  /// Name of the main source for the translation unit.
+  std::string MainSourceFile;
+  std::vector Diagnostics;
+};
+
+} // end namespace tooling
+} // end namespace clang
+#endif // LLVM_CLANG_TOOLING_CORE_DIAGNOSTIC_H
Index: cfe/trunk/include/clang/Tooling/Core/Replacement.h
===
--- cfe/trunk/include/clang/Tooling/Core/Replacement.h
+++ cfe/trunk/include/clang/Tooling/Core/Repla

[clang-tools-extra] r290893 - [clang-tidy] Add check name to YAML export (clang-tools-extra part)

2017-01-03 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Tue Jan  3 08:36:13 2017
New Revision: 290893

URL: http://llvm.org/viewvc/llvm-project?rev=290893&view=rev
Log:
[clang-tidy] Add check name to YAML export (clang-tools-extra part)

Add a field indicating the associated check for every replacement to the YAML
report generated with the '-export-fixes' option.  Update
clang-apply-replacements to handle the new format.

Patch by Alpha Abdoulaye!

Differential revision: https://reviews.llvm.org/D26137

Modified:

clang-tools-extra/trunk/clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h

clang-tools-extra/trunk/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp

clang-tools-extra/trunk/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
clang-tools-extra/trunk/clang-tidy/ClangTidy.h
clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.h
clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp

clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/basic/file1.yaml

clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/basic/file2.yaml

clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file1.yaml

clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file2.yaml

clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file3.yaml
clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/crlf/file1.yaml
clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/format/no.yaml
clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/format/yes.yaml

Modified: 
clang-tools-extra/trunk/clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h?rev=290893&r1=290892&r2=290893&view=diff
==
--- 
clang-tools-extra/trunk/clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h
 (original)
+++ 
clang-tools-extra/trunk/clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h
 Tue Jan  3 08:36:13 2017
@@ -16,6 +16,7 @@
 #ifndef LLVM_CLANG_APPLYREPLACEMENTS_H
 #define LLVM_CLANG_APPLYREPLACEMENTS_H
 
+#include "clang/Tooling/Core/Diagnostic.h"
 #include "clang/Tooling/Refactoring.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
@@ -43,6 +44,9 @@ typedef std::vector TUReplacementFiles;
 
+/// \brief Collection of TranslationUniDiagnostics.
+typedef std::vector TUDiagnostics;
+
 /// \brief Map mapping file name to Replacements targeting that file.
 typedef llvm::DenseMap>
@@ -58,8 +62,8 @@ typedef llvm::DenseMap &Replaces,

Modified: 
clang-tools-extra/trunk/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp?rev=290893&r1=290892&r2=290893&view=diff
==
--- 
clang-tools-extra/trunk/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
 (original)
+++ 
clang-tools-extra/trunk/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
 Tue Jan  3 08:36:13 2017
@@ -20,6 +20,7 @@
 #include "clang/Format/Format.h"
 #include "clang/Lex/Lexer.h"
 #include "clang/Rewrite/Core/Rewriter.h"
+#include "clang/Tooling/DiagnosticsYaml.h"
 #include "clang/Tooling/ReplacementsYaml.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/Support/FileSystem.h"
@@ -37,7 +38,7 @@ namespace replace {
 
 std::error_code collectReplacementsFromDirectory(
 const llvm::StringRef Directory, TUReplacements &TUs,
-TUReplacementFiles &TURFiles, clang::DiagnosticsEngine &Diagnostics) {
+TUReplacementFiles &TUFiles, clang::DiagnosticsEngine &Diagnostics) {
   using namespace llvm::sys::fs;
   using namespace llvm::sys::path;
 
@@ -54,7 +55,7 @@ std::error_code collectReplacementsFromD
 if (extension(I->path()) != ".yaml")
   continue;
 
-TURFiles.push_back(I->path());
+TUFiles.push_back(I->path());
 
 ErrorOr> Out =
 MemoryBuffer::getFile(I->path());
@@ -79,6 +80,51 @@ std::error_code collectReplacementsFromD
   return ErrorCode;
 }
 
+std::error_code
+collectReplacementsFromDirectory(const llvm::StringRef Directory,
+ TUDiagnostics &TUs, TUReplacementFiles 
&TUFiles,
+ clang::DiagnosticsEngine &Diagnostics) {
+  using namespace llvm::sys::fs;
+  using namespace llvm::sys::path;
+
+  std::error_code ErrorCode;
+
+  for (recursive_directory_iterator I(Directory, ErrorCode), E;
+   I != E && !ErrorCode; I.increment(ErrorCode)) {
+if (filename(I

[PATCH] D25406: Fix doubled whitespace in modernize-use-auto fixit

2017-01-03 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

In https://reviews.llvm.org/D25406#633892, @malcolm.parsons wrote:

> I'd prefer a -format option to clang-tidy.


Exactly.


https://reviews.llvm.org/D25406



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


[PATCH] D28217: [libc++] Overallocation of am_pm array in locale.cpp

2017-01-03 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists added a comment.

This looks fine to me.  
All the other places that use this (or related functionality) have a rank of 2.

Interestingly enough, this has been there since "the beginning of time" (the 
initial import of libc++ into the LLVM subversion repo)


https://reviews.llvm.org/D28217



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


[PATCH] D20689: [clang-tidy] Suspicious Call Argument checker

2017-01-03 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh requested changes to this revision.
alexfh added a comment.
This revision now requires changes to proceed.

In https://reviews.llvm.org/D20689#633889, @varjujan wrote:

> I ran the check on multiple projects and tried to categorize the warnings: 
> real errors, false positives, naming errors and coincidences. The results are 
> attached. I got no warnings on LLVM.


I didn't find any "real errors" in the files you posted, which means that 
either all of these projects are of extreme code quality or that the error is 
rather unlikely to happen.

Another concern is that the check seems to treat argument types in a rather 
primitive way, e.g. it doesn't consider any type conversions or promotions.


https://reviews.llvm.org/D20689



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


[PATCH] D27529: Correct Vectorcall Register passing and HVA Behavior

2017-01-03 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 82887.
erichkeane added a comment.

Sorry about that, I have no idea how I messed up the process, I must have 
thought this was a different window.  I've updated it with the latest version 
of this diff that I have which seems to be the one I intended initially.

Additionally, I note that the back end one went in here: 
https://reviews.llvm.org/D27392

Thanks,
Erich

PS: I apologize for the delay, I've been out of internet-communication over the 
last 2 weeks!


https://reviews.llvm.org/D27529

Files:
  include/clang/CodeGen/CGFunctionInfo.h
  lib/CodeGen/TargetInfo.cpp
  test/CodeGen/vectorcall.c
  test/CodeGenCXX/homogeneous-aggregates.cpp

Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -870,6 +870,11 @@
   unsigned FreeSSERegs;
 };
 
+enum {
+  // Vectorcall only allows the first 6 parameters to be passed in registers.
+  VectorcallMaxParamNumAsReg = 6
+};
+
 /// X86_32ABIInfo - The X86-32 ABI information.
 class X86_32ABIInfo : public SwiftABIInfo {
   enum Class {
@@ -915,6 +920,8 @@
   Class classify(QualType Ty) const;
   ABIArgInfo classifyReturnType(QualType RetTy, CCState &State) const;
   ABIArgInfo classifyArgumentType(QualType RetTy, CCState &State) const;
+  ABIArgInfo reclassifyHvaArgType(QualType RetTy, CCState &State, 
+  const ABIArgInfo& current) const;
   /// \brief Updates the number of available free registers, returns 
   /// true if any registers were allocated.
   bool updateFreeRegs(QualType Ty, CCState &State) const;
@@ -1480,6 +1487,27 @@
   return true;
 }
 
+ABIArgInfo
+X86_32ABIInfo::reclassifyHvaArgType(QualType Ty, CCState &State,
+const ABIArgInfo ¤t) const {
+  // Assumes vectorCall calling convention.
+  const Type *Base = nullptr;
+  uint64_t NumElts = 0;
+
+  if (!Ty->isBuiltinType() && !Ty->isVectorType() &&
+  isHomogeneousAggregate(Ty, Base, NumElts)) {
+if (State.FreeSSERegs >= NumElts) {
+  // HVA types get passed directly in registers if there is room.
+  State.FreeSSERegs -= NumElts;
+  return ABIArgInfo::getDirectHva();
+}
+// If there's no room, the HVA gets passed as normal indirect
+// structure.
+return getIndirectResult(Ty, /*ByVal=*/false, State);
+  } 
+  return current;
+}
+
 ABIArgInfo X86_32ABIInfo::classifyArgumentType(QualType Ty,
CCState &State) const {
   // FIXME: Set alignment on indirect arguments.
@@ -1499,19 +1527,34 @@
   }
 
   // vectorcall adds the concept of a homogenous vector aggregate, similar
-  // to other targets.
-  const Type *Base = nullptr;
-  uint64_t NumElts = 0;
-  if ((State.CC == llvm::CallingConv::X86_VectorCall ||
-   State.CC == llvm::CallingConv::X86_RegCall) &&
-  isHomogeneousAggregate(Ty, Base, NumElts)) {
-if (State.FreeSSERegs >= NumElts) {
-  State.FreeSSERegs -= NumElts;
-  if (Ty->isBuiltinType() || Ty->isVectorType())
+  // to other targets, regcall uses some of the HVA rules.
+  if (State.CC == llvm::CallingConv::X86_VectorCall ||
+  State.CC == llvm::CallingConv::X86_RegCall) {
+const Type *Base = nullptr;
+uint64_t NumElts = 0;
+bool IsHva = isHomogeneousAggregate(Ty, Base, NumElts);
+
+if (State.CC == llvm::CallingConv::X86_RegCall && IsHva) {
+  if (State.FreeSSERegs >= NumElts) {
+State.FreeSSERegs -= NumElts;
+if (Ty->isBuiltinType() || Ty->isVectorType())
+  return ABIArgInfo::getDirect();
+return ABIArgInfo::getExpand();
+
+  }
+  return getIndirectResult(Ty, /*ByVal=*/false, State);
+} else if (State.CC == llvm::CallingConv::X86_VectorCall && IsHva) {
+  if (State.FreeSSERegs >= NumElts && (Ty->isBuiltinType() || Ty->isVectorType())) {
+// Actual floating-point types get registers first time through if
+// there is registers available
+State.FreeSSERegs -= NumElts;
 return ABIArgInfo::getDirect();
-  return ABIArgInfo::getExpand();
+  }  else if (!Ty->isBuiltinType() && !Ty->isVectorType()) {
+// HVA Types only get registers after everything else has been
+// set, so it gets set as indirect for now.
+return ABIArgInfo::getIndirect(getContext().getTypeAlignInChars(Ty));
+  }
 }
-return getIndirectResult(Ty, /*ByVal=*/false, State);
   }
 
   if (isAggregateTypeForABI(Ty)) {
@@ -1624,9 +1667,40 @@
 ++State.FreeRegs;
 
   bool UsedInAlloca = false;
-  for (auto &I : FI.arguments()) {
-I.info = classifyArgumentType(I.type, State);
-UsedInAlloca |= (I.info.getKind() == ABIArgInfo::InAlloca);
+  if (State.CC == llvm::CallingConv::X86_VectorCall) {
+// Vectorcall only allows the first 6 parameters to be passed in registers,
+// and homogeneous vector aggregates are only put into registers as a second
+// priorit

[PATCH] D27680: [CodeGen] Move lifetime.start of a variable when goto jumps back past its declaration

2017-01-03 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added inline comments.



Comment at: lib/CodeGen/CGDecl.cpp:917
+  if (!InsertPt)
+Builder.SetInsertPoint(BB, BB->begin());
+  // If InsertPt is a terminator, insert it before InsertPt.

rjmccall wrote:
> BB->begin() is not necessarily a legal place to insert a call.  This could 
> happen if e.g. a scope was unconditionally entered after a statement 
> including a ternary expression.
> 
> Also, I think lexical scopes don't necessarily have an active basic block 
> upon entry, because their entry can be unreachable.  This happens most 
> importantly with e.g. switch statements, but can also happen with goto or 
> simply with unreachable code (which it's still important to not crash on).
I'm not sure why BB->begin() wouldn't be the right place to insert a call when 
a scope is entered after a ternary expression. Is it because 
EmitConditionalOperatorLValue inserts a phi at the beginning of block 
"cond.end"?

Also, I'm not sure when goto or unreachable code might be mis-compiled. Could 
you elaborate further on that? I can see now why lifetime.start can be inserted 
at a wrong location when lowering switch statements because EmitSwitchStmt 
creates and inserts a SwitchInst before a lexical scope is entered, but I'm not 
sure about the other two cases you mentioned.


https://reviews.llvm.org/D27680



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


[PATCH] D27440: clang-format-vsix: fail when clang-format outputs to stderr

2017-01-03 Thread Cameron via Phabricator via cfe-commits
cameron314 added a comment.

>> Thanks, I'll check these out! Btw, I noticed that the clang-format tests are 
>> non-Windows due to path assumptions. Is this a lost cause, or just something 
>> no one's bothered to look into yet?
> 
> No one's bothered looking into it yet.

Which tests? We run the unit tests (FormatTests.exe) locally just fine on 
Windows.


https://reviews.llvm.org/D27440



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


[PATCH] D28166: Properly merge K&R functions that have attributes

2017-01-03 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In https://reviews.llvm.org/D28166#633643, @rsmith wrote:

> In https://reviews.llvm.org/D28166#633621, @aaron.ballman wrote:
>
> > Do you think this patch should be gated on (or perhaps combined with) a fix 
> > for the lowering bug, or do you think this patch is reasonable on its own? 
> > Given that it turns working code into UB, I think my preference is to gate 
> > it on a fix for the lowering bug, but I'm also not certain I am the right 
> > person to implement that fix (though I could give it a shot).
>
>
> The test in question has a comment pointing to PR7117, which in turn 
> indicates that we might miscompile parts of FreeBSD if we land this as-is. So 
> I think we need to gate this on a fix for the lowering bug.


I agree with that logic, but would also point out that this bug appears to have 
nothing to do with attributed functions, but K&R calls in general. Removing the 
`__stdcall` entirely shows an identical issue:

  void g(int n) {}
  void (*p)() = g;
  void f() { p(0);}

generates

  ; ModuleID = '-'
  source_filename = "-"
  target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
  target triple = "x86_64-pc-windows-msvc"
  
  @p = global void (...)* bitcast (void (i32)* @g to void (...)*), align 8
  
  ; Function Attrs: noinline nounwind
  define void @g(i32 %n) #0 {
  entry:
%n.addr = alloca i32, align 4
store i32 %n, i32* %n.addr, align 4
ret void
  }
  
  ; Function Attrs: noinline nounwind
  define void @f() #0 {
  entry:
%0 = load void (...)*, void (...)** @p, align 8
%callee.knr.cast = bitcast void (...)* %0 to void (i64)*
call void %callee.knr.cast(i64 0)
ret void
  }
  
  attributes #0 = { noinline nounwind 
"correctly-rounded-divide-sqrt-fp-math"="fal
  se" "disable-tail-calls"="false" "less-precise-fpmad"="false" 
"no-frame-pointer-
  elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" 
"no-nans-fp-mat
  h"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" 
"stack-p
  rotector-buffer-size"="8" "target-features"="+mmx,+sse,+sse2,+x87" 
"unsafe-fp-ma
  th"="false" "use-soft-float"="false" }
  
  !llvm.ident = !{!0}
  
  !0 = !{!"clang version 4.0.0 (trunk 290670)"}

I'm happy to try to work on fixing this, but am unfamiliar with this part of 
the codegen. I *think* the problem is that we gin up the function type for a 
non-prototyped function based on the function call expression argument types, 
and the literal `0` is getting the type `signed long long`. This forces us to 
bitcast the function to one taking an i64 rather than an i32. If you switch the 
argument from the literal `0` to a variable of type `int`, the bitcast becomes 
`%3 = bitcast void (...)* %1 to void (i32)*`, which is correct (at least, as I 
interpret the comments left in `EmitCall()` around line 4245).

Suggestions and hints welcome. :-)


https://reviews.llvm.org/D28166



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


[PATCH] D28235: [clang-format cleanup] merge continuous deleted lines into one deletion.

2017-01-03 Thread Eric Liu via Phabricator via cfe-commits
ioeric created this revision.
ioeric added a reviewer: djasper.
ioeric added a subscriber: cfe-commits.
Herald added a subscriber: klimek.

This cleans up "\n" among continuous lines when they are deleted.


https://reviews.llvm.org/D28235

Files:
  lib/Format/Format.cpp
  unittests/Format/CleanupTest.cpp

Index: unittests/Format/CleanupTest.cpp
===
--- unittests/Format/CleanupTest.cpp
+++ unittests/Format/CleanupTest.cpp
@@ -48,13 +48,13 @@
   std::string Code = "namespace A {\n"
  "namespace B {\n"
  "} // namespace B\n"
- "} // namespace A\n\n"
+ "} // namespace A\n"
  "namespace C {\n"
  "namespace D { int i; }\n"
  "inline namespace E { namespace { } }\n"
  "}";
-  std::string Expected = "\n\n\n\n\nnamespace C {\n"
- "namespace D { int i; }\n   \n"
+  std::string Expected = "\nnamespace C {\n"
+ "namespace D { int i; }\n\n"
  "}";
   EXPECT_EQ(Expected, cleanupAroundOffsets({28, 91, 132}, Code));
 }
@@ -68,8 +68,8 @@
  "inline namespace E { namespace { } }\n"
  "}";
   std::string Expected = "namespace A {\n"
- "\n\n\nnamespace C {\n"
- "namespace D int i; }\n   \n"
+ "\n\nnamespace C {\n"
+ "namespace D int i; }\n\n"
  "}";
   std::vector Ranges(1, tooling::Range(0, Code.size()));
   EXPECT_EQ(Expected, cleanup(Code, Ranges));
@@ -94,7 +94,7 @@
  "} // namespace A\n"
  "namespace C { // Yo\n"
  "}";
-  std::string Expected = "\n\n\n\n\n\n";
+  std::string Expected = "";
   std::vector Ranges(1, tooling::Range(0, Code.size()));
   std::string Result = cleanup(Code, Ranges);
   EXPECT_EQ(Expected, Result);
@@ -111,7 +111,7 @@
  "namespace C\n"
  "{ // Yo\n"
  "}\n";
-  std::string Expected = "\n\n\n\n\n\n\n\n\n\n";
+  std::string Expected = "\n";
   std::vector Ranges(1, tooling::Range(0, Code.size()));
   FormatStyle Style = getLLVMStyle();
   Style.BraceWrapping.AfterNamespace = true;
@@ -268,8 +268,8 @@
  "inline namespace E { namespace { } }\n"
  "}";
   std::string Expected = "namespace A {\n"
- "\n\n\nnamespace C {\n"
- "class A { A() : x(0) {} };\n   \n"
+ "\n\nnamespace C {\n"
+ "class A { A() : x(0) {} };\n\n"
  "}";
   std::vector Ranges(1, tooling::Range(0, Code.size()));
   std::string Result = cleanup(Code, Ranges);
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -1034,7 +1034,7 @@
   }
 }
 
-return generateFixes();
+return generateFixes(AnnotatedLines);
   }
 
 private:
@@ -1172,20 +1172,33 @@
   DeletedTokens.insert(Tok);
   }
 
-  tooling::Replacements generateFixes() {
+  tooling::Replacements
+  generateFixes(const SmallVectorImpl &AnnotatedLines) {
+// A map from the last token of a line to the first token of the next line
+// if it exists.
+std::map LastToNextLineFirst;
+for (auto I = AnnotatedLines.begin(), E = std::prev(AnnotatedLines.end());
+ I != E; ++I)
+  LastToNextLineFirst[(*I)->Last] = (*std::next(I))->First;
 tooling::Replacements Fixes;
 std::vector Tokens;
 std::copy(DeletedTokens.begin(), DeletedTokens.end(),
   std::back_inserter(Tokens));
 
+auto NextTokenInFile = [&LastToNextLineFirst](FormatToken *Tok) {
+  if (Tok->Next)
+return Tok->Next;
+  return LastToNextLineFirst[Tok];
+};
 // Merge multiple continuous token deletions into one big deletion so that
 // the number of replacements can be reduced. This makes computing affected
 // ranges more efficient when we run reformat on the changed code.
+// FIXME: delete trailing '\n' when deleting an entire line.
 unsigned Idx = 0;
 while (Idx < Tokens.size()) {
   unsigned St = Idx, End = Idx;
   while ((End + 1) < Tokens.size() &&
- Tokens[End]->Next == Tokens[End + 1]) {
+ NextTokenInFile(Tokens[End]) == Tokens[End + 1]) {
 End++;
   }
   auto SR = CharSourceRange::getCharRange(Tokens[St]->Tok.getLocation(),
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D27680: [CodeGen] Move lifetime.start of a variable when goto jumps back past its declaration

2017-01-03 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added inline comments.



Comment at: lib/CodeGen/CGDecl.cpp:917
+  if (!InsertPt)
+Builder.SetInsertPoint(BB, BB->begin());
+  // If InsertPt is a terminator, insert it before InsertPt.

ahatanak wrote:
> rjmccall wrote:
> > BB->begin() is not necessarily a legal place to insert a call.  This could 
> > happen if e.g. a scope was unconditionally entered after a statement 
> > including a ternary expression.
> > 
> > Also, I think lexical scopes don't necessarily have an active basic block 
> > upon entry, because their entry can be unreachable.  This happens most 
> > importantly with e.g. switch statements, but can also happen with goto or 
> > simply with unreachable code (which it's still important to not crash on).
> I'm not sure why BB->begin() wouldn't be the right place to insert a call 
> when a scope is entered after a ternary expression. Is it because 
> EmitConditionalOperatorLValue inserts a phi at the beginning of block 
> "cond.end"?
> 
> Also, I'm not sure when goto or unreachable code might be mis-compiled. Could 
> you elaborate further on that? I can see now why lifetime.start can be 
> inserted at a wrong location when lowering switch statements because 
> EmitSwitchStmt creates and inserts a SwitchInst before a lexical scope is 
> entered, but I'm not sure about the other two cases you mentioned.
Also, I realized this patch doesn't always insert lifetime.start at the 
beginning of the block the variable is associated with. For example, when the 
following code is compiled, lifetime.start for "i" is inserted after the call 
to foo2, but it should be inserted before the call (at the beginning of the 
function):

```
void foo1(int a) {
  foo2();
  for (int i = 0; i < 10; ++i)
foo3();
}
```

I'll fix this in my next patch.


https://reviews.llvm.org/D27680



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


[PATCH] D27440: clang-format-vsix: fail when clang-format outputs to stderr

2017-01-03 Thread Antonio Maiorano via Phabricator via cfe-commits
amaiorano added a comment.

In https://reviews.llvm.org/D27440#634043, @cameron314 wrote:

> >> Thanks, I'll check these out! Btw, I noticed that the clang-format tests 
> >> are non-Windows due to path assumptions. Is this a lost cause, or just 
> >> something no one's bothered to look into yet?
> > 
> > No one's bothered looking into it yet.
>
> Which tests? We run the unit tests (FormatTests.exe) locally just fine on 
> Windows.


There was one test disabled for MSVC, which I fixed and enabled here: 
https://reviews.llvm.org/D27971

I will soon close this issue (https://reviews.llvm.org/D27440) once 
https://reviews.llvm.org/D28081 goes through as clang-format should return 
non-zero when an error occurs.

In https://reviews.llvm.org/D27440#634043, @cameron314 wrote:

> >> Thanks, I'll check these out! Btw, I noticed that the clang-format tests 
> >> are non-Windows due to path assumptions. Is this a lost cause, or just 
> >> something no one's bothered to look into yet?
> > 
> > No one's bothered looking into it yet.
>
> Which tests? We run the unit tests (FormatTests.exe) locally just fine on 
> Windows.





https://reviews.llvm.org/D27440



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


[PATCH] D28235: [clang-format cleanup] merge continuous deleted lines into one deletion.

2017-01-03 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 82889.
ioeric added a comment.

- Fixed a nit.


https://reviews.llvm.org/D28235

Files:
  lib/Format/Format.cpp
  unittests/Format/CleanupTest.cpp

Index: unittests/Format/CleanupTest.cpp
===
--- unittests/Format/CleanupTest.cpp
+++ unittests/Format/CleanupTest.cpp
@@ -48,13 +48,13 @@
   std::string Code = "namespace A {\n"
  "namespace B {\n"
  "} // namespace B\n"
- "} // namespace A\n\n"
+ "} // namespace A\n"
  "namespace C {\n"
  "namespace D { int i; }\n"
  "inline namespace E { namespace { } }\n"
  "}";
-  std::string Expected = "\n\n\n\n\nnamespace C {\n"
- "namespace D { int i; }\n   \n"
+  std::string Expected = "\nnamespace C {\n"
+ "namespace D { int i; }\n\n"
  "}";
   EXPECT_EQ(Expected, cleanupAroundOffsets({28, 91, 132}, Code));
 }
@@ -68,8 +68,8 @@
  "inline namespace E { namespace { } }\n"
  "}";
   std::string Expected = "namespace A {\n"
- "\n\n\nnamespace C {\n"
- "namespace D int i; }\n   \n"
+ "\n\nnamespace C {\n"
+ "namespace D int i; }\n\n"
  "}";
   std::vector Ranges(1, tooling::Range(0, Code.size()));
   EXPECT_EQ(Expected, cleanup(Code, Ranges));
@@ -94,7 +94,7 @@
  "} // namespace A\n"
  "namespace C { // Yo\n"
  "}";
-  std::string Expected = "\n\n\n\n\n\n";
+  std::string Expected = "";
   std::vector Ranges(1, tooling::Range(0, Code.size()));
   std::string Result = cleanup(Code, Ranges);
   EXPECT_EQ(Expected, Result);
@@ -111,7 +111,7 @@
  "namespace C\n"
  "{ // Yo\n"
  "}\n";
-  std::string Expected = "\n\n\n\n\n\n\n\n\n\n";
+  std::string Expected = "\n";
   std::vector Ranges(1, tooling::Range(0, Code.size()));
   FormatStyle Style = getLLVMStyle();
   Style.BraceWrapping.AfterNamespace = true;
@@ -268,8 +268,8 @@
  "inline namespace E { namespace { } }\n"
  "}";
   std::string Expected = "namespace A {\n"
- "\n\n\nnamespace C {\n"
- "class A { A() : x(0) {} };\n   \n"
+ "\n\nnamespace C {\n"
+ "class A { A() : x(0) {} };\n\n"
  "}";
   std::vector Ranges(1, tooling::Range(0, Code.size()));
   std::string Result = cleanup(Code, Ranges);
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -1034,7 +1034,7 @@
   }
 }
 
-return generateFixes();
+return generateFixes(AnnotatedLines);
   }
 
 private:
@@ -1172,20 +1172,31 @@
   DeletedTokens.insert(Tok);
   }
 
-  tooling::Replacements generateFixes() {
+  tooling::Replacements
+  generateFixes(const SmallVectorImpl &AnnotatedLines) {
+// A map from the last token of a line to the first token of the next line
+// if it exists.
+std::map LastToNextLineFirst;
+for (auto I = AnnotatedLines.begin(), E = std::prev(AnnotatedLines.end());
+ I != E; ++I)
+  LastToNextLineFirst[(*I)->Last] = (*std::next(I))->First;
 tooling::Replacements Fixes;
 std::vector Tokens;
 std::copy(DeletedTokens.begin(), DeletedTokens.end(),
   std::back_inserter(Tokens));
 
+auto NextTokenInFile = [&LastToNextLineFirst](FormatToken *Tok) {
+  return Tok->Next ? Tok->Next : LastToNextLineFirst[Tok];
+};
 // Merge multiple continuous token deletions into one big deletion so that
 // the number of replacements can be reduced. This makes computing affected
 // ranges more efficient when we run reformat on the changed code.
+// FIXME: delete trailing '\n' when deleting an entire line.
 unsigned Idx = 0;
 while (Idx < Tokens.size()) {
   unsigned St = Idx, End = Idx;
   while ((End + 1) < Tokens.size() &&
- Tokens[End]->Next == Tokens[End + 1]) {
+ NextTokenInFile(Tokens[End]) == Tokens[End + 1]) {
 End++;
   }
   auto SR = CharSourceRange::getCharRange(Tokens[St]->Tok.getLocation(),
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26137: [clang-tidy] Add check name to YAML export

2017-01-03 Thread Alpha Abdoulaye via Phabricator via cfe-commits
Alpha added a comment.

Thanks for the review!




Comment at: tools/extra/clang-tidy/ClangTidy.cpp:106
   void reportDiagnostic(const ClangTidyError &Error) {
-const ClangTidyMessage &Message = Error.Message;
+const ClangTidyMessage Message = Error.Message;
 SourceLocation Loc = getLocation(Message.FilePath, Message.FileOffset);

alexfh wrote:
> alexfh wrote:
> > Why this change?
> Assuming, it was unintentional, changing back to reference.
It is indeed unintentional.



Comment at: tools/extra/clang-tidy/ClangTidy.h:245
 /// output stream.
-void exportReplacements(const std::vector &Errors,
+void exportReplacements(const StringRef MainFilePath,
+const std::vector &Errors,

alexfh wrote:
> Top-level const on function parameters in function declarations is useless 
> (it's not a part of the function prototype and it tells nothing to the 
> function users). It might make sense on a function definition, if used 
> consistently (same way as on local variables). However, is not very common in 
> LLVM/Clang.
Ok, this is good to know.



Comment at: tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.h:36
 
-/// \brief A message from a clang-tidy check.
-///
-/// Note that this is independent of a \c SourceManager.
-struct ClangTidyMessage {
-  ClangTidyMessage(StringRef Message = "");
-  ClangTidyMessage(StringRef Message, const SourceManager &Sources,
-   SourceLocation Loc);
-  std::string Message;
-  std::string FilePath;
-  unsigned FileOffset;
-};
+typedef clang::tooling::DiagnosticMessage ClangTidyMessage;
 

alexfh wrote:
> alexfh wrote:
> > Do we actually need this typedef? How much is the old type name used?
> Removed.
I was quite hesitant with this one, wondering if it would be better to keep 
clang-tidy specific naming in that case.


Repository:
  rL LLVM

https://reviews.llvm.org/D26137



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


[PATCH] D27680: [CodeGen] Move lifetime.start of a variable when goto jumps back past its declaration

2017-01-03 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/CodeGen/CGDecl.cpp:917
+  if (!InsertPt)
+Builder.SetInsertPoint(BB, BB->begin());
+  // If InsertPt is a terminator, insert it before InsertPt.

ahatanak wrote:
> ahatanak wrote:
> > rjmccall wrote:
> > > BB->begin() is not necessarily a legal place to insert a call.  This 
> > > could happen if e.g. a scope was unconditionally entered after a 
> > > statement including a ternary expression.
> > > 
> > > Also, I think lexical scopes don't necessarily have an active basic block 
> > > upon entry, because their entry can be unreachable.  This happens most 
> > > importantly with e.g. switch statements, but can also happen with goto or 
> > > simply with unreachable code (which it's still important to not crash on).
> > I'm not sure why BB->begin() wouldn't be the right place to insert a call 
> > when a scope is entered after a ternary expression. Is it because 
> > EmitConditionalOperatorLValue inserts a phi at the beginning of block 
> > "cond.end"?
> > 
> > Also, I'm not sure when goto or unreachable code might be mis-compiled. 
> > Could you elaborate further on that? I can see now why lifetime.start can 
> > be inserted at a wrong location when lowering switch statements because 
> > EmitSwitchStmt creates and inserts a SwitchInst before a lexical scope is 
> > entered, but I'm not sure about the other two cases you mentioned.
> Also, I realized this patch doesn't always insert lifetime.start at the 
> beginning of the block the variable is associated with. For example, when the 
> following code is compiled, lifetime.start for "i" is inserted after the call 
> to foo2, but it should be inserted before the call (at the beginning of the 
> function):
> 
> ```
> void foo1(int a) {
>   foo2();
>   for (int i = 0; i < 10; ++i)
> foo3();
> }
> ```
> 
> I'll fix this in my next patch.
Yes, my point was about PHIs and any other instruction that might be required 
to appear at the start of a block.


https://reviews.llvm.org/D27680



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


[PATCH] D28081: Make GetStyle return Expected instead of FormatStyle

2017-01-03 Thread Antonio Maiorano via Phabricator via cfe-commits
amaiorano updated this revision to Diff 82896.
amaiorano added a comment.

Minor comment change, turned the ObjC test into a non-fixture test, and renamed 
FormatStyleOrError to FormatStyle in format function.


https://reviews.llvm.org/D28081

Files:
  include/clang/Format/Format.h
  lib/Format/Format.cpp
  lib/Tooling/Refactoring.cpp
  tools/clang-format/ClangFormat.cpp
  unittests/Format/FormatTest.cpp
  unittests/Format/FormatTestObjC.cpp

Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -68,17 +68,21 @@
   FormatStyle Style;
 };
 
-TEST_F(FormatTestObjC, DetectsObjCInHeaders) {
-  Style = getStyle("LLVM", "a.h", "none", "@interface\n"
-  "- (id)init;");
-  EXPECT_EQ(FormatStyle::LK_ObjC, Style.Language);
+TEST(FormatTestObjCStyle, DetectsObjCInHeaders) {
+  auto Style = getStyle("LLVM", "a.h", "none", "@interface\n"
+   "- (id)init;");
+  ASSERT_TRUE((bool)Style);
+  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
+
   Style = getStyle("LLVM", "a.h", "none", "@interface\n"
   "+ (id)init;");
-  EXPECT_EQ(FormatStyle::LK_ObjC, Style.Language);
+  ASSERT_TRUE((bool)Style);
+  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
 
   // No recognizable ObjC.
   Style = getStyle("LLVM", "a.h", "none", "void f() {}");
-  EXPECT_EQ(FormatStyle::LK_Cpp, Style.Language);
+  ASSERT_TRUE((bool)Style);
+  EXPECT_EQ(FormatStyle::LK_Cpp, Style->Language);
 }
 
 TEST_F(FormatTestObjC, FormatObjCTryCatch) {
Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -10945,22 +10945,51 @@
   ASSERT_TRUE(
   FS.addFile("/a/test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("int i;")));
   auto Style1 = getStyle("file", "/a/.clang-format", "Google", "", &FS);
-  ASSERT_EQ(Style1, getLLVMStyle());
+  ASSERT_TRUE((bool)Style1);
+  ASSERT_EQ(*Style1, getLLVMStyle());
 
   // Test 2: fallback to default.
   ASSERT_TRUE(
   FS.addFile("/b/test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("int i;")));
   auto Style2 = getStyle("file", "/b/test.cpp", "Mozilla", "", &FS);
-  ASSERT_EQ(Style2, getMozillaStyle());
+  ASSERT_TRUE((bool)Style2);
+  ASSERT_EQ(*Style2, getMozillaStyle());
 
   // Test 3: format file in parent directory.
   ASSERT_TRUE(
   FS.addFile("/c/.clang-format", 0,
  llvm::MemoryBuffer::getMemBuffer("BasedOnStyle: Google")));
   ASSERT_TRUE(FS.addFile("/c/sub/sub/sub/test.cpp", 0,
  llvm::MemoryBuffer::getMemBuffer("int i;")));
   auto Style3 = getStyle("file", "/c/sub/sub/sub/test.cpp", "LLVM", "", &FS);
-  ASSERT_EQ(Style3, getGoogleStyle());
+  ASSERT_TRUE((bool)Style3);
+  ASSERT_EQ(*Style3, getGoogleStyle());
+
+  // Test 4: error on invalid fallback style
+  auto Style4 = getStyle("file", "a.h", "KungFu", "", &FS);
+  ASSERT_FALSE((bool)Style4);
+  llvm::consumeError(Style4.takeError());
+
+  // Test 5: error on invalid yaml on command line
+  auto Style5 = getStyle("{invalid_key=invalid_value}", "a.h", "LLVM", "", &FS);
+  ASSERT_FALSE((bool)Style5);
+  llvm::consumeError(Style5.takeError());
+
+  // Test 6: error on invalid style
+  auto Style6 = getStyle("KungFu", "a.h", "LLVM", "", &FS);
+  ASSERT_FALSE((bool)Style6);
+  llvm::consumeError(Style6.takeError());
+
+  // Test 7: found config file, error on parsing it
+  ASSERT_TRUE(
+  FS.addFile("/d/.clang-format", 0,
+ llvm::MemoryBuffer::getMemBuffer("BasedOnStyle: LLVM\n"
+  "InvalidKey: InvalidValue")));
+  ASSERT_TRUE(
+  FS.addFile("/d/test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("int i;")));
+  auto Style7 = getStyle("file", "/d/.clang-format", "LLVM", "", &FS);
+  ASSERT_FALSE((bool)Style7);
+  llvm::consumeError(Style7.takeError());
 }
 
 TEST_F(ReplacementTest, FormatCodeAfterReplacements) {
Index: tools/clang-format/ClangFormat.cpp
===
--- tools/clang-format/ClangFormat.cpp
+++ tools/clang-format/ClangFormat.cpp
@@ -249,12 +249,17 @@
   if (fillRanges(Code.get(), Ranges))
 return true;
   StringRef AssumedFileName = (FileName == "-") ? AssumeFileName : FileName;
-  FormatStyle FormatStyle =
+
+  llvm::Expected FormatStyle =
   getStyle(Style, AssumedFileName, FallbackStyle, Code->getBuffer());
+  if (!FormatStyle) {
+llvm::errs() << llvm::toString(FormatStyle.takeError()) << "\n";
+return true;
+  }
   if (SortIncludes.getNumOccurrences() != 0)
-FormatStyle.SortIncludes = SortIncludes;
+FormatStyle->SortIncludes = SortIncludes;
   unsigned CursorPosition = Cursor;
-  Replacements Replaces = sortIncludes(FormatStyle, Code->getBuffer(), Ranges,
+  Replacem

[PATCH] D28238: [Driver] Add openSuse AArch64 Triple

2017-01-03 Thread Kostya Kortchinsky via Phabricator via cfe-commits
cryptoad created this revision.
cryptoad added reviewers: chandlerc, bruno, bkramer.
cryptoad added a subscriber: cfe-commits.
Herald added subscribers: rengolin, aemerson.

openSuse has AArch64 support, with images running on the Raspberry Pi 3.
The libraries and headers live under the aarch64-suse-linux subdirectory,
which is currently not in the AArch64 triples list. Address this by adding
the corresponding string to AArch64Triples.


https://reviews.llvm.org/D28238

Files:
  lib/Driver/ToolChains.cpp


Index: lib/Driver/ToolChains.cpp
===
--- lib/Driver/ToolChains.cpp
+++ lib/Driver/ToolChains.cpp
@@ -1531,7 +1531,7 @@
   static const char *const AArch64LibDirs[] = {"/lib64", "/lib"};
   static const char *const AArch64Triples[] = {
   "aarch64-none-linux-gnu", "aarch64-linux-gnu", "aarch64-linux-android",
-  "aarch64-redhat-linux"};
+  "aarch64-redhat-linux", "aarch64-suse-linux"};
   static const char *const AArch64beLibDirs[] = {"/lib"};
   static const char *const AArch64beTriples[] = {"aarch64_be-none-linux-gnu",
  "aarch64_be-linux-gnu"};


Index: lib/Driver/ToolChains.cpp
===
--- lib/Driver/ToolChains.cpp
+++ lib/Driver/ToolChains.cpp
@@ -1531,7 +1531,7 @@
   static const char *const AArch64LibDirs[] = {"/lib64", "/lib"};
   static const char *const AArch64Triples[] = {
   "aarch64-none-linux-gnu", "aarch64-linux-gnu", "aarch64-linux-android",
-  "aarch64-redhat-linux"};
+  "aarch64-redhat-linux", "aarch64-suse-linux"};
   static const char *const AArch64beLibDirs[] = {"/lib"};
   static const char *const AArch64beTriples[] = {"aarch64_be-none-linux-gnu",
  "aarch64_be-linux-gnu"};
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D28226: threading_support: introduce __libcpp_recursive_mutex_t

2017-01-03 Thread David Majnemer via Phabricator via cfe-commits
majnemer added a comment.

Is `__libcpp_mutex_reference` all that useful? There is no real dynamism for 
these mutexes. I'd just add functions for the recursive locks just like we have 
a separate function for `__libcpp_recursive_mutex_init`


Repository:
  rL LLVM

https://reviews.llvm.org/D28226



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


[PATCH] D28165: Change clang-format's Chromium JavaScript defaults

2017-01-03 Thread Nico Weber via Phabricator via cfe-commits
thakis added inline comments.



Comment at: lib/Format/Format.cpp:643
+ChromiumStyle.AllowShortIfStatementsOnASingleLine = false;
+ChromiumStyle.AllowShortLoopsOnASingleLine = false;
+  }

Thanks for the patch! Do we want these as false in Chromium's JS? I would've 
thought the diff would just be 

```
- } else {
+ } else if (Language != FormatStyle::LK_JavaScript)
```

so that we just use google style for JS.

If we do want to deviate from google style here for some reason then
a) say why somewhere
b) change the check for cpp to also include `|| Language == 
FormatStyle::LK_ObjC`

(If you include more diff context as described on 
http://llvm.org/docs/Phabricator.html, reviewing on phab is a bit easier.)


https://reviews.llvm.org/D28165



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


[PATCH] D27486: Correct class-template deprecation behavior

2017-01-03 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 82909.
erichkeane added a comment.

Updated based on Richard Smith's suggestion, all tests pass with no alteration, 
and the initial incorrect behavior was corrected in an existing test.


https://reviews.llvm.org/D27486

Files:
  include/clang/Basic/Attr.td
  include/clang/Sema/Sema.h
  lib/Sema/SemaTemplate.cpp
  lib/Sema/SemaTemplateInstantiate.cpp
  lib/Sema/SemaTemplateInstantiateDecl.cpp
  test/CXX/dcl.dcl/dcl.attr/dcl.attr.deprecated/p1.cpp
  utils/TableGen/ClangAttrEmitter.cpp

Index: lib/Sema/SemaTemplateInstantiate.cpp
===
--- lib/Sema/SemaTemplateInstantiate.cpp
+++ lib/Sema/SemaTemplateInstantiate.cpp
@@ -1882,6 +1882,8 @@
   namespace sema {
 Attr *instantiateTemplateAttribute(const Attr *At, ASTContext &C, Sema &S,
 const MultiLevelTemplateArgumentList &TemplateArgs);
+Attr *instantiateTemplateAttributeForDecl(const Attr *At, ASTContext &C, Sema &S,
+const MultiLevelTemplateArgumentList &TemplateArgs);
   }
 }
 
Index: lib/Sema/SemaTemplate.cpp
===
--- lib/Sema/SemaTemplate.cpp
+++ lib/Sema/SemaTemplate.cpp
@@ -2401,6 +2401,10 @@
 ClassTemplate->getLocation(),
  ClassTemplate,
  Converted, nullptr);
+  MultiLevelTemplateArgumentList TemplateArgLists;
+  TemplateArgLists.addOuterTemplateArguments(Converted);
+  InstantiateAttrsForDecl(TemplateArgLists,
+  ClassTemplate->getTemplatedDecl(), Decl);
   ClassTemplate->AddSpecialization(Decl, InsertPos);
   if (ClassTemplate->isOutOfLine())
 Decl->setLexicalDeclContext(ClassTemplate->getLexicalDeclContext());
Index: lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -308,6 +308,26 @@
   Attr.getRange());
 }
 
+void Sema::InstantiateAttrsForDecl(
+const MultiLevelTemplateArgumentList &TemplateArgs, const Decl *Tmpl,
+Decl *New, LateInstantiatedAttrVec *LateAttrs,
+LocalInstantiationScope *OuterMostScope) {
+  for (const auto *TmplAttr : Tmpl->attrs()) {
+// FIXME: If any of the special case versions from InstantiateAttrs become
+// applicable to template declaration, we'll need to add them here.
+NamedDecl *ND = dyn_cast(New);
+CXXRecordDecl *ThisContext =
+dyn_cast_or_null(ND->getDeclContext());
+CXXThisScopeRAII ThisScope(*this, ThisContext, /*TypeQuals*/ 0,
+   ND && ND->isCXXInstanceMember());
+
+Attr *NewAttr = sema::instantiateTemplateAttributeForDecl(TmplAttr, Context, *this,
+   TemplateArgs);
+if (NewAttr)
+  New->addAttr(NewAttr);
+  }
+}
+
 void Sema::InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs,
 const Decl *Tmpl, Decl *New,
 LateInstantiatedAttrVec *LateAttrs,
@@ -945,6 +965,7 @@
 }
   }
 
+  SemaRef.InstantiateAttrsForDecl(TemplateArgs, D, Enum);
   SemaRef.InstantiateAttrs(TemplateArgs, D, Enum);
 
   Enum->setInstantiationOfMemberEnum(D, TSK_ImplicitInstantiation);
@@ -1033,6 +1054,7 @@
 }
 
 if (EnumConst) {
+  SemaRef.InstantiateAttrsForDecl(TemplateArgs, EC, EnumConst);
   SemaRef.InstantiateAttrs(TemplateArgs, EC, EnumConst);
 
   EnumConst->setAccess(Enum->getAccess());
Index: utils/TableGen/ClangAttrEmitter.cpp
===
--- utils/TableGen/ClangAttrEmitter.cpp
+++ utils/TableGen/ClangAttrEmitter.cpp
@@ -2452,26 +2452,20 @@
   OS << "#endif  // ATTR_VISITOR_DECLS_ONLY\n";
 }
 
-// Emits code to instantiate dependent attributes on templates.
-void EmitClangAttrTemplateInstantiate(RecordKeeper &Records, raw_ostream &OS) {
-  emitSourceFileHeader("Template instantiation code for attributes", OS);
-
-  std::vector Attrs = Records.getAllDerivedDefinitions("Attr");
-
-  OS << "namespace clang {\n"
- << "namespace sema {\n\n"
- << "Attr *instantiateTemplateAttribute(const Attr *At, ASTContext &C, "
- << "Sema &S,\n"
- << "const MultiLevelTemplateArgumentList &TemplateArgs) {\n"
- << "  switch (At->getKind()) {\n";
+void EmitClangAttrTemplateInstantiateHelper(const std::vector &Attrs,
+raw_ostream &OS, bool DeclTime) {
+ OS << "  switch (At->getKind()) {\n";
 
   for (const auto *Attr : Attrs) {
 const Record &R = *Attr;
 if (!R.getValueAsBit("ASTNode"))
   continue;
 
 OS << "case attr::" << R.getName() << ": {\n";
-bool ShouldClone = R.getValueAsBit("Clone");
+
+  

[PATCH] D28223: clean up use of _WIN32

2017-01-03 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd added inline comments.



Comment at: include/__config:158
+#if defined(_WIN32)
+#  define _LIBCPP_WIN32 1
 #  define _LIBCPP_LITTLE_ENDIAN 1

EricWF wrote:
> smeenai wrote:
> > Perhaps `_LIBCPP_WIN32API` instead, to be clear that this is specific to 
> > the usage of Win32 APIs, rather than just a general catch-all libc++ on 
> > Windows macro?
> +1 for that name, since it is self documenting.
Yeah, I like `WIN32API` better too.  Ill change that.



Comment at: include/__config:791
 // Most unix variants have catopen.  These are the specific ones that don't.
-#if !defined(_WIN32) && !defined(__BIONIC__) && !defined(_NEWLIB_VERSION)
+#if !defined(__BIONIC__) && !defined(_NEWLIB_VERSION)
 #define _LIBCPP_HAS_CATOPEN 1

EricWF wrote:
> smeenai wrote:
> > Windows has `catopen`?
> This is nested in a block that already excludes windows.
What @EricWF said :-).



Comment at: include/type_traits:1684
 // PE/COFF does not support alignment beyond 8192 (=0x2000)
-#if !defined(_WIN32)
+#if !defined(__ELF__) && !defined(__MACH__)
 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x4000);

EricWF wrote:
> smeenai wrote:
> > Might be cleaner to have a `_LIBCPP_COFF` macro (both here and for the 
> > similar `__config` change), to make the intent clearer?
> +1 for `_LIBCPP_COFF` or similar. I would rather explicitly exclude coff than 
> include a list of supported formats.
WFM, Ill introduce a `_LIBCPP_ELF`, `_LIBCPP_MACHO`, and `_LIBCPP_COFF`.


Repository:
  rL LLVM

https://reviews.llvm.org/D28223



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


[PATCH] D28166: Properly merge K&R functions that have attributes

2017-01-03 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a reviewer: majnemer.
aaron.ballman added a comment.

> I *think* the problem is that we gin up the function type for a 
> non-prototyped function based on the function call expression argument types, 
> and the literal `0` is getting the type `signed long long`.

I think this is because of `CodeGenFunction::getVarArgType()` and is specific 
to the Windows ABI.

  // System headers on Windows define NULL to 0 instead of 0LL on Win64. MSVC
  // implicitly widens null pointer constants that are arguments to varargs
  // functions to pointer-sized ints.

This causes the 0 to be emit as a 64-bit value rather than a 32-bit value. 
Indeed, if you change your original example to pass `1` rather than `0` when 
calling `p`, you no longer get the UB:

  ; Function Attrs: noinline nounwind
  define void @f() #0 {
  entry:
%0 = load void (...)*, void (...)** @p, align 8
%callee.knr.cast = bitcast void (...)* %0 to void (i32)*
call void %callee.knr.cast(i32 1)
ret void
  }

However, when I test with MSVC 2015, I do not get the behavior that Clang 
produces. My test was:

  void h(int i, ...) {}
  void i(int i, int j, int k, int l, int m) {}
  
  void(*p)() = i;
  
  void f() {
p(0, 1, 2, 3, 0);
h(0, 1, 2, 3, 0);
i(0, 1, 2, 3, 0);
  }

MSVC outputs:

  ; 8:   p(0, 1, 2, 3, 0);
  
mov DWORD PTR [rsp+32], 0
mov r9d, 3
mov r8d, 2
mov edx, 1
xor ecx, ecx
callQWORD PTR p
  
  ; 9:   h(0, 1, 2, 3, 0);
  
mov QWORD PTR [rsp+32], 0
mov r9d, 3
mov r8d, 2
mov edx, 1
xor ecx, ecx
callh
  
  ; 10   :   i(0, 1, 2, 3, 0);
  
mov DWORD PTR [rsp+32], 0
mov r9d, 3
mov r8d, 2
mov edx, 1
xor ecx, ecx
calli

Clang outputs:

  %callee.knr.cast = bitcast void (...)* %0 to void (i64, i32, i32, i32, i64)*
  call void %callee.knr.cast(i64 0, i32 1, i32 2, i32 3, i64 0)
  call void (i32, ...) @h(i32 0, i32 1, i32 2, i32 3, i64 0)
  call void @i(i32 0, i32 1, i32 2, i32 3, i32 0)

Note that the K&R call casts to i64 in Clang but uses a DWORD PTR in MSVC. Only 
the variadic call to `h()` uses the QWORD PTR. So I think the correct behavior 
is to only enable the vararg behavior when the function is variadic with an 
ellipsis rather than variadic due to a lack of prototype.

Thoughts?


https://reviews.llvm.org/D28166



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


[PATCH] D28223: clean up use of _WIN32

2017-01-03 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd added a comment.

I figured that using the explicit encoding is nicer since it means that its 
more documenting.  I dont have a problem with `_LIBCPP_SHORT_WCHAR` as that 
maps quite well to `-fshort-wchar`.


Repository:
  rL LLVM

https://reviews.llvm.org/D28223



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


[PATCH] D28145: [OpenMP] Basic support for a parallel directive in a target region on an NVPTX device.

2017-01-03 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp:511-516
+// Activate workers.
+syncCTAThreads(CGF);
+
+// Barrier at end of parallel region.
+syncCTAThreads(CGF);
+

Are two back-to-back syncCTAThreads() intentional or did you mean to call 
something else to activate workers?


https://reviews.llvm.org/D28145



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


[PATCH] D28223: clean up use of _WIN32

2017-01-03 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd updated this revision to Diff 82912.
compnerd added a comment.

Update for `_LIBCPP_WIN32API` and addition of `_LIBCPP_OBJECT_FORMAT_COFF`, 
`_LIBCPP_OBJECT_FORMAT_ELF`, `_LIBCPP_OBJECT_FORMAT_MACHO`


Repository:
  rL LLVM

https://reviews.llvm.org/D28223

Files:
  include/__config
  include/__locale
  include/support/win32/support.h
  include/type_traits
  src/chrono.cpp
  src/include/config_elast.h
  src/locale.cpp
  src/new.cpp
  src/system_error.cpp
  src/thread.cpp

Index: src/thread.cpp
===
--- src/thread.cpp
+++ src/thread.cpp
@@ -24,16 +24,17 @@
 # endif // defined(BSD)
 #endif // defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))

-#if !defined(_WIN32)
+#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
 # include 
-#endif // !_WIN32
+#endif // defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))

 #if defined(__NetBSD__)
 #pragma weak pthread_create // Do not create libpthread dependency
 #endif
-#if defined(_WIN32)
+
+#if defined(_LIBCPP_WIN32API)
 #include 
-#endif
+#endif // defined(_LIBCPP_WIN32API)

 _LIBCPP_BEGIN_NAMESPACE_STD

@@ -91,7 +92,7 @@
 if (result < 0)
 return 0;
 return static_cast(result);
-#elif defined(_WIN32)
+#elif defined(_LIBCPP_WIN32API)
 SYSTEM_INFO info;
 GetSystemInfo(&info);
 return info.dwNumberOfProcessors;
Index: src/system_error.cpp
===
--- src/system_error.cpp
+++ src/system_error.cpp
@@ -65,7 +65,7 @@

 string do_strerror_r(int ev);

-#if defined(_WIN32)
+#if defined(_LIBCPP_MSVCRT)
 string do_strerror_r(int ev) {
   char buffer[strerror_buff_size];
   if (::strerror_s(buffer, strerror_buff_size, ev) == 0)
Index: src/new.cpp
===
--- src/new.cpp
+++ src/new.cpp
@@ -72,7 +72,7 @@
 if (static_cast(alignment) < sizeof(void*))
   alignment = std::align_val_t(sizeof(void*));
 void* p;
-#if defined(_WIN32)
+#if defined(_LIBCPP_MSVCRT)
 while ((p = _aligned_malloc(size, static_cast(alignment))) == nullptr)
 #else
 while (::posix_memalign(&p, static_cast(alignment), size) != 0)
Index: src/locale.cpp
===
--- src/locale.cpp
+++ src/locale.cpp
@@ -3254,7 +3254,7 @@
 const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
 extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
 {
-#if _WIN32
+#if defined(_LIBCPP_WCHAR_IS_UCS2)
 const uint16_t* _frm = reinterpret_cast(frm);
 const uint16_t* _frm_end = reinterpret_cast(frm_end);
 const uint16_t* _frm_nxt = _frm;
@@ -3266,7 +3266,7 @@
 uint8_t* _to = reinterpret_cast(to);
 uint8_t* _to_end = reinterpret_cast(to_end);
 uint8_t* _to_nxt = _to;
-#if _WIN32
+#if defined(_LIBCPP_WCHAR_IS_UCS2)
 result r = ucs2_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
 _Maxcode_, _Mode_);
 #else
@@ -3286,7 +3286,7 @@
 const uint8_t* _frm = reinterpret_cast(frm);
 const uint8_t* _frm_end = reinterpret_cast(frm_end);
 const uint8_t* _frm_nxt = _frm;
-#if _WIN32
+#if defined(_LIBCCPP_WCHAR_IS_UCS2)
 uint16_t* _to = reinterpret_cast(to);
 uint16_t* _to_end = reinterpret_cast(to_end);
 uint16_t* _to_nxt = _to;
Index: src/include/config_elast.h
===
--- src/include/config_elast.h
+++ src/include/config_elast.h
@@ -10,7 +10,7 @@
 #ifndef _LIBCPP_CONFIG_ELAST
 #define _LIBCPP_CONFIG_ELAST

-#if defined(_WIN32)
+#if defined(_LIBCPP_MSCVRT)
 #include 
 #else
 #include 
@@ -28,7 +28,7 @@
 // No _LIBCPP_ELAST needed on Apple
 #elif defined(__sun__)
 #define _LIBCPP_ELAST ESTALE
-#elif defined(_WIN32)
+#elif defined(_LIBCPP_MSCVRT)
 #define _LIBCPP_ELAST _sys_nerr
 #else
 // Warn here so that the person doing the libcxx port has an easier time:
Index: src/chrono.cpp
===
--- src/chrono.cpp
+++ src/chrono.cpp
@@ -12,7 +12,7 @@
 #include "system_error"  // __throw_system_error
 #include // clock_gettime, CLOCK_MONOTONIC and CLOCK_REALTIME

-#if defined(_WIN32)
+#if defined(_LIBCPP_WIN32API)
 #define WIN32_LEAN_AND_MEAN
 #define VC_EXTRA_LEAN
 #include 
@@ -22,13 +22,13 @@
 #else
 #if !defined(CLOCK_REALTIME)
 #include // for gettimeofday and timeval
-#endif
-#endif
+#endif // !defined(CLOCK_REALTIME)
+#endif // defined(_LIBCPP_WIN32API)

 #if !defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK)
 #if __APPLE__
 #include   // mach_absolute_time, mach_timebase_info_data_t
-#elif !defined(_WIN32) && !defined(CLOCK_MONOTONIC)
+#elif !defined(_LIBCPP_WIN32API) && !defined(CLOCK_MONOTONIC)
 #error "Monotonic clock not implemented"
 #endif
 #endif
@@ -45,7 +45,7 @@
 system_clock::time_point
 system_clock::now() _NOEXCEPT
 {
-#if defined(_WIN32)
+#if defined(_LIBC

r290898 - [OPENMP] Private, firstprivate, and lastprivate clauses for distribute, host code generation

2017-01-03 Thread Carlo Bertolli via cfe-commits
Author: cbertol
Date: Tue Jan  3 12:24:42 2017
New Revision: 290898

URL: http://llvm.org/viewvc/llvm-project?rev=290898&view=rev
Log:
[OPENMP] Private, firstprivate, and lastprivate clauses for distribute, host 
code generation

https://reviews.llvm.org/D17840

This patch enables private, firstprivate, and lastprivate clauses for the 
OpenMP distribute directive.
Regression tests differ from the similar case of the same clauses on the for 
directive, by removing a reference to two global variables g and g1. This is 
necessary because: 1. a distribute pragma is only allowed inside a target 
region; 2. referring a global variable (e.g. g and g1) in a target region 
requires the program to enclose the variable in a "declare target" region; 3. 
declare target pragmas, which are used to define a declare target region, are 
currently unavailable in clang (patch being prepared).
For this reason, I moved the global declarations into local variables.


Added:
cfe/trunk/test/OpenMP/distribute_lastprivate_codegen.cpp
cfe/trunk/test/OpenMP/distribute_private_codegen.cpp
Modified:
cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp

Modified: cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp?rev=290898&r1=290897&r2=290898&view=diff
==
--- cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp Tue Jan  3 12:24:42 2017
@@ -2770,6 +2770,7 @@ void CodeGenFunction::EmitOMPDistributeL
 
   auto &RT = CGM.getOpenMPRuntime();
 
+  bool HasLastprivateClause = false;
   // Check pre-condition.
   {
 OMPLoopScope PreInitScope(*this, S);
@@ -2803,6 +2804,16 @@ void CodeGenFunction::EmitOMPDistributeL
   EmitOMPHelperVar(*this, 
cast(S.getIsLastIterVariable()));
 
   OMPPrivateScope LoopScope(*this);
+  if (EmitOMPFirstprivateClause(S, LoopScope)) {
+// Emit implicit barrier to synchronize threads and avoid data races on
+// initialization of firstprivate variables and post-update of
+// lastprivate variables.
+CGM.getOpenMPRuntime().emitBarrierCall(
+  *this, S.getLocStart(), OMPD_unknown, /*EmitChecks=*/false,
+  /*ForceSimpleCall=*/true);
+  }
+  EmitOMPPrivateClause(S, LoopScope);
+  HasLastprivateClause = EmitOMPLastprivateClauseInit(S, LoopScope);
   EmitOMPPrivateLoopCounters(S, LoopScope);
   (void)LoopScope.Privatize();
 
@@ -2859,6 +2870,13 @@ void CodeGenFunction::EmitOMPDistributeL
 LB.getAddress(), UB.getAddress(), ST.getAddress(),
 IL.getAddress(), Chunk);
   }
+
+  // Emit final copy of the lastprivate variables if IsLastIter != 0.
+  if (HasLastprivateClause)
+EmitOMPLastprivateClauseFinal(
+S, /*NoFinals=*/false,
+Builder.CreateIsNotNull(
+EmitLoadOfScalar(IL, S.getLocStart(;
 }
 
 // We're now done with the loop, so jump to the continuation block.

Added: cfe/trunk/test/OpenMP/distribute_lastprivate_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/distribute_lastprivate_codegen.cpp?rev=290898&view=auto
==
--- cfe/trunk/test/OpenMP/distribute_lastprivate_codegen.cpp (added)
+++ cfe/trunk/test/OpenMP/distribute_lastprivate_codegen.cpp Tue Jan  3 
12:24:42 2017
@@ -0,0 +1,379 @@
+// RUN: %clang_cc1 -DLAMBDA -verify -fopenmp -x c++ -std=c++11 -triple 
powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu 
-emit-llvm %s -o - | FileCheck %s --check-prefix LAMBDA --check-prefix LAMBDA-64
+// RUN: %clang_cc1 -DLAMBDA -fopenmp -x c++ -std=c++11 -triple 
powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu 
-emit-pch -o %t %s
+// RUN: %clang_cc1 -DLAMBDA -fopenmp -x c++ -triple 
powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu 
-std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s 
--check-prefix LAMBDA --check-prefix LAMBDA-64
+// RUN: %clang_cc1 -DLAMBDA -verify -fopenmp -x c++ -std=c++11 -triple 
i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -o - | 
FileCheck %s --check-prefix LAMBDA --check-prefix LAMBDA-32
+// RUN: %clang_cc1 -DLAMBDA -fopenmp -x c++ -std=c++11 -triple 
i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-pch -o %t %s
+// RUN: %clang_cc1 -DLAMBDA -fopenmp -x c++ -std=c++11 -triple 
i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -std=c++11 -include-pch 
%t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix LAMBDA 
--check-prefix LAMBDA-32
+
+// RUN: %clang_cc1  -verify -fopenmp -x c++ -std=c++11 -triple 
powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu 
-emit-llvm %s -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-64
+// RUN: %clang_cc1  -fopenmp -x c++ -st

[PATCH] D28145: [OpenMP] Basic support for a parallel directive in a target region on an NVPTX device.

2017-01-03 Thread Arpith Jacob via Phabricator via cfe-commits
arpith-jacob added inline comments.



Comment at: lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp:511-516
+// Activate workers.
+syncCTAThreads(CGF);
+
+// Barrier at end of parallel region.
+syncCTAThreads(CGF);
+

tra wrote:
> Are two back-to-back syncCTAThreads() intentional or did you mean to call 
> something else to activate workers?
Intentional.  The first wakes up worker warps to execute the parallel region.  
The second is for the master warp to wait until the region has completed 
execution.  This is to implement the semantics of an implicit barrier at the 
end of an OpenMP parallel region.


https://reviews.llvm.org/D28145



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


[PATCH] D28243: [OpenMP] Add missing regression test for pragma distribute, clause firstprivate

2017-01-03 Thread Carlo Bertolli via Phabricator via cfe-commits
carlo.bertolli created this revision.
carlo.bertolli added reviewers: ABataev, sfantao, kkwli0.
carlo.bertolli added subscribers: arpith-jacob, gtbercea, caomhin, cfe-commits.

The regression test was missing from the previous already accepted patch.


https://reviews.llvm.org/D28243

Files:
  test/OpenMP/distribute_firstprivate_codegen.cpp

Index: test/OpenMP/distribute_firstprivate_codegen.cpp
===
--- /dev/null
+++ test/OpenMP/distribute_firstprivate_codegen.cpp
@@ -0,0 +1,382 @@
+// RUN: %clang_cc1 -DLAMBDA -verify -fopenmp -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix LAMBDA --check-prefix LAMBDA-64
+// RUN: %clang_cc1 -DLAMBDA -fopenmp -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-pch -o %t %s
+// RUN: %clang_cc1 -DLAMBDA -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix LAMBDA --check-prefix LAMBDA-64
+// RUN: %clang_cc1 -DLAMBDA -verify -fopenmp -x c++ -std=c++11 -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix LAMBDA --check-prefix LAMBDA-32
+// RUN: %clang_cc1 -DLAMBDA -fopenmp -x c++ -std=c++11 -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-pch -o %t %s
+// RUN: %clang_cc1 -DLAMBDA -fopenmp -x c++ -std=c++11 -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix LAMBDA --check-prefix LAMBDA-32
+
+// RUN: %clang_cc1  -verify -fopenmp -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-64
+// RUN: %clang_cc1  -fopenmp -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-pch -o %t %s
+// RUN: %clang_cc1  -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-64
+// RUN: %clang_cc1  -verify -fopenmp -x c++ -std=c++11 -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-32
+// RUN: %clang_cc1  -fopenmp -x c++ -std=c++11 -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-pch -o %t %s
+// RUN: %clang_cc1  -fopenmp -x c++ -std=c++11 -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-32
+// expected-no-diagnostics
+#ifndef HEADER
+#define HEADER
+
+template 
+struct S {
+  T f;
+  S(T a) : f(a) {}
+  S() : f() {}
+  operator T() { return T(); }
+  ~S() {}
+};
+
+// CHECK: [[S_FLOAT_TY:%.+]] = type { float }
+// CHECK: [[S_INT_TY:%.+]] = type { i{{[0-9]+}} }
+template 
+T tmain() {
+  S test;
+  T t_var = T();
+  T vec[] = {1, 2};
+  S s_arr[] = {1, 2};
+  S &var = test;
+  #pragma omp target
+  #pragma omp teams
+#pragma omp distribute firstprivate(t_var, vec, s_arr, s_arr, var, var)
+  for (int i = 0; i < 2; ++i) {
+vec[i] = t_var;
+s_arr[i] = var;
+  }
+  return T();
+}
+
+int main() {
+  static int svar;
+  volatile double g;
+  volatile double &g1 = g;
+
+  #ifdef LAMBDA
+  // LAMBDA-LABEL: @main
+  // LAMBDA: call{{.*}} void [[OUTER_LAMBDA:@.+]](
+  [&]() {
+static float sfvar;
+// LAMBDA: define{{.*}} internal{{.*}} void [[OUTER_LAMBDA]](
+// LAMBDA: call i{{[0-9]+}} @__tgt_target_teams(
+// LAMBDA: call void [[OFFLOADING_FUN:@.+]](
+
+// LAMBDA: define{{.+}} void [[OFFLOADING_FUN]](
+// LAMBDA: call {{.*}}void {{.+}} @__kmpc_fork_teams({{.+}}, {{.+}}, {{.+}}* [[OMP_OUTLINED:@.+]] to {{.+}})
+#pragma omp target
+#pragma omp teams
+#pragma omp distribute firstprivate(g, g1, svar, sfvar)
+for (int i = 0; i < 2; ++i) {
+  // LAMBDA-64: define{{.*}} internal{{.*}} void [[OMP_OUTLINED]](i32* noalias %{{.+}}, i32* noalias %{{.+}}, i{{[0-9]+}} [[G_IN:%.+]], i{{[0-9]+}} [[G1_IN:%.+]], i{{[0-9]+}} [[SVAR_IN:%.+]], i{{[0-9]+}} [[SFVAR_IN:%.+]])
+  // LAMBDA-32: define internal{{.*}} void [[OMP_OUTLINED]](i32* noalias %{{.+}}, i32* noalias %{{.+}}, double*{{.*}} [[G_IN:%.+]], i{{[0-9]+}} [[G1_IN:%.+]], i{{[0-9]+}} [[SVAR_IN:%.+]], i{{[0-9]+}} [[SFVAR_IN:%.+]])
+  // Private alloca's for conversion
+  // LAMBDA-64: [[G_ADDR:%.+]] = alloca i{{[0-9]+}},
+  // LAMBDA-32: [[G_ADDR:%.+]] = alloca double*,
+  // LAMBDA: [[G1_ADDR:%.+]] = alloca i{{[0-9]+}},
+  // LAMBDA: [[SVAR_ADDR:%.+]] = alloca i{{[0-9]+}},
+  // LAMBDA: [[SFVAR_ADDR:%.+]] = alloca i{{[0-9]+}},
+  // LAMBDA:

[PATCH] D17840: [OPENMP] Private, firstprivate, and lastprivate clauses for distribute, host code generation

2017-01-03 Thread Carlo Bertolli via Phabricator via cfe-commits
carlo.bertolli closed this revision.
carlo.bertolli added a comment.

Commited r290898.


Repository:
  rL LLVM

https://reviews.llvm.org/D17840



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


[PATCH] D28223: clean up use of _WIN32

2017-01-03 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added a comment.

In https://reviews.llvm.org/D28223#634199, @compnerd wrote:

> I figured that using the explicit encoding is nicer since it means that its 
> more documenting.


I think @kimgr's point was that if you're using an explicit encoding, it should 
be UTF-16 rather than UCS-2 :)


Repository:
  rL LLVM

https://reviews.llvm.org/D28223



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


[PATCH] D28145: [OpenMP] Basic support for a parallel directive in a target region on an NVPTX device.

2017-01-03 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp:511-516
+// Activate workers.
+syncCTAThreads(CGF);
+
+// Barrier at end of parallel region.
+syncCTAThreads(CGF);
+

arpith-jacob wrote:
> tra wrote:
> > Are two back-to-back syncCTAThreads() intentional or did you mean to call 
> > something else to activate workers?
> Intentional.  The first wakes up worker warps to execute the parallel region. 
>  The second is for the master warp to wait until the region has completed 
> execution.  This is to implement the semantics of an implicit barrier at the 
> end of an OpenMP parallel region.
OK. It may be good to add few comments documenting these assumptions (or point 
to existing docs) here.



https://reviews.llvm.org/D28145



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


[PATCH] D27621: [clang-tidy] check to find declarations declaring more than one name

2017-01-03 Thread Firat Kasmis via Phabricator via cfe-commits
firolino added inline comments.



Comment at: clang-tidy/readability/OneNamePerDeclarationCheck.cpp:34
+  // a tag declaration (e.g. struct, class etc.):
+  // class A { } Object1, Object2;  <-- won't be matched
+  Finder->addMatcher(

aaron.ballman wrote:
> firolino wrote:
> > aaron.ballman wrote:
> > > firolino wrote:
> > > > firolino wrote:
> > > > > firolino wrote:
> > > > > > firolino wrote:
> > > > > > > aaron.ballman wrote:
> > > > > > > > firolino wrote:
> > > > > > > > > aaron.ballman wrote:
> > > > > > > > > > Why do we not want to match this?
> > > > > > > > > If we decide, whether we transform 
> > > > > > > > > ```
> > > > > > > > > class A { 
> > > > > > > > > } Object1, Object2;
> > > > > > > > > ``` 
> > > > > > > > > to
> > > > > > > > > ```
> > > > > > > > > class A { 
> > > > > > > > > } Object1, 
> > > > > > > > > Object2;
> > > > > > > > > ``` 
> > > > > > > > > or
> > > > > > > > > ```
> > > > > > > > > class A { 
> > > > > > > > > } 
> > > > > > > > > Object1, 
> > > > > > > > > Object2;
> > > > > > > > > ``` 
> > > > > > > > > I might consider adding support for it. Moreover, this kind 
> > > > > > > > > of definition is usually seen globally and I don't know how 
> > > > > > > > > to handle globals yet. See 
> > > > > > > > > http://lists.llvm.org/pipermail/cfe-dev/2015-November/046262.html
> > > > > > > > I think this should be handled. It can be handled in either of 
> > > > > > > > the forms you show, or by saying:
> > > > > > > > ```
> > > > > > > > A Object1;
> > > > > > > > A Object2;
> > > > > > > > ```
> > > > > > > > If all of these turn out to be a problem, we can still diagnose 
> > > > > > > > without providing a fixit.
> > > > > > > > 
> > > > > > > > As for globals in general, they can be handled in a separate 
> > > > > > > > patch once we figure out the declaration grouping.
> > > > > > > OK. I will try to split the object definition from the class 
> > > > > > > definition, as you have suggested. Thus, I can kick out the 
> > > > > > > tagDecl-matcher as well. If there is no easy way to do this, it 
> > > > > > > will be reported anyway but without a fixit.
> > > > > > > 
> > > > > > > Note for me: Update documentation!
> > > > > > What about
> > > > > > ```
> > > > > > struct S {
> > > > > > } S1;
> > > > > > ```
> > > > > > I would like to report this too, since two names are being declared 
> > > > > > here. `S` and `S1`. What do you think?
> > > > > ```
> > > > > struct {
> > > > > } nn1, nn2;
> > > > > ```
> > > > > Shall we ignore anonymous definitions?
> > > > To be more precise: Warn and provide a fixit for `struct S {} S1`. Only 
> > > > warn for `struct {} nn1, nn2`.
> > > > What about
> > > > 
> > > > ```
> > > > struct S {
> > > > } S1;
> > > > ```
> > > > I would like to report this too, since two names are being declared 
> > > > here. S and S1. What do you think?
> > > 
> > > I don't think that this should be diagnosed. For one, this is a 
> > > relatively common pattern (arguably more common than `struct S { } S1, 
> > > S2;`), but also, it names two very distinct entities (a type and a 
> > > variable).
> > > 
> > > > ```
> > > > struct {
> > > > } nn1, nn2;
> > > >```
> > > > Shall we ignore anonymous definitions?
> > > 
> > > Yes, we basically have to.
> > > 
> > Transforming
> > ```
> > typedef struct X { int t; } X, Y;
> > ```
> > to
> > ```
> > typedef struct X { int t; };
> > typedef X X;
> > typedef X Y;
> > ```
> > will be valid, but looks odd.
> I am on the fence about this transformation -- it does not declare new 
> objects, but instead declares new types. A very common pattern in some 
> libraries (such as the Win32 SDK) is to declare:
> ```
> typedef struct Blah {
> 
> } Blah, *PBlah, **PPBlah;
> ```
> Because of that pattern, diagnosing the above typedef is likely to be very 
> chatty in some projects, and I don't know that the fixit provides much real 
> benefit for types.
> 
> At least for the CERT DCL04-C version of this rule, that code should not be 
> flagged. Do you think any of the variations of this check should flag it?
Maybe we should reconsider where to split and where not. The original idea was 
to minimize confusion on code like
```
int* a,b;
```
whereas 
```
struct S {} *s1, s2;
```
seems not so confusing as above. However, 
```
struct S {}* s1, s2;
```
looks dangerous again.

Even following code looks unfamiliar to me.
```
typedef struct Blah {} Blah, *PBlah;
```

It really depends on the beholder. So, how about letting this check split 
**everything** and provide options for maximum flexibility? So specific 
rulesets or the user may configure it as they wish. We could add for example 
split-after-tag-def, split-tag-typedef in addition to cppcore and cert and use 
a default setting (split-after-tag-def=true, split-tag-typedef=false).


https://reviews.llvm.org/D27621



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.o

[PATCH] D20791: Support SOURCE_DATE_EPOCH environment variable

2017-01-03 Thread Ed Maste via Phabricator via cfe-commits
emaste abandoned this revision.
emaste added a comment.

Abandon in favour of https://reviews.llvm.org/D23934


https://reviews.llvm.org/D20791



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


  1   2   >