]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c-decl.c (finish_struct): Add DECL_EXPR for variable sized structures seen inside...
authorRichard Henderson <rth@redhat.com>
Sun, 19 Dec 2004 04:07:54 +0000 (20:07 -0800)
committerRichard Henderson <rth@gcc.gnu.org>
Sun, 19 Dec 2004 04:07:54 +0000 (20:07 -0800)
        * c-decl.c (finish_struct): Add DECL_EXPR for variable sized
        structures seen inside functions.

From-SVN: r92371

gcc/ChangeLog
gcc/c-decl.c
gcc/testsuite/gcc.c-torture/execute/20041218-2.c [new file with mode: 0644]

index 51ad04e5266e86d296fadd7073cf53082c0d6afc..f9a9b5628bc2e349ff49522acd4c6de38ed6c07d 100644 (file)
@@ -1,3 +1,8 @@
+2004-12-18  Richard Henderson  <rth@redhat.com>
+
+       * c-decl.c (finish_struct): Add DECL_EXPR for variable sized
+       structures seen inside functions.
+
 2004-12-18  Richard Henderson  <rth@redhat.com>
 
        * c-decl.c (grokdeclarator): Save variable array size before
index b76e2746d99a66e0fec21c8e4411d1e2097372f9..26caa2c47b3457333d1bd8070350c46f4d1a0346 100644 (file)
@@ -5401,6 +5401,12 @@ finish_struct (tree t, tree fieldlist, tree attributes)
   /* Finish debugging output for this type.  */
   rest_of_type_compilation (t, toplevel);
 
+  /* If we're inside a function proper, i.e. not file-scope and not still
+     parsing parameters, then arrange for the size of a variable sized type
+     to be bound now.  */
+  if (cur_stmt_list && variably_modified_type_p (t, NULL))
+    add_stmt (build_stmt (DECL_EXPR, build_decl (TYPE_DECL, NULL, t)));
+
   return t;
 }
 
diff --git a/gcc/testsuite/gcc.c-torture/execute/20041218-2.c b/gcc/testsuite/gcc.c-torture/execute/20041218-2.c
new file mode 100644 (file)
index 0000000..c4b3627
--- /dev/null
@@ -0,0 +1,15 @@
+extern void abort (void);
+
+int test(int n)
+{
+  struct s { char b[n]; };
+  n++;
+  return sizeof(struct s);
+}
+
+int main()
+{
+  if (test(123) != 123)
+    abort ();
+  return 0;
+}