Skip to content

Commit 2c7ed98

Browse files
authored
[SYCL] Fix crash in unique stable name processing (#7927)
It seems built-in implementation expects only lambdas as unnamed structures, turns out that is not always the case. Fixes #7360
1 parent 7a81119 commit 2c7ed98

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

clang/lib/AST/Expr.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,8 @@ std::string SYCLUniqueStableNameExpr::ComputeName(ASTContext &Context) const {
644644
static llvm::Optional<unsigned>
645645
UniqueStableNameDiscriminator(ASTContext &, const NamedDecl *ND) {
646646
if (const auto *RD = dyn_cast<CXXRecordDecl>(ND))
647-
return RD->getDeviceLambdaManglingNumber();
647+
if (RD->isLambda())
648+
return RD->getDeviceLambdaManglingNumber();
648649
return llvm::None;
649650
}
650651

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %clang_cc1 %s %s -std=c++17 -triple x86_64-linux-gnu -Wno-sycl-2020-compat -fsycl-is-device -verify -fsyntax-only -Wno-unused
2+
3+
// This would crash due to UniqueStableNameDiscriminator expecting only lambdas
4+
// as unnamed records.
5+
// expected-no-diagnostics
6+
7+
template <typename T1, typename T2>
8+
class TC {};
9+
10+
template <typename T1, typename T2> void TFoo(T1 _T1, T2 _T2) {
11+
__builtin_sycl_unique_stable_name(TC<T1, T2>);
12+
}
13+
void use() {
14+
struct {float r1, r2, r12; } s;
15+
TFoo(1, s);
16+
}

0 commit comments

Comments
 (0)