Skip to content

Commit 66ae784

Browse files
committed
Add LayoutStruct to HLSLBufferDecl; add skipping of implicit initializers
1 parent 6dc3a1a commit 66ae784

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed

clang/include/clang/AST/Decl.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5035,6 +5035,8 @@ class HLSLBufferDecl final : public NamedDecl, public DeclContext {
50355035
/// HasValidPackoffset - Whether the buffer has valid packoffset annotations
50365036
// on all declarations
50375037
bool HasPackoffset;
5038+
// LayoutStruct - Layout struct for the buffer
5039+
CXXRecordDecl *LayoutStruct;
50385040

50395041
HLSLBufferDecl(DeclContext *DC, bool CBuffer, SourceLocation KwLoc,
50405042
IdentifierInfo *ID, SourceLocation IDLoc,
@@ -5057,7 +5059,8 @@ class HLSLBufferDecl final : public NamedDecl, public DeclContext {
50575059
bool isCBuffer() const { return IsCBuffer; }
50585060
void setHasPackoffset(bool PO) { HasPackoffset = PO; }
50595061
bool hasPackoffset() const { return HasPackoffset; }
5060-
const CXXRecordDecl *getLayoutStruct() const;
5062+
const CXXRecordDecl *getLayoutStruct() const { return LayoutStruct; }
5063+
void addLayoutStruct(CXXRecordDecl *LS);
50615064

50625065
// Implement isa/cast/dyncast/etc.
50635066
static bool classof(const Decl *D) { return classofKind(D->getKind()); }

clang/lib/AST/Decl.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5717,7 +5717,7 @@ HLSLBufferDecl::HLSLBufferDecl(DeclContext *DC, bool CBuffer,
57175717
SourceLocation IDLoc, SourceLocation LBrace)
57185718
: NamedDecl(Decl::Kind::HLSLBuffer, DC, IDLoc, DeclarationName(ID)),
57195719
DeclContext(Decl::Kind::HLSLBuffer), LBraceLoc(LBrace), KwLoc(KwLoc),
5720-
IsCBuffer(CBuffer), HasPackoffset(false) {}
5720+
IsCBuffer(CBuffer), HasPackoffset(false), LayoutStruct(nullptr) {}
57215721

57225722
HLSLBufferDecl *HLSLBufferDecl::Create(ASTContext &C,
57235723
DeclContext *LexicalParent, bool CBuffer,
@@ -5747,15 +5747,10 @@ HLSLBufferDecl *HLSLBufferDecl::CreateDeserialized(ASTContext &C,
57475747
SourceLocation(), SourceLocation());
57485748
}
57495749

5750-
const CXXRecordDecl *HLSLBufferDecl::getLayoutStruct() const {
5751-
// Layout struct is the last decl in the HLSLBufferDecl.
5752-
if (CXXRecordDecl *RD = llvm::dyn_cast_or_null<CXXRecordDecl>(LastDecl)) {
5753-
assert(RD->getName().starts_with(
5754-
("__cblayout_" + getIdentifier()->getName()).str()) &&
5755-
"expected buffer layout struct");
5756-
return RD;
5757-
}
5758-
llvm_unreachable("HLSL buffer is missing a layout struct");
5750+
void HLSLBufferDecl::addLayoutStruct(CXXRecordDecl *LS) {
5751+
assert(LayoutStruct == nullptr && "layout struct has already been set");
5752+
LayoutStruct = LS;
5753+
addDecl(LS);
57595754
}
57605755

57615756
//===----------------------------------------------------------------------===//

clang/lib/Sema/SemaDecl.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14184,6 +14184,12 @@ void Sema::ActOnUninitializedDecl(Decl *RealDecl) {
1418414184
Var->getType().getAddressSpace() == LangAS::opencl_local)
1418514185
return;
1418614186

14187+
// In HLSL, objects in the hlsl_constant address space are initialized
14188+
// externally, so don't synthesize an implicit initializer.
14189+
if (getLangOpts().HLSL &&
14190+
Var->getType().getAddressSpace() == LangAS::hlsl_constant)
14191+
return;
14192+
1418714193
// C++03 [dcl.init]p9:
1418814194
// If no initializer is specified for an object, and the
1418914195
// object is of (possibly cv-qualified) non-POD class type (or

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ void createHostLayoutStructForBuffer(Sema &S, HLSLBufferDecl *BufDecl) {
502502
}
503503
}
504504
LS->completeDefinition();
505-
BufDecl->addDecl(LS);
505+
BufDecl->addLayoutStruct(LS);
506506
}
507507

508508
// Handle end of cbuffer/tbuffer declaration

0 commit comments

Comments
 (0)