This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [fortran, patch] Add PROTECTED support (PR23994) - committed
- From: Tobias Burnus <burnus at net-b dot de>
- To: Paul Thomas <paulthomas2 at wanadoo dot fr>
- Cc: "'fortran at gcc dot gnu dot org'" <fortran at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Sun, 10 Dec 2006 20:57:45 +0100
- Subject: Re: [fortran, patch] Add PROTECTED support (PR23994) - committed
- References: <457BF46C.3050401@net-b.de> <457C1B3F.80906@wanadoo.fr>
Hi Paul,
Paul Thomas wrote:
> That's two sentences :-)
Next time, I will really write it in one sentence - in the way Thomas
Mann and Leo Tolstoy are doing: Writing a very long sentence.
(Allegedly, Thomas Mann has written one, which exceeds the length of one
page.)
> By the way, the patch was terminated with CR/LFs, although it might
> have been my mail client... but I don't think so.
Since I use only Linux , I don't think so. Also if I open
protected3.diff, vim doesn't show "[DOS]".
> Has a tab been lost here, or is it wrapping around?
Wrapped by the email program.
>> + if (a->expr->expr_type == EXPR_VARIABLE
>> + && a->expr->symtree->n.sym->attr.protected
>> + && a->expr->symtree->n.sym->attr.use_assoc
>> + && (f->sym->attr.intent == INTENT_OUT
>> + || f->sym->attr.intent == INTENT_INOUT)
>> + && (!a->expr->symtree->n.sym->attr.pointer
>> + || (a->expr->symtree->n.sym->attr.pointer
>> + && f->sym->attr.pointer)))
>>
> It would match the style of interface.c better to put the condition
> into a separate function and would be clearer as well.
Ok, done so. But actually I was following interface.c; the check for
"Actual argument for '%s' cannot be an assumed-size array" doesn't look
much different.
> if (f->sym->attr.intent == INTENT_IN)
> return 0;
>
> might not be as concise (and maybe not correct - check it)
It is not correct as also INTENT_UNKNOWN is possible.
> Regtested also on Cygwin_NT/amd64 -OK for trunk after attending to a
> couple of little niggles below.
Thanks for testing, finding the reason for my problem and for reviewing!
Checked in with the following changes (interdiff).
Tobias
diff -u gcc/fortran/interface.c gcc/fortran/interface.c
--- gcc/fortran/interface.c (working copy)
+++ gcc/fortran/interface.c (Arbeitskopie)
@@ -1206,6 +1206,36 @@
}
+/* Given a symbol of a formal argument list and an expression, see if
+ the two are compatible as arguments. Returns nonzero if
+ compatible, zero if not compatible. */
+
+static int
+compare_parameter_protected (gfc_symbol * formal, gfc_expr * actual)
+{
+ if (actual->expr_type != EXPR_VARIABLE)
+ return 1;
+
+ if (!actual->symtree->n.sym->attr.protected)
+ return 1;
+
+ if (!actual->symtree->n.sym->attr.use_assoc)
+ return 1;
+
+ if (formal->attr.intent == INTENT_IN
+ || formal->attr.intent == INTENT_UNKNOWN)
+ return 1;
+
+ if (!actual->symtree->n.sym->attr.pointer)
+ return 0;
+ return 0;
+
+ if (actual->symtree->n.sym->attr.pointer && formal->attr.pointer)
+ return 0;
+
+ return 1;
+}
+
+
/* Given formal and actual argument lists, see if they are compatible.
If they are compatible, the actual argument list is sorted to
correspond with the formal list, and elements for missing optional
@@ -1393,18 +1423,7 @@
return 0;
}
- /* Check whether the actual argument has PROTECTED attribute.
- For nonpointers, their value may not be changed, for pointers
- their association status may not be changed (contrary to its
- target). */
- if (a->expr->expr_type == EXPR_VARIABLE
- && a->expr->symtree->n.sym->attr.protected
- && a->expr->symtree->n.sym->attr.use_assoc
- && (f->sym->attr.intent == INTENT_OUT
- || f->sym->attr.intent == INTENT_INOUT)
- && (!a->expr->symtree->n.sym->attr.pointer
- || (a->expr->symtree->n.sym->attr.pointer
- && f->sym->attr.pointer)))
+ if (!compare_parameter_protected(f->sym, a->expr))
{
if (where)
gfc_error ("Actual argument at %L is use-associated with "