mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-23 16:52:18 +01:00
Stop bounds checking after a jump or return.
This commit is contained in:
1 parent
5cce3afe4c
commit
f6cc7950ff
2 files changed
+25
-21
No files matched your search
+18
-12
@@ -145,6 +145,18 @@ func bcheckField(idMap *t.IDMap, n *a.Field) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (q *checker) bcheckBlock(block []*a.Node) error {
|
||||||
|
for _, o := range block {
|
||||||
|
if err := q.bcheckStatement(o); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if k := o.Kind(); k == a.KJump || k == a.KReturn {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (q *checker) bcheckStatement(n *a.Node) error {
|
func (q *checker) bcheckStatement(n *a.Node) error {
|
||||||
q.errFilename, q.errLine = n.Raw().FilenameLine()
|
q.errFilename, q.errLine = n.Raw().FilenameLine()
|
||||||
|
|
||||||
@@ -385,10 +397,8 @@ func (q *checker) bcheckIf(n *a.If) error {
|
|||||||
|
|
||||||
// Check the if-true branch, assuming the if condition.
|
// Check the if-true branch, assuming the if condition.
|
||||||
q.facts.appendFact(n.Condition())
|
q.facts.appendFact(n.Condition())
|
||||||
for _, o := range n.BodyIfTrue() {
|
if err := q.bcheckBlock(n.BodyIfTrue()); err != nil {
|
||||||
if err := q.bcheckStatement(o); err != nil {
|
return err
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if !terminates(n.BodyIfTrue()) {
|
if !terminates(n.BodyIfTrue()) {
|
||||||
branches = append(branches, snapshot(q.facts))
|
branches = append(branches, snapshot(q.facts))
|
||||||
@@ -402,10 +412,8 @@ func (q *checker) bcheckIf(n *a.If) error {
|
|||||||
q.facts.appendFact(inverse)
|
q.facts.appendFact(inverse)
|
||||||
}
|
}
|
||||||
if bif := n.BodyIfFalse(); len(bif) > 0 {
|
if bif := n.BodyIfFalse(); len(bif) > 0 {
|
||||||
for _, o := range bif {
|
if err := q.bcheckBlock(bif); err != nil {
|
||||||
if err := q.bcheckStatement(o); err != nil {
|
return err
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if !terminates(bif) {
|
if !terminates(bif) {
|
||||||
branches = append(branches, snapshot(q.facts))
|
branches = append(branches, snapshot(q.facts))
|
||||||
@@ -494,10 +502,8 @@ func (q *checker) bcheckWhile(n *a.While) error {
|
|||||||
q.facts.appendFact(n.Condition())
|
q.facts.appendFact(n.Condition())
|
||||||
}
|
}
|
||||||
// Check the body.
|
// Check the body.
|
||||||
for _, o := range n.Body() {
|
if err := q.bcheckBlock(n.Body()); err != nil {
|
||||||
if err := q.bcheckStatement(o); err != nil {
|
return err
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Check the pre and inv conditions on the implicit continue after the
|
// Check the pre and inv conditions on the implicit continue after the
|
||||||
// body.
|
// body.
|
||||||
|
|||||||
+7
-9
@@ -333,15 +333,13 @@ func (c *Checker) checkFuncBody(node *a.Node) error {
|
|||||||
|
|
||||||
// Run bounds checks.
|
// Run bounds checks.
|
||||||
if c.flags&FlagsOnlyTypeCheck == 0 {
|
if c.flags&FlagsOnlyTypeCheck == 0 {
|
||||||
for _, o := range n.Body() {
|
if err := q.bcheckBlock(n.Body()); err != nil {
|
||||||
if err := q.bcheckStatement(o); err != nil {
|
return &Error{
|
||||||
return &Error{
|
Err: err,
|
||||||
Err: err,
|
Filename: q.errFilename,
|
||||||
Filename: q.errFilename,
|
Line: q.errLine,
|
||||||
Line: q.errLine,
|
IDMap: c.idMap,
|
||||||
IDMap: c.idMap,
|
Facts: q.facts,
|
||||||
Facts: q.facts,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user