[PATCH] D44878: libFuzzer OpenBSD support

2018-03-28 Thread David CARLIER via Phabricator via cfe-commits
devnexen added a comment.

ping


Repository:
  rC Clang

https://reviews.llvm.org/D44878



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


r328763 - Refactor some code for a warning. NFC.

2018-03-28 Thread Richard Trieu via cfe-commits
Author: rtrieu
Date: Wed Mar 28 22:14:17 2018
New Revision: 328763

URL: http://llvm.org/viewvc/llvm-project?rev=328763=rev
Log:
Refactor some code for a warning.  NFC.

Use range-based for-loops instead of iterators to walk over vectors.
Switch the key of the DenseMap so a custom key handler is no longer needed.
Remove unncessary adds to the DenseMap.
Use unique_ptr instead of manual memory management.

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

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=328763=328762=328763=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Mar 28 22:14:17 2018
@@ -16028,39 +16028,10 @@ static bool ValidDuplicateEnum(EnumConst
   return false;
 }
 
-namespace {
-struct DupKey {
-  int64_t val;
-  bool isTombstoneOrEmptyKey;
-  DupKey(int64_t val, bool isTombstoneOrEmptyKey)
-: val(val), isTombstoneOrEmptyKey(isTombstoneOrEmptyKey) {}
-};
-
-static DupKey GetDupKey(const llvm::APSInt& Val) {
-  return DupKey(Val.isSigned() ? Val.getSExtValue() : Val.getZExtValue(),
-false);
-}
-
-struct DenseMapInfoDupKey {
-  static DupKey getEmptyKey() { return DupKey(0, true); }
-  static DupKey getTombstoneKey() { return DupKey(1, true); }
-  static unsigned getHashValue(const DupKey Key) {
-return (unsigned)(Key.val * 37);
-  }
-  static bool isEqual(const DupKey& LHS, const DupKey& RHS) {
-return LHS.isTombstoneOrEmptyKey == RHS.isTombstoneOrEmptyKey &&
-   LHS.val == RHS.val;
-  }
-};
-} // end anonymous namespace
-
 // Emits a warning when an element is implicitly set a value that
 // a previous element has already been set to.
 static void CheckForDuplicateEnumValues(Sema , ArrayRef Elements,
-EnumDecl *Enum,
-QualType EnumType) {
-  if (S.Diags.isIgnored(diag::warn_duplicate_enum_values, Enum->getLocation()))
-return;
+EnumDecl *Enum, QualType EnumType) {
   // Avoid anonymous enums
   if (!Enum->getIdentifier())
 return;
@@ -16069,20 +16040,28 @@ static void CheckForDuplicateEnumValues(
   if (Enum->getNumPositiveBits() > 63 || Enum->getNumNegativeBits() > 64)
 return;
 
+  if (S.Diags.isIgnored(diag::warn_duplicate_enum_values, Enum->getLocation()))
+return;
+
   typedef SmallVector ECDVector;
-  typedef SmallVector DuplicatesVector;
+  typedef SmallVector DuplicatesVector;
 
   typedef llvm::PointerUnion DeclOrVector;
-  typedef llvm::DenseMap
-  ValueToVectorMap;
+  typedef llvm::DenseMap ValueToVectorMap;
+
+  // Use int64_t as a key to avoid needing special handling for DenseMap keys.
+  auto EnumConstantToKey = [](const EnumConstantDecl *D) {
+llvm::APSInt Val = D->getInitVal();
+return Val.isSigned() ? Val.getSExtValue() : Val.getZExtValue();
+  };
 
   DuplicatesVector DupVector;
   ValueToVectorMap EnumMap;
 
   // Populate the EnumMap with all values represented by enum constants without
-  // an initialier.
-  for (unsigned i = 0, e = Elements.size(); i != e; ++i) {
-EnumConstantDecl *ECD = cast_or_null(Elements[i]);
+  // an initializer.
+  for (auto *Element : Elements) {
+EnumConstantDecl *ECD = cast_or_null(Element);
 
 // Null EnumConstantDecl means a previous diagnostic has been emitted for
 // this constant.  Skip this enum since it may be ill-formed.
@@ -16090,45 +16069,45 @@ static void CheckForDuplicateEnumValues(
   return;
 }
 
+// Constants with initalizers are handled in the next loop.
 if (ECD->getInitExpr())
   continue;
 
-DupKey Key = GetDupKey(ECD->getInitVal());
-DeclOrVector  = EnumMap[Key];
-
-// First time encountering this value.
-if (Entry.isNull())
-  Entry = ECD;
+// Duplicate values are handled in the next loop.
+EnumMap.insert({EnumConstantToKey(ECD), ECD});
   }
 
+  if (EnumMap.size() == 0)
+return;
+
   // Create vectors for any values that has duplicates.
-  for (unsigned i = 0, e = Elements.size(); i != e; ++i) {
-EnumConstantDecl *ECD = cast(Elements[i]);
+  for (auto *Element : Elements) {
+// The last loop returned if any constant was null.
+EnumConstantDecl *ECD = cast(Element);
 if (!ValidDuplicateEnum(ECD, Enum))
   continue;
 
-DupKey Key = GetDupKey(ECD->getInitVal());
-
-DeclOrVector& Entry = EnumMap[Key];
-if (Entry.isNull())
+auto Iter = EnumMap.find(EnumConstantToKey(ECD));
+if (Iter == EnumMap.end())
   continue;
 
+DeclOrVector& Entry = Iter->second;
 if (EnumConstantDecl *D = Entry.dyn_cast()) {
   // Ensure constants are different.
   if (D == ECD)
 continue;
 
   // Create new 

[PATCH] D44865: [libc++] Implement P0608R1 - A sane variant converting constructor

2018-03-28 Thread Zhihao Yuan via Phabricator via cfe-commits
lichray updated this revision to Diff 140188.
lichray added a comment.

More tests


Repository:
  rCXX libc++

https://reviews.llvm.org/D44865

Files:
  include/variant
  test/std/utilities/variant/variant.variant/variant.assign/T.pass.cpp
  test/std/utilities/variant/variant.variant/variant.ctor/T.pass.cpp

Index: test/std/utilities/variant/variant.variant/variant.ctor/T.pass.cpp
===
--- test/std/utilities/variant/variant.variant/variant.ctor/T.pass.cpp
+++ test/std/utilities/variant/variant.variant/variant.ctor/T.pass.cpp
@@ -20,6 +20,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "test_convertible.hpp"
 #include "test_macros.h"
@@ -53,7 +54,7 @@
 
 void test_T_ctor_sfinae() {
   {
-using V = std::variant;
+using V = std::variant;
 static_assert(!std::is_constructible::value, "ambiguous");
   }
   {
@@ -66,6 +67,16 @@
   "no matching constructor");
   }
   {
+using V = std::variant;
+static_assert(!std::is_constructible::value,
+  "no matching constructor");
+  }
+  {
+using V = std::variant;
+static_assert(!std::is_constructible::value,
+  "no explicit bool in constructor");
+  }
+  {
 using V = std::variant;
 static_assert(
 !std::is_constructible::value,
@@ -99,6 +110,26 @@
 static_assert(v.index() == 1, "");
 static_assert(std::get<1>(v) == 42, "");
   }
+  {
+constexpr std::variant v(42);
+static_assert(v.index() == 1, "");
+static_assert(std::get<1>(v) == 42, "");
+  }
+  {
+std::variant v = "foo";
+assert(v.index() == 0);
+assert(std::get<0>(v) == "foo");
+  }
+  {
+std::variant> v = nullptr;
+assert(v.index() == 1);
+assert(std::get<1>(v) == nullptr);
+  }
+  {
+std::variant v = true;
+assert(v.index() == 0);
+assert(std::get<0>(v));
+  }
 #if !defined(TEST_VARIANT_HAS_NO_REFERENCES)
   {
 using V = std::variant;
Index: test/std/utilities/variant/variant.variant/variant.assign/T.pass.cpp
===
--- test/std/utilities/variant/variant.variant/variant.assign/T.pass.cpp
+++ test/std/utilities/variant/variant.variant/variant.assign/T.pass.cpp
@@ -28,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "test_macros.h"
 #include "variant_test_helpers.hpp"
@@ -128,7 +129,7 @@
 
 void test_T_assignment_sfinae() {
   {
-using V = std::variant;
+using V = std::variant;
 static_assert(!std::is_assignable::value, "ambiguous");
   }
   {
@@ -139,6 +140,15 @@
 using V = std::variant;
 static_assert(!std::is_assignable::value, "no matching operator=");
   }
+  {
+using V = std::variant;
+static_assert(!std::is_assignable::value, "no matching operator=");
+  }
+  {
+using V = std::variant;
+static_assert(!std::is_assignable::value,
+  "no explicit bool in operator=");
+  }
 #if !defined(TEST_VARIANT_HAS_NO_REFERENCES)
   {
 using V = std::variant;
@@ -167,6 +177,44 @@
 assert(v.index() == 1);
 assert(std::get<1>(v) == 43);
   }
+  {
+std::variant v;
+v = 42;
+assert(v.index() == 1);
+assert(std::get<1>(v) == 42);
+v = 43u;
+assert(v.index() == 0);
+assert(std::get<0>(v) == 43);
+  }
+  {
+std::variant v = true;
+v = std::false_type();
+assert(v.index() == 1);
+assert(std::get<1>(v) == false);
+v = "bar";
+assert(v.index() == 0);
+assert(std::get<0>(v) == "bar");
+  }
+  {
+std::variant v;
+v = nullptr;
+assert(v.index() == 1);
+assert(std::get<1>(v) == nullptr);
+v = std::true_type();
+assert(v.index() == 0);
+assert(std::get<0>(v));
+  }
+  {
+std::variant v = 42;
+assert(v.index() == 1);
+assert(std::get<1>(v) == 42);
+v = std::false_type();
+assert(v.index() == 0);
+assert(!std::get<0>(v));
+v = true;
+assert(v.index() == 0);
+assert(std::get<0>(v));
+  }
 #if !defined(TEST_VARIANT_HAS_NO_REFERENCES)
   {
 using V = std::variant;
Index: include/variant
===
--- include/variant
+++ include/variant
@@ -1097,11 +1097,40 @@
 template 
 struct __overload<_Tp, _Types...> : __overload<_Types...> {
   using __overload<_Types...>::operator();
-  __identity<_Tp> operator()(_Tp) const;
+
+  template 
+  auto operator()(_Tp, _Up&& __t) const
+  -> decltype(_Tp{__t}, __identity<_Tp>());
+};
+
+template 
+struct __overload_bool : _Base {
+  using 

[PATCH] D44536: Avoid segfault when destructor is not yet known

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

In https://reviews.llvm.org/D44536#1051181, @ahatanak wrote:

> I see, so Sema::CheckCompletedCXXClass probably isn't the right place to call 
> DeclareImplicitDestructor as that could significantly increase the size of 
> the AST.


Right.  Again, I'd like Richard to weigh in here, but my suspicion would be 
that, somehow, the fact that e is an incomplete type when we type-check that 
call is combining poorly with the fact that it's declared by the time that we 
generate IR for it.  We probably do not record the existence of a pre-emptive 
use of the destructor.  There is no other way to get into this situation 
because every other thing that cares about the existence of a destructor 
requires a complete type.

That probably points to the solution here.  We've already emitted a warning 
that the code is doing a trivial deletion.  We should set a flag in the 
CXXDeleteExpr saying that the destructor is trivial, based on what we found in 
Sema, and in IRGen we should honor that flag before actually looking at the 
type.

For what it's worth, I believe this test case has undefined behavior: we're 
[i]allowed[/i] to treat it as a deletion of an incomplete type and not actually 
call the destructor, because that was true at the point where we type-checked 
the call.  Arguably we should just set a flag in the CXXDeleteExpr


Repository:
  rC Clang

https://reviews.llvm.org/D44536



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


[PATCH] D44865: [libc++] Implement P0608R1 - A sane variant converting constructor

2018-03-28 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF added a comment.

This LGTM.

However, we should add tests for `const bool` and `volatile bool` before 
committing.

Also I would like @mclow.lists input about applying this DR early since LWG
hasn't commented on it yet.


Repository:
  rCXX libc++

https://reviews.llvm.org/D44865



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


[libcxx] r328760 - fix typo in align_const_pair_U_V.pass.cpp

2018-03-28 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Wed Mar 28 20:44:01 2018
New Revision: 328760

URL: http://llvm.org/viewvc/llvm-project?rev=328760=rev
Log:
fix typo in align_const_pair_U_V.pass.cpp

Modified:

libcxx/trunk/test/std/utilities/utility/pairs/pairs.pair/assign_const_pair_U_V.pass.cpp

Modified: 
libcxx/trunk/test/std/utilities/utility/pairs/pairs.pair/assign_const_pair_U_V.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/utility/pairs/pairs.pair/assign_const_pair_U_V.pass.cpp?rev=328760=328759=328760=diff
==
--- 
libcxx/trunk/test/std/utilities/utility/pairs/pairs.pair/assign_const_pair_U_V.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/utilities/utility/pairs/pairs.pair/assign_const_pair_U_V.pass.cpp
 Wed Mar 28 20:44:01 2018
@@ -44,7 +44,7 @@ int main()
assert(C::constructed == 0);
assert(C::assigned == 1);
assert(C::copy_assigned == 1);
-   assert(C::move_assigned == 0atu);
+   assert(C::move_assigned == 0);
assert(p.first == 42);
assert(p.second.value == -42);
 }


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


[libcxx] r328758 - Move libc++ pair/tuple assign test to libcxx/ test directory.

2018-03-28 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Wed Mar 28 20:30:00 2018
New Revision: 328758

URL: http://llvm.org/viewvc/llvm-project?rev=328758=rev
Log:
Move libc++ pair/tuple assign test to libcxx/ test directory.

Libc++ implements the pair& operator=(pair) assignment operator
using a single template that handles assignment from all tuple-like types.

This patch moves the test for that to the libcxx test directory since
it's non-standard. It also adds additional tests to the std/.../pair
directory to test the standard behavior this template implements.

Added:

libcxx/trunk/test/libcxx/utilities/utility/pairs/pairs.pair/assign_tuple_like.pass.cpp
  - copied, changed from r328751, 
libcxx/trunk/test/std/utilities/utility/pairs/pairs.pair/assign_tuple.pass.cpp
Removed:

libcxx/trunk/test/std/utilities/utility/pairs/pairs.pair/assign_tuple.pass.cpp
Modified:

libcxx/trunk/test/std/utilities/utility/pairs/pairs.pair/assign_const_pair_U_V.pass.cpp

libcxx/trunk/test/std/utilities/utility/pairs/pairs.pair/assign_rv_pair_U_V.pass.cpp

Copied: 
libcxx/trunk/test/libcxx/utilities/utility/pairs/pairs.pair/assign_tuple_like.pass.cpp
 (from r328751, 
libcxx/trunk/test/std/utilities/utility/pairs/pairs.pair/assign_tuple.pass.cpp)
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/utilities/utility/pairs/pairs.pair/assign_tuple_like.pass.cpp?p2=libcxx/trunk/test/libcxx/utilities/utility/pairs/pairs.pair/assign_tuple_like.pass.cpp=libcxx/trunk/test/std/utilities/utility/pairs/pairs.pair/assign_tuple.pass.cpp=328751=328758=328758=diff
==
--- 
libcxx/trunk/test/std/utilities/utility/pairs/pairs.pair/assign_tuple.pass.cpp 
(original)
+++ 
libcxx/trunk/test/libcxx/utilities/utility/pairs/pairs.pair/assign_tuple_like.pass.cpp
 Wed Mar 28 20:30:00 2018
@@ -21,58 +21,22 @@
 #include 
 #include 
 
+#include "archetypes.hpp"
+
 // Clang warns about missing braces when initializing std::array.
 #if defined(__clang__)
 #pragma clang diagnostic ignored "-Wmissing-braces"
 #endif
 
-struct CountingType {
-  static int constructed;
-  static int copy_constructed;
-  static int move_constructed;
-  static int assigned;
-  static int copy_assigned;
-  static int move_assigned;
-  static void reset() {
-  constructed = copy_constructed = move_constructed = 0;
-  assigned = copy_assigned = move_assigned = 0;
-  }
-  CountingType() : value(0) { ++constructed; }
-  CountingType(int v) : value(v) { ++constructed; }
-  CountingType(CountingType const& o) : value(o.value) { ++constructed; 
++copy_constructed; }
-  CountingType(CountingType&& o) : value(o.value) { ++constructed; 
++move_constructed; o.value = -1;}
-
-  CountingType& operator=(CountingType const& o) {
-  ++assigned;
-  ++copy_assigned;
-  value = o.value;
-  return *this;
-  }
-  CountingType& operator=(CountingType&& o) {
-  ++assigned;
-  ++move_assigned;
-  value = o.value;
-  o.value = -1;
-  return *this;
-  }
-  int value;
-};
-int CountingType::constructed;
-int CountingType::copy_constructed;
-int CountingType::move_constructed;
-int CountingType::assigned;
-int CountingType::copy_assigned;
-int CountingType::move_assigned;
-
 int main()
 {
-using C = CountingType;
+using C = TestTypes::TestType;
 {
using P = std::pair;
using T = std::tuple;
T t(42, C{42});
P p(101, C{101});
-   C::reset();
+   C::reset_constructors();
p = t;
assert(C::constructed == 0);
assert(C::assigned == 1);
@@ -86,7 +50,7 @@ int main()
using T = std::tuple;
T t(42, -42);
P p(101, 101);
-   C::reset();
+   C::reset_constructors();
p = std::move(t);
assert(C::constructed == 0);
assert(C::assigned == 1);
@@ -100,7 +64,7 @@ int main()
using T = std::array;
T t = {42, -42};
P p{101, 101};
-   C::reset();
+   C::reset_constructors();
p = t;
assert(C::constructed == 0);
assert(C::assigned == 2);
@@ -114,7 +78,7 @@ int main()
using T = std::array;
T t = {42, -42};
P p{101, 101};
-   C::reset();
+   C::reset_constructors();
p = t;
assert(C::constructed == 0);
assert(C::assigned == 2);
@@ -128,7 +92,7 @@ int main()
using T = std::array;
T t = {42, -42};
P p{101, 101};
-   C::reset();
+   C::reset_constructors();
p = std::move(t);
assert(C::constructed == 0);
assert(C::assigned == 2);

Modified: 
libcxx/trunk/test/std/utilities/utility/pairs/pairs.pair/assign_const_pair_U_V.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/utility/pairs/pairs.pair/assign_const_pair_U_V.pass.cpp?rev=328758=328757=328758=diff
==
--- 

[PATCH] D37115: [coroutines] Do not attempt to typo-correct when coroutine is looking for required members

2018-03-28 Thread Gor Nishanov via Phabricator via cfe-commits
GorNishanov closed this revision.
GorNishanov added a comment.

Fixed:
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@328663 
91177308-0d34-0410-b5e6-96231b3b80d8


https://reviews.llvm.org/D37115



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


[PATCH] D43927: [Coroutines] Schedule coro-split before asan

2018-03-28 Thread Gor Nishanov via Phabricator via cfe-commits
GorNishanov accepted this revision.
GorNishanov added a comment.
This revision is now accepted and ready to land.

LGTM!


Repository:
  rC Clang

https://reviews.llvm.org/D43927



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


[PATCH] D45016: [libcxx] [test] Avoid MSVC truncation warnings.

2018-03-28 Thread Stephan T. Lavavej via Phabricator via cfe-commits
STL_MSFT created this revision.
STL_MSFT added reviewers: EricWF, mclow.lists.

[libcxx] [test] Avoid MSVC truncation warnings.

MSVC emits "warning C4244: 'initializing': conversion from 'int'
to 'short', possible loss of data" when it sees pair
constructed from (whatever, 4), because int is being truncated to
short within pair's constructor. (The compiler doesn't take into
account the fact that 4 is a literal at the callsite; it generates
this warning when the constructor is instantiated, because it might
be called with a runtime-valued int that would actually truncate.)

Instead of static_cast, we can simply change short to int
in these tests, without affecting the pair operations that they're
trying to test: move assignment, convert copy construction, and
convert move construction.


https://reviews.llvm.org/D45016

Files:
  test/std/utilities/utility/pairs/pairs.pair/assign_rv_pair.pass.cpp
  test/std/utilities/utility/pairs/pairs.pair/const_pair_U_V.pass.cpp
  test/std/utilities/utility/pairs/pairs.pair/rv_pair_U_V.pass.cpp


Index: test/std/utilities/utility/pairs/pairs.pair/rv_pair_U_V.pass.cpp
===
--- test/std/utilities/utility/pairs/pairs.pair/rv_pair_U_V.pass.cpp
+++ test/std/utilities/utility/pairs/pairs.pair/rv_pair_U_V.pass.cpp
@@ -67,7 +67,7 @@
 int main()
 {
 {
-typedef std::pair P1;
+typedef std::pair P1;
 typedef std::pair P2;
 P1 p1(std::unique_ptr(), 4);
 P2 p2 = std::move(p1);
Index: test/std/utilities/utility/pairs/pairs.pair/const_pair_U_V.pass.cpp
===
--- test/std/utilities/utility/pairs/pairs.pair/const_pair_U_V.pass.cpp
+++ test/std/utilities/utility/pairs/pairs.pair/const_pair_U_V.pass.cpp
@@ -57,7 +57,7 @@
 int main()
 {
 {
-typedef std::pair P1;
+typedef std::pair P1;
 typedef std::pair P2;
 const P1 p1(3, 4);
 const P2 p2 = p1;
@@ -154,7 +154,7 @@
 }
 #if TEST_STD_VER > 11
 {
-typedef std::pair P1;
+typedef std::pair P1;
 typedef std::pair P2;
 constexpr P1 p1(3, 4);
 constexpr P2 p2 = p1;
Index: test/std/utilities/utility/pairs/pairs.pair/assign_rv_pair.pass.cpp
===
--- test/std/utilities/utility/pairs/pairs.pair/assign_rv_pair.pass.cpp
+++ test/std/utilities/utility/pairs/pairs.pair/assign_rv_pair.pass.cpp
@@ -49,7 +49,7 @@
 int main()
 {
 {
-typedef std::pair P;
+typedef std::pair P;
 P p1(std::unique_ptr(new int(3)), 4);
 P p2;
 p2 = std::move(p1);


Index: test/std/utilities/utility/pairs/pairs.pair/rv_pair_U_V.pass.cpp
===
--- test/std/utilities/utility/pairs/pairs.pair/rv_pair_U_V.pass.cpp
+++ test/std/utilities/utility/pairs/pairs.pair/rv_pair_U_V.pass.cpp
@@ -67,7 +67,7 @@
 int main()
 {
 {
-typedef std::pair P1;
+typedef std::pair P1;
 typedef std::pair P2;
 P1 p1(std::unique_ptr(), 4);
 P2 p2 = std::move(p1);
Index: test/std/utilities/utility/pairs/pairs.pair/const_pair_U_V.pass.cpp
===
--- test/std/utilities/utility/pairs/pairs.pair/const_pair_U_V.pass.cpp
+++ test/std/utilities/utility/pairs/pairs.pair/const_pair_U_V.pass.cpp
@@ -57,7 +57,7 @@
 int main()
 {
 {
-typedef std::pair P1;
+typedef std::pair P1;
 typedef std::pair P2;
 const P1 p1(3, 4);
 const P2 p2 = p1;
@@ -154,7 +154,7 @@
 }
 #if TEST_STD_VER > 11
 {
-typedef std::pair P1;
+typedef std::pair P1;
 typedef std::pair P2;
 constexpr P1 p1(3, 4);
 constexpr P2 p2 = p1;
Index: test/std/utilities/utility/pairs/pairs.pair/assign_rv_pair.pass.cpp
===
--- test/std/utilities/utility/pairs/pairs.pair/assign_rv_pair.pass.cpp
+++ test/std/utilities/utility/pairs/pairs.pair/assign_rv_pair.pass.cpp
@@ -49,7 +49,7 @@
 int main()
 {
 {
-typedef std::pair P;
+typedef std::pair P;
 P p1(std::unique_ptr(new int(3)), 4);
 P p2;
 p2 = std::move(p1);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45015: [Preprocessor] Allow libc++ to detect when aligned allocation is unavailable.

2018-03-28 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF created this revision.
EricWF added reviewers: rsmith, vsapsai, erik.pilkington, ahatanak.

Libc++ needs to know when aligned allocation is supported by clang, but is 
otherwise unavailable at link time. This patch adds a predefined macro to allow 
libc++ to do that.

IDK if using a predefined macro is the best approach. Better approaches are 
always welcome :-)

Also see llvm.org/PR22634


Repository:
  rC Clang

https://reviews.llvm.org/D45015

Files:
  lib/Frontend/InitPreprocessor.cpp
  test/Preprocessor/predefined-macros.c


Index: test/Preprocessor/predefined-macros.c
===
--- test/Preprocessor/predefined-macros.c
+++ test/Preprocessor/predefined-macros.c
@@ -271,3 +271,20 @@
 // RUN: %clang_cc1 %s -E -dM -o - -x cl -triple spir-unknown-unknown \
 // RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-SPIR
 // CHECK-SPIR: #define __IMAGE_SUPPORT__ 1
+
+
+// RUN: %clang_cc1 %s -x c++ -E -dM  -faligned-allocation \
+// RUN: | FileCheck  %s -check-prefix=CHECK-ALIGNED-ALLOC-AVAILABLE
+// RUN: %clang_cc1 %s -x c++ -E -dM  -std=c++17 \
+// RUN: | FileCheck %s -check-prefix=CHECK-ALIGNED-ALLOC-AVAILABLE
+
+// CHECK-ALIGNED-ALLOC-AVAILABLE-NOT: __ALIGNED_ALLOCATION_UNAVAILABLE__
+
+// RUN: %clang_cc1 %s -x c++ -E -dM -std=c++03  \
+// RUN: | FileCheck %s -match-full-lines 
-check-prefix=CHECK-ALIGNED-ALLOC-UNAVAILABLE
+// RUN: %clang_cc1 %s -x c++ -E -dM -faligned-alloc-unavailable  \
+// RUN: | FileCheck %s -match-full-lines 
-check-prefix=CHECK-ALIGNED-ALLOC-UNAVAILABLE
+// RUN: %clang_cc1 %s -x c++ -E -dM -faligned-allocation 
-faligned-alloc-unavailable  \
+// RUN: | FileCheck %s -match-full-lines 
-check-prefix=CHECK-ALIGNED-ALLOC-UNAVAILABLE
+
+// CHECK-ALIGNED-ALLOC-UNAVAILABLE: #define __ALIGNED_ALLOCATION_UNAVAILABLE__ 
1
Index: lib/Frontend/InitPreprocessor.cpp
===
--- lib/Frontend/InitPreprocessor.cpp
+++ lib/Frontend/InitPreprocessor.cpp
@@ -1056,6 +1056,9 @@
 Builder.defineMacro("__GLIBCXX_BITSIZE_INT_N_0", "128");
   }
 
+  if (!LangOpts.AlignedAllocation || LangOpts.AlignedAllocationUnavailable)
+Builder.defineMacro("__ALIGNED_ALLOCATION_UNAVAILABLE__");
+
   // Get other target #defines.
   TI.getTargetDefines(LangOpts, Builder);
 }


Index: test/Preprocessor/predefined-macros.c
===
--- test/Preprocessor/predefined-macros.c
+++ test/Preprocessor/predefined-macros.c
@@ -271,3 +271,20 @@
 // RUN: %clang_cc1 %s -E -dM -o - -x cl -triple spir-unknown-unknown \
 // RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-SPIR
 // CHECK-SPIR: #define __IMAGE_SUPPORT__ 1
+
+
+// RUN: %clang_cc1 %s -x c++ -E -dM  -faligned-allocation \
+// RUN: | FileCheck  %s -check-prefix=CHECK-ALIGNED-ALLOC-AVAILABLE
+// RUN: %clang_cc1 %s -x c++ -E -dM  -std=c++17 \
+// RUN: | FileCheck %s -check-prefix=CHECK-ALIGNED-ALLOC-AVAILABLE
+
+// CHECK-ALIGNED-ALLOC-AVAILABLE-NOT: __ALIGNED_ALLOCATION_UNAVAILABLE__
+
+// RUN: %clang_cc1 %s -x c++ -E -dM -std=c++03  \
+// RUN: | FileCheck %s -match-full-lines -check-prefix=CHECK-ALIGNED-ALLOC-UNAVAILABLE
+// RUN: %clang_cc1 %s -x c++ -E -dM -faligned-alloc-unavailable  \
+// RUN: | FileCheck %s -match-full-lines -check-prefix=CHECK-ALIGNED-ALLOC-UNAVAILABLE
+// RUN: %clang_cc1 %s -x c++ -E -dM -faligned-allocation -faligned-alloc-unavailable  \
+// RUN: | FileCheck %s -match-full-lines -check-prefix=CHECK-ALIGNED-ALLOC-UNAVAILABLE
+
+// CHECK-ALIGNED-ALLOC-UNAVAILABLE: #define __ALIGNED_ALLOCATION_UNAVAILABLE__ 1
Index: lib/Frontend/InitPreprocessor.cpp
===
--- lib/Frontend/InitPreprocessor.cpp
+++ lib/Frontend/InitPreprocessor.cpp
@@ -1056,6 +1056,9 @@
 Builder.defineMacro("__GLIBCXX_BITSIZE_INT_N_0", "128");
   }
 
+  if (!LangOpts.AlignedAllocation || LangOpts.AlignedAllocationUnavailable)
+Builder.defineMacro("__ALIGNED_ALLOCATION_UNAVAILABLE__");
+
   // Get other target #defines.
   TI.getTargetDefines(LangOpts, Builder);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45014: [Index] Return SourceLocation to consumers, not FileID/Offset pair.

2018-03-28 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added reviewers: akyrtzi, arphaman.
Herald added subscribers: cfe-commits, ioeric, ilya-biryukov.

The FileID/Offset conversion is lossy. The code takes the fileLoc, which loses
e.g. the spelling location in some macro cases.
Instead, pass the original SourceLocation which preserves all information, and
update consumers to match current behavior.

This allows us to fix two bugs in clangd that need the spelling location.


Repository:
  rC Clang

https://reviews.llvm.org/D45014

Files:
  include/clang/Index/IndexDataConsumer.h
  lib/Index/IndexingAction.cpp
  lib/Index/IndexingContext.cpp
  tools/c-index-test/core_main.cpp
  tools/libclang/CXIndexDataConsumer.cpp
  tools/libclang/CXIndexDataConsumer.h

Index: tools/libclang/CXIndexDataConsumer.h
===
--- tools/libclang/CXIndexDataConsumer.h
+++ tools/libclang/CXIndexDataConsumer.h
@@ -465,12 +465,11 @@
 private:
   bool handleDeclOccurence(const Decl *D, index::SymbolRoleSet Roles,
ArrayRef Relations,
-   FileID FID, unsigned Offset,
-   ASTNodeInfo ASTNode) override;
+   SourceLocation Loc, ASTNodeInfo ASTNode) override;
 
   bool handleModuleOccurence(const ImportDecl *ImportD,
  index::SymbolRoleSet Roles,
- FileID FID, unsigned Offset) override;
+ SourceLocation Loc) override;
 
   void finish() override;
 
Index: tools/libclang/CXIndexDataConsumer.cpp
===
--- tools/libclang/CXIndexDataConsumer.cpp
+++ tools/libclang/CXIndexDataConsumer.cpp
@@ -155,13 +155,10 @@
 }
 }
 
-bool CXIndexDataConsumer::handleDeclOccurence(const Decl *D,
-  SymbolRoleSet Roles,
- ArrayRef Relations,
-  FileID FID, unsigned Offset,
-  ASTNodeInfo ASTNode) {
-  SourceLocation Loc = getASTContext().getSourceManager()
-  .getLocForStartOfFile(FID).getLocWithOffset(Offset);
+bool CXIndexDataConsumer::handleDeclOccurence(
+const Decl *D, SymbolRoleSet Roles, ArrayRef Relations,
+SourceLocation Loc, ASTNodeInfo ASTNode) {
+  Loc = getASTContext().getSourceManager().getFileLoc(Loc);
 
   if (Roles & (unsigned)SymbolRole::Reference) {
 const NamedDecl *ND = dyn_cast(D);
@@ -226,8 +223,7 @@
 
 bool CXIndexDataConsumer::handleModuleOccurence(const ImportDecl *ImportD,
 SymbolRoleSet Roles,
-FileID FID,
-unsigned Offset) {
+SourceLocation Loc) {
   IndexingDeclVisitor(*this, SourceLocation(), nullptr).Visit(ImportD);
   return !shouldAbort();
 }
Index: tools/c-index-test/core_main.cpp
===
--- tools/c-index-test/core_main.cpp
+++ tools/c-index-test/core_main.cpp
@@ -88,13 +88,14 @@
 
   bool handleDeclOccurence(const Decl *D, SymbolRoleSet Roles,
ArrayRef Relations,
-   FileID FID, unsigned Offset,
-   ASTNodeInfo ASTNode) override {
+   SourceLocation Loc, ASTNodeInfo ASTNode) override {
 ASTContext  = D->getASTContext();
 SourceManager  = Ctx.getSourceManager();
 
-unsigned Line = SM.getLineNumber(FID, Offset);
-unsigned Col = SM.getColumnNumber(FID, Offset);
+Loc = SM.getFileLoc(Loc);
+FileID FID = SM.getFileID(Loc);
+unsigned Line = SM.getLineNumber(FID, SM.getFileOffset(Loc));
+unsigned Col = SM.getColumnNumber(FID, SM.getFileOffset(Loc));
 OS << Line << ':' << Col << " | ";
 
 printSymbolInfo(getSymbolInfo(D), OS);
@@ -124,12 +125,14 @@
   }
 
   bool handleModuleOccurence(const ImportDecl *ImportD, SymbolRoleSet Roles,
- FileID FID, unsigned Offset) override {
+ SourceLocation Loc) override {
 ASTContext  = ImportD->getASTContext();
 SourceManager  = Ctx.getSourceManager();
 
-unsigned Line = SM.getLineNumber(FID, Offset);
-unsigned Col = SM.getColumnNumber(FID, Offset);
+Loc = SM.getFileLoc(Loc);
+FileID FID = SM.getFileID(Loc);
+unsigned Line = SM.getLineNumber(FID, SM.getFileOffset(Loc));
+unsigned Col = SM.getColumnNumber(FID, SM.getFileOffset(Loc));
 OS << Line << ':' << Col << " | ";
 
 printSymbolInfo(getSymbolInfo(ImportD), OS);
Index: lib/Index/IndexingContext.cpp
===
--- lib/Index/IndexingContext.cpp
+++ lib/Index/IndexingContext.cpp
@@ -82,14 +82,9 @@
 Loc = IdLocs.front();
   else
 

[PATCH] D44764: [clangd] Use operator<< to prevent printers issues in Gtest

2018-03-28 Thread Marc-Andre Laperle via Phabricator via cfe-commits
malaperle added inline comments.



Comment at: unittests/clangd/JSONExprTests.cpp:19
-void PrintTo(const Expr , std::ostream *OS) {
-  llvm::raw_os_ostream(*OS) << llvm::formatv("{0:2}", E);
-}

This one I couldn't change to operator<< because there was already one defined 
with raw_ostream. But this just means losing indentation so perhaps that's not 
too bad?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44764



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


[PATCH] D44536: Avoid segfault when destructor is not yet known

2018-03-28 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added a comment.

I see, so Sema::CheckCompletedCXXClass probably isn't the right place to call 
DeclareImplicitDestructor as that could significantly increase the size of the 
AST.


Repository:
  rC Clang

https://reviews.llvm.org/D44536



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


[PATCH] D44764: [clangd] Use a header for common inclusions for tests

2018-03-28 Thread Marc-Andre Laperle via Phabricator via cfe-commits
malaperle updated this revision to Diff 140180.
malaperle added a comment.

Use operator<< where we can


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44764

Files:
  clangd/Protocol.cpp
  clangd/Protocol.h
  unittests/clangd/CodeCompleteTests.cpp
  unittests/clangd/JSONExprTests.cpp
  unittests/clangd/XRefsTests.cpp

Index: unittests/clangd/XRefsTests.cpp
===
--- unittests/clangd/XRefsTests.cpp
+++ unittests/clangd/XRefsTests.cpp
@@ -24,15 +24,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/JSONExprTests.cpp
===
--- unittests/clangd/JSONExprTests.cpp
+++ unittests/clangd/JSONExprTests.cpp
@@ -15,9 +15,7 @@
 namespace clang {
 namespace clangd {
 namespace json {
-void PrintTo(const Expr , std::ostream *OS) {
-  llvm::raw_os_ostream(*OS) << llvm::formatv("{0:2}", E);
-}
+
 namespace {
 
 std::string s(const Expr ) { return llvm::formatv("{0}", E).str(); }
Index: unittests/clangd/CodeCompleteTests.cpp
===
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -22,33 +22,6 @@
 
 namespace clang {
 namespace clangd {
-// Let GMock print completion items and signature help.
-void PrintTo(const CompletionItem , std::ostream *O) {
-  llvm::raw_os_ostream OS(*O);
-  OS << I.label << " - " << toJSON(I);
-}
-void PrintTo(const std::vector , std::ostream *O) {
-  *O << "{\n";
-  for (const auto  : V) {
-*O << "\t";
-PrintTo(I, O);
-*O << "\n";
-  }
-  *O << "}";
-}
-void PrintTo(const SignatureInformation , std::ostream *O) {
-  llvm::raw_os_ostream OS(*O);
-  OS << I.label << " - " << toJSON(I);
-}
-void PrintTo(const std::vector , std::ostream *O) {
-  *O << "{\n";
-  for (const auto  : V) {
-*O << "\t";
-PrintTo(I, O);
-*O << "\n";
-  }
-  *O << "}";
-}
 
 namespace {
 using namespace llvm;
Index: clangd/Protocol.h
===
--- clangd/Protocol.h
+++ clangd/Protocol.h
@@ -670,6 +670,7 @@
   //  between a completion and a completion resolve request.
 };
 json::Expr toJSON(const CompletionItem &);
+std::ostream <<(std::ostream &, const CompletionItem &);
 
 bool operator<(const CompletionItem &, const CompletionItem &);
 
@@ -708,6 +709,7 @@
   std::vector parameters;
 };
 json::Expr toJSON(const SignatureInformation &);
+std::ostream <<(std::ostream &, const SignatureInformation &);
 
 /// Represents the signature of a callable.
 struct SignatureHelp {
@@ -761,6 +763,7 @@
   }
 };
 json::Expr toJSON(const DocumentHighlight );
+std::ostream <<(std::ostream &, const DocumentHighlight &);
 
 } // namespace clangd
 } // namespace clang
Index: clangd/Protocol.cpp
===
--- clangd/Protocol.cpp
+++ clangd/Protocol.cpp
@@ -19,6 +19,7 @@
 #include "llvm/Support/Format.h"
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/raw_os_ostream.h"
 #include "llvm/Support/raw_ostream.h"
 
 namespace clang {
@@ -446,6 +447,12 @@
   return std::move(Result);
 }
 
+std::ostream <<(std::ostream , const CompletionItem ) {
+  llvm::raw_os_ostream OS(O);
+  OS << I.label << " - " << toJSON(I);
+  return O;
+}
+
 bool operator<(const CompletionItem , const CompletionItem ) {
   return (L.sortText.empty() ? L.label : L.sortText) <
  (R.sortText.empty() ? R.label : R.sortText);
@@ -477,6 +484,12 @@
   return std::move(Result);
 }
 
+std::ostream <<(std::ostream , const SignatureInformation ) {
+  llvm::raw_os_ostream OS(O);
+  OS << I.label << " - " << toJSON(I);
+  return O;
+}
+
 json::Expr toJSON(const SignatureHelp ) {
   assert(SH.activeSignature >= 0 &&
  "Unexpected negative value for number of active signatures.");
@@ -502,6 +515,16 @@
   };
 }
 
+std::ostream <<(std::ostream , const DocumentHighlight ) {
+  llvm::raw_os_ostream OS(O);
+  OS << V.range;
+  if (V.kind == DocumentHighlightKind::Read)
+OS << "(r)";
+  if (V.kind == DocumentHighlightKind::Write)
+OS << "(w)";
+  return O;
+}
+
 bool fromJSON(const json::Expr , DidChangeConfigurationParams ) {
   json::ObjectMapper O(Params);
   return O && O.map("settings", CCP.settings);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r328754 - [astmatchers] Fix linking issue

2018-03-28 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Wed Mar 28 19:47:28 2018
New Revision: 328754

URL: http://llvm.org/viewvc/llvm-project?rev=328754=rev
Log:
[astmatchers] Fix linking issue

Modified:
cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp

Modified: cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp?rev=328754=328753=328754=diff
==
--- cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp (original)
+++ cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp Wed Mar 28 19:47:28 2018
@@ -760,6 +760,9 @@ const internal::VariadicOperatorMatcherF
 const internal::VariadicFunction
 hasAnyName = {};
+const internal::VariadicFunction
+hasAnySelector = {};
 const internal::ArgumentAdaptingMatcherFunc has = {};
 const internal::ArgumentAdaptingMatcherFunc
 hasDescendant = {};


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


[PATCH] D44764: [clangd] Use a header for common inclusions for tests

2018-03-28 Thread Marc-Andre Laperle via Phabricator via cfe-commits
malaperle added a comment.

In https://reviews.llvm.org/D44764#1046766, @sammccall wrote:

> I understand the template instantiations here are a mess and we need to solve 
> the problem. However I'm not sure this is the right direction:
>
> - it violates IWYU, and we expect people consistently to get gmock 
> transitively via this header. This goes against common practice, is 
> inconsistent with the rest of LLVM, and confuses tools (including clangd 
> itself!). It would need to be carefully documented, but I don't think this is 
> enough.


I didn't know LLVM code was IWYU, is this mentioned in the guide-line? I would 
think for tests this can be more lax maybe. I'm curious what you mean though by 
confusing the tools?

>   - it's fragile - as soon as one test includes gmock directly we have this 
> problem again
>   - `printers.h` takes a horizontal slice of the types we have - it seems to 
> suffer from the same problem as "not all tests should depend on clangdserver".
> 
> I'd suggest instead:
> - where there's a fairly nice general-purpose debugging representation of a 
> type, we should name that `operator<<` and declare it in the header alongside 
> the type. That way it's clear that it's available, there's no risk of ODR 
> violation, and it can be used for debugging as well as by gtest.
>   - where there isn't one (or it's insufficiently detailed), we should use 
> something more primitive like `EXPECT_THAT(foo, ...) << dump(foo)` with 
> `dump` defined locally in the cpp file. We can't share these, but these 
> aren't really sharable anyway. This isn't ideal (nested matcher messages) but 
> should be good enough in practice.

Yes, it is fragile but even using operator<<, we can still have the problem of 
anyone adding a Printer, which is normally how gtest is used. So I think either 
way is going to be fragile. But I don't mind either way, so I'll change the 
patch for operator<<


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44764



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


[PATCH] D45013: Generate warning when over-aligned new call is required but not supported.

2018-03-28 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF created this revision.
EricWF added reviewers: vsapsai, mclow.lists.
Herald added a subscriber: christof.

Currently libc++ silently ignores over-aligned allocation requests
made through __libcpp_allocate when aligned new/delete is not available.

  

This patch uses the `diagnose_if` attribute to generate a warning in that
case instead of being silent.

  

The change required converting __is_overaligned_for_new to a macro
so that the diagnose_if condition is still a potential constant expression in 
C++03.


Repository:
  rCXX libc++

https://reviews.llvm.org/D45013

Files:
  include/memory
  include/new
  
test/libcxx/utilities/memory/default.allocation/allocator.members/overaligned_new_not_supported.fail.cpp

Index: test/libcxx/utilities/memory/default.allocation/allocator.members/overaligned_new_not_supported.fail.cpp
===
--- /dev/null
+++ test/libcxx/utilities/memory/default.allocation/allocator.members/overaligned_new_not_supported.fail.cpp
@@ -0,0 +1,85 @@
+//===--===//
+//
+// 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.
+//
+//===--===//
+
+// REQUIRES: diagnose-if-support, verify-support
+
+// 
+
+// allocator:
+// pointer allocate(size_type n, allocator::const_pointer hint=0);
+
+// Test that a warning is generated when aligned allocation is not supported
+// but an over-aligned allocation is requested.
+
+#include 
+
+#include "test_macros.h"
+
+#ifndef TEST_HAS_NO_ALIGNED_ALLOCATION
+// expected-no-diagnostics
+#endif
+
+
+#ifdef __STDCPP_DEFAULT_NEW_ALIGNMENT__
+static const size_t MaxAligned = __STDCPP_DEFAULT_NEW_ALIGNMENT__;
+#else
+static const size_t MaxAligned = std::alignment_of::value;
+#endif
+
+static const size_t OverAligned = MaxAligned * 2;
+
+
+template 
+struct TEST_ALIGNAS(Align) AlignedType {
+  char data;
+  AlignedType() { }
+  AlignedType(AlignedType const&) { }
+  ~AlignedType() {}
+};
+
+
+void test_builtin_new() {
+  {
+typedef AlignedType T;
+void* ptr = std::__libcpp_allocate(sizeof(T), __alignof(T));
+std::__libcpp_deallocate(ptr, __alignof(T));
+  }
+  {
+#if defined(TEST_HAS_NO_ALIGNED_ALLOCATION)
+// expected-warning@+3 1 {{over-aligned allocation using 'operator new' is not supported}}
+#endif
+typedef AlignedType T;
+void* ptr = std::__libcpp_allocate(sizeof(T), __alignof(T));
+std::__libcpp_deallocate(ptr, __alignof(T));
+  }
+}
+
+void test_std_allocator() {
+  {
+typedef AlignedType T;
+std::allocator a;
+T* ptr = a.allocate(1); // OK
+a.deallocate(ptr, 1);
+  }
+  {
+#if defined(TEST_HAS_NO_ALIGNED_ALLOCATION)
+// expected-warning@memory:* 1 {{over-aligned allocation using 'operator new' is not supported}}
+// expected-note@+4  {{requested here}}
+#endif
+typedef AlignedType T;
+std::allocator a;
+T* ptr = a.allocate(1);
+a.deallocate(ptr, 1);
+  }
+}
+
+int main() {
+  test_std_allocator();
+  test_builtin_new();
+}
Index: include/new
===
--- include/new
+++ include/new
@@ -232,17 +232,20 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-_LIBCPP_CONSTEXPR inline _LIBCPP_INLINE_VISIBILITY bool __is_overaligned_for_new(size_t __align) _NOEXCEPT {
 #ifdef __STDCPP_DEFAULT_NEW_ALIGNMENT__
-  return __align > __STDCPP_DEFAULT_NEW_ALIGNMENT__;
+#define _LIBCPP_IS_OVERALIGNED_FOR_NEW(__align) __align > __STDCPP_DEFAULT_NEW_ALIGNMENT__
 #else
-  return __align > alignment_of::value;
+#define _LIBCPP_ISOVERALIGNED_FOR_NEW(__align) __align > _VSTD::alignment_of<_VSTD::max_align_t>::value
 #endif
-}
 
-inline _LIBCPP_INLINE_VISIBILITY void *__libcpp_allocate(size_t __size, size_t __align) {
+inline _LIBCPP_INLINE_VISIBILITY void *__libcpp_allocate(size_t __size, size_t __align)
+#if defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION)
+_LIBCPP_DIAGNOSE_WARNING(_LIBCPP_IS_OVERALIGNED_FOR_NEW(__align),
+  "over-aligned allocation using 'operator new' is not supported")
+#endif
+{
 #ifndef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
-  if (__is_overaligned_for_new(__align)) {
+  if (_LIBCPP_IS_OVERALIGNED_FOR_NEW(__align)) {
 const align_val_t __align_val = static_cast(__align);
 # ifdef _LIBCPP_HAS_NO_BUILTIN_ALIGNED_OPERATOR_NEW_DELETE
 return ::operator new(__size, __align_val);
@@ -262,7 +265,7 @@
 
 inline _LIBCPP_INLINE_VISIBILITY void __libcpp_deallocate(void* __ptr, size_t __align) {
 #ifndef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
-  if (__is_overaligned_for_new(__align)) {
+  if (_LIBCPP_IS_OVERALIGNED_FOR_NEW(__align)) {
 const align_val_t __align_val = static_cast(__align);
 # ifdef _LIBCPP_HAS_NO_BUILTIN_ALIGNED_OPERATOR_NEW_DELETE
 return ::operator delete(__ptr, __align_val);
Index: 

[PATCH] D45012: [Modules] Skip adding unused module maps to the dependency file

2018-03-28 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno created this revision.
bruno added a reviewer: rsmith.

Current generation of dependency files when modules is on take into
account all parsed module maps found while searching for a specific
module.

Add a new cc1 flag that allows changing that behavior: only add module
maps that actually answer for the modules being searched for.


Repository:
  rC Clang

https://reviews.llvm.org/D45012

Files:
  include/clang/Driver/CC1Options.td
  include/clang/Frontend/DependencyOutputOptions.h
  include/clang/Lex/ModuleMap.h
  lib/Frontend/CompilerInvocation.cpp
  lib/Frontend/DependencyFile.cpp
  lib/Lex/ModuleMap.cpp
  test/Modules/Inputs/dependency-skip-unused/module.modulemap
  test/Modules/Inputs/dependency-skip-unused/x/module.modulemap
  test/Modules/Inputs/dependency-skip-unused/y/module.modulemap
  test/Modules/dependency-skip-unused-modulemaps.m

Index: test/Modules/dependency-skip-unused-modulemaps.m
===
--- /dev/null
+++ test/Modules/dependency-skip-unused-modulemaps.m
@@ -0,0 +1,7 @@
+// RUN: rm -rf %t.cache %t.d
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fimplicit-module-maps -fmodules-cache-path=%t.cache -dependency-file %t.d -MT dependencies -I%S/Inputs/dependency-skip-unused/x -I%S/Inputs/dependency-skip-unused/y -I%S/Inputs/dependency-skip-unused -skip-unused-modulemap-deps %s
+// RUN: FileCheck %s < %t.d
+// CHECK-NOT: dependency-skip-unused{{.}}x{{.}}module.modulemap
+// CHECK-NOT: dependency-skip-unused{{.}}y{{.}}module.modulemap
+
+@import A;
Index: test/Modules/Inputs/dependency-skip-unused/y/module.modulemap
===
--- /dev/null
+++ test/Modules/Inputs/dependency-skip-unused/y/module.modulemap
@@ -0,0 +1 @@
+module Y {}
Index: test/Modules/Inputs/dependency-skip-unused/x/module.modulemap
===
--- /dev/null
+++ test/Modules/Inputs/dependency-skip-unused/x/module.modulemap
@@ -0,0 +1 @@
+module X {}
Index: test/Modules/Inputs/dependency-skip-unused/module.modulemap
===
--- /dev/null
+++ test/Modules/Inputs/dependency-skip-unused/module.modulemap
@@ -0,0 +1 @@
+module A {}
Index: lib/Lex/ModuleMap.cpp
===
--- lib/Lex/ModuleMap.cpp
+++ lib/Lex/ModuleMap.cpp
@@ -723,8 +723,17 @@
 
 Module *ModuleMap::findModule(StringRef Name) const {
   llvm::StringMap::const_iterator Known = Modules.find(Name);
-  if (Known != Modules.end())
-return Known->getValue();
+  if (Known != Modules.end()) {
+Module *M = Known->getValue();
+// Notify callbacks that we found a module map for the module.
+if (!M->DefinitionLoc.isInvalid())
+  for (const auto  : Callbacks)
+Cb->moduleMapFoundForModule(
+*getContainingModuleMapFile(M), M,
+SourceMgr.getFileCharacteristic(M->DefinitionLoc) ==
+SrcMgr::C_System_ModuleMap);
+return M;
+  }
 
   return nullptr;
 }
Index: lib/Frontend/DependencyFile.cpp
===
--- lib/Frontend/DependencyFile.cpp
+++ lib/Frontend/DependencyFile.cpp
@@ -161,6 +161,7 @@
   bool AddMissingHeaderDeps;
   bool SeenMissingHeader;
   bool IncludeModuleFiles;
+  bool SkipUnusedModuleMaps;
   DependencyOutputFormat OutputFormat;
 
 private:
@@ -176,6 +177,7 @@
   AddMissingHeaderDeps(Opts.AddMissingHeaderDeps),
   SeenMissingHeader(false),
   IncludeModuleFiles(Opts.IncludeModuleFiles),
+  SkipUnusedModuleMaps(Opts.SkipUnusedModuleMaps),
   OutputFormat(Opts.OutputFormat) {
 for (const auto  : Opts.ExtraDeps) {
   AddFilename(ExtraDep);
@@ -198,17 +200,26 @@
   void AddFilename(StringRef Filename);
   bool includeSystemHeaders() const { return IncludeSystemHeaders; }
   bool includeModuleFiles() const { return IncludeModuleFiles; }
+  bool skipUnusedModuleMaps() const { return SkipUnusedModuleMaps; }
 };
 
 class DFGMMCallback : public ModuleMapCallbacks {
   DFGImpl 
 public:
   DFGMMCallback(DFGImpl ) : Parent(Parent) {}
   void moduleMapFileRead(SourceLocation Loc, const FileEntry ,
  bool IsSystem) override {
+if (Parent.skipUnusedModuleMaps())
+  return;
 if (!IsSystem || Parent.includeSystemHeaders())
   Parent.AddFilename(Entry.getName());
   }
+  void moduleMapFoundForModule(const FileEntry , const Module *M,
+   bool IsSystem) override {
+if (Parent.skipUnusedModuleMaps() &&
+(!IsSystem || Parent.includeSystemHeaders()))
+  Parent.AddFilename(Entry.getName());
+  }
 };
 
 class DFGASTReaderListener : public ASTReaderListener {
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -1070,6 +1070,7 @@
   

[PATCH] D44536: Avoid segfault when destructor is not yet known

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

I think it's part of an effort to avoid creating implicit declarations for all 
the special members of every struct we parse from system headers.


Repository:
  rC Clang

https://reviews.llvm.org/D44536



___
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-28 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

BTW if you're interested in this stuff in clangd, there's some greener-field 
related stuff too:
Our goal is to be able to do project-wide fuzzy-find navigation and code 
completion with the global symbol index.
The index implementation in upstream clangd is naive at the moment (iterates 
over every symbol) but could be made efficient even with the fuzzy find 
functionality. (Inside google there's a service that does this, but we can't 
use that code upstream). It's an interesting problem and could be useful for 
cquery.

We should chat offline if this is at all interesting, even if you don't want to 
work on it - I'd like to hear more about cquery too :)


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


r328752 - [analyzer] [testing] Be less verbose by default in integration testing.

2018-03-28 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Wed Mar 28 18:23:54 2018
New Revision: 328752

URL: http://llvm.org/viewvc/llvm-project?rev=328752=rev
Log:
[analyzer] [testing] Be less verbose by default in integration testing.

Modified:
cfe/trunk/utils/analyzer/SATestBuild.py

Modified: cfe/trunk/utils/analyzer/SATestBuild.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/analyzer/SATestBuild.py?rev=328752=328751=328752=diff
==
--- cfe/trunk/utils/analyzer/SATestBuild.py (original)
+++ cfe/trunk/utils/analyzer/SATestBuild.py Wed Mar 28 18:23:54 2018
@@ -180,7 +180,7 @@ Checkers = ",".join([
 "nullability"
 ])
 
-Verbose = 1
+Verbose = 0
 
 #--
 # Test harness logic.


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


[libcxx] r328751 - Fix PR36914 - num_get::get(unsigned) incorrectly handles negative numbers.

2018-03-28 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Wed Mar 28 18:18:53 2018
New Revision: 328751

URL: http://llvm.org/viewvc/llvm-project?rev=328751=rev
Log:
Fix PR36914 - num_get::get(unsigned) incorrectly handles negative numbers.

This patch corrects num_get for unsigned types to support strings
with a leading `-` character. According to the standard the
number should be parsed as an unsigned integer and then
negated.

Added:

libcxx/trunk/test/std/localization/locale.categories/category.numeric/locale.num.get/facet.num.get.members/test_neg_one.pass.cpp
Modified:
libcxx/trunk/include/locale

libcxx/trunk/test/std/localization/locale.categories/category.numeric/locale.num.get/facet.num.get.members/test_min_max.pass.cpp

Modified: libcxx/trunk/include/locale
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/locale?rev=328751=328750=328751=diff
==
--- libcxx/trunk/include/locale (original)
+++ libcxx/trunk/include/locale Wed Mar 28 18:18:53 2018
@@ -768,10 +768,10 @@ __num_get_unsigned_integral(const char*
 {
 if (__a != __a_end)
 {
-if (*__a == '-')
-{
-__err = ios_base::failbit;
-return 0;
+const bool __negate = *__a == '-';
+if (__negate && ++__a == __a_end) {
+  __err = ios_base::failbit;
+  return 0;
 }
 typename remove_reference::type __save_errno = errno;
 errno = 0;
@@ -785,13 +785,14 @@ __num_get_unsigned_integral(const char*
 __err = ios_base::failbit;
 return 0;
 }
-else if (__current_errno == ERANGE ||
- numeric_limits<_Tp>::max() < __ll)
+else if (__current_errno == ERANGE || numeric_limits<_Tp>::max() < 
__ll)
 {
 __err = ios_base::failbit;
 return numeric_limits<_Tp>::max();
 }
-return static_cast<_Tp>(__ll);
+_Tp __res = static_cast<_Tp>(__ll);
+if (__negate) __res = -__res;
+return __res;
 }
 __err = ios_base::failbit;
 return 0;

Modified: 
libcxx/trunk/test/std/localization/locale.categories/category.numeric/locale.num.get/facet.num.get.members/test_min_max.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/localization/locale.categories/category.numeric/locale.num.get/facet.num.get.members/test_min_max.pass.cpp?rev=328751=328750=328751=diff
==
--- 
libcxx/trunk/test/std/localization/locale.categories/category.numeric/locale.num.get/facet.num.get.members/test_min_max.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/localization/locale.categories/category.numeric/locale.num.get/facet.num.get.members/test_min_max.pass.cpp
 Wed Mar 28 18:18:53 2018
@@ -15,9 +15,17 @@
 
 using namespace std;
 
+template 
+bool check_stream_failed(std::string const& val) {
+istringstream ss(val);
+T result;
+return !(ss >> result);
+}
+
 template
 void check_limits()
 {
+const bool is_unsigned = std::is_unsigned::value;
 T minv = numeric_limits::min();
 T maxv = numeric_limits::max();
 
@@ -36,17 +44,12 @@ void check_limits()
 assert(new_minv == minv);
 assert(new_maxv == maxv);
 
-if(mins == "0")
-mins = "-1";
-else
-mins[mins.size() - 1]++;
-
 maxs[maxs.size() - 1]++;
-
-istringstream maxoss2(maxs), minoss2(mins);
-
-assert(! (maxoss2 >> new_maxv));
-assert(! (minoss2 >> new_minv));
+assert(check_stream_failed(maxs));
+if (!is_unsigned) {
+mins[mins.size() - 1]++;
+assert(check_stream_failed(mins));
+}
 }
 
 int main(void)

Added: 
libcxx/trunk/test/std/localization/locale.categories/category.numeric/locale.num.get/facet.num.get.members/test_neg_one.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/localization/locale.categories/category.numeric/locale.num.get/facet.num.get.members/test_neg_one.pass.cpp?rev=328751=auto
==
--- 
libcxx/trunk/test/std/localization/locale.categories/category.numeric/locale.num.get/facet.num.get.members/test_neg_one.pass.cpp
 (added)
+++ 
libcxx/trunk/test/std/localization/locale.categories/category.numeric/locale.num.get/facet.num.get.members/test_neg_one.pass.cpp
 Wed Mar 28 18:18:53 2018
@@ -0,0 +1,159 @@
+//===--===//
+//
+// 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 num_get
+
+// iter_type get(iter_type in, iter_type end, ios_base&,
+//   ios_base::iostate& err, unsigned int& v) const;
+
+#include 

r328750 - [astmatchers] Move a matcher out of internal namespace: blind debugging of MSVC issues

2018-03-28 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Wed Mar 28 18:15:05 2018
New Revision: 328750

URL: http://llvm.org/viewvc/llvm-project?rev=328750=rev
Log:
[astmatchers] Move a matcher out of internal namespace: blind debugging of MSVC 
issues

Modified:
cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp

Modified: cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp?rev=328750=328749=328750=diff
==
--- cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp (original)
+++ cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp Wed Mar 28 18:15:05 2018
@@ -38,6 +38,16 @@
 
 namespace clang {
 namespace ast_matchers {
+
+AST_MATCHER_P(ObjCMessageExpr, hasAnySelectorMatcher, std::vector,
+  Matches) {
+  std::string SelString = Node.getSelector().getAsString();
+  for (const std::string  : Matches)
+if (S == SelString)
+  return true;
+  return false;
+}
+
 namespace internal {
 
 bool NotUnaryOperator(const ast_type_traits::DynTypedNode ,
@@ -328,15 +338,6 @@ Matcher hasAnyNameFunc(ArrayR
   return internal::Matcher(new internal::HasNameMatcher(Names));
 }
 
-AST_MATCHER_P(ObjCMessageExpr, hasAnySelectorMatcher, std::vector,
-  Matches) {
-  std::string SelString = Node.getSelector().getAsString();
-  for (const std::string  : Matches)
-if (S == SelString)
-  return true;
-  return false;
-}
-
 Matcher hasAnySelectorFunc(
 ArrayRef NameRefs) {
   return hasAnySelectorMatcher(vectorFromRefs(NameRefs));


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


r328690 - [PATCH] [RISCV] Verify the input value of -march=

2018-03-28 Thread Shiva Chen via cfe-commits
Author: shiva
Date: Wed Mar 28 01:29:50 2018
New Revision: 328690

URL: http://llvm.org/viewvc/llvm-project?rev=328690=rev
Log:
[PATCH] [RISCV] Verify the input value of -march=

Summary:
This patch doing more check and verify the -march= string and will issue
an error if it's a invalid combination.

Reviewers: asb, apazos

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

Patch by Kito Cheng.

Added:
cfe/trunk/test/Driver/riscv-arch.c
Modified:
cfe/trunk/lib/Driver/ToolChains/Arch/RISCV.cpp

Modified: cfe/trunk/lib/Driver/ToolChains/Arch/RISCV.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Arch/RISCV.cpp?rev=328690=328689=328690=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Arch/RISCV.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Arch/RISCV.cpp Wed Mar 28 01:29:50 2018
@@ -24,15 +24,66 @@ void riscv::getRISCVTargetFeatures(const
std::vector ) {
   if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) {
 StringRef MArch = A->getValue();
-// TODO: handle rv64
-std::pair MArchSplit = 
StringRef(MArch).split("rv32");
-if (!MArchSplit.second.size())
+if (!(MArch.startswith("rv32") || MArch.startswith("rv64")) ||
+(MArch.size() < 5)) {
+  // ISA string must begin with rv32 or rv64.
+  // TODO: Improve diagnostic message.
+  D.Diag(diag::err_drv_invalid_arch_name) << MArch;
   return;
+}
+
+// The canonical order specified in ISA manual.
+// Ref: Table 22.1 in RISC-V User-Level ISA V2.2
+StringRef StdExts = "mafdc";
+
+bool HasF = false, HasD = false;
+char Baseline = MArch[4];
+
+// TODO: Add 'e' once backend supported.
+switch (Baseline) {
+default:
+  // First letter should be 'e', 'i' or 'g'.
+  // TODO: Improve diagnostic message.
+  D.Diag(diag::err_drv_invalid_arch_name) << MArch;
+  return;
+case 'i':
+  break;
+case 'g':
+  // g = imafd
+  StdExts = StdExts.drop_front(4);
+  Features.push_back("+m");
+  Features.push_back("+a");
+  Features.push_back("+f");
+  Features.push_back("+d");
+  HasF = true;
+  HasD = true;
+  break;
+}
+
+auto StdExtsItr = StdExts.begin();
+// Skip rvxxx
+StringRef Exts = MArch.substr(5);
 
-for (char c : MArchSplit.second) {
+for (char c : Exts) {
+  // Check ISA extensions are specified in the canonical order.
+  while (StdExtsItr != StdExts.end() && *StdExtsItr != c)
+++StdExtsItr;
+
+  if (StdExtsItr == StdExts.end()) {
+// TODO: Improve diagnostic message.
+D.Diag(diag::err_drv_invalid_arch_name) << MArch;
+return;
+  }
+
+  // Move to next char to prevent repeated letter.
+  ++StdExtsItr;
+
+  // The order is OK, then push it into features.
   switch (c) {
-  case 'i':
-break;
+  default:
+// TODO: Improve diagnostic message.
+D.Diag(diag::err_drv_invalid_arch_name) << MArch;
+return;
   case 'm':
 Features.push_back("+m");
 break;
@@ -41,15 +92,25 @@ void riscv::getRISCVTargetFeatures(const
 break;
   case 'f':
 Features.push_back("+f");
+HasF = true;
 break;
   case 'd':
 Features.push_back("+d");
+HasD = true;
 break;
   case 'c':
 Features.push_back("+c");
 break;
   }
 }
+
+// Dependency check
+// It's illegal to specify the 'd' (double-precision floating point)
+// extension without also specifying the 'f' (single precision
+// floating-point) extension.
+// TODO: Improve diagnostic message.
+if (HasD && !HasF)
+  D.Diag(diag::err_drv_invalid_arch_name) << MArch;
   }
 }
 

Added: cfe/trunk/test/Driver/riscv-arch.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/riscv-arch.c?rev=328690=auto
==
--- cfe/trunk/test/Driver/riscv-arch.c (added)
+++ cfe/trunk/test/Driver/riscv-arch.c Wed Mar 28 01:29:50 2018
@@ -0,0 +1,89 @@
+// RUN: %clang -target riscv32-unknown-elf -march=rv32i -### %s -fsyntax-only 
2>&1 | FileCheck %s
+// RUN: %clang -target riscv32-unknown-elf -march=rv32im -### %s -fsyntax-only 
2>&1 | FileCheck %s
+// RUN: %clang -target riscv32-unknown-elf -march=rv32ima -### %s 
-fsyntax-only 2>&1 | FileCheck %s
+// RUN: %clang -target riscv32-unknown-elf -march=rv32imaf -### %s 
-fsyntax-only 2>&1 | FileCheck %s
+// RUN: %clang -target riscv32-unknown-elf -march=rv32imafd -### %s 
-fsyntax-only 2>&1 | FileCheck %s
+
+// RUN: %clang -target riscv32-unknown-elf -march=rv32ic -### %s -fsyntax-only 
2>&1 | FileCheck %s
+// RUN: %clang -target riscv32-unknown-elf -march=rv32imc -### %s 
-fsyntax-only 2>&1 | FileCheck %s
+// RUN: %clang -target riscv32-unknown-elf -march=rv32imac -### 

Re: [clang-tools-extra] r328500 - [clangd] Support incremental document syncing

2018-03-28 Thread Simon Marchi via cfe-commits
On 2018-03-27 01:47 PM, Reid Kleckner wrote:
> One of these new tests does not pass on Windows due to assumptions about 
> absolute path structure. The FileCheck output seems self-explanatory:
> 
> $ "FileCheck" "-strict-whitespace" 
> "C:\b\slave\clang-x86-windows-msvc2015\clang-x86-windows-msvc2015\llvm\tools\clang\tools\extra\test\clangd\textdocument-didchange-fail.test"
> # command stderr:
> C:\b\slave\clang-x86-windows-msvc2015\clang-x86-windows-msvc2015\llvm\tools\clang\tools\extra\test\clangd\textdocument-didchange-fail.test:22:20:
>  error: expected string not found in input
> # CHECK-NEXT:      "uri": "file:///clangd-test/main.cpp"
>                    ^
> :68:7: note: scanning from here
>       "uri": "file:///C%3a/clangd-test/main.cpp"
> 
> I committed a speculative fix for this in r328645, hopefully it does the job.

Makes sense.  Thanks for catching and fixing it!  I received some failure
notifications, but at first sight they seemed unrelated (maybe some of them
were).  I'll look more closely next time.

Simon
___
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-28 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Sorry for the delay, it took me a while to understand exactly what everything 
is doing.
If I understand right, there's actually no functional change (to match logic or 
scoring) being proposed here.
But some nice fixes indeed!

Most of the comments are readability nits. The existing code is pretty dense 
and hard to follow (my fault, thanks for picking through it!) so I might have 
misunderstood some things.




Comment at: clangd/FuzzyMatch.cpp:93
+  for (int I = PatN; I <= WordN; I++)
+Best = std::max(Best, Scores[PatN][I][Match].Score);
   if (isAwful(Best))

MaskRay wrote:
> sammccall wrote:
> > this looks like a behavior change - why?
> This is a behavior change. Instead of choosing between `Match/Miss` in the 
> last position, we enumerate the last matching position in `Word`.
> 
> This saves `if (P < PatN - 1) {` check in the main loop at the cost of a for 
> loop here (use sites of ending values)
Ah, I see - the case where we match only part of the word is handled up here 
now.
(I think you mean this is not a behavior change? The result is the same AFAICS)

That does make more sense, but it's pretty subtle.
Can you add a comment like
 `// The pattern doesn't have to match the whole word (but the whole pattern 
must match).`



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

MaskRay wrote:
> 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.
An important part of the contract of `match()` is that it returns a value in 
`[0,1]`.
We rely on this range to combine this with other scoring signals - we multiply 
this by a quality signal in code completion.
(Currently the quality signal is just derived from Sema, but the global index 
will provide the number of uses).

It would be possible to use a different squash function here, but I found 
max(kFloor,x) worked well for the examples I looked at - anything <= some floor 
value was "not really a useful match at all", and most of the variance below 
the floor seemed to be noise to me.
(Then I tuned the bonuses/penalties so the floor was at zero)



Comment at: clangd/FuzzyMatch.cpp:97
 return None;
-  if (!PatN)
-return 1;

I'd prefer to keep this - the empty pattern case is very common, and 
buildGraph() isn't trivially cheap in this case.



Comment at: clangd/FuzzyMatch.cpp:174
   int N) {
-  assert(N > 0);
+  if (!N)
+return;

Why this change? Previously this check was dynamic at the callsite in the 
constructor (which is cold), and omitted in the call to init() which is 
relatively hot.

Generally, here we expect the constructor to be called once per request and 
match() to be called thousands of times, so it's ok to do some wasteful 
initialization/work in the constructor, but we should avoid it on the match() 
path.



Comment at: clangd/FuzzyMatch.cpp:209
   std::copy(NewWord.begin(), NewWord.begin() + WordN, Word);
-  if (PatN == 0)
-return true;

similarly this one.
(ideally we wouldn't do the work above, it's just there to make dumpLast work I 
think)



Comment at: clangd/FuzzyMatch.cpp:230
 void FuzzyMatcher::buildGraph() {
+  Scores[0][0][Miss] = Scores[0][0][Match] = {0, Miss};
   for (int W = 0; W < WordN; ++W) {

why this change?
this has also been moved from the cheaper constructor to the more expensive 
per-match call. (also the diagonal assignment added in the next loop)

Also, shouldn't [0][0][Match] be AwfulScore?




Comment at: clangd/FuzzyMatch.cpp:325
+  int W = PatN;
+  for (int I = PatN; ++I <= WordN; )
+if (Scores[PatN][I][Match].Score > Scores[PatN][W][Match].Score)

nit: I -> P, move increment to the increment expression of the for loop?



Comment at: clangd/FuzzyMatch.cpp:340
+  A[WordN] = Miss;
+  for (int I = WordN, P = PatN; I > 0; I--) {
+if (I == W)

W is the right name in this file for a variable iterating over word indices, 
please don't change this.
The new variable above could be EndW or so?



Comment at: clangd/FuzzyMatch.cpp:340
+  A[WordN] = Miss;
+  for (int I = WordN, P = PatN; I > 0; I--) {
+if (I == W)

sammccall wrote:
> W is the right name in this file for a variable iterating over word indices, 
> please don't change this.
> The new variable above could be EndW or so?
As far as I can see, this loop is setting `A[W+1:...] = Miss` and populating 
`A[0...W]` with the exsting logic.
I think this would be clearer as two loops, currently there's a lot of 
conditionals around Last that obscure what's actually 

r328749 - [ast] Do not auto-initialize Objective-C for-loop variables in Objective-C++ in templatized code under ARC

2018-03-28 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Wed Mar 28 17:56:24 2018
New Revision: 328749

URL: http://llvm.org/viewvc/llvm-project?rev=328749=rev
Log:
[ast] Do not auto-initialize Objective-C for-loop variables in Objective-C++ in 
templatized code under ARC

The AST for the fragment

```
@interface I
@end

template 
void decode(I *p) {
  for (I *k in p) {}
}

void decode(I *p) {
  decode(p);
}
```

differs heavily when templatized and non-templatized:

```
|-FunctionTemplateDecl 0x7fbfe0863940  line:5:6 decode
| |-TemplateTypeParmDecl 0x7fbfe0863690  col:11 typename depth 0 
index 0
| |-FunctionDecl 0x7fbfe08638a0  line:5:6 decode 'void (I 
*__strong)'
| | |-ParmVarDecl 0x7fbfe08637a0  col:16 referenced p 'I 
*__strong'
| | `-CompoundStmt 0x7fbfe0863b88 
| |   `-ObjCForCollectionStmt 0x7fbfe0863b50 
| | |-DeclStmt 0x7fbfe0863a50 
| | | `-VarDecl 0x7fbfe08639f0  col:11 k 'I *const __strong'
| | |-ImplicitCastExpr 0x7fbfe0863a90  'I *' 
| | | `-DeclRefExpr 0x7fbfe0863a68  'I *__strong' lvalue ParmVar 
0x7fbfe08637a0 'p' 'I *__strong'
| | `-CompoundStmt 0x7fbfe0863b78 
| `-FunctionDecl 0x7fbfe0863f80  line:5:6 used decode 'void 
(I *__strong)'
|   |-TemplateArgument type 'int'
|   |-ParmVarDecl 0x7fbfe0863ef8  col:16 used p 'I *__strong'
|   `-CompoundStmt 0x7fbfe0890cf0 
| `-ObjCForCollectionStmt 0x7fbfe0890cc8 
|   |-DeclStmt 0x7fbfe0890c70 
|   | `-VarDecl 0x7fbfe0890c00  col:11 k 'I *__strong' 
callinit
|   |   `-ImplicitValueInitExpr 0x7fbfe0890c60 <> 'I 
*__strong'
|   |-ImplicitCastExpr 0x7fbfe0890cb0  'I *' 
|   | `-DeclRefExpr 0x7fbfe0890c88  'I *__strong' lvalue ParmVar 
0x7fbfe0863ef8 'p' 'I *__strong'
|   `-CompoundStmt 0x7fbfe0863b78 
```

Note how in the instantiated version ImplicitValueInitExpr unexpectedly appears.

While objects are auto-initialized under ARC, it does not make sense to
have an initializer for a for-loop variable, and it makes even less
sense to have such a different AST for instantiated and non-instantiated
version.

Digging deeper, I have found that there are two separate Sema* files for
dealing with templates and for dealing with non-templatized code.
In a non-templatized version, an initialization was performed only for
variables which are not loop variables for an Objective-C loop and not
variables for a C++ for-in loop:

```
  if (FRI && (Tok.is(tok::colon) || isTokIdentifier_in())) {
bool IsForRangeLoop = false;
if (TryConsumeToken(tok::colon, FRI->ColonLoc)) {
  IsForRangeLoop = true;
  if (Tok.is(tok::l_brace))
FRI->RangeExpr = ParseBraceInitializer();
  else
FRI->RangeExpr = ParseExpression();
}

Decl *ThisDecl = Actions.ActOnDeclarator(getCurScope(), D);
if (IsForRangeLoop)
  Actions.ActOnCXXForRangeDecl(ThisDecl);
Actions.FinalizeDeclaration(ThisDecl);
D.complete(ThisDecl);
return Actions.FinalizeDeclaratorGroup(getCurScope(), DS, ThisDecl);
  }

  SmallVector DeclsInGroup;
  Decl *FirstDecl = ParseDeclarationAfterDeclaratorAndAttributes(
  D, ParsedTemplateInfo(), FRI);
```

However the code in SemaTemplateInstantiateDecl was inconsistent,
guarding only against C++ for-in loops.

rdar://38391075

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

Added:
cfe/trunk/test/SemaObjC/foreachtemplatized.mm
Modified:
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/lib/Serialization/ASTWriterDecl.cpp

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=328749=328748=328749=diff
==
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Wed Mar 28 17:56:24 2018
@@ -937,6 +937,9 @@ protected:
 /// for-range statement.
 unsigned CXXForRangeDecl : 1;
 
+/// Whether this variable is the for-in loop declaration in Objective-C.
+unsigned ObjCForDecl : 1;
+
 /// Whether this variable is an ARC pseudo-__strong
 /// variable;  see isARCPseudoStrong() for details.
 unsigned ARCPseudoStrong : 1;
@@ -1334,6 +1337,16 @@ public:
 NonParmVarDeclBits.CXXForRangeDecl = FRD;
   }
 
+  /// \brief Determine whether this variable is a for-loop declaration for a
+  /// for-in statement in Objective-C.
+  bool isObjCForDecl() const {
+return NonParmVarDeclBits.ObjCForDecl;
+  }
+
+  void setObjCForDecl(bool FRD) {
+NonParmVarDeclBits.ObjCForDecl = FRD;
+  }
+
   /// \brief Determine whether this variable is an ARC pseudo-__strong
   /// variable.  A pseudo-__strong 

r328746 - [ASTMatchers] Extend hasParameter and hasAnyParameter matches to handle Objective-C methods

2018-03-28 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Wed Mar 28 17:51:11 2018
New Revision: 328746

URL: http://llvm.org/viewvc/llvm-project?rev=328746=rev
Log:
[ASTMatchers] Extend hasParameter and hasAnyParameter matches to handle 
Objective-C methods

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

Modified:
cfe/trunk/docs/LibASTMatchersReference.html
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/WorkList.h
cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
cfe/trunk/unittests/ASTMatchers/Dynamic/ParserTest.cpp

Modified: cfe/trunk/docs/LibASTMatchersReference.html
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=328746=328745=328746=diff
==
--- cfe/trunk/docs/LibASTMatchersReference.html (original)
+++ cfe/trunk/docs/LibASTMatchersReference.html Wed Mar 28 17:51:11 2018
@@ -5298,7 +5298,7 @@ matches 'int x = 0' in
 
 
 Matcherhttp://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html;>FunctionDeclhasAnyParameterMatcherhttp://clang.llvm.org/doxygen/classclang_1_1ParmVarDecl.html;>ParmVarDecl
 InnerMatcher
-Matches any 
parameter of a function declaration.
+Matches any 
parameter of a function or ObjC method declaration.
 
 Does not match the 'this' parameter of a method.
 
@@ -5308,6 +5308,13 @@ cxxMethodDecl(hasAnyParameter(hasName("y
   matches f(int x, int y, int z) {}
 with hasAnyParameter(...)
   matching int y
+
+For ObjectiveC, given
+  @interface I - (void) f:(int) y; @end
+
+the matcher objcMethodDecl(hasAnyParameter(hasName("y")))
+matches the declaration of method f with hasParameter
+matching y.
 
 
 
@@ -5347,7 +5354,8 @@ with compoundStmt()
 
 
 Matcherhttp://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html;>FunctionDeclhasParameterunsigned N, Matcherhttp://clang.llvm.org/doxygen/classclang_1_1ParmVarDecl.html;>ParmVarDecl
 InnerMatcher
-Matches the n'th 
parameter of a function declaration.
+Matches the n'th 
parameter of a function or an ObjC method
+declaration.
 
 Given
   class X { void f(int x) {} };
@@ -5355,6 +5363,13 @@ cxxMethodDecl(hasParameter(0, hasType(va
   matches f(int x) {}
 with hasParameter(...)
   matching int x
+
+For ObjectiveC, given
+  @interface I - (void) f:(int) y; @end
+
+the matcher objcMethodDecl(hasParameter(0, hasName("y")))
+matches the declaration of method f with hasParameter
+matching y.
 
 
 
@@ -5713,6 +5728,47 @@ matches the [webView ...] message invoca
 
 
 
+Matcherhttp://clang.llvm.org/doxygen/classclang_1_1ObjCMethodDecl.html;>ObjCMethodDeclhasAnyParameterMatcherhttp://clang.llvm.org/doxygen/classclang_1_1ParmVarDecl.html;>ParmVarDecl
 InnerMatcher
+Matches any 
parameter of a function or ObjC method declaration.
+
+Does not match the 'this' parameter of a method.
+
+Given
+  class X { void f(int x, int y, int z) {} };
+cxxMethodDecl(hasAnyParameter(hasName("y")))
+  matches f(int x, int y, int z) {}
+with hasAnyParameter(...)
+  matching int y
+
+For ObjectiveC, given
+  @interface I - (void) f:(int) y; @end
+
+the matcher objcMethodDecl(hasAnyParameter(hasName("y")))
+matches the declaration of method f with hasParameter
+matching y.
+
+
+
+Matcherhttp://clang.llvm.org/doxygen/classclang_1_1ObjCMethodDecl.html;>ObjCMethodDeclhasParameterunsigned N, Matcherhttp://clang.llvm.org/doxygen/classclang_1_1ParmVarDecl.html;>ParmVarDecl
 InnerMatcher
+Matches the n'th 
parameter of a function or an ObjC method
+declaration.
+
+Given
+  class X { void f(int x) {} };
+cxxMethodDecl(hasParameter(0, hasType(varDecl(
+  matches f(int x) {}
+with hasParameter(...)
+  matching int x
+
+For ObjectiveC, given
+  @interface I - (void) f:(int) y; @end
+
+the matcher objcMethodDecl(hasParameter(0, hasName("y")))
+matches the declaration of method f with hasParameter
+matching y.
+
+
+
 Matcherhttp://clang.llvm.org/doxygen/classclang_1_1OpaqueValueExpr.html;>OpaqueValueExprhasSourceExpressionMatcherhttp://clang.llvm.org/doxygen/classclang_1_1Expr.html;>Expr 
InnerMatcher
 Matches if the 
cast's source expression
 or opaque value's source expression matches the given matcher.

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=328746=328745=328746=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Wed Mar 28 17:51:11 2018
@@ -3466,7 +3466,8 @@ AST_MATCHER(CXXConstructExpr, requiresZe
   return Node.requiresZeroInitialization();
 }
 
-/// \brief Matches the n'th parameter of a function declaration.
+/// \brief Matches the n'th parameter of a function or an ObjC method
+/// declaration.
 ///
 /// Given
 /// \code
@@ -3476,12 +3477,22 @@ AST_MATCHER(CXXConstructExpr, requiresZe
 ///   matches f(int x) {}
 /// 

r328747 - [ASTMatchers] Introduce a matcher for matching any given Objective-C selector

2018-03-28 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Wed Mar 28 17:51:12 2018
New Revision: 328747

URL: http://llvm.org/viewvc/llvm-project?rev=328747=rev
Log:
[ASTMatchers] Introduce a matcher for matching any given Objective-C selector

Incudes a tiny related refactoring.

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

Modified:
cfe/trunk/docs/LibASTMatchersReference.html
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp
cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
cfe/trunk/unittests/ASTMatchers/Dynamic/ParserTest.cpp

Modified: cfe/trunk/docs/LibASTMatchersReference.html
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=328747=328746=328747=diff
==
--- cfe/trunk/docs/LibASTMatchersReference.html (original)
+++ cfe/trunk/docs/LibASTMatchersReference.html Wed Mar 28 17:51:12 2018
@@ -3958,6 +3958,17 @@ This matcher is only provided as a perfo
 
 
 
+Matcherinternal::Matcherhttp://clang.llvm.org/doxygen/classclang_1_1ObjCMessageExpr.html;>ObjCMessageExprhasAnySelectorStringRef, ..., 
StringRef
+Matches when at 
least one of the supplied string equals to the
+Selector.getAsString()
+
+ matcher = objCMessageExpr(hasSelector("methodA:", "methodB:"));
+ matches both of the expressions below:
+[myObj methodA:argA];
+[myObj methodB:argB];
+
+
+
 Matcherinternal::Matcherhttp://clang.llvm.org/doxygen/classclang_1_1Stmt.html;>StmtisInTemplateInstantiation
 Matches 
statements inside of a template instantiation.
 

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=328747=328746=328747=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Wed Mar 28 17:51:12 2018
@@ -2313,9 +2313,7 @@ inline internal::Matcher sizeOfExp
 ///   namespace a { namespace b { class X; } }
 /// \endcode
 inline internal::Matcher hasName(const std::string ) {
-  std::vector Names;
-  Names.push_back(Name);
-  return internal::Matcher(new internal::HasNameMatcher(Names));
+  return internal::Matcher(new internal::HasNameMatcher({Name}));
 }
 
 /// \brief Matches NamedDecl nodes that have any of the specified names.
@@ -2711,7 +2709,7 @@ AST_MATCHER_P(ObjCMessageExpr, hasReceiv
   const QualType TypeDecl = Node.getReceiverType();
   return InnerMatcher.matches(TypeDecl, Finder, Builder);
 }
-  
+
 /// \brief Matches when BaseName == Selector.getAsString()
 ///
 ///  matcher = objCMessageExpr(hasSelector("loadHTMLString:baseURL:"));
@@ -2725,7 +2723,21 @@ AST_MATCHER_P(ObjCMessageExpr, hasSelect
   return BaseName.compare(Sel.getAsString()) == 0;
 }
 
-  
+
+/// \brief Matches when at least one of the supplied string equals to the
+/// Selector.getAsString()
+///
+///  matcher = objCMessageExpr(hasSelector("methodA:", "methodB:"));
+///  matches both of the expressions below:
+/// \code
+/// [myObj methodA:argA];
+/// [myObj methodB:argB];
+/// \endcode
+extern const internal::VariadicFunction
+hasAnySelector;
+
 /// \brief Matches ObjC selectors whose name contains
 /// a substring matched by the given RegExp.
 ///  matcher = objCMessageExpr(matchesSelector("loadHTMLString\:baseURL?"));

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h?rev=328747=328746=328747=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h Wed Mar 28 
17:51:12 2018
@@ -731,6 +731,11 @@ class HasNameMatcher : public SingleNode
 ///HasNameMatcher.
 Matcher hasAnyNameFunc(ArrayRef NameRefs);
 
+/// \brief Trampoline function to use VariadicFunction<> to construct a
+///hasAnySelector matcher.
+Matcher hasAnySelectorFunc(
+ArrayRef NameRefs);
+
 /// \brief Matches declarations for QualType and CallExpr.
 ///
 /// Type argument DeclMatcherT is required by PolymorphicMatcherWithParam1 but

Modified: cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp?rev=328747=328746=328747=diff
==
--- cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp (original)
+++ 

[PATCH] D44854: [analyzer] Be more careful about C++17 copy elision.

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

Fix a comment in tests.


https://reviews.llvm.org/D44854

Files:
  lib/Analysis/CFG.cpp
  lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
  test/Analysis/cfg-rich-constructors.cpp
  test/Analysis/cxx17-mandatory-elision.cpp
  test/Analysis/temp-obj-dtors-cfg-output.cpp

Index: test/Analysis/temp-obj-dtors-cfg-output.cpp
===
--- test/Analysis/temp-obj-dtors-cfg-output.cpp
+++ test/Analysis/temp-obj-dtors-cfg-output.cpp
@@ -218,6 +218,9 @@
 // Don't try to figure out how to perform construction of the record here.
 const C () { return foo1(); } // no-crash
 C &() { return foo2(); } // no-crash
+const C (bool coin) {
+  return coin ? foo1() : foo1(); // no-crash
+}
 } // end namespace pass_references_through
 
 // CHECK:   [B1 (ENTRY)]
Index: test/Analysis/cxx17-mandatory-elision.cpp
===
--- /dev/null
+++ test/Analysis/cxx17-mandatory-elision.cpp
@@ -0,0 +1,58 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -std=c++11 -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -std=c++17 -verify %s
+
+void clang_analyzer_eval(bool);
+
+template  struct AddressVector {
+  T *buf[10];
+  int len;
+
+  AddressVector() : len(0) {}
+
+  void push(T *t) {
+buf[len] = t;
+++len;
+  }
+};
+
+class ClassWithoutDestructor {
+  AddressVector 
+
+public:
+  ClassWithoutDestructor(AddressVector ) : v(v) {
+v.push(this);
+  }
+
+  ClassWithoutDestructor(ClassWithoutDestructor &) : v(c.v) { v.push(this); }
+  ClassWithoutDestructor(const ClassWithoutDestructor ) : v(c.v) {
+v.push(this);
+  }
+};
+
+ClassWithoutDestructor make1(AddressVector ) {
+  return ClassWithoutDestructor(v);
+}
+ClassWithoutDestructor make2(AddressVector ) {
+  return make1(v);
+}
+ClassWithoutDestructor make3(AddressVector ) {
+  return make2(v);
+}
+
+void testMultipleReturns() {
+  AddressVector v;
+  ClassWithoutDestructor c = make3(v);
+
+#if __cplusplus >= 201703L
+  // FIXME: Both should be TRUE.
+  clang_analyzer_eval(v.len == 1); // expected-warning{{TRUE}}
+  clang_analyzer_eval(v.buf[0] == ); // expected-warning{{FALSE}}
+#else
+  clang_analyzer_eval(v.len == 5); // expected-warning{{TRUE}}
+  clang_analyzer_eval(v.buf[0] != v.buf[1]); // expected-warning{{TRUE}}
+  clang_analyzer_eval(v.buf[1] != v.buf[2]); // expected-warning{{TRUE}}
+  clang_analyzer_eval(v.buf[2] != v.buf[3]); // expected-warning{{TRUE}}
+  clang_analyzer_eval(v.buf[3] != v.buf[4]); // expected-warning{{TRUE}}
+  clang_analyzer_eval(v.buf[4] == ); // expected-warning{{TRUE}}
+#endif
+}
Index: test/Analysis/cfg-rich-constructors.cpp
===
--- test/Analysis/cfg-rich-constructors.cpp
+++ test/Analysis/cfg-rich-constructors.cpp
@@ -108,6 +108,9 @@
   C c = C::get();
 }
 
+// FIXME: Find construction contexts for both branches in C++17.
+// Note that once it gets detected, the test for the get() branch would not
+// fail, because FileCheck allows partial matches.
 // CHECK: void simpleVariableWithTernaryOperator(bool coin)
 // CHECK:[B1]
 // CXX11-NEXT: 1: [B4.2] ? [B2.5] : [B3.6]
@@ -122,15 +125,15 @@
 // CXX11-NEXT: 3: [B2.2]() (CXXRecordTypedCall, [B2.4])
 // CXX11-NEXT: 4: [B2.3]
 // CXX11-NEXT: 5: [B2.4] (CXXConstructExpr, [B1.2], class C)
-// CXX17-NEXT: 3: [B2.2]() (CXXRecordTypedCall, [B1.2])
+// CXX17-NEXT: 3: [B2.2]()
 // CHECK:[B3]
 // CHECK-NEXT: 1: 0
 // CHECK-NEXT: 2: [B3.1] (ImplicitCastExpr, NullToPointer, class C *)
 // CXX11-NEXT: 3: [B3.2] (CXXConstructExpr, [B3.5], class C)
 // CXX11-NEXT: 4: C([B3.3]) (CXXFunctionalCastExpr, ConstructorConversion, class C)
 // CXX11-NEXT: 5: [B3.4]
 // CXX11-NEXT: 6: [B3.5] (CXXConstructExpr, [B1.2], class C)
-// CXX17-NEXT: 3: [B3.2] (CXXConstructExpr, [B1.2], class C)
+// CXX17-NEXT: 3: [B3.2] (CXXConstructExpr, class C)
 // CXX17-NEXT: 4: C([B3.3]) (CXXFunctionalCastExpr, ConstructorConversion, class C)
 // CHECK:[B4]
 // CHECK-NEXT: 1: coin
Index: lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -203,13 +203,24 @@
   // 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;
-   

[PATCH] D44854: [analyzer] Be more careful about C++17 copy elision.

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

Conditional operators, like call-expressions in 
https://reviews.llvm.org/D44273, may also be glvalues of record type instead of 
simply being reference-typed.


https://reviews.llvm.org/D44854

Files:
  lib/Analysis/CFG.cpp
  lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
  test/Analysis/cfg-rich-constructors.cpp
  test/Analysis/cxx17-mandatory-elision.cpp
  test/Analysis/temp-obj-dtors-cfg-output.cpp

Index: test/Analysis/temp-obj-dtors-cfg-output.cpp
===
--- test/Analysis/temp-obj-dtors-cfg-output.cpp
+++ test/Analysis/temp-obj-dtors-cfg-output.cpp
@@ -218,6 +218,10 @@
 // Don't try to figure out how to perform construction of the record here.
 const C () { return foo1(); } // no-crash
 C &() { return foo2(); } // no-crash
+
+const C (bool coin) {
+  return coin ? foo1() : foo1();
+}
 } // end namespace pass_references_through
 
 // CHECK:   [B1 (ENTRY)]
Index: test/Analysis/cxx17-mandatory-elision.cpp
===
--- /dev/null
+++ test/Analysis/cxx17-mandatory-elision.cpp
@@ -0,0 +1,58 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -std=c++11 -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -std=c++17 -verify %s
+
+void clang_analyzer_eval(bool);
+
+template  struct AddressVector {
+  T *buf[10];
+  int len;
+
+  AddressVector() : len(0) {}
+
+  void push(T *t) {
+buf[len] = t;
+++len;
+  }
+};
+
+class ClassWithoutDestructor {
+  AddressVector 
+
+public:
+  ClassWithoutDestructor(AddressVector ) : v(v) {
+v.push(this);
+  }
+
+  ClassWithoutDestructor(ClassWithoutDestructor &) : v(c.v) { v.push(this); }
+  ClassWithoutDestructor(const ClassWithoutDestructor ) : v(c.v) {
+v.push(this);
+  }
+};
+
+ClassWithoutDestructor make1(AddressVector ) {
+  return ClassWithoutDestructor(v);
+}
+ClassWithoutDestructor make2(AddressVector ) {
+  return make1(v);
+}
+ClassWithoutDestructor make3(AddressVector ) {
+  return make2(v);
+}
+
+void testMultipleReturns() {
+  AddressVector v;
+  ClassWithoutDestructor c = make3(v);
+
+#if __cplusplus >= 201703L
+  // FIXME: Both should be TRUE.
+  clang_analyzer_eval(v.len == 1); // expected-warning{{TRUE}}
+  clang_analyzer_eval(v.buf[0] == ); // expected-warning{{FALSE}}
+#else
+  clang_analyzer_eval(v.len == 5); // expected-warning{{TRUE}}
+  clang_analyzer_eval(v.buf[0] != v.buf[1]); // expected-warning{{TRUE}}
+  clang_analyzer_eval(v.buf[1] != v.buf[2]); // expected-warning{{TRUE}}
+  clang_analyzer_eval(v.buf[2] != v.buf[3]); // expected-warning{{TRUE}}
+  clang_analyzer_eval(v.buf[3] != v.buf[4]); // expected-warning{{TRUE}}
+  clang_analyzer_eval(v.buf[4] == ); // expected-warning{{TRUE}}
+#endif
+}
Index: test/Analysis/cfg-rich-constructors.cpp
===
--- test/Analysis/cfg-rich-constructors.cpp
+++ test/Analysis/cfg-rich-constructors.cpp
@@ -108,6 +108,9 @@
   C c = C::get();
 }
 
+// FIXME: Find construction contexts for both branches in C++17.
+// Note that once it gets detected, the test for the get() branch would not
+// fail, because FileCheck allows partial matches.
 // CHECK: void simpleVariableWithTernaryOperator(bool coin)
 // CHECK:[B1]
 // CXX11-NEXT: 1: [B4.2] ? [B2.5] : [B3.6]
@@ -122,15 +125,15 @@
 // CXX11-NEXT: 3: [B2.2]() (CXXRecordTypedCall, [B2.4])
 // CXX11-NEXT: 4: [B2.3]
 // CXX11-NEXT: 5: [B2.4] (CXXConstructExpr, [B1.2], class C)
-// CXX17-NEXT: 3: [B2.2]() (CXXRecordTypedCall, [B1.2])
+// CXX17-NEXT: 3: [B2.2]()
 // CHECK:[B3]
 // CHECK-NEXT: 1: 0
 // CHECK-NEXT: 2: [B3.1] (ImplicitCastExpr, NullToPointer, class C *)
 // CXX11-NEXT: 3: [B3.2] (CXXConstructExpr, [B3.5], class C)
 // CXX11-NEXT: 4: C([B3.3]) (CXXFunctionalCastExpr, ConstructorConversion, class C)
 // CXX11-NEXT: 5: [B3.4]
 // CXX11-NEXT: 6: [B3.5] (CXXConstructExpr, [B1.2], class C)
-// CXX17-NEXT: 3: [B3.2] (CXXConstructExpr, [B1.2], class C)
+// CXX17-NEXT: 3: [B3.2] (CXXConstructExpr, class C)
 // CXX17-NEXT: 4: C([B3.3]) (CXXFunctionalCastExpr, ConstructorConversion, class C)
 // CHECK:[B4]
 // CHECK-NEXT: 1: coin
Index: lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -203,13 +203,24 @@
   // 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 

Re: r328282 - [analyzer] Trust _Nonnull annotations for system framework

2018-03-28 Thread Alexander Kornienko via cfe-commits
It looks like it was fixed, indeed. After an update I don't see an awful
number of crashes any more. Thanks!


On Mon, Mar 26, 2018 at 8:05 PM George Karpenkov 
wrote:

> Yeah, I’m pretty sure this was fixed on Friday with
> https://reviews.llvm.org/rC328406
>
> On Mar 26, 2018, at 10:54 AM, Alexander Kornienko 
> wrote:
>
> This checker crashes on almost each file in our codebase. No test case
> yet, but here's a stack trace:
> clang::Type::getTypeClass
> clang::ReferenceType::classof
> llvm::isa_impl::doit
> llvm::isa_impl_cl::doit
> llvm::isa_impl_wrap::doit
> llvm::isa_impl_wrap::doit
> llvm::isa
> clang::Type::getAs
> clang::ASTContext::getLValueReferenceType
> ::TrustNonnullChecker::checkPostCall
> clang::ento::check::PostCall::_checkCall
> clang::ento::CheckerFn::operator()
> ::CheckCallContext::runChecker
> expandGraphWithCheckers
> clang::ento::CheckerManager::runCheckersForCallEvent
> clang::ento::CheckerManager::runCheckersForPostCall
> clang::ento::ExprEngine::VisitCXXDestructor
> clang::ento::ExprEngine::ProcessTemporaryDtor
> clang::ento::ExprEngine::ProcessImplicitDtor
> clang::ento::ExprEngine::processCFGElement
> clang::ento::CoreEngine::dispatchWorkItem
> clang::ento::CoreEngine::ExecuteWorkList
> ::AnalysisConsumer::ActionExprEngine
> ::AnalysisConsumer::HandleCode
> ::AnalysisConsumer::HandleTranslationUnit
> clang::MultiplexConsumer::HandleTranslationUnit
> clang::ParseAST
> clang::FrontendAction::Execute
> clang::CompilerInstance::ExecuteAction
> clang::tooling::FrontendActionFactory::runInvocation
> clang::tooling::ToolInvocation::runInvocation
> clang::tooling::ToolInvocation::run
>
> Could you fix or revert the patch?
>
>
> On Fri, Mar 23, 2018 at 1:18 AM George Karpenkov via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: george.karpenkov
>> Date: Thu Mar 22 17:16:03 2018
>> New Revision: 328282
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=328282=rev
>> Log:
>> [analyzer] Trust _Nonnull annotations for system framework
>>
>> Changes the analyzer to believe that methods annotated with _Nonnull
>> from system frameworks indeed return non null objects.
>> Local methods with such annotation are still distrusted.
>> rdar://24291919
>>
>> Differential Revision: https://reviews.llvm.org/D44341
>>
>> Added:
>> cfe/trunk/lib/StaticAnalyzer/Checkers/TrustNonnullChecker.cpp
>> cfe/trunk/test/Analysis/trustnonnullchecker_test.m
>> Modified:
>> cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
>>
>> cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h
>> cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt
>> cfe/trunk/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
>> cfe/trunk/lib/StaticAnalyzer/Core/CheckerHelpers.cpp
>>
>> cfe/trunk/test/Analysis/Inputs/system-header-simulator-for-nullability.h
>>
>> Modified: cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td?rev=328282=328281=328282=diff
>>
>> ==
>> --- cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td (original)
>> +++ cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td Thu Mar
>> 22 17:16:03 2018
>> @@ -218,6 +218,14 @@ def NullableReturnedFromNonnullChecker :
>>
>>  } // end "nullability"
>>
>> +let ParentPackage = APIModeling in {
>> +
>> +def TrustNonnullChecker : Checker<"TrustNonnull">,
>> +  HelpText<"Trust that returns from framework methods annotated with
>> _Nonnull are not null">,
>> +  DescFile<"TrustNonnullChecker.cpp">;
>> +
>> +}
>> +
>>
>>  
>> //===--===//
>>  // Evaluate "builtin" functions.
>>
>>  
>> //===--===//
>>
>> Modified:
>> cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h?rev=328282=328281=328282=diff
>>
>> ==
>> ---
>> cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h
>> (original)
>> +++
>> cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h
>> Thu Mar 22 17:16:03 2018
>> @@ -21,6 +21,8 @@ namespace clang {
>>
>>  class Expr;
>>  class VarDecl;
>> +class QualType;
>> +class AttributedType;
>>
>>  namespace ento {
>>
>> @@ -42,6 +44,25 @@ template  bool containsStmt(con
>>  std::pair
>>  parseAssignment(const Stmt *S);
>>
>> +// Do not reorder! The getMostNullable method relies on the order.
>> +// Optimization: Most pointers expected to be unspecified. When a symbol
>> has an
>> +// unspecified or nonnull type non of the rules would indicate any
>> problem for
>> +// that symbol. 

[PATCH] D44295: [clang-tidy] Detects and fixes calls to grand-...parent virtual methods instead of calls to parent's virtual methods

2018-03-28 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh requested changes to this revision.
alexfh added a comment.
This revision now requires changes to proceed.

A few more nits.




Comment at: clang-tidy/bugprone/ParentVirtualCallCheck.cpp:114-117
+  auto ParentIter = Parents.begin();
+  std::string ParentsStr = "'" + getNameAsString(*ParentIter) + "'";
+  for (++ParentIter; ParentIter != Parents.end(); ++ParentIter)
+ParentsStr += " or '" + getNameAsString(*ParentIter) + "'";

I suggest using 1. range for loop; 2. std::string::append instead of 
operator+/operator+=. Not that performance is extremely important here, but 
it's also cleaner, IMO:

```
std::string ParentsStr = "'";
for (const CXXRecordDecl *Parent : Parents) {
  if (ParentsStr.size() > 1)
ParentsStr.append("' or '");
  ParentsStr.append(getNameAsString(Parent));
}
ParentsStr.append("'");
```



Comment at: clang-tidy/bugprone/ParentVirtualCallCheck.cpp:126
+   "in subclass%1; did you mean %2?")
+  << (MatchedDecl->getCalleeDecl()->getAsFunction())
+  << (Parents.size() > 1 ? "es" : "") << ParentsStr;

Please remove the parentheses.



Comment at: test/clang-tidy/bugprone-parent-virtual-call.cpp:32
+  int virt_2() override { return A::virt_1() + B::virt_1(); }
+  // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: qualified name 'A::virt_1' 
refers to a member overridden in subclass; did you mean 'B'? 
[bugprone-parent-virtual-call]
+  // CHECK-FIXES:  int virt_2() override { return B::virt_1() + B::virt_1(); }

Specifying each unique message completely once should be enough to detect typos 
in it (e.g. missing or extra spaces or quotes around placeholders). In other 
messages let's omit repeated static parts to make the test a bit more easier to 
read, e.g.:

  // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: qualified name 'A::virt_1' 
{{.*}}; did you mean 'B'?


https://reviews.llvm.org/D44295



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


[PATCH] D44536: Avoid segfault when destructor is not yet known

2018-03-28 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added a comment.

In https://reviews.llvm.org/D44536#1039428, @rjmccall wrote:

> Hmm.  Sema is lazy about actually creating implicit destructor declarations, 
> but it's supposed to only do it whenever the destructor is actually used for 
> something.


I'm looking at a similar problem where clang crashes in IRGen because the 
destructor of a class hasn't been added to the AST.

I'm not sure why Sema has to add the declaration lazily on demand rather than 
always adding it after the class definition has been parsed, for example. Could 
you explain the reason for this behavior? Does doing so break something or 
cause mis-compile?

It seems that DeclareImplicitDestructor should be called somewhere, but it's 
not clear to me where it should be called. Calling it at the end of 
Sema::CheckCompletedCXXClass fixes the crash I'm seeing, but that doesn't seem 
to be the right fix.


Repository:
  rC Clang

https://reviews.llvm.org/D44536



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


[PATCH] D45006: [Tooling] A CompilationDatabase wrapper that infers header commands.

2018-03-28 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 140160.
sammccall added a comment.

Handle the case where no points are awarded (e.g. system headers) and document 
awards better.


Repository:
  rC Clang

https://reviews.llvm.org/D45006

Files:
  include/clang/Tooling/CompilationDatabase.h
  lib/Tooling/CMakeLists.txt
  lib/Tooling/InterpolatingCompilationDatabase.cpp

Index: lib/Tooling/InterpolatingCompilationDatabase.cpp
===
--- /dev/null
+++ lib/Tooling/InterpolatingCompilationDatabase.cpp
@@ -0,0 +1,293 @@
+//===- InterpolatingCompilationDatabase.cpp -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// InterpolatingCompilationDatabase wraps another CompilationDatabase and
+// attempts to heuristically determine appropriate compile commands for files
+// that are not included, such as headers or newly created files.
+//
+// We "borrow" the compile command for the closest available file:
+//   - points are awarded if the filename matches (ignoring extension)
+//   - points are awarded if the directory structure matches
+//   - ties are broken by length of path prefix match
+//
+// The compile command is adjusted:
+//   - the input filename is replaced
+//   - if the extension differs, an "-x" flag is added to preserve the language
+//   - output file arguments are removed
+//
+// This class is only useful when wrapping databases that can enumerate all
+// their compile commands. If getAllFilenames() is empty, no inference occurs.
+//
+//===--===//
+
+#include "clang/Driver/Options.h"
+#include "clang/Driver/Types.h"
+#include "clang/Tooling/CompilationDatabase.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/Option/ArgList.h"
+#include "llvm/Option/OptTable.h"
+#include "llvm/Support/StringSaver.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+namespace clang {
+namespace tooling {
+namespace {
+using namespace llvm;
+
+size_t matchingPrefix(StringRef L, StringRef R) {
+  size_t Limit = std::min(L.size(), R.size());
+  for (size_t I = 0; I < Limit; ++I)
+if (L[I] != R[I])
+  return I;
+  return Limit;
+}
+
+// Like memcmp(), but traverses in reverse order. L and R are one-past-end.
+int rMemCompare(const char *L, const char *R, size_t N) {
+  for (const char *LStop = L - N; L > LStop;)
+if (*--L != *--R)
+  return *L < *R ? -1 : 1;
+  return 0;
+}
+
+// This is like L.compare(R), but maybe with the order of characters reversed.
+template 
+int compare(StringRef L, StringRef R) {
+  if (!Reverse)
+return L.compare(R);
+  // Traverse the common region backwards, first differing byte is decisive.
+  if (int Cmp = rMemCompare(L.end(), R.end(), std::min(L.size(), R.size(
+return Cmp;
+  // No byte differed, so the shorter string is smaller.
+  return L.size() == R.size() ? 0 : L.size() < R.size() ? -1 : 1;
+}
+
+// Returns 0 if S starts with prefix, else -1 for S < Prefix, 1 for S > Prefix.
+template  int prefixCompare(StringRef S, StringRef Prefix) {
+  if (S.size() >= Prefix.size())
+return Reverse ? rMemCompare(S.end(), Prefix.end(), Prefix.size())
+   : memcmp(S.begin(), Prefix.begin(), Prefix.size());
+  return compare(S, Prefix);
+}
+
+template  struct Less {
+  bool operator()(StringRef Key, std::pair Value) const {
+return Prefix ? prefixCompare(Value.first, Key) > 0
+  : compare(Key, Value.first) < 0;
+  }
+  bool operator()(std::pair Value, StringRef Key) const {
+return Prefix ? prefixCompare(Value.first, Key) < 0
+  : compare(Value.first, Key) < 0;
+  }
+};
+
+class InterpolatingCompilationDatabase : public CompilationDatabase {
+public:
+  InterpolatingCompilationDatabase(std::unique_ptr Inner)
+  : Inner(std::move(Inner)), Strings(Arena) {
+for (auto F : getAllFiles())
+  Paths.emplace_back(Strings.save(F), 0);
+finalizeIndex();
+  }
+
+  std::vector
+  getCompileCommands(StringRef FilePath) const override {
+auto Known = Inner->getCompileCommands(FilePath);
+if (Paths.empty() || !Known.empty())
+  return Known;
+return {inferCommand(FilePath)};
+  }
+
+  std::vector getAllFiles() const override {
+return Inner->getAllFiles();
+  }
+
+  std::vector getAllCompileCommands() const override {
+return Inner->getAllCompileCommands();
+  }
+
+private:
+  using SubstringAndIndex = std::pair;
+
+  // Sort the paths list, and populate other index fields from it.
+  // We identify files by the index into (sorted) Paths.
+  void finalizeIndex() {
+llvm::sort(Paths.begin(), Paths.end());
+for (size_t 

[PATCH] D45002: [test] Conservatively re-enable a FreeBSD/XRay test

2018-03-28 Thread Zhihao Yuan via Phabricator via cfe-commits
lichray added inline comments.



Comment at: test/Driver/XRay/xray-instrument-os.c:2
 // RUN: not %clang -o /dev/null -v -fxray-instrument -c %s
-// XFAIL: -linux-
+// XFAIL: -linux-, -freebsd
 // REQUIRES-ANY: amd64, x86_64, x86_64h, arm, aarch64, arm64

devnexen wrote:
> What output do you get when you use directly llvm-lit on this ?
Before:

```
clang -cc1 version 7.0.0 based upon LLVM 7.0.0svn default target 
x86_64-unknown-freebsd11.1
#include "..." search starts here:
#include <...> search starts here:
 [...]/llvm/build/lib/clang/7.0.0/include
 /usr/include
End of search list.

--


Testing Time: 0.12s

Failing Tests (1):
Clang :: Driver/XRay/xray-instrument-os.c

  Unexpected Failures: 1

```
After:
```
lit: [...]llvm/utils/lit/lit/llvm/config.py:334: note: using clang: 
[...]/llvm/build/bin/clang
Testing Time: 0.11s
  Expected Failures  : 1
```



Repository:
  rC Clang

https://reviews.llvm.org/D45002



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


[PATCH] D44931: [WebAssembly] Use Windows EH instructions for Wasm EH

2018-03-28 Thread Derek Schuff via Phabricator via cfe-commits
dschuff added inline comments.



Comment at: lib/CodeGen/CGException.cpp:1541
+  }
   llvm::CallInst *terminateCall =
+  CGM.getCXXABI().emitTerminateForUnexpectedException(*this, Exn);

aheejin wrote:
> dschuff wrote:
> > Should this be in an else block? No need to emit it after we emit the call 
> > to `__clang_call_terminate`
> I don't understand? The call emitted within the `if` block is not a call to 
> `__clang_call_terminate` but to `wasm.get.exception` intrinsic.
Oh you're right, I misread that, nevermind.


Repository:
  rC Clang

https://reviews.llvm.org/D44931



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


[PATCH] D45007: [clang] Use compile-command interpolation to provide commands for header files.

2018-03-28 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
Herald added subscribers: cfe-commits, ioeric, jkorous-apple, ilya-biryukov, 
klimek.

This uses the inferring wrapper introduced in https://reviews.llvm.org/D45006.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D45007

Files:
  clangd/GlobalCompilationDatabase.cpp


Index: clangd/GlobalCompilationDatabase.cpp
===
--- clangd/GlobalCompilationDatabase.cpp
+++ clangd/GlobalCompilationDatabase.cpp
@@ -86,6 +86,8 @@
 return CachedIt->second.get();
   std::string Error = "";
   auto CDB = tooling::CompilationDatabase::loadFromDirectory(Dir, Error);
+  if (CDB)
+CDB = tooling::inferMissingCompileCommands(std::move(CDB));
   auto Result = CDB.get();
   CompilationDatabases.insert(std::make_pair(Dir, std::move(CDB)));
   return Result;


Index: clangd/GlobalCompilationDatabase.cpp
===
--- clangd/GlobalCompilationDatabase.cpp
+++ clangd/GlobalCompilationDatabase.cpp
@@ -86,6 +86,8 @@
 return CachedIt->second.get();
   std::string Error = "";
   auto CDB = tooling::CompilationDatabase::loadFromDirectory(Dir, Error);
+  if (CDB)
+CDB = tooling::inferMissingCompileCommands(std::move(CDB));
   auto Result = CDB.get();
   CompilationDatabases.insert(std::make_pair(Dir, std::move(CDB)));
   return Result;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45004: [clang-format] New style option IndentWrappedObjCMethodNames

2018-03-28 Thread Stephane Moore via Phabricator via cfe-commits
stephanemoore added inline comments.



Comment at: include/clang/Format/Format.h:1154-1163
+  /// \brief The style of indenting long function or method names wrapped
+  /// onto the next line.
+  enum IndentWrappedMethodStyle {
+/// Automatically determine indenting style.
+IWM_Auto,
+/// Always indent wrapped method names.
+IWM_Always,

Do we explicitly want these to be generic with the intent to later reuse the 
enum for C++ method wrapping style?


Repository:
  rC Clang

https://reviews.llvm.org/D45004



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


[PATCH] D45006: [Tooling] A CompilationDatabase wrapper that infers header commands.

2018-03-28 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
Herald added subscribers: cfe-commits, mgorny, klimek.

The wrapper finds the closest matching compile command using filename heuristics
and makes minimal tweaks so it can be used with the header.

(This is WIP and needs tests)


Repository:
  rC Clang

https://reviews.llvm.org/D45006

Files:
  include/clang/Tooling/CompilationDatabase.h
  lib/Tooling/CMakeLists.txt
  lib/Tooling/InterpolatingCompilationDatabase.cpp

Index: lib/Tooling/InterpolatingCompilationDatabase.cpp
===
--- /dev/null
+++ lib/Tooling/InterpolatingCompilationDatabase.cpp
@@ -0,0 +1,271 @@
+//===- InterpolatingCompilationDatabase.cpp -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// InterpolatingCompilationDatabase wraps another CompilationDatabase and
+// attempts to heuristically determine appropriate compile commands for files
+// that are not included, such as headers or newly created files.
+//
+// We "borrow" the compile command for the closest available file:
+//   - points are awarded if the filename matches (ignoring extension)
+//   - points are awarded if the directory structure matches
+//   - ties are broken by length of path prefix match
+//
+// The compile command is adjusted:
+//   - the input filename is replaced
+//   - if the extension differs, an "-x" flag is added to preserve the language
+//   - output file arguments are removed
+//
+// This class is only useful when wrapping databases that can enumerate all
+// their compile commands. If getAllFilenames() is empty, no inference occurs.
+//
+//===--===//
+
+#include "clang/Driver/Options.h"
+#include "clang/Driver/Types.h"
+#include "clang/Tooling/CompilationDatabase.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/Option/ArgList.h"
+#include "llvm/Option/OptTable.h"
+#include "llvm/Support/StringSaver.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+namespace clang {
+namespace tooling {
+namespace {
+using namespace llvm;
+
+size_t matchingPrefix(StringRef L, StringRef R) {
+  size_t Limit = std::min(L.size(), R.size());
+  for (size_t I = 0; I < Limit; ++I)
+if (L[I] != R[I])
+  return I;
+  return Limit;
+}
+
+// Like memcmp(), but traverses in reverse order. L and R are one-past-end.
+int rMemCompare(const char *L, const char *R, size_t N) {
+  for (const char *LStop = L - N; L > LStop;)
+if (*--L != *--R)
+  return *L < *R ? -1 : 1;
+  return 0;
+}
+
+// This is like L.compare(R), but maybe with the order of characters reversed.
+template 
+int compare(StringRef L, StringRef R) {
+  if (!Reverse)
+return L.compare(R);
+  // Traverse the common region backwards, first differing byte is decisive.
+  if (int Cmp = rMemCompare(L.end(), R.end(), std::min(L.size(), R.size(
+return Cmp;
+  // No byte differed, so the shorter string is smaller.
+  return L.size() == R.size() ? 0 : L.size() < R.size() ? -1 : 1;
+}
+
+// Returns 0 if S starts with prefix, else -1 for S < Prefix, 1 for S > Prefix.
+template  int prefixCompare(StringRef S, StringRef Prefix) {
+  if (S.size() >= Prefix.size())
+return Reverse ? rMemCompare(S.end(), Prefix.end(), Prefix.size())
+   : memcmp(S.begin(), Prefix.begin(), Prefix.size());
+  return compare(S, Prefix);
+}
+
+template  struct Less {
+  bool operator()(StringRef Key, std::pair Value) const {
+return Prefix ? prefixCompare(Value.first, Key) > 0
+  : compare(Key, Value.first) < 0;
+  }
+  bool operator()(std::pair Value, StringRef Key) const {
+return Prefix ? prefixCompare(Value.first, Key) < 0
+  : compare(Value.first, Key) < 0;
+  }
+};
+
+class InterpolatingCompilationDatabase : public CompilationDatabase {
+public:
+  InterpolatingCompilationDatabase(std::unique_ptr Inner)
+  : Inner(std::move(Inner)), Strings(Arena) {
+for (auto F : getAllFiles())
+  Paths.emplace_back(Strings.save(F), 0);
+finalizeIndex();
+  }
+
+  std::vector
+  getCompileCommands(StringRef FilePath) const override {
+auto Known = Inner->getCompileCommands(FilePath);
+if (Paths.empty() || !Known.empty())
+  return Known;
+return {inferCommand(FilePath)};
+  }
+
+  std::vector getAllFiles() const override {
+return Inner->getAllFiles();
+  }
+
+  std::vector getAllCompileCommands() const override {
+return Inner->getAllCompileCommands();
+  }
+
+private:
+  using SubstringAndIndex = std::pair;
+
+  // Sort the paths list, and populate other index fields from it.
+  // We identify files by the index into (sorted) 

[PATCH] D44931: [WebAssembly] Use Windows EH instructions for Wasm EH

2018-03-28 Thread Heejin Ahn via Phabricator via cfe-commits
aheejin updated this revision to Diff 140156.
aheejin marked an inline comment as done.
aheejin added a comment.

- GNU_CPlusCPlus -> GNU_CPlusPlus


Repository:
  rC Clang

https://reviews.llvm.org/D44931

Files:
  lib/CodeGen/CGCXXABI.h
  lib/CodeGen/CGCleanup.cpp
  lib/CodeGen/CGCleanup.h
  lib/CodeGen/CGException.cpp
  lib/CodeGen/ItaniumCXXABI.cpp
  lib/CodeGen/MicrosoftCXXABI.cpp
  test/CodeGenCXX/wasm-eh.cpp

Index: test/CodeGenCXX/wasm-eh.cpp
===
--- /dev/null
+++ test/CodeGenCXX/wasm-eh.cpp
@@ -0,0 +1,346 @@
+// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -emit-llvm -o - -std=c++11 | FileCheck %s
+// RUN: %clang_cc1 %s -triple wasm64-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -emit-llvm -o - -std=c++11 | FileCheck %s
+
+void may_throw();
+void dont_throw() noexcept;
+
+struct Cleanup {
+  ~Cleanup() { dont_throw(); }
+};
+
+// Multiple catch clauses w/o catch-all
+void test0() {
+  try {
+may_throw();
+  } catch (int) {
+dont_throw();
+  } catch (double) {
+dont_throw();
+  }
+}
+
+// CHECK-LABEL: define void @_Z5test0v() {{.*}} personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
+
+// CHECK:   %[[INT_ALLOCA:.*]] = alloca i32
+// CHECK:   invoke void @_Z9may_throwv()
+// CHECK-NEXT:   to label %[[NORMAL_BB:.*]] unwind label %[[CATCHDISPATCH_BB:.*]]
+
+// CHECK: [[CATCHDISPATCH_BB]]:
+// CHECK-NEXT:   %[[CATCHSWITCH:.*]] = catchswitch within none [label %[[CATCHSTART_BB:.*]]] unwind to caller
+
+// CHECK: [[CATCHSTART_BB]]:
+// CHECK-NEXT:   %[[CATCHPAD:.*]] = catchpad within %[[CATCHSWITCH]] [i8* bitcast (i8** @_ZTIi to i8*), i8* bitcast (i8** @_ZTId to i8*)]
+// CHECK-NEXT:   %[[EXN:.*]] = call i8* @llvm.wasm.get.exception()
+// CHECK-NEXT:   store i8* %[[EXN]], i8** %exn.slot
+// CHECK-NEXT:   %[[SELECTOR:.*]] = call i32 @llvm.wasm.get.ehselector()
+// CHECK-NEXT:   %[[TYPEID:.*]] = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) #2
+// CHECK-NEXT:   %[[MATCHES:.*]] = icmp eq i32 %[[SELECTOR]], %[[TYPEID]]
+// CHECK-NEXT:   br i1 %[[MATCHES]], label %[[CATCH_INT_BB:.*]], label %[[CATCH_FALLTHROUGH_BB:.*]]
+
+// CHECK: [[CATCH_INT_BB]]:
+// CHECK-NEXT:   %[[EXN:.*]] = load i8*, i8** %exn.slot
+// CHECK-NEXT:   %[[ADDR:.*]] = call i8* @__cxa_begin_catch(i8* %[[EXN]]) {{.*}} [ "funclet"(token %[[CATCHPAD]]) ]
+// CHECK-NEXT:   %[[ADDR_CAST:.*]] = bitcast i8* %[[ADDR]] to i32*
+// CHECK-NEXT:   %[[INT_VAL:.*]] = load i32, i32* %[[ADDR_CAST]]
+// CHECK-NEXT:   store i32 %[[INT_VAL]], i32* %[[INT_ALLOCA]]
+// CHECK-NEXT:   call void @_Z10dont_throwv() {{.*}} [ "funclet"(token %[[CATCHPAD]]) ]
+// CHECK-NEXT:   call void @__cxa_end_catch() {{.*}} [ "funclet"(token %[[CATCHPAD]]) ]
+// CHECK-NEXT:   catchret from %[[CATCHPAD]] to label %[[CATCHRET_DEST_BB0:.*]]
+
+// CHECK: [[CATCHRET_DEST_BB0]]:
+// CHECK-NEXT:   br label %[[TRY_CONT_BB:.*]]
+
+// CHECK: [[CATCH_FALLTHROUGH_BB]]
+// CHECK-NEXT:   %[[TYPEID:.*]] = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTId to i8*)) #2
+// CHECK-NEXT:   %[[MATCHES:.*]] = icmp eq i32 %[[SELECTOR]], %[[TYPEID]]
+// CHECK-NEXT:   br i1 %[[MATCHES]], label %[[CATCH_FLOAT_BB:.*]], label %[[RETHROW_BB:.*]]
+
+// CHECK: [[CATCH_FLOAT_BB]]:
+// CHECK:   catchret from %[[CATCHPAD]] to label %[[CATCHRET_DEST_BB1:.*]]
+
+// CHECK: [[CATCHRET_DEST_BB1]]:
+// CHECK-NEXT:   br label %[[TRY_CONT_BB]]
+
+// CHECK: [[RETHROW_BB]]:
+// CHECK-NEXT:   call void @__cxa_rethrow() {{.*}} [ "funclet"(token %[[CATCHPAD]]) ]
+// CHECK-NEXT:   unreachable
+
+
+// Single catch-all
+void test1() {
+  try {
+may_throw();
+  } catch (...) {
+dont_throw();
+  }
+}
+
+// CATCH-LABEL: @_Z5test1v()
+
+// CHECK:   %[[CATCHSWITCH:.*]] = catchswitch within none [label %[[CATCHSTART_BB:.*]]] unwind to caller
+
+// CHECK: [[CATCHSTART_BB]]:
+// CHECK-NEXT:   %[[CATCHPAD:.*]] = catchpad within %[[CATCHSWITCH]] [i8* null]
+// CHECK:   br label %[[CATCH_ALL_BB:.*]]
+
+// CHECK: [[CATCH_ALL_BB]]:
+// CHECK:   catchret from %[[CATCHPAD]] to label
+
+
+// Multiple catch clauses w/ catch-all
+void test2() {
+  try {
+may_throw();
+  } catch (int) {
+dont_throw();
+  } catch (...) {
+dont_throw();
+  }
+}
+
+// CHECK-LABEL: @_Z5test2v()
+
+// CHECK:   %[[CATCHSWITCH:.*]] = catchswitch within none [label %[[CATCHSTART_BB:.*]]] unwind to caller
+
+// CHECK: [[CATCHSTART_BB]]:
+// CHECK-NEXT:   %[[CATCHPAD:.*]] = catchpad within %[[CATCHSWITCH]] [i8* bitcast (i8** @_ZTIi to i8*), i8* null]
+// CHECK:   br i1 %{{.*}}, label %[[CATCH_INT_BB:.*]], label %[[CATCH_ALL_BB:.*]]
+
+// CHECK: [[CATCH_INT_BB]]:
+// CHECK:   catchret from %[[CATCHPAD]] to label
+
+// CHECK: [[CATCH_ALL_BB]]:
+// CHECK:   catchret from %[[CATCHPAD]] to label
+
+
+// Cleanup
+void test3() {
+  Cleanup c;
+  may_throw();
+}
+
+// CHECK-LABEL: @_Z5test3v()
+
+// CHECK:   invoke void @_Z9may_throwv()
+// CHECK-NEXT:   to label {{.*}} 

[PATCH] D44931: [WebAssembly] Use Windows EH instructions for Wasm EH

2018-03-28 Thread Heejin Ahn via Phabricator via cfe-commits
aheejin added inline comments.



Comment at: lib/CodeGen/CGException.cpp:1541
+  }
   llvm::CallInst *terminateCall =
+  CGM.getCXXABI().emitTerminateForUnexpectedException(*this, Exn);

dschuff wrote:
> Should this be in an else block? No need to emit it after we emit the call to 
> `__clang_call_terminate`
I don't understand? The call emitted within the `if` block is not a call to 
`__clang_call_terminate` but to `wasm.get.exception` intrinsic.


Repository:
  rC Clang

https://reviews.llvm.org/D44931



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


[PATCH] D45004: [clang-format] New style option IndentWrappedObjCMethodNames

2018-03-28 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton added a comment.

> What do you think of the name IndentWrappedObjCMethodSignatures as an 
> alternative to IndentWrappedObjCMethodNames? In Objective-C the method name 
> might be considered the selector whereas I believe that this option pertains 
> to formatting of the method signature?

This is a good suggestion, but since this is a specialization of 
`IndentWrappedFunctionNames`, I figured keeping the name of the new option 
similar to that would be best.


Repository:
  rC Clang

https://reviews.llvm.org/D45004



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


[PATCH] D45004: [clang-format] New style option IndentWrappedObjCMethodNames

2018-03-28 Thread Stephane Moore via Phabricator via cfe-commits
stephanemoore added a comment.

What do you think of the name `IndentWrappedObjCMethodSignatures` as an 
alternative to `IndentWrappedObjCMethodNames`? In Objective-C the method name 
might be considered the selector whereas I believe that this option pertains to 
formatting of the method signature?


Repository:
  rC Clang

https://reviews.llvm.org/D45004



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


[PATCH] D45004: [clang-format] New style option IndentWrappedObjCMethodNames

2018-03-28 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton updated this revision to Diff 140155.
benhamilton added a comment.

Fix typo


Repository:
  rC Clang

https://reviews.llvm.org/D45004

Files:
  include/clang/Format/Format.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/Format.cpp
  unittests/Format/FormatTestObjC.cpp

Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -539,6 +539,36 @@
":(int)a\n"
" aaa:(int)a;\n");
 
+  Style.IndentWrappedObjCMethodNames = FormatStyle::IWM_Always;
+  verifyFormat("- (a)\n"
+   ";\n");
+  verifyFormat("- (a)\n"
+   ":(int)a;\n");
+  verifyFormat("- (a)\n"
+   ":(int)a\n"
+   ":(int)a;\n");
+  verifyFormat("- (a)\n"
+   " aaa:(int)a\n"
+   ":(int)a;\n");
+  verifyFormat("- (a)\n"
+   ":(int)a\n"
+   " aaa:(int)a;\n");
+
+  Style.IndentWrappedObjCMethodNames = FormatStyle::IWM_Never;
+  verifyFormat("- (a)\n"
+   ";\n");
+  verifyFormat("- (a)\n"
+   ":(int)a;\n");
+  verifyFormat("- (a)\n"
+   ":(int)a\n"
+   ":(int)a;\n");
+  verifyFormat("- (a)\n"
+   " aaa:(int)a\n"
+   ":(int)a;\n");
+  verifyFormat("- (a)\n"
+   ":(int)a\n"
+   " aaa:(int)a;\n");
+
   // Continuation indent width should win over aligning colons if the function
   // name is long.
   Style = getGoogleStyle(FormatStyle::LK_ObjC);
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -243,6 +243,16 @@
   }
 };
 
+template <>
+struct ScalarEnumerationTraits {
+  static void enumeration(IO ,
+  FormatStyle::IndentWrappedMethodStyle ) {
+IO.enumCase(Value, "Auto", FormatStyle::IWM_Auto);
+IO.enumCase(Value, "Always", FormatStyle::IWM_Always);
+IO.enumCase(Value, "Never", FormatStyle::IWM_Never);
+  }
+};
+
 template <> struct MappingTraits {
   static void mapping(IO , FormatStyle ) {
 // When reading, read the language first, we need it for getPredefinedStyle.
@@ -378,6 +388,8 @@
 IO.mapOptional("IndentWidth", Style.IndentWidth);
 IO.mapOptional("IndentWrappedFunctionNames",
Style.IndentWrappedFunctionNames);
+IO.mapOptional("IndentWrappedObjCMethodNames",
+   Style.IndentWrappedObjCMethodNames);
 IO.mapOptional("JavaScriptQuotes", Style.JavaScriptQuotes);
 IO.mapOptional("JavaScriptWrapImports", Style.JavaScriptWrapImports);
 IO.mapOptional("KeepEmptyLinesAtTheStartOfBlocks",
@@ -645,6 +657,7 @@
   LLVMStyle.IndentCaseLabels = false;
   LLVMStyle.IndentPPDirectives = FormatStyle::PPDIS_None;
   LLVMStyle.IndentWrappedFunctionNames = false;
+  LLVMStyle.IndentWrappedObjCMethodNames = FormatStyle::IWM_Auto;
   LLVMStyle.IndentWidth = 2;
   LLVMStyle.JavaScriptQuotes = FormatStyle::JSQS_Leave;
   LLVMStyle.JavaScriptWrapImports = true;
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -26,6 +26,19 @@
 namespace clang {
 namespace format {
 
+// Returns true if a TT_SelectorName should be indented when wrapped,
+// false otherwise.
+static bool shouldIndentWrappedSelectorName(const FormatStyle ) {
+  // TT_SelectorName is used across multiple languages; we only want
+  // Style.IndentWrappedObjCMethodNames to apply to ObjC.
+  if (Style.Language == FormatStyle::LK_ObjC)
+return Style.IndentWrappedObjCMethodNames == FormatStyle::IWM_Always ||
+   (Style.IndentWrappedObjCMethodNames == FormatStyle::IWM_Auto &&
+Style.IndentWrappedFunctionNames);
+  else
+return Style.IndentWrappedFunctionNames;
+}
+
 // Returns the length of everything up to the first possible line break after
 // the ), ], } or > matching \c Tok.
 static unsigned getLengthToMatchingParen(const FormatToken ) {
@@ -698,7 +711,7 @@
 State.Stack.back().AlignColons = 

[PATCH] D44934: [analyzer] Improve the modeling of `memset()`.

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

> In addition, `memset` can bind anything to the region, so 
> `getBindingForDerivedDefaultValue()`'s logic needs some adjustment. **The 
> solution in this patch is certainly not correct.**

Yeah, i guess you meant here the thing that i was saying about concrete 
bindings. If we only limit ourselves to concrete bindings, it should work well.


Repository:
  rC Clang

https://reviews.llvm.org/D44934



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


[PATCH] D44934: [analyzer] Improve the modeling of `memset()`.

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

Why do you need separate code for null and non-null character? The function's 
semantics doesn't seem to care.

I'd rather consider the case of non-concrete character separately. Because 
wiping a region with a symbol is not something we currently support; a symbolic 
default binding over a region means a different thing and it'd be equivalent to 
invalidation, so for non-concrete character we don't have a better choice than 
to invalidate. For concrete non-zero character, on the contrary, a default 
binding would work just fine.

Could you explain why didn't a straightforward `bindLoc` over a base region 
wasn't doing the thing you wanted? I.e., why is new Store API function 
necessary?


Repository:
  rC Clang

https://reviews.llvm.org/D44934



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


[PATCH] D45002: [test] Conservatively re-enable a FreeBSD/XRay test

2018-03-28 Thread David CARLIER via Phabricator via cfe-commits
devnexen added inline comments.



Comment at: test/Driver/XRay/xray-instrument-os.c:2
 // RUN: not %clang -o /dev/null -v -fxray-instrument -c %s
-// XFAIL: -linux-
+// XFAIL: -linux-, -freebsd
 // REQUIRES-ANY: amd64, x86_64, x86_64h, arm, aarch64, arm64

What output do you get when you use directly llvm-lit on this ?


Repository:
  rC Clang

https://reviews.llvm.org/D45002



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


[PATCH] D44931: [WebAssembly] Use Windows EH instructions for Wasm EH

2018-03-28 Thread Derek Schuff via Phabricator via cfe-commits
dschuff added a comment.

Otherwise it looks good to me, although @majnemer would know more about the 
subtleties of what IR actually gets generated.




Comment at: lib/CodeGen/CGCleanup.h:630
   static const EHPersonality MSVC_CxxFrameHandler3;
+  static const EHPersonality GNU_Wasm_CPlusCPlus;
 

aheejin wrote:
> dschuff wrote:
> > We might consider having 2 personalities: one for use with builtin 
> > exceptions, and other for emulated exceptions? I'm imagining that with this 
> > style of IR we might be able to do emulated exceptions better than we have 
> > for emscripten today. We don't have to think about that now, but maybe the 
> > name of the personality might reflect it: e.g. `GNU_Wasm_CPlusPlus_Native` 
> > (or builtin) vs `GNU_Wasm_CPlusPlus_Emulated` (or external).
> (We talked in person :) ) I'll think about it. But I guess we can change the 
> name once we start implementing that feature?
Sounds good. BTW this should actually be `GNU_Wasm_CPlusPlus` instead of 
`GNU_Wasm_CPlusCPlus`



Comment at: lib/CodeGen/CGException.cpp:1534
+  // In case of wasm personality, we need to pass the exception value to
+  // __clang_call_terminate function.
+  if (getLangOpts().CPlusPlus &&

aheejin wrote:
> dschuff wrote:
> > Why?
> Not strictly necessarily, because we can modify libcxxabi to our liking. I 
> was trying to keep the same behavior as Itanium-style libcxxabi. The 
> `__clang_call_terminate` function that's called when an EH cleanup throws is 
> as follows:
> ```
> ; Function Attrs: noinline noreturn nounwind  
>
> define linkonce_odr hidden void @__clang_call_terminate(i8*) #6 comdat {  
>
>   %2 = call i8* @__cxa_begin_catch(i8* %0) #2 
>
>   call void @_ZSt9terminatev() #8 
>
>   unreachable 
>
> }   
> ```
> 
> So it calls `__cxa_begin_catch` on the exception value before calling 
> `std::terminate`. We can change this behavior for wasm if we want, and I 
> guess we need some proxy object in case of a foreign exception, but anyway I 
> was trying to keep the behavior the same unless there's any reason not to.
Oh I see, we are deviating from MSVC behavior to be more like itanium here. 
Makes sense.



Comment at: lib/CodeGen/CGException.cpp:1541
+  }
   llvm::CallInst *terminateCall =
+  CGM.getCXXABI().emitTerminateForUnexpectedException(*this, Exn);

Should this be in an else block? No need to emit it after we emit the call to 
`__clang_call_terminate`


Repository:
  rC Clang

https://reviews.llvm.org/D44931



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


[PATCH] D45005: [clang-format] Set IndentWrappedObjCMethodNames to Always in google style

2018-03-28 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton created this revision.
benhamilton added reviewers: djasper, klimek, jolesiak.
Herald added a subscriber: cfe-commits.

Now that we can separately control ObjC method name wrapping
and non-ObjC function name wrapping, this diff sets
`IndentWrappedObjCMethodNames` to `Always` for the Google style.

Depends On https://reviews.llvm.org/D45004

Test Plan: Updated test which manually set
`IndentWrappedFunctionNames` to no longer set that, confirmed
tests which depended on indenting wrapped ObjC method names
still passed.


Repository:
  rC Clang

https://reviews.llvm.org/D45005

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


Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -573,7 +573,6 @@
   // name is long.
   Style = getGoogleStyle(FormatStyle::LK_ObjC);
   Style.ColumnLimit = 40;
-  Style.IndentWrappedFunctionNames = true;
   verifyFormat("- (void)shortf:(GTMFoo *)theFoo\n"
"dontAlignNamef:(NSRect)theRect {\n"
"}");
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -726,6 +726,7 @@
   {"^", 2}, {"^<.*\\.h>", 1}, {"^<.*", 2}, {".*", 3}};
   GoogleStyle.IncludeIsMainRegex = "([-_](test|unittest))?$";
   GoogleStyle.IndentCaseLabels = true;
+  GoogleStyle.IndentWrappedObjCMethodNames = FormatStyle::IWM_Always;
   GoogleStyle.KeepEmptyLinesAtTheStartOfBlocks = false;
   GoogleStyle.ObjCBinPackProtocolList = FormatStyle::BPS_Never;
   GoogleStyle.ObjCSpaceAfterProperty = false;


Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -573,7 +573,6 @@
   // name is long.
   Style = getGoogleStyle(FormatStyle::LK_ObjC);
   Style.ColumnLimit = 40;
-  Style.IndentWrappedFunctionNames = true;
   verifyFormat("- (void)shortf:(GTMFoo *)theFoo\n"
"dontAlignNamef:(NSRect)theRect {\n"
"}");
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -726,6 +726,7 @@
   {"^", 2}, {"^<.*\\.h>", 1}, {"^<.*", 2}, {".*", 3}};
   GoogleStyle.IncludeIsMainRegex = "([-_](test|unittest))?$";
   GoogleStyle.IndentCaseLabels = true;
+  GoogleStyle.IndentWrappedObjCMethodNames = FormatStyle::IWM_Always;
   GoogleStyle.KeepEmptyLinesAtTheStartOfBlocks = false;
   GoogleStyle.ObjCBinPackProtocolList = FormatStyle::BPS_Never;
   GoogleStyle.ObjCSpaceAfterProperty = false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45004: [clang-format] New style option IndentWrappedObjCMethodNames

2018-03-28 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton created this revision.
benhamilton added reviewers: djasper, jolesiak.
Herald added subscribers: cfe-commits, klimek.

Currently, indentation of Objective-C method names which are wrapped
onto the next line due to a long return type is controlled by the
style option `IndentWrappedFunctionNames`.

For the Google style, we'd like to indent Objective-C method names
when wrapped onto the next line, but *not* indent non-Objective-C
functions when wrapped onto the next line.

This diff adds a new style option, `IndentWrappedObjCMethodNames`,
with three options:

1. Auto: Keep current behavior (indent ObjC methods according to

`IndentWrappedFunctionNames`)

2. Always: Always indent wrapped ObjC methods

3. Never: Never indent wrapped ObjC methods

In a separate diff, I'll update the Google style to set
`IndentWrappedFunctionNames` to `Always`.

Test Plan: Tests updated. Ran tests with:

  % make -j12 FormatTests && ./tools/clang/unittests/Format/FormatTests


Repository:
  rC Clang

https://reviews.llvm.org/D45004

Files:
  include/clang/Format/Format.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/Format.cpp
  unittests/Format/FormatTestObjC.cpp

Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -539,6 +539,36 @@
":(int)a\n"
" aaa:(int)a;\n");
 
+  Style.IndentWrappedObjCMethodNames = FormatStyle::IWM_Always;
+  verifyFormat("- (a)\n"
+   ";\n");
+  verifyFormat("- (a)\n"
+   ":(int)a;\n");
+  verifyFormat("- (a)\n"
+   ":(int)a\n"
+   ":(int)a;\n");
+  verifyFormat("- (a)\n"
+   " aaa:(int)a\n"
+   ":(int)a;\n");
+  verifyFormat("- (a)\n"
+   ":(int)a\n"
+   " aaa:(int)a;\n");
+
+  Style.IndentWrappedObjCMethodNames = FormatStyle::IWM_Never;
+  verifyFormat("- (a)\n"
+   ";\n");
+  verifyFormat("- (a)\n"
+   ":(int)a;\n");
+  verifyFormat("- (a)\n"
+   ":(int)a\n"
+   ":(int)a;\n");
+  verifyFormat("- (a)\n"
+   " aaa:(int)a\n"
+   ":(int)a;\n");
+  verifyFormat("- (a)\n"
+   ":(int)a\n"
+   " aaa:(int)a;\n");
+
   // Continuation indent width should win over aligning colons if the function
   // name is long.
   Style = getGoogleStyle(FormatStyle::LK_ObjC);
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -243,6 +243,16 @@
   }
 };
 
+template <>
+struct ScalarEnumerationTraits {
+  static void enumeration(IO ,
+  FormatStyle::IndentWrappedMethodStyle ) {
+IO.enumCase(Value, "Auto", FormatStyle::IWM_Auto);
+IO.enumCase(Value, "Always", FormatStyle::IWM_Always);
+IO.enumCase(Value, "Never", FormatStyle::IWM_Never);
+  }
+};
+
 template <> struct MappingTraits {
   static void mapping(IO , FormatStyle ) {
 // When reading, read the language first, we need it for getPredefinedStyle.
@@ -378,6 +388,8 @@
 IO.mapOptional("IndentWidth", Style.IndentWidth);
 IO.mapOptional("IndentWrappedFunctionNames",
Style.IndentWrappedFunctionNames);
+IO.mapOptional("IndentWrappedObjCMethodNames",
+   Style.IndentWrappedObjCMethodNames);
 IO.mapOptional("JavaScriptQuotes", Style.JavaScriptQuotes);
 IO.mapOptional("JavaScriptWrapImports", Style.JavaScriptWrapImports);
 IO.mapOptional("KeepEmptyLinesAtTheStartOfBlocks",
@@ -645,6 +657,7 @@
   LLVMStyle.IndentCaseLabels = false;
   LLVMStyle.IndentPPDirectives = FormatStyle::PPDIS_None;
   LLVMStyle.IndentWrappedFunctionNames = false;
+  LLVMStyle.IndentWrappedObjCMethodNames = FormatStyle::IWM_Auto;
   LLVMStyle.IndentWidth = 2;
   LLVMStyle.JavaScriptQuotes = FormatStyle::JSQS_Leave;
   LLVMStyle.JavaScriptWrapImports = true;
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -26,6 

[PATCH] D44883: [Sema] Extend -Wself-assign and -Wself-assign-field to warn on overloaded self-assignment (classes)

2018-03-28 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/Sema/SemaExpr.cpp:12093
+break;
+  }
+

lebedev.ri wrote:
> rjmccall wrote:
> > lebedev.ri wrote:
> > > rjmccall wrote:
> > > > lebedev.ri wrote:
> > > > > rjmccall wrote:
> > > > > > I think doing this here can result in double-warning if the 
> > > > > > overload resolves to a builtin operator.  Now, it might not 
> > > > > > actually be possible for that to combine with the requirements for 
> > > > > > self-assignment, but still, I think the right place to diagnose 
> > > > > > this for C++ is the same place we call DiagnoseSelfMove in 
> > > > > > CreateOverloadedBinOp.
> > > > > > 
> > > > > > Can CheckIdentityFieldAssignment just be integrated with 
> > > > > > DiagnoseSelfAssignment so that callers don't need to do call both?
> > > > > > I think the right place to diagnose this for C++ is the same place 
> > > > > > we call DiagnoseSelfMove in CreateOverloadedBinOp.
> > > > > 
> > > > > ```
> > > > > switch (Opc) {
> > > > > case BO_Assign:
> > > > > case BO_DivAssign:
> > > > > case BO_SubAssign:
> > > > > case BO_AndAssign:
> > > > > case BO_OrAssign:
> > > > > case BO_XorAssign:
> > > > >   DiagnoseSelfAssignment(Args[0], Args[1], OpLoc);
> > > > >   CheckIdentityFieldAssignment(Args[0], Args[1], OpLoc);
> > > > >   break;
> > > > > default:
> > > > >   break;
> > > > > }
> > > > > 
> > > > > // Check for a self move.
> > > > > if (Op == OO_Equal)
> > > > >   DiagnoseSelfMove(Args[0], Args[1], OpLoc);
> > > > > ```
> > > > > 
> > > > > 
> > > > > ^ That does not appear to work. Pretty much all these tests start to 
> > > > > fail.
> > > > > 
> > > > Okay.  It's possible that my suggestion is wrong.  Can you explain more 
> > > > how they fail?
> > > Right, i should have been verbose :)
> > > There are no test changes as compared to the current diff.
> > > Here is the output of `$ ninja check-clang-sema check-clang-semacxx`
> > > {F5920055}
> > > It is also totally possible that i'm missing something obvious on my 
> > > end...
> > Oh, DiagnoseSelfAssignment disables itself during template instantiation, 
> > presumably because it's an easy syntactic check that will always warn on 
> > the parsed code and so doesn't need to warn again during instantiation.
> > 
> > In that case, I think the place you had the check is fine.
> Am i correctly reading that as "ok, keep it as it is, in 
> `BuildOverloadedBinOp()`" ?
Yes, I think that's the right place for it, given that it's basically designed 
to only fire during parsing.

We could also just move the check (in all cases) to ActOnBinOp, which is not 
called by template instantiation.


Repository:
  rC Clang

https://reviews.llvm.org/D44883



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


[PATCH] D44968: Generalize NRVO to cover C structs

2018-03-28 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

LGTM!


Repository:
  rC Clang

https://reviews.llvm.org/D44968



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


[PATCH] D45002: [test] Conservatively re-enable a FreeBSD/XRay test

2018-03-28 Thread Zhihao Yuan via Phabricator via cfe-commits
lichray created this revision.
lichray added reviewers: devnexen, krytarowski.
Herald added subscribers: dberris, emaste.

Fixing clang-test on FreeBSD as a follow-up of https://reviews.llvm.org/D43378 
to handle the revert happened in r325749.


Repository:
  rC Clang

https://reviews.llvm.org/D45002

Files:
  test/Driver/XRay/xray-instrument-os.c


Index: test/Driver/XRay/xray-instrument-os.c
===
--- test/Driver/XRay/xray-instrument-os.c
+++ test/Driver/XRay/xray-instrument-os.c
@@ -1,4 +1,4 @@
 // RUN: not %clang -o /dev/null -v -fxray-instrument -c %s
-// XFAIL: -linux-
+// XFAIL: -linux-, -freebsd
 // REQUIRES-ANY: amd64, x86_64, x86_64h, arm, aarch64, arm64
 typedef int a;


Index: test/Driver/XRay/xray-instrument-os.c
===
--- test/Driver/XRay/xray-instrument-os.c
+++ test/Driver/XRay/xray-instrument-os.c
@@ -1,4 +1,4 @@
 // RUN: not %clang -o /dev/null -v -fxray-instrument -c %s
-// XFAIL: -linux-
+// XFAIL: -linux-, -freebsd
 // REQUIRES-ANY: amd64, x86_64, x86_64h, arm, aarch64, arm64
 typedef int a;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44931: [WebAssembly] Use Windows EH instructions for Wasm EH

2018-03-28 Thread Heejin Ahn via Phabricator via cfe-commits
aheejin updated this revision to Diff 140144.
aheejin marked an inline comment as done.
aheejin added a comment.

- Rebase & Simplified the if condition


Repository:
  rC Clang

https://reviews.llvm.org/D44931

Files:
  lib/CodeGen/CGCXXABI.h
  lib/CodeGen/CGCleanup.cpp
  lib/CodeGen/CGCleanup.h
  lib/CodeGen/CGException.cpp
  lib/CodeGen/ItaniumCXXABI.cpp
  lib/CodeGen/MicrosoftCXXABI.cpp
  test/CodeGenCXX/wasm-eh.cpp

Index: test/CodeGenCXX/wasm-eh.cpp
===
--- /dev/null
+++ test/CodeGenCXX/wasm-eh.cpp
@@ -0,0 +1,346 @@
+// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -emit-llvm -o - -std=c++11 | FileCheck %s
+// RUN: %clang_cc1 %s -triple wasm64-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -emit-llvm -o - -std=c++11 | FileCheck %s
+
+void may_throw();
+void dont_throw() noexcept;
+
+struct Cleanup {
+  ~Cleanup() { dont_throw(); }
+};
+
+// Multiple catch clauses w/o catch-all
+void test0() {
+  try {
+may_throw();
+  } catch (int) {
+dont_throw();
+  } catch (double) {
+dont_throw();
+  }
+}
+
+// CHECK-LABEL: define void @_Z5test0v() {{.*}} personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
+
+// CHECK:   %[[INT_ALLOCA:.*]] = alloca i32
+// CHECK:   invoke void @_Z9may_throwv()
+// CHECK-NEXT:   to label %[[NORMAL_BB:.*]] unwind label %[[CATCHDISPATCH_BB:.*]]
+
+// CHECK: [[CATCHDISPATCH_BB]]:
+// CHECK-NEXT:   %[[CATCHSWITCH:.*]] = catchswitch within none [label %[[CATCHSTART_BB:.*]]] unwind to caller
+
+// CHECK: [[CATCHSTART_BB]]:
+// CHECK-NEXT:   %[[CATCHPAD:.*]] = catchpad within %[[CATCHSWITCH]] [i8* bitcast (i8** @_ZTIi to i8*), i8* bitcast (i8** @_ZTId to i8*)]
+// CHECK-NEXT:   %[[EXN:.*]] = call i8* @llvm.wasm.get.exception()
+// CHECK-NEXT:   store i8* %[[EXN]], i8** %exn.slot
+// CHECK-NEXT:   %[[SELECTOR:.*]] = call i32 @llvm.wasm.get.ehselector()
+// CHECK-NEXT:   %[[TYPEID:.*]] = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) #2
+// CHECK-NEXT:   %[[MATCHES:.*]] = icmp eq i32 %[[SELECTOR]], %[[TYPEID]]
+// CHECK-NEXT:   br i1 %[[MATCHES]], label %[[CATCH_INT_BB:.*]], label %[[CATCH_FALLTHROUGH_BB:.*]]
+
+// CHECK: [[CATCH_INT_BB]]:
+// CHECK-NEXT:   %[[EXN:.*]] = load i8*, i8** %exn.slot
+// CHECK-NEXT:   %[[ADDR:.*]] = call i8* @__cxa_begin_catch(i8* %[[EXN]]) {{.*}} [ "funclet"(token %[[CATCHPAD]]) ]
+// CHECK-NEXT:   %[[ADDR_CAST:.*]] = bitcast i8* %[[ADDR]] to i32*
+// CHECK-NEXT:   %[[INT_VAL:.*]] = load i32, i32* %[[ADDR_CAST]]
+// CHECK-NEXT:   store i32 %[[INT_VAL]], i32* %[[INT_ALLOCA]]
+// CHECK-NEXT:   call void @_Z10dont_throwv() {{.*}} [ "funclet"(token %[[CATCHPAD]]) ]
+// CHECK-NEXT:   call void @__cxa_end_catch() {{.*}} [ "funclet"(token %[[CATCHPAD]]) ]
+// CHECK-NEXT:   catchret from %[[CATCHPAD]] to label %[[CATCHRET_DEST_BB0:.*]]
+
+// CHECK: [[CATCHRET_DEST_BB0]]:
+// CHECK-NEXT:   br label %[[TRY_CONT_BB:.*]]
+
+// CHECK: [[CATCH_FALLTHROUGH_BB]]
+// CHECK-NEXT:   %[[TYPEID:.*]] = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTId to i8*)) #2
+// CHECK-NEXT:   %[[MATCHES:.*]] = icmp eq i32 %[[SELECTOR]], %[[TYPEID]]
+// CHECK-NEXT:   br i1 %[[MATCHES]], label %[[CATCH_FLOAT_BB:.*]], label %[[RETHROW_BB:.*]]
+
+// CHECK: [[CATCH_FLOAT_BB]]:
+// CHECK:   catchret from %[[CATCHPAD]] to label %[[CATCHRET_DEST_BB1:.*]]
+
+// CHECK: [[CATCHRET_DEST_BB1]]:
+// CHECK-NEXT:   br label %[[TRY_CONT_BB]]
+
+// CHECK: [[RETHROW_BB]]:
+// CHECK-NEXT:   call void @__cxa_rethrow() {{.*}} [ "funclet"(token %[[CATCHPAD]]) ]
+// CHECK-NEXT:   unreachable
+
+
+// Single catch-all
+void test1() {
+  try {
+may_throw();
+  } catch (...) {
+dont_throw();
+  }
+}
+
+// CATCH-LABEL: @_Z5test1v()
+
+// CHECK:   %[[CATCHSWITCH:.*]] = catchswitch within none [label %[[CATCHSTART_BB:.*]]] unwind to caller
+
+// CHECK: [[CATCHSTART_BB]]:
+// CHECK-NEXT:   %[[CATCHPAD:.*]] = catchpad within %[[CATCHSWITCH]] [i8* null]
+// CHECK:   br label %[[CATCH_ALL_BB:.*]]
+
+// CHECK: [[CATCH_ALL_BB]]:
+// CHECK:   catchret from %[[CATCHPAD]] to label
+
+
+// Multiple catch clauses w/ catch-all
+void test2() {
+  try {
+may_throw();
+  } catch (int) {
+dont_throw();
+  } catch (...) {
+dont_throw();
+  }
+}
+
+// CHECK-LABEL: @_Z5test2v()
+
+// CHECK:   %[[CATCHSWITCH:.*]] = catchswitch within none [label %[[CATCHSTART_BB:.*]]] unwind to caller
+
+// CHECK: [[CATCHSTART_BB]]:
+// CHECK-NEXT:   %[[CATCHPAD:.*]] = catchpad within %[[CATCHSWITCH]] [i8* bitcast (i8** @_ZTIi to i8*), i8* null]
+// CHECK:   br i1 %{{.*}}, label %[[CATCH_INT_BB:.*]], label %[[CATCH_ALL_BB:.*]]
+
+// CHECK: [[CATCH_INT_BB]]:
+// CHECK:   catchret from %[[CATCHPAD]] to label
+
+// CHECK: [[CATCH_ALL_BB]]:
+// CHECK:   catchret from %[[CATCHPAD]] to label
+
+
+// Cleanup
+void test3() {
+  Cleanup c;
+  may_throw();
+}
+
+// CHECK-LABEL: @_Z5test3v()
+
+// CHECK:   invoke void @_Z9may_throwv()
+// CHECK-NEXT:   to label 

[PATCH] D44931: [WebAssembly] Use Windows EH instructions for Wasm EH

2018-03-28 Thread Heejin Ahn via Phabricator via cfe-commits
aheejin added inline comments.



Comment at: lib/CodeGen/CGCXXABI.h:610
 
+struct CatchRetScope final : EHScopeStack::Cleanup {
+  llvm::CatchPadInst *CPI;

dschuff wrote:
> Should be `public`?
This code was moved from [[ 
https://github.com/llvm-mirror/clang/blob/c4bfd75d786a2a77c779cee6976534f37202ac21/lib/CodeGen/MicrosoftCXXABI.cpp#L865
 | here ]] in `lib/CodeGen/MicrosoftCXXABI.cpp`. There are dozens of classes 
inheriting from `EHScopeStack::Cleanup` and they all use private inheritance. 
Examples [[ 
https://github.com/llvm-mirror/clang/blob/c4bfd75d786a2a77c779cee6976534f37202ac21/lib/CodeGen/CGDecl.cpp#L449
 | 1 ]] [[ 
https://github.com/llvm-mirror/clang/blob/c4bfd75d786a2a77c779cee6976534f37202ac21/lib/CodeGen/CGDecl.cpp#L504
 | 2 ]] [[ 
https://github.com/llvm-mirror/clang/blob/master/lib/CodeGen/CGException.cpp#L347
 | 3 ]] [[ 
https://github.com/llvm-mirror/clang/blob/c4bfd75d786a2a77c779cee6976534f37202ac21/lib/CodeGen/ItaniumCXXABI.cpp#L3728
 | 4 ]] 

The [[ 
https://github.com/llvm-mirror/clang/blob/c4bfd75d786a2a77c779cee6976534f37202ac21/lib/CodeGen/EHScopeStack.h#L140-L147
 | comment ]] from `EHScopeStack::Cleanup` says all subclasses must be 
POD-like, which I guess is the reason, but I'm not very sure.



Comment at: lib/CodeGen/CGCleanup.h:630
   static const EHPersonality MSVC_CxxFrameHandler3;
+  static const EHPersonality GNU_Wasm_CPlusCPlus;
 

dschuff wrote:
> We might consider having 2 personalities: one for use with builtin 
> exceptions, and other for emulated exceptions? I'm imagining that with this 
> style of IR we might be able to do emulated exceptions better than we have 
> for emscripten today. We don't have to think about that now, but maybe the 
> name of the personality might reflect it: e.g. `GNU_Wasm_CPlusPlus_Native` 
> (or builtin) vs `GNU_Wasm_CPlusPlus_Emulated` (or external).
(We talked in person :) ) I'll think about it. But I guess we can change the 
name once we start implementing that feature?



Comment at: lib/CodeGen/CGException.cpp:1236
+  // them, we should unwind to the next EH enclosing scope. We generate a call
+  // to rethrow function here to do that.
+  if (EHPersonality::get(*this).isWasmPersonality() && !HasCatchAll) {

dschuff wrote:
> Why do we need to call `__cxa_rethrow` instead of just emitting a rethrow 
> instruction intrinsic to unwind?
Because we have to run the library code as well. As well as in other functions 
in libcxxabi, [[ 
https://github.com/llvm-mirror/libcxxabi/blob/565ba0415b6b17bbca46820a0fcfe4b6ab5abce2/src/cxa_exception.cpp#L571-L607
 | `__cxa_rethrow` ]] has some bookeeping code like incrementing the handler 
count or something. After it is re-caught by an enclosing scope, it is 
considered as a newly thrown exception and the enclosing scope is run functions 
like `__cxa_begin_catch` and `__cxa_end_catch`. So we also have to run 
`__cxa_rethrow` when rethrowing something to make sure everything is matched. 

The actual `rethrow` instruction will be added next to `__cxa_rethrow` in the 
backend, or can be embedded within `__cxa_rethrow` function later if we decide 
how to pass an exception value to a function. (which might be one reason why we 
want to keep the first-class exception thing)



Comment at: lib/CodeGen/CGException.cpp:1534
+  // In case of wasm personality, we need to pass the exception value to
+  // __clang_call_terminate function.
+  if (getLangOpts().CPlusPlus &&

dschuff wrote:
> Why?
Not strictly necessarily, because we can modify libcxxabi to our liking. I was 
trying to keep the same behavior as Itanium-style libcxxabi. The 
`__clang_call_terminate` function that's called when an EH cleanup throws is as 
follows:
```
; Function Attrs: noinline noreturn nounwind
 
define linkonce_odr hidden void @__clang_call_terminate(i8*) #6 comdat {
 
  %2 = call i8* @__cxa_begin_catch(i8* %0) #2   
 
  call void @_ZSt9terminatev() #8   
 
  unreachable   
 
}   
```

So it calls `__cxa_begin_catch` on the exception value before calling 
`std::terminate`. We can change this behavior for wasm if we want, and I guess 
we need some proxy object in case of a foreign exception, but anyway I was 
trying to keep the behavior the same unless there's any reason not to.



Comment at: test/CodeGenCXX/wasm-eh.cpp:33
+// CHECK-NEXT:   %[[CATCHPAD:.*]] = catchpad within %[[CATCHSWITCH]] [i8* 
bitcast (i8** @_ZTIi to i8*), i8* bitcast (i8** @_ZTId to i8*)]
+// CHECK-NEXT:   %[[EXN:.*]] = call i8* @llvm.wasm.get.exception()
+// CHECK-NEXT:   store i8* %[[EXN]], i8** %exn.slot

majnemer wrote:
> I'd expect a funclet bundle operand here..
Even if it cannot throw? Looks like even 

[PATCH] D44883: [Sema] Extend -Wself-assign and -Wself-assign-field to warn on overloaded self-assignment (classes)

2018-03-28 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

Will do stage2 testing next..




Comment at: lib/Sema/SemaExpr.cpp:12087
+  case BO_AndAssign:
+  case BO_OrAssign:
+DiagnoseSelfAssignment(S, LHS, RHS, OpLoc, /*IsBuiltin=*/false);

lebedev.ri wrote:
> rjmccall wrote:
> > Quuxplusone wrote:
> > > I understand why `x &= x` and `x |= x` are mathematically special for the 
> > > built-in types, but surely `x -= x` and `x ^= x` and `x /= x` are just as 
> > > likely to indicate programmer error. I would be happy if Clang either 
> > > took the philosophical stance "We will diagnose `x = x` but uniformly 
> > > //never// `x op= x`," or else took the pragmatic stance "We will diagnose 
> > > any `x op= x` or `x op x` that seems likely to be a programming bug." 
> > > This "middle way" of warning only for `&=` and `|=` is bothersome to me.
> > I think "we want to diagnose anything that seems likely to be a programming 
> > bug" is already our policy here.  It's inevitable that we'll overlook 
> > examples of that.  I agree that we should apply this warning to at least 
> > -=, ^=, and /=.
> Ok, will extend.
Would it make sense to also check `%=`?
It's a direct counterpart to `/=`, so i guess it would?



Comment at: lib/Sema/SemaExpr.cpp:12093
+break;
+  }
+

rjmccall wrote:
> lebedev.ri wrote:
> > rjmccall wrote:
> > > lebedev.ri wrote:
> > > > rjmccall wrote:
> > > > > I think doing this here can result in double-warning if the overload 
> > > > > resolves to a builtin operator.  Now, it might not actually be 
> > > > > possible for that to combine with the requirements for 
> > > > > self-assignment, but still, I think the right place to diagnose this 
> > > > > for C++ is the same place we call DiagnoseSelfMove in 
> > > > > CreateOverloadedBinOp.
> > > > > 
> > > > > Can CheckIdentityFieldAssignment just be integrated with 
> > > > > DiagnoseSelfAssignment so that callers don't need to do call both?
> > > > > I think the right place to diagnose this for C++ is the same place we 
> > > > > call DiagnoseSelfMove in CreateOverloadedBinOp.
> > > > 
> > > > ```
> > > > switch (Opc) {
> > > > case BO_Assign:
> > > > case BO_DivAssign:
> > > > case BO_SubAssign:
> > > > case BO_AndAssign:
> > > > case BO_OrAssign:
> > > > case BO_XorAssign:
> > > >   DiagnoseSelfAssignment(Args[0], Args[1], OpLoc);
> > > >   CheckIdentityFieldAssignment(Args[0], Args[1], OpLoc);
> > > >   break;
> > > > default:
> > > >   break;
> > > > }
> > > > 
> > > > // Check for a self move.
> > > > if (Op == OO_Equal)
> > > >   DiagnoseSelfMove(Args[0], Args[1], OpLoc);
> > > > ```
> > > > 
> > > > 
> > > > ^ That does not appear to work. Pretty much all these tests start to 
> > > > fail.
> > > > 
> > > Okay.  It's possible that my suggestion is wrong.  Can you explain more 
> > > how they fail?
> > Right, i should have been verbose :)
> > There are no test changes as compared to the current diff.
> > Here is the output of `$ ninja check-clang-sema check-clang-semacxx`
> > {F5920055}
> > It is also totally possible that i'm missing something obvious on my end...
> Oh, DiagnoseSelfAssignment disables itself during template instantiation, 
> presumably because it's an easy syntactic check that will always warn on the 
> parsed code and so doesn't need to warn again during instantiation.
> 
> In that case, I think the place you had the check is fine.
Am i correctly reading that as "ok, keep it as it is, in 
`BuildOverloadedBinOp()`" ?


Repository:
  rC Clang

https://reviews.llvm.org/D44883



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


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

2018-03-28 Thread Eugene Zelenko via cfe-commits
Author: eugenezelenko
Date: Wed Mar 28 15:09:09 2018
New Revision: 328735

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

Modified:
cfe/trunk/include/clang/Basic/AddressSpaces.h
cfe/trunk/include/clang/Basic/CommentOptions.h
cfe/trunk/include/clang/Basic/FileSystemStatCache.h
cfe/trunk/include/clang/Basic/Linkage.h
cfe/trunk/include/clang/Basic/ObjCRuntime.h
cfe/trunk/include/clang/Basic/Sanitizers.h
cfe/trunk/include/clang/Basic/VirtualFileSystem.h
cfe/trunk/lib/Basic/FileSystemStatCache.cpp
cfe/trunk/lib/Basic/ObjCRuntime.cpp
cfe/trunk/lib/Basic/Sanitizers.cpp
cfe/trunk/lib/Basic/VirtualFileSystem.cpp

Modified: cfe/trunk/include/clang/Basic/AddressSpaces.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/AddressSpaces.h?rev=328735=328734=328735=diff
==
--- cfe/trunk/include/clang/Basic/AddressSpaces.h (original)
+++ cfe/trunk/include/clang/Basic/AddressSpaces.h Wed Mar 28 15:09:09 2018
@@ -1,4 +1,4 @@
-//===--- AddressSpaces.h - Language-specific address spaces -*- C++ 
-*-===//
+//===- AddressSpaces.h - Language-specific address spaces ---*- C++ 
-*-===//
 //
 // The LLVM Compiler Infrastructure
 //
@@ -6,17 +6,17 @@
 // License. See LICENSE.TXT for details.
 //
 
//===--===//
-///
+//
 /// \file
 /// \brief Provides definitions for the various language-specific address
 /// spaces.
-///
+//
 
//===--===//
 
 #ifndef LLVM_CLANG_BASIC_ADDRESSSPACES_H
 #define LLVM_CLANG_BASIC_ADDRESSSPACES_H
 
-#include 
+#include 
 
 namespace clang {
 
@@ -51,7 +51,7 @@ enum class LangAS : unsigned {
 
 /// The type of a lookup table which maps from language-specific address spaces
 /// to target-specific ones.
-typedef unsigned LangASMap[(unsigned)LangAS::FirstTargetAddressSpace];
+using LangASMap = unsigned[(unsigned)LangAS::FirstTargetAddressSpace];
 
 /// \return whether \p AS is a target-specific address space rather than a
 /// clang AST address space
@@ -71,4 +71,4 @@ inline LangAS getLangASFromTargetAS(unsi
 
 } // namespace clang
 
-#endif
+#endif // LLVM_CLANG_BASIC_ADDRESSSPACES_H

Modified: cfe/trunk/include/clang/Basic/CommentOptions.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/CommentOptions.h?rev=328735=328734=328735=diff
==
--- cfe/trunk/include/clang/Basic/CommentOptions.h (original)
+++ cfe/trunk/include/clang/Basic/CommentOptions.h Wed Mar 28 15:09:09 2018
@@ -1,4 +1,4 @@
-//===--- CommentOptions.h - Options for parsing comments -*- C++ -*-===//
+//===- CommentOptions.h - Options for parsing comments --*- C++ 
-*-===//
 //
 // The LLVM Compiler Infrastructure
 //
@@ -6,10 +6,10 @@
 // License. See LICENSE.TXT for details.
 //
 
//===--===//
-///
+//
 /// \file
 /// \brief Defines the clang::CommentOptions interface.
-///
+//
 
//===--===//
 
 #ifndef LLVM_CLANG_BASIC_COMMENTOPTIONS_H
@@ -22,18 +22,18 @@ namespace clang {
 
 /// \brief Options for controlling comment parsing.
 struct CommentOptions {
-  typedef std::vector BlockCommandNamesTy;
+  using BlockCommandNamesTy = std::vector;
 
   /// \brief Command names to treat as block commands in comments.
   /// Should not include the leading backslash.
   BlockCommandNamesTy BlockCommandNames;
 
   /// \brief Treat ordinary comments as documentation comments.
-  bool ParseAllComments;
+  bool ParseAllComments = false;
 
-  CommentOptions() : ParseAllComments(false) { }
+  CommentOptions() = default;
 };
 
-}  // end namespace clang
+} // namespace clang
 
-#endif
+#endif // LLVM_CLANG_BASIC_COMMENTOPTIONS_H

Modified: cfe/trunk/include/clang/Basic/FileSystemStatCache.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/FileSystemStatCache.h?rev=328735=328734=328735=diff
==
--- cfe/trunk/include/clang/Basic/FileSystemStatCache.h (original)
+++ cfe/trunk/include/clang/Basic/FileSystemStatCache.h Wed Mar 28 15:09:09 2018
@@ -1,4 +1,4 @@
-//===--- FileSystemStatCache.h - Caching for 'stat' calls ---*- C++ 
-*-===//
+//===- FileSystemStatCache.h - Caching for 'stat' calls -*- C++ 
-*-===//
 //
 // The LLVM Compiler Infrastructure
 //
@@ -6,10 +6,10 @@
 // License. See LICENSE.TXT for details.
 //
 
//===--===//
-///
+//
 /// \file
 /// \brief Defines the FileSystemStatCache 

[PATCH] D44883: [Sema] Extend -Wself-assign and -Wself-assign-field to warn on overloaded self-assignment (classes)

2018-03-28 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/Sema/SemaExpr.cpp:12093
+break;
+  }
+

lebedev.ri wrote:
> rjmccall wrote:
> > lebedev.ri wrote:
> > > rjmccall wrote:
> > > > I think doing this here can result in double-warning if the overload 
> > > > resolves to a builtin operator.  Now, it might not actually be possible 
> > > > for that to combine with the requirements for self-assignment, but 
> > > > still, I think the right place to diagnose this for C++ is the same 
> > > > place we call DiagnoseSelfMove in CreateOverloadedBinOp.
> > > > 
> > > > Can CheckIdentityFieldAssignment just be integrated with 
> > > > DiagnoseSelfAssignment so that callers don't need to do call both?
> > > > I think the right place to diagnose this for C++ is the same place we 
> > > > call DiagnoseSelfMove in CreateOverloadedBinOp.
> > > 
> > > ```
> > > switch (Opc) {
> > > case BO_Assign:
> > > case BO_DivAssign:
> > > case BO_SubAssign:
> > > case BO_AndAssign:
> > > case BO_OrAssign:
> > > case BO_XorAssign:
> > >   DiagnoseSelfAssignment(Args[0], Args[1], OpLoc);
> > >   CheckIdentityFieldAssignment(Args[0], Args[1], OpLoc);
> > >   break;
> > > default:
> > >   break;
> > > }
> > > 
> > > // Check for a self move.
> > > if (Op == OO_Equal)
> > >   DiagnoseSelfMove(Args[0], Args[1], OpLoc);
> > > ```
> > > 
> > > 
> > > ^ That does not appear to work. Pretty much all these tests start to fail.
> > > 
> > Okay.  It's possible that my suggestion is wrong.  Can you explain more how 
> > they fail?
> Right, i should have been verbose :)
> There are no test changes as compared to the current diff.
> Here is the output of `$ ninja check-clang-sema check-clang-semacxx`
> {F5920055}
> It is also totally possible that i'm missing something obvious on my end...
Oh, DiagnoseSelfAssignment disables itself during template instantiation, 
presumably because it's an easy syntactic check that will always warn on the 
parsed code and so doesn't need to warn again during instantiation.

In that case, I think the place you had the check is fine.


Repository:
  rC Clang

https://reviews.llvm.org/D44883



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


[PATCH] D44494: [libunwind] Support __register_frame with a full .eh_frame section

2018-03-28 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a subscriber: joerg.
mstorsjo added a comment.

Also, relating to this, @joerg mentioned on irc that one should rather use 
`__register_frame_info_bases` instead of `__register_frame`. That function is a 
bit tricky to call though, since it uses a libgcc internal struct `struct 
object`, only available in libgcc headers and in Unwind_AppleExtras.cpp (as 
struct libgcc_object, with the comment "undocumented libgcc struct object").


https://reviews.llvm.org/D44494



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


[PATCH] D44968: [ObjC] Generalize NRVO to cover C structs

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

Wow, the IR improvements here are amazing.




Comment at: lib/CodeGen/CGDecl.cpp:1119
+if ((CXXRD && !CXXRD->hasTrivialDestructor()) ||
+RD->isNonTrivialToPrimitiveCopy()) {
   // Create a flag that is used to indicate when the NRVO was applied

This should be isNonTrivialToPrimitiveDestroy(), I think.  The dynamic NRVO 
flag is specifically tied to whether we should destroy the local variable in 
its normal cleanup.


Repository:
  rC Clang

https://reviews.llvm.org/D44968



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


[PATCH] D44494: [libunwind] Support __register_frame with a full .eh_frame section

2018-03-28 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

In https://reviews.llvm.org/D44494#1050803, @mstorsjo wrote:

> In https://reviews.llvm.org/D44494#1050797, @mstorsjo wrote:
>
> > This else clause isn't about `.eh_frame` vs `.eh_frame_hdr`, but about 
> > registering a single FDE (which libunwind's `__register_frame` currently 
> > does) vs registering a full `.eh_frame` section (which libgcc's 
> > `__register_frame` does).
>
>
> However, this function actually just is `_unw_add_dynamic_fde`, while 
> `__register_frame` in `UnwindLevel1-gcc-ext.c` just calls this function. So 
> we should probably check there instead, whether it's an FDE (which libgcc 
> doesn't support via that entry point) or a full `.eh_frame` section.


In this case, it triggers the "FDE is really a CIE" case in decodeFDE, so we 
could do a quick check in `__register_frame` and see if it is a CIE or an FDE, 
and then call the right underlying functions based on that, instead of adding 
it in the error handling else statement like this.


https://reviews.llvm.org/D44494



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


[PATCH] D44747: Set calling convention for CUDA kernel

2018-03-28 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

LGTM.


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] D44987: Disable emitting static extern C aliases for amdgcn target for CUDA

2018-03-28 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.

LGTM.


https://reviews.llvm.org/D44987



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


[PATCH] D44985: Remove initializer for CUDA shared varirable

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

In https://reviews.llvm.org/D44985#1050674, @yaxunl wrote:

> In https://reviews.llvm.org/D44985#1050670, @rjmccall wrote:
>
> > What exactly are you trying to express here?  Are you just trying to make 
> > these external declarations when compiling for the device because 
> > `__shared__` variables are actually defined on the host?  That should be 
> > handled by the frontend by setting up the AST so that these declarations 
> > are not definitions.
>
>
> No. These variables are not like external symbols defined on the host. They 
> behave like global variables in the kernel code but never initialized. 
> Currently no targets are able to initialize them and it is users' 
> responsibility to initialize them explicitly.
>
> Giving them an initial value will cause error in some backends since they 
> cannot handle them, therefore put undef as initializer.


So undef is being used as a special marker to the backends that it's okay not 
to try to initialize these variables?


https://reviews.llvm.org/D44985



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


[PATCH] D44908: [ObjC++] Make parameter passing and function return compatible with ObjC

2018-03-28 Thread Akira Hatanaka via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL328731: [ObjC++] Make parameter passing and function return 
compatible with ObjC (authored by ahatanak, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D44908?vs=139935=140138#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D44908

Files:
  cfe/trunk/include/clang/AST/Decl.h
  cfe/trunk/include/clang/AST/DeclCXX.h
  cfe/trunk/include/clang/AST/Type.h
  cfe/trunk/include/clang/Basic/LangOptions.def
  cfe/trunk/include/clang/Basic/LangOptions.h
  cfe/trunk/include/clang/Basic/TargetInfo.h
  cfe/trunk/include/clang/Frontend/CodeGenOptions.def
  cfe/trunk/lib/AST/ASTContext.cpp
  cfe/trunk/lib/AST/Decl.cpp
  cfe/trunk/lib/AST/DeclCXX.cpp
  cfe/trunk/lib/AST/Type.cpp
  cfe/trunk/lib/Basic/TargetInfo.cpp
  cfe/trunk/lib/Basic/Targets/X86.h
  cfe/trunk/lib/CodeGen/CGCall.cpp
  cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
  cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
  cfe/trunk/lib/CodeGen/TargetInfo.cpp
  cfe/trunk/lib/Frontend/CompilerInvocation.cpp
  cfe/trunk/lib/Sema/SemaDecl.cpp
  cfe/trunk/lib/Sema/SemaDeclCXX.cpp
  cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
  cfe/trunk/lib/Serialization/ASTWriter.cpp
  cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
  cfe/trunk/test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp
  cfe/trunk/test/CodeGenObjCXX/arc-special-member-functions.mm
  cfe/trunk/test/CodeGenObjCXX/objc-struct-cxx-abi.mm
  cfe/trunk/test/CodeGenObjCXX/property-dot-copy-elision.mm
  cfe/trunk/test/CodeGenObjCXX/trivial_abi.mm

Index: cfe/trunk/lib/AST/DeclCXX.cpp
===
--- cfe/trunk/lib/AST/DeclCXX.cpp
+++ cfe/trunk/lib/AST/DeclCXX.cpp
@@ -801,7 +801,17 @@
 struct DefinitionData  = data();
 Data.PlainOldData = false;
 Data.HasTrivialSpecialMembers = 0;
-Data.HasTrivialSpecialMembersForCall = 0;
+
+// __strong or __weak fields do not make special functions non-trivial
+// for the purpose of calls.
+Qualifiers::ObjCLifetime LT = T.getQualifiers().getObjCLifetime();
+if (LT != Qualifiers::OCL_Strong && LT != Qualifiers::OCL_Weak)
+  data().HasTrivialSpecialMembersForCall = 0;
+
+// Structs with __weak fields should never be passed directly.
+if (LT == Qualifiers::OCL_Weak)
+  setCanPassInRegisters(false);
+
 Data.HasIrrelevantDestructor = false;
   } else if (!Context.getLangOpts().ObjCAutoRefCount) {
 setHasObjectMember(true);
Index: cfe/trunk/lib/AST/Decl.cpp
===
--- cfe/trunk/lib/AST/Decl.cpp
+++ cfe/trunk/lib/AST/Decl.cpp
@@ -3951,7 +3951,7 @@
   LoadedFieldsFromExternalStorage(false),
   NonTrivialToPrimitiveDefaultInitialize(false),
   NonTrivialToPrimitiveCopy(false), NonTrivialToPrimitiveDestroy(false),
-  CanPassInRegisters(true) {
+  CanPassInRegisters(true), ParamDestroyedInCallee(false) {
   assert(classof(static_cast(this)) && "Invalid Kind!");
 }
 
Index: cfe/trunk/lib/AST/ASTContext.cpp
===
--- cfe/trunk/lib/AST/ASTContext.cpp
+++ cfe/trunk/lib/AST/ASTContext.cpp
@@ -2643,9 +2643,11 @@
 }
 
 bool ASTContext::isParamDestroyedInCallee(QualType T) const {
-  return getTargetInfo().getCXXABI().areArgsDestroyedLeftToRightInCallee() ||
- T.hasTrivialABIOverride() ||
- T.isDestructedType() == QualType::DK_nontrivial_c_struct;
+  if (getTargetInfo().getCXXABI().areArgsDestroyedLeftToRightInCallee())
+return true;
+  if (const auto *RT = T->getBaseElementTypeUnsafe()->getAs())
+return RT->getDecl()->isParamDestroyedInCallee();
+  return false;
 }
 
 /// getComplexType - Return the uniqued reference to the type for a complex
Index: cfe/trunk/lib/AST/Type.cpp
===
--- cfe/trunk/lib/AST/Type.cpp
+++ cfe/trunk/lib/AST/Type.cpp
@@ -2195,12 +2195,6 @@
   return false;
 }
 
-bool QualType::hasTrivialABIOverride() const {
-  if (const auto *RD = getTypePtr()->getAsCXXRecordDecl())
-return RD->hasTrivialABIOverride();
-  return false;
-}
-
 bool QualType::isNonWeakInMRRWithObjCWeak(const ASTContext ) const {
   return !Context.getLangOpts().ObjCAutoRefCount &&
  Context.getLangOpts().ObjCWeak &&
Index: cfe/trunk/lib/Sema/SemaDecl.cpp
===
--- cfe/trunk/lib/Sema/SemaDecl.cpp
+++ cfe/trunk/lib/Sema/SemaDecl.cpp
@@ -15461,8 +15461,10 @@
   QualType::PrimitiveCopyKind PCK = FT.isNonTrivialToPrimitiveCopy();
   if (PCK != QualType::PCK_Trivial && PCK != QualType::PCK_VolatileTrivial)
 Record->setNonTrivialToPrimitiveCopy(true);
-  if (FT.isDestructedType())
+  if (FT.isDestructedType()) {
 Record->setNonTrivialToPrimitiveDestroy(true);
+

[PATCH] D44908: [ObjC++] Make parameter passing and function return compatible with ObjC

2018-03-28 Thread Akira Hatanaka via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC328731: [ObjC++] Make parameter passing and function return 
compatible with ObjC (authored by ahatanak, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D44908?vs=139935=140137#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D44908

Files:
  include/clang/AST/Decl.h
  include/clang/AST/DeclCXX.h
  include/clang/AST/Type.h
  include/clang/Basic/LangOptions.def
  include/clang/Basic/LangOptions.h
  include/clang/Basic/TargetInfo.h
  include/clang/Frontend/CodeGenOptions.def
  lib/AST/ASTContext.cpp
  lib/AST/Decl.cpp
  lib/AST/DeclCXX.cpp
  lib/AST/Type.cpp
  lib/Basic/TargetInfo.cpp
  lib/Basic/Targets/X86.h
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/ItaniumCXXABI.cpp
  lib/CodeGen/MicrosoftCXXABI.cpp
  lib/CodeGen/TargetInfo.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclCXX.cpp
  lib/Serialization/ASTReaderDecl.cpp
  lib/Serialization/ASTWriter.cpp
  lib/Serialization/ASTWriterDecl.cpp
  test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp
  test/CodeGenObjCXX/arc-special-member-functions.mm
  test/CodeGenObjCXX/objc-struct-cxx-abi.mm
  test/CodeGenObjCXX/property-dot-copy-elision.mm
  test/CodeGenObjCXX/trivial_abi.mm

Index: include/clang/AST/DeclCXX.h
===
--- include/clang/AST/DeclCXX.h
+++ include/clang/AST/DeclCXX.h
@@ -1468,13 +1468,6 @@
 return data().HasIrrelevantDestructor;
   }
 
-  /// Determine whether the triviality for the purpose of calls for this class
-  /// is overridden to be trivial because this class or the type of one of its
-  /// subobjects has attribute "trivial_abi".
-  bool hasTrivialABIOverride() const {
-return canPassInRegisters() && hasNonTrivialDestructor();
-  }
-
   /// \brief Determine whether this class has a non-literal or/ volatile type
   /// non-static data member or base class.
   bool hasNonLiteralTypeFieldsOrBases() const {
Index: include/clang/AST/Decl.h
===
--- include/clang/AST/Decl.h
+++ include/clang/AST/Decl.h
@@ -3559,6 +3559,11 @@
   /// pass an object of this class.
   bool CanPassInRegisters : 1;
 
+  /// Indicates whether this struct is destroyed in the callee. This flag is
+  /// meaningless when Microsoft ABI is used since parameters are always
+  /// destroyed in the callee.
+  bool ParamDestroyedInCallee : 1;
+
 protected:
   RecordDecl(Kind DK, TagKind TK, const ASTContext , DeclContext *DC,
  SourceLocation StartLoc, SourceLocation IdLoc,
@@ -3654,6 +3659,14 @@
 CanPassInRegisters = CanPass;
   }
 
+  bool isParamDestroyedInCallee() const {
+return ParamDestroyedInCallee;
+  }
+
+  void setParamDestroyedInCallee(bool V) {
+ParamDestroyedInCallee = V;
+  }
+
   /// \brief Determines whether this declaration represents the
   /// injected class name.
   ///
Index: include/clang/AST/Type.h
===
--- include/clang/AST/Type.h
+++ include/clang/AST/Type.h
@@ -808,11 +808,6 @@
   /// Return true if this is a trivially copyable type (C++0x [basic.types]p9)
   bool isTriviallyCopyableType(const ASTContext ) const;
 
-  /// Determine whether this is a class whose triviality for the purpose of
-  /// calls is overridden to be trivial because the class or the type of one of
-  /// its subobjects has attribute "trivial_abi".
-  bool hasTrivialABIOverride() const;
-
   // Don't promise in the API that anything besides 'const' can be
   // easily added.
 
Index: include/clang/Basic/TargetInfo.h
===
--- include/clang/Basic/TargetInfo.h
+++ include/clang/Basic/TargetInfo.h
@@ -1053,6 +1053,14 @@
 }
   }
 
+  enum CallingConvKind {
+CCK_Default,
+CCK_ClangABI4OrPS4,
+CCK_MicrosoftX86_64
+  };
+
+  virtual CallingConvKind getCallingConvKind(bool ClangABICompat4) const;
+
   /// Controls if __builtin_longjmp / __builtin_setjmp can be lowered to
   /// llvm.eh.sjlj.longjmp / llvm.eh.sjlj.setjmp.
   virtual bool hasSjLjLowering() const {
Index: include/clang/Basic/LangOptions.h
===
--- include/clang/Basic/LangOptions.h
+++ include/clang/Basic/LangOptions.h
@@ -102,6 +102,23 @@
 MSVC2015 = 19
   };
 
+  /// Clang versions with different platform ABI conformance.
+  enum class ClangABI {
+/// Attempt to be ABI-compatible with code generated by Clang 3.8.x
+/// (SVN r257626). This causes <1 x long long> to be passed in an
+/// integer register instead of an SSE register on x64_64.
+Ver3_8,
+
+/// Attempt to be ABI-compatible with code generated by Clang 4.0.x
+/// (SVN r291814). This causes move operations to be ignored when
+/// determining whether a class type can be passed or returned directly.
+Ver4,
+
+/// Conform to the 

r328731 - [ObjC++] Make parameter passing and function return compatible with ObjC

2018-03-28 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Wed Mar 28 14:13:14 2018
New Revision: 328731

URL: http://llvm.org/viewvc/llvm-project?rev=328731=rev
Log:
[ObjC++] Make parameter passing and function return compatible with ObjC

ObjC and ObjC++ pass non-trivial structs in a way that is incompatible
with each other. For example:

typedef struct {
  id f0;
  __weak id f1;
} S;

// this code is compiled in c++.
extern "C" {
  void foo(S s);
}

void caller() {
  // the caller passes the parameter indirectly and destructs it.
  foo(S());
}

// this function is compiled in c.
// 'a' is passed directly and is destructed in the callee.
void foo(S a) {
}

This patch fixes the incompatibility by passing and returning structs
with __strong or weak fields using the C ABI in C++ mode. __strong and
__weak fields in a struct do not cause the struct to be destructed in
the caller and __strong fields do not cause the struct to be passed
indirectly.

Also, this patch fixes the microsoft ABI bug mentioned here:

https://reviews.llvm.org/D41039?id=128767#inline-364710

rdar://problem/38887866

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

Added:
cfe/trunk/test/CodeGenObjCXX/objc-struct-cxx-abi.mm
  - copied, changed from r328730, 
cfe/trunk/test/CodeGenObjCXX/trivial_abi.mm
Removed:
cfe/trunk/test/CodeGenObjCXX/trivial_abi.mm
Modified:
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/include/clang/AST/DeclCXX.h
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/include/clang/Basic/LangOptions.def
cfe/trunk/include/clang/Basic/LangOptions.h
cfe/trunk/include/clang/Basic/TargetInfo.h
cfe/trunk/include/clang/Frontend/CodeGenOptions.def
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/Decl.cpp
cfe/trunk/lib/AST/DeclCXX.cpp
cfe/trunk/lib/AST/Type.cpp
cfe/trunk/lib/Basic/TargetInfo.cpp
cfe/trunk/lib/Basic/Targets/X86.h
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
cfe/trunk/lib/CodeGen/TargetInfo.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
cfe/trunk/test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp
cfe/trunk/test/CodeGenObjCXX/arc-special-member-functions.mm
cfe/trunk/test/CodeGenObjCXX/property-dot-copy-elision.mm

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=328731=328730=328731=diff
==
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Wed Mar 28 14:13:14 2018
@@ -3559,6 +3559,11 @@ class RecordDecl : public TagDecl {
   /// pass an object of this class.
   bool CanPassInRegisters : 1;
 
+  /// Indicates whether this struct is destroyed in the callee. This flag is
+  /// meaningless when Microsoft ABI is used since parameters are always
+  /// destroyed in the callee.
+  bool ParamDestroyedInCallee : 1;
+
 protected:
   RecordDecl(Kind DK, TagKind TK, const ASTContext , DeclContext *DC,
  SourceLocation StartLoc, SourceLocation IdLoc,
@@ -3654,6 +3659,14 @@ public:
 CanPassInRegisters = CanPass;
   }
 
+  bool isParamDestroyedInCallee() const {
+return ParamDestroyedInCallee;
+  }
+
+  void setParamDestroyedInCallee(bool V) {
+ParamDestroyedInCallee = V;
+  }
+
   /// \brief Determines whether this declaration represents the
   /// injected class name.
   ///

Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=328731=328730=328731=diff
==
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Wed Mar 28 14:13:14 2018
@@ -1468,13 +1468,6 @@ public:
 return data().HasIrrelevantDestructor;
   }
 
-  /// Determine whether the triviality for the purpose of calls for this class
-  /// is overridden to be trivial because this class or the type of one of its
-  /// subobjects has attribute "trivial_abi".
-  bool hasTrivialABIOverride() const {
-return canPassInRegisters() && hasNonTrivialDestructor();
-  }
-
   /// \brief Determine whether this class has a non-literal or/ volatile type
   /// non-static data member or base class.
   bool hasNonLiteralTypeFieldsOrBases() const {

Modified: cfe/trunk/include/clang/AST/Type.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=328731=328730=328731=diff
==
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Wed Mar 28 14:13:14 2018

[PATCH] D44882: [clangd] Implementation of workspace/symbol request

2018-03-28 Thread Marc-Andre Laperle via Phabricator via cfe-commits
malaperle added inline comments.



Comment at: clangd/SourceCode.cpp:110
+
+llvm::Optional offsetRangeToLocation(SourceManager ,
+   StringRef File,

MaskRay wrote:
> May I ask a question about the conversion between SourceLocation and LSP 
> location? When the document is slightly out of sync with the indexed version, 
> what will be returned?
I forgot to cover the case of the unsaved files, which are indexed in memory. 
It that what you mean? I'll update the patch to address by using the DraftStore 
when available. There is also the case where the file is not opened but 
outdated on disk. I don't think we can do much about it but make sure it 
doesn't crash :) At worst, the location might be off, and navigation will be 
momentarily affected, until the index can be updated with the file change. This 
is what I've noticed in other IDEs as well.



Comment at: clangd/tool/ClangdMain.cpp:105
 
+static llvm::cl::opt LimitWorkspaceSymbolResult(
+"workspace-symbol-limit",

MaskRay wrote:
> malaperle wrote:
> > sammccall wrote:
> > > the -completion-limit was mostly to control rollout, I'm not sure this 
> > > needs to be a flag. If it does, can we make it the same flag as 
> > > completions (and call it -limit or so?)
> > I think it's quite similar to "completions", when you type just one letter 
> > for example, you can get a lot of results and a lot of JSON output. So it 
> > feels like the flag could apply to both completions and workspace symbols. 
> > How about -limit-resuts? I think just -limit might be a bit too general as 
> > we might want to limit other things.
> Can these options be set by LSP initialization options?
They could. Are you say they *should*? We could add it in 
DidChangeConfigurationParams/ClangdConfigurationParamsChange 
(workspace/didChangeConfiguration) if we need to. I haven't tried or needed to 
add it on the client side though. It's not 100% clear what should go in 
workspace/didChangeConfiguration but I think it should probably things that the 
user would change more often at run-time. I'm not sure how frequent this 
"limit" will be changed by the user.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44882



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


[PATCH] D44494: [libunwind] Support __register_frame with a full .eh_frame section

2018-03-28 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

In https://reviews.llvm.org/D44494#1050797, @mstorsjo wrote:

> This else clause isn't about `.eh_frame` vs `.eh_frame_hdr`, but about 
> registering a single FDE (which libunwind's `__register_frame` currently 
> does) vs registering a full `.eh_frame` section (which libgcc's 
> `__register_frame` does).


However, this function actually just is `_unw_add_dynamic_fde`, while 
`__register_frame` in `UnwindLevel1-gcc-ext.c` just calls this function. So we 
should probably check there instead, whether it's an FDE (which libgcc doesn't 
support via that entry point) or a full `.eh_frame` section.


https://reviews.llvm.org/D44494



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


[PATCH] D44883: [Sema] Extend -Wself-assign and -Wself-assign-field to warn on overloaded self-assignment (classes)

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



Comment at: lib/Sema/SemaExpr.cpp:12093
+break;
+  }
+

rjmccall wrote:
> lebedev.ri wrote:
> > rjmccall wrote:
> > > I think doing this here can result in double-warning if the overload 
> > > resolves to a builtin operator.  Now, it might not actually be possible 
> > > for that to combine with the requirements for self-assignment, but still, 
> > > I think the right place to diagnose this for C++ is the same place we 
> > > call DiagnoseSelfMove in CreateOverloadedBinOp.
> > > 
> > > Can CheckIdentityFieldAssignment just be integrated with 
> > > DiagnoseSelfAssignment so that callers don't need to do call both?
> > > I think the right place to diagnose this for C++ is the same place we 
> > > call DiagnoseSelfMove in CreateOverloadedBinOp.
> > 
> > ```
> > switch (Opc) {
> > case BO_Assign:
> > case BO_DivAssign:
> > case BO_SubAssign:
> > case BO_AndAssign:
> > case BO_OrAssign:
> > case BO_XorAssign:
> >   DiagnoseSelfAssignment(Args[0], Args[1], OpLoc);
> >   CheckIdentityFieldAssignment(Args[0], Args[1], OpLoc);
> >   break;
> > default:
> >   break;
> > }
> > 
> > // Check for a self move.
> > if (Op == OO_Equal)
> >   DiagnoseSelfMove(Args[0], Args[1], OpLoc);
> > ```
> > 
> > 
> > ^ That does not appear to work. Pretty much all these tests start to fail.
> > 
> Okay.  It's possible that my suggestion is wrong.  Can you explain more how 
> they fail?
Right, i should have been verbose :)
There are no test changes as compared to the current diff.
Here is the output of `$ ninja check-clang-sema check-clang-semacxx`
{F5920055}
It is also totally possible that i'm missing something obvious on my end...


Repository:
  rC Clang

https://reviews.llvm.org/D44883



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


[PATCH] D44747: Set calling convention for CUDA kernel

2018-03-28 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 140131.
yaxunl marked 2 inline comments as done.
yaxunl added a comment.

Use getAs instead of dyn_cast as John suggested.


https://reviews.llvm.org/D44747

Files:
  include/clang/Basic/Specifiers.h
  lib/AST/ItaniumMangle.cpp
  lib/AST/Type.cpp
  lib/AST/TypePrinter.cpp
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/TargetInfo.cpp
  lib/CodeGen/TargetInfo.h
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaOverload.cpp
  lib/Sema/SemaType.cpp
  test/CodeGenCUDA/kernel-amdgcn.cu
  tools/libclang/CXType.cpp

Index: tools/libclang/CXType.cpp
===
--- tools/libclang/CXType.cpp
+++ tools/libclang/CXType.cpp
@@ -626,6 +626,7 @@
   TCALLINGCONV(PreserveAll);
 case CC_SpirFunction: return CXCallingConv_Unexposed;
 case CC_OpenCLKernel: return CXCallingConv_Unexposed;
+case CC_CUDAKernel: return CXCallingConv_Unexposed;
   break;
 }
 #undef TCALLINGCONV
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
+__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/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -3316,6 +3316,18 @@
   CallingConv CC = S.Context.getDefaultCallingConvention(FTI.isVariadic,
  IsCXXInstanceMethod);
 
+  // Attribute AT_CUDAGlobal affects the calling convention for AMDGPU targets.
+  // This is the simplest place to infer calling convention for CUDA kernels.
+  if (S.getLangOpts().CUDA && S.getLangOpts().CUDAIsDevice) {
+for (const AttributeList *Attr = D.getDeclSpec().getAttributes().getList();
+ Attr; Attr = Attr->getNext()) {
+  if (Attr->getKind() == AttributeList::AT_CUDAGlobal) {
+CC = CC_CUDAKernel;
+break;
+  }
+}
+  }
+
   // Attribute AT_OpenCLKernel affects the calling convention for SPIR
   // and AMDGPU targets, hence it cannot be treated as a calling
   // convention attribute. This is the simplest place to infer
Index: lib/Sema/SemaOverload.cpp
===
--- lib/Sema/SemaOverload.cpp
+++ lib/Sema/SemaOverload.cpp
@@ -1481,7 +1481,6 @@
  .getTypePtr());
   Changed = true;
 }
-
 // Convert FromFPT's ExtParameterInfo if necessary. The conversion is valid
 // only if the ExtParameterInfo lists of the two function prototypes can be
 // merged and the merged list is identical to ToFPT's ExtParameterInfo list.
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -25,6 +25,7 @@
 #include "clang/AST/ExprObjC.h"
 #include "clang/AST/ExprOpenMP.h"
 #include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/Type.h"
 #include "clang/AST/TypeLoc.h"
 #include "clang/Basic/PartialDiagnostic.h"
 #include "clang/Basic/SourceManager.h"
@@ -1657,6 +1658,16 @@
   isa(D) &&
   NeedToCaptureVariable(cast(D), NameInfo.getLoc());
 
+  // Drop CUDA kernel calling convention since it is invisible to the user
+  // in DRE.
+  if (const auto *FT = Ty->getAs()) {
+if (FT->getCallConv() == CC_CUDAKernel) {
+  FT = Context.adjustFunctionType(FT,
+  FT->getExtInfo().withCallingConv(CC_C));
+  Ty = QualType(FT, Ty.getQualifiers().getAsOpaqueValue());
+}
+  }
+
   DeclRefExpr *E;
   if (isa(D)) {
 VarTemplateSpecializationDecl *VarSpec =
Index: lib/CodeGen/TargetInfo.h
===
--- lib/CodeGen/TargetInfo.h
+++ lib/CodeGen/TargetInfo.h
@@ -223,6 +223,9 @@
   /// Get LLVM calling convention for OpenCL kernel.
   virtual unsigned getOpenCLKernelCallingConv() const;
 
+  /// Get LLVM calling convention for CUDA kernel.
+  virtual unsigned getCUDAKernelCallingConv() const;
+
   /// Get target specific null pointer.
   /// \param T is the LLVM type of the null pointer.
   /// \param QT is the clang QualType of the null pointer.
Index: lib/CodeGen/TargetInfo.cpp
===
--- 

[PATCH] D44494: [libunwind] Support __register_frame with a full .eh_frame section

2018-03-28 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

In https://reviews.llvm.org/D44494#1050783, @compnerd wrote:

> I really don't like this approach.  I think that we should introduce a 
> different entry point for this behavior rather than saying that we go through 
> the existing interface.  Having a reference to the `.eh_frame_hdr` seems 
> better, as it would be better to make use of that optimization and we already 
> have handling for that in libunwind.


Well, this is just a plain `.eh_frame`, not an `.eh_frame_hdr`, since nothing 
for MinGW actually produces such a section for COFF (yet), GNU binutils doesn't 
either. Adding support for an indexed `.eh_frame_hdr`, while good from a 
performance PoV, feels like an orthogonal issue from this.

This else clause isn't about `.eh_frame` vs `.eh_frame_hdr`, but about 
registering a single FDE (which libunwind's `__register_frame` currently does) 
vs registering a full `.eh_frame` section (which libgcc's `__register_frame` 
does).


https://reviews.llvm.org/D44494



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


[PATCH] D44536: Avoid segfault when destructor is not yet known

2018-03-28 Thread Dimitry Andric via Phabricator via cfe-commits
dim added a comment.

Ping. Open to sugggestions here :)


Repository:
  rC Clang

https://reviews.llvm.org/D44536



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


[PATCH] D44494: [libunwind] Support __register_frame with a full .eh_frame section

2018-03-28 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd requested changes to this revision.
compnerd added a comment.
This revision now requires changes to proceed.

I really don't like this approach.  I think that we should introduce a 
different entry point for this behavior rather than saying that we go through 
the existing interface.  Having a reference to the `.eh_frame_hdr` seems 
better, as it would be better to make use of that optimization and we already 
have handling for that in libunwind.


https://reviews.llvm.org/D44494



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


[PATCH] D44987: Disable emitting static extern C aliases for amdgcn target for CUDA

2018-03-28 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 140129.
yaxunl edited the summary of this revision.
yaxunl added a comment.

Add a target hook as suggested by John.


https://reviews.llvm.org/D44987

Files:
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/TargetInfo.cpp
  lib/CodeGen/TargetInfo.h
  test/CodeGenCUDA/alias.cu


Index: test/CodeGenCUDA/alias.cu
===
--- test/CodeGenCUDA/alias.cu
+++ test/CodeGenCUDA/alias.cu
@@ -1,8 +1,11 @@
 // REQUIRES: x86-registered-target
 // REQUIRES: nvptx-registered-target
+// REQUIRES: amdgpu-registered-target
 
 // RUN: %clang_cc1 -fcuda-is-device -triple nvptx-nvidia-cuda -emit-llvm \
 // RUN:   -o - %s | FileCheck %s
+// RUN: %clang_cc1 -fcuda-is-device -triple amdgcn -emit-llvm \
+// RUN:   -o - %s | FileCheck %s
 
 #include "Inputs/cuda.h"
 
Index: lib/CodeGen/TargetInfo.h
===
--- lib/CodeGen/TargetInfo.h
+++ lib/CodeGen/TargetInfo.h
@@ -296,6 +296,11 @@
   createEnqueuedBlockKernel(CodeGenFunction ,
 llvm::Function *BlockInvokeFunc,
 llvm::Value *BlockLiteral) const;
+
+  /// \return true if the target supports alias from the unmangled name to the
+  /// mangled name of functions declared within an extern "C" region and marked
+  /// as 'used', and having internal linkage.
+  virtual bool shouldEmitStaticExternCAliases() const { return true; }
 };
 
 } // namespace CodeGen
Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -6154,6 +6154,7 @@
 
   void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
CodeGen::CodeGenModule ) const override;
+  bool shouldEmitStaticExternCAliases() const override;
 
 private:
   // Adds a NamedMDNode with F, Name, and Operand as operands, and adds the
@@ -6275,6 +6276,10 @@
   // Append metadata to nvvm.annotations
   MD->addOperand(llvm::MDNode::get(Ctx, MDVals));
 }
+
+bool NVPTXTargetCodeGenInfo::shouldEmitStaticExternCAliases() const {
+  return false;
+}
 }
 
 
//===--===//
@@ -7646,6 +7651,7 @@
   createEnqueuedBlockKernel(CodeGenFunction ,
 llvm::Function *BlockInvokeFunc,
 llvm::Value *BlockLiteral) const override;
+  bool shouldEmitStaticExternCAliases() const override;
 };
 }
 
@@ -,6 +7783,10 @@
   return C.getOrInsertSyncScopeID(Name);
 }
 
+bool AMDGPUTargetCodeGenInfo::shouldEmitStaticExternCAliases() const {
+  return false;
+}
+
 
//===--===//
 // SPARC v8 ABI Implementation.
 // Based on the SPARC Compliance Definition version 2.4.1.
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -4677,9 +4677,7 @@
 /// to such functions with an unmangled name from inline assembly within the
 /// same translation unit.
 void CodeGenModule::EmitStaticExternCAliases() {
-  // Don't do anything if we're generating CUDA device code -- the NVPTX
-  // assembly target doesn't support aliases.
-  if (Context.getTargetInfo().getTriple().isNVPTX())
+  if (!getTargetCodeGenInfo().shouldEmitStaticExternCAliases())
 return;
   for (auto  : StaticExternCValues) {
 IdentifierInfo *Name = I.first;


Index: test/CodeGenCUDA/alias.cu
===
--- test/CodeGenCUDA/alias.cu
+++ test/CodeGenCUDA/alias.cu
@@ -1,8 +1,11 @@
 // REQUIRES: x86-registered-target
 // REQUIRES: nvptx-registered-target
+// REQUIRES: amdgpu-registered-target
 
 // RUN: %clang_cc1 -fcuda-is-device -triple nvptx-nvidia-cuda -emit-llvm \
 // RUN:   -o - %s | FileCheck %s
+// RUN: %clang_cc1 -fcuda-is-device -triple amdgcn -emit-llvm \
+// RUN:   -o - %s | FileCheck %s
 
 #include "Inputs/cuda.h"
 
Index: lib/CodeGen/TargetInfo.h
===
--- lib/CodeGen/TargetInfo.h
+++ lib/CodeGen/TargetInfo.h
@@ -296,6 +296,11 @@
   createEnqueuedBlockKernel(CodeGenFunction ,
 llvm::Function *BlockInvokeFunc,
 llvm::Value *BlockLiteral) const;
+
+  /// \return true if the target supports alias from the unmangled name to the
+  /// mangled name of functions declared within an extern "C" region and marked
+  /// as 'used', and having internal linkage.
+  virtual bool shouldEmitStaticExternCAliases() const { return true; }
 };
 
 } // namespace CodeGen
Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -6154,6 +6154,7 @@
 
   void setTargetAttributes(const Decl *D, 

[PATCH] D44964: Change order of libclang_rt.profile link for freebsd

2018-03-28 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added a comment.

Could you add a test in test/Driver/instrprof-ld.c?


Repository:
  rC Clang

https://reviews.llvm.org/D44964



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


[PATCH] D44996: [clang-format] Ensure ObjC selectors with 0 args are annotated correctly

2018-03-28 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton created this revision.
benhamilton added reviewers: djasper, jolesiak.
Herald added subscribers: cfe-commits, klimek.

Previously, clang-format would incorrectly annotate 0-argument
Objective-C selector names as TT_TrailingAnnotation:

  % echo "-(void)foo;" > /tmp/test.m
  % ./bin/clang-format -debug /tmp/test.m
  Language: Objective-C
  
  Line(0, FSC=0): minus[T=68, OC=0] l_paren[T=68, OC=1] void[T=68, OC=2]
  r_paren[T=68, OC=6] identifier[T=68, OC=7] semi[T=68, OC=10]
  Line(0, FSC=0): eof[T=68, OC=0]
  Run 0...
  AnnotatedTokens(L=0):
   M=0 C=0 T=ObjCMethodSpecifier S=1 B=0 BK=0 P=0 Name=minus L=1 PPK=2
   FakeLParens= FakeRParens=0 Text='-'
   M=0 C=1 T=Unknown S=1 B=0 BK=0 P=33 Name=l_paren L=3 PPK=2
   FakeLParens= FakeRParens=0 Text='('
   M=0 C=1 T=Unknown S=0 B=0 BK=0 P=140 Name=void L=7 PPK=2 FakeLParens=
   FakeRParens=0 Text='void'
   M=0 C=0 T=CastRParen S=0 B=0 BK=0 P=43 Name=r_paren L=8 PPK=2
   FakeLParens= FakeRParens=0 Text=')'
   M=0 C=1 T=TrailingAnnotation S=0 B=0 BK=0 P=120 Name=identifier L=11
   PPK=2 FakeLParens= FakeRParens=0 Text='foo'
   M=0 C=0 T=Unknown S=0 B=0 BK=0 P=23 Name=semi L=12 PPK=2 FakeLParens=
   FakeRParens=0 Text=';'

This caused us to incorrectly indent 0-argument wrapped selectors
when Style.IndentWrappedFunctionNames was false, as we thought
the 0-argument ObjC selector name was actually a trailing
annotation (which is always indented).

This diff fixes the issue and adds tests.

Test Plan: New tests added. Confirmed tests failed before diff.

  After diff, tests passed. Ran tests with:
  % make -j12 FormatTests &&
  ./tools/clang/unittests/Format/FormatTests


Repository:
  rC Clang

https://reviews.llvm.org/D44996

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


Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -522,6 +522,22 @@
   verifyFormat("- (void)drawRectOn:(id)surface\n"
"ofSize:(size_t)height\n"
"  :(size_t)width;");
+  Style.ColumnLimit = 40;
+  // Make sure selectors with 0, 1, or more arguments are not indented
+  // when IndentWrappedFunctionNames is false.
+  verifyFormat("- (a)\n"
+   ";\n");
+  verifyFormat("- (a)\n"
+   ":(int)a;\n");
+  verifyFormat("- (a)\n"
+   ":(int)a\n"
+   ":(int)a;\n");
+  verifyFormat("- (a)\n"
+   " aaa:(int)a\n"
+   ":(int)a;\n");
+  verifyFormat("- (a)\n"
+   ":(int)a\n"
+   " aaa:(int)a;\n");
 
   // Continuation indent width should win over aligning colons if the function
   // name is long.
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -1343,6 +1343,16 @@
  TT_LeadingJavaAnnotation)) {
 Current.Type = Current.Previous->Type;
   }
+} else if (Current.isOneOf(tok::identifier, tok::kw_new) &&
+   Current.Previous && Current.Previous->is(TT_CastRParen) &&
+   Current.Previous->MatchingParen &&
+   Current.Previous->MatchingParen->Previous &&
+   Current.Previous->MatchingParen->Previous->is(
+   TT_ObjCMethodSpecifier)) {
+  // This is the first part of an Objective-C selector name. (If there's no
+  // colon after this, this is the only place which annotates the 
identifier
+  // as a selector.)
+  Current.Type = TT_SelectorName;
 } else if (Current.isOneOf(tok::identifier, tok::kw_const) &&
Current.Previous &&
!Current.Previous->isOneOf(tok::equal, tok::at) &&


Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -522,6 +522,22 @@
   verifyFormat("- (void)drawRectOn:(id)surface\n"
"ofSize:(size_t)height\n"
"  :(size_t)width;");
+  Style.ColumnLimit = 40;
+  // Make sure selectors with 0, 1, or more arguments are not indented
+  // when IndentWrappedFunctionNames is false.
+  verifyFormat("- (a)\n"
+   ";\n");
+  verifyFormat("- (a)\n"
+   ":(int)a;\n");
+  verifyFormat("- 

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

2018-03-28 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

Friendly ping..


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] D42893: [libclang] Add clang_File_tryGetRealPathName

2018-03-28 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

Ping


Repository:
  rC Clang

https://reviews.llvm.org/D42893



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


r328725 - [Hexagon] Add support for "new" circular buffer intrinsics

2018-03-28 Thread Krzysztof Parzyszek via cfe-commits
Author: kparzysz
Date: Wed Mar 28 12:40:57 2018
New Revision: 328725

URL: http://llvm.org/viewvc/llvm-project?rev=328725=rev
Log:
[Hexagon] Add support for "new" circular buffer intrinsics

These instructions have been around for a long time, but we
haven't supported intrinsics for them. The "new" vesrions use
the CSx register for the start of the buffer instead of the K
field in the Mx register.

There is a related llvm patch.

Patch by Brendon Cahoon.

Added:
cfe/trunk/test/CodeGen/builtins-hexagon-circ.c
Modified:
cfe/trunk/include/clang/Basic/BuiltinsHexagon.def
cfe/trunk/lib/CodeGen/CGBuiltin.cpp

Modified: cfe/trunk/include/clang/Basic/BuiltinsHexagon.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsHexagon.def?rev=328725=328724=328725=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsHexagon.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsHexagon.def Wed Mar 28 12:40:57 2018
@@ -39,6 +39,29 @@ BUILTIN(__builtin_circ_stw,   "i*i*iiIi"
 BUILTIN(__builtin_circ_sth,   "s*s*iiIi", "")
 BUILTIN(__builtin_circ_sthhi, "s*s*iiIi", "")
 BUILTIN(__builtin_circ_stb,   "c*c*iiIi", "")
+BUILTIN(__builtin_HEXAGON_L2_loadrub_pci, "iv*IiivC*", "")
+BUILTIN(__builtin_HEXAGON_L2_loadrb_pci, "iv*IiivC*", "")
+BUILTIN(__builtin_HEXAGON_L2_loadruh_pci, "iv*IiivC*", "")
+BUILTIN(__builtin_HEXAGON_L2_loadrh_pci, "iv*IiivC*", "")
+BUILTIN(__builtin_HEXAGON_L2_loadri_pci, "iv*IiivC*", "")
+BUILTIN(__builtin_HEXAGON_L2_loadrd_pci, "LLiv*IiivC*", "")
+BUILTIN(__builtin_HEXAGON_L2_loadrub_pcr, "iv*ivC*", "")
+BUILTIN(__builtin_HEXAGON_L2_loadrb_pcr, "iv*ivC*", "")
+BUILTIN(__builtin_HEXAGON_L2_loadruh_pcr, "iv*ivC*", "")
+BUILTIN(__builtin_HEXAGON_L2_loadrh_pcr, "iv*ivC*", "")
+BUILTIN(__builtin_HEXAGON_L2_loadri_pcr, "iv*ivC*", "")
+BUILTIN(__builtin_HEXAGON_L2_loadrd_pcr, "LLiv*ivC*", "")
+
+BUILTIN(__builtin_HEXAGON_S2_storerb_pci, "vv*IiiivC*", "")
+BUILTIN(__builtin_HEXAGON_S2_storerh_pci, "vv*IiiivC*", "")
+BUILTIN(__builtin_HEXAGON_S2_storerf_pci, "vv*IiiivC*", "")
+BUILTIN(__builtin_HEXAGON_S2_storeri_pci, "vv*IiiivC*", "")
+BUILTIN(__builtin_HEXAGON_S2_storerd_pci, "vv*IiiLLivC*", "")
+BUILTIN(__builtin_HEXAGON_S2_storerb_pcr, "vv*iivC*", "")
+BUILTIN(__builtin_HEXAGON_S2_storerh_pcr, "vv*iivC*", "")
+BUILTIN(__builtin_HEXAGON_S2_storerf_pcr, "vv*iivC*", "")
+BUILTIN(__builtin_HEXAGON_S2_storeri_pcr, "vv*iivC*", "")
+BUILTIN(__builtin_HEXAGON_S2_storerd_pcr, "vv*iLLivC*", "")
 
 // The builtins above are not autogenerated from iset.py.
 // Make sure you do not overwrite these.

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=328725=328724=328725=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Wed Mar 28 12:40:57 2018
@@ -10772,6 +10772,54 @@ Value *CodeGenFunction::EmitHexagonBuilt
   SmallVector Ops;
   Intrinsic::ID ID = Intrinsic::not_intrinsic;
 
+  auto MakeCircLd = [&](unsigned IntID, bool HasImm = true) {
+// The base pointer is passed by address, so it needs to be loaded.
+Address BP = EmitPointerWithAlignment(E->getArg(0));
+BP = Address(Builder.CreateBitCast(BP.getPointer(), Int8PtrPtrTy),
+ BP.getAlignment());
+llvm::Value *Base = Builder.CreateLoad(BP);
+// Operands are Base, Increment, Modifier, Start.
+if (HasImm)
+  Ops = { Base, EmitScalarExpr(E->getArg(1)), EmitScalarExpr(E->getArg(2)),
+  EmitScalarExpr(E->getArg(3)) };
+else
+  Ops = { Base, EmitScalarExpr(E->getArg(1)),
+  EmitScalarExpr(E->getArg(2)) };
+
+llvm::Value *Result = Builder.CreateCall(CGM.getIntrinsic(IntID), Ops);
+llvm::Value *NewBase = Builder.CreateExtractValue(Result, 1);
+llvm::Value *LV = Builder.CreateBitCast(EmitScalarExpr(E->getArg(0)),
+
NewBase->getType()->getPointerTo());
+Address Dest = EmitPointerWithAlignment(E->getArg(0));
+// The intrinsic generates two results. The new value for the base pointer
+// needs to be stored.
+Builder.CreateAlignedStore(NewBase, LV, Dest.getAlignment());
+return Builder.CreateExtractValue(Result, 0);
+  };
+
+  auto MakeCircSt = [&](unsigned IntID, bool HasImm = true) {
+// The base pointer is passed by address, so it needs to be loaded.
+Address BP = EmitPointerWithAlignment(E->getArg(0));
+BP = Address(Builder.CreateBitCast(BP.getPointer(), Int8PtrPtrTy),
+ BP.getAlignment());
+llvm::Value *Base = Builder.CreateLoad(BP);
+// Operands are Base, Increment, Modifier, Value, Start.
+if (HasImm)
+  Ops = { Base, EmitScalarExpr(E->getArg(1)), EmitScalarExpr(E->getArg(2)),
+  EmitScalarExpr(E->getArg(3)), EmitScalarExpr(E->getArg(4)) };
+else
+  Ops 

[PATCH] D44984: [HIP] Add hip file type and codegen for kernel launching

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

In https://reviews.llvm.org/D44984#1050672, @rjmccall wrote:

> You should send an RFC to cfe-dev about adding this new language mode.  I 
> understand that it's very similar to an existing language mode that we 
> already support, and that's definitely we'll consider, but we shouldn't just 
> agree to add new language modes in patch review.


RFC sent http://lists.llvm.org/pipermail/cfe-dev/2018-March/057426.html

Thanks.


https://reviews.llvm.org/D44984



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


[PATCH] D44995: [Driver] Include the Android multiarch includes.

2018-03-28 Thread Dan Albert via Phabricator via cfe-commits
danalbert created this revision.
danalbert added a reviewer: srhines.
Herald added a subscriber: javed.absar.

Most Android headers live in a single directory, but a small handful
live in multiarch directories.


Repository:
  rC Clang

https://reviews.llvm.org/D44995

Files:
  lib/Driver/ToolChains/Linux.cpp
  
test/Driver/Inputs/basic_android_ndk_tree/include/c++/4.9/x86_64-linux-android/.keep
  
test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/x86_64-linux-android/4.9/crtbegin.o
  
test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/x86_64-linux-android/4.9/crtend.o
  
test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/x86_64-linux-android/4.9/include/.keep
  
test/Driver/Inputs/basic_android_ndk_tree/sysroot/usr/include/aarch64-linux-android/.keep
  
test/Driver/Inputs/basic_android_ndk_tree/sysroot/usr/include/arm-linux-androideabi/.keep
  
test/Driver/Inputs/basic_android_ndk_tree/sysroot/usr/include/i686-linux-android/.keep
  
test/Driver/Inputs/basic_android_ndk_tree/sysroot/usr/include/x86_64-linux-android/.keep
  test/Driver/Inputs/basic_android_ndk_tree/x86_64-linux-android/bin/ld
  test/Driver/Inputs/basic_android_ndk_tree/x86_64-linux-android/bin/ld.bfd
  test/Driver/Inputs/basic_android_ndk_tree/x86_64-linux-android/bin/ld.gold
  test/Driver/Inputs/basic_android_ndk_tree/x86_64-linux-android/lib/.keep
  test/Driver/android-ndk-standalone.cpp

Index: test/Driver/android-ndk-standalone.cpp
===
--- test/Driver/android-ndk-standalone.cpp
+++ test/Driver/android-ndk-standalone.cpp
@@ -19,6 +19,7 @@
 // CHECK: "-internal-isystem" "{{.*}}/include/c++/4.9/backward"
 // CHECK: "-internal-isystem" "{{.*}}/sysroot/usr/local/include"
 // CHECK: "-internal-isystem" "[[RESOURCE_DIR]]{{(/|)}}include"
+// CHECK: "-internal-externc-isystem" "{{.*}}/sysroot/usr/include/arm-linux-androideabi"
 // CHECK: "-internal-externc-isystem" "{{.*}}/sysroot/include"
 // CHECK: "-internal-externc-isystem" "{{.*}}/sysroot/usr/include"
 // CHECK: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
@@ -56,6 +57,7 @@
 // CHECK-ARMV7: "-internal-isystem" "{{.*}}/include/c++/4.9/backward"
 // CHECK-ARMV7: "-internal-isystem" "{{.*}}/sysroot/usr/local/include"
 // CHECK-ARMV7: "-internal-isystem" "[[RESOURCE_DIR]]{{(/|)}}include"
+// CHECK-ARMV7: "-internal-externc-isystem" "{{.*}}/sysroot/usr/include/arm-linux-androideabi"
 // CHECK-ARMV7: "-internal-externc-isystem" "{{.*}}/sysroot/include"
 // CHECK-ARMV7: "-internal-externc-isystem" "{{.*}}/sysroot/usr/include"
 // CHECK-ARMV7: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
@@ -115,6 +117,7 @@
 // CHECK-THUMB: "-internal-isystem" "{{.*}}/include/c++/4.9/backward"
 // CHECK-THUMB: "-internal-isystem" "{{.*}}/sysroot/usr/local/include"
 // CHECK-THUMB: "-internal-isystem" "[[RESOURCE_DIR]]{{(/|)}}include"
+// CHECK-THUMB: "-internal-externc-isystem" "{{.*}}/sysroot/usr/include/arm-linux-androideabi"
 // CHECK-THUMB: "-internal-externc-isystem" "{{.*}}/sysroot/include"
 // CHECK-THUMB: "-internal-externc-isystem" "{{.*}}/sysroot/usr/include"
 // CHECK-THUMB: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
@@ -154,6 +157,7 @@
 // CHECK-ARMV7THUMB: "-internal-isystem" "{{.*}}/include/c++/4.9/backward"
 // CHECK-ARMV7THUMB: "-internal-isystem" "{{.*}}/sysroot/usr/local/include"
 // CHECK-ARMV7THUMB: "-internal-isystem" "[[RESOURCE_DIR]]{{(/|)}}include"
+// CHECK-ARMV7THUMB: "-internal-externc-isystem" "{{.*}}/sysroot/usr/include/arm-linux-androideabi"
 // CHECK-ARMV7THUMB: "-internal-externc-isystem" "{{.*}}/sysroot/include"
 // CHECK-ARMV7THUMB: "-internal-externc-isystem" "{{.*}}/sysroot/usr/include"
 // CHECK-ARMV7THUMB: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
@@ -203,6 +207,7 @@
 // CHECK-AARCH64: "-internal-isystem" "{{.*}}/include/c++/4.9"
 // CHECK-AARCH64: "-internal-isystem" "{{.*}}/include/c++/4.9/aarch64-linux-android"
 // CHECK-AARCH64: "-internal-isystem" "{{.*}}/include/c++/4.9/backward"
+// CHECK-AARCH64: "-internal-externc-isystem" "{{.*}}/sysroot/usr/include/aarch64-linux-android"
 // CHECK-AARCH64: "-internal-externc-isystem" "{{.*}}/sysroot/include"
 // CHECK-AARCH64: "-internal-externc-isystem" "{{.*}}/sysroot/usr/include"
 // CHECK-AARCH64: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
@@ -219,6 +224,7 @@
 // CHECK-ARM64: "-internal-isystem" "{{.*}}/include/c++/4.9"
 // CHECK-ARM64: "-internal-isystem" "{{.*}}/include/c++/4.9/aarch64-linux-android"
 // CHECK-ARM64: "-internal-isystem" "{{.*}}/include/c++/4.9/backward"
+// CHECK-ARM64: "-internal-externc-isystem" "{{.*}}/sysroot/usr/include/aarch64-linux-android"
 // CHECK-ARM64: "-internal-externc-isystem" "{{.*}}/sysroot/include"
 // CHECK-ARM64: "-internal-externc-isystem" "{{.*}}/sysroot/usr/include"
 // CHECK-ARM64: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
@@ -321,9 +327,28 @@
 // CHECK-I686: "-internal-isystem" "{{.*}}/include/c++/4.9"
 // CHECK-I686: "-internal-isystem" 

[PATCH] D44994: [clang-format] Ensure wrapped ObjC selectors with 1 arg obey IndentWrappedFunctionNames

2018-03-28 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton created this revision.
benhamilton added reviewers: djasper, klimek, Typz.
Herald added a subscriber: cfe-commits.
benhamilton added a reviewer: jolesiak.

In https://reviews.llvm.org/D43121, @Typz introduced logic to avoid indenting 
2-or-more
argument ObjC selectors too far to the right if the first component
of the selector was longer than the others.

This had a small side effect of causing wrapped ObjC selectors with
exactly 1 argument to not obey IndentWrappedFunctionNames:

  - (aa)
  aa;

This diff fixes the issue by ensuring we align wrapped 1-argument
ObjC selectors correctly:

  - (aa)
  aa;

Test Plan: New tests added. Test failed before change, passed

  after change. Ran tests with:
  % make -j12 FormatTests && ./tools/clang/unittests/Format/FormatTests


Repository:
  rC Clang

https://reviews.llvm.org/D44994

Files:
  lib/Format/ContinuationIndenter.cpp
  unittests/Format/FormatTestObjC.cpp


Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -537,6 +537,22 @@
"   aShortf:(NSRect)theRect {\n"
"}");
 
+  // Make sure selectors with 0, 1, or more arguments are indented
+  // when IndentWrappedFunctionNames is true.
+  verifyFormat("- (a)\n"
+   ";\n");
+  verifyFormat("- (a)\n"
+   ":(int)a;\n");
+  verifyFormat("- (a)\n"
+   ":(int)a\n"
+   ":(int)a;\n");
+  verifyFormat("- (a)\n"
+   " aaa:(int)a\n"
+   ":(int)a;\n");
+  verifyFormat("- (a)\n"
+   ":(int)a\n"
+   " aaa:(int)a;\n");
+
   // Format pairs correctly.
   Style.ColumnLimit = 80;
   verifyFormat("- (void)drawRectOn:(id)surface\n"
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -896,12 +896,14 @@
 return std::max(State.Stack.back().LastSpace, State.Stack.back().Indent);
   if (NextNonComment->is(TT_SelectorName)) {
 if (!State.Stack.back().ObjCSelectorNameFound) {
+  unsigned MinIndent =
+  (Style.IndentWrappedFunctionNames
+   ? std::max(State.Stack.back().Indent,
+  State.FirstIndent + Style.ContinuationIndentWidth)
+   : State.Stack.back().Indent);
   if (NextNonComment->LongestObjCSelectorName == 0)
-return State.Stack.back().Indent;
-  return (Style.IndentWrappedFunctionNames
-  ? std::max(State.Stack.back().Indent,
- State.FirstIndent + Style.ContinuationIndentWidth)
-  : State.Stack.back().Indent) +
+return MinIndent;
+  return MinIndent +
  std::max(NextNonComment->LongestObjCSelectorName,
   NextNonComment->ColumnWidth) -
  NextNonComment->ColumnWidth;


Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -537,6 +537,22 @@
"   aShortf:(NSRect)theRect {\n"
"}");
 
+  // Make sure selectors with 0, 1, or more arguments are indented
+  // when IndentWrappedFunctionNames is true.
+  verifyFormat("- (a)\n"
+   ";\n");
+  verifyFormat("- (a)\n"
+   ":(int)a;\n");
+  verifyFormat("- (a)\n"
+   ":(int)a\n"
+   ":(int)a;\n");
+  verifyFormat("- (a)\n"
+   " aaa:(int)a\n"
+   ":(int)a;\n");
+  verifyFormat("- (a)\n"
+   ":(int)a\n"
+   " aaa:(int)a;\n");
+
   // Format pairs correctly.
   Style.ColumnLimit = 80;
   verifyFormat("- (void)drawRectOn:(id)surface\n"
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -896,12 +896,14 @@
 return std::max(State.Stack.back().LastSpace, 

[PATCH] D33537: [clang-tidy] Exception Escape Checker

2018-03-28 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 140117.
baloghadamsoftware added a comment.

,html removed from release notes.


https://reviews.llvm.org/D33537

Files:
  clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tidy/bugprone/CMakeLists.txt
  clang-tidy/bugprone/ExceptionEscapeCheck.cpp
  clang-tidy/bugprone/ExceptionEscapeCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/bugprone-exception-escape.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/bugprone-exception-escape.cpp

Index: test/clang-tidy/bugprone-exception-escape.cpp
===
--- /dev/null
+++ test/clang-tidy/bugprone-exception-escape.cpp
@@ -0,0 +1,256 @@
+// RUN: %check_clang_tidy %s bugprone-exception-escape %t -- -extra-arg=-std=c++11 -config="{CheckOptions: [{key: bugprone-exception-escape.IgnoredExceptions, value: 'ignored1,ignored2'}, {key: bugprone-exception-escape.EnabledFunctions, value: 'enabled1,enabled2,enabled3'}]}" --
+
+struct throwing_destructor {
+  ~throwing_destructor() {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: function '~throwing_destructor' throws
+throw 1;
+  }
+};
+
+struct throwing_move_constructor {
+  throwing_move_constructor(throwing_move_constructor&&) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: function 'throwing_move_constructor' throws
+throw 1;
+  }
+};
+
+struct throwing_move_assignment {
+  throwing_move_assignment& operator=(throwing_move_assignment&&) {
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: function 'operator=' throws
+throw 1;
+  }
+};
+
+void throwing_noexcept() noexcept {
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'throwing_noexcept' throws
+  throw 1;
+}
+
+void throwing_throw_nothing() throw() {
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'throwing_throw_nothing' throws
+  throw 1;
+}
+
+void throw_and_catch() noexcept {
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:6: warning: function 'throw_and_catch' throws
+  try {
+throw 1;
+  } catch(int &) {
+  }
+}
+
+void throw_and_catch_some(int n) noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'throw_and_catch_some' throws
+  try {
+if (n) throw 1;
+throw 1.1;
+  } catch(int &) {
+  }
+}
+
+void throw_and_catch_each(int n) noexcept {
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:6: warning: function 'throw_and_catch_each' throws
+  try {
+if (n) throw 1;
+throw 1.1;
+  } catch(int &) {
+  } catch(double &) {
+  }
+}
+
+void throw_and_catch_all(int n) noexcept {
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:6: warning: function 'throw_and_catch_all' throws
+  try {
+if (n) throw 1;
+throw 1.1;
+  } catch(...) {
+  }
+}
+
+void throw_and_rethrow() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'throw_and_rethrow' throws
+  try {
+throw 1;
+  } catch(int &) {
+throw;
+  }
+}
+
+void throw_catch_throw() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'throw_catch_throw' throws
+  try {
+throw 1;
+  } catch(int &) {
+throw 2;
+  }
+}
+
+void throw_catch_rethrow_the_rest(int n) noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'throw_catch_rethrow_the_rest' throws
+  try {
+if (n) throw 1;
+throw 1.1;
+  } catch(int &) {
+  } catch(...) {
+throw;
+  }
+}
+
+class base {};
+class derived: public base {};
+
+void throw_derived_catch_base() noexcept {
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:6: warning: function 'throw_derived_catch_base' throws
+  try {
+throw derived();
+  } catch(base &) {
+  }
+}
+
+void try_nested_try(int n) noexcept {
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:6: warning: function 'try_nested_try' throws
+  try {
+try {
+  if (n) throw 1;
+  throw 1.1;
+} catch(int &) {
+}
+  } catch(double &) {
+  }
+}
+
+void bad_try_nested_try(int n) noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'bad_try_nested_try' throws
+  try {
+if (n) throw 1;
+try {
+  throw 1.1;
+} catch(int &) {
+}
+  } catch(double &) {
+  }
+}
+
+void try_nested_catch() noexcept {
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:6: warning: function 'try_nested_catch' throws
+  try {
+try {
+  throw 1;
+} catch(int &) {
+  throw 1.1;
+}
+  } catch(double &) {
+  }
+}
+
+void catch_nested_try() noexcept {
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:6: warning: function 'catch_nested_try' throws
+  try {
+throw 1;
+  } catch(int &) {
+try {
+  throw 1; 
+} catch(int &) {
+}
+  }
+}
+
+void bad_catch_nested_try() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'bad_catch_nested_try' throws
+  try {
+throw 1;
+  } catch(int &) {
+try {
+  throw 1.1;
+} catch(int &) {
+}
+  } catch(double &) {
+  }
+}
+
+void implicit_int_thrower() {
+  throw 1;
+}
+
+void explicit_int_thrower() throw(int);
+
+void indirect_implicit() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'indirect_implicit' 

[PATCH] D44985: Remove initializer for CUDA shared varirable

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

In https://reviews.llvm.org/D44985#1050670, @rjmccall wrote:

> What exactly are you trying to express here?  Are you just trying to make 
> these external declarations when compiling for the device because 
> `__shared__` variables are actually defined on the host?  That should be 
> handled by the frontend by setting up the AST so that these declarations are 
> not definitions.


No. These variables are not like external symbols defined on the host. They 
behave like global variables in the kernel code but never initialized. 
Currently no targets are able to initialize them and it is users' 
responsibility to initialize them explicitly.

Giving them an initial value will cause error in some backends since they 
cannot handle them, therefore put undef as initializer.


https://reviews.llvm.org/D44985



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


[PATCH] D44984: [HIP] Add hip file type and codegen for kernel launching

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

You should send an RFC to cfe-dev about adding this new language mode.  I 
understand that it's very similar to an existing language mode that we already 
support, and that's definitely we'll consider, but we shouldn't just agree to 
add new language modes in patch review.


https://reviews.llvm.org/D44984



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


[PATCH] D44985: Remove initializer for CUDA shared varirable

2018-03-28 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

In https://reviews.llvm.org/D44985#1050670, @rjmccall wrote:

> What exactly are you trying to express here?  Are you just trying to make 
> these external declarations when compiling for the device because 
> `__shared__` variables are actually defined on the host?  That should be 
> handled by the frontend by setting up the AST so that these declarations are 
> not definitions.


__shared__ vars (at least in CUDA) are weird. Local-scoped ones are implicitly 
static (which compiler will attempt to zero-init) but in CUDA __shared__ 
variables can't have static initializers and we don't know the value of such 
vars when we launch the kernel.


https://reviews.llvm.org/D44985



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


[PATCH] D44987: Disable emitting static extern C aliases for amdgcn target for CUDA

2018-03-28 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/CodeGen/CodeGenModule.cpp:4684
+  (Context.getTargetInfo().getTriple().getArch() == llvm::Triple::amdgcn))
 return;
   for (auto  : StaticExternCValues) {

Please add a target hook for this instead of building a list of targets that 
don't support it.


https://reviews.llvm.org/D44987



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


[PATCH] D44985: Remove initializer for CUDA shared varirable

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

What exactly are you trying to express here?  Are you just trying to make these 
external declarations when compiling for the device because `__shared__` 
variables are actually defined on the host?  That should be handled by the 
frontend by setting up the AST so that these declarations are not definitions.


https://reviews.llvm.org/D44985



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


[PATCH] D44747: Set calling convention for CUDA kernel

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

Matt, are you OK with the change from amdgcn backend point of view? Thanks.




Comment at: lib/Sema/SemaExpr.cpp:1669
+}
+  }
+

rjmccall wrote:
> You should use `getAs` here (no `const` necessary).  It's 
> possible to declare a function with a typedef of function type, you just 
> can't define it that way.
will do.


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: Set calling convention for CUDA kernel

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

LGTM.

If `__global__` is supported in C++ structures, you might also need to make 
sure that member function constants (`::kernel_function`) drop the CC.  And 
it might be a good idea to make sure that `decltype(kernel_function)` doesn't 
have a problem with it, either, since that does do some special-case work.




Comment at: lib/Sema/SemaExpr.cpp:1669
+}
+  }
+

You should use `getAs` here (no `const` necessary).  It's 
possible to declare a function with a typedef of function type, you just can't 
define it that way.


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] D44883: [Sema] Extend -Wself-assign and -Wself-assign-field to warn on overloaded self-assignment (classes)

2018-03-28 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/Sema/SemaExpr.cpp:12093
+break;
+  }
+

lebedev.ri wrote:
> rjmccall wrote:
> > I think doing this here can result in double-warning if the overload 
> > resolves to a builtin operator.  Now, it might not actually be possible for 
> > that to combine with the requirements for self-assignment, but still, I 
> > think the right place to diagnose this for C++ is the same place we call 
> > DiagnoseSelfMove in CreateOverloadedBinOp.
> > 
> > Can CheckIdentityFieldAssignment just be integrated with 
> > DiagnoseSelfAssignment so that callers don't need to do call both?
> > I think the right place to diagnose this for C++ is the same place we call 
> > DiagnoseSelfMove in CreateOverloadedBinOp.
> 
> ```
> switch (Opc) {
> case BO_Assign:
> case BO_DivAssign:
> case BO_SubAssign:
> case BO_AndAssign:
> case BO_OrAssign:
> case BO_XorAssign:
>   DiagnoseSelfAssignment(Args[0], Args[1], OpLoc);
>   CheckIdentityFieldAssignment(Args[0], Args[1], OpLoc);
>   break;
> default:
>   break;
> }
> 
> // Check for a self move.
> if (Op == OO_Equal)
>   DiagnoseSelfMove(Args[0], Args[1], OpLoc);
> ```
> 
> 
> ^ That does not appear to work. Pretty much all these tests start to fail.
> 
Okay.  It's possible that my suggestion is wrong.  Can you explain more how 
they fail?


Repository:
  rC Clang

https://reviews.llvm.org/D44883



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


[PATCH] D44985: Remove initializer for CUDA shared varirable

2018-03-28 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: test/CodeGenCUDA/device-var-init.cu:121
 __device__ void df() {
+  // AMDGCN:  %[[ec:.*]] = addrspacecast %struct.EC addrspace(5)* %ec to 
%struct.EC*
+  // AMDGCN:  %[[ed:.*]] = addrspacecast %struct.ED addrspace(5)* %ed to 
%struct.ED*

tra wrote:
> Perhaps it would make sense to capture there names for NVPTX as well and 
> avoid duplicating all the checks below.
will do when committing.


https://reviews.llvm.org/D44985



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


[PATCH] D44985: Remove initializer for CUDA shared varirable

2018-03-28 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: test/CodeGenCUDA/device-var-init.cu:121
 __device__ void df() {
+  // AMDGCN:  %[[ec:.*]] = addrspacecast %struct.EC addrspace(5)* %ec to 
%struct.EC*
+  // AMDGCN:  %[[ed:.*]] = addrspacecast %struct.ED addrspace(5)* %ed to 
%struct.ED*

Perhaps it would make sense to capture there names for NVPTX as well and avoid 
duplicating all the checks below.


https://reviews.llvm.org/D44985



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


[PATCH] D44801: Add the -fsanitize=shadow-call-stack flag

2018-03-28 Thread Vlad Tsyrklevich via Phabricator via cfe-commits
vlad.tsyrklevich added inline comments.



Comment at: docs/ShadowCallStack.rst:14
+buffer overflows. It works by saving a function's return address to a
+separately allocated 'shadow call stack' in the function prolog and checking 
the
+return address on the stack against the shadow call stack in the function

kcc wrote:
> kcc wrote:
> > prologue/epilogue? 
> > (it's your native tongue, not mine, though)
> PTAL
Forgot to submit this comment: It's used both ways across LLVM but I chose to 
go with this one just because that's how the PrologEpilogInserter pass wrote it.


Repository:
  rC Clang

https://reviews.llvm.org/D44801



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


[PATCH] D44727: [RISCV] Extend getTargetDefines for RISCVTargetInfo

2018-03-28 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

Do the macros you're defining here match gcc?




Comment at: lib/Basic/Targets/RISCV.cpp:68
+
+bool RISCVTargetInfo::hasFeature(StringRef Feature) const {
+  return llvm::StringSwitch(Feature)

asb wrote:
> It seems a number of other targets also return true for the archname, e.g. 
> "riscv".
> 
> Is it the case that hasFeature should always support at least everything 
> detected by handleTargetFeatures? If so, a comment to document this would be 
> helpful.
> 
> I can see this method was introduced in rC149227 and is primarily motivated 
> by module requirements.
> 
> @doug.gregor / @rsmith : could you please advise on the implementation and 
> testing of this function? Which features should be hasFeature check for? I 
> note that e.g. lib/Basic/Targets/ARM.cpp only supports a subset of the 
> features in hasFeature compared to handleTargetFeatures.
I think your assessment is right... and also, it looks like we have poor test 
coverage for the set of features which are actually supported.  So probably 
some targets are missing relevant features.

Should be straightforward to test, I think; you just need to write a module.map 
with appropriate "requires" lines, and a test file which tries to include those 
modules.  See test/Modules/Inputs/module.map.


Repository:
  rC Clang

https://reviews.llvm.org/D44727



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


r328723 - [MS] Fix bug in method vfptr location code

2018-03-28 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Wed Mar 28 11:23:35 2018
New Revision: 328723

URL: http://llvm.org/viewvc/llvm-project?rev=328723=rev
Log:
[MS] Fix bug in method vfptr location code

We were assuming that vbtable indices were assigned in layout order in
our comparison, which is not the case. When a virtual method, such as
the destructor, appears in multiple vftables, the vftable that appears
first in object layout order is the one that points to the main
implementation of that method. The later vftables use thunks.

In this layout, we adjusted "this" in the main implementation by the
amount that is appropriate for 'B' instead of 'A', even though the main
implementation is found in D's vftable for A:

  struct A {
virtual ~A() {}
  };
  struct B {
virtual ~B() {}
  };
  struct C : virtual B {};
  struct D : virtual A, C {};

D's layout looks like:
   0 D subobject (empty)
   0 C base suboject
   8 A base subobject
  16 B base subobject

With this fix, we correctly adjust by -8 in D's deleting destructor
instead of -16.

Fixes PR36921.

Modified:
cfe/trunk/lib/AST/VTableBuilder.cpp
cfe/trunk/test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp

Modified: cfe/trunk/lib/AST/VTableBuilder.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/VTableBuilder.cpp?rev=328723=328722=328723=diff
==
--- cfe/trunk/lib/AST/VTableBuilder.cpp (original)
+++ cfe/trunk/lib/AST/VTableBuilder.cpp Wed Mar 28 11:23:35 2018
@@ -3544,6 +3544,19 @@ static void computeFullPathsForVFTables(
   }
 }
 
+static bool
+vfptrIsEarlierInMDC(const ASTRecordLayout ,
+const MicrosoftVTableContext::MethodVFTableLocation ,
+const MicrosoftVTableContext::MethodVFTableLocation ) {
+  CharUnits L = LHS.VFPtrOffset;
+  CharUnits R = RHS.VFPtrOffset;
+  if (LHS.VBase)
+L += Layout.getVBaseClassOffset(LHS.VBase);
+  if (RHS.VBase)
+R += Layout.getVBaseClassOffset(RHS.VBase);
+  return L < R;
+}
+
 void MicrosoftVTableContext::computeVTableRelatedInformation(
 const CXXRecordDecl *RD) {
   assert(RD->isDynamicClass());
@@ -3574,12 +3587,15 @@ void MicrosoftVTableContext::computeVTab
 EmptyAddressPointsMap);
 Thunks.insert(Builder.thunks_begin(), Builder.thunks_end());
 
+const ASTRecordLayout  = Context.getASTRecordLayout(RD);
 for (const auto  : Builder.vtable_locations()) {
-  GlobalDecl GD = Loc.first;
-  MethodVFTableLocation NewLoc = Loc.second;
-  auto M = NewMethodLocations.find(GD);
-  if (M == NewMethodLocations.end() || NewLoc < M->second)
-NewMethodLocations[GD] = NewLoc;
+  auto Insert = NewMethodLocations.insert(Loc);
+  if (!Insert.second) {
+const MethodVFTableLocation  = Loc.second;
+MethodVFTableLocation  = Insert.first->second;
+if (vfptrIsEarlierInMDC(Layout, NewLoc, OldLoc))
+  OldLoc = NewLoc;
+  }
 }
   }
 

Modified: cfe/trunk/test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp?rev=328723=328722=328723=diff
==
--- cfe/trunk/test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp Wed Mar 28 
11:23:35 2018
@@ -538,3 +538,20 @@ D::D() : C() {}
 // CHECK:   %[[FIELD:.*]] = getelementptr inbounds i8, i8* %[[C_i8]], i32 8
 // CHECK:   call void @llvm.memset.p0i8.i32(i8* align 4 %[[FIELD]], i8 0, i32 
4, i1 false)
 }
+
+namespace pr36921 {
+struct A {
+  virtual ~A() {}
+};
+struct B {
+  virtual ~B() {}
+};
+struct C : virtual B {};
+struct D : virtual A, C {};
+D d;
+// CHECK-LABEL: define linkonce_odr dso_local x86_thiscallcc i8* 
@"??_GD@pr36921@@UAEPAXI@Z"(
+// CHECK:   %[[THIS:.*]] = load %"struct.pr36921::D"*, %"struct.pr36921::D"**
+// CHECK:   %[[THIS_UNADJ_i8:.*]] = bitcast %"struct.pr36921::D"* 
%[[THIS_RELOAD]] to i8*
+// CHECK:   %[[THIS_ADJ_i8:.*]] = getelementptr inbounds i8, i8* 
%[[THIS_UNADJ_i8]], i32 -4
+// CHECK:   %[[THIS:.*]] = bitcast i8* %[[THIS_ADJ_i8]] to 
%"struct.pr36921::D"*
+}


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


[PATCH] D44985: Remove initializer for CUDA shared varirable

2018-03-28 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 140110.
yaxunl retitled this revision from "Disable zeroinitializer for CUDA shared 
varirable for amdgcn target" to "Remove initializer for CUDA shared varirable".
yaxunl edited the summary of this revision.
yaxunl added a reviewer: tra.
yaxunl added a comment.

Revised by Artem's comments.


https://reviews.llvm.org/D44985

Files:
  lib/CodeGen/CGDecl.cpp
  test/CodeGenCUDA/address-spaces.cu
  test/CodeGenCUDA/device-var-init.cu

Index: test/CodeGenCUDA/device-var-init.cu
===
--- test/CodeGenCUDA/device-var-init.cu
+++ test/CodeGenCUDA/device-var-init.cu
@@ -1,10 +1,14 @@
 // REQUIRES: nvptx-registered-target
+// REQUIRES: amdgpu-registered-target
 
 // Make sure we don't allow dynamic initialization for device
 // variables, but accept empty constructors allowed by CUDA.
 
 // RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -fcuda-is-device -std=c++11 \
-// RUN: -fno-threadsafe-statics -emit-llvm -o - %s | FileCheck %s
+// RUN: -fno-threadsafe-statics -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK,NVPTX %s
+
+// RUN: %clang_cc1 -triple amdgcn -fcuda-is-device -std=c++11 \
+// RUN: -fno-threadsafe-statics -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK,AMDGCN %s
 
 #ifdef __clang__
 #include "Inputs/cuda.h"
@@ -105,68 +109,114 @@
 __constant__ EC_I_EC c_ec_i_ec;
 // CHECK: @c_ec_i_ec = addrspace(4) externally_initialized global %struct.EC_I_EC zeroinitializer,
 
+// CHECK: @_ZZ2dfvE4s_ec = internal addrspace(3) global %struct.EC undef
+// CHECK: @_ZZ2dfvE5s_etc = internal addrspace(3) global %struct.ETC undef
+
 // We should not emit global initializers for device-side variables.
 // CHECK-NOT: @__cxx_global_var_init
 
 // Make sure that initialization restrictions do not apply to local
 // variables.
 __device__ void df() {
+  // AMDGCN:  %[[ec:.*]] = addrspacecast %struct.EC addrspace(5)* %ec to %struct.EC*
+  // AMDGCN:  %[[ed:.*]] = addrspacecast %struct.ED addrspace(5)* %ed to %struct.ED*
+  // AMDGCN:  %[[ecd:.*]] = addrspacecast %struct.ECD addrspace(5)* %ecd to %struct.ECD*
+  // AMDGCN:  %[[etc:.*]] = addrspacecast %struct.ETC addrspace(5)* %etc to %struct.ETC*
+  // AMDGCN:  %[[uc:.*]] = addrspacecast %struct.UC addrspace(5)* %uc to %struct.UC*
+  // AMDGCN:  %[[ud:.*]] = addrspacecast %struct.UD addrspace(5)* %ud to %struct.UD*
+  // AMDGCN:  %[[eci:.*]] = addrspacecast %struct.ECI addrspace(5)* %eci to %struct.ECI*
+  // AMDGCN:  %[[nec:.*]] = addrspacecast %struct.NEC addrspace(5)* %nec to %struct.NEC*
+  // AMDGCN:  %[[ned:.*]] = addrspacecast %struct.NED addrspace(5)* %ned to %struct.NED*
+  // AMDGCN:  %[[ncv:.*]] = addrspacecast %struct.NCV addrspace(5)* %ncv to %struct.NCV*
+  // AMDGCN:  %[[vd:.*]] = addrspacecast %struct.VD addrspace(5)* %vd to %struct.VD*
+  // AMDGCN:  %[[ncf:.*]] = addrspacecast %struct.NCF addrspace(5)* %ncf to %struct.NCF*
+  // AMDGCN:  %[[ncfs:.*]] = addrspacecast %struct.NCFS addrspace(5)* %ncfs to %struct.NCFS*
+  // AMDGCN:  %[[utc:.*]] = addrspacecast %struct.UTC addrspace(5)* %utc to %struct.UTC*
+  // AMDGCN:  %[[netc:.*]] = addrspacecast %struct.NETC addrspace(5)* %netc to %struct.NETC*
+  // AMDGCN:  %[[ec_i_ec:.*]] = addrspacecast %struct.EC_I_EC addrspace(5)* %ec_i_ec to %struct.EC_I_EC*
+  // AMDGCN:  %[[ec_i_ec1:.*]] = addrspacecast %struct.EC_I_EC1 addrspace(5)* %ec_i_ec1 to %struct.EC_I_EC1*
+  // AMDGCN:  %[[t_v_t:.*]] = addrspacecast %struct.T_V_T addrspace(5)* %t_v_t to %struct.T_V_T*
+  // AMDGCN:  %[[t_b_nec:.*]] = addrspacecast %struct.T_B_NEC addrspace(5)* %t_b_nec to %struct.T_B_NEC*
+  // AMDGCN:  %[[t_f_nec:.*]] = addrspacecast %struct.T_F_NEC addrspace(5)* %t_f_nec to %struct.T_F_NEC*
+  // AMDGCN:  %[[t_fa_nec:.*]] = addrspacecast %struct.T_FA_NEC addrspace(5)* %t_fa_nec to %struct.T_FA_NEC*
+  // AMDGCN:  %[[t_b_ned:.*]] = addrspacecast %struct.T_B_NED addrspace(5)* %t_b_ned to %struct.T_B_NED*
+  // AMDGCN:  %[[t_f_ned:.*]] = addrspacecast %struct.T_F_NED addrspace(5)* %t_f_ned to %struct.T_F_NED*
+  // AMDGCN:  %[[t_fa_ned:.*]] = addrspacecast %struct.T_FA_NED addrspace(5)* %t_fa_ned to %struct.T_FA_NED*
+
   T t;
   // CHECK-NOT: call
   EC ec;
-  // CHECK:   call void @_ZN2ECC1Ev(%struct.EC* %ec)
+  // NVPTX:   call void @_ZN2ECC1Ev(%struct.EC* %ec)
+  // AMDGCN:  call void @_ZN2ECC1Ev(%struct.EC* %[[ec]])
   ED ed;
   // CHECK-NOT: call
   ECD ecd;
-  // CHECK:   call void @_ZN3ECDC1Ev(%struct.ECD* %ecd)
+  // NVPTX:   call void @_ZN3ECDC1Ev(%struct.ECD* %ecd)
+  // AMDGCN:  call void @_ZN3ECDC1Ev(%struct.ECD* %[[ecd]])
   ETC etc;
-  // CHECK:   call void @_ZN3ETCC1IJEEEDpT_(%struct.ETC* %etc)
+  // NVPTX:   call void @_ZN3ETCC1IJEEEDpT_(%struct.ETC* %etc)
+  // AMDGCN:  call void @_ZN3ETCC1IJEEEDpT_(%struct.ETC* %[[etc]])
   UC uc;
   // undefined constructor -- not allowed
-  // CHECK:   call void @_ZN2UCC1Ev(%struct.UC* %uc)
+  // NVPTX:   call void @_ZN2UCC1Ev(%struct.UC* %uc)
+  // AMDGCN:  call void 

  1   2   >