Skip to content

Commit e1f723e

Browse files
authored
[SYCL] Fixes to issues reported by a static analyzer run (#17550)
In the order of files in the patch, the complaints were: * uninit member - sycl-jit/common/include/Kernel.h * check error ignored - sycl-jit/jit-compiler/lib/translation/KernelTranslation.cpp * `TargetMachine` going out of scope leaking - sycl-jit/jit-compiler/lib/translation/KernelTranslation.cpp x2 * dereferencing potential null ptr - sycl-jit/passes/target/TargetFusionInfo.cpp
1 parent fb23663 commit e1f723e

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

sycl-jit/common/include/Kernel.h

+1-1
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/lib/translation/KernelTranslation.cpp

+11-6
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,13 @@ 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+
}
142+
138143
if (AddressBits != BinInfo.AddressBits) {
139144
return createStringError(
140145
inconvertibleErrorCode(),
@@ -300,9 +305,9 @@ KernelTranslator::translateToPTX(SYCLKernelInfo &KernelInfo, llvm::Module &Mod,
300305
}
301306

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

307312
llvm::legacy::PassManager PM;
308313

@@ -380,9 +385,9 @@ KernelTranslator::translateToAMDGCN(SYCLKernelInfo &KernelInfo,
380385
}
381386

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

387392
std::string AMDObj;
388393
{

sycl-jit/passes/target/TargetFusionInfo.cpp

+1
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 retrieve 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)