Skip to content

Commit

Permalink
Rollup merge of rust-lang#46030 - Zoxc:asm-volatile, r=nikomatsakis
Browse files Browse the repository at this point in the history
Make inline assembly volatile if it has no outputs. Fixes rust-lang#46026
  • Loading branch information
kennytm committed Feb 5, 2018
2 parents 6c04c41 + a29d854 commit eb5a461
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/libsyntax_ext/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,12 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt,
}
}

// If there are no outputs, the inline assembly is executed just for its side effects,
// so ensure that it is volatile
if outputs.is_empty() {
volatile = true;
}

MacEager::expr(P(ast::Expr {
id: ast::DUMMY_NODE_ID,
node: ast::ExprKind::InlineAsm(P(ast::InlineAsm {
Expand Down
26 changes: 26 additions & 0 deletions src/test/codegen/no-output-asm-is-volatile.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -O

// ignore-asmjs

#![feature(asm)]
#![crate_type = "lib"]

// Check that inline assembly expressions without any outputs
// are marked as having side effects / being volatile

// CHECK-LABEL: @assembly
#[no_mangle]
pub fn assembly() {
unsafe { asm!("") }
// CHECK: tail call void asm sideeffect "", {{.*}}
}

0 comments on commit eb5a461

Please sign in to comment.