Skip to content

Commit

Permalink
[SYCL] Fixed issues found by static code analysis.
Browse files Browse the repository at this point in the history
Signed-off-by: Vladimir Lazarev <vladimir.lazarev@intel.com>
  • Loading branch information
vladimirlaz committed Jan 23, 2019
1 parent 6adb425 commit a36d83a
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 11 deletions.
5 changes: 4 additions & 1 deletion clang/lib/CodeGen/OclCxxRewrite/BifNameReflower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ struct OclCxxBiAdaptTraits {
if (!EffectiveTArg->isExpression())
return nullptr;
auto Expr = EffectiveTArg->getExpression();
assert(Expr && "No expression info.");
switch (Expr->getKind()) {
case DXK_TemplateParam:
EffectiveTArg = Expr->getAs<DXK_TemplateParam>()
Expand Down Expand Up @@ -899,7 +900,9 @@ struct OclCxxBiAdaptTraits {

if (Node->getSpecialKind() != DSNK_TypeInfoNameString)
return std::make_pair(printer::AR_Failure, nullptr);
auto RelTypeNameNode = Node->getRelatedType()->getAs<DTK_TypeName>();
auto RelType = Node->getRelatedType();
assert(RelType && "No related type info.");
auto RelTypeNameNode = RelType->getAs<DTK_TypeName>();
if (RelTypeNameNode == nullptr)
return std::make_pair(printer::AR_Failure, nullptr);

Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/OclCxxRewrite/OclCxxPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -1190,7 +1190,7 @@ struct ItaniumEncodeTraits

if (Value.isExpression()) {
const auto &Expr = Value.getExpression();

assert(Expr && "No expression info");
if (Expr->getKind() == DXK_Primary || IsUnwrappedExprAllowed)
return encode(Out, Value.getExpression());

Expand Down
2 changes: 2 additions & 0 deletions clang/lib/Sema/SemaSYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ CreateSYCLKernelBody(Sema &S, FunctionDecl *KernelCallerFunc, DeclContext *DC) {
KernelObjClone, false, DeclarationNameInfo(),
QualType(LC->getTypeForDecl(), 0), VK_LValue);
auto TargetFunc = dyn_cast<FunctionDecl>(DC);
assert(TargetFunc && "Not FunctionDecl");
auto TargetFuncParam =
TargetFunc->param_begin(); // Iterator to ParamVarDecl (VarDecl)
if (TargetFuncParam) {
Expand Down Expand Up @@ -710,6 +711,7 @@ void Sema::ConstructSYCLKernel(FunctionDecl *KernelCallerFunc) {
// Get Name for our kernel.
const TemplateArgumentList *TemplateArgs =
KernelCallerFunc->getTemplateSpecializationArgs();
assert(TemplateArgs && "No template argument info");
// The first teamplate argument always describes the kernel name - whether
// it is lambda or functor.
QualType KernelNameType = TypeName::getFullyQualifiedType(
Expand Down
8 changes: 6 additions & 2 deletions llvm/lib/SYCL/ASFixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ static void collectTypeReplacementData(Type *OldTy, Type *NewTy,
Value *OldValUser = U.getUser();

if (CallInst *Call = dyn_cast<CallInst>(OldValUser)) {
assert(Call->getCalledFunction() && "Indirect function call?");
auto F = Call->getCalledFunction();
assert(F && "Indirect function call?");
FunctionType *&FuncReplacementType = FTyMap[Call->getCalledFunction()];
if (!FuncReplacementType)
FuncReplacementType = F->getFunctionType();
Expand Down Expand Up @@ -346,9 +346,11 @@ static void traceAddressSpace(AddrSpaceCastInst *AS,
if (auto Call = dyn_cast<CallInst>(User)) {
WorkList.push(std::make_pair(AS, NewAS));
auto F = Call->getCalledFunction();
assert(F && "No function info.");
for (auto &Arg : F->args()) {
if (Arg.getType() == OldTy) {
auto ActArg = Call->getArgOperand(Arg.getArgNo());
assert(ActArg && "No argument info.");
if (!isa<AddrSpaceCastInst>(ActArg)) {
AddrSpaceCastInst *AddAS =
new AddrSpaceCastInst(ActArg, NewTy, "", Call);
Expand Down Expand Up @@ -481,8 +483,10 @@ static bool needToReplaceAlloca(AllocaInst *Alloca,
Value *NextUsr = nullptr;
if (CallInst *Call = dyn_cast<CallInst>(Usr)) {
if (VMap[Call]) {
auto F = Call->getCalledFunction();
assert(F && "No function info.");
NextUsr =
getAllocaOrArgValue(Call->getCalledFunction(), U.getOperandNo());
getAllocaOrArgValue(F, U.getOperandNo());
}
} else {
NextUsr = Usr;
Expand Down
3 changes: 2 additions & 1 deletion sycl/include/CL/sycl/detail/scheduler/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ void ExecuteKernelCommand<
if (m_Queue->is_host()) {
detail::waitEvents(DepEvents);
Event->setIsHostEvent(true);
return runOnHost();
runOnHost();
return;
}

if (!m_ClKernel) {
Expand Down
11 changes: 5 additions & 6 deletions sycl/source/detail/program_manager/program_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ cl_program ProgramManager::getClProgramFromClKernel(cl_kernel ClKernel) {
const vector_class<char> ProgramManager::getSpirvSource() {
// TODO FIXME make this function thread-safe
if (!m_SpirvSource) {
vector_class<char> *DataPtr = nullptr;

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

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

if (!F.is_open())
throw compile_program_error("Can not write kernel.spv\n");

F.write(BegPtr, ImgSize);
F.close();
}
Expand All @@ -170,12 +170,11 @@ const vector_class<char> ProgramManager::getSpirvSource() {
throw compile_program_error("Can not open kernel.spv\n");
}
File.seekg(0, std::ios::end);
DataPtr = new vector_class<char>(File.tellg());
m_SpirvSource.reset(new vector_class<char>(File.tellg()));
File.seekg(0);
File.read(DataPtr->data(), DataPtr->size());
File.read(m_SpirvSource->data(), m_SpirvSource->size());
File.close();
}
m_SpirvSource.reset(DataPtr);
}
// TODO makes unnecessary copy of the data
return *m_SpirvSource.get();
Expand Down

0 comments on commit a36d83a

Please sign in to comment.