Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libc / test / integration / startup / linux / tls_test.cpp
blob5f235a96006d6515319d139f1502678a6026faef
1 //===-- Loader test to check if tls size is read correctly ----------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "src/errno/libc_errno.h"
10 #include "src/sys/mman/mmap.h"
11 #include "test/IntegrationTest/test.h"
13 #include <errno.h>
14 #include <sys/mman.h>
16 constexpr int threadLocalDataSize = 101;
17 _Thread_local int a[threadLocalDataSize] = {123};
19 TEST_MAIN(int argc, char **argv, char **envp) {
20 ASSERT_TRUE(a[0] == 123);
22 for (int i = 1; i < threadLocalDataSize; ++i)
23 a[i] = i;
24 for (int i = 1; i < threadLocalDataSize; ++i)
25 ASSERT_TRUE(a[i] == i);
27 // Call mmap with bad params so that an error value is
28 // set in errno. Since errno is implemented using a thread
29 // local var, this helps us test setting of errno and
30 // reading it back.
31 ASSERT_TRUE(libc_errno == 0);
32 void *addr = LIBC_NAMESPACE::mmap(nullptr, 0, PROT_READ,
33 MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
34 ASSERT_TRUE(addr == MAP_FAILED);
35 ASSERT_TRUE(libc_errno == EINVAL);
37 return 0;