This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug rtl-optimization/16536] New: Incorrect __restrict__ optimization in -O2


#include <assert.h> 
 
struct V2F { 
  inline V2F()                { } 
  inline V2F(float x)         { _v[1]=_v[0]=x; } 
  inline V2F(float x,float y) { _v[0]=x; _v[1]=y; } 
   
  float _v[2]; 
}; 
 
inline V2F operator + (const V2F& a,const V2F& b) 
{ 
  return V2F(a._v[0]+b._v[0],a._v[1]+b._v[1]); 
} 
 
inline bool operator == (const V2F& a,const V2F& b) 
{ 
  return a._v[0]==b._v[0] && a._v[1]==b._v[1]; 
} 
 
void 
test_restrict_v(V2F * __restrict__ v0, 
		V2F * __restrict__ v1, 
		V2F * __restrict__ v2) 
{ 
  (*v2)=(*v0); 
  (*v2)=(*v2)+(*v1); 
  assert((*v2)==(*v0)+(*v1)); 
} 
 
int 
main(int,char**) 
{ 
  V2F v0(1.0),v1(1.0),v2; 
   
  test_restrict_v(&v0,&v1,&v2); 
 
  return 0; 
} 
 
/* 
 
  % g++ -W -Wall -O bug.cxx 
  % ./a.out 
  % g++ -W -Wall -O2 bug.cxx 
  % ./a.out 
a.out: t.cxx:28: void test_restrict_v(V2F*, V2F*, V2F*): Assertion 
`(*v2)==(*v0)+(*v1)' failed. 
 
Looks like optimization mishandles const references to restricted data 
(here in  'operator +'). This code works  in -O2 if any  of 'const &', 
'inline'  ('operator  +'),  or '__restrict__'  ('test_restrict_v')  is 
removed. 
 
My system is Debian GNU/Linux (sarge) with g++ (GCC) 3.3.4 (Debian 1:3.3.4-2) 
 
Thanks for this great piece of software! 
 
JD 
 
 */

-- 
           Summary: Incorrect __restrict__ optimization in -O2
           Product: gcc
           Version: 3.3.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: rtl-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jeremy dot denise at libertysurf dot fr
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16536


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]