[PATCH] D26226: Don't require nullability on template parameters in typedefs.

2016-11-01 Thread Doug Gregor via cfe-commits
doug.gregor accepted this revision.
doug.gregor added a comment.
This revision is now accepted and ready to land.

Seem fine; I'd rename the "FIXME" to a "Note" unless you're going to pass a 
flag to Type::canHaveNullability to say how to classify dependent types.


Repository:
  rL LLVM

https://reviews.llvm.org/D26226



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


[libcxx] r285788 - Fix GCC test failure caused by manually defining _LIBCPP_HAS_NO_VARIADICS

2016-11-01 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Wed Nov  2 00:08:58 2016
New Revision: 285788

URL: http://llvm.org/viewvc/llvm-project?rev=285788=rev
Log:
Fix GCC test failure caused by manually defining _LIBCPP_HAS_NO_VARIADICS

Modified:
libcxx/trunk/include/type_traits

Modified: libcxx/trunk/include/type_traits
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/type_traits?rev=285788=285787=285788=diff
==
--- libcxx/trunk/include/type_traits (original)
+++ libcxx/trunk/include/type_traits Wed Nov  2 00:08:58 2016
@@ -520,7 +520,7 @@ using bool_constant = integral_constant<
 typedef _LIBCPP_BOOL_CONSTANT(true)  true_type;
 typedef _LIBCPP_BOOL_CONSTANT(false) false_type;
 
-#if !defined(_LIBCPP_HAS_NO_VARIADICS)
+#if !defined(_LIBCPP_CXX03_LANG)
 
 // __lazy_and
 
@@ -595,7 +595,7 @@ struct __or_<_B0, _B1, _B2, _Bn...>
 template 
 struct __not_ : conditional<_Tp::value, false_type, true_type>::type {};
 
-#endif // !defined(_LIBCPP_HAS_NO_VARIADICS)
+#endif // !defined(_LIBCPP_CXX03_LANG)
 
 // is_const
 


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


[libcxx] r285786 - Fix __libcpp_is_constructible for source types with explicit conversion operators.

2016-11-01 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Tue Nov  1 22:57:34 2016
New Revision: 285786

URL: http://llvm.org/viewvc/llvm-project?rev=285786=rev
Log:
Fix __libcpp_is_constructible for source types with explicit conversion 
operators.

Previously __libcpp_is_constructible checked the validity of reference
construction using 'eat(declval())' but this doesn't consider
From's explicit conversion operators. This patch teaches 
__libcpp_is_constructible
how to handle these cases. To do this we need to check the validity
using 'static_cast(declval())'. Unfortunately static_cast allows
additional base-to-derived and lvalue-to-rvalue conversions, which have to be
checked for and manually rejected.

While implementing these changes I discovered that Clang incorrectly
rejects `static_cast(declval())` even though
`int &(declval())` is well formed. In order to tolerate this bug
the `__eat(...)` needs to be left in-place. Otherwise it could be replaced
entirely with the new static_cast implementation.

Thanks to Walter Brown for providing the test cases.

Modified:
libcxx/trunk/include/type_traits

libcxx/trunk/test/std/utilities/meta/meta.unary/meta.unary.prop/is_constructible.pass.cpp

Modified: libcxx/trunk/include/type_traits
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/type_traits?rev=285786=285785=285786=diff
==
--- libcxx/trunk/include/type_traits (original)
+++ libcxx/trunk/include/type_traits Tue Nov  1 22:57:34 2016
@@ -2894,26 +2894,64 @@ namespace __is_construct
 struct __nat {};
 }
 
-#if __has_feature(is_constructible)
+#if !defined(_LIBCPP_CXX03_LANG) && (!__has_feature(is_constructible) || \
+defined(_LIBCPP_TESTING_FALLBACK_IS_CONSTRUCTIBLE))
 
-template 
-struct _LIBCPP_TYPE_VIS_ONLY is_constructible
-: public integral_constant
-{};
-
-#else
+template 
+struct __libcpp_is_constructible;
 
-#ifndef _LIBCPP_HAS_NO_VARIADICS
+template 
+struct __is_invalid_base_to_derived_cast {
+  static_assert(is_reference<_To>::value, "Wrong specialization");
+  using _RawFrom = __uncvref_t<_From>;
+  using _RawTo = __uncvref_t<_To>;
+  static const bool value = __lazy_and<
+__lazy_not>,
+is_base_of<_RawFrom, _RawTo>,
+__lazy_not<__libcpp_is_constructible<_RawTo, _From>>
+  >::value;
+};
 
-//  main is_constructible test
+template 
+struct __is_invalid_lvalue_to_rvalue_cast : false_type {
+  static_assert(is_reference<_To>::value, "Wrong specialization");
+};
 
+template 
+struct __is_invalid_lvalue_to_rvalue_cast<_ToRef&&, _FromRef&> {
+  using _RawFrom = __uncvref_t<_FromRef>;
+  using _RawTo = __uncvref_t<_ToRef>;
+  static const bool value = __lazy_and<
+  __lazy_not>,
+  __lazy_or<
+is_same<_RawFrom, _RawTo>,
+is_base_of<_RawTo, _RawFrom>>
+>::value;
+};
 
 struct __is_constructible_helper
 {
-template 
-static true_type __test_ref(_Tp);
-template 
-static false_type __test_ref(...);
+template 
+static void __eat(_To);
+
+// This overload is needed to work around a Clang bug that disallows
+// static_cast(e) for non-reference-compatible types.
+// Example: static_cast(declval());
+// NOTE: The static_cast implementation below is required to support
+//  classes with explicit conversion operators.
+template (_VSTD::declval<_From>()))>
+static true_type __test_cast(int);
+
+template (_VSTD::declval<_From>()))>
+static integral_constant::value &&
+!__is_invalid_lvalue_to_rvalue_cast<_To, _From>::value
+> __test_cast(long);
+
+template 
+static false_type __test_cast(...);
 
 template ()...))>
@@ -2961,24 +2999,27 @@ struct __libcpp_is_constructible<_Tp, _A
 template 
 struct __libcpp_is_constructible<_Tp&, _A0>
 : public decltype(__is_constructible_helper::
-__test_ref<_Tp&>(_VSTD::declval<_A0>()))
+__test_cast<_Tp&, _A0>(0))
 {};
 
 template 
 struct __libcpp_is_constructible<_Tp&&, _A0>
 : public decltype(__is_constructible_helper::
-__test_ref<_Tp&&>(_VSTD::declval<_A0>()))
+__test_cast<_Tp&&, _A0>(0))
 {};
 
-//  is_constructible entry point
+#endif
 
+#if __has_feature(is_constructible)
+template 
+struct _LIBCPP_TYPE_VIS_ONLY is_constructible
+: public integral_constant
+{};
+#elif !defined(_LIBCPP_CXX03_LANG)
 template 
 struct _LIBCPP_TYPE_VIS_ONLY is_constructible
 : public __libcpp_is_constructible<_Tp, _Args...>::type {};
-
-
-#else  // _LIBCPP_HAS_NO_VARIADICS
-
+#else
 // template  struct is_constructible0;
 
 //  main is_constructible0 test
@@ -3151,8 +3192,8 @@ struct __is_constructible2_imp

[PATCH] D26231: [Sema] Allow static_cast<T&&>(e) to check explicit conversions for non-reference-related types.

2016-11-01 Thread Eric Fiselier via cfe-commits
EricWF created this revision.
EricWF added a reviewer: rsmith.
EricWF added a subscriber: cfe-commits.

[expr.cast.static] states:

> 3. A glvalue of type “cv1 T1” can be cast to type “rvalue reference to cv2 
> T2” if “cv2 T2” is reference-compatible with “cv1 T1”. The result refers to 
> the object or the specified base class subobject thereof. If T2 is an 
> inaccessible or ambiguous base class of T1, a program that necessitates such 
> a cast is ill-formed.
> 4. Otherwise, an expression e can be explicitly converted to a type T using a 
> static_cast of the form static_- cast(e) if the declaration T t(e); is 
> well-formed, for some invented temporary variable t. [...]

Currently when checking p3 Clang will diagnose `static_cast(e)` as invalid 
if the argument is not reference compatible with `T`. However I believe the 
correct behavior is to also check p4 in those cases.  For example:

  double y = 42;
  static_cast(y); // this should be OK.  'int&& t(y)' is well formed

Note that we still don't check p4 for non-reference-compatible types which are 
reference-related since  `T&& t(e);` should never be well formed in those cases.


https://reviews.llvm.org/D26231

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaCast.cpp
  test/SemaCXX/rval-references.cpp


Index: test/SemaCXX/rval-references.cpp
===
--- test/SemaCXX/rval-references.cpp
+++ test/SemaCXX/rval-references.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify 
-std=c++11 %s
+// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only  -verify 
-std=c++11 %s
 
 typedef int&& irr;
 typedef irr& ilr_c1; // Collapses to int&
@@ -30,11 +30,15 @@
   int & = 0;
   int & = virr2; // expected-error {{rvalue reference to type 'int' 
cannot bind to lvalue of type 'int'}}
   int i1 = 0;
+  const double d1 = 0;
+  const int ci1 = 1;
   int & = i1; // expected-error {{rvalue reference to type 'int' cannot 
bind to lvalue of type 'int'}}
   int & = ret_irr();
   int & = static_cast(i1);
-  (void)static_cast(i1); // expected-error {{types are not 
compatible}}
-
+  (void)static_cast(i1); // expected-error {{reference to type 
'not_int' could not bind to an lvalue of type 'int'}}
+  (void)static_cast(static_cast(i1)); // expected-error 
{{cannot cast from rvalue reference of type 'const int' to rvalue reference 
type 'int &&'}}
+  (void)static_cast(ci1);// expected-error {{types are not 
compatible}}
+  (void)static_cast(d1);
   int i2 = over(i1);
   not_int ni1 = over(0);
   int i3 = over(virr2);
Index: lib/Sema/SemaCast.cpp
===
--- lib/Sema/SemaCast.cpp
+++ lib/Sema/SemaCast.cpp
@@ -983,7 +983,7 @@
   // C++11 [expr.static.cast]p3: 
   //   A glvalue of type "cv1 T1" can be cast to type "rvalue reference to cv2
   //   T2" if "cv2 T2" is reference-compatible with "cv1 T1".
-  tcr = TryLValueToRValueCast(Self, SrcExpr.get(), DestType, CStyle, Kind, 
+  tcr = TryLValueToRValueCast(Self, SrcExpr.get(), DestType, CStyle, Kind,
   BasePath, msg);
   if (tcr != TC_NotApplicable)
 return tcr;
@@ -1134,10 +1134,10 @@
 }
 
 /// Tests whether a conversion according to N2844 is valid.
-TryCastResult
-TryLValueToRValueCast(Sema , Expr *SrcExpr, QualType DestType,
-  bool CStyle, CastKind , CXXCastPath , 
-  unsigned ) {
+TryCastResult TryLValueToRValueCast(Sema , Expr *SrcExpr,
+QualType DestType, bool CStyle,
+CastKind , CXXCastPath ,
+unsigned ) {
   // C++11 [expr.static.cast]p3:
   //   A glvalue of type "cv1 T1" can be cast to type "rvalue reference to 
   //   cv2 T2" if "cv2 T2" is reference-compatible with "cv1 T1".
@@ -1160,15 +1160,15 @@
 FromType = FromType.getUnqualifiedType();
 ToType = ToType.getUnqualifiedType();
   }
-  
-  if (Self.CompareReferenceRelationship(SrcExpr->getLocStart(),
-ToType, FromType,
-DerivedToBase, ObjCConversion,
-ObjCLifetimeConversion) 
-!= Sema::Ref_Compatible) {
-if (CStyle)
+
+  Sema::ReferenceCompareResult RefResult = Self.CompareReferenceRelationship(
+  SrcExpr->getLocStart(), ToType, FromType, DerivedToBase, ObjCConversion,
+  ObjCLifetimeConversion);
+  if (RefResult != Sema::Ref_Compatible) {
+if (CStyle || RefResult == Sema::Ref_Incompatible)
   return TC_NotApplicable;
-msg = diag::err_bad_lvalue_to_rvalue_cast;
+msg = SrcExpr->isLValue() ? diag::err_bad_lvalue_to_rvalue_cast
+  : diag::err_bad_rvalue_to_rvalue_cast;
 return TC_Failed;
   }
 
Index: include/clang/Basic/DiagnosticSemaKinds.td

Re: r284256 - Link static PIE programs against rcrt0.o on OpenBSD

2016-11-01 Thread Brad Smith via cfe-commits

On 10/30/16 01:57, Brad Smith via cfe-commits wrote:

On 10/25/16 19:34, Brad Smith via cfe-commits wrote:

On 10/18/16 22:13, Brad Smith via cfe-commits wrote:

On Fri, Oct 14, 2016 at 09:47:17PM -0400, Brad Smith via cfe-commits
wrote:

On Fri, Oct 14, 2016 at 05:59:54PM -, Ed Maste via cfe-commits
wrote:

Author: emaste
Date: Fri Oct 14 12:59:53 2016
New Revision: 284256

URL: http://llvm.org/viewvc/llvm-project?rev=284256=rev
Log:
Link static PIE programs against rcrt0.o on OpenBSD

Patch by Stefan Kempf.

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

Modified:
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/test/Driver/openbsd.c

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=284256=284255=284256=diff


==


--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Fri Oct 14 12:59:53 2016
@@ -8519,6 +8519,10 @@ void openbsd::Linker::ConstructJob(Compi
   if (Args.hasArg(options::OPT_pg))
 CmdArgs.push_back(

Args.MakeArgString(getToolChain().GetFilePath("gcrt0.o")));
+  else if (Args.hasArg(options::OPT_static) &&
+   !Args.hasArg(options::OPT_nopie))
+CmdArgs.push_back(
+
Args.MakeArgString(getToolChain().GetFilePath("rcrt0.o")));
   else
 CmdArgs.push_back(

Args.MakeArgString(getToolChain().GetFilePath("crt0.o")));

Modified: cfe/trunk/test/Driver/openbsd.c
URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/openbsd.c?rev=284256=284255=284256=diff


==


--- cfe/trunk/test/Driver/openbsd.c (original)
+++ cfe/trunk/test/Driver/openbsd.c Fri Oct 14 12:59:53 2016
@@ -67,3 +67,26 @@
 // CHECK-MIPS64-PIC: as{{.*}}" "-mabi" "64" "-EB" "-KPIC"
 // CHECK-MIPS64EL: as{{.*}}" "-mabi" "64" "-EL"
 // CHECK-MIPS64EL-PIC: as{{.*}}" "-mabi" "64" "-EL" "-KPIC"
+
+// Check linking against correct startup code when (not) using PIE
+// RUN: %clang -no-canonical-prefixes -target i686-pc-openbsd %s
-### 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-PIE %s
+// RUN: %clang -no-canonical-prefixes -target i686-pc-openbsd %s
-fno-pie %s -### 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-PIE %s
+// RUN: %clang -no-canonical-prefixes -target i686-pc-openbsd
-static %s -### 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-STATIC-PIE %s
+// RUN: %clang -no-canonical-prefixes -target i686-pc-openbsd
-static -fno-pie %s -### 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-STATIC-PIE %s
+// RUN: %clang -no-canonical-prefix -target i868-pc-openbsd -nopie
%s -### 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-NOPIE %s
+// RUN: %clang -no-canonical-prefix -target i868-pc-openbsd
-fno-pie -nopie %s -### 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-NOPIE %s
+// RUN: %clang -no-canonical-prefix -target i868-pc-openbsd -static
-nopie %s -### 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-NOPIE %s
+// RUN: %clang -no-canonical-prefix -target i868-pc-openbsd
-fno-pie -static -nopie %s -### 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-NOPIE %s
+// CHECK-PIE: "/usr/lib/crt0.o"
+// CHECK-PIE-NOT: "-nopie"
+// CHECK-STATIC-PIE: "/usr/lib/rcrt0.o"
+// CHECK-STATIC-PIE-NOT: "-nopie"
+// CHECK-NOPIE: "-nopie" {{.*}}"/usr/lib/crt0.o"


Ok, I see the obvious issue with -no-canonical-prefix vs
-no-canonical-prefixes
and fix the typo with the target triples.


After seeing what the test failure was I have adjusted the tests as
appropriate.


ping.


ping ping.


The original patch to Tools.cpp was fine but the tests that were
written had issues, which should be fixed now. I am looking to be
able to re-commit the (updated) patch so Clang is no longer building
broken static binaries on OpenBSD.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D24085: arm: Fix ttype encoding assertion failure.

2016-11-01 Thread Marshall Clow via cfe-commits
mclow.lists accepted this revision.
mclow.lists added a comment.
This revision is now accepted and ready to land.

Thanks.


https://reviews.llvm.org/D24085



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


[PATCH] D26197: Protect tests for new/delete under libcpp-no-exceptions

2016-11-01 Thread Marshall Clow via cfe-commits
mclow.lists accepted this revision.
mclow.lists added a comment.
This revision is now accepted and ready to land.

LGTM.


https://reviews.llvm.org/D26197



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


[PATCH] D26227: Don't require nullability on 'va_list'.

2016-11-01 Thread Jordan Rose via cfe-commits
jordan_rose created this revision.
jordan_rose added reviewers: doug.gregor, rsmith.
jordan_rose added a subscriber: cfe-commits.
jordan_rose set the repository for this revision to rL LLVM.
jordan_rose added dependencies: D26226: Don't require nullability on template 
parameters in typedefs., D25850: Accept nullability annotations (_Nullable) on 
array parameters.

There are many non-portable typedefs, but va_list is one that nobody ever 
thinks of as a pointer or an array. (When's the last time you saw someone check 
for a NULL va_list?) Make an exception for this one special type.

(Is this the best way to do this?)

  

Part of rdar://problem/25846421. Depends on https://reviews.llvm.org/D26226 and 
https://reviews.llvm.org/D25850.


Repository:
  rL LLVM

https://reviews.llvm.org/D26227

Files:
  lib/Sema/SemaType.cpp
  test/SemaObjCXX/Inputs/nullability-consistency-arrays.h


Index: test/SemaObjCXX/Inputs/nullability-consistency-arrays.h
===
--- test/SemaObjCXX/Inputs/nullability-consistency-arrays.h
+++ test/SemaObjCXX/Inputs/nullability-consistency-arrays.h
@@ -1,3 +1,5 @@
+#include 
+
 void firstThingInTheFileThatNeedsNullabilityIsAnArray(int ints[]);
 #if ARRAYS_CHECKED
 // expected-warning@-2 {{array parameter is missing a nullability type 
specifier (_Nonnull, _Nullable, or _Null_unspecified)}}
@@ -33,6 +35,26 @@
 void * _Nullable ptrs[_Nonnull],
 void * _Nullable * _Nullable nestedPtrs[_Nonnull]);
 
+void testVAList(va_list ok); // no warning
+
+#if __cplusplus
+// Carefully construct a test case such that if a platform's va_list is an 
array
+// or pointer type, it gets tested, but otherwise it does not.
+template
+struct pointer_like_or { typedef F type; };
+template
+struct pointer_like_or { typedef T *type; };
+template
+struct pointer_like_or { typedef T * const type; };
+template
+struct pointer_like_or { typedef T type[]; };
+template
+struct pointer_like_or { typedef T type[size]; };
+
+void testVAListWithNullability(
+  pointer_like_or::type _Nonnull x); // no errors
+#endif
+
 void nestedArrays(int x[5][1]) {}
 #if ARRAYS_CHECKED
 // expected-warning@-2 {{array parameter is missing a nullability type 
specifier (_Nonnull, _Nullable, or _Null_unspecified)}}
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -3894,8 +3894,22 @@
 attr->setUsedAsTypeAttr();
   }
 }
+
+auto isVaList = [](QualType T) -> bool {
+  auto *typedefTy = T->getAs();
+  if (!typedefTy)
+return false;
+  TypedefDecl *vaListTypedef = S.Context.getBuiltinVaListDecl();
+  do {
+if (typedefTy->getDecl() == vaListTypedef)
+  return true;
+typedefTy = typedefTy->desugar()->getAs();
+  } while (typedefTy);
+  return false;
+};
+
 if (complainAboutMissingNullability == CAMN_Yes &&
-T->isArrayType() && !T->getNullability(S.Context) &&
+T->isArrayType() && !T->getNullability(S.Context) && !isVaList(T) &&
 D.isPrototypeContext() &&
 !hasOuterPointerLikeChunk(D, D.getNumTypeObjects())) {
   checkNullabilityConsistency(S, SimplePointerKind::Array,


Index: test/SemaObjCXX/Inputs/nullability-consistency-arrays.h
===
--- test/SemaObjCXX/Inputs/nullability-consistency-arrays.h
+++ test/SemaObjCXX/Inputs/nullability-consistency-arrays.h
@@ -1,3 +1,5 @@
+#include 
+
 void firstThingInTheFileThatNeedsNullabilityIsAnArray(int ints[]);
 #if ARRAYS_CHECKED
 // expected-warning@-2 {{array parameter is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified)}}
@@ -33,6 +35,26 @@
 void * _Nullable ptrs[_Nonnull],
 void * _Nullable * _Nullable nestedPtrs[_Nonnull]);
 
+void testVAList(va_list ok); // no warning
+
+#if __cplusplus
+// Carefully construct a test case such that if a platform's va_list is an array
+// or pointer type, it gets tested, but otherwise it does not.
+template
+struct pointer_like_or { typedef F type; };
+template
+struct pointer_like_or { typedef T *type; };
+template
+struct pointer_like_or { typedef T * const type; };
+template
+struct pointer_like_or { typedef T type[]; };
+template
+struct pointer_like_or { typedef T type[size]; };
+
+void testVAListWithNullability(
+  pointer_like_or::type _Nonnull x); // no errors
+#endif
+
 void nestedArrays(int x[5][1]) {}
 #if ARRAYS_CHECKED
 // expected-warning@-2 {{array parameter is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified)}}
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -3894,8 +3894,22 @@
 attr->setUsedAsTypeAttr();
   

[PATCH] D26226: Don't require nullability on template parameters in typedefs.

2016-11-01 Thread Jordan Rose via cfe-commits
jordan_rose created this revision.
jordan_rose added reviewers: doug.gregor, rsmith.
jordan_rose added a subscriber: cfe-commits.
jordan_rose set the repository for this revision to rL LLVM.

Previously the following code would warn on the use of `T`:

  template 
  struct X {
typedef T *type;
  };
  

...because nullability is //allowed// on template parameters (because they 
could be pointers). (Actually putting nullability on this use of `T` will of 
course break if the argument is a non-pointer type.)

This fix doesn't handle the case where a template parameter is used //outside// 
of a typedef. That seems trickier, especially in parameter position.


Repository:
  rL LLVM

https://reviews.llvm.org/D26226

Files:
  lib/Sema/SemaType.cpp
  test/SemaObjCXX/Inputs/nullability-consistency-1.h


Index: test/SemaObjCXX/Inputs/nullability-consistency-1.h
===
--- test/SemaObjCXX/Inputs/nullability-consistency-1.h
+++ test/SemaObjCXX/Inputs/nullability-consistency-1.h
@@ -13,5 +13,13 @@
   int X:: *memptr; // expected-warning{{member pointer is missing a 
nullability type specifier}}
 };
 
+template 
+struct Typedefs {
+  typedef T *Base; // no-warning
+  typedef Base *type; // expected-warning{{pointer is missing a nullability 
type specifier}}
+};
+
+Typedefs xx;
+Typedefs yy;
 
 
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -3662,7 +3662,15 @@
 // inner pointers.
 complainAboutMissingNullability = CAMN_InnerPointers;
 
-if (T->canHaveNullability() && !T->getNullability(S.Context)) {
+auto isDependentNonPointerType = [](QualType T) -> bool {
+  // FIXME: This just duplicates logic inside Type::canHaveNullability.
+  return T->isDependentType() && !T->isAnyPointerType() &&
+!T->isBlockPointerType() && !T->isMemberPointerType();
+};
+
+if (T->canHaveNullability() && !T->getNullability(S.Context) &&
+!isDependentNonPointerType(T)) {
+  // Note that we allow but don't require nullability on dependent types.
   ++NumPointersRemaining;
 }
 


Index: test/SemaObjCXX/Inputs/nullability-consistency-1.h
===
--- test/SemaObjCXX/Inputs/nullability-consistency-1.h
+++ test/SemaObjCXX/Inputs/nullability-consistency-1.h
@@ -13,5 +13,13 @@
   int X:: *memptr; // expected-warning{{member pointer is missing a nullability type specifier}}
 };
 
+template 
+struct Typedefs {
+  typedef T *Base; // no-warning
+  typedef Base *type; // expected-warning{{pointer is missing a nullability type specifier}}
+};
+
+Typedefs xx;
+Typedefs yy;
 
 
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -3662,7 +3662,15 @@
 // inner pointers.
 complainAboutMissingNullability = CAMN_InnerPointers;
 
