@@ -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 ();
0 commit comments