Skip to content

Commit ffcc43c

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 914931c commit ffcc43c

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
@@ -24045,9 +24045,9 @@ aarch64_libgcc_floating_mode_supported_p
2404524045
#define TARGET_DWARF_POLY_INDETERMINATE_VALUE \
2404624046
aarch64_dwarf_poly_indeterminate_value
2404724047

24048-
/* The architecture reserves bits 0 and 1 so use bit 2 for descriptors. */
24048+
/* The architecture reserves bits 0 and 1 but hack 1 for now. */
2404924049
#undef TARGET_CUSTOM_FUNCTION_DESCRIPTORS
24050-
#define TARGET_CUSTOM_FUNCTION_DESCRIPTORS 4
24050+
#define TARGET_CUSTOM_FUNCTION_DESCRIPTORS 2
2405124051

2405224052
#undef TARGET_HARD_REGNO_NREGS
2405324053
#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
@@ -331,3 +331,13 @@ along with GCC; see the file COPYING3. If not see
331331
= darwin_init_cfstring_builtins ((unsigned) (IX86_BUILTIN_CFSTRING)); \
332332
darwin_rename_builtins (); \
333333
} while(0)
334+
335+
/* Define the shadow offset for asan. */
336+
#undef SUBTARGET_SHADOW_OFFSET
337+
#define SUBTARGET_SHADOW_OFFSET \
338+
(TARGET_LP64 ? HOST_WIDE_INT_1 << 44 : HOST_WIDE_INT_1 << 29)
339+
340+
/* Make sure that any code we generate is compatible with the Fortran/Ada
341+
function descriptor impl. */
342+
#undef FUNCTION_BOUNDARY
343+
#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
@@ -7123,6 +7123,8 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym,
71237123
arglist = retargs;
71247124

71257125
/* Generate the actual call. */
7126+
bool is_proc_ptr_comp = gfc_is_proc_ptr_comp (expr);
7127+
71267128
if (base_object == NULL_TREE)
71277129
conv_function_val (se, sym, expr, args);
71287130
else
@@ -7148,6 +7150,11 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym,
71487150

71497151
fntype = TREE_TYPE (TREE_TYPE (se->expr));
71507152
se->expr = build_call_vec (TREE_TYPE (fntype), se->expr, arglist);
7153+
tree ff = CALL_EXPR_FN (se->expr);
7154+
if (ff && INDIRECT_REF_P (ff))
7155+
ff = TREE_OPERAND (ff, 0);
7156+
if (is_proc_ptr_comp || !ff || VAR_P (ff) || TREE_CODE (ff) == PARM_DECL)
7157+
CALL_EXPR_BY_DESCRIPTOR (se->expr) = true;
71517158

71527159
/* Allocatable scalar function results must be freed and nullified
71537160
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)