Skip to content

Commit

Permalink
fix strndup typecast
Browse files Browse the repository at this point in the history
  • Loading branch information
douyixuan committed Aug 27, 2024
1 parent dcdeafa commit 03c5f27
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion compiler/compiler/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ func (c *Compiler) compileSubstring(src value.Value, v *parser.SliceArrayNode) v
c.contextBlock = safeBlock

offset := safeBlock.NewGetElementPtr(pointer.ElemType(srcVal), srcVal, startVar)

if length.Type() != llvmTypes.I64 {
length = c.contextBlock.NewZExt(length, i64.LLVM())
}
dst := safeBlock.NewCall(c.osFuncs.Strndup.Value.(llvmValue.Named), offset, length)

// Convert *i8 to %string
Expand Down
7 changes: 6 additions & 1 deletion compiler/compiler/strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ func (c *Compiler) compileInitializeStringWithSliceNode(v *parser.InitializeStri
srcArrStartPtr := c.contextBlock.NewGetElementPtr(pointer.ElemType(srcArr), srcArr, srcOff)
length := c.contextBlock.NewSub(srcLen, srcOff)
// create new string
strVal := c.contextBlock.NewCall(c.osFuncs.Strndup.Value.(llvmValue.Named), srcArrStartPtr, length)
var len64 llvmValue.Value
len64 = length
if length.Type() != llvmTypes.I64 {
len64 = c.contextBlock.NewZExt(length, i64.LLVM())
}
strVal := c.contextBlock.NewCall(c.osFuncs.Strndup.Value.(llvmValue.Named), srcArrStartPtr, len64)
// construct a new string {i64, i8*}
sType, ok := c.packages["global"].GetPkgType("string", true)
if !ok {
Expand Down

0 comments on commit 03c5f27

Please sign in to comment.