ExprEngine: Sign extension in truncateValue

This commit is contained in:
Daniel Marjamäki 2019-09-24 20:31:12 +02:00
parent 0471e74489
commit 7cf8327b31
1 changed files with 3 additions and 2 deletions

View File

@ -508,11 +508,12 @@ static ExprEngine::ValuePtr truncateValue(ExprEngine::ValuePtr val, const ValueT
return val; return val;
if (auto range = std::dynamic_pointer_cast<ExprEngine::IntRange>(val)) { if (auto range = std::dynamic_pointer_cast<ExprEngine::IntRange>(val)) {
if (range->minValue == range->maxValue) { if (range->minValue == range->maxValue) {
int128_t newValue = range->minValue; int128_t newValue = range->minValue;
newValue = newValue & (((int128_t)1 << bits) - 1); newValue = newValue & (((int128_t)1 << bits) - 1);
// TODO: Sign extension // Sign extension
if (valueType->sign == ValueType::Sign::SIGNED && newValue & (1ULL << (bits - 1)))
newValue |= ~(((int128_t)1 << bits) - 1);
if (newValue == range->minValue) if (newValue == range->minValue)
return val; return val;
return std::make_shared<ExprEngine::IntRange>(ExprEngine::str(newValue), newValue, newValue); return std::make_shared<ExprEngine::IntRange>(ExprEngine::str(newValue), newValue, newValue);