davidmalcolm / gcc-python-plugin

GCC plugin that embeds CPython inside the compiler
GNU General Public License v3.0
199 stars 58 forks source link

assertion error when compiling with -fexceptions #83

Open davidmalcolm opened 7 years ago

davidmalcolm commented 7 years ago

running from git on f17: {{{ $ cat a.c

include

static PyObject f(PyObject self, PyObject args) { const char text; int len;

if (!PyArg_ParseTuple(args, "s#", &text, &len))
    return NULL;
return NULL;

}

static PyMethodDef methods[] = { {"f", f, METH_VARARGS, ""}, {NULL, NULL} };

PyMODINIT_FUNC initX(void) { Py_InitModule3("name", methods, "doc"); }

$ gcc-with-cpychecker -fexceptions -I/usr/include/python2.7 -c a.c a.c: In function ‘initX’: a.c:22:1: warning: ob_refcnt of new ref from (unknown) Py_InitModule4 is 1 too high [enabled by default] a.c:22:1: note: was expecting final ob_refcnt to be N + 0 (for some unknown N) a.c:22:1: note: but final ob_refcnt is N + 1 a.c:21:2: note: new ref from (unknown) Py_InitModule4 allocated at: Py_InitModule3("name", methods, "doc"); a.c:21:2: note: when Py_InitModule4() succeeds at: Py_InitModule3("name", methods, "doc"); a.c:21:2: note: ob_refcnt is now refs: 1 + N where N >= 0 a.c:22:1: note: returning at: } a.c:20:1: note: graphical error report for function 'initX' written out to 'a.c.initX-refcount-errors.html' a.c: In function ‘f’: a.c:9:23: error: Unhandled Python exception raised calling 'execute' method Traceback (most recent call last): File "/home/mk/gcc-python-plugin/libcpychecker/init.py", line 79, in execute self._check_refcounts(fun) File "/home/mk/gcc-python-plugin/libcpychecker/init.py", line 85, in _check_refcounts dump_json=self.dump_json) File "/home/mk/gcc-python-plugin/libcpychecker/refcounts.py", line 4148, in check_refcounts maxtrans) File "/home/mk/gcc-python-plugin/libcpychecker/refcounts.py", line 4003, in impl_check_refcounts limits=limits) File "/home/mk/gcc-python-plugin/libcpychecker/absinterp.py", line 3056, in iter_traces depth + 1): File "/home/mk/gcc-python-plugin/libcpychecker/absinterp.py", line 3020, in iter_traces transitions = curstate.get_transitions() File "/home/mk/gcc-python-plugin/libcpychecker/absinterp.py", line 2073, in get_transitions return self._get_transitions_for_stmt(stmt) File "/home/mk/gcc-python-plugin/libcpychecker/absinterp.py", line 2089, in _get_transitions_for_stmt return self._get_transitions_for_GimpleCall(stmt) File "/home/mk/gcc-python-plugin/libcpychecker/absinterp.py", line 2260, in _get_transitions_for_GimpleCall return meth(stmt, *args) File "/home/mk/gcc-python-plugin/libcpychecker/refcounts.py", line 984, in impl_PyArg_ParseTuple v_fmt, v_varargs, with_size_t=False) File "/home/mk/gcc-python-plugin/libcpychecker/refcounts.py", line 887, in _handle_PyArg_function s_success = self.state.mkstate_concrete_return_of(stmt, 1) File "/home/mk/gcc-python-plugin/libcpychecker/absinterp.py", line 2139, in mkstate_concrete_return_of newstate.loc = self.loc.next_loc() File "/home/mk/gcc-python-plugin/libcpychecker/absinterp.py", line 1148, in next_loc assert len(self.bb.succs) == 1 AssertionError

}}}

It took me some time to figure out what caused the problem.

I would expect -fexceptions to not spoil anything ... or at least to get a helpful error message.

davidmalcolm commented 7 years ago

Imported from trac issue 43. Created by kiilerix on 2012-05-21T17:30:17, last modified: 2012-05-22T12:41:53

davidmalcolm commented 7 years ago

Trac comment by dmalcolm on 2012-05-22 12:23:38:

Thanks for filing this. I see it with gcc 4.7 (though not with gcc 4.6) and am investigating.

davidmalcolm commented 7 years ago

Trac comment by dmalcolm on 2012-05-22 12:28:32:

cpychecker is getting confused by the two successor blocks to block 2: block 8 and block 3 (which is something I've not seen before).

I'm guessing that block 8 relates to exception-handling.

davidmalcolm commented 7 years ago

Trac comment by dmalcolm on 2012-05-22 12:41:53:

Yes, it's a GIMPLE_RESX, a gimple statement which I haven't wrapped yet.

From gimple.def: {{{ / GIMPLE_RESX resumes execution after an exception. / DEFGSCODE(GIMPLE_RESX, "gimple_resx", GSS_EH_CTRL) }}}

It has an exception region number.