Skip to content

Commit 85a10e2

Browse files
authored
Access out of scope fix in OCLToSPIRVBase::transBuiltin (#2262)
OldRetTy pointer was passed to lambda by reference. This means that in lambda it's real C-like type was Value ** pointing to the stack within of the transBuiltin stack frame. Logic of lambda is executed in doConversion function executed in destructor of BuiltinCallMutator. The stack frame is unaccessible during the destructor call and it worked only as undfined behaviour.
1 parent 0166a0f commit 85a10e2

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

lib/SPIRV/OCLToSPIRV.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -912,16 +912,16 @@ void OCLToSPIRVBase::transBuiltin(CallInst *CI, OCLBuiltinTransInfo &Info) {
912912
Info.UniqName = getSPIRVFuncName(BVKind);
913913
} else
914914
return;
915-
auto Mutator = mutateCallInst(CI, Info.UniqName + Info.Postfix);
915+
BuiltinCallMutator Mutator = mutateCallInst(CI, Info.UniqName + Info.Postfix);
916916
Info.PostProc(Mutator);
917917
if (Info.RetTy) {
918918
Type *OldRetTy = CI->getType();
919919
Mutator.changeReturnType(
920-
Info.RetTy, [&](IRBuilder<> &Builder, CallInst *NewCI) {
921-
if (Info.RetTy->isIntegerTy() && OldRetTy->isIntegerTy())
920+
Info.RetTy, [OldRetTy, &Info](IRBuilder<> &Builder, CallInst *NewCI) {
921+
if (Info.RetTy->isIntegerTy() && OldRetTy->isIntegerTy()) {
922922
return Builder.CreateIntCast(NewCI, OldRetTy, Info.IsRetSigned);
923-
else
924-
return Builder.CreatePointerBitCastOrAddrSpaceCast(NewCI, OldRetTy);
923+
}
924+
return Builder.CreatePointerBitCastOrAddrSpaceCast(NewCI, OldRetTy);
925925
});
926926
}
927927
}

0 commit comments

Comments
 (0)