Skip to content

Commit faf6b84

Browse files
committed
Addresses comments in PR #43836
- removes warnings introduced in changeset 0cd3587 - makes documentation more neat and grammatically correct
1 parent 6a607fa commit faf6b84

File tree

4 files changed

+16
-126
lines changed

4 files changed

+16
-126
lines changed

src/libcore/ptr.rs

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

src/librustc_trans/intrinsic.rs

+3-43
Original file line numberDiff line numberDiff line change
@@ -83,38 +83,6 @@ fn get_simple_intrinsic(ccx: &CrateContext, name: &str) -> Option<ValueRef> {
8383
Some(ccx.get_intrinsic(&llvm_name))
8484
}
8585

86-
fn warn_if_size_is_weird<'a, 'tcx>(bcx: &Builder<'a, 'tcx>,
87-
tp_ty: Ty<'tcx>,
88-
count: ValueRef,
89-
span: Span,
90-
name: &str) {
91-
let ccx = bcx.ccx;
92-
let lltp_ty = type_of::type_of(ccx, tp_ty);
93-
let ty_size = machine::llsize_of(ccx, lltp_ty);
94-
let total = const_to_uint( bcx.mul(ty_size, count) );
95-
96-
if total > 0 {
97-
return;
98-
}
99-
100-
let text = format!("suspicious monomorphization of `{}` intrinsic", name);
101-
let note = match name
102-
{
103-
"volatile_load" | "volatile_store" =>
104-
format!("'{}' was specialized with zero-sized type '{}'",
105-
name, tp_ty),
106-
_ => format!("'{}' was specialized with type '{}', number of \
107-
elements is {}",
108-
name, tp_ty,
109-
const_to_uint(count))
110-
};
111-
112-
let sess = bcx.sess();
113-
sess.struct_span_warn(span, &text)
114-
.note(&note)
115-
.emit();
116-
}
117-
11886
/// Remember to add all intrinsics here, in librustc_typeck/check/mod.rs,
11987
/// and in libcore/intrinsics.rs; if you need access to any llvm intrinsics,
12088
/// add them to librustc_trans/trans/context.rs
@@ -249,24 +217,17 @@ pub fn trans_intrinsic_call<'a, 'tcx>(bcx: &Builder<'a, 'tcx>,
249217
}
250218

251219
"volatile_copy_nonoverlapping_memory" => {
252-
let tp_ty = substs.type_at(0);
253-
warn_if_size_is_weird(bcx, tp_ty, llargs[2], span, name);
254-
copy_intrinsic(bcx, false, true, tp_ty, llargs[0], llargs[1], llargs[2])
220+
copy_intrinsic(bcx, false, true, substs.type_at(0), llargs[0], llargs[1], llargs[2])
255221
}
256222
"volatile_copy_memory" => {
257-
let tp_ty = substs.type_at(0);
258-
warn_if_size_is_weird(bcx, tp_ty, llargs[2], span, name);
259-
copy_intrinsic(bcx, true, true, tp_ty, llargs[0], llargs[1], llargs[2])
223+
copy_intrinsic(bcx, true, true, substs.type_at(0), llargs[0], llargs[1], llargs[2])
260224
}
261225
"volatile_set_memory" => {
262-
let tp_ty = substs.type_at(0);
263-
warn_if_size_is_weird(bcx, tp_ty, llargs[2], span, name);
264-
memset_intrinsic(bcx, true, tp_ty, llargs[0], llargs[1], llargs[2])
226+
memset_intrinsic(bcx, true, substs.type_at(0), llargs[0], llargs[1], llargs[2])
265227
}
266228
"volatile_load" => {
267229
let tp_ty = substs.type_at(0);
268230
let mut ptr = llargs[0];
269-
warn_if_size_is_weird(bcx, tp_ty, C_uint(ccx,1usize), span, name);
270231
if let Some(ty) = fn_ty.ret.cast {
271232
ptr = bcx.pointercast(ptr, ty.ptr_to());
272233
}
@@ -278,7 +239,6 @@ pub fn trans_intrinsic_call<'a, 'tcx>(bcx: &Builder<'a, 'tcx>,
278239
},
279240
"volatile_store" => {
280241
let tp_ty = substs.type_at(0);
281-
warn_if_size_is_weird(bcx, tp_ty, C_uint(ccx,1usize), span, name);
282242
if type_is_fat_ptr(bcx.ccx, tp_ty) {
283243
bcx.volatile_store(llargs[1], get_dataptr(bcx, llargs[0]));
284244
bcx.volatile_store(llargs[2], get_meta(bcx, llargs[0]));

src/test/ui/issue-39827.rs renamed to src/test/run-pass/issue-39827.rs

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ use std::intrinsics::{ volatile_copy_memory, volatile_store, volatile_load,
1313
volatile_copy_nonoverlapping_memory,
1414
volatile_set_memory };
1515

16+
//
17+
// This test ensures that volatile intrinsics can be specialised with
18+
// zero-sized types and, in case of copy/set functions, can accept
19+
// number of elements equal to zero.
20+
//
1621
fn main () {
1722
let mut dst_pair = (1, 2);
1823
let src_pair = (3, 4);

src/test/ui/issue-39827.stderr

-73
This file was deleted.

0 commit comments

Comments
 (0)