<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/60714>60714</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [libc++] uninitialized values in experimental unit tests
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          bregma
      </td>
    </tr>
</table>

<pre>
    Running the following command
```
llvm-lit -sv libcxx/test/libcxx/experimental/memory/memory.resource.adaptor/memory.resource.adaptor.mem/db_deallocate.pass.cpp --param=std=c++17 --param=enable_warning=True
```
using a compiler with static analysis and -Werror fails the test due to the use of uninitialized variables.
```
In file included from libcxx/test/support/test_memory_resource.h:22,
                 from libcxx/test/libcxx/experimental/memory/memory.resource.adaptor/memory.resource.adaptor.mem/db_deallocate.pass.cpp:25:
In member function 'void AllocController::countDealloc(void*, size_t, size_t)',
    inlined from 'void NullAllocator<T>::deallocate(T*, size_t) [with T = std::__1::aligned_storage<16, 16>::type]' at libcxx/test/support/controlled_allocators.h:478:24,
    inlined from 'void std::experimental::fundamentals_v1::pmr::__resource_adaptor_imp<_CharAlloc>::do_deallocate(void*, size_t, size_t) [with _CharAlloc = NullAllocator<char>]' at build/nto-x86_64-a/include/c++/v1/experimental/memory_resource:401:28,
 inlined from 'void std::experimental::fundamentals_v1::pmr::memory_resource::deallocate(void*, size_t, size_t)' at build/nto-x86_64-a/include/c++/v1/experimental/memory_resource:112:24,
 inlined from 'int main(int, char**)' at libcxx/test/libcxx/experimental/memory/memory.resource.adaptor/memory.resource.adaptor.mem/db_deallocate.pass.cpp:42:18:
libcxx/test/support/controlled_allocators.h:111:9: error: 'P.AllocController::alive_size' is used uninitialized [-Werror=uninitialized]
  111 |         alive_size -= s;
      | ^~~~~~~~~~
libcxx/test/libcxx/experimental/memory/memory.resource.adaptor/memory.resource.adaptor.mem/db_deallocate.pass.cpp: In function 'int main(int, char**)':
libcxx/test/libcxx/experimental/memory/memory.resource.adaptor/memory.resource.adaptor.mem/db_deallocate.pass.cpp:35:21: note: 'P' declared here
   35 |     AllocController P;
      | ^
In member function 'void AllocController::countDealloc(void*, size_t, size_t)',
    inlined from 'void NullAllocator<T>::deallocate(T*, size_t) [with T = std::__1::aligned_storage<16, 16>::type]' at libcxx/test/support/controlled_allocators.h:478:24,
    inlined from 'void std::experimental::fundamentals_v1::pmr::__resource_adaptor_imp<_CharAlloc>::do_deallocate(void*, size_t, size_t) [with _CharAlloc = NullAllocator<char>]' at build/nto-x86_64-a/include/c++/v1/experimental/memory_resource:401:28,
 inlined from 'void std::experimental::fundamentals_v1::pmr::memory_resource::deallocate(void*, size_t, size_t)' at build/nto-x86_64-a/include/c++/v1/experimental/memory_resource:112:24,
 inlined from 'int main(int, char**)' at ibcxx/test/libcxx/experimental/memory/memory.resource.adaptor/memory.resource.adaptor.mem/db_deallocate.pass.cpp:42:18:
libcxx/test/support/controlled_allocators.h:112:9: error: 'P.AllocController::deallocated_size' is used uninitialized [-Werror=uninitialized]
  112 |         deallocated_size += s;
      | ^~~~~~~~~~~~~~~~
libcxx/test/libcxx/experimental/memory/memory.resource.adaptor/memory.resource.adaptor.mem/db_deallocate.pass.cpp: In function 'int main(int, char**)':
libcxx/test/libcxx/experimental/memory/memory.resource.adaptor/memory.resource.adaptor.mem/db_deallocate.pass.cpp:35:21: note: 'P' declared here
   35 |     AllocController P;
      | ^
At global scope:

cc: unlinking /tmp/fileiwsD3T_qcc_3316798/db_deallocate.pass.o
cc: removing /tmp/fileiwsD3T_qcc_3316798

error: command failed with exit status: 1

--

********************
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90.. 
********************
Failed Tests (1):
 libc++ :: libcxx/experimental/memory/memory.resource.adaptor/memory.resource.adaptor.mem/db_deallocate.pass.cpp


Testing Time: 0.93s
  Failed: 1

```
The failure can be fixed with the following patch.
```
diff --git a/libcxx/test/support/controlled_allocators.h b/libcxx/test/support/controlled_allocators.h
index b00f7fdc4..dcc861581 100644
--- a/libcxx/test/support/controlled_allocators.h
+++ b/libcxx/test/support/controlled_allocators.h
@@ -64,9 +64,9 @@ struct AllocController {
     int dealloc_count = 0;
     int is_equal_count = 0;
 
-    std::size_t alive_size;
-    std::size_t allocated_size;
-    std::size_t deallocated_size;
+    std::size_t alive_size = 0;
+    std::size_t allocated_size = 0;
+    std::size_t deallocated_size = 0;
 
     std::size_t last_size = 0;
 std::size_t last_align = 0;
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWE9v47YT_TT0hZAgkZJlH3xw7DXwu_ywKAz0KFAUZbOlRC1JOcke-tmLoSz5T5xsmqZZtEhgMJI1JGfeG76xhlkrd40QC5TeoXQ9YZ3ba7MojNjVbFLo8nHxS9c0stlhtxe40krpe7jjuq5ZU6JojaIlmkbHj79V6lAHSjoc2ANWsuAPD4hsnLAOkc14Lx5aYWQtGscUIpta1No8jhehEVZ3houQlax12jz_JKxFjcimLPJSMKU0Z06ELbM25G2Lg6BlhtWIrq0rEV1zRO4QuYuzsyeiYYUS-T0zECmi663pxM3QOgvBMwi_lUoYfC_dHlvHnOSYNUw9Wmkxa0oc_CqM0QZXTCrrwQMAcNkJ7LS_76zAusJdIxvpJFPyuyjxgRkJztjw5v7_a3AllcCy4aorRYkro-snGNuubbVxxy_yHrd8xG2P6JIQRFb9mvj67-aaH8wbuJgiuhzDrkVdCIOrruFO6gYjkh20LPESZq5044xWShiYQpdcd41b96siMgNDRJaIrLCV30Xuzq_miGQXWMhGyWaAdtjm_51Sy95JbRBdbRH90u91ch6R2fZqmzlG6Z3PkS1GdI19DsKsPI_7C6bgAJa5ddqwnUB0FU9hhXg67uAeW4HSNSIZZu4FsvmAQpmzwVXr2U6yGQCa_DjO0cELmv03VdeUrP_C5oej-21thoAGfvMjv7msW0RX-WrPjIfuBJnOL1B7mZ8RwtNKHstrSvieGdhiRKropCoR2TROBw-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