Skip to content

Commit 948aabd

Browse files
committed
add error
Signed-off-by: Sarnie, Nick <[email protected]>
1 parent 68cf3dd commit 948aabd

File tree

4 files changed

+26
-36
lines changed

4 files changed

+26
-36
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4126,6 +4126,9 @@ def warn_missing_sdksettings_for_availability_checking : Warning<
41264126
"%0 availability is ignored without a valid 'SDKSettings.json' in the SDK">,
41274127
InGroup<DiagGroup<"ignored-availability-without-sdk-settings">>;
41284128

4129+
def err_hidden_device_kernel
4130+
: Error<"%0 is specified as a device kernel but it is not externally visible">;
4131+
41294132
// Thread Safety Attributes
41304133
def warn_thread_attribute_ignored : Warning<
41314134
"ignoring %0 attribute because its argument is invalid">,

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5206,7 +5206,12 @@ static void handleDeviceKernelAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
52065206
bool IsFunctionTemplate = FD && FD->getDescribedFunctionTemplate();
52075207
llvm::Triple Triple = S.getASTContext().getTargetInfo().getTriple();
52085208
const LangOptions &LangOpts = S.getLangOpts();
5209-
5209+
// OpenCL has its own error messages.
5210+
if (!LangOpts.OpenCL && FD && !FD->isExternallyVisible()) {
5211+
S.Diag(AL.getLoc(), diag::err_hidden_device_kernel) << FD;
5212+
AL.setInvalid();
5213+
return;
5214+
}
52105215
if (Triple.isNVPTX()) {
52115216
handleGlobalAttr(S, D, AL);
52125217
} else {
@@ -5222,17 +5227,7 @@ static void handleDeviceKernelAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
52225227
// TODO: isGPU() should probably return true for SPIR.
52235228
bool TargetDeviceEnvironment = Triple.isGPU() || Triple.isSPIR() ||
52245229
LangOpts.isTargetDevice() || LangOpts.OpenCL;
5225-
bool IsAMDGPUMismatch =
5226-
DeviceKernelAttr::isAMDGPUSpelling(AL) && !Triple.isAMDGPU();
5227-
bool IsNVPTXMismatch =
5228-
DeviceKernelAttr::isNVPTXSpelling(AL) && !Triple.isNVPTX();
5229-
if (IsAMDGPUMismatch || IsNVPTXMismatch || !TargetDeviceEnvironment) {
5230-
// While both are just different spellings of the same underlying
5231-
// attribute, it makes more sense to the user if amdgpu_kernel can only
5232-
// be used on AMDGPU and the equivalent for NVPTX, so warn and ignore
5233-
// the attribute if there's a mismatch.
5234-
// Also warn if this is not an environment where a device kernel makes
5235-
// sense.
5230+
if (!TargetDeviceEnvironment) {
52365231
S.Diag(AL.getLoc(), diag::warn_cconv_unsupported)
52375232
<< AL << (int)Sema::CallingConventionIgnoredReason::ForThisTarget;
52385233
AL.setInvalid();

clang/test/Sema/callingconv-devicekernel.c

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -fsyntax-only -verify %s
2+
// RUN: %clang_cc1 -triple nvptx64-nvidia-cuda- -fsyntax-only -verify %s
3+
// RUN: %clang_cc1 -triple spir64 -fsyntax-only -verify %s
4+
// RUN: %clang_cc1 -triple spirv64 -fsyntax-only -verify %s
5+
6+
[[clang::device_kernel]] void kernel1() {}
7+
8+
namespace {
9+
[[clang::device_kernel]] void kernel2() {} // expected-error {{'kernel2' is specified as a device kernel but it is not externally visible}}
10+
}
11+
12+
namespace ns {
13+
[[clang::device_kernel]] void kernel3() {}
14+
}
15+
16+
[[clang::device_kernel]] static void kernel4() {} // expected-error {{'kernel4' is specified as a device kernel but it is not externally visible}}

0 commit comments

Comments
 (0)