[PATCH] D57086: Ignore trailing NullStmts in StmtExprs for GCC compatibility

2019-06-09 Thread Dominic Ferreira via Phabricator via cfe-commits
domdom updated this revision to Diff 203775.
domdom added a comment.

Sorry I it's taken me a while to get back to this work. I've rebased the 
changes and taken advantage of the refactoring to stop modifying the 
CompoundStmt after creating it. This definitely simplified the changes required 
in Stmt.h, which is nice.

I've addressed the the need to update the TreeTransformer for the template 
case, and added a test case for that.

Something I should ask, it seems like GCC only ignores the NullStmts at the end 
if it's in C mode. Should clang match this behaviour exactly?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D57086/new/

https://reviews.llvm.org/D57086

Files:
  clang/include/clang/AST/Stmt.h
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/AST/ast-dump-stmt.c
  clang/test/CodeGen/exprs.c
  clang/test/Sema/statements.c
  clang/test/SemaCXX/statements.cpp

Index: clang/test/SemaCXX/statements.cpp
===
--- clang/test/SemaCXX/statements.cpp
+++ clang/test/SemaCXX/statements.cpp
@@ -37,3 +37,16 @@
 
 struct MMX_t {};
 void test6() { __asm__("" : "=m"(*(MMX_t *)0)); }
+
+template
+T test7(T v) {
+  return ({ // expected-warning{{use of GNU statement expression extension}}
+  T a = v;
+  a;;;
+  });
+}
+
+void test8() {
+  int a = test7(1);
+  double b = test7(2.0);
+}
Index: clang/test/Sema/statements.c
===
--- clang/test/Sema/statements.c
+++ clang/test/Sema/statements.c
@@ -119,3 +119,17 @@
 SIZE = sizeof(({unsigned long __ptr; __ptr;}))
   };
 }
+
+// GCC ignores empty statements at the end of compound expressions where the
+// result type is concerned.
+void test13() {
+  int a;
+  a = ({1;});
+  a = ({1;;});
+  a = ({int x = 1; (void)x;}); // expected-error {{assigning to 'int' from incompatible type 'void'}}
+  a = ({int x = 1; (void)x;;}); // expected-error {{assigning to 'int' from incompatible type 'void'}}
+}
+
+void test14() { return ({}); }
+void test15() { return ({}); }
+void test16() { return ({test:;;}); }
Index: clang/test/CodeGen/exprs.c
===
--- clang/test/CodeGen/exprs.c
+++ clang/test/CodeGen/exprs.c
@@ -196,3 +196,13 @@
 }
 // CHECK-LABEL: define void @f18()
 // CHECK: call i32 @returns_int()
+
+// Ensure the right stmt is returned
+int f19() {
+  return ({ 3;;4;; });
+}
+// CHECK-LABEL: define i32 @f19()
+// CHECK: [[T:%.*]] = alloca i32
+// CHECK: store i32 4, i32* [[T]]
+// CHECK: [[L:%.*]] = load i32, i32* [[T]]
+// CHECK: ret i32 [[L]]
Index: clang/test/AST/ast-dump-stmt.c
===
--- clang/test/AST/ast-dump-stmt.c
+++ clang/test/AST/ast-dump-stmt.c
@@ -372,4 +372,14 @@
   // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}}  'int' 10
   // CHECK-NEXT: ImplicitCastExpr
   // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}}  'int' lvalue Var 0x{{[^ ]*}} 'a' 'int'
