https://github.com/inbelic updated https://github.com/llvm/llvm-project/pull/147084
>From 34d3879022f65d51002d3abe3aec50a952ca6e18 Mon Sep 17 00:00:00 2001 From: Finn Plummer <canadienf...@gmail.com> Date: Fri, 4 Jul 2025 00:13:32 +0000 Subject: [PATCH 1/6] nfc: add phony ASTContext and StringLiteral to ParseHLSL --- .../Parse/ParseHLSLRootSignatureTest.cpp | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp b/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp index 871f12ef3cce3..6f00c042404b0 100644 --- a/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp +++ b/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp @@ -6,6 +6,8 @@ // //===----------------------------------------------------------------------===// +#include "clang/AST/ASTContext.h" +#include "clang/AST/Expr.h" #include "clang/Basic/Diagnostic.h" #include "clang/Basic/DiagnosticOptions.h" #include "clang/Basic/FileManager.h" @@ -93,6 +95,22 @@ class ParseHLSLRootSignatureTest : public ::testing::Test { return PP; } + std::unique_ptr<ASTContext> createMinimalASTContext() { + IdentifierTable Idents(LangOpts); + SelectorTable Selectors; + Builtin::Context Builtins; + + return std::make_unique<ASTContext>(LangOpts, SourceMgr, Idents, Selectors, + Builtins, TU_Complete); + } + + StringLiteral *wrapSource(std::unique_ptr<ASTContext> &Ctx, + StringRef Source) { + SourceLocation Locs[1] = {SourceLocation()}; + return StringLiteral::Create(*Ctx, Source, StringLiteralKind::Unevaluated, + false, Ctx->VoidTy, Locs); + } + FileSystemOptions FileMgrOpts; FileManager FileMgr; IntrusiveRefCntPtr<DiagnosticIDs> DiagID; @@ -111,6 +129,9 @@ class ParseHLSLRootSignatureTest : public ::testing::Test { TEST_F(ParseHLSLRootSignatureTest, ValidParseEmptyTest) { const llvm::StringLiteral Source = R"cc()cc"; + auto Ctx = createMinimalASTContext(); + StringLiteral *Signature = wrapSource(Ctx, Source); + TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); auto TokLoc = SourceLocation(); @@ -146,6 +167,9 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseDTClausesTest) { DescriptorTable() )cc"; + auto Ctx = createMinimalASTContext(); + StringLiteral *Signature = wrapSource(Ctx, Source); + TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); auto TokLoc = SourceLocation(); @@ -250,6 +274,9 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseStaticSamplerTest) { ) )cc"; + auto Ctx = createMinimalASTContext(); + StringLiteral *Signature = wrapSource(Ctx, Source); + TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); auto TokLoc = SourceLocation(); @@ -336,6 +363,9 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseFloatsTest) { StaticSampler(s0, mipLODBias = 2147483648), )cc"; + auto Ctx = createMinimalASTContext(); + StringLiteral *Signature = wrapSource(Ctx, Source); + TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); auto TokLoc = SourceLocation(); @@ -412,6 +442,9 @@ TEST_F(ParseHLSLRootSignatureTest, ValidSamplerFlagsTest) { DescriptorTable(Sampler(s0, flags = DESCRIPTORS_VOLATILE)) )cc"; + auto Ctx = createMinimalASTContext(); + StringLiteral *Signature = wrapSource(Ctx, Source); + TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); auto TokLoc = SourceLocation(); @@ -444,6 +477,9 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootConsantsTest) { ) )cc"; + auto Ctx = createMinimalASTContext(); + StringLiteral *Signature = wrapSource(Ctx, Source); + TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); auto TokLoc = SourceLocation(); @@ -502,6 +538,9 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootFlagsTest) { ) )cc"; + auto Ctx = createMinimalASTContext(); + StringLiteral *Signature = wrapSource(Ctx, Source); + TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); auto TokLoc = SourceLocation(); @@ -556,6 +595,9 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootDescriptorsTest) { CBV(b0, flags = 0), )cc"; + auto Ctx = createMinimalASTContext(); + StringLiteral *Signature = wrapSource(Ctx, Source); + TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); auto TokLoc = SourceLocation(); @@ -631,6 +673,9 @@ TEST_F(ParseHLSLRootSignatureTest, ValidTrailingCommaTest) { ) )cc"; + auto Ctx = createMinimalASTContext(); + StringLiteral *Signature = wrapSource(Ctx, Source); + TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); auto TokLoc = SourceLocation(); @@ -802,6 +847,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseUnexpectedTokenTest) { space )cc"; + auto Ctx = createMinimalASTContext(); + StringLiteral *Signature = wrapSource(Ctx, Source); + TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); auto TokLoc = SourceLocation(); @@ -823,6 +871,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseInvalidTokenTest) { notAnIdentifier )cc"; + auto Ctx = createMinimalASTContext(); + StringLiteral *Signature = wrapSource(Ctx, Source); + TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); auto TokLoc = SourceLocation(); @@ -844,6 +895,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseUnexpectedEndOfStreamTest) { DescriptorTable )cc"; + auto Ctx = createMinimalASTContext(); + StringLiteral *Signature = wrapSource(Ctx, Source); + TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); auto TokLoc = SourceLocation(); @@ -870,6 +924,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidMissingDTParameterTest) { ) )cc"; + auto Ctx = createMinimalASTContext(); + StringLiteral *Signature = wrapSource(Ctx, Source); + TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); auto TokLoc = SourceLocation(); @@ -893,6 +950,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidMissingRDParameterTest) { SRV() )cc"; + auto Ctx = createMinimalASTContext(); + StringLiteral *Signature = wrapSource(Ctx, Source); + TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); auto TokLoc = SourceLocation(); @@ -916,6 +976,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidMissingRCParameterTest) { RootConstants(b0) )cc"; + auto Ctx = createMinimalASTContext(); + StringLiteral *Signature = wrapSource(Ctx, Source); + TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); auto TokLoc = SourceLocation(); @@ -941,6 +1004,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedMandatoryDTParameterTest) { ) )cc"; + auto Ctx = createMinimalASTContext(); + StringLiteral *Signature = wrapSource(Ctx, Source); + TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); auto TokLoc = SourceLocation(); @@ -964,6 +1030,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedMandatoryRCParameterTest) { RootConstants(num32BitConstants = 32, num32BitConstants = 24) )cc"; + auto Ctx = createMinimalASTContext(); + StringLiteral *Signature = wrapSource(Ctx, Source); + TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); auto TokLoc = SourceLocation(); @@ -989,6 +1058,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedOptionalDTParameterTest) { ) )cc"; + auto Ctx = createMinimalASTContext(); + StringLiteral *Signature = wrapSource(Ctx, Source); + TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); auto TokLoc = SourceLocation(); @@ -1016,6 +1088,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedOptionalRCParameterTest) { ) )cc"; + auto Ctx = createMinimalASTContext(); + StringLiteral *Signature = wrapSource(Ctx, Source); + TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); auto TokLoc = SourceLocation(); @@ -1040,6 +1115,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedNumberTest) { ) )cc"; + auto Ctx = createMinimalASTContext(); + StringLiteral *Signature = wrapSource(Ctx, Source); + TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); auto TokLoc = SourceLocation(); @@ -1063,6 +1141,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseOverflowedNegativeNumberTest) { StaticSampler(s0, mipLODBias = -4294967295) )cc"; + auto Ctx = createMinimalASTContext(); + StringLiteral *Signature = wrapSource(Ctx, Source); + TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); auto TokLoc = SourceLocation(); @@ -1085,6 +1166,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedFloatTest) { StaticSampler(s0, mipLODBias = 3.402823467e+38F) )cc"; + auto Ctx = createMinimalASTContext(); + StringLiteral *Signature = wrapSource(Ctx, Source); + TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); auto TokLoc = SourceLocation(); @@ -1107,6 +1191,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexNegOverflowedFloatTest) { StaticSampler(s0, mipLODBias = -3.402823467e+38F) )cc"; + auto Ctx = createMinimalASTContext(); + StringLiteral *Signature = wrapSource(Ctx, Source); + TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); auto TokLoc = SourceLocation(); @@ -1129,6 +1216,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedDoubleTest) { StaticSampler(s0, mipLODBias = 1.e+500) )cc"; + auto Ctx = createMinimalASTContext(); + StringLiteral *Signature = wrapSource(Ctx, Source); + TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); auto TokLoc = SourceLocation(); @@ -1151,6 +1241,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexUnderflowFloatTest) { StaticSampler(s0, mipLODBias = 10e-309) )cc"; + auto Ctx = createMinimalASTContext(); + StringLiteral *Signature = wrapSource(Ctx, Source); + TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); auto TokLoc = SourceLocation(); @@ -1176,6 +1269,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidNonZeroFlagsTest) { ) )cc"; + auto Ctx = createMinimalASTContext(); + StringLiteral *Signature = wrapSource(Ctx, Source); + TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); auto TokLoc = SourceLocation(); >From d84d287203cc6f6d3d6cfbd4d8931d4267569a75 Mon Sep 17 00:00:00 2001 From: Finn Plummer <canadienf...@gmail.com> Date: Fri, 4 Jul 2025 00:22:12 +0000 Subject: [PATCH 2/6] nfc: add StringLiteral as a member of RootSignatureParser --- .../clang/Parse/ParseHLSLRootSignature.h | 5 +- clang/lib/Parse/ParseDeclCXX.cpp | 11 ++-- clang/lib/Parse/ParseHLSLRootSignature.cpp | 6 +-- .../Parse/ParseHLSLRootSignatureTest.cpp | 52 +++++++++---------- 4 files changed, 38 insertions(+), 36 deletions(-) diff --git a/clang/include/clang/Parse/ParseHLSLRootSignature.h b/clang/include/clang/Parse/ParseHLSLRootSignature.h index 66a5a3b7eaad0..2eb0eac34f4a1 100644 --- a/clang/include/clang/Parse/ParseHLSLRootSignature.h +++ b/clang/include/clang/Parse/ParseHLSLRootSignature.h @@ -13,6 +13,7 @@ #ifndef LLVM_CLANG_PARSE_PARSEHLSLROOTSIGNATURE_H #define LLVM_CLANG_PARSE_PARSEHLSLROOTSIGNATURE_H +#include "clang/AST/Expr.h" #include "clang/Basic/DiagnosticParse.h" #include "clang/Lex/LexHLSLRootSignature.h" #include "clang/Lex/Preprocessor.h" @@ -29,7 +30,8 @@ class RootSignatureParser { public: RootSignatureParser(llvm::dxbc::RootSignatureVersion Version, SmallVector<llvm::hlsl::rootsig::RootElement> &Elements, - RootSignatureLexer &Lexer, clang::Preprocessor &PP); + RootSignatureLexer &Lexer, StringLiteral *Signature, + Preprocessor &PP); /// Consumes tokens from the Lexer and constructs the in-memory /// representations of the RootElements. Tokens are consumed until an @@ -192,6 +194,7 @@ class RootSignatureParser { SmallVector<llvm::hlsl::rootsig::RootElement> &Elements; RootSignatureLexer &Lexer; + clang::StringLiteral *Signature; clang::Preprocessor &PP; RootSignatureToken CurToken; diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index 6b0564dca6f45..8d730d25a831a 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -4944,20 +4944,19 @@ void Parser::ParseHLSLRootSignatureAttributeArgs(ParsedAttributes &Attrs) { } // Construct our identifier - StringRef Signature = StrLiteral.value()->getString(); + StringLiteral *Signature = StrLiteral.value(); auto [DeclIdent, Found] = - Actions.HLSL().ActOnStartRootSignatureDecl(Signature); + Actions.HLSL().ActOnStartRootSignatureDecl(Signature->getString()); // If we haven't found an already defined DeclIdent then parse the root // signature string and construct the in-memory elements if (!Found) { // Offset location 1 to account for '"' - SourceLocation SignatureLoc = - StrLiteral.value()->getExprLoc().getLocWithOffset(1); + SourceLocation SignatureLoc = Signature->getExprLoc().getLocWithOffset(1); // Invoke the root signature parser to construct the in-memory constructs - hlsl::RootSignatureLexer Lexer(Signature, SignatureLoc); + hlsl::RootSignatureLexer Lexer(Signature->getString(), SignatureLoc); SmallVector<llvm::hlsl::rootsig::RootElement> RootElements; hlsl::RootSignatureParser Parser(getLangOpts().HLSLRootSigVer, RootElements, - Lexer, PP); + Lexer, Signature, PP); if (Parser.parse()) { T.consumeClose(); return; diff --git a/clang/lib/Parse/ParseHLSLRootSignature.cpp b/clang/lib/Parse/ParseHLSLRootSignature.cpp index 96d3999ff2acb..33c843d7b5fcf 100644 --- a/clang/lib/Parse/ParseHLSLRootSignature.cpp +++ b/clang/lib/Parse/ParseHLSLRootSignature.cpp @@ -20,9 +20,9 @@ using TokenKind = RootSignatureToken::Kind; RootSignatureParser::RootSignatureParser( llvm::dxbc::RootSignatureVersion Version, SmallVector<RootElement> &Elements, RootSignatureLexer &Lexer, - Preprocessor &PP) - : Version(Version), Elements(Elements), Lexer(Lexer), PP(PP), - CurToken(SourceLocation()) {} + StringLiteral *Signature, Preprocessor &PP) + : Version(Version), Elements(Elements), Signature(Signature), Lexer(Lexer), + PP(PP), CurToken(SourceLocation()) {} bool RootSignatureParser::parse() { // Iterate as many RootElements as possible diff --git a/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp b/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp index 6f00c042404b0..b06e5d4711773 100644 --- a/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp +++ b/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp @@ -139,7 +139,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseEmptyTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, - *PP); + Signature, *PP); // Test no diagnostics produced Consumer->setNoDiag(); @@ -177,7 +177,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseDTClausesTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, - *PP); + Signature, *PP); // Test no diagnostics produced Consumer->setNoDiag(); @@ -284,7 +284,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseStaticSamplerTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, - *PP); + Signature, *PP); // Test no diagnostics produced Consumer->setNoDiag(); @@ -373,7 +373,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseFloatsTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, - *PP); + Signature, *PP); // Test no diagnostics produced Consumer->setNoDiag(); @@ -452,7 +452,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidSamplerFlagsTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, - *PP); + Signature, *PP); // Test no diagnostics produced Consumer->setNoDiag(); @@ -487,7 +487,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootConsantsTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, - *PP); + Signature, *PP); // Test no diagnostics produced Consumer->setNoDiag(); @@ -548,7 +548,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootFlagsTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, - *PP); + Signature, *PP); // Test no diagnostics produced Consumer->setNoDiag(); @@ -605,7 +605,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootDescriptorsTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, - *PP); + Signature, *PP); // Test no diagnostics produced Consumer->setNoDiag(); @@ -683,7 +683,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidTrailingCommaTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, - *PP); + Signature, *PP); // Test no diagnostics produced Consumer->setNoDiag(); @@ -857,7 +857,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseUnexpectedTokenTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, - *PP); + Signature, *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_unexpected_end_of_params); @@ -881,7 +881,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseInvalidTokenTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, - *PP); + Signature, *PP); // Test correct diagnostic produced - invalid token Consumer->setExpected(diag::err_hlsl_unexpected_end_of_params); @@ -905,7 +905,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseUnexpectedEndOfStreamTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, - *PP); + Signature, *PP); // Test correct diagnostic produced - end of stream Consumer->setExpected(diag::err_expected_after); @@ -934,7 +934,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidMissingDTParameterTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, - *PP); + Signature, *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_rootsig_missing_param); @@ -960,7 +960,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidMissingRDParameterTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, - *PP); + Signature, *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_rootsig_missing_param); @@ -986,7 +986,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidMissingRCParameterTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, - *PP); + Signature, *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_rootsig_missing_param); @@ -1014,7 +1014,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedMandatoryDTParameterTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, - *PP); + Signature, *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_rootsig_repeat_param); @@ -1040,7 +1040,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedMandatoryRCParameterTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, - *PP); + Signature, *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_rootsig_repeat_param); @@ -1068,7 +1068,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedOptionalDTParameterTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, - *PP); + Signature, *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_rootsig_repeat_param); @@ -1098,7 +1098,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedOptionalRCParameterTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, - *PP); + Signature, *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_rootsig_repeat_param); @@ -1125,7 +1125,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedNumberTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, - *PP); + Signature, *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_number_literal_overflow); @@ -1151,7 +1151,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseOverflowedNegativeNumberTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, - *PP); + Signature, *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_number_literal_overflow); @@ -1176,7 +1176,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedFloatTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, - *PP); + Signature, *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_number_literal_overflow); @@ -1201,7 +1201,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexNegOverflowedFloatTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, - *PP); + Signature, *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_number_literal_overflow); @@ -1226,7 +1226,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedDoubleTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, - *PP); + Signature, *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_number_literal_overflow); @@ -1251,7 +1251,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexUnderflowFloatTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, - *PP); + Signature, *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_number_literal_underflow); @@ -1279,7 +1279,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidNonZeroFlagsTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, - *PP); + Signature, *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_rootsig_non_zero_flag); >From 9351946477a3aba890938a326b88c19532087fdb Mon Sep 17 00:00:00 2001 From: Finn Plummer <canadienf...@gmail.com> Date: Fri, 4 Jul 2025 15:55:48 +0000 Subject: [PATCH 3/6] update `RootSignatureToken` to hold the offset into the signature string --- .../include/clang/Lex/LexHLSLRootSignature.h | 22 ++- .../clang/Parse/ParseHLSLRootSignature.h | 6 + clang/lib/Lex/LexHLSLRootSignature.cpp | 6 +- clang/lib/Parse/ParseDeclCXX.cpp | 4 +- clang/lib/Parse/ParseHLSLRootSignature.cpp | 142 +++++++++++------- .../Lex/LexHLSLRootSignatureTest.cpp | 13 +- .../Parse/ParseHLSLRootSignatureTest.cpp | 78 ++++------ 7 files changed, 141 insertions(+), 130 deletions(-) diff --git a/clang/include/clang/Lex/LexHLSLRootSignature.h b/clang/include/clang/Lex/LexHLSLRootSignature.h index 9901485b44d38..9bfefc96335b8 100644 --- a/clang/include/clang/Lex/LexHLSLRootSignature.h +++ b/clang/include/clang/Lex/LexHLSLRootSignature.h @@ -31,16 +31,17 @@ struct RootSignatureToken { Kind TokKind = Kind::invalid; - // Retain the SouceLocation of the token for diagnostics - clang::SourceLocation TokLoc; + // Retain the location offset of the token in the Signature + // string + uint32_t LocOffset; // Retain spelling of an numeric constant to be parsed later StringRef NumSpelling; // Constructors - RootSignatureToken(clang::SourceLocation TokLoc) : TokLoc(TokLoc) {} - RootSignatureToken(Kind TokKind, clang::SourceLocation TokLoc) - : TokKind(TokKind), TokLoc(TokLoc) {} + RootSignatureToken(uint32_t LocOffset) : LocOffset(LocOffset) {} + RootSignatureToken(Kind TokKind, uint32_t LocOffset) + : TokKind(TokKind), LocOffset(LocOffset) {} }; inline const DiagnosticBuilder & @@ -61,8 +62,7 @@ operator<<(const DiagnosticBuilder &DB, const RootSignatureToken::Kind Kind) { class RootSignatureLexer { public: - RootSignatureLexer(StringRef Signature, clang::SourceLocation SourceLoc) - : Buffer(Signature), SourceLoc(SourceLoc) {} + RootSignatureLexer(StringRef Signature) : Buffer(Signature) {} /// Consumes and returns the next token. RootSignatureToken consumeToken(); @@ -76,15 +76,13 @@ class RootSignatureLexer { } private: - // Internal buffer to iterate over + // Internal buffer state StringRef Buffer; + uint32_t LocOffset = 0; // Current peek state std::optional<RootSignatureToken> NextToken = std::nullopt; - // Passed down parameters from Sema - clang::SourceLocation SourceLoc; - /// Consumes the buffer and returns the lexed token. RootSignatureToken lexToken(); @@ -92,7 +90,7 @@ class RootSignatureLexer { /// Updates the SourceLocation appropriately. void advanceBuffer(unsigned NumCharacters = 1) { Buffer = Buffer.drop_front(NumCharacters); - SourceLoc = SourceLoc.getLocWithOffset(NumCharacters); + LocOffset += NumCharacters; } }; diff --git a/clang/include/clang/Parse/ParseHLSLRootSignature.h b/clang/include/clang/Parse/ParseHLSLRootSignature.h index 2eb0eac34f4a1..e6c770a409233 100644 --- a/clang/include/clang/Parse/ParseHLSLRootSignature.h +++ b/clang/include/clang/Parse/ParseHLSLRootSignature.h @@ -189,6 +189,12 @@ class RootSignatureParser { bool tryConsumeExpectedToken(RootSignatureToken::Kind Expected); bool tryConsumeExpectedToken(ArrayRef<RootSignatureToken::Kind> Expected); + /// Convert the token's offset in the signature string to its SourceLocation + /// + /// This allows to currently retrieve the location for multi-token + /// StringLiterals + SourceLocation getTokenLocation(RootSignatureToken Tok); + private: llvm::dxbc::RootSignatureVersion Version; SmallVector<llvm::hlsl::rootsig::RootElement> &Elements; diff --git a/clang/lib/Lex/LexHLSLRootSignature.cpp b/clang/lib/Lex/LexHLSLRootSignature.cpp index e5de9ad15b07f..a89462c13c8e3 100644 --- a/clang/lib/Lex/LexHLSLRootSignature.cpp +++ b/clang/lib/Lex/LexHLSLRootSignature.cpp @@ -27,10 +27,10 @@ RootSignatureToken RootSignatureLexer::lexToken() { advanceBuffer(Buffer.take_while(isspace).size()); if (isEndOfBuffer()) - return RootSignatureToken(TokenKind::end_of_stream, SourceLoc); + return RootSignatureToken(TokenKind::end_of_stream, LocOffset); // Record where this token is in the text for usage in parser diagnostics - RootSignatureToken Result(SourceLoc); + RootSignatureToken Result(LocOffset); char C = Buffer.front(); @@ -62,7 +62,7 @@ RootSignatureToken RootSignatureLexer::lexToken() { // All following tokens require at least one additional character if (Buffer.size() <= 1) { - Result = RootSignatureToken(TokenKind::invalid, SourceLoc); + Result = RootSignatureToken(TokenKind::invalid, LocOffset); return Result; } diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index 8d730d25a831a..04df8681269fd 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -4950,10 +4950,8 @@ void Parser::ParseHLSLRootSignatureAttributeArgs(ParsedAttributes &Attrs) { // If we haven't found an already defined DeclIdent then parse the root // signature string and construct the in-memory elements if (!Found) { - // Offset location 1 to account for '"' - SourceLocation SignatureLoc = Signature->getExprLoc().getLocWithOffset(1); // Invoke the root signature parser to construct the in-memory constructs - hlsl::RootSignatureLexer Lexer(Signature->getString(), SignatureLoc); + hlsl::RootSignatureLexer Lexer(Signature->getString()); SmallVector<llvm::hlsl::rootsig::RootElement> RootElements; hlsl::RootSignatureParser Parser(getLangOpts().HLSLRootSigVer, RootElements, Lexer, Signature, PP); diff --git a/clang/lib/Parse/ParseHLSLRootSignature.cpp b/clang/lib/Parse/ParseHLSLRootSignature.cpp index 33c843d7b5fcf..2244f09d1a3b0 100644 --- a/clang/lib/Parse/ParseHLSLRootSignature.cpp +++ b/clang/lib/Parse/ParseHLSLRootSignature.cpp @@ -22,7 +22,7 @@ RootSignatureParser::RootSignatureParser( SmallVector<RootElement> &Elements, RootSignatureLexer &Lexer, StringLiteral *Signature, Preprocessor &PP) : Version(Version), Elements(Elements), Signature(Signature), Lexer(Lexer), - PP(PP), CurToken(SourceLocation()) {} + PP(PP), CurToken(0) {} bool RootSignatureParser::parse() { // Iterate as many RootElements as possible @@ -91,7 +91,8 @@ std::optional<llvm::dxbc::RootFlags> RootSignatureParser::parseRootFlags() { // Handle the edge-case of '0' to specify no flags set if (tryConsumeExpectedToken(TokenKind::int_literal)) { if (!verifyZeroFlag()) { - getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_non_zero_flag); + getDiags().Report(getTokenLocation(CurToken), + diag::err_hlsl_rootsig_non_zero_flag); return std::nullopt; } } else { @@ -141,7 +142,8 @@ std::optional<RootConstants> RootSignatureParser::parseRootConstants() { // Check mandatory parameters where provided if (!Params->Num32BitConstants.has_value()) { - getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_missing_param) + getDiags().Report(getTokenLocation(CurToken), + diag::err_hlsl_rootsig_missing_param) << TokenKind::kw_num32BitConstants; return std::nullopt; } @@ -149,7 +151,8 @@ std::optional<RootConstants> RootSignatureParser::parseRootConstants() { Constants.Num32BitConstants = Params->Num32BitConstants.value(); if (!Params->Reg.has_value()) { - getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_missing_param) + getDiags().Report(getTokenLocation(CurToken), + diag::err_hlsl_rootsig_missing_param) << TokenKind::bReg; return std::nullopt; } @@ -209,7 +212,8 @@ std::optional<RootDescriptor> RootSignatureParser::parseRootDescriptor() { // Check mandatory parameters were provided if (!Params->Reg.has_value()) { - getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_missing_param) + getDiags().Report(getTokenLocation(CurToken), + diag::err_hlsl_rootsig_missing_param) << ExpectedReg; return std::nullopt; } @@ -258,7 +262,8 @@ std::optional<DescriptorTable> RootSignatureParser::parseDescriptorTable() { if (tryConsumeExpectedToken(TokenKind::kw_visibility)) { if (Visibility.has_value()) { - getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param) + getDiags().Report(getTokenLocation(CurToken), + diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } @@ -328,7 +333,8 @@ RootSignatureParser::parseDescriptorTableClause() { // Check mandatory parameters were provided if (!Params->Reg.has_value()) { - getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_missing_param) + getDiags().Report(getTokenLocation(CurToken), + diag::err_hlsl_rootsig_missing_param) << ExpectedReg; return std::nullopt; } @@ -372,7 +378,8 @@ std::optional<StaticSampler> RootSignatureParser::parseStaticSampler() { // Check mandatory parameters were provided if (!Params->Reg.has_value()) { - getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_missing_param) + getDiags().Report(getTokenLocation(CurToken), + diag::err_hlsl_rootsig_missing_param) << TokenKind::sReg; return std::nullopt; } @@ -437,7 +444,8 @@ RootSignatureParser::parseRootConstantParams() { // `num32BitConstants` `=` POS_INT if (tryConsumeExpectedToken(TokenKind::kw_num32BitConstants)) { if (Params.Num32BitConstants.has_value()) { - getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param) + getDiags().Report(getTokenLocation(CurToken), + diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } @@ -454,7 +462,8 @@ RootSignatureParser::parseRootConstantParams() { // `b` POS_INT if (tryConsumeExpectedToken(TokenKind::bReg)) { if (Params.Reg.has_value()) { - getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param) + getDiags().Report(getTokenLocation(CurToken), + diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } @@ -467,7 +476,8 @@ RootSignatureParser::parseRootConstantParams() { // `space` `=` POS_INT if (tryConsumeExpectedToken(TokenKind::kw_space)) { if (Params.Space.has_value()) { - getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param) + getDiags().Report(getTokenLocation(CurToken), + diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } @@ -484,7 +494,8 @@ RootSignatureParser::parseRootConstantParams() { // `visibility` `=` SHADER_VISIBILITY if (tryConsumeExpectedToken(TokenKind::kw_visibility)) { if (Params.Visibility.has_value()) { - getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param) + getDiags().Report(getTokenLocation(CurToken), + diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } @@ -512,7 +523,8 @@ RootSignatureParser::parseRootDescriptorParams(TokenKind RegType) { // ( `b` | `t` | `u`) POS_INT if (tryConsumeExpectedToken(RegType)) { if (Params.Reg.has_value()) { - getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param) + getDiags().Report(getTokenLocation(CurToken), + diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } @@ -525,7 +537,8 @@ RootSignatureParser::parseRootDescriptorParams(TokenKind RegType) { // `space` `=` POS_INT if (tryConsumeExpectedToken(TokenKind::kw_space)) { if (Params.Space.has_value()) { - getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param) + getDiags().Report(getTokenLocation(CurToken), + diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } @@ -542,7 +555,8 @@ RootSignatureParser::parseRootDescriptorParams(TokenKind RegType) { // `visibility` `=` SHADER_VISIBILITY if (tryConsumeExpectedToken(TokenKind::kw_visibility)) { if (Params.Visibility.has_value()) { - getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param) + getDiags().Report(getTokenLocation(CurToken), + diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } @@ -559,7 +573,8 @@ RootSignatureParser::parseRootDescriptorParams(TokenKind RegType) { // `flags` `=` ROOT_DESCRIPTOR_FLAGS if (tryConsumeExpectedToken(TokenKind::kw_flags)) { if (Params.Flags.has_value()) { - getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param) + getDiags().Report(getTokenLocation(CurToken), + diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } @@ -587,7 +602,8 @@ RootSignatureParser::parseDescriptorTableClauseParams(TokenKind RegType) { // ( `b` | `t` | `u` | `s`) POS_INT if (tryConsumeExpectedToken(RegType)) { if (Params.Reg.has_value()) { - getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param) + getDiags().Report(getTokenLocation(CurToken), + diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } @@ -600,7 +616,8 @@ RootSignatureParser::parseDescriptorTableClauseParams(TokenKind RegType) { // `numDescriptors` `=` POS_INT | unbounded if (tryConsumeExpectedToken(TokenKind::kw_numDescriptors)) { if (Params.NumDescriptors.has_value()) { - getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param) + getDiags().Report(getTokenLocation(CurToken), + diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } @@ -623,7 +640,8 @@ RootSignatureParser::parseDescriptorTableClauseParams(TokenKind RegType) { // `space` `=` POS_INT if (tryConsumeExpectedToken(TokenKind::kw_space)) { if (Params.Space.has_value()) { - getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param) + getDiags().Report(getTokenLocation(CurToken), + diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } @@ -640,7 +658,8 @@ RootSignatureParser::parseDescriptorTableClauseParams(TokenKind RegType) { // `offset` `=` POS_INT | DESCRIPTOR_RANGE_OFFSET_APPEND if (tryConsumeExpectedToken(TokenKind::kw_offset)) { if (Params.Offset.has_value()) { - getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param) + getDiags().Report(getTokenLocation(CurToken), + diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } @@ -663,7 +682,8 @@ RootSignatureParser::parseDescriptorTableClauseParams(TokenKind RegType) { // `flags` `=` DESCRIPTOR_RANGE_FLAGS if (tryConsumeExpectedToken(TokenKind::kw_flags)) { if (Params.Flags.has_value()) { - getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param) + getDiags().Report(getTokenLocation(CurToken), + diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } @@ -692,7 +712,8 @@ RootSignatureParser::parseStaticSamplerParams() { // `s` POS_INT if (tryConsumeExpectedToken(TokenKind::sReg)) { if (Params.Reg.has_value()) { - getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param) + getDiags().Report(getTokenLocation(CurToken), + diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } @@ -705,7 +726,8 @@ RootSignatureParser::parseStaticSamplerParams() { // `filter` `=` FILTER if (tryConsumeExpectedToken(TokenKind::kw_filter)) { if (Params.Filter.has_value()) { - getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param) + getDiags().Report(getTokenLocation(CurToken), + diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } @@ -722,7 +744,8 @@ RootSignatureParser::parseStaticSamplerParams() { // `addressU` `=` TEXTURE_ADDRESS if (tryConsumeExpectedToken(TokenKind::kw_addressU)) { if (Params.AddressU.has_value()) { - getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param) + getDiags().Report(getTokenLocation(CurToken), + diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } @@ -739,7 +762,8 @@ RootSignatureParser::parseStaticSamplerParams() { // `addressV` `=` TEXTURE_ADDRESS if (tryConsumeExpectedToken(TokenKind::kw_addressV)) { if (Params.AddressV.has_value()) { - getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param) + getDiags().Report(getTokenLocation(CurToken), + diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } @@ -756,7 +780,8 @@ RootSignatureParser::parseStaticSamplerParams() { // `addressW` `=` TEXTURE_ADDRESS if (tryConsumeExpectedToken(TokenKind::kw_addressW)) { if (Params.AddressW.has_value()) { - getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param) + getDiags().Report(getTokenLocation(CurToken), + diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } @@ -773,7 +798,8 @@ RootSignatureParser::parseStaticSamplerParams() { // `mipLODBias` `=` NUMBER if (tryConsumeExpectedToken(TokenKind::kw_mipLODBias)) { if (Params.MipLODBias.has_value()) { - getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param) + getDiags().Report(getTokenLocation(CurToken), + diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } @@ -790,7 +816,8 @@ RootSignatureParser::parseStaticSamplerParams() { // `maxAnisotropy` `=` POS_INT if (tryConsumeExpectedToken(TokenKind::kw_maxAnisotropy)) { if (Params.MaxAnisotropy.has_value()) { - getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param) + getDiags().Report(getTokenLocation(CurToken), + diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } @@ -807,7 +834,8 @@ RootSignatureParser::parseStaticSamplerParams() { // `comparisonFunc` `=` COMPARISON_FUNC if (tryConsumeExpectedToken(TokenKind::kw_comparisonFunc)) { if (Params.CompFunc.has_value()) { - getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param) + getDiags().Report(getTokenLocation(CurToken), + diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } @@ -824,7 +852,8 @@ RootSignatureParser::parseStaticSamplerParams() { // `borderColor` `=` STATIC_BORDER_COLOR if (tryConsumeExpectedToken(TokenKind::kw_borderColor)) { if (Params.BorderColor.has_value()) { - getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param) + getDiags().Report(getTokenLocation(CurToken), + diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } @@ -841,7 +870,8 @@ RootSignatureParser::parseStaticSamplerParams() { // `minLOD` `=` NUMBER if (tryConsumeExpectedToken(TokenKind::kw_minLOD)) { if (Params.MinLOD.has_value()) { - getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param) + getDiags().Report(getTokenLocation(CurToken), + diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } @@ -858,7 +888,8 @@ RootSignatureParser::parseStaticSamplerParams() { // `maxLOD` `=` NUMBER if (tryConsumeExpectedToken(TokenKind::kw_maxLOD)) { if (Params.MaxLOD.has_value()) { - getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param) + getDiags().Report(getTokenLocation(CurToken), + diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } @@ -875,7 +906,8 @@ RootSignatureParser::parseStaticSamplerParams() { // `space` `=` POS_INT if (tryConsumeExpectedToken(TokenKind::kw_space)) { if (Params.Space.has_value()) { - getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param) + getDiags().Report(getTokenLocation(CurToken), + diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } @@ -892,7 +924,8 @@ RootSignatureParser::parseStaticSamplerParams() { // `visibility` `=` SHADER_VISIBILITY if (tryConsumeExpectedToken(TokenKind::kw_visibility)) { if (Params.Visibility.has_value()) { - getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param) + getDiags().Report(getTokenLocation(CurToken), + diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } @@ -1124,7 +1157,8 @@ RootSignatureParser::parseRootDescriptorFlags() { // Handle the edge-case of '0' to specify no flags set if (tryConsumeExpectedToken(TokenKind::int_literal)) { if (!verifyZeroFlag()) { - getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_non_zero_flag); + getDiags().Report(getTokenLocation(CurToken), + diag::err_hlsl_rootsig_non_zero_flag); return std::nullopt; } return llvm::dxbc::RootDescriptorFlags::None; @@ -1163,7 +1197,8 @@ RootSignatureParser::parseDescriptorRangeFlags() { // Handle the edge-case of '0' to specify no flags set if (tryConsumeExpectedToken(TokenKind::int_literal)) { if (!verifyZeroFlag()) { - getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_non_zero_flag); + getDiags().Report(getTokenLocation(CurToken), + diag::err_hlsl_rootsig_non_zero_flag); return std::nullopt; } return llvm::dxbc::DescriptorRangeFlags::None; @@ -1196,9 +1231,9 @@ RootSignatureParser::parseDescriptorRangeFlags() { std::optional<uint32_t> RootSignatureParser::handleUIntLiteral() { // Parse the numeric value and do semantic checks on its specification - clang::NumericLiteralParser Literal(CurToken.NumSpelling, CurToken.TokLoc, - PP.getSourceManager(), PP.getLangOpts(), - PP.getTargetInfo(), PP.getDiagnostics()); + clang::NumericLiteralParser Literal( + CurToken.NumSpelling, getTokenLocation(CurToken), PP.getSourceManager(), + PP.getLangOpts(), PP.getTargetInfo(), PP.getDiagnostics()); if (Literal.hadError) return std::nullopt; // Error has already been reported so just return @@ -1208,7 +1243,7 @@ std::optional<uint32_t> RootSignatureParser::handleUIntLiteral() { llvm::APSInt Val(32, /*IsUnsigned=*/true); if (Literal.GetIntegerValue(Val)) { // Report that the value has overflowed - PP.getDiagnostics().Report(CurToken.TokLoc, + PP.getDiagnostics().Report(getTokenLocation(CurToken), diag::err_hlsl_number_literal_overflow) << /*integer type*/ 0 << /*is signed*/ 0; return std::nullopt; @@ -1219,9 +1254,9 @@ std::optional<uint32_t> RootSignatureParser::handleUIntLiteral() { std::optional<int32_t> RootSignatureParser::handleIntLiteral(bool Negated) { // Parse the numeric value and do semantic checks on its specification - clang::NumericLiteralParser Literal(CurToken.NumSpelling, CurToken.TokLoc, - PP.getSourceManager(), PP.getLangOpts(), - PP.getTargetInfo(), PP.getDiagnostics()); + clang::NumericLiteralParser Literal( + CurToken.NumSpelling, getTokenLocation(CurToken), PP.getSourceManager(), + PP.getLangOpts(), PP.getTargetInfo(), PP.getDiagnostics()); if (Literal.hadError) return std::nullopt; // Error has already been reported so just return @@ -1242,7 +1277,7 @@ std::optional<int32_t> RootSignatureParser::handleIntLiteral(bool Negated) { if (Overflowed) { // Report that the value has overflowed - PP.getDiagnostics().Report(CurToken.TokLoc, + PP.getDiagnostics().Report(getTokenLocation(CurToken), diag::err_hlsl_number_literal_overflow) << /*integer type*/ 0 << /*is signed*/ 1; return std::nullopt; @@ -1256,9 +1291,9 @@ std::optional<int32_t> RootSignatureParser::handleIntLiteral(bool Negated) { std::optional<float> RootSignatureParser::handleFloatLiteral(bool Negated) { // Parse the numeric value and do semantic checks on its specification - clang::NumericLiteralParser Literal(CurToken.NumSpelling, CurToken.TokLoc, - PP.getSourceManager(), PP.getLangOpts(), - PP.getTargetInfo(), PP.getDiagnostics()); + clang::NumericLiteralParser Literal( + CurToken.NumSpelling, getTokenLocation(CurToken), PP.getSourceManager(), + PP.getLangOpts(), PP.getTargetInfo(), PP.getDiagnostics()); if (Literal.hadError) return std::nullopt; // Error has already been reported so just return @@ -1286,14 +1321,14 @@ std::optional<float> RootSignatureParser::handleFloatLiteral(bool Negated) { if (Status & llvm::APFloat::opStatus::opUnderflow) { // Report that the value has underflowed - PP.getDiagnostics().Report(CurToken.TokLoc, + PP.getDiagnostics().Report(getTokenLocation(CurToken), diag::err_hlsl_number_literal_underflow); return std::nullopt; } if (Status & llvm::APFloat::opStatus::opOverflow) { // Report that the value has overflowed - PP.getDiagnostics().Report(CurToken.TokLoc, + PP.getDiagnostics().Report(getTokenLocation(CurToken), diag::err_hlsl_number_literal_overflow) << /*float type*/ 1; return std::nullopt; @@ -1306,7 +1341,7 @@ std::optional<float> RootSignatureParser::handleFloatLiteral(bool Negated) { double FloatMax = double(std::numeric_limits<float>::max()); if (FloatMax < DoubleVal || DoubleVal < -FloatMax) { // Report that the value has overflowed - PP.getDiagnostics().Report(CurToken.TokLoc, + PP.getDiagnostics().Report(getTokenLocation(CurToken), diag::err_hlsl_number_literal_overflow) << /*float type*/ 1; return std::nullopt; @@ -1337,7 +1372,7 @@ bool RootSignatureParser::consumeExpectedToken(TokenKind Expected, return false; // Report unexpected token kind error - DiagnosticBuilder DB = getDiags().Report(CurToken.TokLoc, DiagID); + DiagnosticBuilder DB = getDiags().Report(getTokenLocation(CurToken), DiagID); switch (DiagID) { case diag::err_expected: DB << Expected; @@ -1366,5 +1401,10 @@ bool RootSignatureParser::tryConsumeExpectedToken( return true; } +SourceLocation RootSignatureParser::getTokenLocation(RootSignatureToken Tok) { + return Signature->getLocationOfByte(Tok.LocOffset, PP.getSourceManager(), + PP.getLangOpts(), PP.getTargetInfo()); +} + } // namespace hlsl } // namespace clang diff --git a/clang/unittests/Lex/LexHLSLRootSignatureTest.cpp b/clang/unittests/Lex/LexHLSLRootSignatureTest.cpp index b5bd233c52557..01f8d4f97b092 100644 --- a/clang/unittests/Lex/LexHLSLRootSignatureTest.cpp +++ b/clang/unittests/Lex/LexHLSLRootSignatureTest.cpp @@ -49,9 +49,7 @@ TEST_F(LexHLSLRootSignatureTest, ValidLexNumbersTest) { 42.e+10f )cc"; - auto TokLoc = SourceLocation(); - - hlsl::RootSignatureLexer Lexer(Source, TokLoc); + hlsl::RootSignatureLexer Lexer(Source); SmallVector<hlsl::RootSignatureToken> Tokens; SmallVector<TokenKind> Expected = { @@ -229,8 +227,7 @@ TEST_F(LexHLSLRootSignatureTest, ValidLexAllTokensTest) { STATIC_BORDER_COLOR_OPAQUE_BLACK_UINT STATIC_BORDER_COLOR_OPAQUE_WHITE_UINT )cc"; - auto TokLoc = SourceLocation(); - hlsl::RootSignatureLexer Lexer(Source, TokLoc); + hlsl::RootSignatureLexer Lexer(Source); SmallVector<hlsl::RootSignatureToken> Tokens; SmallVector<TokenKind> Expected = { @@ -251,8 +248,7 @@ TEST_F(LexHLSLRootSignatureTest, ValidCaseInsensitiveKeywordsTest) { SPACE visibility FLAGS numDescriptors OFFSET )cc"; - auto TokLoc = SourceLocation(); - hlsl::RootSignatureLexer Lexer(Source, TokLoc); + hlsl::RootSignatureLexer Lexer(Source); SmallVector<hlsl::RootSignatureToken> Tokens; SmallVector<TokenKind> Expected = { @@ -276,8 +272,7 @@ TEST_F(LexHLSLRootSignatureTest, ValidLexPeekTest) { const llvm::StringLiteral Source = R"cc( )1 )cc"; - auto TokLoc = SourceLocation(); - hlsl::RootSignatureLexer Lexer(Source, TokLoc); + hlsl::RootSignatureLexer Lexer(Source); // Test basic peek hlsl::RootSignatureToken Res = Lexer.peekNextToken(); diff --git a/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp b/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp index b06e5d4711773..e6e8991d914fd 100644 --- a/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp +++ b/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp @@ -134,9 +134,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseEmptyTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - auto TokLoc = SourceLocation(); - hlsl::RootSignatureLexer Lexer(Source, TokLoc); + hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, Signature, *PP); @@ -172,9 +171,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseDTClausesTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - auto TokLoc = SourceLocation(); - hlsl::RootSignatureLexer Lexer(Source, TokLoc); + hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, Signature, *PP); @@ -279,9 +277,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseStaticSamplerTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - auto TokLoc = SourceLocation(); - hlsl::RootSignatureLexer Lexer(Source, TokLoc); + hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, Signature, *PP); @@ -368,9 +365,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseFloatsTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - auto TokLoc = SourceLocation(); - hlsl::RootSignatureLexer Lexer(Source, TokLoc); + hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, Signature, *PP); @@ -447,9 +443,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidSamplerFlagsTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - auto TokLoc = SourceLocation(); - hlsl::RootSignatureLexer Lexer(Source, TokLoc); + hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, Signature, *PP); @@ -482,9 +477,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootConsantsTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - auto TokLoc = SourceLocation(); - hlsl::RootSignatureLexer Lexer(Source, TokLoc); + hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, Signature, *PP); @@ -543,9 +537,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootFlagsTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - auto TokLoc = SourceLocation(); - hlsl::RootSignatureLexer Lexer(Source, TokLoc); + hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, Signature, *PP); @@ -600,9 +593,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootDescriptorsTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - auto TokLoc = SourceLocation(); - hlsl::RootSignatureLexer Lexer(Source, TokLoc); + hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, Signature, *PP); @@ -678,9 +670,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidTrailingCommaTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - auto TokLoc = SourceLocation(); - hlsl::RootSignatureLexer Lexer(Source, TokLoc); + hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, Signature, *PP); @@ -852,9 +843,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseUnexpectedTokenTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - auto TokLoc = SourceLocation(); - hlsl::RootSignatureLexer Lexer(Source, TokLoc); + hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, Signature, *PP); @@ -876,9 +866,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseInvalidTokenTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - auto TokLoc = SourceLocation(); - hlsl::RootSignatureLexer Lexer(Source, TokLoc); + hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, Signature, *PP); @@ -900,9 +889,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseUnexpectedEndOfStreamTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - auto TokLoc = SourceLocation(); - hlsl::RootSignatureLexer Lexer(Source, TokLoc); + hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, Signature, *PP); @@ -929,9 +917,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidMissingDTParameterTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - auto TokLoc = SourceLocation(); - hlsl::RootSignatureLexer Lexer(Source, TokLoc); + hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, Signature, *PP); @@ -955,9 +942,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidMissingRDParameterTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - auto TokLoc = SourceLocation(); - hlsl::RootSignatureLexer Lexer(Source, TokLoc); + hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, Signature, *PP); @@ -981,9 +967,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidMissingRCParameterTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - auto TokLoc = SourceLocation(); - hlsl::RootSignatureLexer Lexer(Source, TokLoc); + hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, Signature, *PP); @@ -1009,9 +994,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedMandatoryDTParameterTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - auto TokLoc = SourceLocation(); - hlsl::RootSignatureLexer Lexer(Source, TokLoc); + hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, Signature, *PP); @@ -1035,9 +1019,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedMandatoryRCParameterTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - auto TokLoc = SourceLocation(); - hlsl::RootSignatureLexer Lexer(Source, TokLoc); + hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, Signature, *PP); @@ -1063,9 +1046,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedOptionalDTParameterTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - auto TokLoc = SourceLocation(); - hlsl::RootSignatureLexer Lexer(Source, TokLoc); + hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, Signature, *PP); @@ -1093,9 +1075,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedOptionalRCParameterTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - auto TokLoc = SourceLocation(); - hlsl::RootSignatureLexer Lexer(Source, TokLoc); + hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, Signature, *PP); @@ -1120,9 +1101,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedNumberTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - auto TokLoc = SourceLocation(); - hlsl::RootSignatureLexer Lexer(Source, TokLoc); + hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, Signature, *PP); @@ -1146,9 +1126,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseOverflowedNegativeNumberTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - auto TokLoc = SourceLocation(); - hlsl::RootSignatureLexer Lexer(Source, TokLoc); + hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, Signature, *PP); @@ -1171,9 +1150,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedFloatTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - auto TokLoc = SourceLocation(); - hlsl::RootSignatureLexer Lexer(Source, TokLoc); + hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, Signature, *PP); @@ -1196,9 +1174,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexNegOverflowedFloatTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - auto TokLoc = SourceLocation(); - hlsl::RootSignatureLexer Lexer(Source, TokLoc); + hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, Signature, *PP); @@ -1221,9 +1198,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedDoubleTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - auto TokLoc = SourceLocation(); - hlsl::RootSignatureLexer Lexer(Source, TokLoc); + hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, Signature, *PP); @@ -1246,9 +1222,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexUnderflowFloatTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - auto TokLoc = SourceLocation(); - hlsl::RootSignatureLexer Lexer(Source, TokLoc); + hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, Signature, *PP); @@ -1274,9 +1249,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidNonZeroFlagsTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - auto TokLoc = SourceLocation(); - hlsl::RootSignatureLexer Lexer(Source, TokLoc); + hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, Signature, *PP); >From dece8af09b9223d03e8b399e3433ba2c1cd635a5 Mon Sep 17 00:00:00 2001 From: Finn Plummer <canadienf...@gmail.com> Date: Fri, 4 Jul 2025 17:29:53 +0000 Subject: [PATCH 4/6] nfc: instantiate Lexer in Parser constructor - the StringLiteral between the Lexer and Parser is now inherently coupled together and this constructor will enforce such --- .../clang/Parse/ParseHLSLRootSignature.h | 6 +- clang/lib/Parse/ParseDeclCXX.cpp | 3 +- clang/lib/Parse/ParseHLSLRootSignature.cpp | 8 +- .../Parse/ParseHLSLRootSignatureTest.cpp | 78 +++++++------------ 4 files changed, 33 insertions(+), 62 deletions(-) diff --git a/clang/include/clang/Parse/ParseHLSLRootSignature.h b/clang/include/clang/Parse/ParseHLSLRootSignature.h index e6c770a409233..b0ef617a13c28 100644 --- a/clang/include/clang/Parse/ParseHLSLRootSignature.h +++ b/clang/include/clang/Parse/ParseHLSLRootSignature.h @@ -30,8 +30,7 @@ class RootSignatureParser { public: RootSignatureParser(llvm::dxbc::RootSignatureVersion Version, SmallVector<llvm::hlsl::rootsig::RootElement> &Elements, - RootSignatureLexer &Lexer, StringLiteral *Signature, - Preprocessor &PP); + StringLiteral *Signature, Preprocessor &PP); /// Consumes tokens from the Lexer and constructs the in-memory /// representations of the RootElements. Tokens are consumed until an @@ -198,9 +197,8 @@ class RootSignatureParser { private: llvm::dxbc::RootSignatureVersion Version; SmallVector<llvm::hlsl::rootsig::RootElement> &Elements; - RootSignatureLexer &Lexer; - clang::StringLiteral *Signature; + RootSignatureLexer Lexer; clang::Preprocessor &PP; RootSignatureToken CurToken; diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index 04df8681269fd..d3bc6f1e89832 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -4951,10 +4951,9 @@ void Parser::ParseHLSLRootSignatureAttributeArgs(ParsedAttributes &Attrs) { // signature string and construct the in-memory elements if (!Found) { // Invoke the root signature parser to construct the in-memory constructs - hlsl::RootSignatureLexer Lexer(Signature->getString()); SmallVector<llvm::hlsl::rootsig::RootElement> RootElements; hlsl::RootSignatureParser Parser(getLangOpts().HLSLRootSigVer, RootElements, - Lexer, Signature, PP); + Signature, PP); if (Parser.parse()) { T.consumeClose(); return; diff --git a/clang/lib/Parse/ParseHLSLRootSignature.cpp b/clang/lib/Parse/ParseHLSLRootSignature.cpp index 2244f09d1a3b0..ebaf7ba60fa17 100644 --- a/clang/lib/Parse/ParseHLSLRootSignature.cpp +++ b/clang/lib/Parse/ParseHLSLRootSignature.cpp @@ -19,10 +19,10 @@ using TokenKind = RootSignatureToken::Kind; RootSignatureParser::RootSignatureParser( llvm::dxbc::RootSignatureVersion Version, - SmallVector<RootElement> &Elements, RootSignatureLexer &Lexer, - StringLiteral *Signature, Preprocessor &PP) - : Version(Version), Elements(Elements), Signature(Signature), Lexer(Lexer), - PP(PP), CurToken(0) {} + SmallVector<RootElement> &Elements, StringLiteral *Signature, + Preprocessor &PP) + : Version(Version), Elements(Elements), Signature(Signature), + Lexer(Signature->getString()), PP(PP), CurToken(0) {} bool RootSignatureParser::parse() { // Iterate as many RootElements as possible diff --git a/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp b/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp index e6e8991d914fd..86d897c7d86a5 100644 --- a/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp +++ b/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp @@ -135,9 +135,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseEmptyTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Signature, *PP); // Test no diagnostics produced @@ -172,9 +171,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseDTClausesTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Signature, *PP); // Test no diagnostics produced @@ -278,9 +276,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseStaticSamplerTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Signature, *PP); // Test no diagnostics produced @@ -366,9 +363,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseFloatsTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Signature, *PP); // Test no diagnostics produced @@ -444,9 +440,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidSamplerFlagsTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Signature, *PP); // Test no diagnostics produced @@ -478,9 +473,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootConsantsTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Signature, *PP); // Test no diagnostics produced @@ -538,9 +532,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootFlagsTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Signature, *PP); // Test no diagnostics produced @@ -594,9 +587,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootDescriptorsTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Signature, *PP); // Test no diagnostics produced @@ -671,9 +663,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidTrailingCommaTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Signature, *PP); // Test no diagnostics produced @@ -844,9 +835,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseUnexpectedTokenTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Signature, *PP); // Test correct diagnostic produced @@ -867,9 +857,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseInvalidTokenTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Signature, *PP); // Test correct diagnostic produced - invalid token @@ -890,9 +879,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseUnexpectedEndOfStreamTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Signature, *PP); // Test correct diagnostic produced - end of stream @@ -918,9 +906,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidMissingDTParameterTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Signature, *PP); // Test correct diagnostic produced @@ -943,9 +930,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidMissingRDParameterTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Signature, *PP); // Test correct diagnostic produced @@ -968,9 +954,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidMissingRCParameterTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Signature, *PP); // Test correct diagnostic produced @@ -995,9 +980,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedMandatoryDTParameterTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Signature, *PP); // Test correct diagnostic produced @@ -1020,9 +1004,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedMandatoryRCParameterTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Signature, *PP); // Test correct diagnostic produced @@ -1047,9 +1030,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedOptionalDTParameterTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Signature, *PP); // Test correct diagnostic produced @@ -1076,9 +1058,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedOptionalRCParameterTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Signature, *PP); // Test correct diagnostic produced @@ -1102,9 +1083,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedNumberTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Signature, *PP); // Test correct diagnostic produced @@ -1127,9 +1107,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseOverflowedNegativeNumberTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Signature, *PP); // Test correct diagnostic produced @@ -1151,9 +1130,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedFloatTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Signature, *PP); // Test correct diagnostic produced @@ -1175,9 +1153,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexNegOverflowedFloatTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Signature, *PP); // Test correct diagnostic produced @@ -1199,9 +1176,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedDoubleTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Signature, *PP); // Test correct diagnostic produced @@ -1223,9 +1199,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexUnderflowFloatTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Signature, *PP); // Test correct diagnostic produced @@ -1250,9 +1225,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidNonZeroFlagsTest) { TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - hlsl::RootSignatureLexer Lexer(Source); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Signature, *PP); // Test correct diagnostic produced >From b953140a7281dd4252fa9907f20a2628d627967b Mon Sep 17 00:00:00 2001 From: Finn Plummer <canadienf...@gmail.com> Date: Fri, 4 Jul 2025 17:29:59 +0000 Subject: [PATCH 5/6] add sample testcase --- clang/test/SemaHLSL/RootSignature-err.hlsl | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/clang/test/SemaHLSL/RootSignature-err.hlsl b/clang/test/SemaHLSL/RootSignature-err.hlsl index aec8a15f8ed7f..a5fd76e73b04e 100644 --- a/clang/test/SemaHLSL/RootSignature-err.hlsl +++ b/clang/test/SemaHLSL/RootSignature-err.hlsl @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -o - %s -verify +// RUN: not %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -o - %s 2>&1 | FileCheck %s // Attr test @@ -22,3 +23,14 @@ void bad_root_signature_4() {} // expected-error@+1 {{expected ')' to denote end of parameters, or, another valid parameter of RootConstants}} [RootSignature("RootConstants(b0, num32BitConstants = 1, invalid)")] void bad_root_signature_5() {} + +#define MultiLineRootSignature \ + "CBV(b0)," \ + "RootConstants(num32BitConstants = 3, b0, invalid)" + +// CHECK: note: expanded from macro 'MultiLineRootSignature' +// CHECK-NEXT: [[@LINE-3]] | "RootConstants(num32BitConstants = 3, b0, invalid)" +// CHECK-NEXT: | ^ +// expected-error@+1 {{expected ')' to denote end of parameters, or, another valid parameter of RootConstants}} +[RootSignature(MultiLineRootSignature)] +void bad_root_signature_6() {} >From 1a64eff52692ea510a8e80c8d728f512192f88d8 Mon Sep 17 00:00:00 2001 From: Finn Plummer <canadienf...@gmail.com> Date: Fri, 4 Jul 2025 17:33:36 +0000 Subject: [PATCH 6/6] rebase: clean-ups --- .../Parse/ParseHLSLRootSignatureTest.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp b/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp index 86d897c7d86a5..ff1697f1bbb9a 100644 --- a/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp +++ b/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp @@ -690,14 +690,15 @@ TEST_F(ParseHLSLRootSignatureTest, ValidVersion10Test) { ) )cc"; + auto Ctx = createMinimalASTContext(); + StringLiteral *Signature = wrapSource(Ctx, Source); + TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - auto TokLoc = SourceLocation(); - hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_0, Elements, Lexer, - *PP); + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_0, Elements, + Signature, *PP); // Test no diagnostics produced Consumer->setNoDiag(); @@ -762,14 +763,15 @@ TEST_F(ParseHLSLRootSignatureTest, ValidVersion11Test) { ) )cc"; + auto Ctx = createMinimalASTContext(); + StringLiteral *Signature = wrapSource(Ctx, Source); + TrivialModuleLoader ModLoader; auto PP = createPP(Source, ModLoader); - auto TokLoc = SourceLocation(); - hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, - *PP); + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, + Signature, *PP); // Test no diagnostics produced Consumer->setNoDiag(); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits