llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Finn Plummer (inbelic) <details> <summary>Changes</summary> Reverts llvm/llvm-project#<!-- -->133302 Reverting to inspect build failures that were introduced from use of the `clang::Preprocessor`, and the warning about an unused declaration. See linked issue for failures. --- Patch is 24.20 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/133790.diff 11 Files Affected: - (modified) clang/include/clang/Basic/DiagnosticParseKinds.td (-4) - (modified) clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def (+11-12) - (modified) clang/include/clang/Lex/LexHLSLRootSignature.h (+1-14) - (removed) clang/include/clang/Parse/ParseHLSLRootSignature.h (-107) - (modified) clang/lib/Parse/CMakeLists.txt (-1) - (removed) clang/lib/Parse/ParseHLSLRootSignature.cpp (-166) - (modified) clang/unittests/CMakeLists.txt (-1) - (modified) clang/unittests/Lex/LexHLSLRootSignatureTest.cpp (+1-3) - (removed) clang/unittests/Parse/CMakeLists.txt (-23) - (removed) clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp (-245) - (removed) llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h (-44) ``````````diff diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td index 2582e1e5ef0f6..86c361b4dbcf7 100644 --- a/clang/include/clang/Basic/DiagnosticParseKinds.td +++ b/clang/include/clang/Basic/DiagnosticParseKinds.td @@ -1830,8 +1830,4 @@ def err_hlsl_virtual_function def err_hlsl_virtual_inheritance : Error<"virtual inheritance is unsupported in HLSL">; -// HLSL Root Siganture diagnostic messages -def err_hlsl_unexpected_end_of_params - : Error<"expected %0 to denote end of parameters, or, another valid parameter of %1">; - } // end of Parser diagnostics diff --git a/clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def b/clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def index c514d3456146a..e6df763920430 100644 --- a/clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def +++ b/clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def @@ -14,16 +14,16 @@ //===----------------------------------------------------------------------===// #ifndef TOK -#define TOK(X, SPELLING) +#define TOK(X) #endif #ifndef PUNCTUATOR -#define PUNCTUATOR(X,Y) TOK(pu_ ## X, Y) +#define PUNCTUATOR(X,Y) TOK(pu_ ## X) #endif #ifndef KEYWORD -#define KEYWORD(X) TOK(kw_ ## X, #X) +#define KEYWORD(X) TOK(kw_ ## X) #endif #ifndef ENUM -#define ENUM(NAME, LIT) TOK(en_ ## NAME, LIT) +#define ENUM(NAME, LIT) TOK(en_ ## NAME) #endif // Defines the various types of enum @@ -49,15 +49,15 @@ #endif // General Tokens: -TOK(invalid, "invalid identifier") -TOK(end_of_stream, "end of stream") -TOK(int_literal, "integer literal") +TOK(invalid) +TOK(end_of_stream) +TOK(int_literal) // Register Tokens: -TOK(bReg, "b register") -TOK(tReg, "t register") -TOK(uReg, "u register") -TOK(sReg, "s register") +TOK(bReg) +TOK(tReg) +TOK(uReg) +TOK(sReg) // Punctuators: PUNCTUATOR(l_paren, '(') @@ -69,7 +69,6 @@ PUNCTUATOR(plus, '+') PUNCTUATOR(minus, '-') // RootElement Keywords: -KEYWORD(RootSignature) // used only for diagnostic messaging KEYWORD(DescriptorTable) // DescriptorTable Keywords: diff --git a/clang/include/clang/Lex/LexHLSLRootSignature.h b/clang/include/clang/Lex/LexHLSLRootSignature.h index a7e1f782b767f..21c44e0351d9e 100644 --- a/clang/include/clang/Lex/LexHLSLRootSignature.h +++ b/clang/include/clang/Lex/LexHLSLRootSignature.h @@ -13,7 +13,6 @@ #ifndef LLVM_CLANG_LEX_LEXHLSLROOTSIGNATURE_H #define LLVM_CLANG_LEX_LEXHLSLROOTSIGNATURE_H -#include "clang/Basic/Diagnostic.h" #include "clang/Basic/SourceLocation.h" #include "llvm/ADT/SmallVector.h" @@ -25,7 +24,7 @@ namespace hlsl { struct RootSignatureToken { enum Kind { -#define TOK(X, SPELLING) X, +#define TOK(X) X, #include "clang/Lex/HLSLRootSignatureTokenKinds.def" }; @@ -44,18 +43,6 @@ struct RootSignatureToken { }; using TokenKind = enum RootSignatureToken::Kind; -inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, - const TokenKind Kind) { - switch (Kind) { -#define TOK(X, SPELLING) \ - case TokenKind::X: \ - DB << SPELLING; \ - break; -#include "clang/Lex/HLSLRootSignatureTokenKinds.def" - } - return DB; -} - class RootSignatureLexer { public: RootSignatureLexer(StringRef Signature, clang::SourceLocation SourceLoc) diff --git a/clang/include/clang/Parse/ParseHLSLRootSignature.h b/clang/include/clang/Parse/ParseHLSLRootSignature.h deleted file mode 100644 index 43b41315b88b5..0000000000000 --- a/clang/include/clang/Parse/ParseHLSLRootSignature.h +++ /dev/null @@ -1,107 +0,0 @@ -//===--- ParseHLSLRootSignature.h -------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -// -// This file defines the RootSignatureParser interface. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_CLANG_PARSE_PARSEHLSLROOTSIGNATURE_H -#define LLVM_CLANG_PARSE_PARSEHLSLROOTSIGNATURE_H - -#include "clang/Basic/DiagnosticParse.h" -#include "clang/Lex/LexHLSLRootSignature.h" -#include "clang/Lex/Preprocessor.h" - -#include "llvm/ADT/SmallVector.h" -#include "llvm/ADT/StringRef.h" - -#include "llvm/Frontend/HLSL/HLSLRootSignature.h" - -namespace clang { -namespace hlsl { - -class RootSignatureParser { -public: - RootSignatureParser(SmallVector<llvm::hlsl::rootsig::RootElement> &Elements, - RootSignatureLexer &Lexer, clang::Preprocessor &PP); - - /// Consumes tokens from the Lexer and constructs the in-memory - /// representations of the RootElements. Tokens are consumed until an - /// error is encountered or the end of the buffer. - /// - /// Returns true if a parsing error is encountered. - bool parse(); - -private: - DiagnosticsEngine &getDiags() { return PP.getDiagnostics(); } - - // All private Parse.* methods follow a similar pattern: - // - Each method will start with an assert to denote what the CurToken is - // expected to be and will parse from that token forward - // - // - Therefore, it is the callers responsibility to ensure that you are - // at the correct CurToken. This should be done with the pattern of: - // - // if (TryConsumeExpectedToken(TokenKind)) - // if (Parse.*()) - // return true; - // - // or, - // - // if (ConsumeExpectedToken(TokenKind, ...)) - // return true; - // if (Parse.*()) - // return true; - // - // - All methods return true if a parsing error is encountered. It is the - // callers responsibility to propogate this error up, or deal with it - // otherwise - // - // - An error will be raised if the proceeding tokens are not what is - // expected, or, there is a lexing error - - /// Root Element parse methods: - bool parseDescriptorTable(); - bool parseDescriptorTableClause(); - - /// Invoke the Lexer to consume a token and update CurToken with the result - void consumeNextToken() { CurToken = Lexer.ConsumeToken(); } - - /// Return true if the next token one of the expected kinds - bool peekExpectedToken(TokenKind Expected); - bool peekExpectedToken(ArrayRef<TokenKind> AnyExpected); - - /// Consumes the next token and report an error if it is not of the expected - /// kind. - /// - /// Returns true if there was an error reported. - bool consumeExpectedToken(TokenKind Expected, - unsigned DiagID = diag::err_expected, - TokenKind Context = TokenKind::invalid); - - /// Peek if the next token is of the expected kind and if it is then consume - /// it. - /// - /// Returns true if it successfully matches the expected kind and the token - /// was consumed. - bool tryConsumeExpectedToken(TokenKind Expected); - bool tryConsumeExpectedToken(ArrayRef<TokenKind> Expected); - -private: - SmallVector<llvm::hlsl::rootsig::RootElement> &Elements; - RootSignatureLexer &Lexer; - - clang::Preprocessor &PP; - - RootSignatureToken CurToken; -}; - -} // namespace hlsl -} // namespace clang - -#endif // LLVM_CLANG_PARSE_PARSEHLSLROOTSIGNATURE_H diff --git a/clang/lib/Parse/CMakeLists.txt b/clang/lib/Parse/CMakeLists.txt index 00fde537bb9c6..22e902f7e1bc5 100644 --- a/clang/lib/Parse/CMakeLists.txt +++ b/clang/lib/Parse/CMakeLists.txt @@ -14,7 +14,6 @@ add_clang_library(clangParse ParseExpr.cpp ParseExprCXX.cpp ParseHLSL.cpp - ParseHLSLRootSignature.cpp ParseInit.cpp ParseObjc.cpp ParseOpenMP.cpp diff --git a/clang/lib/Parse/ParseHLSLRootSignature.cpp b/clang/lib/Parse/ParseHLSLRootSignature.cpp deleted file mode 100644 index 33caca5fa1c82..0000000000000 --- a/clang/lib/Parse/ParseHLSLRootSignature.cpp +++ /dev/null @@ -1,166 +0,0 @@ -//=== ParseHLSLRootSignature.cpp - Parse Root Signature -------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "clang/Parse/ParseHLSLRootSignature.h" - -#include "llvm/Support/raw_ostream.h" - -using namespace llvm::hlsl::rootsig; - -namespace clang { -namespace hlsl { - -RootSignatureParser::RootSignatureParser(SmallVector<RootElement> &Elements, - RootSignatureLexer &Lexer, - Preprocessor &PP) - : Elements(Elements), Lexer(Lexer), PP(PP), CurToken(SourceLocation()) {} - -bool RootSignatureParser::parse() { - // Iterate as many RootElements as possible - while (tryConsumeExpectedToken(TokenKind::kw_DescriptorTable)) { - // Dispatch onto parser method. - // We guard against the unreachable here as we just ensured that CurToken - // will be one of the kinds in the while condition - switch (CurToken.Kind) { - case TokenKind::kw_DescriptorTable: - if (parseDescriptorTable()) - return true; - break; - default: - llvm_unreachable("Switch for consumed token was not provided"); - } - - if (!tryConsumeExpectedToken(TokenKind::pu_comma)) - break; - } - - if (!tryConsumeExpectedToken(TokenKind::end_of_stream)) { - getDiags().Report(CurToken.TokLoc, diag::err_hlsl_unexpected_end_of_params) - << /*expected=*/TokenKind::end_of_stream - << /*param of=*/TokenKind::kw_RootSignature; - return true; - } - return false; -} - -bool RootSignatureParser::parseDescriptorTable() { - assert(CurToken.Kind == TokenKind::kw_DescriptorTable && - "Expects to only be invoked starting at given keyword"); - - DescriptorTable Table; - - if (consumeExpectedToken(TokenKind::pu_l_paren, diag::err_expected_after, - CurToken.Kind)) - return true; - - // Iterate as many Clauses as possible - while (tryConsumeExpectedToken({TokenKind::kw_CBV, TokenKind::kw_SRV, - TokenKind::kw_UAV, TokenKind::kw_Sampler})) { - if (parseDescriptorTableClause()) - return true; - - Table.NumClauses++; - - if (!tryConsumeExpectedToken(TokenKind::pu_comma)) - break; - } - - if (!tryConsumeExpectedToken(TokenKind::pu_r_paren)) { - getDiags().Report(CurToken.TokLoc, diag::err_hlsl_unexpected_end_of_params) - << /*expected=*/TokenKind::pu_r_paren - << /*param of=*/TokenKind::kw_DescriptorTable; - return true; - } - - Elements.push_back(Table); - return false; -} - -bool RootSignatureParser::parseDescriptorTableClause() { - assert((CurToken.Kind == TokenKind::kw_CBV || - CurToken.Kind == TokenKind::kw_SRV || - CurToken.Kind == TokenKind::kw_UAV || - CurToken.Kind == TokenKind::kw_Sampler) && - "Expects to only be invoked starting at given keyword"); - - DescriptorTableClause Clause; - switch (CurToken.Kind) { - default: - llvm_unreachable("Switch for consumed token was not provided"); - case TokenKind::kw_CBV: - Clause.Type = ClauseType::CBuffer; - break; - case TokenKind::kw_SRV: - Clause.Type = ClauseType::SRV; - break; - case TokenKind::kw_UAV: - Clause.Type = ClauseType::UAV; - break; - case TokenKind::kw_Sampler: - Clause.Type = ClauseType::Sampler; - break; - } - - if (consumeExpectedToken(TokenKind::pu_l_paren, diag::err_expected_after, - CurToken.Kind)) - return true; - - if (consumeExpectedToken(TokenKind::pu_r_paren, diag::err_expected_after, - CurToken.Kind)) - return true; - - Elements.push_back(Clause); - return false; -} - -bool RootSignatureParser::peekExpectedToken(TokenKind Expected) { - return peekExpectedToken(ArrayRef{Expected}); -} - -bool RootSignatureParser::peekExpectedToken(ArrayRef<TokenKind> AnyExpected) { - RootSignatureToken Result = Lexer.PeekNextToken(); - return llvm::is_contained(AnyExpected, Result.Kind); -} - -bool RootSignatureParser::consumeExpectedToken(TokenKind Expected, - unsigned DiagID, - TokenKind Context) { - if (tryConsumeExpectedToken(Expected)) - return false; - - // Report unexpected token kind error - DiagnosticBuilder DB = getDiags().Report(CurToken.TokLoc, DiagID); - switch (DiagID) { - case diag::err_expected: - DB << Expected; - break; - case diag::err_expected_either: - case diag::err_expected_after: - DB << Expected << Context; - break; - default: - break; - } - return true; -} - -bool RootSignatureParser::tryConsumeExpectedToken(TokenKind Expected) { - return tryConsumeExpectedToken(ArrayRef{Expected}); -} - -bool RootSignatureParser::tryConsumeExpectedToken( - ArrayRef<TokenKind> AnyExpected) { - // If not the expected token just return - if (!peekExpectedToken(AnyExpected)) - return false; - consumeNextToken(); - return true; -} - -} // namespace hlsl -} // namespace clang diff --git a/clang/unittests/CMakeLists.txt b/clang/unittests/CMakeLists.txt index 9b3ce8aa7de73..85d265426ec80 100644 --- a/clang/unittests/CMakeLists.txt +++ b/clang/unittests/CMakeLists.txt @@ -25,7 +25,6 @@ endfunction() add_subdirectory(Basic) add_subdirectory(Lex) -add_subdirectory(Parse) add_subdirectory(Driver) if(CLANG_ENABLE_STATIC_ANALYZER) add_subdirectory(Analysis) diff --git a/clang/unittests/Lex/LexHLSLRootSignatureTest.cpp b/clang/unittests/Lex/LexHLSLRootSignatureTest.cpp index 04af01ef97dea..d72a842922f98 100644 --- a/clang/unittests/Lex/LexHLSLRootSignatureTest.cpp +++ b/clang/unittests/Lex/LexHLSLRootSignatureTest.cpp @@ -85,8 +85,6 @@ TEST_F(LexHLSLRootSignatureTest, ValidLexAllTokensTest) { (),|=+- - RootSignature - DescriptorTable CBV SRV UAV Sampler @@ -115,7 +113,7 @@ TEST_F(LexHLSLRootSignatureTest, ValidLexAllTokensTest) { SmallVector<hlsl::RootSignatureToken> Tokens; SmallVector<hlsl::TokenKind> Expected = { -#define TOK(NAME, SPELLING) hlsl::TokenKind::NAME, +#define TOK(NAME) hlsl::TokenKind::NAME, #include "clang/Lex/HLSLRootSignatureTokenKinds.def" }; diff --git a/clang/unittests/Parse/CMakeLists.txt b/clang/unittests/Parse/CMakeLists.txt deleted file mode 100644 index eeb58174568cd..0000000000000 --- a/clang/unittests/Parse/CMakeLists.txt +++ /dev/null @@ -1,23 +0,0 @@ -set(LLVM_LINK_COMPONENTS - Support - ) -add_clang_unittest(ParseTests - ParseHLSLRootSignatureTest.cpp - ) -clang_target_link_libraries(ParseTests - PRIVATE - clangAST - clangASTMatchers - clangBasic - clangFrontend - clangParse - clangSema - clangSerialization - clangTooling - ) -target_link_libraries(ParseTests - PRIVATE - LLVMTestingAnnotations - LLVMTestingSupport - clangTesting - ) diff --git a/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp b/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp deleted file mode 100644 index acdf455a5d6aa..0000000000000 --- a/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp +++ /dev/null @@ -1,245 +0,0 @@ -//=== ParseHLSLRootSignatureTest.cpp - Parse Root Signature tests ---------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "clang/Basic/Diagnostic.h" -#include "clang/Basic/DiagnosticOptions.h" -#include "clang/Basic/FileManager.h" -#include "clang/Basic/LangOptions.h" -#include "clang/Basic/SourceLocation.h" -#include "clang/Basic/SourceManager.h" -#include "clang/Basic/TargetInfo.h" -#include "clang/Lex/HeaderSearch.h" -#include "clang/Lex/HeaderSearchOptions.h" -#include "clang/Lex/Lexer.h" -#include "clang/Lex/ModuleLoader.h" -#include "clang/Lex/Preprocessor.h" -#include "clang/Lex/PreprocessorOptions.h" - -#include "clang/Lex/LexHLSLRootSignature.h" -#include "clang/Parse/ParseHLSLRootSignature.h" -#include "gtest/gtest.h" - -using namespace clang; -using namespace llvm::hlsl::rootsig; - -namespace { - -// Diagnostic helper for helper tests -class ExpectedDiagConsumer : public DiagnosticConsumer { - virtual void anchor() {} - - void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, - const Diagnostic &Info) override { - if (!FirstDiag || !ExpectedDiagID.has_value()) { - Satisfied = false; - return; - } - FirstDiag = false; - - Satisfied = ExpectedDiagID.value() == Info.getID(); - } - - bool FirstDiag = true; - bool Satisfied = false; - std::optional<unsigned> ExpectedDiagID; - -public: - void setNoDiag() { - Satisfied = true; - ExpectedDiagID = std::nullopt; - } - - void setExpected(unsigned DiagID) { - Satisfied = false; - ExpectedDiagID = DiagID; - } - - bool isSatisfied() { return Satisfied; } -}; - -// The test fixture. -class ParseHLSLRootSignatureTest : public ::testing::Test { -protected: - ParseHLSLRootSignatureTest() - : FileMgr(FileMgrOpts), DiagID(new DiagnosticIDs()), - Consumer(new ExpectedDiagConsumer()), - Diags(DiagID, new DiagnosticOptions, Consumer), - SourceMgr(Diags, FileMgr), TargetOpts(new TargetOptions) { - // This is an arbitrarily chosen target triple to create the target info. - TargetOpts->Triple = "dxil"; - Target = TargetInfo::CreateTargetInfo(Diags, TargetOpts); - } - - std::unique_ptr<Preprocessor> createPP(StringRef Source, - TrivialModuleLoader &ModLoader) { - std::unique_ptr<llvm::MemoryBuffer> Buf = - llvm::MemoryBuffer::getMemBuffer(Source); - SourceMgr.setMainFileID(SourceMgr.createFileID(std::move(Buf))); - - HeaderSearchOptions SearchOpts; - HeaderSearch HeaderInfo(SearchOpts, SourceMgr, Diags, LangOpts, - Target.get()); - std::unique_ptr<Preprocessor> PP = std::make_unique<Preprocessor>( - std::make_shared<PreprocessorOptions>(), Diags, LangOpts, SourceMgr, - HeaderInfo, ModLoader, - /*IILookup =*/nullptr, - /*OwnsHeaderSearch =*/false); - PP->Initialize(*Target); - PP->EnterMainSourceFile(); - return PP; - } - - FileSystemOptions FileMgrOpts; - FileManager FileMgr; - IntrusiveRefCntPtr<DiagnosticIDs> DiagID; - ExpectedDiagConsumer *Consumer; - DiagnosticsEngine Diags; - SourceManager SourceMgr; - LangOptions LangOpts; - std::shared_ptr<TargetOptions> TargetOpts; - IntrusiveRefCntPtr<TargetInfo> Target; -}; - -// Valid Parser Tests - -TEST_F(ParseHLSLRootSignatureTest, ValidParseEmptyTest) { - const llvm::StringLiteral Source = R"cc()cc"; - - TrivialModuleLoader ModLoader; - auto PP = createPP(Source, ModLoader); - auto TokLoc = SourceLocation(); - - hlsl::RootSignatureLexer Lexer(Source, TokLoc); - SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); - - // Test no diagnostics produced - Consumer->setNoDiag(); - - ASSERT_FALSE(Parser.parse()); - ASSERT_EQ((int)Elements.size(), 0); - - ASSERT_TRUE(Consumer->isSatisfied()); -} - -TEST_F(ParseHLSLRootSignatureTest, ValidParseDTClausesTest) { - const llvm::StringLiteral Source = R"cc( - DescriptorTable( - CBV(), - SRV(), - Sampler(), - UAV() - ), - DescriptorTable() - )cc"; - - TrivialModuleLoader ModLoader; - auto PP = createPP(Source, ModLoader); - auto TokLoc = SourceLocation(); - - hlsl::RootSignatureLexer Lexer(Source, TokLoc); - SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); - - // Test no diagnostics produced - Consumer->setNoDiag(); - - ASSERT_FALSE(Parser.parse()); - - // First Descriptor Table with 4 elements - RootElement Elem = Elements[0]; - ASSERT_TRUE(std::holds_alternative<DescriptorTableClause>(Elem)); - ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Type, ClauseType::CBuffer); - - Elem = Elements[1]; - ASSERT_TRUE(std::holds_alternative<DescriptorTableClause>(Elem)); - ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Type, ClauseType::SRV); - - ... [truncated] `````````` </details> https://github.com/llvm/llvm-project/pull/133790 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits