Skip to content

Commit

Permalink
clif: Fix parsing the cold calling convention (#8854)
Browse files Browse the repository at this point in the history
The identifier for the `cold` calling convention overlaps with the
`cold` keyword for basic blocks so handle another kind of token when
parsing signatures.
  • Loading branch information
alexcrichton authored Jun 20, 2024
1 parent e29d56e commit 6b89213
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
12 changes: 12 additions & 0 deletions cranelift/filetests/filetests/parser/cold.clif
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
test cat

function %cold() cold {
sig0 = () cold
sig1 = () -> i8 cold
block1:
return
}

; sameln: function %cold() cold {
; nextln: sig0 = () cold
; nextln: sig1 = () -> i8 cold
10 changes: 8 additions & 2 deletions cranelift/reader/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1347,14 +1347,20 @@ impl<'a> Parser<'a> {
}

// The calling convention is optional.
if let Some(Token::Identifier(text)) = self.token() {
match text.parse() {
match self.token() {
Some(Token::Identifier(text)) => match text.parse() {
Ok(cc) => {
self.consume();
sig.call_conv = cc;
}
_ => return err!(self.loc, "unknown calling convention: {}", text),
},

Some(Token::Cold) => {
self.consume();
sig.call_conv = CallConv::Cold;
}
_ => {}
}

Ok(sig)
Expand Down

0 comments on commit 6b89213

Please sign in to comment.