if (const auto *LitFloat = llvm::dyn_cast<FloatingLiteral>(&Node))
// Attempt to simplify a `Duration` factory call with a literal argument.
if (llvm::Optional<llvm::APSInt> IntValue = truncateIfIntegral(*LitFloat))
- return IntValue->toString(/*radix=*/10);
+ return toString(*IntValue, /*radix=*/10);
return llvm::None;
}
if (Index->isSigned() && Index->isNegative()) {
diag(Matched->getExprLoc(), "std::array<> index %0 is negative")
- << Index->toString(10);
+ << toString(*Index, 10);
return;
}
diag(Matched->getExprLoc(),
"std::array<> index %0 is past the end of the array "
"(which contains %1 elements)")
- << Index->toString(10) << ArraySize.toString(10, false);
+ << toString(*Index, 10) << toString(ArraySize, 10, false);
}
}
}
std::string getDetail(const TemplateArgumentLoc &TAL) {
if (TAL.getArgument().getKind() == TemplateArgument::Integral)
- return TAL.getArgument().getAsIntegral().toString(10);
+ return toString(TAL.getArgument().getAsIntegral(), 10);
return "";
}
std::string getDetail(const TemplateName &TN) {
} else if (const auto *ECD = dyn_cast<EnumConstantDecl>(D)) {
// Dependent enums (e.g. nested in template classes) don't have values yet.
if (!ECD->getType()->isDependentType())
- HI.Value = ECD->getInitVal().toString(10);
+ HI.Value = toString(ECD->getInitVal(), 10);
}
HI.Definition = printDefinition(D, PP);
std::string, Value) {
if (Node.getKind() != TemplateArgument::Integral)
return false;
- return Node.getAsIntegral().toString(10) == Value;
+ return toString(Node.getAsIntegral(), 10) == Value;
}
/// Matches an Objective-C autorelease pool statement.
#include "clang/AST/ExprCXX.h"
#include "clang/AST/TemplateBase.h"
#include "clang/AST/Type.h"
+#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/raw_ostream.h"
using namespace clang;
if (FromIntType->isBooleanType()) {
OS << ((FromInt == 0) ? "false" : "true");
} else {
- OS << FromInt.toString(10);
+ OS << toString(FromInt, 10);
}
return;
}
if (IntType->isBooleanType()) {
OS << ((Val == 0) ? "false" : "true");
} else {
- OS << Val.toString(10);
+ OS << toString(Val, 10);
}
} else if (E) {
PrintExpr(E);
#include "llvm/ADT/APSInt.h"
#include "llvm/ADT/None.h"
#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/ErrorHandling.h"
diag::err_odr_tag_type_inconsistent))
<< Context.ToCtx.getTypeDeclType(D2);
Context.Diag1(EC1->getLocation(), diag::note_odr_enumerator)
- << EC1->getDeclName() << EC1->getInitVal().toString(10);
+ << EC1->getDeclName() << toString(EC1->getInitVal(), 10);
Context.Diag2(D2->getLocation(), diag::note_odr_missing_enumerator);
}
return false;
diag::err_odr_tag_type_inconsistent))
<< Context.ToCtx.getTypeDeclType(D2);
Context.Diag2(EC2->getLocation(), diag::note_odr_enumerator)
- << EC2->getDeclName() << EC2->getInitVal().toString(10);
+ << EC2->getDeclName() << toString(EC2->getInitVal(), 10);
Context.Diag1(EC1->getLocation(), diag::note_odr_enumerator)
- << EC1->getDeclName() << EC1->getInitVal().toString(10);
+ << EC1->getDeclName() << toString(EC1->getInitVal(), 10);
}
return false;
}
diag::err_odr_tag_type_inconsistent))
<< Context.ToCtx.getTypeDeclType(D2);
Context.Diag2(EC2->getLocation(), diag::note_odr_enumerator)
- << EC2->getDeclName() << EC2->getInitVal().toString(10);
+ << EC2->getDeclName() << toString(EC2->getInitVal(), 10);
Context.Diag1(D1->getLocation(), diag::note_odr_missing_enumerator);
}
return false;
if (Info.checkingForUndefinedBehavior())
Info.Ctx.getDiagnostics().Report(E->getExprLoc(),
diag::warn_integer_constant_overflow)
- << Result.toString(10) << E->getType();
+ << toString(Result, 10) << E->getType();
return HandleOverflow(Info, E, Value, E->getType());
}
return true;
llvm::NoneType unrepresentableValue(QualType Ty, const APSInt &Val) {
Info.FFDiag(BCE->getBeginLoc(),
diag::note_constexpr_bit_cast_unrepresentable_value)
- << Ty << Val.toString(/*Radix=*/10);
+ << Ty << toString(Val, /*Radix=*/10);
return None;
}
llvm::APInt::udivrem(OrigN, TSize, N, Remainder);
if (Remainder) {
Info.FFDiag(E, diag::note_constexpr_memcpy_unsupported)
- << Move << WChar << 0 << T << OrigN.toString(10, /*Signed*/false)
+ << Move << WChar << 0 << T << toString(OrigN, 10, /*Signed*/false)
<< (unsigned)TSize;
return false;
}
if (N.ugt(RemainingSrcSize) || N.ugt(RemainingDestSize)) {
Info.FFDiag(E, diag::note_constexpr_memcpy_unsupported)
<< Move << WChar << (N.ugt(RemainingSrcSize) ? 1 : 2) << T
- << N.toString(10, /*Signed*/false);
+ << toString(N, 10, /*Signed*/false);
return false;
}
uint64_t NElems = N.getZExtValue();
return ZeroInitialization(E);
Info.FFDiag(*ArraySize, diag::note_constexpr_new_too_small)
- << AllocBound.toString(10, /*Signed=*/false)
- << InitBound.toString(10, /*Signed=*/false)
+ << toString(AllocBound, 10, /*Signed=*/false)
+ << toString(InitBound, 10, /*Signed=*/false)
<< (*ArraySize)->getSourceRange();
return false;
}
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Compiler.h"
if (Policy.ConstantsAsWritten && printExprAsWritten(OS, Node, Context))
return;
bool isSigned = Node->getType()->isSignedIntegerType();
- OS << Node->getValue().toString(10, isSigned);
+ OS << toString(Node->getValue(), 10, isSigned);
// Emit suffixes. Integer literals are always a builtin integer type.
switch (Node->getType()->castAs<BuiltinType>()->getKind()) {
case UserDefinedLiteral::LOK_Integer: {
// Print integer literal without suffix.
const auto *Int = cast<IntegerLiteral>(Node->getCookedLiteral());
- OS << Int->getValue().toString(10, /*isSigned*/false);
+ OS << toString(Int->getValue(), 10, /*isSigned*/false);
break;
}
case UserDefinedLiteral::LOK_Floating: {
#include "llvm/ADT/FoldingSet.h"
#include "llvm/ADT/None.h"
#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Compiler.h"
return DB << "nullptr";
case TemplateArgument::Integral:
- return DB << Arg.getAsIntegral().toString(10);
+ return DB << toString(Arg.getAsIntegral(), 10);
case TemplateArgument::Template:
return DB << Arg.getAsTemplate();
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/Specifiers.h"
#include "clang/Basic/TypeTraits.h"
+#include "llvm/ADT/StringExtras.h"
#include <algorithm>
#include <utility>
void TextNodeDumper::VisitIntegerLiteral(const IntegerLiteral *Node) {
bool isSigned = Node->getType()->isSignedIntegerType();
ColorScope Color(OS, ShowColors, ValueColor);
- OS << " " << Node->getValue().toString(10, isSigned);
+ OS << " " << toString(Node->getValue(), 10, isSigned);
}
void TextNodeDumper::VisitFixedPointLiteral(const FixedPointLiteral *Node) {
#include "clang/Basic/LLVM.h"
#include "clang/Basic/OperatorKinds.h"
#include "clang/Basic/Specifiers.h"
+#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Casting.h"
#include <algorithm>
std::string threadSafety::getSourceLiteralString(const Expr *CE) {
switch (CE->getStmtClass()) {
case Stmt::IntegerLiteralClass:
- return cast<IntegerLiteral>(CE)->getValue().toString(10, true);
+ return toString(cast<IntegerLiteral>(CE)->getValue(), 10, true);
case Stmt::StringLiteralClass: {
std::string ret("\"");
ret += cast<StringLiteral>(CE)->getString();
llvm::APSInt Value = Result.Val.getInt();
LLVMContext &Context = CGM.getLLVMContext();
- std::string Reg = Value == 31 ? "sp" : "x" + Value.toString(10);
+ std::string Reg = Value == 31 ? "sp" : "x" + toString(Value, 10);
llvm::Metadata *Ops[] = {llvm::MDString::get(Context, Reg)};
llvm::MDNode *RegName = llvm::MDNode::get(Context, Ops);
// created with -funique-internal-linakge-symbols and the tools can strip or
// keep the prefix as needed.
ModuleNameHash = (Twine(".__uniq.") +
- Twine(IntHash.toString(/* Radix = */ 10, /* Signed = */false))).str();
+ Twine(toString(IntHash, /* Radix = */ 10, /* Signed = */false))).str();
}
}
if (!SanHash.empty())
code = hash_combine(code, SanHash.Mask);
- return llvm::APInt(64, code).toString(36, /*Signed=*/false);
+ return toString(llvm::APInt(64, code), 36, /*Signed=*/false);
}
void CompilerInvocation::generateCC1CommandLine(
MacroBuilder &Builder) {
llvm::APInt MaxVal = isSigned ? llvm::APInt::getSignedMaxValue(TypeWidth)
: llvm::APInt::getMaxValue(TypeWidth);
- Builder.defineMacro(MacroName, MaxVal.toString(10, isSigned) + ValSuffix);
+ Builder.defineMacro(MacroName, toString(MaxVal, 10, isSigned) + ValSuffix);
}
/// DefineTypeSize - An overloaded helper that uses TargetInfo to determine
Result += " {\n";
for (const auto *EC : ED->enumerators()) {
Result += "\t"; Result += EC->getName(); Result += " = ";
- llvm::APSInt Val = EC->getInitVal();
- Result += Val.toString(10);
+ Result += toString(EC->getInitVal(), 10);
Result += ",\n";
}
Result += "\t} ";
if (ValueLive && Res.isUnsigned()) {
if (!LHS.isUnsigned() && LHS.Val.isNegative())
PP.Diag(OpLoc, diag::warn_pp_convert_to_positive) << 0
- << LHS.Val.toString(10, true) + " to " +
- LHS.Val.toString(10, false)
+ << toString(LHS.Val, 10, true) + " to " +
+ toString(LHS.Val, 10, false)
<< LHS.getRange() << RHS.getRange();
if (!RHS.isUnsigned() && RHS.Val.isNegative())
PP.Diag(OpLoc, diag::warn_pp_convert_to_positive) << 1
- << RHS.Val.toString(10, true) + " to " +
- RHS.Val.toString(10, false)
+ << toString(RHS.Val, 10, true) + " to " +
+ toString(RHS.Val, 10, false)
<< LHS.getRange() << RHS.getRange();
}
LHS.Val.setIsUnsigned(Res.isUnsigned());
}
Self.Diag(OpRange.getBegin(),
diag::err_opencl_cast_non_zero_to_event_t)
- << CastInt.toString(10) << SrcExpr.get()->getSourceRange();
+ << toString(CastInt, 10) << SrcExpr.get()->getSourceRange();
SrcExpr = ExprError();
return;
}
}
if (llvm::APSInt::compareValues(AlignValue, MaxValue) > 0) {
S.Diag(AlignOp->getExprLoc(), diag::err_alignment_too_big)
- << MaxValue.toString(10);
+ << toString(MaxValue, 10);
return true;
}
if (!AlignValue.isPowerOf2()) {
DiagRuntimeBehavior(TheCall->getBeginLoc(), TheCall,
PDiag(DiagID)
- << FunctionName << ObjectSize.toString(/*Radix=*/10)
- << UsedSize.getValue().toString(/*Radix=*/10));
+ << FunctionName << toString(ObjectSize, /*Radix=*/10)
+ << toString(UsedSize.getValue(), /*Radix=*/10));
}
static bool SemaBuiltinSEHScopeCheck(Sema &SemaRef, CallExpr *TheCall,
if (Result.getSExtValue() < Low || Result.getSExtValue() > High) {
if (RangeIsError)
return Diag(TheCall->getBeginLoc(), diag::err_argument_invalid_range)
- << Result.toString(10) << Low << High << Arg->getSourceRange();
+ << toString(Result, 10) << Low << High << Arg->getSourceRange();
else
// Defer the warning until we know if the code will be emitted so that
// dead code can ignore this.
DiagRuntimeBehavior(TheCall->getBeginLoc(), TheCall,
PDiag(diag::warn_argument_invalid_range)
- << Result.toString(10) << Low << High
+ << toString(Result, 10) << Low << High
<< Arg->getSourceRange());
}
if (FieldWidth == 1 && Value == 1)
return false;
- std::string PrettyValue = Value.toString(10);
- std::string PrettyTrunc = TruncatedValue.toString(10);
+ std::string PrettyValue = toString(Value, 10);
+ std::string PrettyTrunc = toString(TruncatedValue, 10);
S.Diag(InitLoc, diag::warn_impcast_bitfield_precision_constant)
<< PrettyValue << PrettyTrunc << OriginalInit->getType()
llvm::APSInt ValueInRange = Value;
ValueInRange.setIsSigned(!Range.NonNegative);
ValueInRange = ValueInRange.trunc(Range.Width);
- return ValueInRange.toString(10);
+ return toString(ValueInRange, 10);
}
static bool IsImplicitBoolFloatConversion(Sema &S, Expr *Ex, bool ToBool) {
adornObjCBoolConversionDiagWithTernaryFixit(
S, E,
S.Diag(CC, diag::warn_impcast_constant_value_to_objc_bool)
- << Result.Val.getInt().toString(10));
+ << toString(Result.Val.getInt(), 10));
}
return;
}
if (Overflowed) {
S.DiagRuntimeBehavior(E->getExprLoc(), E,
S.PDiag(diag::warn_impcast_fixed_point_range)
- << Value.toString(/*Radix=*/10) << T
+ << toString(Value, /*Radix=*/10) << T
<< E->getSourceRange()
<< clang::SourceRange(CC));
return;
llvm::APFloat::rmNearestTiesToEven);
if (ConversionStatus != llvm::APFloat::opOK) {
- std::string PrettySourceValue = SourceInt->toString(10);
+ SmallString<32> PrettySourceValue;
+ SourceInt->toString(PrettySourceValue, 10);
SmallString<32> PrettyTargetValue;
TargetFloatValue.toString(PrettyTargetValue, TargetPrecision);
if (S.SourceMgr.isInSystemMacro(CC))
return;
- std::string PrettySourceValue = Value.toString(10);
+ std::string PrettySourceValue = toString(Value, 10);
std::string PrettyTargetValue = PrettyPrintInRange(Value, TargetRange);
S.DiagRuntimeBehavior(
!S.SourceMgr.isInSystemMacro(CC)) {
llvm::APSInt Value = Result.Val.getInt();
if (isSameWidthConstantConversion(S, E, T, CC)) {
- std::string PrettySourceValue = Value.toString(10);
+ std::string PrettySourceValue = toString(Value, 10);
std::string PrettyTargetValue = PrettyPrintInRange(Value, TargetRange);
S.DiagRuntimeBehavior(
DiagID = diag::warn_array_index_exceeds_bounds;
DiagRuntimeBehavior(BaseExpr->getBeginLoc(), BaseExpr,
- PDiag(DiagID) << index.toString(10, true)
- << size.toString(10, true)
+ PDiag(DiagID) << toString(index, 10, true)
+ << toString(size, 10, true)
<< (unsigned)size.getLimitedValue(~0U)
<< IndexExpr->getSourceRange());
} else {
}
DiagRuntimeBehavior(BaseExpr->getBeginLoc(), BaseExpr,
- PDiag(DiagID) << index.toString(10, true)
+ PDiag(DiagID) << toString(index, 10, true)
<< IndexExpr->getSourceRange());
}
#include "clang/Basic/OperatorPrecedence.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/PointerUnion.h"
+#include "llvm/ADT/StringExtras.h"
+
using namespace clang;
using namespace sema;
S.Diag(SubstExpr->getBeginLoc(),
diag::note_atomic_constraint_evaluated_to_false_elaborated)
<< (int)First << SubstExpr
- << SimplifiedLHS.Val.getInt().toString(10)
+ << toString(SimplifiedLHS.Val.getInt(), 10)
<< BinaryOperator::getOpcodeStr(BO->getOpcode())
- << SimplifiedRHS.Val.getInt().toString(10);
+ << toString(SimplifiedRHS.Val.getInt(), 10);
return;
}
}
if (SizeIsNegative)
Diag(Loc, diag::err_typecheck_negative_array_size);
else if (Oversized.getBoolValue())
- Diag(Loc, diag::err_array_too_large) << Oversized.toString(10);
+ Diag(Loc, diag::err_array_too_large) << toString(Oversized, 10);
else if (FailedFoldDiagID)
Diag(Loc, FailedFoldDiagID);
return false;
Diag(NewTD->getLocation(), diag::err_vla_decl_in_file_scope);
else if (Oversized.getBoolValue())
Diag(NewTD->getLocation(), diag::err_array_too_large)
- << Oversized.toString(10);
+ << toString(Oversized, 10);
else
Diag(NewTD->getLocation(), diag::err_vm_decl_in_file_scope);
NewTD->setInvalidDecl();
if (Value.isSigned() && Value.isNegative()) {
if (FieldName)
return Diag(FieldLoc, diag::err_bitfield_has_negative_width)
- << FieldName << Value.toString(10);
+ << FieldName << toString(Value, 10);
return Diag(FieldLoc, diag::err_anon_bitfield_has_negative_width)
- << Value.toString(10);
+ << toString(Value, 10);
}
// The size of the bit-field must not exceed our maximum permitted object
// size.
if (Value.getActiveBits() > ConstantArrayType::getMaxSizeBits(Context)) {
return Diag(FieldLoc, diag::err_bitfield_too_wide)
- << !FieldName << FieldName << Value.toString(10);
+ << !FieldName << FieldName << toString(Value, 10);
}
if (!FieldTy->isDependentType()) {
CStdConstraintViolation ? TypeWidth : TypeStorageSize;
if (FieldName)
return Diag(FieldLoc, diag::err_bitfield_width_exceeds_type_width)
- << FieldName << Value.toString(10)
+ << FieldName << toString(Value, 10)
<< !CStdConstraintViolation << DiagWidth;
return Diag(FieldLoc, diag::err_anon_bitfield_width_exceeds_type_width)
- << Value.toString(10) << !CStdConstraintViolation
+ << toString(Value, 10) << !CStdConstraintViolation
<< DiagWidth;
}
// 'bool'.
if (BitfieldIsOverwide && !FieldTy->isBooleanType() && FieldName) {
Diag(FieldLoc, diag::warn_bitfield_width_exceeds_type_width)
- << FieldName << Value.toString(10)
+ << FieldName << toString(Value, 10)
<< (unsigned)TypeWidth;
}
}
// Complain if the value is not representable in an int.
if (!isRepresentableIntegerValue(Context, EnumVal, Context.IntTy))
Diag(IdLoc, diag::ext_enum_value_not_int)
- << EnumVal.toString(10) << Val->getSourceRange()
+ << toString(EnumVal, 10) << Val->getSourceRange()
<< (EnumVal.isUnsigned() || EnumVal.isNonNegative());
else if (!Context.hasSameType(Val->getType(), Context.IntTy)) {
// Force the type of the expression to 'int'.
if (Enum->isFixed())
// When the underlying type is fixed, this is ill-formed.
Diag(IdLoc, diag::err_enumerator_wrapped)
- << EnumVal.toString(10)
+ << toString(EnumVal, 10)
<< EltTy;
else
Diag(IdLoc, diag::ext_enumerator_increment_too_large)
- << EnumVal.toString(10);
+ << toString(EnumVal, 10);
} else {
EltTy = T;
}
!isRepresentableIntegerValue(Context, EnumVal, EltTy)) {
// Enforce C99 6.7.2.2p2 even when we compute the next value.
Diag(IdLoc, diag::ext_enum_value_not_int)
- << EnumVal.toString(10) << 1;
+ << toString(EnumVal, 10) << 1;
}
}
}
// Emit warning for one enum constant.
auto *FirstECD = Vec->front();
S.Diag(FirstECD->getLocation(), diag::warn_duplicate_enum_values)
- << FirstECD << FirstECD->getInitVal().toString(10)
+ << FirstECD << toString(FirstECD->getInitVal(), 10)
<< FirstECD->getSourceRange();
// Emit one note for each of the remaining enum constants with
// the same value.
for (auto *ECD : llvm::make_range(Vec->begin() + 1, Vec->end()))
S.Diag(ECD->getLocation(), diag::note_duplicate_element)
- << ECD << ECD->getInitVal().toString(10)
+ << ECD << toString(ECD->getInitVal(), 10)
<< ECD->getSourceRange();
}
}
if (!I->isIntN(32)) {
S.Diag(Expr->getExprLoc(), diag::err_ice_too_large)
- << I->toString(10, false) << 32 << /* Unsigned */ 1;
+ << toString(*I, 10, false) << 32 << /* Unsigned */ 1;
return false;
}
llvm::APSInt I(32); // for toString
I = UVal;
S.Diag(Expr->getExprLoc(), diag::err_ice_too_large)
- << I.toString(10, false) << 32 << /* Unsigned */ 0;
+ << toString(I, 10, false) << 32 << /* Unsigned */ 0;
return false;
}
// Make sure we can fit it in 32 bits.
if (!I->isIntN(32)) {
S.Diag(E->getExprLoc(), diag::err_ice_too_large)
- << I->toString(10, false) << 32 << /* Unsigned */ 1;
+ << toString(*I, 10, false) << 32 << /* Unsigned */ 1;
return nullptr;
}
if (*I < 0)
if ((int64_t)Bindings.size() != NumElems) {
S.Diag(Src->getLocation(), diag::err_decomp_decl_wrong_number_bindings)
<< DecompType << (unsigned)Bindings.size()
- << (unsigned)NumElems.getLimitedValue(UINT_MAX) << NumElems.toString(10)
- << (NumElems < Bindings.size());
+ << (unsigned)NumElems.getLimitedValue(UINT_MAX)
+ << toString(NumElems, 10) << (NumElems < Bindings.size());
return true;
}
S.Diag(Src->getLocation(), diag::err_decomp_decl_wrong_number_bindings)
<< DecompType << (unsigned)Bindings.size()
<< (unsigned)TupleSize.getLimitedValue(UINT_MAX)
- << TupleSize.toString(10) << (TupleSize < Bindings.size());
+ << toString(TupleSize, 10) << (TupleSize < Bindings.size());
return true;
}
#include "clang/Sema/SemaInternal.h"
#include "clang/Sema/Template.h"
#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/ConvertUTF.h"
#include "llvm/Support/SaveAndRestore.h"
+
using namespace clang;
using namespace sema;
using llvm::RoundingMode;
bool ValueIsPositive = ValueAPS.isStrictlyPositive();
if (!ValueIsPositive || ValueAPS.getActiveBits() > 31) {
Diag(E->getExprLoc(), diag::err_pragma_loop_invalid_argument_value)
- << ValueAPS.toString(10) << ValueIsPositive;
+ << toString(ValueAPS, 10) << ValueIsPositive;
return true;
}
llvm::APSInt LengthValue = Result.Val.getInt();
if (LengthValue.isNegative()) {
Diag(Length->getExprLoc(), diag::err_omp_section_length_negative)
- << LengthValue.toString(/*Radix=*/10, /*Signed=*/true)
+ << toString(LengthValue, /*Radix=*/10, /*Signed=*/true)
<< Length->getSourceRange();
return ExprError();
}
llvm::APSInt StrideValue = Result.Val.getInt();
if (!StrideValue.isStrictlyPositive()) {
Diag(Stride->getExprLoc(), diag::err_omp_section_stride_non_positive)
- << StrideValue.toString(/*Radix=*/10, /*Signed=*/true)
+ << toString(StrideValue, /*Radix=*/10, /*Signed=*/true)
<< Stride->getSourceRange();
return ExprError();
}
llvm::APSInt Value = EvResult.Val.getInt();
if (!Value.isStrictlyPositive()) {
Diag(Dim->getExprLoc(), diag::err_omp_shaping_dimension_not_positive)
- << Value.toString(/*Radix=*/10, /*Signed=*/true)
+ << toString(Value, /*Radix=*/10, /*Signed=*/true)
<< Dim->getSourceRange();
ErrorFound = true;
continue;
RHSStrRef.find('\'') != StringRef::npos)
return;
- bool SuggestXor = S.getLangOpts().CPlusPlus || S.getPreprocessor().isMacroDefined("xor");
+ bool SuggestXor =
+ S.getLangOpts().CPlusPlus || S.getPreprocessor().isMacroDefined("xor");
const llvm::APInt XorValue = LeftSideValue ^ RightSideValue;
int64_t RightSideIntValue = RightSideValue.getSExtValue();
if (LeftSideValue == 2 && RightSideIntValue >= 0) {
if (Overflow) {
if (RightSideIntValue < 64)
S.Diag(Loc, diag::warn_xor_used_as_pow_base)
- << ExprStr << XorValue.toString(10, true) << ("1LL << " + RHSStr)
+ << ExprStr << toString(XorValue, 10, true) << ("1LL << " + RHSStr)
<< FixItHint::CreateReplacement(ExprRange, "1LL << " + RHSStr);
else if (RightSideIntValue == 64)
- S.Diag(Loc, diag::warn_xor_used_as_pow) << ExprStr << XorValue.toString(10, true);
+ S.Diag(Loc, diag::warn_xor_used_as_pow)
+ << ExprStr << toString(XorValue, 10, true);
else
return;
} else {
S.Diag(Loc, diag::warn_xor_used_as_pow_base_extra)
- << ExprStr << XorValue.toString(10, true) << SuggestedExpr
- << PowValue.toString(10, true)
+ << ExprStr << toString(XorValue, 10, true) << SuggestedExpr
+ << toString(PowValue, 10, true)
<< FixItHint::CreateReplacement(
ExprRange, (RightSideIntValue == 0) ? "1" : SuggestedExpr);
}
- S.Diag(Loc, diag::note_xor_used_as_pow_silence) << ("0x2 ^ " + RHSStr) << SuggestXor;
+ S.Diag(Loc, diag::note_xor_used_as_pow_silence)
+ << ("0x2 ^ " + RHSStr) << SuggestXor;
} else if (LeftSideValue == 10) {
std::string SuggestedValue = "1e" + std::to_string(RightSideIntValue);
S.Diag(Loc, diag::warn_xor_used_as_pow_base)
- << ExprStr << XorValue.toString(10, true) << SuggestedValue
+ << ExprStr << toString(XorValue, 10, true) << SuggestedValue
<< FixItHint::CreateReplacement(ExprRange, SuggestedValue);
- S.Diag(Loc, diag::note_xor_used_as_pow_silence) << ("0xA ^ " + RHSStr) << SuggestXor;
+ S.Diag(Loc, diag::note_xor_used_as_pow_silence)
+ << ("0xA ^ " + RHSStr) << SuggestXor;
}
}
if (ActiveSizeBits > ConstantArrayType::getMaxSizeBits(Context))
return ExprError(
Diag((*ArraySize)->getBeginLoc(), diag::err_array_too_large)
- << Value->toString(10) << (*ArraySize)->getSourceRange());
+ << toString(*Value, 10) << (*ArraySize)->getSourceRange());
}
KnownArraySize = Value->getZExtValue();
if (!VerifyOnly)
SemaRef.Diag(IndexExpr->getBeginLoc(),
diag::err_array_designator_too_large)
- << DesignatedEndIndex.toString(10) << MaxElements.toString(10)
+ << toString(DesignatedEndIndex, 10) << toString(MaxElements, 10)
<< IndexExpr->getSourceRange();
++Index;
return true;
if (Value.isSigned() && Value.isNegative())
return S.Diag(Loc, diag::err_array_designator_negative)
- << Value.toString(10) << Index->getSourceRange();
+ << toString(Value, 10) << Index->getSourceRange();
Value.setIsUnsigned(true);
return Result;
if (!StartDependent && !EndDependent && EndValue < StartValue) {
Diag(D.getEllipsisLoc(), diag::err_array_designator_empty_range)
- << StartValue.toString(10) << EndValue.toString(10)
+ << toString(StartValue, 10) << toString(EndValue, 10)
<< StartIndex->getSourceRange() << EndIndex->getSourceRange();
Invalid = true;
} else {
Diag(StartLoc, diag::err_omp_critical_with_hint);
if (HintLoc.isValid())
Diag(HintLoc, diag::note_omp_critical_hint_here)
- << 0 << Hint.toString(/*Radix=*/10, /*Signed=*/false);
+ << 0 << toString(Hint, /*Radix=*/10, /*Signed=*/false);
else
Diag(StartLoc, diag::note_omp_critical_no_hint) << 0;
if (const auto *C = Pair.first->getSingleClause<OMPHintClause>()) {
Diag(C->getBeginLoc(), diag::note_omp_critical_hint_here)
<< 1
- << C->getHint()->EvaluateKnownConstInt(Context).toString(
- /*Radix=*/10, /*Signed=*/false);
+ << toString(C->getHint()->EvaluateKnownConstInt(Context),
+ /*Radix=*/10, /*Signed=*/false);
} else {
Diag(Pair.first->getBeginLoc(), diag::note_omp_critical_no_hint) << 1;
}
// type versus "switch expression cannot have this value". Use proper
// IntRange checking rather than just looking at the unpromoted type here.
if (ConvVal != Val)
- S.Diag(Loc, diag::warn_case_value_overflow) << Val.toString(10)
- << ConvVal.toString(10);
+ S.Diag(Loc, diag::warn_case_value_overflow) << toString(Val, 10)
+ << toString(ConvVal, 10);
}
}
if (OverlapStmt) {
// If we have a duplicate, report it.
Diag(CR->getLHS()->getBeginLoc(), diag::err_duplicate_case)
- << OverlapVal.toString(10);
+ << toString(OverlapVal, 10);
Diag(OverlapStmt->getLHS()->getBeginLoc(),
diag::note_duplicate_case_prev);
// FIXME: We really want to remove the bogus case stmt from the
// TODO: it would be nice if we printed enums as enums, chars as
// chars, etc.
Diag(CondExpr->getExprLoc(), diag::warn_missing_case_for_condition)
- << ConstantCondValue.toString(10)
+ << toString(ConstantCondValue, 10)
<< CondExpr->getSourceRange();
}
if (!Info.isValidAsmImmediate(IntResult))
return StmtError(Diag(InputExpr->getBeginLoc(),
diag::err_invalid_asm_value_for_constraint)
- << IntResult.toString(10)
+ << toString(IntResult, 10)
<< Info.getConstraintStr()
<< InputExpr->getSourceRange());
}
Value.setIsSigned(IntegerType->isSignedIntegerOrEnumerationType());
// Complain if an unsigned parameter received a negative value.
- if (IntegerType->isUnsignedIntegerOrEnumerationType()
- && (OldValue.isSigned() && OldValue.isNegative())) {
+ if (IntegerType->isUnsignedIntegerOrEnumerationType() &&
+ (OldValue.isSigned() && OldValue.isNegative())) {
Diag(Arg->getBeginLoc(), diag::warn_template_arg_negative)
- << OldValue.toString(10) << Value.toString(10) << Param->getType()
+ << toString(OldValue, 10) << toString(Value, 10) << Param->getType()
<< Arg->getSourceRange();
Diag(Param->getLocation(), diag::note_template_param_here);
}
RequiredBits = OldValue.getMinSignedBits();
if (RequiredBits > AllowedBits) {
Diag(Arg->getBeginLoc(), diag::warn_template_arg_too_large)
- << OldValue.toString(10) << Value.toString(10) << Param->getType()
+ << toString(OldValue, 10) << toString(Value, 10) << Param->getType()
<< Arg->getSourceRange();
Diag(Param->getLocation(), diag::note_template_param_here);
}
: ConstVal.getActiveBits();
if (ActiveSizeBits > ConstantArrayType::getMaxSizeBits(Context)) {
Diag(ArraySize->getBeginLoc(), diag::err_array_too_large)
- << ConstVal.toString(10) << ArraySize->getSourceRange();
+ << toString(ConstVal, 10) << ArraySize->getSourceRange();
return QualType();
}
#include "llvm/ADT/FoldingSet.h"
#include "llvm/ADT/ImmutableSet.h"
#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
}
void Range::dump(raw_ostream &OS) const {
- OS << '[' << From().toString(10) << ", " << To().toString(10) << ']';
+ OS << '[' << toString(From(), 10) << ", " << toString(To(), 10) << ']';
}
void RangeSet::dump(raw_ostream &OS) const {
return SS.str();
}
LLVM_ATTRIBUTE_UNUSED static std::string toString(const llvm::APSInt &Point) {
- return Point.toString(10);
+ return toString(Point, 10);
}
// We need it here for better fail diagnostics from gtest.
LLVM_ATTRIBUTE_UNUSED static std::ostream &operator<<(std::ostream &OS,
}
bool VisitIntegerLiteral(IntegerLiteral *Lit) {
- VisitedNodes.push_back(Lit->getValue().toString(10, false));
+ VisitedNodes.push_back(toString(Lit->getValue(), 10, false));
return true;
}
std::string stmtToString(Stmt *S) {
StringRef ClassName = S->getStmtClassName();
if (IntegerLiteral *IL = dyn_cast<IntegerLiteral>(S)) {
- return (ClassName + "(" + IL->getValue().toString(10, false) + ")").str();
+ return (ClassName + "(" + toString(IL->getValue(), 10, false) + ")").str();
}
if (UnaryOperator *UO = dyn_cast<UnaryOperator>(S)) {
return (ClassName + "(" + UnaryOperator::getOpcodeStr(UO->getOpcode()) +
#include <cassert>
#include <climits>
#include <cstring>
-#include <string>
namespace llvm {
class FoldingSetNodeID;
toString(Str, Radix, true, false);
}
- /// Return the APInt as a std::string.
- ///
- /// Note that this is an inefficient method. It is better to pass in a
- /// SmallVector/SmallString to the methods above to avoid thrashing the heap
- /// for the string.
- std::string toString(unsigned Radix, bool Signed) const;
-
/// \returns a byte-swapped representation of this APInt Value.
APInt byteSwap() const;
void toString(SmallVectorImpl<char> &Str, unsigned Radix = 10) const {
APInt::toString(Str, Radix, isSigned());
}
- /// Converts an APInt to a std::string. This is an inefficient
- /// method; you should prefer passing in a SmallString instead.
- std::string toString(unsigned Radix) const {
- return APInt::toString(Radix, isSigned());
- }
using APInt::toString;
/// Get the correctly-extended \c int64_t value.
#ifndef LLVM_ADT_STRINGEXTRAS_H
#define LLVM_ADT_STRINGEXTRAS_H
+#include "llvm/ADT/APSInt.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringRef.h"
return utostr(static_cast<uint64_t>(X));
}
+inline std::string toString(const APInt &I, unsigned Radix, bool Signed,
+ bool formatAsCLiteral = false) {
+ SmallString<40> S;
+ I.toString(S, Radix, Signed, formatAsCLiteral);
+ return std::string(S.str());
+}
+
+inline std::string toString(const APSInt &I, unsigned Radix) {
+ return toString(I, Radix, I.isSigned());
+}
+
/// StrInStrNoCase - Portable version of strcasestr. Locates the first
/// occurrence of string 's1' in string 's2', ignoring case. Returns
/// the offset of s2 in s1 or npos if s2 cannot be found.
dumpResult(const MachineInstr &MI, const KnownBits &Known, unsigned Depth) {
dbgs() << "[" << Depth << "] Compute known bits: " << MI << "[" << Depth
<< "] Computed for: " << MI << "[" << Depth << "] Known: 0x"
- << (Known.Zero | Known.One).toString(16, false) << "\n"
- << "[" << Depth << "] Zero: 0x" << Known.Zero.toString(16, false)
+ << toString(Known.Zero | Known.One, 16, false) << "\n"
+ << "[" << Depth << "] Zero: 0x" << toString(Known.Zero, 16, false)
<< "\n"
- << "[" << Depth << "] One: 0x" << Known.One.toString(16, false)
+ << "[" << Depth << "] One: 0x" << toString(Known.One, 16, false)
<< "\n";
}
static std::string APIntToHexString(const APInt &AI) {
unsigned Width = (AI.getBitWidth() / 8) * 2;
- std::string HexString = AI.toString(16, /*Signed=*/false);
+ std::string HexString = toString(AI, 16, /*Signed=*/false);
llvm::transform(HexString, HexString.begin(), tolower);
unsigned Size = HexString.size();
assert(Width >= Size && "hex string is too large!");
std::reverse(Str.begin()+StartDig, Str.end());
}
-/// Returns the APInt as a std::string. Note that this is an inefficient method.
-/// It is better to pass in a SmallVector/SmallString to the methods above.
-std::string APInt::toString(unsigned Radix = 10, bool Signed = true) const {
- SmallString<40> S;
- toString(S, Radix, Signed, /* formatAsCLiteral = */false);
- return std::string(S.str());
-}
-
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void APInt::dump() const {
SmallString<40> S, U;
const MachineOperand &DstOp = MI->getOperand(0);
CS << X86ATTInstPrinter::getRegisterName(DstOp.getReg()) << " = ";
if (auto *CF = dyn_cast<ConstantFP>(C)) {
- CS << "0x" << CF->getValueAPF().bitcastToAPInt().toString(16, false);
+ CS << "0x" << toString(CF->getValueAPF().bitcastToAPInt(), 16, false);
OutStreamer.AddComment(CS.str());
}
}
return ORA << "OpenMP ICV " << ore::NV("OpenMPICV", ICVInfo.Name)
<< " Value: "
<< (ICVInfo.InitValue
- ? ICVInfo.InitValue->getValue().toString(10, true)
+ ? toString(ICVInfo.InitValue->getValue(), 10, true)
: "IMPLEMENTATION_DEFINED");
};
raw_ostream &Out) {
YamlContext &Context = getTypedContext(Ctx);
Out << Context.getRegName(RV.Register) << "=0x"
- << RV.Value.toString(kRadix, kSigned);
+ << toString(RV.Value, kRadix, kSigned);
}
static StringRef input(StringRef String, void *Ctx,
P.format(" `{0}`", Constant.Name);
AutoIndent Indent(P, 7);
P.formatLine("type = {0}, value = {1}", typeIndex(Constant.Type),
- Constant.Value.toString(10));
+ toString(Constant.Value, 10));
return Error::success();
}
Error MinimalTypeDumpVisitor::visitKnownMember(CVMemberRecord &CVR,
EnumeratorRecord &Enum) {
P.format(" [{0} = {1}]", Enum.Name,
- Enum.Value.toString(10, Enum.Value.isSigned()));
+ toString(Enum.Value, 10, Enum.Value.isSigned()));
return Error::success();
}
APInt ValC(65, 0);
ValC = ValA * ValB;
ValA *= ValB;
- EXPECT_EQ(ValA.toString(10, false), ValC.toString(10, false));
+ SmallString<16> StrA, StrC;
+ ValA.toString(StrA, 10, false);
+ ValC.toString(StrC, 10, false);
+ EXPECT_EQ(std::string(StrA), std::string(StrC));
}
TEST(APIntTest, Rotate) {
S = LS2;
EXPECT_EQ(S, " ");
}
+
+TEST(StringExtrasTest, toStringAPInt) {
+ bool isSigned;
+
+ EXPECT_EQ(toString(APInt(8, 0), 2, true, true), "0b0");
+ EXPECT_EQ(toString(APInt(8, 0), 8, true, true), "00");
+ EXPECT_EQ(toString(APInt(8, 0), 10, true, true), "0");
+ EXPECT_EQ(toString(APInt(8, 0), 16, true, true), "0x0");
+ EXPECT_EQ(toString(APInt(8, 0), 36, true, false), "0");
+
+ isSigned = false;
+ EXPECT_EQ(toString(APInt(8, 255, isSigned), 2, isSigned, true), "0b11111111");
+ EXPECT_EQ(toString(APInt(8, 255, isSigned), 8, isSigned, true), "0377");
+ EXPECT_EQ(toString(APInt(8, 255, isSigned), 10, isSigned, true), "255");
+ EXPECT_EQ(toString(APInt(8, 255, isSigned), 16, isSigned, true), "0xFF");
+ EXPECT_EQ(toString(APInt(8, 255, isSigned), 36, isSigned, false), "73");
+
+ isSigned = true;
+ EXPECT_EQ(toString(APInt(8, 255, isSigned), 2, isSigned, true), "-0b1");
+ EXPECT_EQ(toString(APInt(8, 255, isSigned), 8, isSigned, true), "-01");
+ EXPECT_EQ(toString(APInt(8, 255, isSigned), 10, isSigned, true), "-1");
+ EXPECT_EQ(toString(APInt(8, 255, isSigned), 16, isSigned, true), "-0x1");
+ EXPECT_EQ(toString(APInt(8, 255, isSigned), 36, isSigned, false), "-1");
+}
+
+TEST(StringExtrasTest, toStringAPSInt) {
+ bool isUnsigned;
+
+ EXPECT_EQ(toString(APSInt(APInt(8, 0), false), 2), "0");
+ EXPECT_EQ(toString(APSInt(APInt(8, 0), false), 8), "0");
+ EXPECT_EQ(toString(APSInt(APInt(8, 0), false), 10), "0");
+ EXPECT_EQ(toString(APSInt(APInt(8, 0), false), 16), "0");
+
+ isUnsigned = true;
+ EXPECT_EQ(toString(APSInt(APInt(8, 255), isUnsigned), 2), "11111111");
+ EXPECT_EQ(toString(APSInt(APInt(8, 255), isUnsigned), 8), "377");
+ EXPECT_EQ(toString(APSInt(APInt(8, 255), isUnsigned), 10), "255");
+ EXPECT_EQ(toString(APSInt(APInt(8, 255), isUnsigned), 16), "FF");
+
+ isUnsigned = false;
+ EXPECT_EQ(toString(APSInt(APInt(8, 255), isUnsigned), 2), "-1");
+ EXPECT_EQ(toString(APSInt(APInt(8, 255), isUnsigned), 8), "-1");
+ EXPECT_EQ(toString(APSInt(APInt(8, 255), isUnsigned), 10), "-1");
+ EXPECT_EQ(toString(APSInt(APInt(8, 255), isUnsigned), 16), "-1");
+}
\ No newline at end of file