[libcxx] r328182 - Fix dynarray test failures after changing __libcpp_allocate/deallocate

2018-03-21 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Wed Mar 21 22:44:48 2018
New Revision: 328182

URL: http://llvm.org/viewvc/llvm-project?rev=328182=rev
Log:
Fix dynarray test failures after changing __libcpp_allocate/deallocate

Modified:
libcxx/trunk/include/experimental/dynarray

Modified: libcxx/trunk/include/experimental/dynarray
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/experimental/dynarray?rev=328182=328181=328182=diff
==
--- libcxx/trunk/include/experimental/dynarray (original)
+++ libcxx/trunk/include/experimental/dynarray Wed Mar 21 22:44:48 2018
@@ -135,17 +135,18 @@ private:
 value_type *__base_;
 _LIBCPP_ALWAYS_INLINE dynarray () noexcept :  __size_(0), __base_(nullptr) 
{}
 
-static inline _LIBCPP_INLINE_VISIBILITY value_type* __allocate ( size_t 
count )
-{
-if ( numeric_limits::max() / sizeof (value_type) <= count )
+static inline _LIBCPP_INLINE_VISIBILITY
+value_type* __allocate(size_t __count) {
+if (numeric_limits::max() / sizeof (value_type) <= __count)
 __throw_bad_array_length();
 
-return static_cast (_VSTD::__allocate 
(sizeof(value_type) * count));
+return static_cast(
+_VSTD::__libcpp_allocate(sizeof(value_type) * __count, 
__alignof(value_type)));
 }
 
-static inline _LIBCPP_INLINE_VISIBILITY void __deallocate_value( 
value_type* __ptr ) noexcept
-{
-_VSTD::__libcpp_deallocate (static_cast (__ptr));
+static inline _LIBCPP_INLINE_VISIBILITY
+void __deallocate_value(value_type* __ptr ) noexcept {
+_VSTD::__libcpp_deallocate(static_cast(__ptr), 
__alignof(value_type));
 }
 
 public:


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


[PATCH] D43957: Fixing issue where a space was not added before a global namespace variable when SpacesInParentheses is set

2018-03-21 Thread Darby Payne via Phabricator via cfe-commits
dpayne added a comment.

I'll make sure to do the full diff in the future. I did that for the first 
patch but forgot to do it in the follow up patch, I won't make that mistake in 
the future.

I do not have commit access so I cannot merge myself. When you have the time 
could you merge this change?


Repository:
  rC Clang

https://reviews.llvm.org/D43957



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


[libcxx] r328180 - Fix PR22634 - std::allocator doesn't respect over-aligned types.

2018-03-21 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Wed Mar 21 21:42:56 2018
New Revision: 328180

URL: http://llvm.org/viewvc/llvm-project?rev=328180=rev
Log:
Fix PR22634 - std::allocator doesn't respect over-aligned types.

This patch fixes std::allocator, and more specifically, all users
of __libcpp_allocate and __libcpp_deallocate, to support over-aligned
types.

__libcpp_allocate/deallocate now take an alignment parameter, and when
the specified alignment is greater than that supported by malloc/new,
the aligned version of operator new is called (assuming it's available).

When aligned new isn't available, the old behavior has been kept, and the
alignment parameter is ignored.

This patch depends on recent changes to __builtin_operator_new/delete which
allow them to be used to call any regular new/delete operator. By using
__builtin_operator_new/delete when possible, the new/delete erasure optimization
is maintained.

Modified:
libcxx/trunk/include/__config
libcxx/trunk/include/__sso_allocator
libcxx/trunk/include/memory
libcxx/trunk/include/new
libcxx/trunk/include/valarray
libcxx/trunk/src/experimental/memory_resource.cpp

libcxx/trunk/test/std/utilities/memory/default.allocator/allocator.members/allocate.pass.cpp
libcxx/trunk/test/support/count_new.hpp
libcxx/trunk/test/support/test_macros.h

Modified: libcxx/trunk/include/__config
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__config?rev=328180=328179=328180=diff
==
--- libcxx/trunk/include/__config (original)
+++ libcxx/trunk/include/__config Wed Mar 21 21:42:56 2018
@@ -955,6 +955,7 @@ template  struct __static_asse
 #  endif
 #endif // defined(__APPLE__)
 
+
 #if defined(__APPLE__) || defined(__FreeBSD__)
 #define _LIBCPP_HAS_DEFAULTRUNELOCALE
 #endif

Modified: libcxx/trunk/include/__sso_allocator
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__sso_allocator?rev=328180=328179=328180=diff
==
--- libcxx/trunk/include/__sso_allocator (original)
+++ libcxx/trunk/include/__sso_allocator Wed Mar 21 21:42:56 2018
@@ -55,14 +55,14 @@ public:
 __allocated_ = true;
 return (pointer)_;
 }
-return static_cast(_VSTD::__allocate(__n * sizeof(_Tp)));
+return static_cast(_VSTD::__libcpp_allocate(__n * 
sizeof(_Tp), __alignof(_Tp)));
 }
 _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type)
 {
 if (__p == (pointer)_)
 __allocated_ = false;
 else
-_VSTD::__libcpp_deallocate(__p);
+_VSTD::__libcpp_deallocate(__p, __alignof(_Tp));
 }
 _LIBCPP_INLINE_VISIBILITY size_type max_size() const throw() {return 
size_type(~0) / sizeof(_Tp);}
 

Modified: libcxx/trunk/include/memory
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/memory?rev=328180=328179=328180=diff
==
--- libcxx/trunk/include/memory (original)
+++ libcxx/trunk/include/memory Wed Mar 21 21:42:56 2018
@@ -1796,10 +1796,10 @@ public:
 if (__n > max_size())
 __throw_length_error("allocator::allocate(size_t n)"
  " 'n' exceeds maximum supported size");
-return static_cast(_VSTD::__allocate(__n * sizeof(_Tp)));
+return static_cast(_VSTD::__libcpp_allocate(__n * 
sizeof(_Tp), __alignof(_Tp)));
 }
 _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
-{_VSTD::__libcpp_deallocate((void*)__p);}
+{_VSTD::__libcpp_deallocate((void*)__p, __alignof(_Tp));}
 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
 {return size_type(~0) / sizeof(_Tp);}
 #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && 
!defined(_LIBCPP_HAS_NO_VARIADICS)
@@ -1897,10 +1897,10 @@ public:
 if (__n > max_size())
 __throw_length_error("allocator::allocate(size_t n)"
  " 'n' exceeds maximum supported size");
-return static_cast(_VSTD::__allocate(__n * sizeof(_Tp)));
+return static_cast(_VSTD::__libcpp_allocate(__n * 
sizeof(_Tp), __alignof(_Tp)));
 }
 _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
-{_VSTD::__libcpp_deallocate((void*) const_cast<_Tp *>(__p));}
+{_VSTD::__libcpp_deallocate((void*) const_cast<_Tp *>(__p), 
__alignof(_Tp));}
 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
 {return size_type(~0) / sizeof(_Tp);}
 #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && 
