Skip to content

Commit

Permalink
[clang][Interp] Implement __builtin_sycl_unique_stable_name
Browse files Browse the repository at this point in the history
  • Loading branch information
tbaederr committed May 21, 2024
1 parent 6ff8236 commit a7521fd
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
24 changes: 24 additions & 0 deletions clang/lib/AST/Interp/ByteCodeExprGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1594,6 +1594,30 @@ bool ByteCodeExprGen<Emitter>::VisitStringLiteral(const StringLiteral *E) {
return true;
}

template <class Emitter>
bool ByteCodeExprGen<Emitter>::VisitSYCLUniqueStableNameExpr(
const SYCLUniqueStableNameExpr *E) {
if (DiscardResult)
return true;

assert(!Initializing);

auto &A = Ctx.getASTContext();
std::string ResultStr = E->ComputeName(A);

QualType CharTy = A.CharTy.withConst();
APInt Size(A.getTypeSize(A.getSizeType()), ResultStr.size() + 1);
QualType ArrayTy = A.getConstantArrayType(CharTy, Size, nullptr,
ArraySizeModifier::Normal, 0);

StringLiteral *SL =
StringLiteral::Create(A, ResultStr, StringLiteralKind::Ordinary,
/*Pascal=*/false, ArrayTy, E->getLocation());

unsigned StringIndex = P.createGlobalString(SL);
return this->emitGetPtrGlobal(StringIndex, E);
}

template <class Emitter>
bool ByteCodeExprGen<Emitter>::VisitCharacterLiteral(
const CharacterLiteral *E) {
Expand Down
1 change: 1 addition & 0 deletions clang/lib/AST/Interp/ByteCodeExprGen.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class ByteCodeExprGen : public ConstStmtVisitor<ByteCodeExprGen<Emitter>, bool>,
bool VisitOpaqueValueExpr(const OpaqueValueExpr *E);
bool VisitAbstractConditionalOperator(const AbstractConditionalOperator *E);
bool VisitStringLiteral(const StringLiteral *E);
bool VisitSYCLUniqueStableNameExpr(const SYCLUniqueStableNameExpr *E);
bool VisitCharacterLiteral(const CharacterLiteral *E);
bool VisitCompoundAssignOperator(const CompoundAssignOperator *E);
bool VisitFloatCompoundAssignOperator(const CompoundAssignOperator *E);
Expand Down
9 changes: 9 additions & 0 deletions clang/test/AST/Interp/sycl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN: %clang_cc1 %s -std=c++17 -triple x86_64-linux-gnu -fsycl-is-device -verify=both,ref -fsyntax-only -Wno-unused
// RUN: %clang_cc1 %s -std=c++17 -triple x86_64-linux-gnu -fsycl-is-device -verify=both,expected -fsyntax-only -Wno-unused -fexperimental-new-constant-interpreter

// both-no-diagnostics

constexpr int a = 0;
constexpr const char *a_name = __builtin_sycl_unique_stable_name(decltype(a));
static_assert(__builtin_strcmp(a_name, "_ZTSKi") == 0);

0 comments on commit a7521fd

Please sign in to comment.