Re: [libcxx] r296561 - Fix PR32097 - is_abstract doesn't work on class templates.

2017-03-01 Thread Eric Fiselier via cfe-commits
@Hans Where are we in the release process? I would like to merge this into
4.0.

Although it's not a regression, it is a significant bug. This patch fixes
the bug by
forwarding to a compiler builtin, which is strictly better than what we
have. I'm
confident this patch is safe.

/Eric

On Tue, Feb 28, 2017 at 6:27 PM, Eric Fiselier via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: ericwf
> Date: Tue Feb 28 19:27:14 2017
> New Revision: 296561
>
> URL: http://llvm.org/viewvc/llvm-project?rev=296561&view=rev
> Log:
> Fix PR32097 - is_abstract doesn't work on class templates.
>
> This patch fixes llvm.org/PR32097 by using the __is_abstract
> builtin type-trait instead of the previous library-only implementation.
>
> All supported compilers provide this trait. I've tested as far
> back as Clang 3.2, GCC 4.6 and MSVC trunk.
>
> Modified:
> libcxx/trunk/include/type_traits
> libcxx/trunk/test/std/utilities/meta/meta.unary/
> meta.unary.prop/is_abstract.pass.cpp
>
> Modified: libcxx/trunk/include/type_traits
> URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/
> type_traits?rev=296561&r1=296560&r2=296561&view=diff
> 
> ==
> --- libcxx/trunk/include/type_traits (original)
> +++ libcxx/trunk/include/type_traits Tue Feb 28 19:27:14 2017
> @@ -1297,18 +1297,8 @@ template  using decay_t = typ
>
>  // is_abstract
>
> -namespace __is_abstract_imp
> -{
> -template  char  __test(_Tp (*)[1]);
> -template  __two __test(...);
> -}
> -
> -template ::value>
> -struct __libcpp_abstract : public integral_constant sizeof(__is_abstract_imp::__test<_Tp>(0)) != 1> {};
> -
> -template  struct __libcpp_abstract<_Tp, false> : public
> false_type {};
> -
> -template  struct _LIBCPP_TEMPLATE_VIS is_abstract : public
> __libcpp_abstract<_Tp> {};
> +template  struct _LIBCPP_TEMPLATE_VIS is_abstract
> +: public integral_constant {};
>
>  #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
>  template  _LIBCPP_CONSTEXPR bool is_abstract_v
>
> Modified: libcxx/trunk/test/std/utilities/meta/meta.unary/
> meta.unary.prop/is_abstract.pass.cpp
> URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/
> utilities/meta/meta.unary/meta.unary.prop/is_abstract.
> pass.cpp?rev=296561&r1=296560&r2=296561&view=diff
> 
> ==
> --- libcxx/trunk/test/std/utilities/meta/meta.unary/
> meta.unary.prop/is_abstract.pass.cpp (original)
> +++ libcxx/trunk/test/std/utilities/meta/meta.unary/
> meta.unary.prop/is_abstract.pass.cpp Tue Feb 28 19:27:14 2017
> @@ -65,6 +65,14 @@ class Abstract
>  virtual ~Abstract() = 0;
>  };
>
> +template 
> +struct AbstractTemplate {
> +  virtual void test() = 0;
> +};
> +
> +template <>
> +struct AbstractTemplate {};
> +
>  int main()
>  {
>  test_is_not_abstract();
> @@ -81,4 +89,6 @@ int main()
>  test_is_not_abstract();
>
>  test_is_abstract();
> +test_is_abstract >();
> +test_is_not_abstract >();
>  }
>
>
> ___
> 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] D30489: [analyzer] catch out of bounds for VLA

2017-03-01 Thread Daniel Marjamäki via Phabricator via cfe-commits
danielmarjamaki created this revision.

This is a work in progress patch. I try to detect such error:

  void foo(int X) {
  int Buf[X];
  Buf[X] = 0;
  }

The patch successfully detects this bug. However it writes FP when you try to 
take the address.

I would like to know if you think my approach to add a checkPreStmt is good. I 
would need to add logic to handle *(Buf+X) also.

This checker doesn't really logically belong in the ArrayBounds checker but 
from a user perspective it seems to belong there. I can move it to a new 
checker if that sounds best.


Repository:
  rL LLVM

https://reviews.llvm.org/D30489

Files:
  lib/StaticAnalyzer/Checkers/ArrayBoundChecker.cpp


Index: lib/StaticAnalyzer/Checkers/ArrayBoundChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/ArrayBoundChecker.cpp
+++ lib/StaticAnalyzer/Checkers/ArrayBoundChecker.cpp
@@ -24,17 +24,20 @@
 
 namespace {
 class ArrayBoundChecker :
-public Checker {
+public Checker> {
   mutable std::unique_ptr BT;
+  mutable std::unique_ptr BT_VLA;
 
 public:
   void checkLocation(SVal l, bool isLoad, const Stmt* S,
  CheckerContext &C) const;
+  void checkPreStmt(const ArraySubscriptExpr *A, CheckerContext &C) const;
 };
 }
 
 void ArrayBoundChecker::checkLocation(SVal l, bool isLoad, const Stmt* LoadS,
   CheckerContext &C) const {
+
   // Check for out of bound array element access.
   const MemRegion *R = l.getAsRegion();
   if (!R)
@@ -88,6 +91,39 @@
   C.addTransition(StInBound);
 }
 
+void ArrayBoundChecker::checkPreStmt(const ArraySubscriptExpr *A, 
CheckerContext &C) const
+{
+  const Expr *Base = A->getBase()->IgnoreImpCasts();
+
+  ASTContext &Ctx = C.getASTContext();
+  const VariableArrayType *VLA = Ctx.getAsVariableArrayType(Base->getType());
+  if (!VLA)
+return;
+
+  ProgramStateRef State = C.getState();
+  SVal sizeV = State->getSVal(VLA->getSizeExpr(), C.getLocationContext());
+  SVal idxV = State->getSVal(A->getIdx(), C.getLocationContext());
+
+  // Is idx greater than size?
+  SValBuilder &Bldr = C.getSValBuilder();
+  SVal GE = Bldr.evalBinOp(State, BO_GE, idxV, sizeV, Bldr.getConditionType());
+  if (!GE.isConstant(1))
+return;
+
+  ExplodedNode *N = C.generateErrorNode(State);
+  if (!N)
+return;
+
+  if (!BT_VLA)
+BT_VLA.reset(new BuiltinBug(
+  this, "Out-of-bound VLA access",
+  "Out-of-bounds VLA access (symbolically this index is greater than the 
size)"));
+  // Generate a report for this bug.
+  auto report = llvm::make_unique(*BT_VLA, 
BT_VLA->getDescription(), N);
+  report->addRange(A->getSourceRange());
+  C.emitReport(std::move(report));
+}
+
 void ento::registerArrayBoundChecker(CheckerManager &mgr) {
   mgr.registerChecker();
 }


Index: lib/StaticAnalyzer/Checkers/ArrayBoundChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/ArrayBoundChecker.cpp
+++ lib/StaticAnalyzer/Checkers/ArrayBoundChecker.cpp
@@ -24,17 +24,20 @@
 
 namespace {
 class ArrayBoundChecker :
-public Checker {
+public Checker> {
   mutable std::unique_ptr BT;
+  mutable std::unique_ptr BT_VLA;
 
 public:
   void checkLocation(SVal l, bool isLoad, const Stmt* S,
  CheckerContext &C) const;
+  void checkPreStmt(const ArraySubscriptExpr *A, CheckerContext &C) const;
 };
 }
 
 void ArrayBoundChecker::checkLocation(SVal l, bool isLoad, const Stmt* LoadS,
   CheckerContext &C) const {
+
   // Check for out of bound array element access.
   const MemRegion *R = l.getAsRegion();
   if (!R)
@@ -88,6 +91,39 @@
   C.addTransition(StInBound);
 }
 
+void ArrayBoundChecker::checkPreStmt(const ArraySubscriptExpr *A, CheckerContext &C) const
+{
+  const Expr *Base = A->getBase()->IgnoreImpCasts();
+
+  ASTContext &Ctx = C.getASTContext();
+  const VariableArrayType *VLA = Ctx.getAsVariableArrayType(Base->getType());
+  if (!VLA)
+return;
+
+  ProgramStateRef State = C.getState();
+  SVal sizeV = State->getSVal(VLA->getSizeExpr(), C.getLocationContext());
+  SVal idxV = State->getSVal(A->getIdx(), C.getLocationContext());
+
+  // Is idx greater than size?
+  SValBuilder &Bldr = C.getSValBuilder();
+  SVal GE = Bldr.evalBinOp(State, BO_GE, idxV, sizeV, Bldr.getConditionType());
+  if (!GE.isConstant(1))
+return;
+
+  ExplodedNode *N = C.generateErrorNode(State);
+  if (!N)
+return;
+
+  if (!BT_VLA)
+BT_VLA.reset(new BuiltinBug(
+  this, "Out-of-bound VLA access",
+  "Out-of-bounds VLA access (symbolically this index is greater than the size)"));
+  // Generate a report for this bug.
+  auto report = llvm::make_unique(*BT_VLA, BT_VLA->getDescription(), N);
+  report->addRange(A->getSourceRange());
+  C.emitReport(std::move(report));
+}
+
 void ento::registerArrayBoundChecker(CheckerManager &mgr) {
   mgr.registerChecker();
 }
_

[PATCH] D30157: [analyzer] Improve valist check

2017-03-01 Thread Daniel Marjamäki via Phabricator via cfe-commits
danielmarjamaki added a comment.

I am running this checker right now on various projects. Here are currently 
seen results.. https://drive.google.com/open?id=0BykPmWrCOxt2STZMOXZ5OGlwM3c

Feel free to look at it and see if there are FPs or TPs.


https://reviews.llvm.org/D30157



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


[PATCH] D30490: [change-namespace] get insertion points of forward declarations correct.

2017-03-01 Thread Eric Liu via Phabricator via cfe-commits
ioeric created this revision.

Previously, the insertion points would conflict with the old namespace
deletion.


https://reviews.llvm.org/D30490

Files:
  change-namespace/ChangeNamespace.cpp
  unittests/change-namespace/ChangeNamespaceTests.cpp


Index: unittests/change-namespace/ChangeNamespaceTests.cpp
===
--- unittests/change-namespace/ChangeNamespaceTests.cpp
+++ unittests/change-namespace/ChangeNamespaceTests.cpp
@@ -351,11 +351,13 @@
 TEST_F(ChangeNamespaceTest, LeaveForwardDeclarationBehind) {
   std::string Code = "namespace na {\n"
  "namespace nb {\n"
+ "\n"
  "class FWD;\n"
  "class FWD2;\n"
  "class A {\n"
  "  FWD *fwd;\n"
  "};\n"
+ "\n"
  "} // namespace nb\n"
  "} // namespace na\n";
   std::string Expected = "namespace na {\n"
@@ -370,6 +372,7 @@
  "class A {\n"
  "  ::na::nb::FWD *fwd;\n"
  "};\n"
+ "\n"
  "} // namespace y\n"
  "} // namespace x\n";
   EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
Index: change-namespace/ChangeNamespace.cpp
===
--- change-namespace/ChangeNamespace.cpp
+++ change-namespace/ChangeNamespace.cpp
@@ -697,8 +697,10 @@
   const auto *NsDecl = Result.Nodes.getNodeAs("ns_decl");
   // The namespace contains the forward declaration, so it must not be empty.
   assert(!NsDecl->decls_empty());
-  const auto Insertion = createInsertion(NsDecl->decls_begin()->getLocStart(),
- Code, *Result.SourceManager);
+  const auto Insertion =
+  createInsertion(getLocAfterNamespaceLBrace(NsDecl, *Result.SourceManager,
+ 
Result.Context->getLangOpts()),
+  Code, *Result.SourceManager);
   InsertForwardDeclaration InsertFwd;
   InsertFwd.InsertionOffset = Insertion.getOffset();
   InsertFwd.ForwardDeclText = Insertion.getReplacementText().str();


Index: unittests/change-namespace/ChangeNamespaceTests.cpp
===
--- unittests/change-namespace/ChangeNamespaceTests.cpp
+++ unittests/change-namespace/ChangeNamespaceTests.cpp
@@ -351,11 +351,13 @@
 TEST_F(ChangeNamespaceTest, LeaveForwardDeclarationBehind) {
   std::string Code = "namespace na {\n"
  "namespace nb {\n"
+ "\n"
  "class FWD;\n"
  "class FWD2;\n"
  "class A {\n"
  "  FWD *fwd;\n"
  "};\n"
+ "\n"
  "} // namespace nb\n"
  "} // namespace na\n";
   std::string Expected = "namespace na {\n"
@@ -370,6 +372,7 @@
  "class A {\n"
  "  ::na::nb::FWD *fwd;\n"
  "};\n"
+ "\n"
  "} // namespace y\n"
  "} // namespace x\n";
   EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
Index: change-namespace/ChangeNamespace.cpp
===
--- change-namespace/ChangeNamespace.cpp
+++ change-namespace/ChangeNamespace.cpp
@@ -697,8 +697,10 @@
   const auto *NsDecl = Result.Nodes.getNodeAs("ns_decl");
   // The namespace contains the forward declaration, so it must not be empty.
   assert(!NsDecl->decls_empty());
-  const auto Insertion = createInsertion(NsDecl->decls_begin()->getLocStart(),
- Code, *Result.SourceManager);
+  const auto Insertion =
+  createInsertion(getLocAfterNamespaceLBrace(NsDecl, *Result.SourceManager,
+ Result.Context->getLangOpts()),
+  Code, *Result.SourceManager);
   InsertForwardDeclaration InsertFwd;
   InsertFwd.InsertionOffset = Insertion.getOffset();
   InsertFwd.ForwardDeclText = Insertion.getReplacementText().str();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D30490: [change-namespace] get insertion points of forward declarations correct.

2017-03-01 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: unittests/change-namespace/ChangeNamespaceTests.cpp:354
  "namespace nb {\n"
+ "\n"
  "class FWD;\n"

I'd create a new test for the fix instead of modifying the current one.


https://reviews.llvm.org/D30490



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


[PATCH] D30490: [change-namespace] get insertion points of forward declarations correct.

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

- Create a new test case. And slight refactor.


https://reviews.llvm.org/D30490

Files:
  change-namespace/ChangeNamespace.cpp
  unittests/change-namespace/ChangeNamespaceTests.cpp


Index: unittests/change-namespace/ChangeNamespaceTests.cpp
===
--- unittests/change-namespace/ChangeNamespaceTests.cpp
+++ unittests/change-namespace/ChangeNamespaceTests.cpp
@@ -375,6 +375,36 @@
   EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
 }
 
+TEST_F(ChangeNamespaceTest, InsertForwardDeclsProperly) {
+  std::string Code = "namespace na {\n"
+ "namespace nb {\n"
+ "\n"
+ "class FWD;\n"
+ "class FWD2;\n"
+ "class A {\n"
+ "  FWD *fwd;\n"
+ "};\n"
+ "\n"
+ "} // namespace nb\n"
+ "} // namespace na\n";
+  std::string Expected = "namespace na {\n"
+ "namespace nb {\n"
+ "class FWD;\n"
+ "class FWD2;\n"
+ "} // namespace nb\n"
+ "} // namespace na\n"
+ "namespace x {\n"
+ "namespace y {\n"
+ "\n"
+ "class A {\n"
+ "  ::na::nb::FWD *fwd;\n"
+ "};\n"
+ "\n"
+ "} // namespace y\n"
+ "} // namespace x\n";
+  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
 TEST_F(ChangeNamespaceTest, TemplateClassForwardDeclaration) {
   std::string Code = "namespace na {\n"
  "namespace nb {\n"
Index: change-namespace/ChangeNamespace.cpp
===
--- change-namespace/ChangeNamespace.cpp
+++ change-namespace/ChangeNamespace.cpp
@@ -676,29 +676,29 @@
 const NamedDecl *FwdDecl) {
   SourceLocation Start = FwdDecl->getLocStart();
   SourceLocation End = FwdDecl->getLocEnd();
+  const SourceManager &SM = *Result.SourceManager;
   SourceLocation AfterSemi = Lexer::findLocationAfterToken(
-  End, tok::semi, *Result.SourceManager, Result.Context->getLangOpts(),
+  End, tok::semi, SM, Result.Context->getLangOpts(),
   /*SkipTrailingWhitespaceAndNewLine=*/true);
   if (AfterSemi.isValid())
 End = AfterSemi.getLocWithOffset(-1);
   // Delete the forward declaration from the code to be moved.
-  addReplacementOrDie(Start, End, "", *Result.SourceManager,
-  &FileToReplacements);
+  addReplacementOrDie(Start, End, "", SM, &FileToReplacements);
   llvm::StringRef Code = Lexer::getSourceText(
-  CharSourceRange::getTokenRange(
-  Result.SourceManager->getSpellingLoc(Start),
-  Result.SourceManager->getSpellingLoc(End)),
-  *Result.SourceManager, Result.Context->getLangOpts());
+  CharSourceRange::getTokenRange(SM.getSpellingLoc(Start),
+ SM.getSpellingLoc(End)),
+  SM, Result.Context->getLangOpts());
   // Insert the forward declaration back into the old namespace after moving 
the
   // code from old namespace to new namespace.
   // Insertion information is stored in `InsertFwdDecls` and actual
   // insertion will be performed in `onEndOfTranslationUnit`.
   // Get the (old) namespace that contains the forward declaration.
   const auto *NsDecl = Result.Nodes.getNodeAs("ns_decl");
   // The namespace contains the forward declaration, so it must not be empty.
   assert(!NsDecl->decls_empty());
-  const auto Insertion = createInsertion(NsDecl->decls_begin()->getLocStart(),
- Code, *Result.SourceManager);
+  const auto Insertion = createInsertion(
+  getLocAfterNamespaceLBrace(NsDecl, SM, Result.Context->getLangOpts()),
+  Code, SM);
   InsertForwardDeclaration InsertFwd;
   InsertFwd.InsertionOffset = Insertion.getOffset();
   InsertFwd.ForwardDeclText = Insertion.getReplacementText().str();


Index: unittests/change-namespace/ChangeNamespaceTests.cpp
===
--- unittests/change-namespace/ChangeNamespaceTests.cpp
+++ unittests/change-namespace/ChangeNamespaceTests.cpp
@@ -375,6 +375,36 @@
   EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
 }
 
+TEST_F(ChangeNamespaceTest, InsertForwardDeclsProperly) {
+  std::string Code = "namespace na {\n"
+ "namespace nb {\n"
+ "\n"
+ "class FWD;\n"
+ "class FWD2;\n"
+ "class A {\n"
+ "  FWD *fwd;\n"
+ "};\n"
+ "\n"
+ "} // namespace nb\n"
+ 

[clang-tools-extra] r296598 - [clang-tidy] Fix handling of methods with try-statement as a body in modernize-use-override

2017-03-01 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Wed Mar  1 04:16:36 2017
New Revision: 296598

URL: http://llvm.org/viewvc/llvm-project?rev=296598&view=rev
Log:
[clang-tidy] Fix handling of methods with try-statement as a body in 
modernize-use-override

Summary:
Fix generated by modernize-use-override caused syntax error when method
used try-statement as a body. `override` keyword was inserted after last
declaration token which happened to be a `try` keyword.

This fixes PR27119.

Reviewers: ehsan, djasper, alexfh

Reviewed By: alexfh

Subscribers: JDevlieghere, cfe-commits

Tags: #clang-tools-extra

Patch by Paweł Żukowski!

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

Modified:
clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-use-override.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.cpp?rev=296598&r1=296597&r2=296598&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.cpp Wed Mar  
1 04:16:36 2017
@@ -147,14 +147,13 @@ void UseOverrideCheck::check(const Match
   // end of the declaration of the function, but prefer to put it on the
   // same line as the declaration if the beginning brace for the start of
   // the body falls on the next line.
-  Token LastNonCommentToken;
-  for (Token T : Tokens) {
-if (!T.is(tok::comment)) {
-  LastNonCommentToken = T;
-}
-  }
-  InsertLoc = LastNonCommentToken.getEndLoc();
   ReplacementText = " override";
+  auto LastTokenIter = std::prev(Tokens.end());
+  // When try statement is used instead of compound statement as
+  // method body - insert override keyword before it.
+  if (LastTokenIter->is(tok::kw_try))
+LastTokenIter = std::prev(LastTokenIter);
+  InsertLoc = LastTokenIter->getEndLoc();
 }
 
 if (!InsertLoc.isValid()) {

Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-use-override.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-use-override.cpp?rev=296598&r1=296597&r2=296598&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/modernize-use-override.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-use-override.cpp Wed Mar  
1 04:16:36 2017
@@ -288,3 +288,17 @@ struct MembersOfSpecializations : public
 };
 template <> void MembersOfSpecializations<3>::a() {}
 void ff() { MembersOfSpecializations<3>().a(); };
+
+// In case try statement is used as a method body,
+// make sure that override fix is placed before try keyword.
+struct TryStmtAsBody : public Base {
+  void a() try
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: annotate this
+  // CHECK-FIXES: {{^}}  void a() override try
+  { b(); } catch(...) { c(); }
+
+  virtual void d() try
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using
+  // CHECK-FIXES: {{^}}  void d() override try
+  { e(); } catch(...) { f(); }
+};


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


[PATCH] D30002: [clang-tidy] Fix handling of methods with try-statement as a body in modernize-use-override

2017-03-01 Thread Alexander Kornienko via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL296598: [clang-tidy] Fix handling of methods with 
try-statement as a body in modernize… (authored by alexfh).

Changed prior to commit:
  https://reviews.llvm.org/D30002?vs=88582&id=90136#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D30002

Files:
  clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.cpp
  clang-tools-extra/trunk/test/clang-tidy/modernize-use-override.cpp


Index: clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.cpp
@@ -147,14 +147,13 @@
   // end of the declaration of the function, but prefer to put it on the
   // same line as the declaration if the beginning brace for the start of
   // the body falls on the next line.
-  Token LastNonCommentToken;
-  for (Token T : Tokens) {
-if (!T.is(tok::comment)) {
-  LastNonCommentToken = T;
-}
-  }
-  InsertLoc = LastNonCommentToken.getEndLoc();
   ReplacementText = " override";
+  auto LastTokenIter = std::prev(Tokens.end());
+  // When try statement is used instead of compound statement as
+  // method body - insert override keyword before it.
+  if (LastTokenIter->is(tok::kw_try))
+LastTokenIter = std::prev(LastTokenIter);
+  InsertLoc = LastTokenIter->getEndLoc();
 }
 
 if (!InsertLoc.isValid()) {
Index: clang-tools-extra/trunk/test/clang-tidy/modernize-use-override.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/modernize-use-override.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-use-override.cpp
@@ -288,3 +288,17 @@
 };
 template <> void MembersOfSpecializations<3>::a() {}
 void ff() { MembersOfSpecializations<3>().a(); };
+
+// In case try statement is used as a method body,
+// make sure that override fix is placed before try keyword.
+struct TryStmtAsBody : public Base {
+  void a() try
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: annotate this
+  // CHECK-FIXES: {{^}}  void a() override try
+  { b(); } catch(...) { c(); }
+
+  virtual void d() try
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using
+  // CHECK-FIXES: {{^}}  void d() override try
+  { e(); } catch(...) { f(); }
+};


Index: clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.cpp
@@ -147,14 +147,13 @@
   // end of the declaration of the function, but prefer to put it on the
   // same line as the declaration if the beginning brace for the start of
   // the body falls on the next line.
-  Token LastNonCommentToken;
-  for (Token T : Tokens) {
-if (!T.is(tok::comment)) {
-  LastNonCommentToken = T;
-}
-  }
-  InsertLoc = LastNonCommentToken.getEndLoc();
   ReplacementText = " override";
+  auto LastTokenIter = std::prev(Tokens.end());
+  // When try statement is used instead of compound statement as
+  // method body - insert override keyword before it.
+  if (LastTokenIter->is(tok::kw_try))
+LastTokenIter = std::prev(LastTokenIter);
+  InsertLoc = LastTokenIter->getEndLoc();
 }
 
 if (!InsertLoc.isValid()) {
Index: clang-tools-extra/trunk/test/clang-tidy/modernize-use-override.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/modernize-use-override.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-use-override.cpp
@@ -288,3 +288,17 @@
 };
 template <> void MembersOfSpecializations<3>::a() {}
 void ff() { MembersOfSpecializations<3>().a(); };
+
+// In case try statement is used as a method body,
+// make sure that override fix is placed before try keyword.
+struct TryStmtAsBody : public Base {
+  void a() try
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: annotate this
+  // CHECK-FIXES: {{^}}  void a() override try
+  { b(); } catch(...) { c(); }
+
+  virtual void d() try
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using
+  // CHECK-FIXES: {{^}}  void d() override try
+  { e(); } catch(...) { f(); }
+};
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r296599 - [clang-tidy] Add parametercount for readibility-function-size

2017-03-01 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Wed Mar  1 04:17:32 2017
New Revision: 296599

URL: http://llvm.org/viewvc/llvm-project?rev=296599&view=rev
Log:
[clang-tidy] Add parametercount for readibility-function-size

Summary:
Add an option to function-size to warn about high parameter counts.

This might be relevant for cppcoreguidelines and the safety module as well. 
Since the safety module is not landed in master already, i did not create an 
alias, but that can be done later as well.

Reviewers: sbenza, alexfh, hokein

Reviewed By: alexfh, hokein

Subscribers: JDevlieghere

Patch by Jonas Toth!

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

Modified:
clang-tools-extra/trunk/clang-tidy/readability/FunctionSizeCheck.cpp
clang-tools-extra/trunk/clang-tidy/readability/FunctionSizeCheck.h
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/readability-function-size.rst
clang-tools-extra/trunk/test/clang-tidy/readability-function-size.cpp

Modified: clang-tools-extra/trunk/clang-tidy/readability/FunctionSizeCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/FunctionSizeCheck.cpp?rev=296599&r1=296598&r2=296599&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/readability/FunctionSizeCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/readability/FunctionSizeCheck.cpp Wed 
Mar  1 04:17:32 2017
@@ -72,12 +72,14 @@ FunctionSizeCheck::FunctionSizeCheck(Str
 : ClangTidyCheck(Name, Context),
   LineThreshold(Options.get("LineThreshold", -1U)),
   StatementThreshold(Options.get("StatementThreshold", 800U)),
-  BranchThreshold(Options.get("BranchThreshold", -1U)) {}
+  BranchThreshold(Options.get("BranchThreshold", -1U)),
+  ParameterThreshold(Options.get("ParameterThreshold", 6)) {}
 
 void FunctionSizeCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "LineThreshold", LineThreshold);
   Options.store(Opts, "StatementThreshold", StatementThreshold);
   Options.store(Opts, "BranchThreshold", BranchThreshold);
+  Options.store(Opts, "ParameterThreshold", ParameterThreshold);
 }
 
 void FunctionSizeCheck::registerMatchers(MatchFinder *Finder) {
@@ -103,8 +105,11 @@ void FunctionSizeCheck::check(const Matc
 }
   }
 
+  unsigned ActualNumberParameters = Func->getNumParams();
+
   if (FI.Lines > LineThreshold || FI.Statements > StatementThreshold ||
-  FI.Branches > BranchThreshold) {
+  FI.Branches > BranchThreshold ||
+  ActualNumberParameters > ParameterThreshold) {
 diag(Func->getLocation(),
  "function %0 exceeds recommended size/complexity thresholds")
 << Func;
@@ -127,6 +132,12 @@ void FunctionSizeCheck::check(const Matc
 diag(Func->getLocation(), "%0 branches (threshold %1)", 
DiagnosticIDs::Note)
 << FI.Branches << BranchThreshold;
   }
+
+  if (ActualNumberParameters > ParameterThreshold) {
+diag(Func->getLocation(), "%0 parameters (threshold %1)",
+ DiagnosticIDs::Note)
+<< ActualNumberParameters << ParameterThreshold;
+  }
 }
 
 } // namespace readability

Modified: clang-tools-extra/trunk/clang-tidy/readability/FunctionSizeCheck.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/FunctionSizeCheck.h?rev=296599&r1=296598&r2=296599&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/readability/FunctionSizeCheck.h 
(original)
+++ clang-tools-extra/trunk/clang-tidy/readability/FunctionSizeCheck.h Wed Mar  
1 04:17:32 2017
@@ -27,6 +27,8 @@ namespace readability {
 /// macro-heavy code. The default is `800`.
 ///   * `BranchThreshold` - flag functions exceeding this number of control
 /// statements. The default is `-1` (ignore the number of branches).
+///   * `ParameterThreshold` - flag functions having a high number of 
parameters.
+/// The default is `6`.
 class FunctionSizeCheck : public ClangTidyCheck {
 public:
   FunctionSizeCheck(StringRef Name, ClangTidyContext *Context);
@@ -39,6 +41,7 @@ private:
   const unsigned LineThreshold;
   const unsigned StatementThreshold;
   const unsigned BranchThreshold;
+  const unsigned ParameterThreshold;
 };
 
 } // namespace readability

Modified: clang-tools-extra/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/ReleaseNotes.rst?rev=296599&r1=296598&r2=296599&view=diff
==
--- clang-tools-extra/trunk/docs/ReleaseNotes.rst (original)
+++ clang-tools-extra/trunk/docs/ReleaseNotes.rst Wed Mar  1 04:17:32 2017
@@ -67,6 +67,10 @@ Improvements to clang-tidy
 
   Finds misleading indentation where braces should be introduced or the code 
should be reformatted.
 
+- Added `ParameterThreshold` to `readability-function-size`.

[PATCH] D16183: Added CheckName field to YAML report

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

This patch is superseded by https://reviews.llvm.org/D26137.


https://reviews.llvm.org/D16183



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


r296602 - [Sema] Improve side effect checking for unused-lambda-capture warning

2017-03-01 Thread Malcolm Parsons via cfe-commits
Author: malcolm.parsons
Date: Wed Mar  1 04:23:38 2017
New Revision: 296602

URL: http://llvm.org/viewvc/llvm-project?rev=296602&view=rev
Log:
[Sema] Improve side effect checking for unused-lambda-capture warning

Summary:
Don't warn about unused lambda captures that involve copying a
value of a type that cannot be trivially copied and destroyed.

Fixes PR31977

Reviewers: rsmith, aaron.ballman

Subscribers: cfe-commits

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

Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaLambda.cpp
cfe/trunk/test/SemaCXX/warn-unused-lambda-capture.cpp

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=296602&r1=296601&r2=296602&view=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Wed Mar  1 04:23:38 2017
@@ -5340,6 +5340,9 @@ public:
   ExprResult ActOnLambdaExpr(SourceLocation StartLoc, Stmt *Body,
  Scope *CurScope);
 
+  /// \brief Does copying/destroying the captured variable have side effects?
+  bool CaptureHasSideEffects(const sema::LambdaScopeInfo::Capture &From);
+
   /// \brief Diagnose if an explicit lambda capture is unused.
   void DiagnoseUnusedLambdaCapture(const sema::LambdaScopeInfo::Capture &From);
 

Modified: cfe/trunk/lib/Sema/SemaLambda.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLambda.cpp?rev=296602&r1=296601&r2=296602&view=diff
==
--- cfe/trunk/lib/Sema/SemaLambda.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLambda.cpp Wed Mar  1 04:23:38 2017
@@ -1438,13 +1438,35 @@ mapImplicitCaptureStyle(CapturingScopeIn
   llvm_unreachable("Unknown implicit capture style");
 }
 
-void Sema::DiagnoseUnusedLambdaCapture(const LambdaScopeInfo::Capture &From) {
+bool Sema::CaptureHasSideEffects(const LambdaScopeInfo::Capture &From) {
   if (!From.isVLATypeCapture()) {
 Expr *Init = From.getInitExpr();
 if (Init && Init->HasSideEffects(Context))
-  return;
+  return true;
   }
 
+  if (!From.isCopyCapture())
+return false;
+
+  const QualType T = From.isThisCapture()
+ ? getCurrentThisType()->getPointeeType()
+ : From.getCaptureType();
+
+  if (T.isVolatileQualified())
+return true;
+
+  const Type *BaseT = T->getBaseElementTypeUnsafe();
+  if (const CXXRecordDecl *RD = BaseT->getAsCXXRecordDecl())
+return !RD->isCompleteDefinition() || !RD->hasTrivialCopyConstructor() ||
+   !RD->hasTrivialDestructor();
+
+  return false;
+}
+
+void Sema::DiagnoseUnusedLambdaCapture(const LambdaScopeInfo::Capture &From) {
+  if (CaptureHasSideEffects(From))
+return;
+
   auto diag = Diag(From.getLocation(), diag::warn_unused_lambda_capture);
   if (From.isThisCapture())
 diag << "'this'";

Modified: cfe/trunk/test/SemaCXX/warn-unused-lambda-capture.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-unused-lambda-capture.cpp?rev=296602&r1=296601&r2=296602&view=diff
==
--- cfe/trunk/test/SemaCXX/warn-unused-lambda-capture.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-unused-lambda-capture.cpp Wed Mar  1 04:23:38 
2017
@@ -1,10 +1,16 @@
-// RUN: %clang_cc1 -fsyntax-only -Wunused-lambda-capture 
-Wused-but-marked-unused -Wno-uninitialized -verify -std=c++14 %s
+// RUN: %clang_cc1 -fsyntax-only -Wunused-lambda-capture 
-Wused-but-marked-unused -Wno-uninitialized -verify -std=c++1z %s
 
 class NonTrivialConstructor {
 public:
   NonTrivialConstructor() {}
 };
 
+class NonTrivialCopyConstructor {
+public:
+  NonTrivialCopyConstructor() = default;
+  NonTrivialCopyConstructor(const NonTrivialCopyConstructor &) {}
+};
+
 class NonTrivialDestructor {
 public:
   ~NonTrivialDestructor() {}
@@ -57,14 +63,67 @@ void test() {
 auto explicit_by_value_used = [i] { return i + 1; };
 auto explicit_by_value_unused = [i] {}; // expected-warning{{lambda 
capture 'i' is not used}}
   };
+
+  Trivial trivial;
+  auto explicit_by_value_trivial = [trivial] {}; // expected-warning{{lambda 
capture 'trivial' is not used}}
+
+  NonTrivialConstructor cons;
+  auto explicit_by_value_non_trivial_constructor = [cons] {}; // 
expected-warning{{lambda capture 'cons' is not used}}
+
+  NonTrivialCopyConstructor copy_cons;
+  auto explicit_by_value_non_trivial_copy_constructor = [copy_cons] {};
+
+  NonTrivialDestructor dest;
+  auto explicit_by_value_non_trivial_destructor = [dest] {};
+
+  volatile int v;
+  auto explicit_by_value_volatile = [v] {};
 }
 
