[all-commits] [llvm/llvm-project] cd9533: [CUDA][HIP] Fix capturing reference to host variable
Yaxun (Sam) Liu via All-commits
all-commits at lists.llvm.org
Wed Dec 2 07:15:32 PST 2020
Branch: refs/heads/master
Home: https://github.com/llvm/llvm-project
Commit: cd95338ee3022bffd658e52cd3eb9419b4c218ca
https://github.com/llvm/llvm-project/commit/cd95338ee3022bffd658e52cd3eb9419b4c218ca
Author: Yaxun (Sam) Liu <yaxun.liu at amd.com>
Date: 2020-12-02 (Wed, 02 Dec 2020)
Changed paths:
M clang/lib/CodeGen/CGExpr.cpp
M clang/lib/Sema/SemaExpr.cpp
A clang/test/CodeGenCUDA/lambda-reference-var.cu
Log Message:
-----------
[CUDA][HIP] Fix capturing reference to host variable
In C++ when a reference variable is captured by copy, the lambda
is supposed to make a copy of the referenced variable in the captures
and refer to the copy in the lambda. Therefore, it is valid to capture
a reference to a host global variable in a device lambda since the
device lambda will refer to the copy of the host global variable instead
of access the host global variable directly.
However, clang tries to avoid capturing of reference to a host global variable
if it determines the use of the reference variable in the lambda function is
not odr-use. Clang also tries to emit load of the reference to a global variable
as load of the global variable if it determines that the reference variable is
a compile-time constant.
For a device lambda to capture a reference variable to host global variable
and use the captured value, clang needs to be taught that in such cases the use of the reference
variable is odr-use and the reference variable is not compile-time constant.
This patch fixes that.
Differential Revision: https://reviews.llvm.org/D91088
More information about the All-commits
mailing list