diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 60c658a8d8f99..5d399a3c75ca8 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -1428,11 +1428,11 @@ namespace { } bool destroy(bool RunDestructors = true) { bool OK = cleanup(Info, RunDestructors, OldStackSize); - OldStackSize = -1U; + OldStackSize = std::numeric_limits::max(); return OK; } ~ScopeRAII() { - if (OldStackSize != -1U) + if (OldStackSize != std::numeric_limits::max()) destroy(false); // Body moved to a static method to encourage the compiler to inline away // instances of this class. diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index f0412cddc6f19..8b217bcbeece6 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -22,7 +22,9 @@ #include "UnwrappedLineFormatter.h" #include "UsingDeclarationsSorter.h" #include "clang/Tooling/Inclusions/HeaderIncludes.h" + #include "llvm/ADT/Sequence.h" +#include #define DEBUG_TYPE "format-formatter" @@ -777,7 +779,7 @@ template <> struct MappingTraits { IO.mapOptional("Maximum", signedMaximum); Space.Maximum = static_cast(signedMaximum); - if (Space.Maximum != -1u) + if (Space.Maximum < std::numeric_limits::max()) Space.Minimum = std::min(Space.Minimum, Space.Maximum); } }; @@ -1672,7 +1674,8 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) { LLVMStyle.SpacesBeforeTrailingComments = 1; LLVMStyle.SpacesInAngles = FormatStyle::SIAS_Never; LLVMStyle.SpacesInContainerLiterals = true; - LLVMStyle.SpacesInLineCommentPrefix = {/*Minimum=*/1, /*Maximum=*/-1u}; + LLVMStyle.SpacesInLineCommentPrefix = { + /*Minimum=*/1, /*Maximum=*/std::numeric_limits::max()}; LLVMStyle.SpacesInParens = FormatStyle::SIPO_Never; LLVMStyle.SpacesInSquareBrackets = false; LLVMStyle.Standard = FormatStyle::LS_Latest; @@ -3168,11 +3171,12 @@ static bool affectsRange(ArrayRef Ranges, unsigned Start, // the index of the first of the duplicates as the others are going to be // removed. OffsetToEOL describes the cursor's position relative to the end of // its current line. -// If `Cursor` is not on any #include, `Index` will be UINT_MAX. +// If `Cursor` is not on any #include, `Index` will be +// std::numeric_limits::max(). static std::pair FindCursorIndex(const ArrayRef &Includes, const ArrayRef &Indices, unsigned Cursor) { - unsigned CursorIndex = UINT_MAX; + unsigned CursorIndex = std::numeric_limits::max(); unsigned OffsetToEOL = 0; for (int i = 0, e = Includes.size(); i != e; ++i) { unsigned Start = Includes[Indices[i]].Offset; @@ -3440,11 +3444,12 @@ tooling::Replacements sortCppIncludes(const FormatStyle &Style, StringRef Code, return Replaces; } -// Returns group number to use as a first order sort on imports. Gives UINT_MAX -// if the import does not match any given groups. +// Returns group number to use as a first order sort on imports. Gives +// std::numeric_limits::max() if the import does not match any given +// groups. static unsigned findJavaImportGroup(const FormatStyle &Style, StringRef ImportIdentifier) { - unsigned LongestMatchIndex = UINT_MAX; + unsigned LongestMatchIndex = std::numeric_limits::max(); unsigned LongestMatchLength = 0; for (unsigned I = 0; I < Style.JavaImportGroups.size(); I++) { const std::string &GroupPrefix = Style.JavaImportGroups[I]; @@ -3673,13 +3678,15 @@ formatReplacements(StringRef Code, const tooling::Replacements &Replaces, namespace { inline bool isHeaderInsertion(const tooling::Replacement &Replace) { - return Replace.getOffset() == UINT_MAX && Replace.getLength() == 0 && + return Replace.getOffset() == std::numeric_limits::max() && + Replace.getLength() == 0 && tooling::HeaderIncludes::IncludeRegex.match( Replace.getReplacementText()); } inline bool isHeaderDeletion(const tooling::Replacement &Replace) { - return Replace.getOffset() == UINT_MAX && Replace.getLength() == 1; + return Replace.getOffset() == std::numeric_limits::max() && + Replace.getLength() == 1; } // FIXME: insert empty lines between newly created blocks. @@ -3699,7 +3706,7 @@ fixCppIncludeInsertions(StringRef Code, const tooling::Replacements &Replaces, consumeError(HeaderInsertions.add(R)); } else if (isHeaderDeletion(R)) { HeadersToDelete.insert(R.getReplacementText()); - } else if (R.getOffset() == UINT_MAX) { + } else if (R.getOffset() == std::numeric_limits::max()) { llvm::errs() << "Insertions other than header #include insertion are " "not supported! " << R.getReplacementText() << "\n"; diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp index 78988e928a689..1f695b4a8676c 100644 --- a/clang/lib/Lex/Lexer.cpp +++ b/clang/lib/Lex/Lexer.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -3456,7 +3457,7 @@ std::optional Lexer::tryReadNumericUCN(const char *&StartPtr, } unsigned Value = llvm::hexDigitValue(C); - if (Value == -1U) { + if (Value == std::numeric_limits::max()) { if (!Delimited) break; if (Diagnose) diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 3c3d29c415249..fcc015be1d5f4 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -65,6 +65,7 @@ #include "llvm/Support/SaveAndRestore.h" #include "llvm/Support/TimeProfiler.h" #include "llvm/Support/TypeSize.h" +#include #include using namespace clang; @@ -1906,7 +1907,7 @@ ExprResult Sema::CreateGenericSelectionExpr( } SmallVector CompatIndices; - unsigned DefaultIndex = -1U; + unsigned DefaultIndex = std::numeric_limits::max(); // Look at the canonical type of the controlling expression in case it was a // deduced type like __auto_type. However, when issuing diagnostics, use the // type the user wrote in source rather than the canonical one. @@ -1961,7 +1962,8 @@ ExprResult Sema::CreateGenericSelectionExpr( // C11 6.5.1.1p2 "If a generic selection has no default generic association, // its controlling expression shall have type compatible with exactly one of // the types named in its generic association list." - if (DefaultIndex == -1U && CompatIndices.size() == 0) { + if (DefaultIndex == std::numeric_limits::max() && + CompatIndices.size() == 0) { auto P = GetControllingRangeAndType(ControllingExpr, ControllingType); SourceRange SR = P.first; Diag(SR.getBegin(), diag::err_generic_sel_no_match) << SR << P.second;