Skip to content

Commit b38b0dc

Browse files
author
Jakub Chlanda
committed
[SYCL] Fixes to issues reported by a static analyzer run
1 parent b23d69e commit b38b0dc

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

sycl-jit/common/include/Kernel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ struct FrozenPropertyValue {
380380
FrozenPropertyValue(std::string_view Name, uint32_t Value)
381381
: Name{Name}, IsUIntValue{true}, UIntValue{Value}, Bytes{0} {}
382382
FrozenPropertyValue(std::string_view Name, const uint8_t *Ptr, size_t Size)
383-
: Name{Name}, IsUIntValue{false}, Bytes{Size} {
383+
: Name{Name}, IsUIntValue{false}, UIntValue{0}, Bytes{Size} {
384384
std::memcpy(Bytes.begin(), Ptr, Size);
385385
}
386386
};

sycl-jit/jit-compiler/include/Options.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ class OptionStorage {
4545
}
4646

4747
OptionStorage &operator=(OptionStorage &&Other) {
48+
if (this == &Other)
49+
return *this;
4850
Storage = Other.Storage;
4951
Other.Storage = nullptr;
5052
return *this;

sycl-jit/jit-compiler/lib/translation/KernelTranslation.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,12 @@ KernelTranslator::loadKernels(llvm::LLVMContext &LLVMCtx,
133133
// read last. This could cause problems if different modules contain
134134
// definitions with the same name, but different body/content.
135135
// Check that this is not problematic.
136-
Linker::linkModules(*Result, std::move(NewMod),
137-
Linker::Flags::OverrideFromSrc);
136+
const bool HasErrors = Linker::linkModules(
137+
*Result, std::move(NewMod), Linker::Flags::OverrideFromSrc);
138+
if (HasErrors)
139+
return createStringError(inconvertibleErrorCode(),
140+
"Failed to link modules");
141+
138142
if (AddressBits != BinInfo.AddressBits) {
139143
return createStringError(
140144
inconvertibleErrorCode(),
@@ -300,9 +304,9 @@ KernelTranslator::translateToPTX(SYCLKernelInfo &KernelInfo, llvm::Module &Mod,
300304
}
301305

302306
// FIXME: Check whether we can provide more accurate target information here
303-
auto *TargetMachine = Target->createTargetMachine(
307+
std::unique_ptr<TargetMachine> TargetMachine(Target->createTargetMachine(
304308
TargetTriple, CPU, Features, {}, llvm::Reloc::PIC_, std::nullopt,
305-
llvm::CodeGenOptLevel::Default);
309+
llvm::CodeGenOptLevel::Default));
306310

307311
llvm::legacy::PassManager PM;
308312

@@ -380,9 +384,9 @@ KernelTranslator::translateToAMDGCN(SYCLKernelInfo &KernelInfo,
380384
}
381385

382386
// FIXME: Check whether we can provide more accurate target information here
383-
auto *TargetMachine = Target->createTargetMachine(
387+
std::unique_ptr<TargetMachine> TargetMachine(Target->createTargetMachine(
384388
TargetTriple, CPU, Features, {}, llvm::Reloc::PIC_, std::nullopt,
385-
llvm::CodeGenOptLevel::Default);
389+
llvm::CodeGenOptLevel::Default));
386390

387391
std::string AMDObj;
388392
{

sycl-jit/passes/target/TargetFusionInfo.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ class NVPTXAMDGCNTargetFusionInfoBase : public TargetFusionInfoImpl {
458458
SmallPtrSet<Constant *, 8> DeletedFuncs{Funcs.begin(), Funcs.end()};
459459
SmallVector<MDNode *> ValidKernels;
460460
auto *OldAnnotations = LLVMMod->getNamedMetadata(MDName);
461+
assert(OldAnnotations && "Failed to retreive old annotations");
461462
for (auto *Op : OldAnnotations->operands()) {
462463
if (auto *TOp = dyn_cast<MDTuple>(Op)) {
463464
if (auto *COp = dyn_cast_if_present<ConstantAsMetadata>(

0 commit comments

Comments
 (0)