Skip to content

Commit b133d67

Browse files
committed
make it even more conservative, and note some FIXMEs
1 parent df6a3a0 commit b133d67

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

src/librustc_codegen_ssa/mir/block.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
526526
#[derive(Debug, PartialEq)]
527527
enum PanicIntrinsic { IfUninhabited, IfZeroInvalid, IfAnyInvalid };
528528
let panic_intrinsic = intrinsic.and_then(|i| match i {
529+
// FIXME: Move to symbols instead of strings.
529530
"panic_if_uninhabited" => Some(PanicIntrinsic::IfUninhabited),
530531
"panic_if_zero_invalid" => Some(PanicIntrinsic::IfZeroInvalid),
531532
"panic_if_any_invalid" => Some(PanicIntrinsic::IfAnyInvalid),
@@ -555,6 +556,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
555556
let location = self.get_caller_location(&mut bx, span).immediate();
556557

557558
// Obtain the panic entry point.
559+
// FIXME: dedup this with `codegen_assert_terminator` above.
558560
let def_id =
559561
common::langcall(bx.tcx(), Some(span), "", lang_items::PanicFnLangItem);
560562
let instance = ty::Instance::mono(bx.tcx(), def_id);

src/librustc_target/abi/mod.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,10 @@ impl<'a, Ty> TyLayout<'a, Ty> {
10431043
/// `zero` indicates if the memory is zero-initialized, or alternatively
10441044
/// left entirely uninitialized.
10451045
/// This is conservative: in doubt, it will answer `true`.
1046+
///
1047+
/// FIXME: Once we removed all the conservatism, we could alternatively
1048+
/// create an all-0/all-undef constant and run the vonst value validator to see if
1049+
/// this is a valid value for the given type.
10461050
pub fn might_permit_raw_init<C, E>(
10471051
self,
10481052
cx: &C,
@@ -1095,11 +1099,14 @@ impl<'a, Ty> TyLayout<'a, Ty> {
10951099
FieldPlacement::Array { .. } =>
10961100
// FIXME(#66151): The widely use smallvec 0.6 creates uninit arrays
10971101
// with any element type, so let us not (yet) complain about that.
1098-
// count == 0 ||
1099-
// self.field(cx, 0).to_result()?.might_permit_raw_init(cx, zero)?
1102+
/* count == 0 ||
1103+
self.field(cx, 0).to_result()?.might_permit_raw_init(cx, zero)? */
11001104
true,
1101-
FieldPlacement::Arbitrary { ref offsets, .. } => {
1102-
let mut res = true;
1105+
FieldPlacement::Arbitrary { .. } => {
1106+
// FIXME(#66151) cargo depends on sized-chunks 0.3.0 which
1107+
// has some illegal zero-initialization, so let us not (yet)
1108+
// complain about aggregates either.
1109+
/* let mut res = true;
11031110
// Check that all fields accept zero-init.
11041111
for idx in 0..offsets.len() {
11051112
let field = self.field(cx, idx).to_result()?;
@@ -1108,7 +1115,8 @@ impl<'a, Ty> TyLayout<'a, Ty> {
11081115
break;
11091116
}
11101117
}
1111-
res
1118+
res */
1119+
true
11121120
}
11131121
}
11141122
}

src/test/ui/intrinsics/panic-uninitialized-zeroed.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ fn main() {
9292
"attempted to zero-initialize type `*const dyn std::marker::Send`, which is invalid"
9393
);
9494

95+
/* FIXME(#66151) we conservatively do not error here yet.
9596
test_panic_msg(
9697
|| mem::uninitialized::<(NonNull<u32>, u32, u32)>(),
9798
"attempted to leave type `(std::ptr::NonNull<u32>, u32, u32)` uninitialized, \
@@ -102,6 +103,7 @@ fn main() {
102103
"attempted to zero-initialize type `(std::ptr::NonNull<u32>, u32, u32)`, \
103104
which is invalid"
104105
);
106+
*/
105107

106108
test_panic_msg(
107109
|| mem::uninitialized::<bool>(),

0 commit comments

Comments
 (0)