Bug 21450 - [3.4/4.0/4.1 regression] C++ aliasing sets and downcast pointers to pointers
Summary: [3.4/4.0/4.1 regression] C++ aliasing sets and downcast pointers to pointers
Status: RESOLVED DUPLICATE of bug 11376
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 4.0.1
: P2 critical
Target Milestone: 3.4.4
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2005-05-07 21:56 UTC by Serge Belyshev
Modified: 2005-05-07 22:30 UTC (History)
1 user (show)

See Also:
Host:
Target: i686-pc-linux-gnu
Build:
Known to work: 2.95.3 3.0.4
Known to fail: 3.2.3 3.3.4 3.4.2 4.0.0 4.1.0
Last reconfirmed: 2005-05-07 22:19:39


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Serge Belyshev 2005-05-07 21:56:12 UTC
This C++ code snippet aborts on amd64 and i386 if compiled with -O[23]:
(Note: tree dumps are correct)

-------------------------------------------------------------------------------
extern "C" void abort (void);

struct T {};
struct U : T {};

int main ()
{
  int i;
  U *p;
  T **q;

  for (i = 0; i < 2; i++)
    {
      q = (T **) &p;
      *q = 0;
      if (p)
	abort ();
    }
  return 0;
}
-------------------------------------------------------------------------------

The above bug shows as Mozilla Firefox segfault in function
imgRequest::NotifyProxyListener(imgRequestProxy *) when pressing 'reload'
button, and the testcase was reduced from function
imgCacheValidator::OnStartRequest(nsIRequest *, nsISupports *), here is part of
original code:

NS_IMETHODIMP imgCacheValidator::OnStartRequest(nsIRequest *aRequest,
nsISupports *ctxt)
{
...
      for (PRInt32 i = count-1; i>=0; i--) {
        imgRequestProxy *proxy;
        mProxies.GetElementAt(i, (nsISupports**)&proxy);
        mRequest->NotifyProxyListener(proxy);
        NS_RELEASE(proxy);
      }
...
Comment 1 Andrew Pinski 2005-05-07 22:19:38 UTC
Confirmed, here is a testcase which makes it fail with 3.4.0:
extern "C" void abort (void) throw();

struct T {};
struct U : T {};
int size = 2;

int main ()
{
  struct T * * pretmp3;
  struct U * p;
  int i;
  int size1 = size;
 p  =(U*)1 ;


  pretmp3 = (struct T * *) &p;
  i = 0;
L0:;
  *pretmp3 = 0;
  if (p != 0) abort();
  i = i + 1;
  if (i != 2) goto L0;
L4:;
  return 0;
}
Comment 2 Falk Hueffner 2005-05-07 22:27:41 UTC
I guess I'm missing something in here. *q accesses an object of type
U* (namely p). The type of the lvalue *q is T*. Right? Which case in
3.10/15 covers this?
Comment 3 Andrew Pinski 2005-05-07 22:30:24 UTC
Yes the code is invalid after I thought about it and looked for another bug which has the same issue, 
see PR 11376.

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