46
46
using namespace clang ;
47
47
using RegisterType = HLSLResourceBindingAttr::RegisterType;
48
48
49
+ static CXXRecordDecl *createHostLayoutStruct (Sema &S, CXXRecordDecl *StructDecl,
50
+ HLSLBufferDecl *BufDecl);
51
+
49
52
static RegisterType getRegisterType (ResourceClass RC) {
50
53
switch (RC) {
51
54
case ResourceClass::SRV:
@@ -296,7 +299,7 @@ static CXXRecordDecl *findRecordDecl(Sema &S, IdentifierInfo *II,
296
299
DeclContext *DC) {
297
300
DeclarationNameInfo NameInfo =
298
301
DeclarationNameInfo (DeclarationName (II), SourceLocation ());
299
- LookupResult R (S, NameInfo, Sema::LookupOrdinaryName );
302
+ LookupResult R (S, NameInfo, Sema::LookupTagName );
300
303
S.LookupName (R, S.getScopeForContext (DC));
301
304
if (R.isSingleResult ())
302
305
return R.getAsSingle <CXXRecordDecl>();
@@ -311,24 +314,24 @@ static IdentifierInfo *getHostLayoutStructName(Sema &S,
311
314
bool MustBeUnique,
312
315
DeclContext *DC) {
313
316
ASTContext &AST = S.getASTContext ();
314
- std::string NameBase;
317
+ StringRef NameBase;
315
318
if (NameBaseII) {
316
- NameBase = NameBaseII->getName (). str () ;
319
+ NameBase = NameBaseII->getName ();
317
320
} else {
318
321
// anonymous struct
319
322
NameBase = " anon" ;
320
323
MustBeUnique = true ;
321
324
}
322
325
323
- std::string Name = " __layout_" + NameBase;
326
+ std::string Name = ( " __layout_" + NameBase). str () ;
324
327
IdentifierInfo *II = &AST.Idents .get (Name, tok::TokenKind::identifier);
325
328
if (!MustBeUnique)
326
329
return II;
327
330
328
331
unsigned suffix = 0 ;
329
332
while (true ) {
330
333
if (suffix != 0 )
331
- II = &AST.Idents .get ((llvm::Twine ( Name) + " _" + Twine (suffix)).str (),
334
+ II = &AST.Idents .get ((Name + " _" + Twine (suffix)).str (),
332
335
tok::TokenKind::identifier);
333
336
if (!findRecordDecl (S, II, DC))
334
337
return II;
@@ -343,9 +346,6 @@ static bool isResourceRecordType(const Type *Ty) {
343
346
return HLSLAttributedResourceType::findHandleTypeOnResource (Ty) != nullptr ;
344
347
}
345
348
346
- static CXXRecordDecl *createHostLayoutStruct (Sema &S, CXXRecordDecl *StructDecl,
347
- HLSLBufferDecl *BufDecl);
348
-
349
349
// Creates a field declaration of given name and type for HLSL buffer layout
350
350
// struct. Returns nullptr if the type cannot be use in HLSL Buffer layout.
351
351
static FieldDecl *createFieldForHostLayoutStruct (Sema &S, const Type *Ty,
@@ -362,10 +362,11 @@ static FieldDecl *createFieldForHostLayoutStruct(Sema &S, const Type *Ty,
362
362
return nullptr ;
363
363
Ty = RD->getTypeForDecl ();
364
364
}
365
- } else if (Ty->isConstantArrayType ()) {
366
- if (isZeroSizedArray (cast<ConstantArrayType>(Ty)))
367
- return nullptr ;
368
365
}
366
+ if (Ty->isConstantArrayType () &&
367
+ isZeroSizedArray (cast<ConstantArrayType>(Ty)))
368
+ return nullptr ;
369
+
369
370
QualType QT = QualType (Ty, 0 );
370
371
ASTContext &AST = S.getASTContext ();
371
372
TypeSourceInfo *TSI = AST.getTrivialTypeSourceInfo (QT, SourceLocation ());
0 commit comments