@@ -802,15 +802,35 @@ static SILLinkage resolveSILLinkage(Optional<SILLinkage> linkage,
802
802
}
803
803
}
804
804
805
- static bool parseSILOptional (StringRef &Result, SourceLoc &Loc, SILParser &SP) {
806
- if (SP.P .consumeIf (tok::l_square)) {
807
- Identifier Id;
808
- SP.parseSILIdentifier (Id, Loc, diag::expected_in_attribute_list);
809
- SP.P .parseToken (tok::r_square, diag::expected_in_attribute_list);
810
- Result = Id.str ();
805
+ // Returns false if no optional exists. Returns true on both success and
806
+ // failure. On success, the Result string is nonempty. If the optional is
807
+ // assigned to an integer value, \p value contains the parsed value. Otherwise,
808
+ // value is set to the maximum uint64_t.
809
+ static bool parseSILOptional (StringRef &Result, uint64_t &value, SourceLoc &Loc,
810
+ SILParser &SP) {
811
+ if (!SP.P .consumeIf (tok::l_square))
812
+ return false ;
813
+
814
+ value = ~uint64_t (0 );
815
+
816
+ Identifier Id;
817
+ if (SP.parseSILIdentifier (Id, Loc, diag::expected_in_attribute_list))
811
818
return true ;
819
+
820
+ if (SP.P .consumeIf (tok::equal)) {
821
+ if (SP.parseInteger (value, diag::expected_in_attribute_list))
822
+ return true ;
812
823
}
813
- return false ;
824
+ if (SP.P .parseToken (tok::r_square, diag::expected_in_attribute_list))
825
+ return true ;
826
+
827
+ Result = Id.str ();
828
+ return true ;
829
+ }
830
+
831
+ static bool parseSILOptional (StringRef &Result, SourceLoc &Loc, SILParser &SP) {
832
+ uint64_t value;
833
+ return parseSILOptional (Result, value, Loc, SP);
814
834
}
815
835
816
836
static bool parseSILOptional (StringRef &Result, SILParser &SP) {
@@ -3603,21 +3623,35 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
3603
3623
parseSILIdentifier (ToToken, ToLoc, diag::expected_tok_in_sil_instr,
3604
3624
" to" ))
3605
3625
return true ;
3606
- if (parseSILOptional (attr, *this ) && attr.empty ())
3607
- return true ;
3626
+
3627
+ bool isStrict = false ;
3628
+ bool isInvariant = false ;
3629
+ llvm::MaybeAlign alignment;
3630
+ uint64_t parsedValue = 0 ;
3631
+ while (parseSILOptional (attr, parsedValue, ToLoc, *this )) {
3632
+ if (attr.empty ())
3633
+ return true ;
3634
+
3635
+ if (attr.equals (" strict" ))
3636
+ isStrict = true ;
3637
+
3638
+ if (attr.equals (" invariant" ))
3639
+ isInvariant = true ;
3640
+
3641
+ if (attr.equals (" align" ))
3642
+ alignment = llvm::Align (parsedValue);
3643
+ }
3644
+
3608
3645
if (parseSILType (Ty) || parseSILDebugLocation (InstLoc, B))
3609
3646
return true ;
3610
3647
3611
- bool isStrict = attr.equals (" strict" );
3612
- bool isInvariant = attr.equals (" invariant" );
3613
-
3614
3648
if (ToToken.str () != " to" ) {
3615
3649
P.diagnose (ToLoc, diag::expected_tok_in_sil_instr, " to" );
3616
3650
return true ;
3617
3651
}
3618
3652
3619
- ResultVal =
3620
- B. createPointerToAddress (InstLoc, Val, Ty, isStrict, isInvariant);
3653
+ ResultVal = B. createPointerToAddress (InstLoc, Val, Ty, isStrict,
3654
+ isInvariant, alignment );
3621
3655
break ;
3622
3656
}
3623
3657
case SILInstructionKind::RefToBridgeObjectInst: {
0 commit comments