[prev in list] [next in list] [prev in thread] [next in thread]
List: gcc-python-plugin-commits
Subject: [gcc-python-plugin] cpychecker: handle gcc.Constructor()
From: dmalcolm () fedoraproject ! org (dmalcolm)
Date: 2011-10-21 16:10:53
Message-ID: 20111021161053.EFF671201B5 () lists ! fedorahosted ! org
[Download RAW message or body]
commit 2d780321154a5f9674980f4404c2d706013fe894
Author: David Malcolm <dmalcolm at redhat.com>
Date: Fri Oct 21 12:10:19 2011 -0400
cpychecker: handle gcc.Constructor()
libcpychecker/absinterp.py | 7 ++
.../partial-initialization-on-stack/input.c | 60 ++++++++++++++++++++
.../partial-initialization-on-stack/script.py | 22 +++++++
.../partial-initialization-on-stack/stdout.txt | 10 +++
4 files changed, 99 insertions(+), 0 deletions(-)
---
diff --git a/libcpychecker/absinterp.py b/libcpychecker/absinterp.py
index a4febfd..dea5226 100644
--- a/libcpychecker/absinterp.py
+++ b/libcpychecker/absinterp.py
@@ -406,6 +406,9 @@ class ConcreteValue(AbstractValue):
return self.value >= rhs.value
return None
+ def extract_from_parent(self, region, gcctype, loc):
+ return ConcreteValue(gcctype, loc, self.value)
+
def union(self, v_other):
check_isinstance(v_other, AbstractValue)
if isinstance(v_other, ConcreteValue):
@@ -2048,6 +2051,10 @@ class State:
return v_rhs.eval_unary_op(stmt.exprcode, stmt.lhs.type, stmt.loc)
elif stmt.exprcode == gcc.BitFieldRef:
return self.eval_rvalue(rhs[0], stmt.loc)
+ elif stmt.exprcode == gcc.Constructor:
+ # Default value for whole array becomes 0:
+ return ConcreteValue(stmt.lhs.type,
+ stmt.loc, 0)
else:
raise NotImplementedError("Don't know how to cope with exprcode: %r (%s) \
at %s"
% (stmt.exprcode, stmt.exprcode, stmt.loc))
diff --git a/tests/cpychecker/absinterp/array-range/partial-initialization-on-stack/input.c \
b/tests/cpychecker/absinterp/array-range/partial-initialization-on-stack/input.c new \
file mode 100644 index 0000000..c605f62
--- /dev/null
+++ b/tests/cpychecker/absinterp/array-range/partial-initialization-on-stack/input.c
@@ -0,0 +1,60 @@
+/*
+ Copyright 2011 David Malcolm <dmalcolm at redhat.com>
+ Copyright 2011 Red Hat, Inc.
+
+ This is free software: you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#include <Python.h>
+
+/*
+ Test of reading from an array where the read can be proven to be within
+ the correct region, but the array has only a subrange of explicit initial
+ values, with implicit zero initialization, as per K&R 2nd edn, p86.
+
+ This is handled internally using a gcc.Constructor() expression.
+*/
+
+extern void __cpychecker_dump(int);
+
+void
+test(int i)
+{
+ /*
+ This initialization doesn't list explicit values for all items, leading
+ to a gcc.Constructor() for the implicit zero-fill of the others.
+ */
+ short array[9] = {42};
+
+ __cpychecker_dump(array[0]); /* should be 42 */
+ __cpychecker_dump(array[11]); /* should be 0 */
+
+ __cpychecker_dump(i);
+
+ i = (i & 0x7) + 1;
+ /* i should now be provably in the range [1-8]: */
+ __cpychecker_dump(i);
+
+ /* array[i] should provably be 0: */
+ __cpychecker_dump(array[i]);
+}
+
+/*
+ PEP-7
+Local variables:
+c-basic-offset: 4
+indent-tabs-mode: nil
+End:
+*/
diff --git a/tests/cpychecker/absinterp/array-range/partial-initialization-on-stack/script.py \
b/tests/cpychecker/absinterp/array-range/partial-initialization-on-stack/script.py \
new file mode 100644 index 0000000..fdd5ba3
--- /dev/null
+++ b/tests/cpychecker/absinterp/array-range/partial-initialization-on-stack/script.py
@@ -0,0 +1,22 @@
+# -*- coding: utf-8 -*-
+# Copyright 2011 David Malcolm <dmalcolm at redhat.com>
+# Copyright 2011 Red Hat, Inc.
+#
+# This is free software: you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see
+# <http://www.gnu.org/licenses/>.
+
+from libcpychecker import main
+main(verify_refcounting=True,
+ dump_traces=True,
+ show_traces=False)
diff --git a/tests/cpychecker/absinterp/array-range/partial-initialization-on-stack/stdout.txt \
b/tests/cpychecker/absinterp/array-range/partial-initialization-on-stack/stdout.txt \
new file mode 100644 index 0000000..9873935
--- /dev/null
+++ b/tests/cpychecker/absinterp/array-range/partial-initialization-on-stack/stdout.txt
@@ -0,0 +1,10 @@
+Trace 0:
+ Transitions:
+ '__dump((short int)42 from \
tests/cpychecker/absinterp/array-range/partial-initialization-on-stack/input.c:39)' + \
'__dump((short int)0 from \
tests/cpychecker/absinterp/array-range/partial-initialization-on-stack/input.c:42)' + \
'__dump((int)val [-0x80000000 <= val <= 0x7fffffff] from \
tests/cpychecker/absinterp/array-range/partial-initialization-on-stack/input.c:33)' + \
'__dump((int)val [1 <= val <= 8] from \
tests/cpychecker/absinterp/array-range/partial-initialization-on-stack/input.c:46)' + \
'__dump((short int)0 from \
tests/cpychecker/absinterp/array-range/partial-initialization-on-stack/input.c:51)' + \
'returning' + Exception:
+ (struct PyObject *)0 from \
tests/cpychecker/absinterp/array-range/partial-initialization-on-stack/input.c:34
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic