Skip to content

Commit

Permalink
#7213: Handle asm! macro calls in control flow
Browse files Browse the repository at this point in the history
Add very initial handling of `asm!(...)` macro calls during control flow graph building. Previously, `asm!(...)` macro calls caused `java.lang.IllegalStateException: unreachable`
  • Loading branch information
artemmukhin committed Jun 1, 2021
1 parent 2ae1364 commit b70d116
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main/kotlin/org/rust/lang/core/dfa/CFGBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,11 @@ class CFGBuilder(
.fold(pred) { acc, subExpr -> process(subExpr, acc) }
}

is RsAsmMacroArgument -> {
// TODO: Handle this case when type inference is implemented for `asm!` macro calls
null
}

is RsMacroArgument -> {
val expansion = macroCall.expansion
val expandedElementsExit = expansion?.elements?.fold(pred) { pred, element -> process(element, pred) }
Expand Down
29 changes: 29 additions & 0 deletions src/test/kotlin/org/rust/lang/core/dfa/RsControlFlowGraphTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,35 @@ class RsControlFlowGraphTest : RsTestBase() {
Termination
""")

fun `test asm! macro call`() = testCFG("""
fn main() {
1;
let x: u64;
unsafe {
asm!("mov {}, 5", out(reg) x);
}
2;
}
""", """
Entry
1
1;
x
x
let x: u64;
x
asm!("mov {}, 5", out(reg) x)
asm!("mov {}, 5", out(reg) x);
BLOCK
BLOCK
BLOCK;
2
2;
BLOCK
Exit
Termination
""")

private fun testCFG(@Language("Rust") code: String, expectedIndented: String) {
InlineFile(code)
val function = myFixture.file.descendantsOfType<RsFunction>().firstOrNull() ?: return
Expand Down

0 comments on commit b70d116

Please sign in to comment.