-class Foo
-{
+class TrivialThis : Trivial {
   void test() {
 auto explicit_this_used = [this] { return i; };
 auto explicit_this_used_void = [this] { (void)this; };
 auto explicit_this_unused = [

[PATCH] D30327: [Sema] Improve side effect checking for unused-lambda-capture warning

2017-03-01 Thread Malcolm Parsons via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL296602: [Sema] Improve side effect checking for 
unused-lambda-capture warning (authored by malcolm.parsons).

Changed prior to commit:
  https://reviews.llvm.org/D30327?vs=89988&id=90139#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D30327

Files:
  cfe/trunk/include/clang/Sema/Sema.h
  cfe/trunk/lib/Sema/SemaLambda.cpp
  cfe/trunk/test/SemaCXX/warn-unused-lambda-capture.cpp

Index: cfe/trunk/include/clang/Sema/Sema.h
===
--- cfe/trunk/include/clang/Sema/Sema.h
+++ cfe/trunk/include/clang/Sema/Sema.h
@@ -5340,6 +5340,9 @@
   ExprResult ActOnLambdaExpr(SourceLocation StartLoc, Stmt *Body,
  Scope *CurScope);
 
+  /// \brief Does copying/destroying the captured variable have side effects?
+  bool CaptureHasSideEffects(const sema::LambdaScopeInfo::Capture &From);
+
   /// \brief Diagnose if an explicit lambda capture is unused.
   void DiagnoseUnusedLambdaCapture(const sema::LambdaScopeInfo::Capture &From);
 
Index: cfe/trunk/test/SemaCXX/warn-unused-lambda-capture.cpp
===
--- cfe/trunk/test/SemaCXX/warn-unused-lambda-capture.cpp
+++ cfe/trunk/test/SemaCXX/warn-unused-lambda-capture.cpp
@@ -1,10 +1,16 @@
-// RUN: %clang_cc1 -fsyntax-only -Wunused-lambda-capture -Wused-but-marked-unused -Wno-uninitialized -verify -std=c++14 %s
+// RUN: %clang_cc1 -fsyntax-only -Wunused-lambda-capture -Wused-but-marked-unused -Wno-uninitialized -verify -std=c++1z %s
 
 class NonTrivialConstructor {
 public:
   NonTrivialConstructor() {}
 };
 
+class NonTrivialCopyConstructor {
+public:
+  NonTrivialCopyConstructor() = default;
+  NonTrivialCopyConstructor(const NonTrivialCopyConstructor &) {}
+};
+
 class NonTrivialDestructor {
 public:
   ~NonTrivialDestructor() {}
@@ -57,14 +63,67 @@
 auto explicit_by_value_used = [i] { return i + 1; };
 auto explicit_by_value_unused = [i] {}; // expected-warning{{lambda capture 'i' is not used}}
   };
+
+  Trivial trivial;
+  auto explicit_by_value_trivial = [trivial] {}; // expected-warning{{lambda capture 'trivial' is not used}}
+
+  NonTrivialConstructor cons;
+  auto explicit_by_value_non_trivial_constructor = [cons] {}; // expected-warning{{lambda capture 'cons' is not used}}
+
+  NonTrivialCopyConstructor copy_cons;
+  auto explicit_by_value_non_trivial_copy_constructor = [copy_cons] {};
+
+  NonTrivialDestructor dest;
+  auto explicit_by_value_non_trivial_destructor = [dest] {};
+
+  volatile int v;
+  auto explicit_by_value_volatile = [v] {};
 }
 
-class Foo
-{
+class TrivialThis : Trivial {
   void test() {
 auto explicit_this_used = [this] { return i; };
 auto explicit_this_used_void = [this] { (void)this; };
 auto explicit_this_unused = [this] {}; // expected-warning{{lambda capture 'this' is not used}}
+auto explicit_star_this_used = [*this] { return i; };
+auto explicit_star_this_used_void = [*this] { (void)this; };
+auto explicit_star_this_unused = [*this] {}; // expected-warning{{lambda capture 'this' is not used}}
+  }
+  int i;
+};
+
+class NonTrivialConstructorThis : NonTrivialConstructor {
+  void test() {
+auto explicit_this_used = [this] { return i; };
+auto explicit_this_used_void = [this] { (void)this; };
+auto explicit_this_unused = [this] {}; // expected-warning{{lambda capture 'this' is not used}}
+auto explicit_star_this_used = [*this] { return i; };
+auto explicit_star_this_used_void = [*this] { (void)this; };
+auto explicit_star_this_unused = [*this] {}; // expected-warning{{lambda capture 'this' is not used}}
+  }
+  int i;
+};
+
+class NonTrivialCopyConstructorThis : NonTrivialCopyConstructor {
+  void test() {
+auto explicit_this_used = [this] { return i; };
+auto explicit_this_used_void = [this] { (void)this; };
+auto explicit_this_unused = [this] {}; // expected-warning{{lambda capture 'this' is not used}}
+auto explicit_star_this_used = [*this] { return i; };
+auto explicit_star_this_used_void = [*this] { (void)this; };
+auto explicit_star_this_unused = [*this] {};
+  }
+  int i;
+};
+
+class NonTrivialDestructorThis : NonTrivialDestructor {
+  void test() {
+auto explicit_this_used = [this] { return i; };
+auto explicit_this_used_void = [this] { (void)this; };
+auto explicit_this_unused = [this] {}; // expected-warning{{lambda capture 'this' is not used}}
+auto explicit_star_this_used = [*this] { return i; };
+auto explicit_star_this_used_void = [*this] { (void)this; };
+auto explicit_star_this_unused = [*this] {};
   }
   int i;
 };
@@ -107,6 +166,21 @@
 auto explicit_by_value_used = [i] { return i + 1; };
 auto explicit_by_value_unused = [i] {}; // expected-warning{{lambda capture 'i' is not used}}
   };
+
+  Trivial trivial;
+  auto explicit_by_value_trivial = [trivial] {}; // expected-warni

[PATCH] D30034: [clang-tidy] Fix a false positive for explicit template instantiations in misc-unused-using-decls.

2017-03-01 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.

I think, we decided to extend the AST instead of working around its 
incompleteness.


https://reviews.llvm.org/D30034



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


[PATCH] D30490: [change-namespace] get insertion points of forward declarations correct.

2017-03-01 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

LGTM.


https://reviews.llvm.org/D30490



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


[PATCH] D30490: [change-namespace] get insertion points of forward declarations correct.

2017-03-01 Thread Eric Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL296604: [change-namespace] get insertion points of forward 
declarations correct. (authored by ioeric).

Changed prior to commit:
  https://reviews.llvm.org/D30490?vs=90135&id=90141#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D30490

Files:
  clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
  clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp


Index: clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
===
--- clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
+++ clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
@@ -676,29 +676,29 @@
 const NamedDecl *FwdDecl) {
   SourceLocation Start = FwdDecl->getLocStart();
   SourceLocation End = FwdDecl->getLocEnd();
+  const SourceManager &SM = *Result.SourceManager;
   SourceLocation AfterSemi = Lexer::findLocationAfterToken(
-  End, tok::semi, *Result.SourceManager, Result.Context->getLangOpts(),
+  End, tok::semi, SM, Result.Context->getLangOpts(),
   /*SkipTrailingWhitespaceAndNewLine=*/true);
   if (AfterSemi.isValid())
 End = AfterSemi.getLocWithOffset(-1);
   // Delete the forward declaration from the code to be moved.
-  addReplacementOrDie(Start, End, "", *Result.SourceManager,
-  &FileToReplacements);
+  addReplacementOrDie(Start, End, "", SM, &FileToReplacements);
   llvm::StringRef Code = Lexer::getSourceText(
-  CharSourceRange::getTokenRange(
-  Result.SourceManager->getSpellingLoc(Start),
-  Result.SourceManager->getSpellingLoc(End)),
-  *Result.SourceManager, Result.Context->getLangOpts());
+  CharSourceRange::getTokenRange(SM.getSpellingLoc(Start),
+ SM.getSpellingLoc(End)),
+  SM, Result.Context->getLangOpts());
   // Insert the forward declaration back into the old namespace after moving 
the
   // code from old namespace to new namespace.
   // Insertion information is stored in `InsertFwdDecls` and actual
   // insertion will be performed in `onEndOfTranslationUnit`.
   // Get the (old) namespace that contains the forward declaration.
   const auto *NsDecl = Result.Nodes.getNodeAs("ns_decl");
   // The namespace contains the forward declaration, so it must not be empty.
   assert(!NsDecl->decls_empty());
-  const auto Insertion = createInsertion(NsDecl->decls_begin()->getLocStart(),
- Code, *Result.SourceManager);
+  const auto Insertion = createInsertion(
+  getLocAfterNamespaceLBrace(NsDecl, SM, Result.Context->getLangOpts()),
+  Code, SM);
   InsertForwardDeclaration InsertFwd;
   InsertFwd.InsertionOffset = Insertion.getOffset();
   InsertFwd.ForwardDeclText = Insertion.getReplacementText().str();
Index: 
clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp
===
--- clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp
+++ clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp
@@ -375,6 +375,36 @@
   EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
 }
 
+TEST_F(ChangeNamespaceTest, InsertForwardDeclsProperly) {
+  std::string Code = "namespace na {\n"
+ "namespace nb {\n"
+ "\n"
+ "class FWD;\n"
+ "class FWD2;\n"
+ "class A {\n"
+ "  FWD *fwd;\n"
+ "};\n"
+ "\n"
+ "} // namespace nb\n"
+ "} // namespace na\n";
+  std::string Expected = "namespace na {\n"
+ "namespace nb {\n"
+ "class FWD;\n"
+ "class FWD2;\n"
+ "} // namespace nb\n"
+ "} // namespace na\n"
+ "namespace x {\n"
+ "namespace y {\n"
+ "\n"
+ "class A {\n"
+ "  ::na::nb::FWD *fwd;\n"
+ "};\n"
+ "\n"
+ "} // namespace y\n"
+ "} // namespace x\n";
+  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
 TEST_F(ChangeNamespaceTest, TemplateClassForwardDeclaration) {
   std::string Code = "namespace na {\n"
  "namespace nb {\n"


Index: clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
===
--- clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
+++ clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
@@ -676,29 +676,29 @@
 const NamedDecl *FwdDecl) {
   SourceLocation Start = FwdDecl->getLocStart();
   SourceLo

[clang-tools-extra] r296604 - [change-namespace] get insertion points of forward declarations correct.

2017-03-01 Thread Eric Liu via cfe-commits
Author: ioeric
Date: Wed Mar  1 04:29:39 2017
New Revision: 296604

URL: http://llvm.org/viewvc/llvm-project?rev=296604&view=rev
Log:
[change-namespace] get insertion points of forward declarations correct.

Summary:
Previously, the insertion points would conflict with the old namespace
deletion.

Reviewers: hokein

Reviewed By: hokein

Subscribers: cfe-commits

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

Modified:
clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp

Modified: clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp?rev=296604&r1=296603&r2=296604&view=diff
==
--- clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp (original)
+++ clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp Wed Mar  1 
04:29:39 2017
@@ -676,19 +676,18 @@ void ChangeNamespaceTool::moveClassForwa
 const NamedDecl *FwdDecl) {
   SourceLocation Start = FwdDecl->getLocStart();
   SourceLocation End = FwdDecl->getLocEnd();
+  const SourceManager &SM = *Result.SourceManager;
   SourceLocation AfterSemi = Lexer::findLocationAfterToken(
-  End, tok::semi, *Result.SourceManager, Result.Context->getLangOpts(),
+  End, tok::semi, SM, Result.Context->getLangOpts(),
   /*SkipTrailingWhitespaceAndNewLine=*/true);
   if (AfterSemi.isValid())
 End = AfterSemi.getLocWithOffset(-1);
   // Delete the forward declaration from the code to be moved.
-  addReplacementOrDie(Start, End, "", *Result.SourceManager,
-  &FileToReplacements);
+  addReplacementOrDie(Start, End, "", SM, &FileToReplacements);
   llvm::StringRef Code = Lexer::getSourceText(
-  CharSourceRange::getTokenRange(
-  Result.SourceManager->getSpellingLoc(Start),
-  Result.SourceManager->getSpellingLoc(End)),
-  *Result.SourceManager, Result.Context->getLangOpts());
+  CharSourceRange::getTokenRange(SM.getSpellingLoc(Start),
+ SM.getSpellingLoc(End)),
+  SM, Result.Context->getLangOpts());
   // Insert the forward declaration back into the old namespace after moving 
the
   // code from old namespace to new namespace.
   // Insertion information is stored in `InsertFwdDecls` and actual
@@ -697,8 +696,9 @@ void ChangeNamespaceTool::moveClassForwa
   const auto *NsDecl = Result.Nodes.getNodeAs("ns_decl");
   // The namespace contains the forward declaration, so it must not be empty.
   assert(!NsDecl->decls_empty());
-  const auto Insertion = createInsertion(NsDecl->decls_begin()->getLocStart(),
- Code, *Result.SourceManager);
+  const auto Insertion = createInsertion(
+  getLocAfterNamespaceLBrace(NsDecl, SM, Result.Context->getLangOpts()),
+  Code, SM);
   InsertForwardDeclaration InsertFwd;
   InsertFwd.InsertionOffset = Insertion.getOffset();
   InsertFwd.ForwardDeclText = Insertion.getReplacementText().str();

Modified: 
clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp?rev=296604&r1=296603&r2=296604&view=diff
==
--- clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp 
(original)
+++ clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp 
Wed Mar  1 04:29:39 2017
@@ -375,6 +375,36 @@ TEST_F(ChangeNamespaceTest, LeaveForward
   EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
 }
 
+TEST_F(ChangeNamespaceTest, InsertForwardDeclsProperly) {
+  std::string Code = "namespace na {\n"
+ "namespace nb {\n"
+ "\n"
+ "class FWD;\n"
+ "class FWD2;\n"
+ "class A {\n"
+ "  FWD *fwd;\n"
+ "};\n"
+ "\n"
+ "} // namespace nb\n"
+ "} // namespace na\n";
+  std::string Expected = "namespace na {\n"
+ "namespace nb {\n"
+ "class FWD;\n"
+ "class FWD2;\n"
+ "} // namespace nb\n"
+ "} // namespace na\n"
+ "namespace x {\n"
+ "namespace y {\n"
+ "\n"
+ "class A {\n"
+ "  ::na::nb::FWD *fwd;\n"
+ "};\n"
+ "\n"
+ "} // namespace y\n"
+ "} // namespace x\n";
+  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
 TEST_F(ChangeNamespa

[PATCH] D24933: Enable configuration files in clang

2017-03-01 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff added a comment.

Glad to know that someone is interested in this feature!
Below is actual proposal.

**Adding named configuration files to clang driver**

A configuration file is a collection of driver options, which are inserted into 
command line before other options specified in the clang invocation. It groups 
related options together and allows specifying them in simpler, more flexible 
and less error prone way than just listing the options somewhere in build 
scripts. Configuration file may be thought as a "macro" that names an option 
set and is expanded when the driver is called.  This feature must be helpful 
when a user need to specify many options, cross compilation is likely to be 
such case.

Configuration file can be specified by either of two methods:

- by command line option `--config `, or
- by using special executable file names, such as `armv7l-clang`.

If the option `--config` is used, its argument is treated as a path to 
configuration file if it contains a directory separator, otherwise the file is 
searched for in the set of directories described below. If option `--config` is 
absent and clang executable has name in the form `armv7l-clang`, driver will 
search for file `armv7l.cfg` in the same set of directories. Similar encoding 
is already used by clang to specify target.

The set of directories where configuration files are searched for consists of 
at most three directories, checked in this order:

- user directory (like `~/.llvm`),
- system directory (like `/etc/llvm`),
- the directory where clang executable resides.

User and system directories are optional, they are reserved for distribution or 
SDK suppliers. By default they are absent, corresponding directories can be 
specified by cmake arguments `CLANG_CONFIG_FILE_SYSTEM_DIR` and 
`CLANG_CONFIG_FILE_USER_DIR`. The first found file is used.

Format of configuration file is similar to file used in the construct `@file`, 
it is a set of options. Configuration file have advantage over this construct:

- it is searched for in well-known places rather than in current directory,
- it may contain comments, long options may be split between lines using 
trailing backslashes,
- other files may be included by `@file` and they will be resolved relative to 
the including file,
- the file may be encoded in executable name,
- unused options from configuration file do not produce warnings.


https://reviews.llvm.org/D24933



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


r296605 - clang-format: Ignore contents of #ifdef SWIG .. #endif blocks.

2017-03-01 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Wed Mar  1 04:47:52 2017
New Revision: 296605

URL: http://llvm.org/viewvc/llvm-project?rev=296605&view=rev
Log:
clang-format: Ignore contents of #ifdef SWIG .. #endif blocks.

Those blocks are used if C++ code is SWIG-wrapped (see swig.org) and
usually do not contain C++ code. Also cleanup the implementation of for #if 0
and #if false a bit.

Modified:
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/unittests/Format/FormatTestComments.cpp

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=296605&r1=296604&r2=296605&view=diff
==
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Wed Mar  1 04:47:52 2017
@@ -590,12 +590,12 @@ void UnwrappedLineParser::conditionalCom
 
 void UnwrappedLineParser::parsePPIf(bool IfDef) {
   nextToken();
-  bool IsLiteralFalse = (FormatTok->Tok.isLiteral() &&
- FormatTok->Tok.getLiteralData() != nullptr &&
- StringRef(FormatTok->Tok.getLiteralData(),
-   FormatTok->Tok.getLength()) == "0") ||
-FormatTok->Tok.is(tok::kw_false);
-  conditionalCompilationStart(!IfDef && IsLiteralFalse);
+  bool Unreachable = false;
+  if (!IfDef && (FormatTok->is(tok::kw_false) || FormatTok->TokenText == "0"))
+Unreachable = true;
+  if (IfDef && FormatTok->TokenText == "SWIG")
+Unreachable = true;
+  conditionalCompilationStart(Unreachable);
   parsePPUnknown();
 }
 

Modified: cfe/trunk/unittests/Format/FormatTestComments.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestComments.cpp?rev=296605&r1=296604&r2=296605&view=diff
==
--- cfe/trunk/unittests/Format/FormatTestComments.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestComments.cpp Wed Mar  1 04:47:52 2017
@@ -1683,6 +1683,14 @@ TEST_F(FormatTestComments, IgnoresIf0Con
"void f(  ) {  }\n"
"#endif\n"
"void g(  ) {  }\n"));
+  EXPECT_EQ("#ifdef SWIG\n"
+"}{)(&*(^%%#%@! fsadj f;ldjs ,:;| <<<>>>][)(][\n"
+"#endif\n"
+"void f() {}",
+format("#ifdef SWIG\n"
+   "}{)(&*(^%%#%@! fsadj f;ldjs ,:;| <<<>>>][)(][\n"
+   "#endif\n"
+   "void f(  ) {  }"));
   EXPECT_EQ("enum E {\n"
 "  One,\n"
 "  Two,\n"


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


[PATCH] D30405: [clang-format] Add a new flag FixNamespaceEndComments to FormatStyle

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



Comment at: include/clang/Format/Format.h:354
+  /// fixes invalid existing ones.
+  bool FixNamespaceEndComments;
+

To be consistent with the clang-tidy check, just call this 
"FixNamespaceComments".

After a change like this, you need to call docs/tools/dump_format_style.py in 
order to update the documentation.



Comment at: lib/Format/Format.cpp:1837
 
+  if (Style.Language == FormatStyle::LK_Cpp &&
+  Style.FixNamespaceEndComments) {

So much code copied and pasted. Could you pull out a method or lambda and call 
this with either the JavaScriptRequoter or the NamespaceEndCommentsFixer?

Also, at some point, we'll probably want to call several of these fixers in 
series. But we can leave that problem for another day.


https://reviews.llvm.org/D30405



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


r296608 - Fix r296605 so that stuff in #ifndef SWIG blocks is still formatted.

2017-03-01 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Wed Mar  1 05:10:11 2017
New Revision: 296608

URL: http://llvm.org/viewvc/llvm-project?rev=296608&view=rev
Log:
Fix r296605 so that stuff in #ifndef SWIG blocks is still formatted.

Modified:
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/unittests/Format/FormatTestComments.cpp

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=296608&r1=296607&r2=296608&view=diff
==
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Wed Mar  1 05:10:11 2017
@@ -589,11 +589,12 @@ void UnwrappedLineParser::conditionalCom
 }
 
 void UnwrappedLineParser::parsePPIf(bool IfDef) {
+  bool IfNDef = FormatTok->is(tok::pp_ifndef);
   nextToken();
   bool Unreachable = false;
   if (!IfDef && (FormatTok->is(tok::kw_false) || FormatTok->TokenText == "0"))
 Unreachable = true;
-  if (IfDef && FormatTok->TokenText == "SWIG")
+  if (IfDef && !IfNDef && FormatTok->TokenText == "SWIG")
 Unreachable = true;
   conditionalCompilationStart(Unreachable);
   parsePPUnknown();

Modified: cfe/trunk/unittests/Format/FormatTestComments.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestComments.cpp?rev=296608&r1=296607&r2=296608&view=diff
==
--- cfe/trunk/unittests/Format/FormatTestComments.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestComments.cpp Wed Mar  1 05:10:11 2017
@@ -1683,14 +1683,6 @@ TEST_F(FormatTestComments, IgnoresIf0Con
"void f(  ) {  }\n"
"#endif\n"
"void g(  ) {  }\n"));
-  EXPECT_EQ("#ifdef SWIG\n"
-"}{)(&*(^%%#%@! fsadj f;ldjs ,:;| <<<>>>][)(][\n"
-"#endif\n"
-"void f() {}",
-format("#ifdef SWIG\n"
-   "}{)(&*(^%%#%@! fsadj f;ldjs ,:;| <<<>>>][)(][\n"
-   "#endif\n"
-   "void f(  ) {  }"));
   EXPECT_EQ("enum E {\n"
 "  One,\n"
 "  Two,\n"
@@ -1809,6 +1801,22 @@ TEST_F(FormatTestComments, IgnoresIf0Con
"#endif\n"
"Five\n"
"};"));
+
+  // Ignore stuff in SWIG-blocks.
+  EXPECT_EQ("#ifdef SWIG\n"
+"}{)(&*(^%%#%@! fsadj f;ldjs ,:;| <<<>>>][)(][\n"
+"#endif\n"
+"void f() {}",
+format("#ifdef SWIG\n"
+   "}{)(&*(^%%#%@! fsadj f;ldjs ,:;| <<<>>>][)(][\n"
+   "#endif\n"
+   "void f(  ) {  }"));
+  EXPECT_EQ("#ifndef SWIG\n"
+"void f() {}\n"
+"#endif",
+format("#ifndef SWIG\n"
+   "void f(  ) {   }\n"
+   "#endif"));
 }
 
 TEST_F(FormatTestComments, DontCrashOnBlockComments) {


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


[PATCH] D30158: [clang-tidy] modernize: Find usage of random_shuffle and replace it with shuffle.

2017-03-01 Thread Mads Ravn via Phabricator via cfe-commits
madsravn updated this revision to Diff 90148.
madsravn added a comment.

Updated patch according to comments by Ballman.


https://reviews.llvm.org/D30158

Files:
  clang-tidy/modernize/CMakeLists.txt
  clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp
  clang-tidy/modernize/ReplaceRandomShuffleCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/modernize-replace-random-shuffle.rst
  test/clang-tidy/modernize-replace-random-shuffle.cpp

Index: test/clang-tidy/modernize-replace-random-shuffle.cpp
===
--- test/clang-tidy/modernize-replace-random-shuffle.cpp
+++ test/clang-tidy/modernize-replace-random-shuffle.cpp
@@ -0,0 +1,58 @@
+// RUN: %check_clang_tidy %s modernize-replace-random-shuffle %t -- -- -std=c++11
+
+//CHECK-FIXES: #include 
+
+namespace std {
+template  struct vec_iterator {
+  T *ptr;
+  vec_iterator operator++(int);
+};
+
+template  struct vector {
+  typedef vec_iterator iterator;
+
+  iterator begin();
+  iterator end();
+};
+
+template 
+void random_shuffle(FwIt begin, FwIt end);
+
+template 
+void random_shuffle(FwIt begin, FwIt end, randomFunc& randomfunc);
+
+template 
+void shuffle(FwIt begin, FwIt end);
+} // namespace std
+
+// Random Func
+int myrandom (int i) { return i;}
+
+using namespace std;
+
+int main() {
+  std::vector vec;
+
+  std::random_shuffle(vec.begin(), vec.end());
+  // CHECK-MESSAGE: [[@LINE-1]]:3: warning: 'std::random_shuffle' has been removed in C++17; use 'std::shuffle' instead
+  // CHECK-FIXES: std::shuffle(vec.begin(), vec.end(), std::mt19937(std::random_device()()));
+
+
+  std::shuffle(vec.begin(), vec.end());
+
+  random_shuffle(vec.begin(), vec.end());
+  // CHECK-MESSAGE: [[@LINE-1]]:3: warning: 'std::random_shuffle' has been removed in C++17; use 'std::shuffle' instead
+  // CHECK-FIXES: shuffle(vec.begin(), vec.end(), std::mt19937(std::random_device()()));
+  
+  std::random_shuffle(vec.begin(), vec.end(), myrandom);
+  // CHECK-MESSAGE: [[@LINE-1]]:3: warning: 'std::random_shuffle' has been removed in C++17; use 'std::shuffle' and an alternative random mechanism instead
+  // CHECK-FIXES: std::shuffle(vec.begin(), vec.end(), std::mt19937(std::random_device()()));
+
+  random_shuffle(vec.begin(), vec.end(), myrandom);
+  // CHECK-MESSAGE: [[@LINE-1]]:3: warning: 'std::random_shuffle' has been removed in C++17; use 'std::shuffle' and an alternative random mechanism instead
+  // CHECK-FIXES: shuffle(vec.begin(), vec.end(), std::mt19937(std::random_device()()));
+
+  shuffle(vec.begin(), vec.end());
+
+  return 0;
+}
Index: docs/clang-tidy/checks/modernize-replace-random-shuffle.rst
===
--- docs/clang-tidy/checks/modernize-replace-random-shuffle.rst
+++ docs/clang-tidy/checks/modernize-replace-random-shuffle.rst
@@ -0,0 +1,28 @@
+.. title:: clang-tidy - modernize-replace-random-shuffle
+
+modernize-replace-random-shuffle
+
+
+This check will find occurrences of ``std::random_shuffle`` and replace it with ``std::shuffle``. In C++17 ``std::random_shuffle`` will no longer be available and thus we need to replace it.
+
+Below are two examples of what kind of occurrences will be found and two examples of what it will be replaced with.
+
+.. code-block:: c++
+
+  std::vector v;
+
+  // First example
+  std::random_shuffle(vec.begin(), vec.end());
+
+  // Second example
+  std::random_shuffle(vec.begin(), vec.end(), randomFun);
+
+Both of these examples will be replaced with:
+
+.. code-block:: c++
+
+  std::shuffle(vec.begin(), vec.end(), std::mt19937(std::random_device()()));
+
+The second example will also receive a warning that ``randomFunc`` is no longer supported in the same way as before so if the user wants the same functionality, the user will need to change the implementation of the ``randomFunc``.
+
+One thing to be aware of here is that ``std::random_device`` is quite expensive to initialize. So if you are using the code in a performance critical place, you probably want to initialize it elsewhere. 
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -110,6 +110,7 @@
modernize-raw-string-literal
modernize-redundant-void-arg
modernize-replace-auto-ptr
+   modernize-replace-random-shuffle
modernize-return-braced-init-list
modernize-shrink-to-fit
modernize-use-auto
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -72,6 +72,11 @@
 
   Finds uses of inline assembler.
 
+- New `modernize-replace-random-shuffle
+  `_ check
+
+  Finds and fixes usage of ``std::random_shuffle`` 

[PATCH] D30459: [libcxxabi] Clean up macro usage

2017-03-01 Thread Ranjeet Singh via Phabricator via cfe-commits
rs updated this revision to Diff 90150.
rs added a comment.

Thanks for reviewing. Before I commit could you tell me if I need to update any 
build systems e.g. buildbots ?


https://reviews.llvm.org/D30459

Files:
  CMakeLists.txt
  include/__cxxabi_config.h
  include/cxxabi.h
  src/abort_message.cpp
  src/config.h
  src/cxa_default_handlers.cpp
  src/cxa_exception.cpp
  src/cxa_exception.hpp
  src/cxa_personality.cpp

Index: src/cxa_personality.cpp
===
--- src/cxa_personality.cpp
+++ src/cxa_personality.cpp
@@ -317,7 +317,7 @@
 std::terminate();
 }
 
-#if _LIBCXXABI_ARM_EHABI
+#if defined(_LIBCXXABI_ARM_EHABI)
 static const void* read_target2_value(const void* ptr)
 {
 uintptr_t offset = *reinterpret_cast(ptr);
@@ -328,7 +328,7 @@
 // deferred to the linker. For bare-metal they turn into absolute
 // relocations. For linux they turn into GOT-REL relocations."
 // https://gcc.gnu.org/ml/gcc-patches/2009-08/msg00264.html
-#if LIBCXXABI_BAREMETAL
+#if defined(LIBCXXABI_BAREMETAL)
 return reinterpret_cast(reinterpret_cast(ptr) +
  offset);
 #else
@@ -358,7 +358,7 @@
 return reinterpret_cast(
 read_target2_value(ttypePtr));
 }
-#else // !_LIBCXXABI_ARM_EHABI
+#else // !defined(_LIBCXXABI_ARM_EHABI)
 static
 const __shim_type_info*
 get_shim_type_info(uint64_t ttypeIndex, const uint8_t* classInfo,
@@ -394,7 +394,7 @@
 classInfo -= ttypeIndex;
 return (const __shim_type_info*)readEncodedPointer(&classInfo, ttypeEncoding);
 }
-#endif // !_LIBCXXABI_ARM_EHABI
+#endif // !defined(_LIBCXXABI_ARM_EHABI)
 
 /*
 This is checking a thrown exception type, excpType, against a possibly empty
@@ -405,7 +405,7 @@
 the list will catch a excpType.  If any catchType in the list can catch an
 excpType, then this exception spec does not catch the excpType.
 */
-#if _LIBCXXABI_ARM_EHABI
+#if defined(_LIBCXXABI_ARM_EHABI)
 static
 bool
 exception_spec_can_catch(int64_t specIndex, const uint8_t* classInfo,
@@ -934,7 +934,7 @@
 Else a cleanup is not found: return _URC_CONTINUE_UNWIND
 */
 
-#if !_LIBCXXABI_ARM_EHABI
+#if !defined(_LIBCXXABI_ARM_EHABI)
 _LIBCXXABI_FUNC_VIS _Unwind_Reason_Code
 #ifdef __USING_SJLJ_EXCEPTIONS__
 __gxx_personality_sj0
@@ -1194,7 +1194,7 @@
 u_handler = old_exception_header->unexpectedHandler;
 // If std::__unexpected(u_handler) rethrows the same exception,
 //   these values get overwritten by the rethrow.  So save them now:
-#if _LIBCXXABI_ARM_EHABI
+#if defined(_LIBCXXABI_ARM_EHABI)
 ttypeIndex = (int64_t)(int32_t)unwind_exception->barrier_cache.bitpattern[4];
 lsda = (const uint8_t*)unwind_exception->barrier_cache.bitpattern[2];
 #else
Index: src/cxa_exception.hpp
===
--- src/cxa_exception.hpp
+++ src/cxa_exception.hpp
@@ -25,7 +25,7 @@
 static const uint64_t get_vendor_and_language = 0xFF00; // mask for CLNGC++
 
 struct _LIBCXXABI_HIDDEN __cxa_exception {
-#if defined(__LP64__) || _LIBCXXABI_ARM_EHABI
+#if defined(__LP64__) || defined(_LIBCXXABI_ARM_EHABI)
 // This is a new field to support C++ 0x exception_ptr.
 // For binary compatibility it is at the start of this
 // struct which is prepended to the object thrown in
@@ -43,7 +43,7 @@
 
 int handlerCount;
 
-#if _LIBCXXABI_ARM_EHABI
+#if defined(_LIBCXXABI_ARM_EHABI)
 __cxa_exception* nextPropagatingException;
 int propagationCount;
 #else
@@ -54,7 +54,7 @@
 void *adjustedPtr;
 #endif
 
-#if !defined(__LP64__) && !_LIBCXXABI_ARM_EHABI
+#if !defined(__LP64__) && !defined(_LIBCXXABI_ARM_EHABI)
 // This is a new field to support C++ 0x exception_ptr.
 // For binary compatibility it is placed where the compiler
 // previously adding padded to 64-bit align unwindHeader.
@@ -68,7 +68,7 @@
 // The layout of this structure MUST match the layout of __cxa_exception, with
 // primaryException instead of referenceCount.
 struct _LIBCXXABI_HIDDEN __cxa_dependent_exception {
-#if defined(__LP64__) || _LIBCXXABI_ARM_EHABI
+#if defined(__LP64__) || defined(_LIBCXXABI_ARM_EHABI)
 void* primaryException;
 #endif
 
@@ -81,7 +81,7 @@
 
 int handlerCount;
 
-#if _LIBCXXABI_ARM_EHABI
+#if defined(_LIBCXXABI_ARM_EHABI)
 __cxa_exception* nextPropagatingException;
 int propagationCount;
 #else
@@ -92,7 +92,7 @@
 void *adjustedPtr;
 #endif
 
-#if !defined(__LP64__) && !_LIBCXXABI_ARM_EHABI
+#if !defined(__LP64__) && !defined(_LIBCXXABI_ARM_EHABI)
 void* primaryException;
 #endif
 
@@ -102,7 +102,7 @@
 struct _LIBCXXABI_HIDDEN __cxa_eh_globals {
 __cxa_exception *   caughtExceptions;
 unsigned intuncaughtExceptions;
-#if _LIBCXXABI_ARM_EHABI
+#if defined(_LIBCXXABI_ARM_EHABI)
 __cxa_exception* propagatingExceptions;
 #endif
 };
Index: src/cxa_exception.cpp
===

[PATCH] D30158: [clang-tidy] modernize: Find usage of random_shuffle and replace it with shuffle.

2017-03-01 Thread Mads Ravn via Phabricator via cfe-commits
madsravn marked 9 inline comments as done.
madsravn added inline comments.



Comment at: clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp:77
+
+  auto Diag = [=]() {
+std::string Message = ReplaceMessage;

aaron.ballman wrote:
> Is there a reason this needs to capture everything by copy? Also, no need for 
> the empty parens. Actually, is the lambda even necessary at all?
Is it OK to capture by reference then? Or how do we want it in llvm? 

We need the lambda, because first I need to create the diag with a message 
based on the count of arguments and then I need to find fixits based on the 
same count. Example: 


```
string message = "Message for 2 arguments";
if(argumentCount == 3) {
  message = "Message for 3 arguments";
}
auto Diag = diag(startLoc(), message);
if(argumentCount == 3) {
  Diag << FixitHint::FixForThreeArguments();
} else {
  Diag << FixitHint::FixForTwoArguments();
}
```

So the idea with the lambda is to avoid doing the same if-statement twice. 


https://reviews.llvm.org/D30158



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


[PATCH] D30459: [libcxxabi] Clean up macro usage

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

In https://reviews.llvm.org/D30459#689461, @rs wrote:

> Thanks for reviewing. Before I commit could you tell me if I need to update 
> any build systems e.g. buildbots ?


Those two options are not used by any of the current public builders, so I 
think it's safe to commit.

If something breaks, we can revert and have a look :)


https://reviews.llvm.org/D30459



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


[PATCH] D30493: [change-namespace] avoid adding leading '::' when possible.

2017-03-01 Thread Eric Liu via Phabricator via cfe-commits
ioeric created this revision.

When changing namespaces, the tool adds leading "::" to references that need to
be fully-qualified, which would affect readability.

We avoid adding "::" when the symbol name does not conflict with the new
namespace name. For example, a symbol name "na::nb::X" conflicts with "ns::na"
since it would be resolved to "ns::na::nb::X" in the new namespace.


https://reviews.llvm.org/D30493

Files:
  change-namespace/ChangeNamespace.cpp
  unittests/change-namespace/ChangeNamespaceTests.cpp

Index: unittests/change-namespace/ChangeNamespaceTests.cpp
===
--- unittests/change-namespace/ChangeNamespaceTests.cpp
+++ unittests/change-namespace/ChangeNamespaceTests.cpp
@@ -242,7 +242,7 @@
  "} // namespace na\n"
  "namespace x {\n"
  "namespace y {\n"
- "class X { ::na::A a; z::Z zz; T t; };\n"
+ "class X { na::A a; z::Z zz; T t; };\n"
  "} // namespace y\n"
  "} // namespace x\n";
   EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
@@ -296,8 +296,8 @@
  "namespace y {\n"
  "class C_X {\n"
  "public:\n"
- "  ::na::C_A a;\n"
- "  ::na::nc::C_C c;\n"
+ "  na::C_A a;\n"
+ "  na::nc::C_C c;\n"
  "};\n"
  "class C_Y {\n"
  "  C_X x;\n"
@@ -339,9 +339,9 @@
  "namespace x {\n"
  "namespace y {\n"
  "void f() {\n"
- "  ::na::B<::na::A> b;\n"
- "  ::na::B<::na::nc::C> b_c;\n"
- "  ::na::Two<::na::A, ::na::nc::C> two;\n"
+ "  na::B b;\n"
+ "  na::B b_c;\n"
+ "  na::Two two;\n"
  "}\n"
  "} // namespace y\n"
  "} // namespace x\n";
@@ -368,7 +368,7 @@
  "namespace y {\n"
  "\n"
  "class A {\n"
- "  ::na::nb::FWD *fwd;\n"
+ "  na::nb::FWD *fwd;\n"
  "};\n"
  "} // namespace y\n"
  "} // namespace x\n";
@@ -397,7 +397,7 @@
  "namespace y {\n"
  "\n"
  "class A {\n"
- "  ::na::nb::FWD *fwd;\n"
+ "  na::nb::FWD *fwd;\n"
  "};\n"
  "\n"
  "} // namespace y\n"
@@ -426,7 +426,7 @@
  "namespace y {\n"
  "\n"
  "class A {\n"
- "  ::na::nb::FWD *fwd;\n"
+ "  na::nb::FWD *fwd;\n"
  "};\n"
  "template class TEMP {};\n"
  "} // namespace y\n"
@@ -481,8 +481,8 @@
  "namespace x {\n"
  "namespace y {\n"
  "void fwd();\n"
- "void f(::na::C_A ca, ::na::nc::C_C cc) {\n"
- "  ::na::C_A ca_1 = ca;\n"
+ "void f(na::C_A ca, na::nc::C_C cc) {\n"
+ "  na::C_A ca_1 = ca;\n"
  "}\n"
  "} // namespace y\n"
  "} // namespace x\n";
@@ -521,9 +521,9 @@
  "namespace x {\n"
  "namespace y {\n"
  "using ::na::nc::SAME;\n"
- "using YO = ::na::nd::SAME;\n"
- "typedef ::na::nd::SAME IDENTICAL;\n"
- "void f(::na::nd::SAME Same) {}\n"
+ "using YO = na::nd::SAME;\n"
+ "typedef na::nd::SAME IDENTICAL;\n"
+ "void f(na::nd::SAME Same) {}\n"
  "} // namespace y\n"
  "} // namespace x\n";
   EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
@@ -549,9 +549,9 @@
  "} // namespace na\n"
  "namespace x {\n"
  "namespace y {\n"
- "class D : public ::na::Base {\n"
+ "class D : public na::Base {\n"
  "public:\n"
- "  using AA = ::na::A; using B = ::na::Base;\n"
+ "  using AA = na::A; using B = na::Base;\n"
  "  

[libcxxabi] r296612 - [libcxxabi] Clean up macro usage.

2017-03-01 Thread Ranjeet Singh via cfe-commits
Author: rsingh
Date: Wed Mar  1 05:42:01 2017
New Revision: 296612

URL: http://llvm.org/viewvc/llvm-project?rev=296612&view=rev
Log:
[libcxxabi] Clean up macro usage.

Convention in libcxxabi is to use !defined(FOO) not !FOO.

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


Modified:
libcxxabi/trunk/CMakeLists.txt
libcxxabi/trunk/include/__cxxabi_config.h
libcxxabi/trunk/include/cxxabi.h
libcxxabi/trunk/src/abort_message.cpp
libcxxabi/trunk/src/config.h
libcxxabi/trunk/src/cxa_default_handlers.cpp
libcxxabi/trunk/src/cxa_exception.cpp
libcxxabi/trunk/src/cxa_exception.hpp
libcxxabi/trunk/src/cxa_personality.cpp

Modified: libcxxabi/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/CMakeLists.txt?rev=296612&r1=296611&r2=296612&view=diff
==
--- libcxxabi/trunk/CMakeLists.txt (original)
+++ libcxxabi/trunk/CMakeLists.txt Wed Mar  1 05:42:01 2017
@@ -157,6 +157,11 @@ set(LIBCXXABI_LIBCXX_LIBRARY_PATH "" CAC
 option(LIBCXXABI_ENABLE_SHARED "Build libc++abi as a shared library." ON)
 option(LIBCXXABI_ENABLE_STATIC "Build libc++abi as a static library." ON)
 
+option(LIBCXXABI_BAREMETAL "Build libc++abi for baremetal targets." OFF)
+# The default terminate handler attempts to demangle uncaught exceptions, which
+# causes extra I/O and demangling code to be pulled in.
+option(LIBCXXABI_SILENT_TERMINATE "Set this to make the terminate handler 
default to a silent alternative" OFF)
+
 if (NOT LIBCXXABI_ENABLE_SHARED AND NOT LIBCXXABI_ENABLE_STATIC)
   message(FATAL_ERROR "libc++abi must be built as either a shared or static 
library.")
 endif()
@@ -432,11 +437,15 @@ endif()
 
 # Define LIBCXXABI_USE_LLVM_UNWINDER for conditional compilation.
 if (LIBCXXABI_USE_LLVM_UNWINDER)
-  add_definitions(-DLIBCXXABI_USE_LLVM_UNWINDER=1)
+  add_definitions(-DLIBCXXABI_USE_LLVM_UNWINDER)
 endif()
 
 if (LIBCXXABI_SILENT_TERMINATE)
-  add_definitions(-DLIBCXXABI_SILENT_TERMINATE=1)
+  add_definitions(-DLIBCXXABI_SILENT_TERMINATE)
+endif()
+
+if (LIBCXXABI_BAREMETAL)
+add_definitions(-DLIBCXXABI_BAREMETAL)
 endif()
 
 string(REPLACE ";" " " LIBCXXABI_CXX_FLAGS "${LIBCXXABI_CXX_FLAGS}")

Modified: libcxxabi/trunk/include/__cxxabi_config.h
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/include/__cxxabi_config.h?rev=296612&r1=296611&r2=296612&view=diff
==
--- libcxxabi/trunk/include/__cxxabi_config.h (original)
+++ libcxxabi/trunk/include/__cxxabi_config.h Wed Mar  1 05:42:01 2017
@@ -12,9 +12,7 @@
 
 #if defined(__arm__) && !defined(__USING_SJLJ_EXCEPTIONS__) && 
\
 !defined(__ARM_DWARF_EH__)
-#define _LIBCXXABI_ARM_EHABI 1
-#else
-#define _LIBCXXABI_ARM_EHABI 0
+#define _LIBCXXABI_ARM_EHABI
 #endif
 
 #if !defined(__has_attribute)

Modified: libcxxabi/trunk/include/cxxabi.h
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/include/cxxabi.h?rev=296612&r1=296611&r2=296612&view=diff
==
--- libcxxabi/trunk/include/cxxabi.h (original)
+++ libcxxabi/trunk/include/cxxabi.h Wed Mar  1 05:42:01 2017
@@ -55,7 +55,7 @@ __cxa_get_exception_ptr(void *exceptionO
 extern _LIBCXXABI_FUNC_VIS void *
 __cxa_begin_catch(void *exceptionObject) throw();
 extern _LIBCXXABI_FUNC_VIS void __cxa_end_catch();
-#if _LIBCXXABI_ARM_EHABI
+#if defined(_LIBCXXABI_ARM_EHABI)
 extern _LIBCXXABI_FUNC_VIS bool
 __cxa_begin_cleanup(void *exceptionObject) throw();
 extern _LIBCXXABI_FUNC_VIS void __cxa_end_cleanup();

Modified: libcxxabi/trunk/src/abort_message.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/abort_message.cpp?rev=296612&r1=296611&r2=296612&view=diff
==
--- libcxxabi/trunk/src/abort_message.cpp (original)
+++ libcxxabi/trunk/src/abort_message.cpp Wed Mar  1 05:42:01 2017
@@ -32,7 +32,7 @@ extern "C" void android_set_abort_messag
 void abort_message(const char* format, ...)
 {
 // write message to stderr
-#if !defined(NDEBUG) || !LIBCXXABI_BAREMETAL
+#if !defined(NDEBUG) || !defined(LIBCXXABI_BAREMETAL)
 #ifdef __APPLE__
 fprintf(stderr, "libc++abi.dylib: ");
 #endif

Modified: libcxxabi/trunk/src/config.h
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/config.h?rev=296612&r1=296611&r2=296612&view=diff
==
--- libcxxabi/trunk/src/config.h (original)
+++ libcxxabi/trunk/src/config.h Wed Mar  1 05:42:01 2017
@@ -16,18 +16,4 @@
 
 #include 
 
-// Set this in the CXXFLAGS when you need it, because otherwise we'd have to
-// #if !defined(__linux__) && !defined(__APPLE__) && ...
-// and so-on for *every* platform.
-#ifndef LIBCXXABI_BAREMETAL
-#  define LIBCXXABI_BAREMETAL 0
-#endif
-
-// The default terminate handler attempts to de

[PATCH] D30459: [libcxxabi] Clean up macro usage

2017-03-01 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL296612: [libcxxabi] Clean up macro usage. (authored by 
rsingh).

Changed prior to commit:
  https://reviews.llvm.org/D30459?vs=90150&id=90155#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D30459

Files:
  libcxxabi/trunk/CMakeLists.txt
  libcxxabi/trunk/include/__cxxabi_config.h
  libcxxabi/trunk/include/cxxabi.h
  libcxxabi/trunk/src/abort_message.cpp
  libcxxabi/trunk/src/config.h
  libcxxabi/trunk/src/cxa_default_handlers.cpp
  libcxxabi/trunk/src/cxa_exception.cpp
  libcxxabi/trunk/src/cxa_exception.hpp
  libcxxabi/trunk/src/cxa_personality.cpp

Index: libcxxabi/trunk/src/abort_message.cpp
===
--- libcxxabi/trunk/src/abort_message.cpp
+++ libcxxabi/trunk/src/abort_message.cpp
@@ -32,7 +32,7 @@
 void abort_message(const char* format, ...)
 {
 // write message to stderr
-#if !defined(NDEBUG) || !LIBCXXABI_BAREMETAL
+#if !defined(NDEBUG) || !defined(LIBCXXABI_BAREMETAL)
 #ifdef __APPLE__
 fprintf(stderr, "libc++abi.dylib: ");
 #endif
Index: libcxxabi/trunk/src/config.h
===
--- libcxxabi/trunk/src/config.h
+++ libcxxabi/trunk/src/config.h
@@ -16,18 +16,4 @@
 
 #include 
 
-// Set this in the CXXFLAGS when you need it, because otherwise we'd have to
-// #if !defined(__linux__) && !defined(__APPLE__) && ...
-// and so-on for *every* platform.
-#ifndef LIBCXXABI_BAREMETAL
-#  define LIBCXXABI_BAREMETAL 0
-#endif
-
-// The default terminate handler attempts to demangle uncaught exceptions, which
-// causes extra I/O and demangling code to be pulled in.
-// Set this to make the terminate handler default to a silent alternative.
-#ifndef LIBCXXABI_SILENT_TERMINATE
-#  define LIBCXXABI_SILENT_TERMINATE 0
-#endif
-
 #endif // LIBCXXABI_CONFIG_H
Index: libcxxabi/trunk/src/cxa_personality.cpp
===
--- libcxxabi/trunk/src/cxa_personality.cpp
+++ libcxxabi/trunk/src/cxa_personality.cpp
@@ -317,7 +317,7 @@
 std::terminate();
 }
 
-#if _LIBCXXABI_ARM_EHABI
+#if defined(_LIBCXXABI_ARM_EHABI)
 static const void* read_target2_value(const void* ptr)
 {
 uintptr_t offset = *reinterpret_cast(ptr);
@@ -328,7 +328,7 @@
 // deferred to the linker. For bare-metal they turn into absolute
 // relocations. For linux they turn into GOT-REL relocations."
 // https://gcc.gnu.org/ml/gcc-patches/2009-08/msg00264.html
-#if LIBCXXABI_BAREMETAL
+#if defined(LIBCXXABI_BAREMETAL)
 return reinterpret_cast(reinterpret_cast(ptr) +
  offset);
 #else
@@ -358,7 +358,7 @@
 return reinterpret_cast(
 read_target2_value(ttypePtr));
 }
-#else // !_LIBCXXABI_ARM_EHABI
+#else // !defined(_LIBCXXABI_ARM_EHABI)
 static
 const __shim_type_info*
 get_shim_type_info(uint64_t ttypeIndex, const uint8_t* classInfo,
@@ -394,7 +394,7 @@
 classInfo -= ttypeIndex;
 return (const __shim_type_info*)readEncodedPointer(&classInfo, ttypeEncoding);
 }
-#endif // !_LIBCXXABI_ARM_EHABI
+#endif // !defined(_LIBCXXABI_ARM_EHABI)
 
 /*
 This is checking a thrown exception type, excpType, against a possibly empty
@@ -405,7 +405,7 @@
 the list will catch a excpType.  If any catchType in the list can catch an
 excpType, then this exception spec does not catch the excpType.
 */
-#if _LIBCXXABI_ARM_EHABI
+#if defined(_LIBCXXABI_ARM_EHABI)
 static
 bool
 exception_spec_can_catch(int64_t specIndex, const uint8_t* classInfo,
@@ -934,7 +934,7 @@
 Else a cleanup is not found: return _URC_CONTINUE_UNWIND
 */
 
-#if !_LIBCXXABI_ARM_EHABI
+#if !defined(_LIBCXXABI_ARM_EHABI)
 _LIBCXXABI_FUNC_VIS _Unwind_Reason_Code
 #ifdef __USING_SJLJ_EXCEPTIONS__
 __gxx_personality_sj0
@@ -1194,7 +1194,7 @@
 u_handler = old_exception_header->unexpectedHandler;
 // If std::__unexpected(u_handler) rethrows the same exception,
 //   these values get overwritten by the rethrow.  So save them now:
-#if _LIBCXXABI_ARM_EHABI
+#if defined(_LIBCXXABI_ARM_EHABI)
 ttypeIndex = (int64_t)(int32_t)unwind_exception->barrier_cache.bitpattern[4];
 lsda = (const uint8_t*)unwind_exception->barrier_cache.bitpattern[2];
 #else
Index: libcxxabi/trunk/src/cxa_default_handlers.cpp
===
--- libcxxabi/trunk/src/cxa_default_handlers.cpp
+++ libcxxabi/trunk/src/cxa_default_handlers.cpp
@@ -85,7 +85,7 @@
 std::terminate();
 }
 
-#if !LIBCXXABI_SILENT_TERMINATE
+#if !defined(LIBCXXABI_SILENT_TERMINATE)
 static std::terminate_handler default_terminate_handler = demangling_terminate_handler;
 static std::terminate_handler default_unexpected_handler = demangling_unexpected_handler;
 #else
Index: libcxxabi/trunk/src/cxa_exception.hpp
===
--- libcxxabi/trunk/src/cxa_exception.

[PATCH] D30459: [libcxxabi] Clean up macro usage

2017-03-01 Thread Ranjeet Singh via Phabricator via cfe-commits
rs added a comment.

ok thanks.


https://reviews.llvm.org/D30459



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


r296616 - Introducing clang::tooling::AtomicChange for refactoring tools.

2017-03-01 Thread Eric Liu via cfe-commits
Author: ioeric
Date: Wed Mar  1 07:14:01 2017
New Revision: 296616

URL: http://llvm.org/viewvc/llvm-project?rev=296616&view=rev
Log:
Introducing clang::tooling::AtomicChange for refactoring tools.

Summary:
An AtomicChange is used to create and group a set of source edits, e.g.
replacements or header insertions. Edits in an AtomicChange should be related,
e.g. replacements for the same type reference and the corresponding header
insertion/deletion.

An AtomicChange is uniquely identified by a key position and will either be
fully applied or not applied at all. The key position should be the location
of the key syntactical element that is being changed, e.g. the call to a
refactored method.

Next step: add a tool that applies AtomicChange.

Reviewers: klimek, djasper

Reviewed By: klimek

Subscribers: alexshap, cfe-commits, djasper, mgorny

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

Added:
cfe/trunk/include/clang/Tooling/Refactoring/
cfe/trunk/include/clang/Tooling/Refactoring/AtomicChange.h
cfe/trunk/lib/Tooling/Refactoring/
cfe/trunk/lib/Tooling/Refactoring/AtomicChange.cpp
cfe/trunk/lib/Tooling/Refactoring/CMakeLists.txt
Modified:
cfe/trunk/lib/Tooling/CMakeLists.txt
cfe/trunk/unittests/Tooling/CMakeLists.txt
cfe/trunk/unittests/Tooling/RefactoringTest.cpp

Added: cfe/trunk/include/clang/Tooling/Refactoring/AtomicChange.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Refactoring/AtomicChange.h?rev=296616&view=auto
==
--- cfe/trunk/include/clang/Tooling/Refactoring/AtomicChange.h (added)
+++ cfe/trunk/include/clang/Tooling/Refactoring/AtomicChange.h Wed Mar  1 
07:14:01 2017
@@ -0,0 +1,129 @@
+//===--- AtomicChange.h - AtomicChange class *- C++ 
-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+//  This file defines AtomicChange which is used to create a set of source
+//  changes, e.g. replacements and header insertions.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLING_REFACTOR_ATOMICCHANGE_H
+#define LLVM_CLANG_TOOLING_REFACTOR_ATOMICCHANGE_H
+
+#include "clang/Basic/SourceManager.h"
+#include "clang/Tooling/Core/Replacement.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Error.h"
+
+namespace clang {
+namespace tooling {
+
+/// \brief An atomic change is used to create and group a set of source edits,
+/// e.g. replacements or header insertions. Edits in an AtomicChange should be
+/// related, e.g. replacements for the same type reference and the 
corresponding
+/// header insertion/deletion.
+///
+/// An AtomicChange is uniquely identified by a key and will either be fully
+/// applied or not applied at all.
+///
+/// Calling setError on an AtomicChange stores the error message and marks it 
as
+/// bad, i.e. none of its source edits will be applied.
+class AtomicChange {
+public:
+  /// \brief Creates an atomic change around \p KeyPosition with the key being 
a
+  /// concatenation of the file name and the offset of \p KeyPosition.
+  /// \p KeyPosition should be the location of the key syntactical element that
+  /// is being changed, e.g. the call to a refactored method.
+  AtomicChange(const SourceManager &SM, SourceLocation KeyPosition);
+
+  /// \brief Creates an atomic change for \p FilePath with a customized key.
+  AtomicChange(llvm::StringRef FilePath, llvm::StringRef Key)
+  : Key(Key), FilePath(FilePath) {}
+
+  /// \brief Returns the atomic change as a YAML string.
+  std::string toYAMLString();
+
+  /// \brief Converts a YAML-encoded automic change to AtomicChange.
+  static AtomicChange convertFromYAML(llvm::StringRef YAMLContent);
+
+  /// \brief Returns the key of this change, which is a concatenation of the
+  /// file name and offset of the key position.
+  const std::string &getKey() const { return Key; }
+
+  /// \brief Returns the path of the file containing this atomic change.
+  const std::string &getFilePath() const { return FilePath; }
+
+  /// \brief If this change could not be created successfully, e.g. because of
+  /// conflicts among replacements, use this to set an error description.
+  /// Thereby, places that cannot be fixed automatically can be gathered when
+  /// applying changes.
+  void setError(llvm::StringRef Error) { this->Error = Error; }
+
+  /// \brief Returns whether an error has been set on this list.
+  bool hasError() const { return !Error.empty(); }
+
+  /// \brief Returns the error message or an empty string if it does not exist.
+  const std::string &getError() const { return Error; }
+
+  /// \brief Adds a replacement that replaces range [Loc, Loc+Length) with
+  /// \p Text

[PATCH] D27054: Introducing clang::tooling::AtomicChange for refactoring tools.

2017-03-01 Thread Eric Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL296616: Introducing clang::tooling::AtomicChange for 
refactoring tools. (authored by ioeric).

Changed prior to commit:
  https://reviews.llvm.org/D27054?vs=90018&id=90165#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D27054

Files:
  cfe/trunk/include/clang/Tooling/Refactoring/AtomicChange.h
  cfe/trunk/lib/Tooling/CMakeLists.txt
  cfe/trunk/lib/Tooling/Refactoring/AtomicChange.cpp
  cfe/trunk/lib/Tooling/Refactoring/CMakeLists.txt
  cfe/trunk/unittests/Tooling/CMakeLists.txt
  cfe/trunk/unittests/Tooling/RefactoringTest.cpp

Index: cfe/trunk/include/clang/Tooling/Refactoring/AtomicChange.h
===
--- cfe/trunk/include/clang/Tooling/Refactoring/AtomicChange.h
+++ cfe/trunk/include/clang/Tooling/Refactoring/AtomicChange.h
@@ -0,0 +1,129 @@
+//===--- AtomicChange.h - AtomicChange class *- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+//  This file defines AtomicChange which is used to create a set of source
+//  changes, e.g. replacements and header insertions.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLING_REFACTOR_ATOMICCHANGE_H
+#define LLVM_CLANG_TOOLING_REFACTOR_ATOMICCHANGE_H
+
+#include "clang/Basic/SourceManager.h"
+#include "clang/Tooling/Core/Replacement.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Error.h"
+
+namespace clang {
+namespace tooling {
+
+/// \brief An atomic change is used to create and group a set of source edits,
+/// e.g. replacements or header insertions. Edits in an AtomicChange should be
+/// related, e.g. replacements for the same type reference and the corresponding
+/// header insertion/deletion.
+///
+/// An AtomicChange is uniquely identified by a key and will either be fully
+/// applied or not applied at all.
+///
+/// Calling setError on an AtomicChange stores the error message and marks it as
+/// bad, i.e. none of its source edits will be applied.
+class AtomicChange {
+public:
+  /// \brief Creates an atomic change around \p KeyPosition with the key being a
+  /// concatenation of the file name and the offset of \p KeyPosition.
+  /// \p KeyPosition should be the location of the key syntactical element that
+  /// is being changed, e.g. the call to a refactored method.
+  AtomicChange(const SourceManager &SM, SourceLocation KeyPosition);
+
+  /// \brief Creates an atomic change for \p FilePath with a customized key.
+  AtomicChange(llvm::StringRef FilePath, llvm::StringRef Key)
+  : Key(Key), FilePath(FilePath) {}
+
+  /// \brief Returns the atomic change as a YAML string.
+  std::string toYAMLString();
+
+  /// \brief Converts a YAML-encoded automic change to AtomicChange.
+  static AtomicChange convertFromYAML(llvm::StringRef YAMLContent);
+
+  /// \brief Returns the key of this change, which is a concatenation of the
+  /// file name and offset of the key position.
+  const std::string &getKey() const { return Key; }
+
+  /// \brief Returns the path of the file containing this atomic change.
+  const std::string &getFilePath() const { return FilePath; }
+
+  /// \brief If this change could not be created successfully, e.g. because of
+  /// conflicts among replacements, use this to set an error description.
+  /// Thereby, places that cannot be fixed automatically can be gathered when
+  /// applying changes.
+  void setError(llvm::StringRef Error) { this->Error = Error; }
+
+  /// \brief Returns whether an error has been set on this list.
+  bool hasError() const { return !Error.empty(); }
+
+  /// \brief Returns the error message or an empty string if it does not exist.
+  const std::string &getError() const { return Error; }
+
+  /// \brief Adds a replacement that replaces range [Loc, Loc+Length) with
+  /// \p Text.
+  /// \returns An llvm::Error carrying ReplacementError on error.
+  llvm::Error replace(const SourceManager &SM, SourceLocation Loc,
+  unsigned Length, llvm::StringRef Text);
+
+  /// \brief Adds a replacement that inserts \p Text at \p Loc. If this
+  /// insertion conflicts with an existing insertion (at the same position),
+  /// this will be inserted before/after the existing insertion depending on
+  /// \p InsertAfter. Users should use `replace` with `Length=0` instead if they
+  /// do not want conflict resolving by default. If the conflicting replacement
+  /// is not an insertion, an error is returned.
+  ///
+  /// \returns An llvm::Error carrying ReplacementError on error.
+  llvm::Error insert(const SourceManager &SM, SourceLocation Loc,
+ llvm::StringRef Text, bool InsertAfter = true);
+
+  ///

[PATCH] D30487: ClangFormat - Add option to break before inheritance separation operator in class declaration

2017-03-01 Thread Andi via Phabricator via cfe-commits
Abpostelnicu updated this revision to Diff 90171.
Abpostelnicu added a comment.

Also added tests.


Repository:
  rL LLVM

https://reviews.llvm.org/D30487

Files:
  docs/ClangFormatStyleOptions.rst
  include/clang/Format/Format.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/Format.cpp
  lib/Format/FormatToken.h
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -1011,6 +1011,29 @@
   verifyFormat("class ::A::B {};");
 }
 
+TEST_F(FormatTest, BreakBeforeInhertianceDelimiter) {
+  FormatStyle StyleWithInheritanceBreak = getLLVMStyle();
+  LocalStyle.BreakBeforeInhertianceDelimiter = true;
+
+  verifyFormat("class MyClass : public X {}", LocalStyle);
+  verifyFormat("class MyClass\n"
+   ": public X\n"
+   ", public Y // some difficult comment\n"
+   ", public Z {}",
+   StyleWithInheritanceBreak);
+  verifyFormat("class MyClass"
+   "  : public X\n"
+   "  , public Y // some difficult comment\n"
+   "  , public Z\n",
+   StyleWithInheritanceBreak);
+  verifyFormat("class MyClass\n"
+   ": public X // When deriving from more than one class, put "
+   "each on its own\n"
+   "   // line.\n"
+   ", public Y {}",
+   StyleWithInheritanceBreak);
+}
+
 TEST_F(FormatTest, FormatsVariableDeclarationsAfterStructOrClass) {
   verifyFormat("class A {\n} a, b;");
   verifyFormat("struct A {\n} a, b;");
@@ -8459,6 +8482,7 @@
   CHECK_PARSE_BOOL(BreakBeforeTernaryOperators);
   CHECK_PARSE_BOOL(BreakConstructorInitializersBeforeComma);
   CHECK_PARSE_BOOL(BreakStringLiterals);
+  CHECK_PARSE_BOOL(BreakBeforeInhertianceDelimiter)
   CHECK_PARSE_BOOL(ConstructorInitializerAllOnOneLineOrOnePerLine);
   CHECK_PARSE_BOOL(DerivePointerAlignment);
   CHECK_PARSE_BOOL_FIELD(DerivePointerAlignment, "DerivePointerBinding");
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -676,6 +676,8 @@
 case tok::comma:
   if (Contexts.back().InCtorInitializer)
 Tok->Type = TT_CtorInitializerComma;
+  else if (Contexts.back().InInhertiance)
+Tok->Type = TT_InheritanceComma;
   else if (Contexts.back().FirstStartOfName &&
(Contexts.size() == 1 || Line.startsWith(tok::kw_for))) {
 Contexts.back().FirstStartOfName->PartOfMultiVariableDeclStmt = true;
@@ -945,6 +947,7 @@
 bool CanBeExpression = true;
 bool InTemplateArgument = false;
 bool InCtorInitializer = false;
+bool InInhertiance = false;
 bool CaretFound = false;
 bool IsForEachMacro = false;
   };
@@ -1004,6 +1007,10 @@
Current.Previous->is(TT_CtorInitializerColon)) {
   Contexts.back().IsExpression = true;
   Contexts.back().InCtorInitializer = true;
+} else if (Current.Previous &&
+   Current.Previous->is(TT_InheritanceColon)) {
+  Contexts.back().IsExpression = true;
+  Contexts.back().InInhertiance = true;
 } else if (Current.isOneOf(tok::r_paren, tok::greater, tok::comma)) {
   for (FormatToken *Previous = Current.Previous;
Previous && Previous->isOneOf(tok::star, tok::amp);
@@ -2377,6 +2384,15 @@
  !Tok.isOneOf(TT_ObjCBlockLBrace, TT_DictLiteral);
 }
 
+// Determine if the next token from the closing scope is an inheritance token
+static bool hasMultipleInheritance(const FormatToken &Tok) {
+  // Look for a column of type TT_InheritanceComma untill we find it or
+  // we find a declaration termination
+  for (const FormatToken* nextTok = Tok.Next; nextTok; nextTok = nextTok->Next)
+if (nextTok->is(TT_InheritanceComma)) return true;
+  return false;
+}
+  
 bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
  const FormatToken &Right) {
   const FormatToken &Left = *Right.Previous;
@@ -2460,6 +2476,11 @@
   Style.BreakConstructorInitializersBeforeComma &&
   !Style.ConstructorInitializerAllOnOneLineOrOnePerLine)
 return true;
+  //Break only if we have multiple inheritance
+  if (Style.BreakBeforeInhertianceDelimiter &&
+  ((Right.is(TT_InheritanceColon) && hasMultipleInheritance(Right)) ||
+  Right.is(TT_InheritanceComma)))
+return true;
   if (Right.is(tok::string_literal) && Right.TokenText.startswith("R\""))
 // Raw string literals are special wrt. line breaks. The author has made a
 // deliberate choice and might have aligned the contents of the string
@@ -2634,6 +2655,12 @@
   if (Right.is(TT_CtorInitializerComma) &&
   Style.BreakConstructorInitializersBeforeComma)
 return true;
+  if (Left.is(TT_InheritanceComma) &&
+  S

[PATCH] D30489: [analyzer] catch out of bounds for VLA

2017-03-01 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

There is an alternative approach idea:

This is not found by ArrayBoundCheckerV2? If no, an alternative approach would 
be to properly set the constraints on the extent of the VLA's memory region. 
After that, maybe ArrayBoundCheckerV2 would work automatically on this case. If 
the extent size is not set for VLAs properly yet, it should be similar to this 
patch: https://reviews.llvm.org/D24307

@zaks.anna, @dcoughlin WDYT?


Repository:
  rL LLVM

https://reviews.llvm.org/D30489



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


[PATCH] D30405: [clang-format] Add a new flag FixNamespaceEndComments to FormatStyle

2017-03-01 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 90172.
krasimir marked 2 inline comments as done.
krasimir added a comment.

- Address review comments


https://reviews.llvm.org/D30405

Files:
  docs/ClangFormatStyleOptions.rst
  include/clang/Format/Format.h
  lib/Format/Format.cpp
  lib/Index/CommentToXML.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -185,7 +185,7 @@
   EXPECT_EQ("namespace N {\n"
 "\n"
 "int i;\n"
-"}",
+"}  // namespace N",
 format("namespace N {\n"
"\n"
"inti;\n"
@@ -270,12 +270,22 @@
"}"));
 
   // FIXME: This is slightly inconsistent.
+  FormatStyle LLVMWithNoNamespaceFix = getLLVMStyle();
+  LLVMWithNoNamespaceFix.FixNamespaceComments = false;
   EXPECT_EQ("namespace {\n"
 "int i;\n"
 "}",
 format("namespace {\n"
"int i;\n"
"\n"
+   "}", LLVMWithNoNamespaceFix));
+  EXPECT_EQ("namespace {\n"
+"int i;\n"
+"\n"
+"} // namespace",
+format("namespace {\n"
+   "int i;\n"
+   "\n"
"}"));
   EXPECT_EQ("namespace {\n"
 "int i;\n"
@@ -1197,33 +1207,43 @@
 }
 
 TEST_F(FormatTest, FormatsNamespaces) {
+  FormatStyle LLVMWithNoNamespaceFix = getLLVMStyle();
+  LLVMWithNoNamespaceFix.FixNamespaceComments = false;
+
   verifyFormat("namespace some_namespace {\n"
"class A {};\n"
"void f() { f(); }\n"
-   "}");
+   "}",
+   LLVMWithNoNamespaceFix);
   verifyFormat("namespace {\n"
"class A {};\n"
"void f() { f(); }\n"
-   "}");
+   "}",
+   LLVMWithNoNamespaceFix);
   verifyFormat("inline namespace X {\n"
"class A {};\n"
"void f() { f(); }\n"
-   "}");
+   "}",
+   LLVMWithNoNamespaceFix);
   verifyFormat("using namespace some_namespace;\n"
"class A {};\n"
-   "void f() { f(); }");
+   "void f() { f(); }",
+   LLVMWithNoNamespaceFix);
 
   // This code is more common than we thought; if we
   // layout this correctly the semicolon will go into
   // its own line, which is undesirable.
-  verifyFormat("namespace {};");
+  verifyFormat("namespace {};",
+   LLVMWithNoNamespaceFix);
   verifyFormat("namespace {\n"
"class A {};\n"
-   "};");
+   "};",
+   LLVMWithNoNamespaceFix);
 
   verifyFormat("namespace {\n"
"int SomeVariable = 0; // comment\n"
-   "} // namespace");
+   "} // namespace",
+   LLVMWithNoNamespaceFix);
   EXPECT_EQ("#ifndef HEADER_GUARD\n"
 "#define HEADER_GUARD\n"
 "namespace my_namespace {\n"
@@ -1235,44 +1255,46 @@
"   namespace my_namespace {\n"
"int i;\n"
"}// my_namespace\n"
-   "#endif// HEADER_GUARD"));
+   "#endif// HEADER_GUARD",
+   LLVMWithNoNamespaceFix));
 
   EXPECT_EQ("namespace A::B {\n"
 "class C {};\n"
 "}",
 format("namespace A::B {\n"
"class C {};\n"
-   "}"));
+   "}",
+   LLVMWithNoNamespaceFix));
 
   FormatStyle Style = getLLVMStyle();
   Style.NamespaceIndentation = FormatStyle::NI_All;
   EXPECT_EQ("namespace out {\n"
 "  int i;\n"
 "  namespace in {\n"
 "int i;\n"
-"  } // namespace\n"
-"} // namespace",
+"  } // namespace in\n"
+"} // namespace out",
 format("namespace out {\n"
"int i;\n"
"namespace in {\n"
"int i;\n"
-   "} // namespace\n"
-   "} // namespace",
+   "} // namespace in\n"
+   "} // namespace out",
Style));
 
   Style.NamespaceIndentation = FormatStyle::NI_Inner;
   EXPECT_EQ("namespace out {\n"
 "int i;\n"
 "namespace in {\n"
 "  int i;\n"
-"} // namespace\n"
-"} // namespace",
+"} // namespace in\n"
+"} // namespace out",
 format("namespace out {\n"
"int i;\n"
"namespace in {\n"
"int i;\n"
-   "} // namespace\n"
-   "} // namespace",
+   "} // namespace in\n"
+   "} // namespace out",
  

[clang-tools-extra] r296618 - [clangd] Add a toy VS Code integration for development purposes

2017-03-01 Thread Krasimir Georgiev via cfe-commits
Author: krasimir
Date: Wed Mar  1 07:53:12 2017
New Revision: 296618

URL: http://llvm.org/viewvc/llvm-project?rev=296618&view=rev
Log:
[clangd] Add a toy VS Code integration for development purposes

Summary: This patch adds bare-bone VS Code integration for development purposes 
of clangd.

Reviewers: klimek, bkramer, mprobst

Reviewed By: bkramer

Subscribers: mprobst

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

Added:
clang-tools-extra/trunk/clangd/clients/
clang-tools-extra/trunk/clangd/clients/clangd-vscode/
clang-tools-extra/trunk/clangd/clients/clangd-vscode/.gitignore
clang-tools-extra/trunk/clangd/clients/clangd-vscode/.vscode/
clang-tools-extra/trunk/clangd/clients/clangd-vscode/.vscode/launch.json
clang-tools-extra/trunk/clangd/clients/clangd-vscode/.vscode/settings.json
clang-tools-extra/trunk/clangd/clients/clangd-vscode/.vscode/tasks.json
clang-tools-extra/trunk/clangd/clients/clangd-vscode/.vscodeignore
clang-tools-extra/trunk/clangd/clients/clangd-vscode/README.txt
clang-tools-extra/trunk/clangd/clients/clangd-vscode/package.json
clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/
clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/extension.ts
clang-tools-extra/trunk/clangd/clients/clangd-vscode/test/
clang-tools-extra/trunk/clangd/clients/clangd-vscode/test/extension.test.ts
clang-tools-extra/trunk/clangd/clients/clangd-vscode/test/index.ts
clang-tools-extra/trunk/clangd/clients/clangd-vscode/tsconfig.json

clang-tools-extra/trunk/clangd/clients/clangd-vscode/vsc-extension-quickstart.md

Added: clang-tools-extra/trunk/clangd/clients/clangd-vscode/.gitignore
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/clients/clangd-vscode/.gitignore?rev=296618&view=auto
==
--- clang-tools-extra/trunk/clangd/clients/clangd-vscode/.gitignore (added)
+++ clang-tools-extra/trunk/clangd/clients/clangd-vscode/.gitignore Wed Mar  1 
07:53:12 2017
@@ -0,0 +1,2 @@
+out
+node_modules
\ No newline at end of file

Added: clang-tools-extra/trunk/clangd/clients/clangd-vscode/.vscode/launch.json
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/clients/clangd-vscode/.vscode/launch.json?rev=296618&view=auto
==
--- clang-tools-extra/trunk/clangd/clients/clangd-vscode/.vscode/launch.json 
(added)
+++ clang-tools-extra/trunk/clangd/clients/clangd-vscode/.vscode/launch.json 
Wed Mar  1 07:53:12 2017
@@ -0,0 +1,28 @@
+// A launch configuration that compiles the extension and then opens it inside 
a new window
+{
+"version": "0.1.0",
+"configurations": [
+{
+"name": "Launch Extension",
+"type": "extensionHost",
+"request": "launch",
+"runtimeExecutable": "${execPath}",
+"args": ["--extensionDevelopmentPath=${workspaceRoot}" ],
+"stopOnEntry": false,
+"sourceMaps": true,
+"outFiles": [ "${workspaceRoot}/out/src/**/*.js" ],
+"preLaunchTask": "npm"
+},
+{
+"name": "Launch Tests",
+"type": "extensionHost",
+"request": "launch",
+"runtimeExecutable": "${execPath}",
+"args": ["--extensionDevelopmentPath=${workspaceRoot}", 
"--extensionTestsPath=${workspaceRoot}/out/test" ],
+"stopOnEntry": false,
+"sourceMaps": true,
+"outFiles": [ "${workspaceRoot}/out/test/**/*.js" ],
+"preLaunchTask": "npm"
+}
+]
+}

Added: 
clang-tools-extra/trunk/clangd/clients/clangd-vscode/.vscode/settings.json
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/clients/clangd-vscode/.vscode/settings.json?rev=296618&view=auto
==
--- clang-tools-extra/trunk/clangd/clients/clangd-vscode/.vscode/settings.json 
(added)
+++ clang-tools-extra/trunk/clangd/clients/clangd-vscode/.vscode/settings.json 
Wed Mar  1 07:53:12 2017
@@ -0,0 +1,9 @@
+// Place your settings in this file to overwrite default and user settings.
+{
+"files.exclude": {
+"out": false // set this to true to hide the "out" folder with the 
compiled JS files
+},
+"search.exclude": {
+"out": true // set this to false to include "out" folder in search 
results
+}
+}
\ No newline at end of file

Added: clang-tools-extra/trunk/clangd/clients/clangd-vscode/.vscode/tasks.json
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/clients/clangd-vscode/.vscode/tasks.json?rev=296618&view=auto
==
--- clang-tools-extra/trunk/clangd/clients/clangd-vscode/.vscode/tasks.json 
(added)
+++ clang-tools-extra/trunk/clangd/clients/clangd-vscode/.vscode/t

[PATCH] D30476: [clangd] Add a toy Eclipse integration for development purposes

2017-03-01 Thread Marc-Andre Laperle via Phabricator via cfe-commits
malaperle-ericsson added a comment.

To be honest, I don't think this needs to be merged but it makes sense to put 
it somewhere people can try it.


Repository:
  rL LLVM

https://reviews.llvm.org/D30476



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


[PATCH] D30498: [clangd] Add support for FixIts.

2017-03-01 Thread Benjamin Kramer via Phabricator via cfe-commits
bkramer created this revision.

This uses CodeActions to show 'apply fix' actions when code actions are
requested for a location. The actions themselves make use of a
clangd.applyFix command which has to be implemented on the editor side. I
included an implementation for vscode.

This also adds a -run-synchronously flag which runs everything on the main
thread. This is useful for testing.


https://reviews.llvm.org/D30498

Files:
  clangd/ASTManager.cpp
  clangd/ASTManager.h
  clangd/ClangDMain.cpp
  clangd/Protocol.cpp
  clangd/Protocol.h
  clangd/ProtocolHandlers.cpp
  clangd/ProtocolHandlers.h
  clangd/clients/clangd-vscode/src/extension.ts
  test/clangd/fixits.test

Index: test/clangd/fixits.test
===
--- /dev/null
+++ test/clangd/fixits.test
@@ -0,0 +1,22 @@
+# RUN: clangd -run-synchronously < %s | FileCheck %s
+# It is absolutely vital that this file has CRLF line endings.
+#
+Content-Length: 125
+
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
+#
+Content-Length: 180
+
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///foo.c","languageId":"c","version":1,"text":"int main(int i, char **a) { if (i = 2) {}}"}}}
+#
+# CHECK-DAG: {"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///foo.c","diagnostics":[{"range":{"start": {"line": 0, "character": 35}, "end": {"line": 0, "character": 35}},"severity":2,"message":"using the result of an assignment as a condition without parentheses"},{"range":{"start": {"line": 0, "character": 35}, "end": {"line": 0, "character": 35}},"severity":3,"message":"place parentheses around the assignment to silence this warning"},{"range":{"start": {"line": 0, "character": 35}, "end": {"line": 0, "character": 35}},"severity":3,"message":"use '==' to turn this assignment into an equality comparison"}]}}}
+#
+Content-Length: 746
+
+ {"jsonrpc":"2.0","id":2,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"file:///foo.c"},"range":{"start":{"line":104,"character":13},"end":{"line":0,"character":35}},"context":{"diagnostics":[{"range":{"start": {"line": 0, "character": 35}, "end": {"line": 0, "character": 35}},"severity":2,"message":"using the result of an assignment as a condition without parentheses"},{"range":{"start": {"line": 0, "character": 35}, "end": {"line": 0, "character": 35}},"severity":3,"message":"place parentheses around the assignment to silence this warning"},{"range":{"start": {"line": 0, "character": 35}, "end": {"line": 0, "character": 35}},"severity":3,"message":"use '==' to turn this assignment into an equality comparison"}]}}}
+#
+# CHECK: {"jsonrpc":"2.0","id":2, "result": [{"title":"Apply FixIt 'place parentheses around the assignment to silence this warning'", "command": "clangd.applyFix", "arguments": ["file:///foo.c", [{"range": {"start": {"line": 0, "character": 32}, "end": {"line": 0, "character": 32}}, "newText": "("},{"range": {"start": {"line": 0, "character": 37}, "end": {"line": 0, "character": 37}}, "newText": ")"}]]},{"title":"Apply FixIt 'use '==' to turn this assignment into an equality comparison'", "command": "clangd.applyFix", "arguments": ["file:///foo.c", [{"range": {"start": {"line": 0, "character": 34}, "end": {"line": 0, "character": 35}}, "newText": "=="}]]}]
+#
+Content-Length: 44
+
+{"jsonrpc":"2.0","id":3,"method":"shutdown"}
Index: clangd/clients/clangd-vscode/src/extension.ts
===
--- clangd/clients/clangd-vscode/src/extension.ts
+++ clangd/clients/clangd-vscode/src/extension.ts
@@ -18,9 +18,25 @@
 
 const clangdClient = new vscodelc.LanguageClient('Clang Language Server', serverOptions, clientOptions);
 
+function applyTextEdits(uri: string, edits: vscodelc.TextEdit[]) {
+let textEditor = vscode.window.activeTextEditor;
+
+if (textEditor && textEditor.document.uri.toString() === uri) {
+textEditor.edit(mutator => {
+for (let edit of edits) {
+mutator.replace(vscodelc.Protocol2Code.asRange(edit.range), edit.newText);
+}
+}).then((success) => {
+if (!success) {
+vscode.window.showErrorMessage('Failed to apply fixes to the document.');
+}
+});
+}
+}
+
 console.log('Clang Language Server is now active!');
 
 const disposable = clangdClient.start();
 
-context.subscriptions.push(disposable);
+context.subscriptions.push(disposable, vscode.commands.registerCommand('clangd.applyFix', applyTextEdits));
 }
\ No newline at end of file
Index: clangd/ProtocolHandlers.h
===
--- clangd/ProtocolHandlers.h
+++ clangd/ProtocolHandlers.h
@@ -22,6 +22,7 @@
 
 namespace clang {
 namespace clangd {
+class ASTMana

[PATCH] D30487: ClangFormat - Add option to break before inheritance separation operator in class declaration

2017-03-01 Thread Andi via Phabricator via cfe-commits
Abpostelnicu updated this revision to Diff 90176.
Abpostelnicu added a comment.

added patch against the updated repo.


Repository:
  rL LLVM

https://reviews.llvm.org/D30487

Files:
  docs/ClangFormatStyleOptions.rst
  include/clang/Format/Format.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/Format.cpp
  lib/Format/FormatToken.h
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -1020,6 +1020,29 @@
   verifyFormat("class ::A::B {};");
 }
 
+TEST_F(FormatTest, BreakBeforeInhertianceDelimiter) {
+  FormatStyle StyleWithInheritanceBreak = getLLVMStyle();
+  LocalStyle.BreakBeforeInhertianceDelimiter = true;
+
+  verifyFormat("class MyClass : public X {}", LocalStyle);
+  verifyFormat("class MyClass\n"
+   ": public X\n"
+   ", public Y // some difficult comment\n"
+   ", public Z {}",
+   StyleWithInheritanceBreak);
+  verifyFormat("class MyClass"
+   "  : public X\n"
+   "  , public Y // some difficult comment\n"
+   "  , public Z\n",
+   StyleWithInheritanceBreak);
+  verifyFormat("class MyClass\n"
+   ": public X // When deriving from more than one class, put "
+   "each on its own\n"
+   "   // line.\n"
+   ", public Y {}",
+   StyleWithInheritanceBreak);
+}
+
 TEST_F(FormatTest, FormatsVariableDeclarationsAfterStructOrClass) {
   verifyFormat("class A {\n} a, b;");
   verifyFormat("struct A {\n} a, b;");
@@ -8468,6 +8491,7 @@
   CHECK_PARSE_BOOL(BreakBeforeTernaryOperators);
   CHECK_PARSE_BOOL(BreakConstructorInitializersBeforeComma);
   CHECK_PARSE_BOOL(BreakStringLiterals);
+  CHECK_PARSE_BOOL(BreakBeforeInhertianceDelimiter)
   CHECK_PARSE_BOOL(ConstructorInitializerAllOnOneLineOrOnePerLine);
   CHECK_PARSE_BOOL(DerivePointerAlignment);
   CHECK_PARSE_BOOL_FIELD(DerivePointerAlignment, "DerivePointerBinding");
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -676,6 +676,8 @@
 case tok::comma:
   if (Contexts.back().InCtorInitializer)
 Tok->Type = TT_CtorInitializerComma;
+  else if (Contexts.back().InInhertiance)
+Tok->Type = TT_InheritanceComma;
   else if (Contexts.back().FirstStartOfName &&
(Contexts.size() == 1 || Line.startsWith(tok::kw_for))) {
 Contexts.back().FirstStartOfName->PartOfMultiVariableDeclStmt = true;
@@ -945,6 +947,7 @@
 bool CanBeExpression = true;
 bool InTemplateArgument = false;
 bool InCtorInitializer = false;
+bool InInhertiance = false;
 bool CaretFound = false;
 bool IsForEachMacro = false;
   };
@@ -1004,6 +1007,10 @@
Current.Previous->is(TT_CtorInitializerColon)) {
   Contexts.back().IsExpression = true;
   Contexts.back().InCtorInitializer = true;
+} else if (Current.Previous &&
+   Current.Previous->is(TT_InheritanceColon)) {
+  Contexts.back().IsExpression = true;
+  Contexts.back().InInhertiance = true;
 } else if (Current.isOneOf(tok::r_paren, tok::greater, tok::comma)) {
   for (FormatToken *Previous = Current.Previous;
Previous && Previous->isOneOf(tok::star, tok::amp);
@@ -2388,6 +2395,15 @@
  !Tok.isOneOf(TT_ObjCBlockLBrace, TT_DictLiteral);
 }
 
+// Determine if the next token from the closing scope is an inheritance token
+static bool hasMultipleInheritance(const FormatToken &Tok) {
+  // Look for a column of type TT_InheritanceComma untill we find it or
+  // we find a declaration termination
+  for (const FormatToken* nextTok = Tok.Next; nextTok; nextTok = nextTok->Next)
+if (nextTok->is(TT_InheritanceComma)) return true;
+  return false;
+}
+  
 bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
  const FormatToken &Right) {
   const FormatToken &Left = *Right.Previous;
@@ -2471,6 +2487,11 @@
   Style.BreakConstructorInitializersBeforeComma &&
   !Style.ConstructorInitializerAllOnOneLineOrOnePerLine)
 return true;
+  //Break only if we have multiple inheritance
+  if (Style.BreakBeforeInhertianceDelimiter &&
+  ((Right.is(TT_InheritanceColon) && hasMultipleInheritance(Right)) ||
+  Right.is(TT_InheritanceComma)))
+return true;
   if (Right.is(tok::string_literal) && Right.TokenText.startswith("R\""))
 // Raw string literals are special wrt. line breaks. The author has made a
 // deliberate choice and might have aligned the contents of the string
@@ -2648,6 +2669,12 @@
   if (Right.is(TT_CtorInitializerComma) &&
   Style.BreakConstructorInitializersBeforeComma)
 return true;
+  if (Left.is(TT_Inheritan

[clang-tools-extra] r296627 - [clang-tidy] Attempt to fix the test where exceptions are disabled by default.

2017-03-01 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Wed Mar  1 08:41:11 2017
New Revision: 296627

URL: http://llvm.org/viewvc/llvm-project?rev=296627&view=rev
Log:
[clang-tidy] Attempt to fix the test where exceptions are disabled by default.

Modified:
clang-tools-extra/trunk/test/clang-tidy/modernize-use-override.cpp

Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-use-override.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-use-override.cpp?rev=296627&r1=296626&r2=296627&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/modernize-use-override.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-use-override.cpp Wed Mar  
1 08:41:11 2017
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s modernize-use-override %t
+// RUN: %check_clang_tidy %s modernize-use-override %t -- -- -std=c++11 
-fexceptions
 
 #define ABSTRACT = 0
 


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


[PATCH] D30405: [clang-format] Add a new flag FixNamespaceComments to FormatStyle

2017-03-01 Thread Daniel Jasper via Phabricator via cfe-commits
djasper accepted this revision.
djasper added a comment.
This revision is now accepted and ready to land.

LG


https://reviews.llvm.org/D30405



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


[PATCH] D30487: ClangFormat - Add option to break before inheritance separation operator in class declaration

2017-03-01 Thread Sylvestre Ledru via Phabricator via cfe-commits
sylvestre.ledru added inline comments.



Comment at: docs/ClangFormatStyleOptions.rst:430
+  If ``true``, in the class inheritance expression clang-format will
+  break before operands ``:`` and ``,`` only if there is multiple
+  inheritance.

s/is/are/




Comment at: docs/ClangFormatStyleOptions.rst:431
+  break before operands ``:`` and ``,`` only if there is multiple
+  inheritance.
+

s/inheritance/ inheritances/




Comment at: include/clang/Format/Format.h:307
+  /// \brief If ``true``, in the class inheritance expression clang-format will
+  /// break before operands ``:`` and ``,`` only if there is multiple
+  /// inheritance.

same typo


Repository:
  rL LLVM

https://reviews.llvm.org/D30487



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


[PATCH] D30499: [analyzer] pr32088: Don't destroy the temporary if its initializer causes return.

2017-03-01 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ created this revision.

In the following code involving GNU statement-expression extension:

  struct S {
~S();
  };
  
  void foo() {
const S &x = ({ return; S(); });
  }

function `foo()` returns before reference `x` is initialized. We shouldn't call 
the destructor for the temporary object lifetime-exteneded by `x` in this case, 
because the object never gets constructed in the first place.

The real problem is probably in the CFG somewhere, so this is a quick-and-dirty 
hotfix rather than the perfect solution.


https://reviews.llvm.org/D30499

Files:
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  test/Analysis/temporaries.cpp


Index: test/Analysis/temporaries.cpp
===
--- test/Analysis/temporaries.cpp
+++ test/Analysis/temporaries.cpp
@@ -493,3 +493,13 @@
 clang_analyzer_eval(x == 47); // expected-warning{{TRUE}}
   }
 }
+
+namespace PR32088 {
+  void testReturnFromStmtExprInitializer() {
+// We shouldn't try to destroy the object pointed to by `obj' upon return.
+const NonTrivial &obj = ({
+  return; // no-crash
+  NonTrivial(42);
+});
+  }
+}
Index: lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -615,7 +615,15 @@
   const MemRegion *Region = dest.castAs().getRegion();
 
   if (varType->isReferenceType()) {
-Region = state->getSVal(Region).getAsRegion()->getBaseRegion();
+const MemRegion *ValueRegion = state->getSVal(Region).getAsRegion();
+if (!ValueRegion) {
+  // FIXME: This should not happen. The language guarantees a presence
+  // of a valid initializer here, so the reference shall not be undefined.
+  // It seems that we're calling destructors over variables that
+  // were not initialized yet.
+  return;
+}
+Region = ValueRegion->getBaseRegion();
 varType = cast(Region)->getValueType();
   }
 


Index: test/Analysis/temporaries.cpp
===
--- test/Analysis/temporaries.cpp
+++ test/Analysis/temporaries.cpp
@@ -493,3 +493,13 @@
 clang_analyzer_eval(x == 47); // expected-warning{{TRUE}}
   }
 }
+
+namespace PR32088 {
+  void testReturnFromStmtExprInitializer() {
+// We shouldn't try to destroy the object pointed to by `obj' upon return.
+const NonTrivial &obj = ({
+  return; // no-crash
+  NonTrivial(42);
+});
+  }
+}
Index: lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -615,7 +615,15 @@
   const MemRegion *Region = dest.castAs().getRegion();
 
   if (varType->isReferenceType()) {
-Region = state->getSVal(Region).getAsRegion()->getBaseRegion();
+const MemRegion *ValueRegion = state->getSVal(Region).getAsRegion();
+if (!ValueRegion) {
+  // FIXME: This should not happen. The language guarantees a presence
+  // of a valid initializer here, so the reference shall not be undefined.
+  // It seems that we're calling destructors over variables that
+  // were not initialized yet.
+  return;
+}
+Region = ValueRegion->getBaseRegion();
 varType = cast(Region)->getValueType();
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D30373: [analyzer] NFC: Update test infrastructure to support multiple constraint managers

2017-03-01 Thread Dominic Chen via Phabricator via cfe-commits
ddcc added a comment.

With the first method, I'm not sure how to refer to the `AnalyzerTest` class 
defined in `lit.cfg` from `lit.local.cfg`. It doesn't seem to be in scope, so 
unless I store an instantiation in the `config` object, I don't think it's 
accessible.


Repository:
  rL LLVM

https://reviews.llvm.org/D30373



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


[PATCH] D30498: [clangd] Add support for FixIts.

2017-03-01 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added inline comments.



Comment at: clangd/ASTManager.cpp:105
+  std::string Diagnostics;
+  decltype(this->FixIts) LocalFixIts; // Temporary storage
+  for (ASTUnit::stored_diag_iterator D = Unit->stored_diag_begin(),

Why not typedef the type of the FixIts map?



Comment at: clangd/ASTManager.cpp:124
+clangd::Diagnostic Diag = {R, getSeverity(D->getLevel()), D->getMessage()};
+auto &FixIts = LocalFixIts[Diag];
+for (const FixItHint &Fix : D->getFixIts()) {

I prefer this local variable to have a different name.



Comment at: clangd/ASTManager.cpp:134
+std::lock_guard Guard(RequestLock);
+FixIts = std::move(LocalFixIts);
   }

Consider the following situation:
1. worker thread is at line 130 just before the critical section with full info 
about file A in LocalFixits;
main thread takes the lock at line 159 in onDocumentAdd(file B)
2. main thread finishes the critical section, calling CV.notify_one(), which 
has no effect and releases RequestLock.
3. worker thread then gets RequestLock and enters the critical section at line 
133, which outputs essentially stale diagnostics.

Arguably this seems OK, but maybe we want a separate mutex controlling access 
to the FixIts, which also might be more logical.
I can't find a real issue with the code as-is, you can leave it like this, I'm 
just wondering.



Comment at: clangd/clients/clangd-vscode/src/extension.ts:26
+textEditor.edit(mutator => {
+for (let edit of edits) {
+
mutator.replace(vscodelc.Protocol2Code.asRange(edit.range), edit.newText);

Consider using `const` instead of `let`.


https://reviews.llvm.org/D30498



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


r296632 - [clang-format] Add a new flag FixNamespaceComments to FormatStyle

2017-03-01 Thread Krasimir Georgiev via cfe-commits
Author: krasimir
Date: Wed Mar  1 09:35:39 2017
New Revision: 296632

URL: http://llvm.org/viewvc/llvm-project?rev=296632&view=rev
Log:
[clang-format] Add a new flag FixNamespaceComments to FormatStyle

Summary:
This patch enables namespace end comments under a new flag FixNamespaceComments,
which is enabled for the LLVM and Google styles.

Reviewers: djasper

Reviewed By: djasper

Subscribers: cfe-commits, klimek

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

Modified:
cfe/trunk/docs/ClangFormatStyleOptions.rst
cfe/trunk/include/clang/Format/Format.h
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/lib/Index/CommentToXML.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/docs/ClangFormatStyleOptions.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormatStyleOptions.rst?rev=296632&r1=296631&r2=296632&view=diff
==
--- cfe/trunk/docs/ClangFormatStyleOptions.rst (original)
+++ cfe/trunk/docs/ClangFormatStyleOptions.rst Wed Mar  1 09:35:39 2017
@@ -471,6 +471,10 @@ the configuration (without a prefix: ``A
   NOTE: This is an experimental flag, that might go away or be renamed. Do
   not use this in config files, etc. Use at your own risk.
 
+**FixNamespaceComments** (``bool``)
+  If ``true``, clang-format adds missing namespace end comments and
+  fixes invalid existing ones.
+
 **ForEachMacros** (``std::vector``)
   A vector of macros that should be interpreted as foreach loops
   instead of as function calls.
@@ -561,6 +565,9 @@ the configuration (without a prefix: ``A
 
 
 
+**JavaScriptWrapImports** (``bool``)
+  Whether to wrap JavaScript import/export statements.
+
 **KeepEmptyLinesAtTheStartOfBlocks** (``bool``)
   If true, empty lines at the start of blocks are kept.
 
@@ -573,7 +580,7 @@ the configuration (without a prefix: ``A
 Do not use.
 
   * ``LK_Cpp`` (in configuration: ``Cpp``)
-Should be used for C, C++, ObjectiveC, ObjectiveC++.
+Should be used for C, C++.
 
   * ``LK_Java`` (in configuration: ``Java``)
 Should be used for Java.
@@ -581,6 +588,9 @@ the configuration (without a prefix: ``A
   * ``LK_JavaScript`` (in configuration: ``JavaScript``)
 Should be used for JavaScript.
 
+  * ``LK_ObjC`` (in configuration: ``ObjC``)
+Should be used for Objective-C, Objective-C++.
+
   * ``LK_Proto`` (in configuration: ``Proto``)
 Should be used for Protocol Buffers
 (https://developers.google.com/protocol-buffers/).
@@ -755,6 +765,9 @@ the configuration (without a prefix: ``A
   * ``UT_ForIndentation`` (in configuration: ``ForIndentation``)
 Use tabs only for indentation.
 
+  * ``UT_ForContinuationAndIndentation`` (in configuration: 
``ForContinuationAndIndentation``)
+Use tabs only for line continuation and indentation.
+
   * ``UT_Always`` (in configuration: ``Always``)
 Use tabs whenever we need to fill whitespace that spans at least from
 one tab stop to the next one.

Modified: cfe/trunk/include/clang/Format/Format.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=296632&r1=296631&r2=296632&view=diff
==
--- cfe/trunk/include/clang/Format/Format.h (original)
+++ cfe/trunk/include/clang/Format/Format.h Wed Mar  1 09:35:39 2017
@@ -349,6 +349,10 @@ struct FormatStyle {
   /// not use this in config files, etc. Use at your own risk.
   bool ExperimentalAutoDetectBinPacking;
 
+  /// \brief If ``true``, clang-format adds missing namespace end comments and
+  /// fixes invalid existing ones.
+  bool FixNamespaceComments;
+
   /// \brief A vector of macros that should be interpreted as foreach loops
   /// instead of as function calls.
   ///
@@ -679,6 +683,7 @@ struct FormatStyle {
DisableFormat == R.DisableFormat &&
ExperimentalAutoDetectBinPacking ==
R.ExperimentalAutoDetectBinPacking &&
+   FixNamespaceComments == R.FixNamespaceComments &&
ForEachMacros == R.ForEachMacros &&
IncludeCategories == R.IncludeCategories &&
IndentCaseLabels == R.IndentCaseLabels &&

Modified: cfe/trunk/lib/Format/Format.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=296632&r1=296631&r2=296632&view=diff
==
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Wed Mar  1 09:35:39 2017
@@ -308,6 +308,7 @@ template <> struct MappingTraitshttp://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/CommentToXML.cpp?rev=296632&r1=296631&r2=296632&view=diff
==
--- cfe/trunk/lib/Index/CommentToXML.cpp (original)
+++ cfe/trunk/lib/Index/CommentToXML.cpp Wed Mar  1 09:35:39 2017
@@ -593,9 +593,11 @@ void CommentASTToXMLConverter::formatTex
   unsigned

[PATCH] D30405: [clang-format] Add a new flag FixNamespaceComments to FormatStyle

2017-03-01 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL296632: [clang-format] Add a new flag FixNamespaceComments 
to FormatStyle (authored by krasimir).

Changed prior to commit:
  https://reviews.llvm.org/D30405?vs=90172&id=90179#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D30405

Files:
  cfe/trunk/docs/ClangFormatStyleOptions.rst
  cfe/trunk/include/clang/Format/Format.h
  cfe/trunk/lib/Format/Format.cpp
  cfe/trunk/lib/Index/CommentToXML.cpp
  cfe/trunk/unittests/Format/FormatTest.cpp

Index: cfe/trunk/lib/Index/CommentToXML.cpp
===
--- cfe/trunk/lib/Index/CommentToXML.cpp
+++ cfe/trunk/lib/Index/CommentToXML.cpp
@@ -593,9 +593,11 @@
   unsigned Length = Declaration.size();
 
   bool IncompleteFormat = false;
+  format::FormatStyle Style = format::getLLVMStyle();
+  Style.FixNamespaceComments = false;
   tooling::Replacements Replaces =
-  reformat(format::getLLVMStyle(), StringDecl,
-   tooling::Range(Offset, Length), "xmldecl.xd", &IncompleteFormat);
+  reformat(Style, StringDecl, tooling::Range(Offset, Length), "xmldecl.xd",
+   &IncompleteFormat);
   auto FormattedStringDecl = applyAllReplacements(StringDecl, Replaces);
   if (static_cast(FormattedStringDecl)) {
 Declaration = *FormattedStringDecl;
Index: cfe/trunk/lib/Format/Format.cpp
===
--- cfe/trunk/lib/Format/Format.cpp
+++ cfe/trunk/lib/Format/Format.cpp
@@ -308,6 +308,7 @@
 IO.mapOptional("DisableFormat", Style.DisableFormat);
 IO.mapOptional("ExperimentalAutoDetectBinPacking",
Style.ExperimentalAutoDetectBinPacking);
+IO.mapOptional("FixNamespaceComments", Style.FixNamespaceComments);
 IO.mapOptional("ForEachMacros", Style.ForEachMacros);
 IO.mapOptional("IncludeCategories", Style.IncludeCategories);
 IO.mapOptional("IncludeIsMainRegex", Style.IncludeIsMainRegex);
@@ -529,6 +530,7 @@
   LLVMStyle.Cpp11BracedListStyle = true;
   LLVMStyle.DerivePointerAlignment = false;
   LLVMStyle.ExperimentalAutoDetectBinPacking = false;
+  LLVMStyle.FixNamespaceComments = true;
   LLVMStyle.ForEachMacros.push_back("foreach");
   LLVMStyle.ForEachMacros.push_back("Q_FOREACH");
   LLVMStyle.ForEachMacros.push_back("BOOST_FOREACH");
@@ -676,6 +678,7 @@
   MozillaStyle.ConstructorInitializerIndentWidth = 2;
   MozillaStyle.ContinuationIndentWidth = 2;
   MozillaStyle.Cpp11BracedListStyle = false;
+  MozillaStyle.FixNamespaceComments = false;
   MozillaStyle.IndentCaseLabels = true;
   MozillaStyle.ObjCSpaceAfterProperty = true;
   MozillaStyle.ObjCSpaceBeforeProtocolList = false;
@@ -696,6 +699,7 @@
   Style.BreakConstructorInitializersBeforeComma = true;
   Style.Cpp11BracedListStyle = false;
   Style.ColumnLimit = 0;
+  Style.FixNamespaceComments = false;
   Style.IndentWidth = 4;
   Style.NamespaceIndentation = FormatStyle::NI_Inner;
   Style.ObjCBlockIndentWidth = 4;
@@ -713,6 +717,7 @@
   Style.BreakBeforeTernaryOperators = true;
   Style.Cpp11BracedListStyle = false;
   Style.ColumnLimit = 79;
+  Style.FixNamespaceComments = false;
   Style.SpaceBeforeParens = FormatStyle::SBPO_Always;
   Style.Standard = FormatStyle::LS_Cpp03;
   return Style;
@@ -1829,20 +1834,32 @@
 return tooling::Replacements();
   auto Env = Environment::CreateVirtualEnvironment(Code, FileName, Ranges);
 
-  if (Style.Language == FormatStyle::LK_JavaScript &&
-  Style.JavaScriptQuotes != FormatStyle::JSQS_Leave) {
-JavaScriptRequoter Requoter(*Env, Expanded);
-tooling::Replacements Requotes = Requoter.process();
-if (!Requotes.empty()) {
-  auto NewCode = applyAllReplacements(Code, Requotes);
+  auto reformatAfterApplying = [&] (TokenAnalyzer& Fixer) {
+tooling::Replacements Fixes = Fixer.process();
+if (!Fixes.empty()) {
+  auto NewCode = applyAllReplacements(Code, Fixes);
   if (NewCode) {
 auto NewEnv = Environment::CreateVirtualEnvironment(
 *NewCode, FileName,
-tooling::calculateRangesAfterReplacements(Requotes, Ranges));
+tooling::calculateRangesAfterReplacements(Fixes, Ranges));
 Formatter Format(*NewEnv, Expanded, IncompleteFormat);
-return Requotes.merge(Format.process());
+return Fixes.merge(Format.process());
   }
 }
+Formatter Format(*Env, Expanded, IncompleteFormat);
+return Format.process();
+  };
+
+  if (Style.Language == FormatStyle::LK_Cpp &&
+  Style.FixNamespaceComments) {
+NamespaceEndCommentsFixer CommentsFixer(*Env, Expanded);
+return reformatAfterApplying(CommentsFixer);
+  }
+
+  if (Style.Language == FormatStyle::LK_JavaScript &&
+  Style.JavaScriptQuotes != FormatStyle::JSQS_Leave) {
+JavaScriptRequoter Requoter(*Env, Expanded);
+return reformatAfterApplying(Requoter);
   }
 
   Formatter Format(*Env, Expanded, IncompleteFormat);
Index: cfe/trunk/unittests

[PATCH] D30487: ClangFormat - Add option to break before inheritance separation operator in class declaration

2017-03-01 Thread Daniel Jasper via Phabricator via cfe-commits
djasper added a comment.

Could you please upload a diff with the entire file as context? That makes 
reviewing this easier.




Comment at: docs/ClangFormatStyleOptions.rst:428
 
+**BreakBeforeInhertianceDelimiter** (``boolt``)
+  If ``true``, in the class inheritance expression clang-format will

Auto-generate this with docs/tools/dump_format_style.py



Comment at: include/clang/Format/Format.h:309
+  /// inheritance.
+  bool BreakBeforeInhertianceDelimiter;
+  

s/Delimiter/Colon/

Not because it is better, but just because it's more consistent with much of 
the rest of clang-format.



Comment at: lib/Format/TokenAnnotator.cpp:950
 bool InCtorInitializer = false;
+bool InInhertiance = false;
 bool CaretFound = false;

Maybe "InInheritanceList"?



Comment at: lib/Format/TokenAnnotator.cpp:1012
+   Current.Previous->is(TT_InheritanceColon)) {
+  Contexts.back().IsExpression = true;
+  Contexts.back().InInhertiance = true;

Why would we be in an expression here?



Comment at: lib/Format/TokenAnnotator.cpp:2398
 
+// Determine if the next token from the closing scope is an inheritance token
+static bool hasMultipleInheritance(const FormatToken &Tok) {

I don't understand this comment or what the function is supposed to do. It 
seems to search whether there is an inheritance comma somewhere in the rest of 
the line.



Comment at: lib/Format/TokenAnnotator.cpp:2490
 return true;
+  //Break only if we have multiple inheritance
+  if (Style.BreakBeforeInhertianceDelimiter &&

nit: Use periods of the end of sentences and a space after //.



Comment at: unittests/Format/FormatTest.cpp:1023
 
+TEST_F(FormatTest, BreakBeforeInhertianceDelimiter) {
+  FormatStyle StyleWithInheritanceBreak = getLLVMStyle();

I am missing tests that show the behavior when there are multiple base classes, 
but they do fit on one line.



Comment at: unittests/Format/FormatTest.cpp:1033
+   StyleWithInheritanceBreak);
+  verifyFormat("class MyClass"
+   "  : public X\n"

What is this supposed to test?



Comment at: unittests/Format/FormatTest.cpp:1039
+  verifyFormat("class MyClass\n"
+   ": public X // When deriving from more than one class, put "
+   "each on its own\n"

Sure, but the comment is forcing that, so I don't know what this test does.


Repository:
  rL LLVM

https://reviews.llvm.org/D30487



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


[PATCH] D30111: [clang-format] Add a test to check at once all the Mozilla coding style

2017-03-01 Thread Sylvestre Ledru via Phabricator via cfe-commits
sylvestre.ledru added a comment.

Manuel, is that ok with you? thanks (I will rename the file)


https://reviews.llvm.org/D30111



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


[PATCH] D30498: [clangd] Add support for FixIts.

2017-03-01 Thread Benjamin Kramer via Phabricator via cfe-commits
bkramer updated this revision to Diff 90181.
bkramer added a comment.

- Use typedef instead of decltype()
- Rename local variable not to shadow member.
- Give FixIts their own mutex
- Use const instead of let in typescript


https://reviews.llvm.org/D30498

Files:
  clangd/ASTManager.cpp
  clangd/ASTManager.h
  clangd/ClangDMain.cpp
  clangd/Protocol.cpp
  clangd/Protocol.h
  clangd/ProtocolHandlers.cpp
  clangd/ProtocolHandlers.h
  clangd/clients/clangd-vscode/src/extension.ts
  test/clangd/fixits.test
  test/clangd/formatting.test

Index: test/clangd/formatting.test
===
--- test/clangd/formatting.test
+++ test/clangd/formatting.test
@@ -4,12 +4,13 @@
 Content-Length: 125
 
 {"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
-# CHECK: Content-Length: 294
+# CHECK: Content-Length: 332
 # CHECK: {"jsonrpc":"2.0","id":0,"result":{"capabilities":{
 # CHECK:   "textDocumentSync": 1,
 # CHECK:   "documentFormattingProvider": true,
 # CHECK:   "documentRangeFormattingProvider": true,
-# CHECK:   "documentOnTypeFormattingProvider": {"firstTriggerCharacter":"}","moreTriggerCharacter":[]}
+# CHECK:   "documentOnTypeFormattingProvider": {"firstTriggerCharacter":"}","moreTriggerCharacter":[]},
+# CHECK:   "codeActionProvider": true
 # CHECK: }}}
 #
 Content-Length: 193
Index: test/clangd/fixits.test
===
--- /dev/null
+++ test/clangd/fixits.test
@@ -0,0 +1,22 @@
+# RUN: clangd -run-synchronously < %s | FileCheck %s
+# It is absolutely vital that this file has CRLF line endings.
+#
+Content-Length: 125
+
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
+#
+Content-Length: 180
+
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///foo.c","languageId":"c","version":1,"text":"int main(int i, char **a) { if (i = 2) {}}"}}}
+#
+# CHECK: {"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///foo.c","diagnostics":[{"range":{"start": {"line": 0, "character": 35}, "end": {"line": 0, "character": 35}},"severity":2,"message":"using the result of an assignment as a condition without parentheses"},{"range":{"start": {"line": 0, "character": 35}, "end": {"line": 0, "character": 35}},"severity":3,"message":"place parentheses around the assignment to silence this warning"},{"range":{"start": {"line": 0, "character": 35}, "end": {"line": 0, "character": 35}},"severity":3,"message":"use '==' to turn this assignment into an equality comparison"}]}}
+#
+Content-Length: 746
+
+ {"jsonrpc":"2.0","id":2,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"file:///foo.c"},"range":{"start":{"line":104,"character":13},"end":{"line":0,"character":35}},"context":{"diagnostics":[{"range":{"start": {"line": 0, "character": 35}, "end": {"line": 0, "character": 35}},"severity":2,"message":"using the result of an assignment as a condition without parentheses"},{"range":{"start": {"line": 0, "character": 35}, "end": {"line": 0, "character": 35}},"severity":3,"message":"place parentheses around the assignment to silence this warning"},{"range":{"start": {"line": 0, "character": 35}, "end": {"line": 0, "character": 35}},"severity":3,"message":"use '==' to turn this assignment into an equality comparison"}]}}}
+#
+# CHECK: {"jsonrpc":"2.0","id":2, "result": [{"title":"Apply FixIt 'place parentheses around the assignment to silence this warning'", "command": "clangd.applyFix", "arguments": ["file:///foo.c", [{"range": {"start": {"line": 0, "character": 32}, "end": {"line": 0, "character": 32}}, "newText": "("},{"range": {"start": {"line": 0, "character": 37}, "end": {"line": 0, "character": 37}}, "newText": ")"}]]},{"title":"Apply FixIt 'use '==' to turn this assignment into an equality comparison'", "command": "clangd.applyFix", "arguments": ["file:///foo.c", [{"range": {"start": {"line": 0, "character": 34}, "end": {"line": 0, "character": 35}}, "newText": "=="}]]}]
+#
+Content-Length: 44
+
+{"jsonrpc":"2.0","id":3,"method":"shutdown"}
Index: clangd/clients/clangd-vscode/src/extension.ts
===
--- clangd/clients/clangd-vscode/src/extension.ts
+++ clangd/clients/clangd-vscode/src/extension.ts
@@ -18,9 +18,25 @@
 
 const clangdClient = new vscodelc.LanguageClient('Clang Language Server', serverOptions, clientOptions);
 
+function applyTextEdits(uri: string, edits: vscodelc.TextEdit[]) {
+let textEditor = vscode.window.activeTextEditor;
+
+if (textEditor && textEditor.document.uri.toString() === uri) {
+textEditor.edit(mutator => {
+for (const edit of edits) {
+mutator.replace(vscodelc.Protocol2Code.asRange(edit.range), edit.newText);
+}
+}

[PATCH] D30498: [clangd] Add support for FixIts.

2017-03-01 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir accepted this revision.
krasimir added a comment.
This revision is now accepted and ready to land.

Looks Great!


https://reviews.llvm.org/D30498



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


[PATCH] D30326: [MS-ABI] Allow #pragma section to choose for ZI data

2017-03-01 Thread Javed Absar via Phabricator via cfe-commits
javed.absar added a comment.

Hi Nico:
This is for the case when using  '#pragma bss_seg..' feature outside of msvc 
context. That's the reason for the flag.
One could use attribute, but as attribute is attached to individual 
declaration, while pragma applies to whole file (unless superseded by another 
pragma),  the latter is easier to use in some cases (i.e. when there are lots 
of such declarations). Hope this clarifies the question you asked.
Best Regards
Javed


https://reviews.llvm.org/D30326



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


[clang-tools-extra] r296636 - [clangd] Add support for FixIts.

2017-03-01 Thread Benjamin Kramer via cfe-commits
Author: d0k
Date: Wed Mar  1 10:16:29 2017
New Revision: 296636

URL: http://llvm.org/viewvc/llvm-project?rev=296636&view=rev
Log:
[clangd] Add support for FixIts.

Summary:
This uses CodeActions to show 'apply fix' actions when code actions are
requested for a location. The actions themselves make use of a
clangd.applyFix command which has to be implemented on the editor side. I
included an implementation for vscode.

This also adds a -run-synchronously flag which runs everything on the main
thread. This is useful for testing.

Reviewers: krasimir

Subscribers: cfe-commits

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

Added:
clang-tools-extra/trunk/test/clangd/fixits.test
Modified:
clang-tools-extra/trunk/clangd/ASTManager.cpp
clang-tools-extra/trunk/clangd/ASTManager.h
clang-tools-extra/trunk/clangd/ClangDMain.cpp
clang-tools-extra/trunk/clangd/Protocol.cpp
clang-tools-extra/trunk/clangd/Protocol.h
clang-tools-extra/trunk/clangd/ProtocolHandlers.cpp
clang-tools-extra/trunk/clangd/ProtocolHandlers.h
clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/extension.ts
clang-tools-extra/trunk/test/clangd/formatting.test

Modified: clang-tools-extra/trunk/clangd/ASTManager.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ASTManager.cpp?rev=296636&r1=296635&r2=296636&view=diff
==
--- clang-tools-extra/trunk/clangd/ASTManager.cpp (original)
+++ clang-tools-extra/trunk/clangd/ASTManager.cpp Wed Mar  1 10:16:29 2017
@@ -54,8 +54,9 @@ static int getSeverity(DiagnosticsEngine
   llvm_unreachable("Unknown diagnostic level!");
 }
 
-ASTManager::ASTManager(JSONOutput &Output, DocumentStore &Store)
-: Output(Output), Store(Store),
+ASTManager::ASTManager(JSONOutput &Output, DocumentStore &Store,
+   bool RunSynchronously)
+: Output(Output), Store(Store), RunSynchronously(RunSynchronously),
   PCHs(std::make_shared()),
   ClangWorker([this]() { runWorker(); }) {}
 
@@ -67,9 +68,8 @@ void ASTManager::runWorker() {
   std::unique_lock Lock(RequestLock);
   // Check if there's another request pending. We keep parsing until
   // our one-element queue is empty.
-  ClangRequestCV.wait(Lock, [this] {
-return !RequestQueue.empty() || Done;
-  });
+  ClangRequestCV.wait(Lock,
+  [this] { return !RequestQueue.empty() || Done; });
 
   if (RequestQueue.empty() && Done)
 return;
@@ -78,49 +78,67 @@ void ASTManager::runWorker() {
   RequestQueue.pop_back();
 } // unlock.
 
-auto &Unit = ASTs[File]; // Only one thread can access this at a time.
+parseFileAndPublishDiagnostics(File);
+  }
+}
 
-if (!Unit) {
-  Unit = createASTUnitForFile(File, this->Store);
-} else {
-  // Do a reparse if this wasn't the first parse.
-  // FIXME: This might have the wrong working directory if it changed in 
the
-  // meantime.
-  Unit->Reparse(PCHs, getRemappedFiles(this->Store));
-}
+void ASTManager::parseFileAndPublishDiagnostics(StringRef File) {
+  auto &Unit = ASTs[File]; // Only one thread can access this at a time.
 
-if (!Unit)
-  continue;
+  if (!Unit) {
+Unit = createASTUnitForFile(File, this->Store);
+  } else {
+// Do a reparse if this wasn't the first parse.
+// FIXME: This might have the wrong working directory if it changed in the
+// meantime.
+Unit->Reparse(PCHs, getRemappedFiles(this->Store));
+  }
+
+  if (!Unit)
+return;
 
-// Send the diagnotics to the editor.
-// FIXME: If the diagnostic comes from a different file, do we want to
-// show them all? Right now we drop everything not coming from the
-// main file.
-// FIXME: Send FixIts to the editor.
-std::string Diagnostics;
-for (ASTUnit::stored_diag_iterator D = Unit->stored_diag_begin(),
-   DEnd = Unit->stored_diag_end();
- D != DEnd; ++D) {
-  if (!D->getLocation().isValid() ||
-  !D->getLocation().getManager().isInMainFile(D->getLocation()))
-continue;
-  Position P;
-  P.line = D->getLocation().getSpellingLineNumber() - 1;
-  P.character = D->getLocation().getSpellingColumnNumber();
-  Range R = {P, P};
-  Diagnostics +=
-  R"({"range":)" + Range::unparse(R) +
-  R"(,"severity":)" + std::to_string(getSeverity(D->getLevel())) +
-  R"(,"message":")" + llvm::yaml::escape(D->getMessage()) +
-  R"("},)";
+  // Send the diagnotics to the editor.
+  // FIXME: If the diagnostic comes from a different file, do we want to
+  // show them all? Right now we drop everything not coming from the
+  // main file.
+  std::string Diagnostics;
+  DiagnosticToReplacementMap LocalFixIts; // Temporary storage
+  for (ASTUnit::stored_diag_iterator D = Unit->stored_diag_begin(),
+ DEn

[PATCH] D30498: [clangd] Add support for FixIts.

2017-03-01 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL296636: [clangd] Add support for FixIts. (authored by d0k).

Changed prior to commit:
  https://reviews.llvm.org/D30498?vs=90181&id=90187#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D30498

Files:
  clang-tools-extra/trunk/clangd/ASTManager.cpp
  clang-tools-extra/trunk/clangd/ASTManager.h
  clang-tools-extra/trunk/clangd/ClangDMain.cpp
  clang-tools-extra/trunk/clangd/Protocol.cpp
  clang-tools-extra/trunk/clangd/Protocol.h
  clang-tools-extra/trunk/clangd/ProtocolHandlers.cpp
  clang-tools-extra/trunk/clangd/ProtocolHandlers.h
  clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/extension.ts
  clang-tools-extra/trunk/test/clangd/fixits.test
  clang-tools-extra/trunk/test/clangd/formatting.test

Index: clang-tools-extra/trunk/clangd/ClangDMain.cpp
===
--- clang-tools-extra/trunk/clangd/ClangDMain.cpp
+++ clang-tools-extra/trunk/clangd/ClangDMain.cpp
@@ -11,13 +11,20 @@
 #include "DocumentStore.h"
 #include "JSONRPCDispatcher.h"
 #include "ProtocolHandlers.h"
+#include "llvm/Support/CommandLine.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Program.h"
 #include 
 #include 
 using namespace clang::clangd;
 
+static llvm::cl::opt
+RunSynchronously("run-synchronously",
+ llvm::cl::desc("parse on main thread"),
+ llvm::cl::init(false), llvm::cl::Hidden);
+
 int main(int argc, char *argv[]) {
+  llvm::cl::ParseCommandLineOptions(argc, argv, "clangd");
   llvm::raw_ostream &Outs = llvm::outs();
   llvm::raw_ostream &Logs = llvm::errs();
   JSONOutput Out(Outs, Logs);
@@ -28,14 +35,14 @@
   // Set up a document store and intialize all the method handlers for JSONRPC
   // dispatching.
   DocumentStore Store;
-  ASTManager AST(Out, Store);
+  ASTManager AST(Out, Store, RunSynchronously);
   Store.addListener(&AST);
   JSONRPCDispatcher Dispatcher(llvm::make_unique(Out));
   Dispatcher.registerHandler("initialize",
  llvm::make_unique(Out));
   auto ShutdownPtr = llvm::make_unique(Out);
   auto *ShutdownHandler = ShutdownPtr.get();
-  Dispatcher.registerHandler("shutdown",std::move(ShutdownPtr));
+  Dispatcher.registerHandler("shutdown", std::move(ShutdownPtr));
   Dispatcher.registerHandler(
   "textDocument/didOpen",
   llvm::make_unique(Out, Store));
@@ -52,6 +59,8 @@
   Dispatcher.registerHandler(
   "textDocument/formatting",
   llvm::make_unique(Out, Store));
+  Dispatcher.registerHandler("textDocument/codeAction",
+ llvm::make_unique(Out, AST));
 
   while (std::cin.good()) {
 // A Language Server Protocol message starts with a HTTP header, delimited
Index: clang-tools-extra/trunk/clangd/ProtocolHandlers.h
===
--- clang-tools-extra/trunk/clangd/ProtocolHandlers.h
+++ clang-tools-extra/trunk/clangd/ProtocolHandlers.h
@@ -22,6 +22,7 @@
 
 namespace clang {
 namespace clangd {
+class ASTManager;
 class DocumentStore;
 
 struct InitializeHandler : Handler {
@@ -34,7 +35,8 @@
   "textDocumentSync": 1,
   "documentFormattingProvider": true,
   "documentRangeFormattingProvider": true,
-  "documentOnTypeFormattingProvider": {"firstTriggerCharacter":"}","moreTriggerCharacter":[]}
+  "documentOnTypeFormattingProvider": {"firstTriggerCharacter":"}","moreTriggerCharacter":[]},
+  "codeActionProvider": true
 }}})");
   }
 };
@@ -102,6 +104,16 @@
   DocumentStore &Store;
 };
 
+struct CodeActionHandler : Handler {
+  CodeActionHandler(JSONOutput &Output, ASTManager &AST)
+  : Handler(Output), AST(AST) {}
+
+  void handleMethod(llvm::yaml::MappingNode *Params, StringRef ID) override;
+
+private:
+  ASTManager &AST;
+};
+
 } // namespace clangd
 } // namespace clang
 
Index: clang-tools-extra/trunk/clangd/ASTManager.h
===
--- clang-tools-extra/trunk/clangd/ASTManager.h
+++ clang-tools-extra/trunk/clangd/ASTManager.h
@@ -12,6 +12,8 @@
 
 #include "DocumentStore.h"
 #include "JSONRPCDispatcher.h"
+#include "Protocol.h"
+#include "clang/Tooling/Core/Replacement.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include 
 #include 
@@ -29,17 +31,27 @@
 
 class ASTManager : public DocumentStoreListener {
 public:
-  ASTManager(JSONOutput &Output, DocumentStore &Store);
+  ASTManager(JSONOutput &Output, DocumentStore &Store, bool RunSynchronously);
   ~ASTManager() override;
 
   void onDocumentAdd(StringRef Uri) override;
   // FIXME: Implement onDocumentRemove
   // FIXME: Implement codeComplete
 
+  /// Get the fixes associated with a certain diagnostic as replacements.
+  llvm::ArrayRef
+  getFixIts(const clangd::Diagnostic &D);
+
+  DocumentStore &getStore() const { return Store; }
+
 private:
   JSONOutput &Output;
   DocumentStore &Store;

[clang-tools-extra] r296637 - [clangd] Unbreak the shared build.

2017-03-01 Thread Benjamin Kramer via cfe-commits
Author: d0k
Date: Wed Mar  1 10:23:40 2017
New Revision: 296637

URL: http://llvm.org/viewvc/llvm-project?rev=296637&view=rev
Log:
[clangd] Unbreak the shared build.

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

Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CMakeLists.txt?rev=296637&r1=296636&r2=296637&view=diff
==
--- clang-tools-extra/trunk/clangd/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clangd/CMakeLists.txt Wed Mar  1 10:23:40 2017
@@ -13,5 +13,6 @@ target_link_libraries(clangd
   clangFormat
   clangFrontend
   clangTooling
+  clangToolingCore
   LLVMSupport
   )


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


[PATCH] D30326: [MS-ABI] Allow #pragma section to choose for ZI data

2017-03-01 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Adding incompatible extensions to MS extensions sounds like bad precedent to 
me. I think it'd be good if a code owner could opine on this change before it 
goes in.


https://reviews.llvm.org/D30326



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


[PATCH] D30499: [analyzer] pr32088: Don't destroy the temporary if its initializer causes return.

2017-03-01 Thread Devin Coughlin via Phabricator via cfe-commits
dcoughlin accepted this revision.
dcoughlin added a comment.
This revision is now accepted and ready to land.

Seems like a safe quick fix for the crash. Looks good to me!


https://reviews.llvm.org/D30499



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


r296638 - [clang-format] Don't add namespace end comments for unbalanced right braces after namespace end

2017-03-01 Thread Krasimir Georgiev via cfe-commits
Author: krasimir
Date: Wed Mar  1 10:38:08 2017
New Revision: 296638

URL: http://llvm.org/viewvc/llvm-project?rev=296638&view=rev
Log:
[clang-format] Don't add namespace end comments for unbalanced right braces 
after namespace end

Modified:
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/unittests/Format/NamespaceEndCommentsFixerTest.cpp

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=296638&r1=296637&r2=296638&view=diff
==
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Wed Mar  1 10:38:08 2017
@@ -2048,6 +2048,7 @@ void UnwrappedLineParser::addUnwrappedLi
   });
   CurrentLines->push_back(std::move(*Line));
   Line->Tokens.clear();
+  Line->MatchingOpeningBlockLineIndex = UnwrappedLine::kInvalidIndex;
   if (CurrentLines == &Lines && !PreprocessorDirectives.empty()) {
 CurrentLines->append(
 std::make_move_iterator(PreprocessorDirectives.begin()),

Modified: cfe/trunk/unittests/Format/NamespaceEndCommentsFixerTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/NamespaceEndCommentsFixerTest.cpp?rev=296638&r1=296637&r2=296638&view=diff
==
--- cfe/trunk/unittests/Format/NamespaceEndCommentsFixerTest.cpp (original)
+++ cfe/trunk/unittests/Format/NamespaceEndCommentsFixerTest.cpp Wed Mar  1 
10:38:08 2017
@@ -345,6 +345,18 @@ TEST_F(NamespaceEndCommentsFixerTest,
 "}\n"
 "}\n"));
 }
+
+TEST_F(NamespaceEndCommentsFixerTest,
+   DoesNotAddEndCommentForUnbalancedRBracesAfterNamespaceEnd) {
+  EXPECT_EQ("namespace {\n"
+"  int i;\n"
+"} // namespace\n"
+"}",
+fixNamespaceEndComments("namespace {\n"
+"  int i;\n"
+"} // namespace\n"
+"}"));
+}
 } // end namespace
 } // end namespace format
 } // end namespace clang


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


Re: [libcxx] r296561 - Fix PR32097 - is_abstract doesn't work on class templates.

2017-03-01 Thread Hans Wennborg via cfe-commits
We're at the "should have tagged 'final' days ago" stage :-)

Since it's not a regression, I would prefer not to merge it unless you
feel super strongly about it.

Sounds like a good candidate for 4.0.1 (tracking bug is PR32061).

Thanks,
Hans

On Wed, Mar 1, 2017 at 1:36 AM, Eric Fiselier  wrote:
> @Hans Where are we in the release process? I would like to merge this into
> 4.0.
>
> Although it's not a regression, it is a significant bug. This patch fixes
> the bug by
> forwarding to a compiler builtin, which is strictly better than what we
> have. I'm
> confident this patch is safe.
>
> /Eric
>
> On Tue, Feb 28, 2017 at 6:27 PM, Eric Fiselier via cfe-commits
>  wrote:
>>
>> Author: ericwf
>> Date: Tue Feb 28 19:27:14 2017
>> New Revision: 296561
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=296561&view=rev
>> Log:
>> Fix PR32097 - is_abstract doesn't work on class templates.
>>
>> This patch fixes llvm.org/PR32097 by using the __is_abstract
>> builtin type-trait instead of the previous library-only implementation.
>>
>> All supported compilers provide this trait. I've tested as far
>> back as Clang 3.2, GCC 4.6 and MSVC trunk.
>>
>> Modified:
>> libcxx/trunk/include/type_traits
>>
>> libcxx/trunk/test/std/utilities/meta/meta.unary/meta.unary.prop/is_abstract.pass.cpp
>>
>> Modified: libcxx/trunk/include/type_traits
>> URL:
>> http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/type_traits?rev=296561&r1=296560&r2=296561&view=diff
>>
>> ==
>> --- libcxx/trunk/include/type_traits (original)
>> +++ libcxx/trunk/include/type_traits Tue Feb 28 19:27:14 2017
>> @@ -1297,18 +1297,8 @@ template  using decay_t = typ
>>
>>  // is_abstract
>>
>> -namespace __is_abstract_imp
>> -{
>> -template  char  __test(_Tp (*)[1]);
>> -template  __two __test(...);
>> -}
>> -
>> -template ::value>
>> -struct __libcpp_abstract : public integral_constant> sizeof(__is_abstract_imp::__test<_Tp>(0)) != 1> {};
>> -
>> -template  struct __libcpp_abstract<_Tp, false> : public
>> false_type {};
>> -
>> -template  struct _LIBCPP_TEMPLATE_VIS is_abstract : public
>> __libcpp_abstract<_Tp> {};
>> +template  struct _LIBCPP_TEMPLATE_VIS is_abstract
>> +: public integral_constant {};
>>
>>  #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
>>  template  _LIBCPP_CONSTEXPR bool is_abstract_v
>>
>> Modified:
>> libcxx/trunk/test/std/utilities/meta/meta.unary/meta.unary.prop/is_abstract.pass.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/meta/meta.unary/meta.unary.prop/is_abstract.pass.cpp?rev=296561&r1=296560&r2=296561&view=diff
>>
>> ==
>> ---
>> libcxx/trunk/test/std/utilities/meta/meta.unary/meta.unary.prop/is_abstract.pass.cpp
>> (original)
>> +++
>> libcxx/trunk/test/std/utilities/meta/meta.unary/meta.unary.prop/is_abstract.pass.cpp
>> Tue Feb 28 19:27:14 2017
>> @@ -65,6 +65,14 @@ class Abstract
>>  virtual ~Abstract() = 0;
>>  };
>>
>> +template 
>> +struct AbstractTemplate {
>> +  virtual void test() = 0;
>> +};
>> +
>> +template <>
>> +struct AbstractTemplate {};
>> +
>>  int main()
>>  {
>>  test_is_not_abstract();
>> @@ -81,4 +89,6 @@ int main()
>>  test_is_not_abstract();
>>
>>  test_is_abstract();
>> +test_is_abstract >();
>> +test_is_not_abstract >();
>>  }
>>
>>
>> ___
>> 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


LLVM buildmaster will be updated and restarted tonight

2017-03-01 Thread Galina Kistanova via cfe-commits
Hello everyone,

LLVM buildmaster will be updated and restarted after 6 PM Pacific time
today.

Thanks

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


[PATCH] D30345: [CodeGen][Blocks] Refactor capture handling in code that generates block copy/destroy routines

2017-03-01 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman updated this revision to Diff 90197.
arphaman marked 4 inline comments as done.
arphaman added a comment.

Addressed John's comments.


Repository:
  rL LLVM

https://reviews.llvm.org/D30345

Files:
  lib/CodeGen/CGBlocks.cpp

Index: lib/CodeGen/CGBlocks.cpp
===
--- lib/CodeGen/CGBlocks.cpp
+++ lib/CodeGen/CGBlocks.cpp
@@ -1373,6 +1373,103 @@
   return fn;
 }
 
+namespace {
+
+/// Represents a type of copy/destroy operation that should be performed for an
+/// entity that's captured by a block.
+enum class BlockCaptureEntityKind {
+  CXXRecord, // Copy or destroy
+  ARCWeak,
+  ARCStrong,
+  BlockObject, // Assign or release
+  None
+};
+
+/// Represents a captured entity that requires extra operations in order for
+/// this entity to be copied or destroyed correctly.
+struct BlockCaptureManagedEntity {
+  BlockCaptureEntityKind Kind;
+  BlockFieldFlags Flags;
+  const BlockDecl::Capture &CI;
+  const CGBlockInfo::Capture &Capture;
+
+  BlockCaptureManagedEntity(BlockCaptureEntityKind Type, BlockFieldFlags Flags,
+const BlockDecl::Capture &CI,
+const CGBlockInfo::Capture &Capture)
+  : Kind(Type), Flags(Flags), CI(CI), Capture(Capture) {}
+};
+
+} // end anonymous namespace
+
+static std::pair
+computeCopyInfoForBlockCapture(const BlockDecl::Capture &CI, QualType T,
+   const LangOptions &LangOpts) {
+  if (CI.getCopyExpr()) {
+assert(!CI.isByRef());
+// don't bother computing flags
+return std::make_pair(BlockCaptureEntityKind::CXXRecord, BlockFieldFlags());
+  }
+  BlockFieldFlags Flags;
+  if (CI.isByRef()) {
+Flags = BLOCK_FIELD_IS_BYREF;
+if (T.isObjCGCWeak())
+  Flags |= BLOCK_FIELD_IS_WEAK;
+return std::make_pair(BlockCaptureEntityKind::BlockObject, Flags);
+  }
+  if (!T->isObjCRetainableType())
+// For all other types, the memcpy is fine.
+return std::make_pair(BlockCaptureEntityKind::None, Flags);
+
+  Flags = BLOCK_FIELD_IS_OBJECT;
+  bool isBlockPointer = T->isBlockPointerType();
+  if (isBlockPointer)
+Flags = BLOCK_FIELD_IS_BLOCK;
+
+  // Special rules for ARC captures:
+  Qualifiers QS = T.getQualifiers();
+
+  // We need to register __weak direct captures with the runtime.
+  if (QS.getObjCLifetime() == Qualifiers::OCL_Weak)
+return std::make_pair(BlockCaptureEntityKind::ARCWeak, Flags);
+
+  // We need to retain the copied value for __strong direct captures.
+  if (QS.getObjCLifetime() == Qualifiers::OCL_Strong) {
+// If it's a block pointer, we have to copy the block and
+// assign that to the destination pointer, so we might as
+// well use _Block_object_assign.  Otherwise we can avoid that.
+return std::make_pair(!isBlockPointer ? BlockCaptureEntityKind::ARCStrong
+  : BlockCaptureEntityKind::BlockObject,
+  Flags);
+  }
+
+  // Non-ARC captures of retainable pointers are strong and
+  // therefore require a call to _Block_object_assign.
+  if (!QS.getObjCLifetime() && !LangOpts.ObjCAutoRefCount)
+return std::make_pair(BlockCaptureEntityKind::BlockObject, Flags);
+
+  // Otherwise the memcpy is fine.
+  return std::make_pair(BlockCaptureEntityKind::None, Flags);
+}
+
+/// Find the set of block captures that need to be explicitly copied or destroy.
+static void findBlockCapturedManagedEntities(
+const CGBlockInfo &BlockInfo, const LangOptions &LangOpts,
+SmallVectorImpl &ManagedCaptures,
+llvm::function_ref(
+const BlockDecl::Capture &, QualType, const LangOptions &)>
+Predicate) {
+  for (const auto &CI : BlockInfo.getBlockDecl()->captures()) {
+const VarDecl *Variable = CI.getVariable();
+const CGBlockInfo::Capture &Capture = BlockInfo.getCapture(Variable);
+if (Capture.isConstant())
+  continue;
+
+auto Info = Predicate(CI, Variable->getType(), LangOpts);
+if (Info.first != BlockCaptureEntityKind::None)
+  ManagedCaptures.emplace_back(Info.first, Info.second, CI, Capture);
+  }
+}
+
 /// Generate the copy-helper function for a block closure object:
 ///   static void block_copy_helper(block_t *dst, block_t *src);
 /// The runtime will have previously initialized 'dst' by doing a
@@ -1431,78 +1528,28 @@
   dst = Address(Builder.CreateLoad(dst), blockInfo.BlockAlign);
   dst = Builder.CreateBitCast(dst, structPtrTy, "block.dest");
 
-  const BlockDecl *blockDecl = blockInfo.getBlockDecl();
-
-  for (const auto &CI : blockDecl->captures()) {
-const VarDecl *variable = CI.getVariable();
-QualType type = variable->getType();
-
-const CGBlockInfo::Capture &capture = blockInfo.getCapture(variable);
-if (capture.isConstant()) continue;
-
-const Expr *copyExpr = CI.getCopyExpr();
-BlockFieldFlags flags;
+  SmallVector CopiedCaptures;
+  findBlockCapturedManagedEntities(blockInfo, getLangOpts(), CopiedCaptures,
+

[PATCH] D30499: [analyzer] pr32088: Don't destroy the temporary if its initializer causes return.

2017-03-01 Thread Devin Coughlin via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL296646: [analyzer] pr32088: Don't destroy the temporary if 
its initializer causes… (authored by dcoughlin).

Changed prior to commit:
  https://reviews.llvm.org/D30499?vs=90178&id=90201#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D30499

Files:
  cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
  cfe/trunk/test/Analysis/temporaries.cpp


Index: cfe/trunk/test/Analysis/temporaries.cpp
===
--- cfe/trunk/test/Analysis/temporaries.cpp
+++ cfe/trunk/test/Analysis/temporaries.cpp
@@ -493,3 +493,13 @@
 clang_analyzer_eval(x == 47); // expected-warning{{TRUE}}
   }
 }
+
+namespace PR32088 {
+  void testReturnFromStmtExprInitializer() {
+// We shouldn't try to destroy the object pointed to by `obj' upon return.
+const NonTrivial &obj = ({
+  return; // no-crash
+  NonTrivial(42);
+});
+  }
+}
Index: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -615,7 +615,15 @@
   const MemRegion *Region = dest.castAs().getRegion();
 
   if (varType->isReferenceType()) {
-Region = state->getSVal(Region).getAsRegion()->getBaseRegion();
+const MemRegion *ValueRegion = state->getSVal(Region).getAsRegion();
+if (!ValueRegion) {
+  // FIXME: This should not happen. The language guarantees a presence
+  // of a valid initializer here, so the reference shall not be undefined.
+  // It seems that we're calling destructors over variables that
+  // were not initialized yet.
+  return;
+}
+Region = ValueRegion->getBaseRegion();
 varType = cast(Region)->getValueType();
   }
 


Index: cfe/trunk/test/Analysis/temporaries.cpp
===
--- cfe/trunk/test/Analysis/temporaries.cpp
+++ cfe/trunk/test/Analysis/temporaries.cpp
@@ -493,3 +493,13 @@
 clang_analyzer_eval(x == 47); // expected-warning{{TRUE}}
   }
 }
+
+namespace PR32088 {
+  void testReturnFromStmtExprInitializer() {
+// We shouldn't try to destroy the object pointed to by `obj' upon return.
+const NonTrivial &obj = ({
+  return; // no-crash
+  NonTrivial(42);
+});
+  }
+}
Index: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -615,7 +615,15 @@
   const MemRegion *Region = dest.castAs().getRegion();
 
   if (varType->isReferenceType()) {
-Region = state->getSVal(Region).getAsRegion()->getBaseRegion();
+const MemRegion *ValueRegion = state->getSVal(Region).getAsRegion();
+if (!ValueRegion) {
+  // FIXME: This should not happen. The language guarantees a presence
+  // of a valid initializer here, so the reference shall not be undefined.
+  // It seems that we're calling destructors over variables that
+  // were not initialized yet.
+  return;
+}
+Region = ValueRegion->getBaseRegion();
 varType = cast(Region)->getValueType();
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r296646 - [analyzer] pr32088: Don't destroy the temporary if its initializer causes return.

2017-03-01 Thread Devin Coughlin via cfe-commits
Author: dcoughlin
Date: Wed Mar  1 11:48:39 2017
New Revision: 296646

URL: http://llvm.org/viewvc/llvm-project?rev=296646&view=rev
Log:
[analyzer] pr32088: Don't destroy the temporary if its initializer causes 
return.

In the following code involving GNU statement-expression extension:
  struct S {
~S();
  };

  void foo() {
const S &x = ({ return; S(); });
  }
function 'foo()' returns before reference x is initialized. We shouldn't call
the destructor for the temporary object lifetime-extended by 'x' in this case,
because the object never gets constructed in the first place.

The real problem is probably in the CFG somewhere, so this is a quick-and-dirty
hotfix rather than the perfect solution.

A patch by Artem Dergachev!

rdar://problem/30759076

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

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
cfe/trunk/test/Analysis/temporaries.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp?rev=296646&r1=296645&r2=296646&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp Wed Mar  1 11:48:39 2017
@@ -615,7 +615,15 @@ void ExprEngine::ProcessAutomaticObjDtor
   const MemRegion *Region = dest.castAs().getRegion();
 
   if (varType->isReferenceType()) {
-Region = state->getSVal(Region).getAsRegion()->getBaseRegion();
+const MemRegion *ValueRegion = state->getSVal(Region).getAsRegion();
+if (!ValueRegion) {
+  // FIXME: This should not happen. The language guarantees a presence
+  // of a valid initializer here, so the reference shall not be undefined.
+  // It seems that we're calling destructors over variables that
+  // were not initialized yet.
+  return;
+}
+Region = ValueRegion->getBaseRegion();
 varType = cast(Region)->getValueType();
   }
 

Modified: cfe/trunk/test/Analysis/temporaries.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/temporaries.cpp?rev=296646&r1=296645&r2=296646&view=diff
==
--- cfe/trunk/test/Analysis/temporaries.cpp (original)
+++ cfe/trunk/test/Analysis/temporaries.cpp Wed Mar  1 11:48:39 2017
@@ -493,3 +493,13 @@ namespace PR16629 {
 clang_analyzer_eval(x == 47); // expected-warning{{TRUE}}
   }
 }
+
+namespace PR32088 {
+  void testReturnFromStmtExprInitializer() {
+// We shouldn't try to destroy the object pointed to by `obj' upon return.
+const NonTrivial &obj = ({
+  return; // no-crash
+  NonTrivial(42);
+});
+  }
+}


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


r296648 - [Test] NFC: Fixed typo in comments

2017-03-01 Thread Charles Li via cfe-commits
Author: lcharles
Date: Wed Mar  1 11:55:03 2017
New Revision: 296648

URL: http://llvm.org/viewvc/llvm-project?rev=296648&view=rev
Log:
[Test] NFC: Fixed typo in comments

Changed "declerations" to "declarations"

Modified:
cfe/trunk/test/Modules/Inputs/merge-using-decls/b.h
cfe/trunk/test/Modules/merge-using-decls.cpp

Modified: cfe/trunk/test/Modules/Inputs/merge-using-decls/b.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/merge-using-decls/b.h?rev=296648&r1=296647&r2=296648&view=diff
==
--- cfe/trunk/test/Modules/Inputs/merge-using-decls/b.h (original)
+++ cfe/trunk/test/Modules/Inputs/merge-using-decls/b.h Wed Mar  1 11:55:03 2017
@@ -29,7 +29,7 @@ template struct D : X, T {
   using typename X::t;
 };
 
-#if __cplusplus <= 199711L // C++11 does not allow access declerations
+#if __cplusplus <= 199711L // C++11 does not allow access declarations
 template struct E : X, T {
   // Mismatch in using/access-declaration-ness.
   T::value;
@@ -49,7 +49,7 @@ template struct F : X, T {
 typedef C::type I;
 typedef D::t I;
 
-#if __cplusplus <= 199711L // C++11 does not allow access declerations
+#if __cplusplus <= 199711L // C++11 does not allow access declarations
 typedef E::type I;
 #endif
 

Modified: cfe/trunk/test/Modules/merge-using-decls.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/merge-using-decls.cpp?rev=296648&r1=296647&r2=296648&view=diff
==
--- cfe/trunk/test/Modules/merge-using-decls.cpp (original)
+++ cfe/trunk/test/Modules/merge-using-decls.cpp Wed Mar  1 11:55:03 2017
@@ -28,7 +28,7 @@ template int Use() {
 }
 
 template int UseAll() {
-#if __cplusplus <= 199711L // C++11 does not allow access declerations
+#if __cplusplus <= 199711L // C++11 does not allow access declarations
   return Use >() + Use >() + Use >() + Use >(); // 
expected-note 0-2{{instantiation of}}
 #else
   return Use >() + Use >() + Use >(); // expected-note 
0-2{{instantiation of}}
@@ -45,7 +45,7 @@ template int UseAll();
 // Here, we're instantiating the definition from 'A' and merging the definition
 // from 'B' into it.
 
-#if __cplusplus <= 199711L // C++11 does not allow access declerations
+#if __cplusplus <= 199711L // C++11 does not allow access declarations
 // expected-error@b.h:* {{'E::value' from module 'B' is not present in 
definition of 'E' in module 'A'}}
 // expected-error@b.h:* {{'E::v' from module 'B' is not present in definition 
of 'E' in module 'A'}}
 #endif
@@ -65,7 +65,7 @@ template int UseAll();
 // expected-error@b.h:* 2{{'typename' keyword used on a non-type}}
 // expected-error@b.h:* 2{{dependent using declaration resolved to type 
without 'typename'}}
 
-#if __cplusplus <= 199711L // C++11 does not allow access declerations
+#if __cplusplus <= 199711L // C++11 does not allow access declarations
 // expected-error@a.h:* {{'E::type' from module 'A' is not present in 
definition of 'E' in module 'B'}}
 // expected-error@a.h:* {{'E::t' from module 'A' is not present in definition 
of 'E' in module 'B'}}
 // expected-error@a.h:* {{'E::value' from module 'A' is not present in 
definition of 'E' in module 'B'}}


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


[PATCH] D29819: Introduce an 'external_source_symbol' attribute that describes the origin and the nature of a declaration

2017-03-01 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added inline comments.



Comment at: lib/Parse/ParseDeclCXX.cpp:3830-3837
+  unsigned NumArgs;
+  // Some Clang-scoped attributes have some special parsing behavior.
+  if (ScopeName && ScopeName->getName() == "clang")
+NumArgs =
+ParseClangAttributeArgs(AttrName, AttrNameLoc, Attrs, EndLoc, 
ScopeName,
+ScopeLoc, AttributeList::AS_CXX11);
+  else

aaron.ballman wrote:
> This code is equivalent to the old code, which is good. However, it points 
> out what I think may be a latent bug -- for attributes in the clang namespace 
> that are also standard attributes, I'm not certain we should be generating 
> parse errors for the clang-namespaced spelling. This only impacts 
> [[fallthrough]] vs [[clang::fallthrough]], according to the implementation of 
> `IsBuiltInOrStandardCXX11Attribute()`.
> 
> All of that is to say: I'm not certain we need to hoist `NumArgs` to get to 
> the call to `IsBuiltInOrStandardCXX11Attribute()` below, because attributes 
> in the clang namespace are not built-in or standard attributes.
> 
> This requires a bit further exploration, but I won't have time to do that for 
> a few weeks. I don't want to hold your patch up for that, so I think this is 
> fine for now -- I can modify the code later when I have the chance to finish 
> my exploration.
Thanks!

I agree with the comment about `NumArgs`, I wasn't sure if we need it for 
`clang::` attributes as well.


Repository:
  rL LLVM

https://reviews.llvm.org/D29819



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


[PATCH] D29819: Introduce an 'external_source_symbol' attribute that describes the origin and the nature of a declaration

2017-03-01 Thread Alex Lorenz via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL296649: Introduce an 'external_source_symbol' attribute that 
describes the origin (authored by arphaman).

Changed prior to commit:
  https://reviews.llvm.org/D29819?vs=90042&id=90205#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D29819

Files:
  cfe/trunk/include/clang/Basic/Attr.td
  cfe/trunk/include/clang/Basic/AttrDocs.td
  cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
  cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
  cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
  cfe/trunk/include/clang/Parse/Parser.h
  cfe/trunk/include/clang/Sema/AttributeList.h
  cfe/trunk/lib/Parse/ParseDecl.cpp
  cfe/trunk/lib/Parse/ParseDeclCXX.cpp
  cfe/trunk/lib/Parse/Parser.cpp
  cfe/trunk/lib/Sema/SemaDeclAttr.cpp
  cfe/trunk/test/Misc/ast-dump-attr.cpp
  cfe/trunk/test/Parser/attr-external-source-symbol-cxx11.cpp
  cfe/trunk/test/Parser/attr-external-source-symbol.m
  cfe/trunk/test/Sema/attr-external-source-symbol.c

Index: cfe/trunk/include/clang/Sema/AttributeList.h
===
--- cfe/trunk/include/clang/Sema/AttributeList.h
+++ cfe/trunk/include/clang/Sema/AttributeList.h
@@ -927,6 +927,7 @@
   ExpectedStructClassVariableFunctionOrInlineNamespace,
   ExpectedForMaybeUnused,
   ExpectedEnumOrClass,
+  ExpectedNamedDecl,
 };
 
 }  // end namespace clang
Index: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
@@ -859,6 +859,12 @@
 def err_availability_query_repeated_star : Error<
   "'*' query has already been specified">;
 
+// External source symbol attribute
+def err_external_source_symbol_expected_keyword : Error<
+  "expected 'language', 'defined_in', or 'generated_declaration'">;
+def err_external_source_symbol_duplicate_clause : Error<
+  "duplicate %0 clause in an 'external_source_symbol' attribute">;
+
 // Type safety attributes
 def err_type_safety_unknown_flag : Error<
   "invalid comparison flag %0; use 'layout_compatible' or 'must_be_null'">;
Index: cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
@@ -45,7 +45,9 @@
   "must end with ':'">;
 def err_expected_string_literal : Error<"expected string literal "
   "%select{in %1|for diagnostic message in static_assert|"
-  "for optional message in 'availability' attribute}0">;
+  "for optional message in 'availability' attribute|"
+  "for %select{language|source container}1 name in "
+  "'external_source_symbol' attribute}0">;
 def err_invalid_string_udl : Error<
   "string literal with user-defined suffix cannot be used here">;
 def err_invalid_character_udl : Error<
Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2754,7 +2754,8 @@
   "|functions, methods, enums, and classes"
   "|structs, classes, variables, functions, and inline namespaces"
   "|variables, functions, methods, types, enumerations, enumerators, labels, and non-static data members"
-  "|classes and enumerations}1">,
+  "|classes and enumerations"
+  "|named declarations}1">,
   InGroup;
 def err_attribute_wrong_decl_type : Error;
 def warn_type_attribute_wrong_type : Warning<
Index: cfe/trunk/include/clang/Basic/AttrDocs.td
===
--- cfe/trunk/include/clang/Basic/AttrDocs.td
+++ cfe/trunk/include/clang/Basic/AttrDocs.td
@@ -960,6 +960,63 @@
   }];
 }
 
