Skip to content

[SYCL] Functions with variadic arguments should not get a diagnostic … #324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 18, 2019
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
3 changes: 2 additions & 1 deletion clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -9746,7 +9746,8 @@ def err_sycl_restrict : Error<
"|call through a function pointer"
"|allocate storage"
"|use inline assembly"
"|have a class with a virtual function table}0">;
"|have a class with a virtual function table"
"|call a variadic function}0">;
def err_sycl_virtual_types : Error<
"No class with a vtable can be used in a SYCL kernel or any code included in the kernel">;
def note_sycl_used_here : Note<"used here">;
Expand Down
3 changes: 2 additions & 1 deletion clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -11326,7 +11326,8 @@ class Sema {
KernelCallFunctionPointer,
KernelAllocateStorage,
KernelUseAssembly,
KernelHavePolymorphicClass
KernelHavePolymorphicClass,
KernelCallVariadicFunction
};
DeviceDiagBuilder SYCLDiagIfDeviceCode(SourceLocation Loc, unsigned DiagID);
void ConstructOpenCLKernel(FunctionDecl *KernelCallerFunc);
Expand Down
6 changes: 6 additions & 0 deletions clang/lib/Sema/SemaSYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,9 @@ class MarkDeviceFunction : public RecursiveASTVisitor<MarkDeviceFunction> {
if (!Visited.insert(Ty).second)
return true;

if (const auto *ATy = dyn_cast<AttributedType>(Ty))
return CheckSYCLType(ATy->getModifiedType(), Loc, Visited);

if (const auto *CRD = Ty->getAsCXXRecordDecl()) {
// If the class is a forward declaration - skip it, because otherwise we
// would query property of class with no definition, which results in
Expand Down Expand Up @@ -354,6 +357,9 @@ class MarkDeviceFunction : public RecursiveASTVisitor<MarkDeviceFunction> {
}
}
} else if (const auto *FPTy = dyn_cast<FunctionProtoType>(Ty)) {
if (FPTy->isVariadic() && SemaRef.getLangOpts().SYCLIsDevice)
SemaRef.SYCLDiagIfDeviceCode(Loc.getBegin(), diag::err_sycl_restrict)
<< Sema::KernelCallVariadicFunction;
for (const auto &ParamTy : FPTy->param_types())
if (!CheckSYCLType(ParamTy, Loc, Visited))
return false;
Expand Down
5 changes: 0 additions & 5 deletions clang/lib/Sema/SemaType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7075,11 +7075,6 @@ static bool handleFunctionTypeAttr(TypeProcessingState &state, ParsedAttr &attr,
<< (int)Sema::CallingConventionIgnoredReason::VariadicFunction;

attr.setInvalid();
if (S.getLangOpts().SYCLIsDevice) {
S.SYCLDiagIfDeviceCode(attr.getLoc(), diag::err_cconv_varargs)
<< FunctionType::getNameForCallConv(CC);
return true;
} else
return S.Diag(attr.getLoc(), diag::err_cconv_varargs)
<< FunctionType::getNameForCallConv(CC);
}
Expand Down
24 changes: 24 additions & 0 deletions clang/test/SemaSYCL/sycl-varargs-cconv.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// RUN: %clang_cc1 -fsycl-is-device -verify -fsyntax-only -x c++ %s

int __cdecl foo(int, ...); // expected-no-error

float bar(float f, ...) { return ++f; } // expected-no-error

void bar() {
foo(5); // expected-no-error
bar(7.0f); // expected-no-error
}

template <typename name, typename Func>
__attribute__((sycl_kernel)) void kernel_single_task(Func kernelFunc) {
kernelFunc();
}

int main() {
//expected-error@+1 {{SYCL kernel cannot call a variadic function}}
kernel_single_task<class fake_kernel>([]() { foo(6); });
//expected-error@+1 {{SYCL kernel cannot call a variadic function}}
kernel_single_task<class fake_kernel>([]() { bar(9.0); });
bar();
return 0;
}