Skip to content

Commit b02eab0

Browse files
committed
cpychecker: implement gcc.FixTruncExpr
1 parent 26430c0 commit b02eab0

File tree

4 files changed

+71
-1
lines changed

4 files changed

+71
-1
lines changed

libcpychecker/absinterp.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,8 @@ def eval_unary_op(self, exprcode, gcctype, loc):
488488
return ConcreteValue(gcctype, loc, self.value)
489489
# We might lose information e.g. truncation; be pessimistic for now:
490490
return UnknownValue.make(gcctype, loc)
491+
elif exprcode == gcc.FixTruncExpr:
492+
return ConcreteValue(gcctype, loc, int(self.value))
491493
else:
492494
raise NotImplementedError("Don't know how to cope with exprcode: %r (%s) on %s at %s"
493495
% (exprcode, exprcode, self, loc))
@@ -2590,7 +2592,7 @@ def eval_rhs(self, stmt):
25902592
return UnknownValue.make(stmt.lhs.type, stmt.loc)
25912593
# Unary expressions:
25922594
elif stmt.exprcode in (gcc.AbsExpr, gcc.BitNotExpr, gcc.ConvertExpr,
2593-
gcc.NegateExpr):
2595+
gcc.NegateExpr, gcc.FixTruncExpr):
25942596
v_rhs = self.eval_rvalue(stmt.rhs[0], stmt.loc)
25952597
return v_rhs.eval_unary_op(stmt.exprcode, stmt.lhs.type, stmt.loc)
25962598
elif stmt.exprcode == gcc.BitFieldRef:
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
Copyright 2012 David Malcolm <dmalcolm@redhat.com>
3+
Copyright 2012 Red Hat, Inc.
4+
5+
This is free software: you can redistribute it and/or modify it
6+
under the terms of the GNU General Public License as published by
7+
the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful, but
11+
WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with this program. If not, see
17+
<http://www.gnu.org/licenses/>.
18+
*/
19+
20+
#include <Python.h>
21+
22+
/*
23+
Test of gcc.FixTruncExpr
24+
*/
25+
26+
int
27+
test(float x)
28+
{
29+
return (int)x;
30+
}
31+
32+
/*
33+
PEP-7
34+
Local variables:
35+
c-basic-offset: 4
36+
indent-tabs-mode: nil
37+
End:
38+
*/
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2011 David Malcolm <dmalcolm@redhat.com>
3+
# Copyright 2011 Red Hat, Inc.
4+
#
5+
# This is free software: you can redistribute it and/or modify it
6+
# under the terms of the GNU General Public License as published by
7+
# the Free Software Foundation, either version 3 of the License, or
8+
# (at your option) any later version.
9+
#
10+
# This program is distributed in the hope that it will be useful, but
11+
# WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
# General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU General Public License
16+
# along with this program. If not, see
17+
# <http://www.gnu.org/licenses/>.
18+
19+
from libcpychecker import main
20+
main(verify_refcounting=True,
21+
dump_traces=True,
22+
show_traces=False)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Trace 0:
2+
Transitions:
3+
'returning'
4+
Return value:
5+
repr(): WithinRange(gcctype='int', loc=gcc.Location(file='tests/cpychecker/absinterp/arithmetic/fix-trunc-expr/input.c', line=29), minvalue=-0x80000000, maxvalue=0x7fffffff)
6+
str(): (int)val [-0x80000000 <= val <= 0x7fffffff] from tests/cpychecker/absinterp/arithmetic/fix-trunc-expr/input.c:29
7+
Exception:
8+
(struct PyObject *)0 from tests/cpychecker/absinterp/arithmetic/fix-trunc-expr/input.c:28

0 commit comments

Comments
 (0)