Commit 3651f7ad by Eric Botcazou Committed by Eric Botcazou

tree-nested.c (convert_tramp_reference): Do not build a trampoline if we don't want one.

	 * 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.

From-SVN: r135884
parent b885a4c1
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> 2008-05-26 Daniel Franke <franke.daniel@gmail.com>
* doc/invoke.texi: Added f77, f77-cpp-input to list of file types. * doc/invoke.texi: Added f77, f77-cpp-input to list of file types.
......
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> 2008-05-24 Eric Botcazou <ebotcazou@adacore.com>
* trans.c (gnat_to_gnu): Do not set source location info on NOP_EXPRs. * trans.c (gnat_to_gnu): Do not set source location info on NOP_EXPRs.
...@@ -920,7 +920,7 @@ Attribute_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, int attribute) ...@@ -920,7 +920,7 @@ Attribute_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, int attribute)
TREE_CONSTANT (gnu_expr) = 1; TREE_CONSTANT (gnu_expr) = 1;
if (TREE_CODE (gnu_expr) == ADDR_EXPR) 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, /* For other address attributes applied to a nested function,
......
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> 2008-05-25 Tobias Burnus <burnus@net-b.de>
PR fortran/32600 PR fortran/32600
......
-- { 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" } }
-- { 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;
...@@ -1645,6 +1645,10 @@ convert_tramp_reference (tree *tp, int *walk_subtrees, void *data) ...@@ -1645,6 +1645,10 @@ convert_tramp_reference (tree *tp, int *walk_subtrees, void *data)
if (DECL_NO_STATIC_CHAIN (decl)) if (DECL_NO_STATIC_CHAIN (decl))
break; 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 /* Lookup the immediate parent of the callee, as that's where
we need to insert the trampoline. */ we need to insert the trampoline. */
for (i = info; i->context != target_context; i = i->outer) for (i = info; i->context != target_context; i = i->outer)
......
...@@ -4099,25 +4099,29 @@ initializer_constant_valid_p (tree value, tree endtype) ...@@ -4099,25 +4099,29 @@ initializer_constant_valid_p (tree value, tree endtype)
case ADDR_EXPR: case ADDR_EXPR:
case FDESC_EXPR: case FDESC_EXPR:
value = staticp (TREE_OPERAND (value, 0)); {
if (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. */ /* "&(*a).f" is like unto pointer arithmetic. If "a" turns out
if (TREE_CODE (value) == INDIRECT_REF to be a constant, this is old-skool offsetof-like nonsense. */
&& TREE_CONSTANT (TREE_OPERAND (value, 0))) if (TREE_CODE (op0) == INDIRECT_REF
return null_pointer_node; && TREE_CONSTANT (TREE_OPERAND (op0, 0)))
/* Taking the address of a nested function involves a trampoline. */ return null_pointer_node;
if (TREE_CODE (value) == FUNCTION_DECL /* Taking the address of a nested function involves a trampoline,
&& decl_function_context (value) unless we don't need or want one. */
&& !DECL_NO_STATIC_CHAIN (value)) if (TREE_CODE (op0) == FUNCTION_DECL
return NULL_TREE; && decl_function_context (op0)
/* "&{...}" requires a temporary to hold the constructed && !DECL_NO_STATIC_CHAIN (op0)
object. */ && !TREE_NO_TRAMPOLINE (value))
if (TREE_CODE (value) == CONSTRUCTOR) return NULL_TREE;
return NULL_TREE; /* "&{...}" requires a temporary to hold the constructed
} object. */
return value; if (TREE_CODE (op0) == CONSTRUCTOR)
return NULL_TREE;
}
return op0;
}
case VIEW_CONVERT_EXPR: case VIEW_CONVERT_EXPR:
case NON_LVALUE_EXPR: case NON_LVALUE_EXPR:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment