Skip to content

Commit a29d854

Browse files
committed
Make inline assembly volatile if it has no outputs. Fixes #46026
1 parent 8385fc0 commit a29d854

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/libsyntax_ext/asm.rs

+6
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,12 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt,
239239
}
240240
}
241241

242+
// If there are no outputs, the inline assembly is executed just for its side effects,
243+
// so ensure that it is volatile
244+
if outputs.is_empty() {
245+
volatile = true;
246+
}
247+
242248
MacEager::expr(P(ast::Expr {
243249
id: ast::DUMMY_NODE_ID,
244250
node: ast::ExprKind::InlineAsm(P(ast::InlineAsm {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-flags: -O
12+
13+
// ignore-asmjs
14+
15+
#![feature(asm)]
16+
#![crate_type = "lib"]
17+
18+
// Check that inline assembly expressions without any outputs
19+
// are marked as having side effects / being volatile
20+
21+
// CHECK-LABEL: @assembly
22+
#[no_mangle]
23+
pub fn assembly() {
24+
unsafe { asm!("") }
25+
// CHECK: tail call void asm sideeffect "", {{.*}}
26+
}

0 commit comments

Comments
 (0)