================
@@ -5743,10 +5743,11 @@ bool Sema::CheckCallingConvAttr(const ParsedAttr 
&Attrs, CallingConv &CC,
   bool IsTargetDefaultMSABI =
       Context.getTargetInfo().getTriple().isOSWindows() ||
       Context.getTargetInfo().getTriple().isUEFI();
+  const TargetInfo &TI = Context.getTargetInfo();
   // TODO: diagnose uses of these conventions on the wrong target.
   switch (Attrs.getKind()) {
   case ParsedAttr::AT_CDecl:
-    CC = CC_C;
+    CC = LangOpts.SYCLIsDevice ? TI.getDefaultCallingConv() : CC_C;
----------------
Fznamznon wrote:

@tahonermann 

> The diagnostic this PR is intended to address is exemplified by [this 
> Compiler Explorer example](https://godbolt.org/z/oGPE8vf44), correct? Are 
> there examples that generate other diagnostics?

This is an easy case which I also observed but it can be solved better than 
this patch proposes with something like 
https://github.com/llvm/llvm-project/pull/152023. The main trouble I observe is 
breakage within MSVC's implementation of std::function. The errors I see when 
using the downsteam SYCL implementation are
```

c:/Program files (x86)/Microsoft Visual 
Studio/2019/Professional/VC/Tools/MSVC/14.29.30133/include\functional:999:19: 
error: static assertion failed due to requirement '_Always_false<bool (int)>': 
std::function does not accept non-function types as template arguments.
  999 |     static_assert(_Always_false<_Tx>, "std::function does not accept 
non-function types as template arguments.");
      |                   ^~~~~~~~~~~~~~~~~~
c:/Program files (x86)/Microsoft Visual 
Studio/2019/Professional/VC/Tools/MSVC/14.29.30133/include\functional:1023:25: 
note: in instantiation of template class 'std::_Get_function_impl<bool (int)>' 
requested here
 1023 | class function : public _Get_function_impl<_Fty>::type { // wrapper for 
callable objects
      |                         ^
property_list_base.hpp:106:52: note: in instantiation of template class 
'std::function<bool (int)>' requested here
  106 |   void checkPropsAndThrow(std::function<bool(int)> FunctionForDataless,
      |                                                    ^
In file included from <built-in>:1:
include\sycl\ext\oneapi\accessor_property_list.hpp:15:
include\sycl/detail/property_list_base.hpp:16:
include\functional:1025:56: error: no type named 'type' in 
'std::_Get_function_impl<bool (int)>'
 1025 |     using _Mybase = typename _Get_function_impl<_Fty>::type;
      |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
include\sycl/detail/property_list_base.hpp:106:52: note: in instantiation of 
template class 'std::function<bool (int)>' requested here
  106 |   void checkPropsAndThrow(std::function<bool(int)> FunctionForDataless,
      |                                                    ^
include\sycl/detail/property_list_base.hpp:120:12: error: type 
'std::function<bool (int)>' does not provide a call operator
  120 |       if (!FunctionForData(PropertyItem->getKind()))
      |            ^~~~~~~~~~~~~~~
```
I can't make head nor tail of MSVC headers in this place but my assumption is 
they end up applying/expecting __cdecl to the template parameter representing 
function type of `std::function` and there is simply type mismatch happening. 
The error goes away with this patch. The test case illustrating the type 
mismatch problem is

```

// Make sure that function type conversions work.
typedef void (__cdecl *funcTy)();
void invoke(funcTy f);

static void callee() noexcept {
}

void foo() {
   invoke(callee);
}

// Errors are given for it:
t1.cpp:9:5: error: no matching function for call to 'invoke'
    9 |     invoke(callee);
      |     ^~~~~~
t1.cpp:3:6: note: candidate function not viable: no known conversion from 'void 
() noexcept' to 'funcTy' (aka 'void (*)()') for 1st argument
    3 | void invoke(funcTy f);
```
Unfortunately I can't find a combination of options that would illustrate this 
behavior on compiler explorer because it always assumes linux host and there is 
no cc1 interface. 

I think this is a general problem which cannot be solved with small diagnostic 
relaxations.

I think Alexey's suggestion makes a lot of sense and I'd like to try it out.

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

Reply via email to