[clang-tools-extra] r249970 - [clang-tidy] Python script for easy check rename

2015-10-11 Thread Piotr Zegar via cfe-commits
Author: clockman
Date: Sun Oct 11 02:58:34 2015
New Revision: 249970

URL: http://llvm.org/viewvc/llvm-project?rev=249970&view=rev
Log:
[clang-tidy] Python script for easy check rename

Summary:
Script can rename check that is in same module - I found it useful.

Diff generated in root directory of clang-tools-extra project.

Reviewers: sbenza, aaron.ballman, alexfh

Subscribers: mgehre, xazax.hun, cfe-commits

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

Added:
clang-tools-extra/trunk/clang-tidy/rename_check.py   (with props)

Added: clang-tools-extra/trunk/clang-tidy/rename_check.py
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/rename_check.py?rev=249970&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/rename_check.py (added)
+++ clang-tools-extra/trunk/clang-tidy/rename_check.py Sun Oct 11 02:58:34 2015
@@ -0,0 +1,93 @@
+#!/usr/bin/env python
+#
+#===- rename_check.py - clang-tidy check renamer -*- python 
-*--===#
+#
+# The LLVM Compiler Infrastructure
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+#======#
+
+import os
+import re
+import sys
+import glob
+
+def replaceInFile(fileName, sFrom, sTo):
+  if sFrom == sTo:
+return
+  txt = None
+  with open(fileName, "r") as f:
+txt = f.read()
+
+  if sFrom not in txt:
+return
+
+  txt = txt.replace(sFrom, sTo)
+  print("Replace '%s' -> '%s' in '%s'" % (sFrom, sTo, fileName))
+  with open(fileName, "w") as f:
+f.write(txt)
+
+def generateCommentLineHeader(filename):
+  return ''.join(['//===--- ',
+  os.path.basename(filename),
+  ' - clang-tidy ',
+  '-' * max(0, 42 - len(os.path.basename(filename))),
+  '*- C++ -*-===//'])
+
+def generateCommentLineSource(filename):
+  return ''.join(['//===--- ',
+  os.path.basename(filename),
+  ' - clang-tidy',
+  '-' * max(0, 52 - len(os.path.basename(filename))),
+  '-===//'])
+
+def fileRename(fileName, sFrom, sTo):
+  if sFrom not in fileName:
+return fileName
+  newFileName = fileName.replace(sFrom, sTo)
+  print("Rename '%s' -> '%s'" % (fileName, newFileName))
+  os.rename(fileName, newFileName)
+  return newFileName
+
+def getListOfFiles(clang_tidy_path):
+  files =  glob.glob(os.path.join(clang_tidy_path,'*'))
+  for dirname in files:
+if os.path.isdir(dirname):
+  files += glob.glob(os.path.join(dirname,'*'))
+  files += glob.glob(os.path.join(clang_tidy_path,'..', 'test', 'clang-tidy', 
'*'))
+  files += glob.glob(os.path.join(clang_tidy_path,'..', 'docs', 'clang-tidy', 
'checks', '*'))
+  return [filename for filename in files if os.path.isfile(filename)]
+
+def main():
+  if len(sys.argv) != 4:
+print('Usage: rename_check.py   
\n')
+print('   example: rename_check.py misc awesome-functions 
new-awesome-function')
+return
+
+  module = sys.argv[1].lower()
+  check_name = sys.argv[2]
+  check_name_camel = ''.join(map(lambda elem: elem.capitalize(),
+ check_name.split('-'))) + 'Check'
+  check_name_new = sys.argv[3]
+  check_name_new_camel = ''.join(map(lambda elem: elem.capitalize(),
+ check_name_new.split('-'))) + 'Check'
+
+  clang_tidy_path = os.path.dirname(sys.argv[0])
+
+  header_guard_old = module.upper() + '_' + check_name.upper().replace('-', 
'_')
+  header_guard_new = module.upper() + '_' + 
check_name_new.upper().replace('-', '_')
+
+  for filename in getListOfFiles(clang_tidy_path):
+originalName = filename
+filename = fileRename(filename, check_name, check_name_new)
+filename = fileRename(filename, check_name_camel, check_name_new_camel)
+replaceInFile(filename, generateCommentLineHeader(originalName), 
generateCommentLineHeader(filename))
+replaceInFile(filename, generateCommentLineSource(originalName), 
generateCommentLineSource(filename))
+replaceInFile(filename, header_guard_old, header_guard_new)
+replaceInFile(filename, check_name, check_name_new)
+replaceInFile(filename, check_name_camel, check_name_new_camel)
+
+if __name__ == '__main__':
+  main()

Propchange: clang-tools-extra/trunk/clang-tidy/rename_check.py
--
svn:executable = *


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


r249982 - Keep the IfStmt node even if the condition is invalid

2015-10-11 Thread Olivier Goffart via cfe-commits
Author: ogoffart
Date: Sun Oct 11 12:27:29 2015
New Revision: 249982

URL: http://llvm.org/viewvc/llvm-project?rev=249982&view=rev
Log:
Keep the IfStmt node even if the condition is invalid

This is important to keep the information in IDE or other tools
even if the code contains a few errors

Modified:
cfe/trunk/lib/Sema/SemaStmt.cpp
cfe/trunk/test/Misc/ast-dump-invalid.cpp

Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=249982&r1=249981&r2=249982&view=diff
==
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Sun Oct 11 12:27:29 2015
@@ -483,13 +483,6 @@ StmtResult
 Sema::ActOnIfStmt(SourceLocation IfLoc, FullExprArg CondVal, Decl *CondVar,
   Stmt *thenStmt, SourceLocation ElseLoc,
   Stmt *elseStmt) {
-  // If the condition was invalid, discard the if statement.  We could recover
-  // better by replacing it with a valid expr, but don't do that yet.
-  if (!CondVal.get() && !CondVar) {
-getCurFunction()->setHasDroppedStmt();
-return StmtError();
-  }
-
   ExprResult CondResult(CondVal.release());
 
   VarDecl *ConditionVar = nullptr;
@@ -497,22 +490,23 @@ Sema::ActOnIfStmt(SourceLocation IfLoc,
 ConditionVar = cast(CondVar);
 CondResult = CheckConditionVariable(ConditionVar, IfLoc, true);
 CondResult = ActOnFinishFullExpr(CondResult.get(), IfLoc);
-if (CondResult.isInvalid())
-  return StmtError();
   }
   Expr *ConditionExpr = CondResult.getAs();
-  if (!ConditionExpr)
-return StmtError();
+  if (ConditionExpr) {
+DiagnoseUnusedExprResult(thenStmt);
 
-  DiagnoseUnusedExprResult(thenStmt);
-
-  if (!elseStmt) {
-DiagnoseEmptyStmtBody(ConditionExpr->getLocEnd(), thenStmt,
-  diag::warn_empty_if_body);
+if (!elseStmt) {
+  DiagnoseEmptyStmtBody(ConditionExpr->getLocEnd(), thenStmt,
+diag::warn_empty_if_body);
+}
+
+DiagnoseUnusedExprResult(elseStmt);
+  } else {
+// Create a dummy Expr for the condition for error recovery
+ConditionExpr = new (Context) OpaqueValueExpr(SourceLocation(),
+  Context.BoolTy, VK_RValue);
   }
 
-  DiagnoseUnusedExprResult(elseStmt);
-
   return new (Context) IfStmt(Context, IfLoc, ConditionVar, ConditionExpr,
   thenStmt, ElseLoc, elseStmt);
 }

Modified: cfe/trunk/test/Misc/ast-dump-invalid.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/ast-dump-invalid.cpp?rev=249982&r1=249981&r2=249982&view=diff
==
--- cfe/trunk/test/Misc/ast-dump-invalid.cpp (original)
+++ cfe/trunk/test/Misc/ast-dump-invalid.cpp Sun Oct 11 12:27:29 2015
@@ -18,3 +18,26 @@ void f(T i, T j) {
 // CHECK-NEXT: `-CXXUnresolvedConstructExpr {{.*}}  'T'
 // CHECK-NEXT:   |-DeclRefExpr {{.*}}  'T' lvalue ParmVar 
{{.*}} 'i' 'T'
 // CHECK-NEXT:   `-DeclRefExpr {{.*}}  'T' lvalue ParmVar 
{{.*}} 'j' 'T'
+
+
+namespace TestInvalidIf {
+int g(int i) {
+  if (invalid_condition)
+return 4;
+  else
+return i;
+}
+}
+// CHECK: NamespaceDecl {{.*}} <{{.*}}> {{.*}} TestInvalidIf
+// CHECK-NEXT: `-FunctionDecl
+// CHECK-NEXT:   |-ParmVarDecl
+// CHECK-NEXT:   `-CompoundStmt
+// CHECK-NEXT: `-IfStmt {{.*}} 
+// CHECK-NEXT:   |-<<>>
+// CHECK-NEXT:   |-OpaqueValueExpr {{.*}} <> '_Bool'
+// CHECK-NEXT:   |-ReturnStmt {{.*}} 
+// CHECK-NEXT:   | `-IntegerLiteral {{.*}}  'int' 4
+// CHECK-NEXT:   `-ReturnStmt {{.*}} 
+// CHECK-NEXT: `-ImplicitCastExpr {{.*}}  'int' 

+// CHECK-NEXT:   `-DeclRefExpr {{.*}}  'int' lvalue ParmVar 
{{.*}} 'i' 'int'
+


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


Re: [PATCH] D13344: Keep the IfStmt node even if the condition is invalid

2015-10-11 Thread Olivier Goffart via cfe-commits
ogoffart abandoned this revision.
ogoffart marked an inline comment as done.
ogoffart added a comment.

commited as r249982. (I forgot to add the link to reviews.llvm.org in the 
commit message. I'll do it next time)


http://reviews.llvm.org/D13344



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


Re: [PATCH] D13604: Fix to allow C conversions on arguments passed to functions with __attribute__((overloadable)) in C

2015-10-11 Thread George Burgess IV via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL249995: [Sema] Allow C conversions in C overload logic 
(authored by gbiv).

Changed prior to commit:
  http://reviews.llvm.org/D13604?vs=36986&id=37062#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D13604

Files:
  cfe/trunk/include/clang/Sema/Overload.h
  cfe/trunk/include/clang/Sema/Sema.h
  cfe/trunk/lib/Sema/SemaExpr.cpp
  cfe/trunk/lib/Sema/SemaOverload.cpp
  cfe/trunk/test/Sema/overloadable.c

Index: cfe/trunk/include/clang/Sema/Overload.h
===
--- cfe/trunk/include/clang/Sema/Overload.h
+++ cfe/trunk/include/clang/Sema/Overload.h
@@ -83,7 +83,8 @@
 ICK_TransparentUnionConversion, ///< Transparent Union Conversions
 ICK_Writeback_Conversion,  ///< Objective-C ARC writeback conversion
 ICK_Zero_Event_Conversion, ///< Zero constant to event (OpenCL1.2 6.12.10)
-ICK_Num_Conversion_Kinds   ///< The number of conversion kinds
+ICK_C_Only_Conversion, ///< Conversions allowed in C, but not C++
+ICK_Num_Conversion_Kinds,  ///< The number of conversion kinds
   };
 
   /// ImplicitConversionRank - The rank of an implicit conversion
@@ -95,7 +96,9 @@
 ICR_Promotion,   ///< Promotion
 ICR_Conversion,  ///< Conversion
 ICR_Complex_Real_Conversion, ///< Complex <-> Real conversion
-ICR_Writeback_Conversion ///< ObjC ARC writeback conversion
+ICR_Writeback_Conversion,///< ObjC ARC writeback conversion
+ICR_C_Conversion ///< Conversion only allowed in the C standard.
+ ///  (e.g. void* to char*)
   };
 
   ImplicitConversionRank GetConversionRank(ImplicitConversionKind Kind);
Index: cfe/trunk/include/clang/Sema/Sema.h
===
--- cfe/trunk/include/clang/Sema/Sema.h
+++ cfe/trunk/include/clang/Sema/Sema.h
@@ -8292,19 +8292,23 @@
QualType LHSType,
QualType RHSType);
 
-  /// Check assignment constraints and prepare for a conversion of the
-  /// RHS to the LHS type.
+  /// Check assignment constraints and optionally prepare for a conversion of
+  /// the RHS to the LHS type. The conversion is prepared for if ConvertRHS
+  /// is true.
   AssignConvertType CheckAssignmentConstraints(QualType LHSType,
ExprResult &RHS,
-   CastKind &Kind);
+   CastKind &Kind,
+   bool ConvertRHS = true);
 
   // CheckSingleAssignmentConstraints - Currently used by
   // CheckAssignmentOperands, and ActOnReturnStmt. Prior to type checking,
-  // this routine performs the default function/array converions.
+  // this routine performs the default function/array converions, if ConvertRHS
+  // is true.
   AssignConvertType CheckSingleAssignmentConstraints(QualType LHSType,
  ExprResult &RHS,
  bool Diagnose = true,
- bool DiagnoseCFAudited = false);
+ bool DiagnoseCFAudited = false,
+ bool ConvertRHS = true);
 
   // \brief If the lhs type is a transparent union, check whether we
   // can initialize the transparent union with the given expression.
