[cfe-dev] [EXTERNAL] Re: Issue where Lambda capture of reference to globals doesn't actually capture anything

Lewis, Cannada via cfe-dev cfe-dev at lists.llvm.org
Mon Oct 26 10:53:00 PDT 2020

Thanks Arthur,

This came up in the context of the HIP backend. The HIP release notes apparently mention that this is currently a bug (I don’t write code for HIP, but apparently HIP cannot access globals in device functions).  So while I don’t have a bug number I’m guessing that at least someone knows about it.

Incidentally, [x=x] is the workout around I just suggested to our users.


On Oct 26, 2020, at 10:46 AM, Arthur O'Dwyer <arthur.j.odwyer at gmail.com<mailto:arthur.j.odwyer at gmail.com>> wrote:

I confirm that this is a Clang bug, going back at least to Clang 6.  I don't know if it's been reported on bugs.llvm.org<http://bugs.llvm.org/> yet.
It doesn't matter whether the capture is done as [=] or as [x]. Doing it explicitly as [x=x] is a possible workaround.


On Mon, Oct 26, 2020 at 1:26 PM Lewis, Cannada via cfe-dev <cfe-dev at lists.llvm.org<mailto:cfe-dev at lists.llvm.org>> wrote:

We recently encountered an issue where clang has some unexpected behavior with respect to the capture of local references to global variables https://godbolt.org/z/KasP9K.

Most compilers (gcc, MSVC, icc) appear to create a member variable to hold the value of `myfoo` and have `dummy` return a size of 16.  Clang does not store a member for `myfoo` (in the AST there is no `FieldDecl` for `myfoo`).

This leads to the interesting issue here: https://godbolt.org/z/G59e7M
Where clang and gcc will print out different values.

I don’t know if this is a clang issue (known?), or a {gcc,icc,msvc} issue, or is implementation defined, but any insight on this would be welcome.

cfe-dev mailing list
cfe-dev at lists.llvm.org<mailto:cfe-dev at lists.llvm.org>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20201026/0ab3af52/attachment.html>

More information about the cfe-dev mailing list