Addresses comments in PR #43836

- removes warnings introduced in changeset 0cd3587
- makes documentation more neat and grammatically correct
This commit is contained in:
Alexey Tarasov 2017-08-13 19:28:04 +10:00
parent 6a607faba4
commit faf6b84304
4 changed files with 16 additions and 126 deletions

View File

@ -384,11 +384,10 @@ pub unsafe fn write_unaligned<T>(dst: *mut T, src: T) {
/// over time. That being said, the semantics will almost always end up pretty /// over time. That being said, the semantics will almost always end up pretty
/// similar to [C11's definition of volatile][c11]. /// similar to [C11's definition of volatile][c11].
/// ///
/// Compiler shouldn't change relative order or number of volatile memory /// The compiler shouldn't change the relative order or number of volatile
/// operations, however this implies that memory operation actually takes place. /// memory operations. However, volatile memory operations on zero-sized types
/// If a zero-sized type is used in a specialisation of `read_volatile`, value /// (e.g. if a zero-sized type is passed to `read_volatile`) are no-ops
/// is known at any time and can not be modified outside of program control. /// and may be ignored.
/// In this case such operation may be omitted by compiler backend.
/// ///
/// [c11]: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf /// [c11]: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf
/// ///
@ -433,11 +432,10 @@ pub unsafe fn read_volatile<T>(src: *const T) -> T {
/// over time. That being said, the semantics will almost always end up pretty /// over time. That being said, the semantics will almost always end up pretty
/// similar to [C11's definition of volatile][c11]. /// similar to [C11's definition of volatile][c11].
/// ///
/// Compiler shouldn't change relative order or number of volatile memory /// The compiler shouldn't change the relative order or number of volatile
/// operations, however this implies that memory operation actually takes place. /// memory operations. However, volatile memory operations on zero-sized types
/// If a zero-sized type is used in a specialisation of `write_volatile`, value /// (e.g. if a zero-sized type is passed to `write_volatile`) are no-ops
/// is known at any time and can not be modified outside of program control. /// and may be ignored.
/// In this case such operation may be omitted by compiler backend.
/// ///
/// [c11]: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf /// [c11]: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf
/// ///

View File

@ -83,38 +83,6 @@ fn get_simple_intrinsic(ccx: &CrateContext, name: &str) -> Option<ValueRef> {
Some(ccx.get_intrinsic(&llvm_name)) Some(ccx.get_intrinsic(&llvm_name))
} }
fn warn_if_size_is_weird<'a, 'tcx>(bcx: &Builder<'a, 'tcx>,
tp_ty: Ty<'tcx>,
count: ValueRef,
span: Span,
name: &str) {
let ccx = bcx.ccx;
let lltp_ty = type_of::type_of(ccx, tp_ty);
let ty_size = machine::llsize_of(ccx, lltp_ty);
let total = const_to_uint( bcx.mul(ty_size, count) );
if total > 0 {
return;
}
let text = format!("suspicious monomorphization of `{}` intrinsic", name);
let note = match name
{
"volatile_load" | "volatile_store" =>
format!("'{}' was specialized with zero-sized type '{}'",
name, tp_ty),
_ => format!("'{}' was specialized with type '{}', number of \
elements is {}",
name, tp_ty,
const_to_uint(count))
};
let sess = bcx.sess();
sess.struct_span_warn(span, &text)
.note(&note)
.emit();
}
/// Remember to add all intrinsics here, in librustc_typeck/check/mod.rs, /// Remember to add all intrinsics here, in librustc_typeck/check/mod.rs,
/// and in libcore/intrinsics.rs; if you need access to any llvm intrinsics, /// and in libcore/intrinsics.rs; if you need access to any llvm intrinsics,
/// add them to librustc_trans/trans/context.rs /// add them to librustc_trans/trans/context.rs
@ -249,24 +217,17 @@ pub fn trans_intrinsic_call<'a, 'tcx>(bcx: &Builder<'a, 'tcx>,
} }
"volatile_copy_nonoverlapping_memory" => { "volatile_copy_nonoverlapping_memory" => {
let tp_ty = substs.type_at(0); copy_intrinsic(bcx, false, true, substs.type_at(0), llargs[0], llargs[1], llargs[2])
warn_if_size_is_weird(bcx, tp_ty, llargs[2], span, name);
copy_intrinsic(bcx, false, true, tp_ty, llargs[0], llargs[1], llargs[2])
} }
"volatile_copy_memory" => { "volatile_copy_memory" => {
let tp_ty = substs.type_at(0); copy_intrinsic(bcx, true, true, substs.type_at(0), llargs[0], llargs[1], llargs[2])
warn_if_size_is_weird(bcx, tp_ty, llargs[2], span, name);
copy_intrinsic(bcx, true, true, tp_ty, llargs[0], llargs[1], llargs[2])
} }
"volatile_set_memory" => { "volatile_set_memory" => {
let tp_ty = substs.type_at(0); memset_intrinsic(bcx, true, substs.type_at(0), llargs[0], llargs[1], llargs[2])
warn_if_size_is_weird(bcx, tp_ty, llargs[2], span, name);
memset_intrinsic(bcx, true, tp_ty, llargs[0], llargs[1], llargs[2])
} }
"volatile_load" => { "volatile_load" => {
let tp_ty = substs.type_at(0); let tp_ty = substs.type_at(0);
let mut ptr = llargs[0]; let mut ptr = llargs[0];
warn_if_size_is_weird(bcx, tp_ty, C_uint(ccx,1usize), span, name);
if let Some(ty) = fn_ty.ret.cast { if let Some(ty) = fn_ty.ret.cast {
ptr = bcx.pointercast(ptr, ty.ptr_to()); ptr = bcx.pointercast(ptr, ty.ptr_to());
} }
@ -278,7 +239,6 @@ pub fn trans_intrinsic_call<'a, 'tcx>(bcx: &Builder<'a, 'tcx>,
}, },
"volatile_store" => { "volatile_store" => {
let tp_ty = substs.type_at(0); let tp_ty = substs.type_at(0);
warn_if_size_is_weird(bcx, tp_ty, C_uint(ccx,1usize), span, name);
if type_is_fat_ptr(bcx.ccx, tp_ty) { if type_is_fat_ptr(bcx.ccx, tp_ty) {
bcx.volatile_store(llargs[1], get_dataptr(bcx, llargs[0])); bcx.volatile_store(llargs[1], get_dataptr(bcx, llargs[0]));
bcx.volatile_store(llargs[2], get_meta(bcx, llargs[0])); bcx.volatile_store(llargs[2], get_meta(bcx, llargs[0]));

View File

@ -13,6 +13,11 @@ use std::intrinsics::{ volatile_copy_memory, volatile_store, volatile_load,
volatile_copy_nonoverlapping_memory, volatile_copy_nonoverlapping_memory,
volatile_set_memory }; volatile_set_memory };
//
// This test ensures that volatile intrinsics can be specialised with
// zero-sized types and, in case of copy/set functions, can accept
// number of elements equal to zero.
//
fn main () { fn main () {
let mut dst_pair = (1, 2); let mut dst_pair = (1, 2);
let src_pair = (3, 4); let src_pair = (3, 4);

View File

@ -1,73 +0,0 @@
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 '()'