Issue |
124808
|
Summary |
[libc][test] -Werror=maybe-uninitialized in high_precision_decimal_test.cpp
|
Labels |
build-problem,
libc
|
Assignees |
michaelrj-google
|
Reporter |
nickdesaulniers
|
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`.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs