diff mbox

[Fortran,OOP] PR 63733: [4.8/4.9/5 Regression] wrong resolution for OPERATOR generics

Message ID CAKwh3qj_XvUzB_4LQ4d3dAx11gCGMd6O9bS0-c_t7YL9EQi_YA@mail.gmail.com
State New
Headers show

Commit Message

Janus Weil Jan. 11, 2015, 1:38 p.m. UTC
Hi all,

this patch fixes a wrong-code regression related to operators, by
making sure that we look for typebound operators first, before looking
for non-typebound ones. (Note: Each typebound operator is also added
to the list of non-typebound ones, for reasons of diagnostics.)

Regtested on x86_64-unknown-linux-gnu. Ok for trunk? 4.9/4.8?

Cheers,
Janus



2015-01-11  Janus Weil  <janus@gcc.gnu.org>

    PR fortran/63733
    * interface.c (gfc_extend_expr): Look for type-bound operators before
    non-typebound ones.

2015-01-11  Janus Weil  <janus@gcc.gnu.org>

    PR fortran/63733
    * gfortran.dg/typebound_operator_20.f90: New.

Comments

Paul Richard Thomas Jan. 11, 2015, 8:36 p.m. UTC | #1
Dear Janus,

Well done for sorting that out. OK for trunk.

Thanks for the patch.

Paul

On 11 January 2015 at 14:38, Janus Weil <janus@gcc.gnu.org> wrote:
> Hi all,
>
> this patch fixes a wrong-code regression related to operators, by
> making sure that we look for typebound operators first, before looking
> for non-typebound ones. (Note: Each typebound operator is also added
> to the list of non-typebound ones, for reasons of diagnostics.)
>
> Regtested on x86_64-unknown-linux-gnu. Ok for trunk? 4.9/4.8?
>
> Cheers,
> Janus
>
>
>
> 2015-01-11  Janus Weil  <janus@gcc.gnu.org>
>
>     PR fortran/63733
>     * interface.c (gfc_extend_expr): Look for type-bound operators before
>     non-typebound ones.
>
> 2015-01-11  Janus Weil  <janus@gcc.gnu.org>
>
>     PR fortran/63733
>     * gfortran.dg/typebound_operator_20.f90: New.
Janus Weil Jan. 11, 2015, 10:01 p.m. UTC | #2
> Well done for sorting that out. OK for trunk.

Thanks, Paul. Committed as r219440.

What about the branches?

Cheers,
Janus



> On 11 January 2015 at 14:38, Janus Weil <janus@gcc.gnu.org> wrote:
>> Hi all,
>>
>> this patch fixes a wrong-code regression related to operators, by
>> making sure that we look for typebound operators first, before looking
>> for non-typebound ones. (Note: Each typebound operator is also added
>> to the list of non-typebound ones, for reasons of diagnostics.)
>>
>> Regtested on x86_64-unknown-linux-gnu. Ok for trunk? 4.9/4.8?
>>
>> Cheers,
>> Janus
>>
>>
>>
>> 2015-01-11  Janus Weil  <janus@gcc.gnu.org>
>>
>>     PR fortran/63733
>>     * interface.c (gfc_extend_expr): Look for type-bound operators before
>>     non-typebound ones.
>>
>> 2015-01-11  Janus Weil  <janus@gcc.gnu.org>
>>
>>     PR fortran/63733
>>     * gfortran.dg/typebound_operator_20.f90: New.
>
>
>
> --
> Outside of a dog, a book is a man's best friend. Inside of a dog it's
> too dark to read.
>
> Groucho Marx
Paul Richard Thomas Jan. 12, 2015, 8:30 a.m. UTC | #3
Dear Janus,

Since it is a regression, by all means update the branches. We
usually, propose delaying a bit but I am not convinced that this is
effective for this kind of bug fix - usually, further problems take a
long time to emerge. Thus, I would recommend that you get on with it.

Thanks

Paul

