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 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 66a5a3b7eaad0..007c3f7ba1e9c 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,7 @@ class RootSignatureParser { public: RootSignatureParser(llvm::dxbc::RootSignatureVersion Version, SmallVector &Elements, - RootSignatureLexer &Lexer, clang::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 @@ -187,12 +188,23 @@ class RootSignatureParser { bool tryConsumeExpectedToken(RootSignatureToken::Kind Expected); bool tryConsumeExpectedToken(ArrayRef 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); + + /// Construct a diagnostics at the location of the current token + DiagnosticBuilder reportDiag(unsigned DiagID) { + return getDiags().Report(getTokenLocation(CurToken), DiagID); + } + private: llvm::dxbc::RootSignatureVersion Version; SmallVector &Elements; - RootSignatureLexer &Lexer; - - clang::Preprocessor &PP; + StringLiteral *Signature; + RootSignatureLexer Lexer; + Preprocessor &PP; RootSignatureToken CurToken; }; 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 6b0564dca6f45..d3bc6f1e89832 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -4944,20 +4944,16 @@ 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); // Invoke the root signature parser to construct the in-memory constructs - hlsl::RootSignatureLexer Lexer(Signature, SignatureLoc); SmallVector RootElements; hlsl::RootSignatureParser Parser(getLangOpts().HLSLRootSigVer, RootElements, - Lexer, PP); + Signature, PP); if (Parser.parse()) { T.consumeClose(); return; diff --git a/clang/lib/Parse/ParseHLSLRootSignature.cpp b/clang/lib/Parse/ParseHLSLRootSignature.cpp index 96d3999ff2acb..cf86c62f3b671 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 &Elements, RootSignatureLexer &Lexer, + SmallVector &Elements, StringLiteral *Signature, Preprocessor &PP) - : Version(Version), Elements(Elements), Lexer(Lexer), PP(PP), - CurToken(SourceLocation()) {} + : Version(Version), Elements(Elements), Signature(Signature), + Lexer(Signature->getString()), PP(PP), CurToken(0) {} bool RootSignatureParser::parse() { // Iterate as many RootElements as possible @@ -91,7 +91,7 @@ std::optional 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); + reportDiag(diag::err_hlsl_rootsig_non_zero_flag); return std::nullopt; } } else { @@ -141,7 +141,7 @@ std::optional RootSignatureParser::parseRootConstants() { // Check mandatory parameters where provided if (!Params->Num32BitConstants.has_value()) { - getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_missing_param) + reportDiag(diag::err_hlsl_rootsig_missing_param) << TokenKind::kw_num32BitConstants; return std::nullopt; } @@ -149,8 +149,7 @@ std::optional RootSignatureParser::parseRootConstants() { Constants.Num32BitConstants = Params->Num32BitConstants.value(); if (!Params->Reg.has_value()) { - getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_missing_param) - << TokenKind::bReg; + reportDiag(diag::err_hlsl_rootsig_missing_param) << TokenKind::bReg; return std::nullopt; } @@ -209,8 +208,7 @@ std::optional RootSignatureParser::parseRootDescriptor() { // Check mandatory parameters were provided if (!Params->Reg.has_value()) { - getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_missing_param) - << ExpectedReg; + reportDiag(diag::err_hlsl_rootsig_missing_param) << ExpectedReg; return std::nullopt; } @@ -258,8 +256,7 @@ std::optional RootSignatureParser::parseDescriptorTable() { if (tryConsumeExpectedToken(TokenKind::kw_visibility)) { if (Visibility.has_value()) { - getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param) - << CurToken.TokKind; + reportDiag(diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } @@ -328,8 +325,7 @@ RootSignatureParser::parseDescriptorTableClause() { // Check mandatory parameters were provided if (!Params->Reg.has_value()) { - getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_missing_param) - << ExpectedReg; + reportDiag(diag::err_hlsl_rootsig_missing_param) << ExpectedReg; return std::nullopt; } @@ -372,8 +368,7 @@ std::optional RootSignatureParser::parseStaticSampler() { // Check mandatory parameters were provided if (!Params->Reg.has_value()) { - getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_missing_param) - << TokenKind::sReg; + reportDiag(diag::err_hlsl_rootsig_missing_param) << TokenKind::sReg; return std::nullopt; } @@ -437,8 +432,7 @@ 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) - << CurToken.TokKind; + reportDiag(diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } @@ -454,8 +448,7 @@ RootSignatureParser::parseRootConstantParams() { // `b` POS_INT if (tryConsumeExpectedToken(TokenKind::bReg)) { if (Params.Reg.has_value()) { - getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param) - << CurToken.TokKind; + reportDiag(diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } auto Reg = parseRegister(); @@ -467,8 +460,7 @@ 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) - << CurToken.TokKind; + reportDiag(diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } @@ -484,8 +476,7 @@ 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) - << CurToken.TokKind; + reportDiag(diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } @@ -512,8 +503,7 @@ 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) - << CurToken.TokKind; + reportDiag(diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } auto Reg = parseRegister(); @@ -525,8 +515,7 @@ 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) - << CurToken.TokKind; + reportDiag(diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } @@ -542,8 +531,7 @@ 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) - << CurToken.TokKind; + reportDiag(diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } @@ -559,8 +547,7 @@ 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) - << CurToken.TokKind; + reportDiag(diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } @@ -587,8 +574,7 @@ 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) - << CurToken.TokKind; + reportDiag(diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } auto Reg = parseRegister(); @@ -600,8 +586,7 @@ 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) - << CurToken.TokKind; + reportDiag(diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } @@ -623,8 +608,7 @@ 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) - << CurToken.TokKind; + reportDiag(diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } @@ -640,8 +624,7 @@ 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) - << CurToken.TokKind; + reportDiag(diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } @@ -663,8 +646,7 @@ 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) - << CurToken.TokKind; + reportDiag(diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } @@ -692,8 +674,7 @@ RootSignatureParser::parseStaticSamplerParams() { // `s` POS_INT if (tryConsumeExpectedToken(TokenKind::sReg)) { if (Params.Reg.has_value()) { - getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param) - << CurToken.TokKind; + reportDiag(diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } auto Reg = parseRegister(); @@ -705,8 +686,7 @@ RootSignatureParser::parseStaticSamplerParams() { // `filter` `=` FILTER if (tryConsumeExpectedToken(TokenKind::kw_filter)) { if (Params.Filter.has_value()) { - getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param) - << CurToken.TokKind; + reportDiag(diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } @@ -722,8 +702,7 @@ 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) - << CurToken.TokKind; + reportDiag(diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } @@ -739,8 +718,7 @@ 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) - << CurToken.TokKind; + reportDiag(diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } @@ -756,8 +734,7 @@ 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) - << CurToken.TokKind; + reportDiag(diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } @@ -773,8 +750,7 @@ RootSignatureParser::parseStaticSamplerParams() { // `mipLODBias` `=` NUMBER if (tryConsumeExpectedToken(TokenKind::kw_mipLODBias)) { if (Params.MipLODBias.has_value()) { - getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param) - << CurToken.TokKind; + reportDiag(diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } @@ -790,8 +766,7 @@ 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) - << CurToken.TokKind; + reportDiag(diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } @@ -807,8 +782,7 @@ 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) - << CurToken.TokKind; + reportDiag(diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } @@ -824,8 +798,7 @@ 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) - << CurToken.TokKind; + reportDiag(diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } @@ -841,8 +814,7 @@ RootSignatureParser::parseStaticSamplerParams() { // `minLOD` `=` NUMBER if (tryConsumeExpectedToken(TokenKind::kw_minLOD)) { if (Params.MinLOD.has_value()) { - getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param) - << CurToken.TokKind; + reportDiag(diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } @@ -858,8 +830,7 @@ RootSignatureParser::parseStaticSamplerParams() { // `maxLOD` `=` NUMBER if (tryConsumeExpectedToken(TokenKind::kw_maxLOD)) { if (Params.MaxLOD.has_value()) { - getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param) - << CurToken.TokKind; + reportDiag(diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } @@ -875,8 +846,7 @@ 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) - << CurToken.TokKind; + reportDiag(diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } @@ -892,8 +862,7 @@ 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) - << CurToken.TokKind; + reportDiag(diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; return std::nullopt; } @@ -1124,7 +1093,7 @@ 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); + reportDiag(diag::err_hlsl_rootsig_non_zero_flag); return std::nullopt; } return llvm::dxbc::RootDescriptorFlags::None; @@ -1163,7 +1132,7 @@ 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); + reportDiag(diag::err_hlsl_rootsig_non_zero_flag); return std::nullopt; } return llvm::dxbc::DescriptorRangeFlags::None; @@ -1196,9 +1165,9 @@ RootSignatureParser::parseDescriptorRangeFlags() { std::optional 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,8 +1177,7 @@ std::optional RootSignatureParser::handleUIntLiteral() { llvm::APSInt Val(32, /*IsUnsigned=*/true); if (Literal.GetIntegerValue(Val)) { // Report that the value has overflowed - PP.getDiagnostics().Report(CurToken.TokLoc, - diag::err_hlsl_number_literal_overflow) + reportDiag(diag::err_hlsl_number_literal_overflow) << /*integer type*/ 0 << /*is signed*/ 0; return std::nullopt; } @@ -1219,9 +1187,9 @@ std::optional RootSignatureParser::handleUIntLiteral() { std::optional 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,8 +1210,7 @@ std::optional RootSignatureParser::handleIntLiteral(bool Negated) { if (Overflowed) { // Report that the value has overflowed - PP.getDiagnostics().Report(CurToken.TokLoc, - diag::err_hlsl_number_literal_overflow) + reportDiag(diag::err_hlsl_number_literal_overflow) << /*integer type*/ 0 << /*is signed*/ 1; return std::nullopt; } @@ -1256,9 +1223,9 @@ std::optional RootSignatureParser::handleIntLiteral(bool Negated) { std::optional 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,16 +1253,13 @@ std::optional RootSignatureParser::handleFloatLiteral(bool Negated) { if (Status & llvm::APFloat::opStatus::opUnderflow) { // Report that the value has underflowed - PP.getDiagnostics().Report(CurToken.TokLoc, - diag::err_hlsl_number_literal_underflow); + reportDiag(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, - diag::err_hlsl_number_literal_overflow) - << /*float type*/ 1; + reportDiag(diag::err_hlsl_number_literal_overflow) << /*float type*/ 1; return std::nullopt; } @@ -1306,9 +1270,7 @@ std::optional RootSignatureParser::handleFloatLiteral(bool Negated) { double FloatMax = double(std::numeric_limits::max()); if (FloatMax < DoubleVal || DoubleVal < -FloatMax) { // Report that the value has overflowed - PP.getDiagnostics().Report(CurToken.TokLoc, - diag::err_hlsl_number_literal_overflow) - << /*float type*/ 1; + reportDiag(diag::err_hlsl_number_literal_overflow) << /*float type*/ 1; return std::nullopt; } @@ -1337,7 +1299,7 @@ bool RootSignatureParser::consumeExpectedToken(TokenKind Expected, return false; // Report unexpected token kind error - DiagnosticBuilder DB = getDiags().Report(CurToken.TokLoc, DiagID); + DiagnosticBuilder DB = reportDiag(DiagID); switch (DiagID) { case diag::err_expected: DB << Expected; @@ -1366,5 +1328,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/test/SemaHLSL/RootSignature-err.hlsl b/clang/test/SemaHLSL/RootSignature-err.hlsl index aec8a15f8ed7f..118fc38daf3f2 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: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -fsyntax-only %s -verify +// RUN: not %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -fsyntax-only %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: [[@LINE-2]]:42: 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() {} 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 Tokens; SmallVector 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 Tokens; SmallVector 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 Tokens; SmallVector 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 871f12ef3cce3..ff1697f1bbb9a 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 createMinimalASTContext() { + IdentifierTable Idents(LangOpts); + SelectorTable Selectors; + Builtin::Context Builtins; + + return std::make_unique(LangOpts, SourceMgr, Idents, Selectors, + Builtins, TU_Complete); + } + + StringLiteral *wrapSource(std::unique_ptr &Ctx, + StringRef Source) { + SourceLocation Locs[1] = {SourceLocation()}; + return StringLiteral::Create(*Ctx, Source, StringLiteralKind::Unevaluated, + false, Ctx->VoidTy, Locs); + } + FileSystemOptions FileMgrOpts; FileManager FileMgr; IntrusiveRefCntPtr DiagID; @@ -111,14 +129,15 @@ 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(); - hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector 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(); @@ -146,14 +165,15 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseDTClausesTest) { DescriptorTable() )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 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(); @@ -250,14 +270,15 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseStaticSamplerTest) { ) )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 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(); @@ -336,14 +357,15 @@ 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(); - hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector 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(); @@ -412,14 +434,15 @@ 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(); - hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector 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(); @@ -444,14 +467,15 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootConsantsTest) { ) )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 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(); @@ -502,14 +526,15 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootFlagsTest) { ) )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 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(); @@ -556,14 +581,15 @@ 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(); - hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector 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(); @@ -631,14 +657,15 @@ TEST_F(ParseHLSLRootSignatureTest, ValidTrailingCommaTest) { ) )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 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(); @@ -663,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 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(); @@ -735,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 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(); @@ -802,14 +831,15 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseUnexpectedTokenTest) { space )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 Elements; - hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, - *PP); + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, + Signature, *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_unexpected_end_of_params); @@ -823,14 +853,15 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseInvalidTokenTest) { notAnIdentifier )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 Elements; - hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, - *PP); + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, + Signature, *PP); // Test correct diagnostic produced - invalid token Consumer->setExpected(diag::err_hlsl_unexpected_end_of_params); @@ -844,14 +875,15 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseUnexpectedEndOfStreamTest) { DescriptorTable )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 Elements; - hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, - *PP); + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, + Signature, *PP); // Test correct diagnostic produced - end of stream Consumer->setExpected(diag::err_expected_after); @@ -870,14 +902,15 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidMissingDTParameterTest) { ) )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 Elements; - hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, - *PP); + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, + Signature, *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_rootsig_missing_param); @@ -893,14 +926,15 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidMissingRDParameterTest) { SRV() )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 Elements; - hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, - *PP); + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, + Signature, *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_rootsig_missing_param); @@ -916,14 +950,15 @@ 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(); - hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector Elements; - hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, - *PP); + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, + Signature, *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_rootsig_missing_param); @@ -941,14 +976,15 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedMandatoryDTParameterTest) { ) )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 Elements; - hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, - *PP); + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, + Signature, *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_rootsig_repeat_param); @@ -964,14 +1000,15 @@ 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(); - hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector Elements; - hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, - *PP); + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, + Signature, *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_rootsig_repeat_param); @@ -989,14 +1026,15 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedOptionalDTParameterTest) { ) )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 Elements; - hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, - *PP); + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, + Signature, *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_rootsig_repeat_param); @@ -1016,14 +1054,15 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedOptionalRCParameterTest) { ) )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 Elements; - hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, - *PP); + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, + Signature, *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_rootsig_repeat_param); @@ -1040,14 +1079,15 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedNumberTest) { ) )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 Elements; - hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, - *PP); + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, + Signature, *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_number_literal_overflow); @@ -1063,14 +1103,15 @@ 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(); - hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector Elements; - hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, - *PP); + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, + Signature, *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_number_literal_overflow); @@ -1085,14 +1126,15 @@ 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(); - hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector Elements; - hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, - *PP); + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, + Signature, *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_number_literal_overflow); @@ -1107,14 +1149,15 @@ 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(); - hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector Elements; - hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, - *PP); + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, + Signature, *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_number_literal_overflow); @@ -1129,14 +1172,15 @@ 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(); - hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector Elements; - hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, - *PP); + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, + Signature, *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_number_literal_overflow); @@ -1151,14 +1195,15 @@ 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(); - hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector Elements; - hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, - *PP); + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, + Signature, *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_number_literal_underflow); @@ -1176,14 +1221,15 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidNonZeroFlagsTest) { ) )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 Elements; - hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, - *PP); + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, + Signature, *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_rootsig_non_zero_flag);