Skip to content

Commit 94abfe9

Browse files
authored
Address compiler warnings: Enable warning C4146 as a break. (microsoft#7587)
Addresses microsoft#7584 by removing the warning disable for 4146. Also includes a few trivial fixes for C4146 across several files that were missed in previous PRs.
1 parent 8a9f882 commit 94abfe9

File tree

13 files changed

+28
-19
lines changed

13 files changed

+28
-19
lines changed

cmake/modules/HandleLLVMOptions.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,6 @@ if( MSVC )
301301

302302
set(msvc_warning_flags
303303
# Disabled warnings.
304-
-wd4146 # Suppress 'unary minus operator applied to unsigned type, result still unsigned'
305304
-wd4180 # Suppress 'qualifier applied to function type has no meaning; ignored'
306305
-wd4244 # Suppress ''argument' : conversion from 'type1' to 'type2', possible loss of data'
307306
-wd4258 # Suppress ''var' : definition from the for loop is ignored; the definition from the enclosing scope is used'

include/llvm/ADT/IntervalMap.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,11 @@ class NodeBase {
320320
return Count;
321321
} else {
322322
// We want to shrink, copy to sib.
323-
unsigned Count = std::min(std::min(unsigned(-Add), Size), N - SSize);
323+
// Count <= INT_MAX: Since Add is an int, unsigned(-Add) <= 2^31, so
324+
// std::min result <= INT_MAX. Meaning its safe to store the result in an
325+
// int to avoid the compiler warning for '-Count' if we were to use an
326+
// unsigned value instead.
327+
int Count = std::min(std::min(unsigned(-Add), Size), N - SSize);
324328
transferToLeftSib(Size, Sib, SSize, Count);
325329
return -Count;
326330
}

lib/Analysis/LoopAccessAnalysis.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,8 +1677,8 @@ LoopAccessInfo::LoopAccessInfo(Loop *L, ScalarEvolution *SE,
16771677
const ValueToValueMap &Strides)
16781678
: PtrRtChecking(SE), DepChecker(SE, L), TheLoop(L), SE(SE), DL(DL),
16791679
TLI(TLI), AA(AA), DT(DT), LI(LI), NumLoads(0), NumStores(0),
1680-
MaxSafeDepDistBytes(-1U), CanVecMem(false),
1681-
StoreToLoopInvariantAddress(false) {
1680+
MaxSafeDepDistBytes(std::numeric_limits<unsigned>::max()),
1681+
CanVecMem(false), StoreToLoopInvariantAddress(false) {
16821682
if (canAnalyzeLoop())
16831683
analyzeLoop(Strides);
16841684
}

lib/Transforms/Scalar/LoadCombine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ bool LoadCombine::combineLoads(SmallVectorImpl<LoadPOPPair> &Loads) {
186186

187187
// Find first load. This is where we put the new load.
188188
LoadPOPPair FirstLP;
189-
FirstLP.InsertOrder = -1u;
189+
FirstLP.InsertOrder = std::numeric_limits<unsigned>::max();
190190
for (const auto &L : Loads)
191191
if (L.InsertOrder < FirstLP.InsertOrder)
192192
FirstLP = L;

lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4472,8 +4472,8 @@ LoopVectorizationCostModel::selectVectorizationFactor(bool OptForSize) {
44724472

44734473
unsigned WidestType = getWidestType();
44744474
unsigned WidestRegister = TTI.getRegisterBitWidth(true);
4475-
unsigned MaxSafeDepDist = -1U;
4476-
if (Legal->getMaxSafeDepDistBytes() != -1U)
4475+
unsigned MaxSafeDepDist = std::numeric_limits<unsigned>::max();
4476+
if (Legal->getMaxSafeDepDistBytes() != std::numeric_limits<unsigned>::max())
44774477
MaxSafeDepDist = Legal->getMaxSafeDepDistBytes() * 8;
44784478
WidestRegister = ((WidestRegister < MaxSafeDepDist) ?
44794479
WidestRegister : MaxSafeDepDist);
@@ -4638,7 +4638,7 @@ unsigned LoopVectorizationCostModel::selectInterleaveCount(bool OptForSize,
46384638
return 1;
46394639

46404640
// We used the distance for the interleave count.
4641-
if (Legal->getMaxSafeDepDistBytes() != -1U)
4641+
if (Legal->getMaxSafeDepDistBytes() != std::numeric_limits<unsigned>::max())
46424642
return 1;
46434643

46444644
// Do not interleave loops with a relatively small trip count.

tools/clang/lib/AST/SelectorLocationsKind.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ static SourceLocation getStandardSelLoc(unsigned Index,
2828
if (EndLoc.isInvalid())
2929
return SourceLocation();
3030
IdentifierInfo *II = Sel.getIdentifierInfoForSlot(0);
31-
unsigned Len = II ? II->getLength() : 0;
31+
int Len = II ? II->getLength() : 0;
3232
return EndLoc.getLocWithOffset(-Len);
3333
}
3434

3535
assert(Index < NumSelArgs);
3636
if (ArgLoc.isInvalid())
3737
return SourceLocation();
3838
IdentifierInfo *II = Sel.getIdentifierInfoForSlot(Index);
39-
unsigned Len = /* selector id */ (II ? II->getLength() : 0) + /* ':' */ 1;
39+
int Len = /* selector id */ (II ? II->getLength() : 0) + /* ':' */ 1;
4040
if (WithArgSpace)
4141
++Len;
4242
return ArgLoc.getLocWithOffset(-Len);

tools/clang/lib/CodeGen/ItaniumCXXABI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1090,7 +1090,7 @@ llvm::Value *ItaniumCXXABI::EmitTypeid(CodeGenFunction &CGF,
10901090
CGF.GetVTablePtr(ThisPtr, StdTypeInfoPtrTy->getPointerTo());
10911091

10921092
// Load the type info.
1093-
Value = CGF.Builder.CreateConstInBoundsGEP1_64(Value, -1ULL);
1093+
Value = CGF.Builder.CreateConstInBoundsGEP1_64(Value, -1LL);
10941094
return CGF.Builder.CreateLoad(Value);
10951095
}
10961096

tools/clang/unittests/HLSLExec/ExecutionTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
///////////////////////////////////////////////////////////////////////////////
1212

1313
// We need to keep & fix these warnings to integrate smoothly with HLK
14-
#pragma warning(error : 4100 4146 4242 4244 4267 4701 4389 4018)
14+
#pragma warning(error : 4100 4242 4244 4267 4701 4389 4018)
1515

1616
// *** THIS FILE CANNOT TAKE ANY LLVM DEPENDENCIES *** //
1717

tools/clang/unittests/HLSLExec/ShaderOpTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
///////////////////////////////////////////////////////////////////////////////
1111

1212
// We need to keep & fix these warnings to integrate smoothly with HLK
13-
#pragma warning(error : 4100 4146 4242 4244 4267 4701 4389)
13+
#pragma warning(error : 4100 4242 4244 4267 4701 4389)
1414

1515
#include "d3dx12.h"
1616
#include <atlbase.h>

tools/clang/unittests/HLSLExec/ShaderOpTest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include <vector>
2727

2828
// We need to keep & fix these warnings to integrate smoothly with HLK
29-
#pragma warning(error : 4100 4146 4242 4244 4267 4701 4389)
29+
#pragma warning(error : 4100 4242 4244 4267 4701 4389)
3030

3131
///////////////////////////////////////////////////////////////////////////////
3232
// Forward declarations.

0 commit comments

Comments
 (0)