On 11 January 2015 at 23:01, Janus Weil <janus@gcc.gnu.org> wrote:
>> Well done for sorting that out. OK for trunk.
>
> Thanks, Paul. Committed as r219440.
>
> What about the branches?
>
> Cheers,
> Janus
>
>
>
>> On 11 January 2015 at 14:38, Janus Weil <janus@gcc.gnu.org> wrote:
>>> Hi all,
>>>
>>> this patch fixes a wrong-code regression related to operators, by
>>> making sure that we look for typebound operators first, before looking
>>> for non-typebound ones. (Note: Each typebound operator is also added
>>> to the list of non-typebound ones, for reasons of diagnostics.)
>>>
>>> Regtested on x86_64-unknown-linux-gnu. Ok for trunk? 4.9/4.8?
>>>
>>> Cheers,
>>> Janus
>>>
>>>
>>>
>>> 2015-01-11  Janus Weil  <janus@gcc.gnu.org>
>>>
>>>     PR fortran/63733
>>>     * interface.c (gfc_extend_expr): Look for type-bound operators before
>>>     non-typebound ones.
>>>
>>> 2015-01-11  Janus Weil  <janus@gcc.gnu.org>
>>>
>>>     PR fortran/63733
>>>     * gfortran.dg/typebound_operator_20.f90: New.
>>
>>
>>
>> --
>> Outside of a dog, a book is a man's best friend. Inside of a dog it's
>> too dark to read.
>>
>> Groucho Marx
Janus Weil Jan. 12, 2015, 4:18 p.m. UTC | #4
Good, I fully agree. Fortunately the patch applies cleanly to the 4.9
branch and regtests without errors. Thus I have applied it as r219475.
Will do 4.8 soon.

Cheers,
Janus



2015-01-12 9:30 GMT+01:00 Paul Richard Thomas <paul.richard.thomas@gmail.com>:
> Dear Janus,
>
> Since it is a regression, by all means update the branches. We
> usually, propose delaying a bit but I am not convinced that this is
> effective for this kind of bug fix - usually, further problems take a
> long time to emerge. Thus, I would recommend that you get on with it.
>
> Thanks
>
> Paul
>
> On 11 January 2015 at 23:01, Janus Weil <janus@gcc.gnu.org> wrote:
>>> Well done for sorting that out. OK for trunk.
>>
>> Thanks, Paul. Committed as r219440.
>>
>> What about the branches?
>>
>> Cheers,
>> Janus
>>
>>
>>
>>> On 11 January 2015 at 14:38, Janus Weil <janus@gcc.gnu.org> wrote:
>>>> Hi all,
>>>>
>>>> this patch fixes a wrong-code regression related to operators, by
>>>> making sure that we look for typebound operators first, before looking
>>>> for non-typebound ones. (Note: Each typebound operator is also added
>>>> to the list of non-typebound ones, for reasons of diagnostics.)
>>>>
>>>> Regtested on x86_64-unknown-linux-gnu. Ok for trunk? 4.9/4.8?
>>>>
>>>> Cheers,
>>>> Janus
>>>>
>>>>
>>>>
>>>> 2015-01-11  Janus Weil  <janus@gcc.gnu.org>
>>>>
>>>>     PR fortran/63733
>>>>     * interface.c (gfc_extend_expr): Look for type-bound operators before
>>>>     non-typebound ones.
>>>>
>>>> 2015-01-11  Janus Weil  <janus@gcc.gnu.org>
>>>>
>>>>     PR fortran/63733
>>>>     * gfortran.dg/typebound_operator_20.f90: New.
>>>
>>>
>>>
>>> --
>>> Outside of a dog, a book is a man's best friend. Inside of a dog it's
>>> too dark to read.
>>>
>>> Groucho Marx
>
>
>
> --
> Outside of a dog, a book is a man's best friend. Inside of a dog it's
> too dark to read.
>
> Groucho Marx
diff mbox

Patch

Index: gcc/fortran/interface.c
===================================================================
--- gcc/fortran/interface.c	(Revision 219429)
+++ gcc/fortran/interface.c	(Arbeitskopie)
@@ -3706,6 +3706,8 @@  gfc_extend_expr (gfc_expr *e)
   gfc_user_op *uop;
   gfc_intrinsic_op i;
   const char *gname;
