commit 4280be45a09445808050addc67b3e7d29ae0e8ca Author: David Malcolm dmalcolm@redhat.com Date: Fri Sep 23 17:15:53 2011 -0400
cpychecker: implement bit-shifting operations
docs/tree.rst | 4 ++-- libcpychecker/refcounts.py | 18 ++++++++++++++++++ .../absinterp/arithmetic/correct/input.c | 4 ++++ .../absinterp/arithmetic/correct/stdout.txt | 4 ++-- 4 files changed, 26 insertions(+), 4 deletions(-) --- diff --git a/docs/tree.rst b/docs/tree.rst index f45d65c..a33339f 100644 --- a/docs/tree.rst +++ b/docs/tree.rst @@ -516,9 +516,9 @@ Binary Expressions Subclass C/C++ operators =================================== ====================== .. py:class:: gcc.LrotateExpr - .. py:class:: gcc.LshiftExpr + .. py:class:: gcc.LshiftExpr `<<`, `<<=` .. py:class:: gcc.RrotateExpr - .. py:class:: gcc.RshiftExpr + .. py:class:: gcc.RshiftExpr `>>`, `>>=` =================================== ======================
Bitwise binary expressions: diff --git a/libcpychecker/refcounts.py b/libcpychecker/refcounts.py index 3a4420a..9dccb6e 100644 --- a/libcpychecker/refcounts.py +++ b/libcpychecker/refcounts.py @@ -1905,6 +1905,24 @@ class MyState(State): a.value ^ b.value) raise NotImplementedError("Don't know how to cope with bitwise-xor of\n %r\nand\n %rat %s" % (a, b, stmt.loc)) + elif stmt.exprcode == gcc.LshiftExpr: + a, b = self.eval_binop_args(stmt) + if isinstance(a, UnknownValue) or isinstance(b, UnknownValue): + return UnknownValue(stmt.lhs.type, stmt.loc) + if isinstance(a, ConcreteValue) and isinstance(b, ConcreteValue): + return ConcreteValue(stmt.lhs.type, stmt.loc, + a.value << b.value) + raise NotImplementedError("Don't know how to cope with left shift of of\n %r\nand\n %rat %s" + % (a, b, stmt.loc)) + elif stmt.exprcode == gcc.RshiftExpr: + a, b = self.eval_binop_args(stmt) + if isinstance(a, UnknownValue) or isinstance(b, UnknownValue): + return UnknownValue(stmt.lhs.type, stmt.loc) + if isinstance(a, ConcreteValue) and isinstance(b, ConcreteValue): + return ConcreteValue(stmt.lhs.type, stmt.loc, + a.value >> b.value) + raise NotImplementedError("Don't know how to cope with right shift of of\n %r\nand\n %rat %s" + % (a, b, stmt.loc)) elif stmt.exprcode == gcc.ComponentRef: return self.eval_rvalue(rhs[0], stmt.loc) elif stmt.exprcode == gcc.VarDecl: diff --git a/tests/cpychecker/absinterp/arithmetic/correct/input.c b/tests/cpychecker/absinterp/arithmetic/correct/input.c index 5bc319c..dedabbd 100644 --- a/tests/cpychecker/absinterp/arithmetic/correct/input.c +++ b/tests/cpychecker/absinterp/arithmetic/correct/input.c @@ -41,6 +41,10 @@ test(void) i &= 0xaaaa; i ^= 0xaaaa;
+ /* Bit shifting */ + i <<= 2; + i >>= 1; + return i; }
diff --git a/tests/cpychecker/absinterp/arithmetic/correct/stdout.txt b/tests/cpychecker/absinterp/arithmetic/correct/stdout.txt index 1d42045..98a2d65 100644 --- a/tests/cpychecker/absinterp/arithmetic/correct/stdout.txt +++ b/tests/cpychecker/absinterp/arithmetic/correct/stdout.txt @@ -2,7 +2,7 @@ Trace 0: Transitions: 'returning' Return value: - repr(): ConcreteValue(gcctype='int', loc=gcc.Location(file='tests/cpychecker/absinterp/arithmetic/correct/input.c', line=42), value=2570) - str(): (int)2570 from tests/cpychecker/absinterp/arithmetic/correct/input.c:42 + repr(): ConcreteValue(gcctype='int', loc=gcc.Location(file='tests/cpychecker/absinterp/arithmetic/correct/input.c', line=46), value=5140) + str(): (int)5140 from tests/cpychecker/absinterp/arithmetic/correct/input.c:46 Exception: (struct PyObject *)0 from tests/cpychecker/absinterp/arithmetic/correct/input.c:30
gcc-python-plugin-commits@lists.stg.fedorahosted.org