@@ -841,9 +841,13 @@ static bool parseSILOptional(StringRef &Result, SILParser &SP) {
841
841
// / Parse an option attribute ('[' Expected ']')?
842
842
static bool parseSILOptional (bool &Result, SILParser &SP, StringRef Expected) {
843
843
StringRef Optional;
844
- if (parseSILOptional (Optional, SP)) {
845
- if (Optional != Expected)
844
+ SourceLoc Loc;
845
+ if (parseSILOptional (Optional, Loc, SP)) {
846
+ if (Optional != Expected) {
847
+ SP.P .diagnose (Loc, diag::sil_invalid_attribute_for_expected, Optional,
848
+ Expected);
846
849
return true ;
850
+ }
847
851
Result = true ;
848
852
}
849
853
return false ;
@@ -3279,14 +3283,8 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
3279
3283
SourceLoc AddrLoc;
3280
3284
3281
3285
bool isLexical = false ;
3282
- StringRef attributeName;
3283
-
3284
- if (parseSILOptional (attributeName, *this )) {
3285
- if (attributeName.equals (" lexical" ))
3286
- isLexical = true ;
3287
- else
3288
- return true ;
3289
- }
3286
+ if (parseSILOptional (isLexical, *this , " lexical" ))
3287
+ return true ;
3290
3288
3291
3289
if (parseTypedValueRef (Val, AddrLoc, B) ||
3292
3290
parseSILDebugLocation (InstLoc, B))
@@ -4146,29 +4144,18 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
4146
4144
bool hasDynamicLifetime = false ;
4147
4145
bool isLexical = false ;
4148
4146
4149
- while (P.consumeIf (tok::l_square)) {
4150
- Identifier ident;
4151
- SourceLoc identLoc;
4152
- if (parseSILIdentifier (ident, identLoc,
4153
- diag::expected_in_attribute_list)) {
4154
- if (P.consumeIf (tok::r_square)) {
4155
- continue ;
4156
- } else {
4157
- return true ;
4158
- }
4159
- }
4160
- StringRef attr = ident.str ();
4161
-
4162
- if (attr == " dynamic_lifetime" ) {
4147
+ StringRef attributeName;
4148
+ SourceLoc attributeLoc;
4149
+ while (parseSILOptional (attributeName, attributeLoc, *this )) {
4150
+ if (attributeName == " dynamic_lifetime" )
4163
4151
hasDynamicLifetime = true ;
4164
- } else if (attr == " lexical" ) {
4152
+ else if (attributeName == " lexical" )
4165
4153
isLexical = true ;
4166
- } else {
4154
+ else {
4155
+ P.diagnose (attributeLoc, diag::sil_invalid_attribute_for_instruction,
4156
+ attributeName, " alloc_stack" );
4167
4157
return true ;
4168
4158
}
4169
-
4170
- if (!P.consumeIf (tok::r_square))
4171
- return true ;
4172
4159
}
4173
4160
4174
4161
SILType Ty;
0 commit comments