@@ -367,6 +367,18 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
367
367
// Destroying an uninit pthread_mutexattr is UB, so check to make sure it's not uninit.
368
368
mutexattr_get_kind ( this, attr_op) ?. check_init ( ) ?;
369
369
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
+
370
382
mutexattr_set_kind ( this, attr_op, ScalarMaybeUninit :: Uninit ) ?;
371
383
372
384
Ok ( 0 )
@@ -509,6 +521,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
509
521
mutex_get_kind ( this, mutex_op) ?. check_init ( ) ?;
510
522
mutex_get_id ( this, mutex_op) ?. check_init ( ) ?;
511
523
524
+ // This might lead to false positives, see comment in pthread_mutexattr_destroy
512
525
mutex_set_kind ( this, mutex_op, ScalarMaybeUninit :: Uninit ) ?;
513
526
mutex_set_id ( this, mutex_op, ScalarMaybeUninit :: Uninit ) ?;
514
527
// FIXME: delete interpreter state associated with this mutex.
@@ -613,6 +626,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
613
626
// Destroying an uninit pthread_rwlock is UB, so check to make sure it's not uninit.
614
627
rwlock_get_id ( this, rwlock_op) ?. check_init ( ) ?;
615
628
629
+ // This might lead to false positives, see comment in pthread_mutexattr_destroy
616
630
rwlock_set_id ( this, rwlock_op, ScalarMaybeUninit :: Uninit ) ?;
617
631
// FIXME: delete interpreter state associated with this rwlock.
618
632
@@ -670,6 +684,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
670
684
// Destroying an uninit pthread_condattr is UB, so check to make sure it's not uninit.
671
685
condattr_get_clock_id ( this, attr_op) ?. check_init ( ) ?;
672
686
687
+ // This might lead to false positives, see comment in pthread_mutexattr_destroy
673
688
condattr_set_clock_id ( this, attr_op, ScalarMaybeUninit :: Uninit ) ?;
674
689
675
690
Ok ( 0 )
@@ -812,6 +827,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
812
827
cond_get_id ( this, cond_op) ?. check_init ( ) ?;
813
828
cond_get_clock_id ( this, cond_op) ?. check_init ( ) ?;
814
829
830
+ // This might lead to false positives, see comment in pthread_mutexattr_destroy
815
831
cond_set_id ( this, cond_op, ScalarMaybeUninit :: Uninit ) ?;
816
832
cond_set_clock_id ( this, cond_op, ScalarMaybeUninit :: Uninit ) ?;
817
833
// FIXME: delete interpreter state associated with this condvar.
0 commit comments