classification
Title: integer undefined behaviors
Type: behavior Stage:
Components: Versions: Python 3.3
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: mark.dickinson Nosy List: eric.smith, jcea, mark.dickinson, python-dev, regehr
Priority: normal Keywords: patch

Created on 2010-08-06 06:16 by regehr, last changed 2011-12-02 16:28 by mark.dickinson.

Files
File name Uploaded Description Edit
python-errors.txt regehr, 2010-08-06 06:16
issue9530_1.patch mark.dickinson, 2010-08-06 12:04 review
Messages (15)
msg113079 - (view) Author: John Regehr (regehr) Date: 2010-08-06 06:16
I ran "make test" for today's Python3k snapshot under a tool which detects math operations that the C language considers to have undefined behavior.  This was on x86 Linux.  The list of undefined behaviors is attached.  Hopefully they are self-explanatory, but please let me know if more details are needed.
msg113091 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-08-06 10:07
This is good stuff!  Thank you!  I'll look through these.

Is the tool you used publicly available?
msg113098 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-08-06 12:04
Here are some fixes for Objects/bytesobject.c and Objects/bytearrayobject.c.  More to come.
msg113099 - (view) Author: John Regehr (regehr) Date: 2010-08-06 13:09
Hi Mark-- Glad it's useful! We plan to release this tool but haven't done so yet, it still has rough edges.  It's LLVM-based and it seems likely they will take our patches.
msg113138 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-08-06 21:34
Fixed two more bytearray problems in r83768.
msg113555 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-08-10 18:35
Applied issue9530_1.patch in r83936.
msg147954 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2011-11-19 16:58
Status update:  all the reported errors from the Objects/ directory have been fixed in the default branch (many of these were fixed recently as part of making sure that the test-suite runs under Clang's -ftrapv option), or are out of date.  I haven't checked the reports for the extension Modules.
msg147955 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2011-11-19 17:00
See also issue #1621.
msg147957 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2011-11-19 17:08
The issues reported for the datetime, array, itertools and math modules are also already fixed.  That just leaves the following two of the reported issues outstanding:

</home/regehr/z/python/Modules/_ctypes/cfield.c, (590:5)> : Op: <<=, Reason : Signed Left Shift Error: Right operand is negative or is greater than or equal to the width of the promoted left operand, BINARY OPERATION: left (int32): 0 right (int32): -2 

and

</home/regehr/z/python/Modules/testcapi_long.h, (37:47)> : Op: -, Reason : Signed Subtraction Overflow, UNARY OPERATION: left (int32): 0 right (int32): -2147483648

I'm using r63764 as the revision that the line numbers relate to; not sure whether this exactly right, but it seems to be close enough.
msg147961 - (view) Author: John Regehr (regehr) Date: 2011-11-19 17:28
This is great.  I'd be happy to re-run the tests sometime, and also we're talking with the LLVM folks about getting our patches into the main LLMM tree.  Basically it'll act as a more powerful -ftrapv, and the error message will be much better than "aborted".
msg147964 - (view) Author: Roundup Robot (python-dev) Date: 2011-11-19 17:58
New changeset 71100ef4f7a2 by Mark Dickinson in branch 'default':
Issue #9530: Fix undefined behaviour due to signed overflow in testcapi_long.h.
http://hg.python.org/cpython/rev/71100ef4f7a2
msg148035 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2011-11-21 12:39
> I'd be happy to re-run the tests sometime.

Yes, please!  Alternatively, if there are easy instructions for us to re-run these tests, that would be valuable, too.  Do I understand correctly that you have a publicly available extension to LLVM for this?

> Basically it'll act as a more powerful -ftrapv, and the error message will be much better than "aborted".

Indeed---there were a number of places where tracking down the exact cause of the error using a combination of -ftrapv and gdb was painful. :-)

I'm aware of two current issues: one in Python/formatter_unicode.c, and one in Modules/timemodule.c.  I'll try to fix these shortly.
msg148068 - (view) Author: John Regehr (regehr) Date: 2011-11-21 18:17
Hi Mark, yes you can run the overflow checker but "easy instructions" depends on whether you feel like building your own LLVM.  It is not at all difficult, but it's certainly not as easy as "apt-get install ...".

Patch and instructions are here:

  http://embed.cs.utah.edu/ioc/

If/when we get this into LLVM (the earliest possible release containing IOC will be 3.1), I'll let you know.  Thanks again.
msg148726 - (view) Author: Roundup Robot (python-dev) Date: 2011-12-01 15:27
New changeset 7e37598a25a6 by Mark Dickinson in branch 'default':
Issue #9530: Fix undefined behaviour due to signed overflow in Python/formatter_unicode.c.
http://hg.python.org/cpython/rev/7e37598a25a6
msg148758 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2011-12-02 16:28
See also issue #13496.
History
Date User Action Args
2011-12-02 16:28:24mark.dickinsonsetmessages: + msg148758
2011-12-01 15:27:10python-devsetmessages: + msg148726
2011-11-21 18:17:02regehrsetmessages: + msg148068
2011-11-21 12:39:28mark.dickinsonsetmessages: + msg148035
2011-11-20 03:43:34jceasetnosy: + jcea
2011-11-19 17:58:59python-devsetnosy: + python-dev
messages: + msg147964
2011-11-19 17:28:26regehrsetmessages: + msg147961
2011-11-19 17:08:34mark.dickinsonsetmessages: + msg147957
2011-11-19 17:00:09mark.dickinsonsetmessages: + msg147955
2011-11-19 16:58:35mark.dickinsonsetmessages: + msg147954
versions: + Python 3.3, - Python 3.2
2010-08-10 18:35:57mark.dickinsonsetmessages: + msg113555
2010-08-06 21:34:32mark.dickinsonsetmessages: + msg113138
2010-08-06 13:09:33regehrsetmessages: + msg113099
2010-08-06 12:04:45mark.dickinsonsetfiles: + issue9530_1.patch
keywords: + patch
messages: + msg113098

versions: + Python 3.2, - Python 3.3
2010-08-06 11:52:48eric.smithsetnosy: + eric.smith
2010-08-06 10:07:03mark.dickinsonsetassignee: mark.dickinson

messages: + msg113091
nosy: + mark.dickinson
2010-08-06 06:16:24regehrcreate