-if (T->canHaveNullability() && !T->getNullability(S.Context)) {
+auto isDependentNonPointerType = [](QualType T) -> bool {
+  // FIXME: This just duplicates logic inside Type::canHaveNullability.
+  return T->isDependentType() && !T->isAnyPointerType() &&
+!T->isBlockPointerType() && !T->isMemberPointerType();
+};
+
+if (T->canHaveNullability() && !T->getNullability(S.Context) &&
+!isDependentNonPointerType(T)) {
+  // Note that we allow but don't require nullability on dependent types.
   ++NumPointersRemaining;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r285779 - More forcibly resolve exception specifications when checking a function

2016-11-01 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Tue Nov  1 19:47:52 2016
New Revision: 285779

URL: http://llvm.org/viewvc/llvm-project?rev=285779=rev
Log:
More forcibly resolve exception specifications when checking a function
redeclaration in C++1z mode. We need the exception specification in order for
the function's type to be complete.

Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaCXX/cxx1z-noexcept-function-type.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=285779=285778=285779=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Nov  1 19:47:52 2016
@@ -2949,6 +2949,15 @@ bool Sema::MergeFunctionDecl(FunctionDec
 // but do not necessarily update the type of New.
 if (CheckEquivalentExceptionSpec(Old, New))
   return true;
+// If exceptions are disabled, we might not have resolved the exception 
spec
+// of one or both declarations. Do so now in C++1z, so that we can properly
+// compare the types.
+if (getLangOpts().CPlusPlus1z) {
+  for (QualType T : {Old->getType(), New->getType()})
+if (auto *FPT = T->getAs())
+  if (isUnresolvedExceptionSpec(FPT->getExceptionSpecType()))
+ResolveExceptionSpec(New->getLocation(), FPT);
+}
 OldQType = Context.getCanonicalType(Old->getType());
 NewQType = Context.getCanonicalType(New->getType());
 

Modified: cfe/trunk/test/SemaCXX/cxx1z-noexcept-function-type.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx1z-noexcept-function-type.cpp?rev=285779=285778=285779=diff
==
--- cfe/trunk/test/SemaCXX/cxx1z-noexcept-function-type.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx1z-noexcept-function-type.cpp Tue Nov  1 19:47:52 
2016
@@ -89,3 +89,11 @@ namespace CompatWarning {
   template void h(...) = delete; // expected-note {{deleted}}
   void test_h() { h(nullptr); } // expected-error {{deleted}}
 }
+
+namespace ImplicitExceptionSpec {
+  struct S {
+~S();
+void f(const S  = S());
+  };
+  S::~S() {}
+}


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


[clang-tools-extra] r285778 - [Documentation] Clang-tidy readability-redundant-declaration consistency.

2016-11-01 Thread Eugene Zelenko via cfe-commits
Author: eugenezelenko
Date: Tue Nov  1 19:43:23 2016
New Revision: 285778

URL: http://llvm.org/viewvc/llvm-project?rev=285778=rev
Log:
[Documentation] Clang-tidy readability-redundant-declaration consistency.

Release notes checks order and consistent Clang-tidy 
readability-redundant-declaration description.

Modified:
clang-tools-extra/trunk/docs/ReleaseNotes.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/readability-redundant-declaration.rst

Modified: clang-tools-extra/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/ReleaseNotes.rst?rev=285778=285777=285778=diff
==
--- clang-tools-extra/trunk/docs/ReleaseNotes.rst (original)
+++ clang-tools-extra/trunk/docs/ReleaseNotes.rst Tue Nov  1 19:43:23 2016
@@ -123,17 +123,17 @@ Improvements to clang-tidy
   Flags function parameters of a pointer type that could be changed to point to
   a constant type instead.
 
+- New `readability-redundant-declaration
+  
`_
 check
+
+  Finds redundant variable and function declarations.
+
 - New `readability-redundant-member-init
   
`_
 check
 
   Flags member initializations that are unnecessary because the same default
   constructor would be called if they were not present.
 
-- New `readability-redundant-declaration
-  
`_
 check
-
-  Warns about duplicate variable declarations.
-
 Fixed bugs:
 
 - `modernize-make-unique

Modified: 
clang-tools-extra/trunk/docs/clang-tidy/checks/readability-redundant-declaration.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/readability-redundant-declaration.rst?rev=285778=285777=285778=diff
==
--- 
clang-tools-extra/trunk/docs/clang-tidy/checks/readability-redundant-declaration.rst
 (original)
+++ 
clang-tools-extra/trunk/docs/clang-tidy/checks/readability-redundant-declaration.rst
 Tue Nov  1 19:43:23 2016
@@ -21,7 +21,9 @@ They can for instance be unintentional l
 when code has been moved around. Having redundant declarations could in worst
 case mean that there are typos in the code that cause bugs.
 
-Normally the code can be automatically fixed, clang-tidy can remove the second
-declaration. However there are 2 cases when you need to fix the code manually:
- * When the declarations are in different header files.
- * When multiple variables are declared together.
+Normally the code can be automatically fixed, :program:`clang-tidy` can remove
+the second declaration. However there are 2 cases when you need to fix the code
+manually:
+
+* When the declarations are in different header files;
+* When multiple variables are declared together.


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


[PATCH] D26057: [coroutines] Add CoawaitDependentExpr AST node and use it to properly build await_transform.

2016-11-01 Thread Richard Smith via cfe-commits
rsmith added inline comments.



Comment at: include/clang/AST/ExprCXX.h:4256
+/// is dependent.
+class CoawaitDependentExpr : public Expr {
+  SourceLocation KeywordLoc;

Rename -> `DependentCoawaitExpr`, to match our other `Dependent*Expr` classes.



Comment at: include/clang/AST/ExprCXX.h:4259
+  Stmt *Operand;
+  UnresolvedSet<16> CoawaitOperatorCandidates;
+

Would it make sense to store this as an `UnresolvedLookupExpr*` instead?



Comment at: lib/AST/ExprClassification.cpp:191
   case Expr::DesignatedInitUpdateExprClass:
+  // FIXME How should we classify co_await expressions while they're still
+  // dependent?

EricWF wrote:
> @rsmith: What's the correct way to classify this type?
See above:
```
// Unresolved lookups and uncorrected typos get classified as lvalues.
// FIXME: Is this wise? Should they get their own kind?
```
It shouldn't ever matter what value category we give to a type-dependent 
expression.



Comment at: lib/Sema/TreeTransform.h:6707-6708
+  // context or if the promise type has changed.
+  return getDerived().RebuildCoawaitDependentExpr(
+  E->getKeywordLoc(), Result.get(), E->getOperatorCandidates());
+}

This should ideally call into the same function we use for the non-dependent 
case.


https://reviews.llvm.org/D26057



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


[PATCH] D26041: [clang-tidy] Extend misc-use-after-move to support unique_ptr and shared_ptr.

2016-11-01 Thread Martin Böhme via cfe-commits
mboehme marked 4 inline comments as done.
mboehme added a comment.

Please take another look.




Comment at: clang-tidy/misc/UseAfterMoveCheck.cpp:467
+StringRef getName(const NamedDecl *ND) {
+  if (!ND->getIdentifier())
+return StringRef();

aaron.ballman wrote:
> This logic could be improved as:
> ```
> if (const auto *ID = ND->getIdentifier())
>   return ID->getName();
> return "";
> ```
> However, I'm not certain that this function is needed at all -- it's pretty 
> simple and is only used from `isStandardSmartPointer()`.
> However, I'm not certain that this function is needed at all -- it's pretty 
> simple and is only used from isStandardSmartPointer().

Good point -- I've inlined it there.



Comment at: clang-tidy/misc/UseAfterMoveCheck.cpp:482
+  StringRef Name = getName(RecordDecl);
+  if (Name != "unique_ptr" && Name != "shared_ptr")
+return false;

aaron.ballman wrote:
> Shouldn't this improvement also include `weak_ptr`?
Good point -- done.


https://reviews.llvm.org/D26041



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


[PATCH] D26041: [clang-tidy] Extend misc-use-after-move to support unique_ptr and shared_ptr.

2016-11-01 Thread Martin Böhme via cfe-commits
mboehme updated this revision to Diff 76655.
mboehme added a comment.

- Responses to reviewer comments


https://reviews.llvm.org/D26041

Files:
  clang-tidy/misc/UseAfterMoveCheck.cpp
  docs/clang-tidy/checks/misc-use-after-move.rst
  test/clang-tidy/misc-use-after-move.cpp

Index: test/clang-tidy/misc-use-after-move.cpp
===
--- test/clang-tidy/misc-use-after-move.cpp
+++ test/clang-tidy/misc-use-after-move.cpp
@@ -9,12 +9,27 @@
 struct unique_ptr {
   unique_ptr();
   T *get() const;
+  explicit operator bool() const;
+  void reset(T *ptr);
+  T *() const;
+  T *operator->() const;
+  T& operator[](size_t i) const;
 };
 
 template 
 struct shared_ptr {
   shared_ptr();
   T *get() const;
+  explicit operator bool() const;
+  void reset(T *ptr);
+  T *() const;
+  T *operator->() const;
+};
+
+template 
+struct weak_ptr {
+  weak_ptr();
+  bool expired() const;
 };
 
 #define DECLARE_STANDARD_CONTAINER(name) \
@@ -146,20 +161,58 @@
   // CHECK-MESSAGES: [[@LINE-3]]:3: note: move occurred here
 }
 
-void uniquePtrAndSharedPtr() {
-  // Use-after-moves on std::unique_ptr<> or std::shared_ptr<> aren't flagged.
+void standardSmartPtr() {
+  // std::unique_ptr<>, std::shared_ptr<> and std::weak_ptr<> are guaranteed to
+  // be null after a std::move. So the check only flags accesses that would
+  // dereference the pointer.
   {
 std::unique_ptr ptr;
 std::move(ptr);
 ptr.get();
+static_cast(ptr);
+*ptr;
+// CHECK-MESSAGES: [[@LINE-1]]:6: warning: 'ptr' used after it was moved
+// CHECK-MESSAGES: [[@LINE-5]]:5: note: move occurred here
+  }
+  {
+std::unique_ptr ptr;
+std::move(ptr);
+ptr->foo();
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: 'ptr' used after it was moved
+// CHECK-MESSAGES: [[@LINE-3]]:5: note: move occurred here
+  }
+  {
+std::unique_ptr ptr;
+std::move(ptr);
+ptr[0];
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: 'ptr' used after it was moved
+// CHECK-MESSAGES: [[@LINE-3]]:5: note: move occurred here
   }
   {
 std::shared_ptr ptr;
 std::move(ptr);
 ptr.get();
+static_cast(ptr);
+*ptr;
+// CHECK-MESSAGES: [[@LINE-1]]:6: warning: 'ptr' used after it was moved
+// CHECK-MESSAGES: [[@LINE-5]]:5: note: move occurred here
+  }
+  {
+std::shared_ptr ptr;
+std::move(ptr);
+ptr->foo();
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: 'ptr' used after it was moved
+// CHECK-MESSAGES: [[@LINE-3]]:5: note: move occurred here
   }
-  // This is also true if the std::unique_ptr<> or std::shared_ptr<> is wrapped
-  // in a typedef.
+  {
+// std::weak_ptr<> cannot be dereferenced directly, so we only check that
+// member functions may be called on it after a move.
+std::weak_ptr ptr;
+std::move(ptr);
+ptr.expired();
+  }
+  // Make sure we recognize std::unique_ptr<> or std::shared_ptr<> if they're
+  // wrapped in a typedef.
   {
 typedef std::unique_ptr PtrToA;
 PtrToA ptr;
@@ -172,15 +225,27 @@
 std::move(ptr);
 ptr.get();
   }
-  // And it's also true if the template argument is a little more involved.
+  // And we don't get confused if the template argument is a little more
+  // involved.
   {
 struct B {
   typedef A AnotherNameForA;
 };
 std::unique_ptr ptr;
 std::move(ptr);
 ptr.get();
   }
+  // We don't give any special treatment to types that are called "unique_ptr"
+  // or "shared_ptr" but are not in the "::std" namespace.
+  {
+struct unique_ptr {
+  void get();
+} ptr;
+std::move(ptr);
+ptr.get();
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: 'ptr' used after it was moved
+// CHECK-MESSAGES: [[@LINE-3]]:5: note: move occurred here
+  }
 }
 
 // The check also works in member functions.
@@ -795,6 +860,24 @@
   }
 }
 
+// Resetting the standard smart pointer types using reset() is treated as a
+// re-initialization. (We don't test std::weak_ptr<> because it can't be
+// dereferenced directly.)
+void standardSmartPointerResetIsReinit() {
+  {
+std::unique_ptr ptr;
+std::move(ptr);
+ptr.reset(new A);
+*ptr;
+  }
+  {
+std::shared_ptr ptr;
+std::move(ptr);
+ptr.reset(new A);
+*ptr;
+  }
+}
+
 
 // Tests related to order of evaluation within expressions
 
Index: docs/clang-tidy/checks/misc-use-after-move.rst
===
--- docs/clang-tidy/checks/misc-use-after-move.rst
+++ docs/clang-tidy/checks/misc-use-after-move.rst
@@ -75,10 +75,6 @@
   std::cout << str;
 }
 
-No warnings are emitted for objects of type ``std::unique_ptr`` and
-``std::shared_ptr``, as they have defined move behavior. (Objects of these
-classes are guaranteed to be empty after they have been moved from.)
-
 Subsections below explain more precisely what exactly the check considers to be
 a move, 

[PATCH] D26189: Add a note that points to the linkage specifier for the "must have C++ linkage" errors

2016-11-01 Thread John McCall via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rL LLVM

https://reviews.llvm.org/D26189



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


[PATCH] D26206: Fix Clang-tidy readability-redundant-string-cstr warnings

2016-11-01 Thread Malcolm Parsons via cfe-commits
malcolm.parsons updated this revision to Diff 76642.
malcolm.parsons added a comment.

clang-format


https://reviews.llvm.org/D26206

Files:
  lib/ARCMigrate/FileRemapper.cpp
  lib/CodeGen/CGObjCGNU.cpp
  lib/CodeGen/TargetInfo.cpp
  lib/Driver/Driver.cpp
  lib/Driver/Job.cpp
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Frontend/Rewrite/RewriteModernObjC.cpp
  lib/Frontend/Rewrite/RewriteObjC.cpp
  lib/Parse/ParseDeclCXX.cpp
  lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp
  unittests/AST/ASTImporterTest.cpp

Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -71,8 +71,7 @@
 ToCtx.getSourceManager().getFileManager().getVirtualFileSystem().get());
   vfs::InMemoryFileSystem *MFS = static_cast(
 OFS->overlays_begin()->get());
-  MFS->addFile(InputFileName, 0,
-   llvm::MemoryBuffer::getMemBuffer(FromCode.c_str()));
+  MFS->addFile(InputFileName, 0, llvm::MemoryBuffer::getMemBuffer(FromCode));
 
   ASTImporter Importer(ToCtx, ToAST->getFileManager(),
FromCtx, FromAST->getFileManager(), false);
Index: lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp
===
--- lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp
+++ lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp
@@ -106,7 +106,7 @@
   SmallVector checkerOpts;
   for (unsigned i = 0, e = opts.CheckersControlList.size(); i != e; ++i) {
 const std::pair  = opts.CheckersControlList[i];
-checkerOpts.push_back(CheckerOptInfo(opt.first.c_str(), opt.second));
+checkerOpts.push_back(CheckerOptInfo(opt.first, opt.second));
   }
   return checkerOpts;
 }
Index: lib/Parse/ParseDeclCXX.cpp
===
--- lib/Parse/ParseDeclCXX.cpp
+++ lib/Parse/ParseDeclCXX.cpp
@@ -2234,7 +2234,7 @@
   if (!(Function.TypeQuals & TypeQual)) {
 std::string Name(FixItName);
 Name += " ";
-Insertion = FixItHint::CreateInsertion(VS.getFirstLocation(), Name.c_str());
+Insertion = FixItHint::CreateInsertion(VS.getFirstLocation(), Name);
 Function.TypeQuals |= TypeQual;
 *QualifierLoc = SpecLoc.getRawEncoding();
   }
Index: lib/Frontend/Rewrite/RewriteObjC.cpp
===
--- lib/Frontend/Rewrite/RewriteObjC.cpp
+++ lib/Frontend/Rewrite/RewriteObjC.cpp
@@ -4426,11 +4426,9 @@
   // Initialize the block descriptor.
   std::string DescData = "__" + FuncName + "_block_desc_" + BlockNumber + "_DATA";
 
-  VarDecl *NewVD = VarDecl::Create(*Context, TUDecl,
-   SourceLocation(), SourceLocation(),
-   >Idents.get(DescData.c_str()),
-   Context->VoidPtrTy, nullptr,
-   SC_Static);
+  VarDecl *NewVD = VarDecl::Create(
+  *Context, TUDecl, SourceLocation(), SourceLocation(),
+  >Idents.get(DescData), Context->VoidPtrTy, nullptr, SC_Static);
   UnaryOperator *DescRefExpr =
 new (Context) UnaryOperator(new (Context) DeclRefExpr(NewVD, false,
   Context->VoidPtrTy,
@@ -5650,14 +5648,12 @@
   InstanceMethods.push_back(Setter);
   }
   RewriteObjCMethodsMetaData(InstanceMethods.begin(), InstanceMethods.end(),
- true, "CATEGORY_", FullCategoryName.c_str(),
- Result);
-  
+ true, "CATEGORY_", FullCategoryName, Result);
+
   // Build _objc_method_list for class's class methods if needed
   RewriteObjCMethodsMetaData(IDecl->classmeth_begin(), IDecl->classmeth_end(),
- false, "CATEGORY_", FullCategoryName.c_str(),
- Result);
-  
+ false, "CATEGORY_", FullCategoryName, Result);
+
   // Protocols referenced in class declaration?
   // Null CDecl is case of a category implementation with no category interface
   if (CDecl)
@@ -5776,7 +5772,7 @@
   Result += "{\n\t0, " + utostr(NumMethods) + "\n";
   
   Result += "\t,{{(SEL)\"";
-  Result += (*MethodBegin)->getSelector().getAsString().c_str();
+  Result += (*MethodBegin)->getSelector().getAsString();
   std::string MethodTypeString;
   Context->getObjCEncodingForMethodDecl(*MethodBegin, MethodTypeString);
   Result += "\", \"";
@@ -5786,7 +5782,7 @@
   Result += "}\n";
   for (++MethodBegin; MethodBegin != MethodEnd; ++MethodBegin) {
 Result += "\t  ,{(SEL)\"";
-Result += (*MethodBegin)->getSelector().getAsString().c_str();
+Result += (*MethodBegin)->getSelector().getAsString();
 std::string MethodTypeString;
 Context->getObjCEncodingForMethodDecl(*MethodBegin, 

[PATCH] D25940: [analyzer] LibraryFunctions: Fix errors due to different integral types and typedefs on different architectures.

2016-11-01 Thread Artem Dergachev via cfe-commits
NoQ updated this revision to Diff 76641.
NoQ added a comment.

Try out a completely different approach which was also suggested by Anna.

Allow providing multiple variants of summaries for each function identifier, 
with different type specifications and branches. This way we preserve type 
checks and support overloads fairly well, however we introduce a bit of summary 
data duplication. This solves the `ssize_t` problem by providing multiple 
variants for every summary that uses it: one summary for the case when 
`ssize_t` is `int`, one for the case when it's `long`, one for the case when 
it's `long long`.


https://reviews.llvm.org/D25940

Files:
  lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  test/Analysis/std-c-library-functions.c

Index: test/Analysis/std-c-library-functions.c
===
--- test/Analysis/std-c-library-functions.c
+++ test/Analysis/std-c-library-functions.c
@@ -1,4 +1,8 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=unix.StdCLibraryFunctions,debug.ExprInspection -verify %s
+// RUN: %clang_cc1 -triple i686-unknown-linux -analyze -analyzer-checker=unix.StdCLibraryFunctions,debug.ExprInspection -verify %s
 // RUN: %clang_cc1 -triple x86_64-unknown-linux -analyze -analyzer-checker=unix.StdCLibraryFunctions,debug.ExprInspection -verify %s
+// RUN: %clang_cc1 -triple armv7-a15-linux -analyze -analyzer-checker=unix.StdCLibraryFunctions,debug.ExprInspection -verify %s
+// RUN: %clang_cc1 -triple thumbv7-a15-linux -analyze -analyzer-checker=unix.StdCLibraryFunctions,debug.ExprInspection -verify %s
 
 void clang_analyzer_eval(int);
 
@@ -23,7 +27,7 @@
 }
 
 
-typedef unsigned long size_t;
+typedef typeof(sizeof(int)) size_t;
 typedef signed long ssize_t;
 ssize_t read(int, void *, size_t);
 ssize_t write(int, const void *, size_t);
Index: lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -79,11 +79,15 @@
   /// impose a constraint that involves other argument or return value symbols.
   enum ValueRangeKindTy { OutOfRange, WithinRange, ComparesToArgument };
 
+  // The universal integral type to use in value range descriptions.
+  // Unsigned to make sure overflows are well-defined.
+  typedef uint64_t RangeIntTy;
+
   /// Normally, describes a single range constraint, eg. {{0, 1}, {3, 4}} is
   /// a non-negative integer, which less than 5 and not equal to 2. For
   /// `ComparesToArgument', holds information about how exactly to compare to
   /// the argument.
-  typedef std::vector> IntRangeVectorTy;
+  typedef std::vector> IntRangeVectorTy;
 
   /// A reference to an argument or return value by its number.
   /// ArgNo in CallExpr and CallEvent is defined as Unsigned, but
@@ -192,7 +196,8 @@
 
   // The map of all functions supported by the checker. It is initialized
   // lazily, and it doesn't change after initialization.
-  typedef llvm::StringMap FunctionSummaryMapTy;
+  typedef std::vector FunctionVariantsTy;
+  typedef llvm::StringMap FunctionSummaryMapTy;
   mutable FunctionSummaryMapTy FunctionSummaryMap;
 
   // Auxiliary functions to support ArgNoTy within all structures
@@ -442,11 +447,12 @@
   // Strict checking is important because we will be conducting
   // very integral-type-sensitive operations on arguments and
   // return values.
-  const FunctionSummaryTy  = FSMI->second;
-  if (!Spec.matchesCall(CE))
-return None;
+  const FunctionVariantsTy  = FSMI->second;
+  for (const FunctionSummaryTy  : SpecVariants)
+if (Spec.matchesCall(CE))
+  return Spec;
 
-  return Spec;
+  return None;
 }
 
 void StdLibraryFunctionsChecker::initFunctionSummaries(
@@ -460,15 +466,13 @@
   // New specifications should probably introduce more types.
   QualType Irrelevant; // A placeholder, whenever we do not care about the type.
   QualType IntTy = ACtx.IntTy;
+  QualType LongTy = ACtx.LongTy;
+  QualType LongLongTy = ACtx.LongLongTy;
   QualType SizeTy = ACtx.getSizeType();
-  QualType SSizeTy = ACtx.getIntTypeForBitwidth(ACtx.getTypeSize(SizeTy), true);
 
-  // Don't worry about truncation here, it'd be cast back to SIZE_MAX when used.
-  int64_t SizeMax =
-  BVF.getMaxValue(SizeTy).getLimitedValue();
-  int64_t SSizeMax =
-BVF.getMaxValue(SSizeTy).getLimitedValue();
-  (void)SizeMax;
+  RangeIntTy IntMax = BVF.getMaxValue(IntTy).getLimitedValue();
+  RangeIntTy LongMax = BVF.getMaxValue(LongTy).getLimitedValue();
+  RangeIntTy LongLongMax = BVF.getMaxValue(LongLongTy).getLimitedValue();
 
   // We are finally ready to define specifications for all supported functions.
   //
@@ -511,10 +515,15 @@
   //  }
   //}
 
+#define SUMMARY_WITH_VARIANTS(identifier) {#identifier, {
+#define END_SUMMARY_WITH_VARIANTS }},
+#define 

r285759 - [analyzer] Fix capitalization in ObjCSuperDealloc checker diagnostic.

2016-11-01 Thread Devin Coughlin via cfe-commits
Author: dcoughlin
Date: Tue Nov  1 17:16:39 2016
New Revision: 285759

URL: http://llvm.org/viewvc/llvm-project?rev=285759=rev
Log:
[analyzer] Fix capitalization in ObjCSuperDealloc checker diagnostic.

Change "use of 'self'..." to "Use of 'self'...". The convention is to
start diagnostics with a capital letter.

rdar://problem/28322494

Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/ObjCSuperDeallocChecker.cpp
cfe/trunk/test/Analysis/DeallocUseAfterFreeErrors.m

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/ObjCSuperDeallocChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/ObjCSuperDeallocChecker.cpp?rev=285759=285758=285759=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/ObjCSuperDeallocChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/ObjCSuperDeallocChecker.cpp Tue Nov  
1 17:16:39 2016
@@ -191,7 +191,7 @@ void ObjCSuperDeallocChecker::reportUseA
 return;
 
   if (Desc.empty())
-Desc = "use of 'self' after it has been deallocated";
+Desc = "Use of 'self' after it has been deallocated";
 
   // Generate the report.
   std::unique_ptr BR(

Modified: cfe/trunk/test/Analysis/DeallocUseAfterFreeErrors.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/DeallocUseAfterFreeErrors.m?rev=285759=285758=285759=diff
==
--- cfe/trunk/test/Analysis/DeallocUseAfterFreeErrors.m (original)
+++ cfe/trunk/test/Analysis/DeallocUseAfterFreeErrors.m Tue Nov  1 17:16:39 2016
@@ -125,8 +125,8 @@ struct SomeStruct {
 }
 - (void)dealloc {
   [super dealloc]; // expected-note {{[super dealloc] called here}}
-  self.ivar = nil; // expected-warning {{use of 'self' after it has been 
deallocated}}
-  // expected-note@-1 {{use of 'self' after it has been deallocated}}
+  self.ivar = nil; // expected-warning {{Use of 'self' after it has been 
deallocated}}
+  // expected-note@-1 {{Use of 'self' after it has been deallocated}}
 }
 @end
 
@@ -144,8 +144,8 @@ struct SomeStruct {
 }
 - (void)dealloc {
   [super dealloc]; // expected-note {{[super dealloc] called here}}
-  self.delegate = nil; // expected-warning {{use of 'self' after it has been 
deallocated}}
-  // expected-note@-1 {{use of 'self' after it has been deallocated}}
+  self.delegate = nil; // expected-warning {{Use of 'self' after it has been 
deallocated}}
+  // expected-note@-1 {{Use of 'self' after it has been deallocated}}
 }
 @end
 
@@ -158,8 +158,8 @@ struct SomeStruct {
 }
 - (void)dealloc {
   [super dealloc]; // expected-note {{[super dealloc] called here}}
-  [self _invalidate]; // expected-warning {{use of 'self' after it has been 
deallocated}}
-  // expected-note@-1 {{use of 'self' after it has been deallocated}}
+  [self _invalidate]; // expected-warning {{Use of 'self' after it has been 
deallocated}}
+  // expected-note@-1 {{Use of 'self' after it has been deallocated}}
 }
 @end
 
@@ -173,8 +173,8 @@ static void _invalidate(NSObject *object
 @implementation SuperDeallocThenCallNonObjectiveCMethodClass
 - (void)dealloc {
   [super dealloc]; // expected-note {{[super dealloc] called here}}
-  _invalidate(self); // expected-warning {{use of 'self' after it has been 
deallocated}}
-  // expected-note@-1 {{use of 'self' after it has been deallocated}}
+  _invalidate(self); // expected-warning {{Use of 'self' after it has been 
deallocated}}
+  // expected-note@-1 {{Use of 'self' after it has been deallocated}}
 }
 @end
 
@@ -187,8 +187,8 @@ static void _invalidate(NSObject *object
 
 - (void)dealloc {
   [super dealloc]; // expected-note {{[super dealloc] called here}}
-  [SuperDeallocThenCallObjectiveClassMethodClass invalidate:self]; // 
expected-warning {{use of 'self' after it has been deallocated}}
-  // expected-note@-1 {{use of 'self' after it has been deallocated}}
+  [SuperDeallocThenCallObjectiveClassMethodClass invalidate:self]; // 
expected-warning {{Use of 'self' after it has been deallocated}}
+  // expected-note@-1 {{Use of 'self' after it has been deallocated}}
 }
 @end
 
@@ -208,8 +208,8 @@ static void _invalidate(NSObject *object
 return;
   }
   [super dealloc];// expected-note {{[super dealloc] called here}}
-  [self _invalidate]; // expected-warning {{use of 'self' after it has been 
deallocated}}
-  // expected-note@-1 {{use of 'self' after it has been deallocated}}
+  [self _invalidate]; // expected-warning {{Use of 'self' after it has been 
deallocated}}
+  // expected-note@-1 {{Use of 'self' after it has been deallocated}}
 }
 @end
 
@@ -366,8 +366,8 @@ static void _invalidate(NSObject *object
 
 - (void)dealloc; {
   [super dealloc]; // expected-note {{[super dealloc] called here}}
-  [self anotherMethod]; // expected-warning {{use of 'self' after it has been 
deallocated}}
-  // expected-note@-1 {{use of 'self' after it has been 

[PATCH] D12839: Extend MoveConstructorInitCheck to also flag constructor arguments passed by value and can be moved assigned to fields.

2016-11-01 Thread Aaron Ballman via cfe-commits
aaron.ballman added a comment.

In https://reviews.llvm.org/D12839#582828, @malcolm.parsons wrote:

> The modernize-pass-by-value check does the same thing:
>
>   test/clang-tidy/misc-move-constructor-init.cpp:98:12: warning: pass by 
> value and use std::move [modernize-pass-by-value]
> Positive(Movable M) : M_(M) {}
>  ^
>  std::move( )
>   test/clang-tidy/misc-move-constructor-init.cpp:98:28: warning: value 
> argument 'M' can be moved to avoid copy [misc-move-constructor-init]
> Positive(Movable M) : M_(M) {}
>  ^
>
>
> Do we need two checks for this?


This overlap is unfortunate. misc-move-constructor-init is for move constructor 
initializer lists which accidentally initialize a member or base through a copy 
constructor rather than a move constructor. Consider:

  struct B { B(B&&); B(const B&); };
  struct D {
D(D &) : B(d) {} // Oops, calling B(const B&) not B(B&&)
D(const D ) : B(d) {}

modernize-pass-by-value is slightly different in that it is concerned with the 
parameter of an arbitrary function being something that is movable if you pass 
it by value instead of passing it by reference.

So misc-move-constructor-init cares about move constructor initializer lists 
while modernize-pass-by-value cares about the parameters of a function.


https://reviews.llvm.org/D12839



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


[PATCH] D19170: [safestack] Link SafeStack runtime only when not using separate stack segment

2016-11-01 Thread Michael LeMay via cfe-commits
mlemay-intel updated this revision to Diff 76636.
mlemay-intel added a comment.

Disabled linking of the compiler-rt SafeStack runtime library for musl
environments rather than for targets that use the separate stack segment
feature.  This reflects changes in my proposed musl libc patches to add
architecture-independent support for storing USP in the TCB.


https://reviews.llvm.org/D19170

Files:
  lib/Driver/Tools.cpp
  test/Driver/sanitizer-ld.c


Index: test/Driver/sanitizer-ld.c
===
--- test/Driver/sanitizer-ld.c
+++ test/Driver/sanitizer-ld.c
@@ -406,6 +406,22 @@
 // CHECK-SAFESTACK-LINUX: "-lpthread"
 // CHECK-SAFESTACK-LINUX: "-ldl"
 
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: -target i386-unknown-linux-musl -fsanitize=safe-stack \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-SAFESTACK-MUSL32 %s
+//
+// CHECK-SAFESTACK-MUSL32: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-SAFESTACK-MUSL32-NOT: libclang_rt.safestack-i386.a"
+
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: -target x86_64-unknown-linux-musl -fsanitize=safe-stack \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-SAFESTACK-MUSL64 %s
+//
+// CHECK-SAFESTACK-MUSL64: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-SAFESTACK-MUSL64-NOT: libclang_rt.safestack-x86_64.a"
+
 // RUN: %clang -fsanitize=cfi -fsanitize-stats %s -### -o %t.o 2>&1 \
 // RUN: -target x86_64-unknown-linux \
 // RUN: --sysroot=%S/Inputs/basic_linux_tree \
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -3254,7 +3254,7 @@
 if (SanArgs.linkCXXRuntimes())
   StaticRuntimes.push_back("ubsan_standalone_cxx");
   }
-  if (SanArgs.needsSafeStackRt())
+  if (SanArgs.needsSafeStackRt() && !TC.getTriple().isMusl())
 StaticRuntimes.push_back("safestack");
   if (SanArgs.needsCfiRt())
 StaticRuntimes.push_back("cfi");


Index: test/Driver/sanitizer-ld.c
===
--- test/Driver/sanitizer-ld.c
+++ test/Driver/sanitizer-ld.c
@@ -406,6 +406,22 @@
 // CHECK-SAFESTACK-LINUX: "-lpthread"
 // CHECK-SAFESTACK-LINUX: "-ldl"
 
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: -target i386-unknown-linux-musl -fsanitize=safe-stack \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-SAFESTACK-MUSL32 %s
+//
+// CHECK-SAFESTACK-MUSL32: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-SAFESTACK-MUSL32-NOT: libclang_rt.safestack-i386.a"
+
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: -target x86_64-unknown-linux-musl -fsanitize=safe-stack \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-SAFESTACK-MUSL64 %s
+//
+// CHECK-SAFESTACK-MUSL64: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-SAFESTACK-MUSL64-NOT: libclang_rt.safestack-x86_64.a"
+
 // RUN: %clang -fsanitize=cfi -fsanitize-stats %s -### -o %t.o 2>&1 \
 // RUN: -target x86_64-unknown-linux \
 // RUN: --sysroot=%S/Inputs/basic_linux_tree \
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -3254,7 +3254,7 @@
 if (SanArgs.linkCXXRuntimes())
   StaticRuntimes.push_back("ubsan_standalone_cxx");
   }
-  if (SanArgs.needsSafeStackRt())
+  if (SanArgs.needsSafeStackRt() && !TC.getTriple().isMusl())
 StaticRuntimes.push_back("safestack");
   if (SanArgs.needsCfiRt())
 StaticRuntimes.push_back("cfi");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r285752 - [clang-tidy] Handle bitfields in cppcoreguidelines-pro-type-member-init

2016-11-01 Thread Malcolm Parsons via cfe-commits
Author: malcolm.parsons
Date: Tue Nov  1 16:26:53 2016
New Revision: 285752

URL: http://llvm.org/viewvc/llvm-project?rev=285752=rev
Log:
[clang-tidy] Handle bitfields in cppcoreguidelines-pro-type-member-init

Summary:
Unnamed bitfields cannot be initialized.
Bitfields cannot be in-class initialized.

Reviewers: alexfh, hokein, aaron.ballman

Subscribers: Prazek, nemanjai, cfe-commits

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

Modified:

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

clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp?rev=285752=285751=285752=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp 
(original)
+++ 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp 
Tue Nov  1 16:26:53 2016
@@ -358,7 +358,7 @@ void ProTypeMemberInitCheck::checkMissin
 if (!F->hasInClassInitializer() &&
 utils::type_traits::isTriviallyDefaultConstructible(F->getType(),
 Context) &&
-!isEmpty(Context, F->getType()))
+!isEmpty(Context, F->getType()) && !F->isUnnamedBitfield())
   FieldsToInit.insert(F);
   });
   if (FieldsToInit.empty())
@@ -407,7 +407,9 @@ void ProTypeMemberInitCheck::checkMissin
   SmallPtrSet FieldsToFix;
   forEachField(ClassDecl, FieldsToInit, true, [&](const FieldDecl *F) {
 // Don't suggest fixes for enums because we don't know a good default.
-if (!F->getType()->isEnumeralType())
+// Don't suggest fixes for bitfields because in-class initialization is not
+// possible.
+if (!F->getType()->isEnumeralType() && !F->isBitField())
   FieldsToFix.insert(F);
   });
   if (FieldsToFix.empty())

Modified: 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp?rev=285752=285751=285752=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
 (original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
 Tue Nov  1 16:26:53 2016
@@ -456,3 +456,20 @@ template  class NoCrash {
 template  B(U u) {}
   };
 };
+
+struct PositiveBitfieldMember {
+  PositiveBitfieldMember() {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize 
these fields: F
+  unsigned F : 5;
+};
+
+struct NegativeUnnamedBitfieldMember {
+  NegativeUnnamedBitfieldMember() {}
+  unsigned : 5;
+};
+
+struct NegativeInitializedBitfieldMembers {
+  NegativeInitializedBitfieldMembers() : F(3) { G = 2; }
+  unsigned F : 5;
+  unsigned G : 5;
+};


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


[PATCH] D26195: Ignore incomplete types when determining whether they are expensive to copy

2016-11-01 Thread Felix Berger via cfe-commits
flx added a comment.

In https://reviews.llvm.org/D26195#585091, @aaron.ballman wrote:

> In https://reviews.llvm.org/D26195#584958, @flx wrote:
>
> > In https://reviews.llvm.org/D26195#584730, @aaron.ballman wrote:
> >
> > > In https://reviews.llvm.org/D26195#584724, @flx wrote:
> > >
> > > > In https://reviews.llvm.org/D26195#584712, @aaron.ballman wrote:
> > > >
> > > > > Please add a test case with an incomplete type that would exercise 
> > > > > this code path, otherwise, LGTM.
> > > >
> > > >
> > > > Hi Aaron,
> > > >
> > > > do you have any advise on how to add an incomplete type? When debugging 
> > > > this I had a compilation unit that failed to compile causing it, but 
> > > > I'm not sure this is a good way to add a test case.
> > >
> > >
> > > A type like `class C;` is an incomplete type, as is `void`, so perhaps 
> > > you can find a check that would let such a construct call through to 
> > > `isExpensiveToCopy()`.
> >
> >
> > Great, this works and I was able to see the check produce a false positive 
> > without the proposed change here, but the test code introduces a compile 
> > error now due to the incomplete type used in the function definition. Is 
> > there a way to suppress that?
>
>
> Unlikely -- fixing the compile error likely makes the type not expensive to 
> copy by using a pointer (or reference). This may be tricky to test because 
> the times when you would call `isExpensiveToCopy()` is with types that are 
> going to be logically required to be complete. I am not certain the compile 
> error is actually a problem though -- I would imagine your existing 
> false-positives (that you mentioned in the patch summary) are cases where 
> there is a compile error *and* a clang-tidy diagnostic, so the test may 
> simply be "check that there's only a compile error and no clang-tidy 
> diagnostic where there used to be a false-positive one."


That's exactly the case, my question here is how can I make the test succeed in 
the face of a compile error, i.e. by expecting the error as well?


Repository:
  rL LLVM

https://reviews.llvm.org/D26195



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


[PATCH] D26207: [ClangTidy - performance-unnecessary-value-param] Only add "const" when current parameter is not already const qualified

2016-11-01 Thread Felix Berger via cfe-commits
flx added inline comments.



Comment at: test/clang-tidy/performance-unnecessary-value-param.cpp:242
+// Case where parameter in declaration is already const-qualified but not in
+// implementation. Make sure a second 'const' is not added to the declaration.
+void PositiveConstDeclaration(const ExpensiveToCopyType A);

aaron.ballman wrote:
> This comment doesn't really match the test cases. The original code has two 
> *different* declarations (only one of which is a definition), not one 
> declaration and one redeclaration with the definition.
> 
> I think what is really happening is that it is adding the `&` qualifier to 
> the first declaration, and adding the `const` and `&` qualifiers to the 
> second declaration, and the result is that you get harmonization. But it 
> brings up a question to me; what happens with:
> ```
> void f1(ExpensiveToCopyType A) {
> }
> 
> void f1(const ExpensiveToCopyType A) {
> 
> }
> ```
> Does the fix-it try to create two definitions of the same function?
Good catch. I added the reverse case as well and modified the check slightly to 
make that case work as well.



Comment at: test/clang-tidy/performance-unnecessary-value-param.cpp:244
+void PositiveConstDeclaration(const ExpensiveToCopyType A);
+// CHECK-FIXES: void PositiveConstDeclaration(const ExpensiveToCopyType& A);
+void PositiveConstDeclaration(ExpensiveToCopyType A) {

aaron.ballman wrote:
> Is the `CHECK-MESSAGES` missing?
The message is only generated on the definition below, the declaration will 
only have a fix.


Repository:
  rL LLVM

https://reviews.llvm.org/D26207



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


[PATCH] D25660: [Analyzer] Checker for iterators dereferenced beyond their range.

2016-11-01 Thread Artem Dergachev via cfe-commits
NoQ added inline comments.



Comment at: lib/StaticAnalyzer/Checkers/IteratorPastEndChecker.cpp:580
+  C.addTransition(stateFound);
+  C.addTransition(stateNotFound);
+}

NoQ wrote:
> Ouch, i have one more concern, which can be expressed with the following 
> false-positive test which currently fails:
> 
> ```
> void foo() {
>   std::vector vec;
>   vec.push_back(2016);
>   auto i = vec.find(vec.begin(), vec.end(), 2016);
>   *i; // no-warning
> }
> ```
> 
> Not instantly sure what to do with this. You can avoid state splits until you 
> are actually sure if both branches are possible, but that'd suppress a lot of 
> useful positives. Such positives could be suppressed with assertions, of 
> course, but i'd still hope there aren't too many of those.
I mean, `std::find(...` ><


https://reviews.llvm.org/D25660



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


[PATCH] D26207: [ClangTidy - performance-unnecessary-value-param] Only add "const" when current parameter is not already const qualified

2016-11-01 Thread Felix Berger via cfe-commits
flx updated this revision to Diff 76630.

Repository:
  rL LLVM

https://reviews.llvm.org/D26207

Files:
  clang-tidy/performance/UnnecessaryValueParamCheck.cpp
  test/clang-tidy/performance-unnecessary-value-param.cpp


Index: test/clang-tidy/performance-unnecessary-value-param.cpp
===
--- test/clang-tidy/performance-unnecessary-value-param.cpp
+++ test/clang-tidy/performance-unnecessary-value-param.cpp
@@ -237,3 +237,19 @@
   ExpensiveToCopyType B;
   B = A;
 }
