llvm/llvm/unittests/Support/ManagedStatic.cpp

//===- llvm/unittest/Support/ManagedStatic.cpp - ManagedStatic tests ------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "llvm/Support/ManagedStatic.h"
#include "llvm/Config/config.h"
#include "llvm/Config/llvm-config.h" // for LLVM_ENABLE_THREADS
#include "llvm/Support/Allocator.h"
#include "gtest/gtest.h"
#ifdef HAVE_PTHREAD_H
#include <pthread.h>
#endif

#include "gtest/gtest.h"

usingnamespacellvm;

namespace {

#if LLVM_ENABLE_THREADS != 0 && defined(HAVE_PTHREAD_H) && \
  !__has_feature(memory_sanitizer)
namespace test1 {
  llvm::ManagedStatic<int> ms;
  void *helper(void*) {}

  // Valgrind's leak checker complains glibc's stack allocation.
  // To appease valgrind, we provide our own stack for each thread.
  void *allocate_stack(pthread_attr_t &a, size_t n = 65536) {}
}

TEST(Initialize, MultipleThreads) {}
#endif

namespace NestedStatics {
static ManagedStatic<int> Ms1;
struct Nest {};
static ManagedStatic<Nest> Ms2;

TEST(ManagedStaticTest, NestedStatics) {}
} // namespace NestedStatics

namespace CustomCreatorDeletor {
struct CustomCreate {};
struct CustomDelete {};
static ManagedStatic<int, CustomCreate, CustomDelete> Custom;
TEST(ManagedStaticTest, CustomCreatorDeletor) {}
} // namespace CustomCreatorDeletor

} // anonymous namespace