Skip to content

Commit 5a7c88e

Browse files
fda0igcbot
authored andcommitted
Initialize members, use std::move, use const& in loops - try 2
Coverity related fixes. Initialize members, use std::move, use const& in loops, organize code in a way that's easier to analyze for Coverity.
1 parent d5ad459 commit 5a7c88e

File tree

6 files changed

+46
-64
lines changed

6 files changed

+46
-64
lines changed

IGC/AdaptorCommon/RayTracing/TraceRayInlineLoweringPass.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ using namespace RTStackFormat;
3434
//Lowering pass for Synchronous raytracing intrinsics known as TraceRayInline/RayQuery
3535
class TraceRayInlineLoweringPass : public FunctionPass
3636
{
37-
LoopInfo* LI;
37+
LoopInfo* LI = nullptr;
3838
public:
3939
TraceRayInlineLoweringPass() : FunctionPass(ID) {
4040
initializeTraceRayInlineLoweringPassPass(*PassRegistry::getPassRegistry());

IGC/Compiler/CISACodeGen/CShader.cpp

-19
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,6 @@ CShader::CShader(Function *pFunc, CShaderProgram *pProgram, GenericShaderState &
3737
, encoder()
3838
{
3939
m_ctx = m_parent->GetContext();
40-
m_WI = nullptr;
41-
m_deSSA = nullptr;
42-
m_coalescingEngine = nullptr;
43-
m_DL = nullptr;
44-
m_FGA = nullptr;
45-
m_VRA = nullptr;
46-
m_RLA = nullptr;
47-
m_EmitPass = nullptr;
48-
m_HW_TID = nullptr;
49-
50-
m_shaderStats = nullptr;
51-
// [OCL] preAnalysis()/ParseShaderSpecificOpcode() must
52-
// set this to ture if there is any stateless access.
53-
m_HasGlobalStatelessMemoryAccess = false;
54-
m_HasConstantStatelessMemoryAccess = false;
55-
56-
m_SavedSRetPtr = nullptr;
57-
m_FP = nullptr;
58-
m_SavedFP = nullptr;
5940

6041
bool SepSpillPvtSS = SeparateSpillAndScratch(m_ctx);
6142
bool SeparateScratchWA =

IGC/Compiler/CISACodeGen/ResourceLoopUnroll.cpp

+5-7
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,6 @@ bool ResourceLoopUnroll::emitResourceLoop(llvm::CallInst* CI)
152152

153153
GetResourceOperand(inst, resource, pairTexture, texture, sampler);
154154

155-
// either resource (ld instr), or sample instr must be available
156-
if (!resource && (!pairTexture || !texture || !sampler))
157-
{
158-
IGC_ASSERT(0);
159-
}
160-
161155
// Fill UniformSendBB
162156
builder.SetInsertPoint(checkBB);
163157

@@ -170,7 +164,7 @@ bool ResourceLoopUnroll::emitResourceLoop(llvm::CallInst* CI)
170164
resourceNew->setName("firstActiveRes");
171165
cond = builder.CreateICmpEQ(resource, resourceNew);
172166
}
173-
else // then must be sampler
167+
else if (pairTexture && texture && sampler) // then must be sampler
174168
{
175169
samplerNew = sampler;
176170
textureNew = texture;
@@ -224,6 +218,10 @@ bool ResourceLoopUnroll::emitResourceLoop(llvm::CallInst* CI)
224218
cond = samplerCond;
225219
}
226220
}
221+
else
222+
{
223+
IGC_ASSERT(0);
224+
}
227225

228226
// Here we swap the last loop load and goto, such as
229227
// From

IGC/Compiler/CISACodeGen/ShaderCodeGen.hpp

+37-34
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ class CShader
399399
SIMDMode m_SIMDSize{};
400400
uint8_t m_numberInstance = 0;
401401
PushInfo pushInfo;
402-
EmitPass* m_EmitPass;
402+
EmitPass* m_EmitPass = nullptr;
403403
uint m_sendStallCycle = 0;
404404
uint m_staticCycle = 0;
405405
uint m_loopNestedStallCycle = 0;
@@ -648,19 +648,19 @@ class CShader
648648
e_alignment preferredAlign);
649649

650650
protected:
651-
CShaderProgram* m_parent;
652-
CodeGenContext* m_ctx;
653-
WIAnalysis* m_WI;
654-
DeSSA* m_deSSA;
655-
CoalescingEngine* m_coalescingEngine;
656-
CodeGenPatternMatch* m_CG;
657-
llvm::DominatorTree* m_DT;
658-
const llvm::DataLayout* m_DL;
659-
GenXFunctionGroupAnalysis* m_FGA;
660-
VariableReuseAnalysis* m_VRA;
661-
ResourceLoopAnalysis* m_RLA;
662-
663-
IGC::IGCMD::MetaDataUtils* m_pMdUtils;
651+
CShaderProgram* m_parent = nullptr;
652+
CodeGenContext* m_ctx = nullptr;
653+
WIAnalysis* m_WI = nullptr;
654+
DeSSA* m_deSSA = nullptr;
655+
CoalescingEngine* m_coalescingEngine = nullptr;
656+
CodeGenPatternMatch* m_CG = nullptr;
657+
llvm::DominatorTree* m_DT = nullptr;
658+
const llvm::DataLayout* m_DL = nullptr;
659+
GenXFunctionGroupAnalysis* m_FGA = nullptr;
660+
VariableReuseAnalysis* m_VRA = nullptr;
661+
ResourceLoopAnalysis* m_RLA = nullptr;
662+
663+
IGC::IGCMD::MetaDataUtils* m_pMdUtils = nullptr;
664664

665665
#if defined(_DEBUG) || defined(_INTERNAL)
666666
llvm::SpecificBumpPtrAllocator<CVariable> Allocator;
@@ -698,26 +698,26 @@ class CShader
698698

699699
uint m_maxBlockId = 0;
700700

701-
CVariable* m_R0;
702-
CVariable* m_NULL;
703-
CVariable* m_TSC;
704-
CVariable* m_SR0;
705-
CVariable* m_CR0;
706-
CVariable* m_CE0;
707-
CVariable* m_MSG0;
708-
CVariable* m_DBG;
709-
CVariable* m_HW_TID;
710-
CVariable* m_SP;
711-
CVariable* m_FP;
712-
CVariable* m_SavedFP;
713-
CVariable* m_ARGV;
701+
CVariable* m_R0 = nullptr;
702+
CVariable* m_NULL = nullptr;
703+
CVariable* m_TSC = nullptr;
704+
CVariable* m_SR0 = nullptr;
705+
CVariable* m_CR0 = nullptr;
706+
CVariable* m_CE0 = nullptr;
707+
CVariable* m_MSG0 = nullptr;
708+
CVariable* m_DBG = nullptr;
709+
CVariable* m_HW_TID = nullptr;
710+
CVariable* m_SP = nullptr;
711+
CVariable* m_FP = nullptr;
712+
CVariable* m_SavedFP = nullptr;
713+
CVariable* m_ARGV = nullptr;
714714
std::array<CVariable*, NUM_ARG_SPACE_RESERVATION_SLOTS> m_ARGVReservedVariables{};
715715
uint32_t m_ARGVReservedVariablesTotalSize = 0;
716-
CVariable* m_RETV;
717-
CVariable* m_SavedSRetPtr;
718-
CVariable* m_ImplArgBufPtr;
719-
CVariable* m_LocalIdBufPtr;
720-
CVariable* m_GlobalBufferArg;
716+
CVariable* m_RETV = nullptr;
717+
CVariable* m_SavedSRetPtr = nullptr;
718+
CVariable* m_ImplArgBufPtr = nullptr;
719+
CVariable* m_LocalIdBufPtr = nullptr;
720+
CVariable* m_GlobalBufferArg = nullptr;
721721

722722
/// holds max number of inputs that can be pushed for this shader unit
723723
static const uint32_t m_pMaxNumOfPushedInputs;
@@ -731,8 +731,11 @@ class CShader
731731
// Those two are for stateful token setup. It is a quick
732732
// special case checking. Once a generic approach is added,
733733
// this two fields shall be retired.
734-
bool m_HasGlobalStatelessMemoryAccess;
735-
bool m_HasConstantStatelessMemoryAccess;
734+
//
735+
// [OCL] preAnalysis()/ParseShaderSpecificOpcode() must
736+
// set this to true if there is any stateless access.
737+
bool m_HasGlobalStatelessMemoryAccess = false;
738+
bool m_HasConstantStatelessMemoryAccess = false;
736739

737740
bool m_HasGlobalAtomics = false;
738741

IGC/Compiler/Optimizer/WaveShuffleIndexSinking.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ namespace IGC
8888
}
8989