+  ({int a = 10; a;;;});
+  // CHECK-NEXT: StmtExpr 0x{{[^ ]*}}  'int'
+  // CHECK-NEXT: CompoundStmt
+  // CHECK-NEXT: DeclStmt
+  // CHECK-NEXT: VarDecl 0x{{[^ ]*}}  col:9 used a 'int' cinit
+  // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}}  'int' 10
+  // CHECK-NEXT: ImplicitCastExpr
+  // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}}  'int' lvalue Var 0x{{[^ ]*}} 'a' 'int'
+  // CHECK-NEXT: NullStmt
+  // CHECK-NEXT: NullStmt
 }
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -6604,13 +6604,14 @@
   bool IsStmtExpr) {
   Sema::CompoundScopeRAII CompoundScope(getSema());
 
+  const Stmt *ExprResult = S->getStmtExprResult();
   bool SubStmtInvalid = false;
   bool SubStmtChanged = false;
   SmallVector Statements;
   for (auto *B : S->body()) {
 StmtResult Result = getDerived().TransformStmt(
 B,
-IsStmtExpr && B == S->body_back() ? SDK_StmtExprResult : SDK_Discarded);
+IsStmtExpr && B == ExprResult ? SDK_StmtExprResult : SDK_Discarded);
 
 if (Result.isInvalid()) {
   // Immediately fail if this was a DeclStmt, since it's very
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -13372,7 +13372,8 @@
   QualType Ty = Context.VoidTy;
   bool StmtExprMayBindToTemp = false;
   if (!Compound->body_empty()) {
-if (const auto *LastStmt = dyn_cast(Compound->body_back())) {
+// For GCC compatibility we get the last Stmt excluding trailing NullStmts.
+if (const auto *LastStmt = dyn_cast(Compound->getStmtExprResult())) {
   if (const Expr *Value = LastStmt->getExprStmt()) {
 StmtExprMayBindToTemp = true;
 Ty = Value->getType();
Index: clang/lib/Parse/P

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

2019-06-09 Thread Zhihao Yuan via Phabricator via cfe-commits
lichray updated this revision to Diff 203766.
lichray added a comment.

Update www


Repository:
  rCXX libc++

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D44865/new/

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
  www/cxx2a_status.html

Index: www/cxx2a_status.html
===
--- www/cxx2a_status.html
+++ www/cxx2a_status.html
@@ -115,7 +115,7 @@
 	https://wg21.link/P0591R4";>P0591R4LWGUtility functions to implement uses-allocator constructionSan Diego 
 	https://wg21.link/P0595R2";>P0595R2CWGP0595R2 std::is_constant_evaluated()San DiegoComplete9.0
 	https://wg21.link/P0602R4";>P0602R4LWGvariant and optional should propagate copy/move trivialitySan DiegoComplete8.0
-	https://wg21.link/P0608R3";>P0608R3LWGA sane variant converting constructorSan Diego 
+	https://wg21.link/P0608R3";>P0608R3LWGA sane variant converting constructorSan DiegoComplete9.0
 	https://wg21.link/P0655R1";>P0655R1LWGvisit: Explicit Return Type for visitSan Diego 
 	https://wg21.link/P0771R1";>P0771R1LWGstd::function move constructor should be noexceptSan DiegoComplete6.0
 	https://wg21.link/P0896R4";>P0896R4LWGThe One Ranges ProposalSan Diego 
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,8 +20,8 @@
 #include 
 #include 
 #include 
+#include 
 
-#include "test_convertible.hpp"
 #include "test_macros.h"
 #include "variant_test_helpers.hpp"
 
@@ -39,6 +39,8 @@
 
 struct AnyConstructible { template  AnyConstructible(T&&) {} };
 struct NoConstructible { NoConstructible() = delete; };
+template 
+struct RValueConvertibleFrom { RValueConvertibleFrom(T&&) {} };
 
 void test_T_ctor_noexcept() {
   {
@@ -53,7 +55,7 @@
 
 void test_T_ctor_sfinae() {
   {
-using V = std::variant;
+using V = std::variant;
 static_assert(!std::is_constructible::value, "ambiguous");
   }
   {
@@ -66,6 +68,32 @@
   "no matching constructor");
   }
   {
+using V = std::variant;
+static_assert(!std::is_constructible::value,
+  "no matching constructor");
+  }
+  {
+using V = std::variant, bool>;
+static_assert(!std::is_constructible>::value,
+  "no explicit bool in constructor");
+struct X {
+  operator void*();
+};
+static_assert(!std::is_constructible::value,
+  "no boolean conversion in constructor");
+static_assert(!std::is_constructible::value,
+  "no converted to bool in constructor");
+  }
+  {
+struct X {};
+struct Y {
+  operator X();
+};
+using V = std::variant;
+static_assert(std::is_constructible::value,
+  "regression on user-defined conversions in constructor");
+  }
+  {
 using V = std::variant;
 static_assert(
 !std::is_constructible>::value,
@@ -99,6 +127,34 @@
 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));
+  }
+  {
+std::variant> v1 = 42;
+assert(v1.index() == 0);
+
+int x = 42;
+std::variant, AnyConstructible> v2 = x;
+assert(v2.index() == 1);
+  }
 #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
@@ -22,6 +22,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "test_macros.h"
 #include "variant_test_helpers.hpp"
@@ -122,7 +123,7 @@
 
 void test_T_assignment_sfinae() {
   {
-using V = std::variant;
+using V = std::variant;
 static_assert(!std::is_assignable::value, "ambiguous");
   }
   {
@@ -133,6 +134,31 @@
 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, bool>;
+static_assert(!std::is_assignable>::value,
+  "no explicit bool in operator=");
+struct X {
+ 

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

2019-06-09 Thread Zhihao Yuan via Phabricator via cfe-commits
lichray marked an inline comment as done.
lichray added a comment.

In D44865#1535823 , @zoecarver wrote:

> - the spacing is different from the rest of libc++ (a lot of it was that way 
> before).


That's not something I can "fix" in this patch :(

> - since this is a paper it should probably be guarded with `#if 
> _LIBCPP_STD_VER > 17`

Marshall and me agreed that we are going to apply the paper as a "bugfix." We 
don't want to make the constructor behave differently under different language 
versions.

> - update the status in `www`.

Done.




Comment at: include/variant:1110
+template 
+struct __overload_bool : _Base {
+  using _Base::operator();

zoecarver wrote:
> Is this structure 100% necessary? Couldn't `__overload` add an overload to 
> take care of `bool`s? Maybe something like this:
>  
> ```
>   template
>   auto operator()(_Tp, _Up&&) const
> ->  enable_if_t<
> is_same_v<__uncvref_t<_Up>, bool>,
> __identity<_Tp>
> >;
> ```
I'm trying to reduce the compile time cost of SFINAE by putting the bool 
handling logic in specializations.


Repository:
  rCXX libc++

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D44865/new/

https://reviews.llvm.org/D44865



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


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

2019-06-09 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists added a comment.

In D44865#1391996 , @lichray wrote:

> Ping @mclow.lists @EricWF  ; the patch still applies, is there any other 
> thing I need to address?


Just a note: P0608R3 was adopted in San Diego.


Repository:
  rCXX libc++

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D44865/new/

https://reviews.llvm.org/D44865



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


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

2019-06-09 Thread Zoe Carver via Phabricator via cfe-commits
zoecarver added a comment.

A few minor things:

- the spacing is different from the rest of libc++ (a lot of it was that way 
before).
- since this is a paper it should probably be guarded with `#if _LIBCPP_STD_VER 
> 17`
- update the status in `www`.

Also, the standard says explicitly, "A variant is permitted to hold the same 
type more than once, and to hold differently cv-qualified versions of the same 
type." But currently, that is not allowed — not an issue with this patch, but 
something that should be fixed.




Comment at: include/variant:1110
+template 
+struct __overload_bool : _Base {
+  using _Base::operator();

Is this structure 100% necessary? Couldn't `__overload` add an overload to take 
care of `bool`s? Maybe something like this:
 
```
  template
  auto operator()(_Tp, _Up&&) const
->  enable_if_t<
is_same_v<__uncvref_t<_Up>, bool>,
__identity<_Tp>
>;
```


Repository:
  rCXX libc++

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D44865/new/

https://reviews.llvm.org/D44865



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


[PATCH] D62363: [X86] Enable intrinsics that convert float and bf16 data to each other

2019-06-09 Thread Kan Shengchen via Phabricator via cfe-commits
skan updated this revision to Diff 203762.
skan added a comment.

change mask paramater' s name from `__M` to `__U` in order to be consistent 
with other intrinsics in the file


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62363/new/

https://reviews.llvm.org/D62363

Files:
  include/clang/Basic/BuiltinsX86.def
  lib/CodeGen/CGBuiltin.cpp
  lib/Headers/avx512bf16intrin.h
  lib/Headers/avx512vlbf16intrin.h
  test/CodeGen/avx512bf16-builtins.c
  test/CodeGen/avx512vlbf16-builtins.c

Index: test/CodeGen/avx512vlbf16-builtins.c
===
--- test/CodeGen/avx512vlbf16-builtins.c
+++ test/CodeGen/avx512vlbf16-builtins.c
@@ -161,3 +161,39 @@
   // CHECK: ret <8 x float> %{{.*}}
   return _mm256_mask_dpbf16_ps(D, U, A, B);
 }
+
+__bfloat16 test_mm_cvtness_sbh(float A) {
+  // CHECK-LABEL: @test_mm_cvtness_sbh
+  // CHECK: @llvm.x86.avx512bf16.mask.cvtneps2bf16.128
+  // CHECK: ret i16 %{{.*}}
+  return _mm_cvtness_sbh(A);
+}
+
+__m256 test_mm256_cvtpbh_ps(__m128bh A) {
+  // CHECK-LABEL: @test_mm256_cvtpbh_ps
+  // CHECK: sext <8 x i16> %{{.*}} to <8 x i32>
+  // CHECK: @llvm.x86.avx2.pslli.d
+  // CHECK: bitcast <4 x i64> %{{.*}} to <8 x float>
+  // CHECK: ret <8 x float> %{{.*}}
+  return _mm256_cvtpbh_ps(A);
+}
+
+__m256 test_mm256_maskz_cvtpbh_ps(__mmask8 M, __m128bh A) {
+  // CHECK-LABEL: @test_mm256_maskz_cvtpbh_ps
+  // CHECK: sext <8 x i16> %{{.*}} to <8 x i32>
+  // CHECK: select <8 x i1> %{{.*}}, <8 x i32> %{{.*}}, <8 x i32> %{{.*}}
+  // CHECK: @llvm.x86.avx2.pslli.d
+  // CHECK: bitcast <4 x i64> %{{.*}} to <8 x float>
+  // CHECK: ret <8 x float> %{{.*}}
+  return _mm256_maskz_cvtpbh_ps(M, A);
+}
+
+__m256 test_mm256_mask_cvtpbh_ps(__m256 S, __mmask8 M, __m128bh A) {
+  // CHECK-LABEL: @test_mm256_mask_cvtpbh_ps
+  // CHECK: sext <8 x i16> %{{.*}} to <8 x i32>
+  // CHECK: @llvm.x86.avx2.pslli.d
+  // CHECK: select <8 x i1> %{{.*}}, <8 x i32> %{{.*}}, <8 x i32> %{{.*}}
+  // CHECK: bitcast <4 x i64> %{{.*}} to <8 x float>
+  // CHECK: ret <8 x float> %{{.*}}
+  return _mm256_mask_cvtpbh_ps(S, M, A);
+}
Index: test/CodeGen/avx512bf16-builtins.c
===
--- test/CodeGen/avx512bf16-builtins.c
+++ test/CodeGen/avx512bf16-builtins.c
@@ -4,46 +4,55 @@
 
 #include 
 
-__m512bh test_mm512_cvtne2ps2bf16(__m512 A, __m512 B) {
-  // CHECK-LABEL: @test_mm512_cvtne2ps2bf16
+float test_mm_cvtsbh_ss(__bfloat16 A) {
+  // CHECK-LABEL: @test_mm_cvtsbh_ss
+  // CHECK: zext i16 %{{.*}} to i32
+  // CHECK: shl i32 %{{.*}}, 16
+  // CHECK: bitcast i32 %{{.*}} to float
+  // CHECK: ret float %{{.*}}
+  return _mm_cvtsbh_ss(A);
+}
+
+__m512bh test_mm512_cvtne2ps_pbh(__m512 A, __m512 B) {
+  // CHECK-LABEL: @test_mm512_cvtne2ps_pbh
   // CHECK: @llvm.x86.avx512bf16.cvtne2ps2bf16.512
   // CHECK: ret <32 x i16> %{{.*}}
   return _mm512_cvtne2ps_pbh(A, B);
 }
 
-__m512bh test_mm512_maskz_cvtne2ps2bf16(__m512 A, __m512 B, __mmask32 U) {
-  // CHECK-LABEL: @test_mm512_maskz_cvtne2ps2bf16
+__m512bh test_mm512_maskz_cvtne2ps_pbh(__m512 A, __m512 B, __mmask32 U) {
+  // CHECK-LABEL: @test_mm512_maskz_cvtne2ps_pbh
   // CHECK: @llvm.x86.avx512bf16.cvtne2ps2bf16.512
   // CHECK: select <32 x i1> %{{.*}}, <32 x i16> %{{.*}}, <32 x i16> %{{.*}}
   // CHECK: ret <32 x i16> %{{.*}}
   return _mm512_maskz_cvtne2ps_pbh(U, A, B);
 }
 
-__m512bh test_mm512_mask_cvtne2ps2bf16(__m512bh C, __mmask32 U, __m512 A, __m512 B) {
-  // CHECK-LABEL: @test_mm512_mask_cvtne2ps2bf16
+__m512bh test_mm512_mask_cvtne2ps_pbh(__m512bh C, __mmask32 U, __m512 A, __m512 B) {
+  // CHECK-LABEL: @test_mm512_mask_cvtne2ps_pbh
   // CHECK: @llvm.x86.avx512bf16.cvtne2ps2bf16.512
   // CHECK: select <32 x i1> %{{.*}}, <32 x i16> %{{.*}}, <32 x i16> %{{.*}}
   // CHECK: ret <32 x i16> %{{.*}}
   return _mm512_mask_cvtne2ps_pbh(C, U, A, B);
 }
 
-__m256bh test_mm512_cvtneps2bf16(__m512 A) {
-  // CHECK-LABEL: @test_mm512_cvtneps2bf16
+__m256bh test_mm512_cvtneps_pbh(__m512 A) {
+  // CHECK-LABEL: @test_mm512_cvtneps_pbh
   // CHECK: @llvm.x86.avx512bf16.cvtneps2bf16.512
   // CHECK: ret <16 x i16> %{{.*}}
   return _mm512_cvtneps_pbh(A);
 }
 
-__m256bh test_mm512_mask_cvtneps2bf16(__m256bh C, __mmask16 U, __m512 A) {
-  // CHECK-LABEL: @test_mm512_mask_cvtneps2bf16
+__m256bh test_mm512_mask_cvtneps_pbh(__m256bh C, __mmask16 U, __m512 A) {
+  // CHECK-LABEL: @test_mm512_mask_cvtneps_pbh
   // CHECK: @llvm.x86.avx512bf16.cvtneps2bf16.512
   // CHECK: select <16 x i1> %{{.*}}, <16 x i16> %{{.*}}, <16 x i16> %{{.*}}
   // CHECK: ret <16 x i16> %{{.*}}
   return _mm512_mask_cvtneps_pbh(C, U, A);
 }
 
-__m256bh test_mm512_maskz_cvtneps2bf16(__m512 A, __mmask16 U) {
-  // CHECK-LABEL: @test_mm512_maskz_cvtneps2bf16
+__m256bh test_mm512_maskz_cvtneps_pbh(__m512 A, __mmask16 U) {
+  // CHECK-LABEL: @test_mm512_maskz_cvtneps_pbh
   // CHECK: @llvm.x86.avx512bf16.cvtneps2bf16.512
   // CHECK: select <16 x i1> %{{.*}}, <16 x i16> %{{.*}}, <16 x i16> %{{.

[PATCH] D63062: [clang-format] Added New Style Rule: BitFieldDeclsOnSeparateLines

2019-06-09 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay requested changes to this revision.
MyDeveloperDay added a comment.
This revision now requires changes to proceed.

You need to add a unit test in clang/unittests




Comment at: docs/ClangFormatStyleOptions.rst:195
+**BitFieldDeclsOnSeparateLines** (``bool``)
+  If ``true``, Linesup Bitfield Declarations.
+

Nit: Aligns Bitfield Declarations

I think Align is a better work than Linesup



Comment at: docs/ClangFormatStyleOptions.rst:197
+
+  This will lineup Bitfield declarations on consecutive lines. This
+  will result in formatting like

align



Comment at: docs/ClangFormatStyleOptions.rst:198
+  This will lineup Bitfield declarations on consecutive lines. This
+  will result in formatting like
+

end with :



Comment at: lib/Format/TokenAnnotator.cpp:2920
+  if(Right.Previous->is(tok::comma) && Style.BitFieldDeclsOnSeparateLines && 
Right.is(tok::identifier)){
+  if(Right.Next->is(tok::colon)){
+return true;

elide the {}


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63062/new/

https://reviews.llvm.org/D63062



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


[PATCH] D59919: [Attributor] Deduce "returned" argument attribute

2019-06-09 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert marked 2 inline comments as done.
jdoerfert added a comment.

Thanks for looking at this. I'll update the patch asap

In D59919#1535643 , @nicholas wrote:

> CHANGED: build-libcalls   NumNoUnwind 
> 4526 ->   3382 (   -25.276%)
>
> Why did the number of nounwinds drop?


I haven't looked into this but my initial guess would be that we removed code 
due to the "returned" information for which we then did not add nounwind. To be 
honest, I don't see how else it should have happened.




Comment at: llvm/lib/Transforms/IPO/Attributor.cpp:127
+if (Arg.hasReturnedAttr())
+  return gernericValueTraversal(CS.getArgOperand(Arg.getArgNo()), 
State,
+FollowValueCB, VisitValueCB);

nicholas wrote:
> LLVM generally has a preference for not recursing like this, it means that 
> the amount of stack space we need depends on the input IR and it's hard for a 
> user of llvm as a library to foresee or handle an out of stack condition.
> 
> Common practice is to structure it as a loop like:
> ```
> SmallVector Worklist;
> SmallSet Visited;
> Worklist.push_back(V);
> do {
>   Value *V = Worklist.pop_back_val();
>   if (!Visited.insert(V).second)
> continue;
>   V = V->stripPointerCasts();
>   // ...
> } while (!Worklist.empty());
> ```
> 
> Also, consider having some sort of loop iteration limit as a safety value 
> against runaway compile time.
Though there is not really stack space needed I see your point. I'll rewrite 
the recursion.




Comment at: llvm/lib/Transforms/IPO/Attributor.cpp:133
+  // recursion keep a record of the values we followed!
+  if (!FollowValueCB(V, State))
+return;

nicholas wrote:
> Offhand, I think placing this after the CS check is incorrect. I haven't 
> tried it out, but I expect the testcase that triggers infinite loop to look 
> something like this:
> 
> ```
> define i32 @test(i32 %A) {
> entry:
>   ret i32 0
> unreachableblock:
>   %B = call i32 @test(i32 %B)
>   ret i32 %B
> }
> ```
> 
> which should pass the verifier and trigger an infinite loop if you call 
> gernericValueTraversal on %B.
> 
> Also, if you really need a callback and not just a SmallSet named Visited, 
> I'd suggest calling the callback immediately before adding each value to the 
> Worklist (or as written not, call it on each value before recursing).
The test cases above passes just fine but again I see your point. I will add 
that one and the one below which breaks as you predicted. I'll rewrite the 
whole traversal.

```
declare i32 @test2(i32 returned %A);
define i32 @test(i32 %A) {
entry:
  ret i32 %A
unreachableblock:
  %B = call i32 @test2(i32 %B)
  ret i32 %B
}
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59919/new/

https://reviews.llvm.org/D59919



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


[PATCH] D63062: Added New Style Rule: BitFieldDeclsOnSeparateLines

2019-06-09 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan created this revision.
Manikishan added reviewers: aaron.ballman, rsmith.
Herald added a subscriber: krytarowski.
Herald added a project: clang.

This new Style rule is made as a part of adding support for NetBSD KNF in 
clang-format. This style Lines up BitField Declarations on consecutive lines 
with correct Indentation. The working of this Style rule shown below:

//Configuration
BitFieldDeclsOnSeparateLines: true

//Before Formatting:

unsigned int bas :3,  hh : 4, jjj : 8;

unsigned int baz:1,

  fuz:5, 
  zap:2;

//After Formatting:

unsigned int bas : 3,

  hh : 4,
  jjj : 8;

unsigned int baz : 1,

  fuz : 5,
  zap : 2;

This style is formatted even if the one-line declaration line is less than the 
column limit.

There is a minor Bug:
Comments after the bitfield in before the break line will not cause a proper 
indentation.

//Before Formatting:

unsigned int baz:1, /* foo*/

  fuz:5,  /*bar*/
  zap:2;

//After Formatting:
unsigned int  baz : 1, /* Bitfield; line up entries if desire*/

  fuz : 5, /*jgifjjggirrj*/
  zap : 2;


Repository:
  rC Clang

https://reviews.llvm.org/D63062

Files:
  docs/ClangFormatStyleOptions.rst
  include/clang/Format/Format.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/Format.cpp
  lib/Format/TokenAnnotator.cpp

Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2916,6 +2916,11 @@
 bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
  const FormatToken &Right) {
   const FormatToken &Left = *Right.Previous;
+  if(Right.Previous->is(tok::comma) && Style.BitFieldDeclsOnSeparateLines && Right.is(tok::identifier)){
+  if(Right.Next->is(tok::colon)){
+return true;
+  }
+  }
   if (Right.NewlinesBefore > 1 && Style.MaxEmptyLinesToKeep > 0)
 return true;
 
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -451,6 +451,7 @@
 IO.mapOptional("JavaScriptWrapImports", Style.JavaScriptWrapImports);
 IO.mapOptional("KeepEmptyLinesAtTheStartOfBlocks",
Style.KeepEmptyLinesAtTheStartOfBlocks);
+IO.mapOptional("BitFieldDeclsOnSeparateLines", Style.BitFieldDeclsOnSeparateLines);
 IO.mapOptional("MacroBlockBegin", Style.MacroBlockBegin);
 IO.mapOptional("MacroBlockEnd", Style.MacroBlockEnd);
 IO.mapOptional("MaxEmptyLinesToKeep", Style.MaxEmptyLinesToKeep);
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -278,6 +278,10 @@
   const FormatToken &Current = *State.NextToken;
   const FormatToken &Previous = *Current.Previous;
   assert(&Previous == Current.Previous);
+  if(Previous.is(tok::comma) && Style.BitFieldDeclsOnSeparateLines && Current.is(tok::identifier)){
+  if(Current.Next->is(tok::colon))
+return true;
+  }
   if (!Current.CanBreakBefore && !(State.Stack.back().BreakBeforeClosingBrace &&
Current.closesBlockOrBlockTypeList(Style)))
 return false;
@@ -329,6 +333,11 @@
 bool ContinuationIndenter::mustBreak(const LineState &State) {
   const FormatToken &Current = *State.NextToken;
   const FormatToken &Previous = *Current.Previous;
+  if(Previous.is(tok::comma) && Style.BitFieldDeclsOnSeparateLines && Current.is(tok::identifier)){
+  if(Current.Next->is(tok::colon)){
+return true;
+  }
+  }
   if (Current.MustBreakBefore || Current.is(TT_InlineASMColon))
 return true;
   if (State.Stack.back().BreakBeforeClosingBrace &&
@@ -541,7 +550,7 @@
  unsigned ExtraSpaces) {
   FormatToken &Current = *State.NextToken;
   const FormatToken &Previous = *State.NextToken->Previous;
-  if (Current.is(tok::equal) &&
+  if (Current.isOneOf(tok::equal, tok::colon) &&
   (State.Line->First->is(tok::kw_for) || Current.NestingLevel == 0) &&
   State.Stack.back().VariablePos == 0) {
 State.Stack.back().VariablePos = State.Column;
Index: include/clang/Format/Format.h
===
--- include/clang/Format/Format.h
+++ include/clang/Format/Format.h
@@ -101,6 +101,16 @@
   /// \endcode
   bool AlignConsecutiveDeclarations;
 
+  /// If ``true``, Linesup Bitfield Declarations.
+  /// This will lineup Bitfield declarations on consecutive lines. This
+  /// will result in formatting like
+  /// \code
+  ///  unsigned int  baz : 1, /* Bitfield; line up entries if desire*/
+  ///fuz : 5,
+  ///zap : 2;
+  /// \endcode
+  bool BitFieldDeclsOnSeparateLines;
+
   /// Different styles for aligning escaped newlines.
   enum EscapedNewlineAlignmentStyle {
 /// Don't align escaped newlines.
@@ -1950,6 +1

[PATCH] D59919: [Attributor] Deduce "returned" argument attribute

2019-06-09 Thread Nick Lewycky via Phabricator via cfe-commits
nicholas added a comment.

> CHANGED: build-libcalls   NumNoUnwind 
> 4526 ->   3382 (   -25.276%)

Why did the number of nounwinds drop?




Comment at: llvm/lib/Transforms/IPO/Attributor.cpp:115
+template 
+static void gernericValueTraversal(Value *V, StateTy &State,
+   followValueCB_t &FollowValueCB,

Typo in "gerneric", should be "generic".



Comment at: llvm/lib/Transforms/IPO/Attributor.cpp:127
+if (Arg.hasReturnedAttr())
+  return gernericValueTraversal(CS.getArgOperand(Arg.getArgNo()), 
State,
+FollowValueCB, VisitValueCB);

LLVM generally has a preference for not recursing like this, it means that the 
amount of stack space we need depends on the input IR and it's hard for a user 
of llvm as a library to foresee or handle an out of stack condition.

Common practice is to structure it as a loop like:
```
SmallVector Worklist;
SmallSet Visited;
Worklist.push_back(V);
do {
  Value *V = Worklist.pop_back_val();
  if (!Visited.insert(V).second)
continue;
  V = V->stripPointerCasts();
  // ...
} while (!Worklist.empty());
```

Also, consider having some sort of loop iteration limit as a safety value 
against runaway compile time.



Comment at: llvm/lib/Transforms/IPO/Attributor.cpp:133
+  // recursion keep a record of the values we followed!
+  if (!FollowValueCB(V, State))
+return;

Offhand, I think placing this after the CS check is incorrect. I haven't tried 
it out, but I expect the testcase that triggers infinite loop to look something 
like this:

```
define i32 @test(i32 %A) {
entry:
  ret i32 0
unreachableblock:
  %B = call i32 @test(i32 %B)
  ret i32 %B
}
```

which should pass the verifier and trigger an infinite loop if you call 
gernericValueTraversal on %B.

Also, if you really need a callback and not just a SmallSet named Visited, I'd 
suggest calling the callback immediately before adding each value to the 
Worklist (or as written not, call it on each value before recursing).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59919/new/

https://reviews.llvm.org/D59919



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


[PATCH] D61838: [Sema] Suppress additional warnings for C's zero initializer

2019-06-09 Thread Peter Wu via Phabricator via cfe-commits
Lekensteyn added a comment.

@rsmith Are you happy with the changes, is it ready to be merged?


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D61838/new/

https://reviews.llvm.org/D61838



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


[PATCH] D59919: [Attributor] Deduce "returned" argument attribute

2019-06-09 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert updated this revision to Diff 203742.
jdoerfert added a comment.

Cleanup leftover arguments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59919/new/

https://reviews.llvm.org/D59919

Files:
  clang/test/CodeGenOpenCL/as_type.cl
  llvm/include/llvm/Transforms/IPO/Attributor.h
  llvm/lib/Transforms/IPO/Attributor.cpp
  llvm/test/Transforms/FunctionAttrs/arg_nocapture.ll
  llvm/test/Transforms/FunctionAttrs/arg_returned.ll
  llvm/test/Transforms/FunctionAttrs/read_write_returned_arguments_scc.ll

Index: llvm/test/Transforms/FunctionAttrs/read_write_returned_arguments_scc.ll
===
--- llvm/test/Transforms/FunctionAttrs/read_write_returned_arguments_scc.ll
+++ llvm/test/Transforms/FunctionAttrs/read_write_returned_arguments_scc.ll
@@ -31,7 +31,7 @@
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
 
 ; CHECK: Function Attrs: nounwind
-; CHECK-NEXT: define i32* @external_ret2_nrw(i32* %n0, i32* %r0, i32* %w0)
+; CHECK-NEXT: define i32* @external_ret2_nrw(i32* %n0, i32* %r0, i32* returned %w0)
 define i32* @external_ret2_nrw(i32* %n0, i32* %r0, i32* %w0) {
 entry:
   %call = call i32* @internal_ret0_nw(i32* %n0, i32* %w0)
@@ -42,7 +42,7 @@
 }
 
 ; CHECK: Function Attrs: nounwind
-; CHECK-NEXT: define internal i32* @internal_ret0_nw(i32* %n0, i32* %w0)
+; CHECK-NEXT: define internal i32* @internal_ret0_nw(i32* returned %n0, i32* %w0)
 define internal i32* @internal_ret0_nw(i32* %n0, i32* %w0) {
 entry:
   %r0 = alloca i32, align 4
@@ -71,7 +71,7 @@
 }
 
 ; CHECK: Function Attrs: nounwind
-; CHECK-NEXT: define internal i32* @internal_ret1_rrw(i32* %r0, i32* %r1, i32* %w0)
+; CHECK-NEXT: define internal i32* @internal_ret1_rrw(i32* %r0, i32* returned %r1, i32* %w0)
 define internal i32* @internal_ret1_rrw(i32* %r0, i32* %r1, i32* %w0) {
 entry:
   %0 = load i32, i32* %r0, align 4
@@ -122,7 +122,7 @@
 }
 
 ; CHECK: Function Attrs: nounwind
-; CHECK-NEXT: define internal i32* @internal_ret1_rw(i32* %r0, i32* %w0)
+; CHECK-NEXT: define internal i32* @internal_ret1_rw(i32* %r0, i32* returned %w0)
 define internal i32* @internal_ret1_rw(i32* %r0, i32* %w0) {
 entry:
   %0 = load i32, i32* %r0, align 4
@@ -148,7 +148,7 @@
 }
 
 ; CHECK: Function Attrs: nounwind
-; CHECK-NEXT: define i32* @external_source_ret2_nrw(i32* %n0, i32* %r0, i32* %w0)
+; CHECK-NEXT: define i32* @external_source_ret2_nrw(i32* %n0, i32* %r0, i32* returned %w0)
 define i32* @external_source_ret2_nrw(i32* %n0, i32* %r0, i32* %w0) {
 entry:
   %call = call i32* @external_sink_ret2_nrw(i32* %n0, i32* %r0, i32* %w0)
Index: llvm/test/Transforms/FunctionAttrs/arg_returned.ll
===
--- llvm/test/Transforms/FunctionAttrs/arg_returned.ll
+++ llvm/test/Transforms/FunctionAttrs/arg_returned.ll
@@ -1,5 +1,6 @@
-; RUN: opt -functionattrs -attributor -attributor-disable=false -S < %s | FileCheck %s
-; RUN: opt -functionattrs -attributor -attributor-disable=false -attributor-verify=true -S < %s | FileCheck %s
+; RUN: opt -functionattrs -S < %s | FileCheck %s --check-prefix=FNATTR
+; RUN: opt -attributor -attributor-disable=false -S < %s | FileCheck %s --check-prefix=ATTRIBUTOR
+; RUN: opt -attributor -attributor-disable=false -functionattrs -S < %s | FileCheck %s --check-prefix=BOTH
 ;
 ; Test cases specifically designed for the "returned" argument attribute.
 ; We use FIXME's to indicate problems and missing attributes.
@@ -7,16 +8,24 @@
 
 ; TEST SCC test returning an integer value argument
 ;
-; CHECK: Function Attrs: noinline norecurse nounwind readnone uwtable
-; CHECK: define i32 @sink_r0(i32 returned %r)
-;
-; FIXME: returned on %r missing:
-; CHECK: Function Attrs: noinline nounwind readnone uwtable
-; CHECK: define i32 @scc_r1(i32 %a, i32 %r, i32 %b)
-;
-; FIXME: returned on %r missing:
-; CHECK: Function Attrs: noinline nounwind readnone uwtable
-; CHECK: define i32 @scc_r2(i32 %a, i32 %b, i32 %r)
+; BOTH: Function Attrs: noinline norecurse nounwind readnone uwtable
+; BOTH: define i32 @sink_r0(i32 returned %r)
+; BOTH: Function Attrs: noinline nounwind readnone uwtable
+; BOTH: define i32 @scc_r1(i32 %a, i32 returned %r, i32 %b)
+; BOTH: Function Attrs: noinline nounwind readnone uwtable
+; BOTH: define i32 @scc_r2(i32 %a, i32 %b, i32 returned %r)
+; BOTH: Function Attrs: noinline nounwind readnone uwtable
+; BOTH: define i32 @scc_rX(i32 %a, i32 %b, i32 %r)
+;
+; FNATTR: define i32 @sink_r0(i32 returned %r)
+; FNATTR: define i32 @scc_r1(i32 %a, i32 %r, i32 %b)
+; FNATTR: define i32 @scc_r2(i32 %a, i32 %b, i32 %r)
+; FNATTR: define i32 @scc_rX(i32 %a, i32 %b, i32 %r)
+;
+; ATTRIBUTOR: define i32 @sink_r0(i32 returned %r)
+; ATTRIBUTOR: define i32 @scc_r1(i32 %a, i32 returned %r, i32 %b)
+; ATTRIBUTOR: define i32 @scc_r2(i32 %a, i32 %b, i32 returned %r)
+; ATTRIBUTOR: define i32 @scc_rX(i32 %a, i32 %b, i32 %r)
 ;
 ; int scc_r1(int a, int b, int r);
 ; int scc_r2(in

[PATCH] D59919: [Attributor] Deduce "returned" argument attribute

2019-06-09 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert updated this revision to Diff 203741.
jdoerfert added a comment.

Update to new Attributor design and more tests


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59919/new/

https://reviews.llvm.org/D59919

Files:
  clang/test/CodeGenOpenCL/as_type.cl
  llvm/include/llvm/Transforms/IPO/Attributor.h
  llvm/lib/Transforms/IPO/Attributor.cpp
  llvm/test/Transforms/FunctionAttrs/arg_nocapture.ll
  llvm/test/Transforms/FunctionAttrs/arg_returned.ll
  llvm/test/Transforms/FunctionAttrs/read_write_returned_arguments_scc.ll

Index: llvm/test/Transforms/FunctionAttrs/read_write_returned_arguments_scc.ll
===
--- llvm/test/Transforms/FunctionAttrs/read_write_returned_arguments_scc.ll
+++ llvm/test/Transforms/FunctionAttrs/read_write_returned_arguments_scc.ll
@@ -31,7 +31,7 @@
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
 
 ; CHECK: Function Attrs: nounwind
-; CHECK-NEXT: define i32* @external_ret2_nrw(i32* %n0, i32* %r0, i32* %w0)
+; CHECK-NEXT: define i32* @external_ret2_nrw(i32* %n0, i32* %r0, i32* returned %w0)
 define i32* @external_ret2_nrw(i32* %n0, i32* %r0, i32* %w0) {
 entry:
   %call = call i32* @internal_ret0_nw(i32* %n0, i32* %w0)
@@ -42,7 +42,7 @@
 }
 
 ; CHECK: Function Attrs: nounwind
-; CHECK-NEXT: define internal i32* @internal_ret0_nw(i32* %n0, i32* %w0)
+; CHECK-NEXT: define internal i32* @internal_ret0_nw(i32* returned %n0, i32* %w0)
 define internal i32* @internal_ret0_nw(i32* %n0, i32* %w0) {
 entry:
   %r0 = alloca i32, align 4
@@ -71,7 +71,7 @@
 }
 
 ; CHECK: Function Attrs: nounwind
-; CHECK-NEXT: define internal i32* @internal_ret1_rrw(i32* %r0, i32* %r1, i32* %w0)
+; CHECK-NEXT: define internal i32* @internal_ret1_rrw(i32* %r0, i32* returned %r1, i32* %w0)
 define internal i32* @internal_ret1_rrw(i32* %r0, i32* %r1, i32* %w0) {
 entry:
   %0 = load i32, i32* %r0, align 4
@@ -122,7 +122,7 @@
 }
 
 ; CHECK: Function Attrs: nounwind
-; CHECK-NEXT: define internal i32* @internal_ret1_rw(i32* %r0, i32* %w0)
+; CHECK-NEXT: define internal i32* @internal_ret1_rw(i32* %r0, i32* returned %w0)
 define internal i32* @internal_ret1_rw(i32* %r0, i32* %w0) {
 entry:
   %0 = load i32, i32* %r0, align 4
@@ -148,7 +148,7 @@
 }
 
 ; CHECK: Function Attrs: nounwind
-; CHECK-NEXT: define i32* @external_source_ret2_nrw(i32* %n0, i32* %r0, i32* %w0)
+; CHECK-NEXT: define i32* @external_source_ret2_nrw(i32* %n0, i32* %r0, i32* returned %w0)
 define i32* @external_source_ret2_nrw(i32* %n0, i32* %r0, i32* %w0) {
 entry:
   %call = call i32* @external_sink_ret2_nrw(i32* %n0, i32* %r0, i32* %w0)
Index: llvm/test/Transforms/FunctionAttrs/arg_returned.ll
===
--- llvm/test/Transforms/FunctionAttrs/arg_returned.ll
+++ llvm/test/Transforms/FunctionAttrs/arg_returned.ll
@@ -1,5 +1,6 @@
-; RUN: opt -functionattrs -attributor -attributor-disable=false -S < %s | FileCheck %s
-; RUN: opt -functionattrs -attributor -attributor-disable=false -attributor-verify=true -S < %s | FileCheck %s
+; RUN: opt -functionattrs -S < %s | FileCheck %s --check-prefix=FNATTR
+; RUN: opt -attributor -attributor-disable=false -S < %s | FileCheck %s --check-prefix=ATTRIBUTOR
+; RUN: opt -attributor -attributor-disable=false -functionattrs -S < %s | FileCheck %s --check-prefix=BOTH
 ;
 ; Test cases specifically designed for the "returned" argument attribute.
 ; We use FIXME's to indicate problems and missing attributes.
@@ -7,16 +8,24 @@
 
 ; TEST SCC test returning an integer value argument
 ;
-; CHECK: Function Attrs: noinline norecurse nounwind readnone uwtable
-; CHECK: define i32 @sink_r0(i32 returned %r)
-;
-; FIXME: returned on %r missing:
-; CHECK: Function Attrs: noinline nounwind readnone uwtable
-; CHECK: define i32 @scc_r1(i32 %a, i32 %r, i32 %b)
-;
-; FIXME: returned on %r missing:
-; CHECK: Function Attrs: noinline nounwind readnone uwtable
-; CHECK: define i32 @scc_r2(i32 %a, i32 %b, i32 %r)
+; BOTH: Function Attrs: noinline norecurse nounwind readnone uwtable
+; BOTH: define i32 @sink_r0(i32 returned %r)
+; BOTH: Function Attrs: noinline nounwind readnone uwtable
+; BOTH: define i32 @scc_r1(i32 %a, i32 returned %r, i32 %b)
+; BOTH: Function Attrs: noinline nounwind readnone uwtable
+; BOTH: define i32 @scc_r2(i32 %a, i32 %b, i32 returned %r)
+; BOTH: Function Attrs: noinline nounwind readnone uwtable
+; BOTH: define i32 @scc_rX(i32 %a, i32 %b, i32 %r)
+;
+; FNATTR: define i32 @sink_r0(i32 returned %r)
+; FNATTR: define i32 @scc_r1(i32 %a, i32 %r, i32 %b)
+; FNATTR: define i32 @scc_r2(i32 %a, i32 %b, i32 %r)
+; FNATTR: define i32 @scc_rX(i32 %a, i32 %b, i32 %r)
+;
+; ATTRIBUTOR: define i32 @sink_r0(i32 returned %r)
+; ATTRIBUTOR: define i32 @scc_r1(i32 %a, i32 returned %r, i32 %b)
+; ATTRIBUTOR: define i32 @scc_r2(i32 %a, i32 %b, i32 returned %r)
+; ATTRIBUTOR: define i32 @scc_rX(i32 %a, i32 %b, i32 %r)
 ;
 ; int scc_r1(int a, int b, int 

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

2019-06-09 Thread Zhihao Yuan via Phabricator via cfe-commits
lichray updated this revision to Diff 203733.
lichray added a comment.

Trivial rebase


Repository:
  rCXX libc++

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D44865/new/

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,8 +20,8 @@
 #include 
 #include 
 #include 
+#include 
 
-#include "test_convertible.hpp"
 #include "test_macros.h"
 #include "variant_test_helpers.hpp"
 
@@ -39,6 +39,8 @@
 
 struct AnyConstructible { template  AnyConstructible(T&&) {} };
 struct NoConstructible { NoConstructible() = delete; };
+template 
+struct RValueConvertibleFrom { RValueConvertibleFrom(T&&) {} };
 
 void test_T_ctor_noexcept() {
   {
@@ -53,7 +55,7 @@
 
 void test_T_ctor_sfinae() {
   {
-using V = std::variant;
+using V = std::variant;
 static_assert(!std::is_constructible::value, "ambiguous");
   }
   {
@@ -66,6 +68,32 @@
   "no matching constructor");
   }
   {
+using V = std::variant;
+static_assert(!std::is_constructible::value,
+  "no matching constructor");
+  }
+  {
+using V = std::variant, bool>;
+static_assert(!std::is_constructible>::value,
+  "no explicit bool in constructor");
+struct X {
+  operator void*();
+};
+static_assert(!std::is_constructible::value,
+  "no boolean conversion in constructor");
+static_assert(!std::is_constructible::value,
+  "no converted to bool in constructor");
+  }
+  {
+struct X {};
+struct Y {
+  operator X();
+};
+using V = std::variant;
+static_assert(std::is_constructible::value,
+  "regression on user-defined conversions in constructor");
+  }
+  {
 using V = std::variant;
 static_assert(
 !std::is_constructible>::value,
@@ -99,6 +127,34 @@
 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));
+  }
+  {
+std::variant> v1 = 42;
+assert(v1.index() == 0);
+
+int x = 42;
+std::variant, AnyConstructible> v2 = x;
+assert(v2.index() == 1);
+  }
 #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
@@ -22,6 +22,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "test_macros.h"
 #include "variant_test_helpers.hpp"
@@ -122,7 +123,7 @@
 
 void test_T_assignment_sfinae() {
   {
-using V = std::variant;
+using V = std::variant;
 static_assert(!std::is_assignable::value, "ambiguous");
   }
   {
@@ -133,6 +134,31 @@
 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, bool>;
+static_assert(!std::is_assignable>::value,
+  "no explicit bool in operator=");
+struct X {
+  operator void*();
+};
+static_assert(!std::is_assignable::value,
+  "no boolean conversion in operator=");
+static_assert(!std::is_assignable::value,
+  "no converted to bool in operator=");
+  }
+  {
+struct X {};
+struct Y {
+  operator X();
+};
+using V = std::variant;
+static_assert(std::is_assignable::value,
+  "regression on user-defined conversions in operator=");
+  }
 #if !defined(TEST_VARIANT_HAS_NO_REFERENCES)
   {
 using V = std::variant;
@@ -161,6 +187,37 @@
 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 = "bar";
+assert(v.index() == 0);
+assert(std::get<0>(v) == "bar");
+  }
+  {
+std::variant> v;
+  

[PATCH] D61790: [C++20] add Basic consteval specifier

2019-06-09 Thread Tyker via Phabricator via cfe-commits
Tyker updated this revision to Diff 203725.
Tyker marked 5 inline comments as done.
Tyker added a comment.

fixed requested changes.
also adapted lldb to AST change.
I will commit this when i have access.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D61790/new/

https://reviews.llvm.org/D61790

Files:
  clang/include/clang/AST/Decl.h
  clang/include/clang/AST/DeclBase.h
  clang/include/clang/AST/DeclCXX.h
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/Specifiers.h
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Sema/DeclSpec.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/Decl.cpp
  clang/lib/AST/DeclCXX.cpp
  clang/lib/AST/DeclPrinter.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/Parse/ParseCXXInlineMethods.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Parse/ParseTentative.cpp
  clang/lib/Sema/DeclSpec.cpp
  clang/lib/Sema/SemaCoroutine.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/test/SemaCXX/cxx2a-compat.cpp
  clang/test/SemaCXX/cxx2a-consteval.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
  lldb/source/Symbol/ClangASTContext.cpp

Index: lldb/source/Symbol/ClangASTContext.cpp
===
--- lldb/source/Symbol/ClangASTContext.cpp
+++ lldb/source/Symbol/ClangASTContext.cpp
@@ -2170,7 +2170,7 @@
   *ast, decl_ctx, SourceLocation(), SourceLocation(), declarationName,
   ClangUtil::GetQualType(function_clang_type), nullptr,
   (clang::StorageClass)storage, is_inline, hasWrittenPrototype,
-  isConstexprSpecified);
+  isConstexprSpecified ? CSK_constexpr : CSK_unspecified);
   if (func_decl)
 decl_ctx->addDecl(func_decl);
 
@@ -8210,7 +8210,7 @@
 clang::SourceLocation()),
 method_qual_type,
 nullptr, // TypeSourceInfo *
-explicit_spec, is_inline, is_artificial, false /*is_constexpr*/);
+explicit_spec, is_inline, is_artificial, CSK_unspecified);
 cxx_method_decl = cxx_ctor_decl;
   } else {
 clang::StorageClass SC = is_static ? clang::SC_Static : clang::SC_None;
@@ -8233,7 +8233,7 @@
 clang::SourceLocation()),
 method_qual_type,
 nullptr, // TypeSourceInfo *
-SC, is_inline, false /*is_constexpr*/, clang::SourceLocation());
+SC, is_inline, CSK_unspecified, clang::SourceLocation());
   } else if (num_params == 0) {
 // Conversion operators don't take params...
 cxx_method_decl = clang::CXXConversionDecl::Create(
@@ -8245,7 +8245,7 @@
 clang::SourceLocation()),
 method_qual_type,
 nullptr, // TypeSourceInfo *
-is_inline, explicit_spec, false /*is_constexpr*/,
+is_inline, explicit_spec, CSK_unspecified,
 clang::SourceLocation());
   }
 }
@@ -8256,7 +8256,7 @@
   clang::DeclarationNameInfo(decl_name, clang::SourceLocation()),
   method_qual_type,
   nullptr, // TypeSourceInfo *
-  SC, is_inline, false /*is_constexpr*/, clang::SourceLocation());
+  SC, is_inline, CSK_unspecified, clang::SourceLocation());
 }
   }
 
Index: lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
===
--- lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
@@ -2127,7 +2127,7 @@
   clang::FunctionDecl *func_decl = FunctionDecl::Create(
   *ast, context, SourceLocation(), SourceLocation(), decl_name, qual_type,
   nullptr, SC_Extern, isInlineSpecified, hasWrittenPrototype,
-  isConstexprSpecified);
+  isConstexprSpecified ? CSK_constexpr : CSK_unspecified);
 
   // We have to do more than just synthesize the FunctionDecl.  We have to
   // synthesize ParmVarDecls for all of the FunctionDecl's arguments.  To do
Index: clang/test/SemaCXX/cxx2a-consteval.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx2a-consteval.cpp
@@ -0,0 +1,58 @@
+// RUN: %clang_cc1 -std=c++2a -fsyntax-only %s -verify
+
+namespace basic_sema {
+
+consteval int f1(int i) {
+  return i;
+}
+
+consteval constexpr int f2(int i) { 
+  //expected-error@-1 {{cannot combine}}
+  return i;
+}
+
+constexpr auto l_eval = [](int i) consteval {
+
+  return i;
+};
+
+constexpr conste

[PATCH] D62399: [clang] Add storage for APValue in ConstantExpr

2019-06-09 Thread Tyker via Phabricator via cfe-commits
Tyker updated this revision to Diff 203723.
Tyker marked 4 inline comments as done.
Tyker edited the summary of this revision.
Tyker added a comment.

fixed requested changes.
i will commit it when i have access.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62399/new/

https://reviews.llvm.org/D62399

Files:
  clang/include/clang/AST/APValue.h
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/Expr.h
  clang/include/clang/AST/Stmt.h
  clang/include/clang/AST/TextNodeDumper.h
  clang/include/clang/Serialization/ASTReader.h
  clang/include/clang/Serialization/ASTWriter.h
  clang/lib/AST/APValue.cpp
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/test/AST/ast-dump-color.cpp
  llvm/include/llvm/ADT/APFloat.h
  llvm/lib/Support/APFloat.cpp

Index: llvm/lib/Support/APFloat.cpp
===
--- llvm/lib/Support/APFloat.cpp
+++ llvm/lib/Support/APFloat.cpp
@@ -113,6 +113,42 @@
   static const fltSemantics semPPCDoubleDoubleLegacy = {1023, -1022 + 53,
 53 + 53, 128};
 
+  const llvm::fltSemantics &APFloatBase::EnumToSemantics(Semantics S) {
+switch (S) {
+case S_IEEEhalf:
+  return IEEEhalf();
+case S_IEEEsingle:
+  return IEEEsingle();
+case S_IEEEdouble:
+  return IEEEdouble();
+case S_x87DoubleExtended:
+  return x87DoubleExtended();
+case S_IEEEquad:
+  return IEEEquad();
+case S_PPCDoubleDouble:
+  return PPCDoubleDouble();
+}
+llvm_unreachable("Unrecognised floating semantics");
+  }
+
+  APFloatBase::Semantics
+  APFloatBase::SemanticsToEnum(const llvm::fltSemantics &Sem) {
+if (&Sem == &llvm::APFloat::IEEEhalf())
+  return S_IEEEhalf;
+else if (&Sem == &llvm::APFloat::IEEEsingle())
+  return S_IEEEsingle;
+else if (&Sem == &llvm::APFloat::IEEEdouble())
+  return S_IEEEdouble;
+else if (&Sem == &llvm::APFloat::x87DoubleExtended())
+  return S_x87DoubleExtended;
+else if (&Sem == &llvm::APFloat::IEEEquad())
+  return S_IEEEquad;
+else if (&Sem == &llvm::APFloat::PPCDoubleDouble())
+  return S_PPCDoubleDouble;
+else
+  llvm_unreachable("Unknown floating semantics");
+  }
+
   const fltSemantics &APFloatBase::IEEEhalf() {
 return semIEEEhalf;
   }
Index: llvm/include/llvm/ADT/APFloat.h
===
--- llvm/include/llvm/ADT/APFloat.h
+++ llvm/include/llvm/ADT/APFloat.h
@@ -147,6 +147,17 @@
 
   /// \name Floating Point Semantics.
   /// @{
+  enum Semantics {
+S_IEEEhalf,
+S_IEEEsingle,
+S_IEEEdouble,
+S_x87DoubleExtended,
+S_IEEEquad,
+S_PPCDoubleDouble
+  };
+
+  static const llvm::fltSemantics &EnumToSemantics(Semantics S);
+  static Semantics SemanticsToEnum(const llvm::fltSemantics &Sem);
 
   static const fltSemantics &IEEEhalf() LLVM_READNONE;
   static const fltSemantics &IEEEsingle() LLVM_READNONE;
Index: clang/test/AST/ast-dump-color.cpp
===
--- clang/test/AST/ast-dump-color.cpp
+++ clang/test/AST/ast-dump-color.cpp
@@ -49,13 +49,13 @@
 //CHECK: {{^}}[[Blue]]| |   |-[[RESET]][[MAGENTA]]IntegerLiteral[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]line:10:11[[RESET]]> [[Green]]'int'[[RESET]][[Cyan:.\[0;36m]][[RESET]][[Cyan]][[RESET]][[CYAN]] 1[[RESET]]{{$}}
 //CHECK: {{^}}[[Blue]]| |   `-[[RESET]][[MAGENTA]]CompoundStmt[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]col:14[[RESET]], [[Yellow]]line:15:3[[RESET]]>{{$}}
 //CHECK: {{^}}[[Blue]]| | |-[[RESET]][[MAGENTA]]CaseStmt[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]line:11:3[[RESET]], [[Yellow]]line:12:27[[RESET]]>{{$}}
-//CHECK: {{^}}[[Blue]]| | | |-[[RESET]][[MAGENTA]]ConstantExpr[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]line:11:8[[RESET]]> [[Green]]'int'[[RESET]][[Cyan]][[RESET]][[Cyan]][[RESET]]{{$}}
+//CHECK: {{^}}[[Blue]]| | | |-[[RESET]][[MAGENTA]]ConstantExpr[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]line:11:8[[RESET]]> [[Green]]'int'[[RESET]][[Cyan]][[RESET]][[Cyan]][[RESET]][[CYAN]] 1[[RESET]]{{$}}
 //CHECK: {{^}}[[Blue]]| | | | `-[[RESET]][[MAGENTA]]IntegerLiteral[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]col:8[[RESET]]> [[Green]]'int'[[RESET]][[Cyan]][[RESET]][[Cyan]][[RESET]][[CYAN]] 1[[RESET]]{{$}}
 //CHECK: {{^}}[[Blue]]| | | `-[[RESET]][[MAGENTA]]AttributedStmt[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]line:12:5[[RESET]], [[Yellow]]col:27[[RESET]]>{{$}}
 //CHECK: {{^}}[[Blue]]| | |   |-[[RESET]][[BLUE]]FallThroughAttr[[RESET]][[Yellow]] 0x{{