+
+// Case where parameter in declaration is already const-qualified but not in
+// implementation. Make sure a second 'const' is not added to the declaration.
+void PositiveConstDeclaration(const ExpensiveToCopyType A);
+// CHECK-FIXES: void PositiveConstDeclaration(const ExpensiveToCopyType& A);
+void PositiveConstDeclaration(ExpensiveToCopyType A) {
+  // CHECK-MESSAGES: [[@LINE-1]]:51: warning: the parameter 'A' is copied
+  // CHECK-FIXES: void PositiveConstDeclaration(const ExpensiveToCopyType& A) {
+}
+
+void PositiveNonConstDeclaration(ExpensiveToCopyType A);
+// CHECK-FIXES: void PositiveNonConstDeclaration(const ExpensiveToCopyType& A);
+void PositiveNonConstDeclaration(const ExpensiveToCopyType A) {
+  // CHECK-MESSAGES: [[@LINE-1]]:60: warning: the const qualified parameter 'A'
+  // CHECK-FIXES: void PositiveNonConstDeclaration(const ExpensiveToCopyType& 
A) {
+}
Index: clang-tidy/performance/UnnecessaryValueParamCheck.cpp
===
--- clang-tidy/performance/UnnecessaryValueParamCheck.cpp
+++ clang-tidy/performance/UnnecessaryValueParamCheck.cpp
@@ -128,7 +128,7 @@
 const auto  = *FunctionDecl->getParamDecl(Index);
 Diag << utils::fixit::changeVarDeclToReference(CurrentParam,
*Result.Context);
-if (!IsConstQualified)
+if (!CurrentParam.getType().getCanonicalType().isConstQualified())
   Diag << utils::fixit::changeVarDeclToConst(CurrentParam);
   }
 }


Index: test/clang-tidy/performance-unnecessary-value-param.cpp
===
--- test/clang-tidy/performance-unnecessary-value-param.cpp
+++ test/clang-tidy/performance-unnecessary-value-param.cpp
@@ -237,3 +237,19 @@
   ExpensiveToCopyType B;
   B = A;
 }
+
+// Case where parameter in declaration is already const-qualified but not in
+// implementation. Make sure a second 'const' is not added to the declaration.
+void PositiveConstDeclaration(const ExpensiveToCopyType A);
+// CHECK-FIXES: void PositiveConstDeclaration(const ExpensiveToCopyType& A);
+void PositiveConstDeclaration(ExpensiveToCopyType A) {
+  // CHECK-MESSAGES: [[@LINE-1]]:51: warning: the parameter 'A' is copied
+  // CHECK-FIXES: void PositiveConstDeclaration(const ExpensiveToCopyType& A) {
+}
+
+void PositiveNonConstDeclaration(ExpensiveToCopyType A);
+// CHECK-FIXES: void PositiveNonConstDeclaration(const ExpensiveToCopyType& A);
+void PositiveNonConstDeclaration(const ExpensiveToCopyType A) {
+  // CHECK-MESSAGES: [[@LINE-1]]:60: warning: the const qualified parameter 'A'
+  // CHECK-FIXES: void PositiveNonConstDeclaration(const ExpensiveToCopyType& A) {
+}
Index: clang-tidy/performance/UnnecessaryValueParamCheck.cpp
===
--- clang-tidy/performance/UnnecessaryValueParamCheck.cpp
+++ clang-tidy/performance/UnnecessaryValueParamCheck.cpp
@@ -128,7 +128,7 @@
 const auto  = *FunctionDecl->getParamDecl(Index);
 Diag << utils::fixit::changeVarDeclToReference(CurrentParam,
*Result.Context);
-if (!IsConstQualified)
+if (!CurrentParam.getType().getCanonicalType().isConstQualified())
   Diag << utils::fixit::changeVarDeclToConst(CurrentParam);
   }
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25660: [Analyzer] Checker for iterators dereferenced beyond their range.

2016-11-01 Thread Artem Dergachev via cfe-commits
NoQ added inline comments.



Comment at: lib/StaticAnalyzer/Checkers/IteratorPastEndChecker.cpp:580
+  C.addTransition(stateFound);
+  C.addTransition(stateNotFound);
+}

Ouch, i have one more concern, which can be expressed with the following 
false-positive test which currently fails:

```
void foo() {
  std::vector vec;
  vec.push_back(2016);
  auto i = vec.find(vec.begin(), vec.end(), 2016);
  *i; // no-warning
}
```

Not instantly sure what to do with this. You can avoid state splits until you 
are actually sure if both branches are possible, but that'd suppress a lot of 
useful positives. Such positives could be suppressed with assertions, of 
course, but i'd still hope there aren't too many of those.


https://reviews.llvm.org/D25660



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


[PATCH] D26118: [clang-tidy] Change readability-redundant-member-init to get base type from constructor

2016-11-01 Thread Malcolm Parsons via cfe-commits
malcolm.parsons added inline comments.



Comment at: clang-tidy/readability/RedundantMemberInitCheck.cpp:57
"initializer for base class %0 is redundant")
-  << Init->getTypeSourceInfo()->getType()
+  << Construct->getType()
   << FixItHint::CreateRemoval(Init->getSourceRange());

aaron.ballman wrote:
> Why is it more correct to use the CXXConstructExpr type information rather 
> than the CXXCtorInitializer?
Something to do with templates and namespaces.

In the bug report, `CXXCtorInitializer` had type `std::__1::bitset<128>` and 
`CXXConstructExpr` had type `std::bitset`.

I don't know why.


Repository:
  rL LLVM

https://reviews.llvm.org/D26118



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


[PATCH] D24869: [cfe] [test] Fix detecting LLVM zlib support in stand-alone builds

2016-11-01 Thread Michał Górny via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL285741: [test] Fix detecting LLVM zlib support in 
stand-alone builds (authored by mgorny).

Changed prior to commit:
  https://reviews.llvm.org/D24869?vs=72258=76625#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D24869

Files:
  cfe/trunk/test/CMakeLists.txt


Index: cfe/trunk/test/CMakeLists.txt
===
--- cfe/trunk/test/CMakeLists.txt
+++ cfe/trunk/test/CMakeLists.txt
@@ -9,6 +9,15 @@
 
 string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} CLANG_TOOLS_DIR 
${LLVM_RUNTIME_OUTPUT_INTDIR})
 
+if(CLANG_BUILT_STANDALONE)
+  # Set HAVE_LIBZ according to recorded LLVM_ENABLE_ZLIB value. This
+  # value is forced to 0 if zlib was not found, so it is fine to use it
+  # instead of HAVE_LIBZ (not recorded).
+  if(LLVM_ENABLE_ZLIB)
+set(HAVE_LIBZ 1)
+  endif()
+endif()
+
 configure_lit_site_cfg(
   ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
   ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg


Index: cfe/trunk/test/CMakeLists.txt
===
--- cfe/trunk/test/CMakeLists.txt
+++ cfe/trunk/test/CMakeLists.txt
@@ -9,6 +9,15 @@
 
 string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} CLANG_TOOLS_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR})
 
+if(CLANG_BUILT_STANDALONE)
+  # Set HAVE_LIBZ according to recorded LLVM_ENABLE_ZLIB value. This
+  # value is forced to 0 if zlib was not found, so it is fine to use it
+  # instead of HAVE_LIBZ (not recorded).
+  if(LLVM_ENABLE_ZLIB)
+set(HAVE_LIBZ 1)
+  endif()
+endif()
+
 configure_lit_site_cfg(
   ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
   ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r285741 - [test] Fix detecting LLVM zlib support in stand-alone builds

2016-11-01 Thread Michal Gorny via cfe-commits
Author: mgorny
Date: Tue Nov  1 15:31:52 2016
New Revision: 285741

URL: http://llvm.org/viewvc/llvm-project?rev=285741=rev
Log:
[test] Fix detecting LLVM zlib support in stand-alone builds

Fix the test run to declare missing HAVE_LIBZ value in stand-alone
builds, using the LLVM_ENABLE_ZLIB that is exported in LLVMConfig.cmake.

When using in-tree builds, HAVE_LIBZ is declared in
cmake/config-ix.cmake as a result of LLVM's CMake checks. When building
stand-alone, this value is not available and as a result caused clang to
wrongly assume that LLVM was built without zlib support.

To fix it, set it to the value of LLVM_ENABLE_ZLIB. While this variable
is originally used to control the user preference, LLVM updates its
value to 0 if zlib checks fail. Therefore, we can use it to reliably
determine whether LLVM was built with zlib support or not.

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

Modified:
cfe/trunk/test/CMakeLists.txt

Modified: cfe/trunk/test/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CMakeLists.txt?rev=285741=285740=285741=diff
==
--- cfe/trunk/test/CMakeLists.txt (original)
+++ cfe/trunk/test/CMakeLists.txt Tue Nov  1 15:31:52 2016
@@ -9,6 +9,15 @@ endif ()
 
 string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} CLANG_TOOLS_DIR 
${LLVM_RUNTIME_OUTPUT_INTDIR})
 
+if(CLANG_BUILT_STANDALONE)
+  # Set HAVE_LIBZ according to recorded LLVM_ENABLE_ZLIB value. This
+  # value is forced to 0 if zlib was not found, so it is fine to use it
+  # instead of HAVE_LIBZ (not recorded).
+  if(LLVM_ENABLE_ZLIB)
+set(HAVE_LIBZ 1)
+  endif()
+endif()
+
 configure_lit_site_cfg(
   ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
   ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg


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


[PATCH] D25659: [clang-tidy] Avoid running aliased checks twice

2016-11-01 Thread Malcolm Parsons via cfe-commits
malcolm.parsons added a comment.

In https://reviews.llvm.org/D25659#584986, @aaron.ballman wrote:

> (1) I think that the aliases and the originals should be listed with 
> -list-checks, because these are names under which the checks may be run (and 
> sometimes the name may even imply different semantics for the check).


I've always found it odd that -list-checks only lists the enabled checks.
I think a list of enabled checks shouldn't report aliases that will not be used.

> (2) I'm not as certain about -dump-config, since I am not really familiar 
> with that option, but I think we want to list the alias and the original 
> under that as well because different check names may have different 
> configuration options.

It was because of -dump-config that I noticed the checks were running twice.
I had to configure a check in two places to be sure it was configured how I 
wanted.
I don't think there is a use case for running the same check with different 
options at the same time.
Dumping options that won't be used isn't good either.

I'd like to remove cert-oop11-cpp's UseCERTSemantics option - see my comment on 
https://reviews.llvm.org/D12839.

An alternative to clang-tidy preferring the original check would be to complain 
if both are enabled.


https://reviews.llvm.org/D25659



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


[PATCH] D24933: Enable configuration files in clang

2016-11-01 Thread Hans Wennborg via cfe-commits
hans added a comment.

I didn't follow the original thread too closely as I didn't really see the 
problem this was trying to address, but since I'm now cc'd I'll add my opinion.

I'm not in favour of this functionality. (But I guess I might be missing the 
main use case.)

The way I see it, what flags to pass to the compiler should be configured in a 
project's build system. If a project wants to disable some warnings by default, 
add it to the Makefile (or equivalent). I don't see the point in checking in 
another file next to it.

The idea of having the compiler search for config files in random places on the 
filesystem seems scary to me. If I want to override a project's compile flags, 
I'd like to pass them in when configuring the build. If I don't pass any flags, 
I want Clang to work the same everywhere.

Bundling up compiler flags in a file can be convenient, but we already have 
`@file` for that.

There is already a lot of magic in the driver to figure out how to invoke the 
tools. I fear that this would make things even more complicated.


https://reviews.llvm.org/D24933



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


[PATCH] D24869: [cfe] [test] Fix detecting LLVM zlib support in stand-alone builds

2016-11-01 Thread Chris Bieneman via cfe-commits
beanz accepted this revision.
beanz added a comment.
This revision is now accepted and ready to land.

LGTM!


https://reviews.llvm.org/D24869



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


r285733 - clang/test/CodeGenOpenCL/convergent.cl: Satisfy -Asserts with "opt -instnamer".

2016-11-01 Thread NAKAMURA Takumi via cfe-commits
Author: chapuni
Date: Tue Nov  1 15:08:17 2016
New Revision: 285733

URL: http://llvm.org/viewvc/llvm-project?rev=285733=rev
Log:
clang/test/CodeGenOpenCL/convergent.cl: Satisfy -Asserts with "opt -instnamer".

Modified:
cfe/trunk/test/CodeGenOpenCL/convergent.cl

Modified: cfe/trunk/test/CodeGenOpenCL/convergent.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/convergent.cl?rev=285733=285732=285733=diff
==
--- cfe/trunk/test/CodeGenOpenCL/convergent.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/convergent.cl Tue Nov  1 15:08:17 2016
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple spir-unknown-unknown -emit-llvm %s -o - | FileCheck 
%s
+// RUN: %clang_cc1 -triple spir-unknown-unknown -emit-llvm %s -o - | opt 
-instnamer -S | FileCheck %s
 
 void convfun(void) __attribute__((convergent));
 void non_convfun(void);


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


[clang-tools-extra] r285731 - [clang-query] Fix Clang-tidy readability-redundant-string-cstr warnings

2016-11-01 Thread Malcolm Parsons via cfe-commits
Author: malcolm.parsons
Date: Tue Nov  1 15:07:05 2016
New Revision: 285731

URL: http://llvm.org/viewvc/llvm-project?rev=285731=rev
Log:
[clang-query] Fix Clang-tidy readability-redundant-string-cstr warnings

Reviewers: pcc, dblaikie

Subscribers: cfe-commits

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

Modified:
clang-tools-extra/trunk/clang-query/tool/ClangQuery.cpp

Modified: clang-tools-extra/trunk/clang-query/tool/ClangQuery.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-query/tool/ClangQuery.cpp?rev=285731=285730=285731=diff
==
--- clang-tools-extra/trunk/clang-query/tool/ClangQuery.cpp (original)
+++ clang-tools-extra/trunk/clang-query/tool/ClangQuery.cpp Tue Nov  1 15:07:05 
2016
@@ -80,7 +80,7 @@ int main(int argc, const char **argv) {
 for (cl::list::iterator I = Commands.begin(),
  E = Commands.end();
  I != E; ++I) {
-  QueryRef Q = QueryParser::parse(I->c_str(), QS);
+  QueryRef Q = QueryParser::parse(*I, QS);
   if (!Q->run(llvm::outs(), QS))
 return 1;
 }
@@ -97,7 +97,7 @@ int main(int argc, const char **argv) {
 std::string Line;
 std::getline(Input, Line);
 
-QueryRef Q = QueryParser::parse(Line.c_str(), QS);
+QueryRef Q = QueryParser::parse(Line, QS);
 if (!Q->run(llvm::outs(), QS))
   return 1;
   }


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


[PATCH] D26205: [clang-query] Fix Clang-tidy readability-redundant-string-cstr warnings

2016-11-01 Thread Malcolm Parsons via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL285731: [clang-query] Fix Clang-tidy 
readability-redundant-string-cstr warnings (authored by malcolm.parsons).

Changed prior to commit:
  https://reviews.llvm.org/D26205?vs=76597=76622#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26205

Files:
  clang-tools-extra/trunk/clang-query/tool/ClangQuery.cpp


Index: clang-tools-extra/trunk/clang-query/tool/ClangQuery.cpp
===
--- clang-tools-extra/trunk/clang-query/tool/ClangQuery.cpp
+++ clang-tools-extra/trunk/clang-query/tool/ClangQuery.cpp
@@ -80,7 +80,7 @@
 for (cl::list::iterator I = Commands.begin(),
  E = Commands.end();
  I != E; ++I) {
-  QueryRef Q = QueryParser::parse(I->c_str(), QS);
+  QueryRef Q = QueryParser::parse(*I, QS);
   if (!Q->run(llvm::outs(), QS))
 return 1;
 }
@@ -97,7 +97,7 @@
 std::string Line;
 std::getline(Input, Line);
 
-QueryRef Q = QueryParser::parse(Line.c_str(), QS);
+QueryRef Q = QueryParser::parse(Line, QS);
 if (!Q->run(llvm::outs(), QS))
   return 1;
   }


Index: clang-tools-extra/trunk/clang-query/tool/ClangQuery.cpp
===
--- clang-tools-extra/trunk/clang-query/tool/ClangQuery.cpp
+++ clang-tools-extra/trunk/clang-query/tool/ClangQuery.cpp
@@ -80,7 +80,7 @@
 for (cl::list::iterator I = Commands.begin(),
  E = Commands.end();
  I != E; ++I) {
-  QueryRef Q = QueryParser::parse(I->c_str(), QS);
+  QueryRef Q = QueryParser::parse(*I, QS);
   if (!Q->run(llvm::outs(), QS))
 return 1;
 }
@@ -97,7 +97,7 @@
 std::string Line;
 std::getline(Input, Line);
 
-QueryRef Q = QueryParser::parse(Line.c_str(), QS);
+QueryRef Q = QueryParser::parse(Line, QS);
 if (!Q->run(llvm::outs(), QS))
   return 1;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25660: [Analyzer] Checker for iterators dereferenced beyond their range.

2016-11-01 Thread Artem Dergachev via cfe-commits
NoQ added a comment.

I think i managed to understand the reasoning behind your solutions! Right now 
i definitely approve all the high-level logic apart from the handling of 
left/right `SVal`s for `evalAssume`, which i think could be easily improved 
upon without significant drawbacks. See the inline comment.

As for inlining STL headers - ouch. It was supposed to be working (i.e. never 
inlining), it'd probably be great to know why it gets inlined. STL headers are 
confusing much more often than helpful to the analyzer in most cases. That 
said, if we're going to ever revert this decision, i think it's great to have 
more stuff already working, so i'd not worry about that. If moving stuff to a 
header defeats the purpose of some of your tests (eg. tests that specifically 
test what happens if the function is inlined), then probably it'd be a good 
idea to duplicate the tests, eg:

  // RUN: ... -DUSE_HEADER=0 ...
  // RUN: ... -DUSE_HEADER=1 ...
  
  #if USE_HEADER
  #include "Inputs/..."
  #else
  // Paste header here.
  #endif




Comment at: lib/StaticAnalyzer/Checkers/IteratorPastEndChecker.cpp:195
+auto Param = State->getLValue(P, LCtx);
+auto Arg = State->getSVal(CE->getArg(idx++), LCtx->getParent());
+const auto *Pos = getIteratorPosition(State, Arg);

baloghadamsoftware wrote:
> NoQ wrote:
> > I think this trick needs more comments/explaining. It is very unusual. Are 
> > you trying to model effects of passing an iterator by value into a 
> > function? What part of these effects are not modeled magically by the core?
> If I pass an iterator by value (the most usual case) I have to assign its 
> position (in or out of range) to the formal parameter from the actual one.
Had a look. So, essentially, the core copies argument values to parameter 
regions in `enterStackFrame()` without ever notifying checkers about it in any 
way. Okaay. Yep, let's stick to that for now, as i've no better approach in 
mind.



Comment at: lib/StaticAnalyzer/Checkers/IteratorPastEndChecker.cpp:423
+
+void IteratorPastEndChecker::handleComparison(CheckerContext ,
+  const SVal ,

a.sidorin wrote:
> What will happen if we write something like this:
> ```
> bool Eq1 = it1 == it2;
> bool Eq2 = it3 == it4;
> if (Eq1) {...}?
> ```
> 
> As I understand, we'll assume the second condition instead of first.
Had a look. So the problem is, we obtain the result of the comparison as a 
symbol, from which it is too hard to recover the operands in order to move 
iterator position data from one value to another.

Normally we obtain a simple SymbolConjured for the return value of the 
`operator==()` call (or, similarly, `operator!=()`). For plain-value iterators 
(eg. `typedef T *iterator`) we might be obtaining an actual binary symbolic 
expression, but even then it's not quite clear how to obtain operands (the 
structure of the expression might have changed due to algebraic 
simplifications). Additionally, LHS and RHS aren't necessarily symbols (they 
might be semi-concrete), so composing symbolic expressions from them in general 
is problematic with our symbol hierarchy, which is rarely a problem for numbers 
but for structural symbols it'd be a mess.

For now i suggest, instead of storing only the last LHS and RHS, to save a map 
from symbols (which are results of comparisons) to (LHS value, RHS value) 
pairs. This map should, apart from the obvious, be cleaned up whenever one of 
the iterators in the pair gets mutated (incremented or decremented). This 
should take care of the problem Alexey points out, and should work with 
semi-concrete stuff.

For the future i suggest to let users construct their own symbols and symbolic 
expressions more easily. In fact, if only we had all iterators as regions, we 
should have probably used SymbolMetadata for this purpose: it's easy to both 
recover the parent region from it and use it in symbolic expressions. We could 
also deprecate the confusing structural symbols (provide default-bound lazy 
compound values for conjured structures instead), and then it'd be possible to 
transition to SymbolMetadata entirely.


https://reviews.llvm.org/D25660



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


[PATCH] D26195: Ignore incomplete types when determining whether they are expensive to copy

2016-11-01 Thread Aaron Ballman via cfe-commits
aaron.ballman added a comment.

In https://reviews.llvm.org/D26195#584958, @flx wrote:

> In https://reviews.llvm.org/D26195#584730, @aaron.ballman wrote:
>
> > In https://reviews.llvm.org/D26195#584724, @flx wrote:
> >
> > > In https://reviews.llvm.org/D26195#584712, @aaron.ballman wrote:
> > >
> > > > Please add a test case with an incomplete type that would exercise this 
> > > > code path, otherwise, LGTM.
> > >
> > >
> > > Hi Aaron,
> > >
> > > do you have any advise on how to add an incomplete type? When debugging 
> > > this I had a compilation unit that failed to compile causing it, but I'm 
> > > not sure this is a good way to add a test case.
> >
> >
> > A type like `class C;` is an incomplete type, as is `void`, so perhaps you 
> > can find a check that would let such a construct call through to 
> > `isExpensiveToCopy()`.
>
>
> Great, this works and I was able to see the check produce a false positive 
> without the proposed change here, but the test code introduces a compile 
> error now due to the incomplete type used in the function definition. Is 
> there a way to suppress that?


Unlikely -- fixing the compile error likely makes the type not expensive to 
copy by using a pointer (or reference). This may be tricky to test because the 
times when you would call `isExpensiveToCopy()` is with types that are going to 
be logically required to be complete. I am not certain the compile error is 
actually a problem though -- I would imagine your existing false-positives 
(that you mentioned in the patch summary) are cases where there is a compile 
error *and* a clang-tidy diagnostic, so the test may simply be "check that 
there's only a compile error and no clang-tidy diagnostic where there used to 
be a false-positive one."


Repository:
  rL LLVM

https://reviews.llvm.org/D26195



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


Re: [clang-tools-extra] r285721 - [Clang-tidy] Fix copy-paste error in misc-redundant-expression detected by PVS-Studio

2016-11-01 Thread Aaron Ballman via cfe-commits
On Tue, Nov 1, 2016 at 2:59 PM, Eugene Zelenko via cfe-commits
 wrote:
> Hi, Aaron!
>
> I don't think that it worth to split such trivial changes in three.

Unrelated changes should always go in as separate patches. This is
especially important for code archaeology and times when we have to
revert because a change is problematic.

~Aaron

