Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -13982,7 +13982,7 @@ class Sema final {
KernelConstStaticVariable
};

bool isKnownGoodSYCLDecl(const Decl *D);
bool isDeclAllowedInSYCLDeviceCode(const Decl *D);
void checkSYCLDeviceVarDecl(VarDecl *Var);
void copySYCLKernelAttrs(const CXXRecordDecl *KernelObj);
void ConstructOpenCLKernel(FunctionDecl *KernelCallerFunc, MangleContext &MC);
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Sema/SemaChecking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() && !isDeclAllowedInSYCLDeviceCode(FD))
SYCLDiagIfDeviceCode(Loc, diag::err_sycl_restrict)
<< Sema::KernelCallVariadicFunction;
}
Expand Down
8 changes: 7 additions & 1 deletion clang/lib/Sema/SemaSYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,15 @@ static bool IsSyclMathFunc(unsigned BuiltinID) {
return true;
}

bool Sema::isKnownGoodSYCLDecl(const Decl *D) {
bool Sema::isDeclAllowedInSYCLDeviceCode(const Decl *D) {
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(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)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 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.

#include "sycl.hpp"

using namespace sycl;
queue q;

int main() {
int *Ptr[2];
// expected-no-diagnostics
q.submit([&](handler &h) {
h.single_task<class kernelA>([=]() {
int *APtr = (int *)__builtin_assume_aligned(Ptr, 32);
*APtr = 42;
});
});
return 0;
}