mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-23 08:47:56 +01:00
check: add maxPointerBounds and funcBounds
This commit is contained in:
1 parent
8ac22ceab2
commit
6411561deb
3 files changed
+20
-6
No files matched your search
+18
-4
@@ -65,6 +65,20 @@ var (
|
|||||||
oneTwentyEight = big.NewInt(+128)
|
oneTwentyEight = big.NewInt(+128)
|
||||||
ffff = big.NewInt(0xFFFF)
|
ffff = big.NewInt(0xFFFF)
|
||||||
|
|
||||||
|
// maxPointerBounds is the artificial value in the [0 ..= maxPointerBounds]
|
||||||
|
// range for bounds-checking pointer-typed values. Its value is arbitrary
|
||||||
|
// (but greater than 1).
|
||||||
|
//
|
||||||
|
// It is positive (not 0) to distinguish nullptr from non-nullptr. More
|
||||||
|
// subtly, it is greater than 1 so that two non-nullptr pointer-typed
|
||||||
|
// values aren't necessarily equal.
|
||||||
|
maxPointerBounds = big.NewInt(1234)
|
||||||
|
|
||||||
|
// funcBounds is the artificial value in the [1 ..= funcBounds] range for
|
||||||
|
// bounds-checking function-typed values. Its value is arbitrary (but
|
||||||
|
// greater than 1) for the same reasons as maxPointerBounds.
|
||||||
|
funcBounds = big.NewInt(5678)
|
||||||
|
|
||||||
minIdeal = big.NewInt(0).Lsh(minusOne, 1000)
|
minIdeal = big.NewInt(0).Lsh(minusOne, 1000)
|
||||||
maxIdeal = big.NewInt(0).Lsh(one, 1000)
|
maxIdeal = big.NewInt(0).Lsh(one, 1000)
|
||||||
|
|
||||||
@@ -1507,7 +1521,7 @@ func makeConstValueExpr(tm *t.Map, cv *big.Int) (*a.Expr, error) {
|
|||||||
// makeSliceLength returns "x.length()".
|
// makeSliceLength returns "x.length()".
|
||||||
func makeSliceLength(slice *a.Expr) *a.Expr {
|
func makeSliceLength(slice *a.Expr) *a.Expr {
|
||||||
x := a.NewExpr(0, t.IDDot, t.IDLength, slice.AsNode(), nil, nil, nil)
|
x := a.NewExpr(0, t.IDDot, t.IDLength, slice.AsNode(), nil, nil, nil)
|
||||||
x.SetMBounds(bounds{one, one})
|
x.SetMBounds(bounds{funcBounds, funcBounds})
|
||||||
x.SetMType(a.NewTypeExpr(t.IDFunc, 0, t.IDLength, slice.MType().AsNode(), nil, nil))
|
x.SetMType(a.NewTypeExpr(t.IDFunc, 0, t.IDLength, slice.MType().AsNode(), nil, nil))
|
||||||
x = a.NewExpr(0, t.IDOpenParen, 0, x.AsNode(), nil, nil, nil)
|
x = a.NewExpr(0, t.IDOpenParen, 0, x.AsNode(), nil, nil, nil)
|
||||||
// TODO: call SetMBounds?
|
// TODO: call SetMBounds?
|
||||||
@@ -1785,11 +1799,11 @@ func (q *checker) bcheckTypeExpr1(typ *a.TypeExpr) (bounds, error) {
|
|||||||
if _, err := q.bcheckTypeExpr(typ.Receiver()); err != nil {
|
if _, err := q.bcheckTypeExpr(typ.Receiver()); err != nil {
|
||||||
return bounds{}, err
|
return bounds{}, err
|
||||||
}
|
}
|
||||||
return bounds{one, one}, nil
|
return bounds{one, funcBounds}, nil
|
||||||
case t.IDNptr:
|
case t.IDNptr:
|
||||||
return bounds{zero, one}, nil
|
return bounds{zero, maxPointerBounds}, nil
|
||||||
case t.IDPtr:
|
case t.IDPtr:
|
||||||
return bounds{one, one}, nil
|
return bounds{one, maxPointerBounds}, nil
|
||||||
case t.IDRoslice, t.IDRotable, t.IDSlice, t.IDTable:
|
case t.IDRoslice, t.IDRotable, t.IDSlice, t.IDTable:
|
||||||
return bounds{zero, zero}, nil
|
return bounds{zero, zero}, nil
|
||||||
default:
|
default:
|
||||||
|
|||||||
+1
-1
@@ -648,7 +648,7 @@ func (c *Checker) checkFuncSignature1(node *a.Node, banCPUArchTypes bool) error
|
|||||||
sTyp.AsNode().SetMType(typeExprTypeExpr)
|
sTyp.AsNode().SetMType(typeExprTypeExpr)
|
||||||
|
|
||||||
pTyp := a.NewTypeExpr(t.IDPtr, 0, 0, nil, nil, sTyp)
|
pTyp := a.NewTypeExpr(t.IDPtr, 0, 0, nil, nil, sTyp)
|
||||||
pTyp.AsNode().SetMBounds(bounds{one, one})
|
pTyp.AsNode().SetMBounds(bounds{one, maxPointerBounds})
|
||||||
pTyp.AsNode().SetMType(typeExprTypeExpr)
|
pTyp.AsNode().SetMType(typeExprTypeExpr)
|
||||||
|
|
||||||
localVars[t.IDThis] = pTyp
|
localVars[t.IDThis] = pTyp
|
||||||
|
|||||||
+1
-1
@@ -1232,7 +1232,7 @@ func (q *checker) tcheckChoose(n *a.Choose) error {
|
|||||||
return fmt.Errorf("check: incompatible choose functions %q and %q: %v",
|
return fmt.Errorf("check: incompatible choose functions %q and %q: %v",
|
||||||
fQQID.Str(q.tm), gQQID.Str(q.tm), err)
|
fQQID.Str(q.tm), gQQID.Str(q.tm), err)
|
||||||
}
|
}
|
||||||
o.SetMBounds(bounds{one, one})
|
o.SetMBounds(bounds{one, maxPointerBounds})
|
||||||
o.SetMType(typeExprNonNullptr)
|
o.SetMType(typeExprNonNullptr)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
Reference in new issue
Block a user