>
> Eugene.
>
> On Tue, Nov 1, 2016 at 11:51 AM, Aaron Ballman  wrote:
>> On Tue, Nov 1, 2016 at 2:33 PM, Eugene Zelenko via cfe-commits
>>  wrote:
>>> Author: eugenezelenko
>>> Date: Tue Nov  1 13:33:50 2016
>>> New Revision: 285721
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=285721=rev
>>> Log:
>>> [Clang-tidy] Fix copy-paste error in misc-redundant-expression detected by 
>>> PVS-Studio
>>>
>>> Also fix some Include What You Use and modernize-use-bool-literals warnings.
>>
>> The review thread mentioned that this was supposed to be commit as
>> three separate commits rather than a single one. Can you please revert
>> this change, and then commit the logically distinct parts as separate
>> commits?
>>
>> Thanks!
>>
>> ~Aaron
>>
>>>
>>> Differential revision: https://reviews.llvm.org/D26176
>>>
>>> Modified:
>>> clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp
>>>
>>> Modified: 
>>> clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp
>>> URL: 
>>> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp?rev=285721=285720=285721=diff
>>> ==
>>> --- clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp 
>>> (original)
>>> +++ clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp 
>>> Tue Nov  1 13:33:50 2016
>>> @@ -12,7 +12,20 @@
>>>  #include "../utils/OptionsUtils.h"
>>>  #include "clang/AST/ASTContext.h"
>>>  #include "clang/ASTMatchers/ASTMatchFinder.h"
>>> +#include "clang/Basic/LLVM.h"
>>> +#include "clang/Basic/SourceLocation.h"
>>> +#include "clang/Basic/SourceManager.h"
>>>  #include "clang/Lex/Lexer.h"
>>> +#include "llvm/ADT/APInt.h"
>>> +#include "llvm/ADT/APSInt.h"
>>> +#include "llvm/ADT/FoldingSet.h"
>>> +#include "llvm/Support/Casting.h"
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>>
>>>  using namespace clang::ast_matchers;
>>>  using namespace clang::tidy::matchers;
>>> @@ -171,7 +184,7 @@ static bool areExclusiveRanges(BinaryOpe
>>>}
>>>
>>>// Handle cases where the constants are different.
>>> -  if ((OpcodeLHS == BO_EQ || OpcodeLHS == BO_LE || OpcodeLHS == BO_LE) &&
>>> +  if ((OpcodeLHS == BO_EQ || OpcodeLHS == BO_LT || OpcodeLHS == BO_LE) &&
>>>(OpcodeRHS == BO_EQ || OpcodeRHS == BO_GT || OpcodeRHS == BO_GE))
>>>  return true;
>>>
>>> @@ -401,7 +414,7 @@ retrieveRelationalIntegerConstantExpr(co
>>>  // Operand received with implicit comparator (cast).
>>>  Opcode = BO_NE;
>>>  OperandExpr = Cast;
>>> -Value = APSInt(32, 0);
>>> +Value = APSInt(32, false);
>>>} else {
>>>  return false;
>>>}
>>>
>>>
>>> ___
>>> cfe-commits mailing list
>>> cfe-commits@lists.llvm.org
>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26207: [ClangTidy - performance-unnecessary-value-param] Only add "const" when current parameter is not already const qualified

2016-11-01 Thread Aaron Ballman via cfe-commits
aaron.ballman added inline comments.



Comment at: test/clang-tidy/performance-unnecessary-value-param.cpp:242
+// Case where parameter in declaration is already const-qualified but not in
+// implementation. Make sure a second 'const' is not added to the declaration.
+void PositiveConstDeclaration(const ExpensiveToCopyType A);

This comment doesn't really match the test cases. The original code has two 
*different* declarations (only one of which is a definition), not one 
declaration and one redeclaration with the definition.

I think what is really happening is that it is adding the `&` qualifier to the 
first declaration, and adding the `const` and `&` qualifiers to the second 
declaration, and the result is that you get harmonization. But it brings up a 
question to me; what happens with:
```
void f1(ExpensiveToCopyType A) {
}

void f1(const ExpensiveToCopyType A) {

}
```
Does the fix-it try to create two definitions of the same function?



Comment at: test/clang-tidy/performance-unnecessary-value-param.cpp:244
+void PositiveConstDeclaration(const ExpensiveToCopyType A);
+// CHECK-FIXES: void PositiveConstDeclaration(const ExpensiveToCopyType& A);
+void PositiveConstDeclaration(ExpensiveToCopyType A) {

Is the `CHECK-MESSAGES` missing?


Repository:
  rL LLVM

https://reviews.llvm.org/D26207



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


Re: [clang-tools-extra] r285721 - [Clang-tidy] Fix copy-paste error in misc-redundant-expression detected by PVS-Studio

2016-11-01 Thread Eugene Zelenko via cfe-commits
Hi, Aaron!

I don't think that it worth to split such trivial changes in three.

Eugene.

On Tue, Nov 1, 2016 at 11:51 AM, Aaron Ballman  wrote:
> On Tue, Nov 1, 2016 at 2:33 PM, Eugene Zelenko via cfe-commits
>  wrote:
>> Author: eugenezelenko
>> Date: Tue Nov  1 13:33:50 2016
>> New Revision: 285721
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=285721=rev
>> Log:
>> [Clang-tidy] Fix copy-paste error in misc-redundant-expression detected by 
>> PVS-Studio
>>
>> Also fix some Include What You Use and modernize-use-bool-literals warnings.
>
> The review thread mentioned that this was supposed to be commit as
> three separate commits rather than a single one. Can you please revert
> this change, and then commit the logically distinct parts as separate
> commits?
>
> Thanks!
>
> ~Aaron
>
>>
>> Differential revision: https://reviews.llvm.org/D26176
>>
>> Modified:
>> clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp
>>
>> Modified: 
>> clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp
>> URL: 
>> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp?rev=285721=285720=285721=diff
>> ==
>> --- clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp 
>> (original)
>> +++ clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp Tue 
>> Nov  1 13:33:50 2016
>> @@ -12,7 +12,20 @@
>>  #include "../utils/OptionsUtils.h"
>>  #include "clang/AST/ASTContext.h"
>>  #include "clang/ASTMatchers/ASTMatchFinder.h"
>> +#include "clang/Basic/LLVM.h"
>> +#include "clang/Basic/SourceLocation.h"
>> +#include "clang/Basic/SourceManager.h"
>>  #include "clang/Lex/Lexer.h"
>> +#include "llvm/ADT/APInt.h"
>> +#include "llvm/ADT/APSInt.h"
>> +#include "llvm/ADT/FoldingSet.h"
>> +#include "llvm/Support/Casting.h"
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>>
>>  using namespace clang::ast_matchers;
>>  using namespace clang::tidy::matchers;
>> @@ -171,7 +184,7 @@ static bool areExclusiveRanges(BinaryOpe
>>}
>>
>>// Handle cases where the constants are different.
>> -  if ((OpcodeLHS == BO_EQ || OpcodeLHS == BO_LE || OpcodeLHS == BO_LE) &&
>> +  if ((OpcodeLHS == BO_EQ || OpcodeLHS == BO_LT || OpcodeLHS == BO_LE) &&
>>(OpcodeRHS == BO_EQ || OpcodeRHS == BO_GT || OpcodeRHS == BO_GE))
>>  return true;
>>
>> @@ -401,7 +414,7 @@ retrieveRelationalIntegerConstantExpr(co
>>  // Operand received with implicit comparator (cast).
>>  Opcode = BO_NE;
>>  OperandExpr = Cast;
>> -Value = APSInt(32, 0);
>> +Value = APSInt(32, false);
>>} else {
>>  return false;
>>}
>>
>>
>> ___
>> 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] D26206: Fix Clang-tidy readability-redundant-string-cstr warnings

2016-11-01 Thread Aaron Ballman via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

Aside from some formatting nits, this LGTM. You should run the diff through 
clang-format before committing.




Comment at: lib/CodeGen/CGObjCGNU.cpp:2650
llvm::Constant *TheClass =
- TheModule.getGlobalVariable(("_OBJC_CLASS_" + iter->first).c_str(),
+ TheModule.getGlobalVariable("_OBJC_CLASS_" + iter->first,
 true);

Formatting.



Comment at: lib/CodeGen/TargetInfo.cpp:7460
   FieldEncoding(bool b, SmallStringEnc ) : HasName(b), Enc(e.c_str()) {}
-  StringRef str() {return Enc.c_str();}
+  StringRef str() {return Enc;}
   bool operator<(const FieldEncoding ) const {

Formatting (since you're touching it anyway).



Comment at: lib/Frontend/CompilerInvocation.cpp:1472
 
-Opts.AddPath(Path.c_str(), Group, IsFramework,
+Opts.AddPath(Path, Group, IsFramework,
  /*IgnoreSysroot*/ true);

Formatting.



Comment at: lib/Frontend/Rewrite/RewriteObjC.cpp:5653
   RewriteObjCMethodsMetaData(InstanceMethods.begin(), InstanceMethods.end(),
- true, "CATEGORY_", FullCategoryName.c_str(),
+ true, "CATEGORY_", FullCategoryName,
  Result);

Formatting. Same below.



Comment at: unittests/AST/ASTImporterTest.cpp:75
   MFS->addFile(InputFileName, 0,
-   llvm::MemoryBuffer::getMemBuffer(FromCode.c_str()));
+   llvm::MemoryBuffer::getMemBuffer(FromCode));
 

Possibly formatting?


https://reviews.llvm.org/D26206



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


[PATCH] D25343: [OpenCL] Mark group functions as convergent in opencl-c.h

2016-11-01 Thread Yaxun Liu via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL285725: [OpenCL] Mark group functions as convergent in 
opencl-c.h (authored by yaxunl).

Changed prior to commit:
  https://reviews.llvm.org/D25343?vs=75203=76612#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25343

Files:
  cfe/trunk/include/clang/Basic/Attr.td
  cfe/trunk/include/clang/Basic/AttrDocs.td
  cfe/trunk/lib/CodeGen/CGCall.cpp
  cfe/trunk/lib/Headers/opencl-c.h
  cfe/trunk/lib/Sema/SemaDeclAttr.cpp
  cfe/trunk/test/CodeGenOpenCL/convergent.cl
  cfe/trunk/test/SemaOpenCL/convergent.cl

Index: cfe/trunk/test/CodeGenOpenCL/convergent.cl
===
--- cfe/trunk/test/CodeGenOpenCL/convergent.cl
+++ cfe/trunk/test/CodeGenOpenCL/convergent.cl
@@ -0,0 +1,118 @@
+// RUN: %clang_cc1 -triple spir-unknown-unknown -emit-llvm %s -o - | FileCheck %s
+
+void convfun(void) __attribute__((convergent));
+void non_convfun(void);
+void nodupfun(void) __attribute__((noduplicate));
+
+void f(void);
+void g(void);
+
+// Test two if's are merged and non_convfun duplicated.
+// The LLVM IR is equivalent to:
+//if (a) {
+//  f();
+//  non_convfun();
+//  g();
+//} else {
+//  non_convfun();
+//}
+//
+// CHECK: define spir_func void @test_merge_if(i32 %[[a:.+]])
+// CHECK: %[[tobool:.+]] = icmp eq i32 %[[a]], 0
+// CHECK: br i1 %[[tobool]], label %[[if_end3_critedge:.+]], label %[[if_then:.+]]
+// CHECK: [[if_then]]:
+// CHECK: tail call spir_func void @f()
+// CHECK: tail call spir_func void @non_convfun()
+// CHECK: tail call spir_func void @g()
+// CHECK: br label %[[if_end3:.+]]
+// CHECK: [[if_end3_critedge]]:
+// CHECK: tail call spir_func void @non_convfun()
+// CHECK: br label %[[if_end3]]
+// CHECK: [[if_end3]]:
+// CHECK-LABEL: ret void
+
+void test_merge_if(int a) {
+  if (a) {
+f();
+  }
+  non_convfun();
+  if (a) {
+g();
+  }
+}
+
+// CHECK-DAG: declare spir_func void @f()
+// CHECK-DAG: declare spir_func void @non_convfun()
+// CHECK-DAG: declare spir_func void @g()
+
+// Test two if's are not merged.
+// CHECK: define spir_func void @test_no_merge_if(i32 %[[a:.+]])
+// CHECK:  %[[tobool:.+]] = icmp eq i32 %[[a]], 0
+// CHECK: br i1 %[[tobool]], label %[[if_end:.+]], label %[[if_then:.+]]
+// CHECK: [[if_then]]:
+// CHECK: tail call spir_func void @f()
+// CHECK-NOT: call spir_func void @convfun()
+// CHECK-NOT: call spir_func void @g()
+// CHECK: br label %[[if_end]]
+// CHECK: [[if_end]]:
+// CHECK:  %[[tobool_pr:.+]] = phi i1 [ true, %[[if_then]] ], [ false, %{{.+}} ]
+// CHECK:  tail call spir_func void @convfun() #[[attr5:.+]]
+// CHECK:  br i1 %[[tobool_pr]], label %[[if_then2:.+]], label %[[if_end3:.+]]
+// CHECK: [[if_then2]]:
+// CHECK: tail call spir_func void @g()
+// CHECK:  br label %[[if_end3:.+]]
+// CHECK: [[if_end3]]:
+// CHECK-LABEL:  ret void
+
+void test_no_merge_if(int a) {
+  if (a) {
+f();
+  }
+  convfun();
+  if(a) {
+g();
+  }
+}
+
+// CHECK: declare spir_func void @convfun(){{[^#]*}} #[[attr2:[0-9]+]]
+
+// Test loop is unrolled for convergent function.
+// CHECK-LABEL: define spir_func void @test_unroll()
+// CHECK:  tail call spir_func void @convfun() #[[attr5:[0-9]+]]
+// CHECK:  tail call spir_func void @convfun() #[[attr5]]
+// CHECK:  tail call spir_func void @convfun() #[[attr5]]
+// CHECK:  tail call spir_func void @convfun() #[[attr5]]
+// CHECK:  tail call spir_func void @convfun() #[[attr5]]
+// CHECK:  tail call spir_func void @convfun() #[[attr5]]
+// CHECK:  tail call spir_func void @convfun() #[[attr5]]
+// CHECK:  tail call spir_func void @convfun() #[[attr5]]
+// CHECK:  tail call spir_func void @convfun() #[[attr5]]
+// CHECK:  tail call spir_func void @convfun() #[[attr5]]
+// CHECK-LABEL:  ret void
+
+void test_unroll() {
+  for (int i = 0; i < 10; i++)
+convfun();
+}
+
+// Test loop is not unrolled for noduplicate function.
+// CHECK-LABEL: define spir_func void @test_not_unroll()
+// CHECK:  br label %[[for_body:.+]]
+// CHECK: [[for_cond_cleanup:.+]]:
+// CHECK:  ret void
+// CHECK: [[for_body]]:
+// CHECK:  tail call spir_func void @nodupfun() #[[attr6:[0-9]+]]
+// CHECK-NOT: call spir_func void @nodupfun()
+// CHECK:  br i1 %{{.+}}, label %[[for_body]], label %[[for_cond_cleanup]]
+
+void test_not_unroll() {
+  for (int i = 0; i < 10; i++)
+nodupfun();
+}
+
+// CHECK: declare spir_func void @nodupfun(){{[^#]*}} #[[attr3:[0-9]+]]
+
+// CHECK-DAG: attributes #[[attr2]] = { {{[^}]*}}convergent{{[^}]*}} }
+// CHECK-DAG: attributes #[[attr3]] = { {{[^}]*}}noduplicate{{[^}]*}} }
+// CHECK-DAG: attributes #[[attr5]] = { {{[^}]*}}convergent{{[^}]*}} }
+// CHECK-DAG: attributes #[[attr6]] = { {{[^}]*}}noduplicate{{[^}]*}} }
Index: cfe/trunk/test/SemaOpenCL/convergent.cl
===
--- cfe/trunk/test/SemaOpenCL/convergent.cl
+++ cfe/trunk/test/SemaOpenCL/convergent.cl
@@ -0,0 +1,12 @@
+// RUN: 

r285725 - [OpenCL] Mark group functions as convergent in opencl-c.h

2016-11-01 Thread Yaxun Liu via cfe-commits
Author: yaxunl
Date: Tue Nov  1 13:45:32 2016
New Revision: 285725

URL: http://llvm.org/viewvc/llvm-project?rev=285725=rev
Log:
[OpenCL] Mark group functions as convergent in opencl-c.h

Certain OpenCL builtin functions are supposed to be executed by all threads in 
a work group or sub group. Such functions should not be made divergent during 
transformation. It makes sense to mark them with convergent attribute.

The adding of convergent attribute is based on Ettore Speziale's work and the 
original proposal and patch can be found at 
https://www.mail-archive.com/cfe-commits@lists.llvm.org/msg22271.html.

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

Added:
cfe/trunk/test/CodeGenOpenCL/convergent.cl
cfe/trunk/test/SemaOpenCL/convergent.cl
Modified:
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/include/clang/Basic/AttrDocs.td
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/lib/Headers/opencl-c.h
cfe/trunk/lib/Sema/SemaDeclAttr.cpp

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=285725=285724=285725=diff
==
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Tue Nov  1 13:45:32 2016
@@ -1026,6 +1026,12 @@ def NoDuplicate : InheritableAttr {
   let Documentation = [NoDuplicateDocs];
 }
 
+def Convergent : InheritableAttr {
+  let Spellings = [GNU<"convergent">, CXX11<"clang", "convergent">];
+  let Subjects = SubjectList<[Function]>;
+  let Documentation = [ConvergentDocs];
+}
+
 def NoInline : InheritableAttr {
   let Spellings = [GCC<"noinline">, Declspec<"noinline">];
   let Subjects = SubjectList<[Function]>;

Modified: cfe/trunk/include/clang/Basic/AttrDocs.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/AttrDocs.td?rev=285725=285724=285725=diff
==
--- cfe/trunk/include/clang/Basic/AttrDocs.td (original)
+++ cfe/trunk/include/clang/Basic/AttrDocs.td Tue Nov  1 13:45:32 2016
@@ -606,6 +606,33 @@ of the condition.
   }];
 }
 
+def ConvergentDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+The ``convergent`` attribute can be placed on a function declaration. It is
+translated into the LLVM ``convergent`` attribute, which indicates that the 
call
+instructions of a function with this attribute cannot be made control-dependent
+on any additional values.
+
+In languages designed for SPMD/SIMT programming model, e.g. OpenCL or CUDA,
+the call instructions of a function with this attribute must be executed by
+all work items or threads in a work group or sub group.
+
+This attribute is different from ``noduplicate`` because it allows duplicating
+function calls if it can be proved that the duplicated function calls are
+not made control-dependent on any additional values, e.g., unrolling a loop
+executed by all work items.
+
+Sample usage:
+.. code-block:: c
+
+  void convfunc(void) __attribute__((convergent));
+  // Setting it as a C++11 attribute is also valid in a C++ program.
+  // void convfunc(void) [[clang::convergent]];
+
+  }];
+}
+
 def NoSplitStackDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=285725=285724=285725=diff
==
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Tue Nov  1 13:45:32 2016
@@ -1648,6 +1648,8 @@ void CodeGenModule::ConstructAttributeLi
   FuncAttrs.addAttribute(llvm::Attribute::NoReturn);
 if (TargetDecl->hasAttr())
   FuncAttrs.addAttribute(llvm::Attribute::NoDuplicate);
+if (TargetDecl->hasAttr())
+  FuncAttrs.addAttribute(llvm::Attribute::Convergent);
 
 if (const FunctionDecl *Fn = dyn_cast(TargetDecl)) {
   AddAttributesFromFunctionProtoType(

Modified: cfe/trunk/lib/Headers/opencl-c.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/opencl-c.h?rev=285725=285724=285725=diff
==
--- cfe/trunk/lib/Headers/opencl-c.h (original)
+++ cfe/trunk/lib/Headers/opencl-c.h Tue Nov  1 13:45:32 2016
@@ -17,6 +17,7 @@
 #endif //__OPENCL_C_VERSION__ >= CL_VERSION_2_0
 
 #define __ovld __attribute__((overloadable))
+#define __conv __attribute__((convergent))
 
 // Optimizations
 #define __purefn __attribute__((pure))
@@ -13822,7 +13823,7 @@ typedef uint cl_mem_fence_flags;
  * image objects and then want to read the updated data.
  */
 
-void __ovld barrier(cl_mem_fence_flags flags);
+void __ovld __conv barrier(cl_mem_fence_flags flags);
 
 #if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
 
@@ -13835,8 +13836,8 @@ typedef enum memory_scope
   

[PATCH] D26125: [clang-tidy] Fixed readability-else-after-return for cascade statements

2016-11-01 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. Thanks for fixing this!


https://reviews.llvm.org/D26125



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


[PATCH] D26176: [Clang-tidy] Fix copy-paste error in misc-redundant-expression detected by PVS-Studio

2016-11-01 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL285721: [Clang-tidy] Fix copy-paste error in 
misc-redundant-expression detected by PVS… (authored by eugenezelenko).

Changed prior to commit:
  https://reviews.llvm.org/D26176?vs=76510=76611#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26176

Files:
  clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp


Index: clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp
@@ -12,7 +12,20 @@
 #include "../utils/OptionsUtils.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
 #include "clang/Lex/Lexer.h"
+#include "llvm/ADT/APInt.h"
+#include "llvm/ADT/APSInt.h"
+#include "llvm/ADT/FoldingSet.h"
+#include "llvm/Support/Casting.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
 
 using namespace clang::ast_matchers;
 using namespace clang::tidy::matchers;
@@ -171,7 +184,7 @@
   }
 
   // Handle cases where the constants are different.
-  if ((OpcodeLHS == BO_EQ || OpcodeLHS == BO_LE || OpcodeLHS == BO_LE) &&
+  if ((OpcodeLHS == BO_EQ || OpcodeLHS == BO_LT || OpcodeLHS == BO_LE) &&
   (OpcodeRHS == BO_EQ || OpcodeRHS == BO_GT || OpcodeRHS == BO_GE))
 return true;
 
@@ -401,7 +414,7 @@
 // Operand received with implicit comparator (cast).
 Opcode = BO_NE;
 OperandExpr = Cast;
-Value = APSInt(32, 0);
+Value = APSInt(32, false);
   } else {
 return false;
   }


Index: clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp
@@ -12,7 +12,20 @@
 #include "../utils/OptionsUtils.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
 #include "clang/Lex/Lexer.h"
+#include "llvm/ADT/APInt.h"
+#include "llvm/ADT/APSInt.h"
+#include "llvm/ADT/FoldingSet.h"
+#include "llvm/Support/Casting.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
 
 using namespace clang::ast_matchers;
 using namespace clang::tidy::matchers;
@@ -171,7 +184,7 @@
   }
 
   // Handle cases where the constants are different.
-  if ((OpcodeLHS == BO_EQ || OpcodeLHS == BO_LE || OpcodeLHS == BO_LE) &&
+  if ((OpcodeLHS == BO_EQ || OpcodeLHS == BO_LT || OpcodeLHS == BO_LE) &&
   (OpcodeRHS == BO_EQ || OpcodeRHS == BO_GT || OpcodeRHS == BO_GE))
 return true;
 
@@ -401,7 +414,7 @@
 // Operand received with implicit comparator (cast).
 Opcode = BO_NE;
 OperandExpr = Cast;
-Value = APSInt(32, 0);
+Value = APSInt(32, false);
   } else {
 return false;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r285721 - [Clang-tidy] Fix copy-paste error in misc-redundant-expression detected by PVS-Studio

2016-11-01 Thread Eugene Zelenko via cfe-commits
Author: eugenezelenko
Date: Tue Nov  1 13:33:50 2016
New Revision: 285721

URL: http://llvm.org/viewvc/llvm-project?rev=285721=rev
Log:
[Clang-tidy] Fix copy-paste error in misc-redundant-expression detected by 
PVS-Studio

Also fix some Include What You Use and modernize-use-bool-literals warnings.

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

Modified:
clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp

Modified: clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp?rev=285721=285720=285721=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp Tue 
Nov  1 13:33:50 2016
@@ -12,7 +12,20 @@
 #include "../utils/OptionsUtils.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
 #include "clang/Lex/Lexer.h"
+#include "llvm/ADT/APInt.h"
+#include "llvm/ADT/APSInt.h"
+#include "llvm/ADT/FoldingSet.h"
+#include "llvm/Support/Casting.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
 
 using namespace clang::ast_matchers;
 using namespace clang::tidy::matchers;
@@ -171,7 +184,7 @@ static bool areExclusiveRanges(BinaryOpe
   }
 
   // Handle cases where the constants are different.
-  if ((OpcodeLHS == BO_EQ || OpcodeLHS == BO_LE || OpcodeLHS == BO_LE) &&
+  if ((OpcodeLHS == BO_EQ || OpcodeLHS == BO_LT || OpcodeLHS == BO_LE) &&
   (OpcodeRHS == BO_EQ || OpcodeRHS == BO_GT || OpcodeRHS == BO_GE))
 return true;
 
@@ -401,7 +414,7 @@ retrieveRelationalIntegerConstantExpr(co
 // Operand received with implicit comparator (cast).
 Opcode = BO_NE;
 OperandExpr = Cast;
-Value = APSInt(32, 0);
+Value = APSInt(32, false);
   } else {
 return false;
   }


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


[PATCH] D26205: [clang-query] Fix Clang-tidy readability-redundant-string-cstr warnings

2016-11-01 Thread Peter Collingbourne via cfe-commits
pcc accepted this revision.
pcc added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D26205



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


[PATCH] D26125: [clang-tidy] Fixed readability-else-after-return for cascade statements

2016-11-01 Thread Paweł Żukowski via cfe-commits
idlecode retitled this revision from "[clang-tidy] Fixed else-after-return 
warning in cascade if statement" to "[clang-tidy] Fixed 
readability-else-after-return for cascade statements".
idlecode updated the summary for this revision.
idlecode updated this revision to Diff 76604.
idlecode added a comment.

I have reverted matcher to the state before https://reviews.llvm.org/D23265 
(tests are passing with compoundStmt instead of stmt and this way is better 
than mine).


https://reviews.llvm.org/D26125

Files:
  clang-tidy/readability/ElseAfterReturnCheck.cpp
  test/clang-tidy/readability-else-after-return.cpp


Index: test/clang-tidy/readability-else-after-return.cpp
===
--- test/clang-tidy/readability-else-after-return.cpp
+++ test/clang-tidy/readability-else-after-return.cpp
@@ -29,32 +29,60 @@
   else if (a > 10)
 return;
   else // comment-2
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not use 'else' after 'return'
-  // CHECK-FIXES: {{^}}  // comment-2
+  // CHECK-FIXES-NOT: {{^}}  // comment-2
 f(0);
+
+  if (a > 0)
+if (a < 10)
+  return;
+else // comment-3
+// CHECK-FIXES-NOT: {{^}}// comment-3
+  f(0);
+  else
+if (a > 10)
+  return;
+else // comment-4
+// CHECK-FIXES-NOT: {{^}}// comment-4
+  f(0);
+
+  if (a > 0) {
+if (a < 10)
+  return;
+else // comment-5
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: do not use 'else' after 
'return'
+// CHECK-FIXES: {{^}}// comment-5
+  f(0);
+  } else {
+if (a > 10)
+  return;
+else // comment-6
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: do not use 'else' after 
'return'
+// CHECK-FIXES: {{^}}// comment-6
+  f(0);
+  }
 }
 
 void foo() {
   for (unsigned x = 0; x < 42; ++x) {
 if (x) {
   continue;
-} else { // comment-3
+} else { // comment-7
 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: do not use 'else' after 
'continue'
-// CHECK-FIXES: {{^}}} // comment-3
+// CHECK-FIXES: {{^}}} // comment-7
   x++;
 }
 if (x) {
   break;
-} else { // comment-4
+} else { // comment-8
 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: do not use 'else' after 'break'
-// CHECK-FIXES: {{^}}} // comment-4
+// CHECK-FIXES: {{^}}} // comment-8
   x++;
 }
 if (x) {
   throw 42;
-} else { // comment-5
+} else { // comment-9
 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: do not use 'else' after 'throw'
-// CHECK-FIXES: {{^}}} // comment-5
+// CHECK-FIXES: {{^}}} // comment-9
   x++;
 }
   }
Index: clang-tidy/readability/ElseAfterReturnCheck.cpp
===
--- clang-tidy/readability/ElseAfterReturnCheck.cpp
+++ clang-tidy/readability/ElseAfterReturnCheck.cpp
@@ -23,7 +23,7 @@
   stmt(anyOf(returnStmt().bind("return"), continueStmt().bind("continue"),
  breakStmt().bind("break"), cxxThrowExpr().bind("throw")));
   Finder->addMatcher(
-  stmt(forEach(
+  compoundStmt(forEach(
   ifStmt(hasThen(stmt(
  anyOf(ControlFlowInterruptorMatcher,
compoundStmt(has(ControlFlowInterruptorMatcher),


Index: test/clang-tidy/readability-else-after-return.cpp
===
--- test/clang-tidy/readability-else-after-return.cpp
+++ test/clang-tidy/readability-else-after-return.cpp
@@ -29,32 +29,60 @@
   else if (a > 10)
 return;
   else // comment-2
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not use 'else' after 'return'
-  // CHECK-FIXES: {{^}}  // comment-2
+  // CHECK-FIXES-NOT: {{^}}  // comment-2
 f(0);
+
+  if (a > 0)
+if (a < 10)
+  return;
+else // comment-3
+// CHECK-FIXES-NOT: {{^}}// comment-3
+  f(0);
+  else
+if (a > 10)
+  return;
+else // comment-4
+// CHECK-FIXES-NOT: {{^}}// comment-4
+  f(0);
+
+  if (a > 0) {
+if (a < 10)
+  return;
+else // comment-5
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: do not use 'else' after 'return'
+// CHECK-FIXES: {{^}}// comment-5
+  f(0);
+  } else {
+if (a > 10)
+  return;
+else // comment-6
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: do not use 'else' after 'return'
+// CHECK-FIXES: {{^}}// comment-6
+  f(0);
+  }
 }
 
 void foo() {
   for (unsigned x = 0; x < 42; ++x) {
 if (x) {
   continue;
-} else { // comment-3
+} else { // comment-7
 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: do not use 'else' after 'continue'
-// CHECK-FIXES: {{^}}} // comment-3
+// CHECK-FIXES: {{^}}} // comment-7
   x++;
 }
 if (x) {
   break;
-} else { // comment-4
+} else { // comment-8
 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: do not use 'else' after 'break'
-// CHECK-FIXES: {{^}}   

Re: r285326 - [Driver][OpenMP] Add support to create jobs for unbundling actions.

2016-11-01 Thread Galina Kistanova via cfe-commits
http://lab.llvm.org:8011/builders/clang-3stage-ubuntu/builds/128/steps/cmake-configure/logs/stdio

-- The C compiler identification is GNU 4.8.4
-- The CXX compiler identification is GNU 4.8.4

The code itself seems fine. The similar builder that uses the ToT Clang
does not generate any warnings.
http://lab.llvm.org:8011/builders/clang-with-lto-ubuntu/builds/107​

Thanks

Galina


On Mon, Oct 31, 2016 at 6:26 PM, Samuel F Antao  wrote:

> Hi Galina,
>
> Thanks for letting me know. Can you tell me which compiler (kind and
> version) is used in the buildbot slave? Looks like that compiler is not
> doing what it should, so I need to be able to test a workaround.
>
> We have
>
> virtual void ConstructJob(Compilation , const JobAction ,
> const InputInfo ,
> const InputInfoList ,
> const llvm::opt::ArgList ,
> const char *LinkingOutput) const = 0;
>
> which is the signature of ConstructJob that should be overwritten, so we
> are not hiding anything. And in Action.cpp we have an unreachable
> statement, so no need for return. So, the code seems to be okay, but we can
> probably massage the code a little to silence the compiler you are using.
>
> Thanks!
> Samuel
>
>
> - Original message -
> From: Galina Kistanova 
> To: Samuel F Antao/Watson/IBM@IBMUS
> Cc: cfe-commits 
> Subject: Re: r285326 - [Driver][OpenMP] Add support to create jobs for
> unbundling actions.
> Date: Tue, Nov 1, 2016 12:59 AM
>
> Hi Samuel,
>
> Looks like this revision introduced warning to one of our builders:
> http://lab.llvm.org:8011/builders/clang-3stage-ubuntu/
> builds/67/steps/build-stage3-clang/logs/warnings%20%28830%29
>
> Please have a look at this?
>
> Thanks
>
> Galina
>
> On Thu, Oct 27, 2016 at 11:14 AM, Samuel Antao via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
> Author: sfantao
> Date: Thu Oct 27 13:14:55 2016
> New Revision: 285326
>
> URL: http://llvm.org/viewvc/llvm-project?rev=285326=rev
> Log:
> [Driver][OpenMP] Add support to create jobs for unbundling actions.
>
> Summary:
> This patch adds the support to create jobs for the `OffloadBundlingAction`
> which will invoke the `clang-offload-bundler` tool to unbundle input files.
>
> Unlike other actions, unbundling actions have multiple outputs. Therefore,
> this patch adds the required changes to have a variant of
> `Tool::ConstructJob` with multiple outputs.
>
> The way the naming of the results is implemented is also slightly modified
> so that the same action can use a different offloading prefix for each use
> by the different offloading actions.
>
> With this patch, it is possible to compile a functional OpenMP binary with
> offloading support, even with separate compilation.
>
> Reviewers: echristo, tra, jlebar, ABataev, hfinkel
>
> Subscribers: mkuron, whchung, mehdi_amini, cfe-commits, Hahnfeld,
> andreybokhanko, arpith-jacob, carlo.bertolli, caomhin
>
> Differential Revision: https://reviews.llvm.org/D21857
>
> Modified:
> cfe/trunk/include/clang/Driver/Action.h
> cfe/trunk/include/clang/Driver/Driver.h
> cfe/trunk/include/clang/Driver/Tool.h
> cfe/trunk/lib/Driver/Action.cpp
> cfe/trunk/lib/Driver/Driver.cpp
> cfe/trunk/lib/Driver/Tool.cpp
> cfe/trunk/lib/Driver/Tools.cpp
> cfe/trunk/lib/Driver/Tools.h
> cfe/trunk/test/Driver/cuda-bindings.cu
> cfe/trunk/test/Driver/openmp-offload.c
> cfe/trunk/test/Driver/opt-record.c
>
> Modified: cfe/trunk/include/clang/Driver/Action.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/
> Driver/Action.h?rev=285326=285325=285326=diff
> 
> ==
> --- cfe/trunk/include/clang/Driver/Action.h (original)
> +++ cfe/trunk/include/clang/Driver/Action.h Thu Oct 27 13:14:55 2016
> @@ -157,9 +157,12 @@ public:
>/// Return a string containing the offload kind of the action.
>std::string getOffloadingKindPrefix() const;
>/// Return a string that can be used as prefix in order to generate
> unique
> -  /// files for each offloading kind.
> -  std::string
> -  getOffloadingFileNamePrefix(llvm::StringRef NormalizedTriple) const;
> +  /// files for each offloading kind. By default, no prefix is used for
> +  /// non-device kinds, except if \a CreatePrefixForHost is set.
> +  static std::string
> +  GetOffloadingFileNamePrefix(OffloadKind Kind,
> +  llvm::StringRef NormalizedTriple,
> +  bool CreatePrefixForHost = false);
>/// Return a string containing a offload kind name.
>static StringRef GetOffloadKindName(OffloadKind Kind);
>
>
> Modified: cfe/trunk/include/clang/Driver/Driver.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/
> Driver/Driver.h?rev=285326=285325=285326=diff
> 

[PATCH] D26176: [Clang-tidy] Fix copy-paste error in misc-redundant-expression detected by PVS-Studio

2016-11-01 Thread Aaron Ballman via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

These changes all look good to me, but it would be best to split the commit 
into three parts: one for include what you use, one for 
modernize-use-bool-literals, and one for the copy pasta error. Keeping the 
changes logically separate helps in case we need to roll any particular change 
back for some reason (same is true for similar patches in the future; they 
should probably be multiple patch requests).


Repository:
  rL LLVM

https://reviews.llvm.org/D26176



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


[PATCH] D25659: [clang-tidy] Avoid running aliased checks twice

2016-11-01 Thread Aaron Ballman via cfe-commits
aaron.ballman added a comment.

I *really* like this idea, thank you for working on this! A few things:

(0) I'm uncomfortable with the lack of tests in the patch. I'm not certain of a 
good way to test this, however. @alexfh, do you have ideas?
(1) I think that the aliases and the originals should be listed with 
-list-checks, because these are names under which the checks may be run (and 
sometimes the name may even imply different semantics for the check).
(2) I'm not as certain about -dump-config, since I am not really familiar with 
that option, but I think we want to list the alias and the original under that 
as well because different check names may have different configuration options.


https://reviews.llvm.org/D25659



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


[PATCH] D26207: [ClangTidy - performance-unnecessary-value-param] Only add "const" when current parameter is not already const qualified

2016-11-01 Thread Felix Berger via cfe-commits
flx created this revision.
flx added reviewers: alexfh, sbenza, aaron.ballman.
flx added a subscriber: cfe-commits.
flx set the repository for this revision to rL LLVM.

Repository:
  rL LLVM

https://reviews.llvm.org/D26207

Files:
  clang-tidy/performance/UnnecessaryValueParamCheck.cpp
  test/clang-tidy/performance-unnecessary-value-param.cpp


Index: test/clang-tidy/performance-unnecessary-value-param.cpp
===
--- test/clang-tidy/performance-unnecessary-value-param.cpp
+++ test/clang-tidy/performance-unnecessary-value-param.cpp
@@ -237,3 +237,12 @@
   ExpensiveToCopyType B;
   B = A;
 }
+
+// Case where parameter in declaration is already const-qualified but not in
+// implementation. Make sure a second 'const' is not added to the declaration.
+void PositiveConstDeclaration(const ExpensiveToCopyType A);
+// CHECK-FIXES: void PositiveConstDeclaration(const ExpensiveToCopyType& A);
+void PositiveConstDeclaration(ExpensiveToCopyType A) {
+  // CHECK-MESSAGES: [[@LINE-1]]:51: warning: the parameter 'A' is copied
+  // CHECK-FIXES: void PositiveConstDeclaration(const ExpensiveToCopyType& A) {
+}
Index: clang-tidy/performance/UnnecessaryValueParamCheck.cpp
===
--- clang-tidy/performance/UnnecessaryValueParamCheck.cpp
+++ clang-tidy/performance/UnnecessaryValueParamCheck.cpp
@@ -128,7 +128,8 @@
 const auto  = *FunctionDecl->getParamDecl(Index);
 Diag << utils::fixit::changeVarDeclToReference(CurrentParam,
*Result.Context);
-if (!IsConstQualified)
+if (!IsConstQualified &&
+!CurrentParam.getType().getCanonicalType().isConstQualified())
   Diag << utils::fixit::changeVarDeclToConst(CurrentParam);
   }
 }


Index: test/clang-tidy/performance-unnecessary-value-param.cpp
===
--- test/clang-tidy/performance-unnecessary-value-param.cpp
+++ test/clang-tidy/performance-unnecessary-value-param.cpp
@@ -237,3 +237,12 @@
   ExpensiveToCopyType B;
   B = A;
 }
+
+// Case where parameter in declaration is already const-qualified but not in
+// implementation. Make sure a second 'const' is not added to the declaration.
+void PositiveConstDeclaration(const ExpensiveToCopyType A);
+// CHECK-FIXES: void PositiveConstDeclaration(const ExpensiveToCopyType& A);
+void PositiveConstDeclaration(ExpensiveToCopyType A) {
+  // CHECK-MESSAGES: [[@LINE-1]]:51: warning: the parameter 'A' is copied
+  // CHECK-FIXES: void PositiveConstDeclaration(const ExpensiveToCopyType& A) {
+}
Index: clang-tidy/performance/UnnecessaryValueParamCheck.cpp
===
--- clang-tidy/performance/UnnecessaryValueParamCheck.cpp
+++ clang-tidy/performance/UnnecessaryValueParamCheck.cpp
@@ -128,7 +128,8 @@
 const auto  = *FunctionDecl->getParamDecl(Index);
 Diag << utils::fixit::changeVarDeclToReference(CurrentParam,
*Result.Context);
-if (!IsConstQualified)
+if (!IsConstQualified &&
+!CurrentParam.getType().getCanonicalType().isConstQualified())
   Diag << utils::fixit::changeVarDeclToConst(CurrentParam);
   }
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26196: AMDGPU: Translate null pointers in private and local addr space

2016-11-01 Thread Matt Arsenault via cfe-commits
arsenm added inline comments.



Comment at: lib/CodeGen/TargetInfo.cpp:6957-6958
+
+  llvm::Constant *translateNullPtr(const CodeGen::CodeGenModule ,
+  llvm::Constant *C) const override;
 };

I was thinking that addrspacecast (generic null) should be valid for all 
targets, but I guess this saves the trouble of needing to fold out the nulls 
for the address spaces where null is supposed to be 0



Comment at: lib/CodeGen/TargetInfo.cpp:7038
+  auto AS = PT->getAddressSpace();
+  if (CGM.getTarget().getTriple().getArch() != llvm::Triple::amdgcn ||
+(AS != Ctx.getTargetAddressSpace(LangAS::opencl_local) && AS != 0))

The amdgcn check should be unnecessary



Comment at: lib/CodeGen/TargetInfo.cpp:7039
+  if (CGM.getTarget().getTriple().getArch() != llvm::Triple::amdgcn ||
+(AS != Ctx.getTargetAddressSpace(LangAS::opencl_local) && AS != 0))
+return C;

Shouldn't the 0 be checking lang as::opencl_private? 


https://reviews.llvm.org/D26196



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


[PATCH] D25204: Register Calling Convention, Clang changes

2016-11-01 Thread Erich Keane via cfe-commits
erichkeane added a comment.

@rnk, @majnemer and @ABataev :  I believe that I've done everything that has 
come up in review, and this passes all tests for the convention I can find.  Do 
you guys see anything that is holding this patch up?  What is otherwise the 
'next step' in getting this into master?


https://reviews.llvm.org/D25204



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


[PATCH] D26157: [OpenCL] always use SPIR address spaces for kernel_arg_addr_space MD

2016-11-01 Thread Pekka Jääskeläinen via cfe-commits
pekka.jaaskelainen added a comment.

Thanks. @tstellarAMD OK to commit for 3.9.1 as well?


Repository:
  rL LLVM

https://reviews.llvm.org/D26157



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


[PATCH] D26195: Ignore incomplete types when determining whether they are expensive to copy

2016-11-01 Thread Felix Berger via cfe-commits
flx added a comment.

In https://reviews.llvm.org/D26195#584730, @aaron.ballman wrote:

> In https://reviews.llvm.org/D26195#584724, @flx wrote:
>
> > In https://reviews.llvm.org/D26195#584712, @aaron.ballman wrote:
> >
> > > Please add a test case with an incomplete type that would exercise this 
> > > code path, otherwise, LGTM.
> >
> >
> > Hi Aaron,
> >
> > do you have any advise on how to add an incomplete type? When debugging 
> > this I had a compilation unit that failed to compile causing it, but I'm 
> > not sure this is a good way to add a test case.
>
>
> A type like `class C;` is an incomplete type, as is `void`, so perhaps you 
> can find a check that would let such a construct call through to 
> `isExpensiveToCopy()`.


Great, this works and I was able to see the check produce a false positive 
without the proposed change here, but the test code introduces a compile error 
now due to the incomplete type used in the function definition. Is there a way 
to suppress that?


Repository:
  rL LLVM

https://reviews.llvm.org/D26195



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


[PATCH] D26196: AMDGPU: Translate null pointers in private and local addr space

2016-11-01 Thread Matt Arsenault via cfe-commits
arsenm added inline comments.



Comment at: test/CodeGenOpenCL/amdgpu-nullptr.cl:30
+
+// CHECK: icmp eq i8 addrspace(1)* %p, null
+void cmp_global(global char* p) {

Missing check-label


https://reviews.llvm.org/D26196



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


[PATCH] D26196: AMDGPU: Translate null pointers in private and local addr space

2016-11-01 Thread Matt Arsenault via cfe-commits
arsenm added inline comments.



Comment at: test/CodeGenOpenCL/amdgpu-nullptr.cl:49
+}
+

I think there need to be a lot more tests. A few I can think of:

  - Tests that compare to NULL instead of 0
  - Pointer compares without the explicit 0, i.e. if (p)/if(!p)
  - Storage of a pointer value
  - Calls with a pointer argument
  - Set of tests with constant address space pointers
  - Cast null to integer
  - Compare of null with null
  - Compare null in one address space with null in another





https://reviews.llvm.org/D26196



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


[PATCH] D26118: [clang-tidy] Change readability-redundant-member-init to get base type from constructor

2016-11-01 Thread Aaron Ballman via cfe-commits
aaron.ballman added a comment.

This change is missing a test case.




Comment at: clang-tidy/readability/RedundantMemberInitCheck.cpp:57
"initializer for base class %0 is redundant")
-  << Init->getTypeSourceInfo()->getType()
+  << Construct->getType()
   << FixItHint::CreateRemoval(Init->getSourceRange());

Why is it more correct to use the CXXConstructExpr type information rather than 
the CXXCtorInitializer?


Repository:
  rL LLVM

https://reviews.llvm.org/D26118



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


[PATCH] D26206: Fix Clang-tidy readability-redundant-string-cstr warnings

2016-11-01 Thread Malcolm Parsons via cfe-commits
malcolm.parsons created this revision.
malcolm.parsons added reviewers: aaron.ballman, mehdi_amini, dblaikie.
malcolm.parsons added a subscriber: cfe-commits.

https://reviews.llvm.org/D26206

Files:
  lib/ARCMigrate/FileRemapper.cpp
  lib/CodeGen/CGObjCGNU.cpp
  lib/CodeGen/TargetInfo.cpp
  lib/Driver/Driver.cpp
  lib/Driver/Job.cpp
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Frontend/Rewrite/RewriteModernObjC.cpp
  lib/Frontend/Rewrite/RewriteObjC.cpp
  lib/Parse/ParseDeclCXX.cpp
  lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp
  unittests/AST/ASTImporterTest.cpp

Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -72,7 +72,7 @@
   vfs::InMemoryFileSystem *MFS = static_cast(
 OFS->overlays_begin()->get());
   MFS->addFile(InputFileName, 0,
-   llvm::MemoryBuffer::getMemBuffer(FromCode.c_str()));
+   llvm::MemoryBuffer::getMemBuffer(FromCode));
 
   ASTImporter Importer(ToCtx, ToAST->getFileManager(),
FromCtx, FromAST->getFileManager(), false);
Index: lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp
===
--- lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp
+++ lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp
@@ -106,7 +106,7 @@
   SmallVector checkerOpts;
   for (unsigned i = 0, e = opts.CheckersControlList.size(); i != e; ++i) {
 const std::pair  = opts.CheckersControlList[i];
-checkerOpts.push_back(CheckerOptInfo(opt.first.c_str(), opt.second));
+checkerOpts.push_back(CheckerOptInfo(opt.first, opt.second));
   }
   return checkerOpts;
 }
Index: lib/Parse/ParseDeclCXX.cpp
===
--- lib/Parse/ParseDeclCXX.cpp
+++ lib/Parse/ParseDeclCXX.cpp
@@ -2234,7 +2234,7 @@
   if (!(Function.TypeQuals & TypeQual)) {
 std::string Name(FixItName);
 Name += " ";
-Insertion = FixItHint::CreateInsertion(VS.getFirstLocation(), Name.c_str());
+Insertion = FixItHint::CreateInsertion(VS.getFirstLocation(), Name);
 Function.TypeQuals |= TypeQual;
 *QualifierLoc = SpecLoc.getRawEncoding();
   }
Index: lib/Frontend/Rewrite/RewriteObjC.cpp
===
--- lib/Frontend/Rewrite/RewriteObjC.cpp
+++ lib/Frontend/Rewrite/RewriteObjC.cpp
@@ -4428,7 +4428,7 @@
 
   VarDecl *NewVD = VarDecl::Create(*Context, TUDecl,
SourceLocation(), SourceLocation(),
-   >Idents.get(DescData.c_str()),
+   >Idents.get(DescData),
Context->VoidPtrTy, nullptr,
SC_Static);
   UnaryOperator *DescRefExpr =
@@ -5650,12 +5650,12 @@
   InstanceMethods.push_back(Setter);
   }
   RewriteObjCMethodsMetaData(InstanceMethods.begin(), InstanceMethods.end(),
- true, "CATEGORY_", FullCategoryName.c_str(),
+ true, "CATEGORY_", FullCategoryName,
  Result);
   
   // Build _objc_method_list for class's class methods if needed
   RewriteObjCMethodsMetaData(IDecl->classmeth_begin(), IDecl->classmeth_end(),
- false, "CATEGORY_", FullCategoryName.c_str(),
+ false, "CATEGORY_", FullCategoryName,
  Result);
   
   // Protocols referenced in class declaration?
@@ -5776,7 +5776,7 @@
   Result += "{\n\t0, " + utostr(NumMethods) + "\n";
   
   Result += "\t,{{(SEL)\"";
-  Result += (*MethodBegin)->getSelector().getAsString().c_str();
+  Result += (*MethodBegin)->getSelector().getAsString();
   std::string MethodTypeString;
   Context->getObjCEncodingForMethodDecl(*MethodBegin, MethodTypeString);
   Result += "\", \"";
@@ -5786,7 +5786,7 @@
   Result += "}\n";
   for (++MethodBegin; MethodBegin != MethodEnd; ++MethodBegin) {
 Result += "\t  ,{(SEL)\"";
-Result += (*MethodBegin)->getSelector().getAsString().c_str();
+Result += (*MethodBegin)->getSelector().getAsString();
 std::string MethodTypeString;
 Context->getObjCEncodingForMethodDecl(*MethodBegin, MethodTypeString);
 Result += "\", \"";
Index: lib/Frontend/Rewrite/RewriteModernObjC.cpp
===
--- lib/Frontend/Rewrite/RewriteModernObjC.cpp
+++ lib/Frontend/Rewrite/RewriteModernObjC.cpp
@@ -865,7 +865,7 @@
   RecName += "_IMPL";
   RecordDecl *RD = RecordDecl::Create(*Context, TTK_Struct, TUDecl,
   SourceLocation(), SourceLocation(),
-  >Idents.get(RecName.c_str()));
+  

[PATCH] D26119: [clang-tidy] Handle bitfields in cppcoreguidelines-pro-type-member-init

2016-11-01 Thread Aaron Ballman via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM!


https://reviews.llvm.org/D26119



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


[PATCH] D26205: [clang-query] Fix Clang-tidy readability-redundant-string-cstr warnings

2016-11-01 Thread Malcolm Parsons via cfe-commits
malcolm.parsons created this revision.
malcolm.parsons added reviewers: pcc, dblaikie.
malcolm.parsons added a subscriber: cfe-commits.

https://reviews.llvm.org/D26205

Files:
  clang-query/tool/ClangQuery.cpp


Index: clang-query/tool/ClangQuery.cpp
===
--- clang-query/tool/ClangQuery.cpp
+++ clang-query/tool/ClangQuery.cpp
@@ -80,7 +80,7 @@
 for (cl::list::iterator I = Commands.begin(),
  E = Commands.end();
  I != E; ++I) {
-  QueryRef Q = QueryParser::parse(I->c_str(), QS);
+  QueryRef Q = QueryParser::parse(*I, QS);
   if (!Q->run(llvm::outs(), QS))
 return 1;
 }
@@ -97,7 +97,7 @@
 std::string Line;
 std::getline(Input, Line);
 
-QueryRef Q = QueryParser::parse(Line.c_str(), QS);
+QueryRef Q = QueryParser::parse(Line, QS);
 if (!Q->run(llvm::outs(), QS))
   return 1;
   }


Index: clang-query/tool/ClangQuery.cpp
===
--- clang-query/tool/ClangQuery.cpp
+++ clang-query/tool/ClangQuery.cpp
@@ -80,7 +80,7 @@
 for (cl::list::iterator I = Commands.begin(),
  E = Commands.end();
  I != E; ++I) {
-  QueryRef Q = QueryParser::parse(I->c_str(), QS);
+  QueryRef Q = QueryParser::parse(*I, QS);
   if (!Q->run(llvm::outs(), QS))
 return 1;
 }
@@ -97,7 +97,7 @@
 std::string Line;
 std::getline(Input, Line);
 
-QueryRef Q = QueryParser::parse(Line.c_str(), QS);
+QueryRef Q = QueryParser::parse(Line, QS);
 if (!Q->run(llvm::outs(), QS))
   return 1;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26061: [analyzer] Refactor and simplify SimpleConstraintManager

2016-11-01 Thread Dominic Chen via cfe-commits
ddcc added a comment.

Yes, I've been writing a Z3 solver interface, which motivated this patch. 
However, this patch has snowballed into something that it's a little too 
convoluted, so I'll split it up.

I'm not sure whether the RangedConstraintManager interface is useful or not; I 
preserved it because it's currently in the code, but since 
RangeConstraintManager is the only user, it is possible to merge the two 
together and eliminate the interface. In the past, BasicConstraintManager was 
the other class that used this interface, but that was deleted quite a while 
back, and I'm not sure if there are plans for anything else?


https://reviews.llvm.org/D26061



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


[PATCH] D25208: [libc++] Make _LIBCPP_TYPE_VIS export members

2016-11-01 Thread Shoaib Meenai via cfe-commits
smeenai added a comment.

Ping :)


https://reviews.llvm.org/D25208



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


[PATCH] D25074: [clang-tidy] Improve rename_check.py

2016-11-01 Thread Kirill Bobyrev via cfe-commits
omtcyfz updated this revision to Diff 76593.
omtcyfz added a comment.

Reversed "tabwidth:2 -> tabwidth:4" change.
Removed unused dependency (`re`).
Got rid of `sys.argv[0]` via using Pythonic `__file__` and removed (now) 
redundant dependency (`sys`).


https://reviews.llvm.org/D25074

Files:
  clang-tidy/rename_check.py

Index: clang-tidy/rename_check.py
===
--- clang-tidy/rename_check.py
+++ clang-tidy/rename_check.py
@@ -10,9 +10,9 @@
 #======#
 
 import os
-import re
-import sys
 import glob
+import argparse
+
 
 def replaceInFile(fileName, sFrom, sTo):
   if sFrom == sTo:
@@ -29,64 +29,79 @@
   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,'*'))
+  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', '*'))
+  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
+  parser = argparse.ArgumentParser(description='Rename clang-tidy check.')
+  parser.add_argument('module', type=str,
+  help='Module where the renamed check is defined')
+  parser.add_argument('old_check_name', type=str,
+  help='Old check name.')
+  parser.add_argument('new_check_name', type=str,
+  help='New check name.')
+  args = parser.parse_args()
 
-  module = sys.argv[1].lower()
-  check_name = sys.argv[2]
+  args.module = args.module.lower()
   check_name_camel = ''.join(map(lambda elem: elem.capitalize(),
- check_name.split('-'))) + 'Check'
-  check_name_new = sys.argv[3]
+ args.old_check_name.split('-'))) + 'Check'
   check_name_new_camel = ''.join(map(lambda elem: elem.capitalize(),
- check_name_new.split('-'))) + 'Check'
+ args.new_check_name.split('-'))) + \
+  'Check'
 