+  gfc_typebound_proc* tbo;
+  gfc_expr* tb_base;
 
   sym = NULL;
 
@@ -3722,8 +3724,50 @@  gfc_extend_expr (gfc_expr *e)
 
   i = fold_unary_intrinsic (e->value.op.op);
 
+  /* See if we find a matching type-bound operator.  */
   if (i == INTRINSIC_USER)
+    tbo = matching_typebound_op (&tb_base, actual,
+				  i, e->value.op.uop->name, &gname);
+  else
+    switch (i)
+      {
+#define CHECK_OS_COMPARISON(comp) \
+  case INTRINSIC_##comp: \
+  case INTRINSIC_##comp##_OS: \
+    tbo = matching_typebound_op (&tb_base, actual, \
+				 INTRINSIC_##comp, NULL, &gname); \
+    if (!tbo) \
+      tbo = matching_typebound_op (&tb_base, actual, \
+				   INTRINSIC_##comp##_OS, NULL, &gname); \
+    break;
+	CHECK_OS_COMPARISON(EQ)
+	CHECK_OS_COMPARISON(NE)
+	CHECK_OS_COMPARISON(GT)
+	CHECK_OS_COMPARISON(GE)
+	CHECK_OS_COMPARISON(LT)
+	CHECK_OS_COMPARISON(LE)
+#undef CHECK_OS_COMPARISON
+
+	default:
+	  tbo = matching_typebound_op (&tb_base, actual, i, NULL, &gname);
+	  break;
+      }
+
+  /* If there is a matching typebound-operator, replace the expression with
+      a call to it and succeed.  */
+  if (tbo)
     {
+      gcc_assert (tb_base);
+      build_compcall_for_operator (e, actual, tb_base, tbo, gname);
+
+      if (!gfc_resolve_expr (e))
+	return MATCH_ERROR;
+      else
+	return MATCH_YES;
+    }
+ 
+  if (i == INTRINSIC_USER)
+    {
       for (ns = gfc_current_ns; ns; ns = ns->parent)
 	{
 	  uop = gfc_find_uop (e->value.op.uop->name, ns);
@@ -3772,58 +3816,9 @@  gfc_extend_expr (gfc_expr *e)
 
   if (sym == NULL)
     {
-      gfc_typebound_proc* tbo;
-      gfc_expr* tb_base;
-
-      /* See if we find a matching type-bound operator.  */
-      if (i == INTRINSIC_USER)
-	tbo = matching_typebound_op (&tb_base, actual,
-				     i, e->value.op.uop->name, &gname);
-      else
-	switch (i)
-	  {
-#define CHECK_OS_COMPARISON(comp) \
-  case INTRINSIC_##comp: \
-  case INTRINSIC_##comp##_OS: \
-    tbo = matching_typebound_op (&tb_base, actual, \
-				 INTRINSIC_##comp, NULL, &gname); \
-    if (!tbo) \
-      tbo = matching_typebound_op (&tb_base, actual, \
-				   INTRINSIC_##comp##_OS, NULL, &gname); \
-    break;
-	    CHECK_OS_COMPARISON(EQ)
-	    CHECK_OS_COMPARISON(NE)
-	    CHECK_OS_COMPARISON(GT)
-	    CHECK_OS_COMPARISON(GE)
-	    CHECK_OS_COMPARISON(LT)
-	    CHECK_OS_COMPARISON(LE)
-#undef CHECK_OS_COMPARISON
-
-	    default:
-	      tbo = matching_typebound_op (&tb_base, actual, i, NULL, &gname);
-	      break;
-	  }
-
-      /* If there is a matching typebound-operator, replace the expression with
-	 a call to it and succeed.  */
-      if (tbo)
-	{
-	  bool result;
-
-	  gcc_assert (tb_base);
-	  build_compcall_for_operator (e, actual, tb_base, tbo, gname);
-
-	  result = gfc_resolve_expr (e);
-	  if (!result)
-	    return MATCH_ERROR;
-
-	  return MATCH_YES;
-	}
-
       /* Don't use gfc_free_actual_arglist().  */
       free (actual->next);
       free (actual);
-
       return MATCH_NO;
     }