[PATCH] D42092: implement C++ dr388 for the Itanium C++ ABI: proper handling of catching exceptions by reference

2018-01-15 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: lib/CodeGen/ItaniumCXXABI.cpp:3878
+  } else {
+// FIXME: We could filter out definitely-unreachable catch handlers.
+EHCatchScope *LaterCatchScope =

There are a lot of other optimizations possible here. For example: if there are 
no later catches, and no enclosing EH scopes, we can just `resume` (before the 
`__cxa_begin_catch`) call. Or if the first such later catch will definitely 
catch the exception (eg, `catch (int*&) {} catch (int*) {}`), we could branch 
directly to it.

I'm inclined to think we should keep the frontend emission simpler and 
implement these cases as EHABI-aware middle-end optimization passes if we care 
enough about them.


Repository:
  rC Clang

https://reviews.llvm.org/D42092



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


[PATCH] D42092: implement C++ dr388 for the Itanium C++ ABI: proper handling of catching exceptions by reference

2018-01-15 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith created this revision.
rsmith added a reviewer: rjmccall.
Herald added subscribers: kristof.beyls, sanjoy, aemerson.

This patch fixes three issues with how Clang emits code to catch exceptions by 
reference:

1. We would sometimes bind the reference directly to the exception object when 
a temporary is required (when a pointer-to-member is converted by a 
qualification conversion but not adjusted).
2. We would sometimes bind the reference to a temporary when a direct binding 
is required (when catching a pointer-to-class-object where no derived-to-base 
or qualification conversion is required).
3. We would incorrectly allow a non-const (or volatile) reference to catch an 
exception of a different type that can be converted to the right type.

A single strategy is used to fix all three issues: where necessary, we extract 
the `type_info` of the exception object from the `__cxa_exception` header, and 
compare it directly against the reference's pointee `type_info`. For cases #1 
and #2, this tells us whether to bind to a temporary object or to the exception 
object; for case #3, if the types don't match and the reference can't bind to a 
temporary, we rethrow the exception through the remaining `catch` clauses of 
the `try` statement.

This patch is insufficiently tested (no changes to the test suite, and no 
testing has been done whatsoever for the ARM64 non-unique `type_info` case), 
but I'm posting it now to gauge whether this is a direction we want to pursue 
for DR388 (as opposed to continuing to get this wrong until the Itanium C++ ABI 
has a chance to take an ABI break to properly handle catch-by-reference).

[Despite the different approach to determining catchability, the MS ABI appears 
to have exactly the same bugs (it too does not distinguish between catch by 
value and catch by reference), and I would assume the same approach would also 
work there, assuming the actual type of the exception object can be discerned, 
but I've not looked at all at implementing this in that ABI.]


Repository:
  rC Clang

https://reviews.llvm.org/D42092

Files:
  lib/CodeGen/CGCXXABI.h
  lib/CodeGen/CGCleanup.h
  lib/CodeGen/CGException.cpp
  lib/CodeGen/ItaniumCXXABI.cpp
  lib/CodeGen/MicrosoftCXXABI.cpp
  lib/CodeGen/TargetInfo.cpp
  lib/CodeGen/TargetInfo.h

Index: lib/CodeGen/TargetInfo.h
===
--- lib/CodeGen/TargetInfo.h
+++ lib/CodeGen/TargetInfo.h
@@ -65,6 +65,11 @@
   virtual void emitTargetMD(const Decl *D, llvm::GlobalValue *GV,
 CodeGen::CodeGenModule &M) const {}
 
+  /// Determines the size of struct __cxa_exception on this platform,
+  /// in 8-bit units, excluding the trailing _Unwind_Exception member.
+  /// The Itanium ABI defines the layout of this struct.
+  virtual unsigned getSizeOfCxaException() const;
+
   /// Determines the size of struct _Unwind_Exception on this platform,
   /// in 8-bit units.  The Itanium ABI defines this as:
   ///   struct _Unwind_Exception {
Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -369,6 +369,16 @@
 
 TargetCodeGenInfo::~TargetCodeGenInfo() { delete Info; }
 
+unsigned TargetCodeGenInfo::getSizeOfCxaException() const {
+  // __cxa_exception comprises 5 pointers followed by 2 ints followed by 4
+  // more pointers, then the _Unwind_Exception object. We assume that no
+  // padding is introduced between these fields.
+  ASTContext &Ctx = Info->getContext();
+  return (9 * Ctx.getTypeSizeInChars(Ctx.VoidPtrTy) +
+  2 * Ctx.getTypeSizeInChars(Ctx.IntTy))
+  .getQuantity();
+}
+
 // If someone can figure out a general rule for this, that would be great.
 // It's probably just doomed to be platform-dependent, though.
 unsigned TargetCodeGenInfo::getSizeOfUnwindException() const {
Index: lib/CodeGen/MicrosoftCXXABI.cpp
===
--- lib/CodeGen/MicrosoftCXXABI.cpp
+++ lib/CodeGen/MicrosoftCXXABI.cpp
@@ -120,7 +120,8 @@
   void emitRethrow(CodeGenFunction &CGF, bool isNoReturn) override;
   void emitThrow(CodeGenFunction &CGF, const CXXThrowExpr *E) override;
 
-  void emitBeginCatch(CodeGenFunction &CGF, const CXXCatchStmt *C) override;
+  void emitBeginCatch(CodeGenFunction &CGF, const CXXCatchStmt *C,
+  ArrayRef LaterHandlers) override;
 
   llvm::GlobalVariable *getMSCompleteObjectLocator(const CXXRecordDecl *RD,
const VPtrInfo &Info);
@@ -904,8 +905,9 @@
 };
 }
 
-void MicrosoftCXXABI::emitBeginCatch(CodeGenFunction &CGF,
- const CXXCatchStmt *S) {
+void MicrosoftCXXABI::emitBeginCatch(
+CodeGenFunction &CGF, const CXXCatchStmt *S,
+ArrayRef LaterHandlers) {
   // In the MS ABI, the runtime handles the copy, and the catch handler is
   // responsible for destruction.

r322530 - [Sema] Fix a crash on invalid features in multiversioning

2018-01-15 Thread George Burgess IV via cfe-commits
Author: gbiv
Date: Mon Jan 15 19:01:50 2018
New Revision: 322530

URL: http://llvm.org/viewvc/llvm-project?rev=322530&view=rev
Log:
[Sema] Fix a crash on invalid features in multiversioning

We were trying to emit a diag::err_bad_multiversion_option diagnostic,
which expects an int as its first argument, with a string argument. As
it happens, the string `Feature` that was causing this was shadowing an
int `Feature` from the surrounding scope. :)

Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaCXX/attr-target-mv.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=322530&r1=322529&r2=322530&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Jan 15 19:01:50 2018
@@ -9175,9 +9175,9 @@ static bool CheckMultiVersionValue(Sema
 return true;
   }
 
-  for (const auto &Feature : ParseInfo.Features) {
-auto BareFeat = StringRef{Feature}.substr(1);
-if (Feature[0] == '-') {
+  for (const auto &Feat : ParseInfo.Features) {
+auto BareFeat = StringRef{Feat}.substr(1);
+if (Feat[0] == '-') {
   S.Diag(FD->getLocation(), diag::err_bad_multiversion_option)
   << Feature << ("no-" + BareFeat).str();
   return true;

Modified: cfe/trunk/test/SemaCXX/attr-target-mv.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/attr-target-mv.cpp?rev=322530&r1=322529&r2=322530&view=diff
==
--- cfe/trunk/test/SemaCXX/attr-target-mv.cpp (original)
+++ cfe/trunk/test/SemaCXX/attr-target-mv.cpp Mon Jan 15 19:01:50 2018
@@ -1,4 +1,11 @@
 // RUN: %clang_cc1 -triple x86_64-linux-gnu  -fsyntax-only -verify 
-fexceptions -fcxx-exceptions %s -std=c++14
+void __attribute__((target("default"))) invalid_features(void);
+//expected-error@+2 {{function multiversioning doesn't support feature 
'hello_world'}}
+//expected-warning@+1 {{ignoring unsupported 'hello_world' in the target 
attribute string}}
+void __attribute__((target("hello_world"))) invalid_features(void);
+//expected-error@+1 {{function multiversioning doesn't support feature 
'no-sse4.2'}}
+void __attribute__((target("no-sse4.2"))) invalid_features(void);
+
 void __attribute__((target("sse4.2"))) no_default(void);
 void __attribute__((target("arch=sandybridge")))  no_default(void);
 


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


[libcxx] r322529 - More constexpr algorithms from P0202: lower_bound, upper_bound, equal_range, binary_search

2018-01-15 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Mon Jan 15 18:34:41 2018
New Revision: 322529

URL: http://llvm.org/viewvc/llvm-project?rev=322529&view=rev
Log:
More constexpr algorithms from P0202: lower_bound, upper_bound, equal_range, 
binary_search

Modified:
libcxx/trunk/include/algorithm
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.equal/equal.pass.cpp

libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.equal/equal_pred.pass.cpp

libcxx/trunk/test/std/algorithms/alg.sorting/alg.binary.search/binary.search/binary_search.pass.cpp

libcxx/trunk/test/std/algorithms/alg.sorting/alg.binary.search/binary.search/binary_search_comp.pass.cpp

libcxx/trunk/test/std/algorithms/alg.sorting/alg.binary.search/equal.range/equal_range.pass.cpp

libcxx/trunk/test/std/algorithms/alg.sorting/alg.binary.search/equal.range/equal_range_comp.pass.cpp

libcxx/trunk/test/std/algorithms/alg.sorting/alg.binary.search/lower.bound/lower_bound.pass.cpp

libcxx/trunk/test/std/algorithms/alg.sorting/alg.binary.search/lower.bound/lower_bound_comp.pass.cpp

libcxx/trunk/test/std/algorithms/alg.sorting/alg.binary.search/upper.bound/upper_bound.pass.cpp

libcxx/trunk/test/std/algorithms/alg.sorting/alg.binary.search/upper.bound/upper_bound_comp.pass.cpp

Modified: libcxx/trunk/include/algorithm
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/algorithm?rev=322529&r1=322528&r2=322529&view=diff
==
--- libcxx/trunk/include/algorithm (original)
+++ libcxx/trunk/include/algorithm Mon Jan 15 18:34:41 2018
@@ -321,7 +321,7 @@ template 
-ForwardIterator  // constexpr in C++20
+constexpr ForwardIterator  // constexpr in C++20
 partition_point(ForwardIterator first, ForwardIterator last, Predicate 
pred);
 
 template 
@@ -383,35 +383,35 @@ template 
-ForwardIterator
+constexpr ForwardIterator // constexpr in C++20
 lower_bound(ForwardIterator first, ForwardIterator last, const T& value);
 
 template 
-ForwardIterator
+constexpr ForwardIterator // constexpr in C++20
 lower_bound(ForwardIterator first, ForwardIterator last, const T& value, 
Compare comp);
 
 template 
-ForwardIterator
+constexpr ForwardIterator // constexpr in C++20
 upper_bound(ForwardIterator first, ForwardIterator last, const T& value);
 
 template 
-ForwardIterator
+constexpr ForwardIterator // constexpr in C++20
 upper_bound(ForwardIterator first, ForwardIterator last, const T& value, 
Compare comp);
 
 template 
-pair
+constexpr pair  // constexpr in C++20
 equal_range(ForwardIterator first, ForwardIterator last, const T& value);
 
 template 
-pair
+constexpr pair  // constexpr in C++20
 equal_range(ForwardIterator first, ForwardIterator last, const T& value, 
Compare comp);
 
 template 
-bool
+constexpr bool// constexpr in C++20
 binary_search(ForwardIterator first, ForwardIterator last, const T& value);
 
 template 
-bool
+bool  // constexpr in C++20
 binary_search(ForwardIterator first, ForwardIterator last, const T& value, 
Compare comp);
 
 template 
@@ -4195,7 +4195,7 @@ _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS
 // lower_bound
 
 template 
-_ForwardIterator
+_LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
 __lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& 
__value_, _Compare __comp)
 {
 typedef typename iterator_traits<_ForwardIterator>::difference_type 
difference_type;
@@ -4217,7 +4217,7 @@ __lower_bound(_ForwardIterator __first,
 }
 
 template 
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
 _ForwardIterator
 lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& 
__value_, _Compare __comp)
 {
@@ -4232,7 +4232,7 @@ lower_bound(_ForwardIterator __first, _F
 }
 
 template 
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
 _ForwardIterator
 lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& 
__value_)
 {
@@ -4243,7 +4243,7 @@ lower_bound(_ForwardIterator __first, _F
 // upper_bound
 
 template 
-_ForwardIterator
+_LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
 __upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& 
__value_, _Compare __comp)
 {
 typedef typename iterator_traits<_ForwardIterator>::difference_type 
difference_type;
@@ -4265,7 +4265,7 @@ __upper_bound(_ForwardIterator __first,
 }
 
 template 
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
 _ForwardIterator
 upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& 
__value_, _Compare __comp)
 {
@@ -4280,7 +4280,7 @@ upper_bound(_ForwardIterator __first, _F
 }
 
 template 
-inline _LIBCPP_INLINE

[libcxx] r322528 - Actually CALL the constexpr tests.

2018-01-15 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Mon Jan 15 18:11:13 2018
New Revision: 322528

URL: http://llvm.org/viewvc/llvm-project?rev=322528&view=rev
Log:
Actually CALL the constexpr tests.

Modified:
libcxx/trunk/test/std/algorithms/alg.nonmodifying/mismatch/mismatch.pass.cpp

libcxx/trunk/test/std/algorithms/alg.nonmodifying/mismatch/mismatch_pred.pass.cpp

Modified: 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/mismatch/mismatch.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.nonmodifying/mismatch/mismatch.pass.cpp?rev=322528&r1=322527&r2=322528&view=diff
==
--- 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/mismatch/mismatch.pass.cpp 
(original)
+++ 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/mismatch/mismatch.pass.cpp 
Mon Jan 15 18:11:13 2018
@@ -86,4 +86,8 @@ int main()
 assert(std::mismatch(II(ia), II(ia + sa), II(ib), II(ib+2))
 == (std::pair(II(ia+2), II(ib+2;
 #endif
+
+#if TEST_STD_VER > 17
+static_assert(test_constexpr());
+#endif
 }

Modified: 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/mismatch/mismatch_pred.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.nonmodifying/mismatch/mismatch_pred.pass.cpp?rev=322528&r1=322527&r2=322528&view=diff
==
--- 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/mismatch/mismatch_pred.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/mismatch/mismatch_pred.pass.cpp
 Mon Jan 15 18:11:13 2018
@@ -111,4 +111,8 @@ int main()
 assert(std::mismatch(ia, ia + sa, ib, ib + 2, EQ()) ==
(std::pair(ia+2,ib+2)));
 #endif
+
+#if TEST_STD_VER > 17
+static_assert(test_constexpr());
+#endif
 }


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


[libcxx] r322527 - More constexpr (re P0202) - equal and mismatch

2018-01-15 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Mon Jan 15 18:04:10 2018
New Revision: 322527

URL: http://llvm.org/viewvc/llvm-project?rev=322527&view=rev
Log:
More constexpr (re P0202) - equal and mismatch

Modified:
libcxx/trunk/include/algorithm
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.equal/equal.pass.cpp

libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.equal/equal_pred.pass.cpp
libcxx/trunk/test/std/algorithms/alg.nonmodifying/mismatch/mismatch.pass.cpp

libcxx/trunk/test/std/algorithms/alg.nonmodifying/mismatch/mismatch_pred.pass.cpp

Modified: libcxx/trunk/include/algorithm
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/algorithm?rev=322527&r1=322526&r2=322527&view=diff
==
--- libcxx/trunk/include/algorithm (original)
+++ libcxx/trunk/include/algorithm Mon Jan 15 18:04:10 2018
@@ -87,41 +87,41 @@ template 
-pair
+constexpr pair   // constexpr in C++20
 mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 
first2);
 
 template 
-pair
+constexpr pair   // constexpr in C++20
 mismatch(InputIterator1 first1, InputIterator1 last1,
  InputIterator2 first2, InputIterator2 last2); // **C++14**
 
 template 
-pair
+constexpr pair   // constexpr in C++20
 mismatch(InputIterator1 first1, InputIterator1 last1,
  InputIterator2 first2, BinaryPredicate pred);
 
 template 
-pair
+constexpr pair   // constexpr in C++20
 mismatch(InputIterator1 first1, InputIterator1 last1,
  InputIterator2 first2, InputIterator2 last2,
  BinaryPredicate pred); // **C++14**
 
 template 
-bool
+constexpr bool  // constexpr in C++20
 equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2);
 
 template 
-bool
+constexpr bool  // constexpr in C++20
 equal(InputIterator1 first1, InputIterator1 last1,
   InputIterator2 first2, InputIterator2 last2); // **C++14**
 
 template 
-bool
+constexpr bool  // constexpr in C++20
 equal(InputIterator1 first1, InputIterator1 last1,
   InputIterator2 first2, BinaryPredicate pred);
 
 template 
-bool
+constexpr bool  // constexpr in C++20
 equal(InputIterator1 first1, InputIterator1 last1,
   InputIterator2 first2, InputIterator2 last2,
   BinaryPredicate pred); // **C++14**
@@ -1268,7 +1268,7 @@ count_if(_InputIterator __first, _InputI
 // mismatch
 
 template 
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
 pair<_InputIterator1, _InputIterator2>
 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
  _InputIterator2 __first2, _BinaryPredicate __pred)
@@ -1280,7 +1280,7 @@ mismatch(_InputIterator1 __first1, _Inpu
 }
 
 template 
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
 pair<_InputIterator1, _InputIterator2>
 mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 
__first2)
 {
@@ -1291,7 +1291,7 @@ mismatch(_InputIterator1 __first1, _Inpu
 
 #if _LIBCPP_STD_VER > 11
 template 
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
 pair<_InputIterator1, _InputIterator2>
 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
  _InputIterator2 __first2, _InputIterator2 __last2,
@@ -1304,7 +1304,7 @@ mismatch(_InputIterator1 __first1, _Inpu
 }
 
 template 
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
 pair<_InputIterator1, _InputIterator2>
 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
  _InputIterator2 __first2, _InputIterator2 __last2)
@@ -1318,7 +1318,7 @@ mismatch(_InputIterator1 __first1, _Inpu
 // equal
 
 template 
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
 bool
 equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 
__first2, _BinaryPredicate __pred)
 {
@@ -1329,7 +1329,7 @@ equal(_InputIterator1 __first1, _InputIt
 }
 
 template 
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
 bool
 equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 
__first2)
 {
@@ -1340,7 +1340,7 @@ equal(_InputIterator1 __first1, _InputIt
 
 #if _LIBCPP_STD_VER > 11
 template 
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
 bool
 __equal(_InputIterator1 __first1, _InputIterator1 __last1,
 _InputIterator2 __first2, _InputIterator2 __last2, _BinaryPredicate 
__pred,
@@ -1353,7 +1353,7 @@ __equal(_InputIterator1 __first1, _Input
 }
 
 template 
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
 bool
 __equal(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1,
 _

[PATCH] D41534: Don't add empty InstalledDir as a candidate GCC location

2018-01-15 Thread Jack Andersen via Phabricator via cfe-commits
jackoalan abandoned this revision.
jackoalan added a comment.

I've found that passing `--gcc-toolchain=/usr` results in the exact behavior 
I'm after.

Feel free to reopen if desired.


Repository:
  rC Clang

https://reviews.llvm.org/D41534



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


[PATCH] D41816: [analyzer] Model and check unrepresentable left shifts

2018-01-15 Thread Reka Kovacs via Phabricator via cfe-commits
rnkovacs added inline comments.



Comment at: lib/StaticAnalyzer/Checkers/UndefResultChecker.cpp:150
+SB.getKnownValue(state, C.getSVal(B->getRHS()));
+if ((unsigned) RHS->getZExtValue() > LHS->countLeadingZeros()) {
+  OS << "The result of the left shift is undefined due to shifting \'"

dcoughlin wrote:
> This inner 'if' looks fishy to me because if the 'else' branch is ever taken 
> then OS will be empty.
> 
> If the else branch can't be taken then you should turn it into an assert(). 
> If it can be taken, then you should make sure that the fall through goes 
> through the "default" else case at the bottom. One way to do this is to pull 
> out the "is representable logic" into a helper function and call that in the 
> containing 'else if'.
> 
> Something like:
> 
> ```
> if (B->getOpcode() == BinaryOperatorKind::BO_Shl && 
> isLeftShiftResultRepresentable(LHS, RHS)) {
>   OS << "The result of the left shift ..."
> }
> ```
I overlooked this issue, thanks for pointing out. I pulled the logic out into a 
helper function.


https://reviews.llvm.org/D41816



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


[PATCH] D41816: [analyzer] Model and check unrepresentable left shifts

2018-01-15 Thread Reka Kovacs via Phabricator via cfe-commits
rnkovacs updated this revision to Diff 129905.
rnkovacs marked an inline comment as done.

https://reviews.llvm.org/D41816

Files:
  lib/StaticAnalyzer/Checkers/UndefResultChecker.cpp
  lib/StaticAnalyzer/Core/BasicValueFactory.cpp
  test/Analysis/bitwise-ops.c


Index: test/Analysis/bitwise-ops.c
===
--- test/Analysis/bitwise-ops.c
+++ test/Analysis/bitwise-ops.c
@@ -51,3 +51,9 @@
   }
   return 0;
 }
+
+int testUnrepresentableLeftShift(int a) {
+  if (a == 8)
+return a << 30; // expected-warning{{The result of the left shift is 
undefined due to shifting '8' by '30', which is unrepresentable in the unsigned 
version of the return type 'int'}}
+  return 0;
+}
Index: lib/StaticAnalyzer/Core/BasicValueFactory.cpp
===
--- lib/StaticAnalyzer/Core/BasicValueFactory.cpp
+++ lib/StaticAnalyzer/Core/BasicValueFactory.cpp
@@ -224,7 +224,6 @@
   // FIXME: This logic should probably go higher up, where we can
   // test these conditions symbolically.
 
-  // FIXME: Expand these checks to include all undefined behavior.
   if (V1.isSigned() && V1.isNegative())
 return nullptr;
 
@@ -236,16 +235,17 @@
   if (Amt >= V1.getBitWidth())
 return nullptr;
 
+  if (V1.isSigned() && Amt > V1.countLeadingZeros())
+  return nullptr;
+
   return &getValue( V1.operator<<( (unsigned) Amt ));
 }
 
 case BO_Shr: {
 
   // FIXME: This logic should probably go higher up, where we can
   // test these conditions symbolically.
 
-  // FIXME: Expand these checks to include all undefined behavior.
-
   if (V2.isSigned() && V2.isNegative())
 return nullptr;
 
Index: lib/StaticAnalyzer/Checkers/UndefResultChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/UndefResultChecker.cpp
+++ lib/StaticAnalyzer/Checkers/UndefResultChecker.cpp
@@ -64,6 +64,15 @@
   B->getRHS(), C.getASTContext().getIntWidth(B->getLHS()->getType()));
 }
 
+static bool isLeftShiftResultUnrepresentable(const BinaryOperator *B,
+ CheckerContext &C) {
+  SValBuilder &SB = C.getSValBuilder();
+  ProgramStateRef State = C.getState();
+  const llvm::APSInt *LHS = SB.getKnownValue(State, C.getSVal(B->getLHS()));
+  const llvm::APSInt *RHS = SB.getKnownValue(State, C.getSVal(B->getRHS()));
+  return (unsigned)RHS->getZExtValue() > LHS->countLeadingZeros();
+}
+
 void UndefResultChecker::checkPostStmt(const BinaryOperator *B,
CheckerContext &C) const {
   ProgramStateRef state = C.getState();
@@ -141,6 +150,18 @@
  C.isNegative(B->getLHS())) {
 OS << "The result of the left shift is undefined because the left "
   "operand is negative";
+  } else if (B->getOpcode() == BinaryOperatorKind::BO_Shl &&
+ isLeftShiftResultUnrepresentable(B, C)) {
+SValBuilder &SB = C.getSValBuilder();
+const llvm::APSInt *LHS =
+SB.getKnownValue(state, C.getSVal(B->getLHS()));
+const llvm::APSInt *RHS =
+SB.getKnownValue(state, C.getSVal(B->getRHS()));
+OS << "The result of the left shift is undefined due to shifting \'"
+   << LHS->getSExtValue() << "\' by \'" << RHS->getZExtValue()
+   << "\', which is unrepresentable in the unsigned version of "
+   << "the return type \'" << B->getLHS()->getType().getAsString()
+   << "\'";
   } else {
 OS << "The result of the '"
<< BinaryOperator::getOpcodeStr(B->getOpcode())


Index: test/Analysis/bitwise-ops.c
===
--- test/Analysis/bitwise-ops.c
+++ test/Analysis/bitwise-ops.c
@@ -51,3 +51,9 @@
   }
   return 0;
 }
+
+int testUnrepresentableLeftShift(int a) {
+  if (a == 8)
+return a << 30; // expected-warning{{The result of the left shift is undefined due to shifting '8' by '30', which is unrepresentable in the unsigned version of the return type 'int'}}
+  return 0;
+}
Index: lib/StaticAnalyzer/Core/BasicValueFactory.cpp
===
--- lib/StaticAnalyzer/Core/BasicValueFactory.cpp
+++ lib/StaticAnalyzer/Core/BasicValueFactory.cpp
@@ -224,7 +224,6 @@
   // FIXME: This logic should probably go higher up, where we can
   // test these conditions symbolically.
 
-  // FIXME: Expand these checks to include all undefined behavior.
   if (V1.isSigned() && V1.isNegative())
 return nullptr;
 
@@ -236,16 +235,17 @@
   if (Amt >= V1.getBitWidth())
 return nullptr;
 
+  if (V1.isSigned() && Amt > V1.countLeadingZeros())
+  return nullptr;
+
   return &getValue( V1.operator<<( (unsigned) Amt ));
 }
 
 case BO_Shr: {
 
   // FIXME: This logic should probably go hig

[PATCH] D40023: [RISCV] Implement ABI lowering

2018-01-15 Thread Alex Bradbury via Phabricator via cfe-commits
asb added a comment.

Thanks Eli, that saved me some time - fixed in 
https://reviews.llvm.org/rL322514 (clang-x86_64-linux-selfhost-modules-2 is now 
green).




Comment at: lib/CodeGen/TargetInfo.cpp:8913
+  }
+  return getNaturalAlignIndirect(Ty, /*ByVal=*/true);
+}

efriedma wrote:
> asb wrote:
> > efriedma wrote:
> > > asb wrote:
> > > > efriedma wrote:
> > > > > The spec says "Aggregates larger than 2✕XLEN bits are passed by 
> > > > > reference and are replaced in the argument list with the address".  
> > > > > That's not byval.
> > > > The LLVM backend lowers byval in that way. Given that at this point we 
> > > > have a trivial data type (plain struct or similar) which is 
> > > > copied-by-value by C semantics, the only difference is whether the 
> > > > generated IR indicates implicit copying with 'byval' or relies on the 
> > > > caller explicitly doing the copy. For some reason I thought 'byval' was 
> > > > preferred, but looking again it seems uncommon to do it this way. I've 
> > > > changed it to false - thanks for spotting this.
> > > "byval" generally means the value is memcpy'ed into the argument list (so 
> > > there is no pointer in the argument list). This is useful for handling C 
> > > calling conventions which allow excessively large structs to be passed in 
> > > the argument list, so the backend can emit a memcpy rather than expanding 
> > > the operation into straight-line code.  The RISCV backend handling of 
> > > byval is wrong, in the sense that it isn't consistent with what any other 
> > > backend does.
> > > 
> > > This isn't relevant to the RISC-V C calling convention, but you should 
> > > probably fix the backend at some point to avoid future confusion.
> > If I understand your concern correctly, it's that the RISCV backend passes 
> > a pointer to the byval copied argument rather than passing it direct on the 
> > stack? Isn't that consistent with what the Sparc, Lanai and the PPC 
> > backends do? It also seems consistent with my reading of the description of 
> > the byval attribute in the langref - a hidden copy is made. Whether that 
> > hidden copy is passed direct or a pointer to it is passed (which is 
> > consistent with the RISC-V calling convention for large values) seems an 
> > orthogonal concern.
> I can see SPARC does in fact pass byval arguments like you said (and I'll 
> assume Lanai behaves the same way).  PowerPC doesn't, though, as far as I can 
> tell (there are a bunch of PowerPC variants, but at least the 64-bit Linux 
> ABI requires byval to pass arguments directly).
> 
> Yes, how exactly arguments are passed is not visible to the optimizer, and 
> therefore is formally outside the scope of LangRef, but a byval which doesn't 
> pass arguments directly is essentially useless.
I was looking at `PPCTargetLowering::LowerCall_32SVR4`, seems it's different 
for PPC64 as you say.


Repository:
  rL LLVM

https://reviews.llvm.org/D40023



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


[PATCH] D41517: mmintrin.h documentation fixes and updates

2018-01-15 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: lib/Headers/mmintrin.h:55
 ///
-/// This intrinsic corresponds to the  VMOVD / MOVD  instruction.
+/// This intrinsic corresponds to the  MOVD  instruction.
 ///

RKSimon wrote:
> efriedma wrote:
> > craig.topper wrote:
> > > kromanova wrote:
> > > > I tried clang on Linux, x86_64, and if -mavx option is passed, we 
> > > > generate VMOVD, if this option is omitted, we generate MOVD.
> > > > I think I understand the rational behind this change (namely, to keep 
> > > > MOVD, but remove VMOVD),
> > > > since this intrinsic should use MMX registers and shouldn't have 
> > > > corresponding AVX instruction(s).
> > > > 
> > > > However, that's what we generate at the moment when -mavx is passed (I 
> > > > suspect because our MMX support is limited)
> > > > vmovd   %edi, %xmm0
> > > > 
> > > > Since we are writing the documentation for clang compiler, we should 
> > > > document what clang compiler is doing, not what is should be doing.
> > > > Craig, what do you think? Should we revert back to VMOVD/MOVD?
> > > > 
> > > We can change it back to VMOVD/MOVD
> > The reference to vmovd seems confusing.  Yes, LLVM compiles 
> > `_mm_movpi64_epi64(_mm_cvtsi32_si64(i))` to vmovd, but that doesn't mean 
> > either of those intrinsics "corresponds" to vmovd; that's just the 
> > optimizer combining two operations into one.
> Should all these _mm_cvt* intrinsics be replaced with a 'this is a utility 
> function' style comment like the _mm_set1* intrinsics?
In general, I think "corresponds to" should mean "if the inputs are produced by 
an inline asm, and the output is used by an inline asm, and the lowering will 
produce a single instruction, what instruction will we generate?".  That's 
unambiguous, and will usually give a useful hint to the user.  In this case, on 
trunk, the answer is consistently "movd".

Otherwise, it's not clear what it means for an intrinsic to correspond to 
anything; optimizations exist which can modify the instructions we choose for 
almost any intrinsic.


https://reviews.llvm.org/D41517



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


r322518 - Revert 319303: Add _Float128 as alias to __float128 to enable compilations on Fedora27/glibc2

2018-01-15 Thread Erich Keane via cfe-commits
Author: erichkeane
Date: Mon Jan 15 13:16:25 2018
New Revision: 322518

URL: http://llvm.org/viewvc/llvm-project?rev=322518&view=rev
Log:
Revert 319303: Add _Float128 as alias to __float128 to enable compilations on 
Fedora27/glibc2

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

Removed:
cfe/trunk/test/Sema/_Float128.c
Modified:
cfe/trunk/include/clang/Basic/TokenKinds.def
cfe/trunk/lib/Frontend/InitPreprocessor.cpp
cfe/trunk/test/Preprocessor/cuda-types.cu