-  clang_tidy_path = os.path.dirname(sys.argv[0])
+  clang_tidy_path = os.path.dirname(__file__)
 
-  header_guard_old = module.upper() + '_' + check_name.upper().replace('-', '_')
-  header_guard_new = module.upper() + '_' + check_name_new.upper().replace('-', '_')
+  header_guard_old = args.module.upper() + '_' + \
+  args.old_check_name.upper().replace('-', '_')
+  header_guard_new = args.module.upper() + '_' + \
+  args.new_check_name.upper().replace('-', '_')
 
   for filename in getListOfFiles(clang_tidy_path):
 originalName = filename
-filename = fileRename(filename, check_name, check_name_new)
+filename = fileRename(filename, args.old_check_name,
+  args.new_check_name)
 filename = fileRename(filename, check_name_camel, check_name_new_camel)
-replaceInFile(filename, generateCommentLineHeader(originalName), generateCommentLineHeader(filename))
-replaceInFile(filename, generateCommentLineSource(originalName), generateCommentLineSource(filename))
+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)
+

[PATCH] D26203: [ClangTidy - performance-unnecessary-value-param]: Do not issue fix for functions that are referenced outside of callExpr

2016-11-01 Thread Felix Berger via cfe-commits
flx created this revision.
flx added reviewers: alexfh, sbenza.
flx added a subscriber: cfe-commits.
flx set the repository for this revision to rL LLVM.

Suppress fixes for functions that are referenced within the compilation unit 
outside of a call expression as the signature change could break the code 
referencing the function.

We still issue a warning in this case so that users can decide to manually 
change the function signature.


Repository:
  rL LLVM

https://reviews.llvm.org/D26203

Files:
  clang-tidy/performance/UnnecessaryValueParamCheck.cpp
  test/clang-tidy/performance-unnecessary-value-param.cpp


Index: test/clang-tidy/performance-unnecessary-value-param.cpp
===
--- test/clang-tidy/performance-unnecessary-value-param.cpp
+++ test/clang-tidy/performance-unnecessary-value-param.cpp
@@ -237,3 +237,21 @@
   ExpensiveToCopyType B;
   B = A;
 }
+
+void PositiveOnlyMessageAsReferencedInCompilationUnit(ExpensiveToCopyType A) {
+  // CHECK-MESSAGES: [[@LINE-1]]:75: warning: the parameter 'A' is copied
+  // CHECK-FIXES: void 
PositiveOnlyMessageAsReferencedInCompilationUnit(ExpensiveToCopyType A) {
+}
+
+void ReferenceFunctionOutsideOfCallExpr() {
+  void (*ptr)(ExpensiveToCopyType) = 

+}
+
+void PositiveMessageAndFixAsFunctionIsCalled(ExpensiveToCopyType A) {
+  // CHECK-MESSAGES: [[@LINE-1]]:66: warning: the parameter 'A' is copied
+  // CHECK-FIXES: void PositiveMessageAndFixAsFunctionIsCalled(const 
ExpensiveToCopyType& A) {
+}
+
+void ReferenceFunctionByCallingIt() {
+  PositiveMessageAndFixAsFunctionIsCalled(ExpensiveToCopyType());
+}
Index: clang-tidy/performance/UnnecessaryValueParamCheck.cpp
===
--- clang-tidy/performance/UnnecessaryValueParamCheck.cpp
+++ clang-tidy/performance/UnnecessaryValueParamCheck.cpp
@@ -39,6 +39,14 @@
   return true;
 }
 
