+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(¬e)
+ .emit();
+}
+