Skip to content

Commit 4a5cde3

Browse files
committed
nfc: introduce wrapper RootSignatureElement around RootElement to retain clang diag info
1 parent 1a64eff commit 4a5cde3

File tree

6 files changed

+99
-72
lines changed

6 files changed

+99
-72
lines changed

clang/include/clang/Parse/ParseHLSLRootSignature.h

Lines changed: 15 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
@@ -196,7 +208,8 @@ class RootSignatureParser {
196208

197209
private:
198210
llvm::dxbc::RootSignatureVersion Version;
199-
SmallVector<llvm::hlsl::rootsig::RootElement> &Elements;
211+
SmallVector<RootSignatureElement> &Elements;
212+
200213
clang::StringLiteral *Signature;
201214
RootSignatureLexer Lexer;
202215
clang::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
@@ -4951,7 +4951,7 @@ void Parser::ParseHLSLRootSignatureAttributeArgs(ParsedAttributes &Attrs) {
49514951
// signature string and construct the in-memory elements
49524952
if (!Found) {
49534953
// Invoke the root signature parser to construct the in-memory constructs
4954-
SmallVector<llvm::hlsl::rootsig::RootElement> RootElements;
4954+
SmallVector<hlsl::RootSignatureElement> RootElements;
49554955
hlsl::RootSignatureParser Parser(getLangOpts().HLSLRootSigVer, RootElements,
49564956
Signature, PP);
49574957
if (Parser.parse()) {

clang/lib/Parse/ParseHLSLRootSignature.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,49 +19,54 @@ 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) {}
2626

2727
bool RootSignatureParser::parse() {
28-
// Iterate as many RootElements as possible
28+
// Iterate as many RootSignatureElements as possible
2929
do {
30+
std::optional<RootSignatureElement> Element = std::nullopt;
3031
if (tryConsumeExpectedToken(TokenKind::kw_RootFlags)) {
3132
auto Flags = parseRootFlags();
3233
if (!Flags.has_value())
3334
return true;
34-
Elements.push_back(*Flags);
35+
Element = RootSignatureElement(*Flags);
3536
}
3637

3738
if (tryConsumeExpectedToken(TokenKind::kw_RootConstants)) {
3839
auto Constants = parseRootConstants();
3940
if (!Constants.has_value())
4041
return true;
41-
Elements.push_back(*Constants);
42+
Element = RootSignatureElement(*Constants);
4243
}
4344

4445
if (tryConsumeExpectedToken(TokenKind::kw_DescriptorTable)) {
4546
auto Table = parseDescriptorTable();
4647
if (!Table.has_value())
4748
return true;
48-
Elements.push_back(*Table);
49+
Element = RootSignatureElement(*Table);
4950
}
5051

5152
if (tryConsumeExpectedToken(
5253
{TokenKind::kw_CBV, TokenKind::kw_SRV, TokenKind::kw_UAV})) {
5354
auto Descriptor = parseRootDescriptor();
5455
if (!Descriptor.has_value())
5556
return true;
56-
Elements.push_back(*Descriptor);
57+
Element = RootSignatureElement(*Descriptor);
5758
}
5859

5960
if (tryConsumeExpectedToken(TokenKind::kw_StaticSampler)) {
6061
auto Sampler = parseStaticSampler();
6162
if (!Sampler.has_value())
6263
return true;
63-
Elements.push_back(*Sampler);
64+
Element = RootSignatureElement(*Sampler);
6465
}
66+
67+
if (Element.has_value())
68+
Elements.push_back(*Element);
69+
6570
} while (tryConsumeExpectedToken(TokenKind::pu_comma));
6671

6772
return consumeExpectedToken(TokenKind::end_of_stream,
@@ -256,7 +261,7 @@ std::optional<DescriptorTable> RootSignatureParser::parseDescriptorTable() {
256261
auto Clause = parseDescriptorTableClause();
257262
if (!Clause.has_value())
258263
return std::nullopt;
259-
Elements.push_back(*Clause);
264+
Elements.push_back(RootSignatureElement(*Clause));
260265
Table.NumClauses++;
261266
}
262267

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)