mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-04 19:17:47 +00:00
compiler: implement nil checks
This commit implements nil checks for all platforms. These nil checks
can be optimized on systems with a MMU, but since a major target is
systems without MMU, keep it this way for now.
It implements three checks:
* Nil checks before dereferencing a pointer.
* Nil checks before calculating an address (*ssa.FieldAddr and
*ssa.IndexAddr)
* Nil checks before calling a function pointer.
The first check has by far the biggest impact, with around 5% increase
in code size. The other checks only trigger in only some test cases and
have a minimal impact on code size.
This first nil check is also the one that is easiest to avoid on systems
with MMU, if necessary.
This commit is contained in:
committed by
Ron Evans
parent
b7cdf8cd0c
commit
622d0ebde6
@@ -27,6 +27,11 @@ func _recover() interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Panic when trying to dereference a nil pointer.
|
||||
func nilpanic() {
|
||||
runtimePanic("nil pointer dereference")
|
||||
}
|
||||
|
||||
// Check for bounds in *ssa.Index, *ssa.IndexAddr and *ssa.Lookup.
|
||||
func lookupBoundsCheck(length uintptr, index int) {
|
||||
if index < 0 || index >= int(length) {
|
||||
|
||||
Reference in New Issue
Block a user