1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-18 18:42:46 +02:00

[ADT] Fix itostr handling of min int64_t value

Summary:
UBSan buildbot caught an undefined behavior in itostr with INT64_MIN.
The negation cannot be represented in the promoted operand (long long).
Negation is well defined on unsigned value though so this commit does
the negation after the static cast.

Reviewers: jhenderson, chandlerc, lattner

Reviewed By: lattner

Subscribers: dexonsmith, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D82200
This commit is contained in:
Thomas Preud'homme 2020-06-19 16:08:34 +01:00
parent 57d74cd85f
commit b66c895a2d

View File

@ -245,7 +245,7 @@ inline std::string utostr(uint64_t X, bool isNeg = false) {
inline std::string itostr(int64_t X) {
if (X < 0)
return utostr(static_cast<uint64_t>(-X), true);
return utostr(-static_cast<uint64_t>(X), true);
else
return utostr(static_cast<uint64_t>(X));
}