Open qiulaidongfeng opened 9 months ago
l.str[l.i] memory is not accessed out of bounds, and this boundary check can be eliminated.
l.i
might be negative in theory. That is the cause of the bound check.
Though, for this specified case, the compiler can be smarter. (But worthy it?).
l.i
might be negative in theory. That is the cause of the bound check. Though, for this specified case, the compiler can be smarter. (But worthy it?).
This issue was discovered in the lexer of a real open source project : https://gitee.com/u-language/u-language/blob/master/ucom/lex2/lex.go
If you have a way to make the code linked above have no boundary check without using unsafe. Can prove not worth the compiler can be more smarter.
Go version
go version devel go1.22-78b42a5338a Fri Dec 8 03:28:17 2023 +0000 linux/amd64
What operating system and processor architecture are you using (
go env
)?What did you do?
What did you expect to see?
No Boundary check.
What did you see instead?
Have Boundary check.