Re: [PATCH] D14905: [constexpr-lambda] Support parsing of constexpr specifier (and its inference) on lambda expressions

2016-03-05 Thread Faisal Vali via cfe-commits
faisalv removed reviewers: nwilson, aaron.ballman, hubert.reinterpretcast, 
doug.gregor.
faisalv updated this revision to Diff 49889.
faisalv marked 7 inline comments as done.
faisalv added a comment.

Incorporated Richard's feedback:

- constexpr now elicits an extension warning in pre-cxx1z
- refactored the function that parses constexpr/mutable and added recovery for 
duplicates (while emitting a diagnostic)


http://reviews.llvm.org/D14905

Files:
  include/clang/Basic/DiagnosticASTKinds.td
  include/clang/Basic/DiagnosticParseKinds.td
  include/clang/Sema/Sema.h
  lib/AST/ExprConstant.cpp
  lib/Parse/ParseExprCXX.cpp
  lib/Sema/SemaLambda.cpp
  lib/Sema/TreeTransform.h
  test/Parser/cxx1z-constexpr-lambdas.cpp
  test/SemaCXX/cxx1z-constexpr-lambdas.cpp

Index: test/SemaCXX/cxx1z-constexpr-lambdas.cpp
===
--- test/SemaCXX/cxx1z-constexpr-lambdas.cpp
+++ test/SemaCXX/cxx1z-constexpr-lambdas.cpp
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -std=c++1z -verify -fsyntax-only -fblocks %s
+// RUN: %clang_cc1 -std=c++1z -verify -fsyntax-only -fblocks -fdelayed-template-parsing %s 
+// RUN: %clang_cc1 -std=c++1z -verify -fsyntax-only -fblocks -fms-extensions %s 
+// RUN: %clang_cc1 -std=c++1z -verify -fsyntax-only -fblocks -fdelayed-template-parsing -fms-extensions %s 
+
+namespace test_constexpr_checking {
+
+namespace ns1 {
+  struct NonLit { ~NonLit(); };  //expected-note{{not literal}}
+  auto L = [](NonLit NL) constexpr { }; //expected-error{{not a literal type}}
+} // end ns1
+
+namespace ns2 {
+  auto L = [](int I) constexpr { static int J;  }; //expected-error{{not permitted in a constexpr function}}
+} // end ns1
+
+} // end ns test_constexpr_checking
+
+namespace test_constexpr_call {
+
+namespace ns1 {
+  auto L = [](int I) { return I; };
+  static_assert(L(3) == 3);
+} // end ns1
+
+} // end ns test_constexpr_call
\ No newline at end of file
Index: test/Parser/cxx1z-constexpr-lambdas.cpp
===
--- test/Parser/cxx1z-constexpr-lambdas.cpp
+++ test/Parser/cxx1z-constexpr-lambdas.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -std=c++1z %s -verify 
+// RUN: %clang_cc1 -std=c++14 %s -verify 
+// RUN: %clang_cc1 -std=c++11 %s -verify 
+
+
+auto XL0 = [] constexpr { }; //expected-error{{requires '()'}} expected-error{{expected body}}
+auto XL1 = [] () mutable mutable mutable { }; //expected-error{{cannot appear multiple times}}
+
+#if __cplusplus > 201402L
+auto XL2 = [] () constexpr mutable constexpr { }; //expected-error{{cannot appear multiple times}}
+auto L = []() mutable constexpr { };
+auto L2 = []() constexpr { };
+auto L4 = []() constexpr mutable { }; 
+#else
+auto L = []() mutable constexpr {return 0; }; //expected-warning{{is a C++1z extension}}
+auto L2 = []() constexpr { return 0;};//expected-warning{{is a C++1z extension}}
+auto L4 = []() constexpr mutable { return 0; }; //expected-warning{{is a C++1z extension}}
+#endif
+
+
Index: lib/Sema/TreeTransform.h
===
--- lib/Sema/TreeTransform.h
+++ lib/Sema/TreeTransform.h
@@ -10025,7 +10025,9 @@
   CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
   Class, E->getIntroducerRange(), NewCallOpTSI,
   E->getCallOperator()->getLocEnd(),
-  NewCallOpTSI->getTypeLoc().castAs().getParams());
+  NewCallOpTSI->getTypeLoc().castAs().getParams(),
+  E->getCallOperator()->isConstexpr());
+
   LSI->CallOperator = NewCallOperator;
 
   getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
Index: lib/Sema/SemaLambda.cpp
===
--- lib/Sema/SemaLambda.cpp
+++ lib/Sema/SemaLambda.cpp
@@ -355,7 +355,8 @@
SourceRange IntroducerRange,
TypeSourceInfo *MethodTypeInfo,
SourceLocation EndLoc,
-   ArrayRef Params) {
+   ArrayRef Params,
+   const bool IsConstexprSpecified) {
   QualType MethodType = MethodTypeInfo->getType();
   TemplateParameterList *TemplateParams = 
 getGenericLambdaTemplateParameterList(getCurLambda(), *this);
@@ -392,7 +393,7 @@
 MethodType, MethodTypeInfo,
 SC_None,
 /*isInline=*/true,
-/*isConstExpr=*/false,
+IsConstexprSpecified,
 EndLoc);
   Method->setAccess(AS_public);
   
@@ -884,8 +885,9 @@
   CXXRecordDecl *Class = createLambdaClosureType(Intro.Range, MethodTyInfo,
  KnownDependent, Intro.Default);
 
