[PATCH] D98193: [CUDA][HIP] Allow non-ODR use of host var in device
Richard Smith - zygoloid via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 29 12:31:33 PDT 2021
rsmith added inline comments.
================
Comment at: clang/lib/Sema/SemaExpr.cpp:17050
+ auto Target = SemaRef.IdentifyCUDATarget(FD);
+ if (Var && Var->isFileVarDecl() && !Var->hasAttr<CUDADeviceAttr>() &&
+ !Var->hasAttr<CUDAConstantAttr>() && !Var->hasAttr<CUDASharedAttr>() &&
----------------
I suspect you want `hasGlobalStorage` rather than `isFileVarDecl` here (that is, preserve the condition from the deleted code), in order to disallow use of host-side local static variables from device-side functions:
```
__host__ void f() {
static int n;
struct X {
__device__ void g() { ++n; }
};
// ...
}
```
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D98193/new/
https://reviews.llvm.org/D98193
More information about the cfe-commits
mailing list