Commit 478c205
authored
[SYCL] Fix Lambda Mangling in Namespace-Scope Variable Initializers. (#20176)
The community counterpart to this PR can be found here:
llvm/llvm-project#159115.
In that PR, we propose a fix for the lambda mangling issue in
namespace-scope variable initializers. This fix has uncovered a number
of related problems. @tahonermann has identified several scenarios where
the lambda mangling is either incorrect or diverges from `GCC`’s
behavior.
While the current patch addresses a high-priority issue flagged in our
downstream compiler, it requires additional time and effort to
thoroughly address the full range of scenarios—some of which are
partially listed in llvm/llvm-project#159115.
The current change successfully fixes the issue affecting our downstream
compiler.
Therefore, we propose to “cherry-pick” the community PR now, while
continuing work in the community repository to complete the fix.
For convenience here is the description of
llvm/llvm-project#159115:
This PR addresses an issue with the mangling of lambdas used as
initializers for global variables within namespaces. According to the
Itanium C++ ABI, lambdas should be uniquely mangled based on their
context. GCC correctly includes the name of the declared variable in the
mangling context for such lambdas, avoiding the need for discriminators
since each lambda is scoped to its respective variable (see
https://godbolt.org/z/38Y8qvvj3).
When C++ code is compiled without CUDA, HIP, or SYCL enabled, lambdas
that don't require external linkage are given internal linkage and
mangled with a $ in their name. When CUDA, HIP, or SYCL support is
enabled, separate compilation for host and device requires that the same
mangled names are observed, even for symbols that have internal linkage.
Code to use external mangling was already present, but the mangled names
for lambdas were incorrectly generated in some cases:
Lambdas in the initializers of global variables used the enclosing
namespace as the mangling context rather than the global variable.
When such global variables were declared in different partial namespace
definitions, discriminators were allocated in the context of a specific
partial namespace definition rather than in the primary namespace
definition leading to mangled name clashes, some of which provoked an
error, some of which resulted in an additional .<n> disambiguator being
silently added to the symbol.
This PR ensures that lambdas used as global variable initializers are
mangled in the context of the declared variable and that a canonical
namespace is used for allocation of mangling discriminators.1 parent 8bfe4e0 commit 478c205
File tree
6 files changed
+163
-4
lines changed- clang
- include/clang/Sema
- lib
- AST
- Sema
- test
- CodeGenCUDA
- CodeGenSYCL
- CodeGen
6 files changed
+163
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9183 | 9183 | | |
9184 | 9184 | | |
9185 | 9185 | | |
9186 | | - | |
| 9186 | + | |
| 9187 | + | |
| 9188 | + | |
| 9189 | + | |
| 9190 | + | |
| 9191 | + | |
| 9192 | + | |
9187 | 9193 | | |
9188 | 9194 | | |
9189 | 9195 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13356 | 13356 | | |
13357 | 13357 | | |
13358 | 13358 | | |
| 13359 | + | |
13359 | 13360 | | |
13360 | 13361 | | |
13361 | 13362 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
356 | 356 | | |
357 | 357 | | |
358 | 358 | | |
359 | | - | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
360 | 367 | | |
361 | 368 | | |
362 | 369 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
0 commit comments