compiler: support creating slices with uncommon initial len/cap types

This commit is contained in:
Ayke van Laethem
2018-11-18 18:34:09 +01:00
parent 9181f2d4ce
commit 8cb7b583d8
2 changed files with 27 additions and 0 deletions
+14
View File
@@ -2420,6 +2420,20 @@ func (c *Compiler) parseExpr(frame *Frame, expr ssa.Value) (llvm.Value, error) {
// Bounds checking.
if !frame.fn.IsNoBounds() {
if sliceLen.Type().IntTypeWidth() < c.uintptrType.IntTypeWidth() {
if expr.Len.Type().(*types.Basic).Info()&types.IsUnsigned != 0 {
sliceLen = c.builder.CreateZExt(sliceLen, c.uintptrType, "")
} else {
sliceLen = c.builder.CreateSExt(sliceLen, c.uintptrType, "")
}
}
if sliceCap.Type().IntTypeWidth() < c.uintptrType.IntTypeWidth() {
if expr.Cap.Type().(*types.Basic).Info()&types.IsUnsigned != 0 {
sliceCap = c.builder.CreateZExt(sliceCap, c.uintptrType, "")
} else {
sliceCap = c.builder.CreateSExt(sliceCap, c.uintptrType, "")
}
}
c.createRuntimeCall("sliceBoundsCheckMake", []llvm.Value{sliceLen, sliceCap}, "")
}