PR middle-end/18820
authorebotcazou <ebotcazou@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 14 Jan 2005 08:03:20 +0000 (08:03 +0000)
committerebotcazou <ebotcazou@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 14 Jan 2005 08:03:20 +0000 (08:03 +0000)
* varasm.c (initializer_constant_valid_p) <ADDR_EXPR>: Return
zero for nested functions needing a static chain or functions
with a non-constant address.

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

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/ada/acats/norun.lst
gcc/testsuite/gcc.dg/nested-func-2.c [new file with mode: 0644]
gcc/varasm.c

index d148319..9e73321 100644 (file)
@@ -1,3 +1,10 @@
+2005-01-14  Eric Botcazou  <ebotcazou@libertysurf.fr>
+
+       PR middle-end/18820
+       * varasm.c (initializer_constant_valid_p) <ADDR_EXPR>: Return
+       zero for nested functions needing a static chain or functions
+       with a non-constant address.
+
 2005-01-13  Roger Sayle  <roger@eyesopen.com>
 
        * simplify-rtx.c (simplify_binary_operation) <AND>: Optimize
index 90a14e2..62cda60 100644 (file)
@@ -1,3 +1,8 @@
+2005-01-14  Eric Botcazou  <ebotcazou@libertysurf.fr>
+
+       * gcc.dg/nested-func-2.c: New test.
+       * ada/acats/norun.lst: Remove c953002.
+
 2005-01-12  Ulrich Weigand  <uweigand@de.ibm.com>
 
        * gcc.dg/ftrapv-2.c (labsv): Call labs instead of abs.
index 5d21693..049965b 100644 (file)
@@ -1,8 +1,6 @@
 c380004
-c953002
 cdd2a03
 templat
 # Tests must be sorted in alphabetical order
 # c380004: should be front-end compile time error, PR ada/18817
-# c953002: often hanging, PR ada/18820
 # cdd2a03: new Ada ruling not supported yet, PR ada/19323
diff --git a/gcc/testsuite/gcc.dg/nested-func-2.c b/gcc/testsuite/gcc.dg/nested-func-2.c
new file mode 100644 (file)
index 0000000..14f14c6
--- /dev/null
@@ -0,0 +1,28 @@
+/* PR middle-end/18820 */
+/* Check that we reject nested functions as initializers
+   of static variables.  */
+
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+struct S {
+  void (*f)(int);
+};
+
+extern void baz(struct S *);
+extern void p(int);
+
+void foo(void)
+{
+  int u;
+
+  void bar(int val)
+    {
+      u = val;
+    }
+
+  static struct S s = { bar }; /* { dg-error "(is not constant)|(near initialization)" } */
+
+  baz(&s);
+  p(u);
+}
index ba0aab5..8252f0e 100644 (file)
@@ -3501,6 +3501,12 @@ initializer_constant_valid_p (tree value, tree endtype)
          && TREE_CODE (value) == INDIRECT_REF
          && TREE_CONSTANT (TREE_OPERAND (value, 0)))
        return null_pointer_node;
+      /* Taking the address of a nested function involves a trampoline.  */
+      if (value
+         && TREE_CODE (value) == FUNCTION_DECL
+         && ((decl_function_context (value) && !DECL_NO_STATIC_CHAIN (value))
+             || DECL_NON_ADDR_CONST_P (value)))
+       return NULL_TREE;
       return value;
 
     case VIEW_CONVERT_EXPR: