From fabf8bfdeadfa6f95bc3f1851425b3ef5967f254 Mon Sep 17 00:00:00 2001 From: Hans Wennborg Date: Thu, 19 Dec 2013 20:32:44 +0000 Subject: Make sys::ThreadLocal<> zero-initialized on non-thread builds (PR18205) According to the docs, ThreadLocal<>::get() should return NULL if no object has been set. This patch makes that the case also for non-thread builds and adds a very basic unit test to check it. (This was causing PR18205 because PrettyStackTraceHead didn't get zero- initialized and we'd crash trying to read past the end of that list. We didn't notice this so much on Linux since we'd crash after printing all the entries, but on Mac we print into a SmallString, and would crash before printing that.) llvm-svn: 197718 --- llvm/lib/Support/ThreadLocal.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'llvm/lib/Support/ThreadLocal.cpp') diff --git a/llvm/lib/Support/ThreadLocal.cpp b/llvm/lib/Support/ThreadLocal.cpp index 0587aaec7e6..868b6ea566a 100644 --- a/llvm/lib/Support/ThreadLocal.cpp +++ b/llvm/lib/Support/ThreadLocal.cpp @@ -23,7 +23,7 @@ // Define all methods as no-ops if threading is explicitly disabled namespace llvm { using namespace sys; -ThreadLocalImpl::ThreadLocalImpl() { } +ThreadLocalImpl::ThreadLocalImpl() : data() { } ThreadLocalImpl::~ThreadLocalImpl() { } void ThreadLocalImpl::setInstance(const void* d) { typedef int SIZE_TOO_BIG[sizeof(d) <= sizeof(data) ? 1 : -1]; -- cgit v1.2.3