diff options
author | Tobias Burnus <burnus@net-b.de> | 2007-11-19 13:30:17 +0100 |
---|---|---|
committer | Tobias Burnus <burnus@gcc.gnu.org> | 2007-11-19 13:30:17 +0100 |
commit | bc3e7a8cfc138ec0cdf1f7e39a8c856a25e9b3db (patch) | |
tree | b493494cb6083dff17304745ece59d339bfbb68b /gcc/fortran | |
parent | 4aba7b1186118f8c928047df88a23bfec8d18806 (diff) | |
download | gcc-bc3e7a8cfc138ec0cdf1f7e39a8c856a25e9b3db.zip gcc-bc3e7a8cfc138ec0cdf1f7e39a8c856a25e9b3db.tar.gz gcc-bc3e7a8cfc138ec0cdf1f7e39a8c856a25e9b3db.tar.bz2 |
re PR fortran/34079 (Bind(C): Character argument/return value problems)
2007-11-19 Tobias Burnus <burnus@net-b.de>
PR fortran/34079
* decl.c (gfc_match_entry): Support BIND(C).
(gfc_match_subroutine): Fix comment typo.
2007-11-19 Tobias Burnus <burnus@net-b.de>
PR fortran/34079
* gfortran.dg/bind_c_usage_10_c.c: New.
* gfortran.dg/bind_c_usage_10.f03: New.
From-SVN: r130288
Diffstat (limited to 'gcc/fortran')
-rw-r--r-- | gcc/fortran/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/fortran/decl.c | 64 |
2 files changed, 61 insertions, 9 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index d8c11a5..dbd2c15 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2007-11-19 Tobias Burnus <burnus@net-b.de> + + PR fortran/34079 + * decl.c (gfc_match_entry): Support BIND(C). + (gfc_match_subroutine): Fix comment typo. + 2007-11-18 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR fortran/33317 diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c index 8217c06..78b05c4 100644 --- a/gcc/fortran/decl.c +++ b/gcc/fortran/decl.c @@ -4315,6 +4315,8 @@ gfc_match_entry (void) gfc_entry_list *el; locus old_loc; bool module_procedure; + char peek_char; + match is_bind_c; m = gfc_match_name (name); if (m != MATCH_YES) @@ -4398,6 +4400,26 @@ gfc_match_entry (void) proc = gfc_current_block (); + /* Make sure that it isn't already declared as BIND(C). If it is, it + must have been marked BIND(C) with a BIND(C) attribute and that is + not allowed for procedures. */ + if (entry->attr.is_bind_c == 1) + { + entry->attr.is_bind_c = 0; + if (entry->old_symbol != NULL) + gfc_error_now ("BIND(C) attribute at %L can only be used for " + "variables or common blocks", + &(entry->old_symbol->declared_at)); + else + gfc_error_now ("BIND(C) attribute at %L can only be used for " + "variables or common blocks", &gfc_current_locus); + } + + /* Check what next non-whitespace character is so we can tell if there + is the required parens if we have a BIND(C). */ + gfc_gobble_whitespace (); + peek_char = gfc_peek_char (); + if (state == COMP_SUBROUTINE) { /* An entry in a subroutine. */ @@ -4408,6 +4430,21 @@ gfc_match_entry (void) if (m != MATCH_YES) return MATCH_ERROR; + is_bind_c = gfc_match_bind_c (entry); + if (is_bind_c == MATCH_ERROR) + return MATCH_ERROR; + if (is_bind_c == MATCH_YES) + { + if (peek_char != '(') + { + gfc_error ("Missing required parentheses before BIND(C) at %C"); + return MATCH_ERROR; + } + if (gfc_add_is_bind_c (&(entry->attr), entry->name, &(entry->declared_at), 1) + == FAILURE) + return MATCH_ERROR; + } + if (gfc_add_entry (&entry->attr, entry->name, NULL) == FAILURE || gfc_add_subroutine (&entry->attr, entry->name, NULL) == FAILURE) return MATCH_ERROR; @@ -4452,19 +4489,28 @@ gfc_match_entry (void) } else { - m = match_result (proc, &result); + m = gfc_match_suffix (entry, &result); if (m == MATCH_NO) gfc_syntax_error (ST_ENTRY); if (m != MATCH_YES) return MATCH_ERROR; - if (gfc_add_result (&result->attr, result->name, NULL) == FAILURE - || gfc_add_entry (&entry->attr, result->name, NULL) == FAILURE - || gfc_add_function (&entry->attr, result->name, NULL) - == FAILURE) - return MATCH_ERROR; - - entry->result = result; + if (result) + { + if (gfc_add_result (&result->attr, result->name, NULL) == FAILURE + || gfc_add_entry (&entry->attr, result->name, NULL) == FAILURE + || gfc_add_function (&entry->attr, result->name, NULL) + == FAILURE) + return MATCH_ERROR; + entry->result = result; + } + else + { + if (gfc_add_entry (&entry->attr, entry->name, NULL) == FAILURE + || gfc_add_function (&entry->attr, entry->name, NULL) == FAILURE) + return MATCH_ERROR; + entry->result = entry; + } } } @@ -4523,7 +4569,7 @@ gfc_match_subroutine (void) gfc_new_block = sym; /* Check what next non-whitespace character is so we can tell if there - where the required parens if we have a BIND(C). */ + is the required parens if we have a BIND(C). */ gfc_gobble_whitespace (); peek_char = gfc_peek_char (); |