@@ -323,37 +323,39 @@ no way to reference the variable in the unnamed namespace using fully qualified
323
323
lookup.
324
324
325
325
Such programs are still legal, though. The integration footer can support
326
- cases like this by defining a temporary variable that holds the address of the
326
+ cases like this by defining a shim function that returns a reference to the
327
327
shadowed device global:
328
328
329
329
```
330
330
namespace {
331
- const void *__sycl_UNIQUE_STRING = &FuBar; // References 'FuBar' in the
332
- // unnamed namespace
331
+ namespace __sycl_detail {
332
+
333
+ static constexpr decltype(FuBar) &__shim_1() {
334
+ return FuBar; // References 'FuBar' in the unnamed namespace
333
335
}
334
336
337
+ } // namespace __sycl_detail
338
+ } // namespace (unnamed)
339
+
335
340
namespace sycl::detail {
336
- namespace {
337
341
338
342
__sycl_device_global_registration::__sycl_device_global_registration() noexcept {
339
343
device_global_map::add(&::FuBar,
340
344
/* same string returned from __builtin_sycl_unique_stable_id(::FuBar) */);
341
- device_global_map::add(::__sycl_UNIQUE_STRING ,
345
+ device_global_map::add(&::__sycl_detail::__shim_1() ,
342
346
/* same string returned from __builtin_sycl_unique_stable_id(::(unnamed)::FuBar) */);
343
347
}
344
348
345
- } // namespace (unnamed)
346
349
} // namespace sycl::detail
347
350
```
348
351
349
- The ` __sycl_UNIQUE_STRING ` variable is defined in the same namespace as the
350
- second ` FuBar ` device global, so it can reference the variable through
351
- unqualified name lookup. Furthermore, the name of the temporary variable
352
- (` __sycl_UNIQUE_STRING ` ) is globally unique, so it is guaranteed not to be
353
- shadowed by any other name in the translation unit. This problem with variable
354
- shadowing is also a problem for the integration footer we use for
355
- specialization constants. See the [ specialization constant design document] [ 5 ]
356
- for more details on this topic.
352
+ The ` __shim_1() ` function is defined in the same namespace as the second
353
+ ` FuBar ` device global, so it can reference the variable through unqualified
354
+ name lookup. Furthermore, the name of the shim function is globally unique, so
355
+ it is guaranteed not to be shadowed by any other name in the translation unit.
356
+ This problem with variable shadowing is also a problem for the integration
357
+ footer we use for specialization constants. See the [ specialization constant
358
+ design document] [ 5 ] for more details on this topic.
357
359
358
360
[ 5 ] : < SpecializationConstants.md >
359
361
0 commit comments