+bool isReferencedOutsideOfCallExpr(const FunctionDecl ,
+   ASTContext ) {
+  auto Matches = match(declRefExpr(to(functionDecl(equalsNode())),
+   unless(hasAncestor(callExpr(,
+   Context);
+  return !Matches.empty();
+}
+
 } // namespace
 
 UnnecessaryValueParamCheck::UnnecessaryValueParamCheck(
@@ -118,10 +126,14 @@
   "invocation but only used as a const reference; "
   "consider making it a const reference")
   << paramNameOrIndex(Param->getName(), Index);
-  // Do not propose fixes in macros since we cannot place them correctly, or if
-  // function is virtual as it might break overrides.
+  // Do not propose fixes when:
+  // 1. in macros since we cannot place them correctly
+  // 2. the function is virtual as it might break overrides
+  // 3. the function is referenced outside of a call expression within the
+  //compilation unit as the signature change could introduce build errors.
   const auto *Method = llvm::dyn_cast(Function);
-  if (Param->getLocStart().isMacroID() || (Method && Method->isVirtual()))
+  if (Param->getLocStart().isMacroID() || (Method && Method->isVirtual()) ||
+  isReferencedOutsideOfCallExpr(*Function, *Result.Context))
 return;
   for (const auto *FunctionDecl = Function; FunctionDecl != nullptr;
FunctionDecl = FunctionDecl->getPreviousDecl()) {


Index: test/clang-tidy/performance-unnecessary-value-param.cpp
===
--- test/clang-tidy/performance-unnecessary-value-param.cpp
+++ test/clang-tidy/performance-unnecessary-value-param.cpp
@@ -237,3 +237,21 @@
   ExpensiveToCopyType B;
   B = A;
 }
+
+void PositiveOnlyMessageAsReferencedInCompilationUnit(ExpensiveToCopyType A) {
+  // CHECK-MESSAGES: [[@LINE-1]]:75: warning: the parameter 'A' is copied
+  // CHECK-FIXES: void PositiveOnlyMessageAsReferencedInCompilationUnit(ExpensiveToCopyType A) {
+}
+
+void ReferenceFunctionOutsideOfCallExpr() {
+  void (*ptr)(ExpensiveToCopyType) = 
+}
+
+void PositiveMessageAndFixAsFunctionIsCalled(ExpensiveToCopyType A) {
+  // CHECK-MESSAGES: [[@LINE-1]]:66: warning: the parameter 'A' is copied
+  // CHECK-FIXES: void PositiveMessageAndFixAsFunctionIsCalled(const ExpensiveToCopyType& A) {
+}
+
+void ReferenceFunctionByCallingIt() {
+  PositiveMessageAndFixAsFunctionIsCalled(ExpensiveToCopyType());
+}
Index: clang-tidy/performance/UnnecessaryValueParamCheck.cpp
===
--- clang-tidy/performance/UnnecessaryValueParamCheck.cpp
+++ clang-tidy/performance/UnnecessaryValueParamCheck.cpp
@@ -39,6 +39,14 @@
   return true;
 }
 
+bool isReferencedOutsideOfCallExpr(const FunctionDecl ,
+   ASTContext ) {
+  auto Matches = match(declRefExpr(to(functionDecl(equalsNode())),
+   unless(hasAncestor(callExpr(,
+   Context);
+  return 

[PATCH] D24235: [OpenCL] Improve double literal handling

2016-11-01 Thread Neil Hickey via cfe-commits
neil.hickey updated this revision to Diff 76587.
neil.hickey added a comment.

Sorry for the delay. It looks like the code to handle extensions was changed 
since Neil Henning added the check against opencl 1.2. Perhaps the best 
approach is just to remove the check.


https://reviews.llvm.org/D24235

Files:
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaType.cpp
  test/CodeGenOpenCL/fpmath.cl
  test/SemaOpenCL/extensions.cl

Index: test/SemaOpenCL/extensions.cl
===
--- test/SemaOpenCL/extensions.cl
+++ test/SemaOpenCL/extensions.cl
@@ -1,13 +1,16 @@
 // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only
 // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.1
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.2 -DFP64
 
 // Test with a target not supporting fp64.
 // RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -DNOFP64
 
+#if __OPENCL_C_VERSION__ < 120
 void f1(double da) { // expected-error {{type 'double' requires cl_khr_fp64 extension}}
   double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}}
   (void) 1.0; // expected-warning {{double precision constant requires cl_khr_fp64}}
 }
+#endif
 
 #pragma OPENCL EXTENSION cl_khr_fp64 : enable
 #ifdef NOFP64
@@ -21,16 +24,22 @@
 #endif
 
   (void) 1.0;
+#ifdef FP64
+// expected-no-diagnostics
+#endif
+
 #ifdef NOFP64
-// expected-warning@-2{{double precision constant requires cl_khr_fp64, casting to single precision}}
+// expected-warning@-6{{double precision constant requires cl_khr_fp64, casting to single precision}}
 #endif
 }
 
 #pragma OPENCL EXTENSION cl_khr_fp64 : disable
 #ifdef NOFP64
 // expected-warning@-2{{unsupported OpenCL extension 'cl_khr_fp64' - ignoring}}
 #endif
 
+#if __OPENCL_C_VERSION__ < 120
 void f3(void) {
   double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}}
 }
+#endif
Index: test/CodeGenOpenCL/fpmath.cl
===
--- test/CodeGenOpenCL/fpmath.cl
+++ test/CodeGenOpenCL/fpmath.cl
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown | FileCheck --check-prefix=CHECK --check-prefix=NODIVOPT %s
 // RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown -cl-fp32-correctly-rounded-divide-sqrt | FileCheck --check-prefix=CHECK --check-prefix=DIVOPT %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -DNOFP64 -cl-std=CL1.1 -triple r600-unknown-unknown -target-cpu r600 -pedantic | FileCheck --check-prefix=CHECK-DBL %s
 
 typedef __attribute__(( ext_vector_type(4) )) float float4;
 
@@ -21,14 +22,26 @@
   return a / b;
 }
 
+void printf(constant char* fmt, ...);
+
+#ifndef NOFP64
 #pragma OPENCL EXTENSION cl_khr_fp64 : enable
+#endif
+void testdbllit(long *val) {
+  // CHECK-DBL: float 2.00e+01
+  // CHECK: double 2.00e+01
+  printf("%f", 20.0);
+}
 
+#ifndef NOFP64
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
 double dpscalardiv(double a, double b) {
   // CHECK: @dpscalardiv
   // CHECK: #[[ATTR]]
   // CHECK-NOT: !fpmath
   return a / b;
 }
+#endif
 
 // CHECK: attributes #[[ATTR]] = {
 // NODIVOPT: "correctly-rounded-divide-sqrt-fp-math"="false"
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -1401,8 +1401,7 @@
   Result = Context.DoubleTy;
 
 if (S.getLangOpts().OpenCL &&
-!((S.getLangOpts().OpenCLVersion >= 120) ||
-  S.getOpenCLOptions().cl_khr_fp64)) {
+!(S.getOpenCLOptions().cl_khr_fp64)) {
   S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_requires_extension)
   << Result << "cl_khr_fp64";
   declarator.setInvalidType(true);
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -705,9 +705,13 @@
   if (getLangOpts().ObjCAutoRefCount &&
   E->getType().getObjCLifetime() == Qualifiers::OCL_Weak)
 Cleanup.setExprNeedsCleanups(true);
+  
+  ExprResult Res = E;
 
-  ExprResult Res = ImplicitCastExpr::Create(Context, T, CK_LValueToRValue, E,
-nullptr, VK_RValue);
+  if ( T != E->getType()) {
+Res = ImplicitCastExpr::Create(Context, T, CK_LValueToRValue, E,
+   nullptr, VK_RValue);
+  }
 
   // C11 6.3.2.1p2:
   //   ... if the lvalue has atomic type, the value has the non-atomic version 
@@ -817,8 +821,16 @@
   // double.
   const BuiltinType *BTy = Ty->getAs();
   if (BTy && (BTy->getKind() == BuiltinType::Half ||
-  BTy->getKind() == BuiltinType::Float))
-E = ImpCastExprToType(E, Context.DoubleTy, CK_FloatingCast).get();
+  BTy->getKind() == BuiltinType::Float)) {
+if (getLangOpts().OpenCL &&
+

[PATCH] D24010: [ReachableCode] Skip over ExprWithCleanups in isConfigurationValue

2016-11-01 Thread Ted Kremenek via cfe-commits
krememek added a comment.

LGTM.


Repository:
  rL LLVM

https://reviews.llvm.org/D24010



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


[PATCH] D26195: Ignore incomplete types when determining whether they are expensive to copy

2016-11-01 Thread Aaron Ballman via cfe-commits
aaron.ballman added a comment.

In https://reviews.llvm.org/D26195#584724, @flx wrote:

> In https://reviews.llvm.org/D26195#584712, @aaron.ballman wrote:
>
> > Please add a test case with an incomplete type that would exercise this 
> > code path, otherwise, LGTM.
>
>
> Hi Aaron,
>
> do you have any advise on how to add an incomplete type? When debugging this 
> I had a compilation unit that failed to compile causing it, but I'm not sure 
> this is a good way to add a test case.


A type like `class C;` is an incomplete type, as is `void`, so perhaps you can 
find a check that would let such a construct call through to 
`isExpensiveToCopy()`.


Repository:
  rL LLVM

https://reviews.llvm.org/D26195



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


[PATCH] D26195: Ignore incomplete types when determining whether they are expensive to copy

2016-11-01 Thread Felix Berger via cfe-commits
flx added a comment.

In https://reviews.llvm.org/D26195#584712, @aaron.ballman wrote:

> Please add a test case with an incomplete type that would exercise this code 
> path, otherwise, LGTM.


Hi Aaron,

do you have any advise on how to add an incomplete type? When debugging this I 
had a compilation unit that failed to compile causing it, but I'm not sure this 
is a good way to add a test case.


Repository:
  rL LLVM

https://reviews.llvm.org/D26195



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


[PATCH] D26189: Add a note that points to the linkage specifier for the "must have C++ linkage" errors

2016-11-01 Thread Alex Lorenz via cfe-commits
arphaman updated this revision to Diff 76577.
arphaman marked an inline comment as done.
arphaman added a comment.

The updated patch renames the note diagnostic to a more generic rename.


Repository:
  rL LLVM

https://reviews.llvm.org/D26189

Files:
  include/clang/AST/DeclBase.h
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/AST/DeclBase.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaTemplate.cpp
  test/CXX/over/over.oper/over.literal/p6.cpp
  test/SemaCXX/cxx0x-defaulted-functions.cpp
  test/SemaTemplate/class-template-decl.cpp

Index: test/SemaTemplate/class-template-decl.cpp
===
--- test/SemaTemplate/class-template-decl.cpp
+++ test/SemaTemplate/class-template-decl.cpp
@@ -10,11 +10,11 @@
   template class C;
 }
 
-extern "C" {
+extern "C" { // expected-note {{extern "C" language linkage specification begins here}}
   template class D; // expected-error{{templates must have C++ linkage}}
 }
 
-extern "C" {
+extern "C" { // expected-note 2 {{extern "C" language linkage specification begins here}}
   class PR17968 {
 template class D; // expected-error{{templates must have C++ linkage}}
 template void f(); // expected-error{{templates must have C++ linkage}}
@@ -148,7 +148,7 @@
 }
 
 extern "C" template  // expected-error{{templates must have C++ linkage}}
-void DontCrashOnThis() {
+void DontCrashOnThis() { // expected-note@-1 {{extern "C" language linkage specification begins here}}
   T  = T();
   pT;
 }
Index: test/SemaCXX/cxx0x-defaulted-functions.cpp
===
--- test/SemaCXX/cxx0x-defaulted-functions.cpp
+++ test/SemaCXX/cxx0x-defaulted-functions.cpp
@@ -180,7 +180,7 @@
   Outer::Inner2::~Inner2() = default; // expected-error {{nested name specifier 'Outer::Inner2::' for declaration does not refer into a class, class template or class template partial specialization}}  expected-error {{only special member functions may be defaulted}}
 }
 
-extern "C" {
+extern "C" { // expected-note {{extern "C" language linkage specification begins here}}
  template // expected-error {{templates must have C++ linkage}}
  void PR13573(const _Tp&) = delete;
 }
Index: test/CXX/over/over.oper/over.literal/p6.cpp
===
--- test/CXX/over/over.oper/over.literal/p6.cpp
+++ test/CXX/over/over.oper/over.literal/p6.cpp
@@ -1,9 +1,11 @@
 // RUN: %clang_cc1 -std=c++11 %s -verify
 
+// expected-note@+1 {{extern "C" language linkage specification begins here}}
 extern "C" void operator "" _a(const char *); // expected-error {{must have C++ linkage}}
 extern "C" template void operator "" _b(); // expected-error {{must have C++ linkage}}
+// expected-note@-1 {{extern "C" language linkage specification begins here}}
 
-extern "C" {
+extern "C" { // expected-note 4 {{extern "C" language linkage specification begins here}}
   void operator "" _c(const char *); // expected-error {{must have C++ linkage}}
   template void operator "" _d(); // expected-error {{must have C++ linkage}}
   namespace N {
Index: lib/Sema/SemaTemplate.cpp
===
--- lib/Sema/SemaTemplate.cpp
+++ lib/Sema/SemaTemplate.cpp
@@ -5939,9 +5939,13 @@
   // C++ [temp]p4:
   //   A template [...] shall not have C linkage.
   DeclContext *Ctx = S->getEntity();
-  if (Ctx && Ctx->isExternCContext())
-return Diag(TemplateParams->getTemplateLoc(), diag::err_template_linkage)
- << TemplateParams->getSourceRange();
+  if (Ctx && Ctx->isExternCContext()) {
+Diag(TemplateParams->getTemplateLoc(), diag::err_template_linkage)
+<< TemplateParams->getSourceRange();
+if (const LinkageSpecDecl *LSD = Ctx->getExternCContext())
+  Diag(LSD->getExternLoc(), diag::note_extern_c_begins_here);
+return true;
+  }
   Ctx = Ctx->getRedeclContext();
 
   // C++ [temp]p2:
Index: lib/Sema/SemaDeclCXX.cpp
===
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -12757,6 +12757,9 @@
 
   if (FnDecl->isExternC()) {
 Diag(FnDecl->getLocation(), diag::err_literal_operator_extern_c);
+if (const LinkageSpecDecl *LSD =
+FnDecl->getDeclContext()->getExternCContext())
+  Diag(LSD->getExternLoc(), diag::note_extern_c_begins_here);
 return true;
   }
 
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -15332,7 +15332,7 @@
   } else if (!M->IsExternC && ExternCLoc.isValid()) {
 S.Diag(ImportLoc, diag::ext_module_import_in_extern_c)
   << M->getFullModuleName();
-S.Diag(ExternCLoc, diag::note_module_import_in_extern_c);
+S.Diag(ExternCLoc, diag::note_extern_c_begins_here);
   }
 }
 
Index: lib/AST/DeclBase.cpp

[PATCH] D26195: Ignore incomplete types when determining whether they are expensive to copy

2016-11-01 Thread Aaron Ballman via cfe-commits
aaron.ballman added a comment.

Please add a test case with an incomplete type that would exercise this code 
path, otherwise, LGTM.


Repository:
  rL LLVM

https://reviews.llvm.org/D26195



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


[PATCH] D26197: Protect tests for new/delete under libcpp-no-exceptions

2016-11-01 Thread Roger Ferrer Ibanez via cfe-commits
rogfer01 created this revision.
rogfer01 added reviewers: EricWF, mclow.lists, rmaprath.
rogfer01 added a subscriber: cfe-commits.

Skip the tests that expect an exception be thrown and protect unreachable catch 
blocks.


https://reviews.llvm.org/D26197

Files:
  
test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array.pass.cpp
  
test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array_nothrow.pass.cpp
  
test/std/language.support/support.dynamic/new.delete/new.delete.single/new.pass.cpp
  
test/std/language.support/support.dynamic/new.delete/new.delete.single/new_nothrow.pass.cpp

Index: test/std/language.support/support.dynamic/new.delete/new.delete.single/new_nothrow.pass.cpp
===
--- test/std/language.support/support.dynamic/new.delete/new.delete.single/new_nothrow.pass.cpp
+++ test/std/language.support/support.dynamic/new.delete/new.delete.single/new_nothrow.pass.cpp
@@ -7,7 +7,6 @@
 //
 //===--===//
 
-// XFAIL: libcpp-no-exceptions
 // test operator new (nothrow)
 
 // asan and msan will not call the new handler.
@@ -18,6 +17,8 @@
 #include 
 #include 
 
+#include "test_macros.h"
+
 int new_handler_called = 0;
 
 void new_handler()
@@ -37,16 +38,20 @@
 int main()
 {
 std::set_new_handler(new_handler);
+#ifndef TEST_HAS_NO_EXCEPTIONS
 try
+#endif
 {
 void* vp = operator new (std::numeric_limits::max(), std::nothrow);
 assert(new_handler_called == 1);
 assert(vp == 0);
 }
+#ifndef TEST_HAS_NO_EXCEPTIONS
 catch (...)
 {
 assert(false);
 }
+#endif
 A* ap = new(std::nothrow) A;
 assert(ap);
 assert(A_constructed);
Index: test/std/language.support/support.dynamic/new.delete/new.delete.single/new.pass.cpp
===
--- test/std/language.support/support.dynamic/new.delete/new.delete.single/new.pass.cpp
+++ test/std/language.support/support.dynamic/new.delete/new.delete.single/new.pass.cpp
@@ -7,8 +7,6 @@
 //
 //===--===//
 
-// XFAIL: libcpp-no-exceptions
-
 // test operator new
 
 // asan and msan will not call the new handler.
@@ -19,6 +17,8 @@
 #include 
 #include 
 
+#include "test_macros.h"
+
 int new_handler_called = 0;
 
 void new_handler()
@@ -37,6 +37,7 @@
 
 int main()
 {
+#ifndef TEST_HAS_NO_EXCEPTIONS
 std::set_new_handler(new_handler);
 try
 {
@@ -52,6 +53,7 @@
 {
 assert(false);
 }
+#endif
 A* ap = new A;
 assert(ap);
 assert(A_constructed);
Index: test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array_nothrow.pass.cpp
===
--- test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array_nothrow.pass.cpp
+++ test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array_nothrow.pass.cpp
@@ -7,7 +7,6 @@
 //
 //===--===//
 
-// XFAIL: libcpp-no-exceptions
 // test operator new [] (nothrow)
 // NOTE: asan and msan will not call the new handler.
 // UNSUPPORTED: sanitizer-new-delete
@@ -18,6 +17,8 @@
 #include 
 #include 
 
+#include "test_macros.h"
+
 int new_handler_called = 0;
 
 void new_handler()
@@ -37,16 +38,20 @@
 int main()
 {
 std::set_new_handler(new_handler);
+#ifndef TEST_HAS_NO_EXCEPTIONS
 try
+#endif TEST_HAS_NO_EXCEPTIONS
 {
 void*volatile vp = operator new [] (std::numeric_limits::max(), std::nothrow);
 assert(new_handler_called == 1);
 assert(vp == 0);
 }
+#ifndef TEST_HAS_NO_EXCEPTIONS
 catch (...)
 {
 assert(false);
 }
+#endif
 A* ap = new(std::nothrow) A[3];
 assert(ap);
 assert(A_constructed == 3);
Index: test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array.pass.cpp
===
--- test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array.pass.cpp
+++ test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array.pass.cpp
@@ -7,7 +7,6 @@
 //
 //===--===//
 
-// XFAIL: libcpp-no-exceptions
 // test operator new[]
 // NOTE: asan and msan will not call the new handler.
 // UNSUPPORTED: sanitizer-new-delete
@@ -18,6 +17,8 @@
 #include 
 #include 
 
+#include "test_macros.h"
+
 int new_handler_called = 0;
 
 void new_handler()
@@ -36,6 +37,7 @@
 
 int main()
 {
+#ifndef TEST_HAS_NO_EXCEPTIONS
 std::set_new_handler(new_handler);
 try
 {
@@ -51,6 +53,7 @@
 {
 assert(false);
 }
+#endif
 A* ap = new A[3];
 assert(ap);
 assert(A_constructed == 3);

[PATCH] D26196: AMDGPU: Translate null pointers in private and local addr space

2016-11-01 Thread Yaxun Liu via cfe-commits
yaxunl created this revision.
yaxunl added reviewers: arsenm, tstellarAMD, rjmccall.
yaxunl added a subscriber: cfe-commits.
Herald added subscribers: tony-tye, nhaehnle, wdng, kzhuravl.

In amdgcn target, null pointers in global, constant, and generic address space 
take value 0 but null pointers in private and local address space take value 
-1. Currently LLVM assumes all null pointers take value 0, which results in 
incorrectly translated IR. To workaround this issue, instead of emit null 
pointers in local and private address space, a null pointer in generic address 
space is emitted and casted to local and private address space.

A virtual member function translateNullPtr is added to TargetCodeGenInfo which 
by default does nothing. Each target can override this virtual function for 
translating null pointers.

A wrapper function translateNullPtr is added to CodegenModule to facilitate 
performing the target specific translation of null pointers.

This change has no effect on other targets except amdgcn target.


https://reviews.llvm.org/D26196

Files:
  lib/CodeGen/CGExprConstant.cpp
  lib/CodeGen/CGExprScalar.cpp
  lib/CodeGen/CodeGenModule.h
  lib/CodeGen/TargetInfo.cpp
  lib/CodeGen/TargetInfo.h
  test/CodeGenOpenCL/amdgpu-nullptr.cl

Index: test/CodeGenOpenCL/amdgpu-nullptr.cl
===
--- /dev/null
+++ test/CodeGenOpenCL/amdgpu-nullptr.cl
@@ -0,0 +1,49 @@
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -triple amdgcn -emit-llvm -o - | FileCheck %s
+
+// CHECK: @private_p = local_unnamed_addr addrspace(1) global i8* addrspacecast (i8 addrspace(4)* null to i8*), align 4
+private char *private_p = 0;
+
+// CHECK: @local_p = local_unnamed_addr addrspace(1) global i8 addrspace(3)* addrspacecast (i8 addrspace(4)* null to i8 addrspace(3)*), align 4
+local char *local_p = 0;
+
+// CHECK: @global_p = local_unnamed_addr addrspace(1) global i8 addrspace(1)* null, align 4
+global char *global_p = 0;
+
+// CHECK: @constant_p = local_unnamed_addr addrspace(1) global i8 addrspace(2)* null, align 4
+constant char *constant_p = 0;
+
+// CHECK: @generic_p = local_unnamed_addr addrspace(1) global i8 addrspace(4)* null, align 4
+generic char *generic_p = 0;
+
+// CHECK: icmp eq i8* %p, addrspacecast (i8 addrspace(4)* null to i8*)
+void cmp_private(private char* p) {
+  if (p != 0)
+*p = 0;
+}
+
+// CHECK: icmp eq i8 addrspace(3)* %p, addrspacecast (i8 addrspace(4)* null to i8 addrspace(3)*)
+void cmp_local(local char* p) {
+  if (p != 0)
+*p = 0;
+}
+
+// CHECK: icmp eq i8 addrspace(1)* %p, null
+void cmp_global(global char* p) {
+  if (p != 0)
+*p = 0;
+}
+
+// CHECK: icmp eq i8 addrspace(2)* %p, null
+char cmp_constant(constant char* p) {
+  if (p != 0)
+return *p;
+  else
+return 0;
+}
+
+// CHECK: icmp eq i8 addrspace(4)* %p, null
+void cmp_generic(generic char* p) {
+  if (p != 0)
+*p = 0;
+}
+
Index: lib/CodeGen/TargetInfo.h
===
--- lib/CodeGen/TargetInfo.h
+++ lib/CodeGen/TargetInfo.h
@@ -220,6 +220,13 @@
 
   /// Get LLVM calling convention for OpenCL kernel.
   virtual unsigned getOpenCLKernelCallingConv() const;
+
+  /// Translate null pointer to target specific value.
+  virtual llvm::Constant *translateNullPtr(const CodeGen::CodeGenModule ,
+  llvm::Constant *C) const {
+return C;
+  }
+
 };
 
 } // namespace CodeGen
Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -6953,6 +6953,9 @@
   void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
CodeGen::CodeGenModule ) const override;
   unsigned getOpenCLKernelCallingConv() const override;
+
+  llvm::Constant *translateNullPtr(const CodeGen::CodeGenModule ,
+  llvm::Constant *C) const override;
 };
 
 }
@@ -7018,6 +7021,30 @@
   return llvm::CallingConv::AMDGPU_KERNEL;
 }
 
+// In amdgcn target the null pointer in global, constant, and generic
+// address space has value 0 but in private and local address space has
+// value -1. Currently LLVM assumes null pointers always have value 0,
+// which results in incorrectly transformed IR. Therefore, instead of
+// emitting null pointers in private and local address spaces, a null
+// pointer in generic address space is emitted which is casted to a
+// pointer in local or private address space.
+llvm::Constant *AMDGPUTargetCodeGenInfo::translateNullPtr(
+const CodeGen::CodeGenModule , llvm::Constant *C) const {
+  if (!isa(C))
+return C;
+  auto PT = cast(C->getType());
+  auto  = CGM.getContext();
+  auto AS = PT->getAddressSpace();
+  if (CGM.getTarget().getTriple().getArch() != llvm::Triple::amdgcn ||
+(AS != Ctx.getTargetAddressSpace(LangAS::opencl_local) && AS != 0))
+return C;
+
+  auto NPT = llvm::PointerType::get(PT->getElementType(),
+  

[PATCH] D24448: [atomics] New warning -Watomic-libcall when atomic operation expands to a library call

2016-11-01 Thread Simon Dardis via cfe-commits
sdardis added a comment.

Ping.


https://reviews.llvm.org/D24448



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


[PATCH] D23712: [OpenCL] Override supported OpenCL extensions with -cl-ext option

2016-11-01 Thread Alexey Bader via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL285700: [OpenCL] Override supported OpenCL extensions with 
-cl-ext option (authored by bader).

Changed prior to commit:
  https://reviews.llvm.org/D23712?vs=75568=76571#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D23712

Files:
  cfe/trunk/include/clang/Basic/OpenCLOptions.h
  cfe/trunk/include/clang/Basic/TargetInfo.h
  cfe/trunk/include/clang/Basic/TargetOptions.h
  cfe/trunk/include/clang/Driver/CC1Options.td
  cfe/trunk/lib/Basic/Targets.cpp
  cfe/trunk/lib/Frontend/CompilerInvocation.cpp
  cfe/trunk/test/SemaOpenCL/extensions.cl

Index: cfe/trunk/include/clang/Driver/CC1Options.td
===
--- cfe/trunk/include/clang/Driver/CC1Options.td
+++ cfe/trunk/include/clang/Driver/CC1Options.td
@@ -688,6 +688,13 @@
   HelpText<"include a detailed record of preprocessing actions">;
 
 //===--===//
+// OpenCL Options
+//===--===//
+
+def cl_ext_EQ : CommaJoined<["-"], "cl-ext=">,
+  HelpText<"OpenCL only. Enable or disable OpenCL extensions. The argument is a comma-separated sequence of one or more extension names, each prefixed by '+' or '-'.">;
+
+//===--===//
 // CUDA Options
 //===--===//
 
Index: cfe/trunk/include/clang/Basic/TargetInfo.h
===
--- cfe/trunk/include/clang/Basic/TargetInfo.h
+++ cfe/trunk/include/clang/Basic/TargetInfo.h
@@ -995,6 +995,13 @@
   /// \brief Set supported OpenCL extensions and optional core features.
   virtual void setSupportedOpenCLOpts() {}
 
+  /// \brief Set supported OpenCL extensions as written on command line
+  virtual void setOpenCLExtensionOpts() {
+for (const auto  : getTargetOpts().OpenCLExtensionsAsWritten) {
+  getTargetOpts().SupportedOpenCLOptions.set(Ext);
+}
+  }
+
   /// \brief Get supported OpenCL extensions and optional core features.
   OpenCLOptions () {
 return getTargetOpts().SupportedOpenCLOptions;
Index: cfe/trunk/include/clang/Basic/TargetOptions.h
===
--- cfe/trunk/include/clang/Basic/TargetOptions.h
+++ cfe/trunk/include/clang/Basic/TargetOptions.h
@@ -58,6 +58,10 @@
 
   /// Supported OpenCL extensions and optional core features.
   OpenCLOptions SupportedOpenCLOptions;
+
+  /// \brief The list of OpenCL extensions to enable or disable, as written on
+  /// the command line.
+  std::vector OpenCLExtensionsAsWritten;
 };
 
 }  // end namespace clang
Index: cfe/trunk/include/clang/Basic/OpenCLOptions.h
===
--- cfe/trunk/include/clang/Basic/OpenCLOptions.h
+++ cfe/trunk/include/clang/Basic/OpenCLOptions.h
@@ -15,6 +15,8 @@
 #ifndef LLVM_CLANG_BASIC_OPENCLOPTIONS_H
 #define LLVM_CLANG_BASIC_OPENCLOPTIONS_H
 
+#include "llvm/ADT/StringRef.h"
+
 namespace clang {
 
 /// \brief OpenCL supported extensions and optional core features
@@ -28,9 +30,39 @@
 #include "clang/Basic/OpenCLExtensions.def"
   }
 
-  // Enable all options.
-  void setAll() {
-#define OPENCLEXT(nm)   nm = 1;
+  // Enable or disable all options.
+  void setAll(bool Enable = true) {
+#define OPENCLEXT(nm)   nm = Enable;
+#include "clang/Basic/OpenCLExtensions.def"
+  }
+
+  /// \brief Enable or disable support for OpenCL extensions
+  /// \param Ext name of the extension optionally prefixed with
+  ///'+' or '-'
+  /// \param Enable used when \p Ext is not prefixed by '+' or '-'
+  void set(llvm::StringRef Ext, bool Enable = true) {
+assert(!Ext.empty() && "Extension is empty.");
+
+switch (Ext[0]) {
+case '+':
+  Enable = true;
+  Ext = Ext.drop_front();
+  break;
+case '-':
+  Enable = false;
+  Ext = Ext.drop_front();
+  break;
+}
+
+if (Ext.equals("all")) {
+  setAll(Enable);
+  return;
+}
+
+#define OPENCLEXT(nm)   \
+if (Ext.equals(#nm)) {  \
+  nm = Enable;  \
+}
 #include "clang/Basic/OpenCLExtensions.def"
   }
 
Index: cfe/trunk/test/SemaOpenCL/extensions.cl
===
--- cfe/trunk/test/SemaOpenCL/extensions.cl
+++ cfe/trunk/test/SemaOpenCL/extensions.cl
@@ -2,7 +2,26 @@
 // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.1
 
 // Test with a target not supporting fp64.
-// RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -DNOFP64
+// RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -DNOFP64 -DNOFP16
+
+// Test with some extensions enabled or disabled by cmd-line 

r285700 - [OpenCL] Override supported OpenCL extensions with -cl-ext option

2016-11-01 Thread Alexey Bader via cfe-commits
Author: bader
Date: Tue Nov  1 10:50:52 2016
New Revision: 285700

URL: http://llvm.org/viewvc/llvm-project?rev=285700=rev
Log:
[OpenCL] Override supported OpenCL extensions with -cl-ext option

Summary:
This patch adds a command line option '-cl-ext' to control a set of
supported OpenCL extensions. Option accepts a comma-separated list
of extensions prefixed with '+' or '-'.

It can be used together with a target triple to override support for some
extensions:

  // spir target supports all extensions, but we want to disable fp64
  clang -cc1 -triple spir-unknown-unknown -cl-ext=-cl_khr_fp64

Special 'all' extension allows to enable or disable all possible
extensions:

  // only fp64 will be supported
  clang -cc1 -triple spir-unknown-unknown -cl-ext=-all,+cl_khr_fp64

Patch by asavonic (Andrew Savonichev).

Reviewers: joey, yaxunl

Subscribers: yaxunl, bader, Anastasia, cfe-commits

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



Modified:
cfe/trunk/include/clang/Basic/OpenCLOptions.h
cfe/trunk/include/clang/Basic/TargetInfo.h
cfe/trunk/include/clang/Basic/TargetOptions.h
cfe/trunk/include/clang/Driver/CC1Options.td
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/test/SemaOpenCL/extensions.cl

Modified: cfe/trunk/include/clang/Basic/OpenCLOptions.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/OpenCLOptions.h?rev=285700=285699=285700=diff
==
--- cfe/trunk/include/clang/Basic/OpenCLOptions.h (original)
+++ cfe/trunk/include/clang/Basic/OpenCLOptions.h Tue Nov  1 10:50:52 2016
@@ -15,6 +15,8 @@
 #ifndef LLVM_CLANG_BASIC_OPENCLOPTIONS_H
 #define LLVM_CLANG_BASIC_OPENCLOPTIONS_H
 
+#include "llvm/ADT/StringRef.h"
+
 namespace clang {
 
 /// \brief OpenCL supported extensions and optional core features
@@ -28,9 +30,39 @@ public:
 #include "clang/Basic/OpenCLExtensions.def"
   }
 
-  // Enable all options.
-  void setAll() {
-#define OPENCLEXT(nm)   nm = 1;
+  // Enable or disable all options.
+  void setAll(bool Enable = true) {
+#define OPENCLEXT(nm)   nm = Enable;
+#include "clang/Basic/OpenCLExtensions.def"
+  }
+
+  /// \brief Enable or disable support for OpenCL extensions
+  /// \param Ext name of the extension optionally prefixed with
+  ///'+' or '-'
+  /// \param Enable used when \p Ext is not prefixed by '+' or '-'
+  void set(llvm::StringRef Ext, bool Enable = true) {
+assert(!Ext.empty() && "Extension is empty.");
+
+switch (Ext[0]) {
+case '+':
+  Enable = true;
+  Ext = Ext.drop_front();
+  break;
+case '-':
+  Enable = false;
+  Ext = Ext.drop_front();
+  break;
+}
+
+if (Ext.equals("all")) {
+  setAll(Enable);
+  return;
+}
+
+#define OPENCLEXT(nm)   \
+if (Ext.equals(#nm)) {  \
+  nm = Enable;  \
+}
 #include "clang/Basic/OpenCLExtensions.def"
   }
 

Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=285700=285699=285700=diff
==
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Tue Nov  1 10:50:52 2016
@@ -995,6 +995,13 @@ public:
   /// \brief Set supported OpenCL extensions and optional core features.
   virtual void setSupportedOpenCLOpts() {}
 
+  /// \brief Set supported OpenCL extensions as written on command line
+  virtual void setOpenCLExtensionOpts() {
+for (const auto  : getTargetOpts().OpenCLExtensionsAsWritten) {
+  getTargetOpts().SupportedOpenCLOptions.set(Ext);
+}
+  }
+
   /// \brief Get supported OpenCL extensions and optional core features.
   OpenCLOptions () {
 return getTargetOpts().SupportedOpenCLOptions;

Modified: cfe/trunk/include/clang/Basic/TargetOptions.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetOptions.h?rev=285700=285699=285700=diff
==
--- cfe/trunk/include/clang/Basic/TargetOptions.h (original)
+++ cfe/trunk/include/clang/Basic/TargetOptions.h Tue Nov  1 10:50:52 2016
@@ -58,6 +58,10 @@ public:
 
   /// Supported OpenCL extensions and optional core features.
   OpenCLOptions SupportedOpenCLOptions;
+
+  /// \brief The list of OpenCL extensions to enable or disable, as written on
+  /// the command line.
+  std::vector OpenCLExtensionsAsWritten;
 };
 
 }  // end namespace clang

Modified: cfe/trunk/include/clang/Driver/CC1Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=285700=285699=285700=diff
==
--- cfe/trunk/include/clang/Driver/CC1Options.td (original)
+++ cfe/trunk/include/clang/Driver/CC1Options.td Tue Nov  1 

[PATCH] D24082: [CMake] Fix libc++abi arm build w/o libunwind.

2016-11-01 Thread Logan Chien via cfe-commits
logan added a comment.

Hi @EricWF:

Thanks for your comment.

However, I think `OFF` is a better default for ARM (just like other platforms.) 
 I usually use `libc++abi` without `libunwind` since `libgcc` is quite stable 
and usually linked by default.  Besides, it is much more tricky to get the 
libc++/libc++abi/libunwind/compiler-rt combo work.  The situation goes even 
worse when you are linking `libgcc` together.

Logan


https://reviews.llvm.org/D24082



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


[PATCH] D26136: Protect exceptional path under libcpp-no-exceptions

2016-11-01 Thread Roger Ferrer Ibanez via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL285697: Protect exceptional paths under libcpp-no-exceptions 
(authored by rogfer01).

Changed prior to commit:
  https://reviews.llvm.org/D26136?vs=76566=76567#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26136

Files:
  libcxx/trunk/test/std/strings/basic.string/string.access/at.pass.cpp
  libcxx/trunk/test/std/strings/basic.string/string.capacity/reserve.pass.cpp
  
libcxx/trunk/test/std/strings/basic.string/string.capacity/resize_size.pass.cpp
  
libcxx/trunk/test/std/strings/basic.string/string.capacity/resize_size_char.pass.cpp
  libcxx/trunk/test/std/strings/basic.string/string.cons/substr.pass.cpp
  
libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/T_size_size.pass.cpp
  
libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/string_size_size.pass.cpp
  
libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/T_size_size.pass.cpp
  
libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/string_size_size.pass.cpp
  
libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_copy/copy.pass.cpp
  
libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_erase/size_size.pass.cpp
  
libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_T_size_size.pass.cpp
  
libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer.pass.cpp
  
libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer_size.pass.cpp
  
libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_size_char.pass.cpp
  
libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_string.pass.cpp
  
libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_string_size_size.pass.cpp
  
libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_T_size_size.pass.cpp
  
libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer.pass.cpp
  
libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer_size.pass.cpp
  
libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_size_char.pass.cpp
  
libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string.pass.cpp
  
libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string_size_size.pass.cpp
  
libcxx/trunk/test/std/strings/basic.string/string.ops/string_compare/size_size_T_size_size.pass.cpp
  
libcxx/trunk/test/std/strings/basic.string/string.ops/string_compare/size_size_pointer.pass.cpp
  
libcxx/trunk/test/std/strings/basic.string/string.ops/string_compare/size_size_pointer_size.pass.cpp
  
libcxx/trunk/test/std/strings/basic.string/string.ops/string_compare/size_size_string.pass.cpp
  
libcxx/trunk/test/std/strings/basic.string/string.ops/string_compare/size_size_string_size_size.pass.cpp

Index: libcxx/trunk/test/std/strings/basic.string/string.capacity/resize_size.pass.cpp
===
--- libcxx/trunk/test/std/strings/basic.string/string.capacity/resize_size.pass.cpp
+++ libcxx/trunk/test/std/strings/basic.string/string.capacity/resize_size.pass.cpp
@@ -7,7 +7,6 @@
 //
 //===--===//
 
-// XFAIL: libcpp-no-exceptions
 // 
 
 // void resize(size_type n);
@@ -23,17 +22,26 @@
 void
 test(S s, typename S::size_type n, S expected)
 {
-try
+if (n <= s.max_size())
 {
 s.resize(n);
 LIBCPP_ASSERT(s.__invariants());
-assert(n <= s.max_size());
 assert(s == expected);
 }
-catch (std::length_error&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+else
 {
-assert(n > s.max_size());
+try
+{
+s.resize(n);
+assert(false);
+}
+catch (std::length_error&)
+{
+assert(n > s.max_size());
+}
 }
+#endif
 }
 
 int main()
Index: libcxx/trunk/test/std/strings/basic.string/string.capacity/reserve.pass.cpp
===
--- libcxx/trunk/test/std/strings/basic.string/string.capacity/reserve.pass.cpp
+++ libcxx/trunk/test/std/strings/basic.string/string.capacity/reserve.pass.cpp
@@ -7,7 +7,6 @@
 //
 //===--===//
 
-// XFAIL: libcpp-no-exceptions
 // 
 
 // void reserve(size_type res_arg=0);
@@ -38,18 +37,27 @@
 {
 typename S::size_type old_cap = s.capacity();
 S s0 = s;
-try
+if (res_arg <= s.max_size())
 {
 s.reserve(res_arg);
-assert(res_arg <= s.max_size());
 assert(s == s0);
 assert(s.capacity() >= res_arg);
 assert(s.capacity() >= s.size());
 }
-catch 

[libcxx] r285697 - Protect exceptional paths under libcpp-no-exceptions

2016-11-01 Thread Roger Ferrer Ibanez via cfe-commits
Author: rogfer01
Date: Tue Nov  1 10:46:16 2016
New Revision: 285697

URL: http://llvm.org/viewvc/llvm-project?rev=285697=rev
Log:
Protect exceptional paths under libcpp-no-exceptions

These tests are of the form

try {
   action-that-may-throw
   assert(!exceptional-condition)
   assert(some-other-facts)
 } catch (relevant-exception) {
   assert(exceptional-condition)
 }

Under libcpp-no-exceptions there is still value in verifying
some-other-facts while avoiding the exceptional case. So for these tests
just conditionally check some-other-facts if exceptional-condition is
false. When exception are supported make sure that a true
exceptional-condition throws an exception

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


Modified:
libcxx/trunk/test/std/strings/basic.string/string.access/at.pass.cpp
libcxx/trunk/test/std/strings/basic.string/string.capacity/reserve.pass.cpp

libcxx/trunk/test/std/strings/basic.string/string.capacity/resize_size.pass.cpp

libcxx/trunk/test/std/strings/basic.string/string.capacity/resize_size_char.pass.cpp
libcxx/trunk/test/std/strings/basic.string/string.cons/substr.pass.cpp

libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/T_size_size.pass.cpp

libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/string_size_size.pass.cpp

libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/T_size_size.pass.cpp

libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/string_size_size.pass.cpp

libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_copy/copy.pass.cpp

libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_erase/size_size.pass.cpp

libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_T_size_size.pass.cpp

libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer.pass.cpp

libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer_size.pass.cpp

libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_size_char.pass.cpp

libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_string.pass.cpp

libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_string_size_size.pass.cpp

libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_T_size_size.pass.cpp

libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer.pass.cpp

libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer_size.pass.cpp

libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_size_char.pass.cpp

libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string.pass.cpp

libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string_size_size.pass.cpp

libcxx/trunk/test/std/strings/basic.string/string.ops/string_compare/size_size_T_size_size.pass.cpp

libcxx/trunk/test/std/strings/basic.string/string.ops/string_compare/size_size_pointer.pass.cpp

libcxx/trunk/test/std/strings/basic.string/string.ops/string_compare/size_size_pointer_size.pass.cpp

libcxx/trunk/test/std/strings/basic.string/string.ops/string_compare/size_size_string.pass.cpp

libcxx/trunk/test/std/strings/basic.string/string.ops/string_compare/size_size_string_size_size.pass.cpp

Modified: libcxx/trunk/test/std/strings/basic.string/string.access/at.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.access/at.pass.cpp?rev=285697=285696=285697=diff
==
--- libcxx/trunk/test/std/strings/basic.string/string.access/at.pass.cpp 
(original)
+++ libcxx/trunk/test/std/strings/basic.string/string.access/at.pass.cpp Tue 
Nov  1 10:46:16 2016
@@ -7,7 +7,6 @@
 //
 
//===--===//
 
-// XFAIL: libcpp-no-exceptions
 // 
 
 // const_reference at(size_type pos) const;
@@ -19,21 +18,41 @@
 
 #include "min_allocator.h"
 
+#include "test_macros.h"
+
 template 
 void
 test(S s, typename S::size_type pos)
 {
-try
+const S& cs = s;
+if (pos < s.size())
 {
-const S& cs = s;
 assert(s.at(pos) == s[pos]);
 assert(cs.at(pos) == cs[pos]);
-assert(pos < cs.size());
 }
-catch (std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+else
 {
-assert(pos >= s.size());
+try
+{
+s.at(pos);
+assert(false);
+}
+catch (std::out_of_range&)
+{
+assert(pos >= s.size());
+}
+try
+{
+cs.at(pos);
+assert(false);
+}
+catch (std::out_of_range&)

[PATCH] D26136: Protect exceptional path under libcpp-no-exceptions

2016-11-01 Thread Roger Ferrer Ibanez via cfe-commits
rogfer01 updated this revision to Diff 76566.
rogfer01 added a comment.

Const-ify variables.


https://reviews.llvm.org/D26136

Files:
  test/std/strings/basic.string/string.access/at.pass.cpp
  test/std/strings/basic.string/string.capacity/reserve.pass.cpp
  test/std/strings/basic.string/string.capacity/resize_size.pass.cpp
  test/std/strings/basic.string/string.capacity/resize_size_char.pass.cpp
  test/std/strings/basic.string/string.cons/substr.pass.cpp
  
test/std/strings/basic.string/string.modifiers/string_append/T_size_size.pass.cpp
  
test/std/strings/basic.string/string.modifiers/string_append/string_size_size.pass.cpp
  
test/std/strings/basic.string/string.modifiers/string_assign/T_size_size.pass.cpp
  
test/std/strings/basic.string/string.modifiers/string_assign/string_size_size.pass.cpp
  test/std/strings/basic.string/string.modifiers/string_copy/copy.pass.cpp
  test/std/strings/basic.string/string.modifiers/string_erase/size_size.pass.cpp
  
test/std/strings/basic.string/string.modifiers/string_insert/size_T_size_size.pass.cpp
  
test/std/strings/basic.string/string.modifiers/string_insert/size_pointer.pass.cpp
  
test/std/strings/basic.string/string.modifiers/string_insert/size_pointer_size.pass.cpp
  
test/std/strings/basic.string/string.modifiers/string_insert/size_size_char.pass.cpp
  
test/std/strings/basic.string/string.modifiers/string_insert/size_string.pass.cpp
  
test/std/strings/basic.string/string.modifiers/string_insert/size_string_size_size.pass.cpp
  
test/std/strings/basic.string/string.modifiers/string_replace/size_size_T_size_size.pass.cpp
  
test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer.pass.cpp
  
test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer_size.pass.cpp
  
test/std/strings/basic.string/string.modifiers/string_replace/size_size_size_char.pass.cpp
  
test/std/strings/basic.string/string.modifiers/string_replace/size_size_string.pass.cpp
  
test/std/strings/basic.string/string.modifiers/string_replace/size_size_string_size_size.pass.cpp
  
test/std/strings/basic.string/string.ops/string_compare/size_size_T_size_size.pass.cpp
  
test/std/strings/basic.string/string.ops/string_compare/size_size_pointer.pass.cpp
  
test/std/strings/basic.string/string.ops/string_compare/size_size_pointer_size.pass.cpp
  
test/std/strings/basic.string/string.ops/string_compare/size_size_string.pass.cpp
  
test/std/strings/basic.string/string.ops/string_compare/size_size_string_size_size.pass.cpp

Index: test/std/strings/basic.string/string.ops/string_compare/size_size_string_size_size.pass.cpp
===
--- test/std/strings/basic.string/string.ops/string_compare/size_size_string_size_size.pass.cpp
+++ test/std/strings/basic.string/string.ops/string_compare/size_size_string_size_size.pass.cpp
@@ -7,7 +7,6 @@
 //
 //===--===//
 
-// XFAIL: libcpp-no-exceptions
 // 
 
 // int compare(size_type pos1, size_type n1, const basic_string& str,
@@ -20,6 +19,8 @@
 
 #include "min_allocator.h"
 
+#include "test_macros.h"
+
 int sign(int x)
 {
 if (x == 0)
@@ -34,33 +35,45 @@
 test(const S& s,   typename S::size_type pos1, typename S::size_type n1,
  const S& str, typename S::size_type pos2, typename S::size_type n2, int x)
 {
-try
-{
+if (pos1 <= s.size() && pos2 <= str.size())
 assert(sign(s.compare(pos1, n1, str, pos2, n2)) == sign(x));
-assert(pos1 <= s.size());
-assert(pos2 <= str.size());
-}
-catch (const std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+else
 {
-assert(pos1 > s.size() || pos2 > str.size());
+try
+{
+s.compare(pos1, n1, str, pos2, n2);
+assert(false);
+}
+catch (const std::out_of_range&)
+{
+assert(pos1 > s.size() || pos2 > str.size());
+}
 }
+#endif
 }
 
 template 
 void
 test_npos(const S& s,   typename S::size_type pos1, typename S::size_type n1,
   const S& str, typename S::size_type pos2, int x)
 {
-try
-{
+if (pos1 <= s.size() && pos2 <= str.size())
 assert(sign(s.compare(pos1, n1, str, pos2)) == sign(x));
-assert(pos1 <= s.size());
-assert(pos2 <= str.size());
-}
-catch (const std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+else
 {
-assert(pos1 > s.size() || pos2 > str.size());
+try
+{
+s.compare(pos1, n1, str, pos2);
+assert(false);
+}
+catch (const std::out_of_range&)
+{
+assert(pos1 > s.size() || pos2 > str.size());
+}
 }
+#endif
 }
 
 template 
Index: test/std/strings/basic.string/string.ops/string_compare/size_size_string.pass.cpp
===
--- 

[PATCH] D26195: Ignore incomplete types when determining whether they are expensive to copy

2016-11-01 Thread Felix Berger via cfe-commits
flx created this revision.
flx added a reviewer: alexfh.
flx added a subscriber: cfe-commits.
flx set the repository for this revision to rL LLVM.

IsExpensiveToCopy can return false positives for incomplete types, so ignore 
them.

All existing ClangTidy tests that depend on this function still pass as the 
types are complete.


Repository:
  rL LLVM

https://reviews.llvm.org/D26195

Files:
  clang-tidy/utils/TypeTraits.cpp


Index: clang-tidy/utils/TypeTraits.cpp
===
--- clang-tidy/utils/TypeTraits.cpp
+++ clang-tidy/utils/TypeTraits.cpp
@@ -41,7 +41,7 @@
 
 llvm::Optional isExpensiveToCopy(QualType Type,
const ASTContext ) {
-  if (Type->isDependentType())
+  if (Type->isDependentType() || Type->isIncompleteType())
 return llvm::None;
   return !Type.isTriviallyCopyableType(Context) &&
  !classHasTrivialCopyAndDestroy(Type) &&


Index: clang-tidy/utils/TypeTraits.cpp
===
--- clang-tidy/utils/TypeTraits.cpp
+++ clang-tidy/utils/TypeTraits.cpp
@@ -41,7 +41,7 @@
 
 llvm::Optional isExpensiveToCopy(QualType Type,
const ASTContext ) {
-  if (Type->isDependentType())
+  if (Type->isDependentType() || Type->isIncompleteType())
 return llvm::None;
   return !Type.isTriviallyCopyableType(Context) &&
  !classHasTrivialCopyAndDestroy(Type) &&
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26189: Add a note that points to the linkage specifier for the "must have C++ linkage" errors

2016-11-01 Thread Erik Pilkington via cfe-commits
erik.pilkington added inline comments.



Comment at: lib/Sema/SemaTemplate.cpp:5946
+if (const LinkageSpecDecl *LSD = Ctx->getExternCContext())
+  Diag(LSD->getExternLoc(), diag::note_module_import_in_extern_c);
+return true;

Can you update the name of this diagnostic to not mention modules, now that we 
use it more generally?


Repository:
  rL LLVM

https://reviews.llvm.org/D26189



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


[PATCH] D26138: [clang-tidy] Add modernize-use-equals-delete check

2016-11-01 Thread Malcolm Parsons via cfe-commits
malcolm.parsons updated this revision to Diff 76561.
malcolm.parsons added a comment.

Add quick hack to make methods public.
Cleanup around replacements should be enhanced with rules to remove
empty private/protected/public sections.
private: public: -> public:
public: private: -> private:


https://reviews.llvm.org/D26138

Files:
  clang-tidy/modernize/CMakeLists.txt
  clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tidy/modernize/UseDefaultCheck.cpp
  clang-tidy/modernize/UseDefaultCheck.h
  clang-tidy/modernize/UseEqualsDefaultCheck.cpp
  clang-tidy/modernize/UseEqualsDefaultCheck.h
  clang-tidy/modernize/UseEqualsDeleteCheck.cpp
  clang-tidy/modernize/UseEqualsDeleteCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/modernize-use-default.rst
  docs/clang-tidy/checks/modernize-use-equals-default.rst
  docs/clang-tidy/checks/modernize-use-equals-delete.rst
  test/clang-tidy/modernize-use-default-copy.cpp
  test/clang-tidy/modernize-use-default-delayed.cpp
  test/clang-tidy/modernize-use-default.cpp
  test/clang-tidy/modernize-use-equals-default-copy.cpp
  test/clang-tidy/modernize-use-equals-default-delayed.cpp
  test/clang-tidy/modernize-use-equals-default.cpp
  test/clang-tidy/modernize-use-equals-delete.cpp

Index: test/clang-tidy/modernize-use-equals-delete.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-use-equals-delete.cpp
@@ -0,0 +1,122 @@
+// RUN: %check_clang_tidy %s modernize-use-equals-delete %t
+
+struct PositivePrivate {
+private:
+  PositivePrivate();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+  // CHECK-FIXES: public: PositivePrivate() = delete; private:
+  PositivePrivate(const PositivePrivate &);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+  // CHECK-FIXES: public: PositivePrivate(const PositivePrivate &) = delete; private:
+  PositivePrivate =(const PositivePrivate &);
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+  // CHECK-FIXES: public: PositivePrivate =(const PositivePrivate &) = delete; private:
+  PositivePrivate(PositivePrivate &&);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+  // CHECK-FIXES: public: PositivePrivate(PositivePrivate &&) = delete; private:
+  PositivePrivate =(PositivePrivate &&);
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+  // CHECK-FIXES: public: PositivePrivate =(PositivePrivate &&) = delete; private:
+  ~PositivePrivate();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+  // CHECK-FIXES: public: ~PositivePrivate() = delete; private:
+};
+
+struct NegativePublic {
+  NegativePublic(const NegativePublic &);
+};
+
+struct NegativeProtected {
+protected:
+  NegativeProtected(const NegativeProtected &);
+};
+
+struct PositiveInlineMember {
+  int foo() { return 0; }
+
+private:
+  PositiveInlineMember(const PositiveInlineMember &);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+  // CHECK-FIXES: public: PositiveInlineMember(const PositiveInlineMember &) = delete; private:
+};
+
+struct PositiveOutOfLineMember {
+  int foo();
+
+private:
+  PositiveOutOfLineMember(const PositiveOutOfLineMember &);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+  // CHECK-FIXES: public: PositiveOutOfLineMember(const PositiveOutOfLineMember &) = delete; private:
+};
+
+int PositiveOutOfLineMember::foo() { return 0; }
+
+struct PositiveAbstractMember {
+  virtual int foo() = 0;
+
+private:
+  PositiveAbstractMember(const PositiveAbstractMember &);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+  // CHECK-FIXES: public: PositiveAbstractMember(const PositiveAbstractMember &) = delete; private:
+};
+
+struct NegativeMemberNotImpl {
+  int foo();
+
+private:
+  NegativeMemberNotImpl(const NegativeMemberNotImpl &);
+};
+
+struct NegativeStaticMemberNotImpl {
+  static int foo();
+
+private:
+  NegativeStaticMemberNotImpl(const NegativeStaticMemberNotImpl &);
+};
+
+struct NegativeInline {
+private:
+  NegativeInline(const NegativeInline &) {}
+};
+
+struct NegativeOutOfLine {
+private:
+  NegativeOutOfLine(const NegativeOutOfLine &);
+};
+
+NegativeOutOfLine::NegativeOutOfLine(const NegativeOutOfLine &) {}
+
+struct 

[PATCH] D26184: Protect lock tests under libcpp-no-exceptions

2016-11-01 Thread Roger Ferrer Ibanez via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL285695: Protect lock tests under libcpp-no-exceptions 
(authored by rogfer01).

Changed prior to commit:
  https://reviews.llvm.org/D26184?vs=76545=76559#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26184

Files:
  libcxx/trunk/test/std/thread/thread.mutex/thread.lock.algorithm/lock.pass.cpp
  
libcxx/trunk/test/std/thread/thread.mutex/thread.lock.algorithm/try_lock.pass.cpp
  
libcxx/trunk/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/lock.pass.cpp
  
libcxx/trunk/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/try_lock.pass.cpp
  
libcxx/trunk/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/try_lock_for.pass.cpp
  
libcxx/trunk/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/try_lock_until.pass.cpp
  
libcxx/trunk/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/unlock.pass.cpp
  
libcxx/trunk/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/lock.pass.cpp
  
libcxx/trunk/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/try_lock.pass.cpp
  
libcxx/trunk/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/try_lock_for.pass.cpp
  
libcxx/trunk/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/try_lock_until.pass.cpp
  
libcxx/trunk/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/unlock.pass.cpp
  
libcxx/trunk/test/std/thread/thread.mutex/thread.once/thread.once.callonce/call_once.pass.cpp

Index: libcxx/trunk/test/std/thread/thread.mutex/thread.once/thread.once.callonce/call_once.pass.cpp
===
--- libcxx/trunk/test/std/thread/thread.mutex/thread.once/thread.once.callonce/call_once.pass.cpp
+++ libcxx/trunk/test/std/thread/thread.mutex/thread.once/thread.once.callonce/call_once.pass.cpp
@@ -7,7 +7,6 @@
 //
 //===--===//
 //
-// XFAIL: libcpp-no-exceptions
 // UNSUPPORTED: libcpp-has-no-threads
 
 // 
@@ -50,19 +49,21 @@
 ++init3_called;
 std::this_thread::sleep_for(ms(250));
 if (init3_called == 1)
-throw 1;
+TEST_THROW(1);
 ++init3_completed;
 }
 
 void f3()
 {
+#ifndef TEST_HAS_NO_EXCEPTIONS
 try
 {
 std::call_once(flg3, init3);
 }
 catch (...)
 {
 }
+#endif
 }
 
 #ifndef _LIBCPP_HAS_NO_VARIADICS
@@ -197,6 +198,7 @@
 t1.join();
 assert(init0_called == 1);
 }
+#ifndef TEST_HAS_NO_EXCEPTIONS
 // check basic exception safety
 {
 std::thread t0(f3);
@@ -206,6 +208,7 @@
 assert(init3_called == 2);
 assert(init3_completed == 1);
 }
+#endif
 // check deadlock avoidance
 {
 std::thread t0(f41);
Index: libcxx/trunk/test/std/thread/thread.mutex/thread.lock.algorithm/try_lock.pass.cpp
===
--- libcxx/trunk/test/std/thread/thread.mutex/thread.lock.algorithm/try_lock.pass.cpp
+++ libcxx/trunk/test/std/thread/thread.mutex/thread.lock.algorithm/try_lock.pass.cpp
@@ -7,7 +7,6 @@
 //
 //===--===//
 //
-// XFAIL: libcpp-no-exceptions
 // UNSUPPORTED: libcpp-has-no-threads
 
 // 
@@ -18,6 +17,8 @@
 #include 
 #include 
 
+#include "test_macros.h"
+
 class L0
 {
 bool locked_;
@@ -63,7 +64,7 @@
 
 bool try_lock()
 {
-throw 1;
+TEST_THROW(1);
 return locked_;
 }
 
@@ -95,6 +96,7 @@
 assert(!l0.locked());
 assert(!l1.locked());
 }
+#ifndef TEST_HAS_NO_EXCEPTIONS
 {
 L0 l0;
 L2 l1;
@@ -123,6 +125,7 @@
 assert(!l1.locked());
 }
 }
+#endif
 #ifndef _LIBCPP_HAS_NO_VARIADICS
 {
 L0 l0;
@@ -142,6 +145,7 @@
 assert(!l1.locked());
 assert(!l2.locked());
 }
+#ifndef TEST_HAS_NO_EXCEPTIONS
 {
 L2 l0;
 L2 l1;
@@ -167,6 +171,7 @@
 assert(!l1.locked());
 assert(!l2.locked());
 }
+#endif
 {
 L0 l0;
 L0 l1;
@@ -194,6 +199,7 @@
 assert(!l1.locked());
 assert(!l2.locked());
 }
+#ifndef TEST_HAS_NO_EXCEPTIONS
 {
 L0 l0;
 L0 l1;
@@ -242,6 +248,7 @@
 assert(!l2.locked());
 }
 }
+#endif
 {
 L1 l0;
 L1 l1;
@@ -269,6 +276,7 @@
 assert(!l1.locked());
 assert(!l2.locked());
 }
+#ifndef TEST_HAS_NO_EXCEPTIONS
 {
 L1 l0;
 L1 l1;
@@ -458,6 +466,7 @@
 assert(!l2.locked());
 }
 }
+#endif  // TEST_HAS_NO_EXCEPTIONS
 {
 L0 l0;
 L0 l1;

[libcxx] r285695 - Protect lock tests under libcpp-no-exceptions

2016-11-01 Thread Roger Ferrer Ibanez via cfe-commits
Author: rogfer01
Date: Tue Nov  1 10:00:16 2016
New Revision: 285695

URL: http://llvm.org/viewvc/llvm-project?rev=285695=rev
Log:
Protect lock tests under libcpp-no-exceptions

Skip tests that expect an exception to be thrown.

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



Modified:

libcxx/trunk/test/std/thread/thread.mutex/thread.lock.algorithm/lock.pass.cpp

libcxx/trunk/test/std/thread/thread.mutex/thread.lock.algorithm/try_lock.pass.cpp

libcxx/trunk/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/lock.pass.cpp

libcxx/trunk/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/try_lock.pass.cpp

libcxx/trunk/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/try_lock_for.pass.cpp

libcxx/trunk/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/try_lock_until.pass.cpp

libcxx/trunk/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/unlock.pass.cpp

libcxx/trunk/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/lock.pass.cpp

libcxx/trunk/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/try_lock.pass.cpp

libcxx/trunk/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/try_lock_for.pass.cpp

libcxx/trunk/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/try_lock_until.pass.cpp

libcxx/trunk/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/unlock.pass.cpp

libcxx/trunk/test/std/thread/thread.mutex/thread.once/thread.once.callonce/call_once.pass.cpp

Modified: 
libcxx/trunk/test/std/thread/thread.mutex/thread.lock.algorithm/lock.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/thread/thread.mutex/thread.lock.algorithm/lock.pass.cpp?rev=285695=285694=285695=diff
==
--- 
libcxx/trunk/test/std/thread/thread.mutex/thread.lock.algorithm/lock.pass.cpp 
(original)
+++ 
libcxx/trunk/test/std/thread/thread.mutex/thread.lock.algorithm/lock.pass.cpp 
Tue Nov  1 10:00:16 2016
@@ -7,7 +7,6 @@
 //
 
//===--===//
 //
-// XFAIL: libcpp-no-exceptions
 // UNSUPPORTED: libcpp-has-no-threads
 
 // This test hangs forever when built against libstdc++. In order to allow
@@ -23,6 +22,8 @@
 #include 
 #include 
 
+#include "test_macros.h"
+
 class L0
 {
 bool locked_;
@@ -78,12 +79,12 @@ public:
 
 void lock()
 {
-throw 1;
+TEST_THROW(1);
 }
 
 bool try_lock()
 {
-throw 1;
+TEST_THROW(1);
 return locked_;
 }
 
@@ -115,6 +116,7 @@ int main()
 assert(l0.locked());
 assert(l1.locked());
 }
+#ifndef TEST_HAS_NO_EXCEPTIONS
 {
 L0 l0;
 L2 l1;
@@ -185,6 +187,7 @@ int main()
 assert(!l1.locked());
 }
 }
+#endif
 #ifndef _LIBCPP_HAS_NO_VARIADICS
 {
 L0 l0;
@@ -195,6 +198,7 @@ int main()
 assert(l1.locked());
 assert(l2.locked());
 }
+#ifndef TEST_HAS_NO_EXCEPTIONS
 {
 L2 l0;
 L2 l1;
@@ -211,6 +215,7 @@ int main()
 assert(!l2.locked());
 }
 }
+#endif
 {
 L0 l0;
 L0 l1;
@@ -238,6 +243,7 @@ int main()
 assert(l1.locked());
 assert(l2.locked());
 }
+#ifndef TEST_HAS_NO_EXCEPTIONS
 {
 L0 l0;
 L0 l1;
@@ -382,6 +388,7 @@ int main()
 assert(!l2.locked());
 }
 }
+#endif  // TEST_HAS_NO_EXCEPTIONS
 {
 L0 l0;
 L0 l1;
@@ -437,6 +444,7 @@ int main()
 assert(l2.locked());
 assert(l3.locked());
 }
+#ifndef TEST_HAS_NO_EXCEPTIONS
 {
 L0 l0;
 L0 l1;
@@ -509,5 +517,6 @@ int main()
 assert(!l3.locked());
 }
 }
+#endif  // TEST_HAS_NO_EXCEPTIONS
 #endif  // _LIBCPP_HAS_NO_VARIADICS
 }

Modified: 
libcxx/trunk/test/std/thread/thread.mutex/thread.lock.algorithm/try_lock.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/thread/thread.mutex/thread.lock.algorithm/try_lock.pass.cpp?rev=285695=285694=285695=diff
==
--- 
libcxx/trunk/test/std/thread/thread.mutex/thread.lock.algorithm/try_lock.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/thread/thread.mutex/thread.lock.algorithm/try_lock.pass.cpp
 Tue Nov  1 10:00:16 2016
@@ -7,7 +7,6 @@
 //
 
//===--===//
 //
-// XFAIL: libcpp-no-exceptions
 // UNSUPPORTED: libcpp-has-no-threads
 
 // 
@@ -18,6 +17,8 @@
 #include 
 #include 
 
+#include "test_macros.h"
+
 class L0
 {
 bool locked_;
@@ 

[PATCH] D26138: [clang-tidy] Add modernize-use-equals-delete check

2016-11-01 Thread Malcolm Parsons via cfe-commits
malcolm.parsons updated this revision to Diff 76558.
malcolm.parsons added a comment.

Add FIXME comment.


https://reviews.llvm.org/D26138

Files:
  clang-tidy/modernize/CMakeLists.txt
  clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tidy/modernize/UseDefaultCheck.cpp
  clang-tidy/modernize/UseDefaultCheck.h
  clang-tidy/modernize/UseEqualsDefaultCheck.cpp
  clang-tidy/modernize/UseEqualsDefaultCheck.h
  clang-tidy/modernize/UseEqualsDeleteCheck.cpp
  clang-tidy/modernize/UseEqualsDeleteCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/modernize-use-default.rst
  docs/clang-tidy/checks/modernize-use-equals-default.rst
  docs/clang-tidy/checks/modernize-use-equals-delete.rst
  test/clang-tidy/modernize-use-default-copy.cpp
  test/clang-tidy/modernize-use-default-delayed.cpp
  test/clang-tidy/modernize-use-default.cpp
  test/clang-tidy/modernize-use-equals-default-copy.cpp
  test/clang-tidy/modernize-use-equals-default-delayed.cpp
  test/clang-tidy/modernize-use-equals-default.cpp
  test/clang-tidy/modernize-use-equals-delete.cpp

Index: test/clang-tidy/modernize-use-equals-delete.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-use-equals-delete.cpp
@@ -0,0 +1,122 @@
+// RUN: %check_clang_tidy %s modernize-use-equals-delete %t
+
+struct PositivePrivate {
+private:
+  PositivePrivate();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+  // CHECK-FIXES: PositivePrivate() = delete;
+  PositivePrivate(const PositivePrivate &);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+  // CHECK-FIXES: PositivePrivate(const PositivePrivate &) = delete;
+  PositivePrivate =(const PositivePrivate &);
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+  // CHECK-FIXES: PositivePrivate =(const PositivePrivate &) = delete;
+  PositivePrivate(PositivePrivate &&);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+  // CHECK-FIXES: PositivePrivate(PositivePrivate &&) = delete;
+  PositivePrivate =(PositivePrivate &&);
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+  // CHECK-FIXES: PositivePrivate =(PositivePrivate &&) = delete;
+  ~PositivePrivate();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+  // CHECK-FIXES: ~PositivePrivate() = delete;
+};
+
+struct NegativePublic {
+  NegativePublic(const NegativePublic &);
+};
+
+struct NegativeProtected {
+protected:
+  NegativeProtected(const NegativeProtected &);
+};
+
+struct PositiveInlineMember {
+  int foo() { return 0; }
+
+private:
+  PositiveInlineMember(const PositiveInlineMember &);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+  // CHECK-FIXES: PositiveInlineMember(const PositiveInlineMember &) = delete;
+};
+
+struct PositiveOutOfLineMember {
+  int foo();
+
+private:
+  PositiveOutOfLineMember(const PositiveOutOfLineMember &);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+  // CHECK-FIXES: PositiveOutOfLineMember(const PositiveOutOfLineMember &) = delete;
+};
+
+int PositiveOutOfLineMember::foo() { return 0; }
+
+struct PositiveAbstractMember {
+  virtual int foo() = 0;
+
+private:
+  PositiveAbstractMember(const PositiveAbstractMember &);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+  // CHECK-FIXES: PositiveAbstractMember(const PositiveAbstractMember &) = delete;
+};
+
+struct NegativeMemberNotImpl {
+  int foo();
+
+private:
+  NegativeMemberNotImpl(const NegativeMemberNotImpl &);
+};
+
+struct NegativeStaticMemberNotImpl {
+  static int foo();
+
+private:
+  NegativeStaticMemberNotImpl(const NegativeStaticMemberNotImpl &);
+};
+
+struct NegativeInline {
+private:
+  NegativeInline(const NegativeInline &) {}
+};
+
+struct NegativeOutOfLine {
+private:
+  NegativeOutOfLine(const NegativeOutOfLine &);
+};
+
+NegativeOutOfLine::NegativeOutOfLine(const NegativeOutOfLine &) {}
+
+struct NegativeConstructNotImpl {
+  NegativeConstructNotImpl();
+
+private:
+  NegativeConstructNotImpl(const NegativeConstructNotImpl &);
+};
+
+struct PositiveDefaultedConstruct {
+  PositiveDefaultedConstruct() = default;
+
+private:
+  PositiveDefaultedConstruct(const PositiveDefaultedConstruct &);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 

[PATCH] D26138: [clang-tidy] Add modernize-use-equals-delete check

2016-11-01 Thread Malcolm Parsons via cfe-commits
malcolm.parsons updated this revision to Diff 76557.
malcolm.parsons added a comment.

Reword diagnostic.


https://reviews.llvm.org/D26138

Files:
  clang-tidy/modernize/CMakeLists.txt
  clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tidy/modernize/UseDefaultCheck.cpp
  clang-tidy/modernize/UseDefaultCheck.h
  clang-tidy/modernize/UseEqualsDefaultCheck.cpp
  clang-tidy/modernize/UseEqualsDefaultCheck.h
  clang-tidy/modernize/UseEqualsDeleteCheck.cpp
  clang-tidy/modernize/UseEqualsDeleteCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/modernize-use-default.rst
  docs/clang-tidy/checks/modernize-use-equals-default.rst
  docs/clang-tidy/checks/modernize-use-equals-delete.rst
  test/clang-tidy/modernize-use-default-copy.cpp
  test/clang-tidy/modernize-use-default-delayed.cpp
  test/clang-tidy/modernize-use-default.cpp
  test/clang-tidy/modernize-use-equals-default-copy.cpp
  test/clang-tidy/modernize-use-equals-default-delayed.cpp
  test/clang-tidy/modernize-use-equals-default.cpp
  test/clang-tidy/modernize-use-equals-delete.cpp

Index: test/clang-tidy/modernize-use-equals-delete.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-use-equals-delete.cpp
@@ -0,0 +1,122 @@
+// RUN: %check_clang_tidy %s modernize-use-equals-delete %t
+
+struct PositivePrivate {
+private:
+  PositivePrivate();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+  // CHECK-FIXES: PositivePrivate() = delete;
+  PositivePrivate(const PositivePrivate &);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+  // CHECK-FIXES: PositivePrivate(const PositivePrivate &) = delete;
+  PositivePrivate =(const PositivePrivate &);
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+  // CHECK-FIXES: PositivePrivate =(const PositivePrivate &) = delete;
+  PositivePrivate(PositivePrivate &&);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+  // CHECK-FIXES: PositivePrivate(PositivePrivate &&) = delete;
+  PositivePrivate =(PositivePrivate &&);
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+  // CHECK-FIXES: PositivePrivate =(PositivePrivate &&) = delete;
+  ~PositivePrivate();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+  // CHECK-FIXES: ~PositivePrivate() = delete;
+};
+
+struct NegativePublic {
+  NegativePublic(const NegativePublic &);
+};
+
+struct NegativeProtected {
+protected:
+  NegativeProtected(const NegativeProtected &);
+};
+
+struct PositiveInlineMember {
+  int foo() { return 0; }
+
+private:
+  PositiveInlineMember(const PositiveInlineMember &);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+  // CHECK-FIXES: PositiveInlineMember(const PositiveInlineMember &) = delete;
+};
+
+struct PositiveOutOfLineMember {
+  int foo();
+
+private:
+  PositiveOutOfLineMember(const PositiveOutOfLineMember &);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+  // CHECK-FIXES: PositiveOutOfLineMember(const PositiveOutOfLineMember &) = delete;
+};
+
+int PositiveOutOfLineMember::foo() { return 0; }
+
+struct PositiveAbstractMember {
+  virtual int foo() = 0;
+
+private:
+  PositiveAbstractMember(const PositiveAbstractMember &);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+  // CHECK-FIXES: PositiveAbstractMember(const PositiveAbstractMember &) = delete;
+};
+
+struct NegativeMemberNotImpl {
+  int foo();
+
+private:
+  NegativeMemberNotImpl(const NegativeMemberNotImpl &);
+};
+
+struct NegativeStaticMemberNotImpl {
+  static int foo();
+
+private:
+  NegativeStaticMemberNotImpl(const NegativeStaticMemberNotImpl &);
+};
+
+struct NegativeInline {
+private:
+  NegativeInline(const NegativeInline &) {}
+};
+
+struct NegativeOutOfLine {
+private:
+  NegativeOutOfLine(const NegativeOutOfLine &);
+};
+
+NegativeOutOfLine::NegativeOutOfLine(const NegativeOutOfLine &) {}
+
+struct NegativeConstructNotImpl {
+  NegativeConstructNotImpl();
+
+private:
+  NegativeConstructNotImpl(const NegativeConstructNotImpl &);
+};
+
+struct PositiveDefaultedConstruct {
+  PositiveDefaultedConstruct() = default;
+
+private:
+  PositiveDefaultedConstruct(const PositiveDefaultedConstruct &);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 

[PATCH] D26138: [clang-tidy] Add modernize-use-equals-delete check

2016-11-01 Thread Aaron Ballman via cfe-commits
aaron.ballman added inline comments.



Comment at: clang-tidy/modernize/UseEqualsDeleteCheck.cpp:29
+cxxMethodDecl(
+anyOf(isCopyAssignmentOperator(), isMoveAssignmentOperator())),
+cxxDestructorDecl()));

malcolm.parsons wrote:
> aaron.ballman wrote:
> > malcolm.parsons wrote:
> > > aaron.ballman wrote:
> > > > How about a conversion operator, like `operator bool()`? You'll 
> > > > sometimes see that one declared privately for similar reasons.
> > > I haven't seen that. Do you have an example?
> > anecdote != data, and all that, but: 
> > http://stackoverflow.com/questions/5753460/a-way-to-disable-conversion-operators
> > 
> > I do agree though, this is not as common as noncopyable classes.
> I think I'll leave conversion operators to future 
> modernize-use-explicit-conversion-operators or 
> cppcoreguidelines-avoid-conversion-operators checks.
I'm okay with that.



Comment at: clang-tidy/modernize/UseEqualsDeleteCheck.cpp:52
+  diag(SpecialFunction->getLocation(),
+   "use '= delete' to prevent a default special member function")
+  << FixItHint::CreateInsertion(EndLoc, " = delete");

malcolm.parsons wrote:
> aaron.ballman wrote:
> > malcolm.parsons wrote:
> > > aaron.ballman wrote:
> > > > This diagnostic isn't very clear to me -- what does it mean to 
> > > > "prevent" a default special member function?
> > > > 
> > > > The fixit for this is also somewhat unsatisfying as this takes a 
> > > > private, not-defined function and turns it into a private, deleted 
> > > > function. That's a very small win, because it only impacts code which 
> > > > could access the special member function in the first place (some 
> > > > compilers give a diagnostic about the special member function being 
> > > > inaccessible even if it's explicitly marked as deleted; clang is not 
> > > > one such compiler). Do we have a way to rewrite the access specifier 
> > > > for the special member function as well (kind of like how we have a way 
> > > > to handle includes we're adding)? I am guessing not yet, but if we do, 
> > > > that would be fantastic to use here.
> > > > 
> > > > Note, I don't think this should hold up your patch or the fixit. A 
> > > > small win is still a win. :-)
> > > Do you have a better wording for the diagnostic?
> > > 
> > > I don't see any utility functions to make a method public.
> > Perhaps: "special member function with private access specifier and no 
> > definition is still accessible; use '= delete' to explicitly disallow all 
> > access"?
> > 
> > Or a less-wordy variant.
> How about "use '= delete' to prohibit calling of a special member function".
Given that this is in the modernize module, I think that's reasonable wording.


https://reviews.llvm.org/D26138



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


r285694 - [PowerPC] Implement vector shift builtins - clang portion

2016-11-01 Thread Nemanja Ivanovic via cfe-commits
Author: nemanjai
Date: Tue Nov  1 09:46:20 2016
New Revision: 285694

URL: http://llvm.org/viewvc/llvm-project?rev=285694=rev
Log:
[PowerPC] Implement vector shift builtins - clang portion

This patch corresponds to review https://reviews.llvm.org/D26092.
Committing on behalf of Tony Jiang.

Modified:
cfe/trunk/include/clang/Basic/BuiltinsPPC.def
cfe/trunk/lib/Headers/altivec.h
cfe/trunk/test/CodeGen/builtins-ppc-altivec.c
cfe/trunk/test/CodeGen/builtins-ppc-p9vector.c
cfe/trunk/test/CodeGen/builtins-ppc-vsx.c

Modified: cfe/trunk/include/clang/Basic/BuiltinsPPC.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsPPC.def?rev=285694=285693=285694=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsPPC.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsPPC.def Tue Nov  1 09:46:20 2016
@@ -289,6 +289,10 @@ BUILTIN(__builtin_altivec_vabsdub, "V16U
 BUILTIN(__builtin_altivec_vabsduh, "V8UsV8UsV8Us", "")
 BUILTIN(__builtin_altivec_vabsduw, "V4UiV4UiV4Ui", "")
 
+// P9 Shift built-ins.
+BUILTIN(__builtin_altivec_vslv, "V16UcV16UcV16Uc", "")
+BUILTIN(__builtin_altivec_vsrv, "V16UcV16UcV16Uc", "")
+
 // VSX built-ins.
 
 BUILTIN(__builtin_vsx_lxvd2x, "V2divC*", "")

Modified: cfe/trunk/lib/Headers/altivec.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/altivec.h?rev=285694=285693=285694=diff
==
--- cfe/trunk/lib/Headers/altivec.h (original)
+++ cfe/trunk/lib/Headers/altivec.h Tue Nov  1 09:46:20 2016
@@ -7703,6 +7703,145 @@ static __inline__ vector float __ATTRS_o
 #endif
 }
 
+#ifdef __VSX__
+static __inline__ vector bool long long __ATTRS_o_ai
+vec_sld(vector bool long long __a, vector bool long long __b,
+unsigned const int __c) {
+  unsigned char __d = __c & 0x0F;
+#ifdef __LITTLE_ENDIAN__
+  return vec_perm(
+  __b, __a, (vector unsigned char)(16 - __d, 17 - __d, 18 - __d, 19 - __d,
+   20 - __d, 21 - __d, 22 - __d, 23 - __d,
+   24 - __d, 25 - __d, 26 - __d, 27 - __d,
+   28 - __d, 29 - __d, 30 - __d, 31 - 
__d));
+#else
+  return vec_perm(
+  __a, __b,
+  (vector unsigned char)(__d, __d + 1, __d + 2, __d + 3, __d + 4, __d + 5,
+ __d + 6, __d + 7, __d + 8, __d + 9, __d + 10,
+ __d + 11, __d + 12, __d + 13, __d + 14, __d + 
15));
+#endif
+}
+
+static __inline__ vector signed long long __ATTRS_o_ai
+vec_sld(vector signed long long __a, vector signed long long __b,
+unsigned const int __c) {
+  unsigned char __d = __c & 0x0F;
+#ifdef __LITTLE_ENDIAN__
+  return vec_perm(
+  __b, __a, (vector unsigned char)(16 - __d, 17 - __d, 18 - __d, 19 - __d,
+   20 - __d, 21 - __d, 22 - __d, 23 - __d,
+   24 - __d, 25 - __d, 26 - __d, 27 - __d,
+   28 - __d, 29 - __d, 30 - __d, 31 - 
__d));
+#else
+  return vec_perm(
+  __a, __b,
+  (vector unsigned char)(__d, __d + 1, __d + 2, __d + 3, __d + 4, __d + 5,
+ __d + 6, __d + 7, __d + 8, __d + 9, __d + 10,
+ __d + 11, __d + 12, __d + 13, __d + 14, __d + 
15));
+#endif
+}
+
+static __inline__ vector unsigned long long __ATTRS_o_ai
+vec_sld(vector unsigned long long __a, vector unsigned long long __b,
+unsigned const int __c) {
+  unsigned char __d = __c & 0x0F;
+#ifdef __LITTLE_ENDIAN__
+  return vec_perm(
+  __b, __a, (vector unsigned char)(16 - __d, 17 - __d, 18 - __d, 19 - __d,
+   20 - __d, 21 - __d, 22 - __d, 23 - __d,
+   24 - __d, 25 - __d, 26 - __d, 27 - __d,
+   28 - __d, 29 - __d, 30 - __d, 31 - 
__d));
+#else
+  return vec_perm(
+  __a, __b,
+  (vector unsigned char)(__d, __d + 1, __d + 2, __d + 3, __d + 4, __d + 5,
+ __d + 6, __d + 7, __d + 8, __d + 9, __d + 10,
+ __d + 11, __d + 12, __d + 13, __d + 14, __d + 
15));
+#endif
+}
+
+static __inline__ vector double __ATTRS_o_ai vec_sld(vector double __a,
+ vector double __b,
+ unsigned const int __c) {
+  unsigned char __d = __c & 0x0F;
+#ifdef __LITTLE_ENDIAN__
+  return vec_perm(
+  __b, __a, (vector unsigned char)(16 - __d, 17 - __d, 18 - __d, 19 - __d,
+   20 - __d, 21 - __d, 22 - __d, 23 - __d,
+   24 - __d, 25 - __d, 26 - __d, 27 - __d,
+   28 - __d, 29 - __d, 30 - __d, 31 - 
__d));
+#else
+  return vec_perm(
+  __a, __b,
+  (vector 

[PATCH] D26138: [clang-tidy] Add modernize-use-equals-delete check

2016-11-01 Thread Malcolm Parsons via cfe-commits
malcolm.parsons added inline comments.



Comment at: clang-tidy/modernize/UseEqualsDeleteCheck.cpp:29
+cxxMethodDecl(
+anyOf(isCopyAssignmentOperator(), isMoveAssignmentOperator())),
+cxxDestructorDecl()));

aaron.ballman wrote:
> malcolm.parsons wrote:
> > aaron.ballman wrote:
> > > How about a conversion operator, like `operator bool()`? You'll sometimes 
> > > see that one declared privately for similar reasons.
> > I haven't seen that. Do you have an example?
> anecdote != data, and all that, but: 
> http://stackoverflow.com/questions/5753460/a-way-to-disable-conversion-operators
> 
> I do agree though, this is not as common as noncopyable classes.
I think I'll leave conversion operators to future 
modernize-use-explicit-conversion-operators or 
cppcoreguidelines-avoid-conversion-operators checks.



Comment at: clang-tidy/modernize/UseEqualsDeleteCheck.cpp:52
+  diag(SpecialFunction->getLocation(),
+   "use '= delete' to prevent a default special member function")
+  << FixItHint::CreateInsertion(EndLoc, " = delete");

aaron.ballman wrote:
> malcolm.parsons wrote:
> > aaron.ballman wrote:
> > > This diagnostic isn't very clear to me -- what does it mean to "prevent" 
> > > a default special member function?
> > > 
> > > The fixit for this is also somewhat unsatisfying as this takes a private, 
> > > not-defined function and turns it into a private, deleted function. 
> > > That's a very small win, because it only impacts code which could access 
> > > the special member function in the first place (some compilers give a 
> > > diagnostic about the special member function being inaccessible even if 
> > > it's explicitly marked as deleted; clang is not one such compiler). Do we 
> > > have a way to rewrite the access specifier for the special member 
> > > function as well (kind of like how we have a way to handle includes we're 
> > > adding)? I am guessing not yet, but if we do, that would be fantastic to 
> > > use here.
> > > 
> > > Note, I don't think this should hold up your patch or the fixit. A small 
> > > win is still a win. :-)
> > Do you have a better wording for the diagnostic?
> > 
> > I don't see any utility functions to make a method public.
> Perhaps: "special member function with private access specifier and no 
> definition is still accessible; use '= delete' to explicitly disallow all 
> access"?
> 
> Or a less-wordy variant.
How about "use '= delete' to prohibit calling of a special member function".


https://reviews.llvm.org/D26138



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


[PATCH] D26136: Protect exceptional path under libcpp-no-exceptions

2016-11-01 Thread Marshall Clow via cfe-commits
mclow.lists accepted this revision.
mclow.lists added a comment.
This revision is now accepted and ready to land.

Thanks for making these changes; I think this looks much better than before.
Feature creep: A bunch of the local variables can be marked as `const`.




Comment at: 
test/std/strings/basic.string/string.modifiers/string_insert/size_size_char.pass.cpp:27
 {
 typename S::size_type old_size = s.size();
 S s0 = s;

Nit. `old_size` should be `const`
(and in a few other places)



Comment at: 
test/std/strings/basic.string/string.modifiers/string_replace/size_size_T_size_size.pass.cpp:34
 typename S::size_type old_size = s.size();
 S s0 = s;
+if (pos1 <= old_size && pos2 <= sv.size())

`s0` should be `const`, too.


https://reviews.llvm.org/D26136



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


[PATCH] D26184: Protect lock tests under libcpp-no-exceptions

2016-11-01 Thread Marshall Clow via cfe-commits
mclow.lists accepted this revision.
mclow.lists added a comment.
This revision is now accepted and ready to land.

This looks OK to me.


https://reviews.llvm.org/D26184



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


Re: r285289 - [Sema] -Wunused-variable warning for array variables should behave

2016-11-01 Thread David Blaikie via cfe-commits
On Tue, Nov 1, 2016 at 3:13 AM Alex L  wrote:

> On 31 October 2016 at 15:34, David Blaikie  wrote:
>
>
>
> On Thu, Oct 27, 2016 at 6:40 AM Alex Lorenz via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
> Author: arphaman
> Date: Thu Oct 27 08:30:51 2016
> New Revision: 285289
>
> URL: http://llvm.org/viewvc/llvm-project?rev=285289=rev
> Log:
> [Sema] -Wunused-variable warning for array variables should behave
> similarly to scalar variables.
>
> This commit makes the -Wunused-variable warning behaviour more consistent:
> Now clang won't warn for array variables where it doesn't warn for scalar
> variables.
>
> rdar://24158862
>
> Differential Revision: https://reviews.llvm.org/D25937
>
> Modified:
> cfe/trunk/lib/Sema/SemaDecl.cpp
> cfe/trunk/test/SemaCXX/warn-everthing.cpp
> cfe/trunk/test/SemaCXX/warn-unused-variables.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=285289=285288=285289=diff
>
> ==
> --- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Oct 27 08:30:51 2016
> @@ -1522,7 +1522,7 @@ static bool ShouldDiagnoseUnusedDecl(con
>if (const VarDecl *VD = dyn_cast(D)) {
>
>  // White-list anything with an __attribute__((unused)) type.
> -QualType Ty = VD->getType();
> +const auto *Ty = VD->getType().getTypePtr();
>
>  // Only look at the outermost level of typedef.
>  if (const TypedefType *TT = Ty->getAs()) {
> @@ -1535,6 +1535,10 @@ static bool ShouldDiagnoseUnusedDecl(con
>  if (Ty->isIncompleteType() || Ty->isDependentType())
>return false;
>
> +// Look at the element type to ensure that the warning behaviour is
> +// consistent for both scalars and arrays.
> +Ty = Ty->getBaseElementTypeUnsafe();
> +
>  if (const TagType *TT = Ty->getAs()) {
>const TagDecl *Tag = TT->getDecl();
>if (Tag->hasAttr())
>
> Modified: cfe/trunk/test/SemaCXX/warn-everthing.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-everthing.cpp?rev=285289=285288=285289=diff
>
> ==
> --- cfe/trunk/test/SemaCXX/warn-everthing.cpp (original)
> +++ cfe/trunk/test/SemaCXX/warn-everthing.cpp Thu Oct 27 08:30:51 2016
> @@ -9,5 +9,5 @@ public:
>  };
>
>  void testPR12271() { // expected-warning {{no previous prototype for
> function 'testPR12271'}}
> -  PR12271 a[1][1]; // expected-warning {{unused variable 'a'}}
> +  PR12271 a[1][1];
>  }
>
> Modified: cfe/trunk/test/SemaCXX/warn-unused-variables.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-unused-variables.cpp?rev=285289=285288=285289=diff
>
> ==
> --- cfe/trunk/test/SemaCXX/warn-unused-variables.cpp (original)
> +++ cfe/trunk/test/SemaCXX/warn-unused-variables.cpp Thu Oct 27 08:30:51
> 2016
> @@ -150,3 +150,54 @@ namespace ctor_with_cleanups {
>  }
>
>  #include "Inputs/warn-unused-variables.h"
> +
> +namespace arrayRecords {
> +
> +int total = 0;
> +
> +class Adder {
>
>
> Presumably this class could be a bit simpler - is it just about having a
> non-trivial ctor? or non-trivial dtor?
>
> It'd be helpful to make the test as simple as possible to show what
> features are important to the diagnostic - rather than making the test look
> like real code by having functionality that's not required for testing.
>
> (eg: you don't have to implement functions here - the code will not be
> linked or executed, just compiled for warnings in the test suite)
>
> Potentially name the class by its purpose:
>
> struct NonTriviallyDestructible {
>   ~NonTriviallyDestructible();
> };
>
> and similar.
>
>
> Thanks for looking at this commit!
> You're right about this particular class, it can be simpler, since it's
> testing a non-trivial door. When I started working on this patch I used the
> code from the bug report to reproduce this issue in the test case, and
> didn't simplify it further when I found out the cause.
>

*nod* no worries - it's certainly not uncommon


>
>
>
> (is it important that Adder and Foo are constructed with arguments/have
> ctor parameters? It's not clear to me from the test or code whether that's
> the case)
>
>
> No. Do you think I should simplify this test case in a separate commit?
>

That'd be great if you could simplify it down to what seems to be the
essentials!

- Dave


>
> Cheers,
> Alex
>
>
>
>
> +public:
> +  Adder(int x); // out of line below
> +  ~Adder() {}
> +};
> +
> +Adder::Adder(int x) {
> +  total += x;
> +}
> +
> +struct Foo {
> +  int x;
> +  Foo(int x) : x(x) {}
> +};
> +
> +struct S1 {
> +  S1();
> +};
> +
> +void foo(int size) {
> +  S1 y; // no warning
> +  S1 yarray[2]; // no warning
> +  S1 dynArray[size]; // no warning
> +  

[PATCH] D26189: Add a note that points to the linkage specifier for the "must have C++ linkage" errors

2016-11-01 Thread Alex Lorenz via cfe-commits
arphaman created this revision.
arphaman added reviewers: rsmith, rjmccall.
arphaman added a subscriber: cfe-commits.
arphaman set the repository for this revision to rL LLVM.

This patch improves the "must have C++ linkage" error diagnostics for C++ by 
adding an additional note that points to the appropriate `extern "C"` linkage 
specifier. This patch covers the diagnostics for templates and literal 
operators, which AFAIK are the only declarations that emit this particular kind 
of error. Please let me know if you think there are errors for other C++ 
declarations that require similar changes.


Repository:
  rL LLVM

https://reviews.llvm.org/D26189

Files:
  include/clang/AST/DeclBase.h
  lib/AST/DeclBase.cpp
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaTemplate.cpp
  test/CXX/over/over.oper/over.literal/p6.cpp
  test/SemaCXX/cxx0x-defaulted-functions.cpp
  test/SemaTemplate/class-template-decl.cpp

Index: test/SemaTemplate/class-template-decl.cpp
===
--- test/SemaTemplate/class-template-decl.cpp
+++ test/SemaTemplate/class-template-decl.cpp
@@ -10,11 +10,11 @@
   template class C;
 }
 
-extern "C" {
+extern "C" { // expected-note {{extern "C" language linkage specification begins here}}
   template class D; // expected-error{{templates must have C++ linkage}}
 }
 
-extern "C" {
+extern "C" { // expected-note 2 {{extern "C" language linkage specification begins here}}
   class PR17968 {
 template class D; // expected-error{{templates must have C++ linkage}}
 template void f(); // expected-error{{templates must have C++ linkage}}
@@ -148,7 +148,7 @@
 }
 
 extern "C" template  // expected-error{{templates must have C++ linkage}}
-void DontCrashOnThis() {
+void DontCrashOnThis() { // expected-note@-1 {{extern "C" language linkage specification begins here}}
   T  = T();
   pT;
 }
Index: test/SemaCXX/cxx0x-defaulted-functions.cpp
===
--- test/SemaCXX/cxx0x-defaulted-functions.cpp
+++ test/SemaCXX/cxx0x-defaulted-functions.cpp
@@ -180,7 +180,7 @@
   Outer::Inner2::~Inner2() = default; // expected-error {{nested name specifier 'Outer::Inner2::' for declaration does not refer into a class, class template or class template partial specialization}}  expected-error {{only special member functions may be defaulted}}
 }
 
-extern "C" {
+extern "C" { // expected-note {{extern "C" language linkage specification begins here}}
  template // expected-error {{templates must have C++ linkage}}
  void PR13573(const _Tp&) = delete;
 }
Index: test/CXX/over/over.oper/over.literal/p6.cpp
===
--- test/CXX/over/over.oper/over.literal/p6.cpp
+++ test/CXX/over/over.oper/over.literal/p6.cpp
@@ -1,9 +1,11 @@
 // RUN: %clang_cc1 -std=c++11 %s -verify
 
+// expected-note@+1 {{extern "C" language linkage specification begins here}}
 extern "C" void operator "" _a(const char *); // expected-error {{must have C++ linkage}}
 extern "C" template void operator "" _b(); // expected-error {{must have C++ linkage}}
+// expected-note@-1 {{extern "C" language linkage specification begins here}}
 
-extern "C" {
+extern "C" { // expected-note 4 {{extern "C" language linkage specification begins here}}
   void operator "" _c(const char *); // expected-error {{must have C++ linkage}}
   template void operator "" _d(); // expected-error {{must have C++ linkage}}
   namespace N {
Index: lib/Sema/SemaTemplate.cpp
===
--- lib/Sema/SemaTemplate.cpp
+++ lib/Sema/SemaTemplate.cpp
@@ -5939,9 +5939,13 @@
   // C++ [temp]p4:
   //   A template [...] shall not have C linkage.
   DeclContext *Ctx = S->getEntity();
-  if (Ctx && Ctx->isExternCContext())
-return Diag(TemplateParams->getTemplateLoc(), diag::err_template_linkage)
- << TemplateParams->getSourceRange();
+  if (Ctx && Ctx->isExternCContext()) {
+Diag(TemplateParams->getTemplateLoc(), diag::err_template_linkage)
+<< TemplateParams->getSourceRange();
+if (const LinkageSpecDecl *LSD = Ctx->getExternCContext())
+  Diag(LSD->getExternLoc(), diag::note_module_import_in_extern_c);
+return true;
+  }
   Ctx = Ctx->getRedeclContext();
 
   // C++ [temp]p2:
Index: lib/Sema/SemaDeclCXX.cpp
===
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -12757,6 +12757,9 @@
 
   if (FnDecl->isExternC()) {
 Diag(FnDecl->getLocation(), diag::err_literal_operator_extern_c);
+if (const LinkageSpecDecl *LSD =
+FnDecl->getDeclContext()->getExternCContext())
+  Diag(LSD->getExternLoc(), diag::note_module_import_in_extern_c);
 return true;
   }
 
Index: lib/AST/DeclBase.cpp
===
--- lib/AST/DeclBase.cpp
+++ lib/AST/DeclBase.cpp
@@ -992,6 +992,18 @@
   return 

[PATCH] D26138: [clang-tidy] Add modernize-use-equals-delete check

2016-11-01 Thread Aaron Ballman via cfe-commits
aaron.ballman added inline comments.



Comment at: clang-tidy/modernize/UseEqualsDeleteCheck.cpp:29
+cxxMethodDecl(
+anyOf(isCopyAssignmentOperator(), isMoveAssignmentOperator())),
+cxxDestructorDecl()));

malcolm.parsons wrote:
> aaron.ballman wrote:
> > How about a conversion operator, like `operator bool()`? You'll sometimes 
> > see that one declared privately for similar reasons.
> I haven't seen that. Do you have an example?
anecdote != data, and all that, but: 
http://stackoverflow.com/questions/5753460/a-way-to-disable-conversion-operators

I do agree though, this is not as common as noncopyable classes.



Comment at: clang-tidy/modernize/UseEqualsDeleteCheck.cpp:52
+  diag(SpecialFunction->getLocation(),
+   "use '= delete' to prevent a default special member function")
+  << FixItHint::CreateInsertion(EndLoc, " = delete");

malcolm.parsons wrote:
> aaron.ballman wrote:
> > This diagnostic isn't very clear to me -- what does it mean to "prevent" a 
> > default special member function?
> > 
> > The fixit for this is also somewhat unsatisfying as this takes a private, 
> > not-defined function and turns it into a private, deleted function. That's 
> > a very small win, because it only impacts code which could access the 
> > special member function in the first place (some compilers give a 
> > diagnostic about the special member function being inaccessible even if 
> > it's explicitly marked as deleted; clang is not one such compiler). Do we 
> > have a way to rewrite the access specifier for the special member function 
> > as well (kind of like how we have a way to handle includes we're adding)? I 
> > am guessing not yet, but if we do, that would be fantastic to use here.
> > 
> > Note, I don't think this should hold up your patch or the fixit. A small 
> > win is still a win. :-)
> Do you have a better wording for the diagnostic?
> 
> I don't see any utility functions to make a method public.
Perhaps: "special member function with private access specifier and no 
definition is still accessible; use '= delete' to explicitly disallow all 
access"?

Or a less-wordy variant.


https://reviews.llvm.org/D26138



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


[clang-tools-extra] r285689 - [clang-tidy] Add check readability-redundant-declaration

2016-11-01 Thread Daniel Marjamaki via cfe-commits
Author: danielmarjamaki
Date: Tue Nov  1 08:26:15 2016
New Revision: 285689

URL: http://llvm.org/viewvc/llvm-project?rev=285689=rev
Log:
[clang-tidy] Add check readability-redundant-declaration

Finds redundant variable and function declarations.

  extern int X;
  extern int X;  // <- redundant

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


Added:
clang-tools-extra/trunk/clang-tidy/readability/RedundantDeclarationCheck.cpp
clang-tools-extra/trunk/clang-tidy/readability/RedundantDeclarationCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/readability-redundant-declaration.rst

clang-tools-extra/trunk/test/clang-tidy/readability-redundant-declaration.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/readability/ReadabilityTidyModule.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt?rev=285689=285688=285689=diff
==
--- clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt Tue Nov  1 
08:26:15 2016
@@ -16,6 +16,7 @@ add_clang_library(clangTidyReadabilityMo
   NonConstParameterCheck.cpp
   ReadabilityTidyModule.cpp
   RedundantControlFlowCheck.cpp
+  RedundantDeclarationCheck.cpp
   RedundantMemberInitCheck.cpp
   RedundantStringCStrCheck.cpp
   RedundantSmartptrGetCheck.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/readability/ReadabilityTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/ReadabilityTidyModule.cpp?rev=285689=285688=285689=diff
==
--- clang-tools-extra/trunk/clang-tidy/readability/ReadabilityTidyModule.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/readability/ReadabilityTidyModule.cpp 
Tue Nov  1 08:26:15 2016
@@ -23,6 +23,7 @@
 #include "NamedParameterCheck.h"
 #include "NonConstParameterCheck.h"
 #include "RedundantControlFlowCheck.h"
+#include "RedundantDeclarationCheck.h"
 #include "RedundantMemberInitCheck.h"
 #include "RedundantSmartptrGetCheck.h"
 #include "RedundantStringCStrCheck.h"
@@ -68,6 +69,8 @@ public:
 "readability-non-const-parameter");
 CheckFactories.registerCheck(
 "readability-redundant-control-flow");
+CheckFactories.registerCheck(
+"readability-redundant-declaration");
 CheckFactories.registerCheck(
 "readability-redundant-smartptr-get");
 CheckFactories.registerCheck(

Added: 
clang-tools-extra/trunk/clang-tidy/readability/RedundantDeclarationCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/RedundantDeclarationCheck.cpp?rev=285689=auto
==
--- 
clang-tools-extra/trunk/clang-tidy/readability/RedundantDeclarationCheck.cpp 
(added)
+++ 
clang-tools-extra/trunk/clang-tidy/readability/RedundantDeclarationCheck.cpp 
Tue Nov  1 08:26:15 2016
@@ -0,0 +1,71 @@
+//===--- RedundantDeclarationCheck.cpp - 
clang-tidy===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "RedundantDeclarationCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace readability {
+
+void RedundantDeclarationCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(namedDecl(anyOf(varDecl(), functionDecl())).bind("Decl"), 
this);
+}
+
+void RedundantDeclarationCheck::check(const MatchFinder::MatchResult ) {
+  const NamedDecl *D = Result.Nodes.getNodeAs("Decl");
+  const auto *Prev = D->getPreviousDecl();
+  if (!Prev)
+return;
+  if (Prev->getLocation() == D->getLocation())
+return;
+
+  const SourceManager  = *Result.SourceManager;
+
+  const bool DifferentHeaders =
+   !SM.isInMainFile(D->getLocation()) &&
+   !SM.isWrittenInSameFile(Prev->getLocation(), D->getLocation());
+
+  bool MultiVar = false;
+  if (const auto *VD = dyn_cast(D)) {
+if (VD->getPreviousDecl()->getStorageClass() == SC_Extern &&
+VD->getStorageClass() != SC_Extern)
+  return;
+// Is this a multivariable declaration?
+for (const auto Other : VD->getDeclContext()->decls()) {
+  if (Other != D && Other->getLocStart() == VD->getLocStart()) {
+MultiVar = true;
+   

[PATCH] D24656: [clang-tidy] Add check readability-redundant-declaration

2016-11-01 Thread Daniel Marjamäki via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL285689: [clang-tidy] Add check 
readability-redundant-declaration (authored by danielmarjamaki).

Changed prior to commit:
  https://reviews.llvm.org/D24656?vs=74478=76548#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D24656

Files:
  clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt
  clang-tools-extra/trunk/clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tools-extra/trunk/clang-tidy/readability/RedundantDeclarationCheck.cpp
  clang-tools-extra/trunk/clang-tidy/readability/RedundantDeclarationCheck.h
  clang-tools-extra/trunk/docs/ReleaseNotes.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/trunk/docs/clang-tidy/checks/readability-redundant-declaration.rst
  clang-tools-extra/trunk/test/clang-tidy/readability-redundant-declaration.cpp

Index: clang-tools-extra/trunk/clang-tidy/readability/ReadabilityTidyModule.cpp
===
--- clang-tools-extra/trunk/clang-tidy/readability/ReadabilityTidyModule.cpp
+++ clang-tools-extra/trunk/clang-tidy/readability/ReadabilityTidyModule.cpp
@@ -23,6 +23,7 @@
 #include "NamedParameterCheck.h"
 #include "NonConstParameterCheck.h"
 #include "RedundantControlFlowCheck.h"
+#include "RedundantDeclarationCheck.h"
 #include "RedundantMemberInitCheck.h"
 #include "RedundantSmartptrGetCheck.h"
 #include "RedundantStringCStrCheck.h"
@@ -68,6 +69,8 @@
 "readability-non-const-parameter");
 CheckFactories.registerCheck(
 "readability-redundant-control-flow");
+CheckFactories.registerCheck(
+"readability-redundant-declaration");
 CheckFactories.registerCheck(
 "readability-redundant-smartptr-get");
 CheckFactories.registerCheck(
Index: clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt
===
--- clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt
+++ clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt
@@ -16,6 +16,7 @@
   NonConstParameterCheck.cpp
   ReadabilityTidyModule.cpp
   RedundantControlFlowCheck.cpp
+  RedundantDeclarationCheck.cpp
   RedundantMemberInitCheck.cpp
   RedundantStringCStrCheck.cpp
   RedundantSmartptrGetCheck.cpp
Index: clang-tools-extra/trunk/clang-tidy/readability/RedundantDeclarationCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/readability/RedundantDeclarationCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/readability/RedundantDeclarationCheck.cpp
@@ -0,0 +1,71 @@
+//===--- RedundantDeclarationCheck.cpp - clang-tidy===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "RedundantDeclarationCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace readability {
+
+void RedundantDeclarationCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(namedDecl(anyOf(varDecl(), functionDecl())).bind("Decl"), this);
+}
+
+void RedundantDeclarationCheck::check(const MatchFinder::MatchResult ) {
+  const NamedDecl *D = Result.Nodes.getNodeAs("Decl");
+  const auto *Prev = D->getPreviousDecl();
+  if (!Prev)
+return;
+  if (Prev->getLocation() == D->getLocation())
+return;
+
+  const SourceManager  = *Result.SourceManager;
+
+  const bool DifferentHeaders =
+   !SM.isInMainFile(D->getLocation()) &&
+   !SM.isWrittenInSameFile(Prev->getLocation(), D->getLocation());
+
+  bool MultiVar = false;
+  if (const auto *VD = dyn_cast(D)) {
+if (VD->getPreviousDecl()->getStorageClass() == SC_Extern &&
+VD->getStorageClass() != SC_Extern)
+  return;
+// Is this a multivariable declaration?
+for (const auto Other : VD->getDeclContext()->decls()) {
+  if (Other != D && Other->getLocStart() == VD->getLocStart()) {
+MultiVar = true;
+break;
+  }
+}
+  } else {
+const auto *FD = cast(D);
+if (FD->isThisDeclarationADefinition())
+  return;
+  }
+
+  SourceLocation EndLoc = Lexer::getLocForEndOfToken(
+  D->getSourceRange().getEnd(), 0, SM, Result.Context->getLangOpts());
+  {
+auto Diag = diag(D->getLocation(), "redundant %0 declaration")
+<< D;
+if (!MultiVar && !DifferentHeaders)
+  Diag << FixItHint::CreateRemoval(
+  SourceRange(D->getSourceRange().getBegin(), EndLoc));
+  }
+  diag(Prev->getLocation(), "previously declared here", DiagnosticIDs::Note);
+}
+
+} // namespace readability
+} // namespace tidy
+} // namespace clang
Index: 

r285688 - [x86][inline-asm][clang] accept 'v' constraint

2016-11-01 Thread Michael Zuckerman via cfe-commits
Author: mzuckerm
Date: Tue Nov  1 08:16:44 2016
New Revision: 285688

URL: http://llvm.org/viewvc/llvm-project?rev=285688=rev
Log:
[x86][inline-asm][clang] accept 'v' constraint
Commit on behalf of: Coby Tayree

1.'v' constraint for (x86) non-avx arch imitates the already implemented 'x' 
constraint, i.e. allows XMM{0-15} & YMM{0-15} depending on the apparent arch & 
mode (32/64).
2.for the avx512 arch it allows [X,Y,Z]MM{0-31} (mode dependent)

This patch applies the needed changes to clang
LLVM patch: https://reviews.llvm.org/D25005

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

Added:
cfe/trunk/test/CodeGen/x86-inline-asm-v-constraint.c
Modified:
cfe/trunk/lib/Basic/Targets.cpp

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=285688=285687=285688=diff
==
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Tue Nov  1 08:16:44 2016
@@ -4018,6 +4018,7 @@ X86TargetInfo::validateAsmConstraint(con
   case 'u': // Second from top of floating point stack.
   case 'q': // Any register accessible as [r]l: a, b, c, and d.
   case 'y': // Any MMX register.
+  case 'v': // Any {X,Y,Z}MM register (Arch & context dependent)
   case 'x': // Any SSE register.
   case 'k': // Any AVX512 mask register (same as Yk, additionaly allows k0
 // for intermideate k reg operations).
@@ -4062,6 +4063,7 @@ bool X86TargetInfo::validateOperandSize(
   case 't':
   case 'u':
 return Size <= 128;
+  case 'v':
   case 'x':
 if (SSELevel >= AVX512F)
   // 512-bit zmm registers can be used if target supports AVX512F.

Added: cfe/trunk/test/CodeGen/x86-inline-asm-v-constraint.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/x86-inline-asm-v-constraint.c?rev=285688=auto
==
--- cfe/trunk/test/CodeGen/x86-inline-asm-v-constraint.c (added)
+++ cfe/trunk/test/CodeGen/x86-inline-asm-v-constraint.c Tue Nov  1 08:16:44 
2016
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -emit-llvm -target-cpu 
x86-64 -o - |opt -instnamer -S |FileCheck %s --check-prefix SSE
+// RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -emit-llvm -target-cpu 
skylake -D AVX -o -|opt -instnamer -S  | FileCheck %s --check-prefixes AVX,SSE
+// RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -emit-llvm -target-cpu 
skylake-avx512 -D AVX512 -D AVX -o -|opt -instnamer -S  | FileCheck %s 
--check-prefixes AVX512,AVX,SSE
+// RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -emit-llvm -target-cpu 
knl -D AVX -D AVX512 -o - |opt -instnamer -S  | FileCheck %s --check-prefixes 
AVX512,AVX,SSE
+
+typedef float __m128 __attribute__ ((vector_size (16)));
+typedef float __m256 __attribute__ ((vector_size (32)));
+typedef float __m512 __attribute__ ((vector_size (64)));
+
+// SSE: call <4 x float> asm "vmovhlps $1, $2, $0", 
"=v,v,v,~{dirflag},~{fpsr},~{flags}"(i64 %tmp, <4 x float> %tmp1)
+__m128 testXMM(__m128 _xmm0, long _l) {
+  __asm__("vmovhlps %1, %2, %0" :"=v"(_xmm0) : "v"(_l), "v"(_xmm0));
+  return _xmm0;
+}
+
+// AVX: call <8 x float> asm "vmovsldup $1, $0", 
"=v,v,~{dirflag},~{fpsr},~{flags}"(<8 x float> %tmp)
+__m256 testYMM(__m256 _ymm0) {
+#ifdef AVX
+  __asm__("vmovsldup %1, %0" :"=v"(_ymm0) : "v"(_ymm0));
+#endif
+  return _ymm0;
+}
+
+// AVX512: call <16 x float> asm "vpternlogd $$0, $1, $2, $0", 
"=v,v,v,~{dirflag},~{fpsr},~{flags}"(<16 x float> %tmp, <16 x float> %tmp1)
+__m512 testZMM(__m512 _zmm0, __m512 _zmm1) {
+#ifdef AVX512
+  __asm__("vpternlogd $0, %1, %2, %0" :"=v"(_zmm0) : "v"(_zmm1), "v"(_zmm0));
+#endif
+  return _zmm0;
+}


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


[PATCH] D26184: Protect lock tests under libcpp-no-exceptions

2016-11-01 Thread Roger Ferrer Ibanez via cfe-commits
rogfer01 created this revision.
rogfer01 added reviewers: rmaprath, mclow.lists, EricWF.
rogfer01 added a subscriber: cfe-commits.

Skip tests that expect an exception to be thrown.


https://reviews.llvm.org/D26184

Files:
  test/std/thread/thread.mutex/thread.lock.algorithm/lock.pass.cpp
  test/std/thread/thread.mutex/thread.lock.algorithm/try_lock.pass.cpp
  
test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/lock.pass.cpp
  
test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/try_lock.pass.cpp
  
test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/try_lock_for.pass.cpp
  
test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/try_lock_until.pass.cpp
  
test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/unlock.pass.cpp
  
test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/lock.pass.cpp
  
test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/try_lock.pass.cpp
  
test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/try_lock_for.pass.cpp
  
test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/try_lock_until.pass.cpp
  
test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/unlock.pass.cpp
  
test/std/thread/thread.mutex/thread.once/thread.once.callonce/call_once.pass.cpp

Index: test/std/thread/thread.mutex/thread.once/thread.once.callonce/call_once.pass.cpp
===
--- test/std/thread/thread.mutex/thread.once/thread.once.callonce/call_once.pass.cpp
+++ test/std/thread/thread.mutex/thread.once/thread.once.callonce/call_once.pass.cpp
@@ -7,7 +7,6 @@
 //
 //===--===//
 //
-// XFAIL: libcpp-no-exceptions
 // UNSUPPORTED: libcpp-has-no-threads
 
 // 
@@ -50,19 +49,21 @@
 ++init3_called;
 std::this_thread::sleep_for(ms(250));
 if (init3_called == 1)
-throw 1;
+TEST_THROW(1);
 ++init3_completed;
 }
 
 void f3()
 {
+#ifndef TEST_HAS_NO_EXCEPTIONS
 try
 {
 std::call_once(flg3, init3);
 }
 catch (...)
 {
 }
+#endif
 }
 
 #ifndef _LIBCPP_HAS_NO_VARIADICS
@@ -197,6 +198,7 @@
 t1.join();
 assert(init0_called == 1);
 }
+#ifndef TEST_HAS_NO_EXCEPTIONS
 // check basic exception safety
 {
 std::thread t0(f3);
@@ -206,6 +208,7 @@
 assert(init3_called == 2);
 assert(init3_completed == 1);
 }
+#endif
 // check deadlock avoidance
 {
 std::thread t0(f41);
Index: test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/unlock.pass.cpp
===
--- test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/unlock.pass.cpp
+++ test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/unlock.pass.cpp
@@ -7,7 +7,6 @@
 //
 //===--===//
 //
-// XFAIL: libcpp-no-exceptions
 // UNSUPPORTED: libcpp-has-no-threads
 
 // 
@@ -19,6 +18,8 @@
 #include 
 #include 
 
+#include "test_macros.h"
+
 bool unlock_called = false;
 
 struct mutex
@@ -35,6 +36,7 @@
 lk.unlock();
 assert(unlock_called == true);
 assert(lk.owns_lock() == false);
+#ifndef TEST_HAS_NO_EXCEPTIONS
 try
 {
 lk.unlock();
@@ -44,7 +46,9 @@
 {
 assert(e.code().value() == EPERM);
 }
+#endif
 lk.release();
+#ifndef TEST_HAS_NO_EXCEPTIONS
 try
 {
 lk.unlock();
@@ -54,4 +58,5 @@
 {
 assert(e.code().value() == EPERM);
 }
+#endif
 }
Index: test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/try_lock_until.pass.cpp
===
--- test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/try_lock_until.pass.cpp
+++ test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/try_lock_until.pass.cpp
@@ -7,7 +7,6 @@
 //
 //===--===//
 //
-// XFAIL: libcpp-no-exceptions
 // UNSUPPORTED: libcpp-has-no-threads
 
 // 
@@ -20,6 +19,8 @@
 #include 
 #include 
 
+#include "test_macros.h"
+
 bool try_lock_until_called = false;
 
 struct mutex
@@ -44,6 +45,7 @@
 assert(lk.try_lock_until(Clock::now()) == true);
 assert(try_lock_until_called == true);
 assert(lk.owns_lock() == true);
+#ifndef TEST_HAS_NO_EXCEPTIONS
 try
 {
 lk.try_lock_until(Clock::now());
@@ -53,11 +55,13 @@
 {
 assert(e.code().value() == EDEADLK);
 }
+#endif
 lk.unlock();
 

  1   2   >