[PATCH] D102237: [CUDA][HIP] Fix non-ODR-use of static device variable

Artem Belevich via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue May 11 10:37:21 PDT 2021


tra accepted this revision.
tra added a comment.
This revision is now accepted and ready to land.

LGTM with few nits.



================
Comment at: clang/lib/Sema/SemaExpr.cpp:17145
     };
-    if (Var && Var->hasGlobalStorage() && !IsEmittedOnDeviceSide(Var)) {
-      SemaRef.targetDiag(Loc, diag::err_ref_bad_target)
-          << /*host*/ 2 << /*variable*/ 1 << Var << Target;
+    if (Var && Var->hasGlobalStorage()) {
+      if (SemaRef.LangOpts.CUDAIsDevice && !IsEmittedOnDeviceSide(Var)) {
----------------
This can be collapsed with the `if (SemaRef.LangOpts.CUDA) ` above.


================
Comment at: clang/test/CodeGenCUDA/static-device-var-rdc.cu:100-105
 // HOST: __hipRegisterVar({{.*}}@_ZL1x {{.*}}@[[DEVNAMEX]]
 // HOST: __hipRegisterVar({{.*}}@_ZL1y {{.*}}@[[DEVNAMEY]]
 // HOST-NOT: __hipRegisterVar({{.*}}@_ZL2x2
 // HOST-NOT: __hipRegisterVar({{.*}}@_ZZ6kernelPiPPKiE1w
 // HOST-NOT: __hipRegisterVar({{.*}}@_ZZ6devfunPPKiE1p
+// HOST-NOT: __hipRegisterVar({{.*}}@_ZL1u
----------------
Positive checks should be `-DAG` and negative checks should be done in a separate `RUN` as we can't really guarantee the order in which registration calls are emitted.


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

https://reviews.llvm.org/D102237



More information about the cfe-commits mailing list