OSDN Git Service

PR middle-end/49732
authorebotcazou <ebotcazou@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 17 Jul 2011 15:06:36 +0000 (15:06 +0000)
committerebotcazou <ebotcazou@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 17 Jul 2011 15:06:36 +0000 (15:06 +0000)
* tree.c (walk_tree_1) <DECL_EXPR>: Do not walk a pointed-to type.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@176371 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gnat.dg/pointer_controlled.adb [new file with mode: 0644]
gcc/tree.c

index 8608327..84e9ad5 100644 (file)
@@ -1,3 +1,8 @@
+2011-07-17  Eric Botcazou  <ebotcazou@adacore.com>
+
+       PR middle-end/49732
+       * tree.c (walk_tree_1) <DECL_EXPR>: Do not walk a pointed-to type.
+
 2011-07-16  Matthias Klose  <doko@ubuntu.com>
 
        * doc/install.texi: Document --enable-static-libjava.
index 6abed53..2e5683c 100644 (file)
@@ -1,3 +1,7 @@
+2011-07-17  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gnat.dg/pointer_controlled.adb: New test.
+
 2011-07-17  Tobias Burnus  <burnus@net-b.de>
 
        PR fortran/49624
diff --git a/gcc/testsuite/gnat.dg/pointer_controlled.adb b/gcc/testsuite/gnat.dg/pointer_controlled.adb
new file mode 100644 (file)
index 0000000..1d85b53
--- /dev/null
@@ -0,0 +1,31 @@
+-- PR ada/49732
+-- Testcase by Vorfeed Canal
+
+-- { dg-do compile }
+-- { dg-options "-gnato" }
+
+with Interfaces.C; use Interfaces.C;
+with Interfaces.C.Strings; use Interfaces.C.Strings;
+with Interfaces.C.Pointers;
+
+procedure Pointer_Controlled is
+
+   function Create (Name : String) return size_t is
+
+      type Name_String is new char_array (0 .. Name'Length);
+      type Name_String_Ptr is access Name_String;
+      pragma Controlled (Name_String_Ptr);
+
+      Name_Str : constant Name_String_Ptr := new Name_String;
+      Name_Len : size_t;
+
+   begin
+      To_C (Name, Name_Str.all, Name_Len);
+      return 1;
+   end;
+
+   Test : size_t;
+
+begin
+   Test := Create("ABC");
+end;
index acc3841..10f50de 100644 (file)
@@ -10596,9 +10596,14 @@ walk_tree_1 (tree *tp, walk_tree_fn func, void *data,
          if (result || !walk_subtrees)
            return result;
 
-         result = walk_type_fields (*type_p, func, data, pset, lh);
-         if (result)
-           return result;
+         /* But do not walk a pointed-to type since it may itself need to
+            be walked in the declaration case if it isn't anonymous.  */
+         if (!POINTER_TYPE_P (*type_p))
+           {
+             result = walk_type_fields (*type_p, func, data, pset, lh);
+             if (result)
+               return result;
+           }
 
          /* If this is a record type, also walk the fields.  */
          if (RECORD_OR_UNION_TYPE_P (*type_p))