From dad95474cbf48ad02c768a2a42a2c55150bad67f Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 30 May 2017 10:41:22 -0700 Subject: [PATCH] test thread-local key with no dtor --- src/terminator/mod.rs | 1 - tests/run-pass/thread-local-no-dtor.rs | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 tests/run-pass/thread-local-no-dtor.rs diff --git a/src/terminator/mod.rs b/src/terminator/mod.rs index 799c30f0d4e3..81927ba32996 100644 --- a/src/terminator/mod.rs +++ b/src/terminator/mod.rs @@ -727,7 +727,6 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { // Extract the function type out of the signature (that seems easier than constructing it ourselves...) let dtor_ptr = args[1].read_ptr(&self.memory)?; - // TODO: The null-pointer case here is entirely untested let dtor = if dtor_ptr.is_null_ptr() { None } else { Some(self.memory.get_fn(dtor_ptr.alloc_id)?) }; // Figure out how large a pthread TLS key actually is. This is libc::pthread_key_t. diff --git a/tests/run-pass/thread-local-no-dtor.rs b/tests/run-pass/thread-local-no-dtor.rs new file mode 100644 index 000000000000..8c69be8e2cd7 --- /dev/null +++ b/tests/run-pass/thread-local-no-dtor.rs @@ -0,0 +1,16 @@ +#![feature(libc)] +extern crate libc; + +use std::mem; + +pub type Key = libc::pthread_key_t; + +pub unsafe fn create(dtor: Option) -> Key { + let mut key = 0; + assert_eq!(libc::pthread_key_create(&mut key, mem::transmute(dtor)), 0); + key +} + +fn main() { + let _ = unsafe { create(None) }; +}