From 5c3501f165ef7b7424124a2185510cd19f302665 Mon Sep 17 00:00:00 2001 From: Aleksander Fadeev Date: Wed, 4 Mar 2020 18:37:37 +0300 Subject: [PATCH] [SYCL] reqd_work_group_size attribute is reversed (fix #11) Signed-off-by: Aleksander Fadeev --- clang/lib/Sema/SemaDeclAttr.cpp | 46 +++++++++++--------- clang/test/SemaSYCL/reqd-work-group-size.cpp | 10 ++--- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 4cf219f286eee..d6957b2057f98 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -2895,16 +2895,18 @@ static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &Attr, if (const auto *A = D->getAttr()) if (A->getNumber() == 0) Result &= checkZeroDim(A, WGSize[0], WGSize[1], WGSize[2], - /*ReverseAttrs=*/ true); + /*ReverseAttrs=*/true); if (const auto *A = D->getAttr()) { - if (S.getLangOpts().SYCLIsDevice && !(WGSize[2] <= A->getXDim() && WGSize[1] <= A->getYDim() && + if (S.getLangOpts().SYCLIsDevice && + !(WGSize[2] <= A->getXDim() && WGSize[1] <= A->getYDim() && WGSize[0] <= A->getZDim())) { S.Diag(Attr.getLoc(), diag::err_conflicting_sycl_function_attributes) << Attr << A->getSpelling(); Result &= false; } - if (!S.getLangOpts().SYCLIsDevice && !(WGSize[0] <= A->getXDim() && WGSize[1] <= A->getYDim() && + if (!S.getLangOpts().SYCLIsDevice && + !(WGSize[0] <= A->getXDim() && WGSize[1] <= A->getYDim() && WGSize[2] <= A->getZDim())) { S.Diag(Attr.getLoc(), diag::err_conflicting_sycl_function_attributes) << Attr << A->getSpelling(); @@ -2912,18 +2914,20 @@ static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &Attr, } } if (const auto *A = D->getAttr()) { - if (S.getLangOpts().SYCLIsDevice && !(WGSize[2] >= A->getXDim() && WGSize[1] >= A->getYDim() && - WGSize[0] >= A->getZDim())) { - S.Diag(Attr.getLoc(), diag::err_conflicting_sycl_function_attributes) - << Attr << A->getSpelling(); - Result &= false; - } - if (!S.getLangOpts().SYCLIsDevice && !(WGSize[0] >= A->getXDim() && WGSize[1] >= A->getYDim() && - WGSize[2] >= A->getZDim())) { - S.Diag(Attr.getLoc(), diag::err_conflicting_sycl_function_attributes) - << Attr << A->getSpelling(); - Result &= false; - } + if (S.getLangOpts().SYCLIsDevice && + !(WGSize[2] >= A->getXDim() && WGSize[1] >= A->getYDim() && + WGSize[0] >= A->getZDim())) { + S.Diag(Attr.getLoc(), diag::err_conflicting_sycl_function_attributes) + << Attr << A->getSpelling(); + Result &= false; + } + if (!S.getLangOpts().SYCLIsDevice && + !(WGSize[0] >= A->getXDim() && WGSize[1] >= A->getYDim() && + WGSize[2] >= A->getZDim())) { + S.Diag(Attr.getLoc(), diag::err_conflicting_sycl_function_attributes) + << Attr << A->getSpelling(); + Result &= false; + } } return Result; } @@ -2951,13 +2955,13 @@ static void handleWorkGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) { return; WorkGroupAttr *Existing = D->getAttr(); - if (S.getLangOpts().SYCLIsDevice && Existing && !(Existing->getXDim() == WGSize[2] && - Existing->getYDim() == WGSize[1] && - Existing->getZDim() == WGSize[0])) + if (S.getLangOpts().SYCLIsDevice && Existing && + !(Existing->getXDim() == WGSize[2] && Existing->getYDim() == WGSize[1] && + Existing->getZDim() == WGSize[0])) S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL; - if (!S.getLangOpts().SYCLIsDevice && Existing && !(Existing->getXDim() == WGSize[0] && - Existing->getYDim() == WGSize[1] && - Existing->getZDim() == WGSize[2])) + if (!S.getLangOpts().SYCLIsDevice && Existing && + !(Existing->getXDim() == WGSize[0] && Existing->getYDim() == WGSize[1] && + Existing->getZDim() == WGSize[2])) S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL; if (S.getLangOpts().SYCLIsDevice) diff --git a/clang/test/SemaSYCL/reqd-work-group-size.cpp b/clang/test/SemaSYCL/reqd-work-group-size.cpp index 722f4c20f6f8b..0d01c081e06c5 100644 --- a/clang/test/SemaSYCL/reqd-work-group-size.cpp +++ b/clang/test/SemaSYCL/reqd-work-group-size.cpp @@ -7,7 +7,6 @@ class Functor { public: [[cl::reqd_work_group_size(4, 1, 1)]] void operator()() {} - }; template @@ -24,10 +23,10 @@ void bar() { // expected-note@-1 {{conflicting attribute is here}} [[cl::reqd_work_group_size(32, 1, 1)]] void f32x1x1() {} // expected-note {{conflicting attribute is here}} -[[cl::reqd_work_group_size(16, 1, 1)]] void f16x1x1() {} // expected-note {{conflicting attribute is here}} +[[cl::reqd_work_group_size(16, 1, 1)]] void f16x1x1() {} // expected-note {{conflicting attribute is here}} [[cl::reqd_work_group_size(16, 16, 1)]] void f16x16x1() {} // expected-note {{conflicting attribute is here}} -[[cl::reqd_work_group_size(32, 32, 1)]] void f32x32x1() {} // expected-note {{conflicting attribute is here}} +[[cl::reqd_work_group_size(32, 32, 1)]] void f32x32x1() {} // expected-note {{conflicting attribute is here}} [[cl::reqd_work_group_size(32, 32, 32)]] void f32x32x32() {} // expected-note {{conflicting attribute is here}} class Functor16 { @@ -78,10 +77,9 @@ void bar() { kernel(fattr); kernel([]() [[cl::reqd_work_group_size(32, 32, 32), cl::reqd_work_group_size(32, 32, 32)]] { - f32x32x32(); + f32x32x32(); }); - #ifdef TRIGGER_ERROR Functor8 f8; kernel(f8); @@ -102,7 +100,7 @@ void bar() { }); // expected-error@+1 {{expected variable name or 'this' in lambda capture list}} - kernel([[cl::reqd_work_group_size(32, 32, 32)]] []() { + kernel([[cl::reqd_work_group_size(32, 32, 32)]][]() { f32x32x32(); });