================
@@ -4243,8 +4243,10 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, 
NamedDecl *&OldD, Scope *S,
     //   used on the first declaration of that function in the translation 
unit.
     //   Redeclarations of the function in the same translation unit may
     //   optionally use SYCL_EXTERNAL, but this is not required.
+    // The attribute is ignored and dropped for a variadic function, so 'Old'
+    // won't have it; 'New' still does since the drop happens after this check.
     const SYCLExternalAttr *SEA = New->getAttr<SYCLExternalAttr>();
-    if (SEA && !Old->hasAttr<SYCLExternalAttr>()) {
+    if (SEA && !New->isVariadic() && !Old->hasAttr<SYCLExternalAttr>()) {
----------------
tahonermann wrote:

It looks like there is a slightly cleaner way of handling this. Rather than 
checking for appertainment to a variadic function in 
`CheckSYCLExternalFunctionDecl()` and then dropping the attribute, the call to 
`handleSimpleAttribute<SYCLExternalAttr>()` in 
`clang/lib/Sema/SemaDeclAttr.cpp` can be modified to call a new 
`SemaSYCL::handleSYCLExternalAttr()` function that does the check and avoids 
adding the attribute in the first place. This is what is done for the old 
`sycl_kernel` attribute in similar cases; see `SemaSYCL::handleKernelAttr()`. 
The new function would look something like:
```
void SemaSYCL::handleSYCLExternalAttr(Decl *D, const ParsedAttr &AL) {
  // SYCL 2020 section 5.4 prohibits calling a variadic function from device
  // code, so the attribute cannot be honored; declaring one is not prohibited,
  // so ignore the attribute rather than reject the declaration.
  if (const auto *FD = cast<FunctionDecl>(D)) {
    if (FD->isVariadic()) {
      Diag(AL.getLoc(),
           diag::warn_sycl_external_ignored_variadic_function)
          << AL;
      return;
  }

  handleSimpleAttribute<SYCLExternallAttr>(*this, D, AL);
}
```

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

Reply via email to