+def ExternalSourceSymbolDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+The ``external_source_symbol`` attribute specifies that a declaration originates
+from an external source and describes the nature of that source.
+
+The fact that Clang is capable of recognizing declarations that were defined
+externally can be used to provide better tooling support for mixed-language
+projects or projects that rely on auto-generated code. For instance, an IDE that
+uses Clang and that supports mixed-language projects can use this attribute to
+provide a correct 'jump-to-definition' feature. For a concrete example,
+consider a protocol that's defined in a Swift file:
+
+.. code-block:: swift
+
+  @objc public protocol SwiftProtocol {
+func method()
+  }
+
+This protocol can be used from Objective-C code by including a header file that
+was generated by the Swift compiler. The declarations in that header can use
+the ``external_source_symbol`` attribute to make Clang aware of the fact
+th

r296649 - Introduce an 'external_source_symbol' attribute that describes the origin

2017-03-01 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Wed Mar  1 12:06:25 2017
New Revision: 296649

URL: http://llvm.org/viewvc/llvm-project?rev=296649&view=rev
Log:
Introduce an 'external_source_symbol' attribute that describes the origin
and the nature of a declaration

This commit adds an external_source_symbol attribute to Clang. This attribute
specifies that a declaration originates from an external source and describes
the nature of that source. This attribute will be used to improve IDE features
like 'jump-to-definition' for mixed-language projects or project that use
auto-generated code.

