<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/124808>124808</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[libc][test] -Werror=maybe-uninitialized in high_precision_decimal_test.cpp
</td>
</tr>
<tr>
<th>Labels</th>
<td>
build-problem,
libc
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
michaelrj-google
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
nickdesaulniers
</td>
</tr>
</table>
<pre>
The unit tests fail with gcc-14:
```
In file included from /android0/llvm-project/libc/test/src/__support/high_precision_decimal_test.cpp:9:
In member function ‘bool __llvm_libc_20_0_0_git::internal::HighPrecisionDecimal::should_round_up(int32_t, __llvm_libc_20_0_0_git::internal::RoundDirection)’,
inlined from ‘T __llvm_libc_20_0_0_git::internal::HighPrecisionDecimal::round_to_integer_type(__llvm_libc_20_0_0_git::internal::RoundDirection) [with T = long unsigned int]’ at /android0/llvm-project/libc/src/__support/high_precision_decimal.h:428:46,
inlined from ‘virtual void LlvmLibcHighPrecisionDecimalTest_NumLenDigitsTest::Run()’ at /android0/llvm-project/libc/test/src/__support/high_precision_decimal_test.cpp:435:3:
/android0/llvm-project/libc/src/__support/high_precision_decimal.h:150:36: error: ‘longer_hpd’ may be used uninitialized [-Werror=maybe-uninitialized]
150 | if (this->digits[round_to_digit] == 5 &&
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~^
/android0/llvm-project/libc/test/src/__support/high_precision_decimal_test.cpp: In member function ‘virtual void LlvmLibcHighPrecisionDecimalTest_NumLenDigitsTest::Run()’:
/android0/llvm-project/libc/test/src/__support/high_precision_decimal_test.cpp:431:50: note: ‘longer_hpd’ declared here
431 | LIBC_NAMESPACE::internal::HighPrecisionDecimal longer_hpd =
| ^~~~~~~~~~
```
In this case, I think GCC is correct. The constructor for `HighPrecisionDecimal` doesn't guarantee that its `digits` member is fully initialized, so constructing an object then calling `round_to_integer_type` may end up reading uninitialized memory (UB). I think the constructor of `HighPrecisionDecimal` should unconditionally initialize `digits`.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy0Vs1u4zYXfZrrzYUNibJkaeGF_Pd9AdLBoE3RpUCRlMQZijT4k8Jd9NkLyo4z6aSJi0xpwTBpkZfnnnMuSZ2TvRZiDfkGCBklG6hQ9su8N6ZXAgiBfDejwQ_GrrVkX7lwNCgthXWz1vDT-mEQGLT06IXzDjsqFf4u_YA9Y_N0CVkNSQ1FcnmS-k5jJ5VAqZkKXHDsrBkRyIFqbo3kCZCDUo_j_GjNF8F87MqWATnECEAOzsZO07hwPBobRwbZD83RCiadNLrhgsmRqia-v2DHI2R1dd7HncZRjK2w2AXNvDQaYU-gTKAqW2MUNk0M3cSADUma-Omlj5OzWmovrKbq3Pu_7IfPTyF354jnf9xgguKNNUHzJhyBlFL7jDQeyPZfBPg5zt9JK6Z9AqmedloB2UJSIyJKraS-pvAJycMPgXHevzdNnNAL2_jTUQApP4AAId9M2nhAyHaojO4x6EmBHKX2kO-uIJH6m0RxqxoWA2T1kpTxu3gvg4_S-kAVPhrJ8V49jveyZa-l6kE433wK473QO9lL7-LABX3QQMpvebsV0gd0vsxyyOrs4rofnb40T-LqBWQ1CmuNjT-uSYt0CtsMR_6MeKQnbAUGJ3isElp6SZX8Q_Aohflvl0V2Iz21Yv7ihaiFSFGaJwirLU5kdQik9IN0c8j2fEo45JurUqcRyHdRXVFgOQIp4nPmGq8LxfbnPzfI9zem7wNU4VvF6L8R4O2y-JAEU8jqSSmojRfvaoQLpqgVHAdhxUTVMksvVN3fbbbNp_qn_S-f6-3-1gKGz2EmKbxG_80N8v2zML47yqIYkVEnYnG_i139Ff-33WIcNjbWvgViPCSZ0c7bwLyx2BmLUCSvFt8iQW6E00BWHvtALdVeCPQD9Si9i_Muyi-SJwFJh11Q6oTfGohs0ZnnsFL3SDWaNjKNfhAaGVUqDkORvF7tYwR6QqE5hiNaQbmcSva3Rh7FaOwpGvPXDZBqgdc0-L-h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