本文整理汇总了C++中llvm::APSInt::getSExtValue方法的典型用法代码示例。如果您正苦于以下问题:C++ APSInt::getSExtValue方法的具体用法?C++ APSInt::getSExtValue怎么用?C++ APSInt::getSExtValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类llvm::APSInt
的用法示例。
在下文中一共展示了APSInt::getSExtValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: extractor
DWARFExpression lldb_private::npdb::MakeConstantLocationExpression(
TypeIndex underlying_ti, TpiStream &tpi, const llvm::APSInt &constant,
ModuleSP module) {
const ArchSpec &architecture = module->GetArchitecture();
uint32_t address_size = architecture.GetAddressByteSize();
size_t size = 0;
bool is_signed = false;
std::tie(size, is_signed) = GetIntegralTypeInfo(underlying_ti, tpi);
union {
llvm::support::little64_t I;
llvm::support::ulittle64_t U;
} Value;
std::shared_ptr<DataBufferHeap> buffer = std::make_shared<DataBufferHeap>();
buffer->SetByteSize(size);
llvm::ArrayRef<uint8_t> bytes;
if (is_signed) {
Value.I = constant.getSExtValue();
} else {
Value.U = constant.getZExtValue();
}
bytes = llvm::makeArrayRef(reinterpret_cast<const uint8_t *>(&Value), 8)
.take_front(size);
buffer->CopyData(bytes.data(), size);
DataExtractor extractor(buffer, lldb::eByteOrderLittle, address_size);
DWARFExpression result(nullptr, extractor, nullptr, 0, size);
return result;
}
示例2: checkRange
bool LiteralAnalyser::checkRange(QualType TLeft, const Expr* Right, clang::SourceLocation Loc, llvm::APSInt Result) {
// TODO refactor with check()
const QualType QT = TLeft.getCanonicalType();
int availableWidth = 0;
if (QT.isBuiltinType()) {
const BuiltinType* TL = cast<BuiltinType>(QT);
if (!TL->isInteger()) {
// TODO floats
return false;
}
availableWidth = TL->getIntegerWidth();
} else {
QT.dump();
assert(0 && "todo");
}
const Limit* L = getLimit(availableWidth);
assert(Result.isSigned() && "TEMP FOR NOW");
int64_t value = Result.getSExtValue();
bool overflow = false;
if (Result.isNegative()) {
const int64_t limit = L->minVal;
if (value < limit) overflow = true;
} else {
const int64_t limit = (int64_t)L->maxVal;
if (value > limit) overflow = true;
}
//fprintf(stderr, "VAL=%lld width=%d signed=%d\n", value, availableWidth, Result.isSigned());
if (overflow) {
SmallString<20> ss;
Result.toString(ss, 10, true);
StringBuilder buf1;
TLeft->DiagName(buf1);
if (Right) {
Diags.Report(Right->getLocStart(), diag::err_literal_outofbounds)
<< buf1 << L->minStr << L->maxStr << ss << Right->getSourceRange();
} else {
Diags.Report(Loc, diag::err_literal_outofbounds)
<< buf1 << L->minStr << L->maxStr << ss;
}
return false;
}
return true;
}