diff options
| author | ebotcazou <ebotcazou@138bc75d-0d04-0410-961f-82ee72b054a4> | 2008-05-25 22:42:49 +0000 |
|---|---|---|
| committer | ebotcazou <ebotcazou@138bc75d-0d04-0410-961f-82ee72b054a4> | 2008-05-25 22:42:49 +0000 |
| commit | 939e9bf1bf48c73472583b60cb57cb962b617274 (patch) | |
| tree | 1a3f8d2557f13dd05aa93e2ca0e800b6a5a115c6 | |
| parent | c50688b2bac252df730e3c3af294ec1a82453e2e (diff) | |
| download | ppe42-gcc-939e9bf1bf48c73472583b60cb57cb962b617274.tar.gz ppe42-gcc-939e9bf1bf48c73472583b60cb57cb962b617274.zip | |
* tree-nested.c (convert_tramp_reference) <ADDR_EXPR>: Do not
build a trampoline if we don't want one.
* varasm.c (initializer_constant_valid_p) <ADDR_EXPR>: Do not
return zero for nested functions if we don't want a trampoline.
ada/
* trans.c (Attribute_to_gnu) <Code_Address>: Set TREE_NO_TRAMPOLINE
instead of TREE_STATIC on the ADDR_EXPR.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@135884 138bc75d-0d04-0410-961f-82ee72b054a4
| -rw-r--r-- | gcc/ChangeLog | 7 | ||||
| -rw-r--r-- | gcc/ada/ChangeLog | 5 | ||||
| -rw-r--r-- | gcc/ada/trans.c | 2 | ||||
| -rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
| -rw-r--r-- | gcc/testsuite/gnat.dg/trampoline1.adb | 23 | ||||
| -rw-r--r-- | gcc/testsuite/gnat.dg/trampoline2.adb | 27 | ||||
| -rw-r--r-- | gcc/tree-nested.c | 4 | ||||
| -rw-r--r-- | gcc/varasm.c | 42 |
8 files changed, 95 insertions, 20 deletions
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 <ebotcazou@adacore.com> + + * tree-nested.c (convert_tramp_reference) <ADDR_EXPR>: Do not + build a trampoline if we don't want one. + * varasm.c (initializer_constant_valid_p) <ADDR_EXPR>: Do not + return zero for nested functions if we don't want a trampoline. + 2008-05-26 Daniel Franke <franke.daniel@gmail.com> * 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 <ebotcazou@adacore.com> + + * trans.c (Attribute_to_gnu) <Code_Address>: Set TREE_NO_TRAMPOLINE + instead of TREE_STATIC on the ADDR_EXPR. + 2008-05-24 Eric Botcazou <ebotcazou@adacore.com> * 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 <ebotcazou@adacore.com> + + * gnat.dg/trampoline1.adb: New test. + * gnat.dg/trampoline2.adb: Likewise. + 2008-05-25 Tobias Burnus <burnus@net-b.de> 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: |