Modified: cfe/trunk/include/clang/Basic/TokenKinds.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TokenKinds.def?rev=322518&r1=322517&r2=322518&view=diff
==
--- cfe/trunk/include/clang/Basic/TokenKinds.def (original)
+++ cfe/trunk/include/clang/Basic/TokenKinds.def Mon Jan 15 13:16:25 2018
@@ -398,7 +398,6 @@ TYPE_TRAIT_2(__builtin_types_compatible_
 KEYWORD(__builtin_va_arg, KEYALL)
 KEYWORD(__extension__   , KEYALL)
 KEYWORD(__float128  , KEYALL)
-ALIAS("_Float128", __float128   , KEYNOCXX)
 KEYWORD(__imag  , KEYALL)
 KEYWORD(__int128, KEYALL)
 KEYWORD(__label__   , KEYALL)

Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitPreprocessor.cpp?rev=322518&r1=322517&r2=322518&view=diff
==
--- cfe/trunk/lib/Frontend/InitPreprocessor.cpp (original)
+++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp Mon Jan 15 13:16:25 2018
@@ -817,10 +817,6 @@ static void InitializePredefinedMacros(c
   DefineFloatMacros(Builder, "FLT", &TI.getFloatFormat(), "F");
   DefineFloatMacros(Builder, "DBL", &TI.getDoubleFormat(), "");
   DefineFloatMacros(Builder, "LDBL", &TI.getLongDoubleFormat(), "L");
-  if (TI.hasFloat128Type())
-// FIXME: Switch away from the non-standard "Q" when we can
-DefineFloatMacros(Builder, "FLT128", &TI.getFloat128Format(), "Q");
-
 
   // Define a __POINTER_WIDTH__ macro for stdint.h.
   Builder.defineMacro("__POINTER_WIDTH__",

Modified: cfe/trunk/test/Preprocessor/cuda-types.cu
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/cuda-types.cu?rev=322518&r1=322517&r2=322518&view=diff
==
--- cfe/trunk/test/Preprocessor/cuda-types.cu (original)
+++ cfe/trunk/test/Preprocessor/cuda-types.cu Mon Jan 15 13:16:25 2018
@@ -9,40 +9,40 @@
 
 // RUN: %clang --cuda-host-only -nocudainc -target i386-unknown-linux-gnu -x 
cuda -E -dM -o - /dev/null \
 // RUN:   | grep 'define __[^ ]*\(TYPE\|MAX\|SIZEOF|WIDTH\)\|define 
__GCC_ATOMIC' \
-// RUN:   | grep -v '__FLT128\|__LDBL\|_LONG_DOUBLE' > 
%t/i386-host-defines-filtered
+// RUN:   | grep -v '__LDBL\|_LONG_DOUBLE' > %t/i386-host-defines-filtered
 // RUN: %clang --cuda-device-only -nocudainc -nocudalib -target 
i386-unknown-linux-gnu -x cuda -E -dM -o - /dev/null \
 // RUN:   | grep 'define __[^ ]*\(TYPE\|MAX\|SIZEOF|WIDTH\)\|define 
__GCC_ATOMIC' \
-// RUN:   | grep -v '__FLT128\|__LDBL\|_LONG_DOUBLE' > 
%t/i386-device-defines-filtered
+// RUN:   | grep -v '__LDBL\|_LONG_DOUBLE' > %t/i386-device-defines-filtered
 // RUN: diff %t/i386-host-defines-filtered %t/i386-device-defines-filtered
 
 // RUN: %clang --cuda-host-only -nocudainc -target x86_64-unknown-linux-gnu -x 
cuda -E -dM -o - /dev/null \
 // RUN:   | grep 'define __[^ ]*\(TYPE\|MAX\|SIZEOF|WIDTH\)\|define 
__GCC_ATOMIC' \
-// RUN:   | grep -v '__FLT128\|__LDBL\|_LONG_DOUBLE' > 
%t/x86_64-host-defines-filtered
+// RUN:   | grep -v '__LDBL\|_LONG_DOUBLE' > %t/x86_64-host-defines-filtered
 // RUN: %clang --cuda-device-only -nocudainc -nocudalib -target 
x86_64-unknown-linux-gnu -x cuda -E -dM -o - /dev/null \
 // RUN:   | grep 'define __[^ ]*\(TYPE\|MAX\|SIZEOF|WIDTH\)\|define 
__GCC_ATOMIC' \
-// RUN:   | grep -v '__FLT128\|__LDBL\|_LONG_DOUBLE' > 
%t/x86_64-device-defines-filtered
+// RUN:   | grep -v '__LDBL\|_LONG_DOUBLE' > %t/x86_64-device-defines-filtered
 // RUN: diff %t/x86_64-host-defines-filtered %t/x86_64-device-defines-filtered
 
 // RUN: %clang --cuda-host-only -nocudainc -target powerpc64-unknown-linux-gnu 
-x cuda -E -dM -o - /dev/null \
 // RUN:   | grep 'define __[^ ]*\(TYPE\|MAX\|SIZEOF|WIDTH\)\|define 
__GCC_ATOMIC' \
-// RUN:   | grep -v '__FLT128\|__LDBL\|_LONG_DOUBLE' > 
%t/powerpc64-host-defines-filtered
+// RUN:   | grep -v '__LDBL\|_LONG_DOUBLE' > %t/powerpc64-host-defines-filtered
 // RUN: %clang --cuda-device-only -nocudainc -nocudalib -target 
powerpc64-unknown-linux-gnu -x cuda -E -dM -o - /dev/null \
 // RUN:   | grep 'define __[^ ]*\(TYPE\|MAX\|SIZEOF|WIDTH\)\|define 
__GCC_ATOMIC' \
-// RUN:   | grep -v '__FLT128\|__LDBL\|_LONG_DOUBLE' > 
%t/powerpc64-device-defines-filtered
+// RUN:   | grep -v '__LDBL\|_LONG_DOUBLE' > 
%t/powerpc64-device-defines-filter

[PATCH] D42004: [Driver] Suggest valid integrated tools

2018-01-15 Thread Brian Gesiak via Phabricator via cfe-commits
modocache added a comment.

Great, thanks for the review @bkramer!


Repository:
  rC Clang

https://reviews.llvm.org/D42004



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


[PATCH] D42004: [Driver] Suggest valid integrated tools

2018-01-15 Thread Brian Gesiak via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC322517: [Driver] Suggest valid integrated tools (authored by 
modocache, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D42004?vs=129668&id=129902#toc

Repository:
  rC Clang

https://reviews.llvm.org/D42004

Files:
  test/Driver/unknown-arg.c
  tools/driver/driver.cpp


Index: tools/driver/driver.cpp
===
--- tools/driver/driver.cpp
+++ tools/driver/driver.cpp
@@ -311,7 +311,8 @@
 return cc1as_main(argv.slice(2), argv[0], GetExecutablePathVP);
 
   // Reject unknown tools.
-  llvm::errs() << "error: unknown integrated tool '" << Tool << "'\n";
+  llvm::errs() << "error: unknown integrated tool '" << Tool << "'. "
+   << "Valid tools include '-cc1' and '-cc1as'.\n";
   return 1;
 }
 
Index: test/Driver/unknown-arg.c
===
--- test/Driver/unknown-arg.c
+++ test/Driver/unknown-arg.c
@@ -14,6 +14,8 @@
 // RUN: FileCheck %s --check-prefix=SILENT
 // RUN: not %clang -cc1as -hell --version -debug-info-macros 2>&1 | \
 // RUN: FileCheck %s --check-prefix=CC1AS-DID-YOU-MEAN
+// RUN: not %clang -cc1asphalt -help 2>&1 | \
+// RUN: FileCheck %s --check-prefix=UNKNOWN-INTEGRATED
 
 // CHECK: error: unknown argument: '-cake-is-lie'
 // CHECK: error: unknown argument: '-%0'
@@ -46,7 +48,7 @@
 // CC1AS-DID-YOU-MEAN: error: unknown argument '-hell', did you mean '-help'?
 // CC1AS-DID-YOU-MEAN: error: unknown argument '--version', did you mean 
'-version'?
 // CC1AS-DID-YOU-MEAN: error: unknown argument '-debug-info-macros', did you 
mean '-debug-info-macro'?
-
+// UNKNOWN-INTEGRATED: error: unknown integrated tool 'asphalt'. Valid tools 
include '-cc1' and '-cc1as'.
 
 // RUN: %clang -S %s -o %t.s  -Wunknown-to-clang-option 2>&1 | FileCheck 
--check-prefix=IGNORED %s
 


Index: tools/driver/driver.cpp
===
--- tools/driver/driver.cpp
+++ tools/driver/driver.cpp
@@ -311,7 +311,8 @@
 return cc1as_main(argv.slice(2), argv[0], GetExecutablePathVP);
 
   // Reject unknown tools.
-  llvm::errs() << "error: unknown integrated tool '" << Tool << "'\n";
+  llvm::errs() << "error: unknown integrated tool '" << Tool << "'. "
+   << "Valid tools include '-cc1' and '-cc1as'.\n";
   return 1;
 }
 
Index: test/Driver/unknown-arg.c
===
--- test/Driver/unknown-arg.c
+++ test/Driver/unknown-arg.c
@@ -14,6 +14,8 @@
 // RUN: FileCheck %s --check-prefix=SILENT
 // RUN: not %clang -cc1as -hell --version -debug-info-macros 2>&1 | \
 // RUN: FileCheck %s --check-prefix=CC1AS-DID-YOU-MEAN
+// RUN: not %clang -cc1asphalt -help 2>&1 | \
+// RUN: FileCheck %s --check-prefix=UNKNOWN-INTEGRATED
 
 // CHECK: error: unknown argument: '-cake-is-lie'
 // CHECK: error: unknown argument: '-%0'
@@ -46,7 +48,7 @@
 // CC1AS-DID-YOU-MEAN: error: unknown argument '-hell', did you mean '-help'?
 // CC1AS-DID-YOU-MEAN: error: unknown argument '--version', did you mean '-version'?
 // CC1AS-DID-YOU-MEAN: error: unknown argument '-debug-info-macros', did you mean '-debug-info-macro'?
-
+// UNKNOWN-INTEGRATED: error: unknown integrated tool 'asphalt'. Valid tools include '-cc1' and '-cc1as'.
 
 // RUN: %clang -S %s -o %t.s  -Wunknown-to-clang-option 2>&1 | FileCheck --check-prefix=IGNORED %s
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r322517 - [Driver] Suggest valid integrated tools

2018-01-15 Thread Brian Gesiak via cfe-commits
Author: modocache
Date: Mon Jan 15 13:05:40 2018
New Revision: 322517

URL: http://llvm.org/viewvc/llvm-project?rev=322517&view=rev
Log:
[Driver] Suggest valid integrated tools

Summary:
There are only two valid integrated Clang driver tools: `-cc1` and
`-cc1as`. If a user asks for an unknown tool, such as `-cc1asphalt`,
an error message is displayed to indicate that there is no such tool,
but the message doesn't indicate what the valid options are.

Include the valid options in the error message.

Test Plan: `check-clang`

Reviewers: sepavloff, bkramer, phosek

Reviewed By: bkramer

Subscribers: cfe-commits

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

Modified:
cfe/trunk/test/Driver/unknown-arg.c
cfe/trunk/tools/driver/driver.cpp

Modified: cfe/trunk/test/Driver/unknown-arg.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/unknown-arg.c?rev=322517&r1=322516&r2=322517&view=diff
==
--- cfe/trunk/test/Driver/unknown-arg.c (original)
+++ cfe/trunk/test/Driver/unknown-arg.c Mon Jan 15 13:05:40 2018
@@ -14,6 +14,8 @@
 // RUN: FileCheck %s --check-prefix=SILENT
 // RUN: not %clang -cc1as -hell --version -debug-info-macros 2>&1 | \
 // RUN: FileCheck %s --check-prefix=CC1AS-DID-YOU-MEAN
+// RUN: not %clang -cc1asphalt -help 2>&1 | \
+// RUN: FileCheck %s --check-prefix=UNKNOWN-INTEGRATED
 
 // CHECK: error: unknown argument: '-cake-is-lie'
 // CHECK: error: unknown argument: '-%0'
@@ -46,7 +48,7 @@
 // CC1AS-DID-YOU-MEAN: error: unknown argument '-hell', did you mean '-help'?
 // CC1AS-DID-YOU-MEAN: error: unknown argument '--version', did you mean 
'-version'?
 // CC1AS-DID-YOU-MEAN: error: unknown argument '-debug-info-macros', did you 
mean '-debug-info-macro'?
-
+// UNKNOWN-INTEGRATED: error: unknown integrated tool 'asphalt'. Valid tools 
include '-cc1' and '-cc1as'.
 
 // RUN: %clang -S %s -o %t.s  -Wunknown-to-clang-option 2>&1 | FileCheck 
--check-prefix=IGNORED %s
 

Modified: cfe/trunk/tools/driver/driver.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/driver/driver.cpp?rev=322517&r1=322516&r2=322517&view=diff
==
--- cfe/trunk/tools/driver/driver.cpp (original)
+++ cfe/trunk/tools/driver/driver.cpp Mon Jan 15 13:05:40 2018
@@ -311,7 +311,8 @@ static int ExecuteCC1Tool(ArrayRefhttp://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r322516 - [OPENMP] Update status of OpenMP support, NFC.

2018-01-15 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Mon Jan 15 13:01:29 2018
New Revision: 322516

URL: http://llvm.org/viewvc/llvm-project?rev=322516&view=rev
Log:
[OPENMP] Update status of OpenMP support, NFC.

Modified:
cfe/trunk/docs/OpenMPSupport.rst

Modified: cfe/trunk/docs/OpenMPSupport.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/OpenMPSupport.rst?rev=322516&r1=322515&r2=322516&view=diff
==
--- cfe/trunk/docs/OpenMPSupport.rst (original)
+++ cfe/trunk/docs/OpenMPSupport.rst Mon Jan 15 13:01:29 2018
@@ -58,11 +58,11 @@ Combined directives
 
 * #pragma omp teams distribute [simd]: :good:`Complete`.
 
-* #pragma omp target teams distribute [simd]: :partial:`Partial`.  No support 
for the and `depend` clauses.
+* #pragma omp target teams distribute [simd]: :partial:`Partial`.  No support 
for the `depend` clauses.
 
 * #pragma omp teams distribute parallel for [simd]: :good:`Complete`.
 
-* #pragma omp target teams distribute parallel for [simd]: :partial:`Partial`. 
 No full codegen support.
+* #pragma omp target teams distribute parallel for [simd]: :partial:`Partial`. 
 No support for the `depend` clauses.
 
 Clang does not support any constructs/updates from upcoming OpenMP 5.0 except 
for `reduction`-based clauses in the `task` and `target`-based directives.
 


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


[PATCH] D41815: [clang-tidy] implement check for goto

2018-01-15 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth updated this revision to Diff 129901.
JonasToth added a comment.

- last nits i found


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41815

Files:
  clang-tidy/cppcoreguidelines/AvoidGotoCheck.cpp
  clang-tidy/cppcoreguidelines/AvoidGotoCheck.h
  clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tidy/hicpp/HICPPTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/cppcoreguidelines-avoid-goto.rst
  docs/clang-tidy/checks/hicpp-avoid-goto.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/cppcoreguidelines-avoid-goto.cpp

Index: test/clang-tidy/cppcoreguidelines-avoid-goto.cpp
===
--- /dev/null
+++ test/clang-tidy/cppcoreguidelines-avoid-goto.cpp
@@ -0,0 +1,139 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-avoid-goto %t
+
+void noop() {}
+
+int main() {
+  noop();
+  goto jump_to_me;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: avoid using 'goto' for flow control
+  // CHECK-MESSAGES: [[@LINE+3]]:1: note: label defined here
+  noop();
+
+jump_to_me:;
+
+jump_backwards:;
+  noop();
+  goto jump_backwards;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: avoid using 'goto' for flow control
+  // CHECK-MESSAGES: [[@LINE-4]]:1: note: label defined here
+
+  goto jump_in_line;
+  ;
+jump_in_line:;
+  // CHECK-MESSAGES: [[@LINE-3]]:3: warning: avoid using 'goto' for flow control
+  // CHECK-MESSAGES: [[@LINE-2]]:1: note: label defined here
+
+  // Test the GNU extension https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html
+some_label:;
+  void *dynamic_label = &&some_label;
+
+  // FIXME: `IndirectGotoStmt` is not detected.
+  goto *dynamic_label;
+}
+
+void forward_jump_out_nested_loop() {
+  int array[] = {1, 2, 3, 4, 5};
+  for (int i = 0; i < 10; ++i) {
+noop();
+for (int j = 0; j < 10; ++j) {
+  noop();
+  if (i + j > 10)
+goto early_exit1;
+}
+noop();
+  }
+
+  for (int i = 0; i < 10; ++i) {
+noop();
+while (true) {
+  noop();
+  if (i > 5)
+goto early_exit1;
+}
+noop();
+  }
+
+  for (auto value : array) {
+noop();
+for (auto number : array) {
+  noop();
+  if (number == 5)
+goto early_exit1;
+}
+  }
+
+  do {
+noop();
+do {
+  noop();
+  goto early_exit1;
+} while (true);
+  } while (true);
+
+  do {
+for (auto number : array) {
+  noop();
+  if (number == 2)
+goto early_exit1;
+}
+  } while (true);
+
+  // Jumping further results in error, because the variable declaration would
+  // be skipped.
+early_exit1:;
+
+  int i = 0;
+  while (true) {
+noop();
+while (true) {
+  noop();
+  if (i > 5)
+goto early_exit2;
+  i++;
+}
+noop();
+  }
+
+  while (true) {
+noop();
+for (int j = 0; j < 10; ++j) {
+  noop();
+  if (j > 5)
+goto early_exit2;
+}
+noop();
+  }
+
+  while (true) {
+noop();
+for (auto number : array) {
+  if (number == 1)
+goto early_exit2;
+  noop();
+}
+  }
+
+  while (true) {
+noop();
+do {
+  noop();
+  goto early_exit2;
+} while (true);
+  }
+early_exit2:;
+}
+
+void jump_out_backwards() {
+
+before_the_loop:
+  noop();
+
+  for (int i = 0; i < 10; ++i) {
+for (int j = 0; j < 10; ++j) {
+  if (i * j > 80)
+goto before_the_loop;
+  // CHECK-MESSAGES: [[@LINE-1]]:9: warning: avoid using 'goto' for flow control
+  // CHECK-MESSAGES: [[@LINE-8]]:1: note: label defined here
+}
+  }
+}
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -52,6 +52,7 @@
cert-msc30-c (redirects to cert-msc50-cpp) 
cert-msc50-cpp
cert-oop11-cpp (redirects to performance-move-constructor-init) 
+   cppcoreguidelines-avoid-goto
cppcoreguidelines-c-copy-assignment-signature (redirects to misc-unconventional-assign-operator) 
cppcoreguidelines-interfaces-global-init
cppcoreguidelines-no-malloc
@@ -90,6 +91,7 @@
google-runtime-member-string-references
google-runtime-operator
google-runtime-references
+   hicpp-avoid-goto (redirects to cppcoreguidelines-avoid-goto) 
hicpp-braces-around-statements (redirects to readability-braces-around-statements) 
hicpp-deprecated-headers (redirects to modernize-deprecated-headers) 
hicpp-exception-baseclass
Index: docs/clang-tidy/checks/hicpp-avoid-goto.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/hicpp-avoid-goto.rst
@@ -0,0 +1,12 @@
+.. title:: clang-tidy - hicpp-avoid-goto
+
+hicpp-avoid-goto
+
+
+The `hicpp-avoid-goto` check is an alias to 
+`cppcoreguidelines-avoid-goto `_.
+Rule `6.3.1 High Integrity C++ 

[PATCH] D41648: [clang-tidy] implement cppcoreguidelines macro rules

2018-01-15 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

In https://reviews.llvm.org/D41648#976665, @aaron.ballman wrote:

> My gut reaction is still that this check is going to be too chatty on real 
> world code bases to be of value beyond compliance with the C++ Core 
> Guidelines, but that's also sufficient enough reason to have the check in the 
> first place. Perhaps a reasonable approach would be to put in the heuristics 
> you think make the most sense, then run the check over some large real world 
> C++ code bases to see how many diagnostics are generated. That will also help 
> you to see code patterns to modify your heuristic until you're happy with the 
> results. Then we can debate whether there's more left to do from the data.


Agreed.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41648



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


[PATCH] D41815: [clang-tidy] implement check for goto

2018-01-15 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth updated this revision to Diff 129900.
JonasToth added a comment.

- remove spurious whitespace


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41815

Files:
  clang-tidy/cppcoreguidelines/AvoidGotoCheck.cpp
  clang-tidy/cppcoreguidelines/AvoidGotoCheck.h
  clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tidy/hicpp/HICPPTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/cppcoreguidelines-avoid-goto.rst
  docs/clang-tidy/checks/hicpp-avoid-goto.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/cppcoreguidelines-avoid-goto.cpp

Index: test/clang-tidy/cppcoreguidelines-avoid-goto.cpp
===
--- /dev/null
+++ test/clang-tidy/cppcoreguidelines-avoid-goto.cpp
@@ -0,0 +1,139 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-avoid-goto %t
+
+void noop() {}
+
+int main() {
+  noop();
+  goto jump_to_me;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: avoid using 'goto' for flow control
+  // CHECK-MESSAGES: [[@LINE+3]]:1: note: label defined here
+  noop();
+
+jump_to_me:;
+
+jump_backwards:;
+  noop();
+  goto jump_backwards;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: avoid using 'goto' for flow control
+  // CHECK-MESSAGES: [[@LINE-4]]:1: note: label defined here
+
+  goto jump_in_line;
+  ;
+jump_in_line:;
+  // CHECK-MESSAGES: [[@LINE-3]]:3: warning: avoid using 'goto' for flow control
+  // CHECK-MESSAGES: [[@LINE-2]]:1: note: label defined here
+
+  // Test the GNU extension https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html
+some_label:;
+  void *dynamic_label = &&some_label;
+
+  // FIXME: `IndirectGotoStmt` is not detected.
+  goto *dynamic_label;
+}
+
+void forward_jump_out_nested_loop() {
+  int array[] = {1, 2, 3, 4, 5};
+  for (int i = 0; i < 10; ++i) {
+noop();
+for (int j = 0; j < 10; ++j) {
+  noop();
+  if (i + j > 10)
+goto early_exit1;
+}
+noop();
+  }
+
+  for (int i = 0; i < 10; ++i) {
+noop();
+while (true) {
+  noop();
+  if (i > 5)
+goto early_exit1;
+}
+noop();
+  }
+
+  for (auto value : array) {
+noop();
+for (auto number : array) {
+  noop();
+  if (number == 5)
+goto early_exit1;
+}
+  }
+
+  do {
+noop();
+do {
+  noop();
+  goto early_exit1;
+} while (true);
+  } while (true);
+
+  do {
+for (auto number : array) {
+  noop();
+  if (number == 2)
+goto early_exit1;
+}
+  } while (true);
+
+  // Jumping further results in error, because the variable declaration would
+  // be skipped.
+early_exit1:;
+
+  int i = 0;
+  while (true) {
+noop();
+while (true) {
+  noop();
+  if (i > 5)
+goto early_exit2;
+  i++;
+}
+noop();
+  }
+
+  while (true) {
+noop();
+for (int j = 0; j < 10; ++j) {
+  noop();
+  if (j > 5)
+goto early_exit2;
+}
+noop();
+  }
+
+  while (true) {
+noop();
+for (auto number : array) {
+  if (number == 1)
+goto early_exit2;
+  noop();
+}
+  }
+
+  while (true) {
+noop();
+do {
+  noop();
+  goto early_exit2;
+} while (true);
+  }
+early_exit2:;
+}
+
+void jump_out_backwards() {
+
+before_the_loop:
+  noop();
+
+  for (int i = 0; i < 10; ++i) {
+for (int j = 0; j < 10; ++j) {
+  if (i * j > 80)
+goto before_the_loop;
+  // CHECK-MESSAGES: [[@LINE-1]]:9: warning: avoid using 'goto' for flow control
+  // CHECK-MESSAGES: [[@LINE-8]]:1: note: label defined here
+}
+  }
+}
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -52,6 +52,7 @@
cert-msc30-c (redirects to cert-msc50-cpp) 
cert-msc50-cpp
cert-oop11-cpp (redirects to performance-move-constructor-init) 
+   cppcoreguidelines-avoid-goto
cppcoreguidelines-c-copy-assignment-signature (redirects to misc-unconventional-assign-operator) 
cppcoreguidelines-interfaces-global-init
cppcoreguidelines-no-malloc
@@ -90,6 +91,7 @@
google-runtime-member-string-references
google-runtime-operator
google-runtime-references
+   hicpp-avoid-goto (redirects to cppcoreguidelines-avoid-goto) 
hicpp-braces-around-statements (redirects to readability-braces-around-statements) 
hicpp-deprecated-headers (redirects to modernize-deprecated-headers) 
hicpp-exception-baseclass
Index: docs/clang-tidy/checks/hicpp-avoid-goto.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/hicpp-avoid-goto.rst
@@ -0,0 +1,11 @@
+.. title:: clang-tidy - hicpp-avoid-goto
+
+hicpp-avoid-goto
+
+
+The `hicpp-avoid-go` check is an alias to 
+`cppcoreguidelines-avoid-goto `_.
+Rule `6.3.1 High Integrity C++ 

[PATCH] D41815: [clang-tidy] implement check for goto

2018-01-15 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth updated this revision to Diff 129899.
JonasToth marked 3 inline comments as done.
JonasToth added a comment.

- hicpp alias added
- update documentation


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41815

Files:
  clang-tidy/cppcoreguidelines/AvoidGotoCheck.cpp
  clang-tidy/cppcoreguidelines/AvoidGotoCheck.h
  clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tidy/hicpp/HICPPTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/cppcoreguidelines-avoid-goto.rst
  docs/clang-tidy/checks/hicpp-avoid-goto.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/cppcoreguidelines-avoid-goto.cpp

Index: test/clang-tidy/cppcoreguidelines-avoid-goto.cpp
===
--- /dev/null
+++ test/clang-tidy/cppcoreguidelines-avoid-goto.cpp
@@ -0,0 +1,139 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-avoid-goto %t
+
+void noop() {}
+
+int main() {
+  noop();
+  goto jump_to_me;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: avoid using 'goto' for flow control
+  // CHECK-MESSAGES: [[@LINE+3]]:1: note: label defined here
+  noop();
+
+jump_to_me:;
+
+jump_backwards:;
+  noop();
+  goto jump_backwards;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: avoid using 'goto' for flow control
+  // CHECK-MESSAGES: [[@LINE-4]]:1: note: label defined here
+
+  goto jump_in_line;
+  ;
+jump_in_line:;
+  // CHECK-MESSAGES: [[@LINE-3]]:3: warning: avoid using 'goto' for flow control
+  // CHECK-MESSAGES: [[@LINE-2]]:1: note: label defined here
+
+  // Test the GNU extension https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html
+some_label:;
+  void *dynamic_label = &&some_label;
+
+  // FIXME: `IndirectGotoStmt` is not detected.
+  goto *dynamic_label;
+}
+
+void forward_jump_out_nested_loop() {
+  int array[] = {1, 2, 3, 4, 5};
+  for (int i = 0; i < 10; ++i) {
+noop();
+for (int j = 0; j < 10; ++j) {
+  noop();
+  if (i + j > 10)
+goto early_exit1;
+}
+noop();
+  }
+
+  for (int i = 0; i < 10; ++i) {
+noop();
+while (true) {
+  noop();
+  if (i > 5)
+goto early_exit1;
+}
+noop();
+  }
+
+  for (auto value : array) {
+noop();
+for (auto number : array) {
+  noop();
+  if (number == 5)
+goto early_exit1;
+}
+  }
+
+  do {
+noop();
+do {
+  noop();
+  goto early_exit1;
+} while (true);
+  } while (true);
+
+  do {
+for (auto number : array) {
+  noop();
+  if (number == 2)
+goto early_exit1;
+}
+  } while (true);
+
+  // Jumping further results in error, because the variable declaration would
+  // be skipped.
+early_exit1:;
+
+  int i = 0;
+  while (true) {
+noop();
+while (true) {
+  noop();
+  if (i > 5)
+goto early_exit2;
+  i++;
+}
+noop();
+  }
+
+  while (true) {
+noop();
+for (int j = 0; j < 10; ++j) {
+  noop();
+  if (j > 5)
+goto early_exit2;
+}
+noop();
+  }
+
+  while (true) {
+noop();
+for (auto number : array) {
+  if (number == 1)
+goto early_exit2;
+  noop();
+}
+  }
+
+  while (true) {
+noop();
+do {
+  noop();
+  goto early_exit2;
+} while (true);
+  }
+early_exit2:;
+}
+
+void jump_out_backwards() {
+
+before_the_loop:
+  noop();
+
+  for (int i = 0; i < 10; ++i) {
+for (int j = 0; j < 10; ++j) {
+  if (i * j > 80)
+goto before_the_loop;
+  // CHECK-MESSAGES: [[@LINE-1]]:9: warning: avoid using 'goto' for flow control
+  // CHECK-MESSAGES: [[@LINE-8]]:1: note: label defined here
+}
+  }
+}
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -52,6 +52,7 @@
cert-msc30-c (redirects to cert-msc50-cpp) 
cert-msc50-cpp
cert-oop11-cpp (redirects to performance-move-constructor-init) 
+   cppcoreguidelines-avoid-goto
cppcoreguidelines-c-copy-assignment-signature (redirects to misc-unconventional-assign-operator) 
cppcoreguidelines-interfaces-global-init
cppcoreguidelines-no-malloc
@@ -90,6 +91,7 @@
google-runtime-member-string-references
google-runtime-operator
google-runtime-references
+   hicpp-avoid-goto (redirects to cppcoreguidelines-avoid-goto) 
hicpp-braces-around-statements (redirects to readability-braces-around-statements) 
hicpp-deprecated-headers (redirects to modernize-deprecated-headers) 
hicpp-exception-baseclass
Index: docs/clang-tidy/checks/hicpp-avoid-goto.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/hicpp-avoid-goto.rst
@@ -0,0 +1,11 @@
+.. title:: clang-tidy - hicpp-avoid-goto
+
+hicpp-avoid-goto
+
+
+The `hicpp-avoid-go` check is an alias to 
+`cppcoreguidelines-avoid-goto `_.
+Rule `6.3.1 High Integrity C++ 

r322514 - [RISCV] Fix test failures on non-assert builds introduced in r322494

2018-01-15 Thread Alex Bradbury via cfe-commits
Author: asb
Date: Mon Jan 15 12:45:15 2018
New Revision: 322514

URL: http://llvm.org/viewvc/llvm-project?rev=322514&view=rev
Log:
[RISCV] Fix test failures on non-assert builds introduced in r322494

Thanks to Eli Friedman, who suggested the reason these tests failed on a few 
buildbots yet works fine locally is because non-assert builds don't emit value 
labels.

Modified:
cfe/trunk/test/CodeGen/riscv32-abi.c
cfe/trunk/test/CodeGen/riscv64-abi.c

Modified: cfe/trunk/test/CodeGen/riscv32-abi.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/riscv32-abi.c?rev=322514&r1=322513&r2=322514&view=diff
==
--- cfe/trunk/test/CodeGen/riscv32-abi.c (original)
+++ cfe/trunk/test/CodeGen/riscv32-abi.c Mon Jan 15 12:45:15 2018
@@ -269,8 +269,7 @@ int f_va_1(char *fmt, ...) {
 // correct offsets are used.
 
 // CHECK-LABEL: @f_va_2(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:[[FMT_ADDR:%.*]] = alloca i8*, align 4
+// CHECK: [[FMT_ADDR:%.*]] = alloca i8*, align 4
 // CHECK-NEXT:[[VA:%.*]] = alloca i8*, align 4
 // CHECK-NEXT:[[V:%.*]] = alloca double, align 8
 // CHECK-NEXT:store i8* [[FMT:%.*]], i8** [[FMT_ADDR]], align 4
@@ -303,8 +302,7 @@ double f_va_2(char *fmt, ...) {
 // Two "aligned" register pairs.
 
 // CHECK-LABEL: @f_va_3(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:[[FMT_ADDR:%.*]] = alloca i8*, align 4
+// CHECK: [[FMT_ADDR:%.*]] = alloca i8*, align 4
 // CHECK-NEXT:[[VA:%.*]] = alloca i8*, align 4
 // CHECK-NEXT:[[V:%.*]] = alloca double, align 8
 // CHECK-NEXT:[[W:%.*]] = alloca i32, align 4
@@ -357,8 +355,7 @@ double f_va_3(char *fmt, ...) {
 }
 
 // CHECK-LABEL: define i32 @f_va_4(i8* %fmt, ...) {{.*}} {
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:[[FMT_ADDR:%.*]] = alloca i8*, align 4
+// CHECK: [[FMT_ADDR:%.*]] = alloca i8*, align 4
 // CHECK-NEXT:[[VA:%.*]] = alloca i8*, align 4
 // CHECK-NEXT:[[V:%.*]] = alloca i32, align 4
 // CHECK-NEXT:[[LD:%.*]] = alloca fp128, align 16

Modified: cfe/trunk/test/CodeGen/riscv64-abi.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/riscv64-abi.c?rev=322514&r1=322513&r2=322514&view=diff
==
--- cfe/trunk/test/CodeGen/riscv64-abi.c (original)
+++ cfe/trunk/test/CodeGen/riscv64-abi.c Mon Jan 15 12:45:15 2018
@@ -267,8 +267,7 @@ int f_va_1(char *fmt, ...) {
 // correct offsets are used.
 
 // CHECK-LABEL: @f_va_2(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:[[FMT_ADDR:%.*]] = alloca i8*, align 8
+// CHECK: [[FMT_ADDR:%.*]] = alloca i8*, align 8
 // CHECK-NEXT:[[VA:%.*]] = alloca i8*, align 8
 // CHECK-NEXT:[[V:%.*]] = alloca fp128, align 16
 // CHECK-NEXT:store i8* [[FMT:%.*]], i8** [[FMT_ADDR]], align 8
@@ -301,8 +300,7 @@ long double f_va_2(char *fmt, ...) {
 // Two "aligned" register pairs.
 
 // CHECK-LABEL: @f_va_3(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:[[FMT_ADDR:%.*]] = alloca i8*, align 8
+// CHECK: [[FMT_ADDR:%.*]] = alloca i8*, align 8
 // CHECK-NEXT:[[VA:%.*]] = alloca i8*, align 8
 // CHECK-NEXT:[[V:%.*]] = alloca fp128, align 16
 // CHECK-NEXT:[[W:%.*]] = alloca i32, align 4
@@ -355,8 +353,7 @@ long double f_va_3(char *fmt, ...) {
 }
 
 // CHECK-LABEL: @f_va_4(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:[[FMT_ADDR:%.*]] = alloca i8*, align 8
+// CHECK: [[FMT_ADDR:%.*]] = alloca i8*, align 8
 // CHECK-NEXT:[[VA:%.*]] = alloca i8*, align 8
 // CHECK-NEXT:[[V:%.*]] = alloca i32, align 4
 // CHECK-NEXT:[[TS:%.*]] = alloca [[STRUCT_TINY:%.*]], align 2


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


r322513 - Fixed memory leak in unit test introduced in my previous commit r322503

2018-01-15 Thread Cameron Desrochers via cfe-commits
Author: cameron314
Date: Mon Jan 15 12:37:35 2018
New Revision: 322513

URL: http://llvm.org/viewvc/llvm-project?rev=322513&view=rev
Log:
Fixed memory leak in unit test introduced in my previous commit r322503

Modified:
cfe/trunk/unittests/libclang/LibclangTest.cpp

Modified: cfe/trunk/unittests/libclang/LibclangTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/libclang/LibclangTest.cpp?rev=322513&r1=322512&r2=322513&view=diff
==
--- cfe/trunk/unittests/libclang/LibclangTest.cpp (original)
+++ cfe/trunk/unittests/libclang/LibclangTest.cpp Mon Jan 15 12:37:35 2018
@@ -592,6 +592,9 @@ TEST_F(LibclangReparseTest, Preprocessor
 if (i == 2)
   flags |= CXTranslationUnit_CreatePreambleOnFirstParse;
 
+if (i != 0)
+   clang_disposeTranslationUnit(ClangTU);  // dispose from previous iter
+
 // parse once
 ClangTU = clang_parseTranslationUnit(Index, Main.c_str(), nullptr, 0,
  nullptr, 0, flags);


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


[PATCH] D40023: [RISCV] Implement ABI lowering

2018-01-15 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: lib/CodeGen/TargetInfo.cpp:8913
+  }
+  return getNaturalAlignIndirect(Ty, /*ByVal=*/true);
+}

asb wrote:
> efriedma wrote:
> > asb wrote:
> > > efriedma wrote:
> > > > The spec says "Aggregates larger than 2✕XLEN bits are passed by 
> > > > reference and are replaced in the argument list with the address".  
> > > > That's not byval.
> > > The LLVM backend lowers byval in that way. Given that at this point we 
> > > have a trivial data type (plain struct or similar) which is 
> > > copied-by-value by C semantics, the only difference is whether the 
> > > generated IR indicates implicit copying with 'byval' or relies on the 
> > > caller explicitly doing the copy. For some reason I thought 'byval' was 
> > > preferred, but looking again it seems uncommon to do it this way. I've 
> > > changed it to false - thanks for spotting this.
> > "byval" generally means the value is memcpy'ed into the argument list (so 
> > there is no pointer in the argument list). This is useful for handling C 
> > calling conventions which allow excessively large structs to be passed in 
> > the argument list, so the backend can emit a memcpy rather than expanding 
> > the operation into straight-line code.  The RISCV backend handling of byval 
> > is wrong, in the sense that it isn't consistent with what any other backend 
> > does.
> > 
> > This isn't relevant to the RISC-V C calling convention, but you should 
> > probably fix the backend at some point to avoid future confusion.
> If I understand your concern correctly, it's that the RISCV backend passes a 
> pointer to the byval copied argument rather than passing it direct on the 
> stack? Isn't that consistent with what the Sparc, Lanai and the PPC backends 
> do? It also seems consistent with my reading of the description of the byval 
> attribute in the langref - a hidden copy is made. Whether that hidden copy is 
> passed direct or a pointer to it is passed (which is consistent with the 
> RISC-V calling convention for large values) seems an orthogonal concern.
I can see SPARC does in fact pass byval arguments like you said (and I'll 
assume Lanai behaves the same way).  PowerPC doesn't, though, as far as I can 
tell (there are a bunch of PowerPC variants, but at least the 64-bit Linux ABI 
requires byval to pass arguments directly).

Yes, how exactly arguments are passed is not visible to the optimizer, and 
therefore is formally outside the scope of LangRef, but a byval which doesn't 
pass arguments directly is essentially useless.


Repository:
  rL LLVM

https://reviews.llvm.org/D40023



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


[PATCH] D41648: [clang-tidy] implement cppcoreguidelines macro rules

2018-01-15 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

My gut reaction is still that this check is going to be too chatty on real 
world code bases to be of value beyond compliance with the C++ Core Guidelines, 
but that's also sufficient enough reason to have the check in the first place. 
Perhaps a reasonable approach would be to put in the heuristics you think make 
the most sense, then run the check over some large real world C++ code bases to 
see how many diagnostics are generated. That will also help you to see code 
patterns to modify your heuristic until you're happy with the results. Then we 
can debate whether there's more left to do from the data.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41648



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


[PATCH] D41815: [clang-tidy] implement check for goto

2018-01-15 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang-tidy/cppcoreguidelines/AvoidGotoCheck.h:19-20
+
+/// The usage of `goto` has been discouraged for a long time and is diagnosed
+/// with this check.
+///

This comment is a bit out of date now that it no longer diagnoses all uses of 
`goto`.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41815



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


[PATCH] D42085: Add va_start()/va_copy()/va_end to Builtins.def

2018-01-15 Thread Nico Weber via Phabricator via cfe-commits
thakis created this revision.
thakis added a reviewer: hans.

That way, clang suggests including stdarg.h when these are used in C files.


https://reviews.llvm.org/D42085

Files:
  include/clang/Basic/Builtins.def


Index: include/clang/Basic/Builtins.def
===
--- include/clang/Basic/Builtins.def
+++ include/clang/Basic/Builtins.def
@@ -802,6 +802,10 @@
 LIBBUILTIN(_setjmpex, "iJ", "fj",   "setjmpex.h", ALL_MS_LANGUAGES)
 
 // C99 library functions
+// C99 stdarg.h
+LIBBUILTIN(va_start, "vA.",   "fnt",   "stdarg.h", ALL_LANGUAGES)
+LIBBUILTIN(va_end, "vA",  "fn","stdarg.h", ALL_LANGUAGES)
+LIBBUILTIN(va_copy, "vAA","fn","stdarg.h", ALL_LANGUAGES)
 // C99 stdlib.h
 LIBBUILTIN(abort, "v","fr","stdlib.h", ALL_LANGUAGES)
 LIBBUILTIN(calloc, "v*zz","f", "stdlib.h", ALL_LANGUAGES)


Index: include/clang/Basic/Builtins.def
===
--- include/clang/Basic/Builtins.def
+++ include/clang/Basic/Builtins.def
@@ -802,6 +802,10 @@
 LIBBUILTIN(_setjmpex, "iJ", "fj",   "setjmpex.h", ALL_MS_LANGUAGES)
 
 // C99 library functions
+// C99 stdarg.h
+LIBBUILTIN(va_start, "vA.",   "fnt",   "stdarg.h", ALL_LANGUAGES)
+LIBBUILTIN(va_end, "vA",  "fn","stdarg.h", ALL_LANGUAGES)
+LIBBUILTIN(va_copy, "vAA","fn","stdarg.h", ALL_LANGUAGES)
 // C99 stdlib.h
 LIBBUILTIN(abort, "v","fr","stdlib.h", ALL_LANGUAGES)
 LIBBUILTIN(calloc, "v*zz","f", "stdlib.h", ALL_LANGUAGES)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42059: [clangd] Improve const-correctness of Symbol->Detail. NFC

2018-01-15 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL322509: [clangd] Improve const-correctness of 
Symbol->Detail. NFC (authored by sammccall, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D42059?vs=129830&id=129896#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D42059

Files:
  clang-tools-extra/trunk/clangd/index/Index.cpp
  clang-tools-extra/trunk/clangd/index/Index.h
  clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp

Index: clang-tools-extra/trunk/clangd/index/Index.h
===
--- clang-tools-extra/trunk/clangd/index/Index.h
+++ clang-tools-extra/trunk/clangd/index/Index.h
@@ -156,7 +156,7 @@
   };
 
   // Optional details of the symbol.
-  Details *Detail = nullptr; // FIXME: should be const
+  const Details *Detail = nullptr;
 
   // FIXME: add definition location of the symbol.
   // FIXME: add all occurrences support.
Index: clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp
===
--- clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp
+++ clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp
@@ -60,27 +60,39 @@
   }
 };
 
-template <>
-struct MappingTraits {
-  static void mapping(IO &io, Symbol::Details *&Detail) {
-if (!io.outputting()) {
-  assert(io.getContext() && "Expecting an arena (as context) to allocate "
-"data for new symbols.");
-  Detail = static_cast(io.getContext())
-   ->Allocate();
-} else if (!Detail) {
-  // Detail is optional in outputting.
-  return;
-}
-assert(Detail);
-io.mapOptional("Documentation", Detail->Documentation);
-io.mapOptional("CompletionDetail", Detail->CompletionDetail);
+template <> struct MappingTraits {
+  static void mapping(IO &io, Symbol::Details &Detail) {
+io.mapOptional("Documentation", Detail.Documentation);
+io.mapOptional("CompletionDetail", Detail.CompletionDetail);
   }
 };
 
+// A YamlIO normalizer for fields of type "const T*" allocated on an arena.
+// Normalizes to Optional, so traits should be provided for T.
+template  struct ArenaPtr {
+  ArenaPtr(IO &) {}
+  ArenaPtr(IO &, const T *D) {
+if (D)
+  Opt = *D;
+  }
+
+  const T *denormalize(IO &IO) {
+assert(IO.getContext() && "Expecting an arena (as context) to allocate "
+  "data for read symbols.");
+if (!Opt)
+  return nullptr;
+return new (*static_cast(IO.getContext()))
+T(std::move(*Opt)); // Allocate a copy of Opt on the arena.
+  }
+
+  llvm::Optional Opt;
+};
+
 template <> struct MappingTraits {
   static void mapping(IO &IO, Symbol &Sym) {
 MappingNormalization NSymbolID(IO, Sym.ID);
+MappingNormalization, const Symbol::Details *>
+NDetail(IO, Sym.Detail);
 IO.mapRequired("ID", NSymbolID->HexString);
 IO.mapRequired("Name", Sym.Name);
 IO.mapRequired("Scope", Sym.Scope);
@@ -92,8 +104,7 @@
 
 IO.mapOptional("CompletionSnippetInsertText",
Sym.CompletionSnippetInsertText);
-if (!IO.outputting() || Sym.Detail)
-  IO.mapOptional("Detail", Sym.Detail);
+IO.mapOptional("Detail", NDetail->Opt);
   }
 };
 
Index: clang-tools-extra/trunk/clangd/index/Index.cpp
===
--- clang-tools-extra/trunk/clangd/index/Index.cpp
+++ clang-tools-extra/trunk/clangd/index/Index.cpp
@@ -64,13 +64,12 @@
   if (S.Detail) {
 // Copy values of StringRefs into arena.
 auto *Detail = Arena.Allocate();
-Detail->Documentation = S.Detail->Documentation;
-Detail->CompletionDetail = S.Detail->CompletionDetail;
-S.Detail = Detail;
-
+*Detail = *S.Detail;
 // Intern the actual strings.
-Intern(S.Detail->Documentation);
-Intern(S.Detail->CompletionDetail);
+Intern(Detail->Documentation);
+Intern(Detail->CompletionDetail);
+// Replace the detail pointer with our copy.
+S.Detail = Detail;
   }
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42059: [clangd] Improve const-correctness of Symbol->Detail. NFC

2018-01-15 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE322509: [clangd] Improve const-correctness of 
Symbol->Detail. NFC (authored by sammccall, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D42059?vs=129830&id=129895#toc

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42059

Files:
  clangd/index/Index.cpp
  clangd/index/Index.h
  clangd/index/SymbolYAML.cpp

Index: clangd/index/SymbolYAML.cpp
===
--- clangd/index/SymbolYAML.cpp
+++ clangd/index/SymbolYAML.cpp
@@ -60,27 +60,39 @@
   }
 };
 
-template <>
-struct MappingTraits {
-  static void mapping(IO &io, Symbol::Details *&Detail) {
-if (!io.outputting()) {
-  assert(io.getContext() && "Expecting an arena (as context) to allocate "
-"data for new symbols.");
-  Detail = static_cast(io.getContext())
-   ->Allocate();
-} else if (!Detail) {
-  // Detail is optional in outputting.
-  return;
-}
-assert(Detail);
-io.mapOptional("Documentation", Detail->Documentation);
-io.mapOptional("CompletionDetail", Detail->CompletionDetail);
+template <> struct MappingTraits {
+  static void mapping(IO &io, Symbol::Details &Detail) {
+io.mapOptional("Documentation", Detail.Documentation);
+io.mapOptional("CompletionDetail", Detail.CompletionDetail);
   }
 };
 
+// A YamlIO normalizer for fields of type "const T*" allocated on an arena.
+// Normalizes to Optional, so traits should be provided for T.
+template  struct ArenaPtr {
+  ArenaPtr(IO &) {}
+  ArenaPtr(IO &, const T *D) {
+if (D)
+  Opt = *D;
+  }
+
+  const T *denormalize(IO &IO) {
+assert(IO.getContext() && "Expecting an arena (as context) to allocate "
+  "data for read symbols.");
+if (!Opt)
+  return nullptr;
+return new (*static_cast(IO.getContext()))
+T(std::move(*Opt)); // Allocate a copy of Opt on the arena.
+  }
+
+  llvm::Optional Opt;
+};
+
 template <> struct MappingTraits {
   static void mapping(IO &IO, Symbol &Sym) {
 MappingNormalization NSymbolID(IO, Sym.ID);
+MappingNormalization, const Symbol::Details *>
+NDetail(IO, Sym.Detail);
 IO.mapRequired("ID", NSymbolID->HexString);
 IO.mapRequired("Name", Sym.Name);
 IO.mapRequired("Scope", Sym.Scope);
@@ -92,8 +104,7 @@
 
 IO.mapOptional("CompletionSnippetInsertText",
Sym.CompletionSnippetInsertText);
-if (!IO.outputting() || Sym.Detail)
-  IO.mapOptional("Detail", Sym.Detail);
+IO.mapOptional("Detail", NDetail->Opt);
   }
 };
 
Index: clangd/index/Index.cpp
===
--- clangd/index/Index.cpp
+++ clangd/index/Index.cpp
@@ -64,13 +64,12 @@
   if (S.Detail) {
 // Copy values of StringRefs into arena.
 auto *Detail = Arena.Allocate();
-Detail->Documentation = S.Detail->Documentation;
-Detail->CompletionDetail = S.Detail->CompletionDetail;
-S.Detail = Detail;
-
+*Detail = *S.Detail;
 // Intern the actual strings.
-Intern(S.Detail->Documentation);
-Intern(S.Detail->CompletionDetail);
+Intern(Detail->Documentation);
+Intern(Detail->CompletionDetail);
+// Replace the detail pointer with our copy.
+S.Detail = Detail;
   }
 }
 
Index: clangd/index/Index.h
===
--- clangd/index/Index.h
+++ clangd/index/Index.h
@@ -156,7 +156,7 @@
   };
 
   // Optional details of the symbol.
-  Details *Detail = nullptr; // FIXME: should be const
+  const Details *Detail = nullptr;
 
   // FIXME: add definition location of the symbol.
   // FIXME: add all occurrences support.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r322509 - [clangd] Improve const-correctness of Symbol->Detail. NFC

2018-01-15 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Mon Jan 15 12:09:09 2018
New Revision: 322509

URL: http://llvm.org/viewvc/llvm-project?rev=322509&view=rev
Log:
[clangd] Improve const-correctness of Symbol->Detail. NFC

Summary:
This would have caught a bug I wrote in an early version of D42049, where
an index user could overwrite data internal to the index because the Symbol is
not deep-const.

The YAML traits are now a bit more verbose, but separate concerns a bit more
nicely: ArenaPtr can be reused for other similarly-allocated objects, including
scalars etc.

Reviewers: hokein

Subscribers: klimek, ilya-biryukov, cfe-commits, ioeric

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

Modified:
clang-tools-extra/trunk/clangd/index/Index.cpp
clang-tools-extra/trunk/clangd/index/Index.h
clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp

Modified: clang-tools-extra/trunk/clangd/index/Index.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Index.cpp?rev=322509&r1=322508&r2=322509&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Index.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Index.cpp Mon Jan 15 12:09:09 2018
@@ -64,13 +64,12 @@ static void own(Symbol &S, DenseSet();
-Detail->Documentation = S.Detail->Documentation;
-Detail->CompletionDetail = S.Detail->CompletionDetail;
-S.Detail = Detail;
-
+*Detail = *S.Detail;
 // Intern the actual strings.
-Intern(S.Detail->Documentation);
-Intern(S.Detail->CompletionDetail);
+Intern(Detail->Documentation);
+Intern(Detail->CompletionDetail);
+// Replace the detail pointer with our copy.
+S.Detail = Detail;
   }
 }
 

Modified: clang-tools-extra/trunk/clangd/index/Index.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Index.h?rev=322509&r1=322508&r2=322509&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Index.h (original)
+++ clang-tools-extra/trunk/clangd/index/Index.h Mon Jan 15 12:09:09 2018
@@ -156,7 +156,7 @@ struct Symbol {
   };
 
   // Optional details of the symbol.
-  Details *Detail = nullptr; // FIXME: should be const
+  const Details *Detail = nullptr;
 
   // FIXME: add definition location of the symbol.
   // FIXME: add all occurrences support.

Modified: clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp?rev=322509&r1=322508&r2=322509&view=diff
==
--- clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp Mon Jan 15 12:09:09 2018
@@ -60,27 +60,39 @@ template <> struct MappingTraits
-struct MappingTraits {
-  static void mapping(IO &io, Symbol::Details *&Detail) {
-if (!io.outputting()) {
-  assert(io.getContext() && "Expecting an arena (as context) to allocate "
-"data for new symbols.");
-  Detail = static_cast(io.getContext())
-   ->Allocate();
-} else if (!Detail) {
-  // Detail is optional in outputting.
-  return;
-}
-assert(Detail);
-io.mapOptional("Documentation", Detail->Documentation);
-io.mapOptional("CompletionDetail", Detail->CompletionDetail);
+template <> struct MappingTraits {
+  static void mapping(IO &io, Symbol::Details &Detail) {
+io.mapOptional("Documentation", Detail.Documentation);
+io.mapOptional("CompletionDetail", Detail.CompletionDetail);
   }
 };
 
+// A YamlIO normalizer for fields of type "const T*" allocated on an arena.
+// Normalizes to Optional, so traits should be provided for T.
+template  struct ArenaPtr {
+  ArenaPtr(IO &) {}
+  ArenaPtr(IO &, const T *D) {
+if (D)
+  Opt = *D;
+  }
+
+  const T *denormalize(IO &IO) {
+assert(IO.getContext() && "Expecting an arena (as context) to allocate "
+  "data for read symbols.");
+if (!Opt)
+  return nullptr;
+return new (*static_cast(IO.getContext()))
+T(std::move(*Opt)); // Allocate a copy of Opt on the arena.
+  }
+
+  llvm::Optional Opt;
+};
+
 template <> struct MappingTraits {
   static void mapping(IO &IO, Symbol &Sym) {
 MappingNormalization NSymbolID(IO, Sym.ID);
+MappingNormalization, const Symbol::Details *>
+NDetail(IO, Sym.Detail);
 IO.mapRequired("ID", NSymbolID->HexString);
 IO.mapRequired("Name", Sym.Name);
 IO.mapRequired("Scope", Sym.Scope);
@@ -92,8 +104,7 @@ template <> struct MappingTraits
 
 IO.mapOptional("CompletionSnippetInsertText",
Sym.CompletionSnippetInsertText);
-if (!IO.outputting() || Sym.Detail)
-  IO.mapOptional("Detail", Sym.Detail);
+IO.mapOptional("Detail", NDetail->Opt);
   }
 };
 


___

[libcxx] r322507 - Fix constexpr failure on C++11-based buildbots.

2018-01-15 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Mon Jan 15 11:59:09 2018
New Revision: 322507

URL: http://llvm.org/viewvc/llvm-project?rev=322507&view=rev
Log:
Fix constexpr failure on C++11-based buildbots.

Modified:

libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.find.end/find_end_pred.pass.cpp

Modified: 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.find.end/find_end_pred.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.find.end/find_end_pred.pass.cpp?rev=322507&r1=322506&r2=322507&view=diff
==
--- 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.find.end/find_end_pred.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.find.end/find_end_pred.pass.cpp
 Mon Jan 15 11:59:09 2018
@@ -25,7 +25,7 @@ struct count_equal
 {
 static unsigned count;
 template 
-TEST_CONSTEXPR bool operator()(const T& x, const T& y)
+TEST_CONSTEXPR_CXX14 bool operator()(const T& x, const T& y)
 {++count; return x == y;}
 };
 


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


[PATCH] D40023: [RISCV] Implement ABI lowering

2018-01-15 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

Looks like it fails with assertions disabled; no-asserts builds disable value 
labels, so the IR output looks a little different.


Repository:
  rL LLVM

https://reviews.llvm.org/D40023



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


[PATCH] D41648: [clang-tidy] implement cppcoreguidelines macro rules

2018-01-15 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

> Using regex could be a reasonable way out, but isn't going to solve the 
> problem in general because not all of the macro names are ones the user has 
> control over. Having to whitelist dozens of macros by name means this check 
> is simply going to be disabled by the user as being low-value.

Yes. I think with the regex its exactly implemented like the rules say. But 
adding sugar is still reasonable. I will run the check over llvm to get a 
feeling how much is still left after silence `LLVM_*` and others that are 
clearly scoped.

> Except that's not the only form of conditional compilation I'm worried about. 
> See Compiler.h where we do things like `#define __has_attribute(x) 0`, which 
> is a perfectly reasonable macro to define (and is an example of a macro name 
> outside of the user's control, so they cannot simply prefix it for a 
> whitelist).

Having a regex allows to add `__has_attribute` to it or a pattern like 
`__has*`. But how many cases for such macros are left? The goal of the 
guidelines is to change coding style and requiring to silence _SOME_ warnings 
is reasonable to me.

> However, I have no idea how we would handle cases like LLVM_LIKELY and 
> LLVM_UNLIKELY, but expecting users to NOLINT 500+ lines of common macro code 
> doesn't seem like a good first approach. I'd be curious to know what the C++ 
> Core Guidelines folks think about those use cases and how they would 
> recommend rewriting the code to adhere to their guidelines. Do they really 
> expect users to use *no* macros in C++ code outside of header include guards 
> and noop definitions even when asked about reasonable use cases like 
> cross-compiler attributes or builtins? I mean, many of these things cannot 
> even use the attribute the C++ Core Guidelines require for silencing such 
> diagnostics -- how do they want to use gsl::suppress to silence a diagnostic 
> on a macro definition?

I think the long term goal is removing the preprocessor, but especially 
compiler specifics are very unlikely to get away soon. 
They themself make exceptions: ES.33: If you must use macros, give them unique 
names 


>> 2. Compiler intrinsics These are similar to attributes and could maybe even 
>> treated the same.
> 
> I'm less certain about this one -- with attributes, there's syntax that we 
> can inspect (is there an `__attribute__` or `__declspec` keyword?), but with 
> intrinsics there's no commonality. Or are you thinking of tablegenning the 
> list of intrinsics?

I thought mostly of `__builtin` when proposing. Checking the MSVC docs showed 
that not all compilers do follow such nice naming conventions. Adding a clang 
and gcc list of builtins might still be manageable with basic string handling.
I feel that keeping any list of all compiler intrinsics is too much.

>> 3. Compatibility with older C++ Standards Stuff like `#define OVERRIDE 
>> override` if the code is compiled with C++11 or newer might be acceptable 
>> for stepwise modernization. This can can be considered as program text 
>> manipulation that was explicitly forbidden but does not obscure code so an 
>> exception could be made. Such macros can be detected with string comparisons.
> 
> How would you generalize this? I've seen people use macros for arbitrary 
> keywords (`#define CONST const` and `#define false false`) as well as macros 
> for arbitrary syntax (`#define DEFAULTED {}` or `#define DEFAULTED = 
> default`).

Not sure about all. I think new keywords like `#define OVERRIDE override` 
should definitly be allowed. But things like `false` not, because it already is 
a keyword in C++98.

I am against allowing `#define DEFAULTED` because both are perfectly valid and 
we ship a check for modernizing from one to the other version. This is 
different to `OVERRIDE`, because it adds additional value for the programmer 
who might be stuck at C++98.

>> 4. Debugging/Logging stuff that contains the Line and file. These can not be 
>> modeled with current C++(?), but `LineInfo` or similar exists. I don't know 
>> what its status is. I think it is ok to require manual silencing for such 
>> macros.
> 
> In addition to `__LINE__` and `__FILE__`, I think we want to include 
> `__DATE__`, `__TIME__`, and `__func__`.

Agreed.

> I think this list is a good start, but is likely incomplete. We'll probably 
> discover other things to add to the list when testing the check against other 
> real world code bases to see what patterns emerge from them.

Testing Frameworks are a common source for macro usage too. They should be 
coverable with the regex approach, but I don't know if there are other things 
hidden behind the interface that would be super annoying to silence.
Same for benchmark libraries.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41648



_

[libcxx] r322506 - More constexpr from P0202. count and count_if. Also fix a comment that Morwenn noted.

2018-01-15 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Mon Jan 15 11:40:34 2018
New Revision: 322506

URL: http://llvm.org/viewvc/llvm-project?rev=322506&view=rev
Log:
More constexpr from P0202. count and count_if. Also fix a comment that Morwenn 
noted.

Modified:
libcxx/trunk/include/algorithm
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.count/count.pass.cpp

libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.count/count_if.pass.cpp

Modified: libcxx/trunk/include/algorithm
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/algorithm?rev=322506&r1=322505&r2=322506&view=diff
==
--- libcxx/trunk/include/algorithm (original)
+++ libcxx/trunk/include/algorithm Mon Jan 15 11:40:34 2018
@@ -79,11 +79,11 @@ template 
-typename iterator_traits::difference_type
+constexpr typename iterator_traits::difference_type  // 
constexpr in C++20
 count(InputIterator first, InputIterator last, const T& value);
 
 template 
-typename iterator_traits::difference_type
+constexpr typename iterator_traits::difference_type // 
constexpr in C++20
 count_if(InputIterator first, InputIterator last, Predicate pred);
 
 template 
@@ -333,11 +333,11 @@ template 
-ForwardIterator
+constexpr ForwardIterator// constexpr in C++20
 is_sorted_until(ForwardIterator first, ForwardIterator last);
 
 template 
-ForwardIterator
+constexpr ForwardIterator// constexpr in C++20
 is_sorted_until(ForwardIterator first, ForwardIterator last, Compare comp);
 
 template 
@@ -1240,7 +1240,7 @@ adjacent_find(_ForwardIterator __first,
 // count
 
 template 
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
 typename iterator_traits<_InputIterator>::difference_type
 count(_InputIterator __first, _InputIterator __last, const _Tp& __value_)
 {
@@ -1254,7 +1254,7 @@ count(_InputIterator __first, _InputIter
 // count_if
 
 template 
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
 typename iterator_traits<_InputIterator>::difference_type
 count_if(_InputIterator __first, _InputIterator __last, _Predicate __pred)
 {

Modified: 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.count/count.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.count/count.pass.cpp?rev=322506&r1=322505&r2=322506&view=diff
==
--- libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.count/count.pass.cpp 
(original)
+++ libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.count/count.pass.cpp 
Mon Jan 15 11:40:34 2018
@@ -11,14 +11,25 @@
 
 // template
 //   requires HasEqualTo
-//   Iter::difference_type
+//   constexpr Iter::difference_type   // constexpr after C++17
 //   count(Iter first, Iter last, const T& value);
 
 #include 
 #include 
 
+#include "test_macros.h"
 #include "test_iterators.h"
 
+#if TEST_STD_VER > 17
+TEST_CONSTEXPR bool test_constexpr() {
+int ia[] = {0, 1, 2, 2, 0, 1, 2, 3};
+int ib[] = {1, 2, 3, 4, 5, 6};
+return(std::count(std::begin(ia), std::end(ia), 2) == 3)
+   && (std::count(std::begin(ib), std::end(ib), 9) == 0)
+   ;
+}
+#endif
+
 int main()
 {
 int ia[] = {0, 1, 2, 2, 0, 1, 2, 3};
@@ -29,4 +40,8 @@ int main()
   input_iterator(ia + sa), 7) == 0);
 assert(std::count(input_iterator(ia),
   input_iterator(ia), 2) == 0);
+
+#if TEST_STD_VER > 17
+static_assert(test_constexpr());
+#endif
 }

Modified: 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.count/count_if.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.count/count_if.pass.cpp?rev=322506&r1=322505&r2=322506&view=diff
==
--- 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.count/count_if.pass.cpp 
(original)
+++ 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.count/count_if.pass.cpp 
Mon Jan 15 11:40:34 2018
@@ -11,21 +11,31 @@
 
 // template Pred>
 //   requires CopyConstructible
-//   Iter::difference_type
+//   constexpr Iter::difference_type   // constexpr after C++17
 //   count_if(Iter first, Iter last, Pred pred);
 
 #include 
 #include 
 #include 
 
+#include "test_macros.h"
 #include "test_iterators.h"
 
 struct eq {
-eq (int val) : v(val) {}
-bool operator () (int v2) const { return v == v2; }
+TEST_CONSTEXPR eq (int val) : v(val) {}
+TEST_CONSTEXPR bool operator () (int v2) const { return v == v2; }
 int v;
 };
 
+#if TEST_STD_VER > 17
+TEST_CONSTEXPR bool test_constexpr() {
+int ia[] = {0, 1, 2, 2, 0, 1, 2, 3};
+int ib[] = {1, 2, 3, 4, 5, 6};
+return(std::count_if(std::begin(ia), std::end(ia), eq(2)) == 3)
+   && (std::count_if(std::begin(ib),

[PATCH] D41523: xmmintrin.h documentation fixes and updates

2018-01-15 Thread Craig Topper via Phabricator via cfe-commits
craig.topper accepted this revision.
craig.topper added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D41523



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


[libcxx] r322505 - Some of the tests from earlier today had 'int' as the return type when it should have been 'bool'. Fix that. It doesn't change the behavior of any of the tests, but it's more accura

2018-01-15 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Mon Jan 15 11:32:32 2018
New Revision: 322505

URL: http://llvm.org/viewvc/llvm-project?rev=322505&view=rev
Log:
Some of the tests from earlier today had 'int' as the return type when it 
should have been 'bool'. Fix that. It doesn't change the behavior of any of the 
tests, but it's more accurate.

Modified:

libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.partitions/is_partitioned.pass.cpp

libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.partitions/partition_point.pass.cpp
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.all_of/all_of.pass.cpp
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.any_of/any_of.pass.cpp

libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.is_permutation/is_permutation.pass.cpp

libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.is_permutation/is_permutation_pred.pass.cpp

libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.none_of/none_of.pass.cpp

libcxx/trunk/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap.pass.cpp

libcxx/trunk/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap_comp.pass.cpp

libcxx/trunk/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap_until.pass.cpp

libcxx/trunk/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap_until_comp.pass.cpp

libcxx/trunk/test/std/algorithms/alg.sorting/alg.sort/is.sorted/is_sorted.pass.cpp

libcxx/trunk/test/std/algorithms/alg.sorting/alg.sort/is.sorted/is_sorted_comp.pass.cpp

libcxx/trunk/test/std/algorithms/alg.sorting/alg.sort/is.sorted/is_sorted_until.pass.cpp

libcxx/trunk/test/std/algorithms/alg.sorting/alg.sort/is.sorted/is_sorted_until_comp.pass.cpp

Modified: 
libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.partitions/is_partitioned.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.partitions/is_partitioned.pass.cpp?rev=322505&r1=322504&r2=322505&view=diff
==
--- 
libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.partitions/is_partitioned.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.partitions/is_partitioned.pass.cpp
 Mon Jan 15 11:32:32 2018
@@ -27,7 +27,7 @@ struct is_odd {
 };
 
 #if TEST_STD_VER > 17
-TEST_CONSTEXPR int test_constexpr() {
+TEST_CONSTEXPR bool test_constexpr() {
 int ia[] = {1, 3, 5, 2, 4, 6};
 int ib[] = {1, 2, 3, 4, 5, 6};
 return std::is_partitioned(std::begin(ia), std::end(ia), is_odd())

Modified: 
libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.partitions/partition_point.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.partitions/partition_point.pass.cpp?rev=322505&r1=322504&r2=322505&view=diff
==
--- 
libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.partitions/partition_point.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.partitions/partition_point.pass.cpp
 Mon Jan 15 11:32:32 2018
@@ -26,7 +26,7 @@ struct is_odd
 
 
 #if TEST_STD_VER > 17
-TEST_CONSTEXPR int test_constexpr() {
+TEST_CONSTEXPR bool test_constexpr() {
 int ia[] = {1, 3, 5, 2, 4, 6};
 int ib[] = {1, 2, 3, 4, 5, 6};
 return(std::partition_point(std::begin(ia), std::end(ia), is_odd()) == 
ia+3)

Modified: 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.all_of/all_of.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.all_of/all_of.pass.cpp?rev=322505&r1=322504&r2=322505&view=diff
==
--- 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.all_of/all_of.pass.cpp 
(original)
+++ 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.all_of/all_of.pass.cpp 
Mon Jan 15 11:32:32 2018
@@ -28,7 +28,7 @@ struct test1
 };
 
 #if TEST_STD_VER > 17
-TEST_CONSTEXPR int test_constexpr() {
+TEST_CONSTEXPR bool test_constexpr() {
 int ia[] = {2, 4, 6, 8};
 int ib[] = {2, 4, 5, 8};
 return  std::all_of(std::begin(ia), std::end(ia), test1())

Modified: 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.any_of/any_of.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.any_of/any_of.pass.cpp?rev=322505&r1=322504&r2=322505&view=diff
==
--- 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.any_of/any_of.pass.cpp 
(original)
+++ 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.any_of/any_of.pass.cpp 
Mon Jan 15 11:32:32 2018
@@ -28,7 +28,7 @@ struct test1
 };
 
 #if TEST_STD_VER > 17
-TEST_CONSTEXPR int test_constexpr() {
+TES

[libcxx] r322504 - More P0202 constexpr-ifying. All the find_XXX algorithms in this commit.

2018-01-15 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Mon Jan 15 11:26:05 2018
New Revision: 322504

URL: http://llvm.org/viewvc/llvm-project?rev=322504&view=rev
Log:
More P0202 constexpr-ifying. All the find_XXX algorithms in this commit.

Modified:
libcxx/trunk/include/algorithm

libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.adjacent.find/adjacent_find.pass.cpp

libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.adjacent.find/adjacent_find_pred.pass.cpp

libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.find.end/find_end.pass.cpp

libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.find.end/find_end_pred.pass.cpp

libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.find.first.of/find_first_of.pass.cpp

libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.find.first.of/find_first_of_pred.pass.cpp
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.find/find.pass.cpp
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.find/find_if.pass.cpp

libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.find/find_if_not.pass.cpp

Modified: libcxx/trunk/include/algorithm
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/algorithm?rev=322504&r1=322503&r2=322504&view=diff
==
--- libcxx/trunk/include/algorithm (original)
+++ libcxx/trunk/include/algorithm Mon Jan 15 11:26:05 2018
@@ -39,43 +39,43 @@ template
-constexpr InputIterator   // constexpr in C++20
+constexpr InputIterator // constexpr in C++20
 find(InputIterator first, InputIterator last, const T& value);
 
 template 
-constexpr InputIterator // constexpr in C++20
+constexpr InputIterator // constexpr in C++20
 find_if(InputIterator first, InputIterator last, Predicate pred);
 
 template
-InputIterator
+InputIterator   // constexpr in C++20
 find_if_not(InputIterator first, InputIterator last, Predicate pred);
 
 template 
-ForwardIterator1
+ForwardIterator1// constexpr in C++20
 find_end(ForwardIterator1 first1, ForwardIterator1 last1,
  ForwardIterator2 first2, ForwardIterator2 last2);
 
 template 
-ForwardIterator1
+ForwardIterator1// constexpr in C++20
 find_end(ForwardIterator1 first1, ForwardIterator1 last1,
  ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate 
pred);
 
 template 
-ForwardIterator1
+constexpr ForwardIterator1  // constexpr in C++20
 find_first_of(ForwardIterator1 first1, ForwardIterator1 last1,
   ForwardIterator2 first2, ForwardIterator2 last2);
 
 template 
-ForwardIterator1
+constexpr ForwardIterator1  // constexpr in C++20
 find_first_of(ForwardIterator1 first1, ForwardIterator1 last1,
   ForwardIterator2 first2, ForwardIterator2 last2, 
BinaryPredicate pred);
 
 template 
-ForwardIterator
+constexpr ForwardIterator   // constexpr in C++20
 adjacent_find(ForwardIterator first, ForwardIterator last);
 
 template 
-ForwardIterator
+constexpr ForwardIterator   // constexpr in C++20
 adjacent_find(ForwardIterator first, ForwardIterator last, BinaryPredicate 
pred);
 
 template 
@@ -1016,7 +1016,7 @@ find_if(_InputIterator __first, _InputIt
 // find_if_not
 
 template
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
 _InputIterator
 find_if_not(_InputIterator __first, _InputIterator __last, _Predicate __pred)
 {
@@ -1029,7 +1029,7 @@ find_if_not(_InputIterator __first, _Inp
 // find_end
 
 template 
-_ForwardIterator1
+_LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator1
 __find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
_ForwardIterator2 __first2, _ForwardIterator2 __last2, 
_BinaryPredicate __pred,
forward_iterator_tag, forward_iterator_tag)
@@ -1071,7 +1071,7 @@ __find_end(_ForwardIterator1 __first1, _
 }
 
 template 
-_BidirectionalIterator1
+_LIBCPP_CONSTEXPR_AFTER_CXX17 _BidirectionalIterator1
 __find_end(_BidirectionalIterator1 __first1, _BidirectionalIterator1 __last1,
_BidirectionalIterator2 __first2, _BidirectionalIterator2 __last2, 
_BinaryPredicate __pred,
bidirectional_iterator_tag, bidirectional_iterator_tag)
@@ -1151,7 +1151,7 @@ __find_end(_RandomAccessIterator1 __firs
 }
 
 template 
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
 _ForwardIterator1
 find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
  _ForwardIterator2 __first2, _ForwardIterator2 __last2, 
_BinaryPredicate __pred)
@@ -1163,7 +1163,7 @@ find_end(_ForwardIterator1 __first1, _Fo
 }
 
 template 
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
 _ForwardIterator1
 find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
  _ForwardIterator2 __first2, _ForwardIterator2 __last2)
@@ -118

[PATCH] D40023: [RISCV] Implement ABI lowering

2018-01-15 Thread Alex Bradbury via Phabricator via cfe-commits
asb added a comment.

The riscv32-abi and risc64-abi tests are failing (specifically the vararg 
checks) on the clang-with-thin-lto and modules-slave-2 buildbots:
http://lab.llvm.org:8011/builders/clang-with-thin-lto-ubuntu/builds/7892
http://lab.llvm.org:8011/builders/clang-x86_64-linux-selfhost-modules-2/builds/15300

Other buildbots appear fine. Before I revert, does anyone have any ideas what 
the problem might be? Obviously the tests pass on my local machine, plus a 
range of other builders.


Repository:
  rL LLVM

https://reviews.llvm.org/D40023



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


[PATCH] D41648: [clang-tidy] implement cppcoreguidelines macro rules

2018-01-15 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth updated this revision to Diff 129893.
JonasToth added a comment.

- address eugene comments


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41648

Files:
  clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp
  clang-tidy/cppcoreguidelines/MacroUsageCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/cppcoreguidelines-macro-usage.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/cppcoreguidelines-macro-usage-custom.cpp
  test/clang-tidy/cppcoreguidelines-macro-usage.cpp

Index: test/clang-tidy/cppcoreguidelines-macro-usage.cpp
===
--- /dev/null
+++ test/clang-tidy/cppcoreguidelines-macro-usage.cpp
@@ -0,0 +1,15 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-macro-usage %t
+
+#ifndef INCLUDE_GUARD
+#define INCLUDE_GUARD
+
+#define PROBLEMATIC_CONSTANT 0
+// CHECK-MESSAGES: [[@LINE-1]]:9: warning: macro used to declare a constant; consider using a 'constexpr' constant
+
+#define PROBLEMATIC_FUNCTION(x, y) ((a) > (b) ? (a) : (b))
+// CHECK-MESSAGES: [[@LINE-1]]:9: warning: function like macro used; consider a (constexpr) template function
+
+#define PROBLEMATIC_VARIADIC(...) (__VA_ARGS__)
+// CHECK-MESSAGES: [[@LINE-1]]:9: warning: variadic macro used; consider using a variadic template
+
+#endif
Index: test/clang-tidy/cppcoreguidelines-macro-usage-custom.cpp
===
--- /dev/null
+++ test/clang-tidy/cppcoreguidelines-macro-usage-custom.cpp
@@ -0,0 +1,24 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-macro-usage %t \
+// RUN: -config='{CheckOptions: \
+// RUN:  [{key: cppcoreguidelines-macro-usage.AllowedRegexp, value: "DEBUG_*|TEST_*"}]}' --
+
+#ifndef INCLUDE_GUARD
+#define INCLUDE_GUARD
+
+#define PROBLEMATIC_CONSTANT 0
+// CHECK-MESSAGES: [[@LINE-1]]:9: warning: macro used to declare a constant; consider using a 'constexpr' constant
+
+#define PROBLEMATIC_FUNCTION(x, y) ((a) > (b) ? (a) : (b))
+// CHECK-MESSAGES: [[@LINE-1]]:9: warning: function like macro used; consider a (constexpr) template function
+
+#define PROBLEMATIC_VARIADIC(...) (__VA_ARGS__)
+// CHECK-MESSAGES: [[@LINE-1]]:9: warning: variadic macro used; consider using a variadic template
+
+#define DEBUG_CONSTANT 0
+#define DEBUG_FUNCTION(x, y) ((a) > (b) ? (a) : (b))
+#define DEBUG_VARIADIC(...) (__VA_ARGS__)
+#define TEST_CONSTANT 0
+#define TEST_FUNCTION(x, y) ((a) > (b) ? (a) : (b))
+#define TEST_VARIADIC(...) (__VA_ARGS__)
+
+#endif
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -54,6 +54,7 @@
cert-oop11-cpp (redirects to performance-move-constructor-init) 
cppcoreguidelines-c-copy-assignment-signature (redirects to misc-unconventional-assign-operator) 
cppcoreguidelines-interfaces-global-init
+   cppcoreguidelines-macro-usage
cppcoreguidelines-no-malloc
cppcoreguidelines-owning-memory
cppcoreguidelines-pro-bounds-array-to-pointer-decay
Index: docs/clang-tidy/checks/cppcoreguidelines-macro-usage.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/cppcoreguidelines-macro-usage.rst
@@ -0,0 +1,12 @@
+.. title:: clang-tidy - cppcoreguidelines-macro-usage
+
+cppcoreguidelines-macro-usage
+=
+
+Find macro usage that is considered problematic because better language
+constructs exist for the task.
+The relevant sections in the C++ Core Guidelines are 
+`Enum.1 `_,
+`ES.30 `_,
+`ES.31 `_ and
+`ES.33 `_.
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -57,6 +57,12 @@
 Improvements to clang-tidy
 --
 
+- New `cppcoreguidelines-macro-usage
+  `_ check
+
+  Find macro usage that is considered problematic because better language
+  constructs exist for the task.
+
 - New `fuchsia-statically-constructed-objects
   `_ check
 
Index: clang-tidy/cppcoreguidelines/MacroUsageCheck.h
===
--- /de

[PATCH] D20124: [PCH] Serialize skipped preprocessor ranges

2018-01-15 Thread Cameron via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC322503: [PCH] Serialize skipped preprocessor ranges 
(authored by cameron314, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D20124?vs=125333&id=129892#toc

Repository:
  rC Clang

https://reviews.llvm.org/D20124

Files:
  include/clang/Lex/PreprocessingRecord.h
  include/clang/Serialization/ASTBitCodes.h
  include/clang/Serialization/ASTReader.h
  include/clang/Serialization/Module.h
  lib/Lex/PPDirectives.cpp
  lib/Lex/PreprocessingRecord.cpp
  lib/Serialization/ASTReader.cpp
  lib/Serialization/ASTWriter.cpp
  tools/libclang/CIndex.cpp
  unittests/libclang/LibclangTest.cpp

Index: include/clang/Lex/PreprocessingRecord.h
===
--- include/clang/Lex/PreprocessingRecord.h
+++ include/clang/Lex/PreprocessingRecord.h
@@ -297,6 +297,9 @@
 FileID FID) {
   return None;
 }
+
+/// \brief Read a preallocated skipped range from the external source.
+virtual SourceRange ReadSkippedRange(unsigned Index) = 0;
   };
   
   /// \brief A record of the steps taken while preprocessing a source file,
@@ -322,6 +325,8 @@
 /// \brief The set of ranges that were skipped by the preprocessor,
 std::vector SkippedRanges;
 
+bool SkippedRangesAllLoaded = true;
+
 /// \brief Global (loaded or local) ID for a preprocessed entity.
 /// Negative values are used to indicate preprocessed entities
 /// loaded from the external source while non-negative values are used to
@@ -377,6 +382,16 @@
 /// corresponds to the first newly-allocated entity.
 unsigned allocateLoadedEntities(unsigned NumEntities);
 
+/// \brief Allocate space for a new set of loaded preprocessed skipped
+/// ranges.
+///
+/// \returns The index into the set of loaded preprocessed ranges, which
+/// corresponds to the first newly-allocated range.
+unsigned allocateSkippedRanges(unsigned NumRanges);
+
+/// \brief Ensures that all external skipped ranges have been loaded.
+void ensureSkippedRangesLoaded();
+
 /// \brief Register a new macro definition.
 void RegisterMacroDefinition(MacroInfo *Macro, MacroDefinitionRecord *Def);
 
@@ -499,7 +514,8 @@
 MacroDefinitionRecord *findMacroDefinition(const MacroInfo *MI);
 
 /// \brief Retrieve all ranges that got skipped while preprocessing.
-const std::vector &getSkippedRanges() const {
+const std::vector &getSkippedRanges() {
+  ensureSkippedRangesLoaded();
   return SkippedRanges;
 }
 
Index: include/clang/Serialization/Module.h
===
--- include/clang/Serialization/Module.h
+++ include/clang/Serialization/Module.h
@@ -324,6 +324,12 @@
   const PPEntityOffset *PreprocessedEntityOffsets = nullptr;
   unsigned NumPreprocessedEntities = 0;
 
+  /// \brief Base ID for preprocessed skipped ranges local to this module.
+  unsigned BasePreprocessedSkippedRangeID = 0;
+
+  const PPSkippedRange *PreprocessedSkippedRangeOffsets = nullptr;
+  unsigned NumPreprocessedSkippedRanges = 0;
+
   // === Header search information ===
 
   /// \brief The number of local HeaderFileInfo structures.
Index: include/clang/Serialization/ASTBitCodes.h
===
--- include/clang/Serialization/ASTBitCodes.h
+++ include/clang/Serialization/ASTBitCodes.h
@@ -198,6 +198,25 @@
   }
 };
 
+/// \brief Source range of a skipped preprocessor region
+struct PPSkippedRange {
+  /// \brief Raw source location of beginning of range.
+  unsigned Begin;
+  /// \brief Raw source location of end of range.
+  unsigned End;
+
+  PPSkippedRange(SourceRange R)
+: Begin(R.getBegin().getRawEncoding()),
+  End(R.getEnd().getRawEncoding()) { }
+
+  SourceLocation getBegin() const {
+return SourceLocation::getFromRawEncoding(Begin);
+  }
+  SourceLocation getEnd() const {
+return SourceLocation::getFromRawEncoding(End);
+  }
+};
+
 /// \brief Source range/offset of a preprocessed entity.
 struct DeclOffset {
   /// \brief Raw source location.
@@ -627,6 +646,9 @@
 
   /// \brief The stack of open #ifs/#ifdefs recorded in a preamble.
   PP_CONDITIONAL_STACK = 62,
+
+  /// \brief A table of skipped ranges within the preprocessing record.
+  PPD_SKIPPED_RANGES = 63
 };
 
 /// \brief Record types used within a source manager block.
Index: include/clang/Serialization/ASTReader.h
===
--- include/clang/Serialization/ASTReader.h
+++ include/clang/Serialization/ASTReader.h
@@ -753,6 +753,13 @@
   /// added to the global preprocessing entity ID to produce a local ID.
   GlobalPreprocessedEntityMapType GlobalPreprocessedEntityMap;
 
+  

[PATCH] D41648: [clang-tidy] implement cppcoreguidelines macro rules

2018-01-15 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth marked 2 inline comments as done.
JonasToth added inline comments.



Comment at: docs/clang-tidy/checks/cppcoreguidelines-macro-usage.rst:8
+constructs exist for the task.
+The relevant sections in the C++ Coreguidelines are 
+`Enum.1 
`_,

Eugene.Zelenko wrote:
> Will be good idea to separate statements with empty line.
As a list or how do you mean? 


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41648



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


r322503 - [PCH] Serialize skipped preprocessor ranges

2018-01-15 Thread Cameron Desrochers via cfe-commits
Author: cameron314
Date: Mon Jan 15 11:14:16 2018
New Revision: 322503

URL: http://llvm.org/viewvc/llvm-project?rev=322503&view=rev
Log:
[PCH] Serialize skipped preprocessor ranges

The skipped preprocessor ranges are now serialized in the AST PCH file. This 
fixes, for example, libclang's clang_getSkippedRanges() returning zero ranges 
after reparsing a translation unit.

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

Modified:
cfe/trunk/include/clang/Lex/PreprocessingRecord.h
cfe/trunk/include/clang/Serialization/ASTBitCodes.h
cfe/trunk/include/clang/Serialization/ASTReader.h
cfe/trunk/include/clang/Serialization/Module.h
cfe/trunk/lib/Lex/PPDirectives.cpp
cfe/trunk/lib/Lex/PreprocessingRecord.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/tools/libclang/CIndex.cpp
cfe/trunk/unittests/libclang/LibclangTest.cpp

Modified: cfe/trunk/include/clang/Lex/PreprocessingRecord.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PreprocessingRecord.h?rev=322503&r1=322502&r2=322503&view=diff
==
--- cfe/trunk/include/clang/Lex/PreprocessingRecord.h (original)
+++ cfe/trunk/include/clang/Lex/PreprocessingRecord.h Mon Jan 15 11:14:16 2018
@@ -297,6 +297,9 @@ class Token;
 FileID FID) {
   return None;
 }
+
+/// \brief Read a preallocated skipped range from the external source.
+virtual SourceRange ReadSkippedRange(unsigned Index) = 0;
   };
   
   /// \brief A record of the steps taken while preprocessing a source file,
@@ -322,6 +325,8 @@ class Token;
 /// \brief The set of ranges that were skipped by the preprocessor,
 std::vector SkippedRanges;
 
+bool SkippedRangesAllLoaded = true;
+
 /// \brief Global (loaded or local) ID for a preprocessed entity.
 /// Negative values are used to indicate preprocessed entities
 /// loaded from the external source while non-negative values are used to
@@ -377,6 +382,16 @@ class Token;
 /// corresponds to the first newly-allocated entity.
 unsigned allocateLoadedEntities(unsigned NumEntities);
 
+/// \brief Allocate space for a new set of loaded preprocessed skipped
+/// ranges.
+///
+/// \returns The index into the set of loaded preprocessed ranges, which
+/// corresponds to the first newly-allocated range.
+unsigned allocateSkippedRanges(unsigned NumRanges);
+
+/// \brief Ensures that all external skipped ranges have been loaded.
+void ensureSkippedRangesLoaded();
+
 /// \brief Register a new macro definition.
 void RegisterMacroDefinition(MacroInfo *Macro, MacroDefinitionRecord *Def);
 
@@ -499,7 +514,8 @@ class Token;
 MacroDefinitionRecord *findMacroDefinition(const MacroInfo *MI);
 
 /// \brief Retrieve all ranges that got skipped while preprocessing.
-const std::vector &getSkippedRanges() const {
+const std::vector &getSkippedRanges() {
+  ensureSkippedRangesLoaded();
   return SkippedRanges;
 }
 

Modified: cfe/trunk/include/clang/Serialization/ASTBitCodes.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTBitCodes.h?rev=322503&r1=322502&r2=322503&view=diff
==
--- cfe/trunk/include/clang/Serialization/ASTBitCodes.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTBitCodes.h Mon Jan 15 11:14:16 2018
@@ -198,6 +198,25 @@ namespace serialization {
   }
 };
 
+/// \brief Source range of a skipped preprocessor region
+struct PPSkippedRange {
+  /// \brief Raw source location of beginning of range.
+  unsigned Begin;
+  /// \brief Raw source location of end of range.
+  unsigned End;
+
+  PPSkippedRange(SourceRange R)
+: Begin(R.getBegin().getRawEncoding()),
+  End(R.getEnd().getRawEncoding()) { }
+
+  SourceLocation getBegin() const {
+return SourceLocation::getFromRawEncoding(Begin);
+  }
+  SourceLocation getEnd() const {
+return SourceLocation::getFromRawEncoding(End);
+  }
+};
+
 /// \brief Source range/offset of a preprocessed entity.
 struct DeclOffset {
   /// \brief Raw source location.
@@ -627,6 +646,9 @@ namespace serialization {
 
   /// \brief The stack of open #ifs/#ifdefs recorded in a preamble.
   PP_CONDITIONAL_STACK = 62,
+
+  /// \brief A table of skipped ranges within the preprocessing record.
+  PPD_SKIPPED_RANGES = 63
 };
 
 /// \brief Record types used within a source manager block.

Modified: cfe/trunk/include/clang/Serialization/ASTReader.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTReader.h?rev=322503&r1=322502&r2=322503&view=diff
==

r322502 - [OPENMP] Update docs for OpenMP status, NFC.

2018-01-15 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Mon Jan 15 11:08:36 2018
New Revision: 322502

URL: http://llvm.org/viewvc/llvm-project?rev=322502&view=rev
Log:
[OPENMP] Update docs for OpenMP status, NFC.

Modified:
cfe/trunk/docs/OpenMPSupport.rst

Modified: cfe/trunk/docs/OpenMPSupport.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/OpenMPSupport.rst?rev=322502&r1=322501&r2=322502&view=diff
==
--- cfe/trunk/docs/OpenMPSupport.rst (original)
+++ cfe/trunk/docs/OpenMPSupport.rst Mon Jan 15 11:08:36 2018
@@ -33,7 +33,7 @@ Standalone directives
 
 * #pragma omp target update: :good:`Complete`.
 
-* #pragma omp target: :partial:`Partial`.  No support for the `depend` clauses.
+* #pragma omp target: :good:`Complete`.
 
 * #pragma omp declare target: :partial:`Partial`.  No full codegen support.
 


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


[PATCH] D41648: [clang-tidy] implement cppcoreguidelines macro rules

2018-01-15 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth updated this revision to Diff 129890.
JonasToth marked 2 inline comments as done.
JonasToth added a comment.

- doc fix


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41648

Files:
  clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp
  clang-tidy/cppcoreguidelines/MacroUsageCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/cppcoreguidelines-macro-usage.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/cppcoreguidelines-macro-usage-custom.cpp
  test/clang-tidy/cppcoreguidelines-macro-usage.cpp

Index: test/clang-tidy/cppcoreguidelines-macro-usage.cpp
===
--- /dev/null
+++ test/clang-tidy/cppcoreguidelines-macro-usage.cpp
@@ -0,0 +1,15 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-macro-usage %t
+
+#ifndef INCLUDE_GUARD
+#define INCLUDE_GUARD
+
+#define PROBLEMATIC_CONSTANT 0
+// CHECK-MESSAGES: [[@LINE-1]]:9: warning: macro used to declare a constant; consider using a 'constexpr' constant
+
+#define PROBLEMATIC_FUNCTION(x, y) ((a) > (b) ? (a) : (b))
+// CHECK-MESSAGES: [[@LINE-1]]:9: warning: function like macro used; consider a (constexpr) template function
+
+#define PROBLEMATIC_VARIADIC(...) (__VA_ARGS__)
+// CHECK-MESSAGES: [[@LINE-1]]:9: warning: variadic macro used; consider using a variadic template
+
+#endif
Index: test/clang-tidy/cppcoreguidelines-macro-usage-custom.cpp
===
--- /dev/null
+++ test/clang-tidy/cppcoreguidelines-macro-usage-custom.cpp
@@ -0,0 +1,25 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-macro-usage %t \
+// RUN: -config='{CheckOptions: \
+// RUN:  [{key: cppcoreguidelines-macro-usage.AllowedRegexp, value: "DEBUG_*|TEST_*"}]}' --
+
+#ifndef INCLUDE_GUARD
+#define INCLUDE_GUARD
+
+#define PROBLEMATIC_CONSTANT 0
+// CHECK-MESSAGES: [[@LINE-1]]:9: warning: macro used to declare a constant; consider using a 'constexpr' constant
+
+#define PROBLEMATIC_FUNCTION(x, y) ((a) > (b) ? (a) : (b))
+// CHECK-MESSAGES: [[@LINE-1]]:9: warning: function like macro used; consider a (constexpr) template function
+
+#define PROBLEMATIC_VARIADIC(...) (__VA_ARGS__)
+// CHECK-MESSAGES: [[@LINE-1]]:9: warning: variadic macro used; consider using a variadic template
+
+#define DEBUG_CONSTANT 0
+#define DEBUG_FUNCTION(x, y) ((a) > (b) ? (a) : (b))
+#define DEBUG_VARIADIC(...) (__VA_ARGS__)
+
+#define TEST_CONSTANT 0
+#define TEST_FUNCTION(x, y) ((a) > (b) ? (a) : (b))
+#define TEST_VARIADIC(...) (__VA_ARGS__)
+
+#endif
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -54,6 +54,7 @@
cert-oop11-cpp (redirects to performance-move-constructor-init) 
cppcoreguidelines-c-copy-assignment-signature (redirects to misc-unconventional-assign-operator) 
cppcoreguidelines-interfaces-global-init
+   cppcoreguidelines-macro-usage
cppcoreguidelines-no-malloc
cppcoreguidelines-owning-memory
cppcoreguidelines-pro-bounds-array-to-pointer-decay
Index: docs/clang-tidy/checks/cppcoreguidelines-macro-usage.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/cppcoreguidelines-macro-usage.rst
@@ -0,0 +1,12 @@
+.. title:: clang-tidy - cppcoreguidelines-macro-usage
+
+cppcoreguidelines-macro-usage
+=
+
+Find macro usage that is considered problematic because better language
+constructs exist for the task.
+The relevant sections in the C++ Core Guidelines are 
+`Enum.1 `_,
+`ES.30 `_,
+`ES.31 `_ and
+`ES.33 `_.
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -57,6 +57,12 @@
 Improvements to clang-tidy
 --
 
+- New `cppcoreguidelines-macro-usage
+  `_ check
+
+  Find macro usage that is considered problematic because better language
+  constructs exist for the task.
+
 - New `fuchsia-statically-constructed-objects
   `_ check
 
Index: clang-tidy/cppcoreguidelines/MacroUsageCheck.h
=

[PATCH] D41648: [clang-tidy] implement cppcoreguidelines macro rules

2018-01-15 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth updated this revision to Diff 129889.
JonasToth marked 2 inline comments as done.
JonasToth added a comment.

- address review comments


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41648

Files:
  clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp
  clang-tidy/cppcoreguidelines/MacroUsageCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/cppcoreguidelines-macro-usage.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/cppcoreguidelines-macro-usage-custom.cpp
  test/clang-tidy/cppcoreguidelines-macro-usage.cpp

Index: test/clang-tidy/cppcoreguidelines-macro-usage.cpp
===
--- /dev/null
+++ test/clang-tidy/cppcoreguidelines-macro-usage.cpp
@@ -0,0 +1,15 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-macro-usage %t
+
+#ifndef INCLUDE_GUARD
+#define INCLUDE_GUARD
+
+#define PROBLEMATIC_CONSTANT 0
+// CHECK-MESSAGES: [[@LINE-1]]:9: warning: macro used to declare a constant; consider using a 'constexpr' constant
+
+#define PROBLEMATIC_FUNCTION(x, y) ((a) > (b) ? (a) : (b))
+// CHECK-MESSAGES: [[@LINE-1]]:9: warning: function like macro used; consider a (constexpr) template function
+
+#define PROBLEMATIC_VARIADIC(...) (__VA_ARGS__)
+// CHECK-MESSAGES: [[@LINE-1]]:9: warning: variadic macro used; consider using a variadic template
+
+#endif
Index: test/clang-tidy/cppcoreguidelines-macro-usage-custom.cpp
===
--- /dev/null
+++ test/clang-tidy/cppcoreguidelines-macro-usage-custom.cpp
@@ -0,0 +1,25 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-macro-usage %t \
+// RUN: -config='{CheckOptions: \
+// RUN:  [{key: cppcoreguidelines-macro-usage.AllowedRegexp, value: "DEBUG_*|TEST_*"}]}' --
+
+#ifndef INCLUDE_GUARD
+#define INCLUDE_GUARD
+
+#define PROBLEMATIC_CONSTANT 0
+// CHECK-MESSAGES: [[@LINE-1]]:9: warning: macro used to declare a constant; consider using a 'constexpr' constant
+
+#define PROBLEMATIC_FUNCTION(x, y) ((a) > (b) ? (a) : (b))
+// CHECK-MESSAGES: [[@LINE-1]]:9: warning: function like macro used; consider a (constexpr) template function
+
+#define PROBLEMATIC_VARIADIC(...) (__VA_ARGS__)
+// CHECK-MESSAGES: [[@LINE-1]]:9: warning: variadic macro used; consider using a variadic template
+
+#define DEBUG_CONSTANT 0
+#define DEBUG_FUNCTION(x, y) ((a) > (b) ? (a) : (b))
+#define DEBUG_VARIADIC(...) (__VA_ARGS__)
+
+#define TEST_CONSTANT 0
+#define TEST_FUNCTION(x, y) ((a) > (b) ? (a) : (b))
+#define TEST_VARIADIC(...) (__VA_ARGS__)
+
+#endif
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -54,6 +54,7 @@
cert-oop11-cpp (redirects to performance-move-constructor-init) 
cppcoreguidelines-c-copy-assignment-signature (redirects to misc-unconventional-assign-operator) 
cppcoreguidelines-interfaces-global-init
+   cppcoreguidelines-macro-usage
cppcoreguidelines-no-malloc
cppcoreguidelines-owning-memory
cppcoreguidelines-pro-bounds-array-to-pointer-decay
Index: docs/clang-tidy/checks/cppcoreguidelines-macro-usage.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/cppcoreguidelines-macro-usage.rst
@@ -0,0 +1,12 @@
+.. title:: clang-tidy - cppcoreguidelines-macro-usage
+
+cppcoreguidelines-macro-usage
+=
+
+Find macro usage that is considered problematic because better language
+constructs exist for the task.
+The relevant sections in the C++ Coreguidelines are 
+`Enum.1 `_,
+`ES.30 `_,
+`ES.31 `_ and
+`ES.33 `_.
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -57,6 +57,12 @@
 Improvements to clang-tidy
 --
 
+- New `cppcoreguidelines-macro-usage
+  `_ check
+
+  Find macro usage that is considered problematic because better language
+  constructs exist for the task.
+
 - New `fuchsia-statically-constructed-objects
   `_ check
 
Index: clang-tidy/cppcoreguidelines/MacroUsageCheck.h
==

r322501 - [OPENMP] Add codegen for `depend` clauses on `target` directive.

2018-01-15 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Mon Jan 15 11:06:12 2018
New Revision: 322501

URL: http://llvm.org/viewvc/llvm-project?rev=322501&view=rev
Log:
[OPENMP] Add codegen for `depend` clauses on `target` directive.

Added basic support for codegen of `depend` clauses on `target`
directive.

Added:
cfe/trunk/test/OpenMP/target_depend_codegen.cpp
Modified:
cfe/trunk/include/clang/AST/OpenMPClause.h
cfe/trunk/lib/Basic/OpenMPKinds.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h
cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/test/OpenMP/target_codegen.cpp
cfe/trunk/test/OpenMP/target_parallel_codegen.cpp
cfe/trunk/test/OpenMP/target_parallel_for_codegen.cpp
cfe/trunk/test/OpenMP/target_parallel_for_simd_codegen.cpp
cfe/trunk/test/OpenMP/target_simd_codegen.cpp
cfe/trunk/test/OpenMP/target_teams_codegen.cpp
cfe/trunk/test/OpenMP/target_teams_distribute_codegen.cpp
cfe/trunk/test/OpenMP/target_teams_distribute_simd_codegen.cpp

Modified: cfe/trunk/include/clang/AST/OpenMPClause.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/OpenMPClause.h?rev=322501&r1=322500&r2=322501&view=diff
==
--- cfe/trunk/include/clang/AST/OpenMPClause.h (original)
+++ cfe/trunk/include/clang/AST/OpenMPClause.h Mon Jan 15 11:06:12 2018
@@ -3192,14 +3192,17 @@ public:
   /// \brief Build 'device' clause.
   ///
   /// \param E Expression associated with this clause.
+  /// \param CaptureRegion Innermost OpenMP region where expressions in this
+  /// clause must be captured.
   /// \param StartLoc Starting location of the clause.
   /// \param LParenLoc Location of '('.
   /// \param EndLoc Ending location of the clause.
-  OMPDeviceClause(Expr *E, Stmt *HelperE, SourceLocation StartLoc,
-  SourceLocation LParenLoc, SourceLocation EndLoc)
+  OMPDeviceClause(Expr *E, Stmt *HelperE, OpenMPDirectiveKind CaptureRegion,
+  SourceLocation StartLoc, SourceLocation LParenLoc,
+  SourceLocation EndLoc)
   : OMPClause(OMPC_device, StartLoc, EndLoc), OMPClauseWithPreInit(this),
 LParenLoc(LParenLoc), Device(E) {
-setPreInitStmt(HelperE);
+setPreInitStmt(HelperE, CaptureRegion);
   }
 
   /// \brief Build an empty clause.

Modified: cfe/trunk/lib/Basic/OpenMPKinds.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/OpenMPKinds.cpp?rev=322501&r1=322500&r2=322501&view=diff
==
--- cfe/trunk/lib/Basic/OpenMPKinds.cpp (original)
+++ cfe/trunk/lib/Basic/OpenMPKinds.cpp Mon Jan 15 11:06:12 2018
@@ -891,6 +891,7 @@ void clang::getOpenMPCaptureRegions(
   case OMPD_target_teams:
   case OMPD_target_teams_distribute:
   case OMPD_target_teams_distribute_simd:
+CaptureRegions.push_back(OMPD_task);
 CaptureRegions.push_back(OMPD_target);
 CaptureRegions.push_back(OMPD_teams);
 break;
@@ -901,6 +902,7 @@ void clang::getOpenMPCaptureRegions(
 break;
   case OMPD_target:
   case OMPD_target_simd:
+CaptureRegions.push_back(OMPD_task);
 CaptureRegions.push_back(OMPD_target);
 break;
   case OMPD_teams_distribute_parallel_for:
@@ -911,6 +913,7 @@ void clang::getOpenMPCaptureRegions(
   case OMPD_target_parallel:
   case OMPD_target_parallel_for:
   case OMPD_target_parallel_for_simd:
+CaptureRegions.push_back(OMPD_task);
 CaptureRegions.push_back(OMPD_target);
 CaptureRegions.push_back(OMPD_parallel);
 break;
@@ -925,6 +928,7 @@ void clang::getOpenMPCaptureRegions(
 CaptureRegions.push_back(OMPD_taskloop);
 break;
   case OMPD_target_teams_distribute_parallel_for:
+CaptureRegions.push_back(OMPD_task);
 CaptureRegions.push_back(OMPD_target);
 CaptureRegions.push_back(OMPD_teams);
 CaptureRegions.push_back(OMPD_parallel);

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=322501&r1=322500&r2=322501&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Mon Jan 15 11:06:12 2018
@@ -4187,6 +4187,11 @@ static void emitPrivatesInit(CodeGenFunc
   auto &C = CGF.getContext();
   auto FI = std::next(KmpTaskTWithPrivatesQTyRD->field_begin());
   LValue PrivatesBase = CGF.EmitLValueForField(TDBase, *FI);
+  OpenMPDirectiveKind Kind = isOpenMPTaskLoopDirective(D.getDirectiveKind())
+ ? OMPD_taskloop
+ : OMPD_task;
+  const CapturedStmt &CS = *D.getCapturedStmt(Kind);
+  CodeGenFunction::CGCapturedStmtInfo CapturesInfo(CS);
   LValue SrcBase;
   bool IsTargetTask =
   isOpenMPTargetDataManagementDirective(D.getDirectiveKind()) ||
@@ -4195,16 +4200,12 @

[PATCH] D41648: [clang-tidy] implement cppcoreguidelines macro rules

2018-01-15 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tidy/cppcoreguidelines/MacroUsageCheck.h:15
+#include "clang/Lex/Preprocessor.h"
+
+namespace clang {

Please include .



Comment at: docs/clang-tidy/checks/cppcoreguidelines-macro-usage.rst:8
+constructs exist for the task.
+The relevant sections in the C++ Coreguidelines are 
+`Enum.1 
`_,

Will be good idea to separate statements with empty line.



Comment at: test/clang-tidy/cppcoreguidelines-macro-usage-custom.cpp:17
+
+
+#define DEBUG_CONSTANT 0

Unnecessary empty line.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41648



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


r322494 - [RISCV] Implement RISCV ABI lowering

2018-01-15 Thread Alex Bradbury via cfe-commits
Author: asb
Date: Mon Jan 15 09:54:52 2018
New Revision: 322494

URL: http://llvm.org/viewvc/llvm-project?rev=322494&view=rev
Log:
[RISCV] Implement RISCV ABI lowering

RISCVABIInfo is implemented in terms of XLen, supporting both RV32 and RV64. 
Unfortunately we need to count argument registers in the frontend in order to 
determine when to emit signext and zeroext attributes. Integer scalars are 
extended according to their type up to 32-bits and then sign-extended to XLen 
when passed in registers, but are anyext when passed on the stack. This patch 
only implements the base integer (soft float) ABIs.

For more information on the RISC-V ABI, see [the ABI 
doc](https://github.com/riscv/riscv-elf-psabi-doc/blob/master/riscv-elf.md), 
my [golden model](https://github.com/lowRISC/riscv-calling-conv-model), and 
the [LLVM RISC-V calling convention 
patch](https://reviews.llvm.org/D39898#2d1595b4) (specifically the comment 
documenting frontend expectations).

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

Added:
cfe/trunk/test/CodeGen/riscv32-abi.c
cfe/trunk/test/CodeGen/riscv64-abi.c
Modified:
cfe/trunk/lib/CodeGen/TargetInfo.cpp
cfe/trunk/test/Driver/riscv32-toolchain.c
cfe/trunk/test/Driver/riscv64-toolchain.c

Modified: cfe/trunk/lib/CodeGen/TargetInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.cpp?rev=322494&r1=322493&r2=322494&view=diff
==
--- cfe/trunk/lib/CodeGen/TargetInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/TargetInfo.cpp Mon Jan 15 09:54:52 2018
@@ -8770,6 +8770,182 @@ static bool getTypeString(SmallStringEnc
   return false;
 }
 
+//===--===//
+// RISCV ABI Implementation
+//===--===//
+
+namespace {
+class RISCVABIInfo : public DefaultABIInfo {
+private:
+  unsigned XLen; // Size of the integer ('x') registers in bits.
+  static const int NumArgGPRs = 8;
+
+public:
+  RISCVABIInfo(CodeGen::CodeGenTypes &CGT, unsigned XLen)
+  : DefaultABIInfo(CGT), XLen(XLen) {}
+
+  // DefaultABIInfo's classifyReturnType and classifyArgumentType are
+  // non-virtual, but computeInfo is virtual, so we overload it.
+  void computeInfo(CGFunctionInfo &FI) const override;
+
+  ABIArgInfo classifyArgumentType(QualType Ty, bool IsFixed,
+  int &ArgGPRsLeft) const;
+  ABIArgInfo classifyReturnType(QualType RetTy) const;
+
+  Address EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
+QualType Ty) const override;
+
+  ABIArgInfo extendType(QualType Ty) const;
+};
+} // end anonymous namespace
+
+void RISCVABIInfo::computeInfo(CGFunctionInfo &FI) const {
+  QualType RetTy = FI.getReturnType();
+  if (!getCXXABI().classifyReturnType(FI))
+FI.getReturnInfo() = classifyReturnType(RetTy);
+
+  // IsRetIndirect is true if classifyArgumentType indicated the value should
+  // be passed indirect or if the type size is greater than 2*xlen. e.g. fp128
+  // is passed direct in LLVM IR, relying on the backend lowering code to
+  // rewrite the argument list and pass indirectly on RV32.
+  bool IsRetIndirect = FI.getReturnInfo().getKind() == ABIArgInfo::Indirect ||
+   getContext().getTypeSize(RetTy) > (2 * XLen);
+
+  // We must track the number of GPRs used in order to conform to the RISC-V
+  // ABI, as integer scalars passed in registers should have signext/zeroext
+  // when promoted, but are anyext if passed on the stack. As GPR usage is
+  // different for variadic arguments, we must also track whether we are
+  // examining a vararg or not.
+  int ArgGPRsLeft = IsRetIndirect ? NumArgGPRs - 1 : NumArgGPRs;
+  int NumFixedArgs = FI.getNumRequiredArgs();
+
+  int ArgNum = 0;
+  for (auto &ArgInfo : FI.arguments()) {
+bool IsFixed = ArgNum < NumFixedArgs;
+ArgInfo.info = classifyArgumentType(ArgInfo.type, IsFixed, ArgGPRsLeft);
+ArgNum++;
+  }
+}
+
+ABIArgInfo RISCVABIInfo::classifyArgumentType(QualType Ty, bool IsFixed,
+  int &ArgGPRsLeft) const {
+  assert(ArgGPRsLeft <= NumArgGPRs && "Arg GPR tracking underflow");
+  Ty = useFirstFieldIfTransparentUnion(Ty);
+
+  // Structures with either a non-trivial destructor or a non-trivial
+  // copy constructor are always passed indirectly.
+  if (CGCXXABI::RecordArgABI RAA = getRecordArgABI(Ty, getCXXABI())) {
+if (ArgGPRsLeft)
+  ArgGPRsLeft -= 1;
+return getNaturalAlignIndirect(Ty, /*ByVal=*/RAA ==
+   CGCXXABI::RAA_DirectInMemory);
+  }
+
+  // Ignore empty structs/unions.
+  if (isEmptyRecord(getContext(), Ty, true))
+return ABIArgInfo::getIgnore();
+
+  uint64_t Size = getContext().getTypeSize(Ty);
+  uint64_t NeededAlign = getContext().getTypeAlign(Ty);
+  bool MustUseStack = false;
+  // Determine the numbe

[analyzer] Add support for __builtin_constant_p to BuiltinFunctionChecker

2018-01-15 Thread Felix Kostenzer via cfe-commits

Hi,

Added evaluation of __builtin_constant_p to the dedicated StaticAnalyzer checker
along with a regression test.

'make clang-test' results:

Testing Time: 335.63s
  Expected Passes : 11769
  Expected Failures : 19
  Unsupported Tests : 50

- felixIndex: lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
+++ lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
@@ -113,6 +113,23 @@ bool BuiltinFunctionChecker::evalCall(const CallExpr *CE,
 C.addTransition(state->BindExpr(CE, LCtx, V));
 return true;
   }
+  case Builtin::BI__builtin_constant_p: {
+SVal V;
+SValBuilder& SVB = C.getSValBuilder();
+
+llvm::APSInt Result;
+// Model semantics as 'A return of 0 does not indicate that the value is
+// not a constant, but merely that GCC cannot prove it is a constant [...]'
+if (CE->EvaluateAsInt(Result, C.getASTContext(), Expr::SE_NoSideEffects)) {
+  SVB.getBasicValueFactory().getAPSIntType(CE->getType()).apply(Result);
+  V = SVB.makeIntVal(Result);
+}
+else
+  V = SVB.makeZeroVal(CE->getType());
+
+C.addTransition(state->BindExpr(CE, LCtx, V));
+return true;
+  }
   }
 }
 
Index: test/Analysis/builtin-functions.cpp
===
--- test/Analysis/builtin-functions.cpp
+++ test/Analysis/builtin-functions.cpp
@@ -64,3 +64,18 @@ void g(int i) {
 // We give up the analysis on this path.
   }
 }
+
+void test_constant_p() {
+  int i = 1;
+  const int j = 2;
+  constexpr int k = 3;
+  clang_analyzer_eval(__builtin_constant_p(42)); // expected-warning {{TRUE}}
+  clang_analyzer_eval(__builtin_constant_p(i)); // expected-warning {{FALSE}}
+  clang_analyzer_eval(__builtin_constant_p(j)); // expected-warning {{TRUE}}
+  clang_analyzer_eval(__builtin_constant_p(k)); // expected-warning {{TRUE}}
+  clang_analyzer_eval(__builtin_constant_p(i + 42)); // expected-warning {{FALSE}}
+  clang_analyzer_eval(__builtin_constant_p(j + 42)); // expected-warning {{TRUE}}
+  clang_analyzer_eval(__builtin_constant_p(k + 42)); // expected-warning {{TRUE}}
+  clang_analyzer_eval(__builtin_constant_p(" ")); // expected-warning {{TRUE}}
+  clang_analyzer_eval(__builtin_constant_p(test_constant_p)); // expected-warning {{FALSE}}
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: D40673: Add _Float128 as alias to __float128 to enable compilations on Fedora27/glibc2-26

2018-01-15 Thread Szabolcs Nagy via cfe-commits
On 13/01/18 12:33, Blower, Melanie wrote:
>> -Original Message-
>> From: Szabolcs Nagy via Phabricator [mailto:revi...@reviews.llvm.org]
>> Sent: Friday, January 12, 2018 3:18 PM 
>>
>> nsz added a comment.
>>  
>>
>> it is not clear to me from the original bug report what "fedora 27 workloads"
>> break because of the lack of _Float128 type on x86.  The glibc headers refer 
>> to
>> _Float128, but normal include should not break unless the compiler claims to 
>> be
>>> =gcc-7 or somebody explicitly requested the _Float128 support.
> [Blower, Melanie] I was building open source projects like ffmpeg, linux from 
> scratch, and others. I was incorrect in my original post, I was using a 
> patched compiler which led to _Float128 being exposed. In an unpatched clang 
> this problem doesn't arise.  I regret the lack of care taken in my analysis 
> of the problem.

then please revert the related patches.
(or finish the _Float128 support).

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


[PATCH] D41648: [clang-tidy] implement cppcoreguidelines macro rules

2018-01-15 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth updated this revision to Diff 129886.
JonasToth added a comment.

- [Feature] implement regex for allowed macros
- [Test] add proper tests for regex silencing


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41648

Files:
  clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp
  clang-tidy/cppcoreguidelines/MacroUsageCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/cppcoreguidelines-macro-usage.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/cppcoreguidelines-macro-usage-custom.cpp
  test/clang-tidy/cppcoreguidelines-macro-usage.cpp

Index: test/clang-tidy/cppcoreguidelines-macro-usage.cpp
===
--- /dev/null
+++ test/clang-tidy/cppcoreguidelines-macro-usage.cpp
@@ -0,0 +1,15 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-macro-usage %t
+
+#ifndef INCLUDE_GUARD
+#define INCLUDE_GUARD
+
+#define PROBLEMATIC_CONSTANT 0
+// CHECK-MESSAGES: [[@LINE-1]]:9: warning: don't use macros to declare constants
+
+#define PROBLEMATIC_FUNCTION(x,y) ((a) > (b) ? (a) : (b))
+// CHECK-MESSAGES: [[@LINE-1]]:9: warning: don't use macros to simulate functions
+
+#define PROBLEMATIC_VARIADIC(...) (__VA_ARGS__)
+// CHECK-MESSAGES: [[@LINE-1]]:9: warning: don't use macros to simulate variadic templates
+
+#endif
Index: test/clang-tidy/cppcoreguidelines-macro-usage-custom.cpp
===
--- /dev/null
+++ test/clang-tidy/cppcoreguidelines-macro-usage-custom.cpp
@@ -0,0 +1,26 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-macro-usage %t \
+// RUN: -config='{CheckOptions: \
+// RUN:  [{key: cppcoreguidelines-macro-usage.AllowedRegexp, value: "DEBUG_*|TEST_*"}]}' --
+
+#ifndef INCLUDE_GUARD
+#define INCLUDE_GUARD
+
+#define PROBLEMATIC_CONSTANT 0
+// CHECK-MESSAGES: [[@LINE-1]]:9: warning: don't use macros to declare constants
+
+#define PROBLEMATIC_FUNCTION(x,y) ((a) > (b) ? (a) : (b))
+// CHECK-MESSAGES: [[@LINE-1]]:9: warning: don't use macros to simulate functions
+
+#define PROBLEMATIC_VARIADIC(...) (__VA_ARGS__)
+// CHECK-MESSAGES: [[@LINE-1]]:9: warning: don't use macros to simulate variadic templates
+
+
+#define DEBUG_CONSTANT 0
+#define DEBUG_FUNCTION(x,y) ((a) > (b) ? (a) : (b))
+#define DEBUG_VARIADIC(...) (__VA_ARGS__)
+
+#define TEST_CONSTANT 0
+#define TEST_FUNCTION(x,y) ((a) > (b) ? (a) : (b))
+#define TEST_VARIADIC(...) (__VA_ARGS__)
+
+#endif
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -54,6 +54,7 @@
cert-oop11-cpp (redirects to performance-move-constructor-init) 
cppcoreguidelines-c-copy-assignment-signature (redirects to misc-unconventional-assign-operator) 
cppcoreguidelines-interfaces-global-init
+   cppcoreguidelines-macro-usage
cppcoreguidelines-no-malloc
cppcoreguidelines-owning-memory
cppcoreguidelines-pro-bounds-array-to-pointer-decay
Index: docs/clang-tidy/checks/cppcoreguidelines-macro-usage.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/cppcoreguidelines-macro-usage.rst
@@ -0,0 +1,12 @@
+.. title:: clang-tidy - cppcoreguidelines-macro-usage
+
+cppcoreguidelines-macro-usage
+=
+
+Find macro usage that is considered problematic because better language
+constructs exist for the task.
+The relevant sections in the C++ Coreguidelines are 
+`Enum.1 `_,
+`ES.30 `_,
+`ES.31 `_ and
+`ES.33 `_.
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -57,6 +57,12 @@
 Improvements to clang-tidy
 --
 
+- New `cppcoreguidelines-macro-usage
+  `_ check
+
+  Find macro usage that is considered problematic because better language
+  constructs exist for the task.
+
 - New `fuchsia-statically-constructed-objects
   `_ check
 
Index: clang-tidy/cppcoreguidelines/MacroUsageCheck.h
===
--- /dev/null
+++ clang-tidy/cppcoreguidelines/MacroUsageCheck.h
@@ -0,0 +1,44 @@

Re: r322065 - Avoid assumption that lit tests are writable (in a couple more places). NFC

2018-01-15 Thread David Blaikie via cfe-commits
I feel like this sort of change will regress quite quickly - in the sense
that most 'cp' in tests is probably there to put it somewhere writable (in
some cases its to put it in a particular location, not about writability).
Any way we could fix 'cp' in lit to do the right thing here? (I doubt any
test /needs/ cp to propagate the writability bit?)

On Tue, Jan 9, 2018 at 1:34 AM Sam McCall via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: sammccall
> Date: Tue Jan  9 01:32:53 2018
> New Revision: 322065
>
> URL: http://llvm.org/viewvc/llvm-project?rev=322065&view=rev
> Log:
> Avoid assumption that lit tests are writable (in a couple more places). NFC
>
> Modified:
> cfe/trunk/test/Modules/modify-module.m
> cfe/trunk/test/PCH/modified-header-crash.c
>
> Modified: cfe/trunk/test/Modules/modify-module.m
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/modify-module.m?rev=322065&r1=322064&r2=322065&view=diff
>
> ==
> --- cfe/trunk/test/Modules/modify-module.m (original)
> +++ cfe/trunk/test/Modules/modify-module.m Tue Jan  9 01:32:53 2018
> @@ -3,9 +3,9 @@
>
>  // RUN: rm -rf %t
>  // RUN: mkdir -p %t/include
> -// RUN: cp %S/Inputs/Modified/A.h %t/include
> -// RUN: cp %S/Inputs/Modified/B.h %t/include
> -// RUN: cp %S/Inputs/Modified/module.map %t/include
> +// RUN: cat %S/Inputs/Modified/A.h > %t/include/A.h
> +// RUN: cat %S/Inputs/Modified/B.h > %t/include/B.h
> +// RUN: cat %S/Inputs/Modified/module.map > %t/include/module.map
>  // RUN: %clang_cc1 -fdisable-module-hash -fmodules-cache-path=%t/cache
> -fmodules -fimplicit-module-maps -I %t/include %s -verify
>  // RUN: echo '' >> %t/include/B.h
>  // RUN: %clang_cc1 -fdisable-module-hash -fmodules-cache-path=%t/cache
> -fmodules -fimplicit-module-maps -I %t/include %s -verify
>
> Modified: cfe/trunk/test/PCH/modified-header-crash.c
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/modified-header-crash.c?rev=322065&r1=322064&r2=322065&view=diff
>
> ==
> --- cfe/trunk/test/PCH/modified-header-crash.c (original)
> +++ cfe/trunk/test/PCH/modified-header-crash.c Tue Jan  9 01:32:53 2018
> @@ -1,6 +1,6 @@
>  // Don't crash.
>
> -// RUN: cp %S/modified-header-crash.h %t.h
> +// RUN: cat %S/modified-header-crash.h > %t.h
>  // RUN: %clang_cc1 -DCAKE -x c-header %t.h -emit-pch -o %t
>  // RUN: echo 'int foobar;' >> %t.h
>  // RUN: not %clang_cc1 %s -include-pch %t -fsyntax-only
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r322350 - [ODRHash] Don't hash friend functions.

2018-01-15 Thread David Blaikie via cfe-commits
I'm surprised this problem is unique to friend functions with definitions
inline and the friend declaration site - doesn't a similar issue occur with
member functions of templates that are not instantiated in some (similar)
contexts?

Is there a common solution that could be used for both cases?

On Thu, Jan 11, 2018 at 8:43 PM Richard Trieu via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: rtrieu
> Date: Thu Jan 11 20:42:27 2018
> New Revision: 322350
>
> URL: http://llvm.org/viewvc/llvm-project?rev=322350&view=rev
> Log:
> [ODRHash] Don't hash friend functions.
>
> In certain combinations of templated classes and friend functions, the body
> of friend functions does not get propagated along with function signature.
> Exclude friend functions for hashing to avoid this case.
>
> Added:
> cfe/trunk/test/Modules/Inputs/odr_hash-Friend/
> cfe/trunk/test/Modules/Inputs/odr_hash-Friend/Box.h
> cfe/trunk/test/Modules/Inputs/odr_hash-Friend/M1.h
> cfe/trunk/test/Modules/Inputs/odr_hash-Friend/M2.h
> cfe/trunk/test/Modules/Inputs/odr_hash-Friend/M3.h
> cfe/trunk/test/Modules/Inputs/odr_hash-Friend/module.modulemap
> cfe/trunk/test/Modules/odr_hash-Friend.cpp
> Modified:
> cfe/trunk/lib/AST/ODRHash.cpp
>
> Modified: cfe/trunk/lib/AST/ODRHash.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ODRHash.cpp?rev=322350&r1=322349&r2=322350&view=diff
>
> ==
> --- cfe/trunk/lib/AST/ODRHash.cpp (original)
> +++ cfe/trunk/lib/AST/ODRHash.cpp Thu Jan 11 20:42:27 2018
> @@ -478,6 +478,8 @@ void ODRHash::AddFunctionDecl(const Func
>
>// TODO: Fix hashing for class methods.
>if (isa(Function)) return;
> +  // And friend functions.
> +  if (Function->getFriendObjectKind()) return;
>
>// Skip functions that are specializations or in specialization context.
>const DeclContext *DC = Function;
>
> Added: cfe/trunk/test/Modules/Inputs/odr_hash-Friend/Box.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/odr_hash-Friend/Box.h?rev=322350&view=auto
>
> ==
> --- cfe/trunk/test/Modules/Inputs/odr_hash-Friend/Box.h (added)
> +++ cfe/trunk/test/Modules/Inputs/odr_hash-Friend/Box.h Thu Jan 11
> 20:42:27 2018
> @@ -0,0 +1,14 @@
> +template 
> +struct iterator {
> +  void Compare(const iterator &x) { }
> +  friend void Check(iterator) {}
> +};
> +
> +template  struct Box {
> +  iterator I;
> +
> +  void test() {
> +Check(I);
> +I.Compare(I);
> +  }
> +};
>
> Added: cfe/trunk/test/Modules/Inputs/odr_hash-Friend/M1.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/odr_hash-Friend/M1.h?rev=322350&view=auto
>
> ==
> --- cfe/trunk/test/Modules/Inputs/odr_hash-Friend/M1.h (added)
> +++ cfe/trunk/test/Modules/Inputs/odr_hash-Friend/M1.h Thu Jan 11 20:42:27
> 2018
> @@ -0,0 +1,6 @@
> +#include "Box.h"
> +
> +void Peek() {
> +  Box<> Gift;
> +  Gift.test();
> +}
>
> Added: cfe/trunk/test/Modules/Inputs/odr_hash-Friend/M2.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/odr_hash-Friend/M2.h?rev=322350&view=auto
>
> ==
> --- cfe/trunk/test/Modules/Inputs/odr_hash-Friend/M2.h (added)
> +++ cfe/trunk/test/Modules/Inputs/odr_hash-Friend/M2.h Thu Jan 11 20:42:27
> 2018
> @@ -0,0 +1,5 @@
> +#include "Box.h"
> +void x() {
> +  Box<> Unused;
> +  //Unused.test();
> +}
>
> Added: cfe/trunk/test/Modules/Inputs/odr_hash-Friend/M3.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/odr_hash-Friend/M3.h?rev=322350&view=auto
>
> ==
> --- cfe/trunk/test/Modules/Inputs/odr_hash-Friend/M3.h (added)
> +++ cfe/trunk/test/Modules/Inputs/odr_hash-Friend/M3.h Thu Jan 11 20:42:27
> 2018
> @@ -0,0 +1,7 @@
> +#include "Box.h"
> +#include "M2.h"
> +
> +void Party() {
> +  Box<> Present;
> +  Present.test();
> +}
>
> Added: cfe/trunk/test/Modules/Inputs/odr_hash-Friend/module.modulemap
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/odr_hash-Friend/module.modulemap?rev=322350&view=auto
>
> ==
> --- cfe/trunk/test/Modules/Inputs/odr_hash-Friend/module.modulemap (added)
> +++ cfe/trunk/test/Modules/Inputs/odr_hash-Friend/module.modulemap Thu Jan
> 11 20:42:27 2018
> @@ -0,0 +1,15 @@
> +module Box {
> +  header "Box.h"
> +}
> +
> +module Module1 {
> +  header "M1.h"
> +}
> +
> +module Module2 {
> +  header "M2.h"
> +}
> +
> +module Module3 {
> +  header "M3.h"
> +}
>
> Added: cfe/trunk/test/Modules/odr_hash-Friend.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/odr_hash-Friend.cpp?rev=322350&view=

Re: r322405 - Disable test for Windows to fix Windows buildbots.

2018-01-15 Thread David Blaikie via cfe-commits
might be worth having an explanation (probably in both the commit message
and in a comment in the source) about why this test isn't supported on
windows?

On Fri, Jan 12, 2018 at 1:50 PM Richard Trieu via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: rtrieu
> Date: Fri Jan 12 13:49:20 2018
> New Revision: 322405
>
> URL: http://llvm.org/viewvc/llvm-project?rev=322405&view=rev
> Log:
> Disable test for Windows to fix Windows buildbots.
>
> Modified:
> cfe/trunk/test/Modules/odr_hash-Friend.cpp
>
> Modified: cfe/trunk/test/Modules/odr_hash-Friend.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/odr_hash-Friend.cpp?rev=322405&r1=322404&r2=322405&view=diff
>
> ==
> --- cfe/trunk/test/Modules/odr_hash-Friend.cpp (original)
> +++ cfe/trunk/test/Modules/odr_hash-Friend.cpp Fri Jan 12 13:49:20 2018
> @@ -8,6 +8,8 @@
>  // RUN:  -fmodules-cache-path=%t/modules.cache \
>  // RUN:  -std=c++11 -x c++ %s -verify
>
> +// UNSUPPORTED: windows
> +
>  // expected-no-diagnostics
>
>  #include "Box.h"
>
>
> ___
> 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] D5767: Template Instantiation Observer + a few other templight-related changes

2018-01-15 Thread Ábel Sinkovics via Phabricator via cfe-commits
sabel83 added a comment.

I have no commit access, please commit the patch for me.


https://reviews.llvm.org/D5767



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


[PATCH] D41998: [clang-tidy] Expand readability-redundant-smartptr-get to understand implicit converions to bool in more contexts.

2018-01-15 Thread Samuel Benzaquen via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE322497: [clang-tidy] Expand 
readability-redundant-smartptr-get to understand implicit… (authored by sbenza, 
committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D41998?vs=129880&id=129882#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D41998

Files:
  clang-tidy/readability/RedundantSmartptrGetCheck.cpp
  test/clang-tidy/readability-redundant-smartptr-get.cpp

Index: clang-tidy/readability/RedundantSmartptrGetCheck.cpp
===
--- clang-tidy/readability/RedundantSmartptrGetCheck.cpp
+++ clang-tidy/readability/RedundantSmartptrGetCheck.cpp
@@ -51,6 +51,20 @@
   unaryOperator(hasOperatorName("*"),
 hasUnaryOperand(callToGet(QuacksLikeASmartptr))),
   Callback);
+
+  // Catch '!ptr.get()'
+  const auto CallToGetAsBool = ignoringParenImpCasts(callToGet(recordDecl(
+  QuacksLikeASmartptr, has(cxxConversionDecl(returns(booleanType()));
+  Finder->addMatcher(
+  unaryOperator(hasOperatorName("!"), hasUnaryOperand(CallToGetAsBool)),
+  Callback);
+
+  // Catch 'if(ptr.get())'
+  Finder->addMatcher(ifStmt(hasCondition(CallToGetAsBool)), Callback);
+
+  // Catch 'ptr.get() ? X : Y'
+  Finder->addMatcher(conditionalOperator(hasCondition(CallToGetAsBool)),
+ Callback);
 }
 
 void registerMatchersForGetEquals(MatchFinder *Finder,
@@ -72,11 +86,6 @@
  hasEitherOperand(callToGet(IsAKnownSmartptr))),
   Callback);
 
-  // Matches against if(ptr.get())
-  Finder->addMatcher(
-  ifStmt(hasCondition(ignoringImpCasts(callToGet(IsAKnownSmartptr,
-  Callback);
-
   // FIXME: Match and fix if (l.get() == r.get()).
 }
 
Index: test/clang-tidy/readability-redundant-smartptr-get.cpp
===
--- test/clang-tidy/readability-redundant-smartptr-get.cpp
+++ test/clang-tidy/readability-redundant-smartptr-get.cpp
@@ -9,13 +9,15 @@
   T& operator*() const;
   T* operator->() const;
   T* get() const;
+  explicit operator bool() const noexcept;
 };
 
 template 
 struct shared_ptr {
   T& operator*() const;
   T* operator->() const;
   T* get() const;
+  explicit operator bool() const noexcept;
 };
 
 }  // namespace std
@@ -28,6 +30,7 @@
   Bar* operator->();
   Bar& operator*();
   Bar* get();
+  explicit operator bool() const;
 };
 struct int_ptr {
   int* get();
@@ -110,6 +113,23 @@
   // CHECK-MESSAGES: uu.get() == nullptr;
   // CHECK-FIXES: bool bb = uu == nullptr;
 
+  if (up->get());
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant get() call
+  // CHECK-MESSAGES: if (up->get());
+  // CHECK-FIXES: if (*up);
+  if ((uu.get()));
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: redundant get() call
+  // CHECK-MESSAGES: if ((uu.get()));
+  // CHECK-FIXES: if ((uu));
+  bb = !ss->get();
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: redundant get() call
+  // CHECK-MESSAGES: bb = !ss->get();
+  // CHECK-FIXES: bb = !*ss;
+  bb = u.get() ? true : false;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: redundant get() call
+  // CHECK-MESSAGES: bb = u.get() ? true : false;
+  // CHECK-FIXES: bb = u ? true : false;
+
   bb = nullptr != ss->get();
   // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: redundant get() call
   // CHECK-MESSAGES: nullptr != ss->get();
@@ -146,10 +166,6 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: redundant get() call
   // CHECK-MESSAGES: if (NULL == x.get());
   // CHECK-FIXES: if (NULL == x);
-  if (x.get());
-  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant get() call
-  // CHECK-MESSAGES: if (x.get());
-  // CHECK-FIXES: if (x);
 }
 
 void Negative() {
@@ -175,4 +191,6 @@
 
   int_ptr ip;
   bool bb = ip.get() == nullptr;
+  bb = !ip.get();
+  bb = ip.get() ? true : false;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D41998: [clang-tidy] Expand readability-redundant-smartptr-get to understand implicit converions to bool in more contexts.

2018-01-15 Thread Samuel Benzaquen via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL322497: [clang-tidy] Expand 
readability-redundant-smartptr-get to understand implicit… (authored by sbenza, 
committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D41998

Files:
  clang-tools-extra/trunk/clang-tidy/readability/RedundantSmartptrGetCheck.cpp
  clang-tools-extra/trunk/test/clang-tidy/readability-redundant-smartptr-get.cpp

Index: clang-tools-extra/trunk/clang-tidy/readability/RedundantSmartptrGetCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/readability/RedundantSmartptrGetCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/readability/RedundantSmartptrGetCheck.cpp
@@ -51,6 +51,20 @@
   unaryOperator(hasOperatorName("*"),
 hasUnaryOperand(callToGet(QuacksLikeASmartptr))),
   Callback);
+
+  // Catch '!ptr.get()'
+  const auto CallToGetAsBool = ignoringParenImpCasts(callToGet(recordDecl(
+  QuacksLikeASmartptr, has(cxxConversionDecl(returns(booleanType()));
+  Finder->addMatcher(
+  unaryOperator(hasOperatorName("!"), hasUnaryOperand(CallToGetAsBool)),
+  Callback);
+
+  // Catch 'if(ptr.get())'
+  Finder->addMatcher(ifStmt(hasCondition(CallToGetAsBool)), Callback);
+
+  // Catch 'ptr.get() ? X : Y'
+  Finder->addMatcher(conditionalOperator(hasCondition(CallToGetAsBool)),
+ Callback);
 }
 
 void registerMatchersForGetEquals(MatchFinder *Finder,
@@ -72,11 +86,6 @@
  hasEitherOperand(callToGet(IsAKnownSmartptr))),
   Callback);
 
-  // Matches against if(ptr.get())
-  Finder->addMatcher(
-  ifStmt(hasCondition(ignoringImpCasts(callToGet(IsAKnownSmartptr,
-  Callback);
-
   // FIXME: Match and fix if (l.get() == r.get()).
 }
 
Index: clang-tools-extra/trunk/test/clang-tidy/readability-redundant-smartptr-get.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/readability-redundant-smartptr-get.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/readability-redundant-smartptr-get.cpp
@@ -9,13 +9,15 @@
   T& operator*() const;
   T* operator->() const;
   T* get() const;
+  explicit operator bool() const noexcept;
 };
 
 template 
 struct shared_ptr {
   T& operator*() const;
   T* operator->() const;
   T* get() const;
+  explicit operator bool() const noexcept;
 };
 
 }  // namespace std
@@ -28,6 +30,7 @@
   Bar* operator->();
   Bar& operator*();
   Bar* get();
+  explicit operator bool() const;
 };
 struct int_ptr {
   int* get();
@@ -110,6 +113,23 @@
   // CHECK-MESSAGES: uu.get() == nullptr;
   // CHECK-FIXES: bool bb = uu == nullptr;
 
+  if (up->get());
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant get() call
+  // CHECK-MESSAGES: if (up->get());
+  // CHECK-FIXES: if (*up);
+  if ((uu.get()));
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: redundant get() call
+  // CHECK-MESSAGES: if ((uu.get()));
+  // CHECK-FIXES: if ((uu));
+  bb = !ss->get();
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: redundant get() call
+  // CHECK-MESSAGES: bb = !ss->get();
+  // CHECK-FIXES: bb = !*ss;
+  bb = u.get() ? true : false;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: redundant get() call
+  // CHECK-MESSAGES: bb = u.get() ? true : false;
+  // CHECK-FIXES: bb = u ? true : false;
+
   bb = nullptr != ss->get();
   // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: redundant get() call
   // CHECK-MESSAGES: nullptr != ss->get();
@@ -146,10 +166,6 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: redundant get() call
   // CHECK-MESSAGES: if (NULL == x.get());
   // CHECK-FIXES: if (NULL == x);
-  if (x.get());
-  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant get() call
-  // CHECK-MESSAGES: if (x.get());
-  // CHECK-FIXES: if (x);
 }
 
 void Negative() {
@@ -175,4 +191,6 @@
 
   int_ptr ip;
   bool bb = ip.get() == nullptr;
+  bb = !ip.get();
+  bb = ip.get() ? true : false;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D41998: [clang-tidy] Expand readability-redundant-smartptr-get to understand implicit converions to bool in more contexts.

2018-01-15 Thread Samuel Benzaquen via Phabricator via cfe-commits
sbenza updated this revision to Diff 129880.
sbenza marked an inline comment as done.
sbenza added a comment.

minor fix


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41998

Files:
  clang-tidy/readability/RedundantSmartptrGetCheck.cpp
  test/clang-tidy/readability-redundant-smartptr-get.cpp

Index: test/clang-tidy/readability-redundant-smartptr-get.cpp
===
--- test/clang-tidy/readability-redundant-smartptr-get.cpp
+++ test/clang-tidy/readability-redundant-smartptr-get.cpp
@@ -9,13 +9,15 @@
   T& operator*() const;
   T* operator->() const;
   T* get() const;
+  explicit operator bool() const noexcept;
 };
 
 template 
 struct shared_ptr {
   T& operator*() const;
   T* operator->() const;
   T* get() const;
+  explicit operator bool() const noexcept;
 };
 
 }  // namespace std
@@ -28,6 +30,7 @@
   Bar* operator->();
   Bar& operator*();
   Bar* get();
+  explicit operator bool() const;
 };
 struct int_ptr {
   int* get();
@@ -110,6 +113,23 @@
   // CHECK-MESSAGES: uu.get() == nullptr;
   // CHECK-FIXES: bool bb = uu == nullptr;
 
+  if (up->get());
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant get() call
+  // CHECK-MESSAGES: if (up->get());
+  // CHECK-FIXES: if (*up);
+  if ((uu.get()));
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: redundant get() call
+  // CHECK-MESSAGES: if ((uu.get()));
+  // CHECK-FIXES: if ((uu));
+  bb = !ss->get();
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: redundant get() call
+  // CHECK-MESSAGES: bb = !ss->get();
+  // CHECK-FIXES: bb = !*ss;
+  bb = u.get() ? true : false;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: redundant get() call
+  // CHECK-MESSAGES: bb = u.get() ? true : false;
+  // CHECK-FIXES: bb = u ? true : false;
+
   bb = nullptr != ss->get();
   // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: redundant get() call
   // CHECK-MESSAGES: nullptr != ss->get();
@@ -146,10 +166,6 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: redundant get() call
   // CHECK-MESSAGES: if (NULL == x.get());
   // CHECK-FIXES: if (NULL == x);
-  if (x.get());
-  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant get() call
-  // CHECK-MESSAGES: if (x.get());
-  // CHECK-FIXES: if (x);
 }
 
 void Negative() {
@@ -175,4 +191,6 @@
 
   int_ptr ip;
   bool bb = ip.get() == nullptr;
+  bb = !ip.get();
+  bb = ip.get() ? true : false;
 }
Index: clang-tidy/readability/RedundantSmartptrGetCheck.cpp
===
--- clang-tidy/readability/RedundantSmartptrGetCheck.cpp
+++ clang-tidy/readability/RedundantSmartptrGetCheck.cpp
@@ -51,6 +51,20 @@
   unaryOperator(hasOperatorName("*"),
 hasUnaryOperand(callToGet(QuacksLikeASmartptr))),
   Callback);
+
+  // Catch '!ptr.get()'
+  const auto CallToGetAsBool = ignoringParenImpCasts(callToGet(recordDecl(
+  QuacksLikeASmartptr, has(cxxConversionDecl(returns(booleanType()));
+  Finder->addMatcher(
+  unaryOperator(hasOperatorName("!"), hasUnaryOperand(CallToGetAsBool)),
+  Callback);
+
+  // Catch 'if(ptr.get())'
+  Finder->addMatcher(ifStmt(hasCondition(CallToGetAsBool)), Callback);
+
+  // Catch 'ptr.get() ? X : Y'
+  Finder->addMatcher(conditionalOperator(hasCondition(CallToGetAsBool)),
+ Callback);
 }
 
 void registerMatchersForGetEquals(MatchFinder *Finder,
@@ -72,11 +86,6 @@
  hasEitherOperand(callToGet(IsAKnownSmartptr))),
   Callback);
 
-  // Matches against if(ptr.get())
-  Finder->addMatcher(
-  ifStmt(hasCondition(ignoringImpCasts(callToGet(IsAKnownSmartptr,
-  Callback);
-
   // FIXME: Match and fix if (l.get() == r.get()).
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r322497 - [clang-tidy] Expand readability-redundant-smartptr-get to understand implicit converions to bool in more contexts.

2018-01-15 Thread Samuel Benzaquen via cfe-commits
Author: sbenza
Date: Mon Jan 15 10:03:20 2018
New Revision: 322497

URL: http://llvm.org/viewvc/llvm-project?rev=322497&view=rev
Log:
[clang-tidy] Expand readability-redundant-smartptr-get to understand implicit 
converions to bool in more contexts.

Summary: Expand readability-redundant-smartptr-get to understand implicit 
converions to bool in more contexts.

Reviewers: hokein

Subscribers: klimek, xazax.hun, cfe-commits

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

Modified:
clang-tools-extra/trunk/clang-tidy/readability/RedundantSmartptrGetCheck.cpp

clang-tools-extra/trunk/test/clang-tidy/readability-redundant-smartptr-get.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/readability/RedundantSmartptrGetCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/RedundantSmartptrGetCheck.cpp?rev=322497&r1=322496&r2=322497&view=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/readability/RedundantSmartptrGetCheck.cpp 
(original)
+++ 
clang-tools-extra/trunk/clang-tidy/readability/RedundantSmartptrGetCheck.cpp 
Mon Jan 15 10:03:20 2018
@@ -51,6 +51,20 @@ void registerMatchersForGetArrowStart(Ma
   unaryOperator(hasOperatorName("*"),
 hasUnaryOperand(callToGet(QuacksLikeASmartptr))),
   Callback);
+
+  // Catch '!ptr.get()'
+  const auto CallToGetAsBool = ignoringParenImpCasts(callToGet(recordDecl(
+  QuacksLikeASmartptr, has(cxxConversionDecl(returns(booleanType()));
+  Finder->addMatcher(
+  unaryOperator(hasOperatorName("!"), hasUnaryOperand(CallToGetAsBool)),
+  Callback);
+
+  // Catch 'if(ptr.get())'
+  Finder->addMatcher(ifStmt(hasCondition(CallToGetAsBool)), Callback);
+
+  // Catch 'ptr.get() ? X : Y'
+  Finder->addMatcher(conditionalOperator(hasCondition(CallToGetAsBool)),
+ Callback);
 }
 
 void registerMatchersForGetEquals(MatchFinder *Finder,
@@ -72,11 +86,6 @@ void registerMatchersForGetEquals(MatchF
  hasEitherOperand(callToGet(IsAKnownSmartptr))),
   Callback);
 
-  // Matches against if(ptr.get())
-  Finder->addMatcher(
-  ifStmt(hasCondition(ignoringImpCasts(callToGet(IsAKnownSmartptr,
-  Callback);
-
   // FIXME: Match and fix if (l.get() == r.get()).
 }
 

Modified: 
clang-tools-extra/trunk/test/clang-tidy/readability-redundant-smartptr-get.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-redundant-smartptr-get.cpp?rev=322497&r1=322496&r2=322497&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/readability-redundant-smartptr-get.cpp 
(original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/readability-redundant-smartptr-get.cpp 
Mon Jan 15 10:03:20 2018
@@ -9,6 +9,7 @@ struct unique_ptr {
   T& operator*() const;
   T* operator->() const;
   T* get() const;
+  explicit operator bool() const noexcept;
 };
 
 template 
@@ -16,6 +17,7 @@ struct shared_ptr {
   T& operator*() const;
   T* operator->() const;
   T* get() const;
+  explicit operator bool() const noexcept;
 };
 
 }  // namespace std
@@ -28,6 +30,7 @@ struct BarPtr {
   Bar* operator->();
   Bar& operator*();
   Bar* get();
+  explicit operator bool() const;
 };
 struct int_ptr {
   int* get();
@@ -110,6 +113,23 @@ void Positive() {
   // CHECK-MESSAGES: uu.get() == nullptr;
   // CHECK-FIXES: bool bb = uu == nullptr;
 
+  if (up->get());
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant get() call
+  // CHECK-MESSAGES: if (up->get());
+  // CHECK-FIXES: if (*up);
+  if ((uu.get()));
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: redundant get() call
+  // CHECK-MESSAGES: if ((uu.get()));
+  // CHECK-FIXES: if ((uu));
+  bb = !ss->get();
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: redundant get() call
+  // CHECK-MESSAGES: bb = !ss->get();
+  // CHECK-FIXES: bb = !*ss;
+  bb = u.get() ? true : false;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: redundant get() call
+  // CHECK-MESSAGES: bb = u.get() ? true : false;
+  // CHECK-FIXES: bb = u ? true : false;
+
   bb = nullptr != ss->get();
   // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: redundant get() call
   // CHECK-MESSAGES: nullptr != ss->get();
@@ -146,10 +166,6 @@ void Positive() {
   // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: redundant get() call
   // CHECK-MESSAGES: if (NULL == x.get());
   // CHECK-FIXES: if (NULL == x);
-  if (x.get());
-  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant get() call
-  // CHECK-MESSAGES: if (x.get());
-  // CHECK-FIXES: if (x);
 }
 
 void Negative() {
@@ -175,4 +191,6 @@ void Negative() {
 
   int_ptr ip;
   bool bb = ip.get() == nullptr;
+  bb = !ip.get();
+  bb = ip.get() ? true : false;
 }


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


[PATCH] D40023: [RISCV] Implement ABI lowering

2018-01-15 Thread Alex Bradbury via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL322494: [RISCV] Implement RISCV ABI lowering (authored by 
asb, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D40023?vs=129683&id=129878#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D40023

Files:
  cfe/trunk/lib/CodeGen/TargetInfo.cpp
  cfe/trunk/test/CodeGen/riscv32-abi.c
  cfe/trunk/test/CodeGen/riscv64-abi.c
  cfe/trunk/test/Driver/riscv32-toolchain.c
  cfe/trunk/test/Driver/riscv64-toolchain.c

Index: cfe/trunk/test/CodeGen/riscv64-abi.c
===
--- cfe/trunk/test/CodeGen/riscv64-abi.c
+++ cfe/trunk/test/CodeGen/riscv64-abi.c
@@ -0,0 +1,425 @@
+// RUN: %clang_cc1 -triple riscv64 -emit-llvm %s -o - | FileCheck %s
+
+#include 
+#include 
+
+// CHECK-LABEL: define void @f_void()
+void f_void(void) {}
+
+// Scalar arguments and return values smaller than the word size are extended
+// according to the sign of their type, up to 32 bits
+
+// CHECK-LABEL: define zeroext i1 @f_scalar_0(i1 zeroext %x)
+_Bool f_scalar_0(_Bool x) { return x; }
+
+// CHECK-LABEL: define signext i8 @f_scalar_1(i8 signext %x)
+int8_t f_scalar_1(int8_t x) { return x; }
+
+// CHECK-LABEL: define zeroext i8 @f_scalar_2(i8 zeroext %x)
+uint8_t f_scalar_2(uint8_t x) { return x; }
+
+// CHECK-LABEL: define signext i32 @f_scalar_3(i32 signext %x)
+uint32_t f_scalar_3(int32_t x) { return x; }
+
+// CHECK-LABEL: define i64 @f_scalar_4(i64 %x)
+int64_t f_scalar_4(int64_t x) { return x; }
+
+// CHECK-LABEL: define float @f_fp_scalar_1(float %x)
+float f_fp_scalar_1(float x) { return x; }
+
+// CHECK-LABEL: define double @f_fp_scalar_2(double %x)
+double f_fp_scalar_2(double x) { return x; }
+
+// CHECK-LABEL: define fp128 @f_fp_scalar_3(fp128 %x)
+long double f_fp_scalar_3(long double x) { return x; }
+
+// Empty structs or unions are ignored.
+
+struct empty_s {};
+
+// CHECK-LABEL: define void @f_agg_empty_struct()
+struct empty_s f_agg_empty_struct(struct empty_s x) {
+  return x;
+}
+
+union empty_u {};
+
+// CHECK-LABEL: define void @f_agg_empty_union()
+union empty_u f_agg_empty_union(union empty_u x) {
+  return x;
+}
+
+// Aggregates <= 2*xlen may be passed in registers, so will be coerced to
+// integer arguments. The rules for return are the same.
+
+struct tiny {
+  uint16_t a, b, c, d;
+};
+
+// CHECK-LABEL: define void @f_agg_tiny(i64 %x.coerce)
+void f_agg_tiny(struct tiny x) {
+  x.a += x.b;
+  x.c += x.d;
+}
+
+// CHECK-LABEL: define i64 @f_agg_tiny_ret()
+struct tiny f_agg_tiny_ret() {
+  return (struct tiny){1, 2, 3, 4};
+}
+
+typedef uint16_t v4i16 __attribute__((vector_size(8)));
+typedef int64_t v1i64 __attribute__((vector_size(8)));
+
+// CHECK-LABEL: define void @f_vec_tiny_v4i16(i64 %x.coerce)
+void f_vec_tiny_v4i16(v4i16 x) {
+  x[0] = x[1];
+  x[2] = x[3];
+}
+
+// CHECK-LABEL: define i64 @f_vec_tiny_v4i16_ret()
+v4i16 f_vec_tiny_v4i16_ret() {
+  return (v4i16){1, 2, 3, 4};
+}
+
+// CHECK-LABEL: define void @f_vec_tiny_v1i64(i64 %x.coerce)
+void f_vec_tiny_v1i64(v1i64 x) {
+  x[0] = 114;
+}
+
+// CHECK-LABEL: define i64 @f_vec_tiny_v1i64_ret()
+v1i64 f_vec_tiny_v1i64_ret() {
+  return (v1i64){1};
+}
+
+struct small {
+  int64_t a, *b;
+};
+
+// CHECK-LABEL: define void @f_agg_small([2 x i64] %x.coerce)
+void f_agg_small(struct small x) {
+  x.a += *x.b;
+  x.b = &x.a;
+}
+
+// CHECK-LABEL: define [2 x i64] @f_agg_small_ret()
+struct small f_agg_small_ret() {
+  return (struct small){1, 0};
+}
+
+typedef uint16_t v8i16 __attribute__((vector_size(16)));
+typedef __int128_t v1i128 __attribute__((vector_size(16)));
+
+// CHECK-LABEL: define void @f_vec_small_v8i16(i128 %x.coerce)
+void f_vec_small_v8i16(v8i16 x) {
+  x[0] = x[7];
+}
+
+// CHECK-LABEL: define i128 @f_vec_small_v8i16_ret()
+v8i16 f_vec_small_v8i16_ret() {
+  return (v8i16){1, 2, 3, 4, 5, 6, 7, 8};
+}
+
+// CHECK-LABEL: define void @f_vec_small_v1i128(i128 %x.coerce)
+void f_vec_small_v1i128(v1i128 x) {
+  x[0] = 114;
+}
+
+// CHECK-LABEL: define i128 @f_vec_small_v1i128_ret()
+v1i128 f_vec_small_v1i128_ret() {
+  return (v1i128){1};
+}
+
+// Aggregates of 2*xlen size and 2*xlen alignment should be coerced to a
+// single 2*xlen-sized argument, to ensure that alignment can be maintained if
+// passed on the stack.
+
+struct small_aligned {
+  __int128_t a;
+};
+
+// CHECK-LABEL: define void @f_agg_small_aligned(i128 %x.coerce)
+void f_agg_small_aligned(struct small_aligned x) {
+  x.a += x.a;
+}
+
+// CHECK-LABEL: define i128 @f_agg_small_aligned_ret(i128 %x.coerce)
+struct small_aligned f_agg_small_aligned_ret(struct small_aligned x) {
+  return (struct small_aligned){10};
+}
+
+// Aggregates greater > 2*xlen will be passed and returned indirectly
+struct large {
+  int64_t a, b, c, d;
+};
+
+// CHECK-LABEL: define void @f_agg_large(%struct.large* %x)
+void f_agg_large(struct large x) {
+  x.a = x.b + x.c + x.d;
+}
+
+// The address w

[libcxx] r322493 - partition_point gets the P0202 treatment

2018-01-15 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Mon Jan 15 09:53:34 2018
New Revision: 322493

URL: http://llvm.org/viewvc/llvm-project?rev=322493&view=rev
Log:
partition_point gets the P0202 treatment

Modified:
libcxx/trunk/include/algorithm

libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.partitions/partition_point.pass.cpp
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.all_of/all_of.pass.cpp
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.any_of/any_of.pass.cpp

Modified: libcxx/trunk/include/algorithm
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/algorithm?rev=322493&r1=322492&r2=322493&view=diff
==
--- libcxx/trunk/include/algorithm (original)
+++ libcxx/trunk/include/algorithm Mon Jan 15 09:53:34 2018
@@ -321,7 +321,7 @@ template 
-ForwardIterator
+ForwardIterator  // constexpr in C++20
 partition_point(ForwardIterator first, ForwardIterator last, Predicate 
pred);
 
 template 
@@ -3328,7 +3328,7 @@ partition_copy(_InputIterator __first, _
 // partition_point
 
 template
-_ForwardIterator
+_LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
 partition_point(_ForwardIterator __first, _ForwardIterator __last, _Predicate 
__pred)
 {
 typedef typename iterator_traits<_ForwardIterator>::difference_type 
difference_type;

Modified: 
libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.partitions/partition_point.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.partitions/partition_point.pass.cpp?rev=322493&r1=322492&r2=322493&view=diff
==
--- 
libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.partitions/partition_point.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.partitions/partition_point.pass.cpp
 Mon Jan 15 09:53:34 2018
@@ -10,19 +10,32 @@
 // 
 
 // template
-// ForwardIterator
+// constpexr ForwardIterator   // constexpr after C++17
 // partition_point(ForwardIterator first, ForwardIterator last, Predicate 
pred);
 
 #include 
 #include 
 
+#include "test_macros.h"
 #include "test_iterators.h"
 
 struct is_odd
 {
-bool operator()(const int& i) const {return i & 1;}
+TEST_CONSTEXPR bool operator()(const int& i) const {return i & 1;}
 };
 
+
+#if TEST_STD_VER > 17
+TEST_CONSTEXPR int test_constexpr() {
+int ia[] = {1, 3, 5, 2, 4, 6};
+int ib[] = {1, 2, 3, 4, 5, 6};
+return(std::partition_point(std::begin(ia), std::end(ia), is_odd()) == 
ia+3)
+   && (std::partition_point(std::begin(ib), std::end(ib), is_odd()) == 
ib+1)
+   ;
+}
+#endif
+
+
 int main()
 {
 {
@@ -73,4 +86,8 @@ int main()
 forward_iterator(std::begin(ia)),
 is_odd()) == forward_iterator(ia));
 }
+
+#if TEST_STD_VER > 17
+static_assert(test_constexpr());
+#endif
 }

Modified: 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.all_of/all_of.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.all_of/all_of.pass.cpp?rev=322493&r1=322492&r2=322493&view=diff
==
--- 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.all_of/all_of.pass.cpp 
(original)
+++ 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.all_of/all_of.pass.cpp 
Mon Jan 15 09:53:34 2018
@@ -10,7 +10,7 @@
 // 
 
 // template 
-//   bool
+// constpexr bool   // constexpr after C++17
 //   all_of(InputIterator first, InputIterator last, Predicate pred);
 
 #include 

Modified: 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.any_of/any_of.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.any_of/any_of.pass.cpp?rev=322493&r1=322492&r2=322493&view=diff
==
--- 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.any_of/any_of.pass.cpp 
(original)
+++ 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.any_of/any_of.pass.cpp 
Mon Jan 15 09:53:34 2018
@@ -10,7 +10,7 @@
 // 
 
 // template 
-//   bool
+// constpexr bool   // constexpr after C++17
 //   any_of(InputIterator first, InputIterator last, Predicate pred);
 
 #include 


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


[PATCH] D42077: Ensure code complete with !LoadExternal sees all local decls.

2018-01-15 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: ilya-biryukov.
Herald added a subscriber: cfe-commits.

noload_lookups() was too lazy: in addition to avoiding external decls, it
avoided populating the lazy lookup structure for internal decls.
This is the right behavior for the existing callsite in ASTDumper, but I think
it's not a very useful default, so we populate it by default.

While here:

- remove an unused test file accidentally added in r322371.
- remove lookups_begin()/lookups_end() in favor of lookups().begin(), which is 
more common and more efficient.


Repository:
  rC Clang

https://reviews.llvm.org/D42077

Files:
  include/clang/AST/DeclBase.h
  include/clang/AST/DeclLookups.h
  lib/AST/ASTDumper.cpp
  lib/AST/DeclBase.cpp
  test/Index/complete-pch-skip.cpp
  test/Index/complete-pch-skip.h

Index: test/Index/complete-pch-skip.h
===
--- test/Index/complete-pch-skip.h
+++ /dev/null
@@ -1,3 +0,0 @@
-namespace ns {
-int foo;
-}
Index: test/Index/complete-pch-skip.cpp
===
--- test/Index/complete-pch-skip.cpp
+++ test/Index/complete-pch-skip.cpp
@@ -16,3 +16,10 @@
 // SKIP-PCH: {TypedText bar}
 // SKIP-PCH-NOT: foo
 
+// Verify that with *no* preamble (no -include flag) we still get local results.
+// SkipPreamble used to break this, by making lookup *too* lazy.
+// RUN: env CINDEXTEST_COMPLETION_SKIP_PREAMBLE=1 c-index-test -code-completion-at=%s:5:26 %s | FileCheck -check-prefix=NO-PCH %s
+// NO-PCH-NOT: foo
+// NO-PCH: {TypedText bar}
+// NO-PCH-NOT: foo
+
Index: lib/AST/DeclBase.cpp
===
--- lib/AST/DeclBase.cpp
+++ lib/AST/DeclBase.cpp
@@ -1588,17 +1588,7 @@
   if (PrimaryContext != this)
 return PrimaryContext->noload_lookup(Name);
 
-  // If we have any lazy lexical declarations not in our lookup map, add them
-  // now. Don't import any external declarations, not even if we know we have
-  // some missing from the external visible lookups.
-  if (HasLazyLocalLexicalLookups) {
-SmallVector Contexts;
-collectAllContexts(Contexts);
-for (unsigned I = 0, N = Contexts.size(); I != N; ++I)
-  buildLookupImpl(Contexts[I], hasExternalVisibleStorage());
-HasLazyLocalLexicalLookups = false;
-  }
-
+  loadLazyLocalLexicalLookups();
   StoredDeclsMap *Map = LookupPtr;
   if (!Map)
 return lookup_result();
@@ -1608,6 +1598,19 @@
  : lookup_result();
 }
 
+// If we have any lazy lexical declarations not in our lookup map, add them
+// now. Don't import any external declarations, not even if we know we have
+// some missing from the external visible lookups.
+void DeclContext::loadLazyLocalLexicalLookups() {
+  if (HasLazyLocalLexicalLookups) {
+SmallVector Contexts;
+collectAllContexts(Contexts);
+for (unsigned I = 0, N = Contexts.size(); I != N; ++I)
+  buildLookupImpl(Contexts[I], hasExternalVisibleStorage());
+HasLazyLocalLexicalLookups = false;
+  }
+}
+
 void DeclContext::localUncachedLookup(DeclarationName Name,
   SmallVectorImpl &Results) {
   Results.clear();
Index: lib/AST/ASTDumper.cpp
===
--- lib/AST/ASTDumper.cpp
+++ lib/AST/ASTDumper.cpp
@@ -809,11 +809,10 @@
 
 bool HasUndeserializedLookups = Primary->hasExternalVisibleStorage();
 
-for (auto I = Deserialize ? Primary->lookups_begin()
-  : Primary->noload_lookups_begin(),
-  E = Deserialize ? Primary->lookups_end()
-  : Primary->noload_lookups_end();
- I != E; ++I) {
+auto Range = Deserialize
+ ? Primary->lookups()
+ : Primary->noload_lookups(/*PreserveInternalState=*/true);
+for (auto I = Range.begin(), E = Range.end(); I != E; ++I) {
   DeclarationName Name = I.getLookupName();
   DeclContextLookupResult R = *I;
 
Index: include/clang/AST/DeclLookups.h
===
--- include/clang/AST/DeclLookups.h
+++ include/clang/AST/DeclLookups.h
@@ -86,16 +86,13 @@
   return lookups_range(all_lookups_iterator(), all_lookups_iterator());
 }
 
-inline DeclContext::all_lookups_iterator DeclContext::lookups_begin() const {
-  return lookups().begin();
-}
-
-inline DeclContext::all_lookups_iterator DeclContext::lookups_end() const {
-  return lookups().end();
-}
-
-inline DeclContext::lookups_range DeclContext::noload_lookups() const {
+// Like lookups(), but avoids loading external declarations.
+// If PreserveInternalState, avoids building lookup data structures too.
+inline DeclContext::lookups_range
+DeclContext::noload_lookups(bool PreserveInternalState) const {
   DeclContext *Primary = const_cast(this)->getPrimaryContext();
+  if (!PreserveInternalState)
+Primary->loadLazyLocalLex

[libcxx] r322492 - More constexpr algorithms from P0202. any_of/all_of/none_of.

2018-01-15 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Mon Jan 15 09:20:36 2018
New Revision: 322492

URL: http://llvm.org/viewvc/llvm-project?rev=322492&view=rev
Log:
More constexpr algorithms from P0202. any_of/all_of/none_of.

Modified:
libcxx/trunk/include/algorithm
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.all_of/all_of.pass.cpp
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.any_of/any_of.pass.cpp

libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.none_of/none_of.pass.cpp

Modified: libcxx/trunk/include/algorithm
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/algorithm?rev=322492&r1=322491&r2=322492&view=diff
==
--- libcxx/trunk/include/algorithm (original)
+++ libcxx/trunk/include/algorithm Mon Jan 15 09:20:36 2018
@@ -20,15 +20,15 @@ namespace std
 {
 
 template 
-bool
+constexpr bool // constexpr in C++20
 all_of(InputIterator first, InputIterator last, Predicate pred);
 
 template 
-bool
+constexpr bool // constexpr in C++20
 any_of(InputIterator first, InputIterator last, Predicate pred);
 
 template 
-bool
+constexpr bool // constexpr in C++20
 none_of(InputIterator first, InputIterator last, Predicate pred);
 
 template 
@@ -919,7 +919,7 @@ inline _LIBCPP_INLINE_VISIBILITY int __p
 // all_of
 
 template 
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
 bool
 all_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
 {
@@ -932,7 +932,7 @@ all_of(_InputIterator __first, _InputIte
 // any_of
 
 template 
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
 bool
 any_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
 {
@@ -945,7 +945,7 @@ any_of(_InputIterator __first, _InputIte
 // none_of
 
 template 
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
 bool
 none_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
 {

Modified: 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.all_of/all_of.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.all_of/all_of.pass.cpp?rev=322492&r1=322491&r2=322492&view=diff
==
--- 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.all_of/all_of.pass.cpp 
(original)
+++ 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.all_of/all_of.pass.cpp 
Mon Jan 15 09:20:36 2018
@@ -16,16 +16,27 @@
 #include 
 #include 
 
+#include "test_macros.h"
 #include "test_iterators.h"
 
 struct test1
 {
-bool operator()(const int& i) const
+TEST_CONSTEXPR bool operator()(const int& i) const
 {
 return i % 2 == 0;
 }
 };
 
+#if TEST_STD_VER > 17
+TEST_CONSTEXPR int test_constexpr() {
+int ia[] = {2, 4, 6, 8};
+int ib[] = {2, 4, 5, 8};
+return  std::all_of(std::begin(ia), std::end(ia), test1())
+&& !std::all_of(std::begin(ib), std::end(ib), test1())
+;
+}
+#endif
+
 int main()
 {
 {
@@ -44,4 +55,8 @@ int main()
 assert(std::all_of(input_iterator(ia),
input_iterator(ia), test1()) == true);
 }
+
+#if TEST_STD_VER > 17
+static_assert(test_constexpr());
+#endif
 }

Modified: 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.any_of/any_of.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.any_of/any_of.pass.cpp?rev=322492&r1=322491&r2=322492&view=diff
==
--- 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.any_of/any_of.pass.cpp 
(original)
+++ 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.any_of/any_of.pass.cpp 
Mon Jan 15 09:20:36 2018
@@ -16,16 +16,27 @@
 #include 
 #include 
 
+#include "test_macros.h"
 #include "test_iterators.h"
 
 struct test1
 {
-bool operator()(const int& i) const
+TEST_CONSTEXPR bool operator()(const int& i) const
 {
 return i % 2 == 0;
 }
 };
 
+#if TEST_STD_VER > 17
+TEST_CONSTEXPR int test_constexpr() {
+int ia[] = {2, 4, 6, 8};
+int ib[] = {1, 3, 5, 7};
+return  std::any_of(std::begin(ia), std::end(ia), test1())
+&& !std::any_of(std::begin(ib), std::end(ib), test1())
+;
+}
+#endif
+
 int main()
 {
 {
@@ -52,4 +63,8 @@ int main()
 assert(std::any_of(input_iterator(ia),
input_iterator(ia), test1()) == false);
 }
+
+#if TEST_STD_VER > 17
+static_assert(test_constexpr());
+#endif
 }

Modified: 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.none_of/none_of.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.none_of/none_of.pass.cpp?rev=322492&r1=322491&r2=322492&view=diff
===

[PATCH] D41655: [clang-tidy] New check bugprone-unused-return-value

2018-01-15 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added inline comments.



Comment at: clang-tidy/bugprone/UnusedReturnValueCheck.cpp:47
+"^::std::launder$|"
+"^::std::unique_ptr<.*>::release$|"
+"^::std::.*::allocate$|"

khuttun wrote:
> JonasToth wrote:
> > Is the following type a problem for you check?
> > 
> > `std::unique_ptr>` should not be matchable with regex but 
> > I don't know if that would have an impact on the functionality.
> `std::unique_ptr>` is also matched. I added a test case for 
> it.
Alright. I think i had a error in my thinking. Because there are followup 
letters in the regex there are no problems. I thought it would end on the first 
`>`, but thats no the case! Thank you for clarification :)


https://reviews.llvm.org/D41655



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


[PATCH] D32845: [Analyzer] Iterator Checker - Part 4: Mismatched iterator checker for function parameters

2018-01-15 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 129871.
baloghadamsoftware added a comment.

Rebased to current Part 3. Comment added.


https://reviews.llvm.org/D32845

Files:
  include/clang/StaticAnalyzer/Checkers/Checkers.td
  lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
  test/Analysis/Inputs/system-header-simulator-cxx.h
  test/Analysis/mismatched-iterator.cpp

Index: test/Analysis/mismatched-iterator.cpp
===
--- /dev/null
+++ test/Analysis/mismatched-iterator.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,cplusplus,alpha.cplusplus.MismatchedIterator -analyzer-eagerly-assume -analyzer-config aggressive-relational-comparison-simplification=true -analyzer-config c++-container-inlining=false %s -verify
+// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,cplusplus,alpha.cplusplus.MismatchedIterator -analyzer-eagerly-assume -analyzer-config aggressive-relational-comparison-simplification=true -analyzer-config c++-container-inlining=true -DINLINE=1 %s -verify
+
+#include "Inputs/system-header-simulator-cxx.h"
+
+void good_find(std::vector &v, int n) {
+  std::find(v.cbegin(), v.cend(), n); // no-warning
+}
+
+void good_find_first_of(std::vector &v1, std::vector &v2) {
+  std::find_first_of(v1.cbegin(), v1.cend(), v2.cbegin(), v2.cend()); // no-warning
+}
+
+void good_copy(std::vector &v1, std::vector &v2, int n) {
+  std::copy(v1.cbegin(), v1.cend(), v2.begin()); // no-warning
+}
+
+void bad_find(std::vector &v1, std::vector &v2, int n) {
+  std::find(v1.cbegin(), v2.cend(), n); // expected-warning{{Iterator access mismatched}}
+}
+
+void bad_find_first_of(std::vector &v1, std::vector &v2) {
+  std::find_first_of(v1.cbegin(), v2.cend(), v2.cbegin(), v2.cend()); // expected-warning{{Iterator access mismatched}}
+  std::find_first_of(v1.cbegin(), v1.cend(), v2.cbegin(), v1.cend()); // expected-warning{{Iterator access mismatched}}
+}
Index: test/Analysis/Inputs/system-header-simulator-cxx.h
===
--- test/Analysis/Inputs/system-header-simulator-cxx.h
+++ test/Analysis/Inputs/system-header-simulator-cxx.h
@@ -642,6 +642,12 @@
   template 
   InputIterator find(InputIterator first, InputIterator last, const T &val);
 
+  template 
+  ForwardIterator1 find_first_of(ForwardIterator1 first1,
+ ForwardIterator1 last1,
+ ForwardIterator2 first2,
+ ForwardIterator2 last2);
+
   template 
   OutputIterator copy(InputIterator first, InputIterator last,
   OutputIterator result);
Index: lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
+++ lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
@@ -199,6 +199,7 @@
  eval::Assume> {
 
   std::unique_ptr OutOfRangeBugType;
+  std::unique_ptr MismatchedBugType;
   std::unique_ptr InvalidatedBugType;
 
   void handleComparison(CheckerContext &C, const SVal &RetVal, const SVal &LVal,
@@ -222,16 +223,22 @@
   void verifyRandomIncrOrDecr(CheckerContext &C, OverloadedOperatorKind Op,
   const SVal &RetVal, const SVal &LHS,
   const SVal &RHS) const;
+  void verifyMatch(CheckerContext &C, const SVal &Iter1,
+   const SVal &Iter2) const;
+
   void reportOutOfRangeBug(const StringRef &Message, const SVal &Val,
CheckerContext &C, ExplodedNode *ErrNode) const;
+  void reportMismatchedBug(const StringRef &Message, const SVal &Val,
+   CheckerContext &C, ExplodedNode *ErrNode) const;
   void reportInvalidatedBug(const StringRef &Message, const SVal &Val,
 CheckerContext &C, ExplodedNode *ErrNode) const;
 
 public:
   IteratorChecker();
 
   enum CheckKind {
 CK_IteratorRangeChecker,
+CK_MismatchedIteratorChecker,
 CK_InvalidatedIteratorChecker,
 CK_NumCheckKinds
   };
@@ -321,6 +328,9 @@
   OutOfRangeBugType.reset(
   new BugType(this, "Iterator out of range", "Misuse of STL APIs"));
   OutOfRangeBugType->setSuppressOnSink(true);
+  MismatchedBugType.reset(
+  new BugType(this, "Iterator(s) mismatched", "Misuse of STL APIs"));
+  MismatchedBugType->setSuppressOnSink(true);
   InvalidatedBugType.reset(
   new BugType(this, "Iterator invalidated", "Misuse of STL APIs"));
   InvalidatedBugType->setSuppressOnSink(true);
@@ -369,6 +379,65 @@
 verifyDereference(C, Call.getArgSVal(0));
   }
 }
+  } else if (!isa(&Call)) {
+// The main purpose of iterators is to abstract away from different
+// containers and provide a (maybe limited) uniform access to them.
+// This implies that any correctly written template function that
+// works on multiple containers using iterato

[PATCH] D32747: [Analyzer] Iterator Checker - Part 3: Invalidation check, first for (copy) assignments

2018-01-15 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 129870.
baloghadamsoftware added a comment.

Rebased to current Part 2.


https://reviews.llvm.org/D32747

Files:
  include/clang/StaticAnalyzer/Checkers/Checkers.td
  lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
  test/Analysis/Inputs/system-header-simulator-cxx.h
  test/Analysis/diagnostics/explicit-suppression.cpp
  test/Analysis/invalidated-iterator.cpp

Index: test/Analysis/invalidated-iterator.cpp
===
--- /dev/null
+++ test/Analysis/invalidated-iterator.cpp
@@ -0,0 +1,32 @@
+// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,cplusplus,alpha.cplusplus.InvalidatedIterator -analyzer-eagerly-assume -analyzer-config aggressive-relational-comparison-simplification=true -analyzer-config c++-container-inlining=false %s -verify
+// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,cplusplus,alpha.cplusplus.InvalidatedIterator -analyzer-eagerly-assume -analyzer-config aggressive-relational-comparison-simplification=true -analyzer-config c++-container-inlining=true -DINLINE=1 %s -verify
+
+#include "Inputs/system-header-simulator-cxx.h"
+
+void bad_copy_assign_operator_list1(std::list &L1,
+const std::list &L2) {
+  auto i0 = L1.cbegin();
+  L1 = L2;
+  *i0; // expected-warning{{Invalidated iterator accessed}}
+}
+
+void bad_copy_assign_operator_vector1(std::vector &V1,
+  const std::vector &V2) {
+  auto i0 = V1.cbegin();
+  V1 = V2;
+  *i0; // expected-warning{{Invalidated iterator accessed}}
+}
+
+void bad_copy_assign_operator_deque1(std::deque &D1,
+ const std::deque &D2) {
+  auto i0 = D1.cbegin();
+  D1 = D2;
+  *i0; // expected-warning{{Invalidated iterator accessed}}
+}
+
+void bad_copy_assign_operator_forward_list1(std::forward_list &FL1,
+const std::forward_list &FL2) {
+  auto i0 = FL1.cbegin();
+  FL1 = FL2;
+  *i0; // expected-warning{{Invalidated iterator accessed}}
+}
Index: test/Analysis/diagnostics/explicit-suppression.cpp
===
--- test/Analysis/diagnostics/explicit-suppression.cpp
+++ test/Analysis/diagnostics/explicit-suppression.cpp
@@ -19,6 +19,6 @@
 void testCopyNull(C *I, C *E) {
   std::copy(I, E, (C *)0);
 #ifndef SUPPRESSED
-  // expected-warning@../Inputs/system-header-simulator-cxx.h:514 {{Called C++ object pointer is null}}
+  // expected-warning@../Inputs/system-header-simulator-cxx.h:554 {{Called C++ object pointer is null}}
 #endif
 }
Index: test/Analysis/Inputs/system-header-simulator-cxx.h
===
--- test/Analysis/Inputs/system-header-simulator-cxx.h
+++ test/Analysis/Inputs/system-header-simulator-cxx.h
@@ -252,6 +252,15 @@
   return size_t(_finish - _start);
 }
 
+vector& operator=(const vector &other);
+vector& operator=(vector &&other);
+vector& operator=(std::initializer_list ilist);
+
+void assign(size_type count, const T &value);
+template 
+void assign(InputIterator first, InputIterator last);
+void assign(std::initializer_list ilist);
+
 void clear();
 
 void push_back(const T &value);
@@ -301,8 +310,21 @@
 list& operator=(list &&other);
 list& operator=(std::initializer_list ilist);
 
+void assign(size_type count, const T &value);
+template 
+void assign(InputIterator first, InputIterator last);
+void assign(std::initializer_list ilist);
+
 void clear();
 
+void push_back(const T &value);
+void push_back(T &&value);
+void pop_back();
+
+void push_front(const T &value);
+void push_front(T &&value);
+void pop_front();
+
 iterator begin() { return iterator(_start); }
 const_iterator begin() const { return const_iterator(_start); }
 const_iterator cbegin() const { return const_iterator(_start); }
@@ -338,6 +360,15 @@
   return size_t(_finish - _start);
 }
 
+deque& operator=(const deque &other);
+deque& operator=(deque &&other);
+deque& operator=(std::initializer_list ilist);
+
+void assign(size_type count, const T &value);
+template 
+void assign(InputIterator first, InputIterator last);
+void assign(std::initializer_list ilist);
+
 void clear();
 
 void push_back(const T &value);
@@ -351,11 +382,11 @@
 T &operator[](size_t n) {
   return _start[n];
 }
-
+
 const T &operator[](size_t n) const {
   return _start[n];
 }
-
+
 iterator begin() { return iterator(_start); }
 const_iterator begin() const { return const_iterator(_start); }
 const_iterator cbegin() const { return const_iterator(_start); }
@@ -367,7 +398,7 @@
 T& back() { return *(end() - 1); }
 const T& back() const { return *(end() - 1); }
   };
-  
+
   template
   class forward_list {
 struct __item 

[PATCH] D42074: [clangd] Collect enum constants in SymbolCollector

2018-01-15 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clangd/index/SymbolCollector.cpp:75
+  // Skip nameless declarations.
+  if (ND->getDeclName().isEmpty())
+return true;

What are those declarations exactly?



Comment at: unittests/clangd/SymbolCollectorTests.cpp:174
+enum class Color2 {
+  Yellow
+};

I'd say we should drop `enum` constants inside stongly-typed enums (i.e. `enum 
class`).
They can't be found inside namespace by code completion, therefore being 
similar to static method in that regard. (And we don't include static methods 
now, right?)


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42074



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


[PATCH] D42071: [Sema] Add a callback in VisibleDeclConsumer allowing client to know which DeclContext is going to visit.

2018-01-15 Thread Benjamin Kramer via Phabricator via cfe-commits
bkramer added a comment.

We should have a unit test for this, otherwise it's dead code.




Comment at: include/clang/Sema/Lookup.h:791
+  /// \param Ctx the context which Sema begins to visit.
+  virtual void BeginVisitContext(DeclContext *Ctx) {};
 };

ilya-biryukov wrote:
> Maybe rename it to `VisitedContext` ? Seems more in-line with `FoundDecl`.
> `BeginVisitContext` also suggest there should be `EndVisitContext`
Semicolon is not needed here.


Repository:
  rC Clang

https://reviews.llvm.org/D42071



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


[PATCH] D42073: [clangd] Query all visible scopes based on all visible using-namespace declarationsand containing namespace for global qualified code completion.

2018-01-15 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

Discussed this offline.
If we move most to collect visited `DeclContext`s to 
`CodeCompletionDeclConsumer` (from `CodeComplete.cpp`) and provide a list of 
`DeclContext`s to `CodeCompletionConsumer`, we will be able to get rid of 
running lookup manually in clangd.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42073



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


[PATCH] D41815: [clang-tidy] implement check for goto

2018-01-15 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth updated this revision to Diff 129868.
JonasToth added a comment.

- doc clarified that check is c++ only
- add missing tests for `do` and `range-for`, not all combinations done, but 
every loop construct is used as outer and inner loop


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41815

Files:
  clang-tidy/cppcoreguidelines/AvoidGotoCheck.cpp
  clang-tidy/cppcoreguidelines/AvoidGotoCheck.h
  clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/cppcoreguidelines-avoid-goto.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/cppcoreguidelines-avoid-goto.cpp

Index: test/clang-tidy/cppcoreguidelines-avoid-goto.cpp
===
--- /dev/null
+++ test/clang-tidy/cppcoreguidelines-avoid-goto.cpp
@@ -0,0 +1,139 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-avoid-goto %t
+
+void noop() {}
+
+int main() {
+  noop();
+  goto jump_to_me;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: avoid using 'goto' for flow control
+  // CHECK-MESSAGES: [[@LINE+3]]:1: note: label defined here
+  noop();
+
+jump_to_me:;
+
+jump_backwards:;
+  noop();
+  goto jump_backwards;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: avoid using 'goto' for flow control
+  // CHECK-MESSAGES: [[@LINE-4]]:1: note: label defined here
+
+  goto jump_in_line;
+  ;
+jump_in_line:;
+  // CHECK-MESSAGES: [[@LINE-3]]:3: warning: avoid using 'goto' for flow control
+  // CHECK-MESSAGES: [[@LINE-2]]:1: note: label defined here
+
+  // Test the GNU extension https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html
+some_label:;
+  void *dynamic_label = &&some_label;
+
+  // FIXME: `IndirectGotoStmt` is not detected.
+  goto *dynamic_label;
+}
+
+void forward_jump_out_nested_loop() {
+  int array[] = {1, 2, 3, 4, 5};
+  for (int i = 0; i < 10; ++i) {
+noop();
+for (int j = 0; j < 10; ++j) {
+  noop();
+  if (i + j > 10)
+goto early_exit1;
+}
+noop();
+  }
+
+  for (int i = 0; i < 10; ++i) {
+noop();
+while (true) {
+  noop();
+  if (i > 5)
+goto early_exit1;
+}
+noop();
+  }
+
+  for (auto value : array) {
+noop();
+for (auto number : array) {
+  noop();
+  if (number == 5)
+goto early_exit1;
+}
+  }
+
+  do {
+noop();
+do {
+  noop();
+  goto early_exit1;
+} while (true);
+  } while (true);
+
+  do {
+for (auto number : array) {
+  noop();
+  if (number == 2)
+goto early_exit1;
+}
+  } while (true);
+
+  // Jumping further results in error, because the variable declaration would
+  // be skipped.
+early_exit1:;
+
+  int i = 0;
+  while (true) {
+noop();
+while (true) {
+  noop();
+  if (i > 5)
+goto early_exit2;
+  i++;
+}
+noop();
+  }
+
+  while (true) {
+noop();
+for (int j = 0; j < 10; ++j) {
+  noop();
+  if (j > 5)
+goto early_exit2;
+}
+noop();
+  }
+
+  while (true) {
+noop();
+for (auto number : array) {
+  if (number == 1)
+goto early_exit2;
+  noop();
+}
+  }
+
+  while (true) {
+noop();
+do {
+  noop();
+  goto early_exit2;
+} while (true);
+  }
+early_exit2:;
+}
+
+void jump_out_backwards() {
+
+before_the_loop:
+  noop();
+
+  for (int i = 0; i < 10; ++i) {
+for (int j = 0; j < 10; ++j) {
+  if (i * j > 80)
+goto before_the_loop;
+  // CHECK-MESSAGES: [[@LINE-1]]:9: warning: avoid using 'goto' for flow control
+  // CHECK-MESSAGES: [[@LINE-8]]:1: note: label defined here
+}
+  }
+}
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -52,6 +52,7 @@
cert-msc30-c (redirects to cert-msc50-cpp) 
cert-msc50-cpp
cert-oop11-cpp (redirects to performance-move-constructor-init) 
+   cppcoreguidelines-avoid-goto
cppcoreguidelines-c-copy-assignment-signature (redirects to misc-unconventional-assign-operator) 
cppcoreguidelines-interfaces-global-init
cppcoreguidelines-no-malloc
Index: docs/clang-tidy/checks/cppcoreguidelines-avoid-goto.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/cppcoreguidelines-avoid-goto.rst
@@ -0,0 +1,50 @@
+.. title:: clang-tidy - cppcoreguidelines-avoid-goto
+
+cppcoreguidelines-avoid-goto
+
+
+The usage of ``goto`` for control flow is error prone and should be replaced
+with looping constructs. Only forward jumps in nested loops are accepted.
+
+This check implements `ES.76 `_ 
+from the CppCoreGuidelines and 
+`6.3.1 from High Integrity C++ 

[PATCH] D42071: [Sema] Add a callback in VisibleDeclConsumer allowing client to know which DeclContext is going to visit.

2018-01-15 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: include/clang/Sema/Lookup.h:791
+  /// \param Ctx the context which Sema begins to visit.
+  virtual void BeginVisitContext(DeclContext *Ctx) {};
 };

Maybe rename it to `VisitedContext` ? Seems more in-line with `FoundDecl`.
`BeginVisitContext` also suggest there should be `EndVisitContext`


Repository:
  rC Clang

https://reviews.llvm.org/D42071



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


[PATCH] D41815: [clang-tidy] implement check for goto

2018-01-15 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth updated this revision to Diff 129865.
JonasToth marked an inline comment as done.
JonasToth added a comment.

- [Fix] bug with language mode


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41815

Files:
  clang-tidy/cppcoreguidelines/AvoidGotoCheck.cpp
  clang-tidy/cppcoreguidelines/AvoidGotoCheck.h
  clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/cppcoreguidelines-avoid-goto.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/cppcoreguidelines-avoid-goto.cpp

Index: test/clang-tidy/cppcoreguidelines-avoid-goto.cpp
===
--- /dev/null
+++ test/clang-tidy/cppcoreguidelines-avoid-goto.cpp
@@ -0,0 +1,94 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-avoid-goto %t
+
+void noop() {}
+
+int main() {
+  noop();
+  goto jump_to_me;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: avoid using 'goto' for flow control
+  // CHECK-MESSAGES: [[@LINE+3]]:1: note: label defined here
+  noop();
+
+jump_to_me:;
+
+jump_backwards:;
+  noop();
+  goto jump_backwards;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: avoid using 'goto' for flow control
+  // CHECK-MESSAGES: [[@LINE-4]]:1: note: label defined here
+
+  goto jump_in_line; ; jump_in_line:;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: avoid using 'goto' for flow control
+  // CHECK-MESSAGES: [[@LINE-2]]:24: note: label defined here
+
+  // Test the GNU extension https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html
+some_label:;
+  void *dynamic_label = &&some_label;
+
+  // FIXME: Not detected
+  goto *dynamic_label;
+}
+
+void forward_jump_out_nested_loop() {
+  for (int i = 0; i < 10; ++i) {
+noop();
+for (int j = 0; j < 10; ++j) {
+  noop();
+  if (i + j > 10)
+goto early_exit1;
+}
+noop();
+  }
+
+  for (int i = 0; i < 10; ++i) {
+noop();
+while (true) {
+  noop();
+  if (i > 5)
+goto early_exit1;
+}
+noop();
+  }
+  // Jumping further results in error, because the variable declaration would
+  // be skipped.
+early_exit1:;
+
+  int i = 0;
+  while (true) {
+noop();
+while (true) {
+  noop();
+  if (i > 5)
+goto early_exit2;
+  i++;
+}
+noop();
+  }
+
+  while (true) {
+noop();
+for (int j = 0; j < 10; ++j) {
+  noop();
+  if (j > 5)
+goto early_exit2;
+}
+noop();
+  }
+
+early_exit2:;
+}
+
+void jump_out_backwards() {
+
+before_the_loop:
+  noop();
+
+  for (int i = 0; i < 10; ++i) {
+for (int j = 0; j < 10; ++j) {
+  if (i * j > 80)
+goto before_the_loop;
+  // CHECK-MESSAGES: [[@LINE-1]]:9: warning: avoid using 'goto' for flow control
+  // CHECK-MESSAGES: [[@LINE-8]]:1: note: label defined here
+}
+  }
+}
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -52,6 +52,7 @@
cert-msc30-c (redirects to cert-msc50-cpp) 
cert-msc50-cpp
cert-oop11-cpp (redirects to performance-move-constructor-init) 
+   cppcoreguidelines-avoid-goto
cppcoreguidelines-c-copy-assignment-signature (redirects to misc-unconventional-assign-operator) 
cppcoreguidelines-interfaces-global-init
cppcoreguidelines-no-malloc
Index: docs/clang-tidy/checks/cppcoreguidelines-avoid-goto.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/cppcoreguidelines-avoid-goto.rst
@@ -0,0 +1,50 @@
+.. title:: clang-tidy - cppcoreguidelines-avoid-goto
+
+cppcoreguidelines-avoid-goto
+
+
+The usage of ``goto`` for control flow is error prone and should be replaced
+with looping constructs. Only forward jumps in nested loops are accepted.
+
+This check implements `ES.76 `_ 
+from the CppCoreGuidelines and 
+`6.3.1 from High Integrity C++ `_.
+
+For more information on why to avoid programming 
+with ``goto`` you can read the famous paper `A Case against the GO TO Statement. `_.
+
+The check diagnoses ``goto`` for backward jumps in every language mode. These
+should be replaced with `C/C++` looping constructs.
+
+.. code-block:: c++
+
+  // Bad, handwritten for loop.
+  int i = 0;
+  // Jump label for the loop
+  loop_start:
+  do_some_operation();
+
+  if (i < 100) {
+++i;
+goto loop_start;
+  }
+
+  // Better
+  for(int i = 0; i < 100; ++i)
+do_some_operation();
+
+Modern C++ needs ``goto`` only to jump out of nested loops.
+
+.. code-block:: c++
+
+  for(int i = 0; i < 100; ++i) {
+for(int j = 0

[PATCH] D42074: [clangd] Collect enum constants in SymbolCollector

2018-01-15 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: ilya-biryukov.
Herald added a subscriber: klimek.

- ignore nameless symbols
- include enum constant declarataion


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42074

Files:
  clangd/index/SymbolCollector.cpp
  unittests/clangd/SymbolCollectorTests.cpp


Index: unittests/clangd/SymbolCollectorTests.cpp
===
--- unittests/clangd/SymbolCollectorTests.cpp
+++ unittests/clangd/SymbolCollectorTests.cpp
@@ -161,6 +161,37 @@
QName("foo::baz")}));
 }
 
+TEST_F(SymbolCollectorTest, IncludeEnums) {
+  CollectorOpts.IndexMainFiles = false;
+  const std::string Header = R"(
+enum {
+  Red
+};
+enum Color {
+  Green
+};
+enum class Color2 {
+  Yellow
+};
+  )";
+  runSymbolCollector(Header, /*Main=*/"");
+  EXPECT_THAT(Symbols, UnorderedElementsAre(QName("Red"), QName("Color"),
+QName("Color2"), QName("Green"),
+QName("Color2::Yellow")));
+}
+
+TEST_F(SymbolCollectorTest, IgnoreNamelessSymbols) {
+  CollectorOpts.IndexMainFiles = false;
+  const std::string Header = R"(
+struct {
+  int a;
+} Foo;
+  )";
+  runSymbolCollector(Header, /*Main=*/"");
+  EXPECT_THAT(Symbols,
+  UnorderedElementsAre(QName("Foo")));
+}
+
 TEST_F(SymbolCollectorTest, IgnoreSymbolsInMainFile) {
   CollectorOpts.IndexMainFiles = false;
   const std::string Header = R"(
Index: clangd/index/SymbolCollector.cpp
===
--- clangd/index/SymbolCollector.cpp
+++ clangd/index/SymbolCollector.cpp
@@ -71,6 +71,10 @@
   using namespace clang::ast_matchers;
   if (ND->isImplicit())
 return true;
+  // Skip nameless declarations.
+  if (ND->getDeclName().isEmpty())
+return true;
+
   // FIXME: figure out a way to handle internal linkage symbols (e.g. static
   // variables, function) defined in the .cc files. Also we skip the symbols
   // in anonymous namespace as the qualifier names of these symbols are like
@@ -84,10 +88,13 @@
 
   // We only want symbols in namespaces or translation unit scopes (e.g. no
   // class members).
-  if (match(decl(allOf(
-Opts.IndexMainFiles ? decl()
-: decl(unless(isExpansionInMainFile())),
-hasDeclContext(anyOf(namespaceDecl(), 
translationUnitDecl(),
+  auto InTopLevelScope =
+  hasDeclContext(anyOf(namespaceDecl(), translationUnitDecl()));
+  if (match(decl(allOf(Opts.IndexMainFiles
+   ? decl()
+   : decl(unless(isExpansionInMainFile())),
+   anyOf(InTopLevelScope,
+ hasDeclContext(enumDecl(InTopLevelScope),
 *ND, *ASTCtx)
   .empty())
 return true;


Index: unittests/clangd/SymbolCollectorTests.cpp
===
--- unittests/clangd/SymbolCollectorTests.cpp
+++ unittests/clangd/SymbolCollectorTests.cpp
@@ -161,6 +161,37 @@
QName("foo::baz")}));
 }
 
+TEST_F(SymbolCollectorTest, IncludeEnums) {
+  CollectorOpts.IndexMainFiles = false;
+  const std::string Header = R"(
+enum {
+  Red
+};
+enum Color {
+  Green
+};
+enum class Color2 {
+  Yellow
+};
+  )";
+  runSymbolCollector(Header, /*Main=*/"");
+  EXPECT_THAT(Symbols, UnorderedElementsAre(QName("Red"), QName("Color"),
+QName("Color2"), QName("Green"),
+QName("Color2::Yellow")));
+}
+
+TEST_F(SymbolCollectorTest, IgnoreNamelessSymbols) {
+  CollectorOpts.IndexMainFiles = false;
+  const std::string Header = R"(
+struct {
+  int a;
+} Foo;
+  )";
+  runSymbolCollector(Header, /*Main=*/"");
+  EXPECT_THAT(Symbols,
+  UnorderedElementsAre(QName("Foo")));
+}
+
 TEST_F(SymbolCollectorTest, IgnoreSymbolsInMainFile) {
   CollectorOpts.IndexMainFiles = false;
   const std::string Header = R"(
Index: clangd/index/SymbolCollector.cpp
===
--- clangd/index/SymbolCollector.cpp
+++ clangd/index/SymbolCollector.cpp
@@ -71,6 +71,10 @@
   using namespace clang::ast_matchers;
   if (ND->isImplicit())
 return true;
+  // Skip nameless declarations.
+  if (ND->getDeclName().isEmpty())
+return true;
+
   // FIXME: figure out a way to handle internal linkage symbols (e.g. static
   // variables, function) defined in the .cc files. Also we skip the symbols
   // in anonymous namespace as the qualifier names of these symbols are like
@@ -84,10 +88,13 @@
 
   // We only want symbols in namespaces or translation unit scopes (e.g. no
   // class members).
-  if (match(decl(allOf(
-Opts.IndexMainFiles ? decl()
-

[PATCH] D41815: [clang-tidy] implement check for goto

2018-01-15 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth updated this revision to Diff 129863.
JonasToth marked 4 inline comments as done.
JonasToth added a comment.

- address review comments


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41815

Files:
  clang-tidy/cppcoreguidelines/AvoidGotoCheck.cpp
  clang-tidy/cppcoreguidelines/AvoidGotoCheck.h
  clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/cppcoreguidelines-avoid-goto.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/cppcoreguidelines-avoid-goto.cpp

Index: test/clang-tidy/cppcoreguidelines-avoid-goto.cpp
===
--- /dev/null
+++ test/clang-tidy/cppcoreguidelines-avoid-goto.cpp
@@ -0,0 +1,94 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-avoid-goto %t
+
+void noop() {}
+
+int main() {
+  noop();
+  goto jump_to_me;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: avoid using 'goto' for flow control
+  // CHECK-MESSAGES: [[@LINE+3]]:1: note: label defined here
+  noop();
+
+jump_to_me:;
+
+jump_backwards:;
+  noop();
+  goto jump_backwards;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: avoid using 'goto' for flow control
+  // CHECK-MESSAGES: [[@LINE-4]]:1: note: label defined here
+
+  goto jump_in_line; ; jump_in_line:;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: avoid using 'goto' for flow control
+  // CHECK-MESSAGES: [[@LINE-2]]:24: note: label defined here
+
+  // Test the GNU extension https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html
+some_label:;
+  void *dynamic_label = &&some_label;
+
+  // FIXME: Not detected
+  goto *dynamic_label;
+}
+
+void forward_jump_out_nested_loop() {
+  for (int i = 0; i < 10; ++i) {
+noop();
+for (int j = 0; j < 10; ++j) {
+  noop();
+  if (i + j > 10)
+goto early_exit1;
+}
+noop();
+  }
+
+  for (int i = 0; i < 10; ++i) {
+noop();
+while (true) {
+  noop();
+  if (i > 5)
+goto early_exit1;
+}
+noop();
+  }
+  // Jumping further results in error, because the variable declaration would
+  // be skipped.
+early_exit1:;
+
+  int i = 0;
+  while (true) {
+noop();
+while (true) {
+  noop();
+  if (i > 5)
+goto early_exit2;
+  i++;
+}
+noop();
+  }
+
+  while (true) {
+noop();
+for (int j = 0; j < 10; ++j) {
+  noop();
+  if (j > 5)
+goto early_exit2;
+}
+noop();
+  }
+
+early_exit2:;
+}
+
+void jump_out_backwards() {
+
+before_the_loop:
+  noop();
+
+  for (int i = 0; i < 10; ++i) {
+for (int j = 0; j < 10; ++j) {
+  if (i * j > 80)
+goto before_the_loop;
+  // CHECK-MESSAGES: [[@LINE-1]]:9: warning: avoid using 'goto' for flow control
+  // CHECK-MESSAGES: [[@LINE-8]]:1: note: label defined here
+}
+  }
+}
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -52,6 +52,7 @@
cert-msc30-c (redirects to cert-msc50-cpp) 
cert-msc50-cpp
cert-oop11-cpp (redirects to performance-move-constructor-init) 
+   cppcoreguidelines-avoid-goto
cppcoreguidelines-c-copy-assignment-signature (redirects to misc-unconventional-assign-operator) 
cppcoreguidelines-interfaces-global-init
cppcoreguidelines-no-malloc
Index: docs/clang-tidy/checks/cppcoreguidelines-avoid-goto.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/cppcoreguidelines-avoid-goto.rst
@@ -0,0 +1,50 @@
+.. title:: clang-tidy - cppcoreguidelines-avoid-goto
+
+cppcoreguidelines-avoid-goto
+
+
+The usage of ``goto`` for control flow is error prone and should be replaced
+with looping constructs. Only forward jumps in nested loops are accepted.
+
+This check implements `ES.76 `_ 
+from the CppCoreGuidelines and 
+`6.3.1 from High Integrity C++ `_.
+
+For more information on why to avoid programming 
+with ``goto`` you can read the famous paper `A Case against the GO TO Statement. `_.
+
+The check diagnoses ``goto`` for backward jumps in every language mode. These
+should be replaced with `C/C++` looping constructs.
+
+.. code-block:: c++
+
+  // Bad, handwritten for loop.
+  int i = 0;
+  // Jump label for the loop
+  loop_start:
+  do_some_operation();
+
+  if (i < 100) {
+++i;
+goto loop_start;
+  }
+
+  // Better
+  for(int i = 0; i < 100; ++i)
+do_some_operation();
+
+Modern C++ needs ``goto`` only to jump out of nested loops.
+
+.. code-block:: c++
+
+  for(int i = 0; i < 100; ++i) {
+for(int j = 0; j <

[PATCH] D41815: [clang-tidy] implement check for goto

2018-01-15 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added inline comments.



Comment at: clang-tidy/cppcoreguidelines/AvoidGotoCheck.cpp:43
+
+  // Backward jumps are diagnosed in all language modes. Forward jumps
+  // are sometimes required in C to free resources or do other clean-up

aaron.ballman wrote:
> I think that this check should be C++ only. C makes far more use of `goto`, 
> and backwards jumps are not always bad there (they don't have to consider 
> things like destructors or RAII like you do in C++).
> 
> Esp since this is a check for the C++ core guidelines and HICPP (both are C++ 
> standards). 
Ok. I merged the matchers too.



Comment at: docs/ReleaseNotes.rst:67-68
 
+- New `cppcoreguidelines-avoid-goto
+  
`_
 check
+

aaron.ballman wrote:
> I think you should also add the HICPP changes as well, given that this check 
> also covers that rule.
I think `Only forward jumps in nested loops are accepted.` covers it, but i 
reformulated it.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41815



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


[PATCH] D42073: [clangd] Query all visible scopes based on all visible using-namespace declarationsand containing namespace for global qualified code completion.

2018-01-15 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added reviewers: sammccall, ilya-biryukov.
Herald added a subscriber: klimek.

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42073

Files:
  clangd/CodeComplete.cpp
  unittests/clangd/CodeCompleteTests.cpp

Index: unittests/clangd/CodeCompleteTests.cpp
===
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -58,6 +58,7 @@
 using ::testing::Each;
 using ::testing::ElementsAre;
 using ::testing::Not;
+using ::testing::Field;
 using ::testing::UnorderedElementsAre;
 
 class IgnoreDiagnostics : public DiagnosticsConsumer {
@@ -481,6 +482,21 @@
   EXPECT_EQ(1, Results.activeParameter);
 }
 
+class IndexRequestCollector : public SymbolIndex {
+public:
+  bool
+  fuzzyFind(const Context &Ctx, const FuzzyFindRequest &Req,
+llvm::function_ref Callback) const override {
+Requests.push_back(Req);
+return false;
+  }
+
+  const std::vector allRequests() const { return Requests; }
+
+private:
+  mutable std::vector Requests;
+};
+
 std::unique_ptr simpleIndexFromSymbols(
 std::vector> Symbols) {
   SymbolSlab::Builder Slab;
@@ -660,6 +676,48 @@
 Doc("Doooc"), Detail("void";
 }
 
+TEST(CompletionTest, AllVisibleScopesChain) {
+  clangd::CodeCompleteOptions Opts;
+  IndexRequestCollector Requests;
+  Opts.Index = &Requests;
+
+  auto Results = completions(R"cpp(
+  namespace ns1 {}
+  namespace ns2 {} // ignore
+  namespace ns3 {}
+
+  namespace ns4 { using namespace ns3; }
+  using namespace ns1;
+  namespace ns5 { using namespace ns4; }
+  namespace ns5 { bar::^ }
+  )cpp",
+ Opts);
+
+  EXPECT_THAT(
+  Requests.allRequests(),
+  ElementsAre(Field(&FuzzyFindRequest::Scopes,
+UnorderedElementsAre("bar", "ns4::bar", "ns3::bar",
+ "ns5::bar", "ns1::bar";
+}
+
+TEST(CompletionTest, AllVisibleScopesNested) {
+  clangd::CodeCompleteOptions Opts;
+  IndexRequestCollector Requests;
+  Opts.Index = &Requests;
+
+  auto Results = completions(R"cpp(
+  namespace ns1 { namespace ns4 {}  }
+  namespace ns1 { namespace ns2 { namespace ns3 { bar::^ } } }
+  )cpp",
+ Opts);
+
+  EXPECT_THAT(
+  Requests.allRequests(),
+  ElementsAre(Field(&FuzzyFindRequest::Scopes,
+UnorderedElementsAre("bar", "ns1::bar", "ns1::ns2::bar",
+ "ns1::ns2::ns3::bar";
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clangd/CodeComplete.cpp
===
--- clangd/CodeComplete.cpp
+++ clangd/CodeComplete.cpp
@@ -23,6 +23,7 @@
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendActions.h"
 #include "clang/Sema/CodeCompleteConsumer.h"
+#include "clang/Sema/Lookup.h"
 #include "clang/Sema/Sema.h"
 #include "llvm/Support/Format.h"
 #include 
@@ -258,16 +259,34 @@
   }
 };
 
-/// \brief Information about the scope specifier in the qualified-id code
-/// completion (e.g. "ns::ab?").
-struct SpecifiedScope {
-  /// The scope specifier as written. For example, for completion "ns::ab?", the
-  /// written scope specifier is "ns".
-  std::string Written;
-  // If this scope specifier is recognized in Sema (e.g. as a namespace
-  // context), this will be set to the fully qualfied name of the corresponding
-  // context.
-  std::string Resolved;
+/// \brief Scopes being queried in indexes for the qualified-id code completion
+/// (e.g. "ns::ab?").
+struct QueryScopes {
+  /// All scopes being queried in indexes. Each scope should meet the
+  /// restrictions described in FuzzyFindRequest::Scopes.
+  ///
+  /// The scopes are constructed from the written scope specifier as well as all
+  /// namespace scopes which are visible to the qualified-id completion token.
+  std::vector Scopes;
+};
+
+class VisibleNamespaceFinder : public VisibleDeclConsumer {
+public:
+  void FoundDecl(NamedDecl *ND, NamedDecl *Hiding, DeclContext *Ctx,
+ bool InBaseClass) override {}
+
+  void BeginVisitContext(DeclContext *Ctx) override {
+// We only interest in namespace declarations.
+if (const auto *NN = dyn_cast(Ctx))
+  VisibleNamespaces.insert(NN->getQualifiedNameAsString());
+  }
+
+  const std::set &getVisibleNamespaces() const {
+return VisibleNamespaces;
+  }
+
+private:
+  std::set VisibleNamespaces;
 };
 
 /// \brief Information from sema about (parital) symbol names to be completed.
@@ -278,10 +297,11 @@
   std::string Filter;
 
   /// This is set if the completion is for qualified IDs, e.g. "abc::x^".
-  llvm::Optional SSInfo;
+  llvm::Optional QScopes;
 };
 
-SpecifiedScope extraCompletionScope(Sema &S, const CXXScopeSpec &SS);
+QueryScopes extraCompletionScope(
+Sem

[libcxx] r322489 - First part of P0202: Adding constexpr modifiers to functions in and . This commit is all the is_XXX algorithms.

2018-01-15 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Mon Jan 15 08:16:32 2018
New Revision: 322489

URL: http://llvm.org/viewvc/llvm-project?rev=322489&view=rev
Log:
First part of P0202: Adding constexpr modifiers to functions in  and 
. This commit is all the is_XXX algorithms.

Modified:
libcxx/trunk/include/algorithm

libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.partitions/is_partitioned.pass.cpp

libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.is_permutation/is_permutation.pass.cpp

libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.is_permutation/is_permutation_pred.pass.cpp

libcxx/trunk/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap.pass.cpp

libcxx/trunk/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap_comp.pass.cpp

libcxx/trunk/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap_until.pass.cpp

libcxx/trunk/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap_until_comp.pass.cpp

libcxx/trunk/test/std/algorithms/alg.sorting/alg.sort/is.sorted/is_sorted.pass.cpp

libcxx/trunk/test/std/algorithms/alg.sorting/alg.sort/is.sorted/is_sorted_comp.pass.cpp

libcxx/trunk/test/std/algorithms/alg.sorting/alg.sort/is.sorted/is_sorted_until.pass.cpp

libcxx/trunk/test/std/algorithms/alg.sorting/alg.sort/is.sorted/is_sorted_until_comp.pass.cpp
libcxx/trunk/www/cxx2a_status.html

Modified: libcxx/trunk/include/algorithm
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/algorithm?rev=322489&r1=322488&r2=322489&view=diff
==
--- libcxx/trunk/include/algorithm (original)
+++ libcxx/trunk/include/algorithm Mon Jan 15 08:16:32 2018
@@ -39,11 +39,11 @@ template
-InputIterator
+constexpr InputIterator   // constexpr in C++20
 find(InputIterator first, InputIterator last, const T& value);
 
 template 
-InputIterator
+constexpr InputIterator // constexpr in C++20
 find_if(InputIterator first, InputIterator last, Predicate pred);
 
 template
@@ -127,22 +127,22 @@ template 
-bool
+constexpr bool  // constexpr in C++20
 is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2);
 
 template
-bool
+constexpr bool  // constexpr in C++20
 is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2); // 
**C++14**
 
 template
-bool
+constexpr bool  // constexpr in C++20
 is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, BinaryPredicate pred);
 
 template
-bool
+constexpr bool  // constexpr in C++20
 is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2,
BinaryPredicate pred);  // **C++14**
@@ -302,7 +302,7 @@ template
-bool
+constexpr bool  // constexpr in C++20
 is_partitioned(InputIterator first, InputIterator last, Predicate pred);
 
 template 
@@ -325,7 +325,7 @@ template
-bool
+constexpr bool  // constexpr in C++20
 is_sorted(ForwardIterator first, ForwardIterator last);
 
 template 
@@ -513,19 +513,19 @@ template 
-bool
+constexpr bool   // constexpr in C++20
 is_heap(RandomAccessIterator first, RandomAccessiterator last);
 
 template 
-bool
+constexpr bool   // constexpr in C++20
 is_heap(RandomAccessIterator first, RandomAccessiterator last, Compare 
comp);
 
 template 
-RandomAccessIterator
+constexpr RandomAccessIterator   // constexpr in C++20
 is_heap_until(RandomAccessIterator first, RandomAccessiterator last);
 
 template 
-RandomAccessIterator
+constexpr RandomAccessIterator   // constexpr in C++20
 is_heap_until(RandomAccessIterator first, RandomAccessiterator last, 
Compare comp);
 
 template 
@@ -990,7 +990,7 @@ for_each_n(_InputIterator __first, _Size
 // find
 
 template 
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
 _InputIterator
 find(_InputIterator __first, _InputIterator __last, const _Tp& __value_)
 {
@@ -1003,7 +1003,7 @@ find(_InputIterator __first, _InputItera
 // find_if
 
 template 
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
 _InputIterator
 find_if(_InputIterator __first, _InputIterator __last, _Predicate __pred)
 {
@@ -1395,17 +1395,18 @@ equal(_InputIterator1 __first1, _InputIt
 // is_permutation
 
 template
-bool
+_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
 is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
_ForwardIterator2 __first2, _BinaryPredicate __pred)
 {
-// shorten sequences as much as possible by lopping of any equal parts
+//  shorten sequences as much as possible by lopping of any equal prefix
 for (; __fir

[PATCH] D42072: [Sema] Expose current scope in qualified-id code completion.

2018-01-15 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: ilya-biryukov.

Repository:
  rC Clang

https://reviews.llvm.org/D42072

Files:
  include/clang/Sema/CodeCompleteConsumer.h
  lib/Sema/SemaCodeComplete.cpp


Index: lib/Sema/SemaCodeComplete.cpp
===
--- lib/Sema/SemaCodeComplete.cpp
+++ lib/Sema/SemaCodeComplete.cpp
@@ -4618,7 +4618,7 @@
   // contexts/symbols that are not in the AST.
   if (SS.isInvalid()) {
 CodeCompletionContext CC(CodeCompletionContext::CCC_Name);
-CC.setCXXScopeSpecifier(SS);
+CC.setQualifiedCompletionContext({SS, S});
 HandleCodeCompleteResults(this, CodeCompleter, CC, nullptr, 0);
 return;
   }
@@ -4663,7 +4663,7 @@
   }
 
   auto CC = Results.getCompletionContext();
-  CC.setCXXScopeSpecifier(SS);
+  CC.setQualifiedCompletionContext({SS, S});
 
   HandleCodeCompleteResults(this, CodeCompleter, CC, Results.data(),
 Results.size());
Index: include/clang/Sema/CodeCompleteConsumer.h
===
--- include/clang/Sema/CodeCompleteConsumer.h
+++ include/clang/Sema/CodeCompleteConsumer.h
@@ -29,6 +29,7 @@
 namespace clang {
 
 class Decl;
+class Scope;
 
 /// \brief Default priority values for code-completion results based
 /// on their kind.
@@ -268,6 +269,14 @@
 CCC_Recovery
   };
 
+  struct QualifiedCompletionContext {
+/// \brief The scope specifier that comes before the completion token e.g.
+/// "a::b::"
+CXXScopeSpec ScopeSpecifier;
+/// \brief The closest scope where the qualified code completion occurs.
+Scope *ClosestScope;
+  };
+
 private:
   enum Kind Kind;
 
@@ -281,9 +290,9 @@
   /// \brief The identifiers for Objective-C selector parts.
   ArrayRef SelIdents;
 
-  /// \brief The scope specifier that comes before the completion token e.g.
-  /// "a::b::"
-  llvm::Optional ScopeSpecifier;
+  /// \brief The context for qualified-id completion, containing information
+  /// about the scope specifier.
+  llvm::Optional QualifiedCC;
 
 public:
   /// \brief Construct a new code-completion context of the given kind.
@@ -321,16 +330,17 @@
   /// context.
   bool wantConstructorResults() const;
 
-  /// \brief Sets the scope specifier that comes before the completion token.
-  /// This is expected to be set in code completions on qualfied specifiers
+  /// \brief Sets the qualified context.
+  /// This is expected to be set in code completions on qualified specifiers
   /// (e.g. "a::b::").
-  void setCXXScopeSpecifier(CXXScopeSpec SS) {
-this->ScopeSpecifier = std::move(SS);
+  void setQualifiedCompletionContext(QualifiedCompletionContext QCC) {
+this->QualifiedCC = std::move(QCC);
   }
 
-  llvm::Optional getCXXScopeSpecifier() {
-if (ScopeSpecifier)
-  return ScopeSpecifier.getPointer();
+  llvm::Optional
+  getQualifiedCompletionContext() const {
+if (QualifiedCC)
+  return QualifiedCC.getPointer();
 return llvm::None;
   }
 };


Index: lib/Sema/SemaCodeComplete.cpp
===
--- lib/Sema/SemaCodeComplete.cpp
+++ lib/Sema/SemaCodeComplete.cpp
@@ -4618,7 +4618,7 @@
   // contexts/symbols that are not in the AST.
   if (SS.isInvalid()) {
 CodeCompletionContext CC(CodeCompletionContext::CCC_Name);
-CC.setCXXScopeSpecifier(SS);
+CC.setQualifiedCompletionContext({SS, S});
 HandleCodeCompleteResults(this, CodeCompleter, CC, nullptr, 0);
 return;
   }
@@ -4663,7 +4663,7 @@
   }
 
   auto CC = Results.getCompletionContext();
-  CC.setCXXScopeSpecifier(SS);
+  CC.setQualifiedCompletionContext({SS, S});
 
   HandleCodeCompleteResults(this, CodeCompleter, CC, Results.data(),
 Results.size());
Index: include/clang/Sema/CodeCompleteConsumer.h
===
--- include/clang/Sema/CodeCompleteConsumer.h
+++ include/clang/Sema/CodeCompleteConsumer.h
@@ -29,6 +29,7 @@
 namespace clang {
 
 class Decl;
+class Scope;
 
 /// \brief Default priority values for code-completion results based
 /// on their kind.
@@ -268,6 +269,14 @@
 CCC_Recovery
   };
 
+  struct QualifiedCompletionContext {
+/// \brief The scope specifier that comes before the completion token e.g.
+/// "a::b::"
+CXXScopeSpec ScopeSpecifier;
+/// \brief The closest scope where the qualified code completion occurs.
+Scope *ClosestScope;
+  };
+
 private:
   enum Kind Kind;
 
@@ -281,9 +290,9 @@
   /// \brief The identifiers for Objective-C selector parts.
   ArrayRef SelIdents;
 
-  /// \brief The scope specifier that comes before the completion token e.g.
-  /// "a::b::"
-  llvm::Optional ScopeSpecifier;
+  /// \brief The context for qualified-id completion, containing information
+  /// about the scope specifier.
+  llvm::Optional QualifiedCC;
 
 public:
   /// \brief Construct a new code-completion context of the given kind.
@@ -

[PATCH] D42071: [Sema] Add a callback in VisibleDeclConsumer allowing client to know which DeclContext is going to visit.

2018-01-15 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: ilya-biryukov.

Repository:
  rC Clang

https://reviews.llvm.org/D42071

Files:
  include/clang/Sema/Lookup.h
  lib/Sema/SemaLookup.cpp


Index: lib/Sema/SemaLookup.cpp
===
--- lib/Sema/SemaLookup.cpp
+++ lib/Sema/SemaLookup.cpp
@@ -3507,6 +3507,8 @@
   if (Visited.visitedContext(Ctx->getPrimaryContext()))
 return;
 
+  Consumer.BeginVisitContext(Ctx);
+
   // Outside C++, lookup results for the TU live on identifiers.
   if (isa(Ctx) &&
   !Result.getSema().getLangOpts().CPlusPlus) {
Index: include/clang/Sema/Lookup.h
===
--- include/clang/Sema/Lookup.h
+++ include/clang/Sema/Lookup.h
@@ -784,6 +784,11 @@
   /// class of the context we searched.
   virtual void FoundDecl(NamedDecl *ND, NamedDecl *Hiding, DeclContext *Ctx,
  bool InBaseClass) = 0;
+
+  /// \brief Callback to inform the client that Sema begins to visit a context.
+  //
+  /// \param Ctx the context which Sema begins to visit.
+  virtual void BeginVisitContext(DeclContext *Ctx) {};
 };
 
 /// \brief A class for storing results from argument-dependent lookup.


Index: lib/Sema/SemaLookup.cpp
===
--- lib/Sema/SemaLookup.cpp
+++ lib/Sema/SemaLookup.cpp
@@ -3507,6 +3507,8 @@
   if (Visited.visitedContext(Ctx->getPrimaryContext()))
 return;
 
+  Consumer.BeginVisitContext(Ctx);
+
   // Outside C++, lookup results for the TU live on identifiers.
   if (isa(Ctx) &&
   !Result.getSema().getLangOpts().CPlusPlus) {
Index: include/clang/Sema/Lookup.h
===
--- include/clang/Sema/Lookup.h
+++ include/clang/Sema/Lookup.h
@@ -784,6 +784,11 @@
   /// class of the context we searched.
   virtual void FoundDecl(NamedDecl *ND, NamedDecl *Hiding, DeclContext *Ctx,
  bool InBaseClass) = 0;
+
+  /// \brief Callback to inform the client that Sema begins to visit a context.
+  //
+  /// \param Ctx the context which Sema begins to visit.
+  virtual void BeginVisitContext(DeclContext *Ctx) {};
 };
 
 /// \brief A class for storing results from argument-dependent lookup.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42059: [clangd] Improve const-correctness of Symbol->Detail. NFC

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

LTGM.




Comment at: clangd/index/SymbolYAML.cpp:84
+  return nullptr;
+return new (*static_cast(IO.getContext()))
+T(std::move(*Opt));

woo, I learnt new thing here. I'd expect a comment, using placement new with 
the custom allocator  :)



Comment at: clangd/index/SymbolYAML.cpp:88
+
+  llvm::Optional Opt;
+};

The template type should be `T`, I think.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42059



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


[PATCH] [scan-build] Mention --keep-cc in the HTML documentation

2018-01-15 Thread Paul Fertser via cfe-commits
---

Feel free to squash this into the keep-cc introduction commit if appropriate.

 www/analyzer/scan-build.html | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/www/analyzer/scan-build.html b/www/analyzer/scan-build.html
index b16f6bb..83efea9 100644
--- a/www/analyzer/scan-build.html
+++ b/www/analyzer/scan-build.html
@@ -248,7 +248,7 @@ you will probably need to run configure script 
through
 
 
 $ scan-build ./configure
-$ scan-build make
+$ scan-build --keep-cc make
 
 
 The reason configure also needs to be run through
-- 
2.7.0

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


Re: [PATCH] [scan-build] Add an option to skip overriding CC and CXX make vars

2018-01-15 Thread Jonathan Roelofs via cfe-commits

LGTM. Would you like me to commit it for you?


Jon


On 1/14/18 9:22 AM, Paul Fertser wrote:

Autoconf and some other systems tend to add essential compilation
options to CC (e.g. -std=gnu99). When running such an auto-generated
makefile, scan-build does not need to change CC and CXX as they are
already set to use ccc-analyzer by a configure script.

Implement a new option --keep-cc as was proposed in this discussion:
http://lists.llvm.org/pipermail/cfe-dev/2013-September/031832.html
---
  tools/scan-build/bin/scan-build | 24 
  1 file changed, 20 insertions(+), 4 deletions(-)

diff --git a/tools/scan-build/bin/scan-build b/tools/scan-build/bin/scan-build
index cbf3bf3..49018eb 100755
--- a/tools/scan-build/bin/scan-build
+++ b/tools/scan-build/bin/scan-build
@@ -51,6 +51,7 @@ my %Options = (
OutputDir => undef,# Parent directory to store HTML files.
HtmlTitle => basename($CurrentDir)." - scan-build results",
IgnoreErrors => 0, # Ignore build errors.
+  KeepCC => 0,   # Do not override CC and CXX make variables
ViewResults => 0,  # View results when the build terminates.
ExitStatusFoundBugs => 0,  # Exit status reflects whether bugs were found
ShowDescription => 0,  # Display the description of the defect in the 
list
@@ -1062,6 +1063,7 @@ sub RunXcodebuild {
  sub RunBuildCommand {
my $Args = shift;
my $IgnoreErrors = shift;
+  my $KeepCC = shift;
my $Cmd = $Args->[0];
my $CCAnalyzer = shift;
my $CXXAnalyzer = shift;
@@ -1099,8 +1101,10 @@ sub RunBuildCommand {
  unshift @$Args, $CXXAnalyzer;
}
elsif ($Cmd eq "make" or $Cmd eq "gmake" or $Cmd eq "mingw32-make") {
-AddIfNotPresent($Args, "CC=$CCAnalyzer");
-AddIfNotPresent($Args, "CXX=$CXXAnalyzer");
+if (!$KeepCC) {
+  AddIfNotPresent($Args, "CC=$CCAnalyzer");
+  AddIfNotPresent($Args, "CXX=$CXXAnalyzer");
+}
  if ($IgnoreErrors) {
AddIfNotPresent($Args,"-k");
AddIfNotPresent($Args,"-i");
@@ -1158,6 +1162,12 @@ OPTIONS:
 currently supports make and xcodebuild. This is a convenience option; one
 can specify this behavior directly using build options.
  
+ --keep-cc

+
+   Do not override CC and CXX make variables. Useful when running make in
+   autoconf-based (and similar) projects where configure can add extra flags
+   to those variables.
+
   --html-title [title]
   --html-title=[title]
  
@@ -1532,6 +1542,12 @@ sub ProcessArgs {

next;
  }
  
+if ($arg eq "--keep-cc") {

+  shift @$Args;
+  $Options{KeepCC} = 1;
+  next;
+}
+
  if ($arg =~ /^--use-cc(=(.+))?$/) {
shift @$Args;
my $cc;
@@ -1838,8 +1854,8 @@ my %EnvVars = (
  );
  
  # Run the build.

-my $ExitStatus = RunBuildCommand(\@ARGV, $Options{IgnoreErrors}, $Cmd, $CmdCXX,
-\%EnvVars);
+my $ExitStatus = RunBuildCommand(\@ARGV, $Options{IgnoreErrors}, 
$Options{KeepCC},
+   $Cmd, $CmdCXX, \%EnvVars);
  
  if (defined $Options{OutputFormat}) {

if ($Options{OutputFormat} =~ /plist/) {


--
Jon Roelofs
jonat...@codesourcery.com
CodeSourcery / Mentor Embedded / Siemens

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


Re: [PATCH] [analyzer] Fix -x language argument for C preprocessed sources

2018-01-15 Thread Jonathan Roelofs via cfe-commits

LGTM. Would you like me to commit it for you?


Jon


On 1/14/18 3:50 AM, Paul Fertser wrote:

clang's -x option doesn't accept c-cpp-output as a language (even though
463eb6ab was merged, the driver still doesn't handle that).

This bug prevents testing C language projects when ccache is used.

Fixes #25851.

Investigation and patch by Dave Rigby.
---
  tools/scan-build/libexec/ccc-analyzer | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/scan-build/libexec/ccc-analyzer 
b/tools/scan-build/libexec/ccc-analyzer
index b0ec7e7..73cd2ff 100755
--- a/tools/scan-build/libexec/ccc-analyzer
+++ b/tools/scan-build/libexec/ccc-analyzer
@@ -419,7 +419,7 @@ my %LangMap = (
'cc'  => 'c++',
'C'   => 'c++',
'ii'  => 'c++-cpp-output',
-  'i'   => $IsCXX ? 'c++-cpp-output' : 'c-cpp-output',
+  'i'   => $IsCXX ? 'c++-cpp-output' : 'cpp-output',
'm'   => 'objective-c',
'mi'  => 'objective-c-cpp-output',
'mm'  => 'objective-c++',
@@ -439,7 +439,7 @@ my %LangsAccepted = (
"c" => 1,
"c++" => 1,
"objective-c++" => 1,
-  "c-cpp-output" => 1,
+  "cpp-output" => 1,
"objective-c-cpp-output" => 1,
"c++-cpp-output" => 1
  );


--
Jon Roelofs
jonat...@codesourcery.com
CodeSourcery / Mentor Embedded / Siemens

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


[PATCH] D42060: [clangd] Use fuzzy match to select top N index results.

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

LGTM.




Comment at: clangd/index/MemIndex.cpp:60
   }
-  return true;
+  return false;
 }

this should be `more`?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42060



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


[PATCH] D20124: [PCH] Serialize skipped preprocessor ranges

2018-01-15 Thread Cameron via Phabricator via cfe-commits
cameron314 added a comment.

Excellent, I'll rebase and commit. Thanks everyone for your patience!


https://reviews.llvm.org/D20124



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


[PATCH] D41523: xmmintrin.h documentation fixes and updates

2018-01-15 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added a comment.

Apart for the -Wdocumentation issue (which can be handled separately), is there 
anything else stalling this ticket?


https://reviews.llvm.org/D41523



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


[PATCH] D42004: [Driver] Suggest valid integrated tools

2018-01-15 Thread Benjamin Kramer via Phabricator via cfe-commits
bkramer accepted this revision.
bkramer added a comment.
This revision is now accepted and ready to land.

The -cc1 stuff isn't exactly user-facing, so we didn't put so much emphasis on 
providing great error messages there. This change LGTM.


Repository:
  rC Clang

https://reviews.llvm.org/D42004



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


[PATCH] D41517: mmintrin.h documentation fixes and updates

2018-01-15 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added inline comments.



Comment at: lib/Headers/mmintrin.h:55
 ///
-/// This intrinsic corresponds to the  VMOVD / MOVD  instruction.
+/// This intrinsic corresponds to the  MOVD  instruction.
 ///

efriedma wrote:
> craig.topper wrote:
> > kromanova wrote:
> > > I tried clang on Linux, x86_64, and if -mavx option is passed, we 
> > > generate VMOVD, if this option is omitted, we generate MOVD.
> > > I think I understand the rational behind this change (namely, to keep 
> > > MOVD, but remove VMOVD),
> > > since this intrinsic should use MMX registers and shouldn't have 
> > > corresponding AVX instruction(s).
> > > 
> > > However, that's what we generate at the moment when -mavx is passed (I 
> > > suspect because our MMX support is limited)
> > > vmovd   %edi, %xmm0
> > > 
> > > Since we are writing the documentation for clang compiler, we should 
> > > document what clang compiler is doing, not what is should be doing.
> > > Craig, what do you think? Should we revert back to VMOVD/MOVD?
> > > 
> > We can change it back to VMOVD/MOVD
> The reference to vmovd seems confusing.  Yes, LLVM compiles 
> `_mm_movpi64_epi64(_mm_cvtsi32_si64(i))` to vmovd, but that doesn't mean 
> either of those intrinsics "corresponds" to vmovd; that's just the optimizer 
> combining two operations into one.
Should all these _mm_cvt* intrinsics be replaced with a 'this is a utility 
function' style comment like the _mm_set1* intrinsics?


https://reviews.llvm.org/D41517



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


[PATCH] D42049: [clangd] Merge results from static/dynamic index.

2018-01-15 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL322480: [clangd] Merge results from static/dynamic index. 
(authored by sammccall, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D42049

Files:
  clang-tools-extra/trunk/clangd/CMakeLists.txt
  clang-tools-extra/trunk/clangd/ClangdServer.cpp
  clang-tools-extra/trunk/clangd/ClangdServer.h
  clang-tools-extra/trunk/clangd/CodeComplete.cpp
  clang-tools-extra/trunk/clangd/CodeComplete.h
  clang-tools-extra/trunk/clangd/index/Index.h
  clang-tools-extra/trunk/clangd/index/Merge.cpp
  clang-tools-extra/trunk/clangd/index/Merge.h
  clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
  clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp

Index: clang-tools-extra/trunk/clangd/index/Merge.cpp
===
--- clang-tools-extra/trunk/clangd/index/Merge.cpp
+++ clang-tools-extra/trunk/clangd/index/Merge.cpp
@@ -0,0 +1,98 @@
+//===--- Merge.h *- C++-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===-===//
+#include "Merge.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/Support/raw_ostream.h"
+namespace clang {
+namespace clangd {
+namespace {
+using namespace llvm;
+
+class MergedIndex : public SymbolIndex {
+ public:
+   MergedIndex(const SymbolIndex *Dynamic, const SymbolIndex *Static)
+   : Dynamic(Dynamic), Static(Static) {}
+
+   // FIXME: Deleted symbols in dirty files are still returned (from Static).
+   //To identify these eliminate these, we should:
+   //  - find the generating file from each Symbol which is Static-only
+   //  - ask Dynamic if it has that file (needs new SymbolIndex method)
+   //  - if so, drop the Symbol.
+   bool fuzzyFind(const Context &Ctx, const FuzzyFindRequest &Req,
+  function_ref Callback) const override {
+ // We can't step through both sources in parallel. So:
+ //  1) query all dynamic symbols, slurping results into a slab
+ //  2) query the static symbols, for each one:
+ //a) if it's not in the dynamic slab, yield it directly
+ //b) if it's in the dynamic slab, merge it and yield the result
+ //  3) now yield all the dynamic symbols we haven't processed.
+ bool More = false; // We'll be incomplete if either source was.
+ SymbolSlab::Builder DynB;
+ More |=
+ Dynamic->fuzzyFind(Ctx, Req, [&](const Symbol &S) { DynB.insert(S); });
+ SymbolSlab Dyn = std::move(DynB).build();
+
+ DenseSet SeenDynamicSymbols;
+ Symbol::Details Scratch;
+ More |= Static->fuzzyFind(Ctx, Req, [&](const Symbol &S) {
+   auto DynS = Dyn.find(S.ID);
+   if (DynS == Dyn.end())
+ return Callback(S);
+   SeenDynamicSymbols.insert(S.ID);
+   Callback(mergeSymbol(*DynS, S, &Scratch));
+ });
+ for (const Symbol &S : Dyn)
+   if (!SeenDynamicSymbols.count(S.ID))
+ Callback(S);
+ return More;
+  }
+
+private:
+  const SymbolIndex *Dynamic, *Static;
+};
+}
+
+Symbol
+mergeSymbol(const Symbol &L, const Symbol &R, Symbol::Details *Scratch) {
+  assert(L.ID == R.ID);
+  Symbol S = L;
+  // For each optional field, fill it from R if missing in L.
+  // (It might be missing in R too, but that's a no-op).
+  if (S.CanonicalDeclaration.FilePath == "")
+S.CanonicalDeclaration = R.CanonicalDeclaration;
+  if (S.CompletionLabel == "")
+S.CompletionLabel = R.CompletionLabel;
+  if (S.CompletionFilterText == "")
+S.CompletionFilterText = R.CompletionFilterText;
+  if (S.CompletionPlainInsertText == "")
+S.CompletionPlainInsertText = R.CompletionPlainInsertText;
+  if (S.CompletionSnippetInsertText == "")
+S.CompletionSnippetInsertText = R.CompletionSnippetInsertText;
+
+  if (L.Detail && R.Detail) {
+// Copy into scratch space so we can merge.
+*Scratch = *L.Detail;
+if (Scratch->Documentation == "")
+  Scratch->Documentation = R.Detail->Documentation;
+if (Scratch->CompletionDetail == "")
+  Scratch->CompletionDetail = R.Detail->CompletionDetail;
+S.Detail = Scratch;
+  } else if (L.Detail)
+S.Detail = L.Detail;
+  else if (R.Detail)
+S.Detail = R.Detail;
+  return S;
+}
+
+std::unique_ptr mergeIndex(const SymbolIndex *Dynamic,
+const SymbolIndex *Static) {
+  return llvm::make_unique(Dynamic, Static);
+}
+} // namespace clangd
+} // namespace clang
Index: clang-tools-extra/trunk/clangd/index/Index.h
===
--- clang-tools-extra/trunk/clangd/index/Index.h
+++ clang-tools-extra/trunk/clangd/index/Index.h
@@ -106,8 +106,9

[clang-tools-extra] r322480 - [clangd] Merge results from static/dynamic index.

2018-01-15 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Mon Jan 15 04:33:00 2018
New Revision: 322480

URL: http://llvm.org/viewvc/llvm-project?rev=322480&view=rev
Log:
[clangd] Merge results from static/dynamic index.

Summary:
We now hide the static/dynamic split from the code completion, behind a
new implementation of the SymbolIndex interface. This will reduce the
complexity of the sema/index merging that needs to be done by
CodeComplete, at a fairly small cost in flexibility.

Reviewers: hokein

Subscribers: klimek, mgorny, ilya-biryukov, cfe-commits

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

Added:
clang-tools-extra/trunk/clangd/index/Merge.cpp
clang-tools-extra/trunk/clangd/index/Merge.h
Modified:
clang-tools-extra/trunk/clangd/CMakeLists.txt
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/ClangdServer.h
clang-tools-extra/trunk/clangd/CodeComplete.cpp
clang-tools-extra/trunk/clangd/CodeComplete.h
clang-tools-extra/trunk/clangd/index/Index.h
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp

Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CMakeLists.txt?rev=322480&r1=322479&r2=322480&view=diff
==
--- clang-tools-extra/trunk/clangd/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clangd/CMakeLists.txt Mon Jan 15 04:33:00 2018
@@ -25,6 +25,7 @@ add_clang_library(clangDaemon
   index/FileIndex.cpp
   index/Index.cpp
   index/MemIndex.cpp
+  index/Merge.cpp
   index/SymbolCollector.cpp
   index/SymbolYAML.cpp
 

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=322480&r1=322479&r2=322480&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Mon Jan 15 04:33:00 2018
@@ -11,6 +11,7 @@
 #include "CodeComplete.h"
 #include "SourceCode.h"
 #include "XRefs.h"
+#include "index/Merge.h"
 #include "clang/Format/Format.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/CompilerInvocation.h"
@@ -138,7 +139,6 @@ ClangdServer::ClangdServer(GlobalCompila
llvm::Optional ResourceDir)
 : CDB(CDB), DiagConsumer(DiagConsumer), FSProvider(FSProvider),
   FileIdx(BuildDynamicSymbolIndex ? new FileIndex() : nullptr),
-  StaticIdx(StaticIdx),
   // Pass a callback into `Units` to extract symbols from a newly parsed
   // file and rebuild the file index synchronously each time an AST is
   // parsed.
@@ -151,7 +151,17 @@ ClangdServer::ClangdServer(GlobalCompila
   ResourceDir(ResourceDir ? ResourceDir->str() : getStandardResourceDir()),
   PCHs(std::make_shared()),
   StorePreamblesInMemory(StorePreamblesInMemory),
-  WorkScheduler(AsyncThreadsCount) {}
+  WorkScheduler(AsyncThreadsCount) {
+  if (FileIdx && StaticIdx) {
+MergedIndex = mergeIndex(FileIdx.get(), StaticIdx);
+Index = MergedIndex.get();
+  } else if (FileIdx)
+Index = FileIdx.get();
+  else if (StaticIdx)
+Index = StaticIdx;
+  else
+Index = nullptr;
+}
 
 void ClangdServer::setRootPath(PathRef RootPath) {
   std::string NewRootPath = llvm::sys::path::convert_to_slash(
@@ -250,10 +260,8 @@ void ClangdServer::codeComplete(
   Resources->getPossiblyStalePreamble();
   // Copy completion options for passing them to async task handler.
   auto CodeCompleteOpts = Opts;
-  if (FileIdx)
-CodeCompleteOpts.Index = FileIdx.get();
-  if (StaticIdx)
-CodeCompleteOpts.StaticIndex = StaticIdx;
+  if (!CodeCompleteOpts.Index) // Respect overridden index.
+CodeCompleteOpts.Index = Index;
 
   // Copy File, as it is a PathRef that will go out of scope before Task is
   // executed.

Modified: clang-tools-extra/trunk/clangd/ClangdServer.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.h?rev=322480&r1=322479&r2=322480&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.h Mon Jan 15 04:33:00 2018
@@ -340,13 +340,16 @@ private:
   DiagnosticsConsumer &DiagConsumer;
   FileSystemProvider &FSProvider;
   DraftStore DraftMgr;
-  /// If set, this manages index for symbols in opened files.
+  // The index used to look up symbols. This could be:
+  //   - null (all index functionality is optional)
+  //   - the dynamic index owned by ClangdServer (FileIdx)
+  //   - the static index passed to the constructor
+  //   - a merged view of a static and dynamic index (MergedIndex)
+  SymbolIndex *Index;
+  // If present, an up-to-date of symbols in open files.

[PATCH] D42063: [clangd] Avoid combinatorial explosion in CodeCompleteTests.

2018-01-15 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: ilya-biryukov.
Herald added subscribers: cfe-commits, klimek.

This test dominates our unit test runtime, and the change speeds it up by 10x.
We lose coverage of some combinations of flags, but I'm not sure that's finding
many bugs.

3300 -> 300ms on my machine (3800 -> 800ms for the whole of CompletionTest).


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42063

Files:
  unittests/clangd/CodeCompleteTests.cpp


Index: unittests/clangd/CodeCompleteTests.cpp
===
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -254,26 +254,26 @@
 }
 
 TEST(CompletionTest, CompletionOptions) {
-  clangd::CodeCompleteOptions Opts;
-  for (bool IncludeMacros : {true, false}) {
-Opts.IncludeMacros = IncludeMacros;
-for (bool IncludeGlobals : {true, false}) {
-  Opts.IncludeGlobals = IncludeGlobals;
-  for (bool IncludeBriefComments : {true, false}) {
-Opts.IncludeBriefComments = IncludeBriefComments;
-for (bool EnableSnippets : {true, false}) {
-  Opts.EnableSnippets = EnableSnippets;
-  for (bool IncludeCodePatterns : {true, false}) {
-Opts.IncludeCodePatterns = IncludeCodePatterns;
-for (bool IncludeIneligibleResults : {true, false}) {
-  Opts.IncludeIneligibleResults = IncludeIneligibleResults;
-  TestAfterDotCompletion(Opts);
-  TestGlobalScopeCompletion(Opts);
-}
-  }
-}
-  }
-}
+  auto Test = [&](const clangd::CodeCompleteOptions &Opts) {
+TestAfterDotCompletion(Opts);
+TestGlobalScopeCompletion(Opts);
+  };
+  // We used to test every combination of options, but that got too slow (2^N).
+  auto Flags = {
+&clangd::CodeCompleteOptions::IncludeMacros,
+&clangd::CodeCompleteOptions::IncludeGlobals,
+&clangd::CodeCompleteOptions::IncludeBriefComments,
+&clangd::CodeCompleteOptions::EnableSnippets,
+&clangd::CodeCompleteOptions::IncludeCodePatterns,
+&clangd::CodeCompleteOptions::IncludeIneligibleResults,
+  };
+  // Test default options.
+  Test({});
+  // Test one flag set.
+  for (auto &F : Flags) {
+clangd::CodeCompleteOptions O;
+O.*F = true;
+Test(O);
   }
 }
 


Index: unittests/clangd/CodeCompleteTests.cpp
===
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -254,26 +254,26 @@
 }
 
 TEST(CompletionTest, CompletionOptions) {
-  clangd::CodeCompleteOptions Opts;
-  for (bool IncludeMacros : {true, false}) {
-Opts.IncludeMacros = IncludeMacros;
-for (bool IncludeGlobals : {true, false}) {
-  Opts.IncludeGlobals = IncludeGlobals;
-  for (bool IncludeBriefComments : {true, false}) {
-Opts.IncludeBriefComments = IncludeBriefComments;
-for (bool EnableSnippets : {true, false}) {
-  Opts.EnableSnippets = EnableSnippets;
-  for (bool IncludeCodePatterns : {true, false}) {
-Opts.IncludeCodePatterns = IncludeCodePatterns;
-for (bool IncludeIneligibleResults : {true, false}) {
-  Opts.IncludeIneligibleResults = IncludeIneligibleResults;
-  TestAfterDotCompletion(Opts);
-  TestGlobalScopeCompletion(Opts);
-}
-  }
-}
-  }
-}
+  auto Test = [&](const clangd::CodeCompleteOptions &Opts) {
+TestAfterDotCompletion(Opts);
+TestGlobalScopeCompletion(Opts);
+  };
+  // We used to test every combination of options, but that got too slow (2^N).
+  auto Flags = {
+&clangd::CodeCompleteOptions::IncludeMacros,
+&clangd::CodeCompleteOptions::IncludeGlobals,
+&clangd::CodeCompleteOptions::IncludeBriefComments,
+&clangd::CodeCompleteOptions::EnableSnippets,
+&clangd::CodeCompleteOptions::IncludeCodePatterns,
+&clangd::CodeCompleteOptions::IncludeIneligibleResults,
+  };
+  // Test default options.
+  Test({});
+  // Test one flag set.
+  for (auto &F : Flags) {
+clangd::CodeCompleteOptions O;
+O.*F = true;
+Test(O);
   }
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42049: [clangd] Merge results from static/dynamic index.

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

looks good.




Comment at: clangd/index/Merge.cpp:34
+ Dynamic->fuzzyFind(Ctx, Req, [&](const Symbol &S) { DynB.insert(S); 
});
+ SymbolSlab Dyn = std::move(DynB).build();
+

sammccall wrote:
> hokein wrote:
> > IIUC, `Dyn` is a local variable, which holds all the underlying data of 
> > `Symbol`, the `Symbol` returned in the callback of `fuzzyFind` would be 
> > invalid after the `fuzzyFind(..)` function call is finished.
> > 
> > Our previous assumption is that `Symbol` is valid as long as the 
> > `SymbolIndex` exists?
> > Our previous assumption is that Symbol is valid as long as the SymbolIndex 
> > exists?
> 
> No, it's only valid for the callback. Valid for the life of the index would 
> make life hard for remote indexes.
> Added documentation to SymbolIndex.
I see, that makes sense.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42049



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


[PATCH] D42060: [clangd] Use fuzzy match to select top N index results.

2018-01-15 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: hokein.
Herald added subscribers: cfe-commits, ilya-biryukov, klimek.

This makes performance slower but more predictable (it always processes
every symbol). We need to find ways to make this fast, possibly by precomputing
short queries or capping the number of scored results. But our current approach
is too naive.

It also no longer returns results in a "good" order. In fact it's pathological:
the top N results are ranked from worst to best. Indexes aren't responsible for
ranking and MergedIndex can't do a good job, so I'm pleased that this will make
any hidden assumptions we have more noticeable :-)


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42060

Files:
  clangd/index/MemIndex.cpp
  unittests/clangd/IndexTests.cpp

Index: unittests/clangd/IndexTests.cpp
===
--- unittests/clangd/IndexTests.cpp
+++ unittests/clangd/IndexTests.cpp
@@ -148,12 +148,22 @@
   EXPECT_EQ(Matches.size(), Req.MaxCandidateCount);
 }
 
+TEST(MemIndexTest, FuzzyMatch) {
+  MemIndex I;
+  I.build(
+  generateSymbols({"LaughingOutLoud", "LionPopulation", "LittleOldLady"}));
+  FuzzyFindRequest Req;
+  Req.Query = "lol";
+  Req.MaxCandidateCount = 2;
+  EXPECT_THAT(match(I, Req),
+  UnorderedElementsAre("LaughingOutLoud", "LittleOldLady"));
+}
+
 TEST(MemIndexTest, MatchQualifiedNamesWithoutSpecificScope) {
   MemIndex I;
   I.build(generateSymbols({"a::xyz", "b::yz", "yz"}));
   FuzzyFindRequest Req;
   Req.Query = "y";
-  auto Matches = match(I, Req);
   EXPECT_THAT(match(I, Req), UnorderedElementsAre("a::xyz", "b::yz", "yz"));
 }
 
@@ -163,7 +173,6 @@
   FuzzyFindRequest Req;
   Req.Query = "y";
   Req.Scopes = {""};
-  auto Matches = match(I, Req);
   EXPECT_THAT(match(I, Req), UnorderedElementsAre("yz"));
 }
 
@@ -173,7 +182,6 @@
   FuzzyFindRequest Req;
   Req.Query = "y";
   Req.Scopes = {"a"};
-  auto Matches = match(I, Req);
   EXPECT_THAT(match(I, Req), UnorderedElementsAre("a::xyz", "a::yy"));
 }
 
@@ -183,7 +191,6 @@
   FuzzyFindRequest Req;
   Req.Query = "y";
   Req.Scopes = {"a", "b"};
-  auto Matches = match(I, Req);
   EXPECT_THAT(match(I, Req), UnorderedElementsAre("a::xyz", "a::yy", "b::yz"));
 }
 
@@ -193,7 +200,6 @@
   FuzzyFindRequest Req;
   Req.Query = "y";
   Req.Scopes = {"a"};
-  auto Matches = match(I, Req);
   EXPECT_THAT(match(I, Req), UnorderedElementsAre("a::xyz"));
 }
 
@@ -203,7 +209,6 @@
   FuzzyFindRequest Req;
   Req.Query = "AB";
   Req.Scopes = {"ns"};
-  auto Matches = match(I, Req);
   EXPECT_THAT(match(I, Req), UnorderedElementsAre("ns::ABC", "ns::abc"));
 }
 
Index: clangd/index/MemIndex.cpp
===
--- clangd/index/MemIndex.cpp
+++ clangd/index/MemIndex.cpp
@@ -8,7 +8,9 @@
 //===---===//
 
 #include "MemIndex.h"
+#include "../FuzzyMatch.h"
 #include "../Logger.h"
+#include 
 
 namespace clang {
 namespace clangd {
@@ -32,7 +34,9 @@
   assert(!StringRef(Req.Query).contains("::") &&
  "There must be no :: in query.");
 
-  unsigned Matched = 0;
+  std::priority_queue> Top;
+  FuzzyMatcher Filter(Req.Query);
+  bool More = false;
   {
 std::lock_guard Lock(Mutex);
 for (const auto Pair : Index) {
@@ -42,15 +46,18 @@
   if (!Req.Scopes.empty() && !llvm::is_contained(Req.Scopes, Sym->Scope))
 continue;
 
-  // FIXME(ioeric): use fuzzy matcher.
-  if (StringRef(Sym->Name).find_lower(Req.Query) != StringRef::npos) {
-if (++Matched > Req.MaxCandidateCount)
-  return false;
-Callback(*Sym);
+  if (auto Score = Filter.match(Sym->Name)) {
+Top.emplace(-*Score, Sym);
+if (Top.size() > Req.MaxCandidateCount) {
+  More = true;
+  Top.pop();
+}
   }
 }
+for (; !Top.empty(); Top.pop())
+  Callback(*Top.top().second);
   }
-  return true;
+  return false;
 }
 
 std::unique_ptr MemIndex::build(SymbolSlab Slab) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D41487: [clang-format] Adds a FormatStyleSet

2018-01-15 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC322479: [clang-format] Adds a FormatStyleSet (authored by 
krasimir, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D41487?vs=128933&id=129832#toc

Repository:
  rC Clang

https://reviews.llvm.org/D41487

Files:
  include/clang/Format/Format.h
  lib/Format/Format.cpp

Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -859,7 +859,7 @@
   assert(Language != FormatStyle::LK_None);
   if (Text.trim().empty())
 return make_error_code(ParseError::Error);
-
+  Style->StyleSet.Clear();
   std::vector Styles;
   llvm::yaml::Input Input(Text);
   // DocumentListTraits> uses the context to get default
@@ -888,15 +888,23 @@
   // Look for a suitable configuration starting from the end, so we can
   // find the configuration for the specific language first, and the default
   // configuration (which can only be at slot 0) after it.
+  FormatStyle::FormatStyleSet StyleSet;
+  bool LanguageFound = false;
   for (int i = Styles.size() - 1; i >= 0; --i) {
-if (Styles[i].Language == Language ||
-Styles[i].Language == FormatStyle::LK_None) {
-  *Style = Styles[i];
-  Style->Language = Language;
-  return make_error_code(ParseError::Success);
-}
+if (Styles[i].Language != FormatStyle::LK_None)
+  StyleSet.Add(Styles[i]);
+if (Styles[i].Language == Language)
+  LanguageFound = true;
+  }
+  if (!LanguageFound) {
+if (Styles.empty() || Styles[0].Language != FormatStyle::LK_None)
+  return make_error_code(ParseError::Unsuitable);
+FormatStyle DefaultStyle = Styles[0];
+DefaultStyle.Language = Language;
+StyleSet.Add(std::move(DefaultStyle));
   }
-  return make_error_code(ParseError::Unsuitable);
+  *Style = *StyleSet.Get(Language);
+  return make_error_code(ParseError::Success);
 }
 
 std::string configurationAsText(const FormatStyle &Style) {
@@ -910,6 +918,38 @@
   return Stream.str();
 }
 
+llvm::Optional
+FormatStyle::FormatStyleSet::Get(FormatStyle::LanguageKind Language) const {
+  if (!Styles)
+return None;
+  auto It = Styles->find(Language);
+  if (It == Styles->end())
+return None;
+  FormatStyle Style = It->second;
+  Style.StyleSet = *this;
+  return Style;
+}
+
+void FormatStyle::FormatStyleSet::Add(FormatStyle Style) {
+  assert(Style.Language != LK_None &&
+ "Cannot add a style for LK_None to a StyleSet");
+  assert(
+  !Style.StyleSet.Styles &&
+  "Cannot add a style associated with an existing StyleSet to a StyleSet");
+  if (!Styles)
+Styles = std::make_shared();
+  (*Styles)[Style.Language] = std::move(Style);
+}
+
+void FormatStyle::FormatStyleSet::Clear() {
+  Styles.reset();
+}
+
+llvm::Optional
+FormatStyle::GetLanguageStyle(FormatStyle::LanguageKind Language) const {
+  return StyleSet.Get(Language);
+}
+
 namespace {
 
 class JavaScriptRequoter : public TokenAnalyzer {
Index: include/clang/Format/Format.h
===
--- include/clang/Format/Format.h
+++ include/clang/Format/Format.h
@@ -1685,6 +1685,43 @@
Standard == R.Standard && TabWidth == R.TabWidth &&
UseTab == R.UseTab;
   }
+
+  llvm::Optional GetLanguageStyle(LanguageKind Language) const;
+
+  // Stores per-language styles. A FormatStyle instance inside has an empty
+  // StyleSet. A FormatStyle instance returned by the Get method has its
+  // StyleSet set to a copy of the originating StyleSet, effectively keeping the
+  // internal representation of that StyleSet alive.
+  //
+  // The memory management and ownership reminds of a birds nest: chicks
+  // leaving the nest take photos of the nest with them.
+  struct FormatStyleSet {
+typedef std::map MapType;
+
+llvm::Optional Get(FormatStyle::LanguageKind Language) const;
+
+// Adds \p Style to this FormatStyleSet. Style must not have an associated
+// FormatStyleSet.
+// Style.Language should be different than LK_None. If this FormatStyleSet
+// already contains an entry for Style.Language, that gets replaced with the
+// passed Style.
+void Add(FormatStyle Style);
+
+// Clears this FormatStyleSet.
+void Clear();
+
+  private:
+std::shared_ptr Styles;
+  };
+
+  static FormatStyleSet BuildStyleSetFromConfiguration(
+  const FormatStyle &MainStyle,
+  const std::vector &ConfigurationStyles);
+
+private:
+  FormatStyleSet StyleSet;
+
+  friend std::error_code parseConfiguration(StringRef Text, FormatStyle *Style);
 };
 
 /// \brief Returns a format style complying with the LLVM coding standards:
@@ -1730,6 +1767,8 @@
 /// Style->Language is used to get the base style, if the ``BasedOnStyle``
 /// option is present.
 ///
+/// The FormatStyleSet of Style is reset.
+///
 /// When ``BasedOnStyle`` is not present, options not present in the YAML
 /// document, a

r322479 - [clang-format] Adds a FormatStyleSet

2018-01-15 Thread Krasimir Georgiev via cfe-commits
Author: krasimir
Date: Mon Jan 15 04:06:16 2018
New Revision: 322479

URL: http://llvm.org/viewvc/llvm-project?rev=322479&view=rev
Log:
[clang-format] Adds a FormatStyleSet

Summary:
This patch adds a FormatStyleSet for storing per-language FormatStyles for the
purposes of formatting code blocks inside the main code.

Reviewers: bkramer

Reviewed By: bkramer

Subscribers: klimek, djasper, bkramer, cfe-commits

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

Modified:
cfe/trunk/include/clang/Format/Format.h
cfe/trunk/lib/Format/Format.cpp

Modified: cfe/trunk/include/clang/Format/Format.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=322479&r1=322478&r2=322479&view=diff
==
--- cfe/trunk/include/clang/Format/Format.h (original)
+++ cfe/trunk/include/clang/Format/Format.h Mon Jan 15 04:06:16 2018
@@ -1685,6 +1685,43 @@ struct FormatStyle {
Standard == R.Standard && TabWidth == R.TabWidth &&
UseTab == R.UseTab;
   }
+
+  llvm::Optional GetLanguageStyle(LanguageKind Language) const;
+
+  // Stores per-language styles. A FormatStyle instance inside has an empty
+  // StyleSet. A FormatStyle instance returned by the Get method has its
+  // StyleSet set to a copy of the originating StyleSet, effectively keeping 
the
+  // internal representation of that StyleSet alive.
+  //
+  // The memory management and ownership reminds of a birds nest: chicks
+  // leaving the nest take photos of the nest with them.
+  struct FormatStyleSet {
+typedef std::map MapType;
+
+llvm::Optional Get(FormatStyle::LanguageKind Language) const;
+
+// Adds \p Style to this FormatStyleSet. Style must not have an associated
+// FormatStyleSet.
+// Style.Language should be different than LK_None. If this FormatStyleSet
+// already contains an entry for Style.Language, that gets replaced with 
the
+// passed Style.
+void Add(FormatStyle Style);
+
+// Clears this FormatStyleSet.
+void Clear();
+
+  private:
+std::shared_ptr Styles;
+  };
+
+  static FormatStyleSet BuildStyleSetFromConfiguration(
+  const FormatStyle &MainStyle,
+  const std::vector &ConfigurationStyles);
+
+private:
+  FormatStyleSet StyleSet;
+
+  friend std::error_code parseConfiguration(StringRef Text, FormatStyle 
*Style);
 };
 
 /// \brief Returns a format style complying with the LLVM coding standards:
@@ -1730,6 +1767,8 @@ bool getPredefinedStyle(StringRef Name,
 /// Style->Language is used to get the base style, if the ``BasedOnStyle``
 /// option is present.
 ///
+/// The FormatStyleSet of Style is reset.
+///
 /// When ``BasedOnStyle`` is not present, options not present in the YAML
 /// document, are retained in \p Style.
 std::error_code parseConfiguration(StringRef Text, FormatStyle *Style);

Modified: cfe/trunk/lib/Format/Format.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=322479&r1=322478&r2=322479&view=diff
==
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Mon Jan 15 04:06:16 2018
@@ -859,7 +859,7 @@ std::error_code parseConfiguration(Strin
   assert(Language != FormatStyle::LK_None);
   if (Text.trim().empty())
 return make_error_code(ParseError::Error);
-
+  Style->StyleSet.Clear();
   std::vector Styles;
   llvm::yaml::Input Input(Text);
   // DocumentListTraits> uses the context to get default
@@ -888,15 +888,23 @@ std::error_code parseConfiguration(Strin
   // Look for a suitable configuration starting from the end, so we can
   // find the configuration for the specific language first, and the default
   // configuration (which can only be at slot 0) after it.
+  FormatStyle::FormatStyleSet StyleSet;
+  bool LanguageFound = false;
   for (int i = Styles.size() - 1; i >= 0; --i) {
-if (Styles[i].Language == Language ||
-Styles[i].Language == FormatStyle::LK_None) {
-  *Style = Styles[i];
-  Style->Language = Language;
-  return make_error_code(ParseError::Success);
-}
+if (Styles[i].Language != FormatStyle::LK_None)
+  StyleSet.Add(Styles[i]);
+if (Styles[i].Language == Language)
+  LanguageFound = true;
+  }
+  if (!LanguageFound) {
+if (Styles.empty() || Styles[0].Language != FormatStyle::LK_None)
+  return make_error_code(ParseError::Unsuitable);
+FormatStyle DefaultStyle = Styles[0];
+DefaultStyle.Language = Language;
+StyleSet.Add(std::move(DefaultStyle));
   }
-  return make_error_code(ParseError::Unsuitable);
+  *Style = *StyleSet.Get(Language);
+  return make_error_code(ParseError::Success);
 }
 
 std::string configurationAsText(const FormatStyle &Style) {
@@ -910,6 +918,38 @@ std::string configurationAsText(const Fo
   return Stream.str();
 }
 
+llvm::Optional
+FormatStyle::FormatStyleSet::Get(FormatStyle::LanguageKind Language) 

[PATCH] D42059: [clangd] Improve const-correctness of Symbol->Detail. NFC

2018-01-15 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: hokein.
Herald added subscribers: cfe-commits, ilya-biryukov, klimek.

This would have caught a bug I wrote in an early version of 
https://reviews.llvm.org/D42049, where
an index user could overwrite data internal to the index because the Symbol is
not deep-const.

The YAML traits are now a bit more verbose, but separate concerns a bit more
nicely: ArenaPtr can be reused for other similarly-allocated objects, including
scalars etc.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42059

Files:
  clangd/index/Index.cpp
  clangd/index/Index.h
  clangd/index/SymbolYAML.cpp

Index: clangd/index/SymbolYAML.cpp
===
--- clangd/index/SymbolYAML.cpp
+++ clangd/index/SymbolYAML.cpp
@@ -60,27 +60,39 @@
   }
 };
 
-template <>
-struct MappingTraits {
-  static void mapping(IO &io, Symbol::Details *&Detail) {
-if (!io.outputting()) {
-  assert(io.getContext() && "Expecting an arena (as context) to allocate "
-"data for new symbols.");
-  Detail = static_cast(io.getContext())
-   ->Allocate();
-} else if (!Detail) {
-  // Detail is optional in outputting.
-  return;
-}
-assert(Detail);
-io.mapOptional("Documentation", Detail->Documentation);
-io.mapOptional("CompletionDetail", Detail->CompletionDetail);
+template <> struct MappingTraits {
+  static void mapping(IO &io, Symbol::Details &Detail) {
+io.mapOptional("Documentation", Detail.Documentation);
+io.mapOptional("CompletionDetail", Detail.CompletionDetail);
   }
 };
 
+// A YamlIO normalizer for fields of type "const T*" allocated on an arena.
+// Normalizes to Optional, so traits should be provided for T.
+template  struct ArenaPtr {
+  ArenaPtr(IO &) {}
+  ArenaPtr(IO &, const T *D) {
+if (D)
+  Opt = *D;
+  }
+
+  const T *denormalize(IO &IO) {
+assert(IO.getContext() && "Expecting an arena (as context) to allocate "
+  "data for read symbols.");
+if (!Opt)
+  return nullptr;
+return new (*static_cast(IO.getContext()))
+T(std::move(*Opt));
+  }
+
+  llvm::Optional Opt;
+};
+
 template <> struct MappingTraits {
   static void mapping(IO &IO, Symbol &Sym) {
 MappingNormalization NSymbolID(IO, Sym.ID);
+MappingNormalization, const Symbol::Details *>
+NDetail(IO, Sym.Detail);
 IO.mapRequired("ID", NSymbolID->HexString);
 IO.mapRequired("Name", Sym.Name);
 IO.mapRequired("Scope", Sym.Scope);
@@ -92,8 +104,7 @@
 
 IO.mapOptional("CompletionSnippetInsertText",
Sym.CompletionSnippetInsertText);
-if (!IO.outputting() || Sym.Detail)
-  IO.mapOptional("Detail", Sym.Detail);
+IO.mapOptional("Detail", NDetail->Opt);
   }
 };
 
Index: clangd/index/Index.h
===
--- clangd/index/Index.h
+++ clangd/index/Index.h
@@ -155,7 +155,7 @@
   };
 
   // Optional details of the symbol.
-  Details *Detail = nullptr;
+  const Details *Detail = nullptr;
 
   // FIXME: add definition location of the symbol.
   // FIXME: add all occurrences support.
Index: clangd/index/Index.cpp
===
--- clangd/index/Index.cpp
+++ clangd/index/Index.cpp
@@ -64,13 +64,12 @@
   if (S.Detail) {
 // Copy values of StringRefs into arena.
 auto *Detail = Arena.Allocate();
-Detail->Documentation = S.Detail->Documentation;
-Detail->CompletionDetail = S.Detail->CompletionDetail;
-S.Detail = Detail;
-
+*Detail = *S.Detail;
 // Intern the actual strings.
-Intern(S.Detail->Documentation);
-Intern(S.Detail->CompletionDetail);
+Intern(Detail->Documentation);
+Intern(Detail->CompletionDetail);
+// Replace the detail pointer with our copy.
+S.Detail = Detail;
   }
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42049: [clangd] Merge results from static/dynamic index.

2018-01-15 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clangd/index/Merge.cpp:29
+ //b) if it's in the dynamic slab, merge it and yield the result
+ //  3) now yield all the dynamic symbols we haven't processed.
+ bool More = false; // We'll be incomplete if either source was.

hokein wrote:
> Maybe add another FIXME, saying filer out symbols in static index, but are 
> removed in dynamic index?
Done (function-level comment, because it's not a localized fix)



Comment at: clangd/index/Merge.cpp:34
+ Dynamic->fuzzyFind(Ctx, Req, [&](const Symbol &S) { DynB.insert(S); 
});
+ SymbolSlab Dyn = std::move(DynB).build();
+

hokein wrote:
> IIUC, `Dyn` is a local variable, which holds all the underlying data of 
> `Symbol`, the `Symbol` returned in the callback of `fuzzyFind` would be 
> invalid after the `fuzzyFind(..)` function call is finished.
> 
> Our previous assumption is that `Symbol` is valid as long as the 
> `SymbolIndex` exists?
> Our previous assumption is that Symbol is valid as long as the SymbolIndex 
> exists?

No, it's only valid for the callback. Valid for the life of the index would 
make life hard for remote indexes.
Added documentation to SymbolIndex.



Comment at: clangd/index/Merge.cpp:75
+if (S.Detail->Documentation == "")
+  S.Detail->Documentation = R.Detail->Documentation;
+  }

hokein wrote:
> Don't we need ` CompletionDetail`?
Sure. I was assuming it wasn't optional (should be present and match if USR 
matches), but i'm not 100% sure.



Comment at: clangd/index/Merge.cpp:75
+if (S.Detail->Documentation == "")
+  S.Detail->Documentation = R.Detail->Documentation;
+  }

sammccall wrote:
> hokein wrote:
> > Don't we need ` CompletionDetail`?
> Sure. I was assuming it wasn't optional (should be present and match if USR 
> matches), but i'm not 100% sure.
This was a bug. It'd be caught by marking Symbol::Detail const. Added a TODO.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42049



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


[PATCH] D32747: [Analyzer] Iterator Checker - Part 3: Invalidation check, first for (copy) assignments

2018-01-15 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware added inline comments.



Comment at: lib/StaticAnalyzer/Checkers/IteratorChecker.cpp:605
+  if (Pos && !Pos->isValid()) {
+// If I do not put a tag here, some invalidation tests will fail
+static CheckerProgramPointTag Tag("InvalidatedIteratorChecker",

NoQ wrote:
> This needs investigation, because it may be nasty.
> 
> `generateNonFatalErrorNode()` returns null when the exact same non-fatal 
> error node, also produced by the iterator checker with the exact same program 
> state and exact same program point and exact same tag on the program point 
> already exists. As far as i understand, the only difference your tag makes is 
> that the tag is now different, so it is not merged with the existing node. 
> However, it is worth it to try to find out why the node gets merged at all.
> 
> This may be caused by an accidental state split. For example, if you are 
> calling `generateNonFatalErrorNode()` twice in the same checker callback 
> without chaining them together (passing node returned by one as an argument 
> to another), this in fact splits states. I'm not immediately seeing such 
> places in the code - you seem to be aware of this problem and avoiding it 
> well. But still, looking at the topology of the exploded graph in the failing 
> test should help finding out what is going on.
I made some more investigation this time. Unfortunately the case is not what 
you suggest. Only one non-fatal error node is produced. I tested it with a 
common tag (a global static so the tag is exactly the same at every 
`generateNonFatalErrorNode()`, but the tests still pass. I printed out the 
exploded graph and I found that there are indeed two nodes with the same state 
ID. The tag is the default tag automatically generated from the name of the 
checker. The first state is created in function `checkPreStatement()` for 
`CXXOperatorCallExpr` where I copy the state of the iterator from the formal to 
the actual `this` parameter. All the test fails happen at the dereference 
operator call (`*`) of another operator call (`++` or `--`). After this copy, 
when I call `generateNonFatalErrorNode()` I get `nullptr` because at some point 
under the hood (I debugged it when I created it originally) the error node is 
considered as "not new". If I use a custom tag here, the state ID remains, not 
the node ID changes.


https://reviews.llvm.org/D32747



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


[PATCH] D42049: [clangd] Merge results from static/dynamic index.

2018-01-15 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 129824.
sammccall marked 2 inline comments as done.
sammccall added a comment.

Fixed bug where we wrote into the underlying index's symbols.
Extended testcase.
Added documentation around contracts.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42049

Files:
  clangd/CMakeLists.txt
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/CodeComplete.cpp
  clangd/CodeComplete.h
  clangd/index/Index.h
  clangd/index/Merge.cpp
  clangd/index/Merge.h
  unittests/clangd/CodeCompleteTests.cpp
  unittests/clangd/IndexTests.cpp

Index: unittests/clangd/IndexTests.cpp
===
--- unittests/clangd/IndexTests.cpp
+++ unittests/clangd/IndexTests.cpp
@@ -9,6 +9,7 @@
 
 #include "index/Index.h"
 #include "index/MemIndex.h"
+#include "index/Merge.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
@@ -207,6 +208,42 @@
   EXPECT_THAT(match(I, Req), UnorderedElementsAre("ns::ABC", "ns::abc"));
 }
 
+TEST(MergeTest, MergeIndex) {
+  MemIndex I, J;
+  I.build(generateSymbols({"ns::A", "ns::B"}));
+  J.build(generateSymbols({"ns::B", "ns::C"}));
+  FuzzyFindRequest Req;
+  Req.Scopes = {"ns"};
+  EXPECT_THAT(match(*mergeIndex(&I, &J), Req),
+  UnorderedElementsAre("ns::A", "ns::B", "ns::C"));
+}
+
+TEST(MergeTest, Merge) {
+  Symbol L, R;
+  L.ID = R.ID = SymbolID("hello");
+  L.Name = R.Name = "Foo";// same in both
+  L.CanonicalDeclaration.FilePath = "left.h"; // differs
+  R.CanonicalDeclaration.FilePath = "right.h";
+  L.CompletionPlainInsertText = "f00";// present in left only
+  R.CompletionSnippetInsertText = "f0{$1:0}"; // present in right only
+  Symbol::Details DetL, DetR;
+  DetL.CompletionDetail = "DetL";
+  DetR.CompletionDetail = "DetR";
+  DetR.Documentation = "--doc--";
+  L.Detail = &DetL;
+  R.Detail = &DetR;
+
+  Symbol::Details Scratch;
+  Symbol M = mergeSymbol(L, R, &Scratch);
+  EXPECT_EQ(M.Name, "Foo");
+  EXPECT_EQ(M.CanonicalDeclaration.FilePath, "left.h");
+  EXPECT_EQ(M.CompletionPlainInsertText, "f00");
+  EXPECT_EQ(M.CompletionSnippetInsertText, "f0{$1:0}");
+  ASSERT_TRUE(M.Detail);
+  EXPECT_EQ(M.Detail->CompletionDetail, "DetL");
+  EXPECT_EQ(M.Detail->Documentation, "--doc--");
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: unittests/clangd/CodeCompleteTests.cpp
===
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -17,6 +17,7 @@
 #include "SourceCode.h"
 #include "TestFS.h"
 #include "index/MemIndex.h"
+#include "index/Merge.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
@@ -518,17 +519,17 @@
   clangd::CodeCompleteOptions Opts;
   auto StaticIdx =
   simpleIndexFromSymbols({{"ns::XYZ", index::SymbolKind::Class}});
-  Opts.StaticIndex = StaticIdx.get();
   auto DynamicIdx =
   simpleIndexFromSymbols({{"ns::foo", index::SymbolKind::Function}});
-  Opts.Index = DynamicIdx.get();
+  auto Merge = mergeIndex(DynamicIdx.get(), StaticIdx.get());
+  Opts.Index = Merge.get();
 
   auto Results = completions(R"cpp(
   void f() { ::ns::^ }
   )cpp",
  Opts);
-  EXPECT_THAT(Results.items, Contains(Labeled("[S]XYZ")));
-  EXPECT_THAT(Results.items, Contains(Labeled("[D]foo")));
+  EXPECT_THAT(Results.items, Contains(Labeled("[I]XYZ")));
+  EXPECT_THAT(Results.items, Contains(Labeled("[I]foo")));
 }
 
 TEST(CompletionTest, SimpleIndexBased) {
Index: clangd/index/Merge.h
===
--- /dev/null
+++ clangd/index/Merge.h
@@ -0,0 +1,29 @@
+//===--- Merge.h *- C++-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===-===//
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_MERGE_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_MERGE_H
+#include "Index.h"
+namespace clang {
+namespace clangd {
+
+// Merge symbols L and R, preferring data from L in case of conflict.
+// The two symbols must have the same ID.
+// Returned symbol may contain data owned by either source.
+Symbol mergeSymbol(const Symbol &L, const Symbol &R, Symbol::Details *Scratch);
+
+// mergedIndex returns a composite index based on two provided Indexes:
+//  - the Dynamic index covers few files, but is relatively up-to-date.
+//  - the Static index covers a bigger set of files, but is relatively stale.
+// The returned index attempts to combine results, and avoid duplicates.
+std::unique_ptr mergeIndex(const SymbolIndex *Dynamic,
+const SymbolIndex *Static);
+
+} // namespace clangd
+} // namespace clang
+#endif
Index: clangd/index/Merge.cpp
=

[PATCH] D41179: [Sema] Diagnose template specializations with C linkage

2018-01-15 Thread Mikhail Maltsev via Phabricator via cfe-commits
miyuki added a comment.

ping^2


https://reviews.llvm.org/D41179



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


[PATCH] D41629: [libcxx] Improve accuracy of complex asinh and acosh

2018-01-15 Thread Mikhail Maltsev via Phabricator via cfe-commits
miyuki added a comment.

ping


https://reviews.llvm.org/D41629



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


  1   2   >