Skip to content

Commit 45ab868

Browse files
committed
Use llvm::SmallString, add FIXME about interfaces
1 parent a25ac0a commit 45ab868

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include "clang/Basic/SourceLocation.h"
2828
#include "clang/Basic/TargetInfo.h"
2929
#include "clang/Sema/Initialization.h"
30-
#include "clang/Sema/Lookup.h"
3130
#include "clang/Sema/ParsedAttr.h"
3231
#include "clang/Sema/Sema.h"
3332
#include "clang/Sema/Template.h"
@@ -40,8 +39,8 @@
4039
#include "llvm/Support/DXILABI.h"
4140
#include "llvm/Support/ErrorHandling.h"
4241
#include "llvm/TargetParser/Triple.h"
42+
#include <cstddef>
4343
#include <iterator>
44-
#include <string>
4544
#include <utility>
4645

4746
using namespace clang;
@@ -339,30 +338,33 @@ static IdentifierInfo *getHostLayoutStructName(Sema &S, NamedDecl *BaseDecl,
339338
ASTContext &AST = S.getASTContext();
340339

341340
IdentifierInfo *NameBaseII = BaseDecl->getIdentifier();
342-
StringRef NameBase;
341+
llvm::SmallString<64> Name("__layout_");
343342
if (NameBaseII) {
344-
NameBase = NameBaseII->getName();
343+
Name.append(NameBaseII->getName());
345344
} else {
346345
// anonymous struct
347-
NameBase = "anon";
346+
Name.append("anon");
348347
MustBeUnique = true;
349348
}
350349

351-
std::string Name = ("__layout_" + NameBase).str();
350+
size_t NameLength = Name.size();
352351
IdentifierInfo *II = &AST.Idents.get(Name, tok::TokenKind::identifier);
353352
if (!MustBeUnique)
354353
return II;
355354

356355
unsigned suffix = 0;
357356
while (true) {
358-
if (suffix != 0)
359-
II = &AST.Idents.get((Name + "_" + Twine(suffix)).str(),
360-
tok::TokenKind::identifier);
357+
if (suffix != 0) {
358+
Name.append("_");
359+
Name.append(llvm::Twine(suffix).str());
360+
II = &AST.Idents.get(Name, tok::TokenKind::identifier);
361+
}
361362
if (!findRecordDeclInContext(II, BaseDecl->getDeclContext()))
362363
return II;
363364
// declaration with that name already exists - increment suffix and try
364365
// again until unique name is found
365366
suffix++;
367+
Name.truncate(NameLength);
366368
};
367369
}
368370

@@ -421,6 +423,8 @@ static CXXRecordDecl *createHostLayoutStruct(Sema &S,
421423

422424
// copy base struct, create HLSL Buffer compatible version if needed
423425
if (unsigned NumBases = StructDecl->getNumBases()) {
426+
// FIXME: Filter out interfaces from the list of base classes
427+
// (llvm/llvm-project#124178)
424428
assert(NumBases == 1 && "HLSL supports only one base type");
425429
CXXBaseSpecifier Base = *StructDecl->bases_begin();
426430
CXXRecordDecl *BaseDecl = Base.getType()->getAsCXXRecordDecl();

0 commit comments

Comments
 (0)