Skip to content

Commit d1d0a31

Browse files
authored
[NFC] Address compiler warnings: C4146 - Trivial std::numeric_limits<T> cases (microsoft#7559)
Addresses microsoft#7558. There is also one trivial change to use the ~ operator included in LEB128.h. My notes on the files were wrong and suggested that it should use std::numeric_limits<T> but looking at it again using ~0ULL made more sense.
1 parent b4baabb commit d1d0a31

12 files changed

Lines changed: 46 additions & 40 deletions

File tree

include/llvm/DebugInfo/DWARF/DWARFDebugAranges.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,21 @@ class DWARFDebugAranges {
3232
void construct();
3333

3434
struct Range {
35-
explicit Range(uint64_t LowPC = -1ULL, uint64_t HighPC = -1ULL,
36-
uint32_t CUOffset = -1U)
37-
: LowPC(LowPC), Length(HighPC - LowPC), CUOffset(CUOffset) {}
35+
explicit Range(uint64_t LowPC = std::numeric_limits<uint64_t>::max(),
36+
uint64_t HighPC = std::numeric_limits<uint64_t>::max(),
37+
uint32_t CUOffset = std::numeric_limits<uint32_t>::max())
38+
: LowPC(LowPC), Length(HighPC - LowPC), CUOffset(CUOffset) {}
3839

3940
void setHighPC(uint64_t HighPC) {
40-
if (HighPC == -1ULL || HighPC <= LowPC)
41+
if (HighPC == std::numeric_limits<uint64_t>::max() || HighPC <= LowPC)
4142
Length = 0;
4243
else
4344
Length = HighPC - LowPC;
4445
}
4546
uint64_t HighPC() const {
4647
if (Length)
4748
return LowPC + Length;
48-
return -1ULL;
49+
return std::numeric_limits<uint64_t>::max();
4950
}
5051

5152
bool containsAddress(uint64_t Address) const {

include/llvm/Support/BlockFrequency.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#define LLVM_SUPPORT_BLOCKFREQUENCY_H
1616

1717
#include "llvm/Support/DataTypes.h"
18+
#include <limits>
1819

1920
namespace llvm {
2021

@@ -29,7 +30,9 @@ class BlockFrequency {
2930
BlockFrequency(uint64_t Freq = 0) : Frequency(Freq) { }
3031

3132
/// \brief Returns the maximum possible frequency, the saturation value.
32-
static uint64_t getMaxFrequency() { return -1ULL; }
33+
static uint64_t getMaxFrequency() {
34+
return std::numeric_limits<uint64_t>::max();
35+
}
3336

3437
/// \brief Returns the frequency as a fixpoint number scaled by the entry
3538
/// frequency.

lib/Analysis/LoopAccessAnalysis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1179,7 +1179,7 @@ bool MemoryDepChecker::areDepsSafe(DepCandidates &AccessSets,
11791179
MemAccessInfoSet &CheckDeps,
11801180
const ValueToValueMap &Strides) {
11811181

1182-
MaxSafeDepDistBytes = -1U;
1182+
MaxSafeDepDistBytes = std::numeric_limits<unsigned>::max();
11831183
while (!CheckDeps.empty()) {
11841184
MemAccessInfo CurAccess = *CheckDeps.begin();
11851185

lib/Transforms/InstCombine/InstructionCombining.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1937,7 +1937,8 @@ Instruction *InstCombiner::visitAllocSite(Instruction &MI) {
19371937
} else if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(I)) {
19381938
if (II->getIntrinsicID() == Intrinsic::objectsize) {
19391939
ConstantInt *CI = cast<ConstantInt>(II->getArgOperand(1));
1940-
uint64_t DontKnow = CI->isZero() ? -1ULL : 0;
1940+
uint64_t DontKnow =
1941+
CI->isZero() ? std::numeric_limits<uint64_t>::max() : 0;
19411942
ReplaceInstUsesWith(*I, ConstantInt::get(I->getType(), DontKnow));
19421943
}
19431944
}

lib/Transforms/Scalar/LoadCombine.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,10 @@ bool LoadCombine::aggregateLoads(SmallVectorImpl<LoadPOPPair> &Loads) {
131131
LoadInst *BaseLoad = nullptr;
132132
SmallVector<LoadPOPPair, 8> AggregateLoads;
133133
bool Combined = false;
134-
uint64_t PrevOffset = -1ull;
134+
uint64_t PrevOffset = std::numeric_limits<uint64_t>::max();
135135
uint64_t PrevSize = 0;
136136
for (auto &L : Loads) {
137-
if (PrevOffset == -1ull) {
137+
if (PrevOffset == std::numeric_limits<uint64_t>::max()) {
138138
BaseLoad = L.Load;
139139
PrevOffset = L.POP.Offset;
140140
PrevSize = L.Load->getModule()->getDataLayout().getTypeStoreSize(

tools/clang/include/clang/AST/Expr.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4510,7 +4510,9 @@ class GenericSelectionExpr : public Expr {
45104510
Expr *getControllingExpr() { return cast<Expr>(SubExprs[CONTROLLING]); }
45114511

45124512
/// Whether this generic selection is result-dependent.
4513-
bool isResultDependent() const { return ResultIndex == -1U; }
4513+
bool isResultDependent() const {
4514+
return ResultIndex == std::numeric_limits<unsigned>::max();
4515+
}
45144516

45154517
/// The zero-based index of the result expression's generic association in
45164518
/// the generic selection's association list. Defined only if the

tools/clang/lib/AST/Expr.cpp

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3883,25 +3883,21 @@ GenericSelectionExpr::GenericSelectionExpr(const ASTContext &Context,
38833883
std::copy(AssocExprs.begin(), AssocExprs.end(), SubExprs+END_EXPR);
38843884
}
38853885

3886-
GenericSelectionExpr::GenericSelectionExpr(const ASTContext &Context,
3887-
SourceLocation GenericLoc, Expr *ControllingExpr,
3888-
ArrayRef<TypeSourceInfo*> AssocTypes,
3889-
ArrayRef<Expr*> AssocExprs,
3890-
SourceLocation DefaultLoc,
3891-
SourceLocation RParenLoc,
3892-
bool ContainsUnexpandedParameterPack)
3893-
: Expr(GenericSelectionExprClass,
3894-
Context.DependentTy,
3895-
VK_RValue,
3896-
OK_Ordinary,
3897-
/*isTypeDependent=*/true,
3898-
/*isValueDependent=*/true,
3899-
/*isInstantiationDependent=*/true,
3900-
ContainsUnexpandedParameterPack),
3901-
AssocTypes(new (Context) TypeSourceInfo*[AssocTypes.size()]),
3902-
SubExprs(new (Context) Stmt*[END_EXPR+AssocExprs.size()]),
3903-
NumAssocs(AssocExprs.size()), ResultIndex(-1U), GenericLoc(GenericLoc),
3904-
DefaultLoc(DefaultLoc), RParenLoc(RParenLoc) {
3886+
GenericSelectionExpr::GenericSelectionExpr(
3887+
const ASTContext &Context, SourceLocation GenericLoc, Expr *ControllingExpr,
3888+
ArrayRef<TypeSourceInfo *> AssocTypes, ArrayRef<Expr *> AssocExprs,
3889+
SourceLocation DefaultLoc, SourceLocation RParenLoc,
3890+
bool ContainsUnexpandedParameterPack)
3891+
: Expr(GenericSelectionExprClass, Context.DependentTy, VK_RValue,
3892+
OK_Ordinary,
3893+
/*isTypeDependent=*/true,
3894+
/*isValueDependent=*/true,
3895+
/*isInstantiationDependent=*/true, ContainsUnexpandedParameterPack),
3896+
AssocTypes(new(Context) TypeSourceInfo *[AssocTypes.size()]),
3897+
SubExprs(new(Context) Stmt *[END_EXPR + AssocExprs.size()]),
3898+
NumAssocs(AssocExprs.size()),
3899+
ResultIndex(std::numeric_limits<unsigned>::max()), GenericLoc(GenericLoc),
3900+
DefaultLoc(DefaultLoc), RParenLoc(RParenLoc) {
39053901
SubExprs[CONTROLLING] = ControllingExpr;
39063902
assert(AssocTypes.size() == AssocExprs.size());
39073903
std::copy(AssocTypes.begin(), AssocTypes.end(), this->AssocTypes);

tools/clang/lib/CodeGen/CGExprScalar.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2559,7 +2559,8 @@ void ScalarExprEmitter::EmitUndefinedBehaviorIntegerDivAndRemCheck(
25592559

25602560
llvm::Value *IntMin =
25612561
Builder.getInt(llvm::APInt::getSignedMinValue(Ty->getBitWidth()));
2562-
llvm::Value *NegOne = llvm::ConstantInt::get(Ty, -1ULL);
2562+
llvm::Value *NegOne =
2563+
llvm::ConstantInt::get(Ty, std::numeric_limits<uint64_t>::max());
25632564

25642565
llvm::Value *LHSCmp = Builder.CreateICmpNE(Ops.LHS, IntMin);
25652566
llvm::Value *RHSCmp = Builder.CreateICmpNE(Ops.RHS, NegOne);

tools/clang/lib/Lex/Lexer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2737,7 +2737,7 @@ uint32_t Lexer::tryReadUCN(const char *&StartPtr, const char *SlashLoc,
27372737
char C = getCharAndSize(CurPtr, CharSize);
27382738

27392739
unsigned Value = llvm::hexDigitValue(C);
2740-
if (Value == -1U) {
2740+
if (Value == std::numeric_limits<unsigned>::max()) {
27412741
if (Result && !isLexingRawMode()) {
27422742
if (i == 0) {
27432743
Diag(BufferPtr, diag::warn_ucn_escape_no_digits)

tools/clang/lib/Sema/SemaExpr.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,7 +1466,7 @@ Sema::CreateGenericSelectionExpr(SourceLocation KeyLoc,
14661466
ContainsUnexpandedParameterPack);
14671467

14681468
SmallVector<unsigned, 1> CompatIndices;
1469-
unsigned DefaultIndex = -1U;
1469+
unsigned DefaultIndex = std::numeric_limits<unsigned>::max();
14701470
for (unsigned i = 0; i < NumAssocs; ++i) {
14711471
if (!Types[i])
14721472
DefaultIndex = i;
@@ -1498,7 +1498,8 @@ Sema::CreateGenericSelectionExpr(SourceLocation KeyLoc,
14981498
// C11 6.5.1.1p2 "If a generic selection has no default generic association,
14991499
// its controlling expression shall have type compatible with exactly one of
15001500
// the types named in its generic association list."
1501-
if (DefaultIndex == -1U && CompatIndices.size() == 0) {
1501+
if (DefaultIndex == std::numeric_limits<unsigned>::max() &&
1502+
CompatIndices.size() == 0) {
15021503
// We strip parens here because the controlling expression is typically
15031504
// parenthesized in macro definitions.
15041505
ControllingExpr = ControllingExpr->IgnoreParens();

0 commit comments

Comments
 (0)