Index: cfe/trunk/test/Sema/overloadable.c
===
--- cfe/trunk/test/Sema/overloadable.c
+++ cfe/trunk/test/Sema/overloadable.c
@@ -85,3 +85,17 @@
 void after_local_1(int) __attribute__((overloadable)); // expected-error {{conflicting types}}
 void after_local_2(int); // expected-error {{must have the 'overloadable' attribute}}
 void after_local_3(int) __attribute__((overloadable));
+
+// Make sure we allow C-specific conversions in C.
+void conversions() {
+  void foo(char *c) __attribute__((overloadable));
+  void foo(char *c) __attribute__((overloadable, enable_if(c, "nope.jpg")));
+
+  void *ptr;
+  foo(ptr);
+
+  void multi_type(unsigned char *c) __attribute__((overloadable));
+  void multi_type(signed char *c) __attribute__((overloadable));
+  unsigned char *c;
+  multi_type(c);
+}
Index: cfe/trunk/lib/Sema/SemaExpr.cpp
===
--- cfe/trunk/lib/Sema/SemaExpr.cpp
+++ cfe/trunk/lib/Sema/SemaExpr.cpp
@@ -5376,13 +5376,13 @@
   return CK_IntegralToFloating;
 case Type::STK_IntegralComplex:
   Src = ImpCastExprToType(Src.get(),
-  DestTy->castAs()->getElementType(),
-  CK_IntegralCast);
+  DestTy->castAs()->getElementTyp

r249995 - [Sema] Allow C conversions in C overload logic

2015-10-11 Thread George Burgess IV via cfe-commits
Author: gbiv
Date: Sun Oct 11 15:13:20 2015
New Revision: 249995

URL: http://llvm.org/viewvc/llvm-project?rev=249995&view=rev
Log:
[Sema] Allow C conversions in C overload logic

C allows for some implicit conversions that C++ does not, e.g. void* ->
char*. This patch teaches clang that these conversions are okay when
dealing with overloads in C.

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

Modified:
cfe/trunk/include/clang/Sema/Overload.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/test/Sema/overloadable.c

Modified: cfe/trunk/include/clang/Sema/Overload.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Overload.h?rev=249995&r1=249994&r2=249995&view=diff
==
--- cfe/trunk/include/clang/Sema/Overload.h (original)
+++ cfe/trunk/include/clang/Sema/Overload.h Sun Oct 11 15:13:20 2015
@@ -83,7 +83,8 @@ namespace clang {
 ICK_TransparentUnionConversion, ///< Transparent Union Conversions
 ICK_Writeback_Conversion,  ///< Objective-C ARC writeback conversion
 ICK_Zero_Event_Conversion, ///< Zero constant to event (OpenCL1.2 6.12.10)
-ICK_Num_Conversion_Kinds   ///< The number of conversion kinds
+ICK_C_Only_Conversion, ///< Conversions allowed in C, but not C++
+ICK_Num_Conversion_Kinds,  ///< The number of conversion kinds
   };
 
   /// ImplicitConversionRank - The rank of an implicit conversion
@@ -95,7 +96,9 @@ namespace clang {
 ICR_Promotion,   ///< Promotion
 ICR_Conversion,  ///< Conversion
 ICR_Complex_Real_Conversion, ///< Complex <-> Real conversion
-ICR_Writeback_Conversion ///< ObjC ARC writeback conversion
+ICR_Writeback_Conversion,///< ObjC ARC writeback conversion
+ICR_C_Conversion ///< Conversion only allowed in the C 
standard.
+ ///  (e.g. void* to char*)
   };
 
   ImplicitConversionRank GetConversionRank(ImplicitConversionKind Kind);

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=249995&r1=249994&r2=249995&view=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Sun Oct 11 15:13:20 2015
@@ -8292,19 +8292,23 @@ public:
QualType LHSType,
QualType RHSType);
 
-  /// Check assignment constraints and prepare for a conversion of the
-  /// RHS to the LHS type.
+  /// Check assignment constraints and optionally prepare for a conversion of
+  /// the RHS to the LHS type. The conversion is prepared for if ConvertRHS
+  /// is true.
   AssignConvertType CheckAssignmentConstraints(QualType LHSType,
ExprResult &RHS,
-   CastKind &Kind);
+   CastKind &Kind,
+   bool ConvertRHS = true);
 
   // CheckSingleAssignmentConstraints - Currently used by
   // CheckAssignmentOperands, and ActOnReturnStmt. Prior to type checking,
-  // this routine performs the default function/array converions.
+  // this routine performs the default function/array converions, if ConvertRHS
+  // is true.
   AssignConvertType CheckSingleAssignmentConstraints(QualType LHSType,
  ExprResult &RHS,
  bool Diagnose = true,
- bool DiagnoseCFAudited = 
false);
+ bool DiagnoseCFAudited = 
false,
+ bool ConvertRHS = true);
 
   // \brief If the lhs type is a transparent union, check whether we
   // can initialize the transparent union with the given expression.

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=249995&r1=249994&r2=249995&view=diff
==
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Sun Oct 11 15:13:20 2015
@@ -5376,13 +5376,13 @@ CastKind Sema::PrepareScalarCast(ExprRes
   return CK_IntegralToFloating;
 case Type::STK_IntegralComplex:
   Src = ImpCastExprToType(Src.get(),
-  DestTy->castAs()->getElementType(),
-  CK_IntegralCast);
+  DestTy->castAs()->getElementType(),
+  CK_IntegralCast);
   return CK_IntegralRealToComplex;
 case Type::STK_FloatingComplex:
   Src = ImpCastExprTo

r249997 - Fix warning caused by r249995

2015-10-11 Thread George Burgess IV via cfe-commits
Author: gbiv
Date: Sun Oct 11 15:37:14 2015
New Revision: 249997

URL: http://llvm.org/viewvc/llvm-project?rev=249997&view=rev
Log:
Fix warning caused by r249995


Modified:
cfe/trunk/lib/Sema/SemaExprCXX.cpp

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=249997&r1=249996&r2=249997&view=diff
==
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Sun Oct 11 15:37:14 2015
@@ -3445,6 +3445,7 @@ Sema::PerformImplicitConversion(Expr *Fr
   case ICK_Function_To_Pointer:
   case ICK_Qualification:
   case ICK_Num_Conversion_Kinds:
+  case ICK_C_Only_Conversion:
 llvm_unreachable("Improper second standard conversion");
   }
 


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


[PATCH] D13639: Add decayedType and hasDecayedType AST matchers

2015-10-11 Thread Matthias Gehre via cfe-commits
mgehre created this revision.
mgehre added a reviewer: klimek.
mgehre added a subscriber: cfe-commits.
Herald added a subscriber: klimek.

Add decayedType and hasDecayedType AST matchers

http://reviews.llvm.org/D13639

Files:
  include/clang/ASTMatchers/ASTMatchers.h
  lib/ASTMatchers/Dynamic/Registry.cpp

