From 20d4a9e21ca1a7d800661cb7f4cdf47ead4e2b70 Mon Sep 17 00:00:00 2001 From: Sergi Mateo Bellido Date: Tue, 8 May 2018 08:07:16 +0200 Subject: [PATCH] A Fortran enumerator may be an argument of a function call --- src/frontend/fortran/fortran03-exprtype.c | 20 +++++++++++++++++--- tests/01_fortran.dg/success_modules_081.F90 | 2 ++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/frontend/fortran/fortran03-exprtype.c b/src/frontend/fortran/fortran03-exprtype.c index 00ed3a7d75..98a731ce2c 100644 --- a/src/frontend/fortran/fortran03-exprtype.c +++ b/src/frontend/fortran/fortran03-exprtype.c @@ -4425,10 +4425,11 @@ static void check_symbol_of_argument(AST sym, const decl_context_t* decl_context } } } - - if (entry == NULL || + + if (entry == NULL || (entry->kind != SK_VARIABLE && - entry->kind != SK_FUNCTION && + entry->kind != SK_FUNCTION && + entry->kind != SK_ENUMERATOR && entry->kind != SK_UNDEFINED)) { error_printf_at(ast_get_locus(sym), "'%s' cannot be an argument\n", entry->symbol_name); @@ -4439,6 +4440,19 @@ static void check_symbol_of_argument(AST sym, const decl_context_t* decl_context { check_symbol_name_as_a_variable(sym, entry, decl_context, nodecl_output); } + else if (entry->kind == SK_ENUMERATOR) + { + if (nodecl_is_null(entry->value) + || !nodecl_is_constant(entry->value)) + { + error_printf_at(ast_get_locus(sym), "'%s' is not a valid enumerator\n", entry->symbol_name); + *nodecl_output = nodecl_make_err_expr(ast_get_locus(sym)); + return; + } + + // Use the constant value instead + *nodecl_output = fortran_const_value_to_nodecl(nodecl_get_constant(entry->value)); + } else if (entry->kind == SK_FUNCTION) { *nodecl_output = nodecl_make_symbol(entry, ast_get_locus(sym)); diff --git a/tests/01_fortran.dg/success_modules_081.F90 b/tests/01_fortran.dg/success_modules_081.F90 index 8c4743c7d0..5235df085c 100644 --- a/tests/01_fortran.dg/success_modules_081.F90 +++ b/tests/01_fortran.dg/success_modules_081.F90 @@ -9,4 +9,6 @@ MODULE M ENUM, BIND(C) ENUMERATOR :: E1 END ENUM + + INTEGER(KIND(E1)) :: VAR = 0 END MODULE M