rdar://30423368

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

Added:
cfe/trunk/test/Parser/attr-external-source-symbol-cxx11.cpp
cfe/trunk/test/Parser/attr-external-source-symbol.m
cfe/trunk/test/Sema/attr-external-source-symbol.c
Modified:
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/include/clang/Basic/AttrDocs.td
cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/include/clang/Sema/AttributeList.h
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Parse/ParseDeclCXX.cpp
cfe/trunk/lib/Parse/Parser.cpp
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/test/Misc/ast-dump-attr.cpp

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=296649&r1=296648&r2=296649&view=diff
==
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Wed Mar  1 12:06:25 2017
@@ -527,6 +527,17 @@ def Availability : InheritableAttr {
   let Documentation = [AvailabilityDocs];
 }
 
+def ExternalSourceSymbol : InheritableAttr {
+  let Spellings = [GNU<"external_source_symbol">,
+   CXX11<"clang", "external_source_symbol">];
+  let Args = [StringArgument<"language", 1>,
+  StringArgument<"definedIn", 1>,
+  BoolArgument<"generatedDeclaration", 1>];
+  let HasCustomParsing = 1;
+//  let Subjects = SubjectList<[Named]>;
+  let Documentation = [ExternalSourceSymbolDocs];
+}
+
 def Blocks : InheritableAttr {
   let Spellings = [GNU<"blocks">];
   let Args = [EnumArgument<"Type", "BlockType", ["byref"], ["ByRef"]>];

Modified: cfe/trunk/include/clang/Basic/AttrDocs.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/AttrDocs.td?rev=296649&r1=296648&r2=296649&view=diff
==
--- cfe/trunk/include/clang/Basic/AttrDocs.td (original)
+++ cfe/trunk/include/clang/Basic/AttrDocs.td Wed Mar  1 12:06:25 2017
@@ -960,6 +960,63 @@ When one method overrides another, the o
   }];
 }
 
