This fixes PR53364 - an oversight in the alias oracle when detecting
view-conversions on decls.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to
trunk and branch (possibly latent on the 4.6 branch).

Richard.

2012-05-16  Richard Guenther  <rguent...@suse.de>

        PR tree-optimization/53364
        * tree-ssa-alias.c (indirect_ref_may_alias_decl_p): Properly
        detect a view-conversion of the decl.

        * g++.dg/torture/pr53364.C: New testcase.

Index: gcc/tree-ssa-alias.c
===================================================================
*** gcc/tree-ssa-alias.c        (revision 187586)
--- gcc/tree-ssa-alias.c        (working copy)
*************** indirect_ref_may_alias_decl_p (tree ref1
*** 804,811 ****
  
    /* If either reference is view-converted, give up now.  */
    if (same_type_for_tbaa (TREE_TYPE (base1), TREE_TYPE (ptrtype1)) != 1
!       || same_type_for_tbaa (TREE_TYPE (dbase2),
!                            TREE_TYPE (reference_alias_ptr_type (dbase2))) != 
1)
      return true;
  
    /* If both references are through the same type, they do not alias
--- 804,810 ----
  
    /* If either reference is view-converted, give up now.  */
    if (same_type_for_tbaa (TREE_TYPE (base1), TREE_TYPE (ptrtype1)) != 1
!       || same_type_for_tbaa (TREE_TYPE (dbase2), TREE_TYPE (base2)) != 1)
      return true;
  
    /* If both references are through the same type, they do not alias
Index: gcc/testsuite/g++.dg/torture/pr53364.C
===================================================================
*** gcc/testsuite/g++.dg/torture/pr53364.C      (revision 0)
--- gcc/testsuite/g++.dg/torture/pr53364.C      (revision 0)
***************
*** 0 ****
--- 1,37 ----
+ // { dg-do run }
+ 
+ extern "C" void abort (void);
+ 
+ template<typename _Tp>
+ inline const _Tp&
+ min(const _Tp& __a, const _Tp& __b)
+ {
+   if (__b < __a)
+     return __b;
+   return __a;
+ }
+ 
+ struct A
+ {
+   int m_x;
+ 
+   explicit A(int x) : m_x(x) {}
+   operator int() const { return m_x; }
+ };
+ 
+ struct B : public A
+ {
+ public:
+   explicit B(int x) : A(x) {}
+ };
+ 
+ int data = 1;
+ 
+ int main()
+ {
+   B b = B(10);
+   b = min(b, B(data));
+   if (b != 1)
+     abort ();
+   return 0;
+ }

Reply via email to