Skip to content

Commit 7966933

Browse files
committed
[SYCL] Functions with variadic arguments should not get a diagnostic about calling convention
Instead they should be diagnosed at the point of call. Signed-off-by: Premanand M Rao <[email protected]>
1 parent 19f99fe commit 7966933

File tree

5 files changed

+34
-7
lines changed

5 files changed

+34
-7
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9746,7 +9746,8 @@ def err_sycl_restrict : Error<
97469746
"|call through a function pointer"
97479747
"|allocate storage"
97489748
"|use inline assembly"
9749-
"|have a class with a virtual function table}0">;
9749+
"|have a class with a virtual function table"
9750+
"|call a variadic function}0">;
97509751
def err_sycl_virtual_types : Error<
97519752
"No class with a vtable can be used in a SYCL kernel or any code included in the kernel">;
97529753
def note_sycl_used_here : Note<"used here">;

clang/include/clang/Sema/Sema.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11326,7 +11326,8 @@ class Sema {
1132611326
KernelCallFunctionPointer,
1132711327
KernelAllocateStorage,
1132811328
KernelUseAssembly,
11329-
KernelHavePolymorphicClass
11329+
KernelHavePolymorphicClass,
11330+
KernelCallVariadicFunction
1133011331
};
1133111332
DeviceDiagBuilder SYCLDiagIfDeviceCode(SourceLocation Loc, unsigned DiagID);
1133211333
void ConstructOpenCLKernel(FunctionDecl *KernelCallerFunc);

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,9 @@ class MarkDeviceFunction : public RecursiveASTVisitor<MarkDeviceFunction> {
317317
if (!Visited.insert(Ty).second)
318318
return true;
319319

320+
if (const auto *ATy = dyn_cast<AttributedType>(Ty))
321+
return CheckSYCLType(ATy->getModifiedType(), Loc, Visited);
322+
320323
if (const auto *CRD = Ty->getAsCXXRecordDecl()) {
321324
// If the class is a forward declaration - skip it, because otherwise we
322325
// would query property of class with no definition, which results in
@@ -354,6 +357,9 @@ class MarkDeviceFunction : public RecursiveASTVisitor<MarkDeviceFunction> {
354357
}
355358
}
356359
} else if (const auto *FPTy = dyn_cast<FunctionProtoType>(Ty)) {
360+
if (FPTy->isVariadic() && SemaRef.getLangOpts().SYCLIsDevice)
361+
SemaRef.SYCLDiagIfDeviceCode(Loc.getBegin(), diag::err_sycl_restrict)
362+
<< Sema::KernelCallVariadicFunction;
357363
for (const auto &ParamTy : FPTy->param_types())
358364
if (!CheckSYCLType(ParamTy, Loc, Visited))
359365
return false;

clang/lib/Sema/SemaType.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7075,11 +7075,6 @@ static bool handleFunctionTypeAttr(TypeProcessingState &state, ParsedAttr &attr,
70757075
<< (int)Sema::CallingConventionIgnoredReason::VariadicFunction;
70767076

70777077
attr.setInvalid();
7078-
if (S.getLangOpts().SYCLIsDevice) {
7079-
S.SYCLDiagIfDeviceCode(attr.getLoc(), diag::err_cconv_varargs)
7080-
<< FunctionType::getNameForCallConv(CC);
7081-
return true;
7082-
} else
70837078
return S.Diag(attr.getLoc(), diag::err_cconv_varargs)
70847079
<< FunctionType::getNameForCallConv(CC);
70857080
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: %clang_cc1 -fsycl-is-device -verify -fsyntax-only -x c++ %s
2+
3+
int __cdecl foo(int, ...); // expected-no-error
4+
5+
float bar(float f, ...) { return ++f; } // expected-no-error
6+
7+
void bar() {
8+
foo(5); // expected-no-error
9+
bar(7.0f); // expected-no-error
10+
}
11+
12+
template <typename name, typename Func>
13+
__attribute__((sycl_kernel)) void kernel_single_task(Func kernelFunc) {
14+
kernelFunc();
15+
}
16+
17+
int main() {
18+
//expected-error@+1 {{SYCL kernel cannot call a variadic function}}
19+
kernel_single_task<class fake_kernel>([]() { foo(6); });
20+
//expected-error@+1 {{SYCL kernel cannot call a variadic function}}
21+
kernel_single_task<class fake_kernel>([]() { bar(9.0); });
22+
bar();
23+
return 0;
24+
}

0 commit comments

Comments
 (0)