+def ExternalSourceSymbolDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+The ``external_source_symbol`` attribute specifies that a declaration 
originates
+from an external source and describes the nature of that source.
+
+The fact that Clang is capable of recognizing declarations that were defined
+externally can be used to provide better tooling support for mixed-language
+projects or projects that rely on auto-generated code. For instance, an IDE 
that
+uses Clang and that supports mixed-language projects can use this attribute to
+provide a correct 'jump-to-definition' feature. For a concrete example,
+consider a protocol that's defined in a Swift file:
+
+.. code-block:: swift
+
+  @objc public protocol SwiftProtocol {
+func method()
+  }
+
+This protocol can be used from Objective-C code by including a header file that
+was generated by the Swift compiler. The declarations in that header can use
+the ``external_source_symbol`` attribute to make Clang aware of the fact
+that ``SwiftProtocol`` actually originates from a Swift module:
+
+.. code-block:: objc
+
+  __attribute__((external_source_symbol(language=Swift,defined_in="module")))
+  @protocol SwiftProtocol
+  @required
+  - (void) method;
+  @end
+
+Consequently, when 'jump-to-definition' is performed at a location that
+references ``SwiftProtocol``, the IDE can jump to the original definition in
+the Swift source file rather than jumping to the Objective-C declaration in the
+auto-generated header file.
+
+The ``external_source_symbol`` attribute is a comma-separated list that 
includes
+clauses that describe the origin and the nature of the particular declaration.
+Those clauses can be:
+
+language=\ *string-literal*
+  The name of the source language in which this declaration was defined.
+
+defined_in=\ *string-literal*
+  The name of the source container in which the declaration was defined. The
+  exact definition of source container is language-specific, e.g. Swift's
+  source containers are modules, so ``defined_in`` should specify the Swift
+  module name.
+

