[all-commits] [llvm/llvm-project] de0df6: [CUDA][HIP] Fix overloading resolution in global v...

Yaxun (Sam) Liu via All-commits all-commits at lists.llvm.org
Tue Aug 29 07:17:56 PDT 2023

  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: de0df639724b10001ea9a74539381ea494296be9
  Author: Yaxun (Sam) Liu <yaxun.liu at amd.com>
  Date:   2023-08-29 (Tue, 29 Aug 2023)

  Changed paths:
    M clang/include/clang/Sema/Sema.h
    M clang/lib/Parse/ParseDecl.cpp
    M clang/lib/Sema/SemaCUDA.cpp
    M clang/lib/Sema/SemaDeclAttr.cpp
    M clang/lib/Sema/SemaOverload.cpp
    M clang/lib/Sema/SemaType.cpp
    A clang/test/CodeGenCUDA/global-initializers.cu
    M clang/test/SemaCUDA/amdgpu-windows-vectorcall.cu
    M clang/test/SemaCUDA/function-overload.cu
    R clang/test/SemaCUDA/global-initializers-host.cu
    A clang/test/SemaCUDA/global-initializers.cu

  Log Message:
  [CUDA][HIP] Fix overloading resolution in global variable initializer

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

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.

Reviewed by: Artem Belevich

Differential Revision: https://reviews.llvm.org/D158247

Fixes: SWDEV-416731

More information about the All-commits mailing list