Skip to content

Commit c76d611

Browse files
iainscatap
authored andcommitted
Darwin, Arm64 : Proof-of-principle hack Fortran to use descriptors for nested.
This addresses Issue gcc-mirror#32 by adjusting the nested function hack to use bit 1. NOTE: that Arm reserve both bits 0 and 1 for furture use, so that this is still a hack. (cherry picked from commit eb558326dace69781e48bedafe16fd79aa27ca8b) (cherry picked from commit 3422978e480e66623a25e757634d20da0e132c0b)
1 parent a762a2a commit c76d611

File tree

6 files changed

+35
-2
lines changed

6 files changed

+35
-2
lines changed

gcc/c/c-lang.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ enum c_language_kind c_language = clk_c;
3838
#undef LANG_HOOKS_INIT_TS
3939
#define LANG_HOOKS_INIT_TS c_common_init_ts
4040

41+
#undef LANG_HOOKS_CUSTOM_FUNCTION_DESCRIPTORS
42+
#define LANG_HOOKS_CUSTOM_FUNCTION_DESCRIPTORS true
43+
4144
#if CHECKING_P
4245
#undef LANG_HOOKS_RUN_LANG_SELFTESTS
4346
#define LANG_HOOKS_RUN_LANG_SELFTESTS selftest::run_c_tests

gcc/config/aarch64/aarch64.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24039,9 +24039,9 @@ aarch64_libgcc_floating_mode_supported_p
2403924039
#define TARGET_DWARF_POLY_INDETERMINATE_VALUE \
2404024040
aarch64_dwarf_poly_indeterminate_value
2404124041

24042-
/* The architecture reserves bits 0 and 1 so use bit 2 for descriptors. */
24042+
/* The architecture reserves bits 0 and 1 but hack 1 for now. */
2404324043
#undef TARGET_CUSTOM_FUNCTION_DESCRIPTORS
24044-
#define TARGET_CUSTOM_FUNCTION_DESCRIPTORS 4
24044+
#define TARGET_CUSTOM_FUNCTION_DESCRIPTORS 2
2404524045

2404624046
#undef TARGET_HARD_REGNO_NREGS
2404724047
#define TARGET_HARD_REGNO_NREGS aarch64_hard_regno_nregs

gcc/config/i386/darwin.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,3 +323,13 @@ along with GCC; see the file COPYING3. If not see
323323
= darwin_init_cfstring_builtins ((unsigned) (IX86_BUILTIN_CFSTRING)); \
324324
darwin_rename_builtins (); \
325325
} while(0)
326+
327+
/* Define the shadow offset for asan. */
328+
#undef SUBTARGET_SHADOW_OFFSET
329+
#define SUBTARGET_SHADOW_OFFSET \
330+
(TARGET_LP64 ? HOST_WIDE_INT_1 << 44 : HOST_WIDE_INT_1 << 29)
331+
332+
/* Make sure that any code we generate is compatible with the Fortran/Ada
333+
function descriptor impl. */
334+
#undef FUNCTION_BOUNDARY
335+
#define FUNCTION_BOUNDARY 16

gcc/fortran/f95-lang.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ static const struct attribute_spec gfc_attribute_table[] =
169169
#define LANG_HOOKS_BUILTIN_FUNCTION gfc_builtin_function
170170
#define LANG_HOOKS_GET_ARRAY_DESCR_INFO gfc_get_array_descr_info
171171
#define LANG_HOOKS_ATTRIBUTE_TABLE gfc_attribute_table
172+
#undef LANG_HOOKS_CUSTOM_FUNCTION_DESCRIPTORS
173+
#define LANG_HOOKS_CUSTOM_FUNCTION_DESCRIPTORS true
172174

173175
struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
174176

gcc/fortran/trans-expr.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7121,6 +7121,8 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym,
71217121
arglist = retargs;
71227122

71237123
/* Generate the actual call. */
7124+
bool is_proc_ptr_comp = gfc_is_proc_ptr_comp (expr);
7125+
71247126
if (base_object == NULL_TREE)
71257127
conv_function_val (se, sym, expr, args);
71267128
else
@@ -7146,6 +7148,11 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym,
71467148

71477149
fntype = TREE_TYPE (TREE_TYPE (se->expr));
71487150
se->expr = build_call_vec (TREE_TYPE (fntype), se->expr, arglist);
7151+
tree ff = CALL_EXPR_FN (se->expr);
7152+
if (ff && INDIRECT_REF_P (ff))
7153+
ff = TREE_OPERAND (ff, 0);
7154+
if (is_proc_ptr_comp || !ff || VAR_P (ff) || TREE_CODE (ff) == PARM_DECL)
7155+
CALL_EXPR_BY_DESCRIPTOR (se->expr) = true;
71497156

71507157
/* Allocatable scalar function results must be freed and nullified
71517158
after use. This necessitates the creation of a temporary to

gcc/fortran/trans.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,14 @@ gfc_build_addr_expr (tree type, tree t)
288288
else
289289
natural_type = build_pointer_type (base_type);
290290

291+
/* If this is a nested function that uses the static chain, or if
292+
optimization is disabled (a static chain will be added automatically)
293+
then call by descriptor. */
294+
bool fn_with_static_chain = false;
295+
if (TREE_CODE (t) == FUNCTION_DECL
296+
&& (DECL_STATIC_CHAIN (t) || (!optimize && decl_function_context (t))))
297+
fn_with_static_chain = true;
298+
291299
if (TREE_CODE (t) == INDIRECT_REF)
292300
{
293301
if (!type)
@@ -306,6 +314,9 @@ gfc_build_addr_expr (tree type, tree t)
306314
if (type && natural_type != type)
307315
t = convert (type, t);
308316

317+
if (fn_with_static_chain)
318+
FUNC_ADDR_BY_DESCRIPTOR (t) = true;
319+
309320
return t;
310321
}
311322

0 commit comments

Comments
 (0)