Skip to content

Commit 250d450

Browse files
committed
Add comment explaining false positives in _destroy
1 parent a4b2fc0 commit 250d450

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/shims/posix/sync.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,18 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
367367
// Destroying an uninit pthread_mutexattr is UB, so check to make sure it's not uninit.
368368
mutexattr_get_kind(this, attr_op)?.check_init()?;
369369

370+
// This is technically not right and might lead to false positives. For example, the below
371+
// code is *likely* sound, even assuming uninit numbers are UB, but miri with
372+
// -Zmiri-check-number-validity complains
373+
//
374+
// let mut x: MaybeUninit<libc::pthread_mutexattr_t> = MaybeUninit::zeroed();
375+
// libc::pthread_mutexattr_init(x.as_mut_ptr());
376+
// libc::pthread_mutexattr_destroy(x.as_mut_ptr());
377+
// x.assume_init();
378+
//
379+
// This can always be revisited to have some external state to catch double-destroys
380+
// but not complain about the above code. See https://github.com/rust-lang/miri/pull/1933
381+
370382
mutexattr_set_kind(this, attr_op, ScalarMaybeUninit::Uninit)?;
371383

372384
Ok(0)
@@ -509,6 +521,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
509521
mutex_get_kind(this, mutex_op)?.check_init()?;
510522
mutex_get_id(this, mutex_op)?.check_init()?;
511523

524+
// This might lead to false positives, see comment in pthread_mutexattr_destroy
512525
mutex_set_kind(this, mutex_op, ScalarMaybeUninit::Uninit)?;
513526
mutex_set_id(this, mutex_op, ScalarMaybeUninit::Uninit)?;
514527
// FIXME: delete interpreter state associated with this mutex.
@@ -613,6 +626,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
613626
// Destroying an uninit pthread_rwlock is UB, so check to make sure it's not uninit.
614627
rwlock_get_id(this, rwlock_op)?.check_init()?;
615628

629+
// This might lead to false positives, see comment in pthread_mutexattr_destroy
616630
rwlock_set_id(this, rwlock_op, ScalarMaybeUninit::Uninit)?;
617631
// FIXME: delete interpreter state associated with this rwlock.
618632

@@ -670,6 +684,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
670684
// Destroying an uninit pthread_condattr is UB, so check to make sure it's not uninit.
671685
condattr_get_clock_id(this, attr_op)?.check_init()?;
672686

687+
// This might lead to false positives, see comment in pthread_mutexattr_destroy
673688
condattr_set_clock_id(this, attr_op, ScalarMaybeUninit::Uninit)?;
674689

675690
Ok(0)
@@ -812,6 +827,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
812827
cond_get_id(this, cond_op)?.check_init()?;
813828
cond_get_clock_id(this, cond_op)?.check_init()?;
814829

830+
// This might lead to false positives, see comment in pthread_mutexattr_destroy
815831
cond_set_id(this, cond_op, ScalarMaybeUninit::Uninit)?;
816832
cond_set_clock_id(this, cond_op, ScalarMaybeUninit::Uninit)?;
817833
// FIXME: delete interpreter state associated with this condvar.

0 commit comments

Comments
 (0)