From 25c59735722d184a85d8a8ba37fdea35dce00593 Mon Sep 17 00:00:00 2001 From: srividya sundaram Date: Mon, 5 Sep 2022 22:14:44 -0700 Subject: [PATCH 1/7] [SYCL] Remove restriction on buitin_assume_aligned --- clang/include/clang/Sema/Sema.h | 2 +- clang/lib/Sema/SemaChecking.cpp | 4 ++-- clang/lib/Sema/SemaSYCL.cpp | 9 ++++++++- ...ove-restriction-builtin-assume-aligned.cpp | 20 +++++++++++++++++++ 4 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 clang/test/SemaSYCL/remove-restriction-builtin-assume-aligned.cpp diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index a61ad4da77950..08778042d4f5f 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -13975,7 +13975,7 @@ class Sema final { KernelConstStaticVariable }; - bool isKnownGoodSYCLDecl(const Decl *D); + bool isDeclAllowedInKernel(const Decl *D); void checkSYCLDeviceVarDecl(VarDecl *Var); void copySYCLKernelAttrs(const CXXRecordDecl *KernelObj); void ConstructOpenCLKernel(FunctionDecl *KernelCallerFunc, MangleContext &MC); diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index b1a012cc12789..930f0f995ee64 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -5967,8 +5967,8 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, CheckSYCLKernelCall(FD, Range, Args); // Diagnose variadic calls in SYCL. - if (FD && FD ->isVariadic() && getLangOpts().SYCLIsDevice && - !isUnevaluatedContext() && !isKnownGoodSYCLDecl(FD)) + if (FD && FD->isVariadic() && getLangOpts().SYCLIsDevice && + !isUnevaluatedContext() && !isDeclAllowedInKernel(FD)) SYCLDiagIfDeviceCode(Loc, diag::err_sycl_restrict) << Sema::KernelCallVariadicFunction; } diff --git a/clang/lib/Sema/SemaSYCL.cpp b/clang/lib/Sema/SemaSYCL.cpp index c1424fa65705e..48eb83c023720 100644 --- a/clang/lib/Sema/SemaSYCL.cpp +++ b/clang/lib/Sema/SemaSYCL.cpp @@ -403,9 +403,16 @@ static bool IsSyclMathFunc(unsigned BuiltinID) { return true; } -bool Sema::isKnownGoodSYCLDecl(const Decl *D) { +bool Sema::isDeclAllowedInKernel(const Decl *D) { if (const FunctionDecl *FD = dyn_cast(D)) { const IdentifierInfo *II = FD->getIdentifier(); + + // Allow __builtin_assume_aligned to be called from within device code. + if (FD->getBuiltinID() && + FD->getBuiltinID() == Builtin::BI__builtin_assume_aligned) { + return true; + } + // Allow to use `::printf` only for CUDA. if (Context.getTargetInfo().getTriple().isNVPTX()) { if (FD->getBuiltinID() == Builtin::BIprintf) diff --git a/clang/test/SemaSYCL/remove-restriction-builtin-assume-aligned.cpp b/clang/test/SemaSYCL/remove-restriction-builtin-assume-aligned.cpp new file mode 100644 index 0000000000000..aff8997307834 --- /dev/null +++ b/clang/test/SemaSYCL/remove-restriction-builtin-assume-aligned.cpp @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 -fsycl-is-device -internal-isystem %S/Inputs -sycl-std=2020 -verify -pedantic -fsyntax-only %s +// This test checks if __builtin_assume_aligned does not throw an error when +// called from within device code. + +#include "sycl.hpp" + +using namespace sycl; +queue q; + +int main() { + int *Ptr[2]; + // expected-no-diagnostics + q.submit([&](handler &h) { + h.single_task([=]() { + int *APtr = (int *)__builtin_assume_aligned(Ptr, 32); + *APtr = 42; + }); + }); + return 0; +} From ca3797e16f90755d4f88e953afb0d14c7387658e Mon Sep 17 00:00:00 2001 From: Srividya Sundaram Date: Mon, 5 Sep 2022 22:27:35 -0700 Subject: [PATCH 2/7] Update remove-restriction-builtin-assume-aligned.cpp --- .../test/SemaSYCL/remove-restriction-builtin-assume-aligned.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/clang/test/SemaSYCL/remove-restriction-builtin-assume-aligned.cpp b/clang/test/SemaSYCL/remove-restriction-builtin-assume-aligned.cpp index aff8997307834..2db229e72822b 100644 --- a/clang/test/SemaSYCL/remove-restriction-builtin-assume-aligned.cpp +++ b/clang/test/SemaSYCL/remove-restriction-builtin-assume-aligned.cpp @@ -18,3 +18,4 @@ int main() { }); return 0; } + From 39dba379e8c1652ee97b070d60ecc0a082304b01 Mon Sep 17 00:00:00 2001 From: Srividya Sundaram Date: Tue, 6 Sep 2022 09:46:40 -0700 Subject: [PATCH 3/7] Update SemaSYCL.cpp --- clang/lib/Sema/SemaSYCL.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/clang/lib/Sema/SemaSYCL.cpp b/clang/lib/Sema/SemaSYCL.cpp index 48eb83c023720..d8cfa483ba542 100644 --- a/clang/lib/Sema/SemaSYCL.cpp +++ b/clang/lib/Sema/SemaSYCL.cpp @@ -409,9 +409,8 @@ bool Sema::isDeclAllowedInKernel(const Decl *D) { // Allow __builtin_assume_aligned to be called from within device code. if (FD->getBuiltinID() && - FD->getBuiltinID() == Builtin::BI__builtin_assume_aligned) { + FD->getBuiltinID() == Builtin::BI__builtin_assume_aligned) return true; - } // Allow to use `::printf` only for CUDA. if (Context.getTargetInfo().getTriple().isNVPTX()) { From 09ab7e6c86968e8a4023ee2cdcb629e443d64f5d Mon Sep 17 00:00:00 2001 From: Srividya Sundaram Date: Tue, 6 Sep 2022 20:19:31 -0700 Subject: [PATCH 4/7] Update remove-restriction-builtin-assume-aligned.cpp --- .../test/SemaSYCL/remove-restriction-builtin-assume-aligned.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/SemaSYCL/remove-restriction-builtin-assume-aligned.cpp b/clang/test/SemaSYCL/remove-restriction-builtin-assume-aligned.cpp index 2db229e72822b..710ddc916a741 100644 --- a/clang/test/SemaSYCL/remove-restriction-builtin-assume-aligned.cpp +++ b/clang/test/SemaSYCL/remove-restriction-builtin-assume-aligned.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsycl-is-device -internal-isystem %S/Inputs -sycl-std=2020 -verify -pedantic -fsyntax-only %s +// RUN: %clang_cc1 -fsycl-is-device -internal-isystem %S/Inputs -sycl-std=2020 -verify -fsyntax-only %s // This test checks if __builtin_assume_aligned does not throw an error when // called from within device code. From 217493361068e43d24ea80ef2a02e5acb67ea895 Mon Sep 17 00:00:00 2001 From: Srividya Sundaram Date: Wed, 7 Sep 2022 09:01:04 -0700 Subject: [PATCH 5/7] Update Sema.h --- clang/include/clang/Sema/Sema.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 08778042d4f5f..c39ea2a0e7b89 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -13975,7 +13975,7 @@ class Sema final { KernelConstStaticVariable }; - bool isDeclAllowedInKernel(const Decl *D); + bool isDeclAllowedInSYCLDeviceCode(const Decl *D); void checkSYCLDeviceVarDecl(VarDecl *Var); void copySYCLKernelAttrs(const CXXRecordDecl *KernelObj); void ConstructOpenCLKernel(FunctionDecl *KernelCallerFunc, MangleContext &MC); From eb79b501cc02bfb075c0be88eb2fe890d3542dd5 Mon Sep 17 00:00:00 2001 From: Srividya Sundaram Date: Wed, 7 Sep 2022 09:01:42 -0700 Subject: [PATCH 6/7] Update SemaChecking.cpp --- clang/lib/Sema/SemaChecking.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 930f0f995ee64..e0a952593a22b 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -5968,7 +5968,7 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, // Diagnose variadic calls in SYCL. if (FD && FD->isVariadic() && getLangOpts().SYCLIsDevice && - !isUnevaluatedContext() && !isDeclAllowedInKernel(FD)) + !isUnevaluatedContext() && !isDeclAllowedInSYCLDeviceCode(FD)) SYCLDiagIfDeviceCode(Loc, diag::err_sycl_restrict) << Sema::KernelCallVariadicFunction; } From 7f2bf90b84af34f207c8a8f60f38f8e72308c8ce Mon Sep 17 00:00:00 2001 From: Srividya Sundaram Date: Wed, 7 Sep 2022 09:02:20 -0700 Subject: [PATCH 7/7] Update SemaSYCL.cpp --- clang/lib/Sema/SemaSYCL.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaSYCL.cpp b/clang/lib/Sema/SemaSYCL.cpp index d8cfa483ba542..5bcb242e9770f 100644 --- a/clang/lib/Sema/SemaSYCL.cpp +++ b/clang/lib/Sema/SemaSYCL.cpp @@ -403,7 +403,7 @@ static bool IsSyclMathFunc(unsigned BuiltinID) { return true; } -bool Sema::isDeclAllowedInKernel(const Decl *D) { +bool Sema::isDeclAllowedInSYCLDeviceCode(const Decl *D) { if (const FunctionDecl *FD = dyn_cast(D)) { const IdentifierInfo *II = FD->getIdentifier();