Skip to content

Commit af4fdc6

Browse files
committed
libcpychecker: Switch off verify_refcounting for gcc-7 and later
Refcounting verification fails in some cases for gcc-7 and later. Workaround this by disabling refcounting verification entirely for gcc-7 and later, to make sure that users don't run into python exceptions. Emit warning in gcc-with-cpychecker when refcounting verification has been disabled, to make sure that users are aware of this.
1 parent c1c976b commit af4fdc6

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

gcc-with-cpychecker

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ if 0:
7070
# but unfortunately gcc's option parser seems to not be able to cope with '='
7171
# within an option's value. So we do it using dictionary syntax instead:
7272
dictstr = '"verify_refcounting":True'
73+
dictstr += ', "verbose":True'
7374
dictstr += ', "maxtrans":%i' % ns.maxtrans
7475
dictstr += ', "dump_json":%i' % ns.dump_json
7576
cmd = 'from libcpychecker import main; main(**{%s})' % dictstr

libcpychecker/__init__.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
# along with this program. If not, see
1616
# <http://www.gnu.org/licenses/>.
1717

18+
from __future__ import print_function
19+
import sys
1820
import gcc
1921
from libcpychecker.formatstrings import check_pyargs
2022
from libcpychecker.utils import log
@@ -38,12 +40,26 @@ def __init__(self,
3840
show_possible_null_derefs=False,
3941
only_on_python_code=True,
4042
maxtrans=256,
41-
dump_json=False):
43+
dump_json=False,
44+
verbose=False):
4245
gcc.GimplePass.__init__(self, 'cpychecker-gimple')
4346
self.dump_traces = dump_traces
4447
self.show_traces = show_traces
4548
self.verify_pyargs = verify_pyargs
46-
self.verify_refcounting = verify_refcounting
49+
# Refcounting verification is run before rewriting gimple into ssa form,
50+
# and as such is not expected to handle ssa. In gcc 7 and later, gcc
51+
# introduces ssa names before the ssa rewrite (for call arguments that
52+
# are calls themselves), and this causes Python exceptions in
53+
# refcounting verification. So, disable refcounting for gcc 7 and
54+
# later, until refcounting verification can handle ssa names.
55+
if verify_refcounting and gcc.GCC_VERSION >= 7000:
56+
if verbose:
57+
print("cpychecker: warning: "
58+
+ "Detected gcc 7 or later, disabling verify_refcounting",
59+
file=sys.stderr)
60+
self.verify_refcounting = False
61+
else:
62+
self.verify_refcounting = verify_refcounting
4763
self.show_possible_null_derefs = show_possible_null_derefs
4864
self.only_on_python_code = only_on_python_code
4965
self.maxtrans = maxtrans

0 commit comments

Comments
 (0)