diff options
| author | Alexey Tarasov <tarasov@dodologics.com> | 2017-08-12 18:42:44 +1000 |
|---|---|---|
| committer | Alexey Tarasov <tarasov@dodologics.com> | 2017-08-12 18:42:44 +1000 |
| commit | 0cd358742dfcf3fa6b0d8a318cfb5cc748dc905d (patch) | |
| tree | 944cf6399d0b2ed24f9703afc71133b70b810659 /src/test | |
| parent | 2fa5340318111d562af2ef4897c75916731d55a2 (diff) | |
| download | rust-0cd358742dfcf3fa6b0d8a318cfb5cc748dc905d.tar.gz rust-0cd358742dfcf3fa6b0d8a318cfb5cc748dc905d.zip | |
Fixes issue 39827: ICE in volatile_store intrinsic
- adds handling of zero-sized types for volatile_store. - adds type size checks and warnigns for other volatile intrinsics. - adds a test to check warnings emitting. Cause of the issue While preparing for trans_intrinsic_call() invoke arguments are processed with trans_argument() method which excludes zero-sized types from argument list (to be more correct - all arguments for which ArgKind is Ignore are filtered out). As result volatile_store() intrinsic gets one argument instead of expected address and value. How it is fixed Modification of the trans_argument() method may cause side effects, therefore change was implemented in volatile_store() intrinsic building code itself. Now it checks function signature and if it was specialised with zero-sized type, then emits C_nil() instead of accessing non-existing second argument. Additionally warnings are added for all volatile operations which are specialised with zero-sized arguments. In fact, those operations are omitted in LLVM backend if no memory affected at all, e.g. number of elements is zero or type is zero-sized. This was not explicitly documented before and could lead to potential issues if developer expects volatile behaviour, but type has degraded to zero-sized.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/ui/issue-39827.rs | 37 | ||||
| -rw-r--r-- | src/test/ui/issue-39827.stderr | 73 |
2 files changed, 110 insertions, 0 deletions
diff --git a/src/test/ui/issue-39827.rs b/src/test/ui/issue-39827.rs new file mode 100644 index 00000000000..86a3f67b40a --- /dev/null +++ b/src/test/ui/issue-39827.rs @@ -0,0 +1,37 @@ +// 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. +#![feature(core_intrinsics)] + +use std::intrinsics::{ volatile_copy_memory, volatile_store, volatile_load, + volatile_copy_nonoverlapping_memory, + volatile_set_memory }; + +fn main () { + let mut dst_pair = (1, 2); + let src_pair = (3, 4); + let mut dst_empty = (); + let src_empty = (); + + const COUNT_0: usize = 0; + const COUNT_100: usize = 100; + + unsafe { + volatile_copy_memory(&mut dst_pair, &dst_pair, COUNT_0); + volatile_copy_nonoverlapping_memory(&mut dst_pair, &src_pair, 0); + volatile_copy_memory(&mut dst_empty, &dst_empty, 100); + volatile_copy_nonoverlapping_memory(&mut dst_empty, &src_empty, + COUNT_100); + volatile_set_memory(&mut dst_empty, 0, COUNT_100); + volatile_set_memory(&mut dst_pair, 0, COUNT_0); + volatile_store(&mut dst_empty, ()); + volatile_store(&mut dst_empty, src_empty); + volatile_load(&src_empty); + } +} diff --git a/src/test/ui/issue-39827.stderr b/src/test/ui/issue-39827.stderr new file mode 100644 index 00000000000..228309872f9 --- /dev/null +++ b/src/test/ui/issue-39827.stderr @@ -0,0 +1,73 @@ +warning: suspicious monomorphization of `volatile_copy_memory` intrinsic + --> $DIR/issue-39827.rs:26:9 + | +26 | volatile_copy_memory(&mut dst_pair, &dst_pair, COUNT_0); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: 'volatile_copy_memory' was specialized with type '(i32, i32)', number of elements is 0 + +warning: suspicious monomorphization of `volatile_copy_nonoverlapping_memory` intrinsic + --> $DIR/issue-39827.rs:27:9 + | +27 | volatile_copy_nonoverlapping_memory(&mut dst_pair, &src_pair, 0); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: 'volatile_copy_nonoverlapping_memory' was specialized with type '(i32, i32)', number of elements is 0 + +warning: suspicious monomorphization of `volatile_copy_memory` intrinsic + --> $DIR/issue-39827.rs:28:9 + | +28 | volatile_copy_memory(&mut dst_empty, &dst_empty, 100); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: 'volatile_copy_memory' was specialized with type '()', number of elements is 100 + +warning: suspicious monomorphization of `volatile_copy_nonoverlapping_memory` intrinsic + --> $DIR/issue-39827.rs:29:9 + | +29 | / volatile_copy_nonoverlapping_memory(&mut dst_empty, &src_empty, +30 | | COUNT_100); + | |______________________________________________________^ + | + = note: 'volatile_copy_nonoverlapping_memory' was specialized with type '()', number of elements is 100 + +warning: suspicious monomorphization of `volatile_set_memory` intrinsic + --> $DIR/issue-39827.rs:31:9 + | +31 | volatile_set_memory(&mut dst_empty, 0, COUNT_100); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: 'volatile_set_memory' was specialized with type '()', number of elements is 100 + +warning: suspicious monomorphization of `volatile_set_memory` intrinsic + --> $DIR/issue-39827.rs:32:9 + | +32 | volatile_set_memory(&mut dst_pair, 0, COUNT_0); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: 'volatile_set_memory' was specialized with type '(i32, i32)', number of elements is 0 + +warning: suspicious monomorphization of `volatile_store` intrinsic + --> $DIR/issue-39827.rs:33:9 + | +33 | volatile_store(&mut dst_empty, ()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: 'volatile_store' was specialized with zero-sized type '()' + +warning: suspicious monomorphization of `volatile_store` intrinsic + --> $DIR/issue-39827.rs:34:9 + | +34 | volatile_store(&mut dst_empty, src_empty); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: 'volatile_store' was specialized with zero-sized type '()' + +warning: suspicious monomorphization of `volatile_load` intrinsic + --> $DIR/issue-39827.rs:35:9 + | +35 | volatile_load(&src_empty); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: 'volatile_load' was specialized with zero-sized type '()' + |
