Skip to content

Commit bef7466

Browse files
committed
nfc: introduce wrapper RootSignatureElement around RootElement to retain clang diag info
1 parent b9cf614 commit bef7466

File tree

6 files changed

+92
-71
lines changed

6 files changed

+92
-71
lines changed

clang/include/clang/Parse/ParseHLSLRootSignature.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,22 @@
2626
namespace clang {
2727
namespace hlsl {
2828

29+
// Introduce a wrapper struct around the underlying RootElement. This structure
30+
// will retain extra clang diagnostic information that is not available in llvm.
31+
struct RootSignatureElement {
32+
RootSignatureElement(llvm::hlsl::rootsig::RootElement Element)
33+
: Element(Element) {}
34+
35+
const llvm::hlsl::rootsig::RootElement &getElement() const { return Element; }
36+
37+
private:
38+
llvm::hlsl::rootsig::RootElement Element;
39+
};
40+
2941
class RootSignatureParser {
3042
public:
3143
RootSignatureParser(llvm::dxbc::RootSignatureVersion Version,
32-
SmallVector<llvm::hlsl::rootsig::RootElement> &Elements,
44+
SmallVector<RootSignatureElement> &Elements,
3345
StringLiteral *Signature, Preprocessor &PP);
3446

3547
/// Consumes tokens from the Lexer and constructs the in-memory
@@ -201,7 +213,7 @@ class RootSignatureParser {
201213

202214
private:
203215
llvm::dxbc::RootSignatureVersion Version;
204-
SmallVector<llvm::hlsl::rootsig::RootElement> &Elements;
216+
SmallVector<RootSignatureElement> &Elements;
205217
StringLiteral *Signature;
206218
RootSignatureLexer Lexer;
207219
Preprocessor &PP;

clang/include/clang/Sema/SemaHLSL.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ class ParsedAttr;
3232
class Scope;
3333
class VarDecl;
3434

35+
namespace hlsl {
36+
struct RootSignatureElement;
37+
}
38+
3539
using llvm::dxil::ResourceClass;
3640

3741
// FIXME: This can be hidden (as static function in SemaHLSL.cpp) once we no
@@ -130,9 +134,9 @@ class SemaHLSL : public SemaBase {
130134

131135
/// Creates the Root Signature decl of the parsed Root Signature elements
132136
/// onto the AST and push it onto current Scope
133-
void ActOnFinishRootSignatureDecl(
134-
SourceLocation Loc, IdentifierInfo *DeclIdent,
135-
SmallVector<llvm::hlsl::rootsig::RootElement> &Elements);
137+
void
138+
ActOnFinishRootSignatureDecl(SourceLocation Loc, IdentifierInfo *DeclIdent,
139+
ArrayRef<hlsl::RootSignatureElement> Elements);
136140

137141
// Returns true when D is invalid and a diagnostic was produced
138142
bool handleRootSignatureDecl(HLSLRootSignatureDecl *D, SourceLocation Loc);

clang/lib/Parse/ParseDeclCXX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4948,7 +4948,7 @@ void Parser::ParseHLSLRootSignatureAttributeArgs(ParsedAttributes &Attrs) {
49484948
// signature string and construct the in-memory elements
49494949
if (!Found) {
49504950
// Invoke the root signature parser to construct the in-memory constructs
4951-
SmallVector<llvm::hlsl::rootsig::RootElement> RootElements;
4951+
SmallVector<hlsl::RootSignatureElement> RootElements;
49524952
hlsl::RootSignatureParser Parser(getLangOpts().HLSLRootSigVer, RootElements,
49534953
Signature, PP);
49544954
if (Parser.parse()) {

clang/lib/Parse/ParseHLSLRootSignature.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ using TokenKind = RootSignatureToken::Kind;
1919

2020
RootSignatureParser::RootSignatureParser(
2121
llvm::dxbc::RootSignatureVersion Version,
22-
SmallVector<RootElement> &Elements, StringLiteral *Signature,
22+
SmallVector<RootSignatureElement> &Elements, StringLiteral *Signature,
2323
Preprocessor &PP)
2424
: Version(Version), Elements(Elements), Signature(Signature),
2525
Lexer(Signature->getString()), PP(PP), CurToken(0) {}
@@ -32,28 +32,28 @@ bool RootSignatureParser::parse() {
3232
auto Flags = parseRootFlags();
3333
if (!Flags.has_value())
3434
return true;
35-
Elements.push_back(*Flags);
35+
Elements.emplace_back(RootSignatureElement(*Flags));
3636
} else if (tryConsumeExpectedToken(TokenKind::kw_RootConstants)) {
3737
auto Constants = parseRootConstants();
3838
if (!Constants.has_value())
3939
return true;
40-
Elements.push_back(*Constants);
40+
Elements.emplace_back(RootSignatureElement(*Constants));
4141
} else if (tryConsumeExpectedToken(TokenKind::kw_DescriptorTable)) {
4242
auto Table = parseDescriptorTable();
4343
if (!Table.has_value())
4444
return true;
45-
Elements.push_back(*Table);
45+
Elements.emplace_back(RootSignatureElement(*Table));
4646
} else if (tryConsumeExpectedToken(
4747
{TokenKind::kw_CBV, TokenKind::kw_SRV, TokenKind::kw_UAV})) {
4848
auto Descriptor = parseRootDescriptor();
4949
if (!Descriptor.has_value())
5050
return true;
51-
Elements.push_back(*Descriptor);
51+
Elements.emplace_back(RootSignatureElement(*Descriptor));
5252
} else if (tryConsumeExpectedToken(TokenKind::kw_StaticSampler)) {
5353
auto Sampler = parseStaticSampler();
5454
if (!Sampler.has_value())
5555
return true;
56-
Elements.push_back(*Sampler);
56+
Elements.emplace_back(RootSignatureElement(*Sampler));
5757
}
5858

5959
// ',' denotes another element, otherwise, expected to be at end of stream
@@ -248,7 +248,7 @@ std::optional<DescriptorTable> RootSignatureParser::parseDescriptorTable() {
248248
auto Clause = parseDescriptorTableClause();
249249
if (!Clause.has_value())
250250
return std::nullopt;
251-
Elements.push_back(*Clause);
251+
Elements.push_back(RootSignatureElement(*Clause));
252252
Table.NumClauses++;
253253
} else if (tryConsumeExpectedToken(TokenKind::kw_visibility)) {
254254
// visibility = SHADER_VISIBILITY

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1064,7 +1064,11 @@ SemaHLSL::ActOnStartRootSignatureDecl(StringRef Signature) {
10641064

10651065
void SemaHLSL::ActOnFinishRootSignatureDecl(
10661066
SourceLocation Loc, IdentifierInfo *DeclIdent,
1067-
SmallVector<llvm::hlsl::rootsig::RootElement> &Elements) {
1067+
ArrayRef<hlsl::RootSignatureElement> RootElements) {
1068+
1069+
SmallVector<llvm::hlsl::rootsig::RootElement> Elements;
1070+
for (auto &RootSigElement : RootElements)
1071+
Elements.push_back(RootSigElement.getElement());
10681072

10691073
auto *SignatureDecl = HLSLRootSignatureDecl::Create(
10701074
SemaRef.getASTContext(), /*DeclContext=*/SemaRef.CurContext, Loc,

0 commit comments

Comments
 (0)