1// Test that thread local data is handled correctly after forking without exec().
2// RUN: %clangxx_lsan %s -o %t
3// RUN: %run %t 2>&1
4
5#include <assert.h>
6#include <stdio.h>
7#include <stdlib.h>
8#include <sys/wait.h>
9#include <unistd.h>
10
11__thread void *thread_local_var;
12
13int main() {
14 int status = 0;
15 thread_local_var = malloc(size: 1337);
16 pid_t pid = fork();
17 assert(pid >= 0);
18 if (pid > 0) {
19 waitpid(pid: pid, stat_loc: &status, options: 0);
20 assert(WIFEXITED(status));
21 return WEXITSTATUS(status);
22 }
23 return 0;
24}
25

source code of compiler-rt/test/lsan/TestCases/Linux/fork.cpp