[PATCH] D158247: [CUDA][HIP] Fix overloading resolution in global variable initializer
Yaxun Liu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 17 21:22:59 PDT 2023
yaxunl created this revision.
yaxunl added reviewers: tra, rjmccall, rsmith.
Herald added subscribers: mattd, carlosgalvezp, kerbowa, jvesely.
Herald added a reviewer: aaron.ballman.
Herald added a project: All.
yaxunl requested review of this revision.
Currently, clang does not resolve certain overloaded functions correctly in the initializer
of global variables, e.g.
template<typename T1, typename U>
T1 mypow(T1, U);
__attribute__((device)) double mypow(double, int);
double t_extent = mypow(1.0, 2);
In the above example, mypow is supposed to resolve to the host version
but clang resolves it to the device version instead, and emits an error
(https://godbolt.org/z/17xxzaa67).
However, if the variable is assigned in a host function, there is no error.
The discrepancy in overloading resolution inside and outside of
a function is due to clang not accounting for the host/device target
when resolving functions called in the initializer of a global variable.
This patch introduces a global host/device target context for CUDA/HIP
for functions called outside of functions. For global variable initialization,
it is determined by the host/device attribute of the variable. For other
situations, a default value of host_device is sufficient.
https://reviews.llvm.org/D158247
Files:
clang/include/clang/Sema/Sema.h
clang/lib/Parse/ParseDecl.cpp
clang/lib/Sema/SemaCUDA.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaType.cpp
clang/test/CodeGenCUDA/global-initializers.cu
clang/test/SemaCUDA/amdgpu-windows-vectorcall.cu
clang/test/SemaCUDA/function-overload.cu
clang/test/SemaCUDA/global-initializers-host.cu
clang/test/SemaCUDA/global-initializers.cu
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158247.551365.patch
Type: text/x-patch
Size: 15866 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230818/497452e1/attachment.bin>
More information about the cfe-commits
mailing list