[PATCH] D91088: [CUDA][HIP] Fix capturing reference to host variable

Yaxun Liu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 30 20:17:15 PST 2020


yaxunl marked 2 inline comments as done.
yaxunl added inline comments.


================
Comment at: clang/lib/Sema/SemaExpr.cpp:1944
+  // host variable in a device or host device lambda.
+  auto IsCapturingReferenceToHostVarInCUDADeviceLambda = [&](VarDecl *VD) {
+    if (!getLangOpts().CUDA || !VD->hasInit())
----------------
tra wrote:
> Nit: I'd make it a free function.
> The large-ish lambda handling a niche case makes the original simple function less readable. I think keeping capture check separate would be a bit cleaner.
done


================
Comment at: clang/lib/Sema/SemaExpr.cpp:1982
         !(getLangOpts().OpenMP && isOpenMPCapturedDecl(D)) &&
+        !IsCapturingReferenceToHostVarInCUDADeviceLambda(VD) &&
         VD->isUsableInConstantExpressions(Context))
----------------
tra wrote:
> This could use some Sema tests.
the negative cases of the condition that incur diagnostics are referencing host variable in device or host device functions. The sema tests have been added in https://reviews.llvm.org/D91281.

The other negative cases of the condition (capturing host reference in host lambda, referencing host var in host function, capturing device reference in host lambda, referencing device var in host function, etc) do not cause diagnostics, which are covered by codegen tests.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D91088/new/

https://reviews.llvm.org/D91088



More information about the cfe-commits mailing list