================
@@ -14794,9 +14803,36 @@ void 
ASTContext::getFunctionFeatureMap(llvm::StringMap<bool> &FeatureMap,
   }
 }
 
-static SYCLKernelInfo BuildSYCLKernelInfo(CanQualType KernelNameType,
+static SYCLKernelInfo BuildSYCLKernelInfo(ASTContext &Context,
+                                          CanQualType KernelNameType,
                                           const FunctionDecl *FD) {
-  return {KernelNameType, FD};
+  // Host and device compilation may use different ABIs and different ABIs
+  // may allocate name mangling discriminators differently. A discriminator
+  // override is used to ensure consistent discriminator allocation across
+  // host and device compilation.
+  auto DeviceDiscriminatorOverrider =
+      [](ASTContext &Ctx, const NamedDecl *ND) -> std::optional<unsigned> {
+    if (const auto *RD = dyn_cast<CXXRecordDecl>(ND))
+      if (RD->isLambda())
----------------
erichkeane wrote:

>I modified the test included with this PR to use a generic lambda as the 
>kernel name type.

Is this what you're referring to?

```
  auto lambda = [=](auto) { (void) capture; };
  kernel_single_task<decltype(lambda)>(lambda);

// CHECK-HOST-LINUX:      define internal void 
@_Z18kernel_single_taskIZ4mainEUlT_E_S1_EvT0_(i32 %kernelFunc.coerce) 
#{{[0-9]+}} {
// CHECK-HOST-WINDOWS:      define internal void 
@"??$kernel_single_task@V<lambda_1>@?0??main@@9@V1?0??2@9@@@YAXV<lambda_1>@?0??main@@9@@Z"(i32
 %kernelFunc.coerce) #{{[0-9]+}} {
```
If so, I think that does.  

> I'll need a theoretical explanation for why the capture type of a generic 
> lambda would be mangled any differently than for a non-generic lambda in 
> order to make progress. I can't think of any reason for mangling differences.

The concern here is that you're using `DeviceLambdaManglingNumber`, which, at 
one point when I checked, wasn't actually set for non-instantiated generic 
lambdas.  So the attempt to mangle them would always result in the 'same' 
mangling number, which doesn't really work.  In addition to the above, can you 
test the following, and make sure it results in proper looking names?
```
  kernel_single_task<decltype([](auto){})>(<whatever to make this work, the key 
is that we aren't giving it a name, and counting exclusively on its 
type/number>);
  kernel_single_task<decltype([](auto,auto/*if possible? might need a default 
arg*/){})>(<whatever to make this work, the key is that we aren't giving it a 
name, and counting exclusively on its type/number>);
```
I would expect those two to be different lambdas with different manglings.  You 
MIGHT have to extract those out into a `using` of the type if you have to use 
the same lambda for the call(which I don't think you do?)

>I can't think of any reason for mangling differences.

Depending on how types are mangled in some situations we actually mangle the 
arguments of the lambda, which results in `auto` being used as the mangling, 
though my memory on when that happens is vague ATM.

https://github.com/llvm/llvm-project/pull/133030
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to