ptrmemfield.C: New testcase.
authorAndrew Pinski <andrew_pinski@playstation.sony.com>
Sat, 5 Jul 2008 19:37:48 +0000 (19:37 +0000)
committerAndrew Pinski <pinskia@gcc.gnu.org>
Sat, 5 Jul 2008 19:37:48 +0000 (12:37 -0700)
2008-07-05  Andrew Pinski  <andrew_pinski@playstation.sony.com>

        * g++.dg/tree-ssa/ptrmemfield.C: New testcase.

2008-07-05  Andrew Pinski  <andrew_pinski@playstation.sony.com>

        * fold-const.c (fold_convert_const): Treat OFFSET_TYPE the same as
        integral and pointer types.

From-SVN: r137510

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/tree-ssa/ptrmemfield.C [new file with mode: 0644]

index 0b9f0c3a0bbfd1342af037ba4e8a2656aeab8551..b769f6857b5f21c0bd9edc751ea48afd9aa7c93b 100644 (file)
@@ -1,3 +1,8 @@
+2008-07-05  Andrew Pinski  <andrew_pinski@playstation.sony.com>
+
+       * fold-const.c (fold_convert_const): Treat OFFSET_TYPE the same as
+       integral and pointer types.
+
 2008-07-04  Roger Sayle  <roger@eyesopen.com>
 
        * config/rs6000/host-darwin.c (darwin_rs6000_extra_siganls): Cast
index fc72b9b38a2158f2606de4cfa570f7ddd4e0e4a5..e1e04bb625da9b11ed9fa363c002a31833c5a55a 100644 (file)
@@ -2396,7 +2396,8 @@ fold_convert_const (enum tree_code code, tree type, tree arg1)
   if (TREE_TYPE (arg1) == type)
     return arg1;
 
-  if (POINTER_TYPE_P (type) || INTEGRAL_TYPE_P (type))
+  if (POINTER_TYPE_P (type) || INTEGRAL_TYPE_P (type)
+      || TREE_CODE (type) == OFFSET_TYPE)
     {
       if (TREE_CODE (arg1) == INTEGER_CST)
        return fold_convert_const_int_from_int (type, arg1);
index 2cf3a6282d3a55bf43b3beaaffebb0759dc362a2..7eb21a42d71ccc7051fd22da7527160dec21801e 100644 (file)
@@ -1,3 +1,7 @@
+2008-07-05  Andrew Pinski  <andrew_pinski@playstation.sony.com>
+
+       * g++.dg/tree-ssa/ptrmemfield.C: New testcase.
+
 2008-07-05  Joseph Myers  <joseph@codesourcery.com>
 
        * lib/gcc-dg.exp (remove-build-file): Remove files on remote host
diff --git a/gcc/testsuite/g++.dg/tree-ssa/ptrmemfield.C b/gcc/testsuite/g++.dg/tree-ssa/ptrmemfield.C
new file mode 100644 (file)
index 0000000..38189eb
--- /dev/null
@@ -0,0 +1,27 @@
+/* { dg-do compile } */
+// { dg-options "-O2 -fdump-tree-final_cleanup" }
+
+
+struct f
+{
+  char m;
+  char m1;
+};
+
+static inline char f:: *g(int a)
+{
+  return a?0:&f::m;
+}
+
+int h(void)
+{
+  char f:: *a = g(0);
+  return a == 0;
+}
+
+/* We should have no cast to offset_type. */
+/* { dg-final { scan-tree-dump-times "offset_type" 0 "final_cleanup"} } */
+// And we should optimized this code to just return 0
+/* { dg-final { scan-tree-dump-times "return 0" 1 "final_cleanup"} } */
+/* { dg-final { cleanup-tree-dump "final_cleanup" } } */
+