!defined(_LIBCPP_HAS_NO_VARIADICS)
@@ -2016,12 +2016,7 @@ get_temporary_buffer(ptrdiff_t __n) _NOE
 while (__n > 0)
 {
 #if !defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION)
-#if defined(__STDCPP_DEFAULT_NEW_ALIGNMENT__)
-if (std::alignment_of<_Tp>::value > 

r328173 - Improve -Winfinite-recursion

2018-03-21 Thread Robert Widmann via cfe-commits
Author: codafi
Date: Wed Mar 21 20:16:23 2018
New Revision: 328173

URL: http://llvm.org/viewvc/llvm-project?rev=328173=rev
Log:
Improve -Winfinite-recursion

Summary: Rewrites -Winfinite-recursion to remove the state dictionary and 
explore paths in loops - especially infinite loops.  The new check now detects 
recursion in loop bodies dominated by a recursive call.

Reviewers: rsmith, rtrieu

Reviewed By: rtrieu

Subscribers: lebedev.ri, cfe-commits

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

Modified:
cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
cfe/trunk/test/SemaCXX/warn-infinite-recursion.cpp

Modified: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp?rev=328173=328172=328173=diff
==
--- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp (original)
+++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp Wed Mar 21 20:16:23 2018
@@ -200,60 +200,41 @@ static bool hasRecursiveCallInPath(const
   return false;
 }
 
-// All blocks are in one of three states.  States are ordered so that blocks
-// can only move to higher states.
-enum RecursiveState {
-  FoundNoPath,
-  FoundPath,
-  FoundPathWithNoRecursiveCall
-};
-
-// Returns true if there exists a path to the exit block and every path
-// to the exit block passes through a call to FD.
+// Returns true if every path from the entry block passes through a call to FD.
 static bool checkForRecursiveFunctionCall(const FunctionDecl *FD, CFG *cfg) {
+  llvm::SmallPtrSet Visited;
+  llvm::SmallVector WorkList;
+  // Keep track of whether we found at least one recursive path.
+  bool foundRecursion = false;
 
   const unsigned ExitID = cfg->getExit().getBlockID();
 
-  // Mark all nodes as FoundNoPath, then set the status of the entry block.
-  SmallVector States(cfg->getNumBlockIDs(), FoundNoPath);
-  States[cfg->getEntry().getBlockID()] = FoundPathWithNoRecursiveCall;
-
-  // Make the processing stack and seed it with the entry block.
-  SmallVector Stack;
-  Stack.push_back(>getEntry());
-
-  while (!Stack.empty()) {
-CFGBlock *CurBlock = Stack.back();
-Stack.pop_back();
-
-unsigned ID = CurBlock->getBlockID();
-RecursiveState CurState = States[ID];
-
-if (CurState == FoundPathWithNoRecursiveCall) {
-  // Found a path to the exit node without a recursive call.
-  if (ExitID == ID)
-return false;
-
-  // Only change state if the block has a recursive call.
-  if (hasRecursiveCallInPath(FD, *CurBlock))
-CurState = FoundPath;
-}
+  // Seed the work list with the entry block.
+  WorkList.push_back(>getEntry());
 
-// Loop over successor blocks and add them to the Stack if their state
-// changes.
-for (auto I = CurBlock->succ_begin(), E = CurBlock->succ_end(); I != E; 
++I)
-  if (*I) {
-unsigned next_ID = (*I)->getBlockID();
-if (States[next_ID] < CurState) {
-  States[next_ID] = CurState;
-  Stack.push_back(*I);
+  while (!WorkList.empty()) {
+CFGBlock *Block = WorkList.pop_back_val();
+
+for (auto I = Block->succ_begin(), E = Block->succ_end(); I != E; ++I) {
+  if (CFGBlock *SuccBlock = *I) {
+if (!Visited.insert(SuccBlock).second)
+  continue;
+
+// Found a path to the exit node without a recursive call.
+if (ExitID == SuccBlock->getBlockID())
+  return false;
+
+// If the successor block contains a recursive call, end analysis 
there.
+if (hasRecursiveCallInPath(FD, *SuccBlock)) {
+  foundRecursion = true;
+  continue;
 }
+
+WorkList.push_back(SuccBlock);
   }
+}
   }
-
-  // Return true if the exit node is reachable, and only reachable through
-  // a recursive call.
-  return States[ExitID] == FoundPath;
+  return foundRecursion;
 }
 
 static void checkRecursiveFunction(Sema , const FunctionDecl *FD,
@@ -269,10 +250,6 @@ static void checkRecursiveFunction(Sema
   CFG *cfg = AC.getCFG();
   if (!cfg) return;
 
-  // If the exit block is unreachable, skip processing the function.
-  if (cfg->getExit().pred_empty())
-return;
-
   // Emit diagnostic if a recursive function call is detected for all paths.
   if (checkForRecursiveFunctionCall(FD, cfg))
 S.Diag(Body->getLocStart(), diag::warn_infinite_recursive_function);

Modified: cfe/trunk/test/SemaCXX/warn-infinite-recursion.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-infinite-recursion.cpp?rev=328173=328172=328173=diff
==
--- cfe/trunk/test/SemaCXX/warn-infinite-recursion.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-infinite-recursion.cpp Wed Mar 21 20:16:23 2018
@@ -29,8 +29,7 @@ void f();
 void e() { f(); }
 void f() { e(); }
 
-// Don't warn on infinite loops
-void g() {
+void g() {  // 

[PATCH] D44597: [CFG] [analyzer] Add C++17-specific variable and return value construction contexts.

2018-03-21 Thread Devin Coughlin via Phabricator via cfe-commits
dcoughlin accepted this revision.
dcoughlin added a comment.

LGTM. I really appreciate the extra documentation you've added, too.


https://reviews.llvm.org/D44597



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


[PATCH] D44632: [clang-format] Add a few more Core Graphics identifiers to ObjC heuristic

2018-03-21 Thread Ben Hamilton via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL328175: [clang-format] Add a few more Core Graphics 
identifiers to ObjC heuristic (authored by benhamilton, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D44632

Files:
  cfe/trunk/lib/Format/Format.cpp
  cfe/trunk/unittests/Format/FormatTest.cpp


Index: cfe/trunk/lib/Format/Format.cpp
===
--- cfe/trunk/lib/Format/Format.cpp
+++ cfe/trunk/lib/Format/Format.cpp
@@ -1449,6 +1449,19 @@
 // Keep this array sorted, since we are binary searching over it.
 static constexpr llvm::StringLiteral FoundationIdentifiers[] = {
 "CGFloat",
+"CGPoint",
+"CGPointMake",
+"CGPointZero",
+"CGRect",
+"CGRectEdge",
+"CGRectInfinite",
+"CGRectMake",
+"CGRectNull",
+"CGRectZero",
+"CGSize",
+"CGSizeMake",
+"CGVector",
+"CGVectorMake",
 "NSAffineTransform",
 "NSArray",
 "NSAttributedString",
@@ -1497,6 +1510,8 @@
 "NSURLQueryItem",
 "NSUUID",
 "NSValue",
+"UIImage",
+"UIView",
 };
 
 for (auto  : AnnotatedLines) {
Index: cfe/trunk/unittests/Format/FormatTest.cpp
===
--- cfe/trunk/unittests/Format/FormatTest.cpp
+++ cfe/trunk/unittests/Format/FormatTest.cpp
@@ -12108,6 +12108,12 @@
   EXPECT_EQ(FormatStyle::LK_ObjC, guessLanguage("foo.h", "@interface 
Foo\n@end\n"));
   EXPECT_EQ(FormatStyle::LK_Cpp, guessLanguage("foo", ""));
   EXPECT_EQ(FormatStyle::LK_ObjC, guessLanguage("foo", "@interface 
Foo\n@end\n"));
+  EXPECT_EQ(FormatStyle::LK_ObjC,
+guessLanguage("foo.h", "int DoStuff(CGRect rect);\n"));
+  EXPECT_EQ(
+  FormatStyle::LK_ObjC,
+  guessLanguage("foo.h",
+"#define MY_POINT_MAKE(x, y) CGPointMake((x), (y));\n"));
 }
 
 TEST_F(FormatTest, GuessLanguageWithCpp11AttributeSpecifiers) {


Index: cfe/trunk/lib/Format/Format.cpp
===
--- cfe/trunk/lib/Format/Format.cpp
+++ cfe/trunk/lib/Format/Format.cpp
@@ -1449,6 +1449,19 @@
 // Keep this array sorted, since we are binary searching over it.
 static constexpr llvm::StringLiteral FoundationIdentifiers[] = {
 "CGFloat",
+"CGPoint",
+"CGPointMake",
+"CGPointZero",
+"CGRect",
+"CGRectEdge",
+"CGRectInfinite",
+"CGRectMake",
+"CGRectNull",
+"CGRectZero",
+"CGSize",
+"CGSizeMake",
+"CGVector",
+"CGVectorMake",
 "NSAffineTransform",
 "NSArray",
 "NSAttributedString",
@@ -1497,6 +1510,8 @@
 "NSURLQueryItem",
 "NSUUID",
 "NSValue",
+"UIImage",
+"UIView",
 };
 
 for (auto  : AnnotatedLines) {
Index: cfe/trunk/unittests/Format/FormatTest.cpp
===
--- cfe/trunk/unittests/Format/FormatTest.cpp
+++ cfe/trunk/unittests/Format/FormatTest.cpp
@@ -12108,6 +12108,12 @@
   EXPECT_EQ(FormatStyle::LK_ObjC, guessLanguage("foo.h", "@interface Foo\n@end\n"));
   EXPECT_EQ(FormatStyle::LK_Cpp, guessLanguage("foo", ""));
   EXPECT_EQ(FormatStyle::LK_ObjC, guessLanguage("foo", "@interface Foo\n@end\n"));
+  EXPECT_EQ(FormatStyle::LK_ObjC,
+guessLanguage("foo.h", "int DoStuff(CGRect rect);\n"));
+  EXPECT_EQ(
+  FormatStyle::LK_ObjC,
+  guessLanguage("foo.h",
+"#define MY_POINT_MAKE(x, y) CGPointMake((x), (y));\n"));
 }
 
 TEST_F(FormatTest, GuessLanguageWithCpp11AttributeSpecifiers) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r328175 - [clang-format] Add a few more Core Graphics identifiers to ObjC heuristic

2018-03-21 Thread Ben Hamilton via cfe-commits
Author: benhamilton
Date: Wed Mar 21 20:25:22 2018
New Revision: 328175

URL: http://llvm.org/viewvc/llvm-project?rev=328175=rev
Log:
[clang-format] Add a few more Core Graphics identifiers to ObjC heuristic

Summary:
We received reports of the Objective-C style guesser getting a false
negative on header files like:

CGSize SizeOfThing(MyThing thing);

This adds more Core Graphics identifiers to the Objective-C style
guesser.

Test Plan: New tests added. Ran tests with:
  % make -j12 FormatTests && ./tools/clang/unittests/Format/FormatTests

Reviewers: jolesiak, djasper

Reviewed By: jolesiak, djasper

Subscribers: krasimir, klimek, cfe-commits

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

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

Modified: cfe/trunk/lib/Format/Format.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=328175=328174=328175=diff
==
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Wed Mar 21 20:25:22 2018
@@ -1449,6 +1449,19 @@ private:
 // Keep this array sorted, since we are binary searching over it.
 static constexpr llvm::StringLiteral FoundationIdentifiers[] = {
 "CGFloat",
+"CGPoint",
+"CGPointMake",
+"CGPointZero",
+"CGRect",
+"CGRectEdge",
+"CGRectInfinite",
+"CGRectMake",
+"CGRectNull",
+"CGRectZero",
+"CGSize",
+"CGSizeMake",
+"CGVector",
+"CGVectorMake",
 "NSAffineTransform",
 "NSArray",
 "NSAttributedString",
@@ -1497,6 +1510,8 @@ private:
 "NSURLQueryItem",
 "NSUUID",
 "NSValue",
+"UIImage",
+"UIView",
 };
 
 for (auto  : AnnotatedLines) {

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=328175=328174=328175=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Mar 21 20:25:22 2018
@@ -12108,6 +12108,12 @@ TEST_F(FormatTest, FileAndCode) {
   EXPECT_EQ(FormatStyle::LK_ObjC, guessLanguage("foo.h", "@interface 
Foo\n@end\n"));
   EXPECT_EQ(FormatStyle::LK_Cpp, guessLanguage("foo", ""));
   EXPECT_EQ(FormatStyle::LK_ObjC, guessLanguage("foo", "@interface 
Foo\n@end\n"));
+  EXPECT_EQ(FormatStyle::LK_ObjC,
+guessLanguage("foo.h", "int DoStuff(CGRect rect);\n"));
+  EXPECT_EQ(
+  FormatStyle::LK_ObjC,
+  guessLanguage("foo.h",
+"#define MY_POINT_MAKE(x, y) CGPointMake((x), (y));\n"));
 }
 
 TEST_F(FormatTest, GuessLanguageWithCpp11AttributeSpecifiers) {


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


[PATCH] D44632: [clang-format] Add a few more Core Graphics identifiers to ObjC heuristic

2018-03-21 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton updated this revision to Diff 139410.
benhamilton marked an inline comment as done.
benhamilton added a comment.

Remove assert


Repository:
  rC Clang

https://reviews.llvm.org/D44632

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


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -12108,6 +12108,12 @@
   EXPECT_EQ(FormatStyle::LK_ObjC, guessLanguage("foo.h", "@interface 
Foo\n@end\n"));
   EXPECT_EQ(FormatStyle::LK_Cpp, guessLanguage("foo", ""));
   EXPECT_EQ(FormatStyle::LK_ObjC, guessLanguage("foo", "@interface 
Foo\n@end\n"));
+  EXPECT_EQ(FormatStyle::LK_ObjC,
+guessLanguage("foo.h", "int DoStuff(CGRect rect);\n"));
+  EXPECT_EQ(
+  FormatStyle::LK_ObjC,
+  guessLanguage("foo.h",
+"#define MY_POINT_MAKE(x, y) CGPointMake((x), (y));\n"));
 }
 
 TEST_F(FormatTest, GuessLanguageWithCpp11AttributeSpecifiers) {
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -1449,6 +1449,19 @@
 // Keep this array sorted, since we are binary searching over it.
 static constexpr llvm::StringLiteral FoundationIdentifiers[] = {
 "CGFloat",
+"CGPoint",
+"CGPointMake",
+"CGPointZero",
+"CGRect",
+"CGRectEdge",
+"CGRectInfinite",
+"CGRectMake",
+"CGRectNull",
+"CGRectZero",
+"CGSize",
+"CGSizeMake",
+"CGVector",
+"CGVectorMake",
 "NSAffineTransform",
 "NSArray",
 "NSAttributedString",
@@ -1497,6 +1510,8 @@
 "NSURLQueryItem",
 "NSUUID",
 "NSValue",
+"UIImage",
+"UIView",
 };
 
 for (auto  : AnnotatedLines) {


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -12108,6 +12108,12 @@
   EXPECT_EQ(FormatStyle::LK_ObjC, guessLanguage("foo.h", "@interface Foo\n@end\n"));
   EXPECT_EQ(FormatStyle::LK_Cpp, guessLanguage("foo", ""));
   EXPECT_EQ(FormatStyle::LK_ObjC, guessLanguage("foo", "@interface Foo\n@end\n"));
+  EXPECT_EQ(FormatStyle::LK_ObjC,
+guessLanguage("foo.h", "int DoStuff(CGRect rect);\n"));
+  EXPECT_EQ(
+  FormatStyle::LK_ObjC,
+  guessLanguage("foo.h",
+"#define MY_POINT_MAKE(x, y) CGPointMake((x), (y));\n"));
 }
 
 TEST_F(FormatTest, GuessLanguageWithCpp11AttributeSpecifiers) {
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -1449,6 +1449,19 @@
 // Keep this array sorted, since we are binary searching over it.
 static constexpr llvm::StringLiteral FoundationIdentifiers[] = {
 "CGFloat",
+"CGPoint",
+"CGPointMake",
+"CGPointZero",
+"CGRect",
+"CGRectEdge",
+"CGRectInfinite",
+"CGRectMake",
+"CGRectNull",
+"CGRectZero",
+"CGSize",
+"CGSizeMake",
+"CGVector",
+"CGVectorMake",
 "NSAffineTransform",
 "NSArray",
 "NSAttributedString",
@@ -1497,6 +1510,8 @@
 "NSURLQueryItem",
 "NSUUID",
 "NSValue",
+"UIImage",
+"UIView",
 };
 
 for (auto  : AnnotatedLines) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44692: [clang-format] Don't insert space between r_paren and 'new' in ObjC decl

2018-03-21 Thread Ben Hamilton via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL328174: [clang-format] Dont insert space between 
r_paren and new in ObjC decl (authored by benhamilton, committed by 
).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D44692

Files:
  cfe/trunk/lib/Format/TokenAnnotator.cpp
  cfe/trunk/unittests/Format/FormatTestObjC.cpp


Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -2615,8 +2615,10 @@
   if (Line.Type == LT_ObjCMethodDecl) {
 if (Left.is(TT_ObjCMethodSpecifier))
   return true;
-if (Left.is(tok::r_paren) && Right.is(tok::identifier))
-  // Don't space between ')' and 
+if (Left.is(tok::r_paren) && Right.isOneOf(tok::identifier, tok::kw_new))
+  // Don't space between ')' and  or ')' and 'new'. 'new' is not a
+  // keyword in Objective-C, and '+ (instancetype)new;' is a standard class
+  // method declaration.
   return false;
   }
   if (Line.Type == LT_ObjCProperty &&
Index: cfe/trunk/unittests/Format/FormatTestObjC.cpp
===
--- cfe/trunk/unittests/Format/FormatTestObjC.cpp
+++ cfe/trunk/unittests/Format/FormatTestObjC.cpp
@@ -514,6 +514,7 @@
"evenLongerKeyword:(float)theInterval\n"
"error:(NSError **)theError {\n"
"}");
+  verifyFormat("+ (instancetype)new;\n");
   Style.ColumnLimit = 60;
   verifyFormat("- (instancetype)initXx:(id)x\n"
" y:(id)y\n"
@@ -914,6 +915,17 @@
" }]) {\n}");
 }
 
+TEST_F(FormatTestObjC, ObjCNew) {
+  verifyFormat("+ (instancetype)new {\n"
+   "  return nil;\n"
+   "}\n");
+  verifyFormat("+ (instancetype)myNew {\n"
+   "  return [self new];\n"
+   "}\n");
+  verifyFormat("SEL NewSelector(void) { return @selector(new); }\n");
+  verifyFormat("SEL MacroSelector(void) { return MACRO(new); }\n");
+}
+
 TEST_F(FormatTestObjC, ObjCLiterals) {
   verifyFormat("@\"String\"");
   verifyFormat("@1");


Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -2615,8 +2615,10 @@
   if (Line.Type == LT_ObjCMethodDecl) {
 if (Left.is(TT_ObjCMethodSpecifier))
   return true;
-if (Left.is(tok::r_paren) && Right.is(tok::identifier))
-  // Don't space between ')' and 
+if (Left.is(tok::r_paren) && Right.isOneOf(tok::identifier, tok::kw_new))
+  // Don't space between ')' and  or ')' and 'new'. 'new' is not a
+  // keyword in Objective-C, and '+ (instancetype)new;' is a standard class
+  // method declaration.
   return false;
   }
   if (Line.Type == LT_ObjCProperty &&
Index: cfe/trunk/unittests/Format/FormatTestObjC.cpp
===
--- cfe/trunk/unittests/Format/FormatTestObjC.cpp
+++ cfe/trunk/unittests/Format/FormatTestObjC.cpp
@@ -514,6 +514,7 @@
"evenLongerKeyword:(float)theInterval\n"
"error:(NSError **)theError {\n"
"}");
+  verifyFormat("+ (instancetype)new;\n");
   Style.ColumnLimit = 60;
   verifyFormat("- (instancetype)initXx:(id)x\n"
" y:(id)y\n"
@@ -914,6 +915,17 @@
" }]) {\n}");
 }
 
+TEST_F(FormatTestObjC, ObjCNew) {
+  verifyFormat("+ (instancetype)new {\n"
+   "  return nil;\n"
+   "}\n");
+  verifyFormat("+ (instancetype)myNew {\n"
+   "  return [self new];\n"
+   "}\n");
+  verifyFormat("SEL NewSelector(void) { return @selector(new); }\n");
+  verifyFormat("SEL MacroSelector(void) { return MACRO(new); }\n");
+}
+
 TEST_F(FormatTestObjC, ObjCLiterals) {
   verifyFormat("@\"String\"");
   verifyFormat("@1");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r328174 - [clang-format] Don't insert space between r_paren and 'new' in ObjC decl

2018-03-21 Thread Ben Hamilton via cfe-commits
Author: benhamilton
Date: Wed Mar 21 20:23:53 2018
New Revision: 328174

URL: http://llvm.org/viewvc/llvm-project?rev=328174=rev
Log:
[clang-format] Don't insert space between r_paren and 'new' in ObjC decl

Summary:
Previously, clang-format would insert a space between
the closing parenthesis and 'new' in the following valid Objective-C
declaration:

  + (instancetype)new;

This was because 'new' is treated as a keyword, not an identifier.

TokenAnnotator::spaceRequiredBefore() already handled the case where
r_paren came before an identifier, so this diff extends it to
handle r_paren before 'new'.

Test Plan: New tests added. Ran tests with:
  % make -j12 FormatTests && ./tools/clang/unittests/Format/FormatTests

Reviewers: djasper, jolesiak, stephanemoore

Reviewed By: djasper, jolesiak, stephanemoore

Subscribers: stephanemoore, klimek, cfe-commits

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

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

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=328174=328173=328174=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Wed Mar 21 20:23:53 2018
@@ -2615,8 +2615,10 @@ bool TokenAnnotator::spaceRequiredBefore
   if (Line.Type == LT_ObjCMethodDecl) {
 if (Left.is(TT_ObjCMethodSpecifier))
   return true;
-if (Left.is(tok::r_paren) && Right.is(tok::identifier))
-  // Don't space between ')' and 
+if (Left.is(tok::r_paren) && Right.isOneOf(tok::identifier, tok::kw_new))
+  // Don't space between ')' and  or ')' and 'new'. 'new' is not a
+  // keyword in Objective-C, and '+ (instancetype)new;' is a standard class
+  // method declaration.
   return false;
   }
   if (Line.Type == LT_ObjCProperty &&

Modified: cfe/trunk/unittests/Format/FormatTestObjC.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestObjC.cpp?rev=328174=328173=328174=diff
==
--- cfe/trunk/unittests/Format/FormatTestObjC.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestObjC.cpp Wed Mar 21 20:23:53 2018
@@ -514,6 +514,7 @@ TEST_F(FormatTestObjC, FormatObjCMethodD
"evenLongerKeyword:(float)theInterval\n"
"error:(NSError **)theError {\n"
"}");
+  verifyFormat("+ (instancetype)new;\n");
   Style.ColumnLimit = 60;
   verifyFormat("- (instancetype)initXx:(id)x\n"
" y:(id)y\n"
@@ -914,6 +915,17 @@ TEST_F(FormatTestObjC, ObjCForIn) {
" }]) {\n}");
 }
 
+TEST_F(FormatTestObjC, ObjCNew) {
+  verifyFormat("+ (instancetype)new {\n"
+   "  return nil;\n"
+   "}\n");
+  verifyFormat("+ (instancetype)myNew {\n"
+   "  return [self new];\n"
+   "}\n");
+  verifyFormat("SEL NewSelector(void) { return @selector(new); }\n");
+  verifyFormat("SEL MacroSelector(void) { return MACRO(new); }\n");
+}
+
 TEST_F(FormatTestObjC, ObjCLiterals) {
   verifyFormat("@\"String\"");
   verifyFormat("@1");


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


[PATCH] D43737: Improve -Winfinite-recursion

2018-03-21 Thread Robert Widmann via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL328173: Improve -Winfinite-recursion (authored by CodaFi, 
committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D43737?vs=139325=139408#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D43737

Files:
  cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
  cfe/trunk/test/SemaCXX/warn-infinite-recursion.cpp

Index: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
===
--- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
+++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
@@ -200,60 +200,41 @@
   return false;
 }
 
-// All blocks are in one of three states.  States are ordered so that blocks
-// can only move to higher states.
-enum RecursiveState {
-  FoundNoPath,
-  FoundPath,
-  FoundPathWithNoRecursiveCall
-};
-
-// Returns true if there exists a path to the exit block and every path
-// to the exit block passes through a call to FD.
+// Returns true if every path from the entry block passes through a call to FD.
 static bool checkForRecursiveFunctionCall(const FunctionDecl *FD, CFG *cfg) {
+  llvm::SmallPtrSet Visited;
+  llvm::SmallVector WorkList;
+  // Keep track of whether we found at least one recursive path.
+  bool foundRecursion = false;
 
   const unsigned ExitID = cfg->getExit().getBlockID();
 
-  // Mark all nodes as FoundNoPath, then set the status of the entry block.
-  SmallVector States(cfg->getNumBlockIDs(), FoundNoPath);
-  States[cfg->getEntry().getBlockID()] = FoundPathWithNoRecursiveCall;
+  // Seed the work list with the entry block.
+  WorkList.push_back(>getEntry());
 
-  // Make the processing stack and seed it with the entry block.
-  SmallVector Stack;
-  Stack.push_back(>getEntry());
-
-  while (!Stack.empty()) {
-CFGBlock *CurBlock = Stack.back();
-Stack.pop_back();
-
-unsigned ID = CurBlock->getBlockID();
-RecursiveState CurState = States[ID];
-
-if (CurState == FoundPathWithNoRecursiveCall) {
-  // Found a path to the exit node without a recursive call.
-  if (ExitID == ID)
-return false;
+  while (!WorkList.empty()) {
+CFGBlock *Block = WorkList.pop_back_val();
 
-  // Only change state if the block has a recursive call.
-  if (hasRecursiveCallInPath(FD, *CurBlock))
-CurState = FoundPath;
-}
+for (auto I = Block->succ_begin(), E = Block->succ_end(); I != E; ++I) {
+  if (CFGBlock *SuccBlock = *I) {
+if (!Visited.insert(SuccBlock).second)
+  continue;
 
-// Loop over successor blocks and add them to the Stack if their state
-// changes.
-for (auto I = CurBlock->succ_begin(), E = CurBlock->succ_end(); I != E; ++I)
-  if (*I) {
-unsigned next_ID = (*I)->getBlockID();
-if (States[next_ID] < CurState) {
-  States[next_ID] = CurState;
-  Stack.push_back(*I);
+// Found a path to the exit node without a recursive call.
+if (ExitID == SuccBlock->getBlockID())
+  return false;
+
+// If the successor block contains a recursive call, end analysis there.
+if (hasRecursiveCallInPath(FD, *SuccBlock)) {
+  foundRecursion = true;
+  continue;
 }
+
+WorkList.push_back(SuccBlock);
   }
+}
   }
-
-  // Return true if the exit node is reachable, and only reachable through
-  // a recursive call.
-  return States[ExitID] == FoundPath;
+  return foundRecursion;
 }
 
 static void checkRecursiveFunction(Sema , const FunctionDecl *FD,
@@ -269,10 +250,6 @@
   CFG *cfg = AC.getCFG();
   if (!cfg) return;
 
-  // If the exit block is unreachable, skip processing the function.
-  if (cfg->getExit().pred_empty())
-return;
-
   // Emit diagnostic if a recursive function call is detected for all paths.
   if (checkForRecursiveFunctionCall(FD, cfg))
 S.Diag(Body->getLocStart(), diag::warn_infinite_recursive_function);
Index: cfe/trunk/test/SemaCXX/warn-infinite-recursion.cpp
===
--- cfe/trunk/test/SemaCXX/warn-infinite-recursion.cpp
+++ cfe/trunk/test/SemaCXX/warn-infinite-recursion.cpp
@@ -29,8 +29,7 @@
 void e() { f(); }
 void f() { e(); }
 
-// Don't warn on infinite loops
-void g() {
+void g() {  // expected-warning{{call itself}}
   while (true)
 g();
 
@@ -54,6 +53,19 @@
   return 5 + j();
 }
 
+void k() {  // expected-warning{{call itself}}
+  while(true) {
+k();
+  }
+}
+
+// Don't warn on infinite loops
+void l() {
+  while (true) {}
+
+  l();
+}
+
 class S {
   static void a();
   void b();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r328172 - Revert "[clang-doc] Reland "[clang-doc] Setup clang-doc frontend framework""

2018-03-21 Thread Julie Hockett via cfe-commits
Author: juliehockett
Date: Wed Mar 21 19:05:51 2018
New Revision: 328172

URL: http://llvm.org/viewvc/llvm-project?rev=328172=rev
Log:
Revert "[clang-doc] Reland "[clang-doc] Setup clang-doc frontend framework""

This reverts commit r328150 until we can fix the test that are failing
on the Windows release build.

Removed:
clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp
clang-tools-extra/trunk/clang-doc/BitcodeWriter.h
clang-tools-extra/trunk/clang-doc/CMakeLists.txt
clang-tools-extra/trunk/clang-doc/ClangDoc.cpp
clang-tools-extra/trunk/clang-doc/ClangDoc.h
clang-tools-extra/trunk/clang-doc/Mapper.cpp
clang-tools-extra/trunk/clang-doc/Mapper.h
clang-tools-extra/trunk/clang-doc/Representation.h
clang-tools-extra/trunk/clang-doc/Serialize.cpp
clang-tools-extra/trunk/clang-doc/Serialize.h
clang-tools-extra/trunk/clang-doc/tool/CMakeLists.txt
clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-class-in-class.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-class-in-function.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-class.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-comments.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-enum.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-function.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-method.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-namespace.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-struct.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-union.cpp
Modified:
clang-tools-extra/trunk/CMakeLists.txt
clang-tools-extra/trunk/test/CMakeLists.txt

Modified: clang-tools-extra/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/CMakeLists.txt?rev=328172=328171=328172=diff
==
--- clang-tools-extra/trunk/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/CMakeLists.txt Wed Mar 21 19:05:51 2018
@@ -7,7 +7,6 @@ add_subdirectory(clang-tidy-vs)
 endif()
 
 add_subdirectory(change-namespace)
-add_subdirectory(clang-doc)
 add_subdirectory(clang-query)
 add_subdirectory(clang-move)
 add_subdirectory(clangd)

Removed: clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp?rev=328171=auto
==
--- clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp (removed)
@@ -1,511 +0,0 @@
-//===--  BitcodeWriter.cpp - ClangDoc Bitcode Writer *- C++ 
-*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===--===//
-
-#include "BitcodeWriter.h"
-#include "llvm/ADT/IndexedMap.h"
-#include 
-
-namespace clang {
-namespace doc {
-
-// Since id enums are not zero-indexed, we need to transform the given id into
-// its associated index.
-struct BlockIdToIndexFunctor {
-  using argument_type = unsigned;
-  unsigned operator()(unsigned ID) const { return ID - BI_FIRST; }
-};
-
-struct RecordIdToIndexFunctor {
-  using argument_type = unsigned;
-  unsigned operator()(unsigned ID) const { return ID - RI_FIRST; }
-};
-
-using AbbrevDsc = void (*)(std::shared_ptr );
-
-static void AbbrevGen(std::shared_ptr ,
-  const std::initializer_list Ops) {
-  for (const auto  : Ops)
-Abbrev->Add(Op);
-}
-
-static void BoolAbbrev(std::shared_ptr ) {
-  AbbrevGen(Abbrev,
-{// 0. Boolean
- llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
-   BitCodeConstants::BoolSize)});
-}
-
-static void IntAbbrev(std::shared_ptr ) {
-  AbbrevGen(Abbrev,
-{// 0. Fixed-size integer
- llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
-   BitCodeConstants::IntSize)});
-}
-
-static void SymbolIDAbbrev(std::shared_ptr ) {
-  AbbrevGen(Abbrev,
-{// 0. Fixed-size integer (length of the sha1'd USR)
- llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
-   BitCodeConstants::USRLengthSize),
- // 1. Fixed-size array of Char6 (USR)
- llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Array),
- llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
-   BitCodeConstants::USRBitLengthSize)});
-}
-
-static void StringAbbrev(std::shared_ptr ) {
-  AbbrevGen(Abbrev,
-{// 0. Fixed-size integer (length of the following string)
- llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
-   

[PATCH] D41240: [Solaris] __float128 is supported on Solaris/x86

2018-03-21 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

@fedor.sergeev Can you review this for correctness? Thanks!


Repository:
  rC Clang

https://reviews.llvm.org/D41240



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


r328171 - [Frontend] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC).

2018-03-21 Thread Eugene Zelenko via cfe-commits
Author: eugenezelenko
Date: Wed Mar 21 17:53:26 2018
New Revision: 328171

URL: http://llvm.org/viewvc/llvm-project?rev=328171=rev
Log:
[Frontend] Fix some Clang-tidy modernize and Include What You Use warnings; 
other minor fixes (NFC).

Modified:
cfe/trunk/include/clang/Frontend/ASTUnit.h
cfe/trunk/include/clang/Frontend/DiagnosticRenderer.h
cfe/trunk/include/clang/Frontend/FrontendPluginRegistry.h
cfe/trunk/include/clang/Frontend/TextDiagnosticBuffer.h
cfe/trunk/include/clang/Frontend/VerifyDiagnosticConsumer.h
cfe/trunk/lib/Frontend/ASTUnit.cpp
cfe/trunk/lib/Frontend/DiagnosticRenderer.cpp
cfe/trunk/lib/Frontend/TextDiagnosticBuffer.cpp
cfe/trunk/lib/Frontend/VerifyDiagnosticConsumer.cpp

Modified: cfe/trunk/include/clang/Frontend/ASTUnit.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/ASTUnit.h?rev=328171=328170=328171=diff
==
--- cfe/trunk/include/clang/Frontend/ASTUnit.h (original)
+++ cfe/trunk/include/clang/Frontend/ASTUnit.h Wed Mar 21 17:53:26 2018
@@ -1,4 +1,4 @@
-//===--- ASTUnit.h - ASTUnit utility *- C++ 
-*-===//
+//===- ASTUnit.h - ASTUnit utility --*- C++ 
-*-===//
 //
 // The LLVM Compiler Infrastructure
 //
@@ -16,8 +16,11 @@
 
 #include "clang-c/Index.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/FileSystemOptions.h"
+#include "clang/Basic/LLVM.h"
 #include "clang/Basic/LangOptions.h"
+#include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetOptions.h"
 #include "clang/Lex/HeaderSearchOptions.h"
@@ -26,48 +29,59 @@
 #include "clang/Sema/CodeCompleteConsumer.h"
 #include "clang/Serialization/ASTBitCodes.h"
 #include "clang/Frontend/PrecompiledPreamble.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/ADT/None.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringMap.h"
-#include "llvm/Support/MD5.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/iterator_range.h"
 #include 
+#include 
+#include 
 #include 
 #include 
-#include 
 #include 
 #include 
 
 namespace llvm {
-  class MemoryBuffer;
-}
+
+class MemoryBuffer;
+
+} // namespace llvm
 
 namespace clang {
-class Sema;
+
 class ASTContext;
+class ASTDeserializationListener;
+class ASTMutationListener;
 class ASTReader;
-class CompilerInvocation;
 class CompilerInstance;
+class CompilerInvocation;
 class Decl;
-class DiagnosticsEngine;
 class FileEntry;
 class FileManager;
+class FrontendAction;
 class HeaderSearch;
 class InputKind;
 class MemoryBufferCache;
-class Preprocessor;
-class PreprocessorOptions;
 class PCHContainerOperations;
 class PCHContainerReader;
+class Preprocessor;
+class PreprocessorOptions;
+class Sema;
 class TargetInfo;
-class FrontendAction;
-class ASTDeserializationListener;
 
 namespace vfs {
+
 class FileSystem;
-}
+
+} // namespace vfs
 
 /// \brief Utility class for loading a ASTContext from an AST file.
-///
 class ASTUnit {
 public:
   struct StandaloneFixIt {
@@ -83,7 +97,7 @@ public:
 std::string Message;
 std::string Filename;
 unsigned LocOffset;
-std::vector > Ranges;
+std::vector> Ranges;
 std::vector FixIts;
   };
 
@@ -101,7 +115,7 @@ private:
   std::shared_ptrHSOpts;
   std::shared_ptrPPOpts;
   IntrusiveRefCntPtr Reader;
-  bool HadModuleLoaderFatalFailure;
+  bool HadModuleLoaderFatalFailure = false;
 
   struct ASTWriterData;
   std::unique_ptr WriterData;
@@ -126,22 +140,22 @@ private:
   // OnlyLocalDecls - when true, walking this AST should only visit 
declarations
   // that come from the AST itself, not from included precompiled headers.
   // FIXME: This is temporary; eventually, CIndex will always do this.
-  bool OnlyLocalDecls;
+  bool OnlyLocalDecls = false;
 
   /// \brief Whether to capture any diagnostics produced.
-  bool CaptureDiagnostics;
+  bool CaptureDiagnostics = false;
 
   /// \brief Track whether the main file was loaded from an AST or not.
   bool MainFileIsAST;
 
   /// \brief What kind of translation unit this AST represents.
-  TranslationUnitKind TUKind;
+  TranslationUnitKind TUKind = TU_Complete;
 
   /// \brief Whether we should time each operation.
   bool WantTiming;
 
   /// \brief Whether the ASTUnit should delete the remapped buffers.
-  bool OwnsRemappedFileBuffers;
+  bool OwnsRemappedFileBuffers = true;
   
   /// Track the top-level decls which appeared in an ASTUnit which was loaded
   /// from a source file.
@@ -153,8 +167,8 @@ private:
   std::vector TopLevelDecls;
 
   /// \brief Sorted (by file offset) vector of pairs of file offset/Decl.
-  typedef 

[PATCH] D44753: [Preprocessor] Rename __is_{target -> host}_* function-like builtin macros

2018-03-21 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd added a comment.

I may be a bit biased but I agree with @bob.wilson and @steven_wu.  The current 
names are better from the user’s perspective.  GCC’s build is a very bad 
example as it has runtime components built as part of it (libgcc).  When 
building any code, even in a Canadian cross-compile, the target will always be 
what you are running on.  The preprocessor macros are part of the code that you 
are building for a given target.  The association with the command line option 
makes it more obvious what it is going to use to determine the value.  Having a 
pithy name should also be considered a design goal.  Recreating new terminology 
only muddles the problem.

Even if you are compiling a compiler, there is nothing special.  It is a 
standard user space program that will run on a specific target.  Even if you 
treat it as a perspective of the program, if you bootstrap on Linux, the 
bootstrapping compiler’s Target will be Linux even if the final compiler has a 
target of Windows.  The compiler is answering from the perspective of the 
program :)


Repository:
  rC Clang

https://reviews.llvm.org/D44753



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


[PATCH] D44765: PR36643 Make clang-format support more generic TMarcos

2018-03-21 Thread Teodor Petrov via Phabricator via cfe-commits
obfuscated created this revision.
obfuscated added a reviewer: krasimir.
Herald added a subscriber: klimek.

This patch changes the check for _T to detect TMarcos with a more generic check.
This makes it possible to format wxWidgets projects (where wxT is used a lot) 
correctly.

Patch by Teodor Petrov


Repository:
  rC Clang

https://reviews.llvm.org/D44765

Files:
  lib/Format/ContinuationIndenter.cpp
  lib/Format/FormatToken.h
  lib/Format/FormatTokenLexer.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -7935,6 +7935,47 @@
"_T(\"Xn\"));"));
 }
 
+TEST_F(FormatTest, BreaksStringLiteralsWithin_GenericTMacro) {
+  FormatStyle Style = getLLVMStyleWithColumns(25);
+  EXPECT_EQ(
+  "blablaT(\"aa\")\n"
+  "blablaT(\"aa\")\n"
+  "blablaT(\"\")",
+  format("  blablaT(\"\")", Style));
+  EXPECT_EQ("f(x,\n"
+"  blablaT(\"\")\n"
+"  blablaT(\"aaa\"),\n"
+"  z);",
+format("f(x, blablaT(\"aaa\"), z);", Style));
+
+  // FIXME: Handle embedded spaces in one iteration.
+  //  EXPECT_EQ("blablaT(\"a\")\n"
+  //"blablaT(\"a\")\n"
+  //"blablaT(\"a\")\n"
+  //"blablaT(\"a\")",
+  //format("  blablaT ( \"\" )",
+  //   getLLVMStyleWithColumns(20)));
+  EXPECT_EQ(
+  "blablaT ( \"\" )",
+  format("  blablaT ( \"\" )", Style));
+  EXPECT_EQ("f(\n"
+"#if !TEST\n"
+"blablaT(\"Xn\")\n"
+"#endif\n"
+");",
+format("f(\n"
+   "#if !TEST\n"
+   "blablaT(\"Xn\")\n"
+   "#endif\n"
+   ");"));
+  EXPECT_EQ("f(\n"
+"\n"
+"blablaT(\"Xn\"));",
+format("f(\n"
+   "\n"
+   "blablaT(\"Xn\"));"));
+}
+
 TEST_F(FormatTest, BreaksStringLiteralOperands) {
   // In a function call with two operands, the second can be broken with no line
   // break before it.
Index: lib/Format/FormatTokenLexer.cpp
===
--- lib/Format/FormatTokenLexer.cpp
+++ lib/Format/FormatTokenLexer.cpp
@@ -368,7 +368,7 @@
 return false;
 
   FormatToken *Macro = Tokens[Tokens.size() - 4];
-  if (Macro->TokenText != "_T")
+  if (Macro->TokenText.empty() || !String->TokenText.startswith("\"") || !String->TokenText.endswith("\""))
 return false;
 
   const char *Start = Macro->TokenText.data();
@@ -382,6 +382,7 @@
   String->TokenText, String->OriginalColumn, Style.TabWidth, Encoding);
   String->NewlinesBefore = Macro->NewlinesBefore;
   String->HasUnescapedNewline = Macro->HasUnescapedNewline;
+  String->TMacroStringLiteral = true;
 
   Tokens.pop_back();
   Tokens.pop_back();
Index: lib/Format/FormatToken.h
===
--- lib/Format/FormatToken.h
+++ lib/Format/FormatToken.h
@@ -134,6 +134,9 @@
   /// Token.
   bool HasUnescapedNewline = false;
 
+  /// \brief Whether this is a string literal similar to _T("sdfsdf").
+  bool TMacroStringLiteral = false;
+
   /// \brief The range of the whitespace immediately preceding the \c Token.
   SourceRange WhitespaceRange;
 
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -1599,12 +1599,10 @@
 // FIXME: Store Prefix and Suffix (or PrefixLength and SuffixLength to
 // reduce the overhead) for each FormatToken, which is a string, so that we
 // don't run multiple checks here on the hot path.
-if ((Text.endswith(Postfix = "\"") &&
- (Text.startswith(Prefix = "@\"") || Text.startswith(Prefix = "\"") ||
-  Text.startswith(Prefix = "u\"") || Text.startswith(Prefix = "U\"") ||
-  Text.startswith(Prefix = "u8\"") ||
-  Text.startswith(Prefix = "L\""))) ||
-(Text.startswith(Prefix = "_T(\"") && Text.endswith(Postfix = "\")"))) {
+if (Text.endswith(Postfix = "\"") &&
+(Text.startswith(Prefix = "@\"") || Text.startswith(Prefix = "\"") ||
+ Text.startswith(Prefix = "u\"") || Text.startswith(Prefix = "U\"") ||
+ Text.startswith(Prefix = "u8\"") || Text.startswith(Prefix = "L\""))) {
   // We need this to address the case where there is an unbreakable tail
   // only if certain 

[PATCH] D44764: [clangd] Move GTest printers to separate file

2018-03-21 Thread Marc-Andre Laperle via Phabricator via cfe-commits
malaperle created this revision.
Herald added subscribers: cfe-commits, MaskRay, ioeric, jkorous-apple, 
ilya-biryukov, klimek.

This mitigates a possible issue in tests that print objects on failure. It is
possible that there will be two different instantiations of the printer template
for a given type and some tests could end up calling the wrong (default) one.
For example, it was seen in CodeCompleteTests.cpp when printing CompletionItems
that it would use the wrong printer because the default is also instantiated in
ClangdTests.cpp.

With this change, all tests that need to use printers can include the new header
so that this issue does not occur.

Signed-off-by: Marc-Andre Laperle 


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44764

Files:
  unittests/clangd/ClangdTests.cpp
  unittests/clangd/ClangdUnitTests.cpp
  unittests/clangd/CodeCompleteTests.cpp
  unittests/clangd/CodeCompletionStringsTests.cpp
  unittests/clangd/ContextTests.cpp
  unittests/clangd/FileIndexTests.cpp
  unittests/clangd/FuzzyMatchTests.cpp
  unittests/clangd/HeadersTests.cpp
  unittests/clangd/IndexTests.cpp
  unittests/clangd/JSONExprTests.cpp
  unittests/clangd/Matchers.h
  unittests/clangd/Printers.h
  unittests/clangd/SourceCodeTests.cpp
  unittests/clangd/SymbolCollectorTests.cpp
  unittests/clangd/TUSchedulerTests.cpp
  unittests/clangd/TestFS.cpp
  unittests/clangd/TraceTests.cpp
  unittests/clangd/URITests.cpp
  unittests/clangd/XRefsTests.cpp

Index: unittests/clangd/XRefsTests.cpp
===
--- unittests/clangd/XRefsTests.cpp
+++ unittests/clangd/XRefsTests.cpp
@@ -10,6 +10,7 @@
 #include "ClangdUnit.h"
 #include "Compiler.h"
 #include "Matchers.h"
+#include "Printers.h"
 #include "SyncAPI.h"
 #include "TestFS.h"
 #include "XRefs.h"
@@ -24,15 +25,6 @@
 namespace clangd {
 using namespace llvm;
 
-void PrintTo(const DocumentHighlight , std::ostream *O) {
-  llvm::raw_os_ostream OS(*O);
-  OS << V.range;
-  if (V.kind == DocumentHighlightKind::Read)
-OS << "(r)";
-  if (V.kind == DocumentHighlightKind::Write)
-OS << "(w)";
-}
-
 namespace {
 using testing::ElementsAre;
 using testing::Field;
Index: unittests/clangd/URITests.cpp
===
--- unittests/clangd/URITests.cpp
+++ unittests/clangd/URITests.cpp
@@ -7,6 +7,7 @@
 //
 //===--===//
 
+#include "Printers.h"
 #include "TestFS.h"
 #include "URI.h"
 #include "gmock/gmock.h"
Index: unittests/clangd/TraceTests.cpp
===
--- unittests/clangd/TraceTests.cpp
+++ unittests/clangd/TraceTests.cpp
@@ -7,6 +7,7 @@
 //
 //===--===//
 
+#include "Printers.h"
 #include "Trace.h"
 
 #include "llvm/ADT/DenseMap.h"
Index: unittests/clangd/TestFS.cpp
===
--- unittests/clangd/TestFS.cpp
+++ unittests/clangd/TestFS.cpp
@@ -7,6 +7,7 @@
 //
 //===--===//
 #include "TestFS.h"
+#include "Printers.h"
 #include "llvm/Support/Errc.h"
 #include "gtest/gtest.h"
 
Index: unittests/clangd/TUSchedulerTests.cpp
===
--- unittests/clangd/TUSchedulerTests.cpp
+++ unittests/clangd/TUSchedulerTests.cpp
@@ -8,6 +8,7 @@
 //===--===//
 
 #include "Context.h"
+#include "Printers.h"
 #include "TUScheduler.h"
 #include "TestFS.h"
 #include "gmock/gmock.h"
Index: unittests/clangd/SymbolCollectorTests.cpp
===
--- unittests/clangd/SymbolCollectorTests.cpp
+++ unittests/clangd/SymbolCollectorTests.cpp
@@ -8,6 +8,7 @@
 //===--===//
 
 #include "Annotations.h"
+#include "Printers.h"
 #include "TestFS.h"
 #include "index/SymbolCollector.h"
 #include "index/SymbolYAML.h"
Index: unittests/clangd/SourceCodeTests.cpp
===
--- unittests/clangd/SourceCodeTests.cpp
+++ unittests/clangd/SourceCodeTests.cpp
@@ -6,6 +6,7 @@
 // License. See LICENSE.TXT for details.
 //
 //===--===//
+#include "Printers.h"
 #include "SourceCode.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/raw_os_ostream.h"
Index: unittests/clangd/Printers.h
===
--- /dev/null
+++ unittests/clangd/Printers.h
@@ -0,0 +1,77 @@
+//===-- Printers.h --*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed 

[PATCH] D44763: [analyzer] Add C++17-specific constructor-initializer construction contexts.

2018-03-21 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ created this revision.
NoQ added reviewers: dcoughlin, xazax.hun, a.sidorin, george.karpenkov, szepet.
Herald added subscribers: cfe-commits, rnkovacs.

`CXXCtorInitializer`-based constructors are apparently also affected by the 
C++17 mandatory copy elision, like variable constructors and return value 
constructors. Extend https://reviews.llvm.org/D44597 to support those.


Repository:
  rC Clang

https://reviews.llvm.org/D44763

Files:
  include/clang/Analysis/CFG.h
  include/clang/Analysis/ConstructionContext.h
  lib/Analysis/CFG.cpp
  lib/Analysis/ConstructionContext.cpp
  lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
  test/Analysis/cfg-rich-constructors.cpp

Index: test/Analysis/cfg-rich-constructors.cpp
===
--- test/Analysis/cfg-rich-constructors.cpp
+++ test/Analysis/cfg-rich-constructors.cpp
@@ -252,6 +252,34 @@
   D(double): C(C::get()), c1(new C(C::get())) {}
 };
 
+// Let's see if initializers work well for fields with destructors.
+class E {
+public:
+  static E get();
+  ~E();
+};
+
+class F {
+  E e;
+
+public:
+// FIXME: There should be no temporary destructor in C++17.
+// CHECK: F()
+// CHECK:  1: E::get
+// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, FunctionToPointerDecay, class ctor_initializers::E (*)(
+// CXX11-NEXT: 3: [B1.2]() (CXXRecordTypedCall, [B1.4], [B1.6])
+// CXX11-NEXT: 4: [B1.3] (BindTemporary)
+// CXX11-NEXT: 5: [B1.4] (ImplicitCastExpr, NoOp, const class ctor_initializers::E)
+// CXX11-NEXT: 6: [B1.5]
+// CXX11-NEXT: 7: [B1.6] (CXXConstructExpr, e([B1.6]) (Member initializer), class ctor_initializers
+// CXX11-NEXT: 8: e([B1.7]) (Member initializer)
+// CXX11-NEXT: 9: ~ctor_initializers::E() (Temporary object destructor)
+// CXX17-NEXT: 3: [B1.2]() (CXXRecordTypedCall, e([B1.4]) (Member initializer), [B1.4])
+// CXX17-NEXT: 4: [B1.3] (BindTemporary)
+// CXX17-NEXT: 5: e([B1.4]) (Member initializer)
+// CXX17-NEXT: 6: ~ctor_initializers::E() (Temporary object destructor)
+  F(): e(E::get()) {}
+};
 } // end namespace ctor_initializers
 
 namespace return_stmt_without_dtor {
Index: lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -134,7 +134,7 @@
   makeZeroElementRegion(State, LValue, Ty, CallOpts.IsArrayCtorOrDtor);
   return LValue.getAsRegion();
 }
-case ConstructionContext::ConstructorInitializerKind: {
+case ConstructionContext::SimpleConstructorInitializerKind: {
   const auto *ICC = cast(CC);
   const auto *Init = ICC->getCXXCtorInitializer();
   assert(Init->isAnyMemberInitializer());
@@ -217,6 +217,7 @@
 }
 case ConstructionContext::CXX17ElidedCopyVariableKind:
 case ConstructionContext::CXX17ElidedCopyReturnedValueKind:
+case ConstructionContext::CXX17ElidedCopyConstructorInitializerKind:
   // Not implemented yet.
   break;
 }
Index: lib/Analysis/ConstructionContext.cpp
===
--- lib/Analysis/ConstructionContext.cpp
+++ lib/Analysis/ConstructionContext.cpp
@@ -62,21 +62,31 @@
   // lifetime extension on the parent layer.
   if (const ConstructionContextLayer *ParentLayer = TopLayer->getParent()) {
 assert(ParentLayer->isLast());
+// C++17 *requires* elision of the constructor at the return site
+// and at variable/member initialization site, while previous standards
+// were allowing an optional elidable constructor.
+// This is the C++17 copy-elided construction into a ctor initializer.
+if (const CXXCtorInitializer *I = ParentLayer->getTriggerInit()) {
+  return create<
+  CXX17ElidedCopyConstructorInitializerConstructionContext>(C,
+I, BTE);
+}
+assert(ParentLayer->getTriggerStmt() &&
+   "Non-statement-based layers have been handled above!");
+// This is the normal, non-C++17 case: a temporary object which has
+// both destruction and materialization info attached to it in the AST.
 if ((MTE = dyn_cast(
  ParentLayer->getTriggerStmt( {
-  // A temporary object which has both destruction and
-  // materialization info.
   return create(C, BTE, MTE);
 }
-// C++17 *requires* elision of the constructor at the return site
-// and at variable initialization site, while previous standards
-// were allowing an optional elidable constructor.
+// This is C++17 copy-elided construction into return statement.
 if (auto *RS = dyn_cast(ParentLayer->getTriggerStmt())) {
   assert(!RS->getRetValue()->getType().getCanonicalType()
 

[PATCH] D44725: [analyzer] NFC: Move construction context allocation into a helper method.

2018-03-21 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

> E.g. we have `llvm::make_shared<>()`, so we could also have 
> `Allocator::make_obj<...>(...)`

I like your thinking, but that'd require me to make the allocator my friend 
class (:


https://reviews.llvm.org/D44725



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


[PATCH] D38216: [C++17] Fix class template argument deduction for default constructors without an initializer

2018-03-21 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added inline comments.
This revision is now accepted and ready to land.



Comment at: test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.class.deduct/p1.cpp:17
 };
 extern A x; // expected-error {{requires an initializer}}
+static A y;

The diagnostic we produce in this case is not very good. The problem is not 
that the declaration requires an initializer (how can a forward declaration 
like this require an initializer?), instead the problem is that type deduction 
is only possible for the initializing declaration of a variable.


https://reviews.llvm.org/D38216



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


[PATCH] D41148: [libcxx] implement declarations based on P0214R7.

2018-03-21 Thread Tim Shen via Phabricator via cfe-commits
timshen updated this revision to Diff 139393.
timshen marked 7 inline comments as done.
timshen added a comment.

Address comments.


https://reviews.llvm.org/D41148

Files:
  libcxx/include/experimental/__config
  libcxx/include/experimental/simd
  libcxx/test/std/experimental/simd/nothing_to_do.pass.cpp
  libcxx/test/std/experimental/simd/simd.casts/simd_cast.pass.cpp
  libcxx/test/std/experimental/simd/simd.casts/static_simd_cast.pass.cpp
  libcxx/test/std/experimental/simd/simd.cons/broadcast.pass.cpp
  libcxx/test/std/experimental/simd/simd.cons/geneartor.pass.cpp
  libcxx/test/std/experimental/simd/simd.traits/abi_for_size.pass.cpp
  libcxx/test/std/experimental/simd/simd.traits/is_abi_tag.pass.cpp
  libcxx/test/std/experimental/simd/simd.traits/is_simd.pass.cpp
  libcxx/test/std/experimental/simd/simd.traits/is_simd_flag_type.pass.cpp
  libcxx/test/std/experimental/simd/simd.traits/is_simd_mask.pass.cpp

Index: libcxx/test/std/experimental/simd/simd.traits/is_simd_mask.pass.cpp
===
--- /dev/null
+++ libcxx/test/std/experimental/simd/simd.traits/is_simd_mask.pass.cpp
@@ -0,0 +1,121 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// UNSUPPORTED: c++98, c++03
+
+// 
+//
+// [simd.traits]
+// template  struct is_simd_mask;
+// template  inline constexpr bool is_simd_mask_v = is_simd_mask::value;
+
+#include 
+#include 
+#include "test_macros.h"
+
+using namespace std::experimental::parallelism_v2;
+
+static_assert(is_simd_mask::value, "");
+static_assert(is_simd_mask::value, "");
+static_assert(is_simd_mask::value, "");
+static_assert(is_simd_mask::value, "");
+static_assert(is_simd_mask::value, "");
+static_assert(is_simd_mask::value, "");
+static_assert(is_simd_mask::value, "");
+static_assert(is_simd_mask::value, "");
+static_assert(is_simd_mask::value, "");
+static_assert(is_simd_mask::value, "");
+
+static_assert(is_simd_mask>::value, "");
+static_assert(is_simd_mask>::value, "");
+static_assert(is_simd_mask>::value, "");
+static_assert(is_simd_mask>::value, "");
+static_assert(is_simd_mask>::value, "");
+static_assert(is_simd_mask>::value, "");
+static_assert(is_simd_mask>::value, "");
+static_assert(is_simd_mask>::value, "");
+static_assert(is_simd_mask>::value, "");
+static_assert(is_simd_mask>::value, "");
+
+static_assert(is_simd_mask>::value, "");
+static_assert(is_simd_mask>::value, "");
+static_assert(is_simd_mask>::value, "");
+static_assert(is_simd_mask>::value, "");
+static_assert(is_simd_mask>::value, "");
+static_assert(is_simd_mask>::value, "");
+static_assert(is_simd_mask>::value, "");
+static_assert(is_simd_mask>::value, "");
+static_assert(is_simd_mask>::value, "");
+static_assert(is_simd_mask>::value, "");
+
+static_assert(is_simd_mask>::value, "");
+static_assert(is_simd_mask>::value, "");
+static_assert(is_simd_mask>::value, "");
+static_assert(is_simd_mask>::value, "");
+static_assert(is_simd_mask>::value, "");
+static_assert(is_simd_mask>::value, "");
+static_assert(is_simd_mask>::value, "");
+static_assert(is_simd_mask>::value, "");
+static_assert(is_simd_mask>::value, "");
+static_assert(is_simd_mask>::value, "");
+
+static_assert(!is_simd_mask::value, "");
+
+#if TEST_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) &&\
+!defined(_LIBCPP_HAS_NO_INLINE_VARIABLES)
+
+static_assert(is_simd_mask_v, "");
+static_assert(is_simd_mask_v, "");
+static_assert(is_simd_mask_v, 

[PATCH] D41148: [libcxx] implement declarations based on P0214R7.

2018-03-21 Thread Tim Shen via Phabricator via cfe-commits
timshen added inline comments.



Comment at: libcxx/include/experimental/simd:669
+
+#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+template 

mclow.lists wrote:
> Isn't the parallelism TS based on C++17?
> 
I intended to have a C++11 (and C++14) compatible implementation.


https://reviews.llvm.org/D41148



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


[PATCH] D44753: [Preprocessor] Rename __is_{target -> host}_* function-like builtin macros

2018-03-21 Thread John Ericson via Phabricator via cfe-commits
Ericson2314 added a comment.

@steven_wu Maybe there is something outside of "build" "host" or "target" that 
won't suffer from these problems of vantage point? `__will_be_built_for_*` for 
a very lengthy example, but hopefully something shorter too?


Repository:
  rC Clang

https://reviews.llvm.org/D44753



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


[PATCH] D44725: [analyzer] NFC: Move construction context allocation into a helper method.

2018-03-21 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov accepted this revision.
george.karpenkov added a comment.
This revision is now accepted and ready to land.

LGTM, but would actually make even more sense as a static function for the 
allocator.
E.g. we have `llvm::make_shared<>()`, so we could also have 
`Allocator::make_obj<...>(...)`


https://reviews.llvm.org/D44725



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


[PATCH] D41240: [Solaris] __float128 is supported on Solaris/x86

2018-03-21 Thread Rainer Orth via Phabricator via cfe-commits
ro added a comment.

ping^3


Repository:
  rC Clang

https://reviews.llvm.org/D41240



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


[PATCH] D44725: [analyzer] NFC: Move construction context allocation into a helper method.

2018-03-21 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 139389.
NoQ added a comment.

I'd rather keep the helper method within the class. This allows us to keep 
constructors private, which is something i forgot to do originally.


https://reviews.llvm.org/D44725

Files:
  include/clang/Analysis/ConstructionContext.h
  lib/Analysis/ConstructionContext.cpp

Index: lib/Analysis/ConstructionContext.cpp
===
--- lib/Analysis/ConstructionContext.cpp
+++ lib/Analysis/ConstructionContext.cpp
@@ -48,15 +48,13 @@
   if (const Stmt *S = TopLayer->getTriggerStmt()) {
 if (const auto *DS = dyn_cast(S)) {
   assert(TopLayer->isLast());
-  auto *CC =
-  C.getAllocator().Allocate();
-  return new (CC) SimpleVariableConstructionContext(DS);
-} else if (const auto *NE = dyn_cast(S)) {
+  return create(C, DS);
+}
+if (const auto *NE = dyn_cast(S)) {
   assert(TopLayer->isLast());
-  auto *CC =
-  C.getAllocator().Allocate();
-  return new (CC) NewAllocatedObjectConstructionContext(NE);
-} else if (const auto *BTE = dyn_cast(S)) {
+  return create(C, NE);
+}
+if (const auto *BTE = dyn_cast(S)) {
   const MaterializeTemporaryExpr *MTE = nullptr;
   assert(BTE->getType().getCanonicalType()
 ->getAsCXXRecordDecl()->hasNonTrivialDestructor());
@@ -68,60 +66,45 @@
  ParentLayer->getTriggerStmt( {
   // A temporary object which has both destruction and
   // materialization info.
-  auto *CC =
-  C.getAllocator().Allocate();
-  return new (CC) TemporaryObjectConstructionContext(BTE, MTE);
+  return create(C, BTE, MTE);
 }
 // C++17 *requires* elision of the constructor at the return site
 // and at variable initialization site, while previous standards
 // were allowing an optional elidable constructor.
 if (auto *RS = dyn_cast(ParentLayer->getTriggerStmt())) {
   assert(!RS->getRetValue()->getType().getCanonicalType()
 ->getAsCXXRecordDecl()->hasTrivialDestructor());
-  auto *CC =
-  C.getAllocator()
-  .Allocate<
-  CXX17ElidedCopyReturnedValueConstructionContext>();
-  return new (CC)
-  CXX17ElidedCopyReturnedValueConstructionContext(RS, BTE);
+  return create(C,
+   RS, BTE);
 }
 if (auto *DS = dyn_cast(ParentLayer->getTriggerStmt())) {
   assert(!cast(DS->getSingleDecl())->getType()
   .getCanonicalType()->getAsCXXRecordDecl()
   ->hasTrivialDestructor());
-  auto *CC =
-  C.getAllocator()
-  .Allocate();
-  return new (CC) CXX17ElidedCopyVariableConstructionContext(DS, BTE);
+  return create(C, DS, BTE);
 }
 llvm_unreachable("Unexpected construction context with destructor!");
   }
   // A temporary object that doesn't require materialization.
-  auto *CC =
-  C.getAllocator().Allocate();
-  return new (CC)
-  TemporaryObjectConstructionContext(BTE, /*MTE=*/nullptr);
-} else if (const auto *MTE = dyn_cast(S)) {
+  return create(C, BTE, /*MTE=*/nullptr);
+}
+if (const auto *MTE = dyn_cast(S)) {
   // If the object requires destruction and is not lifetime-extended,
   // then it must have a BTE within its MTE.
   assert(MTE->getType().getCanonicalType()
 ->getAsCXXRecordDecl()->hasTrivialDestructor() ||
  MTE->getStorageDuration() != SD_FullExpression);
   assert(TopLayer->isLast());
-  auto *CC =
-  C.getAllocator().Allocate();
-  return new (CC) TemporaryObjectConstructionContext(nullptr, MTE);
-} else if (const auto *RS = dyn_cast(S)) {
+  return create(C, nullptr, MTE);
+}
+if (const auto *RS = dyn_cast(S)) {
   assert(TopLayer->isLast());
-  auto *CC =
-  C.getAllocator().Allocate();
-  return new (CC) SimpleReturnedValueConstructionContext(RS);
+  return create(C, RS);
 }
+llvm_unreachable("Unexpected construction context with statement!");
   } else if (const CXXCtorInitializer *I = TopLayer->getTriggerInit()) {
 assert(TopLayer->isLast());
-auto *CC =
-C.getAllocator().Allocate();
-return new (CC) ConstructorInitializerConstructionContext(I);
+return create(C, I);
   }
   llvm_unreachable("Unexpected construction context!");
 }
Index: include/clang/Analysis/ConstructionContext.h
===
--- include/clang/Analysis/ConstructionContext.h
+++ include/clang/Analysis/ConstructionContext.h
@@ -118,6 +118,14 @@
   // via createFromLayers().
   explicit ConstructionContext(Kind K) : K(K) {}
 
+private:
+  // A helper function for 

[PATCH] D44745: [HWASan] Port HWASan to Linux x86-64 (clang)

2018-03-21 Thread Evgenii Stepanov via Phabricator via cfe-commits
eugenis added inline comments.



Comment at: lib/Driver/SanitizerArgs.cpp:33
   NotAllowedWithMinimalRuntime = Vptr,
-  RequiresPIE = DataFlow | Scudo,
+  RequiresPIE = DataFlow | HWAddress | Scudo,
   NeedsUnwindTables = Address | HWAddress | Thread | Memory | DataFlow,

I did not realize hwasan was not mentioned in RequiresPIE before.
Could you add a test for it?



Comment at: test/Driver/asan.c:12
-// RUN: %clang -O2 -target aarch64-unknown-linux -fsanitize=hwaddress %s -S 
-emit-llvm -o - | FileCheck %s --check-prefix=CHECK-HWASAN
-// RUN: %clang -O3 -target aarch64-unknown-linux -fsanitize=hwaddress %s -S 
-emit-llvm -o - | FileCheck %s --check-prefix=CHECK-HWASAN
 // Verify that -fsanitize={address,kernel-address} invoke ASan and KASan 
instrumentation.

Don't replace existing tests!
Add new ones.



Repository:
  rC Clang

https://reviews.llvm.org/D44745



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


[PATCH] D43737: Improve -Winfinite-recursion

2018-03-21 Thread Richard Trieu via Phabricator via cfe-commits
rtrieu accepted this revision.
rtrieu added a comment.
This revision is now accepted and ready to land.

Looks good.  Ready to commit.


https://reviews.llvm.org/D43737



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


[PATCH] D41148: [libcxx] implement declarations based on P0214R7.

2018-03-21 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists added a comment.

I'm going to stop here, because all the things I've noted are ticky-tack; 
formatting and minor changes.
More substantial comments coming soon.




Comment at: libcxx/include/experimental/simd:40
+template  inline constexpr bool is_abi_tag_v = is_abi_tag::value;
+template  struct is_simd;
+template  inline constexpr bool is_simd_v = is_simd::value;

A blank line between the separate groups (as in the paper) will make this much 
easier to read



Comment at: libcxx/include/experimental/simd:67
+template  see below simd_cast(const simd&);
+
+template  see below static_simd_cast(const 
simd&);

And here you have an extra line - go figure.



Comment at: libcxx/include/experimental/simd:113
+template  int find_last_set(const simd_mask&);
+bool all_of(see below ) noexcept;
+bool any_of(see below ) noexcept;

blank line, extra space `(see below )` should be `(see below)`



Comment at: libcxx/include/experimental/simd:144
+const_where_expression, const simd_mask>
+where(const nodeduce_t>&, const simd_mask&) noexcept;
+

This is better formatting than in the paper :-)



Comment at: libcxx/include/experimental/simd:316
+template  using samesize = fixed_size_simd; // 
exposition only
+template  floatv acos(floatv x);
+template  doublev acos(doublev x);

These would be much easier to read lined up, and with blank lines.

```
template  floatv   acos(floatv   x);
template  doublev  acos(doublev  x);
template  ldoublev acos(ldoublev x);

template  floatv   asin(floatv   x);
template  doublev  asin(doublev  x);
template  ldoublev asin(ldoublev x);

```




Comment at: libcxx/include/experimental/simd:626
+constexpr auto __is_non_narrowing_convertible_impl(_From a [[gnu::unused]])
+-> decltype(_To{a}, true) {
+  return true;

Do you need the trailing return type here? instead of something like 
`decltype(_to{declval<_From>()})`

Then you don't need to name `a`, and can get rid of the (gcc-specific) 
attribute.



Comment at: libcxx/include/experimental/simd:653
+constexpr _Tp __variadic_sum() {
+  return {};
+}

This won't work if `_Tp` has an explicit default ctor (which is probably not 
true for anything in SIMD).  Do you lose anything by writing `return _Tp{}` ?




Comment at: libcxx/include/experimental/simd:669
+
+#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+template 

Isn't the parallelism TS based on C++17?



https://reviews.llvm.org/D41148



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


[PATCH] D41217: [Concepts] Concept Specialization Expressions

2018-03-21 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added inline comments.



Comment at: lib/AST/ExprCXX.cpp:1478
+  {
+// We do not want error diagnostics escaping here.
+Sema::SFINAETrap Trap(S);

saar.raz wrote:
> hubert.reinterpretcast wrote:
> > saar.raz wrote:
> > > faisalv wrote:
> > > > Hubert: This needs a TODO: the idea is not to drop SFINAE errors, but 
> > > > to avoid instantiation that may trigger errors not in the immediate 
> > > > context of instantiation. The substitution needs to happen piecewise.
> > > Could you elaborate/give an example where this handling is inappropriate?
> > Determining satisfaction requires normalization (lazy normalization should 
> > be considered).
> > The determination of satisfaction then proceeds by handling the left-hand 
> > side of conjunction and disjunction constraints before possibly 
> > substituting into the right-hand side; i.e., there is short-circuiting 
> > behaviour.
> > 
> > Example:
> > ```
> > template 
> > concept C = true;
> > 
> > template 
> > struct Q { static constexpr T value = nullptr; };
> > 
> > template 
> > requires C || T::value
> > struct A { };
> > 
> > template 
> > requires C || Q::value
> > struct B { };
> > 
> > A a; // okay
> > B b; // okay
> > ```
> > 
> OK I see your point. You said this should be a TODO - do you think this 
> should be delayed to a further patch (namely D41569, where we actually deal 
> with diagnostics and stuff)?
> About lazy normalization, I tend to think it is not a good idea - you'll 
> probably check satisfaction for every defined constraint expression at some 
> point, and do that many more times than you'd define a new one
The status quo of this patch with regards to this topic is not quite something 
that I would like to commit onto trunk.

As for normalization: The process is needed for distinct purposes with somewhat 
differing output requirements.
The order-dependent form (to check for satisfaction) can be integrated with the 
substitution and evaluation: that is, the output of normalization is realized 
in control flow, and not "stored".

The order-independent form (to check for subsumption) could be delayed until 
overload resolution with a constrained candidate reaches the point where 
determining subsumption is necessary.



Repository:
  rC Clang

https://reviews.llvm.org/D41217



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


[PATCH] D44753: [Preprocessor] Rename __is_{target -> host}_* function-like builtin macros

2018-03-21 Thread Steven Wu via Phabricator via cfe-commits
steven_wu added a comment.

I am not trying to discuss which english word is best here. My point is simply:

1. macros are evaluated during compile time
2. "host"means either the platform you compiled on during compile time or the 
platform you run on during the runtime
3. __is_host_* is not a good name, because it is misleading as it either 
implies "runtime" as a compile-time constant, or indicates the wrong platform.


Repository:
  rC Clang

https://reviews.llvm.org/D44753



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


[PATCH] D34331: func.wrap.func.con: Unset function before destroying anything

2018-03-21 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added inline comments.



Comment at: libcxx/include/functional:1722-1733
 if (__f.__f_ == 0)
 __f_ = 0;
 else if ((void *)__f.__f_ == &__f.__buf_)
 {
 __f_ = __as_base(&__buf_);
 __f.__f_->__clone(__f_);
 }

Here is the similar code I've mentioned.



Comment at: libcxx/include/functional:1821
 {
-if ((void *)__f_ == &__buf_)
-__f_->destroy();
-else if (__f_)
-__f_->destroy_deallocate();
-__f_ = 0;
+function::operator=(nullptr);
 if (__f.__f_ == 0)

mclow.lists wrote:
> Couldn't this be more clearly written as `*this = nullptr;` ?
Personally I prefer to call operator explicitly but checking the code shows it 
isn't very common. Will change.



Comment at: libcxx/include/functional:1822
+function::operator=(nullptr);
 if (__f.__f_ == 0)
 __f_ = 0;

mclow.lists wrote:
> At this point `__f_ == 0` (because we just set it to 0).
> We probably don't need to do that again.
> 
This code is the same as in `function(function&& __f)`. Do you think there is 
enough value to deviate from that implementation?



Comment at: libcxx/include/functional:1843
 __f_ = 0;
+if ((void *)__t == &__buf_)
+__t->destroy();

mclow.lists wrote:
> I see this dance 4x in `` and once here. Did you give any 
> thought to making it a function of `__base`?  Maybe call it `__clear`?
> 
> Then line #1821 can be written as `__clear();`
> 
> 
Haven't really thought about that. Not sure it can be easily done. All `__base` 
classes are separate templates and don't have a common ancestor. Don't want to 
introduce macros as it doesn't look like libc++ style. You achieve the most 
consistency with current code by copy-pasting and repeating the same dance a 
few times.


https://reviews.llvm.org/D34331



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


r328166 - Fix for LLVM change (Transforms/Utils/Local.h -> Analysis/Utils/Local.h)

2018-03-21 Thread David Blaikie via cfe-commits
Author: dblaikie
Date: Wed Mar 21 15:34:27 2018
New Revision: 328166

URL: http://llvm.org/viewvc/llvm-project?rev=328166=rev
Log:
Fix for LLVM change (Transforms/Utils/Local.h -> Analysis/Utils/Local.h)

Modified:
cfe/trunk/lib/CodeGen/CGCall.cpp

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=328166=328165=328166=diff
==
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Wed Mar 21 15:34:27 2018
@@ -29,15 +29,15 @@
 #include "clang/CodeGen/SwiftCallingConv.h"
 #include "clang/Frontend/CodeGenOptions.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/Analysis/Utils/Local.h"
 #include "llvm/Analysis/ValueTracking.h"
 #include "llvm/IR/Attributes.h"
-#include "llvm/IR/CallingConv.h"
 #include "llvm/IR/CallSite.h"
+#include "llvm/IR/CallingConv.h"
 #include "llvm/IR/DataLayout.h"
 #include "llvm/IR/InlineAsm.h"
-#include "llvm/IR/Intrinsics.h"
 #include "llvm/IR/IntrinsicInst.h"
-#include "llvm/Transforms/Utils/Local.h"
+#include "llvm/IR/Intrinsics.h"
 using namespace clang;
 using namespace CodeGen;
 


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


[PATCH] D44691: [CUDA] Disable LTO for device-side compilations.

2018-03-21 Thread Artem Belevich via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL328161: [CUDA] Disable LTO for device-side compilations. 
(authored by tra, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D44691?vs=139151=139381#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D44691

Files:
  cfe/trunk/include/clang/Driver/Driver.h
  cfe/trunk/lib/Driver/Driver.cpp
  cfe/trunk/lib/Driver/ToolChains/Clang.cpp
  cfe/trunk/test/Driver/lto.cu
  cfe/trunk/test/Driver/thinlto.cu

Index: cfe/trunk/include/clang/Driver/Driver.h
===
--- cfe/trunk/include/clang/Driver/Driver.h
+++ cfe/trunk/include/clang/Driver/Driver.h
@@ -456,8 +456,10 @@
   /// ConstructAction - Construct the appropriate action to do for
   /// \p Phase on the \p Input, taking in to account arguments
   /// like -fsyntax-only or --analyze.
-  Action *ConstructPhaseAction(Compilation , const llvm::opt::ArgList ,
-   phases::ID Phase, Action *Input) const;
+  Action *ConstructPhaseAction(
+  Compilation , const llvm::opt::ArgList , phases::ID Phase,
+  Action *Input,
+  Action::OffloadKind TargetDeviceOffloadKind = Action::OFK_None) const;
 
   /// BuildJobsForAction - Construct the jobs to perform for the action \p A and
   /// return an InputInfo for the result of running \p A.  Will only construct
Index: cfe/trunk/test/Driver/thinlto.cu
===
--- cfe/trunk/test/Driver/thinlto.cu
+++ cfe/trunk/test/Driver/thinlto.cu
@@ -0,0 +1,50 @@
+// -flto=thin causes a switch to llvm-bc object files.
+// RUN: %clangxx -ccc-print-phases -nocudainc -nocudalib -c %s -flto=thin 2> %t
+// RUN: FileCheck -check-prefix=CHECK-COMPILE-ACTIONS < %t %s
+//
+// CHECK-COMPILE-ACTIONS: 2: compiler, {1}, ir, (host-cuda)
+// CHECK-COMPILE-ACTIONS-NOT: lto-bc
+// CHECK-COMPILE-ACTIONS: 12: backend, {11}, lto-bc, (host-cuda)
+
+// RUN: %clangxx -ccc-print-phases -nocudainc -nocudalib %s -flto=thin 2> %t
+// RUN: FileCheck -check-prefix=CHECK-COMPILELINK-ACTIONS < %t %s
+//
+// CHECK-COMPILELINK-ACTIONS: 0: input, "{{.*}}thinlto.cu", cuda, (host-cuda)
+// CHECK-COMPILELINK-ACTIONS: 1: preprocessor, {0}, cuda-cpp-output
+// CHECK-COMPILELINK-ACTIONS: 2: compiler, {1}, ir, (host-cuda)
+// CHECK-COMPILELINK-ACTIONS: 3: input, "{{.*}}thinlto.cu", cuda, (device-cuda, sm_20)
+// CHECK-COMPILELINK-ACTIONS: 4: preprocessor, {3}, cuda-cpp-output, (device-cuda, sm_20)
+// CHECK-COMPILELINK-ACTIONS: 5: compiler, {4}, ir, (device-cuda, sm_20)
+// CHECK-COMPILELINK-ACTIONS: 6: backend, {5}, assembler, (device-cuda, sm_20)
+// CHECK-COMPILELINK-ACTIONS: 7: assembler, {6}, object, (device-cuda, sm_20)
+// CHECK-COMPILELINK-ACTIONS: 8: offload, "device-cuda (nvptx64-nvidia-cuda:sm_20)" {7}, object
+// CHECK-COMPILELINK-ACTIONS: 9: offload, "device-cuda (nvptx64-nvidia-cuda:sm_20)" {6}, assembler
+// CHECK-COMPILELINK-ACTIONS: 10: linker, {8, 9}, cuda-fatbin, (device-cuda)
+// CHECK-COMPILELINK-ACTIONS: 11: offload, "host-cuda {{.*}}" {2}, "device-cuda{{.*}}" {10}, ir
+// CHECK-COMPILELINK-ACTIONS: 12: backend, {11}, lto-bc, (host-cuda)
+// CHECK-COMPILELINK-ACTIONS: 13: linker, {12}, image, (host-cuda)
+
+// -flto=thin should cause link using gold plugin with thinlto option,
+// also confirm that it takes precedence over earlier -fno-lto and -flto=full.
+// RUN: %clangxx -nocudainc -nocudalib \
+// RUN:-target x86_64-unknown-linux -### %s -flto=full -fno-lto -flto=thin 2> %t
+// RUN: FileCheck -check-prefix=CHECK-LINK-THIN-ACTION < %t %s
+//
+// CHECK-LINK-THIN-ACTION: "-plugin" "{{.*}}{{[/\\]}}LLVMgold.{{dll|dylib|so}}"
+// CHECK-LINK-THIN-ACTION: "-plugin-opt=thinlto"
+
+// Check that subsequent -flto=full takes precedence
+// RUN: %clangxx -nocudainc -nocudalib \
+// RUN:-target x86_64-unknown-linux -### %s -flto=thin -flto=full 2> %t
+// RUN: FileCheck -check-prefix=CHECK-LINK-FULL-ACTION < %t %s
+//
+// CHECK-LINK-FULL-ACTION: "-plugin" "{{.*}}{{[/\\]}}LLVMgold.{{dll|dylib|so}}"
+// CHECK-LINK-FULL-ACTION-NOT: "-plugin-opt=thinlto"
+
+// Check that subsequent -fno-lto takes precedence
+// RUN: %clangxx -nocudainc -nocudalib \
+// RUN:-target x86_64-unknown-linux -### %s -flto=thin -fno-lto 2> %t
+// RUN: FileCheck -check-prefix=CHECK-LINK-NOLTO-ACTION < %t %s
+//
+// CHECK-LINK-NOLTO-ACTION-NOT: "-plugin" "{{.*}}{{[/\\]}}LLVMgold.{{dll|dylib|so}}"
+// CHECK-LINK-NOLTO-ACTION-NOT: "-plugin-opt=thinlto"
Index: cfe/trunk/test/Driver/lto.cu
===
--- cfe/trunk/test/Driver/lto.cu
+++ cfe/trunk/test/Driver/lto.cu
@@ -0,0 +1,76 @@
+// -flto causes a switch to llvm-bc object files.
+// RUN: %clangxx -nocudainc -nocudalib -ccc-print-phases -c %s -flto 2> %t
+// RUN: FileCheck -check-prefix=CHECK-COMPILE-ACTIONS < %t %s
+//
+// CHECK-COMPILE-ACTIONS: 2: compiler, {1}, ir, 

r328161 - [CUDA] Disable LTO for device-side compilations.

2018-03-21 Thread Artem Belevich via cfe-commits
Author: tra
Date: Wed Mar 21 15:22:59 2018
New Revision: 328161

URL: http://llvm.org/viewvc/llvm-project?rev=328161=rev
Log:
[CUDA] Disable LTO for device-side compilations.

This fixes host-side LTO during CUDA compilation. Before, LTO
pipeline construction was clashing with CUDA pipeline construction.

At the moment there's no point doing LTO on device side as each
device-side TU is a complete program.  We will need to figure out
compilation pipeline construction for the device-side LTO when we
have working support for multi-TU device-side CUDA compilation.

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

Added:
cfe/trunk/test/Driver/lto.cu
cfe/trunk/test/Driver/thinlto.cu
Modified:
cfe/trunk/include/clang/Driver/Driver.h
cfe/trunk/lib/Driver/Driver.cpp
cfe/trunk/lib/Driver/ToolChains/Clang.cpp

Modified: cfe/trunk/include/clang/Driver/Driver.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Driver.h?rev=328161=328160=328161=diff
==
--- cfe/trunk/include/clang/Driver/Driver.h (original)
+++ cfe/trunk/include/clang/Driver/Driver.h Wed Mar 21 15:22:59 2018
@@ -456,8 +456,10 @@ public:
   /// ConstructAction - Construct the appropriate action to do for
   /// \p Phase on the \p Input, taking in to account arguments
   /// like -fsyntax-only or --analyze.
-  Action *ConstructPhaseAction(Compilation , const llvm::opt::ArgList ,
-   phases::ID Phase, Action *Input) const;
+  Action *ConstructPhaseAction(
+  Compilation , const llvm::opt::ArgList , phases::ID Phase,
+  Action *Input,
+  Action::OffloadKind TargetDeviceOffloadKind = Action::OFK_None) const;
 
   /// BuildJobsForAction - Construct the jobs to perform for the action \p A 
and
   /// return an InputInfo for the result of running \p A.  Will only construct

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=328161=328160=328161=diff
==
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Wed Mar 21 15:22:59 2018
@@ -2171,7 +2171,7 @@ class OffloadingActionBuilder final {
   break;
 
 CudaDeviceActions[I] = C.getDriver().ConstructPhaseAction(
-C, Args, Ph, CudaDeviceActions[I]);
+C, Args, Ph, CudaDeviceActions[I], Action::OFK_Cuda);
 
 if (Ph == phases::Assemble)
   break;
@@ -3011,8 +3011,9 @@ void Driver::BuildActions(Compilation 
   Args.ClaimAllArgs(options::OPT_cuda_compile_host_device);
 }
 
-Action *Driver::ConstructPhaseAction(Compilation , const ArgList ,
- phases::ID Phase, Action *Input) const {
+Action *Driver::ConstructPhaseAction(
+Compilation , const ArgList , phases::ID Phase, Action *Input,
+Action::OffloadKind TargetDeviceOffloadKind) const {
   llvm::PrettyStackTraceString CrashInfo("Constructing phase actions");
 
   // Some types skip the assembler phase (e.g., llvm-bc), but we can't
@@ -3074,7 +3075,7 @@ Action *Driver::ConstructPhaseAction(Com
 return C.MakeAction(Input, types::TY_LLVM_BC);
   }
   case phases::Backend: {
-if (isUsingLTO()) {
+if (isUsingLTO() && TargetDeviceOffloadKind == Action::OFK_None) {
   types::ID Output =
   Args.hasArg(options::OPT_S) ? types::TY_LTO_IR : types::TY_LTO_BC;
   return C.MakeAction(Input, Output);

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=328161=328160=328161=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Wed Mar 21 15:22:59 2018
@@ -3249,7 +3249,11 @@ void Clang::ConstructJob(Compilation ,
 if (JA.getType() == types::TY_LLVM_BC)
   CmdArgs.push_back("-emit-llvm-uselists");
 
-if (D.isUsingLTO()) {
+// Device-side jobs do not support LTO.
+bool isDeviceOffloadAction = !(JA.isDeviceOffloading(Action::OFK_None) ||
+   JA.isDeviceOffloading(Action::OFK_Host));
+
+if (D.isUsingLTO() && !isDeviceOffloadAction) {
   Args.AddLastArg(CmdArgs, options::OPT_flto, options::OPT_flto_EQ);
 
   // The Darwin and PS4 linkers currently use the legacy LTO API, which

Added: cfe/trunk/test/Driver/lto.cu
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/lto.cu?rev=328161=auto
==
--- cfe/trunk/test/Driver/lto.cu (added)
+++ cfe/trunk/test/Driver/lto.cu Wed Mar 21 15:22:59 2018
@@ -0,0 +1,76 @@
+// -flto causes a switch to llvm-bc object files.
+// RUN: %clangxx -nocudainc -nocudalib -ccc-print-phases -c %s -flto 2> %t
+// RUN: 

[PATCH] D44753: [Preprocessor] Rename __is_{target -> host}_* function-like builtin macros

2018-03-21 Thread John Ericson via Phabricator via cfe-commits
Ericson2314 added a comment.

> I'm sure I could fine a GCC example

FWIW  
https://github.com/gcc-mirror/gcc/blob/master/gcc/config/aarch64/aarch64.c vs 
https://github.com/gcc-mirror/gcc/blob/master/gcc/common/config/aarch64/aarch64-common.c

@steven_wu

> It is not about matching command line name to builtin marco name.

Whew :)

> "target" is the platform we are compiling for, whether it is host or device 
> or something else.

I'm in total agreement, if we are saying that from the compiler's perspective.

> It is a different concept when you talking about cross-compiling, which 
> "target" is strictly not host and "build" or "host" doesn't matter to 
> compiler at all.

So to be clear, I don't think there is a legitament reason *why* GHC and GCC 
care about the target platform at compile time. LLVM's approaching of always 
being multi-target and only choosing at run-time is far superior. Part of the 
philosophy behind that approach is moving towards a world where everything just 
works whether cross compiling or not. Redefining terminology based on whether 
we are cross compiling is counter to that goal.

> This example is bad because you do not know about runtime when you do 
> compilation.

I'm intrigued you singled out my first `#if` and not my second. If the binary 
is compiled with `clang` targeting windows, then (absent wine or something) we 
can be sure it is running on windows. On the other hand it seems odd and 
gcc-like to decide at compile time whether the newly built binary is targeting 
Darwin. The "emit" platform of the newly-built binary is strictly more removed 
from `clang`'s purview than the "run" platform.


Repository:
  rC Clang

https://reviews.llvm.org/D44753



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


[PATCH] D44755: [analyzer] Suppress more C++17-related crashes.

2018-03-21 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 139378.
NoQ added a comment.

Add a comment for the confusing part.


https://reviews.llvm.org/D44755

Files:
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
  test/Analysis/lifetime-extension.cpp
  test/Analysis/temporaries.cpp

Index: test/Analysis/temporaries.cpp
===
--- test/Analysis/temporaries.cpp
+++ test/Analysis/temporaries.cpp
@@ -1,6 +1,9 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-config cfg-temporary-dtors=false -verify -w -std=c++03 %s
 // RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-config cfg-temporary-dtors=false -verify -w -std=c++11 %s
 // RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -DTEMPORARY_DTORS -verify -w -analyzer-config cfg-temporary-dtors=true,c++-temp-dtor-inlining=true %s -std=c++11
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -DTEMPORARY_DTORS -w -analyzer-config cfg-temporary-dtors=true,c++-temp-dtor-inlining=true %s -std=c++17
+
+// Note: The C++17 run-line doesn't -verify yet - it is a no-crash test.
 
 extern bool clang_analyzer_eval(bool);
 extern bool clang_analyzer_warnIfReached();
Index: test/Analysis/lifetime-extension.cpp
===
--- test/Analysis/lifetime-extension.cpp
+++ test/Analysis/lifetime-extension.cpp
@@ -1,7 +1,11 @@
 // RUN: %clang_analyze_cc1 -Wno-unused -std=c++11 -analyzer-checker=core,debug.ExprInspection -analyzer-config cfg-temporary-dtors=false -verify %s
 // RUN: %clang_analyze_cc1 -Wno-unused -std=c++11 -analyzer-checker=core,debug.ExprInspection -analyzer-config cfg-temporary-dtors=true,c++-temp-dtor-inlining=true -DTEMPORARIES -verify %s
+// RUN: %clang_analyze_cc1 -Wno-unused -std=c++17 -analyzer-checker=core,debug.ExprInspection -analyzer-config cfg-temporary-dtors=true,c++-temp-dtor-inlining=true -DTEMPORARIES %s
 // RUN: %clang_analyze_cc1 -Wno-unused -std=c++11 -analyzer-checker=core,debug.ExprInspection -analyzer-config cfg-temporary-dtors=false -DMOVES -verify %s
 // RUN: %clang_analyze_cc1 -Wno-unused -std=c++11 -analyzer-checker=core,debug.ExprInspection -analyzer-config cfg-temporary-dtors=true,c++-temp-dtor-inlining=true -DTEMPORARIES -DMOVES -verify %s
+// RUN: %clang_analyze_cc1 -Wno-unused -std=c++17 -analyzer-checker=core,debug.ExprInspection -analyzer-config cfg-temporary-dtors=true,c++-temp-dtor-inlining=true -DTEMPORARIES -DMOVES %s
+
+// Note: The C++17 run-lines don't -verify yet - it is a no-crash test.
 
 void clang_analyzer_eval(bool);
 void clang_analyzer_checkInlined(bool);
Index: lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -203,6 +203,10 @@
   // TODO: What exactly happens when we are? Does the temporary object live
   // long enough in the region store in this case? Would checkers think
   // that this object immediately goes out of scope?
+  // TODO: We assume that the call site has a temporary object construction
+  // context. This is no longer true in C++17 or when copy elision is
+  // performed. We may need to unwrap multiple stack frames here and we
+  // won't necessarily end up with a temporary at the end.
   const LocationContext *TempLCtx = LCtx;
   if (const LocationContext *CallerLCtx =
   LCtx->getCurrentStackFrame()->getParent()) {
Index: lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -455,29 +455,51 @@
 const LocationContext *LC, const MemRegion *R) {
   const CXXBindTemporaryExpr *BTE = nullptr;
   const MaterializeTemporaryExpr *MTE = nullptr;
-  const LocationContext *TempLC = LC;
 
   if (CC) {
-// In case of temporary object construction, extract data necessary for
-// destruction and lifetime extension.
-const auto *TCC = dyn_cast(CC);
-
 // If the temporary is being returned from the function, it will be
 // destroyed or lifetime-extended in the caller stack frame.
 if (isa(CC)) {
   const StackFrameContext *SFC = LC->getCurrentStackFrame();
   assert(SFC);
-  if (SFC->getParent()) {
-TempLC = SFC->getParent();
-const CFGElement  =
-(*SFC->getCallSiteBlock())[SFC->getIndex()];
-if (auto RTCElem = CallElem.getAs()) {
-  TCC = cast(
-  RTCElem->getConstructionContext());
-}
+  LC = SFC->getParent();
+  if (!LC) {
+// We are on the top frame. We won't ever need any info
+// for this temporary, so don't set anything.
+return State;
+  }
+  const CFGElement  =
+  

r328158 - [NVPTX] Make tensor shape part of WMMA intrinsic's name.

2018-03-21 Thread Artem Belevich via cfe-commits
Author: tra
Date: Wed Mar 21 14:55:02 2018
New Revision: 328158

URL: http://llvm.org/viewvc/llvm-project?rev=328158=rev
Log:
[NVPTX] Make tensor shape part of WMMA intrinsic's name.

This is needed for the upcoming implementation of the
new 8x32x16 and 32x8x16 variants of WMMA instructions
introduced in CUDA 9.1.

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

Modified:
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/test/CodeGen/builtins-nvptx-sm_70.cu

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=328158=328157=328158=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Wed Mar 21 14:55:02 2018
@@ -10515,23 +10515,23 @@ Value *CodeGenFunction::EmitNVPTXBuiltin
 unsigned NumResults;
 switch (BuiltinID) {
 case NVPTX::BI__hmma_m16n16k16_ld_a:
-  IID = isColMajor ? Intrinsic::nvvm_wmma_load_a_f16_col_stride
-   : Intrinsic::nvvm_wmma_load_a_f16_row_stride;
+  IID = isColMajor ? Intrinsic::nvvm_wmma_m16n16k16_load_a_f16_col_stride
+   : Intrinsic::nvvm_wmma_m16n16k16_load_a_f16_row_stride;
   NumResults = 8;
   break;
 case NVPTX::BI__hmma_m16n16k16_ld_b:
-  IID = isColMajor ? Intrinsic::nvvm_wmma_load_b_f16_col_stride
-   : Intrinsic::nvvm_wmma_load_b_f16_row_stride;
+  IID = isColMajor ? Intrinsic::nvvm_wmma_m16n16k16_load_b_f16_col_stride
+   : Intrinsic::nvvm_wmma_m16n16k16_load_b_f16_row_stride;
   NumResults = 8;
   break;
 case NVPTX::BI__hmma_m16n16k16_ld_c_f16:
-  IID = isColMajor ? Intrinsic::nvvm_wmma_load_c_f16_col_stride
-   : Intrinsic::nvvm_wmma_load_c_f16_row_stride;
+  IID = isColMajor ? Intrinsic::nvvm_wmma_m16n16k16_load_c_f16_col_stride
+   : Intrinsic::nvvm_wmma_m16n16k16_load_c_f16_row_stride;
   NumResults = 4;
   break;
 case NVPTX::BI__hmma_m16n16k16_ld_c_f32:
-  IID = isColMajor ? Intrinsic::nvvm_wmma_load_c_f32_col_stride
-   : Intrinsic::nvvm_wmma_load_c_f32_row_stride;
+  IID = isColMajor ? Intrinsic::nvvm_wmma_m16n16k16_load_c_f32_col_stride
+   : Intrinsic::nvvm_wmma_m16n16k16_load_c_f32_row_stride;
   NumResults = 8;
   break;
 default:
@@ -10566,13 +10566,13 @@ Value *CodeGenFunction::EmitNVPTXBuiltin
 // for some reason nvcc builtins use _c_.
 switch (BuiltinID) {
 case NVPTX::BI__hmma_m16n16k16_st_c_f16:
-  IID = isColMajor ? Intrinsic::nvvm_wmma_store_d_f16_col_stride
-   : Intrinsic::nvvm_wmma_store_d_f16_row_stride;
+  IID = isColMajor ? Intrinsic::nvvm_wmma_m16n16k16_store_d_f16_col_stride
+   : Intrinsic::nvvm_wmma_m16n16k16_store_d_f16_row_stride;
   NumResults = 4;
   break;
 case NVPTX::BI__hmma_m16n16k16_st_c_f32:
-  IID = isColMajor ? Intrinsic::nvvm_wmma_store_d_f32_col_stride
-   : Intrinsic::nvvm_wmma_store_d_f32_row_stride;
+  IID = isColMajor ? Intrinsic::nvvm_wmma_m16n16k16_store_d_f32_col_stride
+   : Intrinsic::nvvm_wmma_m16n16k16_store_d_f32_row_stride;
   break;
 default:
   llvm_unreachable("Unexpected builtin ID.");
@@ -10591,8 +10591,8 @@ Value *CodeGenFunction::EmitNVPTXBuiltin
 return Result;
   }
 
-  // BI__hmma_m16n16k16_mma_(d, a, b, c, layout, satf)
-  //  --> Intrinsic::nvvm_wmma_mma_sync
+  // BI__hmma_m16n16k16_mma_(d, a, b, c, layout, satf) -->
+  // Intrinsic::nvvm_wmma_m16n16k16_mma_sync
   case NVPTX::BI__hmma_m16n16k16_mma_f16f16:
   case NVPTX::BI__hmma_m16n16k16_mma_f32f16:
   case NVPTX::BI__hmma_m16n16k16_mma_f32f32:
@@ -10613,15 +10613,15 @@ Value *CodeGenFunction::EmitNVPTXBuiltin
 bool Satf = SatfArg.getSExtValue();
 
 // clang-format off
-#define MMA_VARIANTS(type) {{   \
-  Intrinsic::nvvm_wmma_mma_sync_row_row_##type, \
-  Intrinsic::nvvm_wmma_mma_sync_row_row_##type##_satfinite, \
-  Intrinsic::nvvm_wmma_mma_sync_row_col_##type, \
-  Intrinsic::nvvm_wmma_mma_sync_row_col_##type##_satfinite, \
-  Intrinsic::nvvm_wmma_mma_sync_col_row_##type, \
-  Intrinsic::nvvm_wmma_mma_sync_col_row_##type##_satfinite, \
-  Intrinsic::nvvm_wmma_mma_sync_col_col_##type, \
-  Intrinsic::nvvm_wmma_mma_sync_col_col_##type##_satfinite  \
+#define MMA_VARIANTS(type) {{\
+  Intrinsic::nvvm_wmma_m16n16k16_mma_row_row_##type, \
+  Intrinsic::nvvm_wmma_m16n16k16_mma_row_row_##type##_satfinite, \
+  Intrinsic::nvvm_wmma_m16n16k16_mma_row_col_##type, \
+  Intrinsic::nvvm_wmma_m16n16k16_mma_row_col_##type##_satfinite, \
+  

[PATCH] D44753: [Preprocessor] Rename __is_{target -> host}_* function-like builtin macros

2018-03-21 Thread Steven Wu via Phabricator via cfe-commits
steven_wu added a comment.

It is not about matching command line name to builtin marco name. "target" is 
the platform we are compiling for, whether it is host or device or something 
else. It is a different concept when you talking about cross-compiling, which 
"target" is strictly not host and "build" or "host" doesn't matter to compiler 
at all.

> #if __is_run(window)
> 
>   printf("Hello, Satya");
> 
> #elif __is_run(darwin)
> 
>   printf("Hello, Tim");
> 
> #else
> 
>   prinf("Unclear who I am talking too.");
> 
> #endif

This example is bad because you do not know about runtime when you do 
compilation. Putting runtime environment onto #if is just wrong in many ways. 
If autoconf really has to name it to something else, you can always write a 
"#define" to rename __is_target.


Repository:
  rC Clang

https://reviews.llvm.org/D44753



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


[PATCH] D44710: Set dso_local on builtin functions

2018-03-21 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

lgtm


https://reviews.llvm.org/D44710



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


[PATCH] D44753: [Preprocessor] Rename __is_{target -> host}_* function-like builtin macros

2018-03-21 Thread John Ericson via Phabricator via cfe-commits
Ericson2314 added a comment.

@steven_wu but what you say is directly contradicted by the GHC example. I'm 
sure I could fine a GCC example too where some macro with "target" is in the 
name affects the target of the compiler being built. In the vast majority of 
programs, no more than one platform need affect preprocessing, but when 
multiple platforms affect preprocessing, they are *always* named from the 
perspective of the being-built tool being run.


Repository:
  rC Clang

https://reviews.llvm.org/D44753



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


[PATCH] D44747: [AMDGPU] Set calling convention for CUDA kernel

2018-03-21 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

In https://reviews.llvm.org/D44747#1044916, @yaxunl wrote:

> In https://reviews.llvm.org/D44747#1044893, @rjmccall wrote:
>
> > Is there a reason for this to be done as a special case in IRGen instead of 
> > just implicitly applying the calling convention in Sema?
>
>
> The calling convention is not used in Sema, therefore it seems simpler to do 
> it in codegen. I could try doing this in Sema too. Is there any advantage of 
> doing this in Sema?


In IRGen, it's a special case for your specific language mode on your specific 
target.  In Sema, it can be done as part of the special checking for kernel 
functions.

Also, it looks like CUDA allows you to take the address of a __global__ 
function, and indirect calls to such functions presumably still follow the 
normal CUDA restrictions, so there must be *some* reflection of this in Sema.

Also, the calling convention


https://reviews.llvm.org/D44747



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


[PATCH] D44753: [Preprocessor] Rename __is_{target -> host}_* function-like builtin macros

2018-03-21 Thread John Ericson via Phabricator via cfe-commits
Ericson2314 added a comment.

One that that might make my position clearer is to substitute the name "build", 
"host", and "target" for "build", "run", and "emit". [A colleague of mine 
proposed these alternative names and I do think they are vastly more human 
friendly.]

Then if we write

  int main(void) {
  
  #if __is_run(window)
printf("Hello, Satya");
  #elif __is_run(darwin)
printf("Hello, Tim");
  #else
prinf("Unclear who I am talking too.");
  #endif
  
  #if __is_emit(darwin)
#error "What's a Mach-O?"
  #else
/* do something with binutils */
  #endif
  
return 0;
  }

and run

  clang -emit something main.c

it is clear the intention is *not* for `-emit` to control `__is_emit`.

To me, this makes clear that the problem isn't the name-shift I am proposing, 
but the inherent vagary of the terms "host" and "target" relative to their 
specific meaning in Autoconf's jargon.


Repository:
  rC Clang

https://reviews.llvm.org/D44753



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


[PATCH] D44753: [Preprocessor] Rename __is_{target -> host}_* function-like builtin macros

2018-03-21 Thread Steven Wu via Phabricator via cfe-commits
steven_wu added a comment.

I disagree. I think "target" is the correct name, even for cross compiling. For 
something compiled with -target foo, we are consistent calling it "target" 
during compile time. It only becomes appropriate to call it "host" during the 
runtime of the executable. There is no such concept as "host" when you are 
doing cross compiling.

The builtin macros are compile time constant, so following the compile time 
naming is much better.


Repository:
  rC Clang

https://reviews.llvm.org/D44753



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


[PATCH] D43494: [Modules] Fix creating fake definition data for lambdas.

2018-03-21 Thread Volodymyr Sapsai via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC328153: [Modules] Fix creating fake definition data for 
lambdas. (authored by vsapsai, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D43494?vs=138059=139372#toc

Repository:
  rC Clang

https://reviews.llvm.org/D43494

Files:
  lib/Serialization/ASTReaderDecl.cpp
  test/Modules/Inputs/self-referencing-lambda/a.h
  test/Modules/Inputs/self-referencing-lambda/module.modulemap
  test/Modules/self-referencing-lambda.cpp


Index: test/Modules/self-referencing-lambda.cpp
===
--- test/Modules/self-referencing-lambda.cpp
+++ test/Modules/self-referencing-lambda.cpp
@@ -0,0 +1,5 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I 
%S/Inputs/self-referencing-lambda %s -verify -emit-obj -o %t2.o
+// expected-no-diagnostics
+
+#include "a.h"
Index: test/Modules/Inputs/self-referencing-lambda/module.modulemap
===
--- test/Modules/Inputs/self-referencing-lambda/module.modulemap
+++ test/Modules/Inputs/self-referencing-lambda/module.modulemap
@@ -0,0 +1,4 @@
+module "a.h" {
+  header "a.h"
+  export *
+}
Index: test/Modules/Inputs/self-referencing-lambda/a.h
===
--- test/Modules/Inputs/self-referencing-lambda/a.h
+++ test/Modules/Inputs/self-referencing-lambda/a.h
@@ -0,0 +1,4 @@
+void f() {
+  int x = 0;
+  auto q = [xm = x]{};
+}
Index: lib/Serialization/ASTReaderDecl.cpp
===
--- lib/Serialization/ASTReaderDecl.cpp
+++ lib/Serialization/ASTReaderDecl.cpp
@@ -1784,29 +1784,31 @@
   else
 DD = new (C) struct CXXRecordDecl::DefinitionData(D);
 
+  CXXRecordDecl *Canon = D->getCanonicalDecl();
+  // Set decl definition data before reading it, so that during deserialization
+  // when we read CXXRecordDecl, it already has definition data and we don't
+  // set fake one.
+  if (!Canon->DefinitionData)
+Canon->DefinitionData = DD;
+  D->DefinitionData = Canon->DefinitionData;
   ReadCXXDefinitionData(*DD, D);
 
-  // We might already have a definition for this record. This can happen either
-  // because we're reading an update record, or because we've already done some
-  // merging. Either way, just merge into it.
-  CXXRecordDecl *Canon = D->getCanonicalDecl();
-  if (Canon->DefinitionData) {
+  // We might already have a different definition for this record. This can
+  // happen either because we're reading an update record, or because we've
+  // already done some merging. Either way, just merge into it.
+  if (Canon->DefinitionData != DD) {
 MergeDefinitionData(Canon, std::move(*DD));
-D->DefinitionData = Canon->DefinitionData;
 return;
   }
 
   // Mark this declaration as being a definition.
   D->IsCompleteDefinition = true;
-  D->DefinitionData = DD;
 
   // If this is not the first declaration or is an update record, we can have
   // other redeclarations already. Make a note that we need to propagate the
   // DefinitionData pointer onto them.
-  if (Update || Canon != D) {
-Canon->DefinitionData = D->DefinitionData;
+  if (Update || Canon != D)
 Reader.PendingDefinitions.insert(D);
-  }
 }
 
 ASTDeclReader::RedeclarableResult


Index: test/Modules/self-referencing-lambda.cpp
===
--- test/Modules/self-referencing-lambda.cpp
+++ test/Modules/self-referencing-lambda.cpp
@@ -0,0 +1,5 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/self-referencing-lambda %s -verify -emit-obj -o %t2.o
+// expected-no-diagnostics
+
+#include "a.h"
Index: test/Modules/Inputs/self-referencing-lambda/module.modulemap
===
--- test/Modules/Inputs/self-referencing-lambda/module.modulemap
+++ test/Modules/Inputs/self-referencing-lambda/module.modulemap
@@ -0,0 +1,4 @@
+module "a.h" {
+  header "a.h"
+  export *
+}
Index: test/Modules/Inputs/self-referencing-lambda/a.h
===
--- test/Modules/Inputs/self-referencing-lambda/a.h
+++ test/Modules/Inputs/self-referencing-lambda/a.h
@@ -0,0 +1,4 @@
+void f() {
+  int x = 0;
+  auto q = [xm = x]{};
+}
Index: lib/Serialization/ASTReaderDecl.cpp
===
--- lib/Serialization/ASTReaderDecl.cpp
+++ lib/Serialization/ASTReaderDecl.cpp
@@ -1784,29 +1784,31 @@
   else
 DD = new (C) struct CXXRecordDecl::DefinitionData(D);
 
+  CXXRecordDecl *Canon = D->getCanonicalDecl();
+  // Set decl definition data before reading it, so that during deserialization
+  // when we read CXXRecordDecl, it already has definition data and we don't
+  // set fake one.
+  

r328153 - [Modules] Fix creating fake definition data for lambdas.

2018-03-21 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Wed Mar 21 14:28:54 2018
New Revision: 328153

URL: http://llvm.org/viewvc/llvm-project?rev=328153=rev
Log:
[Modules] Fix creating fake definition data for lambdas.

During reading C++ definition data for lambda we can access
CXXRecordDecl representing lambda before we finished reading the
definition data. This can happen by reading a captured variable which is
VarDecl, then reading its decl context which is CXXMethodDecl `operator()`,
then trying to merge redeclarable methods and accessing
enclosing CXXRecordDecl. The call stack looks roughly like

VisitCXXRecordDecl
  ReadCXXRecordDefinition
VisitVarDecl
  VisitCXXMethodDecl
mergeRedeclarable
  getPrimaryContextForMerging

If we add fake definition data at this point, later we'll hit the assertion

Assertion failed: (!DD.IsLambda && !MergeDD.IsLambda && "faked up lambda 
definition?"), function MergeDefinitionData, file 
clang/lib/Serialization/ASTReaderDecl.cpp, line 1675.

The fix is to assign definition data before reading it. Fixes PR32556.

rdar://problem/37461072

Reviewers: rsmith, bruno

Reviewed By: rsmith

Subscribers: cfe-commits, jkorous-apple, aprantl

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


Added:
cfe/trunk/test/Modules/Inputs/self-referencing-lambda/
cfe/trunk/test/Modules/Inputs/self-referencing-lambda/a.h
cfe/trunk/test/Modules/Inputs/self-referencing-lambda/module.modulemap
cfe/trunk/test/Modules/self-referencing-lambda.cpp
Modified:
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp

Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=328153=328152=328153=diff
==
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Wed Mar 21 14:28:54 2018
@@ -1784,29 +1784,31 @@ void ASTDeclReader::ReadCXXRecordDefinit
   else
 DD = new (C) struct CXXRecordDecl::DefinitionData(D);
 
+  CXXRecordDecl *Canon = D->getCanonicalDecl();
+  // Set decl definition data before reading it, so that during deserialization
+  // when we read CXXRecordDecl, it already has definition data and we don't
+  // set fake one.
+  if (!Canon->DefinitionData)
+Canon->DefinitionData = DD;
+  D->DefinitionData = Canon->DefinitionData;
   ReadCXXDefinitionData(*DD, D);
 
-  // We might already have a definition for this record. This can happen either
-  // because we're reading an update record, or because we've already done some
-  // merging. Either way, just merge into it.
-  CXXRecordDecl *Canon = D->getCanonicalDecl();
-  if (Canon->DefinitionData) {
+  // We might already have a different definition for this record. This can
+  // happen either because we're reading an update record, or because we've
+  // already done some merging. Either way, just merge into it.
+  if (Canon->DefinitionData != DD) {
 MergeDefinitionData(Canon, std::move(*DD));
-D->DefinitionData = Canon->DefinitionData;
 return;
   }
 
   // Mark this declaration as being a definition.
   D->IsCompleteDefinition = true;
-  D->DefinitionData = DD;
 
   // If this is not the first declaration or is an update record, we can have
   // other redeclarations already. Make a note that we need to propagate the
   // DefinitionData pointer onto them.
-  if (Update || Canon != D) {
-Canon->DefinitionData = D->DefinitionData;
+  if (Update || Canon != D)
 Reader.PendingDefinitions.insert(D);
-  }
 }
 
 ASTDeclReader::RedeclarableResult

Added: cfe/trunk/test/Modules/Inputs/self-referencing-lambda/a.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/self-referencing-lambda/a.h?rev=328153=auto
==
--- cfe/trunk/test/Modules/Inputs/self-referencing-lambda/a.h (added)
+++ cfe/trunk/test/Modules/Inputs/self-referencing-lambda/a.h Wed Mar 21 
14:28:54 2018
@@ -0,0 +1,4 @@
+void f() {
+  int x = 0;
+  auto q = [xm = x]{};
+}

Added: cfe/trunk/test/Modules/Inputs/self-referencing-lambda/module.modulemap
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/self-referencing-lambda/module.modulemap?rev=328153=auto
==
--- cfe/trunk/test/Modules/Inputs/self-referencing-lambda/module.modulemap 
(added)
+++ cfe/trunk/test/Modules/Inputs/self-referencing-lambda/module.modulemap Wed 
Mar 21 14:28:54 2018
@@ -0,0 +1,4 @@
+module "a.h" {
+  header "a.h"
+  export *
+}

Added: cfe/trunk/test/Modules/self-referencing-lambda.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/self-referencing-lambda.cpp?rev=328153=auto
==
--- cfe/trunk/test/Modules/self-referencing-lambda.cpp (added)
+++ 

[clang-tools-extra] r328150 - [clang-doc] Reland "[clang-doc] Setup clang-doc frontend framework"

2018-03-21 Thread Julie Hockett via cfe-commits
Author: juliehockett
Date: Wed Mar 21 14:21:45 2018
New Revision: 328150

URL: http://llvm.org/viewvc/llvm-project?rev=328150=rev
Log:
[clang-doc] Reland "[clang-doc] Setup clang-doc frontend framework"

Fixing the the failing Windows tests.

Added:
clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp
clang-tools-extra/trunk/clang-doc/BitcodeWriter.h
clang-tools-extra/trunk/clang-doc/CMakeLists.txt
clang-tools-extra/trunk/clang-doc/ClangDoc.cpp
clang-tools-extra/trunk/clang-doc/ClangDoc.h
clang-tools-extra/trunk/clang-doc/Mapper.cpp
clang-tools-extra/trunk/clang-doc/Mapper.h
clang-tools-extra/trunk/clang-doc/Representation.h
clang-tools-extra/trunk/clang-doc/Serialize.cpp
clang-tools-extra/trunk/clang-doc/Serialize.h
clang-tools-extra/trunk/clang-doc/tool/CMakeLists.txt
clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-class-in-class.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-class-in-function.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-class.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-comments.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-enum.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-function.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-method.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-namespace.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-struct.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-union.cpp
Modified:
clang-tools-extra/trunk/CMakeLists.txt
clang-tools-extra/trunk/test/CMakeLists.txt

Modified: clang-tools-extra/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/CMakeLists.txt?rev=328150=328149=328150=diff
==
--- clang-tools-extra/trunk/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/CMakeLists.txt Wed Mar 21 14:21:45 2018
@@ -7,6 +7,7 @@ add_subdirectory(clang-tidy-vs)
 endif()
 
 add_subdirectory(change-namespace)
+add_subdirectory(clang-doc)
 add_subdirectory(clang-query)
 add_subdirectory(clang-move)
 add_subdirectory(clangd)

Added: clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp?rev=328150=auto
==
--- clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp (added)
+++ clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp Wed Mar 21 14:21:45 2018
@@ -0,0 +1,511 @@
+//===--  BitcodeWriter.cpp - ClangDoc Bitcode Writer *- C++ 
-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "BitcodeWriter.h"
+#include "llvm/ADT/IndexedMap.h"
+#include 
+
+namespace clang {
+namespace doc {
+
+// Since id enums are not zero-indexed, we need to transform the given id into
+// its associated index.
+struct BlockIdToIndexFunctor {
+  using argument_type = unsigned;
+  unsigned operator()(unsigned ID) const { return ID - BI_FIRST; }
+};
+
+struct RecordIdToIndexFunctor {
+  using argument_type = unsigned;
+  unsigned operator()(unsigned ID) const { return ID - RI_FIRST; }
+};
+
+using AbbrevDsc = void (*)(std::shared_ptr );
+
+static void AbbrevGen(std::shared_ptr ,
+  const std::initializer_list Ops) {
+  for (const auto  : Ops)
+Abbrev->Add(Op);
+}
+
+static void BoolAbbrev(std::shared_ptr ) {
+  AbbrevGen(Abbrev,
+{// 0. Boolean
+ llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
+   BitCodeConstants::BoolSize)});
+}
+
+static void IntAbbrev(std::shared_ptr ) {
+  AbbrevGen(Abbrev,
+{// 0. Fixed-size integer
+ llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
+   BitCodeConstants::IntSize)});
+}
+
+static void SymbolIDAbbrev(std::shared_ptr ) {
+  AbbrevGen(Abbrev,
+{// 0. Fixed-size integer (length of the sha1'd USR)
+ llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
+   BitCodeConstants::USRLengthSize),
+ // 1. Fixed-size array of Char6 (USR)
+ llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Array),
+ llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
+   BitCodeConstants::USRBitLengthSize)});
+}
+
+static void StringAbbrev(std::shared_ptr ) {
+  AbbrevGen(Abbrev,
+{// 0. Fixed-size integer (length of the following string)
+ llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
+   BitCodeConstants::StringLengthSize),
+ // 1. The string blob
+ 

[PATCH] D34331: func.wrap.func.con: Unset function before destroying anything

2018-03-21 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists added a comment.

A few small comments...




Comment at: libcxx/include/functional:1821
 {
-if ((void *)__f_ == &__buf_)
-__f_->destroy();
-else if (__f_)
-__f_->destroy_deallocate();
-__f_ = 0;
+function::operator=(nullptr);
 if (__f.__f_ == 0)

Couldn't this be more clearly written as `*this = nullptr;` ?



Comment at: libcxx/include/functional:1822
+function::operator=(nullptr);
 if (__f.__f_ == 0)
 __f_ = 0;

At this point `__f_ == 0` (because we just set it to 0).
We probably don't need to do that again.




Comment at: libcxx/include/functional:1843
 __f_ = 0;
+if ((void *)__t == &__buf_)
+__t->destroy();

I see this dance 4x in `` and once here. Did you give any 
thought to making it a function of `__base`?  Maybe call it `__clear`?

Then line #1821 can be written as `__clear();`




https://reviews.llvm.org/D34331



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


[PATCH] D44753: [Preprocessor] Rename __is_{target -> host}_* function-like builtin macros

2018-03-21 Thread John Ericson via Phabricator via cfe-commits
Ericson2314 added a comment.

In https://reviews.llvm.org/D44753#1044935, @bob.wilson wrote:

> Sorry that I missed your earlier comment about this. The confusion could only 
> arise in the context of a tool (like a compiler) that is being used for 
> cross-compilation. That is a small fraction of the audience for Clang, and we 
> should design this in a way that makes the most sense for the majority of 
> users. If there's a naming scheme that is better for both, then we should do 
> that, but I don't think this is it.


I agree. But I believe mine no worse for both, and significantly better for the 
compiling-a-compiler case.

> When dealing with a cross compiler, there is a need to distinguish the 
> "target" where the compiler will run (which as you point out is typically 
> referred to as the "host") from the "target" code produced by that cross 
> compiler.

I Agree.

> There are two points in time: (1) when compiling the cross compiler, and (2) 
> when running the cross compiler. In step (1), the compiler will be invoked 
> with a "-target" option that specifies the "host".

I prefer not to think times of points of time but in terms of different 
programs having different perspectives. The bootstrapping compiler was built on 
A, runs on B, and is passed `-target` for C. The new compiler was built on B, 
runs on C, and targets some set D... (which is not constrained). So the two 
compilers' frame of reference is shifted by 1, but the frame of reference per 
compiler is constant whether we are building it or running it.

> The compiler option name will be "-target" regardless. Using "target" names 
> in the macros is consistent with that compiler option name.



> The obvious connection between these macros and the value specified by the 
> "-target" option would be lost.

So I do wonder if `-target` was the best name, but agreed that ship has long 
since sailed.

Furthermore, with the way of per-compiler, not per-time thinking I described 
above, one can reconcile the `-target` flag with the autoconf terminology by 
saying is specifying the "target" of the compiler, not the "target" of the 
thing being built. Indeed, might build the new compiler like

  ./Configure 'CC=clang -target foo-bar-baz` --host foo-bar-baz --target 
alpha-beta-gamma
  make



> The preprocessor checks are compile-time checks, so there no way that one of 
> these macros in the source code of the compiler itself could be referring to 
> the target in step (2).

Yes, agreed clang won't know what the target of the compiler being built is 
(for that would be clang's "post target"). The problem with the status quo is 
that the new compiler's build system will define its own macros, and those will 
clash with this in very confusing ways.

For example, check out this file of GHC's 
https://github.com/ghc/ghc/blob/master/compiler/ghc.mk#L155-L192. The 
`__is_target_*` macros made by LLVM would correspond to to the `*_HOST_*` 
macros produces by the build system and *not* the `*_TARGET_*` ones.


Repository:
  rC Clang

https://reviews.llvm.org/D44753



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


[PATCH] D44755: [analyzer] Suppress more C++17-related crashes.

2018-03-21 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov added inline comments.



Comment at: lib/StaticAnalyzer/Core/ExprEngine.cpp:480
   }
+  CC = dyn_cast(
+  RTCElem->getConstructionContext());

I'm a bit confused as to what is going on here; maybe a short comment would be 
helpful?
What I don't understand is that we go through that branch when construction 
context is supplied only to completely ignore it [..because we know better?..]


Repository:
  rC Clang

https://reviews.llvm.org/D44755



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


[PATCH] D34331: func.wrap.func.con: Unset function before destroying anything

2018-03-21 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai updated this revision to Diff 139369.
vsapsai edited the summary of this revision.
vsapsai added a comment.

- Implement the same functionality for C++98 and C++03.
- Use `DoNotOptimize` instead of `asm`.

Didn't move the tests as the standard doesn't require assignment operator to be
reentrant and we implement that not in general case but only for assigning
`nullptr`. Tests might be still worth moving, just previous arguments don't
apply anymore, as for me.


https://reviews.llvm.org/D34331

Files:
  libcxx/include/__functional_03
  libcxx/include/functional
  
libcxx/test/libcxx/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/move_reentrant.pass.cpp
  
libcxx/test/libcxx/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign_reentrant.pass.cpp

Index: libcxx/test/libcxx/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign_reentrant.pass.cpp
===
--- /dev/null
+++ libcxx/test/libcxx/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign_reentrant.pass.cpp
@@ -0,0 +1,46 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// 
+
+// class function
+
+// function& operator=(nullptr_t);
+
+#include 
+#include 
+
+#include "test_macros.h"
+
+struct A
+{
+  static std::function global;
+  static bool cancel;
+
+  ~A() {
+DoNotOptimize(cancel);
+if (cancel)
+  global = nullptr;
+  }
+  void operator()() {}
+};
+
+std::function A::global;
+bool A::cancel = false;
+
+int main()
+{
+  A::global = A();
+  assert(A::global.target());
+
+  // Check that we don't recurse in A::~A().
+  A::cancel = true;
+  A::global = nullptr;
+  assert(!A::global.target());
+}
Index: libcxx/test/libcxx/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/move_reentrant.pass.cpp
===
--- /dev/null
+++ libcxx/test/libcxx/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/move_reentrant.pass.cpp
@@ -0,0 +1,46 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// 
+
+// class function
+
+// function& operator=(function &&);
+
+#include 
+#include 
+
+#include "test_macros.h"
+
+struct A
+{
+  static std::function global;
+  static bool cancel;
+
+  ~A() {
+DoNotOptimize(cancel);
+if (cancel)
+  global = std::function(nullptr);
+  }
+  void operator()() {}
+};
+
+std::function A::global;
+bool A::cancel = false;
+
+int main()
+{
+  A::global = A();
+  assert(A::global.target());
+
+  // Check that we don't recurse in A::~A().
+  A::cancel = true;
+  A::global = std::function(nullptr);
+  assert(!A::global.target());
+}
Index: libcxx/include/functional
===
--- libcxx/include/functional
+++ libcxx/include/functional
@@ -1818,11 +1818,7 @@
 function<_Rp(_ArgTypes...)>&
 function<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT
 {
-if ((void *)__f_ == &__buf_)
-__f_->destroy();
-else if (__f_)
-__f_->destroy_deallocate();
-__f_ = 0;
+function::operator=(nullptr);
 if (__f.__f_ == 0)
 __f_ = 0;
 else if ((void *)__f.__f_ == &__f.__buf_)
@@ -1842,11 +1838,12 @@
 function<_Rp(_ArgTypes...)>&
 function<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT
 {
-if ((void *)__f_ == &__buf_)
-__f_->destroy();
-else if (__f_)
-__f_->destroy_deallocate();
+__base* __t = __f_;
 __f_ = 0;
+if ((void *)__t == &__buf_)
+__t->destroy();
+else if (__t)
+__t->destroy_deallocate();
 return *this;
 }
 
Index: libcxx/include/__functional_03
===
--- libcxx/include/__functional_03
+++ libcxx/include/__functional_03
@@ -600,19 +600,23 @@
 function<_Rp()>&
 function<_Rp()>::operator=(const function& __f)
 {
-function(__f).swap(*this);
+if (__f)
+function(__f).swap(*this);
+else
+function::operator=(nullptr);
 return *this;
 }
 
 template
 function<_Rp()>&
 function<_Rp()>::operator=(nullptr_t)
 {
-if (__f_ == (__base*)&__buf_)
-__f_->destroy();
-else if (__f_)
-   

[clang-tools-extra] r328149 - [clangd][nfc] Correct header name in comment

2018-03-21 Thread Jan Korous via cfe-commits
Author: jkorous
Date: Wed Mar 21 14:04:10 2018
New Revision: 328149

URL: http://llvm.org/viewvc/llvm-project?rev=328149=rev
Log:
[clangd][nfc] Correct header name in comment

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

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=328149=328148=328149=diff
==
--- clang-tools-extra/trunk/clangd/index/Index.h (original)
+++ clang-tools-extra/trunk/clangd/index/Index.h Wed Mar 21 14:04:10 2018
@@ -1,4 +1,4 @@
-//===--- Symbol.h ---*- C++-*-===//
+//===--- Index.h *- C++-*-===//
 //
 // The LLVM Compiler Infrastructure
 //


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


[PATCH] D44645: [test] Fix Cross-DSO CFI Android sanitizer test for -rtlib=compiler-rt

2018-03-21 Thread Evgenii Stepanov via Phabricator via cfe-commits
eugenis added a comment.

This was fixed in https://reviews.llvm.org/D44655


https://reviews.llvm.org/D44645



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


[PATCH] D44634: [clang-format] Detect Objective-C for #import

2018-03-21 Thread Yan Zhang via Phabricator via cfe-commits
Wizard added a comment.

For some ObjC headers it uses #import to import other headers instead of system 
framework, so I think we should also detect #import "*.h" as well.

The only usage of #import in C++  is to import type library, which won't have 
suffix of ".h".


Repository:
  rC Clang

https://reviews.llvm.org/D44634



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


Re: r327959 - [ms] Parse #pragma optimize and ignore it behind its own flag

2018-03-21 Thread Hans Wennborg via cfe-commits
Not sure either, but I think the ignored warning is used for pragmas
that clang fails to parse, so maybe unsupported is better.

On Wed, Mar 21, 2018 at 9:33 PM, Nico Weber  wrote:
> Ah! Hm, maybe that's the better group for this anyway? Not sure.
>
> On Wed, Mar 21, 2018, 9:03 PM Hans Wennborg  wrote:
>>
>> Aw, rats. I put it under -Wignored-pragmas rather than
>> -Wunsupported-pragmas, because I was looking at #pragma intrinsic.
>>
>> I'll take a look at this again tomorrow.
>>
>> On Wed, Mar 21, 2018 at 5:18 PM, Nico Weber via cfe-commits
>>  wrote:
>> > From the bot changes, it seems that -Wunknown-pragma doesn't disable
>> > this
>> > new warning. Shouldn't it do that?
>> >
>> > On Tue, Mar 20, 2018, 9:55 AM Hans Wennborg via cfe-commits
>> >  wrote:
>> >>
>> >> Author: hans
>> >> Date: Tue Mar 20 01:53:11 2018
>> >> New Revision: 327959
>> >>
>> >> URL: http://llvm.org/viewvc/llvm-project?rev=327959=rev
>> >> Log:
>> >> [ms] Parse #pragma optimize and ignore it behind its own flag
>> >>
>> >> This allows users to turn off warnings about this pragma specifically,
>> >> while still receiving warnings about other ignored pragmas.
>> >>
>> >> Differential Revision: https://reviews.llvm.org/D44630
>> >>
>> >> Modified:
>> >> cfe/trunk/include/clang/Basic/DiagnosticGroups.td
>> >> cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
>> >> cfe/trunk/include/clang/Parse/Parser.h
>> >> cfe/trunk/lib/Parse/ParsePragma.cpp
>> >> cfe/trunk/test/Preprocessor/pragma_microsoft.c
>> >>
>> >> Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
>> >> URL:
>> >>
>> >> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=327959=327958=327959=diff
>> >>
>> >>
>> >> ==
>> >> --- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
>> >> +++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Tue Mar 20
>> >> 01:53:11
>> >> 2018
>> >> @@ -515,8 +515,13 @@ def UninitializedStaticSelfInit : DiagGr
>> >>  def Uninitialized  : DiagGroup<"uninitialized",
>> >> [UninitializedSometimes,
>> >>
>> >> UninitializedStaticSelfInit]>;
>> >>  def IgnoredPragmaIntrinsic : DiagGroup<"ignored-pragma-intrinsic">;
>> >> +// #pragma optimize is often used to avoid to work around MSVC codegen
>> >> bugs or
>> >> +// to disable inlining. It's not completely clear what alternative to
>> >> suggest
>> >> +// (#pragma clang optimize, noinline) so suggest nothing for now.
>> >> +def IgnoredPragmaOptimize : DiagGroup<"ignored-pragma-optimize">;
>> >>  def UnknownPragmas : DiagGroup<"unknown-pragmas">;
>> >> -def IgnoredPragmas : DiagGroup<"ignored-pragmas",
>> >> [IgnoredPragmaIntrinsic]>;
>> >> +def IgnoredPragmas : DiagGroup<"ignored-pragmas",
>> >> +[IgnoredPragmaIntrinsic, IgnoredPragmaOptimize]>;
>> >>  def PragmaClangAttribute : DiagGroup<"pragma-clang-attribute">;
>> >>  def PragmaPackSuspiciousInclude :
>> >> DiagGroup<"pragma-pack-suspicious-include">;
>> >>  def PragmaPack : DiagGroup<"pragma-pack",
>> >> [PragmaPackSuspiciousInclude]>;
>> >>
>> >> Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
>> >> URL:
>> >>
>> >> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=327959=327958=327959=diff
>> >>
>> >>
>> >> ==
>> >> --- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
>> >> +++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Tue Mar 20
>> >> 01:53:11 2018
>> >> @@ -895,6 +895,12 @@ def warn_pragma_expected_rparen : Warnin
>> >>"missing ')' after '#pragma %0' - ignoring">,
>> >> InGroup;
>> >>  def warn_pragma_expected_identifier : Warning<
>> >>"expected identifier in '#pragma %0' - ignored">,
>> >> InGroup;
>> >> +def warn_pragma_expected_string : Warning<
>> >> +  "expected string literal in '#pragma %0' - ignoring">,
>> >> InGroup;
>> >> +def warn_pragma_missing_argument : Warning<
>> >> +  "missing argument to '#pragma %0'%select{|; expected %2}1">,
>> >> InGroup;
>> >> +def warn_pragma_invalid_argument : Warning<
>> >> +  "unexpected argument '%0' to '#pragma %1'%select{|; expected %3}2">,
>> >> InGroup;
>> >>
>> >>  // '#pragma clang section' related errors
>> >>  def err_pragma_expected_clang_section_name : Error<
>> >> @@ -923,6 +929,8 @@ def warn_pragma_ms_struct : Warning<
>> >>  def warn_pragma_extra_tokens_at_eol : Warning<
>> >>"extra tokens at end of '#pragma %0' - ignored">,
>> >>InGroup;
>> >> +def warn_pragma_expected_comma : Warning<
>> >> +  "expected ',' in '#pragma %0'">, InGroup;
>> >>  def warn_pragma_expected_punc : Warning<
>> >>"expected ')' or ',' in '#pragma %0'">, InGroup;
>> >>  def warn_pragma_expected_non_wide_string : Warning<
>> >> @@ -960,6 +968,10 @@ def warn_pragma_pack_malformed : 

Re: [PATCH] D44634: [clang-format] Detect Objective-C for #import

2018-03-21 Thread Ben Hamilton via cfe-commits
#import is perfectly legal in C and C++, it's just not commonly used.

On Wed, Mar 21, 2018, 14:27 Yan Zhang via Phabricator <
revi...@reviews.llvm.org> wrote:

> Wizard added a comment.
>
> Why do we only detect system framework? I think any #import could indicate
> ObjC header.
>
>
> Repository:
>   rC Clang
>
> https://reviews.llvm.org/D44634
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40218: [Clang] Add __builtin_launder

2018-03-21 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF updated this revision to Diff 139363.
EricWF marked an inline comment as done.
EricWF added a comment.

- Launder types with subobjects of dynamic class type.
- Improve diagnostic selection using `llvm::Optional`.
- Add comment about LTO ABI concerns to test file.
- Merge with master.


https://reviews.llvm.org/D40218

Files:
  include/clang/Basic/Builtins.def
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/AST/ExprConstant.cpp
  lib/CodeGen/CGBuiltin.cpp
  lib/Sema/SemaChecking.cpp
  test/CodeGen/builtins.c
  test/CodeGenCXX/builtin-launder.cpp
  test/Preprocessor/feature_tests.c
  test/Sema/builtins.c
  test/SemaCXX/builtins.cpp

Index: test/SemaCXX/builtins.cpp
===
--- test/SemaCXX/builtins.cpp
+++ test/SemaCXX/builtins.cpp
@@ -53,3 +53,71 @@
 void synchronize_args() {
   __sync_synchronize(0); // expected-error {{too many arguments}}
 }
+
+namespace test_launder {
+
+struct Dummy {};
+
+using FnType = int(char);
+using MemFnType = int (Dummy::*)(char);
+using ConstMemFnType = int (Dummy::*)() const;
+
+void foo() {}
+
+void test_builtin_launder_diags(void *vp, const void *cvp, FnType *fnp,
+MemFnType mfp, ConstMemFnType cmfp) {
+  __builtin_launder(vp);   // expected-error {{void pointer argument to '__builtin_launder' is not allowed}}
+  __builtin_launder(cvp);  // expected-error {{void pointer argument to '__builtin_launder' is not allowed}}
+  __builtin_launder(fnp);  // expected-error {{function pointer argument to '__builtin_launder' is not allowed}}
+  __builtin_launder(mfp);  // expected-error {{non-pointer argument to '__builtin_launder' is not allowed}}
+  __builtin_launder(cmfp); // expected-error {{non-pointer argument to '__builtin_launder' is not allowed}}
+  (void)__builtin_launder();
+  __builtin_launder(42);  // expected-error {{non-pointer argument to '__builtin_launder' is not allowed}}
+  __builtin_launder(nullptr); // expected-error {{non-pointer argument to '__builtin_launder' is not allowed}}
+  __builtin_launder(foo)  // expected-error {{non-pointer argument to '__builtin_launder' is not allowed}}
+}
+
+void test_builtin_launder(char *p, const volatile int *ip, const float *,
+  double *__restrict dp) {
+  int x;
+  __builtin_launder(x); // expected-error {{non-pointer argument to '__builtin_launder' is not allowed}}
+#define TEST_TYPE(Ptr, Type) \
+  static_assert(__is_same(decltype(__builtin_launder(Ptr)), Type), "expected same type")
+  TEST_TYPE(p, char*);
+  TEST_TYPE(ip, const volatile int*);
+  TEST_TYPE(fp, const float*);
+  TEST_TYPE(dp, double *__restrict);
+#undef TEST_TYPE
+  char *d = __builtin_launder(p);
+  const volatile int *id = __builtin_launder(ip);
+  int *id2 = __builtin_launder(ip); // expected-error {{cannot initialize a variable of type 'int *' with an rvalue of type 'const volatile int *'}}
+  const float* fd = __builtin_launder(fp);
+}
+
+template 
+constexpr Tp *test_constexpr_launder(Tp *tp) {
+  return __builtin_launder(tp);
+}
+constexpr int const_int = 42;
+constexpr int const_int2 = 101;
+constexpr const int *const_ptr = test_constexpr_launder(_int);
+static_assert(_int == const_ptr, "");
+static_assert(const_ptr != test_constexpr_launder(_int2), "");
+
+void test_non_constexpr() {
+  constexpr int i = 42;// expected-note {{declared here}}
+  constexpr const int *ip = __builtin_launder(); // expected-error {{constexpr variable 'ip' must be initialized by a constant expression}}
+  // expected-note@-1 {{pointer to 'i' is not a constant expression}}
+}
+
+constexpr bool test_in_constexpr(const int ) {
+  return (__builtin_launder() == );
+}
+static_assert(test_in_constexpr(const_int), "");
+void f() {
+  constexpr int i = 42;
+  // FIXME: Should this work? Since `` doesn't.
+  static_assert(test_in_constexpr(i), "");
+}
+
+} // end namespace test_launder
Index: test/Sema/builtins.c
===
--- test/Sema/builtins.c
+++ test/Sema/builtins.c
@@ -248,3 +248,21 @@
 
 return buf;
 }
+
+typedef void (fn_t)(int);
+
+void test_builtin_launder(char *p, void *vp, const void *cvp,
+  const volatile int *ip, float *restrict fp,
+  fn_t *fn) {
+  __builtin_launder(); // expected-error {{too few arguments to function call, expected 1, have 0}}
+  __builtin_launder(p, p); // expected-error {{too many arguments to function call, expected 1, have 2}}
+  int x;
+  __builtin_launder(x); // expected-error {{non-pointer argument to '__builtin_launder' is not allowed}}
+  char *d = __builtin_launder(p);
+  __builtin_launder(vp);  // expected-error {{void pointer argument to '__builtin_launder' is not allowed}}
+  __builtin_launder(cvp); // expected-error {{void pointer argument to '__builtin_launder' is not allowed}}
+  const volatile int *id = __builtin_launder(ip);
+  int *id2 = 

[PATCH] D40218: [Clang] Add __builtin_launder

2018-03-21 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF marked 2 inline comments as done.
EricWF added inline comments.



Comment at: test/CodeGenCXX/builtin-launder.cpp:93-96
+/// The test cases in this namespace technically need to be laundered according
+/// to the language in the standard (ie they have const or reference 
subobjects)
+/// but LLVM doesn't currently optimize on these cases -- so Clang emits
+/// __builtin_launder as a nop.

rsmith wrote:
> I would note that this means adding optimizations for those cases later is an 
> LTO ABI break. That's probably OK, but just something we're going to need to 
> remember.
I added your note almost verbatim to the test case.


https://reviews.llvm.org/D40218



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


Re: r327959 - [ms] Parse #pragma optimize and ignore it behind its own flag

2018-03-21 Thread Nico Weber via cfe-commits
Ah! Hm, maybe that's the better group for this anyway? Not sure.

On Wed, Mar 21, 2018, 9:03 PM Hans Wennborg  wrote:

> Aw, rats. I put it under -Wignored-pragmas rather than
> -Wunsupported-pragmas, because I was looking at #pragma intrinsic.
>
> I'll take a look at this again tomorrow.
>
> On Wed, Mar 21, 2018 at 5:18 PM, Nico Weber via cfe-commits
>  wrote:
> > From the bot changes, it seems that -Wunknown-pragma doesn't disable this
> > new warning. Shouldn't it do that?
> >
> > On Tue, Mar 20, 2018, 9:55 AM Hans Wennborg via cfe-commits
> >  wrote:
> >>
> >> Author: hans
> >> Date: Tue Mar 20 01:53:11 2018
> >> New Revision: 327959
> >>
> >> URL: http://llvm.org/viewvc/llvm-project?rev=327959=rev
> >> Log:
> >> [ms] Parse #pragma optimize and ignore it behind its own flag
> >>
> >> This allows users to turn off warnings about this pragma specifically,
> >> while still receiving warnings about other ignored pragmas.
> >>
> >> Differential Revision: https://reviews.llvm.org/D44630
> >>
> >> Modified:
> >> cfe/trunk/include/clang/Basic/DiagnosticGroups.td
> >> cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
> >> cfe/trunk/include/clang/Parse/Parser.h
> >> cfe/trunk/lib/Parse/ParsePragma.cpp
> >> cfe/trunk/test/Preprocessor/pragma_microsoft.c
> >>
> >> Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
> >> URL:
> >>
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=327959=327958=327959=diff
> >>
> >>
> ==
> >> --- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
> >> +++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Tue Mar 20
> 01:53:11
> >> 2018
> >> @@ -515,8 +515,13 @@ def UninitializedStaticSelfInit : DiagGr
> >>  def Uninitialized  : DiagGroup<"uninitialized",
> [UninitializedSometimes,
> >>
> >> UninitializedStaticSelfInit]>;
> >>  def IgnoredPragmaIntrinsic : DiagGroup<"ignored-pragma-intrinsic">;
> >> +// #pragma optimize is often used to avoid to work around MSVC codegen
> >> bugs or
> >> +// to disable inlining. It's not completely clear what alternative to
> >> suggest
> >> +// (#pragma clang optimize, noinline) so suggest nothing for now.
> >> +def IgnoredPragmaOptimize : DiagGroup<"ignored-pragma-optimize">;
> >>  def UnknownPragmas : DiagGroup<"unknown-pragmas">;
> >> -def IgnoredPragmas : DiagGroup<"ignored-pragmas",
> >> [IgnoredPragmaIntrinsic]>;
> >> +def IgnoredPragmas : DiagGroup<"ignored-pragmas",
> >> +[IgnoredPragmaIntrinsic, IgnoredPragmaOptimize]>;
> >>  def PragmaClangAttribute : DiagGroup<"pragma-clang-attribute">;
> >>  def PragmaPackSuspiciousInclude :
> >> DiagGroup<"pragma-pack-suspicious-include">;
> >>  def PragmaPack : DiagGroup<"pragma-pack",
> [PragmaPackSuspiciousInclude]>;
> >>
> >> Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
> >> URL:
> >>
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=327959=327958=327959=diff
> >>
> >>
> ==
> >> --- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
> >> +++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Tue Mar 20
> >> 01:53:11 2018
> >> @@ -895,6 +895,12 @@ def warn_pragma_expected_rparen : Warnin
> >>"missing ')' after '#pragma %0' - ignoring">,
> InGroup;
> >>  def warn_pragma_expected_identifier : Warning<
> >>"expected identifier in '#pragma %0' - ignored">,
> >> InGroup;
> >> +def warn_pragma_expected_string : Warning<
> >> +  "expected string literal in '#pragma %0' - ignoring">,
> >> InGroup;
> >> +def warn_pragma_missing_argument : Warning<
> >> +  "missing argument to '#pragma %0'%select{|; expected %2}1">,
> >> InGroup;
> >> +def warn_pragma_invalid_argument : Warning<
> >> +  "unexpected argument '%0' to '#pragma %1'%select{|; expected %3}2">,
> >> InGroup;
> >>
> >>  // '#pragma clang section' related errors
> >>  def err_pragma_expected_clang_section_name : Error<
> >> @@ -923,6 +929,8 @@ def warn_pragma_ms_struct : Warning<
> >>  def warn_pragma_extra_tokens_at_eol : Warning<
> >>"extra tokens at end of '#pragma %0' - ignored">,
> >>InGroup;
> >> +def warn_pragma_expected_comma : Warning<
> >> +  "expected ',' in '#pragma %0'">, InGroup;
> >>  def warn_pragma_expected_punc : Warning<
> >>"expected ')' or ',' in '#pragma %0'">, InGroup;
> >>  def warn_pragma_expected_non_wide_string : Warning<
> >> @@ -960,6 +968,10 @@ def warn_pragma_pack_malformed : Warning
> >>  def warn_pragma_intrinsic_builtin : Warning<
> >>"%0 is not a recognized builtin%select{|; consider including
> 
> >> to access non-builtin intrinsics}1">,
> >>InGroup;
> >> +// - #pragma optimize
> >> +def warn_pragma_optimize : Warning<
> >> +  "'#pragma optimize' is not supported">,
> >> +  InGroup;
> >>  // - 

[PATCH] D44755: [analyzer] Suppress more C++17-related crashes.

2018-03-21 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ created this revision.
NoQ added reviewers: dcoughlin, xazax.hun, a.sidorin, george.karpenkov, szepet.
Herald added subscribers: cfe-commits, rnkovacs.

This is assertion removal. The assertion was saying that a function's return 
value is always a temporary object - which is not true when copy elision is 
happening, C++17 mandatory copy elision in particular (we don't support other 
forms of copy elision yet, but we have no choice but to support this one).


Repository:
  rC Clang

https://reviews.llvm.org/D44755

Files:
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
  test/Analysis/lifetime-extension.cpp
  test/Analysis/temporaries.cpp

Index: test/Analysis/temporaries.cpp
===
--- test/Analysis/temporaries.cpp
+++ test/Analysis/temporaries.cpp
@@ -1,6 +1,9 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-config cfg-temporary-dtors=false -verify -w -std=c++03 %s
 // RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-config cfg-temporary-dtors=false -verify -w -std=c++11 %s
 // RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -DTEMPORARY_DTORS -verify -w -analyzer-config cfg-temporary-dtors=true,c++-temp-dtor-inlining=true %s -std=c++11
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -DTEMPORARY_DTORS -w -analyzer-config cfg-temporary-dtors=true,c++-temp-dtor-inlining=true %s -std=c++17
+
+// Note: The C++17 run-line doesn't -verify yet - it is a no-crash test.
 
 extern bool clang_analyzer_eval(bool);
 extern bool clang_analyzer_warnIfReached();
Index: test/Analysis/lifetime-extension.cpp
===
--- test/Analysis/lifetime-extension.cpp
+++ test/Analysis/lifetime-extension.cpp
@@ -1,7 +1,11 @@
 // RUN: %clang_analyze_cc1 -Wno-unused -std=c++11 -analyzer-checker=core,debug.ExprInspection -analyzer-config cfg-temporary-dtors=false -verify %s
 // RUN: %clang_analyze_cc1 -Wno-unused -std=c++11 -analyzer-checker=core,debug.ExprInspection -analyzer-config cfg-temporary-dtors=true,c++-temp-dtor-inlining=true -DTEMPORARIES -verify %s
+// RUN: %clang_analyze_cc1 -Wno-unused -std=c++17 -analyzer-checker=core,debug.ExprInspection -analyzer-config cfg-temporary-dtors=true,c++-temp-dtor-inlining=true -DTEMPORARIES %s
 // RUN: %clang_analyze_cc1 -Wno-unused -std=c++11 -analyzer-checker=core,debug.ExprInspection -analyzer-config cfg-temporary-dtors=false -DMOVES -verify %s
 // RUN: %clang_analyze_cc1 -Wno-unused -std=c++11 -analyzer-checker=core,debug.ExprInspection -analyzer-config cfg-temporary-dtors=true,c++-temp-dtor-inlining=true -DTEMPORARIES -DMOVES -verify %s
+// RUN: %clang_analyze_cc1 -Wno-unused -std=c++17 -analyzer-checker=core,debug.ExprInspection -analyzer-config cfg-temporary-dtors=true,c++-temp-dtor-inlining=true -DTEMPORARIES -DMOVES %s
+
+// Note: The C++17 run-lines don't -verify yet - it is a no-crash test.
 
 void clang_analyzer_eval(bool);
 void clang_analyzer_checkInlined(bool);
Index: lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -203,6 +203,10 @@
   // TODO: What exactly happens when we are? Does the temporary object live
   // long enough in the region store in this case? Would checkers think
   // that this object immediately goes out of scope?
+  // TODO: We assume that the call site has a temporary object construction
+  // context. This is no longer true in C++17 or when copy elision is
+  // performed. We may need to unwrap multiple stack frames here and we
+  // won't necessarily end up with a temporary at the end.
   const LocationContext *TempLCtx = LCtx;
   if (const LocationContext *CallerLCtx =
   LCtx->getCurrentStackFrame()->getParent()) {
Index: lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -455,29 +455,48 @@
 const LocationContext *LC, const MemRegion *R) {
   const CXXBindTemporaryExpr *BTE = nullptr;
   const MaterializeTemporaryExpr *MTE = nullptr;
-  const LocationContext *TempLC = LC;
 
   if (CC) {
-// In case of temporary object construction, extract data necessary for
-// destruction and lifetime extension.
-const auto *TCC = dyn_cast(CC);
-
 // If the temporary is being returned from the function, it will be
 // destroyed or lifetime-extended in the caller stack frame.
 if (isa(CC)) {
   const StackFrameContext *SFC = LC->getCurrentStackFrame();
   assert(SFC);
-  if (SFC->getParent()) {
-TempLC = SFC->getParent();
-const CFGElement  =
-(*SFC->getCallSiteBlock())[SFC->getIndex()];
- 

[PATCH] D44753: [Preprocessor] Rename __is_{target -> host}_* function-like builtin macros

2018-03-21 Thread Bob Wilson via Phabricator via cfe-commits
bob.wilson added a comment.

Sorry that I missed your earlier comment about this. The confusion could only 
arise in the context of a tool (like a compiler) that is being used for 
cross-compilation. That is a small fraction of the audience for Clang, and we 
should design this in a way that makes the most sense for the majority of 
users. If there's a naming scheme that is better for both, then we should do 
that, but I don't think this is it.

When dealing with a cross compiler, there is a need to distinguish the "target" 
where the compiler will run (which as you point out is typically referred to as 
the "host") from the "target" code produced by that cross compiler. There are 
two points in time: (1) when compiling the cross compiler, and (2) when running 
the cross compiler. In step (1), the compiler will be invoked with a "-target" 
option that specifies the "host". The preprocessor checks are compile-time 
checks, so there no way that one of these macros in the source code of the 
compiler itself could be referring to the target in step (2). The compiler 
option name will be "-target" regardless. Using "target" names in the macros is 
consistent with that compiler option name.

When dealing with anything other than a cross compiler (or similar cross-target 
development tool), the "host" terminology is not commonly used. The obvious 
connection between these macros and the value specified by the "-target" option 
would be lost. I really don't think this is a good alternative.


Repository:
  rC Clang

https://reviews.llvm.org/D44753



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


[PATCH] D40218: [Clang] Add __builtin_launder

2018-03-21 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF marked an inline comment as done.
EricWF added inline comments.



Comment at: lib/CodeGen/CGBuiltin.cpp:1947-1948
+const auto *Record = ArgTy->getAsCXXRecordDecl();
+if (CGM.getCodeGenOpts().StrictVTablePointers && Record &&
+Record->isDynamicClass())
+  Ptr = Builder.CreateInvariantGroupBarrier(Ptr);

rsmith wrote:
> I think you also need to catch class types that contain dynamic classes as 
> subobjects.
Only by-value subobjects, or also reference subobjects?


https://reviews.llvm.org/D40218



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


[PATCH] D44634: [clang-format] Detect Objective-C for #import

2018-03-21 Thread Yan Zhang via Phabricator via cfe-commits
Wizard added a comment.

Why do we only detect system framework? I think any #import could indicate ObjC 
header.


Repository:
  rC Clang

https://reviews.llvm.org/D44634



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


[PATCH] D44747: [AMDGPU] Set calling convention for CUDA kernel

2018-03-21 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In https://reviews.llvm.org/D44747#1044893, @rjmccall wrote:

> Is there a reason for this to be done as a special case in IRGen instead of 
> just implicitly applying the calling convention in Sema?


The calling convention is not used in Sema, therefore it seems simpler to do it 
in codegen. I could try doing this in Sema too. Is there any advantage of doing 
this in Sema?

Thanks.


https://reviews.llvm.org/D44747



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


[PATCH] D44747: [AMDGPU] Set calling convention for CUDA kernel

2018-03-21 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 139359.
yaxunl added a comment.

Upload diff with full context.


https://reviews.llvm.org/D44747

Files:
  lib/CodeGen/CodeGenModule.cpp
  test/CodeGenCUDA/kernel-amdgcn.cu


Index: test/CodeGenCUDA/kernel-amdgcn.cu
===
--- /dev/null
+++ test/CodeGenCUDA/kernel-amdgcn.cu
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -triple amdgcn -fcuda-is-device -emit-llvm %s -o - | 
FileCheck %s
+#include "Inputs/cuda.h"
+
+// CHECK: define amdgpu_kernel void @_ZN1A6kernelEv()
+class A {
+public:
+  static __global__ void kernel(){}
+};
+
+// CHECK: define void @_Z10non_kernelv()
+__device__ void non_kernel(){}
+
+// CHECK: define amdgpu_kernel void @_Z6kerneli(i32 %x)
+__global__ void kernel(int x) {
+  non_kernel();
+}
+
+// CHECK: define amdgpu_kernel void @_Z15template_kernelI1AEvT_()
+template
+__global__ void template_kernel(T x) {}
+
+void launch(void *f);
+
+int main() {
+  launch((void*)A::kernel);
+  launch((void*)kernel);
+  launch((void*)template_kernel);
+  return 0;
+}
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -3590,6 +3590,9 @@
 
   MaybeHandleStaticInExternC(D, Fn);
 
+  if ((getTriple().getArch() == llvm::Triple::amdgcn) &&
+  D->hasAttr())
+Fn->setCallingConv(llvm::CallingConv::AMDGPU_KERNEL);
   maybeSetTrivialComdat(*D, *Fn);
 
   CodeGenFunction(*this).GenerateCode(D, Fn, FI);


Index: test/CodeGenCUDA/kernel-amdgcn.cu
===
--- /dev/null
+++ test/CodeGenCUDA/kernel-amdgcn.cu
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -triple amdgcn -fcuda-is-device -emit-llvm %s -o - | FileCheck %s
+#include "Inputs/cuda.h"
+
+// CHECK: define amdgpu_kernel void @_ZN1A6kernelEv()
+class A {
+public:
+  static __global__ void kernel(){}
+};
+
+// CHECK: define void @_Z10non_kernelv()
+__device__ void non_kernel(){}
+
+// CHECK: define amdgpu_kernel void @_Z6kerneli(i32 %x)
+__global__ void kernel(int x) {
+  non_kernel();
+}
+
+// CHECK: define amdgpu_kernel void @_Z15template_kernelI1AEvT_()
+template
+__global__ void template_kernel(T x) {}
+
+void launch(void *f);
+
+int main() {
+  launch((void*)A::kernel);
+  launch((void*)kernel);
+  launch((void*)template_kernel);
+  return 0;
+}
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -3590,6 +3590,9 @@
 
   MaybeHandleStaticInExternC(D, Fn);
 
+  if ((getTriple().getArch() == llvm::Triple::amdgcn) &&
+  D->hasAttr())
+Fn->setCallingConv(llvm::CallingConv::AMDGPU_KERNEL);
   maybeSetTrivialComdat(*D, *Fn);
 
   CodeGenFunction(*this).GenerateCode(D, Fn, FI);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r327959 - [ms] Parse #pragma optimize and ignore it behind its own flag

2018-03-21 Thread Hans Wennborg via cfe-commits
Aw, rats. I put it under -Wignored-pragmas rather than
-Wunsupported-pragmas, because I was looking at #pragma intrinsic.

I'll take a look at this again tomorrow.

On Wed, Mar 21, 2018 at 5:18 PM, Nico Weber via cfe-commits
 wrote:
> From the bot changes, it seems that -Wunknown-pragma doesn't disable this
> new warning. Shouldn't it do that?
>
> On Tue, Mar 20, 2018, 9:55 AM Hans Wennborg via cfe-commits
>  wrote:
>>
>> Author: hans
>> Date: Tue Mar 20 01:53:11 2018
>> New Revision: 327959
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=327959=rev
>> Log:
>> [ms] Parse #pragma optimize and ignore it behind its own flag
>>
>> This allows users to turn off warnings about this pragma specifically,
>> while still receiving warnings about other ignored pragmas.
>>
>> Differential Revision: https://reviews.llvm.org/D44630
>>
>> Modified:
>> cfe/trunk/include/clang/Basic/DiagnosticGroups.td
>> cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
>> cfe/trunk/include/clang/Parse/Parser.h
>> cfe/trunk/lib/Parse/ParsePragma.cpp
>> cfe/trunk/test/Preprocessor/pragma_microsoft.c
>>
>> Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=327959=327958=327959=diff
>>
>> ==
>> --- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
>> +++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Tue Mar 20 01:53:11
>> 2018
>> @@ -515,8 +515,13 @@ def UninitializedStaticSelfInit : DiagGr
>>  def Uninitialized  : DiagGroup<"uninitialized", [UninitializedSometimes,
>>
>> UninitializedStaticSelfInit]>;
>>  def IgnoredPragmaIntrinsic : DiagGroup<"ignored-pragma-intrinsic">;
>> +// #pragma optimize is often used to avoid to work around MSVC codegen
>> bugs or
>> +// to disable inlining. It's not completely clear what alternative to
>> suggest
>> +// (#pragma clang optimize, noinline) so suggest nothing for now.
>> +def IgnoredPragmaOptimize : DiagGroup<"ignored-pragma-optimize">;
>>  def UnknownPragmas : DiagGroup<"unknown-pragmas">;
>> -def IgnoredPragmas : DiagGroup<"ignored-pragmas",
>> [IgnoredPragmaIntrinsic]>;
>> +def IgnoredPragmas : DiagGroup<"ignored-pragmas",
>> +[IgnoredPragmaIntrinsic, IgnoredPragmaOptimize]>;
>>  def PragmaClangAttribute : DiagGroup<"pragma-clang-attribute">;
>>  def PragmaPackSuspiciousInclude :
>> DiagGroup<"pragma-pack-suspicious-include">;
>>  def PragmaPack : DiagGroup<"pragma-pack", [PragmaPackSuspiciousInclude]>;
>>
>> Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=327959=327958=327959=diff
>>
>> ==
>> --- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
>> +++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Tue Mar 20
>> 01:53:11 2018
>> @@ -895,6 +895,12 @@ def warn_pragma_expected_rparen : Warnin
>>"missing ')' after '#pragma %0' - ignoring">, InGroup;
>>  def warn_pragma_expected_identifier : Warning<
>>"expected identifier in '#pragma %0' - ignored">,
>> InGroup;
>> +def warn_pragma_expected_string : Warning<
>> +  "expected string literal in '#pragma %0' - ignoring">,
>> InGroup;
>> +def warn_pragma_missing_argument : Warning<
>> +  "missing argument to '#pragma %0'%select{|; expected %2}1">,
>> InGroup;
>> +def warn_pragma_invalid_argument : Warning<
>> +  "unexpected argument '%0' to '#pragma %1'%select{|; expected %3}2">,
>> InGroup;
>>
>>  // '#pragma clang section' related errors
>>  def err_pragma_expected_clang_section_name : Error<
>> @@ -923,6 +929,8 @@ def warn_pragma_ms_struct : Warning<
>>  def warn_pragma_extra_tokens_at_eol : Warning<
>>"extra tokens at end of '#pragma %0' - ignored">,
>>InGroup;
>> +def warn_pragma_expected_comma : Warning<
>> +  "expected ',' in '#pragma %0'">, InGroup;
>>  def warn_pragma_expected_punc : Warning<
>>"expected ')' or ',' in '#pragma %0'">, InGroup;
>>  def warn_pragma_expected_non_wide_string : Warning<
>> @@ -960,6 +968,10 @@ def warn_pragma_pack_malformed : Warning
>>  def warn_pragma_intrinsic_builtin : Warning<
>>"%0 is not a recognized builtin%select{|; consider including 
>> to access non-builtin intrinsics}1">,
>>InGroup;
>> +// - #pragma optimize
>> +def warn_pragma_optimize : Warning<
>> +  "'#pragma optimize' is not supported">,
>> +  InGroup;
>>  // - #pragma unused
>>  def warn_pragma_unused_expected_var : Warning<
>>"expected '#pragma unused' argument to be a variable name">,
>>
>> Modified: cfe/trunk/include/clang/Parse/Parser.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=327959=327958=327959=diff
>>
>> 

[PATCH] D44747: [AMDGPU] Set calling convention for CUDA kernel

2018-03-21 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Is there a reason for this to be done as a special case in IRGen instead of 
just implicitly applying the calling convention in Sema?


https://reviews.llvm.org/D44747



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


[PATCH] D44753: [Preprocessor] Rename __is_{target -> host}_* function-like builtin macros

2018-03-21 Thread John Ericson via Phabricator via cfe-commits
Ericson2314 created this revision.
Ericson2314 added reviewers: arphaman, compnerd, dexonsmith, bob.wilson, 
steven_wu.
Herald added subscribers: cfe-commits, javed.absar.

Per my belated [reply] to the mailing list, I believe the "target"
nomenclature incorrect for cross compilation.

[reply]: http://lists.llvm.org/pipermail/cfe-dev/2018-March/057258.html


Repository:
  rC Clang

https://reviews.llvm.org/D44753

Files:
  include/clang/Lex/Preprocessor.h
  lib/Lex/PPMacroExpansion.cpp
  test/Preprocessor/is_host.c
  test/Preprocessor/is_host_arm.c
  test/Preprocessor/is_host_arm64.c
  test/Preprocessor/is_host_environment_version.c
  test/Preprocessor/is_host_os_darwin.c
  test/Preprocessor/is_host_unknown.c
  test/Preprocessor/is_target.c
  test/Preprocessor/is_target_arm.c
  test/Preprocessor/is_target_arm64.c
  test/Preprocessor/is_target_environment_version.c
  test/Preprocessor/is_target_os_darwin.c
  test/Preprocessor/is_target_unknown.c

Index: test/Preprocessor/is_target.c
===
--- test/Preprocessor/is_target.c
+++ /dev/null
@@ -1,67 +0,0 @@
-// RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-darwin-simulator -verify %s
-
-#if !__is_target_arch(x86_64) || !__is_target_arch(X86_64)
-  #error "mismatching arch"
-#endif
-
-#if __is_target_arch(arm64)
-  #error "mismatching arch"
-#endif
-
-// Silently ignore invalid archs. This will ensure that older compilers will
-// accept headers that support new arches/vendors/os variants.
-#if __is_target_arch(foo)
-  #error "invalid arch"
-#endif
-
-#if !__is_target_vendor(apple) || !__is_target_vendor(APPLE)
-  #error "mismatching vendor"
-#endif
-
-#if __is_target_vendor(unknown)
-  #error "mismatching vendor"
-#endif
-
-#if __is_target_vendor(foo)
-  #error "invalid vendor"
-#endif
-
-#if !__is_target_os(darwin) || !__is_target_os(DARWIN)
-  #error "mismatching os"
-#endif
-
-#if __is_target_os(ios)
-  #error "mismatching os"
-#endif
-
-#if __is_target_os(foo)
-  #error "invalid os"
-#endif
-
-#if !__is_target_environment(simulator) || !__is_target_environment(SIMULATOR)
-  #error "mismatching environment"
-#endif
-
-#if __is_target_environment(unknown)
-  #error "mismatching environment"
-#endif
-
-#if __is_target_environment(foo)
-  #error "invalid environment"
-#endif
-
-#if !__has_builtin(__is_target_arch) || !__has_builtin(__is_target_os) || !__has_builtin(__is_target_vendor) || !__has_builtin(__is_target_environment)
-  #error "has builtin doesn't work"
-#endif
-
-#if __is_target_arch(11) // expected-error {{builtin feature check macro requires a parenthesized identifier}}
-  #error "invalid arch"
-#endif
-
-#if __is_target_arch x86 // expected-error{{missing '(' after '__is_target_arch'}}
-  #error "invalid arch"
-#endif
-
-#if __is_target_arch ( x86  // expected-error {{unterminated function-like macro invocation}}
-  #error "invalid arch"
-#endif // expected-error@-2 {{expected value in expression}}
Index: test/Preprocessor/is_host_unknown.c
===
--- test/Preprocessor/is_host_unknown.c
+++ test/Preprocessor/is_host_unknown.c
@@ -2,21 +2,21 @@
 // RUN: %clang_cc1 -fsyntax-only -triple i686-- -verify %s
 // expected-no-diagnostics
 
-#if __is_target_arch(unknown)
+#if __is_host_arch(unknown)
   #error "mismatching arch"
 #endif
 
 // Unknown vendor is allowed.
-#if !__is_target_vendor(unknown)
+#if !__is_host_vendor(unknown)
   #error "mismatching vendor"
 #endif
 
 // Unknown OS is allowed.
-#if !__is_target_os(unknown)
+#if !__is_host_os(unknown)
   #error "mismatching OS"
 #endif
 
 // Unknown environment is allowed.
-#if !__is_target_environment(unknown)
+#if !__is_host_environment(unknown)
   #error "mismatching environment"
 #endif
Index: test/Preprocessor/is_host_os_darwin.c
===
--- test/Preprocessor/is_host_os_darwin.c
+++ test/Preprocessor/is_host_os_darwin.c
@@ -4,22 +4,22 @@
 // RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-watchos -verify %s
 // expected-no-diagnostics
 
-#if !__is_target_os(darwin)
+#if !__is_host_os(darwin)
   #error "mismatching os"
 #endif
 
 // macOS matches both macOS and macOSX.
 #ifdef MAC
 
-#if !__is_target_os(macos)
+#if !__is_host_os(macos)
   #error "mismatching os"
 #endif
 
-#if !__is_target_os(macosx)
+#if !__is_host_os(macosx)
   #error "mismatching os"
 #endif
 
-#if __is_target_os(ios)
+#if __is_host_os(ios)
   #error "mismatching os"
 #endif
 
Index: test/Preprocessor/is_host_environment_version.c
===
--- test/Preprocessor/is_host_environment_version.c
+++ test/Preprocessor/is_host_environment_version.c
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -fsyntax-only -triple x86_64-pc-windows-msvc18.0.0 -verify %s
 // expected-no-diagnostics
 
-#if !__is_target_environment(msvc)
+#if !__is_host_environment(msvc)
   #error "mismatching environment"
 #endif

[PATCH] D44272: [clangd] Support incremental document syncing

2018-03-21 Thread Simon Marchi via Phabricator via cfe-commits
simark updated this revision to Diff 139355.
simark marked an inline comment as done.
simark added a comment.

Address review comments I failed to address previously


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44272

Files:
  clangd/ClangdLSPServer.cpp
  clangd/DraftStore.cpp
  clangd/DraftStore.h
  clangd/Protocol.cpp
  clangd/Protocol.h
  test/clangd/initialize-params-invalid.test
  test/clangd/initialize-params.test
  test/clangd/textdocument-didchange-fail.test
  unittests/clangd/CMakeLists.txt
  unittests/clangd/DraftStoreTests.cpp

Index: unittests/clangd/DraftStoreTests.cpp
===
--- /dev/null
+++ unittests/clangd/DraftStoreTests.cpp
@@ -0,0 +1,353 @@
+//===-- DraftStoreTests.cpp - Clangd unit tests -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "Annotations.h"
+#include "DraftStore.h"
+#include "SourceCode.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace clangd {
+namespace {
+
+using namespace llvm;
+
+struct IncrementalTestStep {
+  StringRef Src;
+  StringRef Contents;
+};
+
+int rangeLength(StringRef Code, const Range ) {
+  llvm::Expected Start = positionToOffset(Code, Rng.start);
+  llvm::Expected End = positionToOffset(Code, Rng.end);
+  assert(Start);
+  assert(End);
+  return *End - *Start;
+}
+
+/// Send the changes one by one to updateDraft, verify the intermediate results.
+static void stepByStep(llvm::ArrayRef Steps) {
+  DraftStore DS;
+  Annotations InitialSrc(Steps.front().Src);
+  constexpr StringLiteral Path("/hello.cpp");
+
+  // Set the initial content.
+  DS.addDraft(Path, InitialSrc.code());
+
+  for (size_t i = 1; i < Steps.size(); i++) {
+Annotations SrcBefore(Steps[i - 1].Src);
+Annotations SrcAfter(Steps[i].Src);
+StringRef Contents = Steps[i - 1].Contents;
+TextDocumentContentChangeEvent Event{
+SrcBefore.range(),
+rangeLength(SrcBefore.code(), SrcBefore.range()),
+Contents.str(),
+};
+
+llvm::Expected Result = DS.updateDraft(Path, {Event});
+ASSERT_TRUE(!!Result);
+EXPECT_EQ(*Result, SrcAfter.code());
+EXPECT_EQ(*DS.getDraft(Path), SrcAfter.code());
+  }
+}
+
+/// Send all the changes at once to updateDraft, check only the final result.
+static void allAtOnce(llvm::ArrayRef Steps) {
+  DraftStore DS;
+  Annotations InitialSrc(Steps.front().Src);
+  Annotations FinalSrc(Steps.back().Src);
+  const char Path[] = "/hello.cpp";
+  std::vector Changes;
+
+  for (size_t i = 0; i < Steps.size() - 1; i++) {
+Annotations Src(Steps[i].Src);
+StringRef Contents = Steps[i].Contents;
+
+Changes.push_back({
+Src.range(),
+rangeLength(Src.code(), Src.range()),
+Contents.str(),
+});
+  }
+
+  // Set the initial content.
+  DS.addDraft(Path, InitialSrc.code());
+
+  llvm::Expected Result = DS.updateDraft(Path, Changes);
+
+  ASSERT_TRUE(!!Result) << llvm::toString(Result.takeError());
+  EXPECT_EQ(*Result, FinalSrc.code());
+  EXPECT_EQ(*DS.getDraft(Path), FinalSrc.code());
+}
+
+TEST(DraftStoreIncrementalUpdateTest, Simple) {
+  // clang-format off
+  IncrementalTestStep Steps[] =
+{
+  // Replace a range
+  {
+R"cpp(static int
+hello[[World]]()
+{})cpp",
+"Universe"
+  },
+  // Delete a range
+  {
+R"cpp(static int
+hello[[Universe]]()
+{})cpp",
+""
+  },
+  // Add a range
+  {
+R"cpp(static int
+hello[[]]()
+{})cpp",
+"Monde"
+  },
+  {
+R"cpp(static int
+helloMonde()
+{})cpp",
+""
+  }
+};
+  // clang-format on
+
+  stepByStep(Steps);
+  allAtOnce(Steps);
+}
+
+TEST(DraftStoreIncrementalUpdateTest, MultiLine) {
+  // clang-format off
+  IncrementalTestStep Steps[] =
+{
+  // Replace a range
+  {
+R"cpp(static [[int
+helloWorld]]()
+{})cpp",
+R"cpp(char
+welcome)cpp"
+  },
+  // Delete a range
+  {
+R"cpp(static char[[
+welcome]]()
+{})cpp",
+""
+  },
+  // Add a range
+  {
+R"cpp(static char[[]]()
+{})cpp",
+R"cpp(
+cookies)cpp"
+  },
+  // Replace the whole file
+  {
+R"cpp([[static char
+cookies()
+{}]])cpp",
+R"cpp(#include 
+)cpp"
+  },
+  // Delete the whole file
+  {
+R"cpp([[#include 
+]])cpp",
+"",
+  },
+  // Add something to an empty file
+  {
+"[[]]",
+R"cpp(int main() {
+)cpp",
+  },
+  {
+R"cpp(int main() {
+)cpp",
+""
+  }
+};
+  // clang-format on
+
+  stepByStep(Steps);
+  allAtOnce(Steps);
+}
+
+TEST(DraftStoreIncrementalUpdateTest, WrongRangeLength) {
+  DraftStore DS;
+  Path File = "foo.cpp";
+
+  DS.addDraft(File, "int main() {}\n");
+
+  

[PATCH] D44272: [clangd] Support incremental document syncing

2018-03-21 Thread Simon Marchi via Phabricator via cfe-commits
simark marked 6 inline comments as done.
simark added inline comments.
Herald added a subscriber: MaskRay.



Comment at: unittests/clangd/DraftStoreTests.cpp:27
+
+static int rangeLength(StringRef Code, const Range ) {
+  size_t Start = positionToOffset(Code, Rng.start);

ilya-biryukov wrote:
> ilya-biryukov wrote:
> > no need for `static`, since function is already inside an anonymous 
> > namespace.
> > remove it?
> This comment is marked as done, but not addressed.
Hmm I addressed the comments at two different times, but I probably messed up 
my branches or something, so I lost the changes of my first pass.  Sorry about 
that.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44272



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


[PATCH] D44720: [clangd] Simplify fuzzy matcher (sequence alignment) by removing some condition checks.

2018-03-21 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clangd/FuzzyMatch.h:61
   bool allowMatch(int P, int W) const;
-  int skipPenalty(int W, Action Last) const;
-  int matchBonus(int P, int W, Action Last) const;
+  int missScore(int W, Action Last) const;
+  int matchScore(int P, int W, Action Last) const;

MaskRay wrote:
> sammccall wrote:
> > FWIW, I don't think this is an improvement - I think the clarity of purpose 
> > in names is more useful than having consistent signs in this case.
> Keep `matchBonus` but rename `skipPenalty` to `missPenalty` ?
Also note in the original scheme, the skip score does not need to be negative. 
Because Scores[PatN][WordN][] is used and each path takes the same number of 
positions (WordN). We can add an offset to all positional scores to make all of 
them non-negative. In the new scheme it does make sense to make them negative, 
as each path has now different number of positions.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44720



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


[PATCH] D43047: [Builtins] Overload __builtin_operator_new/delete to allow forwarding to usual allocation/deallocation functions.

2018-03-21 Thread Eric Fiselier via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL328134: [Builtins] Overload __builtin_operator_new/delete to 
allow forwarding to usual… (authored by EricWF, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D43047?vs=139347=139350#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D43047

Files:
  cfe/trunk/include/clang/Basic/Builtins.def
  cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
  cfe/trunk/include/clang/Sema/Sema.h
  cfe/trunk/lib/CodeGen/CGBuiltin.cpp
  cfe/trunk/lib/CodeGen/CGExprCXX.cpp
  cfe/trunk/lib/CodeGen/CodeGenFunction.h
  cfe/trunk/lib/Lex/PPMacroExpansion.cpp
  cfe/trunk/lib/Sema/SemaChecking.cpp
  cfe/trunk/lib/Sema/SemaExprCXX.cpp
  cfe/trunk/test/CodeGenCXX/builtin-operator-new-delete.cpp
  cfe/trunk/test/SemaCXX/builtin-operator-new-delete.cpp

Index: cfe/trunk/lib/Lex/PPMacroExpansion.cpp
===
--- cfe/trunk/lib/Lex/PPMacroExpansion.cpp
+++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp
@@ -1801,12 +1801,21 @@
   [this](Token , bool ) -> int {
 IdentifierInfo *II = ExpectFeatureIdentifierInfo(Tok, *this,
diag::err_feature_check_malformed);
+const LangOptions  = getLangOpts();
 if (!II)
   return false;
-else if (II->getBuiltinID() != 0)
+else if (II->getBuiltinID() != 0) {
+  switch (II->getBuiltinID()) {
+  case Builtin::BI__builtin_operator_new:
+  case Builtin::BI__builtin_operator_delete:
+// denotes date of behavior change to support calling arbitrary
+// usual allocation and deallocation functions. Required by libc++
+return 201802;
+  default:
+return true;
+  }
   return true;
-else {
-  const LangOptions  = getLangOpts();
+} else {
   return llvm::StringSwitch(II->getName())
   .Case("__make_integer_seq", LangOpts.CPlusPlus)
   .Case("__type_pack_element", LangOpts.CPlusPlus)
Index: cfe/trunk/lib/Sema/SemaChecking.cpp
===
--- cfe/trunk/lib/Sema/SemaChecking.cpp
+++ cfe/trunk/lib/Sema/SemaChecking.cpp
@@ -1097,20 +1097,14 @@
   return ExprError();
 break;
   case Builtin::BI__builtin_operator_new:
-  case Builtin::BI__builtin_operator_delete:
-if (!getLangOpts().CPlusPlus) {
-  Diag(TheCall->getExprLoc(), diag::err_builtin_requires_language)
-<< (BuiltinID == Builtin::BI__builtin_operator_new
-? "__builtin_operator_new"
-: "__builtin_operator_delete")
-<< "C++";
-  return ExprError();
-}
-// CodeGen assumes it can find the global new and delete to call,
-// so ensure that they are declared.
-DeclareGlobalNewDelete();
-break;
-
+  case Builtin::BI__builtin_operator_delete: {
+bool IsDelete = BuiltinID == Builtin::BI__builtin_operator_delete;
+ExprResult Res =
+SemaBuiltinOperatorNewDeleteOverloaded(TheCallResult, IsDelete);
+if (Res.isInvalid())
+  CorrectDelayedTyposInExpr(TheCallResult.get());
+return Res;
+  }
   // check secure string manipulation functions where overflows
   // are detectable at compile time
   case Builtin::BI__builtin___memcpy_chk:
Index: cfe/trunk/lib/Sema/SemaExprCXX.cpp
===
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp
@@ -1443,7 +1443,7 @@
   CUDAPref = S.IdentifyCUDAPreference(Caller, FD);
 }
 
-operator bool() const { return FD; }
+explicit operator bool() const { return FD; }
 
 bool isBetterThan(const UsualDeallocFnInfo , bool WantSize,
   bool WantAlign) const {
@@ -2271,7 +2271,6 @@
   llvm_unreachable("Unreachable, bad result from BestViableFunction");
 }
 
-
 /// FindAllocationFunctions - Finds the overloads of operator new and delete
 /// that are appropriate for the allocation.
 bool Sema::FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range,
@@ -3343,6 +3342,128 @@
   return Result;
 }
 
+static bool resolveBuiltinNewDeleteOverload(Sema , CallExpr *TheCall,
+bool IsDelete,
+FunctionDecl *) {
+
+  DeclarationName NewName = S.Context.DeclarationNames.getCXXOperatorName(
+  IsDelete ? OO_Delete : OO_New);
+
+  LookupResult R(S, NewName, TheCall->getLocStart(), Sema::LookupOrdinaryName);
+  S.LookupQualifiedName(R, S.Context.getTranslationUnitDecl());
+  assert(!R.empty() && "implicitly declared allocation functions not found");
+  assert(!R.isAmbiguous() && "global allocation functions are ambiguous");
+
+  // We do our own custom access checks below.
+  R.suppressDiagnostics();
+
+  SmallVector 

[PATCH] D43047: [Builtins] Overload __builtin_operator_new/delete to allow forwarding to usual allocation/deallocation functions.

2018-03-21 Thread Eric Fiselier via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC328134: [Builtins] Overload __builtin_operator_new/delete to 
allow forwarding to usual… (authored by EricWF, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D43047

Files:
  include/clang/Basic/Builtins.def
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/Sema.h
  lib/CodeGen/CGBuiltin.cpp
  lib/CodeGen/CGExprCXX.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/Lex/PPMacroExpansion.cpp
  lib/Sema/SemaChecking.cpp
  lib/Sema/SemaExprCXX.cpp
  test/CodeGenCXX/builtin-operator-new-delete.cpp
  test/SemaCXX/builtin-operator-new-delete.cpp

Index: lib/Sema/SemaExprCXX.cpp
===
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -1443,7 +1443,7 @@
   CUDAPref = S.IdentifyCUDAPreference(Caller, FD);
 }
 
-operator bool() const { return FD; }
+explicit operator bool() const { return FD; }
 
 bool isBetterThan(const UsualDeallocFnInfo , bool WantSize,
   bool WantAlign) const {
@@ -2271,7 +2271,6 @@
   llvm_unreachable("Unreachable, bad result from BestViableFunction");
 }
 
-
 /// FindAllocationFunctions - Finds the overloads of operator new and delete
 /// that are appropriate for the allocation.
 bool Sema::FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range,
@@ -3343,6 +3342,128 @@
   return Result;
 }
 
+static bool resolveBuiltinNewDeleteOverload(Sema , CallExpr *TheCall,
+bool IsDelete,
+FunctionDecl *) {
+
+  DeclarationName NewName = S.Context.DeclarationNames.getCXXOperatorName(
+  IsDelete ? OO_Delete : OO_New);
+
+  LookupResult R(S, NewName, TheCall->getLocStart(), Sema::LookupOrdinaryName);
+  S.LookupQualifiedName(R, S.Context.getTranslationUnitDecl());
+  assert(!R.empty() && "implicitly declared allocation functions not found");
+  assert(!R.isAmbiguous() && "global allocation functions are ambiguous");
+
+  // We do our own custom access checks below.
+  R.suppressDiagnostics();
+
+  SmallVector Args(TheCall->arg_begin(), TheCall->arg_end());
+  OverloadCandidateSet Candidates(R.getNameLoc(),
+  OverloadCandidateSet::CSK_Normal);
+  for (LookupResult::iterator FnOvl = R.begin(), FnOvlEnd = R.end();
+   FnOvl != FnOvlEnd; ++FnOvl) {
+// Even member operator new/delete are implicitly treated as
+// static, so don't use AddMemberCandidate.
+NamedDecl *D = (*FnOvl)->getUnderlyingDecl();
+
+if (FunctionTemplateDecl *FnTemplate = dyn_cast(D)) {
+  S.AddTemplateOverloadCandidate(FnTemplate, FnOvl.getPair(),
+ /*ExplicitTemplateArgs=*/nullptr, Args,
+ Candidates,
+ /*SuppressUserConversions=*/false);
+  continue;
+}
+
+FunctionDecl *Fn = cast(D);
+S.AddOverloadCandidate(Fn, FnOvl.getPair(), Args, Candidates,
+   /*SuppressUserConversions=*/false);
+  }
+
+  SourceRange Range = TheCall->getSourceRange();
+
+  // Do the resolution.
+  OverloadCandidateSet::iterator Best;
+  switch (Candidates.BestViableFunction(S, R.getNameLoc(), Best)) {
+  case OR_Success: {
+// Got one!
+FunctionDecl *FnDecl = Best->Function;
+assert(R.getNamingClass() == nullptr &&
+   "class members should not be considered");
+
+if (!FnDecl->isReplaceableGlobalAllocationFunction()) {
+  S.Diag(R.getNameLoc(), diag::err_builtin_operator_new_delete_not_usual)
+  << (IsDelete ? 1 : 0) << Range;
+  S.Diag(FnDecl->getLocation(), diag::note_non_usual_function_declared_here)
+  << R.getLookupName() << FnDecl->getSourceRange();
+  return true;
+}
+
+Operator = FnDecl;
+return false;
+  }
+
+  case OR_No_Viable_Function:
+S.Diag(R.getNameLoc(), diag::err_ovl_no_viable_function_in_call)
+<< R.getLookupName() << Range;
+Candidates.NoteCandidates(S, OCD_AllCandidates, Args);
+return true;
+
+  case OR_Ambiguous:
+S.Diag(R.getNameLoc(), diag::err_ovl_ambiguous_call)
+<< R.getLookupName() << Range;
+Candidates.NoteCandidates(S, OCD_ViableCandidates, Args);
+return true;
+
+  case OR_Deleted: {
+S.Diag(R.getNameLoc(), diag::err_ovl_deleted_call)
+<< Best->Function->isDeleted() << R.getLookupName()
+<< S.getDeletedOrUnavailableSuffix(Best->Function) << Range;
+Candidates.NoteCandidates(S, OCD_AllCandidates, Args);
+return true;
+  }
+  }
+  llvm_unreachable("Unreachable, bad result from BestViableFunction");
+}
+
+ExprResult
+Sema::SemaBuiltinOperatorNewDeleteOverloaded(ExprResult TheCallResult,
+ bool IsDelete) {
+  CallExpr *TheCall = cast(TheCallResult.get());
+  if (!getLangOpts().CPlusPlus) {
+Diag(TheCall->getExprLoc(), 

r328134 - [Builtins] Overload __builtin_operator_new/delete to allow forwarding to usual allocation/deallocation functions.

2018-03-21 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Wed Mar 21 12:19:48 2018
New Revision: 328134

URL: http://llvm.org/viewvc/llvm-project?rev=328134=rev
Log:
[Builtins] Overload __builtin_operator_new/delete to allow forwarding to usual 
allocation/deallocation functions.

Summary:
Libc++'s default allocator uses `__builtin_operator_new` and 
`__builtin_operator_delete` in order to allow the calls to new/delete to be 
ellided. However, libc++ now needs to support over-aligned types in the default 
allocator. In order to support this without disabling the existing optimization 
Clang needs to support calling the aligned new overloads from the builtins.

See llvm.org/PR22634 for more information about the libc++ bug.

This patch changes `__builtin_operator_new`/`__builtin_operator_delete` to call 
any usual `operator new`/`operator delete` function. It does this by performing 
overload resolution with the arguments passed to the builtin to determine which 
allocation function to call. If the selected function is not a usual allocation 
function a diagnostic is issued.

One open issue is if the `align_val_t` overloads should be considered "usual" 
when `LangOpts::AlignedAllocation` is disabled.


In order to allow libc++ to detect this new behavior the value for 
`__has_builtin(__builtin_operator_new)` has been updated to `201802`.

Reviewers: rsmith, majnemer, aaron.ballman, erik.pilkington, bogner, ahatanak

Reviewed By: rsmith

Subscribers: cfe-commits

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

Added:
cfe/trunk/test/CodeGenCXX/builtin-operator-new-delete.cpp
cfe/trunk/test/SemaCXX/builtin-operator-new-delete.cpp
Modified:
cfe/trunk/include/clang/Basic/Builtins.def
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/lib/CodeGen/CGExprCXX.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/Lex/PPMacroExpansion.cpp
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/lib/Sema/SemaExprCXX.cpp

Modified: cfe/trunk/include/clang/Basic/Builtins.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Builtins.def?rev=328134=328133=328134=diff
==
--- cfe/trunk/include/clang/Basic/Builtins.def (original)
+++ cfe/trunk/include/clang/Basic/Builtins.def Wed Mar 21 12:19:48 2018
@@ -1371,8 +1371,8 @@ BUILTIN(__builtin_smulll_overflow, "bSLL
 
 // Clang builtins (not available in GCC).
 BUILTIN(__builtin_addressof, "v*v&", "nct")
-BUILTIN(__builtin_operator_new, "v*z", "c")
-BUILTIN(__builtin_operator_delete, "vv*", "n")
+BUILTIN(__builtin_operator_new, "v*z", "tc")
+BUILTIN(__builtin_operator_delete, "vv*", "tn")
 BUILTIN(__builtin_char_memchr, "c*cC*iz", "n")
 
 // Safestack builtins

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=328134=328133=328134=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Mar 21 12:19:48 
2018
@@ -7627,6 +7627,11 @@ def err_destroying_operator_delete_not_u
   "alignment parameter">;
 def note_implicit_delete_this_in_destructor_here : Note<
   "while checking implicit 'delete this' for virtual destructor">;
+def err_builtin_operator_new_delete_not_usual : Error<
+  "call to '%select{__builtin_operator_new|__builtin_operator_delete}0' "
+  "selects non-usual %select{allocation|deallocation}0 function">;
+def note_non_usual_function_declared_here : Note<
+  "non-usual %0 declared here">;
 
 // C++ literal operators
 def err_literal_operator_outside_namespace : Error<

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=328134=328133=328134=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Wed Mar 21 12:19:48 2018
@@ -10376,6 +10376,8 @@ private:
   ExprResult SemaBuiltinNontemporalOverloaded(ExprResult TheCallResult);
   ExprResult SemaAtomicOpsOverloaded(ExprResult TheCallResult,
  AtomicExpr::AtomicOp Op);
+  ExprResult SemaBuiltinOperatorNewDeleteOverloaded(ExprResult TheCallResult,
+bool IsDelete);
   bool SemaBuiltinConstantArg(CallExpr *TheCall, int ArgNum,
   llvm::APSInt );
   bool SemaBuiltinConstantArgRange(CallExpr *TheCall, int ArgNum,

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=328134=328133=328134=diff
==
--- 

[PATCH] D43047: [Builtins] Overload __builtin_operator_new/delete to allow forwarding to usual allocation/deallocation functions.

2018-03-21 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF added inline comments.



Comment at: lib/Sema/SemaExprCXX.cpp:3458
+  }
+  TheCall->getCallee()->setType(OperatorNewOrDelete->getType());
+

rsmith wrote:
> It would be nice to assert that the callee you're setting the type of is an 
> ImplicitCastExpr doing a BuiltinFnToFnPtr cast (just so that it's obvious 
> that this is the only type we need to update and that it's freshly-created).
Ack. Done.


https://reviews.llvm.org/D43047



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


[PATCH] D43047: [Builtins] Overload __builtin_operator_new/delete to allow forwarding to usual allocation/deallocation functions.

2018-03-21 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF updated this revision to Diff 139347.
EricWF marked an inline comment as done.
EricWF added a comment.

- Merge with upstream.
- Add requested assertion.


https://reviews.llvm.org/D43047

Files:
  include/clang/Basic/Builtins.def
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/Sema.h
  lib/CodeGen/CGBuiltin.cpp
  lib/CodeGen/CGExprCXX.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/Lex/PPMacroExpansion.cpp
  lib/Sema/SemaChecking.cpp
  lib/Sema/SemaExprCXX.cpp
  test/CodeGenCXX/builtin-operator-new-delete.cpp
  test/SemaCXX/builtin-operator-new-delete.cpp

Index: test/SemaCXX/builtin-operator-new-delete.cpp
===
--- /dev/null
+++ test/SemaCXX/builtin-operator-new-delete.cpp
@@ -0,0 +1,153 @@
+// RUN: %clang_cc1 -std=c++1z -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++03 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++03 -faligned-allocation -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -fsized-deallocation %s
+
+#if !__has_builtin(__builtin_operator_new) || !__has_builtin(__builtin_operator_delete)
+#error builtins should always be available
+#endif
+
+#if __has_builtin(__builtin_operator_new) != 201802L || \
+__has_builtin(__builtin_operator_delete) != 201802L
+#error builtin should report updated value
+#endif
+
+typedef __SIZE_TYPE__ size_t;
+namespace std {
+  struct nothrow_t {};
+#if __cplusplus >= 201103L
+enum class align_val_t : size_t {};
+#else
+  enum align_val_t { __zero = 0,
+ __max = (size_t)-1 };
+#endif
+}
+std::nothrow_t nothrow;
+
+void *operator new(size_t); // expected-note 1+ {{candidate function}}
+void operator delete(void *); // expected-note 1+ {{candidate function}}
+
+// Declare the reserved placement operators.
+void *operator new(size_t, void*) throw(); // expected-note 1+ {{candidate function}}
+void operator delete(void *, void *)throw(); // expected-note 1+ {{candidate function}}
+void *operator new[](size_t, void*) throw();
+void operator delete[](void*, void*) throw();
+
+// Declare the replaceable global allocation operators.
+void *operator new(size_t, const std::nothrow_t &) throw(); // expected-note 1+ {{candidate function}}
+void *operator new[](size_t, const std::nothrow_t &) throw();
+void operator delete(void *, const std::nothrow_t &)throw(); // expected-note 1+ {{candidate function}}
+void operator delete[](void *, const std::nothrow_t &) throw();
+
+// aligned allocation and deallocation functions.
+void* operator new  ( size_t count, std::align_val_t al); // expected-note 1+ {{candidate function}}
+void operator delete(void *, std::align_val_t); // expected-note 1+ {{candidate}}
+#ifndef __cpp_aligned_new
+// expected-note@-3 1+ {{non-usual 'operator new' declared here}}
+// expected-note@-3 1+ {{non-usual 'operator delete' declared here}}
+#endif
+void *operator new[](size_t count, std::align_val_t al);
+void operator delete[](void*, std::align_val_t);
+
+void operator delete(void *, size_t); // expected-note 1+ {{candidate}}
+#ifndef __cpp_sized_deallocation
+// expected-note@-2 1+ {{non-usual 'operator delete' declared here}}
+#endif
+void operator delete[](void*, size_t);
+
+// Declare some other placemenet operators.
+void *operator new(size_t, void*, bool) throw(); // expected-note 1+ {{candidate function}}
+void *operator new[](size_t, void*, bool) throw();
+
+void *NP = 0;
+
+void test_typo_in_args() {
+  __builtin_operator_new(DNE);  // expected-error {{undeclared identifier 'DNE'}}
+  __builtin_operator_new(DNE, DNE2);// expected-error {{undeclared identifier 'DNE'}} expected-error {{'DNE2'}}
+  __builtin_operator_delete(DNE);   // expected-error {{'DNE'}}
+  __builtin_operator_delete(DNE, DNE2); // expected-error {{'DNE'}} expected-error {{'DNE2'}}
+}
+
+void test_arg_types() {
+  __builtin_operator_new(NP);  // expected-error {{no matching function for call to 'operator new'}}
+  __builtin_operator_new(NP, std::align_val_t(0)); // expected-error {{no matching function for call to 'operator new'}}}
+}
+void test_return_type() {
+  int w = __builtin_operator_new(42);// expected-error {{cannot initialize a variable of type 'int' with an rvalue of type 'void *'}}
+  int y = __builtin_operator_delete(NP); // expected-error {{cannot initialize a variable of type 'int' with an rvalue of type 'void'}}
+}
+
+void test_aligned_new() {
+#ifdef __cpp_aligned_new
+  void *p = __builtin_operator_new(42, std::align_val_t(2));
+  __builtin_operator_delete(p, std::align_val_t(2));
+#else
+  // FIXME: We've manually declared the aligned new/delete overloads,
+  // but LangOpts::AlignedAllocation is false. Should our overloads be considered
+  // usual allocation/deallocation functions?
+  void *p = __builtin_operator_new(42, std::align_val_t(2)); // expected-error {{call to '__builtin_operator_new' selects 

[PATCH] D44272: [clangd] Support incremental document syncing

2018-03-21 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: unittests/clangd/DraftStoreTests.cpp:27
+
+static int rangeLength(StringRef Code, const Range ) {
+  size_t Start = positionToOffset(Code, Rng.start);

ilya-biryukov wrote:
> no need for `static`, since function is already inside an anonymous namespace.
> remove it?
This comment is marked as done, but not addressed.



Comment at: unittests/clangd/DraftStoreTests.cpp:38
+// Send the changes one by one to updateDraft, verify the intermediate results.
+
+static void stepByStep(llvm::ArrayRef Steps) {

ilya-biryukov wrote:
> NIT: remove empty line after comment?
> NIT: make the comment doxygen-like (i.e. start with `///`)?
This comment is marked as done, but not addressed.



Comment at: unittests/clangd/DraftStoreTests.cpp:42
+  Annotations InitialSrc(Steps.front().Src);
+  const char Path[] = "/hello.cpp";
+

ilya-biryukov wrote:
> NIT: use `constexpr StringLiteral Path("/hello.cpp")` instead?
> It's a `StringRef` with size known at compile-time.
This comment is marked as done, but not addressed.



Comment at: unittests/clangd/DraftStoreTests.cpp:58
+llvm::Expected Result = DS.updateDraft(Path, {Event});
+EXPECT_TRUE(!!Result);
+EXPECT_EQ(*Result, SrcAfter.code());

ilya-biryukov wrote:
> Use `ASSERT_TRUE(!!Result)`, the code below won't work for failure results 
> anyway.
This comment is marked as done, but not addressed.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44272



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


[PATCH] D41458: [libc++][C++17] Elementary string conversions for integral types

2018-03-21 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists added a comment.

Sorry I've let this lie fallow for so long.




Comment at: include/charconv:234
+to_chars(char* __first, char* __last, _Tp __value, int __base)
+-> to_chars_result
+{

Why use the trailing return type here?
I don't see any advantage - it doesn't depend on the parameters (template or 
runtime).





Comment at: src/support/itoa/itoa.cpp:1
+// -*- C++ -*-
+//===--===//

lichray wrote:
> EricWF wrote:
> > This file should be renamed `charconv.cpp` and moved into the main source 
> > directory.
> We are going to have floating point cpp files so I don't think that one 
> charconv.cpp is enough.
We can put both integral and floating point routines in the same source file ;-)

What Eric said - there should be just `charconv.cpp`, and no subdirectory.

Also, if this is not your work, then I need some notice (an email is fine) by 
the author saying that they're OK with contributing this under the LLVM license.



Comment at: src/support/itoa/itoa.cpp:35
+
+#define APPEND1(i)  \
+do  \

lichray wrote:
> EricWF wrote:
> > Any reason these can't be `static` functions? The compiler should optimize 
> > them away nicely.
> Although yes, but that's what the author provides.  It's an implementation 
> file, so it doesn't matter I guess.
It *does* matter, since we'll have to maintain this.

It would also be nice if they had meaningful names.


Repository:
  rCXX libc++

https://reviews.llvm.org/D41458



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


[PATCH] D44602: [clang-tidy] readability-function-size: add VariableThreshold param.

2018-03-21 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added inline comments.



Comment at: test/clang-tidy/readability-function-size.cpp:207-212
+void variables_8() {
+  int a, b;
+  struct A {
+A(int c, int d);
+  };
+}

aaron.ballman wrote:
> lebedev.ri wrote:
> > aaron.ballman wrote:
> > > lebedev.ri wrote:
> > > > aaron.ballman wrote:
> > > > > lebedev.ri wrote:
> > > > > > aaron.ballman wrote:
> > > > > > > I think the current behavior here is correct and the previous 
> > > > > > > behavior was incorrect. However, it brings up an interesting 
> > > > > > > question about what to do here:
> > > > > > > ```
> > > > > > > void f() {
> > > > > > >   struct S {
> > > > > > > void bar() {
> > > > > > >   int a, b;
> > > > > > > }
> > > > > > >   };
> > > > > > > }
> > > > > > > ```
> > > > > > > Does `f()` contain zero variables or two? I would contend that it 
> > > > > > > has no variables because S::bar() is a different scope than f(). 
> > > > > > > But I can see a case being made about the complexity of f() being 
> > > > > > > increased by the presence of the local class definition. Perhaps 
> > > > > > > this is a different facet of the test about number of types?
> > > > > > As previously briefly discussed in IRC, i **strongly** believe that 
> > > > > > the current behavior is correct, and `readability-function-size`
> > > > > > should analyze/diagnose the function as a whole, including all 
> > > > > > sub-classes/sub-functions.
> > > > > Do you know of any coding standards related to this check that weigh 
> > > > > in on this?
> > > > > 
> > > > > What do you think about this:
> > > > > ```
> > > > > #define SWAP(x, y) ({__typeof__(x) temp = x; x = y; y = x;})
> > > > > 
> > > > > void f() {
> > > > >   int a = 10, b = 12;
> > > > >   SWAP(a, b);
> > > > > }
> > > > > ```
> > > > > Does f() have two variables or three? Should presence of the `SWAP` 
> > > > > macro cause this code to be more complex due to having too many 
> > > > > variables?
> > > > Datapoint: the doc 
> > > > (`docs/clang-tidy/checks/readability-function-size.rst`) actually 
> > > > already states that macros *are* counted.
> > > > 
> > > > ```
> > > > .. option:: StatementThreshold
> > > > 
> > > >Flag functions exceeding this number of statements. This may differ
> > > >significantly from the number of lines for macro-heavy code. The 
> > > > default is
> > > >`800`.
> > > > ```
> > > > ```
> > > > .. option:: NestingThreshold
> > > > 
> > > > Flag compound statements which create next nesting level after
> > > > `NestingThreshold`. This may differ significantly from the expected 
> > > > value
> > > > for macro-heavy code. The default is `-1` (ignore the nesting 
> > > > level).
> > > > ```
> > > My concerns relate to what's considered a "variable declared in the body" 
> > > (per the documentation) in relation to function complexity. To me, if the 
> > > variable is not accessible lexically within the body of the function, 
> > > it's not adding to the function's complexity *for local variables*. It 
> > > may certainly be adding other complexity, of course.
> > > 
> > > I would have a very hard time explaining to a user that variables they 
> > > cannot see or change (assuming the macro is in a header file out of their 
> > > control) contribute to their function's complexity. Similarly, I would 
> > > have difficulty explaining that variables in an locally declared class 
> > > member function contribute to the number of variables in the outer 
> > > function body, but the class data members somehow do not.
> > > 
> > > (per the documentation) 
> > 
> > Please note that the word `complexity` is not used in the 
> > **documentation**, only `size` is.
> > 
> > There also is the other side of the coin:
> > 
> > ```
> > #define simple_macro_please_ignore \
> >   the; \
> >   actual; \
> >   content; \
> >   of; \
> >   the; \
> >   foo();
> > 
> > // Very simple function, nothing to see.
> > void foo() {
> >   simple_macro_please_ignore();
> > }
> > 
> > #undef simple_macro_please_ignore
> > ```
> > 
> > In other words, if we ignore macros, it would be possible to abuse them to 
> > artificially reduce complexity, by hiding it in the macros.
> > I agree that it's total abuse of macros, but macros are in general not 
> > nice, and it would not be good to give such things a pass.
> > 
> > 
> > > My concerns relate to what's considered a "variable declared in the body" 
> > > (per the documentation) in relation to function complexity.
> > 
> > Could you please clarify, at this point, your concerns are only about this 
> > new part of the check (variables), or for the entire check?
> > In other words, if we ignore macros, it would be possible to abuse them to 
> > artificially reduce complexity, by hiding it in the macros.
> 
> I don't disagree, that's why I'm trying to explore the boundaries. Your 
> example does artificially reduce complexity. My example using swap does not 
> -- it's an 

[PATCH] D44541: [OpenMP][Clang] Move device global stack init before master-workers split

2018-03-21 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea abandoned this revision.
gtbercea added a comment.

This leads to usage of statically allocated shared data before their 
initialization in runtime structures by master thread in kernel_init() 
function. New patch available with worker and master-side initialization.


Repository:
  rC Clang

https://reviews.llvm.org/D44541



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


[PATCH] D44749: [OpenMP][Clang] Add call to global data sharing stack initialization on the workers side

2018-03-21 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea created this revision.
gtbercea added reviewers: ABataev, grokos, carlo.bertolli, caomhin.
Herald added subscribers: cfe-commits, guansong, jholewinski.

The workers also need to initialize the global stack. The call to the 
initialization function needs to happen after the kernel_init() function is 
called by the master. This ensures that the per-team data structures of the 
runtime have been initialized.


Repository:
  rC Clang

https://reviews.llvm.org/D44749

Files:
  lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
  test/OpenMP/nvptx_data_sharing.cpp


Index: test/OpenMP/nvptx_data_sharing.cpp
===
--- test/OpenMP/nvptx_data_sharing.cpp
+++ test/OpenMP/nvptx_data_sharing.cpp
@@ -27,6 +27,11 @@
   }
 }
 
+/// = In the worker function = ///
+// CK1: {{.*}}define internal void 
@__omp_offloading{{.*}}test_ds{{.*}}_worker()
+// CK1: call void @llvm.nvvm.barrier0()
+// CK1: call void @__kmpc_data_sharing_init_stack
+
 /// = In the kernel function = ///
 
 // CK1: {{.*}}define void @__omp_offloading{{.*}}test_ds{{.*}}()
Index: lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
===
--- lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
+++ lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
@@ -801,6 +801,11 @@
   // Wait for parallel work
   syncCTAThreads(CGF);
 
+  // For data sharing, we need to initialize the stack for workers.
+  CGF.EmitRuntimeCall(
+  createNVPTXRuntimeFunction(
+  OMPRTL_NVPTX__kmpc_data_sharing_init_stack));
+
   Address WorkFn =
   CGF.CreateDefaultAlignTempAlloca(CGF.Int8PtrTy, /*Name=*/"work_fn");
   Address ExecStatus =


Index: test/OpenMP/nvptx_data_sharing.cpp
===
--- test/OpenMP/nvptx_data_sharing.cpp
+++ test/OpenMP/nvptx_data_sharing.cpp
@@ -27,6 +27,11 @@
   }
 }
 
+/// = In the worker function = ///
+// CK1: {{.*}}define internal void @__omp_offloading{{.*}}test_ds{{.*}}_worker()
+// CK1: call void @llvm.nvvm.barrier0()
+// CK1: call void @__kmpc_data_sharing_init_stack
+
 /// = In the kernel function = ///
 
 // CK1: {{.*}}define void @__omp_offloading{{.*}}test_ds{{.*}}()
Index: lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
===
--- lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
+++ lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
@@ -801,6 +801,11 @@
   // Wait for parallel work
   syncCTAThreads(CGF);
 
+  // For data sharing, we need to initialize the stack for workers.
+  CGF.EmitRuntimeCall(
+  createNVPTXRuntimeFunction(
+  OMPRTL_NVPTX__kmpc_data_sharing_init_stack));
+
   Address WorkFn =
   CGF.CreateDefaultAlignTempAlloca(CGF.Int8PtrTy, /*Name=*/"work_fn");
   Address ExecStatus =
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r328131 - Reland "[lit] Adding config initialization to lit tests in clang-tools-extra"

2018-03-21 Thread Julie Hockett via cfe-commits
Author: juliehockett
Date: Wed Mar 21 11:50:26 2018
New Revision: 328131

URL: http://llvm.org/viewvc/llvm-project?rev=328131=rev
Log:
Reland "[lit] Adding config initialization to lit tests in clang-tools-extra"

Adding the config initialization to clang-tools-extra so that tests that
use REQUIRES, UNSUPPORTED, and XFAIL based on platform or target triple
work properly.

Modified:
clang-tools-extra/trunk/test/lit.site.cfg.in

Modified: clang-tools-extra/trunk/test/lit.site.cfg.in
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/lit.site.cfg.in?rev=328131=328130=328131=diff
==
--- clang-tools-extra/trunk/test/lit.site.cfg.in (original)
+++ clang-tools-extra/trunk/test/lit.site.cfg.in Wed Mar 21 11:50:26 2018
@@ -23,5 +23,7 @@ except KeyError:
 key, = e.args
 lit_config.fatal("unable to find %r parameter, use '--param=%s=VALUE'" % 
(key,key))
 
+@LIT_SITE_CFG_IN_FOOTER@
+
 # Let the main config do the real work.
 lit_config.load_config(config, "@CLANG_TOOLS_SOURCE_DIR@/test/lit.cfg")


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


[PATCH] D42730: [clang-tidy]] Add check for use of types/classes/functions from header which are deprecated and removed in C++17

2018-03-21 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang-tidy/modernize/DeprecatedFunctionalCheck.cpp:48-54
+  } else if (const auto *const Call =
+ Result.Nodes.getNodeAs("ptr_fun_call")) {
+diag(Call->getLocStart(), Message) << "'std::ptr_fun'";
+  } else if (const auto *const Call =
+ Result.Nodes.getNodeAs("mem_fun_call")) {
+diag(Call->getLocStart(), Message) << "'std::mem_fun'";
+  }

alexfh wrote:
> aaron.ballman wrote:
> > alexfh wrote:
> > > aaron.ballman wrote:
> > > > alexfh wrote:
> > > > > aaron.ballman wrote:
> > > > > > alexfh wrote:
> > > > > > > aaron.ballman wrote:
> > > > > > > > alexfh wrote:
> > > > > > > > > alexfh wrote:
> > > > > > > > > > aaron.ballman wrote:
> > > > > > > > > > > massberg wrote:
> > > > > > > > > > > > aaron.ballman wrote:
> > > > > > > > > > > > > I think that this code should be generalized (same 
> > > > > > > > > > > > > with the matchers) so that you match on 
> > > > > > > > > > > > > `hasAnyName()` for the function calls and use 
> > > > > > > > > > > > > `CallExpr::getCalleeDecl()` to get the declaration. 
> > > > > > > > > > > > > e.g.,
> > > > > > > > > > > > > ```
> > > > > > > > > > > > > if (const auto *Call = 
> > > > > > > > > > > > > Result.Nodes.getNodeAs("blech")) {
> > > > > > > > > > > > >   if (const Decl *Callee = Call->getCalleeDecl())
> > > > > > > > > > > > > diag(Call->getLocStart(), Message) << Calleee;
> > > > > > > > > > > > > }
> > > > > > > > > > > > > ```
> > > > > > > > > > > > > This way you can add more named without having to add 
> > > > > > > > > > > > > extra logic for the diagnostics.
> > > > > > > > > > > > I generalized the code and the matcher.
> > > > > > > > > > > > When we use
> > > > > > > > > > > > ```
> > > > > > > > > > > > << cast(Callee);
> > > > > > > > > > > > ```
> > > > > > > > > > > > we get the template arguments in the name , e.g. 
> > > > > > > > > > > > `ptr_fun`, so I chose to use 
> > > > > > > > > > > > `getQualifiedNameAsString`.
> > > > > > > > > > > > If there is there a better way to get the function name 
> > > > > > > > > > > > without template arguments I appreciate any suggestions.
> > > > > > > > > > > > 
> > > > > > > > > > > > 
> > > > > > > > > > > Nope, in that case, your code is correct. However, we 
> > > > > > > > > > > generally provide the template arguments in diagnostics. 
> > > > > > > > > > > I see @alexfh was asking for them to be removed as not 
> > > > > > > > > > > being useful, but I'm not certain I agree with his 
> > > > > > > > > > > rationale. Yes, all instances are deprecated and thus the 
> > > > > > > > > > > template arguments don't discern between good and bad 
> > > > > > > > > > > cases, but showing the template arguments is also 
> > > > > > > > > > > consistent with the other diagnostics we emit. For 
> > > > > > > > > > > instance, other "deprecated" diagnostics also emit the 
> > > > > > > > > > > template arguments. I'm not certain we should be 
> > > > > > > > > > > inconsistent with the way we produce diagnostics, but 
> > > > > > > > > > > I'll defer to Alex if he still feels strongly about 
> > > > > > > > > > > leaving them off here.
> > > > > > > > > > Indeed, -Wdeprecated-declarations warnings print template 
> > > > > > > > > > arguments. Moreover, they seem to be issued only on 
> > > > > > > > > > instantiations, see https://godbolt.org/g/W563gw.
> > > > > > > > > > 
> > > > > > > > > > But I have a number of concerns with template arguments in 
> > > > > > > > > > the deprecation warnings:
> > > > > > > > > > 
> > > > > > > > > > 1. The note attached to the warning lies. Consider a 
> > > > > > > > > > warning from the test above:
> > > > > > > > > >   ...
> > > > > > > > > >   :11:1: warning: 'B' is deprecated: bbb 
> > > > > > > > > > [-Wdeprecated-declarations]
> > > > > > > > > >   B e;
> > > > > > > > > >   ^
> > > > > > > > > >   :7:10: note: 'B' has been explicitly marked 
> > > > > > > > > > deprecated here
> > > > > > > > > >   struct [[deprecated("bbb")]] B {};
> > > > > > > > > > 
> > > > > > > > > >  But `B` hasn't been explicitly marked deprecated, 
> > > > > > > > > > only the template definition of `B` has been. Template 
> > > > > > > > > > arguments are important in the case of the explicit 
> > > > > > > > > > template specialization `A` in the same example, but 
> > > > > > > > > > not in cases where the template definition was marked 
> > > > > > > > > > deprecated, since template arguments only add noise and no 
> > > > > > > > > > useful information there.
> > > > > > > > > > 2. Warnings can easily become unreadable: 
> > > > > > > > > > https://godbolt.org/g/AFdznH
> > > > > > > > > > 3. Certain coding patterns can result in numerous 
> > > > > > > > > > deprecation warnings differing only in template arguments: 
> > > > > > > > > > https://godbolt.org/g/U2JCbG. Clang-tidy can deduplicate 
> > > > > > > > > > warnings, if they have 

[PATCH] D44747: [AMDGPU] Set calling convention for CUDA kernel

2018-03-21 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added reviewers: rjmccall, arsenm.
Herald added subscribers: t-tye, tpr, dstuttard, wdng, kzhuravl.

This patch sets the calling convention for CUDA kernels required by AMDGPU 
target.

Patch by Greg Rodgers.
Lit test added by Yaxun Liu.


https://reviews.llvm.org/D44747

Files:
  lib/CodeGen/CodeGenModule.cpp
  test/CodeGenCUDA/kernel-amdgcn.cu


Index: test/CodeGenCUDA/kernel-amdgcn.cu
===
--- /dev/null
+++ test/CodeGenCUDA/kernel-amdgcn.cu
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -triple amdgcn -fcuda-is-device -emit-llvm %s -o - | 
FileCheck %s
+#include "Inputs/cuda.h"
+
+// CHECK: define amdgpu_kernel void @_ZN1A6kernelEv()
+class A {
+public:
+  static __global__ void kernel(){}
+};
+
+// CHECK: define void @_Z10non_kernelv()
+__device__ void non_kernel(){}
+
+// CHECK: define amdgpu_kernel void @_Z6kerneli(i32 %x)
+__global__ void kernel(int x) {
+  non_kernel();
+}
+
+// CHECK: define amdgpu_kernel void @_Z15template_kernelI1AEvT_()
+template
+__global__ void template_kernel(T x) {}
+
+void launch(void *f);
+
+int main() {
+  launch((void*)A::kernel);
+  launch((void*)kernel);
+  launch((void*)template_kernel);
+  return 0;
+}
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -3590,6 +3590,9 @@
 
   MaybeHandleStaticInExternC(D, Fn);
 
+  if ((getTriple().getArch() == llvm::Triple::amdgcn) &&
+  D->hasAttr())
+Fn->setCallingConv(llvm::CallingConv::AMDGPU_KERNEL);
   maybeSetTrivialComdat(*D, *Fn);
 
   CodeGenFunction(*this).GenerateCode(D, Fn, FI);


Index: test/CodeGenCUDA/kernel-amdgcn.cu
===
--- /dev/null
+++ test/CodeGenCUDA/kernel-amdgcn.cu
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -triple amdgcn -fcuda-is-device -emit-llvm %s -o - | FileCheck %s
+#include "Inputs/cuda.h"
+
+// CHECK: define amdgpu_kernel void @_ZN1A6kernelEv()
+class A {
+public:
+  static __global__ void kernel(){}
+};
+
+// CHECK: define void @_Z10non_kernelv()
+__device__ void non_kernel(){}
+
+// CHECK: define amdgpu_kernel void @_Z6kerneli(i32 %x)
+__global__ void kernel(int x) {
+  non_kernel();
+}
+
+// CHECK: define amdgpu_kernel void @_Z15template_kernelI1AEvT_()
+template
+__global__ void template_kernel(T x) {}
+
+void launch(void *f);
+
+int main() {
+  launch((void*)A::kernel);
+  launch((void*)kernel);
+  launch((void*)template_kernel);
+  return 0;
+}
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -3590,6 +3590,9 @@
 
   MaybeHandleStaticInExternC(D, Fn);
 
+  if ((getTriple().getArch() == llvm::Triple::amdgcn) &&
+  D->hasAttr())
+Fn->setCallingConv(llvm::CallingConv::AMDGPU_KERNEL);
   maybeSetTrivialComdat(*D, *Fn);
 
   CodeGenFunction(*this).GenerateCode(D, Fn, FI);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44743: [clang-tidy] Marking hicpp-no-assembler-msvc unsupported on Windows

2018-03-21 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett closed this revision.
juliehockett added a comment.

Committed in r328127.


https://reviews.llvm.org/D44743



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


[clang-tools-extra] r328127 - [clang-tidy] Marking hicpp-no-assembler-msvc unsupported on Windows

2018-03-21 Thread Julie Hockett via cfe-commits
Author: juliehockett
Date: Wed Mar 21 11:03:41 2018
New Revision: 328127

URL: http://llvm.org/viewvc/llvm-project?rev=328127=rev
Log:
[clang-tidy] Marking hicpp-no-assembler-msvc unsupported on Windows

After changes to lit.site.cfg.in, the test is now running (and failing)
on windows, so temporarily marking it unsupported. See PR36855 for more
details.

Modified:
clang-tools-extra/trunk/test/clang-tidy/hicpp-no-assembler-msvc.cpp

Modified: clang-tools-extra/trunk/test/clang-tidy/hicpp-no-assembler-msvc.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/hicpp-no-assembler-msvc.cpp?rev=328127=328126=328127=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/hicpp-no-assembler-msvc.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/hicpp-no-assembler-msvc.cpp Wed Mar 
21 11:03:41 2018
@@ -1,4 +1,6 @@
 // REQUIRES: system-windows
+// FIXME: Re-enable test on windows (PR36855)
+// UNSUPPORTED: system-windows
 // RUN: %check_clang_tidy %s hicpp-no-assembler %t
 
 void f() {


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


[PATCH] D44559: [Sema] Wrong width of result of mul operation

2018-03-21 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

In https://reviews.llvm.org/D44559#1044653, @aaron.ballman wrote:

> In https://reviews.llvm.org/D44559#1044639, @rjmccall wrote:
>
> > In https://reviews.llvm.org/D44559#1044186, @avt77 wrote:
> >
> > > >> In https://reviews.llvm.org/D44559#1040799, @rjmccall wrote:
> > > >> 
> > > >>> I think we're correct not to warn here and that GCC/ICC are being 
> > > >>> noisy.  The existence of a temporary promotion to a wider type 
> > > >>> doesn't justify warning on arithmetic between two operands that are 
> > > >>> the same size as the ultimate result.  It is totally fair for users 
> > > >>> to think of this operation as being "closed" on the original type.
> > > >> 
> > > >> 
> > > >> Could you please clarify, are you saying that PR35409 
> > > >>  is not a bug, and clang 
> > > >> should continue to not warn in those cases?
> > > > 
> > > > Correct.
> > >
> > > Does it mean we should abandon this revision? On the other hand it's a 
> > > real bug, isn't it?
> >
> >
> > Not as I see it, no.
>
>
> Do you see this code as having a bug when `a` is >= 182?
>
>   short foo(unsigned char a) {
> return a * a;
>   }
>
>
> (If you don't like seeing `unsigned char`  you can imagine it was spelled as 
> `uint8_t`.)


That's an interesting question.  In general, these warnings do try to ignore 
the effects of implicit promotion.  We would not want -Wsign-conversion to fire 
on `unsigned short x = an_unsigned_short + 1;` (or `- 1`, for that matter), 
even though formally this coerces a `signed int` to `unsigned short`.  
Similarly, -Wsign-conversion *should* warn on `signed short x = 
an_unsigned_short + 1;`, even though formally the promotion from `unsigned 
short` to `signed int` is not problematic and the final conversion from `signed 
int` to `signed short` is not a signedness change.  (This second example should 
also generate a -Wconversion warning, but the questions are independent.)  
Applying that strictly here would say that the user is entitled to think of 
this as an operation on `unsigned char` that then gets losslessly promoted to 
`signed short`, even though arithmetically that's not what happens.  On the 
other hand, I do think there's some room for -Wsign-conversion to be more 
aggressive than -Wconversion about this sort of thing; -Wsign-conversion should 
generally fire for any changes in signedness from the original operand types 
(with the usual complexities around constant values), and there's just an 
exception for computations whose value is known to fit within the expressible 
range of the result type, which is not true of this multiplication.  So I think 
it would be acceptable to warn on this.

John.


https://reviews.llvm.org/D44559



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


[PATCH] D44743: [clang-tidy] Marking hicpp-no-assembler-msvc unsupported on Windows

2018-03-21 Thread Petr Hosek via Phabricator via cfe-commits
phosek accepted this revision.
phosek added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D44743



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


[PATCH] D44589: [Sema] Make deprecation fix-it replace all multi-parameter ObjC method slots.

2018-03-21 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington added a comment.

Hi Volodymyr, thanks for working on this! Overall this looks good, I just have 
a few nits.




Comment at: clang/include/clang/Basic/SourceLocation.h:202
+/// Can be used transparently in places where SourceLocation is expected.
+class MultiSourceLocation {
+  bool IsSingleLoc;

Why can't we just use an ArrayRef for this? It looks like that 
type already has a converting constructor from SourceLocation, so we should be 
able to use in in DiagnoseUseOfDecl without any noise.



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:6934-6938
+// Returns a number of method parameters if parsing is successful.
+// In case of unsuccessful parsing SlotNames can contain invalid data.
+static Optional
+parseObjCMethodName(StringRef Name, SmallVectorImpl ,
+const LangOptions ) {

Maybe tryParseReplacementObjCMethodName or something would be better? 
parseObjCMethodName() is pretty vague. Also the comment above should probably 
be a `///` doxygen comment. It would be nice if you mentioned that `Name` 
originated from an availability attribute in the comment.



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:6959-6966
+if (S.empty())
+  continue;
+if (!isIdentifierHead(S[0], AllowDollar))
+  return None;
+for (char C : S)
+  if (!isIdentifierBody(C, AllowDollar))
+return None;

Might be better to add a defaulted AllowDollar parameter to isValidIdentifier() 
in CharInfo.h and use that rather than duplicating it here.


https://reviews.llvm.org/D44589



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


[PATCH] D44272: [clangd] Support incremental document syncing

2018-03-21 Thread Simon Marchi via Phabricator via cfe-commits
simark updated this revision to Diff 139328.
simark added a comment.

Add lit test case


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44272

Files:
  clangd/ClangdLSPServer.cpp
  clangd/DraftStore.cpp
  clangd/DraftStore.h
  clangd/Protocol.cpp
  clangd/Protocol.h
  test/clangd/initialize-params-invalid.test
  test/clangd/initialize-params.test
  test/clangd/textdocument-didchange-fail.test
  unittests/clangd/CMakeLists.txt
  unittests/clangd/DraftStoreTests.cpp

Index: unittests/clangd/DraftStoreTests.cpp
===
--- /dev/null
+++ unittests/clangd/DraftStoreTests.cpp
@@ -0,0 +1,355 @@
+//===-- DraftStoreTests.cpp - Clangd unit tests -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "Annotations.h"
+#include "DraftStore.h"
+#include "SourceCode.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace clangd {
+namespace {
+
+using namespace llvm;
+
+struct IncrementalTestStep {
+  StringRef Src;
+  StringRef Contents;
+};
+
+static int rangeLength(StringRef Code, const Range ) {
+  llvm::Expected Start = positionToOffset(Code, Rng.start);
+  llvm::Expected End = positionToOffset(Code, Rng.end);
+  assert(Start);
+  assert(End);
+  return *End - *Start;
+}
+
+// Send the changes one by one to updateDraft, verify the intermediate results.
+
+static void stepByStep(llvm::ArrayRef Steps) {
+  DraftStore DS;
+  Annotations InitialSrc(Steps.front().Src);
+  const char Path[] = "/hello.cpp";
+
+  // Set the initial content.
+  DS.addDraft(Path, InitialSrc.code());
+
+  for (size_t i = 1; i < Steps.size(); i++) {
+Annotations SrcBefore(Steps[i - 1].Src);
+Annotations SrcAfter(Steps[i].Src);
+StringRef Contents = Steps[i - 1].Contents;
+TextDocumentContentChangeEvent Event{
+SrcBefore.range(),
+rangeLength(SrcBefore.code(), SrcBefore.range()),
+Contents.str(),
+};
+
+llvm::Expected Result = DS.updateDraft(Path, {Event});
+EXPECT_TRUE(!!Result);
+EXPECT_EQ(*Result, SrcAfter.code());
+EXPECT_EQ(*DS.getDraft(Path), SrcAfter.code());
+  }
+}
+
+// Send all the changes at once to updateDraft, check only the final result.
+
+static void allAtOnce(llvm::ArrayRef Steps) {
+  DraftStore DS;
+  Annotations InitialSrc(Steps.front().Src);
+  Annotations FinalSrc(Steps.back().Src);
+  const char Path[] = "/hello.cpp";
+  std::vector Changes;
+
+  for (size_t i = 0; i < Steps.size() - 1; i++) {
+Annotations Src(Steps[i].Src);
+StringRef Contents = Steps[i].Contents;
+
+Changes.push_back({
+Src.range(),
+rangeLength(Src.code(), Src.range()),
+Contents.str(),
+});
+  }
+
+  // Set the initial content.
+  DS.addDraft(Path, InitialSrc.code());
+
+  llvm::Expected Result = DS.updateDraft(Path, Changes);
+
+  EXPECT_TRUE(!!Result) << llvm::toString(Result.takeError());
+  EXPECT_EQ(*Result, FinalSrc.code());
+  EXPECT_EQ(*DS.getDraft(Path), FinalSrc.code());
+}
+
+TEST(DraftStoreIncrementalUpdateTest, Simple) {
+  // clang-format off
+  IncrementalTestStep Steps[] =
+{
+  // Replace a range
+  {
+R"cpp(static int
+hello[[World]]()
+{})cpp",
+"Universe"
+  },
+  // Delete a range
+  {
+R"cpp(static int
+hello[[Universe]]()
+{})cpp",
+""
+  },
+  // Add a range
+  {
+R"cpp(static int
+hello[[]]()
+{})cpp",
+"Monde"
+  },
+  {
+R"cpp(static int
+helloMonde()
+{})cpp",
+""
+  }
+};
+  // clang-format on
+
+  stepByStep(Steps);
+  allAtOnce(Steps);
+}
+
+TEST(DraftStoreIncrementalUpdateTest, MultiLine) {
+  // clang-format off
+  IncrementalTestStep Steps[] =
+{
+  // Replace a range
+  {
+R"cpp(static [[int
+helloWorld]]()
+{})cpp",
+R"cpp(char
+welcome)cpp"
+  },
+  // Delete a range
+  {
+R"cpp(static char[[
+welcome]]()
+{})cpp",
+""
+  },
+  // Add a range
+  {
+R"cpp(static char[[]]()
+{})cpp",
+R"cpp(
+cookies)cpp"
+  },
+  // Replace the whole file
+  {
+R"cpp([[static char
+cookies()
+{}]])cpp",
+R"cpp(#include 
+)cpp"
+  },
+  // Delete the whole file
+  {
+R"cpp([[#include 
+]])cpp",
+"",
+  },
+  // Add something to an empty file
+  {
+"[[]]",
+R"cpp(int main() {
+)cpp",
+  },
+  {
+R"cpp(int main() {
+)cpp",
+""
+  }
+};
+  // clang-format on
+
+  stepByStep(Steps);
+  allAtOnce(Steps);
+}
+
+TEST(DraftStoreIncrementalUpdateTest, WrongRangeLength) {
+  DraftStore DS;
+  Path File = "foo.cpp";
+
+  DS.addDraft(File, "int main() {}\n");
+
+  TextDocumentContentChangeEvent Change;
+  Change.range.emplace();
+  

[PATCH] D44533: [AMDGPU] Fix codegen for inline assembly

2018-03-21 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

Ping


https://reviews.llvm.org/D44533



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


[PATCH] D43737: Improve -Winfinite-recursion

2018-03-21 Thread Robert Widmann via Phabricator via cfe-commits
CodaFi updated this revision to Diff 139325.

https://reviews.llvm.org/D43737

Files:
  lib/Sema/AnalysisBasedWarnings.cpp
  test/SemaCXX/warn-infinite-recursion.cpp

Index: test/SemaCXX/warn-infinite-recursion.cpp
===
--- test/SemaCXX/warn-infinite-recursion.cpp
+++ test/SemaCXX/warn-infinite-recursion.cpp
@@ -29,8 +29,7 @@
 void e() { f(); }
 void f() { e(); }
 
-// Don't warn on infinite loops
-void g() {
+void g() {  // expected-warning{{call itself}}
   while (true)
 g();
 
@@ -54,6 +53,19 @@
   return 5 + j();
 }
 
+void k() {  // expected-warning{{call itself}}
+  while(true) {
+k();
+  }
+}
+
+// Don't warn on infinite loops
+void l() {
+  while (true) {}
+
+  l();
+}
+
 class S {
   static void a();
   void b();
Index: lib/Sema/AnalysisBasedWarnings.cpp
===
--- lib/Sema/AnalysisBasedWarnings.cpp
+++ lib/Sema/AnalysisBasedWarnings.cpp
@@ -200,60 +200,41 @@
   return false;
 }
 
-// All blocks are in one of three states.  States are ordered so that blocks
-// can only move to higher states.
-enum RecursiveState {
-  FoundNoPath,
-  FoundPath,
-  FoundPathWithNoRecursiveCall
-};
-
-// Returns true if there exists a path to the exit block and every path
-// to the exit block passes through a call to FD.
+// Returns true if every path from the entry block passes through a call to FD.
 static bool checkForRecursiveFunctionCall(const FunctionDecl *FD, CFG *cfg) {
+  llvm::SmallPtrSet Visited;
+  llvm::SmallVector WorkList;
+  // Keep track of whether we found at least one recursive path.
+  bool foundRecursion = false;
 
   const unsigned ExitID = cfg->getExit().getBlockID();
 
-  // Mark all nodes as FoundNoPath, then set the status of the entry block.
-  SmallVector States(cfg->getNumBlockIDs(), FoundNoPath);
-  States[cfg->getEntry().getBlockID()] = FoundPathWithNoRecursiveCall;
-
-  // Make the processing stack and seed it with the entry block.
-  SmallVector Stack;
-  Stack.push_back(>getEntry());
-
-  while (!Stack.empty()) {
-CFGBlock *CurBlock = Stack.back();
-Stack.pop_back();
+  // Seed the work list with the entry block.
+  WorkList.push_back(>getEntry());
 
-unsigned ID = CurBlock->getBlockID();
-RecursiveState CurState = States[ID];
+  while (!WorkList.empty()) {
+CFGBlock *Block = WorkList.pop_back_val();
 
-if (CurState == FoundPathWithNoRecursiveCall) {
-  // Found a path to the exit node without a recursive call.
-  if (ExitID == ID)
-return false;
+for (auto I = Block->succ_begin(), E = Block->succ_end(); I != E; ++I) {
+  if (CFGBlock *SuccBlock = *I) {
+if (!Visited.insert(SuccBlock).second)
+  continue;
 
-  // Only change state if the block has a recursive call.
-  if (hasRecursiveCallInPath(FD, *CurBlock))
-CurState = FoundPath;
-}
+// Found a path to the exit node without a recursive call.
+if (ExitID == SuccBlock->getBlockID())
+  return false;
 
-// Loop over successor blocks and add them to the Stack if their state
-// changes.
-for (auto I = CurBlock->succ_begin(), E = CurBlock->succ_end(); I != E; ++I)
-  if (*I) {
-unsigned next_ID = (*I)->getBlockID();
-if (States[next_ID] < CurState) {
-  States[next_ID] = CurState;
-  Stack.push_back(*I);
+// If the successor block contains a recursive call, end analysis there.
+if (hasRecursiveCallInPath(FD, *SuccBlock)) {
+  foundRecursion = true;
+  continue;
 }
+
+WorkList.push_back(SuccBlock);
   }
+}
   }
-
-  // Return true if the exit node is reachable, and only reachable through
-  // a recursive call.
-  return States[ExitID] == FoundPath;
+  return foundRecursion;
 }
 
 static void checkRecursiveFunction(Sema , const FunctionDecl *FD,
@@ -269,10 +250,6 @@
   CFG *cfg = AC.getCFG();
   if (!cfg) return;
 
-  // If the exit block is unreachable, skip processing the function.
-  if (cfg->getExit().pred_empty())
-return;
-
   // Emit diagnostic if a recursive function call is detected for all paths.
   if (checkForRecursiveFunctionCall(FD, cfg))
 S.Diag(Body->getLocStart(), diag::warn_infinite_recursive_function);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44745: [HWASan] Port HWASan to Linux x86-64 (clang)

2018-03-21 Thread Aleksey Shlyapnikov via Phabricator via cfe-commits
alekseyshl created this revision.
alekseyshl added a reviewer: eugenis.
Herald added a subscriber: cryptoad.

Porting HWASan to Linux x86-64, the third of the three patches, clang part.


Repository:
  rC Clang

https://reviews.llvm.org/D44745

Files:
  lib/Driver/SanitizerArgs.cpp
  lib/Driver/ToolChains/Linux.cpp
  test/Driver/Inputs/resource_dir/lib/linux/libclang_rt.hwasan-x86_64.a.syms
  test/Driver/asan.c
  test/Driver/fsanitize-blacklist.c
  test/Driver/fsanitize.c
  test/Driver/sanitizer-ld.c

Index: test/Driver/sanitizer-ld.c
===
--- test/Driver/sanitizer-ld.c
+++ test/Driver/sanitizer-ld.c
@@ -696,54 +696,94 @@
 // CHECK-SCUDO-ANDROID-STATIC: "-lpthread"
 
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
-// RUN: -target aarch64-unknown-linux -fuse-ld=ld -fsanitize=hwaddress \
+// RUN: -target x86_64-unknown-linux -fuse-ld=ld -fsanitize=hwaddress \
 // RUN: -resource-dir=%S/Inputs/resource_dir \
 // RUN: --sysroot=%S/Inputs/basic_linux_tree \
-// RUN:   | FileCheck --check-prefix=CHECK-HWASAN-LINUX %s
+// RUN:   | FileCheck --check-prefix=CHECK-HWASAN-X86-64-LINUX %s
 //
-// CHECK-HWASAN-LINUX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
-// CHECK-HWASAN-LINUX-NOT: "-lc"
-// CHECK-HWASAN-LINUX: libclang_rt.hwasan-aarch64.a"
-// CHECK-HWASAN-LINUX-NOT: "--export-dynamic"
-// CHECK-HWASAN-LINUX: "--dynamic-list={{.*}}libclang_rt.hwasan-aarch64.a.syms"
-// CHECK-HWASAN-LINUX-NOT: "--export-dynamic"
-// CHECK-HWASAN-LINUX: "-lpthread"
-// CHECK-HWASAN-LINUX: "-lrt"
-// CHECK-HWASAN-LINUX: "-ldl"
+// CHECK-HWASAN-X86-64-LINUX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-HWASAN-X86-64-LINUX-NOT: "-lc"
+// CHECK-HWASAN-X86-64-LINUX: libclang_rt.hwasan-x86_64.a"
+// CHECK-HWASAN-X86-64-LINUX-NOT: "--export-dynamic"
+// CHECK-HWASAN-X86-64-LINUX: "--dynamic-list={{.*}}libclang_rt.hwasan-x86_64.a.syms"
+// CHECK-HWASAN-X86-64-LINUX-NOT: "--export-dynamic"
+// CHECK-HWASAN-X86-64-LINUX: "-lpthread"
+// CHECK-HWASAN-X86-64-LINUX: "-lrt"
+// CHECK-HWASAN-X86-64-LINUX: "-ldl"
 
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
-// RUN: -target aarch64-unknown-linux -fuse-ld=ld -fsanitize=hwaddress -shared-libsan \
-// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: -target x86_64-unknown-linux -fuse-ld=ld -fsanitize=hwaddress \
+// RUN: -shared-libsan -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-SHARED-HWASAN-X86-64-LINUX %s
+//
+// CHECK-SHARED-HWASAN-X86-64-LINUX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-SHARED-HWASAN-X86-64-LINUX-NOT: "-lc"
+// CHECK-SHARED-HWASAN-X86-64-LINUX: libclang_rt.hwasan-x86_64.so"
+// CHECK-SHARED-HWASAN-X86-64-LINUX-NOT: "-lpthread"
+// CHECK-SHARED-HWASAN-X86-64-LINUX-NOT: "-lrt"
+// CHECK-SHARED-HWASAN-X86-64-LINUX-NOT: "-ldl"
+// CHECK-SHARED-HWASAN-X86-64-LINUX-NOT: "--export-dynamic"
+// CHECK-SHARED-HWASAN-X86-64-LINUX-NOT: "--dynamic-list"
+
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.so -shared 2>&1 \
+// RUN: -target x86_64-unknown-linux -fuse-ld=ld -fsanitize=hwaddress \
+// RUN: -shared-libsan -resource-dir=%S/Inputs/resource_dir \
 // RUN: --sysroot=%S/Inputs/basic_linux_tree \
-// RUN:   | FileCheck --check-prefix=CHECK-SHARED-HWASAN-LINUX %s
+// RUN:   | FileCheck --check-prefix=CHECK-DSO-SHARED-HWASAN-X86-64-LINUX %s
+//
+// CHECK-DSO-SHARED-HWASAN-X86-64-LINUX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-DSO-SHARED-HWASAN-X86-64-LINUX-NOT: "-lc"
+// CHECK-DSO-SHARED-HWASAN-X86-64-LINUX: libclang_rt.hwasan-x86_64.so"
+// CHECK-DSO-SHARED-HWASAN-X86-64-LINUX-NOT: "-lpthread"
+// CHECK-DSO-SHARED-HWASAN-X86-64-LINUX-NOT: "-lrt"
+// CHECK-DSO-SHARED-HWASAN-X86-64-LINUX-NOT: "-ldl"
+// CHECK-DSO-SHARED-HWASAN-X86-64-LINUX-NOT: "--export-dynamic"
+// CHECK-DSO-SHARED-HWASAN-X86-64-LINUX-NOT: "--dynamic-list"
 
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -target aarch64-unknown-linux -fuse-ld=ld -fsanitize=hwaddress \
-// RUN: -shared-libsan \
 // RUN: -resource-dir=%S/Inputs/resource_dir \
 // RUN: --sysroot=%S/Inputs/basic_linux_tree \
-// RUN:   | FileCheck --check-prefix=CHECK-SHARED-HWASAN-LINUX %s
+// RUN:   | FileCheck --check-prefix=CHECK-HWASAN-AARCH64-LINUX %s
 //
-// CHECK-SHARED-HWASAN-LINUX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
-// CHECK-SHARED-HWASAN-LINUX-NOT: "-lc"
-// CHECK-SHARED-HWASAN-LINUX: libclang_rt.hwasan-aarch64.so"
-// CHECK-SHARED-HWASAN-LINUX-NOT: "-lpthread"
-// CHECK-SHARED-HWASAN-LINUX-NOT: "-lrt"
-// CHECK-SHARED-HWASAN-LINUX-NOT: "-ldl"
-// CHECK-SHARED-HWASAN-LINUX-NOT: "--export-dynamic"
-// CHECK-SHARED-HWASAN-LINUX-NOT: "--dynamic-list"
+// CHECK-HWASAN-AARCH64-LINUX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-HWASAN-AARCH64-LINUX-NOT: "-lc"
+// CHECK-HWASAN-AARCH64-LINUX: libclang_rt.hwasan-aarch64.a"
+// 

[PATCH] D44743: [clang-tidy] Marking hicpp-no-assembler-msvc unsupported on Windows

2018-03-21 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett created this revision.
juliehockett added reviewers: zturner, phosek.
juliehockett added a project: clang-tools-extra.
Herald added a subscriber: xazax.hun.

After changes to lit.site.cfg.in, the test is now running (and failing) on 
windows, so temporarily marking it unsupported. See PR36855 for more details.


https://reviews.llvm.org/D44743

Files:
  test/clang-tidy/hicpp-no-assembler-msvc.cpp


Index: test/clang-tidy/hicpp-no-assembler-msvc.cpp
===
--- test/clang-tidy/hicpp-no-assembler-msvc.cpp
+++ test/clang-tidy/hicpp-no-assembler-msvc.cpp
@@ -1,4 +1,6 @@
 // REQUIRES: system-windows
+// FIXME: Re-enable test on windows (PR36855)
+// UNSUPPORTED: system-windows
 // RUN: %check_clang_tidy %s hicpp-no-assembler %t
 
 void f() {


Index: test/clang-tidy/hicpp-no-assembler-msvc.cpp
===
--- test/clang-tidy/hicpp-no-assembler-msvc.cpp
+++ test/clang-tidy/hicpp-no-assembler-msvc.cpp
@@ -1,4 +1,6 @@
 // REQUIRES: system-windows
+// FIXME: Re-enable test on windows (PR36855)
+// UNSUPPORTED: system-windows
 // RUN: %check_clang_tidy %s hicpp-no-assembler %t
 
 void f() {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42730: [clang-tidy]] Add check for use of types/classes/functions from header which are deprecated and removed in C++17

2018-03-21 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added inline comments.



Comment at: clang-tidy/modernize/DeprecatedFunctionalCheck.cpp:48-54
+  } else if (const auto *const Call =
+ Result.Nodes.getNodeAs("ptr_fun_call")) {
+diag(Call->getLocStart(), Message) << "'std::ptr_fun'";
+  } else if (const auto *const Call =
+ Result.Nodes.getNodeAs("mem_fun_call")) {
+diag(Call->getLocStart(), Message) << "'std::mem_fun'";
+  }

aaron.ballman wrote:
> alexfh wrote:
> > aaron.ballman wrote:
> > > alexfh wrote:
> > > > aaron.ballman wrote:
> > > > > alexfh wrote:
> > > > > > aaron.ballman wrote:
> > > > > > > alexfh wrote:
> > > > > > > > alexfh wrote:
> > > > > > > > > aaron.ballman wrote:
> > > > > > > > > > massberg wrote:
> > > > > > > > > > > aaron.ballman wrote:
> > > > > > > > > > > > I think that this code should be generalized (same with 
> > > > > > > > > > > > the matchers) so that you match on `hasAnyName()` for 
> > > > > > > > > > > > the function calls and use `CallExpr::getCalleeDecl()` 
> > > > > > > > > > > > to get the declaration. e.g.,
> > > > > > > > > > > > ```
> > > > > > > > > > > > if (const auto *Call = 
> > > > > > > > > > > > Result.Nodes.getNodeAs("blech")) {
> > > > > > > > > > > >   if (const Decl *Callee = Call->getCalleeDecl())
> > > > > > > > > > > > diag(Call->getLocStart(), Message) << Calleee;
> > > > > > > > > > > > }
> > > > > > > > > > > > ```
> > > > > > > > > > > > This way you can add more named without having to add 
> > > > > > > > > > > > extra logic for the diagnostics.
> > > > > > > > > > > I generalized the code and the matcher.
> > > > > > > > > > > When we use
> > > > > > > > > > > ```
> > > > > > > > > > > << cast(Callee);
> > > > > > > > > > > ```
> > > > > > > > > > > we get the template arguments in the name , e.g. 
> > > > > > > > > > > `ptr_fun`, so I chose to use 
> > > > > > > > > > > `getQualifiedNameAsString`.
> > > > > > > > > > > If there is there a better way to get the function name 
> > > > > > > > > > > without template arguments I appreciate any suggestions.
> > > > > > > > > > > 
> > > > > > > > > > > 
> > > > > > > > > > Nope, in that case, your code is correct. However, we 
> > > > > > > > > > generally provide the template arguments in diagnostics. I 
> > > > > > > > > > see @alexfh was asking for them to be removed as not being 
> > > > > > > > > > useful, but I'm not certain I agree with his rationale. 
> > > > > > > > > > Yes, all instances are deprecated and thus the template 
> > > > > > > > > > arguments don't discern between good and bad cases, but 
> > > > > > > > > > showing the template arguments is also consistent with the 
> > > > > > > > > > other diagnostics we emit. For instance, other "deprecated" 
> > > > > > > > > > diagnostics also emit the template arguments. I'm not 
> > > > > > > > > > certain we should be inconsistent with the way we produce 
> > > > > > > > > > diagnostics, but I'll defer to Alex if he still feels 
> > > > > > > > > > strongly about leaving them off here.
> > > > > > > > > Indeed, -Wdeprecated-declarations warnings print template 
> > > > > > > > > arguments. Moreover, they seem to be issued only on 
> > > > > > > > > instantiations, see https://godbolt.org/g/W563gw.
> > > > > > > > > 
> > > > > > > > > But I have a number of concerns with template arguments in 
> > > > > > > > > the deprecation warnings:
> > > > > > > > > 
> > > > > > > > > 1. The note attached to the warning lies. Consider a warning 
> > > > > > > > > from the test above:
> > > > > > > > >   ...
> > > > > > > > >   :11:1: warning: 'B' is deprecated: bbb 
> > > > > > > > > [-Wdeprecated-declarations]
> > > > > > > > >   B e;
> > > > > > > > >   ^
> > > > > > > > >   :7:10: note: 'B' has been explicitly marked 
> > > > > > > > > deprecated here
> > > > > > > > >   struct [[deprecated("bbb")]] B {};
> > > > > > > > > 
> > > > > > > > >  But `B` hasn't been explicitly marked deprecated, only 
> > > > > > > > > the template definition of `B` has been. Template arguments 
> > > > > > > > > are important in the case of the explicit template 
> > > > > > > > > specialization `A` in the same example, but not in cases 
> > > > > > > > > where the template definition was marked deprecated, since 
> > > > > > > > > template arguments only add noise and no useful information 
> > > > > > > > > there.
> > > > > > > > > 2. Warnings can easily become unreadable: 
> > > > > > > > > https://godbolt.org/g/AFdznH
> > > > > > > > > 3. Certain coding patterns can result in numerous deprecation 
> > > > > > > > > warnings differing only in template arguments: 
> > > > > > > > > https://godbolt.org/g/U2JCbG. Clang-tidy can deduplicate 
> > > > > > > > > warnings, if they have identical text and location, but 
> > > > > > > > > adding template arguments to the message will prevent 
> > > > > > > > > deduplication. I've seen a case where thousands of 
> > > > > > > > > deprecation warnings were generated for a 

[PATCH] D44272: [clangd] Support incremental document syncing

2018-03-21 Thread Simon Marchi via Phabricator via cfe-commits
simark updated this revision to Diff 139321.
simark added a comment.

Remove draft if update fails


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44272

Files:
  clangd/ClangdLSPServer.cpp
  clangd/DraftStore.cpp
  clangd/DraftStore.h
  clangd/Protocol.cpp
  clangd/Protocol.h
  test/clangd/initialize-params-invalid.test
  test/clangd/initialize-params.test
  unittests/clangd/CMakeLists.txt
  unittests/clangd/DraftStoreTests.cpp

Index: unittests/clangd/DraftStoreTests.cpp
===
--- /dev/null
+++ unittests/clangd/DraftStoreTests.cpp
@@ -0,0 +1,355 @@
+//===-- DraftStoreTests.cpp - Clangd unit tests -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "Annotations.h"
+#include "DraftStore.h"
+#include "SourceCode.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace clangd {
+namespace {
+
+using namespace llvm;
+
+struct IncrementalTestStep {
+  StringRef Src;
+  StringRef Contents;
+};
+
+static int rangeLength(StringRef Code, const Range ) {
+  llvm::Expected Start = positionToOffset(Code, Rng.start);
+  llvm::Expected End = positionToOffset(Code, Rng.end);
+  assert(Start);
+  assert(End);
+  return *End - *Start;
+}
+
+// Send the changes one by one to updateDraft, verify the intermediate results.
+
+static void stepByStep(llvm::ArrayRef Steps) {
+  DraftStore DS;
+  Annotations InitialSrc(Steps.front().Src);
+  const char Path[] = "/hello.cpp";
+
+  // Set the initial content.
+  DS.addDraft(Path, InitialSrc.code());
+
+  for (size_t i = 1; i < Steps.size(); i++) {
+Annotations SrcBefore(Steps[i - 1].Src);
+Annotations SrcAfter(Steps[i].Src);
+StringRef Contents = Steps[i - 1].Contents;
+TextDocumentContentChangeEvent Event{
+SrcBefore.range(),
+rangeLength(SrcBefore.code(), SrcBefore.range()),
+Contents.str(),
+};
+
+llvm::Expected Result = DS.updateDraft(Path, {Event});
+EXPECT_TRUE(!!Result);
+EXPECT_EQ(*Result, SrcAfter.code());
+EXPECT_EQ(*DS.getDraft(Path), SrcAfter.code());
+  }
+}
+
+// Send all the changes at once to updateDraft, check only the final result.
+
+static void allAtOnce(llvm::ArrayRef Steps) {
+  DraftStore DS;
+  Annotations InitialSrc(Steps.front().Src);
+  Annotations FinalSrc(Steps.back().Src);
+  const char Path[] = "/hello.cpp";
+  std::vector Changes;
+
+  for (size_t i = 0; i < Steps.size() - 1; i++) {
+Annotations Src(Steps[i].Src);
+StringRef Contents = Steps[i].Contents;
+
+Changes.push_back({
+Src.range(),
+rangeLength(Src.code(), Src.range()),
+Contents.str(),
+});
+  }
+
+  // Set the initial content.
+  DS.addDraft(Path, InitialSrc.code());
+
+  llvm::Expected Result = DS.updateDraft(Path, Changes);
+
+  EXPECT_TRUE(!!Result) << llvm::toString(Result.takeError());
+  EXPECT_EQ(*Result, FinalSrc.code());
+  EXPECT_EQ(*DS.getDraft(Path), FinalSrc.code());
+}
+
+TEST(DraftStoreIncrementalUpdateTest, Simple) {
+  // clang-format off
+  IncrementalTestStep Steps[] =
+{
+  // Replace a range
+  {
+R"cpp(static int
+hello[[World]]()
+{})cpp",
+"Universe"
+  },
+  // Delete a range
+  {
+R"cpp(static int
+hello[[Universe]]()
+{})cpp",
+""
+  },
+  // Add a range
+  {
+R"cpp(static int
+hello[[]]()
+{})cpp",
+"Monde"
+  },
+  {
+R"cpp(static int
+helloMonde()
+{})cpp",
+""
+  }
+};
+  // clang-format on
+
+  stepByStep(Steps);
+  allAtOnce(Steps);
+}
+
+TEST(DraftStoreIncrementalUpdateTest, MultiLine) {
+  // clang-format off
+  IncrementalTestStep Steps[] =
+{
+  // Replace a range
+  {
+R"cpp(static [[int
+helloWorld]]()
+{})cpp",
+R"cpp(char
+welcome)cpp"
+  },
+  // Delete a range
+  {
+R"cpp(static char[[
+welcome]]()
+{})cpp",
+""
+  },
+  // Add a range
+  {
+R"cpp(static char[[]]()
+{})cpp",
+R"cpp(
+cookies)cpp"
+  },
+  // Replace the whole file
+  {
+R"cpp([[static char
+cookies()
+{}]])cpp",
+R"cpp(#include 
+)cpp"
+  },
+  // Delete the whole file
+  {
+R"cpp([[#include 
+]])cpp",
+"",
+  },
+  // Add something to an empty file
+  {
+"[[]]",
+R"cpp(int main() {
+)cpp",
+  },
+  {
+R"cpp(int main() {
+)cpp",
+""
+  }
+};
+  // clang-format on
+
+  stepByStep(Steps);
+  allAtOnce(Steps);
+}
+
+TEST(DraftStoreIncrementalUpdateTest, WrongRangeLength) {
+  DraftStore DS;
+  Path File = "foo.cpp";
+
+  DS.addDraft(File, "int main() {}\n");
+
+  TextDocumentContentChangeEvent Change;
+  Change.range.emplace();
+  Change.range->start.line = 0;
+  

[PATCH] D44694: [clang-tidy] Use :doc: for check links in Release Notes

2018-03-21 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE328115: [clang-tidy] Use :doc: for check links in Release 
Notes. (authored by eugenezelenko, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D44694?vs=139167=139320#toc

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44694

Files:
  clang-tidy/add_new_check.py
  clang-tidy/rename_check.py
  docs/ReleaseNotes.rst

Index: clang-tidy/add_new_check.py
===
--- clang-tidy/add_new_check.py
+++ clang-tidy/add_new_check.py
@@ -211,8 +211,8 @@
 elif header_found:
   if not line.startswith(''):
 f.write("""
-- New `%s
-  `_ check
+- New :doc:`%s
+  ` check
 
   FIXME: add release notes.
 """ % (check_name_dashes, check_name_dashes))
Index: clang-tidy/rename_check.py
===
--- clang-tidy/rename_check.py
+++ clang-tidy/rename_check.py
@@ -171,8 +171,8 @@
 elif header_found:
   if not line.startswith(''):
 f.write("""
-- The '%s' check was renamed to `%s
-  `_
+- The '%s' check was renamed to :doc:`%s
+  `
 """ % (old_check_name, new_check_name, new_check_name))
 note_added = True
 
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -57,136 +57,136 @@
 Improvements to clang-tidy
 --
 
+- New module `abseil` for checks related to the `Abseil `_
+  library.
+
 - New module ``portability``.
 
 - New module ``zircon`` for checks related to Fuchsia's Zircon kernel.
 
-- New `bugprone-throw-keyword-missing
-  `_ check
+- New :doc:`bugprone-throw-keyword-missing
+  ` check
 
   Diagnoses when a temporary object that appears to be an exception is
   constructed but not thrown.
 
-- New `bugprone-unused-return-value
-  `_ check
+- New :doc:`bugprone-unused-return-value
+  ` check
 
   Warns on unused function return values.
 
-- New `cppcoreguidelines-avoid-goto
-  `_ check
+- New :doc:`cppcoreguidelines-avoid-goto
+  ` check
 
   The usage of ``goto`` for control flow is error prone and should be replaced
   with looping constructs. Every backward jump is rejected. Forward jumps are
   only allowed in nested loops.
 
-- New `fuchsia-multiple-inheritance
-  `_ check
+- New :doc:`fuchsia-multiple-inheritance
+  ` check
 
   Warns if a class inherits from multiple classes that are not pure virtual.
 
-- New `abseil` module for checks related to the `Abseil `_
-  library.
-
-- New `abseil-string-find-startswith
-  `_ check
+- New :doc:`abseil-string-find-startswith
+  ` check
 
   Checks whether a ``std::string::find()`` result is compared with 0, and
   suggests replacing with ``absl::StartsWith()``.
 
-- New `fuchsia-statically-constructed-objects
-  `_ check
+- New :doc:`fuchsia-statically-constructed-objects
+  ` check
 
   Warns if global, non-trivial objects with static storage are constructed,
   unless the object is statically initialized with a ``constexpr`` constructor
   or has no explicit constructor.
 
-- New `fuchsia-trailing-return
-  `_ check
+- New :doc:`fuchsia-trailing-return
+  ` check
 
   Functions that have trailing returns are disallowed, except for those
   using ``decltype`` specifiers and lambda with otherwise unutterable
   return types.
 
-- New `hicpp-multiway-paths-covered
-  `_ check
+- New :doc:`hicpp-multiway-paths-covered
+  ` check
 
   Checks on ``switch`` and ``if`` - ``else if`` constructs that do not cover all possible code paths.
 
-- New `modernize-use-uncaught-exceptions
-  `_ check
+- New :doc:`modernize-use-uncaught-exceptions
+  ` check
 
   Finds and replaces deprecated uses of ``std::uncaught_exception`` to
   ``std::uncaught_exceptions``.
 
-- New `portability-simd-intrinsics
-  `_ check
+- New :doc:`portability-simd-intrinsics
+  ` check
 
   Warns or suggests alternatives if 

[clang-tools-extra] r328115 - [clang-tidy] Use :doc: for check links in Release Notes.

2018-03-21 Thread Eugene Zelenko via cfe-commits
Author: eugenezelenko
Date: Wed Mar 21 10:06:13 2018
New Revision: 328115

URL: http://llvm.org/viewvc/llvm-project?rev=328115=rev
Log:
[clang-tidy] Use :doc: for check links in Release Notes.

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

Modified:
clang-tools-extra/trunk/clang-tidy/add_new_check.py
clang-tools-extra/trunk/clang-tidy/rename_check.py
clang-tools-extra/trunk/docs/ReleaseNotes.rst

Modified: clang-tools-extra/trunk/clang-tidy/add_new_check.py
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/add_new_check.py?rev=328115=328114=328115=diff
==
--- clang-tools-extra/trunk/clang-tidy/add_new_check.py (original)
+++ clang-tools-extra/trunk/clang-tidy/add_new_check.py Wed Mar 21 10:06:13 2018
@@ -211,8 +211,8 @@ def add_release_notes(module_path, modul
 elif header_found:
   if not line.startswith(''):
 f.write("""
-- New `%s
-  `_ check
+- New :doc:`%s
+  ` check
 
   FIXME: add release notes.
 """ % (check_name_dashes, check_name_dashes))

Modified: clang-tools-extra/trunk/clang-tidy/rename_check.py
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/rename_check.py?rev=328115=328114=328115=diff
==
--- clang-tools-extra/trunk/clang-tidy/rename_check.py (original)
+++ clang-tools-extra/trunk/clang-tidy/rename_check.py Wed Mar 21 10:06:13 2018
@@ -171,8 +171,8 @@ def add_release_notes(clang_tidy_path, o
 elif header_found:
   if not line.startswith(''):
 f.write("""
-- The '%s' check was renamed to `%s
-  `_
+- The '%s' check was renamed to :doc:`%s
+  `
 """ % (old_check_name, new_check_name, new_check_name))
 note_added = True
 

Modified: clang-tools-extra/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/ReleaseNotes.rst?rev=328115=328114=328115=diff
==
--- clang-tools-extra/trunk/docs/ReleaseNotes.rst (original)
+++ clang-tools-extra/trunk/docs/ReleaseNotes.rst Wed Mar 21 10:06:13 2018
@@ -57,136 +57,136 @@ The improvements are...
 Improvements to clang-tidy
 --
 
+- New module `abseil` for checks related to the `Abseil `_
+  library.
+
 - New module ``portability``.
 
 - New module ``zircon`` for checks related to Fuchsia's Zircon kernel.
 
-- New `bugprone-throw-keyword-missing
-  
`_
 check
+- New :doc:`bugprone-throw-keyword-missing
+  ` check
 
   Diagnoses when a temporary object that appears to be an exception is
   constructed but not thrown.
 
-- New `bugprone-unused-return-value
-  
`_
 check
+- New :doc:`bugprone-unused-return-value
+  ` check
 
   Warns on unused function return values.
 
-- New `cppcoreguidelines-avoid-goto
-  
`_
 check
+- New :doc:`cppcoreguidelines-avoid-goto
+  ` check
 
   The usage of ``goto`` for control flow is error prone and should be replaced
   with looping constructs. Every backward jump is rejected. Forward jumps are
   only allowed in nested loops.
 
-- New `fuchsia-multiple-inheritance
-  
`_
 check
+- New :doc:`fuchsia-multiple-inheritance
+  ` check
 
   Warns if a class inherits from multiple classes that are not pure virtual.
 
-- New `abseil` module for checks related to the `Abseil `_
-  library.
-
-- New `abseil-string-find-startswith
-  
`_
 check
+- New :doc:`abseil-string-find-startswith
+  ` check
 
   Checks whether a ``std::string::find()`` result is compared with 0, and
   suggests replacing with ``absl::StartsWith()``.
 
-- New `fuchsia-statically-constructed-objects
-  
`_
 check
+- New :doc:`fuchsia-statically-constructed-objects
+  ` check
 
   Warns if global, non-trivial objects with static storage are constructed,
   unless the object is statically initialized with a ``constexpr`` constructor
   or has no explicit constructor.
 
-- New `fuchsia-trailing-return
-  
`_ 
check
+- New :doc:`fuchsia-trailing-return
+  ` check
 
   Functions that have trailing returns are disallowed, except for those
   using ``decltype`` specifiers and lambda with otherwise unutterable
   return 

[PATCH] D44720: [clangd] Simplify fuzzy matcher (sequence alignment) by removing some condition checks.

2018-03-21 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clangd/FuzzyMatch.cpp:96
 return None;
   return ScoreScale * std::min(PerfectBonus * PatN, std::max(0, Best));
 }

I also don't understand why it clamps the value to zero here. Negative values 
are also meaningful to me. Given that perfectBonus is only 3 it is very easy to 
get a negative value here.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44720



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


[PATCH] D44720: [clangd] Simplify fuzzy matcher (sequence alignment) by removing some condition checks.

2018-03-21 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clangd/FuzzyMatch.h:61
   bool allowMatch(int P, int W) const;
-  int skipPenalty(int W, Action Last) const;
-  int matchBonus(int P, int W, Action Last) const;
+  int missScore(int W, Action Last) const;
+  int matchScore(int P, int W, Action Last) const;

sammccall wrote:
> FWIW, I don't think this is an improvement - I think the clarity of purpose 
> in names is more useful than having consistent signs in this case.
Keep `matchBonus` but rename `skipPenalty` to `missPenalty` ?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44720



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


  1   2   >