Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 80867d1

Browse files
author
Sergey Andreenko
authored
Fix simple general warnings found by PVS. (#27283)
* Delete unused `scAvailable`. * Delete unused `PhysRegIntervalIterator`. * Expression is always true. * Possible overflow. * Delete unreachable/unused code. * Two or more case-branches perform the same actions. * Check self-copying. * The 'isOnStack' variable is assigned values twice successively. * The 'then' statement is equivalent to the 'else' statement. `MAX_COST` is `UCHAR_MAX` so if `unsigned char cost >= MAX_COST` then it is equal to ``MAX_COST`. So the code was correct, but confusing. * Expression 'newPage == nullptr' is always true. * Expression 'inconsistentProfileData' is always false. * A part of conditional expression is always false: typ == TYP_BOOL. * A part of conditional expression is always true: emitFullGCinfo. We have an early return from this function if `emitFullGCinfo == false`. * A part of conditional expression is always true: asgNode. We have an early return if it is nullptr. * delete an unused function with errors. There were 3 incorrent printf arguments. * Delete another unused function without return. * An excessive check can be simplified. The '(A && B) || (!A && !B)' expression is equivalent to the 'bool(A) == bool(B)' expression, * The expression is of enum type. It is odd that it is used as an expression of a Boolean-type. * the usage of '#pragma warning(default: X)' is incorrect in this context. The '#pragma warning(push/pop)' should be used instead. That function and almost the whole file is unused, do we want to delete it? * The expression 'eeGetHelperNum(method)' is of enum type. It is odd that it is used as an expression of a Boolean-type. * `nodeThis` and `nodeOther` are always true. * 'this == nullptr' expression should be avoided - this expression is always false on newer compilers, because 'this' pointer can never be NULL. Don't compare `this` with null. * Variables 'm_Cost', 'm_Size' are initialized through the call to the same function. It's probably an error or un-optimized code. Consider inspecting the 'Expr()->GetCostSz()' expression. * Parameter 'toRefPosition' is not used inside function body. * Expression 'parentOfArgObj == parentArgx' is always true. We assigned `parentOfArgObj ` to `parentArgx` and did not change any of them before that check. * The 'srcCount' variable is assigned values twice successively. Perhaps this is a mistake. * Response review.
1 parent 9cae8fa commit 80867d1

26 files changed

+47
-160
lines changed

src/inc/safemath.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ template<typename T> class ClrSafeInt
524524
}
525525

526526
#ifdef _MSC_VER
527+
#pragma warning(push)
527528
#pragma warning( disable : 4146 ) // unary minus applied to unsigned is still unsigned
528529
#endif
529530
if(MaxInt()/(-lhs) < (-rhs) )
@@ -532,7 +533,7 @@ template<typename T> class ClrSafeInt
532533
return false;
533534
}
534535
#ifdef _MSC_VER
535-
#pragma warning( default : 4146 )
536+
#pragma warning(pop)
536537
#endif
537538
}
538539
}

src/jit/alloc.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,23 +81,18 @@ void* ArenaAllocator::allocateNewPage(size_t size)
8181
m_lastPage->m_usedBytes = m_nextFreeByte - m_lastPage->m_contents;
8282
}
8383

84-
PageDescriptor* newPage = nullptr;
85-
8684
if (!bypassHostAllocator())
8785
{
8886
// Round to the nearest multiple of default page size
8987
pageSize = roundUp(pageSize, DEFAULT_PAGE_SIZE);
9088
}
9189

90+
// Allocate the new page
91+
PageDescriptor* newPage = static_cast<PageDescriptor*>(allocateHostMemory(pageSize, &pageSize));
92+
9293
if (newPage == nullptr)
9394
{
94-
// Allocate the new page
95-
newPage = static_cast<PageDescriptor*>(allocateHostMemory(pageSize, &pageSize));
96-
97-
if (newPage == nullptr)
98-
{
99-
NOMEM();
100-
}
95+
NOMEM();
10196
}
10297

10398
// Append the new page to the end of the list

src/jit/assertionprop.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ void Compiler::optAddCopies()
8585
tracks simple assignments. The same goes for lvNormalizedOnStore as
8686
the cast is generated in fgMorphSmpOpAsg. This boils down to not having
8787
a copy until optAssertionGen handles this*/
88-
if (varDsc->lvNormalizeOnLoad() || varDsc->lvNormalizeOnStore() || typ == TYP_BOOL)
88+
if (varDsc->lvNormalizeOnLoad() || varDsc->lvNormalizeOnStore())
8989
{
9090
continue;
9191
}

src/jit/codegen.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,6 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
647647
unsigned scLVnum; // 'which' in eeGetLVinfo()
648648

649649
unsigned scStackLevel; // Only for stk-vars
650-
bool scAvailable : 1; // It has a home / Home recycled - TODO-Cleanup: it appears this is unused (always true)
651650

652651
siScope* scPrev;
653652
siScope* scNext;

src/jit/codegencommon.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10183,8 +10183,8 @@ void CodeGen::genSetScopeInfoUsingsiScope()
1018310183
LclVarDsc* varDsc = compiler->lvaGetDesc(scopeL->scVarNum);
1018410184
siVarLoc varLoc = getSiVarLoc(varDsc, scopeL);
1018510185

10186-
genSetScopeInfo(psiScopeCnt + i, startOffs, endOffs - startOffs, scopeL->scVarNum, scopeL->scLVnum,
10187-
scopeL->scAvailable, &varLoc);
10186+
genSetScopeInfo(psiScopeCnt + i, startOffs, endOffs - startOffs, scopeL->scVarNum, scopeL->scLVnum, false,
10187+
&varLoc);
1018810188
}
1018910189
}
1019010190
#endif // USING_SCOPE_INFO

src/jit/compiler.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8092,15 +8092,11 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
80928092
{
80938093
#ifdef FEATURE_SIMD
80948094
unsigned vectorRegSize = getSIMDVectorRegisterByteLength();
8095-
if (vectorRegSize > TARGET_POINTER_SIZE)
8096-
{
8097-
return vectorRegSize;
8098-
}
8099-
else
8100-
#endif // FEATURE_SIMD
8101-
{
8102-
return TARGET_POINTER_SIZE;
8103-
}
8095+
assert(vectorRegSize >= TARGET_POINTER_SIZE);
8096+
return vectorRegSize;
8097+
#else // !FEATURE_SIMD
8098+
return TARGET_POINTER_SIZE;
8099+
#endif // !FEATURE_SIMD
81048100
}
81058101

81068102
private:

src/jit/compiler.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3592,7 +3592,7 @@ inline CORINFO_METHOD_HANDLE Compiler::eeFindHelper(unsigned helper)
35923592
/* Helpers are marked by the fact that they are odd numbers
35933593
* force this to be an odd number (will shift it back to extract) */
35943594

3595-
return ((CORINFO_METHOD_HANDLE)(size_t)((helper << 2) + 1));
3595+
return ((CORINFO_METHOD_HANDLE)((((size_t)helper) << 2) + 1));
35963596
}
35973597

35983598
inline CorInfoHelpFunc Compiler::eeGetHelperNum(CORINFO_METHOD_HANDLE method)

src/jit/ee_il_dll.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1308,7 +1308,7 @@ static LONG FilterSuperPMIExceptions_ee_il(PEXCEPTION_POINTERS pExceptionPointer
13081308

13091309
const char* Compiler::eeGetMethodName(CORINFO_METHOD_HANDLE method, const char** classNamePtr)
13101310
{
1311-
if (eeGetHelperNum(method))
1311+
if (eeGetHelperNum(method) != CORINFO_HELP_UNDEF)
13121312
{
13131313
if (classNamePtr != nullptr)
13141314
{

src/jit/emit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7375,7 +7375,7 @@ void emitter::emitStackKillArgs(BYTE* addr, unsigned count, unsigned char callIn
73757375
stack, but they are effectively dead. For fully-interruptible
73767376
methods, we need to report that */
73777377

7378-
if (emitFullGCinfo && gcCnt.Value())
7378+
if (gcCnt.Value())
73797379
{
73807380
/* Allocate a new ptr arg entry and fill it in */
73817381

src/jit/flowgraph.cpp

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10433,10 +10433,8 @@ void Compiler::fgCompactBlocks(BasicBlock* block, BasicBlock* bNext)
1043310433
block->bbWeight = bNext->bbWeight;
1043410434

1043510435
block->bbFlags |= (bNext->bbFlags & BBF_PROF_WEIGHT); // Set the profile weight flag (if necessary)
10436-
if (block->bbWeight != 0)
10437-
{
10438-
block->bbFlags &= ~BBF_RUN_RARELY; // Clear any RarelyRun flag
10439-
}
10436+
assert(block->bbWeight != 0);
10437+
block->bbFlags &= ~BBF_RUN_RARELY; // Clear any RarelyRun flag
1044010438
}
1044110439
}
1044210440
// otherwise if either block has a zero weight we select the zero weight
@@ -13652,11 +13650,7 @@ void Compiler::fgComputeEdgeWeights()
1365213650
}
1365313651
}
1365413652

13655-
if (inconsistentProfileData)
13656-
{
13657-
hasIncompleteEdgeWeights = true;
13658-
break;
13659-
}
13653+
assert(!inconsistentProfileData); // Should use EARLY_EXIT when it is false.
1366013654

1366113655
if (numEdges == goodEdgeCountCurrent)
1366213656
{
@@ -15011,8 +15005,7 @@ bool Compiler::fgOptimizeBranch(BasicBlock* bJump)
1501115005
}
1501215006
else
1501315007
{
15014-
BasicBlock::weight_t newWeightDest = 0;
15015-
BasicBlock::weight_t unloopWeightDest = 0;
15008+
BasicBlock::weight_t newWeightDest = 0;
1501615009

1501715010
if (weightDest > weightJump)
1501815011
{
@@ -15022,9 +15015,9 @@ bool Compiler::fgOptimizeBranch(BasicBlock* bJump)
1502215015
{
1502315016
newWeightDest = (weightDest * 2) / (BB_LOOP_WEIGHT * BB_UNITY_WEIGHT);
1502415017
}
15025-
if ((newWeightDest > 0) || (unloopWeightDest > 0))
15018+
if (newWeightDest > 0)
1502615019
{
15027-
bDest->bbWeight = Max(newWeightDest, unloopWeightDest);
15020+
bDest->bbWeight = newWeightDest;
1502815021
}
1502915022
}
1503015023
}
@@ -19240,16 +19233,7 @@ unsigned Compiler::fgGetCodeEstimate(BasicBlock* block)
1924019233
for (Statement* stmt : StatementList(block->FirstNonPhiDef()))
1924119234
{
1924219235
unsigned char cost = stmt->GetCostSz();
19243-
if (cost < MAX_COST)
19244-
{
19245-
costSz += cost;
19246-
}
19247-
else
19248-
{
19249-
// We could walk the tree to find out the real GetCostSz(),
19250-
// but just using MAX_COST for this trees code size works OK
19251-
costSz += cost;
19252-
}
19236+
costSz += cost;
1925319237
}
1925419238

1925519239
return costSz;

0 commit comments

Comments
 (0)