Author: schittir
Date: 2026-11-18T14:53:28-05:00
New Revision: 207c43f7061aabbffa00e2ec766a4150014cb863

URL: 
https://github.com/llvm/llvm-project/commit/207c43f7061aabbffa00e2ec766a4150014cb863
DIFF: 
https://github.com/llvm/llvm-project/commit/207c43f7061aabbffa00e2ec766a4150014cb863.diff

LOG: [clang][SYCL] Diagnose device calls with host-only calling conventions 
(#243613)

A calling convention that is supported by the host but not by the device
is accepted on the declaration. Warn on calls to such functions that are
reachable from device code.

Follow-up for https://github.com/llvm/llvm-project/pull/227665

Added: 
    

Modified: 
    clang/lib/Sema/SemaChecking.cpp
    clang/test/SemaSYCL/sycl-cconv.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index dfbfbf91b7cab4..b4fc2b9d2508e4 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -4902,6 +4902,17 @@ void Sema::checkCall(NamedDecl *FDecl, const 
FunctionProtoType *Proto,
     SYCL().DiagIfDeviceCode(Loc, diag::err_variadic_device_fn)
         << diag::OffloadLang::SYCL;
 
+  // A calling convention that is supported only by the host is accepted on the
+  // declaration, but cannot be used for a call from device code.
+  if (Proto && getLangOpts().SYCLIsDevice && !isUnevaluatedContext()) {
+    CallingConv CC = Proto->getCallConv();
+    if (Context.getTargetInfo().checkCallingConvention(CC) !=
+        TargetInfo::CCCR_OK)
+      SYCL().DiagIfDeviceCode(Loc, diag::warn_cconv_unsupported)
+          << &Context.Idents.get(FunctionType::getNameForCallConv(CC))
+          << (int)CallingConventionIgnoredReason::ForThisTarget;
+  }
+
   if (FD)
     diagnoseArgDependentDiagnoseIfAttrs(FD, ThisArg, Args, Loc);
 }

diff  --git a/clang/test/SemaSYCL/sycl-cconv.cpp 
b/clang/test/SemaSYCL/sycl-cconv.cpp
index c60501d5bd0bed..1e1a24ea8b5265 100644
--- a/clang/test/SemaSYCL/sycl-cconv.cpp
+++ b/clang/test/SemaSYCL/sycl-cconv.cpp
@@ -1,5 +1,7 @@
-// RUN: %clang_cc1 -isystem %S/Inputs/ -fsycl-is-device -triple spirv64 
-aux-triple x86_64-pc-windows-msvc -fsyntax-only -verify %s
-// RUN: %clang_cc1 -isystem %S/Inputs/ -fsycl-is-device -triple spirv64 
-fsyntax-only -verify=expected,no-aux %s
+// RUN: %clang_cc1 -isystem %S/Inputs/ -fsycl-is-device -triple spirv64 
-aux-triple x86_64-pc-windows-msvc -fsyntax-only -verify=expected,x86-host,aux 
%s
+// RUN: %clang_cc1 -isystem %S/Inputs/ -fsycl-is-device -triple spirv64 
-aux-triple x86_64-unknown-linux-gnu -fsyntax-only 
-verify=expected,x86-host,aux %s
+// RUN: %clang_cc1 -isystem %S/Inputs/ -fsycl-is-device -triple spirv64 
-aux-triple aarch64-unknown-linux-gnu -fsyntax-only 
-verify=expected,aux,no-x86-host %s
+// RUN: %clang_cc1 -isystem %S/Inputs/ -fsycl-is-device -triple spirv64 
-fsyntax-only -verify=expected,no-aux,no-x86-host %s
 
 // Check that there is no error/warning emitted for cdecl functions compiled 
for
 // SYCL device. Make sure variadic calls from within device code are diagnosed.
@@ -15,6 +17,13 @@ void bar() {
   printf("hello\n");
 }
 
+// Accepted when the auxiliary host target supports the calling convention and
+// diagnosed when neither the device nor the host does.
+// no-x86-host-warning@+1 {{'regcall' calling convention is not supported for 
this target}}
+void __attribute__((regcall)) rcall(int a, int b) {}
+// no-x86-host-warning@+1 {{'vectorcall' calling convention is not supported 
for this target}}
+void __attribute__((vectorcall)) vcall(float a, float b) {}
+
 // Check some weird calling convention that is not supported even by x86_64 
aux.
 // no-aux-warning@+1 {{'__swiftasynccall__' calling convention is not 
supported for this target}}
 void __attribute__((__swiftasynccall__)) g(void) {}
@@ -32,8 +41,16 @@ int main() {
   //expected-error@+1 {{SYCL device code does not support variadic functions}}
   sycl_entry_point<class kn>([]() { printf("world\n");
      moo();
-  //expected-error@+1 {{SYCL device code does not support variadic functions}}
-     foo(1,2); });
+     //expected-error@+1 {{SYCL device code does not support variadic 
functions}}
+     foo(1,2);
+     // Calls from device code are diagnosed when the device does not support
+     // the calling convention, even if the host does.
+     // x86-host-warning@+1 {{'regcall' calling convention is not supported 
for this target}}
+     rcall(1, 2);
+     // x86-host-warning@+1 {{'vectorcall' calling convention is not supported 
for this target}}
+     vcall(1.0f, 2.0f);
+     // aux-warning@+1 {{'swiftasynccall' calling convention is not supported 
for this target}}
+     g(); });
   bar();
   return 0;
 }


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to