Skip to content

Commit a36d83a

Browse files
committed
[SYCL] Fixed issues found by static code analysis.
Signed-off-by: Vladimir Lazarev <[email protected]>
1 parent 6adb425 commit a36d83a

File tree

6 files changed

+20
-11
lines changed

6 files changed

+20
-11
lines changed

clang/lib/CodeGen/OclCxxRewrite/BifNameReflower.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ struct OclCxxBiAdaptTraits {
336336
if (!EffectiveTArg->isExpression())
337337
return nullptr;
338338
auto Expr = EffectiveTArg->getExpression();
339+
assert(Expr && "No expression info.");
339340
switch (Expr->getKind()) {
340341
case DXK_TemplateParam:
341342
EffectiveTArg = Expr->getAs<DXK_TemplateParam>()
@@ -899,7 +900,9 @@ struct OclCxxBiAdaptTraits {
899900

900901
if (Node->getSpecialKind() != DSNK_TypeInfoNameString)
901902
return std::make_pair(printer::AR_Failure, nullptr);
902-
auto RelTypeNameNode = Node->getRelatedType()->getAs<DTK_TypeName>();
903+
auto RelType = Node->getRelatedType();
904+
assert(RelType && "No related type info.");
905+
auto RelTypeNameNode = RelType->getAs<DTK_TypeName>();
903906
if (RelTypeNameNode == nullptr)
904907
return std::make_pair(printer::AR_Failure, nullptr);
905908

clang/lib/CodeGen/OclCxxRewrite/OclCxxPrinter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,7 @@ struct ItaniumEncodeTraits
11901190

11911191
if (Value.isExpression()) {
11921192
const auto &Expr = Value.getExpression();
1193-
1193+
assert(Expr && "No expression info");
11941194
if (Expr->getKind() == DXK_Primary || IsUnwrappedExprAllowed)
11951195
return encode(Out, Value.getExpression());
11961196

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ CreateSYCLKernelBody(Sema &S, FunctionDecl *KernelCallerFunc, DeclContext *DC) {
371371
KernelObjClone, false, DeclarationNameInfo(),
372372
QualType(LC->getTypeForDecl(), 0), VK_LValue);
373373
auto TargetFunc = dyn_cast<FunctionDecl>(DC);
374+
assert(TargetFunc && "Not FunctionDecl");
374375
auto TargetFuncParam =
375376
TargetFunc->param_begin(); // Iterator to ParamVarDecl (VarDecl)
376377
if (TargetFuncParam) {
@@ -710,6 +711,7 @@ void Sema::ConstructSYCLKernel(FunctionDecl *KernelCallerFunc) {
710711
// Get Name for our kernel.
711712
const TemplateArgumentList *TemplateArgs =
712713
KernelCallerFunc->getTemplateSpecializationArgs();
714+
assert(TemplateArgs && "No template argument info");
713715
// The first teamplate argument always describes the kernel name - whether
714716
// it is lambda or functor.
715717
QualType KernelNameType = TypeName::getFullyQualifiedType(

llvm/lib/SYCL/ASFixer.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,8 @@ static void collectTypeReplacementData(Type *OldTy, Type *NewTy,
245245
Value *OldValUser = U.getUser();
246246

247247
if (CallInst *Call = dyn_cast<CallInst>(OldValUser)) {
248-
assert(Call->getCalledFunction() && "Indirect function call?");
249248
auto F = Call->getCalledFunction();
249+
assert(F && "Indirect function call?");
250250
FunctionType *&FuncReplacementType = FTyMap[Call->getCalledFunction()];
251251
if (!FuncReplacementType)
252252
FuncReplacementType = F->getFunctionType();
@@ -346,9 +346,11 @@ static void traceAddressSpace(AddrSpaceCastInst *AS,
346346
if (auto Call = dyn_cast<CallInst>(User)) {
347347
WorkList.push(std::make_pair(AS, NewAS));
348348
auto F = Call->getCalledFunction();
349+
assert(F && "No function info.");
349350
for (auto &Arg : F->args()) {
350351
if (Arg.getType() == OldTy) {
351352
auto ActArg = Call->getArgOperand(Arg.getArgNo());
353+
assert(ActArg && "No argument info.");
352354
if (!isa<AddrSpaceCastInst>(ActArg)) {
353355
AddrSpaceCastInst *AddAS =
354356
new AddrSpaceCastInst(ActArg, NewTy, "", Call);
@@ -481,8 +483,10 @@ static bool needToReplaceAlloca(AllocaInst *Alloca,
481483
Value *NextUsr = nullptr;
482484
if (CallInst *Call = dyn_cast<CallInst>(Usr)) {
483485
if (VMap[Call]) {
486+
auto F = Call->getCalledFunction();
487+
assert(F && "No function info.");
484488
NextUsr =
485-
getAllocaOrArgValue(Call->getCalledFunction(), U.getOperandNo());
489+
getAllocaOrArgValue(F, U.getOperandNo());
486490
}
487491
} else {
488492
NextUsr = Usr;

sycl/include/CL/sycl/detail/scheduler/commands.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ void ExecuteKernelCommand<
3737
if (m_Queue->is_host()) {
3838
detail::waitEvents(DepEvents);
3939
Event->setIsHostEvent(true);
40-
return runOnHost();
40+
runOnHost();
41+
return;
4142
}
4243

4344
if (!m_ClKernel) {

sycl/source/detail/program_manager/program_manager.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ cl_program ProgramManager::getClProgramFromClKernel(cl_kernel ClKernel) {
142142
const vector_class<char> ProgramManager::getSpirvSource() {
143143
// TODO FIXME make this function thread-safe
144144
if (!m_SpirvSource) {
145-
vector_class<char> *DataPtr = nullptr;
146145

147146
if (DeviceImages && !std::getenv("SYCL_USE_KERNEL_SPV")) {
148147
assert(DeviceImages->NumDeviceImages == 1 &&
@@ -151,16 +150,17 @@ const vector_class<char> ProgramManager::getSpirvSource() {
151150
auto *BegPtr = reinterpret_cast<const char *>(Img.ImageStart);
152151
auto *EndPtr = reinterpret_cast<const char *>(Img.ImageEnd);
153152
ptrdiff_t ImgSize = EndPtr - BegPtr;
154-
DataPtr = new vector_class<char>(static_cast<size_t>(ImgSize));
153+
m_SpirvSource.reset(new vector_class<char>(static_cast<size_t>(ImgSize)));
155154
// TODO this code is expected to be heavily refactored, this copying
156155
// might be redundant (unless we don't want to work on live .rodata)
157-
std::copy(BegPtr, EndPtr, DataPtr->begin());
156+
std::copy(BegPtr, EndPtr, m_SpirvSource->begin());
158157

159158
if (std::getenv("SYCL_DUMP_IMAGES")) {
160159
std::ofstream F("kernel.spv", std::ios::binary);
161160

162161
if (!F.is_open())
163162
throw compile_program_error("Can not write kernel.spv\n");
163+
164164
F.write(BegPtr, ImgSize);
165165
F.close();
166166
}
@@ -170,12 +170,11 @@ const vector_class<char> ProgramManager::getSpirvSource() {
170170
throw compile_program_error("Can not open kernel.spv\n");
171171
}
172172
File.seekg(0, std::ios::end);
173-
DataPtr = new vector_class<char>(File.tellg());
173+
m_SpirvSource.reset(new vector_class<char>(File.tellg()));
174174
File.seekg(0);
175-
File.read(DataPtr->data(), DataPtr->size());
175+
File.read(m_SpirvSource->data(), m_SpirvSource->size());
176176
File.close();
177177
}
178-
m_SpirvSource.reset(DataPtr);
179178
}
180179
// TODO makes unnecessary copy of the data
181180
return *m_SpirvSource.get();

0 commit comments

Comments
 (0)