Re: r296554 - [PS4] Set our default dialect to C++11. NFC for other targets.

2017-03-01 Thread Mehdi Amini via cfe-commits
I’m not sure I find this nice to see this upstream.

I not fond in general of this kind of difference in behavior. I don’t think it 
is good for clang to have different default for this kind of settings depending 
on the platform. It does not provide a very good user experience from a 
cross-platform point of view (i.e. my compiler behaves very differently when I 
target one platform instead of another).

— 
Mehdi



> On Feb 28, 2017, at 11:22 PM, Sean Silva via cfe-commits 
>  wrote:
> 
> Nice!
> 
> -- Sean Silva
> 
> On Tue, Feb 28, 2017 at 5:01 PM, Paul Robinson via cfe-commits 
> mailto:cfe-commits@lists.llvm.org>> wrote:
> Author: probinson
> Date: Tue Feb 28 19:01:10 2017
> New Revision: 296554
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=296554&view=rev 
> 
> Log:
> [PS4] Set our default dialect to C++11. NFC for other targets.
> Reapplies r296209 now that r296549 has fixed what really seems to be
> the last problematic test.
> 
> Modified:
> cfe/trunk/lib/Frontend/CompilerInvocation.cpp
> 
> Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=296554&r1=296553&r2=296554&view=diff
>  
> 
> ==
> --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
> +++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Tue Feb 28 19:01:10 2017
> @@ -1582,7 +1582,11 @@ void CompilerInvocation::setLangDefaults
>  case IK_PreprocessedCXX:
>  case IK_ObjCXX:
>  case IK_PreprocessedObjCXX:
> -  LangStd = LangStandard::lang_gnucxx98;
> +  // The PS4 uses C++11 as the default C++ standard.
> +  if (T.isPS4())
> +LangStd = LangStandard::lang_gnucxx11;
> +  else
> +LangStd = LangStandard::lang_gnucxx98;
>break;
>  case IK_RenderScript:
>LangStd = LangStandard::lang_c99;
> 
> 
> ___
> 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

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


[PATCH] D30158: [clang-tidy] modernize: Find usage of random_shuffle and replace it with shuffle.

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



