|
27 | 27 | #include "clang/Basic/SourceLocation.h" |
28 | 28 | #include "clang/Basic/TargetInfo.h" |
29 | 29 | #include "clang/Sema/Initialization.h" |
30 | | -#include "clang/Sema/Lookup.h" |
31 | 30 | #include "clang/Sema/ParsedAttr.h" |
32 | 31 | #include "clang/Sema/Sema.h" |
33 | 32 | #include "clang/Sema/Template.h" |
|
40 | 39 | #include "llvm/Support/DXILABI.h" |
41 | 40 | #include "llvm/Support/ErrorHandling.h" |
42 | 41 | #include "llvm/TargetParser/Triple.h" |
| 42 | +#include <cstddef> |
43 | 43 | #include <iterator> |
44 | | -#include <string> |
45 | 44 | #include <utility> |
46 | 45 |
|
47 | 46 | using namespace clang; |
@@ -339,30 +338,33 @@ static IdentifierInfo *getHostLayoutStructName(Sema &S, NamedDecl *BaseDecl, |
339 | 338 | ASTContext &AST = S.getASTContext(); |
340 | 339 |
|
341 | 340 | IdentifierInfo *NameBaseII = BaseDecl->getIdentifier(); |
342 | | - StringRef NameBase; |
| 341 | + llvm::SmallString<64> Name("__layout_"); |
343 | 342 | if (NameBaseII) { |
344 | | - NameBase = NameBaseII->getName(); |
| 343 | + Name.append(NameBaseII->getName()); |
345 | 344 | } else { |
346 | 345 | // anonymous struct |
347 | | - NameBase = "anon"; |
| 346 | + Name.append("anon"); |
348 | 347 | MustBeUnique = true; |
349 | 348 | } |
350 | 349 |
|
351 | | - std::string Name = ("__layout_" + NameBase).str(); |
| 350 | + size_t NameLength = Name.size(); |
352 | 351 | IdentifierInfo *II = &AST.Idents.get(Name, tok::TokenKind::identifier); |
353 | 352 | if (!MustBeUnique) |
354 | 353 | return II; |
355 | 354 |
|
356 | 355 | unsigned suffix = 0; |
357 | 356 | 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 | + } |
361 | 362 | if (!findRecordDeclInContext(II, BaseDecl->getDeclContext())) |
362 | 363 | return II; |
363 | 364 | // declaration with that name already exists - increment suffix and try |
364 | 365 | // again until unique name is found |
365 | 366 | suffix++; |
| 367 | + Name.truncate(NameLength); |
366 | 368 | }; |
367 | 369 | } |
368 | 370 |
|
@@ -421,6 +423,8 @@ static CXXRecordDecl *createHostLayoutStruct(Sema &S, |
421 | 423 |
|
422 | 424 | // copy base struct, create HLSL Buffer compatible version if needed |
423 | 425 | if (unsigned NumBases = StructDecl->getNumBases()) { |
| 426 | + // FIXME: Filter out interfaces from the list of base classes |
| 427 | + // (llvm/llvm-project#124178) |
424 | 428 | assert(NumBases == 1 && "HLSL supports only one base type"); |
425 | 429 | CXXBaseSpecifier Base = *StructDecl->bases_begin(); |
426 | 430 | CXXRecordDecl *BaseDecl = Base.getType()->getAsCXXRecordDecl(); |
|
0 commit comments