This patch diagnoses invalid references of global host variables in device,
global, or host device functions.
Details
- Reviewers
tra rjmccall - Commits
- rG5c8911d0ba38: [CUDA][HIP] Diagnose reference of host variable
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
LGTM.
clang/lib/Sema/SemaExpr.cpp | ||
---|---|---|
357 | This could use a comment why we only check D->H references. |
clang/lib/Sema/SemaExpr.cpp | ||
---|---|---|
357 | Just added a comment: Reference of device global variables in host functions is |
It appears that we need to add special handling for texture/surface references. Nominally they are host-side objects, but they are accessed/used from device functions as far as Sema is concerned.
E.g. https://godbolt.org/z/z1YnE3
NVCC and older clang compile it, but the recent one fails because this patch does not let the change through.
I think isCUDADeviceBuiltinTextureType has problem handling texture refs within templates.
@tra I got some issue with this patch. There are cases that an expression using a host variable is compile-time constant, e.g.
int x; __device__ void fun() { sizeof(x); }
Do we want to allow that? Thanks.
It seems we should only diagnose ODR-use (https://en.cppreference.com/w/cpp/language/definition) of host variable in device functions.
This could use a comment why we only check D->H references.