compiler: zero-sized slice lengths truncate to 16 bits on AVR

Đang mở
#6,175 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
54/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
arduino, go
Lĩnh vực
compilers, embedded-iot

Hướng nghiên cứu

Start with the AVR slice length conversion in compiler/compiler.go, then trace sliceAppend and sliceGrow in src/runtime/slice.go; issue #6174 covers related overflow behavior on other targets. Reproduce the listed zero-sized slice cases on arduino-uno under qemu-system-avr. Done means the reported lengths and capacities are preserved or rejected with a compile error, and the runtime cases no longer wrap or produce invalid capacities.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

On AVR, int is 32 bits but uintptr is 16 bits. Slice headers store len and cap as uintptr. A slice of zero-sized elements needs no memory, so its length can exceed 65535 on AVR. Some paths truncate these lengths and do not report an error.

Results on arduino-uno under qemu-system-avr -M uno:

Program Result Expected
var a [65536]struct{}; s := a[:] len 0, cap 0 len 65536, cap 65536
make([]struct{}, 65536) with a constant length len 0, cap 0 len 65536, cap 65536, or a compile error
make([]struct{}, n) with n 65536 at run time panic: slice out of range same as the constant case
s := make([]struct{}, 32768); s = append(s, struct{}{}) len 32769, cap 0 cap >= len
s := make([]struct{}, 65535); s = append(s, struct{}{}) len 0, cap 65535 len 65536

The array conversion creates the length with llvm.ConstInt(b.uintptrType, uint64(length), false) in compiler/compiler.go. This drops the upper bits. The constant make also truncates its length, but the run-time make checks it. The two append results come from sliceAppend and sliceGrow in src/runtime/slice.go. #6174 covers overflow in these functions on other targets.

unsafe.Slice and reflect.MakeSlice reject these lengths, so they do not wrap. A suspected index bounds problem did not occur in QEMU: a dynamic a[65535] on a [65536]struct{} array succeeded and a[65536] panicked.

Ngôn ngữ chính
Go
Star
17.8k
Fork
1.1k
Merge trung bình
1 ngày 4 giờ
Pull request đã merge (30 ngày)
380

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của tinygo-org/tinygo

Tất cả issue của tinygo-org/tinygo

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.