forked from jasonxmueller/gcc-python-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cpychecker: get the checker working on C++ code
Attempting to run the checker on C++ code would fail: it could not locate any global declarations. The logic to locate them in gccutils (searching for blocks in the translation units) worked for C, but not for C++. For C++, we add a new function: gcc.get_global_namespace() to locate the gcc.NamespaceDecl for the "::" namespace, and add a lookup method to gcc.NamespaceDecl. We then use this for C++ to locate global declarations, enabling the checker to run. Also, introduce raise_cplusplus_only()
- Loading branch information
1 parent
02a0d59
commit 194c353
Showing
12 changed files
with
239 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
Copyright 2012 David Malcolm <dmalcolm@redhat.com> | ||
Copyright 2012 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> | ||
|
||
/* Verify that the checker will run on C++ code */ | ||
|
||
PyObject * | ||
test(int i) | ||
{ | ||
if (i) { | ||
/* | ||
Verify that C++ frontend can locate globals | ||
for types ("PyDict_Type") and exceptions (PyExc_MemoryError) | ||
*/ | ||
return PyDict_New(); | ||
} else { | ||
/* Verify that bugs are reported: | ||
this code is missing a Py_INCREF on Py_None */ | ||
return Py_None; | ||
} | ||
} | ||
|
||
/* | ||
PEP-7 | ||
Local variables: | ||
c-basic-offset: 4 | ||
indent-tabs-mode: nil | ||
End: | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[ExpectedBehavior] | ||
# We expect only compilation *warnings*, so we expect a 0 exit code | ||
exitcode = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2011 David Malcolm <dmalcolm@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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
tests/cpychecker/refcounts/cplusplus/input.cc: In function 'PyObject* test(int)': | ||
tests/cpychecker/refcounts/cplusplus/input.cc:38:1: warning: ob_refcnt of return value is 1 too low [enabled by default] | ||
tests/cpychecker/refcounts/cplusplus/input.cc:38:1: note: was expecting final ob_refcnt to be N + 1 (for some unknown N) | ||
tests/cpychecker/refcounts/cplusplus/input.cc:38:1: note: due to object being referenced by: return value | ||
tests/cpychecker/refcounts/cplusplus/input.cc:38:1: note: but final ob_refcnt is N + 0 | ||
tests/cpychecker/refcounts/cplusplus/input.cc:27:5: note: when considering value == (int)0 from tests/cpychecker/refcounts/cplusplus/input.cc:25 at: if (i) { | ||
tests/cpychecker/refcounts/cplusplus/input.cc:27:5: note: taking False path at: if (i) { | ||
tests/cpychecker/refcounts/cplusplus/input.cc:36:16: note: reaching: return Py_None; | ||
tests/cpychecker/refcounts/cplusplus/input.cc:27:5: note: ob_refcnt is now refs: 0 + N where N >= 1 | ||
tests/cpychecker/refcounts/cplusplus/input.cc:38:1: note: returning | ||
tests/cpychecker/refcounts/cplusplus/input.cc:38:1: note: consider using "Py_RETURN_NONE;" | ||
tests/cpychecker/refcounts/cplusplus/input.cc:26:1: note: graphical error report for function 'test' written out to 'tests/cpychecker/refcounts/cplusplus/input.cc.test-refcount-errors.html' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
Trace 0: | ||
Transitions: | ||
'when considering range: -0x80000000 <= value <= -1' | ||
'taking True path' | ||
'when PyDict_New() succeeds' | ||
'returning' | ||
Return value: | ||
repr(): PointerToRegion(gcctype='struct PyObject *', loc=gcc.Location(file='tests/cpychecker/refcounts/cplusplus/input.cc', line=32), region=RegionOnHeap('PyDictObject', gcc.Location(file='tests/cpychecker/refcounts/cplusplus/input.cc', line=32))) | ||
str(): (struct PyObject *)&RegionOnHeap('PyDictObject', gcc.Location(file='tests/cpychecker/refcounts/cplusplus/input.cc', line=32)) from tests/cpychecker/refcounts/cplusplus/input.cc:32 | ||
r->ob_refcnt: refs: 1 + N where N >= 0 | ||
r->ob_type: PointerToRegion(gcctype='struct PyTypeObject *', loc=gcc.Location(file='tests/cpychecker/refcounts/cplusplus/input.cc', line=32), region=RegionForGlobal(gcc.VarDecl('PyDict_Type'))) | ||
Exception: | ||
(struct PyObject *)0 from tests/cpychecker/refcounts/cplusplus/input.cc:26 | ||
|
||
Trace 1: | ||
Transitions: | ||
'when considering range: -0x80000000 <= value <= -1' | ||
'taking True path' | ||
'when PyDict_New() fails' | ||
'returning' | ||
Return value: | ||
repr(): ConcreteValue(gcctype='struct PyObject *', loc=gcc.Location(file='tests/cpychecker/refcounts/cplusplus/input.cc', line=32), value=0) | ||
str(): (struct PyObject *)0 from tests/cpychecker/refcounts/cplusplus/input.cc:32 | ||
Exception: | ||
(struct PyObject *)&RegionForGlobal(gcc.VarDecl('PyExc_MemoryError')) from tests/cpychecker/refcounts/cplusplus/input.cc:32 | ||
|
||
Trace 2: | ||
Transitions: | ||
'when considering value == (int)0 from tests/cpychecker/refcounts/cplusplus/input.cc:25' | ||
'taking False path' | ||
'returning' | ||
Return value: | ||
repr(): PointerToRegion(gcctype='struct PyObject *', loc=gcc.Location(file='tests/cpychecker/refcounts/cplusplus/input.cc', line=36), region=RegionForGlobal(gcc.VarDecl('_Py_NoneStruct'))) | ||
str(): (struct PyObject *)&RegionForGlobal(gcc.VarDecl('_Py_NoneStruct')) from tests/cpychecker/refcounts/cplusplus/input.cc:36 | ||
r->ob_refcnt: refs: 0 + N where N >= 1 | ||
r->ob_type: None | ||
Exception: | ||
(struct PyObject *)0 from tests/cpychecker/refcounts/cplusplus/input.cc:26 | ||
|
||
Trace 3: | ||
Transitions: | ||
'when considering range: 1 <= value <= 0x7fffffff' | ||
'taking True path' | ||
'when PyDict_New() succeeds' | ||
'returning' | ||
Return value: | ||
repr(): PointerToRegion(gcctype='struct PyObject *', loc=gcc.Location(file='tests/cpychecker/refcounts/cplusplus/input.cc', line=32), region=RegionOnHeap('PyDictObject', gcc.Location(file='tests/cpychecker/refcounts/cplusplus/input.cc', line=32))) | ||
str(): (struct PyObject *)&RegionOnHeap('PyDictObject', gcc.Location(file='tests/cpychecker/refcounts/cplusplus/input.cc', line=32)) from tests/cpychecker/refcounts/cplusplus/input.cc:32 | ||
r->ob_refcnt: refs: 1 + N where N >= 0 | ||
r->ob_type: PointerToRegion(gcctype='struct PyTypeObject *', loc=gcc.Location(file='tests/cpychecker/refcounts/cplusplus/input.cc', line=32), region=RegionForGlobal(gcc.VarDecl('PyDict_Type'))) | ||
Exception: | ||
(struct PyObject *)0 from tests/cpychecker/refcounts/cplusplus/input.cc:26 | ||
|
||
Trace 4: | ||
Transitions: | ||
'when considering range: 1 <= value <= 0x7fffffff' | ||
'taking True path' | ||
'when PyDict_New() fails' | ||
'returning' | ||
Return value: | ||
repr(): ConcreteValue(gcctype='struct PyObject *', loc=gcc.Location(file='tests/cpychecker/refcounts/cplusplus/input.cc', line=32), value=0) | ||
str(): (struct PyObject *)0 from tests/cpychecker/refcounts/cplusplus/input.cc:32 | ||
Exception: | ||
(struct PyObject *)&RegionForGlobal(gcc.VarDecl('PyExc_MemoryError')) from tests/cpychecker/refcounts/cplusplus/input.cc:32 |