mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-21 08:47:28 +01:00
cgen: revert simplify "x ~mod+ 0", "1 ~mod* y" etc
This reverts commit a4ec3f8e, which triggers -Werror=sign-conversion
errors on C code like this:
v_foobar += blah;
instead of the equivalent (as all variables here have u32 type):
v_foobar += ((uint32_t)(0u + blah));
This compiler warning (or compiler error, with -Werror) is arguably a
false postive but it's easier not to fight the C compiler.
This commit is contained in:
1 parent
4d5d2e89c0
commit
f3de333642
2 files changed
+69
-69
No files matched your search
+12
-12
@@ -286,25 +286,18 @@ func (g *gen) writeExprUnaryOp(b *buffer, n *a.Expr, depth uint32) error {
|
||||
}
|
||||
|
||||
func (g *gen) writeExprBinaryOp(b *buffer, n *a.Expr, depth uint32) error {
|
||||
op := n.Operator()
|
||||
opName := ""
|
||||
lhsCast := false
|
||||
overallCast := n.MType().IsSmallInteger() || op.IsXBinaryTildeModOp()
|
||||
opName, lhsCast, overallCast := "", false, n.MType().IsSmallInteger()
|
||||
|
||||
op := n.Operator()
|
||||
switch op {
|
||||
case t.IDXBinaryPlus, t.IDXBinaryPipe, t.IDXBinaryHat, t.IDXBinaryTildeModPlus:
|
||||
case t.IDXBinaryPlus, t.IDXBinaryPipe, t.IDXBinaryHat:
|
||||
if lcv := n.LHS().AsExpr().ConstValue(); (lcv != nil) && (lcv.Sign() == 0) {
|
||||
return g.writeExpr(b, n.RHS().AsExpr(), false, depth)
|
||||
} else if rcv := n.RHS().AsExpr().ConstValue(); (rcv != nil) && (rcv.Sign() == 0) {
|
||||
return g.writeExpr(b, n.LHS().AsExpr(), false, depth)
|
||||
}
|
||||
|
||||
case t.IDXBinaryMinus, t.IDXBinaryTildeModMinus:
|
||||
if rcv := n.RHS().AsExpr().ConstValue(); (rcv != nil) && (rcv.Sign() == 0) {
|
||||
return g.writeExpr(b, n.LHS().AsExpr(), false, depth)
|
||||
}
|
||||
|
||||
case t.IDXBinaryStar, t.IDXBinaryTildeModStar:
|
||||
case t.IDXBinaryStar:
|
||||
if lcv := n.LHS().AsExpr().ConstValue(); (lcv != nil) && (lcv.Cmp(one) == 0) {
|
||||
return g.writeExpr(b, n.RHS().AsExpr(), false, depth)
|
||||
} else if (lcv != nil) && (lcv.Sign() == 0) && n.RHS().AsExpr().Effect().Pure() {
|
||||
@@ -330,7 +323,14 @@ func (g *gen) writeExprBinaryOp(b *buffer, n *a.Expr, depth uint32) error {
|
||||
case t.IDXBinaryAs:
|
||||
return g.writeExprAs(b, n.LHS().AsExpr(), n.RHS().AsTypeExpr(), depth)
|
||||
|
||||
case t.IDXBinaryShiftL, t.IDXBinaryShiftR, t.IDXBinaryTildeModShiftL:
|
||||
case t.IDXBinaryTildeModPlus, t.IDXBinaryTildeModMinus, t.IDXBinaryTildeModStar:
|
||||
overallCast = true
|
||||
|
||||
case t.IDXBinaryTildeModShiftL:
|
||||
overallCast = true
|
||||
fallthrough
|
||||
|
||||
case t.IDXBinaryShiftL, t.IDXBinaryShiftR:
|
||||
if rcv := n.RHS().AsExpr().ConstValue(); (rcv != nil) && (rcv.Sign() == 0) {
|
||||
return g.writeExpr(b, n.LHS().AsExpr(), false, depth)
|
||||
} else if lhs := n.LHS().AsExpr(); lhs.ConstValue() != nil {
|
||||
|
||||
Reference in new issue
Block a user