Skip to content

Commit

Permalink
Fix unchecked nullptr dereferences
Browse files Browse the repository at this point in the history
Fix cases where we create a potential nullptr dereference.
  • Loading branch information
fda0 authored and igcbot committed Jan 8, 2024
1 parent 2ebdd35 commit 5f6eb9d
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 12 deletions.
2 changes: 0 additions & 2 deletions IGC/AdaptorCommon/LegalizeFunctionSignatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ class LegalizeFunctionSignatures : public llvm::ModulePass

LegalizeFunctionSignatures();

~LegalizeFunctionSignatures() {}

virtual void getAnalysisUsage(llvm::AnalysisUsage& AU) const
{
AU.addRequired<IGC::CodeGenContextWrapper>();
Expand Down
6 changes: 3 additions & 3 deletions IGC/AdaptorOCL/dllInterfaceCompute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1002,11 +1002,11 @@ void RebuildGlobalAnnotations(IGC::OpenCLProgramContext& oclContext, Module* pKe
};

std::vector<Constant*> newGlobalAnnotations;
auto annotations_array = dyn_cast<ConstantArray>(globalAnnotations->getOperand(0));
auto annotations_array = cast<ConstantArray>(globalAnnotations->getOperand(0));
for (const auto& op : annotations_array->operands())
{
auto annotation_struct = dyn_cast<ConstantStruct>(op.get());
auto annotated_function = dyn_cast<Function>(annotation_struct->getOperand(0)->getOperand(0));
auto annotation_struct = cast<ConstantStruct>(op.get());
auto annotated_function = cast<Function>(annotation_struct->getOperand(0)->getOperand(0));

if (requiresRecompilation(annotated_function))
{
Expand Down
2 changes: 1 addition & 1 deletion IGC/Compiler/CISACodeGen/CISABuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8677,7 +8677,7 @@ namespace IGC
LSC_OP subOp = getLSCAtomicOpCode(atomic_op);

VISA_PredOpnd* predOpnd = GetFlagOperand(m_encoderState.m_flag);
LSC_ADDR addr;
LSC_ADDR addr = {};
VISA_VectorOpnd* globalOffsetOpnd = nullptr;
addr.type = LSC_ADDR_TYPE_FLAT;

Expand Down
2 changes: 1 addition & 1 deletion IGC/Compiler/CISACodeGen/CheckInstrTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ void CheckInstrTypes::checkGlobalLocal(llvm::Instruction& I)
BasicBlock* dBB = I.getParent();

for (auto U : I.users()) {
auto UI = dyn_cast<Instruction>(U);
auto UI = cast<Instruction>(U);
BasicBlock* uBB = UI->getParent();
if (uBB != dBB)
{
Expand Down
2 changes: 1 addition & 1 deletion IGC/Compiler/CISACodeGen/helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2686,7 +2686,7 @@ namespace IGC

for (auto UI = ptr->user_begin(), E = ptr->user_end(); UI != E; ++UI)
{
Instruction* inst = dyn_cast<Instruction>(*UI);
Instruction* inst = cast<Instruction>(*UI);
PointerType* instType = nullptr;
if (isa<BitCastInst>(inst) || isa<GetElementPtrInst>(inst) ||
isa<AddrSpaceCastInst>(inst) || isa<PHINode>(inst))
Expand Down
2 changes: 1 addition & 1 deletion IGC/Compiler/CustomUnsafeOptPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ bool CustomUnsafeOptPass::visitBinaryOperatorExtractCommonMultiplier(BinaryOpera
previousRoot = currentRoot;
if (removeCommonMultiplier(sumComponent, commonMultiplier))
{
currentRoot = dyn_cast<Instruction>(*currentRoot->user_begin());
currentRoot = llvm::cast<Instruction>(*currentRoot->user_begin());
sumComponent = llvm::dyn_cast<llvm::Instruction>(currentRoot->getOperand(1));
patternFound = true;
}
Expand Down
2 changes: 1 addition & 1 deletion IGC/Compiler/LegalizationPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ void Legalization::visitInstruction(llvm::Instruction& I)
BasicBlock* dBB = I.getParent();

for (auto U : I.users()) {
auto UI = dyn_cast<Instruction>(U);
auto UI = cast<Instruction>(U);
BasicBlock* uBB = UI->getParent();
if (uBB != dBB)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1699,7 +1699,7 @@ Type *JointMatrixFuncsResolutionPass::ResolveArrayType(Type *oldType)
if (ResolvedTypes.count(oldType) > 0)
return ResolvedTypes[oldType];

ArrayType *arrayType = dyn_cast<ArrayType>(oldType);
ArrayType *arrayType = cast<ArrayType>(oldType);
Type *elemType = arrayType->getElementType();
if (!isOrContainsMatrixType(elemType))
return oldType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ static void sinkAllocaSingleUse(SmallVectorImpl<AllocaInst*>& Allocas) {
{
bool Skip = false;
SmallVector<Instruction*, 8> UInsts;
auto UI = dyn_cast<Instruction>(A);
auto UI = cast<Instruction>(A);
// can't sink phi nodes to other BBs
// can't sink loads since we don't check for stores on the way
if (isa<PHINode>(UI) || UI->mayReadFromMemory())
Expand Down

0 comments on commit 5f6eb9d

Please sign in to comment.