@@ -5228,68 +5228,73 @@ void Parser::ParseMicrosoftRootSignatureAttributeArgs(ParsedAttributes &Attrs) {
5228
5228
return ;
5229
5229
}
5230
5230
5231
- if (!isTokenStringLiteral ()) {
5231
+ auto ProcessStringLiteral = [this ]() -> std::optional<StringLiteral *> {
5232
+ if (!isTokenStringLiteral ())
5233
+ return std::nullopt;
5234
+
5235
+ ExprResult StringResult = ParseUnevaluatedStringLiteralExpression ();
5236
+ if (StringResult.isInvalid ())
5237
+ return std::nullopt;
5238
+
5239
+ if (auto Lit = dyn_cast<StringLiteral>(StringResult.get ()))
5240
+ return Lit;
5241
+
5242
+ return std::nullopt;
5243
+ };
5244
+
5245
+ auto StrLiteral = ProcessStringLiteral ();
5246
+ if (!StrLiteral.has_value ()) {
5232
5247
Diag (Tok, diag::err_expected_string_literal)
5233
5248
<< /* in attributes...*/ 4 << RootSignatureIdent->getName ();
5234
5249
SkipUntil (tok::r_square, StopAtSemi | StopBeforeMatch);
5235
5250
if (Tok.is (tok::r_paren))
5236
5251
T.consumeClose ();
5237
5252
return ;
5238
5253
}
5254
+
5255
+ // Construct our identifier
5256
+ StringRef Signature = StrLiteral.value ()->getString ();
5257
+ auto Hash = llvm::hash_value (Signature);
5258
+ std::string IdStr = " __hlsl_rootsig_decl_" + std::to_string (Hash);
5259
+ IdentifierInfo *DeclIdent = &(Actions.getASTContext ().Idents .get (IdStr));
5260
+
5261
+ LookupResult R (Actions, DeclIdent, SourceLocation (),
5262
+ Sema::LookupOrdinaryName);
5263
+ // Check if we have already found a decl of the same name, if we haven't
5264
+ // then parse the root signature string and construct the in-memory elements
5265
+ if (!Actions.LookupQualifiedName (R, Actions.CurContext )) {
5266
+ // Invoke the root signature parser to construct the in-memory constructs
5267
+ hlsl::RootSignatureLexer Lexer (Signature, RootSignatureLoc);
5268
+ SmallVector<llvm::hlsl::rootsig::RootElement> Elements;
5269
+ hlsl::RootSignatureParser Parser (Elements, Lexer, PP);
5270
+ if (Parser.parse ()) {
5271
+ SkipUntil (tok::r_square, StopAtSemi | StopBeforeMatch);
5272
+ if (Tok.is (tok::r_paren))
5273
+ T.consumeClose ();
5274
+ return ;
5275
+ }
5239
5276
5240
- ExprResult StringResult = ParseUnevaluatedStringLiteralExpression ();
5241
- if (StringResult. isInvalid ()) {
5242
- SkipUntil (tok::r_square, StopAtSemi | StopBeforeMatch);
5243
- if (Tok. is (tok::r_paren))
5244
- T. consumeClose ( );
5245
- return ;
5246
- }
5277
+ // Allocate the root elements onto ASTContext
5278
+ unsigned N = Elements. size ();
5279
+ auto RootElements = MutableArrayRef<llvm::hlsl::rootsig::RootElement>(
5280
+ :: new (Actions. getASTContext ()) llvm::hlsl::rootsig::RootElement[N],
5281
+ N );
5282
+ for ( unsigned I = 0 ; I < N; ++I)
5283
+ RootElements[I] = Elements[I];
5247
5284
5248
- ArgsVector Args;
5249
- if (auto Lit = dyn_cast<StringLiteral>(StringResult.get ())) {
5250
- // Construct our identifier
5251
- StringRef Signature = Lit->getString ();
5252
- auto Hash = llvm::hash_value (Signature);
5253
- std::string IdStr = " __hlsl_rootsig_decl_" + std::to_string (Hash);
5254
- IdentifierInfo *DeclIdent = &(Actions.getASTContext ().Idents .get (IdStr));
5255
-
5256
- LookupResult R (Actions, DeclIdent, SourceLocation (),
5257
- Sema::LookupOrdinaryName);
5258
- // Check if we have already found a decl of the same name, if we haven't
5259
- // then parse the root signature string and construct the in-memory elements
5260
- if (!Actions.LookupQualifiedName (R, Actions.CurContext )) {
5261
- // Invoke the root signature parser to construct the in-memory constructs
5262
- hlsl::RootSignatureLexer Lexer (Signature, RootSignatureLoc);
5263
- SmallVector<llvm::hlsl::rootsig::RootElement> Elements;
5264
- hlsl::RootSignatureParser Parser (Elements, Lexer, PP);
5265
- if (Parser.parse ()) {
5266
- SkipUntil (tok::r_square, StopAtSemi | StopBeforeMatch);
5267
- if (Tok.is (tok::r_paren))
5268
- T.consumeClose ();
5269
- return ;
5270
- }
5285
+ // Create the Root Signature
5286
+ auto *SignatureDecl = HLSLRootSignatureDecl::Create (
5287
+ Actions.getASTContext (), /* DeclContext=*/ Actions.CurContext ,
5288
+ RootSignatureLoc, DeclIdent, RootElements);
5289
+ SignatureDecl->setImplicit ();
5290
+ Actions.PushOnScopeChains (SignatureDecl, getCurScope ());
5291
+ }
5271
5292
5272
- // Allocate the root elements onto ASTContext
5273
- unsigned N = Elements.size ();
5274
- auto RootElements = MutableArrayRef<llvm::hlsl::rootsig::RootElement>(
5275
- ::new (Actions.getASTContext ()) llvm::hlsl::rootsig::RootElement[N],
5276
- N);
5277
- for (unsigned I = 0 ; I < N; ++I)
5278
- RootElements[I] = Elements[I];
5279
-
5280
- // Create the Root Signature
5281
- auto *SignatureDecl = HLSLRootSignatureDecl::Create (
5282
- Actions.getASTContext (), /* DeclContext=*/ Actions.CurContext ,
5283
- RootSignatureLoc, DeclIdent, RootElements);
5284
- SignatureDecl->setImplicit ();
5285
- Actions.PushOnScopeChains (SignatureDecl, getCurScope ());
5286
- }
5293
+ // Create the arg for the ParsedAttr
5294
+ IdentifierLoc *ILoc = ::new (Actions.getASTContext ())
5295
+ IdentifierLoc (RootSignatureLoc, DeclIdent);
5287
5296
5288
- // Create the arg for the ParsedAttr
5289
- IdentifierLoc *ILoc = ::new (Actions.getASTContext ())
5290
- IdentifierLoc (RootSignatureLoc, DeclIdent);
5291
- Args.push_back (ILoc);
5292
- }
5297
+ ArgsVector Args = { ILoc };
5293
5298
5294
5299
if (!T.consumeClose ())
5295
5300
Attrs.addNew (RootSignatureIdent,
0 commit comments