Skip to content

Commit f8b165e

Browse files
committed
define ActOnStartRootSignatureDecl
1 parent b88e8cc commit f8b165e

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

clang/include/clang/Sema/Sema.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3619,6 +3619,9 @@ class Sema final : public SemaBase {
36193619
SourceLocation NameLoc,
36203620
bool IsTemplateTypeArg);
36213621

3622+
std::pair<IdentifierInfo *, bool>
3623+
ActOnStartRootSignatureDecl(StringRef Signature);
3624+
36223625
class NameClassification {
36233626
NameClassificationKind Kind;
36243627
union {

clang/lib/Parse/ParseDeclCXX.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4942,18 +4942,13 @@ void Parser::ParseMicrosoftRootSignatureAttributeArgs(ParsedAttributes &Attrs) {
49424942

49434943
// Construct our identifier
49444944
StringRef Signature = StrLiteral.value()->getString();
4945-
auto Hash = llvm::hash_value(Signature);
4946-
std::string IdStr = "__hlsl_rootsig_decl_" + std::to_string(Hash);
4947-
IdentifierInfo *DeclIdent = &(Actions.getASTContext().Idents.get(IdStr));
4948-
4949-
LookupResult R(Actions, DeclIdent, SourceLocation(),
4950-
Sema::LookupOrdinaryName);
4951-
// Check if we have already found a decl of the same name, if we haven't
4952-
// then parse the root signature string and construct the in-memory elements
4953-
if (!Actions.LookupQualifiedName(R, Actions.CurContext)) {
4945+
auto [DeclIdent, Found] = Actions.ActOnStartRootSignatureDecl(Signature);
4946+
// If we haven't found an already defined DeclIdent then parse the root
4947+
// signature string and construct the in-memory elements
4948+
if (!Found) {
4949+
// Offset location 1 to account for '"'
49544950
SourceLocation SignatureLoc =
4955-
StrLiteral.value()->getExprLoc().getLocWithOffset(
4956-
1); // offset 1 for '"'
4951+
StrLiteral.value()->getExprLoc().getLocWithOffset(1);
49574952
// Invoke the root signature parser to construct the in-memory constructs
49584953
hlsl::RootSignatureLexer Lexer(Signature, SignatureLoc);
49594954
SmallVector<llvm::hlsl::rootsig::RootElement> RootElements;

clang/lib/Sema/SemaDecl.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,19 @@ ParsedType Sema::ActOnMSVCUnknownTypeName(const IdentifierInfo &II,
653653
return CreateParsedType(T, Builder.getTypeSourceInfo(Context, T));
654654
}
655655

656+
std::pair<IdentifierInfo *, bool>
657+
Sema::ActOnStartRootSignatureDecl(StringRef Signature) {
658+
auto Hash = llvm::hash_value(Signature);
659+
std::string IdStr = "__hlsl_rootsig_decl_" + std::to_string(Hash);
660+
IdentifierInfo *DeclIdent = &(getASTContext().Idents.get(IdStr));
661+
662+
// Check if we have already found a decl of the same name
663+
LookupResult R(Actions, DeclIdent, SourceLocation(),
664+
Sema::LookupOrdinaryName);
665+
bool Found = LookupQualifiedName(R, Actions.CurContext);
666+
return {DeclIdent, Found};
667+
}
668+
656669
DeclSpec::TST Sema::isTagName(IdentifierInfo &II, Scope *S) {
657670
// Do a tag name lookup in this scope.
658671
LookupResult R(*this, &II, SourceLocation(), LookupTagName);

0 commit comments

Comments
 (0)