summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/Support/ManagedStatic.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/unittests/Support/ManagedStatic.cpp')
-rw-r--r--llvm/unittests/Support/ManagedStatic.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/llvm/unittests/Support/ManagedStatic.cpp b/llvm/unittests/Support/ManagedStatic.cpp
index 153884ba429..9c84ce8cb51 100644
--- a/llvm/unittests/Support/ManagedStatic.cpp
+++ b/llvm/unittests/Support/ManagedStatic.cpp
@@ -57,4 +57,46 @@ TEST(Initialize, MultipleThreads) {
}
#endif
+namespace NestedStatics {
+static ManagedStatic<int> Ms1;
+struct Nest {
+ Nest() {
+ ++(*Ms1);
+ }
+
+ ~Nest() {
+ assert(Ms1.isConstructed());
+ ++(*Ms1);
+ }
+};
+static ManagedStatic<Nest> Ms2;
+
+TEST(ManagedStaticTest, NestedStatics) {
+ EXPECT_FALSE(Ms1.isConstructed());
+ EXPECT_FALSE(Ms2.isConstructed());
+
+ *Ms2;
+ EXPECT_TRUE(Ms1.isConstructed());
+ EXPECT_TRUE(Ms2.isConstructed());
+
+ llvm_shutdown();
+ EXPECT_FALSE(Ms1.isConstructed());
+ EXPECT_FALSE(Ms2.isConstructed());
+}
+} // namespace NestedStatics
+
+namespace CustomCreatorDeletor {
+static void *CustomCreate() {
+ void *Mem = std::malloc(sizeof(int));
+ *((int *)Mem) = 42;
+ return Mem;
+}
+static ManagedStatic<int, CustomCreate, std::free> Custom;
+TEST(ManagedStaticTest, CustomCreatorDeletor) {
+ EXPECT_EQ(42, *Custom);
+ llvm_shutdown();
+ EXPECT_FALSE(Custom.isConstructed());
+}
+} // namespace CustomCreatorDeletor
+
} // anonymous namespace
OpenPOWER on IntegriCloud