diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2015-12-01 01:10:48 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2015-12-01 01:10:48 +0000 |
commit | 8c57950603ca9fdb7b0dfd285900f71d7a888e09 (patch) | |
tree | 3c5db5c2435310fe506ee3d134d95b896d7ecd78 /test | |
parent | b1960e2b9ca2bb87303795170d27f839ed966a54 (diff) | |
download | clang-8c57950603ca9fdb7b0dfd285900f71d7a888e09.tar.gz |
Fix use-after-free when a C++ thread_local variable gets replaced (because its
type changes when the initializer is attached). Don't hold onto the
GlobalVariable*; recompute it from the VarDecl* instead.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@254359 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r-- | test/CodeGenCXX/cxx11-thread-local.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/test/CodeGenCXX/cxx11-thread-local.cpp b/test/CodeGenCXX/cxx11-thread-local.cpp index b96b027bb8..e00a881a66 100644 --- a/test/CodeGenCXX/cxx11-thread-local.cpp +++ b/test/CodeGenCXX/cxx11-thread-local.cpp @@ -20,6 +20,18 @@ struct U { static thread_local int m; }; // DARWIN: @_ZN1U1mE = internal thread_local global i32 0 thread_local int U::m = f(); +namespace MismatchedInitType { + // Check that we don't crash here when we're forced to create a new global + // variable (with a different type) when we add the initializer. + union U { + int a; + float f; + constexpr U() : f(0.0) {} + }; + static thread_local U u; + void *p = &u; +} + template<typename T> struct V { static thread_local int m; }; template<typename T> thread_local int V<T>::m = g(); |