llvm-project/clang/test/ParserSYCL/unique_stable_name.cpp
Erich Keane eba69b59d1 Reimplement __builtin_unique_stable_name-
The original version of this was reverted, and @rjmcall provided some
advice to architect a new solution.  This is that solution.

This implements a builtin to provide a unique name that is stable across
compilations of this TU for the purposes of implementing the library
component of the unnamed kernel feature of SYCL.  It does this by
running the Itanium mangler with a few modifications.

Because it is somewhat common to wrap non-kernel-related lambdas in
macros that aren't present on the device (such as for logging), this
uniquely generates an ID for all lambdas involved in the naming of a
kernel. It uses the lambda-mangling number to do this, except replaces
this with its own number (starting at 10000 for readabililty reasons)
for lambdas used to name a kernel.

Additionally, this implements itself as constexpr with a slight catch:
if a name would be invalidated by the use of this lambda in a later
kernel invocation, it is diagnosed as an error (see the Sema tests).

Differential Revision: https://reviews.llvm.org/D103112
2021-05-27 07:12:20 -07:00

44 lines
1.3 KiB
C++

// RUN: %clang_cc1 -fsycl-is-device -fsyntax-only -verify -Wno-unused %s
namespace NS {
using good = double;
}
void f(int var) {
// expected-error@+1{{expected '(' after '__builtin_sycl_unique_stable_name'}}
__builtin_sycl_unique_stable_name int; // Correct usage is __builtin_sycl_unique_stable_name(int);
// expected-error@+1{{expected '(' after '__builtin_sycl_unique_stable_name'}}
__builtin_sycl_unique_stable_name{int}; // Correct usage is __builtin_sycl_unique_stable_name(int);
// expected-error@+2{{expected ')'}}
// expected-note@+1{{to match this '('}}
__builtin_sycl_unique_stable_name(int; // Missing paren before semicolon
// expected-error@+2{{expected ')'}}
// expected-note@+1{{to match this '('}}
__builtin_sycl_unique_stable_name(int, float); // Missing paren before comma
// expected-error@+1{{unknown type name 'var'}}
__builtin_sycl_unique_stable_name(var);
__builtin_sycl_unique_stable_name(NS::good);
// expected-error@+1{{expected a type}}
__builtin_sycl_unique_stable_name(for (int i = 0; i < 10; ++i) {})
__builtin_sycl_unique_stable_name({
(for (int i = 0; i < 10; ++i){})})
}
template <typename T>
void f2() {
__builtin_sycl_unique_stable_name(typename T::good_type);
}
struct S {
class good_type {};
};
void use() {
f2<S>();
}