transform: track 0-index GEPs

It appears that LLVM is turning bitcasts into 0-index GEPs.
This caused stuff to not be tracked, resulting in use-after-free issues.
This solution is sub-optimal, but is the most reasonable solution I could come up with without redesigning the stack slots pass.
This commit is contained in:
Jaden Weiss
2020-07-15 18:15:27 -04:00
committed by Ayke
parent ae5b297d59
commit 19e0f4709e
3 changed files with 61 additions and 13 deletions
+18 -4
View File
@@ -151,10 +151,24 @@ func MakeGCStackSlots(mod llvm.Module) bool {
}
switch ptr.InstructionOpcode() {
case llvm.GetElementPtr:
// These values do not create new values: the values already
// existed locally in this function so must have been tracked
// already.
continue
// Check for all zero offsets.
// Sometimes LLVM rewrites bitcasts to zero-index GEPs, and we still need to track the GEP.
n := ptr.OperandsCount()
var hasOffset bool
for i := 1; i < n; i++ {
offset := ptr.Operand(i)
if offset.IsAConstantInt().IsNil() || offset.ZExtValue() != 0 {
hasOffset = true
break
}
}
if hasOffset {
// These values do not create new values: the values already
// existed locally in this function so must have been tracked
// already.
continue
}
case llvm.PHI:
// While the value may have already been tracked, it may be overwritten in a loop.
// Therefore, a second copy must be created to ensure that it is tracked over the entirety of its lifetime.