Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Merge remote-tracking branch 'upstream/main' into parser-h-reorganiza…
…tion
  • Loading branch information
Endilll committed May 14, 2025
commit 325fe3e78bf290740af3815c8254d59f30491183
13 changes: 12 additions & 1 deletion clang/include/clang/Parse/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -2285,7 +2285,6 @@ class Parser : public CodeCompletionHandler {
}
return AttrsParsed;
}

bool MaybeParseMicrosoftDeclSpecs(ParsedAttributes &Attrs) {
if (getLangOpts().DeclSpecKeyword && Tok.is(tok::kw___declspec)) {
ParseMicrosoftDeclSpecs(Attrs);
Expand Down Expand Up @@ -3603,6 +3602,8 @@ class Parser : public CodeCompletionHandler {
/// keyword.
bool isClassCompatibleKeyword(Token Tok) const;

void ParseMicrosoftRootSignatureAttributeArgs(ParsedAttributes &Attrs);

///@}

//
Expand Down Expand Up @@ -6949,6 +6950,16 @@ class Parser : public CodeCompletionHandler {
/// where, map-type ::= alloc | delete | from | release | to | tofrom
bool parseMapTypeModifiers(SemaOpenMP::OpenMPVarListDataTy &Data);

/// Parses 'omp begin declare variant' directive.
/// The syntax is:
/// \verbatim
/// { #pragma omp begin declare variant clause }
/// <function-declaration-or-definition-sequence>
/// { #pragma omp end declare variant }
/// \endverbatim
///
bool ParseOpenMPDeclareBeginVariantDirective(SourceLocation Loc);

///@}

//
Expand Down
84 changes: 84 additions & 0 deletions clang/lib/Parse/ParseDeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4902,6 +4902,90 @@ void Parser::ParseMicrosoftUuidAttributeArgs(ParsedAttributes &Attrs) {
}
}

void Parser::ParseMicrosoftRootSignatureAttributeArgs(ParsedAttributes &Attrs) {
assert(Tok.is(tok::identifier) &&
"Expected an identifier to denote which MS attribute to consider");
IdentifierInfo *RootSignatureIdent = Tok.getIdentifierInfo();
assert(RootSignatureIdent->getName() == "RootSignature" &&
"Expected RootSignature identifier for root signature attribute");

SourceLocation RootSignatureLoc = Tok.getLocation();
ConsumeToken();

// Ignore the left paren location for now.
BalancedDelimiterTracker T(*this, tok::l_paren);
if (T.consumeOpen()) {
Diag(Tok, diag::err_expected) << tok::l_paren;
return;
}

auto ProcessStringLiteral = [this]() -> std::optional<StringLiteral *> {
if (!isTokenStringLiteral())
return std::nullopt;

ExprResult StringResult = ParseUnevaluatedStringLiteralExpression();
if (StringResult.isInvalid())
return std::nullopt;

if (auto Lit = dyn_cast<StringLiteral>(StringResult.get()))
return Lit;

return std::nullopt;
};

auto StrLiteral = ProcessStringLiteral();
if (!StrLiteral.has_value()) {
Diag(Tok, diag::err_expected_string_literal)
<< /*in attributes...*/ 4 << RootSignatureIdent->getName();
SkipUntil(tok::r_paren, StopAtSemi | StopBeforeMatch);
T.consumeClose();
return;
}

// Construct our identifier
StringRef Signature = StrLiteral.value()->getString();
auto Hash = llvm::hash_value(Signature);
std::string IdStr = "__hlsl_rootsig_decl_" + std::to_string(Hash);
IdentifierInfo *DeclIdent = &(Actions.getASTContext().Idents.get(IdStr));

LookupResult R(Actions, DeclIdent, SourceLocation(),
Sema::LookupOrdinaryName);
// Check if we have already found a decl of the same name, if we haven't
// then parse the root signature string and construct the in-memory elements
if (!Actions.LookupQualifiedName(R, Actions.CurContext)) {
SourceLocation SignatureLoc =
StrLiteral.value()->getExprLoc().getLocWithOffset(
1); // offset 1 for '"'
// Invoke the root signature parser to construct the in-memory constructs
hlsl::RootSignatureLexer Lexer(Signature, SignatureLoc);
SmallVector<llvm::hlsl::rootsig::RootElement> RootElements;
hlsl::RootSignatureParser Parser(RootElements, Lexer, PP);
if (Parser.parse()) {
T.consumeClose();
return;
}

// Create the Root Signature
auto *SignatureDecl = HLSLRootSignatureDecl::Create(
Actions.getASTContext(), /*DeclContext=*/Actions.CurContext,
RootSignatureLoc, DeclIdent, RootElements);
SignatureDecl->setImplicit();
Actions.PushOnScopeChains(SignatureDecl, getCurScope());
}

// Create the arg for the ParsedAttr
IdentifierLoc *ILoc = ::new (Actions.getASTContext())
IdentifierLoc(RootSignatureLoc, DeclIdent);

ArgsVector Args = {ILoc};

if (!T.consumeClose())
Attrs.addNew(RootSignatureIdent,
SourceRange(RootSignatureLoc, T.getCloseLocation()), nullptr,
SourceLocation(), Args.data(), Args.size(),
ParsedAttr::Form::Microsoft());
}

void Parser::ParseMicrosoftAttributes(ParsedAttributes &Attrs) {
assert(Tok.is(tok::l_square) && "Not a Microsoft attribute list");

Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.