-  CXXMethodDecl *Method = startLambdaDefinition(Class, Intro.Range,
-

Re: [PATCH] D17787: [Modules] Don't swallow errors when parsing optional attributes

2016-03-05 Thread Davide Italiano via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL262789: [Modules] Don't swallow errors when parsing optional 
attributes. (authored by davide).

Changed prior to commit:
  http://reviews.llvm.org/D17787?vs=49575=49888#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D17787

Files:
  cfe/trunk/lib/Lex/ModuleMap.cpp
  cfe/trunk/test/Modules/parse-attributes.modulemap

Index: cfe/trunk/lib/Lex/ModuleMap.cpp
===
--- cfe/trunk/lib/Lex/ModuleMap.cpp
+++ cfe/trunk/lib/Lex/ModuleMap.cpp
@@ -1402,7 +1402,9 @@
   
   // Parse the optional attribute list.
   Attributes Attrs;
-  parseOptionalAttributes(Attrs);
+  if (parseOptionalAttributes(Attrs))
+return;
+
   
   // Parse the opening brace.
   if (!Tok.is(MMToken::LBrace)) {
@@ -2067,7 +2069,9 @@
 
   // Parse the optional attributes.
   Attributes Attrs;
-  parseOptionalAttributes(Attrs);
+  if (parseOptionalAttributes(Attrs))
+return;
+
   if (Attrs.IsExhaustive && !ActiveModule->Parent) {
 ActiveModule->ConfigMacrosExhaustive = true;
   }
@@ -2215,7 +2219,8 @@
 
   // Parse optional attributes.
   Attributes Attrs;
-  parseOptionalAttributes(Attrs);
+  if (parseOptionalAttributes(Attrs))
+return;
 
   if (ActiveModule) {
 // Note that we have an inferred submodule.
Index: cfe/trunk/test/Modules/parse-attributes.modulemap
===
--- cfe/trunk/test/Modules/parse-attributes.modulemap
+++ cfe/trunk/test/Modules/parse-attributes.modulemap
@@ -0,0 +1,12 @@
+// RUN: rm -rf %t.modules
+// RUN: not %clang_cc1 -fmodules -fmodules-cache-path=%t.modules \
+// RUN:   -fmodule-map-file=%s -I%S -include "Inputs/empty.h" \
+// RUN:   -fsyntax-only -x c++ /dev/null 2>&1 | FileCheck %s
+
+// CHECK: error: expected ']' to close attribute
+// CHECK-NOT: error: expected '{' to start module 'A'
+
+module A [system {
+  header "Inputs/empty.h"
+  private header "Inputs/empty.h"
+}


Index: cfe/trunk/lib/Lex/ModuleMap.cpp
===
--- cfe/trunk/lib/Lex/ModuleMap.cpp
+++ cfe/trunk/lib/Lex/ModuleMap.cpp
@@ -1402,7 +1402,9 @@
   
   // Parse the optional attribute list.
   Attributes Attrs;
-  parseOptionalAttributes(Attrs);
+  if (parseOptionalAttributes(Attrs))
+return;
+
   
   // Parse the opening brace.
   if (!Tok.is(MMToken::LBrace)) {
@@ -2067,7 +2069,9 @@
 
   // Parse the optional attributes.
   Attributes Attrs;
-  parseOptionalAttributes(Attrs);
+  if (parseOptionalAttributes(Attrs))
+return;
+
   if (Attrs.IsExhaustive && !ActiveModule->Parent) {
 ActiveModule->ConfigMacrosExhaustive = true;
   }
@@ -2215,7 +2219,8 @@
 
   // Parse optional attributes.
   Attributes Attrs;
-  parseOptionalAttributes(Attrs);
+  if (parseOptionalAttributes(Attrs))
+return;
 
   if (ActiveModule) {
 // Note that we have an inferred submodule.
Index: cfe/trunk/test/Modules/parse-attributes.modulemap
===
--- cfe/trunk/test/Modules/parse-attributes.modulemap
+++ cfe/trunk/test/Modules/parse-attributes.modulemap
@@ -0,0 +1,12 @@
+// RUN: rm -rf %t.modules
+// RUN: not %clang_cc1 -fmodules -fmodules-cache-path=%t.modules \
+// RUN:   -fmodule-map-file=%s -I%S -include "Inputs/empty.h" \
+// RUN:   -fsyntax-only -x c++ /dev/null 2>&1 | FileCheck %s
+
+// CHECK: error: expected ']' to close attribute
+// CHECK-NOT: error: expected '{' to start module 'A'
+
+module A [system {
+  header "Inputs/empty.h"
+  private header "Inputs/empty.h"
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r262789 - [Modules] Don't swallow errors when parsing optional attributes.

2016-03-05 Thread Davide Italiano via cfe-commits
Author: davide
Date: Sat Mar  5 22:20:05 2016
New Revision: 262789

URL: http://llvm.org/viewvc/llvm-project?rev=262789=rev
Log:
[Modules] Don't swallow errors when parsing optional attributes.

Differential Revision:  http://reviews.llvm.org/D17787

Added:
cfe/trunk/test/Modules/parse-attributes.modulemap
Modified:
cfe/trunk/lib/Lex/ModuleMap.cpp

Modified: cfe/trunk/lib/Lex/ModuleMap.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/ModuleMap.cpp?rev=262789=262788=262789=diff
==
--- cfe/trunk/lib/Lex/ModuleMap.cpp (original)
+++ cfe/trunk/lib/Lex/ModuleMap.cpp Sat Mar  5 22:20:05 2016
@@ -1402,7 +1402,9 @@ void ModuleMapParser::parseModuleDecl()
   
   // Parse the optional attribute list.
   Attributes Attrs;
-  parseOptionalAttributes(Attrs);
+  if (parseOptionalAttributes(Attrs))
+return;
+
   
   // Parse the opening brace.
   if (!Tok.is(MMToken::LBrace)) {
@@ -2067,7 +2069,9 @@ void ModuleMapParser::parseConfigMacros(
 
   // Parse the optional attributes.
   Attributes Attrs;
-  parseOptionalAttributes(Attrs);
+  if (parseOptionalAttributes(Attrs))
+return;
+
   if (Attrs.IsExhaustive && !ActiveModule->Parent) {
 ActiveModule->ConfigMacrosExhaustive = true;
   }
@@ -2215,7 +2219,8 @@ void ModuleMapParser::parseInferredModul
 
   // Parse optional attributes.
   Attributes Attrs;
-  parseOptionalAttributes(Attrs);
+  if (parseOptionalAttributes(Attrs))
+return;
 
   if (ActiveModule) {
 // Note that we have an inferred submodule.

Added: cfe/trunk/test/Modules/parse-attributes.modulemap
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/parse-attributes.modulemap?rev=262789=auto
==
--- cfe/trunk/test/Modules/parse-attributes.modulemap (added)
+++ cfe/trunk/test/Modules/parse-attributes.modulemap Sat Mar  5 22:20:05 2016
@@ -0,0 +1,12 @@
+// RUN: rm -rf %t.modules
+// RUN: not %clang_cc1 -fmodules -fmodules-cache-path=%t.modules \
+// RUN:   -fmodule-map-file=%s -I%S -include "Inputs/empty.h" \
+// RUN:   -fsyntax-only -x c++ /dev/null 2>&1 | FileCheck %s
+
+// CHECK: error: expected ']' to close attribute
+// CHECK-NOT: error: expected '{' to start module 'A'
+
+module A [system {
+  header "Inputs/empty.h"
+  private header "Inputs/empty.h"
+}


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


[clang-tools-extra] r262787 - [docs] Clean up doxygen comments a bit.

2016-03-05 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Sat Mar  5 22:05:59 2016
New Revision: 262787

URL: http://llvm.org/viewvc/llvm-project?rev=262787=rev
Log:
[docs] Clean up doxygen comments a bit.

Modified:
clang-tools-extra/trunk/clang-tidy/ClangTidy.h

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidy.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidy.h?rev=262787=262786=262787=diff
==
--- clang-tools-extra/trunk/clang-tidy/ClangTidy.h (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidy.h Sat Mar  5 22:05:59 2016
@@ -31,37 +31,37 @@ class CompilationDatabase;
 
 namespace tidy {
 
-/// \brief Provides access to the \c ClangTidyCheck options via check-local
+/// \brief Provides access to the ``ClangTidyCheck`` options via check-local
 /// names.
 ///
-/// Methods of this class prepend CheckName + "." to translate
-/// check-local option names to global option names.
+/// Methods of this class prepend ``CheckName + "."`` to translate check-local
+/// option names to global option names.
 class OptionsView {
 public:
   /// \brief Initializes the instance using \p CheckName + "." as a prefix.
   OptionsView(StringRef CheckName,
   const ClangTidyOptions::OptionMap );
 
-  /// \brief Read a named option from the \c Context.
+  /// \brief Read a named option from the ``Context``.
   ///
   /// Reads the option with the check-local name \p LocalName from the
-  /// \c CheckOptions. If the corresponding key is not present, returns
+  /// ``CheckOptions``. If the corresponding key is not present, returns
   /// \p Default.
   std::string get(StringRef LocalName, StringRef Default) const;
 
-  /// \brief Read a named option from the \c Context.
+  /// \brief Read a named option from the ``Context``.
   ///
   /// Reads the option with the check-local name \p LocalName from local or
-  /// global \c CheckOptions. Gets local option first. If local is not
-  /// present, falls back to get global option. If global option is not present
-  /// either, returns Default.
+  /// global ``CheckOptions``. Gets local option first. If local is not 
present,
+  /// falls back to get global option. If global option is not present either,
+  /// returns Default.
   std::string getLocalOrGlobal(StringRef LocalName, StringRef Default) const;
 
-  /// \brief Read a named option from the \c Context and parse it as an 
integral
-  /// type \c T.
+  /// \brief Read a named option from the ``Context`` and parse it as an
+  /// integral type ``T``.
   ///
   /// Reads the option with the check-local name \p LocalName from the
-  /// \c CheckOptions. If the corresponding key is not present, returns
+  /// ``CheckOptions``. If the corresponding key is not present, returns
   /// \p Default.
   template 
   typename std::enable_if::type
@@ -79,7 +79,7 @@ public:
  StringRef Value) const;
 
   /// \brief Stores an option with the check-local name \p LocalName with
-  /// \c int64_t value \p Value to \p Options.
+  /// ``int64_t`` value \p Value to \p Options.
   void store(ClangTidyOptions::OptionMap , StringRef LocalName,
  int64_t Value) const;
 
@@ -90,20 +90,20 @@ private:
 
 /// \brief Base class for all clang-tidy checks.
 ///
-/// To implement a \c ClangTidyCheck, write a subclass and override some of the
+/// To implement a ``ClangTidyCheck``, write a subclass and override some of 
the
 /// base class's methods. E.g. to implement a check that validates namespace
-/// declarations, override \c registerMatchers:
+/// declarations, override ``registerMatchers``:
 ///
-/// \code
-/// registerMatchers(ast_matchers::MatchFinder *Finder) {
+/// ```c++
+/// void registerMatchers(ast_matchers::MatchFinder *Finder) override {
 ///   Finder->addMatcher(namespaceDecl().bind("namespace"), this);
 /// }
-/// \endcode
+/// ```
 ///
-/// and then override \c check(const MatchResult ) to do the actual
+/// and then override ``check(const MatchResult )`` to do the actual
 /// check for each match.
 ///
-/// A new \c ClangTidyCheck instance is created per translation unit.
+/// A new ``ClangTidyCheck`` instance is created per translation unit.
 ///
 /// FIXME: Figure out whether carrying information from one TU to another is
 /// useful/necessary.
@@ -121,7 +121,7 @@ public:
 assert(!CheckName.empty());
   }
 
-  /// \brief Override this to register \c PPCallbacks with \c Compiler.
+  /// \brief Override this to register ``PPCallbacks`` with ``Compiler``.
   ///
   /// This should be used for clang-tidy checks that analyze preprocessor-
   /// dependent properties, e.g. the order of include directives.
@@ -141,7 +141,7 @@ public:
   /// matches occur in the order of the AST traversal.
   virtual void registerMatchers(ast_matchers::MatchFinder *Finder) {}
 
-  /// \brief \c ClangTidyChecks that register ASTMatchers should do the actual
+  /// \brief ``ClangTidyChecks`` that register 

r262783 - Fixed -Wdocumentation warning - typo in a parameter name

2016-03-05 Thread Simon Pilgrim via cfe-commits
Author: rksimon
Date: Sat Mar  5 16:35:55 2016
New Revision: 262783

URL: http://llvm.org/viewvc/llvm-project?rev=262783=rev
Log:
Fixed -Wdocumentation warning - typo in a parameter name

Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h?rev=262783=262782=262783=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h Sat Mar  5 16:35:55 2016
@@ -819,7 +819,7 @@ public:
   /// global_tid, kmp_int32 num_teams, kmp_int32 thread_limit) to generate code
   /// for num_teams clause.
   /// \param NumTeams An integer value of teams.
-  /// \param ThreadsLimit An integer value of threads.
+  /// \param ThreadLimit An integer value of threads.
   virtual void emitNumTeamsClause(CodeGenFunction , llvm::Value *NumTeams,
   llvm::Value *ThreadLimit, SourceLocation 
Loc);
 


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


Re: [PATCH] D15921: [analyzer] Utility to match function calls.

2016-03-05 Thread Alexander Riccio via cfe-commits
ariccio added a subscriber: ariccio.
ariccio added a comment.

Side note: Has anybody ever considered just treating `fopen` and `fclose` like 
`malloc` and `free`?

On Windows I use a trick that I discovered what I call "the 
`_Post_ptr_invalid_` hack" because* the `_Post_ptr_invalid_` SAL annotation 
lets me treat the argument to `CloseHandle` like the argument to `free`, and 
reports double closes as double frees.

Here we'd just treat the `FILE*` as a different region of memory, to check that 
they're not mixed.

- this also works in part because a Windows `HANDLE` is just a `typedef`d 
`void*`



Comment at: cfe/trunk/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp:106
@@ -108,3 +105,3 @@
 SimpleStreamChecker::SimpleStreamChecker()
-: IIfopen(nullptr), IIfclose(nullptr) {
+: OpenFn("fopen"), CloseFn("fclose", 1) {
   // Initialize the bug types.

Why specify the RequiredArgs for `fclose`,  and not `fopen`?


Repository:
  rL LLVM

http://reviews.llvm.org/D15921



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


Re: [PATCH] D17488: Extend UnnecessaryCopyInitialization check to trigger on non-const copies that can be safely converted to const references.

2016-03-05 Thread Felix Berger via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL262781: [clang-tidy] Extend UnnecessaryCopyInitialization 
check to trigger on non… (authored by flx).

Changed prior to commit:
  http://reviews.llvm.org/D17488?vs=49884=49885#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D17488

Files:
  clang-tools-extra/trunk/clang-tidy/performance/ForRangeCopyCheck.cpp
  
clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
  clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryCopyInitialization.h
  clang-tools-extra/trunk/clang-tidy/utils/CMakeLists.txt
  clang-tools-extra/trunk/clang-tidy/utils/DeclRefExprUtils.cpp
  clang-tools-extra/trunk/clang-tidy/utils/DeclRefExprUtils.h
  clang-tools-extra/trunk/clang-tidy/utils/FixItHintUtils.cpp
  clang-tools-extra/trunk/clang-tidy/utils/FixItHintUtils.h
  
clang-tools-extra/trunk/docs/clang-tidy/checks/performance-unnecessary-copy-initialization.rst
  
clang-tools-extra/trunk/test/clang-tidy/performance-unnecessary-copy-initialization.cpp

Index: clang-tools-extra/trunk/clang-tidy/performance/ForRangeCopyCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/performance/ForRangeCopyCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/performance/ForRangeCopyCheck.cpp
@@ -8,92 +8,15 @@
 //===--===//
 
 #include "ForRangeCopyCheck.h"
-#include "../utils/LexerUtils.h"
+#include "../utils/DeclRefExprUtils.h"
+#include "../utils/FixItHintUtils.h"
 #include "../utils/TypeTraits.h"
-#include "clang/Lex/Lexer.h"
-#include "llvm/ADT/SmallPtrSet.h"
 
 namespace clang {
 namespace tidy {
 namespace performance {
 
 using namespace ::clang::ast_matchers;
-using llvm::SmallPtrSet;
-
-namespace {
-
-template  bool isSetDifferenceEmpty(const S , const S ) {
-  for (const auto  : S1)
-if (S2.count(E) == 0)
-  return false;
-  return true;
-}
-
-// Extracts all Nodes keyed by ID from Matches and inserts them into Nodes.
-template 
-void extractNodesByIdTo(ArrayRef Matches, StringRef ID,
-SmallPtrSet ) {
-  for (const auto  : Matches)
-Nodes.insert(Match.getNodeAs(ID));
-}
-
-// Finds all DeclRefExprs to VarDecl in Stmt.
-SmallPtrSet
-declRefExprs(const VarDecl , const Stmt , ASTContext ) {
-  auto Matches = match(
-  findAll(declRefExpr(to(varDecl(equalsNode(.bind("declRef")),
-  Stmt, Context);
-  SmallPtrSet DeclRefs;
-  extractNodesByIdTo(Matches, "declRef", DeclRefs);
-  return DeclRefs;
-}
-
-// Finds all DeclRefExprs where a const method is called on VarDecl or VarDecl
-// is the a const reference or value argument to a CallExpr or CXXConstructExpr.
-SmallPtrSet
-constReferenceDeclRefExprs(const VarDecl , const Stmt ,
-   ASTContext ) {
-  auto DeclRefToVar =
-  declRefExpr(to(varDecl(equalsNode(.bind("declRef");
-  auto ConstMethodCallee = callee(cxxMethodDecl(isConst()));
-  // Match method call expressions where the variable is referenced as the this
-  // implicit object argument and opertor call expression for member operators
-  // where the variable is the 0-th argument.
-  auto Matches = match(
-  findAll(expr(anyOf(cxxMemberCallExpr(ConstMethodCallee, on(DeclRefToVar)),
- cxxOperatorCallExpr(ConstMethodCallee,
- hasArgument(0, DeclRefToVar),
-  Stmt, Context);
-  SmallPtrSet DeclRefs;
-  extractNodesByIdTo(Matches, "declRef", DeclRefs);
-  auto ConstReferenceOrValue =
-  qualType(anyOf(referenceType(pointee(qualType(isConstQualified(,
- unless(anyOf(referenceType(), pointerType();
-  auto UsedAsConstRefOrValueArg = forEachArgumentWithParam(
-  DeclRefToVar, parmVarDecl(hasType(ConstReferenceOrValue)));
-  Matches = match(findAll(callExpr(UsedAsConstRefOrValueArg)), Stmt, Context);
-  extractNodesByIdTo(Matches, "declRef", DeclRefs);
-  Matches =
-  match(findAll(cxxConstructExpr(UsedAsConstRefOrValueArg)), Stmt, Context);
-  extractNodesByIdTo(Matches, "declRef", DeclRefs);
-  return DeclRefs;
-}
-
-// Modifies VarDecl to be a reference.
-FixItHint createAmpersandFix(const VarDecl , ASTContext ) {
-  SourceLocation AmpLocation = VarDecl.getLocation();
-  auto Token = lexer_utils::getPreviousNonCommentToken(Context, AmpLocation);
-  if (!Token.is(tok::unknown))
-AmpLocation = Token.getLocation().getLocWithOffset(Token.getLength());
-  return FixItHint::CreateInsertion(AmpLocation, "&");
-}
-
-// Modifies VarDecl to be const.
-FixItHint createConstFix(const VarDecl ) {
-  return FixItHint::CreateInsertion(VarDecl.getTypeSpecStartLoc(), "const ");
-}
-
-} // namespace
 
 ForRangeCopyCheck::ForRangeCopyCheck(StringRef Name, ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
@@ -143,35 +66,26 @@
   diag(LoopVar.getLocation(),
"the loop variable's 

[clang-tools-extra] r262781 - [clang-tidy] Extend UnnecessaryCopyInitialization check to trigger on non-const copies that can be safely converted to const references.

2016-03-05 Thread Felix Berger via cfe-commits
Author: flx
Date: Sat Mar  5 15:17:58 2016
New Revision: 262781

URL: http://llvm.org/viewvc/llvm-project?rev=262781=rev
Log:
[clang-tidy] Extend UnnecessaryCopyInitialization check to trigger on non-const 
copies that can be safely converted to const references.

Summary:
Move code shared between UnnecessaryCopyInitialization and ForRangeCopyCheck 
into utilities files.
Add more test cases for UnnecessaryCopyInitialization and disable fixes inside 
of macros.

Reviewers: alexfh

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D17488

Added:
clang-tools-extra/trunk/clang-tidy/utils/DeclRefExprUtils.cpp
clang-tools-extra/trunk/clang-tidy/utils/DeclRefExprUtils.h
clang-tools-extra/trunk/clang-tidy/utils/FixItHintUtils.cpp
clang-tools-extra/trunk/clang-tidy/utils/FixItHintUtils.h

clang-tools-extra/trunk/docs/clang-tidy/checks/performance-unnecessary-copy-initialization.rst
Modified:
clang-tools-extra/trunk/clang-tidy/performance/ForRangeCopyCheck.cpp

clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryCopyInitialization.cpp

clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryCopyInitialization.h
clang-tools-extra/trunk/clang-tidy/utils/CMakeLists.txt

clang-tools-extra/trunk/test/clang-tidy/performance-unnecessary-copy-initialization.cpp

Modified: clang-tools-extra/trunk/clang-tidy/performance/ForRangeCopyCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/performance/ForRangeCopyCheck.cpp?rev=262781=262780=262781=diff
==
--- clang-tools-extra/trunk/clang-tidy/performance/ForRangeCopyCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/performance/ForRangeCopyCheck.cpp Sat 
Mar  5 15:17:58 2016
@@ -8,92 +8,15 @@
 
//===--===//
 
 #include "ForRangeCopyCheck.h"
-#include "../utils/LexerUtils.h"
+#include "../utils/DeclRefExprUtils.h"
+#include "../utils/FixItHintUtils.h"
 #include "../utils/TypeTraits.h"
-#include "clang/Lex/Lexer.h"
-#include "llvm/ADT/SmallPtrSet.h"
 
 namespace clang {
 namespace tidy {
 namespace performance {
 
 using namespace ::clang::ast_matchers;
-using llvm::SmallPtrSet;
-
-namespace {
-
-template  bool isSetDifferenceEmpty(const S , const S ) {
-  for (const auto  : S1)
-if (S2.count(E) == 0)
-  return false;
-  return true;
-}
-
-// Extracts all Nodes keyed by ID from Matches and inserts them into Nodes.
-template 
-void extractNodesByIdTo(ArrayRef Matches, StringRef ID,
-SmallPtrSet ) {
-  for (const auto  : Matches)
-Nodes.insert(Match.getNodeAs(ID));
-}
-
-// Finds all DeclRefExprs to VarDecl in Stmt.
-SmallPtrSet
-declRefExprs(const VarDecl , const Stmt , ASTContext ) {
-  auto Matches = match(
-  findAll(declRefExpr(to(varDecl(equalsNode(.bind("declRef")),
-  Stmt, Context);
-  SmallPtrSet DeclRefs;
-  extractNodesByIdTo(Matches, "declRef", DeclRefs);
-  return DeclRefs;
-}
-
-// Finds all DeclRefExprs where a const method is called on VarDecl or VarDecl
-// is the a const reference or value argument to a CallExpr or 
CXXConstructExpr.
-SmallPtrSet
-constReferenceDeclRefExprs(const VarDecl , const Stmt ,
-   ASTContext ) {
-  auto DeclRefToVar =
-  declRefExpr(to(varDecl(equalsNode(.bind("declRef");
-  auto ConstMethodCallee = callee(cxxMethodDecl(isConst()));
-  // Match method call expressions where the variable is referenced as the this
-  // implicit object argument and opertor call expression for member operators
-  // where the variable is the 0-th argument.
-  auto Matches = match(
-  findAll(expr(anyOf(cxxMemberCallExpr(ConstMethodCallee, 
on(DeclRefToVar)),
- cxxOperatorCallExpr(ConstMethodCallee,
- hasArgument(0, DeclRefToVar),
-  Stmt, Context);
-  SmallPtrSet DeclRefs;
-  extractNodesByIdTo(Matches, "declRef", DeclRefs);
-  auto ConstReferenceOrValue =
-  qualType(anyOf(referenceType(pointee(qualType(isConstQualified(,
- unless(anyOf(referenceType(), pointerType();
-  auto UsedAsConstRefOrValueArg = forEachArgumentWithParam(
-  DeclRefToVar, parmVarDecl(hasType(ConstReferenceOrValue)));
-  Matches = match(findAll(callExpr(UsedAsConstRefOrValueArg)), Stmt, Context);
-  extractNodesByIdTo(Matches, "declRef", DeclRefs);
-  Matches =
-  match(findAll(cxxConstructExpr(UsedAsConstRefOrValueArg)), Stmt, 
Context);
-  extractNodesByIdTo(Matches, "declRef", DeclRefs);
-  return DeclRefs;
-}
-
-// Modifies VarDecl to be a reference.
-FixItHint createAmpersandFix(const VarDecl , ASTContext ) {
-  SourceLocation AmpLocation = VarDecl.getLocation();
-  auto Token = lexer_utils::getPreviousNonCommentToken(Context, AmpLocation);
-  if (!Token.is(tok::unknown))
-AmpLocation = 

r262780 - Misc: add a test for TargetParser usage

2016-03-05 Thread Saleem Abdulrasool via cfe-commits
Author: compnerd
Date: Sat Mar  5 15:12:33 2016
New Revision: 262780

URL: http://llvm.org/viewvc/llvm-project?rev=262780=rev
Log:
Misc: add a test for TargetParser usage

Ensure that an invalid value passed to target parser does not cause an assertion
in +Asserts builds.

Supporting test for PR26839.

Added:
cfe/trunk/test/Misc/target-parser.c

Added: cfe/trunk/test/Misc/target-parser.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/target-parser.c?rev=262780=auto
==
--- cfe/trunk/test/Misc/target-parser.c (added)
+++ cfe/trunk/test/Misc/target-parser.c Sat Mar  5 15:12:33 2016
@@ -0,0 +1,2 @@
+// RUN: not %clang_cc1 -triple armv7--- -target-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s
+// CHECK: error: unknown target CPU 'not-a-cpu'


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


Re: [PATCH] D17488: Extend UnnecessaryCopyInitialization check to trigger on non-const copies that can be safely converted to const references.

2016-03-05 Thread Felix Berger via cfe-commits
flx updated this revision to Diff 49884.
flx marked an inline comment as done.

http://reviews.llvm.org/D17488

Files:
  clang-tidy/performance/ForRangeCopyCheck.cpp
  clang-tidy/performance/UnnecessaryCopyInitialization.cpp
  clang-tidy/performance/UnnecessaryCopyInitialization.h
  clang-tidy/utils/CMakeLists.txt
  clang-tidy/utils/DeclRefExprUtils.cpp
  clang-tidy/utils/DeclRefExprUtils.h
  clang-tidy/utils/FixItHintUtils.cpp
  clang-tidy/utils/FixItHintUtils.h
  docs/clang-tidy/checks/performance-unnecessary-copy-initialization.rst
  test/clang-tidy/performance-unnecessary-copy-initialization.cpp

Index: test/clang-tidy/performance-unnecessary-copy-initialization.cpp
===
--- test/clang-tidy/performance-unnecessary-copy-initialization.cpp
+++ test/clang-tidy/performance-unnecessary-copy-initialization.cpp
@@ -4,6 +4,7 @@
   ExpensiveToCopyType() {}
   virtual ~ExpensiveToCopyType() {}
   const ExpensiveToCopyType () const { return *this; }
+  void nonConstMethod() {}
 };
 
 struct TrivialToCopyType {
@@ -20,6 +21,11 @@
   return *Type;
 }
 
+void mutate(ExpensiveToCopyType &);
+void mutate(ExpensiveToCopyType *);
+void useAsConstReference(const ExpensiveToCopyType &);
+void useByValue(ExpensiveToCopyType);
+
 void PositiveFunctionCall() {
   const auto AutoAssigned = ExpensiveTypeReference();
   // CHECK-MESSAGES: [[@LINE-1]]:14: warning: the const qualified variable 'AutoAssigned' is copy-constructed from a const reference; consider making it a const reference [performance-unnecessary-copy-initialization]
@@ -114,11 +120,53 @@
   static const auto StaticVar = Obj.reference();
 }
 
-void NegativeFunctionCallExpensiveTypeNonConstVariable() {
+void PositiveFunctionCallExpensiveTypeNonConstVariable() {
   auto AutoAssigned = ExpensiveTypeReference();
+  // CHECK-MESSAGES: [[@LINE-1]]:8: warning: the variable 'AutoAssigned' is copy-constructed from a const reference but is only used as const reference; consider making it a const reference [performance-unnecessary-copy-initialization]
+  // CHECK-FIXES: const auto& AutoAssigned = ExpensiveTypeReference();
   auto AutoCopyConstructed(ExpensiveTypeReference());
+  // CHECK-MESSAGES: [[@LINE-1]]:8: warning: the variable
+  // CHECK-FIXES: const auto& AutoCopyConstructed(ExpensiveTypeReference());
   ExpensiveToCopyType VarAssigned = ExpensiveTypeReference();
+  // CHECK-MESSAGES: [[@LINE-1]]:23: warning: the variable
+  // CHECK-FIXES: const ExpensiveToCopyType& VarAssigned = ExpensiveTypeReference();
   ExpensiveToCopyType VarCopyConstructed(ExpensiveTypeReference());
+  // CHECK-MESSAGES: [[@LINE-1]]:23: warning: the variable
+  // CHECK-FIXES: const ExpensiveToCopyType& VarCopyConstructed(ExpensiveTypeReference());
+}
+
+void positiveNonConstVarInCodeBlock(const ExpensiveToCopyType ) {
+  {
+auto Assigned = Obj.reference();
+// CHECK-MESSAGES: [[@LINE-1]]:10: warning: the variable
+// CHECK-FIXES: const auto& Assigned = Obj.reference();
+Assigned.reference();
+useAsConstReference(Assigned);
+useByValue(Assigned);
+  }
+}
+
+void negativeNonConstVarWithNonConstUse(const ExpensiveToCopyType ) {
+  {
+auto NonConstInvoked = Obj.reference();
+// CHECK-FIXES: auto NonConstInvoked = Obj.reference();
+NonConstInvoked.nonConstMethod();
+  }
+  {
+auto Reassigned = Obj.reference();
+// CHECK-FIXES: auto Reassigned = Obj.reference();
+Reassigned = ExpensiveToCopyType();
+  }
+  {
+auto MutatedByReference = Obj.reference();
+// CHECK-FIXES: auto MutatedByReference = Obj.reference();
+mutate(MutatedByReference);
+  }
+  {
+auto MutatedByPointer = Obj.reference();
+// CHECK-FIXES: auto MutatedByPointer = Obj.reference();
+mutate();
+  }
 }
 
 void NegativeMethodCallNonConstRef(ExpensiveToCopyType ) {
@@ -146,11 +194,32 @@
   ExpensiveToCopyType Obj;
   const auto AutoAssigned = Obj.reference();
   const auto AutoCopyConstructed(Obj.reference());
-  const ExpensiveToCopyType VarAssigned = Obj.reference();
-  const ExpensiveToCopyType VarCopyConstructed(Obj.reference());
+  ExpensiveToCopyType VarAssigned = Obj.reference();
+  ExpensiveToCopyType VarCopyConstructed(Obj.reference());
 }
 
 struct NegativeConstructor {
   NegativeConstructor(const ExpensiveToCopyType ) : Obj(Obj) {}
   ExpensiveToCopyType Obj;
 };
+
+#define UNNECESSARY_COPY_INIT_IN_MACRO_BODY(TYPE)	\
+  void functionWith##TYPE(const TYPE& T) {		\
+auto AssignedInMacro = T.reference();		\
+  }			\
+// Ensure fix is not applied.
+// CHECK-FIXES: auto AssignedInMacro = T.reference();
+
+
+UNNECESSARY_COPY_INIT_IN_MACRO_BODY(ExpensiveToCopyType)
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: the variable 'AssignedInMacro' is copy-constructed
+
+#define UNNECESSARY_COPY_INIT_IN_MACRO_ARGUMENT(ARGUMENT)	\
+  ARGUMENT
+
+void PositiveMacroArgument(const ExpensiveToCopyType ) {
+  UNNECESSARY_COPY_INIT_IN_MACRO_ARGUMENT(auto CopyInMacroArg = Obj.reference());
+  // 

Re: [PATCH] D17910: clang-format: [JS] Handle certain cases of ASI.

2016-03-05 Thread Martin Probst via cfe-commits
mprobst updated this revision to Diff 49883.
mprobst added a comment.

- Handle unary !.


http://reviews.llvm.org/D17910

Files:
  lib/Format/UnwrappedLineParser.cpp
  lib/Format/UnwrappedLineParser.h
  unittests/Format/FormatTestJS.cpp

Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -52,6 +52,13 @@
 std::string result = format(test::messUp(Code), Style);
 EXPECT_EQ(Code.str(), result) << "Formatted:\n" << result;
   }
+
+  static void verifyFormatNoMessup(
+  llvm::StringRef Code,
+  const FormatStyle  = getGoogleStyle(FormatStyle::LK_JavaScript)) {
+std::string result = format(Code, Style);
+EXPECT_EQ(Code.str(), result) << "Formatted:\n" << result;
+  }
 };
 
 TEST_F(FormatTestJS, UnderstandsJavaScriptOperators) {
@@ -608,7 +615,7 @@
"}");
 }
 
-TEST_F(FormatTestJS, AutomaticSemicolonInsertion) {
+TEST_F(FormatTestJS, WrapRespectsAutomaticSemicolonInsertion) {
   // The following statements must not wrap, as otherwise the program meaning
   // would change due to automatic semicolon insertion.
   // See http://www.ecma-international.org/ecma-262/5.1/#sec-7.9.1.
@@ -624,6 +631,30 @@
getGoogleJSStyleWithColumns(12));
 }
 
+TEST_F(FormatTestJS, AutomaticSemicolonInsertionHeuristic) {
+  verifyFormatNoMessup("a\n"
+   "b;");
+  verifyFormatNoMessup("a()\n"
+   "b;");
+  verifyFormatNoMessup("a[b]\n"
+   "c;");
+  verifyFormatNoMessup("1\n"
+   "a;");
+  verifyFormatNoMessup("a\n"
+   "1;");
+  verifyFormatNoMessup("a\n"
+   "'x';");
+  verifyFormatNoMessup("a++\n"
+   "b;");
+  verifyFormatNoMessup("a\n"
+   "!b && c;");
+  EXPECT_EQ("var a", format("var\n"
+"a"));
+  EXPECT_EQ("x instanceof String", format("x\n"
+  "instanceof\n"
+  "String"));
+}
+
 TEST_F(FormatTestJS, ClosureStyleCasts) {
   verifyFormat("var x = /** @type {foo} */ (bar);");
 }
Index: lib/Format/UnwrappedLineParser.h
===
--- lib/Format/UnwrappedLineParser.h
+++ lib/Format/UnwrappedLineParser.h
@@ -81,6 +81,8 @@
   void parsePPElse();
   void parsePPEndIf();
   void parsePPUnknown();
+  bool shouldInsertSemiBetween(FormatToken *Previous, FormatToken *Next);
+  bool isJavaScriptIdentifier(FormatToken *FormatTok);
   void parseStructuralElement();
   bool tryToParseBracedList();
   bool parseBracedList(bool ContinueOnSemicolons = false);
Index: lib/Format/UnwrappedLineParser.cpp
===
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -658,6 +658,48 @@
  Tok.isNot(tok::kw_noexcept);
 }
 
+// shouldInsertSemiBetween returns true if Automatic Semicolon Insertion must
+// happen between |Previous| and |Next|. This method is conservative - it cannot
+// cover all edge cases of JavaScript, but only aims to correctly handle certain
+// well known cases. It *must not* return true in speculative cases.
+bool UnwrappedLineParser::shouldInsertSemiBetween(FormatToken *Previous,
+  FormatToken *Next) {
+  bool IsOnSameLine =
+  CommentsBeforeNextToken.empty()
+  ? Next->NewlinesBefore == 0
+  : CommentsBeforeNextToken.front()->NewlinesBefore == 0;
+  if (IsOnSameLine)
+return false;
+
+  bool PreviousMustBeValue =
+  isJavaScriptIdentifier(Previous) || Previous->Tok.isLiteral();
+  bool NextMustBeValue = isJavaScriptIdentifier(Next) || Next->Tok.isLiteral();
+  if (NextMustBeValue && PreviousMustBeValue)
+return true;
+  if ((Previous->is(tok::r_square) || Previous->is(tok::r_paren)) &&
+  NextMustBeValue)
+return true;
+  if (PreviousMustBeValue && Next->is(tok::exclaim))
+return true;
+  if (Previous->isOneOf(tok::plusplus, tok::minusminus) &&
+  NextMustBeValue)
+return true;
+  return false;
+}
+
+bool UnwrappedLineParser::isJavaScriptIdentifier(FormatToken *FormatTok) {
+  return FormatTok->is(tok::identifier) &&
+ (FormatTok->Tok.getIdentifierInfo() == nullptr ||
+  !FormatTok->isOneOf(Keywords.kw_in, Keywords.kw_of,
+  Keywords.kw_finally, Keywords.kw_function,
+  Keywords.kw_import, Keywords.kw_is,
+  Keywords.kw_let, Keywords.kw_var,
+  Keywords.kw_abstract, Keywords.kw_extends,
+  Keywords.kw_implements, Keywords.kw_instanceof,
+  Keywords.kw_interface, Keywords.kw_throws));
+}
+
+
 void UnwrappedLineParser::parseStructuralElement() {
   

[PATCH] D17910: clang-format: [JS] Handle certain cases of ASI.

2016-03-05 Thread Martin Probst via cfe-commits
mprobst created this revision.
mprobst added a reviewer: djasper.
mprobst added subscribers: cfe-commits, klimek.

Automatic Semicolon Insertion can only be properly handled by parsing
source code. However conservatively catching just a few, common
situations prevents breaking code during development, which greatly
improves usability.

JS code should still use semicolons, and ASI code should be flagged by
a compiler or linter.

http://reviews.llvm.org/D17910

Files:
  lib/Format/UnwrappedLineParser.cpp
  lib/Format/UnwrappedLineParser.h
  unittests/Format/FormatTestJS.cpp

Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -52,6 +52,13 @@
 std::string result = format(test::messUp(Code), Style);
 EXPECT_EQ(Code.str(), result) << "Formatted:\n" << result;
   }
+
+  static void verifyFormatNoMessup(
+  llvm::StringRef Code,
+  const FormatStyle  = getGoogleStyle(FormatStyle::LK_JavaScript)) {
+std::string result = format(Code, Style);
+EXPECT_EQ(Code.str(), result) << "Formatted:\n" << result;
+  }
 };
 
 TEST_F(FormatTestJS, UnderstandsJavaScriptOperators) {
@@ -608,7 +615,7 @@
"}");
 }
 
-TEST_F(FormatTestJS, AutomaticSemicolonInsertion) {
+TEST_F(FormatTestJS, WrapRespectsAutomaticSemicolonInsertion) {
   // The following statements must not wrap, as otherwise the program meaning
   // would change due to automatic semicolon insertion.
   // See http://www.ecma-international.org/ecma-262/5.1/#sec-7.9.1.
@@ -624,6 +631,28 @@
getGoogleJSStyleWithColumns(12));
 }
 
+TEST_F(FormatTestJS, AutomaticSemicolonInsertionHeuristic) {
+  verifyFormatNoMessup("a\n"
+   "b;");
+  verifyFormatNoMessup("a()\n"
+   "b;");
+  verifyFormatNoMessup("a[b]\n"
+   "c;");
+  verifyFormatNoMessup("1\n"
+   "a;");
+  verifyFormatNoMessup("a\n"
+   "1;");
+  verifyFormatNoMessup("a\n"
+   "'x';");
+  verifyFormatNoMessup("a++\n"
+   "b;");
+  EXPECT_EQ("var a", format("var\n"
+"a"));
+  EXPECT_EQ("x instanceof String", format("x\n"
+  "instanceof\n"
+  "String"));
+}
+
 TEST_F(FormatTestJS, ClosureStyleCasts) {
   verifyFormat("var x = /** @type {foo} */ (bar);");
 }
Index: lib/Format/UnwrappedLineParser.h
===
--- lib/Format/UnwrappedLineParser.h
+++ lib/Format/UnwrappedLineParser.h
@@ -81,6 +81,8 @@
   void parsePPElse();
   void parsePPEndIf();
   void parsePPUnknown();
+  bool shouldInsertSemiBetween(FormatToken *Previous, FormatToken *Next);
+  bool isJavaScriptIdentifier(FormatToken *FormatTok);
   void parseStructuralElement();
   bool tryToParseBracedList();
   bool parseBracedList(bool ContinueOnSemicolons = false);
Index: lib/Format/UnwrappedLineParser.cpp
===
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -658,6 +658,45 @@
  Tok.isNot(tok::kw_noexcept);
 }
 
+// shouldInsertSemiBetween returns true if Automatic Semicolon Insertion must
+// happen between |Previous| and |Next|. This method is conservative - it cannot
+// cover all edge cases of JavaScript, but only aims to correctly handle certain
+// well known cases. It *must not* return true in speculative cases.
+bool UnwrappedLineParser::shouldInsertSemiBetween(FormatToken *Previous,
+  FormatToken *Next) {
+  bool IsOnSameLine =
+  CommentsBeforeNextToken.empty()
+  ? Next->NewlinesBefore == 0
+  : CommentsBeforeNextToken.front()->NewlinesBefore == 0;
+  if (IsOnSameLine)
+return false;
+
+  bool PreviousMustBeValue =
+  isJavaScriptIdentifier(Previous) || Previous->Tok.isLiteral();
+  bool NextMustBeValue = isJavaScriptIdentifier(Next) || Next->Tok.isLiteral();
+  if (NextMustBeValue && PreviousMustBeValue)
+return true;
+  if ((Previous->is(tok::r_square) || Previous->is(tok::r_paren)) &&
+  NextMustBeValue)
+return true;
+  if (Previous->isOneOf(tok::plusplus, tok::minusminus) && NextMustBeValue)
+return true;
+  return false;
+}
+
+bool UnwrappedLineParser::isJavaScriptIdentifier(FormatToken *FormatTok) {
+  return FormatTok->is(tok::identifier) &&
+ (FormatTok->Tok.getIdentifierInfo() == nullptr ||
+  !FormatTok->isOneOf(Keywords.kw_in, Keywords.kw_of,
+  Keywords.kw_finally, Keywords.kw_function,
+  Keywords.kw_import, Keywords.kw_is,
+  Keywords.kw_let, Keywords.kw_var,
+  Keywords.kw_abstract, Keywords.kw_extends,
+  

Re: [PATCH] D17688: Fix missed leak from MSVC specific allocation functions

2016-03-05 Thread Alexander Riccio via cfe-commits
ariccio added a comment.

In http://reviews.llvm.org/D17688#366780, @zaks.anna wrote:

> LGTM. Thanks!
>
> I can commit this in your behalf.


Oh, and yeah, I don't have privs.


http://reviews.llvm.org/D17688



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


r262776 - clang-format: [JS] Support destructuring assignments in for loops.

2016-03-05 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Sat Mar  5 12:34:26 2016
New Revision: 262776

URL: http://llvm.org/viewvc/llvm-project?rev=262776=rev
Log:
clang-format: [JS] Support destructuring assignments in for loops.

Before:
  for (let { a, b } of x) {
  }

After:
  for (let {a, b} of x) {
  }

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

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=262776=262775=262776=diff
==
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Sat Mar  5 12:34:26 2016
@@ -363,6 +363,8 @@ void UnwrappedLineParser::calculateBrace
   //
   // We exclude + and - as they can be ObjC visibility modifiers.
   ProbablyBracedList =
+  (Style.Language == FormatStyle::LK_JavaScript &&
+   NextTok->isOneOf(Keywords.kw_of, Keywords.kw_in)) ||
   NextTok->isOneOf(tok::comma, tok::period, tok::colon,
tok::r_paren, tok::r_square, tok::l_brace,
tok::l_square, tok::l_paren, tok::ellipsis) ||

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=262776=262775=262776=diff
==
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Sat Mar  5 12:34:26 2016
@@ -606,6 +606,10 @@ TEST_F(FormatTestJS, ForLoops) {
"}");
   verifyFormat("for (var i of [2, 3]) {\n"
"}");
+  verifyFormat("for (let {a, b} of x) {\n"
+   "}");
+  verifyFormat("for (let {a, b} in x) {\n"
+   "}");
 }
 
 TEST_F(FormatTestJS, AutomaticSemicolonInsertion) {


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


[PATCH] D17908: Add Visual Studio Visualizers for more Clang types

2016-03-05 Thread Mike Spertus via cfe-commits
mspertus created this revision.
mspertus added reviewers: aaron.ballman, zturner.
mspertus added a subscriber: cfe-commits.
Herald added a subscriber: aemerson.

This is the first of a series of patches to add additional Visual Studio native 
visualizers for subclasses of clang::Type. For example, a 
SubstTemplateTypeParmType where the template type parameter "T" is replaced by 
the class "A" will show as follows in the locals window:

  Type (1), SubstTemplateTypeParm (30): {Identifier (("T"))} => Record (25), 
{Identifier (("A"))} 

Once this is accepted, I will continue to add further clang Type subclasses

http://reviews.llvm.org/D17908

Files:
  clang.natvis

Index: clang.natvis
===
--- clang.natvis
+++ clang.natvis
@@ -1,18 +1,81 @@
 
 
 http://schemas.microsoft.com/vstudio/debugger/natvis/2010;>
   
-Builtin Type={(clang::BuiltinType::Kind)BuiltinTypeBits.Kind}
-Modified Type={((clang::AttributedType*)this)->ModifiedType} Attribute={(clang::AttributedType::Kind)AttributedTypeBits.AttrKind}
-Type Class={(clang::Type::TypeClass)TypeBits.TC}
+{(clang::Type::TypeClass)TypeBits.TC}
+Builtin Type={*(clang::BuiltinType *)this}
+Modified Type={((clang::AttributedType*)this)->ModifiedType} Attribute={(clang::AttributedType::Kind)AttributedTypeBits.AttrKind}
+{*(clang::SubstTemplateTypeParmType *)this}
+{*(clang::RecordType *)this}
+{(clang::Type::TypeClass)TypeBits.TC}
+
+  (clang::Type::TypeClass)TypeBits.TC
+  TypeBits
+  CanonicalType
+  *(clang::BuiltinType *)this
+  (clang::SubstTemplateTypeParmType *)this
+  (clang::RecordType *)this
+
+  
+  
+{*decl}
+
+  decl
+
+  
+  
+{*(clang::Type *)this, view(BaseOnly)}, {*(clang::TagType *)this}
+
+  *(clang::TagType *)this
+
+  
+  
+{*(clang::Type *)this, view(BaseOnly)}: {*Replaced} = {CanonicalType}
+
+  *(clang::Type *)this, view(BaseOnly)
+  *Replaced
+
+  
+  
+{*TTPDecl}
   
   
-{((clang::ExtQualsTypeCommonBase *)(((uintptr_t)Value.Value)  ~(uintptr_t)((1  clang::TypeAlignmentInBits) - 1)))-BaseType}
+
+{*((clang::ExtQualsTypeCommonBase *)(((uintptr_t)Value.Value)  ~(uintptr_t)((1  clang::TypeAlignmentInBits) - 1)))-BaseType}
+
+  *((clang::ExtQualsTypeCommonBase *)(((uintptr_t)Value.Value)  ~(uintptr_t)((1  clang::TypeAlignmentInBits) - 1)))-BaseType
+
+  
+  
+{Argument}
+
+  Argument
+
+  
+  
+{(clang::TemplateArgument::ArgKind)TypeOrValue.Kind}, {*(clang::QualType *)TypeOrValue.V}
+
+  *(clang::QualType *)TypeOrValue.V
+  
+
+  
+  
+{(clang::BuiltinType::Kind)BuiltinTypeBits.Kind}
+
+  (clang::BuiltinType::Kind)BuiltinTypeBits.Kind
+
+  
+  
+{Name}
+  
+  
+{(clang::TemplateDecl *)((Template.Storage.Val.Val.Value  2)  2)}
+{Template.Storage}
   
   
 ({((llvm::StringMapEntryclang::IdentifierInfo **)Entry)+1,s})
@@ -65,4 +128,10 @@
   ParmVarDeclBits
 
   
+  
+{($T1 *)Ptr
+
+  ($T1 *)Ptr
+
+  
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D15729: Load compiler plugins in ASTUnit, too

2016-03-05 Thread Milian Wolff via cfe-commits
milianw accepted this revision.
milianw added a reviewer: milianw.
milianw added a comment.
This revision is now accepted and ready to land.

Still good from my side.  @klimek, @rsmith: Could you please review this as 
well?

Thanks


http://reviews.llvm.org/D15729



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


Re: [PATCH] D17682: [X86] AMD Bobcat CPU (btver1) doesn't support XSAVE

2016-03-05 Thread Simon Pilgrim via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL262772: [X86] AMD Bobcat CPU (btver1) doesn't support XSAVE  
(authored by RKSimon).

Changed prior to commit:
  http://reviews.llvm.org/D17682?vs=49552=49877#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D17682

Files:
  cfe/trunk/lib/Basic/Targets.cpp
  cfe/trunk/test/Preprocessor/predefined-arch-macros.c

Index: cfe/trunk/test/Preprocessor/predefined-arch-macros.c
===
--- cfe/trunk/test/Preprocessor/predefined-arch-macros.c
+++ cfe/trunk/test/Preprocessor/predefined-arch-macros.c
@@ -1477,7 +1477,6 @@
 // CHECK_BTVER1_M32: #define __SSE_MATH__ 1
 // CHECK_BTVER1_M32: #define __SSE__ 1
 // CHECK_BTVER1_M32: #define __SSSE3__ 1
-// CHECK_BTVER1_M32: #define __XSAVE__ 1
 // CHECK_BTVER1_M32: #define __btver1 1
 // CHECK_BTVER1_M32: #define __btver1__ 1
 // CHECK_BTVER1_M32: #define __i386 1
@@ -1499,7 +1498,6 @@
 // CHECK_BTVER1_M64: #define __SSE_MATH__ 1
 // CHECK_BTVER1_M64: #define __SSE__ 1
 // CHECK_BTVER1_M64: #define __SSSE3__ 1
-// CHECK_BTVER1_M64: #define __XSAVE__ 1
 // CHECK_BTVER1_M64: #define __amd64 1
 // CHECK_BTVER1_M64: #define __amd64__ 1
 // CHECK_BTVER1_M64: #define __btver1 1
Index: cfe/trunk/lib/Basic/Targets.cpp
===
--- cfe/trunk/lib/Basic/Targets.cpp
+++ cfe/trunk/lib/Basic/Targets.cpp
@@ -2765,7 +2765,6 @@
 setFeatureEnabledImpl(Features, "prfchw", true);
 setFeatureEnabledImpl(Features, "cx16", true);
 setFeatureEnabledImpl(Features, "fxsr", true);
-setFeatureEnabledImpl(Features, "xsave", true);
 break;
   case CK_BDVER4:
 setFeatureEnabledImpl(Features, "avx2", true);


Index: cfe/trunk/test/Preprocessor/predefined-arch-macros.c
===
--- cfe/trunk/test/Preprocessor/predefined-arch-macros.c
+++ cfe/trunk/test/Preprocessor/predefined-arch-macros.c
@@ -1477,7 +1477,6 @@
 // CHECK_BTVER1_M32: #define __SSE_MATH__ 1
 // CHECK_BTVER1_M32: #define __SSE__ 1
 // CHECK_BTVER1_M32: #define __SSSE3__ 1
-// CHECK_BTVER1_M32: #define __XSAVE__ 1
 // CHECK_BTVER1_M32: #define __btver1 1
 // CHECK_BTVER1_M32: #define __btver1__ 1
 // CHECK_BTVER1_M32: #define __i386 1
@@ -1499,7 +1498,6 @@
 // CHECK_BTVER1_M64: #define __SSE_MATH__ 1
 // CHECK_BTVER1_M64: #define __SSE__ 1
 // CHECK_BTVER1_M64: #define __SSSE3__ 1
-// CHECK_BTVER1_M64: #define __XSAVE__ 1
 // CHECK_BTVER1_M64: #define __amd64 1
 // CHECK_BTVER1_M64: #define __amd64__ 1
 // CHECK_BTVER1_M64: #define __btver1 1
Index: cfe/trunk/lib/Basic/Targets.cpp
===
--- cfe/trunk/lib/Basic/Targets.cpp
+++ cfe/trunk/lib/Basic/Targets.cpp
@@ -2765,7 +2765,6 @@
 setFeatureEnabledImpl(Features, "prfchw", true);
 setFeatureEnabledImpl(Features, "cx16", true);
 setFeatureEnabledImpl(Features, "fxsr", true);
-setFeatureEnabledImpl(Features, "xsave", true);
 break;
   case CK_BDVER4:
 setFeatureEnabledImpl(Features, "avx2", true);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r262772 - [X86] AMD Bobcat CPU (btver1) doesn't support XSAVE

2016-03-05 Thread Simon Pilgrim via cfe-commits
Author: rksimon
Date: Sat Mar  5 08:35:44 2016
New Revision: 262772

URL: http://llvm.org/viewvc/llvm-project?rev=262772=rev
Log:
[X86] AMD Bobcat CPU (btver1) doesn't support XSAVE 

btver1 is a SSSE3/SSE4a only CPU - it doesn't have AVX and doesn't support 
XSAVE.

Differential Revision: http://reviews.llvm.org/D17682

Modified:
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/test/Preprocessor/predefined-arch-macros.c

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=262772=262771=262772=diff
==
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Sat Mar  5 08:35:44 2016
@@ -2765,7 +2765,6 @@ bool X86TargetInfo::initFeatureMap(
 setFeatureEnabledImpl(Features, "prfchw", true);
 setFeatureEnabledImpl(Features, "cx16", true);
 setFeatureEnabledImpl(Features, "fxsr", true);
-setFeatureEnabledImpl(Features, "xsave", true);
 break;
   case CK_BDVER4:
 setFeatureEnabledImpl(Features, "avx2", true);

Modified: cfe/trunk/test/Preprocessor/predefined-arch-macros.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/predefined-arch-macros.c?rev=262772=262771=262772=diff
==
--- cfe/trunk/test/Preprocessor/predefined-arch-macros.c (original)
+++ cfe/trunk/test/Preprocessor/predefined-arch-macros.c Sat Mar  5 08:35:44 
2016
@@ -1477,7 +1477,6 @@
 // CHECK_BTVER1_M32: #define __SSE_MATH__ 1
 // CHECK_BTVER1_M32: #define __SSE__ 1
 // CHECK_BTVER1_M32: #define __SSSE3__ 1
-// CHECK_BTVER1_M32: #define __XSAVE__ 1
 // CHECK_BTVER1_M32: #define __btver1 1
 // CHECK_BTVER1_M32: #define __btver1__ 1
 // CHECK_BTVER1_M32: #define __i386 1
@@ -1499,7 +1498,6 @@
 // CHECK_BTVER1_M64: #define __SSE_MATH__ 1
 // CHECK_BTVER1_M64: #define __SSE__ 1
 // CHECK_BTVER1_M64: #define __SSSE3__ 1
-// CHECK_BTVER1_M64: #define __XSAVE__ 1
 // CHECK_BTVER1_M64: #define __amd64 1
 // CHECK_BTVER1_M64: #define __amd64__ 1
 // CHECK_BTVER1_M64: #define __btver1 1


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


[libcxx] r262771 - libc++: fix typo

2016-03-05 Thread JF Bastien via cfe-commits
Author: jfb
Date: Sat Mar  5 08:22:02 2016
New Revision: 262771

URL: http://llvm.org/viewvc/llvm-project?rev=262771=rev
Log:
libc++: fix typo

Modified:
libcxx/trunk/CMakeLists.txt

Modified: libcxx/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/CMakeLists.txt?rev=262771=262770=262771=diff
==
--- libcxx/trunk/CMakeLists.txt (original)
+++ libcxx/trunk/CMakeLists.txt Sat Mar  5 08:22:02 2016
@@ -251,7 +251,7 @@ string(TOUPPER "${CMAKE_BUILD_TYPE}" upp
 # Setup Compiler Flags
 
#===
 
-include(HandleLibCXXABI) # Steup the ABI library flags
+include(HandleLibCXXABI) # Setup the ABI library flags
 
 # Include macros for adding and removing libc++ flags.
 include(HandleLibcxxFlags)


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


Re: [PATCH] D16139: [MIPS] initFeatureMap() to handle empty string argument

2016-03-05 Thread Daniel Sanders via cfe-commits
dsanders added a comment.

In http://reviews.llvm.org/D16139#368217, @echristo wrote:

> This seems wrong. You should fix setCPU instead or set a default CPU.


We already set a default CPU in the constructor (e.g. 
Mips32TargetInfoBase::Mips32TargetInfoBase() provides "mips32r2"). It's the CPU 
argument to initFeatureMap() that's the root problem. In several targets, this 
argument has the same name as a member variable and is not subject to anything 
the constructor or setCPU() does to that member variable.

I suspect the right thing to do is to drop the CPU argument and use the member 
variable instead but there may be differences in value/usage that make this 
difficult. For now, this patch serves as a stop-gap measure that resolves the 
empty string to a real CPU name.


Repository:
  rL LLVM

http://reviews.llvm.org/D16139



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