Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cl/_testlibgo/mapzero/expect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
runtime error: index out of range
16 changes: 16 additions & 0 deletions cl/_testlibgo/mapzero/in.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// LITTEST
package main

import "fmt"

var a = 0

func main() {
defer func() {
err := recover()
fmt.Println(err)
}()
// CHECK: call ptr @"github.com/goplus/llgo/runtime/internal/runtime.MapAccess1"(ptr @"map[_llgo_int]_llgo_int", ptr null, ptr {{%.*}})
m := [0]map[int]int{}[a][0]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit (readability): This expression is dense and tests two things at once (array bounds check + nil map representation). A short comment would help future readers:

// Index a zero-length array literal to get a nil map, then index that nil map.
// The array index panics with "index out of range" before the map access.

print(m)
}
3 changes: 0 additions & 3 deletions ssa/datastruct.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,6 @@ func (b Builder) Index(x, idx Expr, takeAddr func() (addr Expr, zero bool)) Expr
return prog.Zero(telem)
}
if ptr.IsNil() {
if x.impl.IsConstant() {
return Expr{llvm.ConstExtractElement(x.impl, idx.impl), telem}
}
ptr = b.Alloc(x.Type, false)
b.impl.CreateStore(x.impl, ptr.impl)
}
Expand Down
2 changes: 1 addition & 1 deletion ssa/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (p Program) Zero(t Type) Expr {
}
ret = p.Zero(p.rtType(name)).impl
case *types.Map:
ret = p.Zero(p.rtType("Map")).impl
ret = p.Zero(p.Pointer(p.rtType("Map"))).impl
case *types.Tuple:
n := u.Len()
flds := make([]llvm.Value, n)
Expand Down
Loading