diff --git a/cmd/wuffs-c/internal/cgen/statement.go b/cmd/wuffs-c/internal/cgen/statement.go index afa72c89..aaaad05c 100644 --- a/cmd/wuffs-c/internal/cgen/statement.go +++ b/cmd/wuffs-c/internal/cgen/statement.go @@ -302,6 +302,18 @@ func (g *gen) writeStatementIOBind(b *buffer, n *a.IOBind, depth uint32) error { } func (g *gen) writeStatementIf(b *buffer, n *a.If, depth uint32) error { + // For an "if true { etc }", just write the "etc". + if cv := n.Condition().ConstValue(); (cv != nil) && (cv.Cmp(one) == 0) && + (n.ElseIf() == nil) && (len(n.BodyIfFalse()) == 0) { + + for _, o := range n.BodyIfTrue() { + if err := g.writeStatement(b, o, depth); err != nil { + return err + } + } + return nil + } + for { condition := buffer(nil) if err := g.writeExpr(&condition, n.Condition(), 0); err != nil { diff --git a/lang/check/bounds.go b/lang/check/bounds.go index fd0beb9b..175673ab 100644 --- a/lang/check/bounds.go +++ b/lang/check/bounds.go @@ -597,12 +597,10 @@ func (q *checker) bcheckIf(n *a.If) error { return err } - if cv := n.Condition().ConstValue(); cv != nil { - return fmt.Errorf("TODO: bcheckIf for \"if true\" or \"if false\"") - } - // Check the if-true branch, assuming the if condition. - q.facts.appendFact(n.Condition()) + if n.Condition().ConstValue() == nil { + q.facts.appendFact(n.Condition()) + } if err := q.bcheckBlock(n.BodyIfTrue()); err != nil { return err } @@ -612,10 +610,12 @@ func (q *checker) bcheckIf(n *a.If) error { // Check the if-false branch, assuming the inverted if condition. q.facts = append(q.facts[:0], snap...) - if inverse, err := invert(q.tm, n.Condition()); err != nil { - return err - } else { - q.facts.appendFact(inverse) + if n.Condition().ConstValue() == nil { + if inverse, err := invert(q.tm, n.Condition()); err != nil { + return err + } else { + q.facts.appendFact(inverse) + } } if bif := n.BodyIfFalse(); len(bif) > 0 { if err := q.bcheckBlock(bif); err != nil {