9090
// Update ShuffleGroup members
91-
HoistOrAnchorInstsIdx = NewHoistOrAnchorInstsIdx;
91+
HoistOrAnchorInstsIdx = std::move(NewHoistOrAnchorInstsIdx);
9292
InstChains.push_back( InstChainA );
9393
InstChains.push_back( InstChainB );
9494
ShuffleOps.push_back( shuffleInst );
@@ -116,7 +116,7 @@ namespace IGC
116116
}
117117

118118
// Update ShuffleGroup members
119-
HoistOrAnchorInstsIdx = NewHoistOrAnchorInstsIdx; // this should be the same size as NewInstChain
119+
HoistOrAnchorInstsIdx = std::move(NewHoistOrAnchorInstsIdx); // this should be the same size as NewInstChain
120120
InstChains.push_back( NewInstChain );
121121
ShuffleOps.push_back( shuffleInst );
122122
return true;

IGC/WrapperLLVM/include/llvmWrapper/IR/Instructions.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ inline unsigned getArgOperandNo(llvm::CallInst &CI, const llvm::Use *U) {
202202
// calls through CB.getCalledFunction() would leave indirect calls unhandled.
203203
inline void setMemoryEffects(llvm::CallBase &CB, IGCLLVM::MemoryEffects ME) {
204204
CB.removeFnAttrs(ME.getOverridenAttrKinds());
205-
for (auto MemAttr : ME.getAsAttributeSet(CB.getContext()))
205+
for (const auto& MemAttr : ME.getAsAttributeSet(CB.getContext()))
206206
CB.addFnAttr(MemAttr);
207207
}
208208

0 commit comments

Comments
 (0)