diff options
| author | John Kåre Alsaker <john.kare.alsaker@gmail.com> | 2017-11-16 10:08:19 +0100 |
|---|---|---|
| committer | John Kåre Alsaker <john.kare.alsaker@gmail.com> | 2018-02-05 15:56:44 +0100 |
| commit | a29d8545b573d008e364571a83fcd865748a8ad8 (patch) | |
| tree | a172464bae2104117c4eeacbed5e4fc3bd1efb55 | |
| parent | 8385fc062dbb57c32d96d16e59d244c168103946 (diff) | |
| download | rust-a29d8545b573d008e364571a83fcd865748a8ad8.tar.gz rust-a29d8545b573d008e364571a83fcd865748a8ad8.zip | |
Make inline assembly volatile if it has no outputs. Fixes #46026
| -rw-r--r-- | src/libsyntax_ext/asm.rs | 6 | ||||
| -rw-r--r-- | src/test/codegen/no-output-asm-is-volatile.rs | 26 |
2 files changed, 32 insertions, 0 deletions
diff --git a/src/libsyntax_ext/asm.rs b/src/libsyntax_ext/asm.rs index 3742fb8c804..d1de4dccd00 100644 --- a/src/libsyntax_ext/asm.rs +++ b/src/libsyntax_ext/asm.rs @@ -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 { diff --git a/src/test/codegen/no-output-asm-is-volatile.rs b/src/test/codegen/no-output-asm-is-volatile.rs new file mode 100644 index 00000000000..457d706a8ff --- /dev/null +++ b/src/test/codegen/no-output-asm-is-volatile.rs @@ -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 "", {{.*}} +} |
