Bug 38660 - Pointer value changed to NULL
Summary: Pointer value changed to NULL
Status: RESOLVED DUPLICATE of bug 38587
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.4.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-12-29 17:17 UTC by Kurt Roeckx
Modified: 2009-01-21 20:03 UTC (History)
10 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
preprocessed file that has the problem (108.73 KB, text/plain)
2008-12-29 17:19 UTC, Kurt Roeckx
Details
Reduced test case part 1 (564 bytes, text/plain)
2009-01-02 13:00 UTC, Kurt Roeckx
Details
Reduced test case part 2 (298 bytes, text/plain)
2009-01-02 13:01 UTC, Kurt Roeckx
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Kurt Roeckx 2008-12-29 17:17:56 UTC
Hi,

It seems that postgresql has a problem with a gcc 4.4 snapshot.  I've last tested this with the gcc-snapshot package from Debian on x86_64 that has a snapshot from 20081213.

It seems that a pointer gets changed into NULL that shouldn't.  I've first asked about this on the pgsql list, see the thread starting at http://archives.postgresql.org/pgsql-hackers/2008-12/msg01813.php

Kurt
Comment 1 Kurt Roeckx 2008-12-29 17:19:20 UTC
Created attachment 17001 [details]
preprocessed file that has the problem
Comment 2 Andrew Pinski 2008-12-29 18:04:47 UTC
plpython.c:2196: warning: dereferencing type-punned pointer will break strict-aliasing rules


plpython.c:2196: warning: dereferencing pointer '_Py_TrueStruct.537' does break strict-aliasing rules
plpython.c:2196: warning: dereferencing pointer '_Py_TrueStruct.537' does break strict-aliasing rules


plpython.c:2956: warning: variable 'xmsg' might be clobbered by 'longjmp' or 'vfork'

Comment 3 Andrew Pinski 2008-12-29 18:05:47 UTC
  ( (((PyObject *) &_Py_TrueStruct))->ob_refcnt++);


Yes that is obvious an alias violation.
Comment 4 Kurt Roeckx 2008-12-29 18:13:25 UTC
pgsql uses -fno-strict-aliasing to compile.

The command that is being used is:
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing -fwrapv -g -fpic -I. -I/usr/include/python2.5 -I../../../src/include -D_GNU_SOURCE   -c -o plpython.o plpython.c

And I only get those warnings:
plpython.c: In function 'PLyDict_FromTuple':
plpython.c:1733: warning: value computed is not used
plpython.c:1733: warning: value computed is not used
Comment 5 Richard Biener 2008-12-29 20:18:08 UTC
And actually

plpython.c:2196: warning: dereferencing pointer '_Py_TrueStruct.537' does break
strict-aliasing rules

also means that it doesn't get miscompiled ;)
Comment 6 Kurt Roeckx 2008-12-30 12:44:41 UTC
So are you saying that because in an unrelated part of the code there is an aliasing bug gcc can miscompile anything else, even if -fno-strict-aliasing is used?

The problem is in the PLy_spi_execute_plan() function.  oldcontext ends up being a NULL pointers while the only place it gets assigned something should set it to a non-NULL value.
Comment 7 Kurt Roeckx 2009-01-02 13:00:33 UTC
Created attachment 17021 [details]
Reduced test case part 1
Comment 8 Kurt Roeckx 2009-01-02 13:01:21 UTC
Created attachment 17022 [details]
Reduced test case part 2
Comment 9 Kurt Roeckx 2009-01-02 13:04:23 UTC
I've reduced the test case.  The call to siglongjmp() needs to be in a separate file.

When the problem occurs the test program returns exit code 1.
Comment 10 Andrew Pinski 2009-01-02 20:16:30 UTC
This code might turn out to be undefined ...
Comment 11 Kurt Roeckx 2009-01-06 23:44:47 UTC
Which part do you think think is undefined and what would you recommend to resolve it?
Comment 12 Andrew Pinski 2009-01-20 21:19:06 UTC
THis is most likely the same issue as PR 38587.  Does -fno-ira fix the issue?
Comment 13 Kurt Roeckx 2009-01-20 21:36:42 UTC
My version of gcc doesn't seem to support the -fno-ira option.  Is that something that needs to be enabled at compile time?  Can you try my test case with that option?
Comment 14 Andrew Pinski 2009-01-20 21:41:26 UTC
(In reply to comment #13)
> My version of gcc doesn't seem to support the -fno-ira option.  

Well then it is not a snapshot of GCC 4.4.0.

Comment 15 Kurt Roeckx 2009-01-20 22:03:03 UTC
I was still using:
gcc (Debian 20081213-1) 4.4.0 20081212 (experimental) [trunk revision 142725]

Which doesn't seem to have that option.

Upgrading to the latest in Debian gives this version:
gcc (Debian 20090107-1) 4.4.0 20090107 (experimental) [trunk revision 143170]

Using that version and the -fno-ira option changes the result of my test case.
Comment 16 H.J. Lu 2009-01-21 20:03:48 UTC
I am closing it as dup of PR 38587, which will be fixed by

http://gcc.gnu.org/ml/gcc-patches/2009-01/msg01067.html

Please re-open it if the patch above doesn't fix this bug.

*** This bug has been marked as a duplicate of 38587 ***