Comment at: clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp:77
+
+  auto Diag = [=]() {
+std::string Message = ReplaceMessage;

madsravn wrote:
> aaron.ballman wrote:
> > Is there a reason this needs to capture everything by copy? Also, no need 
> > for the empty parens. Actually, is the lambda even necessary at all?
> Is it OK to capture by reference then? Or how do we want it in llvm? 
> 
> We need the lambda, because first I need to create the diag with a message 
> based on the count of arguments and then I need to find fixits based on the 
> same count. Example: 
> 
> 
> ```
> string message = "Message for 2 arguments";
> if(argumentCount == 3) {
>   message = "Message for 3 arguments";
> }
> auto Diag = diag(startLoc(), message);
> if(argumentCount == 3) {
>   Diag << FixitHint::FixForThreeArguments();
> } else {
>   Diag << FixitHint::FixForTwoArguments();
> }
> ```
> 
> So the idea with the lambda is to avoid doing the same if-statement twice. 
But you call the lambda immediately rather than store it and reuse it? It seems 
like you should be able to hoist a `DiagnosticBuilder` variable outside of the 
if statement and skip the lambda entirely.



Comment at: clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp:89
+
+  std::string newname = "shuffle";
+  StringRef ContainerText = Lexer::getSourceText(

Should be `NewName` instead.


https://reviews.llvm.org/D30158



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


[PATCH] D29750: [PPC] Enable -fomit-frame-pointer by default for PPC

2017-03-01 Thread Hal Finkel via Phabricator via cfe-commits
hfinkel accepted this revision.
hfinkel added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D29750



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


[PATCH] D30158: [clang-tidy] modernize: Find usage of random_shuffle and replace it with shuffle.

2017-03-01 Thread Mads Ravn via Phabricator via cfe-commits
madsravn marked an inline comment as done.
madsravn added inline comments.



Comment at: clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp:77
+
+  auto Diag = [=]() {
+std::string Message = ReplaceMessage;

aaron.ballman wrote:
> madsravn wrote:
> > aaron.ballman wrote:
> > > Is there a reason this needs to capture everything by copy? Also, no need 
> > > for the empty parens. Actually, is the lambda even necessary at all?
> > Is it OK to capture by reference then? Or how do we want it in llvm? 
> > 
> > We need the lambda, because first I need to create the diag with a message 
> > based on the count of arguments and then I need to find fixits based on the 
> > same count. Example: 
> > 
> > 
> > ```
> > string message = "Message for 2 arguments";
> > if(argumentCount == 3) {
> >   message = "Message for 3 arguments";
> > }
> > auto Diag = diag(startLoc(), message);
> > if(argumentCount == 3) {
> >   Diag << FixitHint::FixForThreeArguments();
> > } else {
> >   Diag << FixitHint::FixForTwoArguments();
> > }
> > ```
> > 
> > So the idea with the lambda is to avoid doing the same if-statement twice. 
> But you call the lambda immediately rather than store it and reuse it? It 
> seems like you should be able to hoist a `DiagnosticBuilder` variable outside 
> of the if statement and skip the lambda entirely.
I am not sure what you mean by this. Can you elaborate? Can you give a short 
example how I would hoist a `DiagnosticBuilder` out?

I think I tried something like that, but it was not an option. 


https://reviews.llvm.org/D30158



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


[PATCH] D30158: [clang-tidy] modernize: Find usage of random_shuffle and replace it with shuffle.

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



Comment at: clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp:77
+
+  auto Diag = [=]() {
+std::string Message = ReplaceMessage;

madsravn wrote:
> aaron.ballman wrote:
> > madsravn wrote:
> > > aaron.ballman wrote:
> > > > Is there a reason this needs to capture everything by copy? Also, no 
> > > > need for the empty parens. Actually, is the lambda even necessary at 
> > > > all?
> > > Is it OK to capture by reference then? Or how do we want it in llvm? 
> > > 
> > > We need the lambda, because first I need to create the diag with a 
> > > message based on the count of arguments and then I need to find fixits 
> > > based on the same count. Example: 
> > > 
> > > 
> > > ```
> > > string message = "Message for 2 arguments";
> > > if(argumentCount == 3) {
> > >   message = "Message for 3 arguments";
> > > }
> > > auto Diag = diag(startLoc(), message);
> > > if(argumentCount == 3) {
> > >   Diag << FixitHint::FixForThreeArguments();
> > > } else {
> > >   Diag << FixitHint::FixForTwoArguments();
> > > }
> > > ```
> > > 
> > > So the idea with the lambda is to avoid doing the same if-statement 
> > > twice. 
> > But you call the lambda immediately rather than store it and reuse it? It 
> > seems like you should be able to hoist a `DiagnosticBuilder` variable 
> > outside of the if statement and skip the lambda entirely.
> I am not sure what you mean by this. Can you elaborate? Can you give a short 
> example how I would hoist a `DiagnosticBuilder` out?
> 
> I think I tried something like that, but it was not an option. 
It's entirely possible I'm missing something (I'm distracted with meetings this 
week), but I was envisioning:
```
DiagnosticBuilder Diag;
if (MatchedCallExpr->getNumArgs() == 3) {
  Diag =
  diag(MatchedCallExpr->getLocStart(),
   "'std::random_shuffle' has been removed in C++17; use "
   "'std::shuffle' and an alternative random mechanism instead");
  Diag << FixItHint::CreateReplacement(
  MatchedArgumentThree->getSourceRange(),
  "std::mt19937(std::random_device()())");
} else {
  Diag = diag(MatchedCallExpr->getLocStart(),
"'std::random_shuffle' has been removed in C++17; use "
"'std::shuffle' instead");
  Diag << FixItHint::CreateInsertion(
  MatchedCallExpr->getRParenLoc(),
  ", std::mt19937(std::random_device()())");
}
```


https://reviews.llvm.org/D30158



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


r296656 - [PCH] Avoid VarDecl emission attempt if no owning module avaiable

2017-03-01 Thread Bruno Cardoso Lopes via cfe-commits
Author: bruno
Date: Wed Mar  1 13:18:42 2017
New Revision: 296656

URL: http://llvm.org/viewvc/llvm-project?rev=296656&view=rev
Log:
[PCH] Avoid VarDecl emission attempt if no owning module avaiable

This is a stopgap fix for PR31863, a regression introduced in r276159.

Consider this snippet:

struct FVector;
struct FVector {};
struct FBox {
  FVector Min;
  FBox(int);
};
namespace {
FBox InvalidBoundingBox(0);
}

While parsing the DECL_VAR for 'struct FBox', clang recursively read all the
dep decls until it finds the DECL_CXX_RECORD forward declaration for 'struct
FVector'. Then, it resumes all the way up back to DECL_VAR handling in
`ReadDeclRecord`, where it checks if `isConsumerInterestedIn` for the decl.

One of the condition for `isConsumerInterestedIn` to return false is if the
VarDecl is imported from a module `D->getImportedOwningModule()`, because it
will get emitted when we import the relevant module. However, before checking
if it comes from a module, clang checks if `Ctx.DeclMustBeEmitted(D)`, which
triggers the emission of 'struct FBox'. Since one of its fields is still
incomplete, it crashes.

Instead, check if `D->getImportedOwningModule()` is true before calling
`Ctx.DeclMustBeEmitted(D)`.

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

rdar://problem/30173654

Added:
cfe/trunk/test/PCH/empty-def-fwd-struct.h
Modified:
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp

Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=296656&r1=296655&r2=296656&view=diff
==
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Wed Mar  1 13:18:42 2017
@@ -2530,8 +2530,8 @@ static bool isConsumerInterestedIn(ASTCo
 
   // An ImportDecl or VarDecl imported from a module will get emitted when
   // we import the relevant module.
-  if ((isa(D) || isa(D)) && Ctx.DeclMustBeEmitted(D) &&
-  D->getImportedOwningModule())
+  if ((isa(D) || isa(D)) && D->getImportedOwningModule() 
&&
+  Ctx.DeclMustBeEmitted(D))
 return false;
 
   if (isa(D) || 

Added: cfe/trunk/test/PCH/empty-def-fwd-struct.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/empty-def-fwd-struct.h?rev=296656&view=auto
==
--- cfe/trunk/test/PCH/empty-def-fwd-struct.h (added)
+++ cfe/trunk/test/PCH/empty-def-fwd-struct.h Wed Mar  1 13:18:42 2017
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -emit-pch -x c++-header %s -std=c++14 -o %t.pch
+// RUN: %clang_cc1 -emit-llvm-only -x c++ /dev/null -std=c++14 -include-pch 
%t.pch -o %t.o
+struct FVector;
+struct FVector {};
+struct FBox {
+  FVector Min;
+  FBox(int);
+};
+namespace {
+FBox InvalidBoundingBox(0);
+}
+


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


[PATCH] D29753: [PCH] Avoid early VarDecl emission attempt if no owning module avaiable

2017-03-01 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL296656: [PCH] Avoid VarDecl emission attempt if no owning 
module avaiable (authored by bruno).

Changed prior to commit:
  https://reviews.llvm.org/D29753?vs=87774&id=90212#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D29753

Files:
  cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
  cfe/trunk/test/PCH/empty-def-fwd-struct.h


Index: cfe/trunk/test/PCH/empty-def-fwd-struct.h
===
--- cfe/trunk/test/PCH/empty-def-fwd-struct.h
+++ cfe/trunk/test/PCH/empty-def-fwd-struct.h
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -emit-pch -x c++-header %s -std=c++14 -o %t.pch
+// RUN: %clang_cc1 -emit-llvm-only -x c++ /dev/null -std=c++14 -include-pch 
%t.pch -o %t.o
+struct FVector;
+struct FVector {};
+struct FBox {
+  FVector Min;
+  FBox(int);
+};
+namespace {
+FBox InvalidBoundingBox(0);
+}
+
Index: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
===
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
@@ -2530,8 +2530,8 @@
 
   // An ImportDecl or VarDecl imported from a module will get emitted when
   // we import the relevant module.
-  if ((isa(D) || isa(D)) && Ctx.DeclMustBeEmitted(D) &&
-  D->getImportedOwningModule())
+  if ((isa(D) || isa(D)) && D->getImportedOwningModule() 
&&
+  Ctx.DeclMustBeEmitted(D))
 return false;
 
   if (isa(D) || 


Index: cfe/trunk/test/PCH/empty-def-fwd-struct.h
===
--- cfe/trunk/test/PCH/empty-def-fwd-struct.h
+++ cfe/trunk/test/PCH/empty-def-fwd-struct.h
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -emit-pch -x c++-header %s -std=c++14 -o %t.pch
+// RUN: %clang_cc1 -emit-llvm-only -x c++ /dev/null -std=c++14 -include-pch %t.pch -o %t.o
+struct FVector;
+struct FVector {};
+struct FBox {
+  FVector Min;
+  FBox(int);
+};
+namespace {
+FBox InvalidBoundingBox(0);
+}
+
Index: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
===
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
@@ -2530,8 +2530,8 @@
 
   // An ImportDecl or VarDecl imported from a module will get emitted when
   // we import the relevant module.
-  if ((isa(D) || isa(D)) && Ctx.DeclMustBeEmitted(D) &&
-  D->getImportedOwningModule())
+  if ((isa(D) || isa(D)) && D->getImportedOwningModule() &&
+  Ctx.DeclMustBeEmitted(D))
 return false;
 
   if (isa(D) || 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r296659 - clang-format: [JS/TS] Properly understand cast expressions.

2017-03-01 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Wed Mar  1 13:26:12 2017
New Revision: 296659

URL: http://llvm.org/viewvc/llvm-project?rev=296659&view=rev
Log:
clang-format: [JS/TS] Properly understand cast expressions.

Many things were wrong:
- We didn't always allow wrapping after "as", which can be necessary.
- We used to Undestand the identifier after "as" as a start of a name.
- We didn't properly parse the structure of the expression with "as"
  having the precedence of relational operators

Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=296659&r1=296658&r2=296659&view=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Wed Mar  1 13:26:12 2017
@@ -1158,7 +1158,8 @@ private:
 if (Tok.isNot(tok::identifier) || !Tok.Previous)
   return false;
 
-if (Tok.Previous->isOneOf(TT_LeadingJavaAnnotation, 
Keywords.kw_instanceof))
+if (Tok.Previous->isOneOf(TT_LeadingJavaAnnotation, Keywords.kw_instanceof,
+  Keywords.kw_as))
   return false;
 if (Style.Language == FormatStyle::LK_JavaScript &&
 Tok.Previous->is(Keywords.kw_in))
@@ -1533,7 +1534,7 @@ private:
   Current->is(Keywords.kw_instanceof))
 return prec::Relational;
   if (Style.Language == FormatStyle::LK_JavaScript &&
-  Current->is(Keywords.kw_in))
+  Current->isOneOf(Keywords.kw_in, Keywords.kw_as))
 return prec::Relational;
   if (Current->is(TT_BinaryOperator) || Current->is(tok::comma))
 return Current->getPrecedence();
@@ -2531,6 +2532,8 @@ bool TokenAnnotator::canBreakBefore(cons
   return Style.BreakBeforeBinaryOperators != FormatStyle::BOS_None;
 if (Right.is(Keywords.kw_as))
   return false; // must not break before as in 'x as type' casts
+if (Left.is(Keywords.kw_as))
+  return true;
 if (Left.is(Keywords.kw_declare) &&
 Right.isOneOf(Keywords.kw_module, tok::kw_namespace,
   Keywords.kw_function, tok::kw_class, tok::kw_enum,

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=296659&r1=296658&r2=296659&view=diff
==
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Wed Mar  1 13:26:12 2017
@@ -1502,6 +1502,9 @@ TEST_F(FormatTestJS, CastSyntax) {
   verifyFormat("x = x as {a: string};");
   verifyFormat("x = x as (string);");
   verifyFormat("x = x! as (string);");
+  verifyFormat("var x = something.someFunction() as\n"
+   "something;",
+   getGoogleJSStyleWithColumns(40));
 }
 
 TEST_F(FormatTestJS, TypeArguments) {


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


[PATCH] D30268: Avoid copy of __atoms when char_type is char

2017-03-01 Thread Aditya Kumar via Phabricator via cfe-commits
hiraditya updated this revision to Diff 90214.
hiraditya added a comment.

Guarded the new implementation with _LIBCPP_ABI_OPTIMIZED_LOCALE macro to avoid 
ABI incompatibilities.


https://reviews.llvm.org/D30268

Files:
  libcxx/include/__config
  libcxx/include/locale

Index: libcxx/include/locale
===
--- libcxx/include/locale
+++ libcxx/include/locale
@@ -380,19 +380,57 @@
 struct __num_get
 : protected __num_get_base
 {
-static string __stage2_int_prep(ios_base& __iob, _CharT* __atoms, _CharT& __thousands_sep);
 static string __stage2_float_prep(ios_base& __iob, _CharT* __atoms, _CharT& __decimal_point,
   _CharT& __thousands_sep);
-static int __stage2_int_loop(_CharT __ct, int __base, char* __a, char*& __a_end,
-  unsigned& __dc, _CharT __thousands_sep, const string& __grouping,
-  unsigned* __g, unsigned*& __g_end, _CharT* __atoms);
+
 static int __stage2_float_loop(_CharT __ct, bool& __in_units, char& __exp,
char* __a, char*& __a_end,
_CharT __decimal_point, _CharT __thousands_sep,
const string& __grouping, unsigned* __g,
unsigned*& __g_end, unsigned& __dc, _CharT* __atoms);
+#ifndef _LIBCPP_ABI_OPTIMIZED_LOCALE
+static string __stage2_int_prep(ios_base& __iob, _CharT* __atoms, _CharT& __thousands_sep);
+static int __stage2_int_loop(_CharT __ct, int __base, char* __a, char*& __a_end,
+  unsigned& __dc, _CharT __thousands_sep, const string& __grouping,
+  unsigned* __g, unsigned*& __g_end, _CharT* __atoms);
+
+#else
+static string __stage2_int_prep(ios_base& __iob, _CharT& __thousands_sep)
+{
+locale __loc = __iob.getloc();
+const numpunct<_CharT>& __np = use_facet >(__loc);
+__thousands_sep = __np.thousands_sep();
+return __np.grouping();
+}
+
+const _CharT* __do_widen(ios_base& __iob, _CharT* __atoms) const
+{
+  return __do_widen_p(__iob, __atoms);
+}
+
+
+static int __stage2_int_loop(_CharT __ct, int __base, char* __a, char*& __a_end,
+  unsigned& __dc, _CharT __thousands_sep, const string& __grouping,
+  unsigned* __g, unsigned*& __g_end, const _CharT* __atoms);
+private:
+template
+const T* __do_widen_p(ios_base& __iob, T* __atoms) const
+{
+  locale __loc = __iob.getloc();
+  use_facet >(__loc).widen(__src, __src + 26, __atoms);
+  return __atoms;
+}
+
+const char* __do_widen_p(ios_base& __iob, char* __atoms) const
+{
+  (void)__iob;
+  (void)__atoms;
+  return __src;
+}
+#endif
 };
 
+#ifndef _LIBCPP_ABI_OPTIMIZED_LOCALE
 template 
 string
 __num_get<_CharT>::__stage2_int_prep(ios_base& __iob, _CharT* __atoms, _CharT& __thousands_sep)
@@ -403,6 +441,7 @@
 __thousands_sep = __np.thousands_sep();
 return __np.grouping();
 }
+#endif
 
 template 
 string
@@ -419,9 +458,17 @@
 
 template 
 int
+#ifndef _LIBCPP_ABI_OPTIMIZED_LOCALE
 __num_get<_CharT>::__stage2_int_loop(_CharT __ct, int __base, char* __a, char*& __a_end,
   unsigned& __dc, _CharT __thousands_sep, const string& __grouping,
   unsigned* __g, unsigned*& __g_end, _CharT* __atoms)
+#else
+__num_get<_CharT>::__stage2_int_loop(_CharT __ct, int __base, char* __a, char*& __a_end,
+  unsigned& __dc, _CharT __thousands_sep, const string& __grouping,
+  unsigned* __g, unsigned*& __g_end, const _CharT* __atoms)
+
+#endif
+
 {
 if (__a_end == __a && (__ct == __atoms[24] || __ct == __atoms[25]))
 {
@@ -841,6 +888,7 @@
 return __b;
 }
 
+#ifndef _LIBCPP_ABI_OPTIMIZED_LOCALE
 // signed
 
 template 
@@ -941,6 +989,110 @@
 return __b;
 }
 
+#else
+//signed
+
+template 
+template 
+_InputIterator
+num_get<_CharT, _InputIterator>::__do_get_signed(iter_type __b, iter_type __e,
+ios_base& __iob,
+ios_base::iostate& __err,
+_Signed& __v) const
+{
+// Stage 1
+int __base = this->__get_base(__iob);
+// Stage 2
+char_type __atoms1[26];
+char_type __thousands_sep;
+const char_type *__atoms = this->__do_widen(__iob, __atoms1);
+string __grouping = this->__stage2_int_prep(__iob, __thousands_sep);
+string __buf;
+__buf.resize(__buf.capacity());
+char* __a = &__buf[0];
+char* __a_end = __a;
+unsigned __g[__num_get_base::__num_get_buf_sz];
+unsigned* __g_end = __g;
+unsigned __dc = 0;
+for (; __b != __e; ++__b)
+{
+if (__a_end == __a + __buf.size())
+{
+size_t __tmp = __buf.size();
+__buf.resize(2*__buf.size());
+__buf.resize(__buf.capacity());
+__a = &__buf[0]

[PATCH] D30158: [clang-tidy] modernize: Find usage of random_shuffle and replace it with shuffle.

2017-03-01 Thread Mads Ravn via Phabricator via cfe-commits
madsravn added inline comments.



Comment at: clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp:77
+
+  auto Diag = [=]() {
+std::string Message = ReplaceMessage;

aaron.ballman wrote:
> madsravn wrote:
> > aaron.ballman wrote:
> > > madsravn wrote:
> > > > aaron.ballman wrote:
> > > > > Is there a reason this needs to capture everything by copy? Also, no 
> > > > > need for the empty parens. Actually, is the lambda even necessary at 
> > > > > all?
> > > > Is it OK to capture by reference then? Or how do we want it in llvm? 
> > > > 
> > > > We need the lambda, because first I need to create the diag with a 
> > > > message based on the count of arguments and then I need to find fixits 
> > > > based on the same count. Example: 
> > > > 
> > > > 
> > > > ```
> > > > string message = "Message for 2 arguments";
> > > > if(argumentCount == 3) {
> > > >   message = "Message for 3 arguments";
> > > > }
> > > > auto Diag = diag(startLoc(), message);
> > > > if(argumentCount == 3) {
> > > >   Diag << FixitHint::FixForThreeArguments();
> > > > } else {
> > > >   Diag << FixitHint::FixForTwoArguments();
> > > > }
> > > > ```
> > > > 
> > > > So the idea with the lambda is to avoid doing the same if-statement 
> > > > twice. 
> > > But you call the lambda immediately rather than store it and reuse it? It 
> > > seems like you should be able to hoist a `DiagnosticBuilder` variable 
> > > outside of the if statement and skip the lambda entirely.
> > I am not sure what you mean by this. Can you elaborate? Can you give a 
> > short example how I would hoist a `DiagnosticBuilder` out?
> > 
> > I think I tried something like that, but it was not an option. 
> It's entirely possible I'm missing something (I'm distracted with meetings 
> this week), but I was envisioning:
> ```
> DiagnosticBuilder Diag;
> if (MatchedCallExpr->getNumArgs() == 3) {
>   Diag =
>   diag(MatchedCallExpr->getLocStart(),
>"'std::random_shuffle' has been removed in C++17; use "
>"'std::shuffle' and an alternative random mechanism instead");
>   Diag << FixItHint::CreateReplacement(
>   MatchedArgumentThree->getSourceRange(),
>   "std::mt19937(std::random_device()())");
> } else {
>   Diag = diag(MatchedCallExpr->getLocStart(),
> "'std::random_shuffle' has been removed in C++17; use "
> "'std::shuffle' instead");
>   Diag << FixItHint::CreateInsertion(
>   MatchedCallExpr->getRParenLoc(),
>   ", std::mt19937(std::random_device()())");
> }
> ```
The constructor for `DiagnosticBuilder` is private. So I cannot do that. The 
idea had crossed my mind, but I think the lambda expression is nicer to look 
at. 

Should I investigate if there is another way to hoist the `DiagnosticBuilder` 
out, like using `diag()` to make a dummy `DiagnosticBuilder` outside and then 
use the copy constructor to assign inside the if-statement? Or can we live with 
the lambda expression? 


https://reviews.llvm.org/D30158



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


[PATCH] D30158: [clang-tidy] modernize: Find usage of random_shuffle and replace it with shuffle.

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



Comment at: clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp:77
+
+  auto Diag = [=]() {
+std::string Message = ReplaceMessage;

madsravn wrote:
> aaron.ballman wrote:
> > madsravn wrote:
> > > aaron.ballman wrote:
> > > > madsravn wrote:
> > > > > aaron.ballman wrote:
> > > > > > Is there a reason this needs to capture everything by copy? Also, 
> > > > > > no need for the empty parens. Actually, is the lambda even 
> > > > > > necessary at all?
> > > > > Is it OK to capture by reference then? Or how do we want it in llvm? 
> > > > > 
> > > > > We need the lambda, because first I need to create the diag with a 
> > > > > message based on the count of arguments and then I need to find 
> > > > > fixits based on the same count. Example: 
> > > > > 
> > > > > 
> > > > > ```
> > > > > string message = "Message for 2 arguments";
> > > > > if(argumentCount == 3) {
> > > > >   message = "Message for 3 arguments";
> > > > > }
> > > > > auto Diag = diag(startLoc(), message);
> > > > > if(argumentCount == 3) {
> > > > >   Diag << FixitHint::FixForThreeArguments();
> > > > > } else {
> > > > >   Diag << FixitHint::FixForTwoArguments();
> > > > > }
> > > > > ```
> > > > > 
> > > > > So the idea with the lambda is to avoid doing the same if-statement 
> > > > > twice. 
> > > > But you call the lambda immediately rather than store it and reuse it? 
> > > > It seems like you should be able to hoist a `DiagnosticBuilder` 
> > > > variable outside of the if statement and skip the lambda entirely.
> > > I am not sure what you mean by this. Can you elaborate? Can you give a 
> > > short example how I would hoist a `DiagnosticBuilder` out?
> > > 
> > > I think I tried something like that, but it was not an option. 
> > It's entirely possible I'm missing something (I'm distracted with meetings 
> > this week), but I was envisioning:
> > ```
> > DiagnosticBuilder Diag;
> > if (MatchedCallExpr->getNumArgs() == 3) {
> >   Diag =
> >   diag(MatchedCallExpr->getLocStart(),
> >"'std::random_shuffle' has been removed in C++17; use "
> >"'std::shuffle' and an alternative random mechanism instead");
> >   Diag << FixItHint::CreateReplacement(
> >   MatchedArgumentThree->getSourceRange(),
> >   "std::mt19937(std::random_device()())");
> > } else {
> >   Diag = diag(MatchedCallExpr->getLocStart(),
> > "'std::random_shuffle' has been removed in C++17; use "
> > "'std::shuffle' instead");
> >   Diag << FixItHint::CreateInsertion(
> >   MatchedCallExpr->getRParenLoc(),
> >   ", std::mt19937(std::random_device()())");
> > }
> > ```
> The constructor for `DiagnosticBuilder` is private. So I cannot do that. The 
> idea had crossed my mind, but I think the lambda expression is nicer to look 
> at. 
> 
> Should I investigate if there is another way to hoist the `DiagnosticBuilder` 
> out, like using `diag()` to make a dummy `DiagnosticBuilder` outside and then 
> use the copy constructor to assign inside the if-statement? Or can we live 
> with the lambda expression? 
Ah, okay, that was the bit I was missing. Thank you for being patient. I think 
the lambda (with the reference capture) is fine as-is.


https://reviews.llvm.org/D30158



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


Re: [libcxx] r296561 - Fix PR32097 - is_abstract doesn't work on class templates.

2017-03-01 Thread Eric Fiselier via cfe-commits
4.0.1 it is. Thanks Hans!

/Eric

On Wed, Mar 1, 2017 at 10:08 AM, Hans Wennborg  wrote:

> We're at the "should have tagged 'final' days ago" stage :-)
>
> Since it's not a regression, I would prefer not to merge it unless you
> feel super strongly about it.
>
> Sounds like a good candidate for 4.0.1 (tracking bug is PR32061).
>
> Thanks,
> Hans
>
> On Wed, Mar 1, 2017 at 1:36 AM, Eric Fiselier  wrote:
> > @Hans Where are we in the release process? I would like to merge this
> into
> > 4.0.
> >
> > Although it's not a regression, it is a significant bug. This patch fixes
> > the bug by
> > forwarding to a compiler builtin, which is strictly better than what we
> > have. I'm
> > confident this patch is safe.
> >
> > /Eric
> >
> > On Tue, Feb 28, 2017 at 6:27 PM, Eric Fiselier via cfe-commits
> >  wrote:
> >>
> >> Author: ericwf
> >> Date: Tue Feb 28 19:27:14 2017
> >> New Revision: 296561
> >>
> >> URL: http://llvm.org/viewvc/llvm-project?rev=296561&view=rev
> >> Log:
> >> Fix PR32097 - is_abstract doesn't work on class templates.
> >>
> >> This patch fixes llvm.org/PR32097 by using the __is_abstract
> >> builtin type-trait instead of the previous library-only implementation.
> >>
> >> All supported compilers provide this trait. I've tested as far
> >> back as Clang 3.2, GCC 4.6 and MSVC trunk.
> >>
> >> Modified:
> >> libcxx/trunk/include/type_traits
> >>
> >> libcxx/trunk/test/std/utilities/meta/meta.unary/
> meta.unary.prop/is_abstract.pass.cpp
> >>
> >> Modified: libcxx/trunk/include/type_traits
> >> URL:
> >> http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/
> type_traits?rev=296561&r1=296560&r2=296561&view=diff
> >>
> >> 
> ==
> >> --- libcxx/trunk/include/type_traits (original)
> >> +++ libcxx/trunk/include/type_traits Tue Feb 28 19:27:14 2017
> >> @@ -1297,18 +1297,8 @@ template  using decay_t = typ
> >>
> >>  // is_abstract
> >>
> >> -namespace __is_abstract_imp
> >> -{
> >> -template  char  __test(_Tp (*)[1]);
> >> -template  __two __test(...);
> >> -}
> >> -
> >> -template ::value>
> >> -struct __libcpp_abstract : public integral_constant >> sizeof(__is_abstract_imp::__test<_Tp>(0)) != 1> {};
> >> -
> >> -template  struct __libcpp_abstract<_Tp, false> : public
> >> false_type {};
> >> -
> >> -template  struct _LIBCPP_TEMPLATE_VIS is_abstract : public
> >> __libcpp_abstract<_Tp> {};
> >> +template  struct _LIBCPP_TEMPLATE_VIS is_abstract
> >> +: public integral_constant {};
> >>
> >>  #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_
> VARIABLE_TEMPLATES)
> >>  template  _LIBCPP_CONSTEXPR bool is_abstract_v
> >>
> >> Modified:
> >> libcxx/trunk/test/std/utilities/meta/meta.unary/
> meta.unary.prop/is_abstract.pass.cpp
> >> URL:
> >> http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/
> utilities/meta/meta.unary/meta.unary.prop/is_abstract.
> pass.cpp?rev=296561&r1=296560&r2=296561&view=diff
> >>
> >> 
> ==
> >> ---
> >> libcxx/trunk/test/std/utilities/meta/meta.unary/
> meta.unary.prop/is_abstract.pass.cpp
> >> (original)
> >> +++
> >> libcxx/trunk/test/std/utilities/meta/meta.unary/
> meta.unary.prop/is_abstract.pass.cpp
> >> Tue Feb 28 19:27:14 2017
> >> @@ -65,6 +65,14 @@ class Abstract
> >>  virtual ~Abstract() = 0;
> >>  };
> >>
> >> +template 
> >> +struct AbstractTemplate {
> >> +  virtual void test() = 0;
> >> +};
> >> +
> >> +template <>
> >> +struct AbstractTemplate {};
> >> +
> >>  int main()
> >>  {
> >>  test_is_not_abstract();
> >> @@ -81,4 +89,6 @@ int main()
> >>  test_is_not_abstract();
> >>
> >>  test_is_abstract();
> >> +test_is_abstract >();
> >> +test_is_not_abstract >();
> >>  }
> >>
> >>
> >> ___
> >> 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] D30158: [clang-tidy] modernize: Find usage of random_shuffle and replace it with shuffle.

2017-03-01 Thread Mads Ravn via Phabricator via cfe-commits
madsravn added inline comments.



Comment at: clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp:77
+
+  auto Diag = [=]() {
+std::string Message = ReplaceMessage;

aaron.ballman wrote:
> madsravn wrote:
> > aaron.ballman wrote:
> > > madsravn wrote:
> > > > aaron.ballman wrote:
> > > > > madsravn wrote:
> > > > > > aaron.ballman wrote:
> > > > > > > Is there a reason this needs to capture everything by copy? Also, 
> > > > > > > no need for the empty parens. Actually, is the lambda even 
> > > > > > > necessary at all?
> > > > > > Is it OK to capture by reference then? Or how do we want it in 
> > > > > > llvm? 
> > > > > > 
> > > > > > We need the lambda, because first I need to create the diag with a 
> > > > > > message based on the count of arguments and then I need to find 
> > > > > > fixits based on the same count. Example: 
> > > > > > 
> > > > > > 
> > > > > > ```
> > > > > > string message = "Message for 2 arguments";
> > > > > > if(argumentCount == 3) {
> > > > > >   message = "Message for 3 arguments";
> > > > > > }
> > > > > > auto Diag = diag(startLoc(), message);
> > > > > > if(argumentCount == 3) {
> > > > > >   Diag << FixitHint::FixForThreeArguments();
> > > > > > } else {
> > > > > >   Diag << FixitHint::FixForTwoArguments();
> > > > > > }
> > > > > > ```
> > > > > > 
> > > > > > So the idea with the lambda is to avoid doing the same if-statement 
> > > > > > twice. 
> > > > > But you call the lambda immediately rather than store it and reuse 
> > > > > it? It seems like you should be able to hoist a `DiagnosticBuilder` 
> > > > > variable outside of the if statement and skip the lambda entirely.
> > > > I am not sure what you mean by this. Can you elaborate? Can you give a 
> > > > short example how I would hoist a `DiagnosticBuilder` out?
> > > > 
> > > > I think I tried something like that, but it was not an option. 
> > > It's entirely possible I'm missing something (I'm distracted with 
> > > meetings this week), but I was envisioning:
> > > ```
> > > DiagnosticBuilder Diag;
> > > if (MatchedCallExpr->getNumArgs() == 3) {
> > >   Diag =
> > >   diag(MatchedCallExpr->getLocStart(),
> > >"'std::random_shuffle' has been removed in C++17; use "
> > >"'std::shuffle' and an alternative random mechanism instead");
> > >   Diag << FixItHint::CreateReplacement(
> > >   MatchedArgumentThree->getSourceRange(),
> > >   "std::mt19937(std::random_device()())");
> > > } else {
> > >   Diag = diag(MatchedCallExpr->getLocStart(),
> > > "'std::random_shuffle' has been removed in C++17; use 
> > > "
> > > "'std::shuffle' instead");
> > >   Diag << FixItHint::CreateInsertion(
> > >   MatchedCallExpr->getRParenLoc(),
> > >   ", std::mt19937(std::random_device()())");
> > > }
> > > ```
> > The constructor for `DiagnosticBuilder` is private. So I cannot do that. 
> > The idea had crossed my mind, but I think the lambda expression is nicer to 
> > look at. 
> > 
> > Should I investigate if there is another way to hoist the 
> > `DiagnosticBuilder` out, like using `diag()` to make a dummy 
> > `DiagnosticBuilder` outside and then use the copy constructor to assign 
> > inside the if-statement? Or can we live with the lambda expression? 
> Ah, okay, that was the bit I was missing. Thank you for being patient. I 
> think the lambda (with the reference capture) is fine as-is.
> Thank you for being patient.

Right back at you. We are working towards the same goal after all :) 

For future reference: Should I try to avoid lambda expressions like this? 




https://reviews.llvm.org/D30158



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


r296664 - clang-format: [JS] Properly format object literals with shorthands.

2017-03-01 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Wed Mar  1 13:47:28 2017
New Revision: 296664

URL: http://llvm.org/viewvc/llvm-project?rev=296664&view=rev
Log:
clang-format: [JS] Properly format object literals with shorthands.

Before:
  return {
a,
b: 'b', c,
  };

After:
  return {
a,
b: 'b',
c,
  };

Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=296664&r1=296663&r2=296664&view=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Wed Mar  1 13:47:28 2017
@@ -1517,13 +1517,14 @@ private:
 return prec::Conditional;
   if (NextNonComment && NextNonComment->is(tok::colon) &&
   NextNonComment->is(TT_DictLiteral))
-return prec::Comma;
+return prec::Assignment;
+  if (Current->is(TT_JsComputedPropertyName))
+return prec::Assignment;
   if (Current->is(TT_LambdaArrow))
 return prec::Comma;
   if (Current->is(TT_JsFatArrow))
 return prec::Assignment;
-  if (Current->isOneOf(tok::semi, TT_InlineASMColon, TT_SelectorName,
-   TT_JsComputedPropertyName) ||
+  if (Current->isOneOf(tok::semi, TT_InlineASMColon, TT_SelectorName) ||
   (Current->is(tok::comment) && NextNonComment &&
NextNonComment->is(TT_SelectorName)))
 return 0;

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=296664&r1=296663&r2=296664&view=diff
==
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Wed Mar  1 13:47:28 2017
@@ -278,6 +278,11 @@ TEST_F(FormatTestJS, ContainerLiterals)
"  aaa,\n"
"  aaa,\n"
"};");
+  verifyFormat("return {\n"
+   "  a,\n"
+   "  b: 'b',\n"
+   "  c,\n"
+   "};");
 }
 
 TEST_F(FormatTestJS, MethodsInObjectLiterals) {


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


[PATCH] D30158: [clang-tidy] modernize: Find usage of random_shuffle and replace it with shuffle.

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

Out of curiosity, have you run this over libc++ or libstdc++ test suites 
involving `std::random_shuffle`? If so, were the results acceptable?

I think this generally LGTM (aside from the minor nit about naming), but I'd 
like to hear from @mclow.lists where this meets his needs.




Comment at: clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp:77
+
+  auto Diag = [=]() {
+std::string Message = ReplaceMessage;

madsravn wrote:
> aaron.ballman wrote:
> > madsravn wrote:
> > > aaron.ballman wrote:
> > > > madsravn wrote:
> > > > > aaron.ballman wrote:
> > > > > > madsravn wrote:
> > > > > > > aaron.ballman wrote:
> > > > > > > > Is there a reason this needs to capture everything by copy? 
> > > > > > > > Also, no need for the empty parens. Actually, is the lambda 
> > > > > > > > even necessary at all?
> > > > > > > Is it OK to capture by reference then? Or how do we want it in 
> > > > > > > llvm? 
> > > > > > > 
> > > > > > > We need the lambda, because first I need to create the diag with 
> > > > > > > a message based on the count of arguments and then I need to find 
> > > > > > > fixits based on the same count. Example: 
> > > > > > > 
> > > > > > > 
> > > > > > > ```
> > > > > > > string message = "Message for 2 arguments";
> > > > > > > if(argumentCount == 3) {
> > > > > > >   message = "Message for 3 arguments";
> > > > > > > }
> > > > > > > auto Diag = diag(startLoc(), message);
> > > > > > > if(argumentCount == 3) {
> > > > > > >   Diag << FixitHint::FixForThreeArguments();
> > > > > > > } else {
> > > > > > >   Diag << FixitHint::FixForTwoArguments();
> > > > > > > }
> > > > > > > ```
> > > > > > > 
> > > > > > > So the idea with the lambda is to avoid doing the same 
> > > > > > > if-statement twice. 
> > > > > > But you call the lambda immediately rather than store it and reuse 
> > > > > > it? It seems like you should be able to hoist a `DiagnosticBuilder` 
> > > > > > variable outside of the if statement and skip the lambda entirely.
> > > > > I am not sure what you mean by this. Can you elaborate? Can you give 
> > > > > a short example how I would hoist a `DiagnosticBuilder` out?
> > > > > 
> > > > > I think I tried something like that, but it was not an option. 
> > > > It's entirely possible I'm missing something (I'm distracted with 
> > > > meetings this week), but I was envisioning:
> > > > ```
> > > > DiagnosticBuilder Diag;
> > > > if (MatchedCallExpr->getNumArgs() == 3) {
> > > >   Diag =
> > > >   diag(MatchedCallExpr->getLocStart(),
> > > >"'std::random_shuffle' has been removed in C++17; use "
> > > >"'std::shuffle' and an alternative random mechanism 
> > > > instead");
> > > >   Diag << FixItHint::CreateReplacement(
> > > >   MatchedArgumentThree->getSourceRange(),
> > > >   "std::mt19937(std::random_device()())");
> > > > } else {
> > > >   Diag = diag(MatchedCallExpr->getLocStart(),
> > > > "'std::random_shuffle' has been removed in C++17; 
> > > > use "
> > > > "'std::shuffle' instead");
> > > >   Diag << FixItHint::CreateInsertion(
> > > >   MatchedCallExpr->getRParenLoc(),
> > > >   ", std::mt19937(std::random_device()())");
> > > > }
> > > > ```
> > > The constructor for `DiagnosticBuilder` is private. So I cannot do that. 
> > > The idea had crossed my mind, but I think the lambda expression is nicer 
> > > to look at. 
> > > 
> > > Should I investigate if there is another way to hoist the 
> > > `DiagnosticBuilder` out, like using `diag()` to make a dummy 
> > > `DiagnosticBuilder` outside and then use the copy constructor to assign 
> > > inside the if-statement? Or can we live with the lambda expression? 
> > Ah, okay, that was the bit I was missing. Thank you for being patient. I 
> > think the lambda (with the reference capture) is fine as-is.
> > Thank you for being patient.
> 
> Right back at you. We are working towards the same goal after all :) 
> 
> For future reference: Should I try to avoid lambda expressions like this? 
> 
> 
No, this sort of expression is fine when it makes the code more simple.


https://reviews.llvm.org/D30158



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


RE: r296554 - [PS4] Set our default dialect to C++11. NFC for other targets.

2017-03-01 Thread Robinson, Paul via cfe-commits
Probably better to debate this on the cfe-dev thread "Setting default dialect 
to C++11" than here.
That said, it's far from the only target-dependent setting in the driver.  
There are things ranging from the default DWARF version to whether exceptions 
are on by default to whether Microsoft extensions are on by default.  
Personally I think mixing things up gets us better coverage; this is why we 
like having bots for a variety of platforms, and it's not just for the obvious 
backend reasons.
--paulr

From: mehdi.am...@apple.com [mailto:mehdi.am...@apple.com]
Sent: Wednesday, March 01, 2017 10:36 AM
To: Sean Silva
Cc: Robinson, Paul; cfe-commits
Subject: Re: r296554 - [PS4] Set our default dialect to C++11. NFC for other 
targets.

I’m not sure I find this nice to see this upstream.

I not fond in general of this kind of difference in behavior. I don’t think it 
is good for clang to have different default for this kind of settings depending 
on the platform. It does not provide a very good user experience from a 
cross-platform point of view (i.e. my compiler behaves very differently when I 
target one platform instead of another).

—
Mehdi



On Feb 28, 2017, at 11:22 PM, Sean Silva via cfe-commits 
mailto:cfe-commits@lists.llvm.org>> wrote:

Nice!

-- Sean Silva

On Tue, Feb 28, 2017 at 5:01 PM, Paul Robinson via cfe-commits 
mailto:cfe-commits@lists.llvm.org>> wrote:
Author: probinson
Date: Tue Feb 28 19:01:10 2017
New Revision: 296554

URL: http://llvm.org/viewvc/llvm-project?rev=296554&view=rev
Log:
[PS4] Set our default dialect to C++11. NFC for other targets.
Reapplies r296209 now that r296549 has fixed what really seems to be
the last problematic test.

Modified:
cfe/trunk/lib/Frontend/CompilerInvocation.cpp

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=296554&r1=296553&r2=296554&view=diff
==
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Tue Feb 28 19:01:10 2017
@@ -1582,7 +1582,11 @@ void CompilerInvocation::setLangDefaults
 case IK_PreprocessedCXX:
 case IK_ObjCXX:
 case IK_PreprocessedObjCXX:
-  LangStd = LangStandard::lang_gnucxx98;
+  // The PS4 uses C++11 as the default C++ standard.
+  if (T.isPS4())
+LangStd = LangStandard::lang_gnucxx11;
+  else
+LangStd = LangStandard::lang_gnucxx98;
   break;
 case IK_RenderScript:
   LangStd = LangStandard::lang_c99;


___
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

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


[PATCH] D30406: [Analyzer] Add support for displaying cross-file diagnostic paths in HTML output

2017-03-01 Thread Anna Zaks via Phabricator via cfe-commits
zaks.anna added a comment.

No multi-file support is a long outstanding limitation of scan-build html 
output. Great to see the patch!! Thank you for working on it!

> It's not as immediately clear this is a multi-file output.

In addition to Artem's suggestions, you might want to insert  multiple lines of 
padding to make the distinction on the border more clear. I think it would help 
especially when scrolling a large report like in the link for the Linux source.

Also, could you put this behind an option or introduce a new format like 
-analyzer-output=plist-multi-file but for html? Just in case someone is relying 
on a single file output format, we'd want to have an option to give them to 
turn it on.


https://reviews.llvm.org/D30406



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


[PATCH] D30326: [MS-ABI] Allow #pragma section to choose for ZI data

2017-03-01 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

This functionality doesn't feel worth a driver flag. It customizes a very small 
aspect of a Microsoft extension that was only implemented for compatibility. It 
also reimplements the logic that LLVM uses in the backend to put global 
variables in .bss or .data. Can you elaborate on the actual use case? Is the 
goal to put all globals that would normally live in .bss into a custom section? 
If so, I think we should implement our own pragma to do that rather than 
piggybacking on the Microsoft one.




Comment at: lib/AST/Expr.cpp:2841
+/// Returns true if the initializer is all zeros.
+bool Expr::isZeroInitializer(ASTContext &Ctx, bool IsForRef,
+ const Expr **Culprit) const {

I seriously doubt we need this much code to check if something is a zero. I'm 
sure we already have a way to do this.


https://reviews.llvm.org/D30326



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


[PATCH] D30489: [analyzer] catch out of bounds for VLA

2017-03-01 Thread Anna Zaks via Phabricator via cfe-commits
zaks.anna added a comment.

Gábor's suggestion sounds good to me. I think ArrayBoundCheckerV2 checker has a 
higher chance to be productized / moved out of alpha in the future.

Should we just remove ArrayBoundChecker.cpp or is there a value in keeping it 
around?


Repository:
  rL LLVM

https://reviews.llvm.org/D30489



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


[PATCH] D30341: [analyzer] clarify error messages about uninitialized function arguments

2017-03-01 Thread Anna Zaks via Phabricator via cfe-commits
zaks.anna added inline comments.



Comment at: lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp:211
   // Generate a report for this bug.
-  StringRef Desc =
-  describeUninitializedArgumentInCall(Call, IsFirstArgument);
+  std::string Desc =
+  describeUninitializedArgumentInCall(Call, ArgumentNumber);

danielmarjamaki wrote:
> zaks.anna wrote:
> > Have you considered using  llvm::raw_svector_ostream here as well as 
> > passing it an argument to describeUninitializedArgumentInCall? For example, 
> > see  MallocChecker.cpp.
> I changed so describeUninitializedArgumentInCall() returns an llvm::Twine 
> instead of std::string. hope you like it.
> 
I do not think it's safe to use llvm:Twine here. See 
http://llvm.org/docs/ProgrammersManual.html#the-twine-class

How about using llvm::raw_svector_ostream as I suggested?


Repository:
  rL LLVM

https://reviews.llvm.org/D30341



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


[PATCH] D30157: [analyzer] Improve valist check

2017-03-01 Thread Anna Zaks via Phabricator via cfe-commits
zaks.anna added inline comments.



Comment at: test/Analysis/valist-uninitialized-no-undef.c:25
+  va_list va;
+  vprintf(isstring ? "%s" : "%d", va); //expected-warning{{Function 'vprintf' 
is called with an uninitialized va_list argument}} expected-note{{Function 
'vprintf' is called with an uninitialized va_list argument}} 
expected-note{{Assuming 'isstring' is 0}} expected-note{{'?' condition is 
false}}
+}

Please, split the long "expected" lines into multiple lines - one per note. It 
will improve readability in non-wrapping editors. Thanks!


https://reviews.llvm.org/D30157



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


[PATCH] D30158: [clang-tidy] modernize: Find usage of random_shuffle and replace it with shuffle.

2017-03-01 Thread Mads Ravn via Phabricator via cfe-commits
madsravn updated this revision to Diff 90223.
madsravn added a comment.

Last small changes based on comments.


https://reviews.llvm.org/D30158

Files:
  clang-tidy/modernize/CMakeLists.txt
  clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp
  clang-tidy/modernize/ReplaceRandomShuffleCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/modernize-replace-random-shuffle.rst
  test/clang-tidy/modernize-replace-random-shuffle.cpp

Index: test/clang-tidy/modernize-replace-random-shuffle.cpp
===
--- test/clang-tidy/modernize-replace-random-shuffle.cpp
+++ test/clang-tidy/modernize-replace-random-shuffle.cpp
@@ -0,0 +1,58 @@
+// RUN: %check_clang_tidy %s modernize-replace-random-shuffle %t -- -- -std=c++11
+
+//CHECK-FIXES: #include 
+
+namespace std {
+template  struct vec_iterator {
+  T *ptr;
+  vec_iterator operator++(int);
+};
+
+template  struct vector {
+  typedef vec_iterator iterator;
+
+  iterator begin();
+  iterator end();
+};
+
+template 
+void random_shuffle(FwIt begin, FwIt end);
+
+template 
+void random_shuffle(FwIt begin, FwIt end, randomFunc& randomfunc);
+
+template 
+void shuffle(FwIt begin, FwIt end);
+} // namespace std
+
+// Random Func
+int myrandom (int i) { return i;}
+
+using namespace std;
+
+int main() {
+  std::vector vec;
+
+  std::random_shuffle(vec.begin(), vec.end());
+  // CHECK-MESSAGE: [[@LINE-1]]:3: warning: 'std::random_shuffle' has been removed in C++17; use 'std::shuffle' instead
+  // CHECK-FIXES: std::shuffle(vec.begin(), vec.end(), std::mt19937(std::random_device()()));
+
+
+  std::shuffle(vec.begin(), vec.end());
+
+  random_shuffle(vec.begin(), vec.end());
+  // CHECK-MESSAGE: [[@LINE-1]]:3: warning: 'std::random_shuffle' has been removed in C++17; use 'std::shuffle' instead
+  // CHECK-FIXES: shuffle(vec.begin(), vec.end(), std::mt19937(std::random_device()()));
+  
+  std::random_shuffle(vec.begin(), vec.end(), myrandom);
+  // CHECK-MESSAGE: [[@LINE-1]]:3: warning: 'std::random_shuffle' has been removed in C++17; use 'std::shuffle' and an alternative random mechanism instead
+  // CHECK-FIXES: std::shuffle(vec.begin(), vec.end(), std::mt19937(std::random_device()()));
+
+  random_shuffle(vec.begin(), vec.end(), myrandom);
+  // CHECK-MESSAGE: [[@LINE-1]]:3: warning: 'std::random_shuffle' has been removed in C++17; use 'std::shuffle' and an alternative random mechanism instead
+  // CHECK-FIXES: shuffle(vec.begin(), vec.end(), std::mt19937(std::random_device()()));
+
+  shuffle(vec.begin(), vec.end());
+
+  return 0;
+}
Index: docs/clang-tidy/checks/modernize-replace-random-shuffle.rst
===
--- docs/clang-tidy/checks/modernize-replace-random-shuffle.rst
+++ docs/clang-tidy/checks/modernize-replace-random-shuffle.rst
@@ -0,0 +1,28 @@
+.. title:: clang-tidy - modernize-replace-random-shuffle
+
+modernize-replace-random-shuffle
+
+
+This check will find occurrences of ``std::random_shuffle`` and replace it with ``std::shuffle``. In C++17 ``std::random_shuffle`` will no longer be available and thus we need to replace it.
+
+Below are two examples of what kind of occurrences will be found and two examples of what it will be replaced with.
+
+.. code-block:: c++
+
+  std::vector v;
+
+  // First example
+  std::random_shuffle(vec.begin(), vec.end());
+
+  // Second example
+  std::random_shuffle(vec.begin(), vec.end(), randomFun);
+
+Both of these examples will be replaced with:
+
+.. code-block:: c++
+
+  std::shuffle(vec.begin(), vec.end(), std::mt19937(std::random_device()()));
+
+The second example will also receive a warning that ``randomFunc`` is no longer supported in the same way as before so if the user wants the same functionality, the user will need to change the implementation of the ``randomFunc``.
+
+One thing to be aware of here is that ``std::random_device`` is quite expensive to initialize. So if you are using the code in a performance critical place, you probably want to initialize it elsewhere. 
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -110,6 +110,7 @@
modernize-raw-string-literal
modernize-redundant-void-arg
modernize-replace-auto-ptr
+   modernize-replace-random-shuffle
modernize-return-braced-init-list
modernize-shrink-to-fit
modernize-use-auto
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -72,6 +72,11 @@
 
   Finds uses of inline assembler.
 
+- New `modernize-replace-random-shuffle
+  `_ check
+
+  Finds and fixes usage of ``std::random_shuffle`` as the fun

[PATCH] D30158: [clang-tidy] modernize: Find usage of random_shuffle and replace it with shuffle.

2017-03-01 Thread Mads Ravn via Phabricator via cfe-commits
madsravn added a comment.

In https://reviews.llvm.org/D30158#689904, @aaron.ballman wrote:

> Out of curiosity, have you run this over libc++ or libstdc++ test suites 
> involving `std::random_shuffle`? If so, were the results acceptable?


I haven't. Good idea. I will get onto that. I don't have either, so I will just 
fetch them and set them up.


https://reviews.llvm.org/D30158



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


[PATCH] D30087: [Driver] Unify linking of OpenMP runtime

2017-03-01 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added a comment.

Ping


https://reviews.llvm.org/D30087



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


[PATCH] D30214: [Driver] Search for libc++ headers in ResourceDir

2017-03-01 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added a comment.

Ping


https://reviews.llvm.org/D30214



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


[PATCH] D28348: [analyzer] Taught the analyzer about Glib API to check Memory-leak

2017-03-01 Thread Anna Zaks via Phabricator via cfe-commits
zaks.anna accepted this revision.
zaks.anna added a comment.
This revision is now accepted and ready to land.

> I am not clear why need to calculate the precise allocated size?

The information generated by this checker is used for array bounds checking. 
For example, see https://reviews.llvm.org/D24307

This patch looks good. Do you have commit access or should I commit it on your 
behalf?


Repository:
  rL LLVM

https://reviews.llvm.org/D28348



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


[libcxx] r296685 - Generate the test configuration even when LIBCXX_INCLUDE_TESTS=OFF.

2017-03-01 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Wed Mar  1 15:53:30 2017
New Revision: 296685

URL: http://llvm.org/viewvc/llvm-project?rev=296685&view=rev
Log:
Generate the test configuration even when LIBCXX_INCLUDE_TESTS=OFF.

This patch changes the CMake configuration so that it always
generates the test/lit.site.cfg file, even when testing is disabled.

This allows users to test libc++ without requiring them to have
a full LLVM checkout on their machine.

Modified:
libcxx/trunk/CMakeLists.txt
libcxx/trunk/test/CMakeLists.txt

Modified: libcxx/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/CMakeLists.txt?rev=296685&r1=296684&r2=296685&view=diff
==
--- libcxx/trunk/CMakeLists.txt (original)
+++ libcxx/trunk/CMakeLists.txt Wed Mar  1 15:53:30 2017
@@ -19,7 +19,6 @@ set(CMAKE_MODULE_PATH
   ${CMAKE_MODULE_PATH}
   )
 
-
 if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
   project(libcxx CXX C)
 
@@ -600,10 +599,15 @@ add_subdirectory(lib)
 if (LIBCXX_INCLUDE_BENCHMARKS)
   add_subdirectory(benchmarks)
 endif()
+
+# Create the lit.site.cfg file even when LIBCXX_INCLUDE_TESTS is OFF or
+# LLVM_FOUND is OFF. This allows users to run the tests manually using
+# LIT without requiring a full LLVM checkout.
+add_subdirectory(test)
 if (LIBCXX_INCLUDE_TESTS)
-  add_subdirectory(test)
   add_subdirectory(lib/abi)
 endif()
+
 if (LIBCXX_INCLUDE_DOCS)
   add_subdirectory(docs)
 endif()

Modified: libcxx/trunk/test/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/CMakeLists.txt?rev=296685&r1=296684&r2=296685&view=diff
==
--- libcxx/trunk/test/CMakeLists.txt (original)
+++ libcxx/trunk/test/CMakeLists.txt Wed Mar  1 15:53:30 2017
@@ -1,5 +1,3 @@
-include(AddLLVM) # for add_lit_testsuite
-
 macro(pythonize_bool var)
   if (${var})
 set(${var} True)
@@ -66,12 +64,15 @@ if (LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY
   list(APPEND LIBCXX_TEST_DEPS cxx_external_threads)
 endif()
 
-add_lit_testsuite(check-cxx
-  "Running libcxx tests"
-  ${CMAKE_CURRENT_BINARY_DIR}
-  DEPENDS cxx ${LIBCXX_TEST_DEPS})
+if (LIBCXX_INCLUDE_TESTS)
+  include(AddLLVM) # for add_lit_testsuite
+  add_lit_testsuite(check-cxx
+"Running libcxx tests"
+${CMAKE_CURRENT_BINARY_DIR}
+DEPENDS cxx ${LIBCXX_TEST_DEPS})
 
-add_custom_target(check-libcxx DEPENDS check-cxx)
+  add_custom_target(check-libcxx DEPENDS check-cxx)
+endif()
 
 if (LIBCXX_GENERATE_COVERAGE)
   include(CodeCoverage)


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


[PATCH] D30214: [Driver] Search for libc++ headers in ResourceDir

2017-03-01 Thread Jonathan Roelofs via Phabricator via cfe-commits
jroelofs added a comment.

libc++ headers should not be installed in the resource dir.


https://reviews.llvm.org/D30214



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


[PATCH] D30158: [clang-tidy] modernize: Find usage of random_shuffle and replace it with shuffle.

2017-03-01 Thread Mads Ravn via Phabricator via cfe-commits
madsravn added a comment.

Looks good for the two tests the are for `random_shuffle` in llvm libc++.


https://reviews.llvm.org/D30158



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


[PATCH] D30158: [clang-tidy] modernize: Find usage of random_shuffle and replace it with shuffle.

2017-03-01 Thread Jonathan Roelofs via Phabricator via cfe-commits
jroelofs added a comment.

In https://reviews.llvm.org/D30158#690032, @madsravn wrote:

> Looks good for the two tests the are for `random_shuffle` in llvm libc++.


There were a lot more some time ago, before @mclow.lists performed this 
transformation on libc++'s testsuite. You might want to try this on the 
revision before that happened.


https://reviews.llvm.org/D30158



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


[PATCH] D29464: [MinGWToolChain] Don't use GCC headers on Win32

2017-03-01 Thread Mateusz Mikuła via Phabricator via cfe-commits
mati865 added a comment.

Ping.


https://reviews.llvm.org/D29464



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


[PATCH] D27627: [WIP] Supporting C++ based kernel languages on AMDGPU Target

2017-03-01 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 90243.
yaxunl edited the summary of this revision.

https://reviews.llvm.org/D27627

Files:
  include/clang/AST/ASTContext.h
  include/clang/Basic/TargetInfo.h
  lib/AST/ASTContext.cpp
  lib/Basic/TargetInfo.cpp
  lib/Basic/Targets.cpp
  lib/CodeGen/CGBuiltin.cpp
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CGClass.cpp
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/CGDeclCXX.cpp
  lib/CodeGen/CGException.cpp
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CGExprCXX.cpp
  lib/CodeGen/CGExprConstant.cpp
  lib/CodeGen/CGExprScalar.cpp
  lib/CodeGen/CGGPUBuiltin.cpp
  lib/CodeGen/CGOpenMPRuntime.cpp
  lib/CodeGen/CGVTT.cpp
  lib/CodeGen/CGVTables.cpp
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenTypes.cpp
  lib/CodeGen/CodeGenTypes.h
  lib/CodeGen/ItaniumCXXABI.cpp
  test/CodeGenCUDA/address-spaces.cu
  test/CodeGenCUDA/convergent.cu
  test/CodeGenCUDA/device-var-init.cu
  test/CodeGenCUDA/device-vtable.cu
  test/CodeGenCUDA/filter-decl.cu
  test/CodeGenCUDA/function-overload.cu
  test/CodeGenCUDA/kernel-args-alignment.cu
  test/CodeGenCUDA/llvm-used.cu
  test/CodeGenCUDA/printf.cu
  test/CodeGenCXX/amdgcn-global-init.cpp
  test/OpenMP/nvptx_parallel_codegen.cpp

Index: test/OpenMP/nvptx_parallel_codegen.cpp
===
--- test/OpenMP/nvptx_parallel_codegen.cpp
+++ test/OpenMP/nvptx_parallel_codegen.cpp
@@ -2,6 +2,7 @@
 // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc
 // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple nvptx64-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-64
 // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple i386-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda -emit-llvm-bc %s -o %t-x86-host.bc
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple i386-unknown-unknown -fopenmp-targets=amdgcn -emit-llvm-bc %s -o %t-x86-host.bc
 // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple nvptx-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-x86-host.bc -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-32
 // RUN: %clang_cc1 -verify -fopenmp -fexceptions -fcxx-exceptions -x c++ -triple nvptx-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-x86-host.bc -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-32
 // expected-no-diagnostics
@@ -62,14 +63,14 @@
   return a;
 }
 
-  // CHECK-NOT: define {{.*}}void {{@__omp_offloading_.+template.+l17}}_worker()
+  // CHECK-NOT: define {{.*}}void {{@__omp_offloading_.+template.+l18}}_worker()
 
 
 
 
 
 
-  // CHECK-LABEL: define {{.*}}void {{@__omp_offloading_.+template.+l26}}_worker()
+  // CHECK-LABEL: define {{.*}}void {{@__omp_offloading_.+template.+l27}}_worker()
   // CHECK-DAG: [[OMP_EXEC_STATUS:%.+]] = alloca i8,
   // CHECK-DAG: [[OMP_WORK_FN:%.+]] = alloca i8*,
   // CHECK: store i8* null, i8** [[OMP_WORK_FN]],
@@ -122,7 +123,7 @@
   // CHECK: [[EXIT]]
   // CHECK: ret void
 
-  // CHECK: define {{.*}}void [[T6:@__omp_offloading_.+template.+l26]](i[[SZ:32|64]]
+  // CHECK: define {{.*}}void [[T6:@__omp_offloading_.+template.+l27]](i[[SZ:32|64]]
   // Create local storage for each capture.
   // CHECK:  [[LOCAL_A:%.+]] = alloca i[[SZ]],
   // CHECK-DAG:  store i[[SZ]] [[ARG_A:%.+]], i[[SZ]]* [[LOCAL_A]]
@@ -194,7 +195,7 @@
 
 
 
-  // CHECK-LABEL: define {{.*}}void {{@__omp_offloading_.+template.+l43}}_worker()
+  // CHECK-LABEL: define {{.*}}void {{@__omp_offloading_.+template.+l44}}_worker()
   // CHECK-DAG: [[OMP_EXEC_STATUS:%.+]] = alloca i8,
   // CHECK-DAG: [[OMP_WORK_FN:%.+]] = alloca i8*,
   // CHECK: store i8* null, i8** [[OMP_WORK_FN]],
@@ -238,7 +239,7 @@
   // CHECK: [[EXIT]]
   // CHECK: ret void
 
-  // CHECK: define {{.*}}void [[T6:@__omp_offloading_.+template.+l43]](i[[SZ:32|64]]
+  // CHECK: define {{.*}}void [[T6:@__omp_offloading_.+template.+l44]](i[[SZ:32|64]]
   // Create local storage for each capture.
   // CHECK:  [[LOCAL_N:%.+]] = alloca i[[SZ]],
   // CHECK:  [[LOCAL_A:%.+]] = alloca i[[SZ]],
Index: test/CodeGenCXX/amdgcn-global-init.cpp
===
--- /dev/null
+++ test/CodeGenCXX/amdgcn-global-init.cpp
@@ -0,0 +1,211 @@
+// RUN: %clang_cc1 -std=c++11 -triple=amdgcn-amd-amdhsa -emit-llvm -fexceptions %s -o - |FileCheck %s
+// RUN: %clang_cc1 -std=c++11 -triple=amdgcn-amd-amdhsa -emit-llvm %s -o - |FileCheck -check-prefix CHECK-NOEXC %s
+// RUN: %clang_cc1 -std=c++11 -triple=amdgcn-amd-amdhsa -emit-llvm \
+// RUN: -momit-leaf-frame-pointer -mdisable-fp-elim %s -o - \
+// RUN:   | FileCheck -check-prefix CHECK-FP %s
+
+struct A {
+  A();

Re: r296554 - [PS4] Set our default dialect to C++11. NFC for other targets.

2017-03-01 Thread Sean Silva via cfe-commits
On Wed, Mar 1, 2017 at 10:35 AM, Mehdi Amini  wrote:

> I’m not sure I find this nice to see this upstream.
>
> I not fond in general of this kind of difference in behavior. I don’t
> think it is good for clang to have different default for this kind of
> settings depending on the platform. It does not provide a very good user
> experience from a cross-platform point of view (i.e. my compiler behaves
> very differently when I target one platform instead of another).
>

What I like about it is that the upstream PS4 bots now test that we don't
depend on the C++98 default language standard in tests, which is net
positive IMO since it facilitates future changes. Should this be a point of
vendor/platform extensibility? That's a question for cfe-dev, but I don't
think it's unreasonable. (see also: PS4 has -fno-rtti and -fno-exceptions
by default, even though users already know to pass the right flags and
expect to have to).

-- Sean Silva


>
> —
> Mehdi
>
>
>
> On Feb 28, 2017, at 11:22 PM, Sean Silva via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
> Nice!
>
> -- Sean Silva
>
> On Tue, Feb 28, 2017 at 5:01 PM, Paul Robinson via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: probinson
>> Date: Tue Feb 28 19:01:10 2017
>> New Revision: 296554
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=296554&view=rev
>> Log:
>> [PS4] Set our default dialect to C++11. NFC for other targets.
>> Reapplies r296209 now that r296549 has fixed what really seems to be
>> the last problematic test.
>>
>> Modified:
>> cfe/trunk/lib/Frontend/CompilerInvocation.cpp
>>
>> Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/
>> CompilerInvocation.cpp?rev=296554&r1=296553&r2=296554&view=diff
>> 
>> ==
>> --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
>> +++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Tue Feb 28 19:01:10
>> 2017
>> @@ -1582,7 +1582,11 @@ void CompilerInvocation::setLangDefaults
>>  case IK_PreprocessedCXX:
>>  case IK_ObjCXX:
>>  case IK_PreprocessedObjCXX:
>> -  LangStd = LangStandard::lang_gnucxx98;
>> +  // The PS4 uses C++11 as the default C++ standard.
>> +  if (T.isPS4())
>> +LangStd = LangStandard::lang_gnucxx11;
>> +  else
>> +LangStd = LangStandard::lang_gnucxx98;
>>break;
>>  case IK_RenderScript:
>>LangStd = LangStandard::lang_c99;
>>
>>
>> ___
>> 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
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] r296704 - Fix Apple-specific XFAIL directive in libc++ test

2017-03-01 Thread Mehdi Amini via cfe-commits
Author: mehdi_amini
Date: Wed Mar  1 17:14:34 2017
New Revision: 296704

URL: http://llvm.org/viewvc/llvm-project?rev=296704&view=rev
Log:
Fix Apple-specific XFAIL directive in libc++ test

These tests are failing in XCode 8.0, 8.1, and 8.2, but not in Xcode
8.3. Annoyingly the version numbering for clang does not follow Xcode
and is bumped to 8.1 only in Xcode 8.3. So Xfailing apple-clang-8.0
should catch all cases here.

Modified:

libcxx/trunk/test/libcxx/utilities/variant/variant.variant/variant.assign/copy.pass.cpp

libcxx/trunk/test/libcxx/utilities/variant/variant.variant/variant.assign/move.pass.cpp

libcxx/trunk/test/std/utilities/variant/variant.variant/variant.status/index.pass.cpp

libcxx/trunk/test/std/utilities/variant/variant.variant/variant.status/valueless_by_exception.pass.cpp

Modified: 
libcxx/trunk/test/libcxx/utilities/variant/variant.variant/variant.assign/copy.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/utilities/variant/variant.variant/variant.assign/copy.pass.cpp?rev=296704&r1=296703&r2=296704&view=diff
==
--- 
libcxx/trunk/test/libcxx/utilities/variant/variant.variant/variant.assign/copy.pass.cpp
 (original)
+++ 
libcxx/trunk/test/libcxx/utilities/variant/variant.variant/variant.assign/copy.pass.cpp
 Wed Mar  1 17:14:34 2017
@@ -12,7 +12,7 @@
 
 // The following compilers don't generate constexpr special members correctly.
 // XFAIL: clang-3.5, clang-3.6, clang-3.7, clang-3.8
-// XFAIL: apple-clang-6, apple-clang-7, apple-clang-8
+// XFAIL: apple-clang-6, apple-clang-7, apple-clang-8.0
 
 // 
 

Modified: 
libcxx/trunk/test/libcxx/utilities/variant/variant.variant/variant.assign/move.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/utilities/variant/variant.variant/variant.assign/move.pass.cpp?rev=296704&r1=296703&r2=296704&view=diff
==
--- 
libcxx/trunk/test/libcxx/utilities/variant/variant.variant/variant.assign/move.pass.cpp
 (original)
+++ 
libcxx/trunk/test/libcxx/utilities/variant/variant.variant/variant.assign/move.pass.cpp
 Wed Mar  1 17:14:34 2017
@@ -12,7 +12,7 @@
 
 // The following compilers don't generate constexpr special members correctly.
 // XFAIL: clang-3.5, clang-3.6, clang-3.7, clang-3.8
-// XFAIL: apple-clang-6, apple-clang-7, apple-clang-8
+// XFAIL: apple-clang-6, apple-clang-7, apple-clang-8.0
 
 // 
 

Modified: 
libcxx/trunk/test/std/utilities/variant/variant.variant/variant.status/index.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/variant/variant.variant/variant.status/index.pass.cpp?rev=296704&r1=296703&r2=296704&view=diff
==
--- 
libcxx/trunk/test/std/utilities/variant/variant.variant/variant.status/index.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/utilities/variant/variant.variant/variant.status/index.pass.cpp
 Wed Mar  1 17:14:34 2017
@@ -16,7 +16,7 @@
 // virtual, private, nor protected (e.g. ConstexprTestTypes:::NoCtors).
 // XFAIL: gcc-5, gcc-6
 // XFAIL: clang-3.5, clang-3.6, clang-3.7, clang-3.8
-// XFAIL: apple-clang-6, apple-clang-7, apple-clang-8
+// XFAIL: apple-clang-6, apple-clang-7, apple-clang-8.0
 
 // 
 

Modified: 
libcxx/trunk/test/std/utilities/variant/variant.variant/variant.status/valueless_by_exception.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/variant/variant.variant/variant.status/valueless_by_exception.pass.cpp?rev=296704&r1=296703&r2=296704&view=diff
==
--- 
libcxx/trunk/test/std/utilities/variant/variant.variant/variant.status/valueless_by_exception.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/utilities/variant/variant.variant/variant.status/valueless_by_exception.pass.cpp
 Wed Mar  1 17:14:34 2017
@@ -16,7 +16,7 @@
 // virtual, private, nor protected (e.g. ConstexprTestTypes:::NoCtors).
 // XFAIL: gcc-5, gcc-6
 // XFAIL: clang-3.5, clang-3.6, clang-3.7, clang-3.8
-// XFAIL: apple-clang-6, apple-clang-7, apple-clang-8
+// XFAIL: apple-clang-6, apple-clang-7, apple-clang-8.0
 
 // 
 


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


[PATCH] D30087: [Driver] Unify linking of OpenMP runtime

2017-03-01 Thread Hal Finkel via Phabricator via cfe-commits
hfinkel added inline comments.



Comment at: lib/Driver/Tools.cpp:10334
 
-  if (Args.hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ,
-   options::OPT_fno_openmp, false)) {
+  // FIXME: Exclude this for platforms with libgomp that don't require
+  // librt. Most modern Linux platforms require it, but some may not.

Now that you've moved the comment, it is not clear what "this" means here. 
Please reword this to say that you should only pass true for GompNeedsRT on 
platforms that really need it.


https://reviews.llvm.org/D30087



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


  1   2   >