Index: lib/ASTMatchers/Dynamic/Registry.cpp
===
--- lib/ASTMatchers/Dynamic/Registry.cpp
+++ lib/ASTMatchers/Dynamic/Registry.cpp
@@ -152,6 +152,7 @@
   REGISTER_MATCHER(cxxThrowExpr);
   REGISTER_MATCHER(cxxTryStmt);
   REGISTER_MATCHER(cxxUnresolvedConstructExpr);
+  REGISTER_MATCHER(decayedType);
   REGISTER_MATCHER(decl);
   REGISTER_MATCHER(declaratorDecl);
   REGISTER_MATCHER(declCountIs);
@@ -199,6 +200,7 @@
   REGISTER_MATCHER(hasCaseConstant);
   REGISTER_MATCHER(hasCondition);
   REGISTER_MATCHER(hasConditionVariableStatement);
+  REGISTER_MATCHER(hasDecayedType);
   REGISTER_MATCHER(hasDeclaration);
   REGISTER_MATCHER(hasDeclContext);
   REGISTER_MATCHER(hasDeducedType);
Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -4123,6 +4123,24 @@
 /// \endcode
 AST_TYPE_MATCHER(InjectedClassNameType, injectedClassNameType);
 
+/// \brief Matches decayed type
+/// Example matches i[] in declaration of f.
+/// (matcher = 
valueDecl(hasType(decayedType(hasDecayedType(pointerType())
+/// Example matches i[1].
+/// (matcher = expr(hasType(decayedType(hasDecayedType(pointerType())
+/// \code
+///   void f(int i[]) {
+/// i[1] = 0;
+///   }
+/// \endcode
+AST_TYPE_MATCHER(DecayedType, decayedType);
+
+/// \brief Matches the decayed type, whos decayed type matches \c InnerMatcher
+AST_MATCHER_P(DecayedType, hasDecayedType, internal::Matcher,
+  InnerType) {
+  return InnerType.matches(Node.getDecayedType(), Finder, Builder);
+}
+
 /// \brief Matches declarations whose declaration context, interpreted as a
 /// Decl, matches \c InnerMatcher.
 ///


Index: lib/ASTMatchers/Dynamic/Registry.cpp
===
--- lib/ASTMatchers/Dynamic/Registry.cpp
+++ lib/ASTMatchers/Dynamic/Registry.cpp
@@ -152,6 +152,7 @@
   REGISTER_MATCHER(cxxThrowExpr);
   REGISTER_MATCHER(cxxTryStmt);
   REGISTER_MATCHER(cxxUnresolvedConstructExpr);
+  REGISTER_MATCHER(decayedType);
   REGISTER_MATCHER(decl);
   REGISTER_MATCHER(declaratorDecl);
   REGISTER_MATCHER(declCountIs);
@@ -199,6 +200,7 @@
   REGISTER_MATCHER(hasCaseConstant);
   REGISTER_MATCHER(hasCondition);
   REGISTER_MATCHER(hasConditionVariableStatement);
+  REGISTER_MATCHER(hasDecayedType);
   REGISTER_MATCHER(hasDeclaration);
   REGISTER_MATCHER(hasDeclContext);
   REGISTER_MATCHER(hasDeducedType);
Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -4123,6 +4123,24 @@
 /// \endcode
 AST_TYPE_MATCHER(InjectedClassNameType, injectedClassNameType);
 
+/// \brief Matches decayed type
+/// Example matches i[] in declaration of f.
+/// (matcher = valueDecl(hasType(decayedType(hasDecayedType(pointerType())
+/// Example matches i[1].
+/// (matcher = expr(hasType(decayedType(hasDecayedType(pointerType())
+/// \code
+///   void f(int i[]) {
+/// i[1] = 0;
+///   }
+/// \endcode
+AST_TYPE_MATCHER(DecayedType, decayedType);
+
+/// \brief Matches the decayed type, whos decayed type matches \c InnerMatcher
+AST_MATCHER_P(DecayedType, hasDecayedType, internal::Matcher,
+  InnerType) {
+  return InnerType.matches(Node.getDecayedType(), Finder, Builder);
+}
+
 /// \brief Matches declarations whose declaration context, interpreted as a
 /// Decl, matches \c InnerMatcher.
 ///
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D13639: Add decayedType and hasDecayedType AST matchers

2015-10-11 Thread Matthias Gehre via cfe-commits
mgehre updated this revision to Diff 37066.
mgehre added a comment.

Add test


http://reviews.llvm.org/D13639

Files:
  include/clang/ASTMatchers/ASTMatchers.h
  lib/ASTMatchers/Dynamic/Registry.cpp
  unittests/ASTMatchers/ASTMatchersTest.cpp

Index: unittests/ASTMatchers/ASTMatchersTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersTest.cpp
+++ unittests/ASTMatchers/ASTMatchersTest.cpp
@@ -4109,6 +4109,11 @@
   EXPECT_TRUE(matches("const int a = 0;", qualType(isInteger(;
 }
 
+TEST(TypeMatching, DecayedType) {
+  EXPECT_TRUE(matches("void f(int i[]);", 
valueDecl(hasType(decayedType(hasDecayedType(pointerType()));
+  EXPECT_TRUE(notMatches("int i[7];", decayedType()));
+}
+
 TEST(TypeMatching, MatchesComplexTypes) {
   EXPECT_TRUE(matches("_Complex float f;", complexType()));
   EXPECT_TRUE(matches(
Index: lib/ASTMatchers/Dynamic/Registry.cpp
===
--- lib/ASTMatchers/Dynamic/Registry.cpp
+++ lib/ASTMatchers/Dynamic/Registry.cpp
@@ -152,6 +152,7 @@
   REGISTER_MATCHER(cxxThrowExpr);
   REGISTER_MATCHER(cxxTryStmt);
   REGISTER_MATCHER(cxxUnresolvedConstructExpr);
+  REGISTER_MATCHER(decayedType);
   REGISTER_MATCHER(decl);
   REGISTER_MATCHER(declaratorDecl);
   REGISTER_MATCHER(declCountIs);
@@ -199,6 +200,7 @@
   REGISTER_MATCHER(hasCaseConstant);
   REGISTER_MATCHER(hasCondition);
   REGISTER_MATCHER(hasConditionVariableStatement);
+  REGISTER_MATCHER(hasDecayedType);
   REGISTER_MATCHER(hasDeclaration);
   REGISTER_MATCHER(hasDeclContext);
   REGISTER_MATCHER(hasDeducedType);
Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -4123,6 +4123,24 @@
 /// \endcode
 AST_TYPE_MATCHER(InjectedClassNameType, injectedClassNameType);
 
+/// \brief Matches decayed type
+/// Example matches i[] in declaration of f.
+/// (matcher = 
valueDecl(hasType(decayedType(hasDecayedType(pointerType())
+/// Example matches i[1].
+/// (matcher = expr(hasType(decayedType(hasDecayedType(pointerType())
+/// \code
+///   void f(int i[]) {
+/// i[1] = 0;
+///   }
+/// \endcode
+AST_TYPE_MATCHER(DecayedType, decayedType);
+
+/// \brief Matches the decayed type, whos decayed type matches \c InnerMatcher
+AST_MATCHER_P(DecayedType, hasDecayedType, internal::Matcher,
+  InnerType) {
+  return InnerType.matches(Node.getDecayedType(), Finder, Builder);
+}
+
 /// \brief Matches declarations whose declaration context, interpreted as a
 /// Decl, matches \c InnerMatcher.
 ///


Index: unittests/ASTMatchers/ASTMatchersTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersTest.cpp
+++ unittests/ASTMatchers/ASTMatchersTest.cpp
@@ -4109,6 +4109,11 @@
   EXPECT_TRUE(matches("const int a = 0;", qualType(isInteger(;
 }
 
+TEST(TypeMatching, DecayedType) {
+  EXPECT_TRUE(matches("void f(int i[]);", valueDecl(hasType(decayedType(hasDecayedType(pointerType()));
+  EXPECT_TRUE(notMatches("int i[7];", decayedType()));
+}
+
 TEST(TypeMatching, MatchesComplexTypes) {
   EXPECT_TRUE(matches("_Complex float f;", complexType()));
   EXPECT_TRUE(matches(
Index: lib/ASTMatchers/Dynamic/Registry.cpp
===
--- lib/ASTMatchers/Dynamic/Registry.cpp
+++ lib/ASTMatchers/Dynamic/Registry.cpp
@@ -152,6 +152,7 @@
   REGISTER_MATCHER(cxxThrowExpr);
   REGISTER_MATCHER(cxxTryStmt);
   REGISTER_MATCHER(cxxUnresolvedConstructExpr);
+  REGISTER_MATCHER(decayedType);
   REGISTER_MATCHER(decl);
   REGISTER_MATCHER(declaratorDecl);
   REGISTER_MATCHER(declCountIs);
@@ -199,6 +200,7 @@
   REGISTER_MATCHER(hasCaseConstant);
   REGISTER_MATCHER(hasCondition);
   REGISTER_MATCHER(hasConditionVariableStatement);
+  REGISTER_MATCHER(hasDecayedType);
   REGISTER_MATCHER(hasDeclaration);
   REGISTER_MATCHER(hasDeclContext);
   REGISTER_MATCHER(hasDeducedType);
Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -4123,6 +4123,24 @@
 /// \endcode
 AST_TYPE_MATCHER(InjectedClassNameType, injectedClassNameType);
 
+/// \brief Matches decayed type
+/// Example matches i[] in declaration of f.
+/// (matcher = valueDecl(hasType(decayedType(hasDecayedType(pointerType())
+/// Example matches i[1].
+/// (matcher = expr(hasType(decayedType(hasDecayedType(pointerType())
+/// \code
+///   void f(int i[]) {
+/// i[1] = 0;
+///   }
+/// \endcode
+AST_TYPE_MATCHER(DecayedType, decayedType);
+
+/// \brief Matches the decayed type, whos decayed type matches \c InnerMatcher
+AST_MATCHER_P(DecayedType, hasDecayedType, internal::Matcher,
+  InnerType) {
+  return InnerType.matche

[clang-tools-extra] r250002 - Test commit

2015-10-11 Thread Matthias Gehre via cfe-commits
Author: mgehre
Date: Sun Oct 11 17:55:29 2015
New Revision: 250002

URL: http://llvm.org/viewvc/llvm-project?rev=250002&view=rev
Log:
Test commit

Modified:

clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp?rev=250002&r1=250001&r2=250002&view=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
 (original)
+++ 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
 Sun Oct 11 17:55:29 2015
@@ -17,6 +17,7 @@ namespace clang {
 namespace tidy {
 namespace cppcoreguidelines {
 
+/// A module containing checks of the C++ Core Guidelines
 class CppCoreGuidelinesModule : public ClangTidyModule {
 public:
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {


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


[PATCH] D13640: [clang-tidy] Add new check cppcoreguidelines-pro-bounds-array-to-pointer-decay

2015-10-11 Thread Matthias Gehre via cfe-commits
mgehre created this revision.
mgehre added reviewers: alexfh, sbenza, bkramer, aaron.ballman.
mgehre added a subscriber: cfe-commits.

This check flags all array to pointer decays.

Pointers should not be used as arrays. array_view is a bounds-checked,
safe alternative to using pointers to access arrays.

This rule is part of the "Bounds safety" profile of the C++ Core
Guidelines, see
https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#-bounds3-no-array-to-pointer-decay

http://reviews.llvm.org/D13640

Files:
  clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
  clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.h
  docs/clang-tidy/checks/cppcoreguidelines-pro-bounds-array-to-pointer-decay.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/cppcoreguidelines-pro-bounds-array-to-pointer-decay.cpp

Index: test/clang-tidy/cppcoreguidelines-pro-bounds-array-to-pointer-decay.cpp
===
--- /dev/null
+++ test/clang-tidy/cppcoreguidelines-pro-bounds-array-to-pointer-decay.cpp
@@ -0,0 +1,26 @@
+// RUN: %python %S/check_clang_tidy.py %s cppcoreguidelines-pro-bounds-array-to-pointer-decay %t
+
+void pointerfun(int* p);
+void arrayfun(int p[]);
+
+void f()
+{
+  int a[5];
+  pointerfun(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: do not (implicitly) convert an array to a pointer [cppcoreguidelines-pro-bounds-array-to-pointer-decay]
+  pointerfun((int*)a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: do not (implicitly) convert an array to a pointer
+  arrayfun(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: do not (implicitly) convert an array to a pointer
+
+  int i = a[0]; // OK
+  pointerfun(&a[0]); // OK
+
+  for(auto e : a ) // OK, iteration internally decays array to pointer
+;
+}
+
+const char* g()
+{
+return "clang"; // OK, decay string literal to pointer
+}
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -4,6 +4,7 @@
 .. toctree::
cert-setlongjmp
cert-variadic-function-def
+   cppcoreguidelines-pro-bounds-array-to-pointer-decay
cppcoreguidelines-pro-type-const-cast
cppcoreguidelines-pro-type-reinterpret-cast
google-build-explicit-make-pair
Index: docs/clang-tidy/checks/cppcoreguidelines-pro-bounds-array-to-pointer-decay.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/cppcoreguidelines-pro-bounds-array-to-pointer-decay.rst
@@ -0,0 +1,9 @@
+cppcoreguidelines-pro-bounds-array-to-pointer-decay
+===
+
+This check flags all array to pointer decays.
+
+Pointers should not be used as arrays. array_view is a bounds-checked, safe alternative to using pointers to access arrays.
+
+This rule is part of the "Bounds safety" profile of the C++ Core Guidelines, see
+https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#-bounds3-no-array-to-pointer-decay
Index: clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.h
===
--- /dev/null
+++ clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.h
@@ -0,0 +1,34 @@
+//===--- ProBoundsArrayToPointerDecayCheck.h - clang-tidy*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PRO_BOUNDS_ARRAY_TO_POINTER_DECAY_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PRO_BOUNDS_ARRAY_TO_POINTER_DECAY_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+
+/// This check flags all array to pointer decays
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines-pro-bounds-array-to-pointer-decay.html
+class ProBoundsArrayToPointerDecayCheck : public ClangTidyCheck {
+public:
+  ProBoundsArrayToPointerDecayCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PRO_BOUNDS_ARRAY_TO_POINTER_DECAY_H
+
Index: clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
===
--- /dev/null
+++ clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDec

[PATCH] D13641: clang-format: [JS] handle character classes in regexes.

2015-10-11 Thread Martin Probst via cfe-commits
mprobst created this revision.
mprobst added a reviewer: djasper.
mprobst added subscribers: cfe-commits, klimek.

Slashes in regular expressions do not need to be escaped and do not terminate
the regular expression even without a preceding backslash.

http://reviews.llvm.org/D13641

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

Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -617,9 +617,15 @@
   verifyFormat("var regex = /x|y/;");
   verifyFormat("var regex = /a{2}/;");
   verifyFormat("var regex = /a{1,3}/;");
+
   verifyFormat("var regex = /[abc]/;");
   verifyFormat("var regex = /[^abc]/;");
   verifyFormat("var regex = /[\\b]/;");
+  verifyFormat("var regex = /[/]/;");
+  verifyFormat("var regex = /[\\/]/;");
+  verifyFormat("var regex = /\\[/;");
+  verifyFormat("var regex = /[/]/;");
+
   verifyFormat("var regex = /\\b/;");
   verifyFormat("var regex = /\\B/;");
   verifyFormat("var regex = /\\d/;");
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -876,12 +876,23 @@
   return false;
 
 unsigned TokenCount = 0;
+auto InCharacterClass = false;
 for (auto I = Tokens.rbegin() + 1, E = Tokens.rend(); I != E; ++I) {
   ++TokenCount;
   auto Prev = I + 1;
   while (Prev != E && Prev[0]->is(tok::comment))
 ++Prev;
-  if (I[0]->isOneOf(tok::slash, tok::slashequal) &&
+  // Slashes in character classes (delimited by [ and ]) do not need
+  // escaping. Escaping of the squares themselves is already handled by
+  // \c tryMergeEscapeSequence(), a plain tok::r_square must be 
non-escaped.
+  if (I[0]->is(tok::r_square))
+InCharacterClass = true;
+  if (I[0]->is(tok::l_square)) {
+if (!InCharacterClass)
+  return false;
+InCharacterClass = false;
+  }
+  if (!InCharacterClass && I[0]->isOneOf(tok::slash, tok::slashequal) &&
   (Prev == E ||
((Prev[0]->isOneOf(tok::l_paren, tok::semi, tok::l_brace,
   tok::r_brace, tok::exclaim, tok::l_square,


Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -617,9 +617,15 @@
   verifyFormat("var regex = /x|y/;");
   verifyFormat("var regex = /a{2}/;");
   verifyFormat("var regex = /a{1,3}/;");
+
   verifyFormat("var regex = /[abc]/;");
   verifyFormat("var regex = /[^abc]/;");
   verifyFormat("var regex = /[\\b]/;");
+  verifyFormat("var regex = /[/]/;");
+  verifyFormat("var regex = /[\\/]/;");
+  verifyFormat("var regex = /\\[/;");
+  verifyFormat("var regex = /[/]/;");
+
   verifyFormat("var regex = /\\b/;");
   verifyFormat("var regex = /\\B/;");
   verifyFormat("var regex = /\\d/;");
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -876,12 +876,23 @@
   return false;
 
 unsigned TokenCount = 0;
+auto InCharacterClass = false;
 for (auto I = Tokens.rbegin() + 1, E = Tokens.rend(); I != E; ++I) {
   ++TokenCount;
   auto Prev = I + 1;
   while (Prev != E && Prev[0]->is(tok::comment))
 ++Prev;
-  if (I[0]->isOneOf(tok::slash, tok::slashequal) &&
+  // Slashes in character classes (delimited by [ and ]) do not need
+  // escaping. Escaping of the squares themselves is already handled by
+  // \c tryMergeEscapeSequence(), a plain tok::r_square must be non-escaped.
+  if (I[0]->is(tok::r_square))
+InCharacterClass = true;
+  if (I[0]->is(tok::l_square)) {
+if (!InCharacterClass)
+  return false;
+InCharacterClass = false;
+  }
+  if (!InCharacterClass && I[0]->isOneOf(tok::slash, tok::slashequal) &&
   (Prev == E ||
((Prev[0]->isOneOf(tok::l_paren, tok::semi, tok::l_brace,
   tok::r_brace, tok::exclaim, tok::l_square,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D13607: [Fix] Make it an error to take the address of (most) enable_if functions.

2015-10-11 Thread George Burgess IV via cfe-commits
george.burgess.iv updated this revision to Diff 37075.
george.burgess.iv marked 2 inline comments as done.
george.burgess.iv added a comment.

Addressed all feedback by rolling two of our overloading checks into one.


http://reviews.llvm.org/D13607

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/Sema.h
  lib/Sema/SemaCast.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaInit.cpp
  lib/Sema/SemaOverload.cpp
  test/CodeGen/enable_if.c
  test/Sema/enable_if.c
  test/SemaCXX/enable_if.cpp

Index: test/SemaCXX/enable_if.cpp
===
--- test/SemaCXX/enable_if.cpp
+++ test/SemaCXX/enable_if.cpp
@@ -163,3 +163,76 @@
 fn3(sizeof(T) == 1);
   }
 }
+
+namespace FnPtrs {
+  int ovlFoo(int m) __attribute__((enable_if(m > 0, "")));
+  int ovlFoo(int m);
+
+  void test() {
+// Assignment gives us a different code path than declarations, and `&foo`
+// gives us a different code path than `foo`
+int (*p)(int) = ovlFoo;
+int (*p2)(int) = &ovlFoo;
+int (*a)(int);
+a = ovlFoo;
+a = &ovlFoo;
+  }
+
+  int ovlBar(int) __attribute__((enable_if(true, "")));
+  int ovlBar(int m) __attribute__((enable_if(false, "")));
+  void test2() {
+int (*p)(int) = ovlBar;
+int (*p2)(int) = &ovlBar;
+int (*a)(int);
+a = ovlBar;
+a = &ovlBar;
+  }
+
+  int ovlConflict(int m) __attribute__((enable_if(true, "")));
+  int ovlConflict(int m);
+  void test3() {
+int (*p)(int) = ovlConflict; // expected-error{{address of overloaded function 'ovlConflict' is ambiguous}} expected-note@191{{candidate function}} expected-note@192{{candidate function}}
+int (*p2)(int) = &ovlConflict; // expected-error{{address of overloaded function 'ovlConflict' is ambiguous}} expected-note@191{{candidate function}} expected-note@192{{candidate function}}
+int (*a)(int);
+a = ovlConflict; // expected-error{{assigning to 'int (*)(int)' from incompatible type ''}} expected-note@191{{candidate function}} expected-note@192{{candidate function}}
+a = &ovlConflict; // expected-error{{assigning to 'int (*)(int)' from incompatible type ''}} expected-note@191{{candidate function}} expected-note@192{{candidate function}}
+  }
+
+  template 
+  T templated(T m) __attribute__((enable_if(true, ""))) { return T(); }
+  template 
+  T templated(T m) __attribute__((enable_if(false, ""))) { return T(); }
+  void test4() {
+int (*p)(int) = templated;
+int (*p2)(int) = &templated;
+int (*a)(int);
+a = templated;
+a = &templated;
+  }
+
+  template 
+  T templatedBar(T m) __attribute__((enable_if(m > 0, ""))) { return T(); }
+  void test5() {
+int (*p)(int) = templatedBar; // expected-error{{address of overloaded function 'templatedBar' does not match required type 'int (int)'}} expected-note@214{{candidate function made ineligible by enable_if}}
+int (*p2)(int) = &templatedBar; // expected-error{{address of overloaded function 'templatedBar' does not match required type 'int (int)'}} expected-note@214{{candidate function made ineligible by enable_if}}
+int (*a)(int);
+a = templatedBar; // expected-error{{assigning to 'int (*)(int)' from incompatible type ''}} expected-note@214{{candidate function made ineligible by enable_if}}
+a = &templatedBar; // expected-error{{assigning to 'int (*)(int)' from incompatible type ''}} expected-note@214{{candidate function made ineligible by enable_if}}
+  }
+
+  template 
+  T templatedConflict(T m) __attribute__((enable_if(false, ""))) { return T(); }
+  template 
+  T templatedConflict(T m) __attribute__((enable_if(true, ""))) { return T(); }
+  template 
+  T templatedConflict(T m) { return T(); }
+  void test6() {
+// NOTE: The redundant errors are a bug, not a feature. Fix is in the works.
+// :)
+int (*p)(int) = templatedConflict; // expected-error{{address of overloaded function 'templatedConflict' is ambiguous}} expected-note@224{{candidate function made ineligible by enable_if}} expected-note@226{{candidate function}} expected-note@228{{candidate function}} expected-error{{address of overloaded function 'templatedConflict' is ambiguous}} expected-note@228{{candidate function}} expected-note@226{{candidate function}}
+int (*p0)(int) = &templatedConflict; // expected-error{{address of overloaded function 'templatedConflict' is ambiguous}} expected-note@224{{candidate function made ineligible by enable_if}} expected-note@226{{candidate function}} expected-note@228{{candidate function}} expected-error{{address of overloaded function 'templatedConflict' is ambiguous}} expected-note@228{{candidate function}} expected-note@226{{candidate function}}
+int (*a)(int);
+a = templatedConflict; // expected-error{{assigning to 'int (*)(int)' from incompatible type ''}} expected-note@224{{candidate function made ineligible by enable_if}} expected-note@226{{candidate function}} expected-note@228{{candidate function}}
+a = &templatedConflict; // e

Re: [PATCH] D13607: [Fix] Make it an error to take the address of (most) enable_if functions.

2015-10-11 Thread George Burgess IV via cfe-commits
george.burgess.iv added inline comments.


Comment at: lib/Sema/SemaInit.cpp:4978-4990
@@ -4977,1 +4977,15 @@
 
+// As an extension, C can have overloaded functions. We need to add the
+// address resolution step.
+if (Initializer->getType() == Context.OverloadTy) {
+  bool MultipleCandidates;
+  DeclAccessPair DAP;
+  if (FunctionDecl *FD = S.ResolveAddressOfOverloadedFunction(
+  Initializer, DestType, false, DAP, &MultipleCandidates)) {
+AddAddressOverloadResolutionStep(FD, DAP, MultipleCandidates);
+  } else {
+SetFailed(InitializationSequence::FK_AddressOfOverloadFailed);
+return;
+  }
+}
+

rsmith wrote:
> It would seem better to handle this in the assignment rules rather than 
> duplicating it between here and the binary operator case.
I tried that initially, and it failed. Turns out the error in my initial 
attempt was just me being dumb. :)

Thanks for catching that.


http://reviews.llvm.org/D13607



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


Re: [PATCH] D11740: ABI versioning macros for libc++

2015-10-11 Thread Eric Fiselier via cfe-commits
EricWF accepted this revision.
EricWF added a comment.
This revision is now accepted and ready to land.

LGTM but this is still blocked by http://reviews.llvm.org/D13407. Ill let you 
know once that has landed.



Comment at: include/__config:251
@@ +250,3 @@
+ !defined(__arm__)) || 
\
+defined(_LIBCPP_ALTERNATE_STRING_LAYOUT)
+#define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT

Is this the last remaining reference to `_LIBCPP_ALTERNATIVE_STRING_LAYOUT`?
If so please leave a note about how this is the old name and is used here to be 
backward compatible.


Comment at: include/__config:252
@@ -246,1 +251,3 @@
+defined(_LIBCPP_ALTERNATE_STRING_LAYOUT)
+#define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
 #endif

I think he's demonstrating the patches functionality and intended usage by 
converting an existing option. Future ABI options should probably start with 
the macro prefix '_LIBCPP_ABI' anyway. 


Repository:
  rL LLVM

http://reviews.llvm.org/D11740



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


Re: [PATCH] D12512: [libcxxabi] Manually align pointers in __cxa_allocate_exception - Fixes PR24604

2015-10-11 Thread Eric Fiselier via cfe-commits
EricWF added a comment.

Whats preventing this from landing? @joerg @danalbert Do we want to use 
"posix_memalign" on Android or not?


http://reviews.llvm.org/D12512



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


[libcxx] r250003 - [Darwin] Need to add -isysroot on OS X otherwise the tests will fail if you don't have the command line tools package installed.

2015-10-11 Thread Chris Bieneman via cfe-commits
Author: cbieneman
Date: Sun Oct 11 19:49:56 2015
New Revision: 250003

URL: http://llvm.org/viewvc/llvm-project?rev=250003&view=rev
Log:
[Darwin] Need to add -isysroot on OS X otherwise the tests will fail if you 
don't have the command line tools package installed.

This mirrors how other LLVM suites are configured for running on OS X.

Modified:
libcxx/trunk/test/libcxx/test/config.py

Modified: libcxx/trunk/test/libcxx/test/config.py
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/test/config.py?rev=250003&r1=250002&r2=250003&view=diff
==
--- libcxx/trunk/test/libcxx/test/config.py (original)
+++ libcxx/trunk/test/libcxx/test/config.py Sun Oct 11 19:49:56 2015
@@ -6,6 +6,7 @@ import pkgutil
 import re
 import shlex
 import sys
+import subprocess
 
 import lit.Test  # pylint: disable=import-error,no-name-in-module
 import lit.util  # pylint: disable=import-error,no-name-in-module
@@ -42,6 +43,24 @@ def loadSiteConfig(lit_config, config, p
 ld_fn(config, site_cfg)
 lit_config.load_config = ld_fn
 
+def getSysrootFlagsOnDarwin(config, lit_config):
+# On Darwin, support relocatable SDKs by providing Clang with a
+# default system root path.
+if 'darwin' in config.target_triple:
+try:
+cmd = subprocess.Popen(['xcrun', '--show-sdk-path'],
+   stdout=subprocess.PIPE, 
stderr=subprocess.PIPE)
+out, err = cmd.communicate()
+out = out.strip()
+res = cmd.wait()
+except OSError:
+res = -1
+if res == 0 and out:
+sdk_path = out
+lit_config.note('using SDKROOT: %r' % sdk_path)
+return ["-isysroot", sdk_path]
+return []
+
 
 class Configuration(object):
 # pylint: disable=redefined-outer-name
@@ -339,6 +358,8 @@ class Configuration(object):
 # Configure extra flags
 compile_flags_str = self.get_lit_conf('compile_flags', '')
 self.cxx.compile_flags += shlex.split(compile_flags_str)
+sysroot_flags = getSysrootFlagsOnDarwin(self.config, self.lit_config)
+self.cxx.compile_flags.extend(sysroot_flags)
 
 def configure_default_compile_flags(self):
 # Try and get the std version from the command line. Fall back to


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


Re: [libcxx] r250003 - [Darwin] Need to add -isysroot on OS X otherwise the tests will fail if you don't have the command line tools package installed.

2015-10-11 Thread Eric Fiselier via cfe-commits
Do we need to do with while building libc++ as well? Also please reuse
lit.util.capture or lit.util.executeCommand instead of subprocess.

/Eric

On Sun, Oct 11, 2015 at 6:49 PM, Chris Bieneman via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: cbieneman
> Date: Sun Oct 11 19:49:56 2015
> New Revision: 250003
>
> URL: http://llvm.org/viewvc/llvm-project?rev=250003&view=rev
> Log:
> [Darwin] Need to add -isysroot on OS X otherwise the tests will fail if
> you don't have the command line tools package installed.
>
> This mirrors how other LLVM suites are configured for running on OS X.
>
> Modified:
> libcxx/trunk/test/libcxx/test/config.py
>
> Modified: libcxx/trunk/test/libcxx/test/config.py
> URL:
> http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/test/config.py?rev=250003&r1=250002&r2=250003&view=diff
>
> ==
> --- libcxx/trunk/test/libcxx/test/config.py (original)
> +++ libcxx/trunk/test/libcxx/test/config.py Sun Oct 11 19:49:56 2015
> @@ -6,6 +6,7 @@ import pkgutil
>  import re
>  import shlex
>  import sys
> +import subprocess
>
>  import lit.Test  # pylint: disable=import-error,no-name-in-module
>  import lit.util  # pylint: disable=import-error,no-name-in-module
> @@ -42,6 +43,24 @@ def loadSiteConfig(lit_config, config, p
>  ld_fn(config, site_cfg)
>  lit_config.load_config = ld_fn
>
> +def getSysrootFlagsOnDarwin(config, lit_config):
> +# On Darwin, support relocatable SDKs by providing Clang with a
> +# default system root path.
> +if 'darwin' in config.target_triple:
> +try:
> +cmd = subprocess.Popen(['xcrun', '--show-sdk-path'],
> +   stdout=subprocess.PIPE,
> stderr=subprocess.PIPE)
> +out, err = cmd.communicate()
> +out = out.strip()
> +res = cmd.wait()
> +except OSError:
> +res = -1
> +if res == 0 and out:
> +sdk_path = out
> +lit_config.note('using SDKROOT: %r' % sdk_path)
> +return ["-isysroot", sdk_path]
> +return []
> +
>
>  class Configuration(object):
>  # pylint: disable=redefined-outer-name
> @@ -339,6 +358,8 @@ class Configuration(object):
>  # Configure extra flags
>  compile_flags_str = self.get_lit_conf('compile_flags', '')
>  self.cxx.compile_flags += shlex.split(compile_flags_str)
> +sysroot_flags = getSysrootFlagsOnDarwin(self.config,
> self.lit_config)
> +self.cxx.compile_flags.extend(sysroot_flags)
>
>  def configure_default_compile_flags(self):
>  # Try and get the std version from the command line. Fall back to
>
>
> ___
> 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


Re: [libcxx] r250003 - [Darwin] Need to add -isysroot on OS X otherwise the tests will fail if you don't have the command line tools package installed.

2015-10-11 Thread Chris Bieneman via cfe-commits
CMake handles doing it while building. I will update to use lit.util.*

-Chris

> On Oct 11, 2015, at 6:04 PM, Eric Fiselier  wrote:
> 
> Do we need to do with while building libc++ as well? Also please reuse 
> lit.util.capture or lit.util.executeCommand instead of subprocess.
> 
> /Eric
> 
> On Sun, Oct 11, 2015 at 6:49 PM, Chris Bieneman via cfe-commits 
> mailto:cfe-commits@lists.llvm.org>> wrote:
> Author: cbieneman
> Date: Sun Oct 11 19:49:56 2015
> New Revision: 250003
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=250003&view=rev 
> 
> Log:
> [Darwin] Need to add -isysroot on OS X otherwise the tests will fail if you 
> don't have the command line tools package installed.
> 
> This mirrors how other LLVM suites are configured for running on OS X.
> 
> Modified:
> libcxx/trunk/test/libcxx/test/config.py
> 
> Modified: libcxx/trunk/test/libcxx/test/config.py
> URL: 
> http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/test/config.py?rev=250003&r1=250002&r2=250003&view=diff
>  
> 
> ==
> --- libcxx/trunk/test/libcxx/test/config.py (original)
> +++ libcxx/trunk/test/libcxx/test/config.py Sun Oct 11 19:49:56 2015
> @@ -6,6 +6,7 @@ import pkgutil
>  import re
>  import shlex
>  import sys
> +import subprocess
> 
>  import lit.Test  # pylint: disable=import-error,no-name-in-module
>  import lit.util  # pylint: disable=import-error,no-name-in-module
> @@ -42,6 +43,24 @@ def loadSiteConfig(lit_config, config, p
>  ld_fn(config, site_cfg)
>  lit_config.load_config = ld_fn
> 
> +def getSysrootFlagsOnDarwin(config, lit_config):
> +# On Darwin, support relocatable SDKs by providing Clang with a
> +# default system root path.
> +if 'darwin' in config.target_triple:
> +try:
> +cmd = subprocess.Popen(['xcrun', '--show-sdk-path'],
> +   stdout=subprocess.PIPE, 
> stderr=subprocess.PIPE)
> +out, err = cmd.communicate()
> +out = out.strip()
> +res = cmd.wait()
> +except OSError:
> +res = -1
> +if res == 0 and out:
> +sdk_path = out
> +lit_config.note('using SDKROOT: %r' % sdk_path)
> +return ["-isysroot", sdk_path]
> +return []
> +
> 
>  class Configuration(object):
>  # pylint: disable=redefined-outer-name
> @@ -339,6 +358,8 @@ class Configuration(object):
>  # Configure extra flags
>  compile_flags_str = self.get_lit_conf('compile_flags', '')
>  self.cxx.compile_flags += shlex.split(compile_flags_str)
> +sysroot_flags = getSysrootFlagsOnDarwin(self.config, self.lit_config)
> +self.cxx.compile_flags.extend(sysroot_flags)
> 
>  def configure_default_compile_flags(self):
>  # Try and get the std version from the command line. Fall back to
> 
> 
> ___
> 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] r250007 - [Darwin] Reworking r250003 to use lit.util.capture instead of subprocess.

2015-10-11 Thread Chris Bieneman via cfe-commits
Author: cbieneman
Date: Sun Oct 11 21:54:30 2015
New Revision: 250007

URL: http://llvm.org/viewvc/llvm-project?rev=250007&view=rev
Log:
[Darwin] Reworking r250003 to use lit.util.capture instead of subprocess.

Modified:
libcxx/trunk/test/libcxx/test/config.py

Modified: libcxx/trunk/test/libcxx/test/config.py
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/test/config.py?rev=250007&r1=250006&r2=250007&view=diff
==
--- libcxx/trunk/test/libcxx/test/config.py (original)
+++ libcxx/trunk/test/libcxx/test/config.py Sun Oct 11 21:54:30 2015
@@ -6,7 +6,6 @@ import pkgutil
 import re
 import shlex
 import sys
-import subprocess
 
 import lit.Test  # pylint: disable=import-error,no-name-in-module
 import lit.util  # pylint: disable=import-error,no-name-in-module
@@ -48,11 +47,8 @@ def getSysrootFlagsOnDarwin(config, lit_
 # default system root path.
 if 'darwin' in config.target_triple:
 try:
-cmd = subprocess.Popen(['xcrun', '--show-sdk-path'],
-   stdout=subprocess.PIPE, 
stderr=subprocess.PIPE)
-out, err = cmd.communicate()
-out = out.strip()
-res = cmd.wait()
+out = lit.util.capture(['xcrun', '--show-sdk-path']).strip()
+res = 0
 except OSError:
 res = -1
 if res == 0 and out:


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


Re: [libcxx] r250003 - [Darwin] Need to add -isysroot on OS X otherwise the tests will fail if you don't have the command line tools package installed.

2015-10-11 Thread Chris Bieneman via cfe-commits
Updated in r250007.

-Chris

> On Oct 11, 2015, at 7:49 PM, Chris Bieneman via cfe-commits 
>  wrote:
> 
> CMake handles doing it while building. I will update to use lit.util.*
> 
> -Chris
> 
>> On Oct 11, 2015, at 6:04 PM, Eric Fiselier > > wrote:
>> 
>> Do we need to do with while building libc++ as well? Also please reuse 
>> lit.util.capture or lit.util.executeCommand instead of subprocess.
>> 
>> /Eric
>> 
>> On Sun, Oct 11, 2015 at 6:49 PM, Chris Bieneman via cfe-commits 
>> mailto:cfe-commits@lists.llvm.org>> wrote:
>> Author: cbieneman
>> Date: Sun Oct 11 19:49:56 2015
>> New Revision: 250003
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=250003&view=rev 
>> 
>> Log:
>> [Darwin] Need to add -isysroot on OS X otherwise the tests will fail if you 
>> don't have the command line tools package installed.
>> 
>> This mirrors how other LLVM suites are configured for running on OS X.
>> 
>> Modified:
>> libcxx/trunk/test/libcxx/test/config.py
>> 
>> Modified: libcxx/trunk/test/libcxx/test/config.py
>> URL: 
>> http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/test/config.py?rev=250003&r1=250002&r2=250003&view=diff
>>  
>> 
>> ==
>> --- libcxx/trunk/test/libcxx/test/config.py (original)
>> +++ libcxx/trunk/test/libcxx/test/config.py Sun Oct 11 19:49:56 2015
>> @@ -6,6 +6,7 @@ import pkgutil
>>  import re
>>  import shlex
>>  import sys
>> +import subprocess
>> 
>>  import lit.Test  # pylint: disable=import-error,no-name-in-module
>>  import lit.util  # pylint: disable=import-error,no-name-in-module
>> @@ -42,6 +43,24 @@ def loadSiteConfig(lit_config, config, p
>>  ld_fn(config, site_cfg)
>>  lit_config.load_config = ld_fn
>> 
>> +def getSysrootFlagsOnDarwin(config, lit_config):
>> +# On Darwin, support relocatable SDKs by providing Clang with a
>> +# default system root path.
>> +if 'darwin' in config.target_triple:
>> +try:
>> +cmd = subprocess.Popen(['xcrun', '--show-sdk-path'],
>> +   stdout=subprocess.PIPE, 
>> stderr=subprocess.PIPE)
>> +out, err = cmd.communicate()
>> +out = out.strip()
>> +res = cmd.wait()
>> +except OSError:
>> +res = -1
>> +if res == 0 and out:
>> +sdk_path = out
>> +lit_config.note('using SDKROOT: %r' % sdk_path)
>> +return ["-isysroot", sdk_path]
>> +return []
>> +
>> 
>>  class Configuration(object):
>>  # pylint: disable=redefined-outer-name
>> @@ -339,6 +358,8 @@ class Configuration(object):
>>  # Configure extra flags
>>  compile_flags_str = self.get_lit_conf('compile_flags', '')
>>  self.cxx.compile_flags += shlex.split(compile_flags_str)
>> +sysroot_flags = getSysrootFlagsOnDarwin(self.config, 
>> self.lit_config)
>> +self.cxx.compile_flags.extend(sysroot_flags)
>> 
>>  def configure_default_compile_flags(self):
>>  # Try and get the std version from the command line. Fall back to
>> 
>> 
>> ___
>> 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


r250008 - bindings: add new C++ function attribute accessors

2015-10-11 Thread Saleem Abdulrasool via cfe-commits
Author: compnerd
Date: Sun Oct 11 22:10:20 2015
New Revision: 250008

URL: http://llvm.org/viewvc/llvm-project?rev=250008&view=rev
Log:
bindings: add new C++ function attribute accessors

Add methods to index Cursor to see if a cxx method is pure_virtual,
virtual or const methods.

Patch by Jonathan B Coe!

Modified:
cfe/trunk/bindings/python/clang/cindex.py
cfe/trunk/bindings/python/tests/cindex/test_cursor.py

Modified: cfe/trunk/bindings/python/clang/cindex.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/clang/cindex.py?rev=250008&r1=250007&r2=250008&view=diff
==
--- cfe/trunk/bindings/python/clang/cindex.py (original)
+++ cfe/trunk/bindings/python/clang/cindex.py Sun Oct 11 22:10:20 2015
@@ -1164,12 +1164,30 @@ class Cursor(Structure):
 """
 return conf.lib.clang_isCursorDefinition(self)
 
+def is_const_method(self):
+"""Returns True if the cursor refers to a C++ member function or member
+function template that is declared 'const'.
+"""
+return conf.lib.clang_CXXMethod_isConst(self)
+
+def is_pure_virtual_method(self):
+"""Returns True if the cursor refers to a C++ member function or member
+function template that is declared pure virtual.
+"""
+return conf.lib.clang_CXXMethod_isPureVirtual(self)
+
 def is_static_method(self):
 """Returns True if the cursor refers to a C++ member function or member
 function template that is declared 'static'.
 """
 return conf.lib.clang_CXXMethod_isStatic(self)
 
+def is_virtual_method(self):
+"""Returns True if the cursor refers to a C++ member function or member
+function template that is declared 'virtual'.
+"""
+return conf.lib.clang_CXXMethod_isVirtual(self)
+
 def get_definition(self):
 """
 If the cursor is a reference to a declaration or a declaration of
@@ -2879,6 +2897,10 @@ functionList = [
[Index, c_char_p],
c_object_p),
 
+  ("clang_CXXMethod_isConst",
+   [Cursor],
+   bool),
+
   ("clang_CXXMethod_isPureVirtual",
[Cursor],
bool),

Modified: cfe/trunk/bindings/python/tests/cindex/test_cursor.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/tests/cindex/test_cursor.py?rev=250008&r1=250007&r2=250008&view=diff
==
--- cfe/trunk/bindings/python/tests/cindex/test_cursor.py (original)
+++ cfe/trunk/bindings/python/tests/cindex/test_cursor.py Sun Oct 11 22:10:20 
2015
@@ -97,6 +97,21 @@ def test_canonical():
 assert len(cursors) == 3
 assert cursors[1].canonical == cursors[2].canonical
 
+def test_is_const_method():
+"""Ensure Cursor.is_const_method works."""
+source = 'class X { void foo() const; void bar(); };'
+tu = get_tu(source, lang='cpp')
+
+cls = get_cursor(tu, 'X')
+foo = get_cursor(tu, 'foo')
+bar = get_cursor(tu, 'bar')
+assert cls is not None
+assert foo is not None
+assert bar is not None
+
+assert foo.is_const_method()
+assert not bar.is_const_method()
+
 def test_is_static_method():
 """Ensure Cursor.is_static_method works."""
 
@@ -113,6 +128,36 @@ def test_is_static_method():
 assert foo.is_static_method()
 assert not bar.is_static_method()
 
+def test_is_pure_virtual_method():
+"""Ensure Cursor.is_pure_virtual_method works."""
+source = 'class X { virtual void foo() = 0; virtual void bar(); };'
+tu = get_tu(source, lang='cpp')
+
+cls = get_cursor(tu, 'X')
+foo = get_cursor(tu, 'foo')
+bar = get_cursor(tu, 'bar')
+assert cls is not None
+assert foo is not None
+assert bar is not None
+
+assert foo.is_pure_virtual_method()
+assert not bar.is_pure_virtual_method()
+
+def test_is_virtual_method():
+"""Ensure Cursor.is_virtual_method works."""
+source = 'class X { virtual void foo(); void bar(); };'
+tu = get_tu(source, lang='cpp')
+
+cls = get_cursor(tu, 'X')
+foo = get_cursor(tu, 'foo')
+bar = get_cursor(tu, 'bar')
+assert cls is not None
+assert foo is not None
+assert bar is not None
+
+assert foo.is_virtual_method()
+assert not bar.is_virtual_method()
+
 def test_underlying_type():
 tu = get_tu('typedef int foo;')
 typedef = get_cursor(tu, 'foo')


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


r250009 - clang-format: [JS] handle character classes in regexes.

2015-10-11 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Sun Oct 11 22:13:48 2015
New Revision: 250009

URL: http://llvm.org/viewvc/llvm-project?rev=250009&view=rev
Log:
clang-format: [JS] handle character classes in regexes.

Slashes in regular expressions do not need to be escaped and do not
terminate the regular expression even without a preceding backslash.

Patch by Martin Probst. Thank you.

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

Modified: cfe/trunk/lib/Format/Format.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=250009&r1=250008&r2=250009&view=diff
==
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Sun Oct 11 22:13:48 2015
@@ -876,12 +876,23 @@ private:
   return false;
 
 unsigned TokenCount = 0;
+bool InCharacterClass = false;
 for (auto I = Tokens.rbegin() + 1, E = Tokens.rend(); I != E; ++I) {
   ++TokenCount;
   auto Prev = I + 1;
   while (Prev != E && Prev[0]->is(tok::comment))
 ++Prev;
-  if (I[0]->isOneOf(tok::slash, tok::slashequal) &&
+  // Slashes in character classes (delimited by [ and ]) do not need
+  // escaping. Escaping of the squares themselves is already handled by
+  // \c tryMergeEscapeSequence(), a plain tok::r_square must be 
non-escaped.
+  if (I[0]->is(tok::r_square))
+InCharacterClass = true;
+  if (I[0]->is(tok::l_square)) {
+if (!InCharacterClass)
+  return false;
+InCharacterClass = false;
+  }
+  if (!InCharacterClass && I[0]->isOneOf(tok::slash, tok::slashequal) &&
   (Prev == E ||
((Prev[0]->isOneOf(tok::l_paren, tok::semi, tok::l_brace,
   tok::r_brace, tok::exclaim, tok::l_square,

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=250009&r1=250008&r2=250009&view=diff
==
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Sun Oct 11 22:13:48 2015
@@ -617,9 +617,15 @@ TEST_F(FormatTestJS, RegexLiteralSpecial
   verifyFormat("var regex = /x|y/;");
   verifyFormat("var regex = /a{2}/;");
   verifyFormat("var regex = /a{1,3}/;");
+
   verifyFormat("var regex = /[abc]/;");
   verifyFormat("var regex = /[^abc]/;");
   verifyFormat("var regex = /[\\b]/;");
+  verifyFormat("var regex = /[/]/;");
+  verifyFormat("var regex = /[\\/]/;");
+  verifyFormat("var regex = /\\[/;");
+  verifyFormat("var regex = /[/]/;");
+
   verifyFormat("var regex = /\\b/;");
   verifyFormat("var regex = /\\B/;");
   verifyFormat("var regex = /\\d/;");


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


Re: [PATCH] D13641: clang-format: [JS] handle character classes in regexes.

2015-10-11 Thread Daniel Jasper via cfe-commits
djasper accepted this revision.
djasper added a comment.
This revision is now accepted and ready to land.

looks good



Comment at: lib/Format/Format.cpp:879
@@ -878,2 +878,3 @@
 unsigned TokenCount = 0;
+auto InCharacterClass = false;
 for (auto I = Tokens.rbegin() + 1, E = Tokens.rend(); I != E; ++I) {

I think, we should just use bool here.


http://reviews.llvm.org/D13641



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


Re: [PATCH] D13641: clang-format: [JS] handle character classes in regexes.

2015-10-11 Thread Daniel Jasper via cfe-commits
djasper closed this revision.
djasper added a comment.

Submitted as r250009.


http://reviews.llvm.org/D13641



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


r250010 - clang-format: Fixed typecast getting put on a separate line from the

2015-10-11 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Sun Oct 11 22:19:07 2015
New Revision: 250010

URL: http://llvm.org/viewvc/llvm-project?rev=250010&view=rev
Log:
clang-format: Fixed typecast getting put on a separate line from the
key in Obj-C dictionary literals

This fixes: https://llvm.org/PR22647

Patch by Kent Sutherland. Thank you.

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

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=250010&r1=250009&r2=250010&view=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Sun Oct 11 22:19:07 2015
@@ -372,7 +372,9 @@ private:
 updateParameterCount(Left, CurrentToken);
 if (CurrentToken->isOneOf(tok::colon, tok::l_brace)) {
   FormatToken *Previous = CurrentToken->getPreviousNonComment();
-  if ((CurrentToken->is(tok::colon) ||
+  if (((CurrentToken->is(tok::colon) &&
+(!Contexts.back().ColonIsDictLiteral ||
+ Style.Language != FormatStyle::LK_Cpp)) ||
Style.Language == FormatStyle::LK_Proto) &&
   Previous->Tok.getIdentifierInfo())
 Previous->Type = TT_SelectorName;

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=250010&r1=250009&r2=250010&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Sun Oct 11 22:19:07 2015
@@ -7531,6 +7531,13 @@ TEST_F(FormatTest, ObjCDictLiterals) {
"  bb : b,\n"
"   : ccc\n"
"}];");
+
+  // Ensure that casts before the key are kept on the same line as the key.
+  verifyFormat(
+  "NSDictionary *d = @{\n"
+  "  ( id)a : ( id),\n"
+  "  ( id)aa : ( id)aa,\n"
+  "};");
 }
 
 TEST_F(FormatTest, ObjCArrayLiterals) {


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


Re: [PATCH] D12501: [clang-format] Obj-C dictionary literals: Fixed typecast getting put on a separate line from the key

2015-10-11 Thread Daniel Jasper via cfe-commits
djasper closed this revision.
djasper added a comment.

Submitted as r250010.


http://reviews.llvm.org/D12501



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


Re: [PATCH] D10834: Added functions to retrieve information about variable storage in libclang and its python bindings.

2015-10-11 Thread guibufolo+l...@gmail.com via cfe-commits
RedX2501 added inline comments.


Comment at: include/clang-c/Index.h:3815-3823
@@ -3814,2 +3814,11 @@
 
 /**
+ * \brief Returns true if a variable with function scope is a non-static local 
variable.
+ */
+CINDEX_LINKAGE bool clang_Cursor_hasLocalStorage(CXCursor C);
+
+/*
+ * \brief  Returns true if a variable with function scope is a static local 
variable.
+ */
+CINDEX_LINKAGE bool clang_Cursor_isStaticLocal(CXCursor C);
+

rsmith wrote:
> It might be better to combine these into a single function 
> (`getLocalVarKind`?) returning an enum { not local, non-static local, static 
> local }.
Combining these into one function with an enum is much more work when porting 
to python (which is also den in this patch). Therefore unless there are reasons 
beyond stylistic ones i'd prefer to keep them separate.

IMHO this also increases the friendliness as you can directly infer from the 
documentation at http://clang.llvm.org/doxygen/ what they should do as they 
just forward the calls..


http://reviews.llvm.org/D10834



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


Re: [PATCH] D13582: [DEBUG INFO] Emit debug info for type used in explicit cast only.

2015-10-11 Thread Bataev, Alexey via cfe-commits
Yes, revision 246985 
 
broke th debug info for types in explicit casts.


Best regards,
Alexey Bataev
=
Software Engineer
Intel Compiler Team

09.10.2015 18:26, David Blaikie пишет:



On Fri, Oct 9, 2015 at 2:26 AM, Alexey Bataev via cfe-commits 
mailto:cfe-commits@lists.llvm.org>> wrote:


ABataev created this revision.
ABataev added a reviewer: echristo.
ABataev added a subscriber: cfe-commits.

Currently debug info for types used in explicit cast only is not
emitted. It happened after a patch for better alignment handling.


You mean a patch related to alignment regressed this functionality? Do 
you have the specific revision number of that change (since it sounds 
like you tracked it down)?


This patch fixes this bug.

http://reviews.llvm.org/D13582

Files:
  lib/CodeGen/CGExpr.cpp
  test/CodeGenCXX/debug-info-explicit-cast.cpp

Index: lib/CodeGen/CGExpr.cpp
===
--- lib/CodeGen/CGExpr.cpp
+++ lib/CodeGen/CGExpr.cpp
@@ -799,6 +799,10 @@
 if (E->getType()->isVariablyModifiedType())
   EmitVariablyModifiedType(E->getType());

+if (isa(CE))
+  if (CGDebugInfo *DI = getDebugInfo())
+DI->EmitExplicitCastType(E->getType());
+
 switch (CE->getCastKind()) {
 // Non-converting casts (but not C's implicit conversion from
void*).
 case CK_BitCast:
Index: test/CodeGenCXX/debug-info-explicit-cast.cpp
===
--- test/CodeGenCXX/debug-info-explicit-cast.cpp
+++ test/CodeGenCXX/debug-info-explicit-cast.cpp
@@ -0,0 +1,18 @@
+// RUN: %clangxx -c -target x86_64-unknown-unknown -g %s
-emit-llvm -S -o - | FileCheck %s
+struct Foo {
+  int a;
+  Foo() : a(1){};
+};
+
+struct Bar {
+  int b;
+  Bar() : b(2){};
+};
+
+int main() {
+  Bar *pb = new Bar;
+
+  return reinterpret_cast(pb)->a;
+}
+
+// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "Foo",



___
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] D13643: [Sema] Warn on ternary comparison

2015-10-11 Thread Matěj Grabovský via cfe-commits
mgrabovsky created this revision.
mgrabovsky added a subscriber: cfe-commits.

This change adds a Sema diagnostic for comparisons like `a < b < c`,
which usually do not behave as intended by the author.

Fixes bug 20082.

http://reviews.llvm.org/D13643

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaChecking.cpp
  test/Sema/bool-compare.c

Index: test/Sema/bool-compare.c
===
--- test/Sema/bool-compare.c
+++ test/Sema/bool-compare.c
@@ -85,7 +85,9 @@
   if ((ayy z)  {} // no warning
   if((a(zy)  {}// no warning
-  if (z > (a(ay)  {}  // expected-warning {{ternary comparisons do not work as 
expected}} \
+  // expected-note {{to achieve the expected behavior, 
turn this expression into a conjunction of two comparisons}} \
+  // expected-note {{place parentheses around either of 
the comparisons to silence this warning}}
+  if (z > (a(agetLHS()->getSourceRange() << E->getRHS()->getSourceRange());
 }
 
+/// Diagnose attempts at ternary comparison, e.g., 1 < x < 2
+static void DiagnoseTernaryComparison(Sema &S, BinaryOperator *E) {
+  BinaryOperator *LHS = dyn_cast(E->getLHS());
+  if (!LHS || !LHS->isComparisonOp())
+return;
+
+  SourceLocation Loc = E->getSourceRange().getBegin();
+
+  S.DiagRuntimeBehavior(Loc, E,
+S.PDiag(diag::warn_ternary_comparison) << E->getSourceRange());
+  S.DiagRuntimeBehavior(Loc, E,
+S.PDiag(diag::note_ternary_comparison_to_conjunction));
+  S.DiagRuntimeBehavior(Loc, E,
+S.PDiag(diag::note_ternary_comparison_silence));
+}
+
 /// Analyze the operands of the given comparison.  Implements the
 /// fallback case from AnalyzeComparison.
 static void AnalyzeImpConvsInComparison(Sema &S, BinaryOperator *E) {
@@ -6720,7 +6736,9 @@
   Expr *RHS = E->getRHS()->IgnoreParenImpCasts();
   
   bool IsComparisonConstant = false;
-  
+
+  DiagnoseTernaryComparison(S, E);
+
   // Check whether an integer constant comparison results in a value
   // of 'true' or 'false'.
   if (T->isIntegralType(S.Context)) {
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -5862,6 +5862,14 @@
 def note_condition_assign_silence : Note<
   "place parentheses around the assignment to silence this warning">;
 
+def warn_ternary_comparison : Warning<"ternary comparisons do not work "
+  "as expected">,
+  InGroup;
+def note_ternary_comparison_to_conjunction : Note<"to achieve the expected 
behavior, "
+  "turn this expression into a conjunction of two comparisons">;
+def note_ternary_comparison_silence : Note<"place parentheses around either "
+  "of the comparisons to silence this warning">;
+
 def warn_equality_with_extra_parens : Warning<"equality comparison with "
   "extraneous parentheses">, InGroup;
 def note_equality_comparison_to_assign : Note<


Index: test/Sema/bool-compare.c
===
--- test/Sema/bool-compare.c
+++ test/Sema/bool-compare.c
@@ -85,7 +85,9 @@
   if ((ayy z)  {} // no warning
   if((a(zy)  {}// no warning
-  if (z > (a(ay)  {}  // expected-warning {{ternary comparisons do not work as expected}} \
+  // expected-note {{to achieve the expected behavior, turn this expression into a conjunction of two comparisons}} \
+  // expected-note {{place parentheses around either of the comparisons to silence this warning}}
+  if (z > (a(agetLHS()->getSourceRange() << E->getRHS()->getSourceRange());
 }
 
+/// Diagnose attempts at ternary comparison, e.g., 1 < x < 2
+static void DiagnoseTernaryComparison(Sema &S, BinaryOperator *E) {
+  BinaryOperator *LHS = dyn_cast(E->getLHS());
+  if (!LHS || !LHS->isComparisonOp())
+return;
+
+  SourceLocation Loc = E->getSourceRange().getBegin();
+
+  S.DiagRuntimeBehavior(Loc, E,
+S.PDiag(diag::warn_ternary_comparison) << E->getSourceRange());
+  S.DiagRuntimeBehavior(Loc, E,
+S.PDiag(diag::note_ternary_comparison_to_conjunction));
+  S.DiagRuntimeBehavior(Loc, E,
+S.PDiag(diag::note_ternary_comparison_silence));
+}
+
 /// Analyze the operands of the given comparison.  Implements the
 /// fallback case from AnalyzeComparison.
 static void AnalyzeImpConvsInComparison(Sema &S, BinaryOperator *E) {
@@ -6720,7 +6736,9 @@
   Expr *RHS = E->getRHS()->IgnoreParenImpCasts();
   
   bool IsComparisonConstant = false;
-  
+
+  DiagnoseTernaryComparison(S, E);
+
   // Check whether an integer constant comparison results in a value
   // of 'true' or 'false'.
   if (T->isIntegralType(S.Context)) {
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -5862,6 +5862,14 @@
 def 

Re: [PATCH] D13639: Add decayedType and hasDecayedType AST matchers

2015-10-11 Thread Manuel Klimek via cfe-commits
klimek accepted this revision.
klimek added a comment.
This revision is now accepted and ready to land.

lg


http://reviews.llvm.org/D13639



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


Re: [PATCH] D13014: [X86] Add XSAVE intrinsics (Clang part)

2015-10-11 Thread Elena Demikhovsky via cfe-commits
delena added a comment.

Do you need to add some tests for clang?


Repository:
  rL LLVM

http://reviews.llvm.org/D13014



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


Re: [PATCH] D13639: Add decayedType and hasDecayedType AST matchers

2015-10-11 Thread Manuel Klimek via cfe-commits
klimek added a comment.

Oh, please also run the docs update script

  cd docs/tools
  python ./dump_ast_matchers.py


http://reviews.llvm.org/D13639



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