Skip to content

Commit 5831c55

Browse files
author
Erich Keane
authored
[SYCL] Fix a crash with __bulitin_unique_stable_name (#3284)
A placeholder expression inside a unique-stable-name(at this point, an unresolved lookup expression) was not properly being transformed during template instantiation. This patch ensures that it gets instantiated.
1 parent 79a1a9f commit 5831c55

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

clang/lib/Sema/SemaTemplateInstantiate.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,6 +1457,11 @@ static ExprResult TransformUniqueStableName(TemplateInstantiator &TI,
14571457
TI.getSema(), Sema::ExpressionEvaluationContext::Unevaluated);
14581458
ExprResult SubExpr = TI.getDerived().TransformExpr(E->getExpr());
14591459

1460+
if (SubExpr.isInvalid())
1461+
return ExprError();
1462+
1463+
SubExpr = TI.getSema().CheckPlaceholderExpr(SubExpr.get());
1464+
14601465
if (SubExpr.isInvalid())
14611466
return ExprError();
14621467

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// RUN: %clang_cc1 -triple spir64-unknown-unknown-sycldevice -internal-isystem %S/Inputs -std=c++17 -sycl-std=2020 -fsycl -fsycl-is-device -disable-llvm-passes -emit-llvm %s -o - | FileCheck %s
2+
3+
#include <sycl.hpp>
4+
5+
using namespace cl::sycl;
6+
7+
struct A {
8+
int a = 0;
9+
A() = default;
10+
};
11+
constexpr A THE_NAME;
12+
13+
template <auto &R> void temp() {}
14+
template <auto &R> void foo(const char *out) {
15+
out = __builtin_unique_stable_name(temp<R>);
16+
}
17+
18+
int main() {
19+
kernel_single_task<class kernel>(
20+
[]() {
21+
const char *c;
22+
foo<THE_NAME>(c);
23+
});
24+
}
25+
26+
// Note: the mangling here is actually the 'typeinfo name for void ()'. That is
27+
// because the type of temp<R> is actually the function type (which is void()).
28+
// CHECK: @__builtin_unique_stable_name._Z3fooIL_ZL8THE_NAMEEEvPKc = private unnamed_addr addrspace(1) constant [9 x i8] c"_ZTSFvvE\00", align 1

0 commit comments

Comments
 (0)