compiler: add dereferenceable_or_null attribute where possible

This gives a hint to the compiler that such parameters are either NULL
or point to a valid object that can be dereferenced. This is not
directly very useful, but is very useful when combined with
https://reviews.llvm.org/D60047 to remove the runtime.isnil hack without
regressing escape analysis.
This commit is contained in:
Ayke van Laethem
2020-03-19 20:15:03 +01:00
committed by Ron Evans
parent 980068543a
commit 85854cd58b
4 changed files with 98 additions and 17 deletions
+4 -2
View File
@@ -125,11 +125,13 @@ func (c *compilerContext) getRawFuncType(typ *types.Signature) llvm.Type {
// The receiver is not an interface, but a i8* type.
recv = c.i8ptrType
}
paramTypes = append(paramTypes, expandFormalParamType(recv)...)
recvFragments, _ := expandFormalParamType(recv, nil)
paramTypes = append(paramTypes, recvFragments...)
}
for i := 0; i < typ.Params().Len(); i++ {
subType := c.getLLVMType(typ.Params().At(i).Type())
paramTypes = append(paramTypes, expandFormalParamType(subType)...)
paramTypeFragments, _ := expandFormalParamType(subType, nil)
paramTypes = append(paramTypes, paramTypeFragments...)
}
// All functions take these parameters at the end.
paramTypes = append(paramTypes, c.i8ptrType) // context