From 3651f7ad941bc7dd797d5e5948c9922da0fb6f8c Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Sun, 25 May 2008 22:42:49 +0000 Subject: [PATCH] tree-nested.c (convert_tramp_reference): Do not build a trampoline if we don't want one. * tree-nested.c (convert_tramp_reference) : Do not build a trampoline if we don't want one. * varasm.c (initializer_constant_valid_p) : Do not return zero for nested functions if we don't want a trampoline. ada/ * trans.c (Attribute_to_gnu) : Set TREE_NO_TRAMPOLINE instead of TREE_STATIC on the ADDR_EXPR. From-SVN: r135884 --- gcc/ChangeLog | 7 +++++ gcc/ada/ChangeLog | 5 ++++ gcc/ada/trans.c | 2 +- gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/gnat.dg/trampoline1.adb | 23 +++++++++++++++ gcc/testsuite/gnat.dg/trampoline2.adb | 27 +++++++++++++++++ gcc/tree-nested.c | 4 +++ gcc/varasm.c | 42 +++++++++++++++------------ 8 files changed, 95 insertions(+), 20 deletions(-) create mode 100644 gcc/testsuite/gnat.dg/trampoline1.adb create mode 100644 gcc/testsuite/gnat.dg/trampoline2.adb diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 6922a02d170..b456a499a32 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2008-05-25 Eric Botcazou + + * tree-nested.c (convert_tramp_reference) : Do not + build a trampoline if we don't want one. + * varasm.c (initializer_constant_valid_p) : Do not + return zero for nested functions if we don't want a trampoline. + 2008-05-26 Daniel Franke * doc/invoke.texi: Added f77, f77-cpp-input to list of file types. diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index f7305e8ef4f..c2ffb5eaa63 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,8 @@ +2008-05-25 Eric Botcazou + + * trans.c (Attribute_to_gnu) : Set TREE_NO_TRAMPOLINE + instead of TREE_STATIC on the ADDR_EXPR. + 2008-05-24 Eric Botcazou * trans.c (gnat_to_gnu): Do not set source location info on NOP_EXPRs. diff --git a/gcc/ada/trans.c b/gcc/ada/trans.c index 5f579e71b45..717c14bbf6a 100644 --- a/gcc/ada/trans.c +++ b/gcc/ada/trans.c @@ -920,7 +920,7 @@ Attribute_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, int attribute) TREE_CONSTANT (gnu_expr) = 1; if (TREE_CODE (gnu_expr) == ADDR_EXPR) - TREE_STATIC (gnu_expr) = TREE_CONSTANT (gnu_expr) = 1; + TREE_NO_TRAMPOLINE (gnu_expr) = TREE_CONSTANT (gnu_expr) = 1; } /* For other address attributes applied to a nested function, diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 2cc96bf4f26..b81a420aaf0 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2008-05-25 Eric Botcazou + + * gnat.dg/trampoline1.adb: New test. + * gnat.dg/trampoline2.adb: Likewise. + 2008-05-25 Tobias Burnus PR fortran/32600 diff --git a/gcc/testsuite/gnat.dg/trampoline1.adb b/gcc/testsuite/gnat.dg/trampoline1.adb new file mode 100644 index 00000000000..065b373f07c --- /dev/null +++ b/gcc/testsuite/gnat.dg/trampoline1.adb @@ -0,0 +1,23 @@ +-- { dg-do compile } +-- { dg-options "-gnatws" } + +with System; use System; + +procedure Trampoline1 is + + A : Integer; + + function F (I : Integer) return Integer is + begin + return A + I; + end F; + + CA : System.Address := F'Code_Address; + +begin + if CA = System.Null_Address then + raise Program_Error; + end if; +end; + +-- { dg-final { scan-assembler-not "GNU-stack.*x" } } diff --git a/gcc/testsuite/gnat.dg/trampoline2.adb b/gcc/testsuite/gnat.dg/trampoline2.adb new file mode 100644 index 00000000000..26b42722ac7 --- /dev/null +++ b/gcc/testsuite/gnat.dg/trampoline2.adb @@ -0,0 +1,27 @@ +-- { dg-do run } +-- { dg-options "-gnatws" } + +with System; use System; + +procedure Trampoline2 is + + A : Integer; + + type FuncPtr is access function (I : Integer) return Integer; + + function F (I : Integer) return Integer is + begin + return A + I; + end F; + + P : FuncPtr := F'Access; + CA : System.Address := F'Code_Address; + I : Integer; + +begin + if CA = System.Null_Address then + raise Program_Error; + end if; + + I := P(0); +end; diff --git a/gcc/tree-nested.c b/gcc/tree-nested.c index e3330032c03..ded3c2bf49b 100644 --- a/gcc/tree-nested.c +++ b/gcc/tree-nested.c @@ -1645,6 +1645,10 @@ convert_tramp_reference (tree *tp, int *walk_subtrees, void *data) if (DECL_NO_STATIC_CHAIN (decl)) break; + /* If we don't want a trampoline, then don't build one. */ + if (TREE_NO_TRAMPOLINE (t)) + break; + /* Lookup the immediate parent of the callee, as that's where we need to insert the trampoline. */ for (i = info; i->context != target_context; i = i->outer) diff --git a/gcc/varasm.c b/gcc/varasm.c index d9468c4997d..2202ce11098 100644 --- a/gcc/varasm.c +++ b/gcc/varasm.c @@ -4099,25 +4099,29 @@ initializer_constant_valid_p (tree value, tree endtype) case ADDR_EXPR: case FDESC_EXPR: - value = staticp (TREE_OPERAND (value, 0)); - if (value) - { - /* "&(*a).f" is like unto pointer arithmetic. If "a" turns out to - be a constant, this is old-skool offsetof-like nonsense. */ - if (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 (TREE_CODE (value) == FUNCTION_DECL - && decl_function_context (value) - && !DECL_NO_STATIC_CHAIN (value)) - return NULL_TREE; - /* "&{...}" requires a temporary to hold the constructed - object. */ - if (TREE_CODE (value) == CONSTRUCTOR) - return NULL_TREE; - } - return value; + { + tree op0 = staticp (TREE_OPERAND (value, 0)); + if (op0) + { + /* "&(*a).f" is like unto pointer arithmetic. If "a" turns out + to be a constant, this is old-skool offsetof-like nonsense. */ + if (TREE_CODE (op0) == INDIRECT_REF + && TREE_CONSTANT (TREE_OPERAND (op0, 0))) + return null_pointer_node; + /* Taking the address of a nested function involves a trampoline, + unless we don't need or want one. */ + if (TREE_CODE (op0) == FUNCTION_DECL + && decl_function_context (op0) + && !DECL_NO_STATIC_CHAIN (op0) + && !TREE_NO_TRAMPOLINE (value)) + return NULL_TREE; + /* "&{...}" requires a temporary to hold the constructed + object. */ + if (TREE_CODE (op0) == CONSTRUCTOR) + return NULL_TREE; + } + return op0; + } case VIEW_CONVERT_EXPR: case NON_LVALUE_EXPR: -- 2.30.2