This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATCH: Potential patch for PR fortran/6491


Toon Moene <toon@moene.indiv.nluug.nl> writes:

> Ian Lance Taylor wrote:
> 
> > What should happen when logical and integer operands are combined when
> > using -fugly-logint?
> 
> How would I know ?  It's not something written down in standardese
> somewhere - it's behaviour some compilers "exhibit" ;-)
> 
> However, I tested your example on the most ugly logical-vs-integer
> compiler I know of (SGI's f77) and it produced the same answers as
> your patch.
> 
> I also like the explanation going with it - so please apply your patch
> to the trunk.

Thanks.  I committed this patch (as previously sent to the fortran
list, now also sent to gcc-patches).

Ian


2004-01-13  Ian Lance Taylor  <ian@wasabisystems.com>

	PR fortran/6491
	* expr.c (ffeexpr_reduce_): When handling AND, OR, and XOR, and
	when using -fugly-logint, if both operands are logical, convert
	the result back to logical.
	(ffeexpr_reduced_ugly2log_): Add bothlogical parameter.  Change
	all callers.  Convert logical operands to integer.


Index: expr.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/f/expr.c,v
retrieving revision 1.30
diff -p -u -r1.30 expr.c
--- expr.c	24 Nov 2003 21:48:08 -0000	1.30
+++ expr.c	14 Jan 2004 02:31:05 -0000
@@ -309,7 +309,8 @@ static ffebld ffeexpr_reduced_ugly1log_ 
 static ffebld ffeexpr_reduced_ugly2_ (ffebld reduced, ffeexprExpr_ l,
 				      ffeexprExpr_ op, ffeexprExpr_ r);
 static ffebld ffeexpr_reduced_ugly2log_ (ffebld reduced, ffeexprExpr_ l,
-					 ffeexprExpr_ op, ffeexprExpr_ r);
+					 ffeexprExpr_ op, ffeexprExpr_ r,
+					 bool *);
 static ffelexHandler ffeexpr_find_close_paren_ (ffelexToken t,
 						ffelexHandler after);
 static ffelexHandler ffeexpr_nil_finished_ (ffelexToken t);
@@ -8802,6 +8803,7 @@ ffeexpr_reduce_ (void)
   ffebld expr;
   ffebld left_expr;
   bool submag = FALSE;
+  bool bothlogical;
 
   operand = ffeexpr_stack_->exprstack;
   assert (operand != NULL);
@@ -8993,37 +8995,58 @@ ffeexpr_reduce_ (void)
 	  reduced = ffebld_new_and (left_expr, expr);
 	  if (ffe_is_ugly_logint ())
 	    reduced = ffeexpr_reduced_ugly2log_ (reduced, left_operand, operator,
-						 operand);
+						 operand, &bothlogical);
 	  reduced = ffeexpr_reduced_bool2_ (reduced, left_operand, operator,
 					    operand);
 	  reduced = ffeexpr_collapse_and (reduced, operator->token);
+	  if (ffe_is_ugly_logint() && bothlogical)
+	    reduced = ffeexpr_convert (reduced, left_operand->token,
+				       operator->token,
+				       FFEINFO_basictypeLOGICAL,
+				       FFEINFO_kindtypeLOGICALDEFAULT, 0,
+				       FFETARGET_charactersizeNONE,
+				       FFEEXPR_contextLET);
 	  break;
 
 	case FFEEXPR_operatorOR_:
 	  reduced = ffebld_new_or (left_expr, expr);
 	  if (ffe_is_ugly_logint ())
 	    reduced = ffeexpr_reduced_ugly2log_ (reduced, left_operand, operator,
-						 operand);
+						 operand, &bothlogical);
 	  reduced = ffeexpr_reduced_bool2_ (reduced, left_operand, operator,
 					    operand);
 	  reduced = ffeexpr_collapse_or (reduced, operator->token);
+	  if (ffe_is_ugly_logint() && bothlogical)
+	    reduced = ffeexpr_convert (reduced, left_operand->token,
+				       operator->token,
+				       FFEINFO_basictypeLOGICAL,
+				       FFEINFO_kindtypeLOGICALDEFAULT, 0,
+				       FFETARGET_charactersizeNONE,
+				       FFEEXPR_contextLET);
 	  break;
 
 	case FFEEXPR_operatorXOR_:
 	  reduced = ffebld_new_xor (left_expr, expr);
 	  if (ffe_is_ugly_logint ())
 	    reduced = ffeexpr_reduced_ugly2log_ (reduced, left_operand, operator,
-						 operand);
+						 operand, &bothlogical);
 	  reduced = ffeexpr_reduced_bool2_ (reduced, left_operand, operator,
 					    operand);
 	  reduced = ffeexpr_collapse_xor (reduced, operator->token);
+	  if (ffe_is_ugly_logint() && bothlogical)
+	    reduced = ffeexpr_convert (reduced, left_operand->token,
+				       operator->token,
+				       FFEINFO_basictypeLOGICAL,
+				       FFEINFO_kindtypeLOGICALDEFAULT, 0,
+				       FFETARGET_charactersizeNONE,
+				       FFEEXPR_contextLET);
 	  break;
 
 	case FFEEXPR_operatorEQV_:
 	  reduced = ffebld_new_eqv (left_expr, expr);
 	  if (ffe_is_ugly_logint ())
 	    reduced = ffeexpr_reduced_ugly2log_ (reduced, left_operand, operator,
-						 operand);
+						 operand, NULL);
 	  reduced = ffeexpr_reduced_bool2_ (reduced, left_operand, operator,
 					    operand);
 	  reduced = ffeexpr_collapse_eqv (reduced, operator->token);
@@ -9033,7 +9056,7 @@ ffeexpr_reduce_ (void)
 	  reduced = ffebld_new_neqv (left_expr, expr);
 	  if (ffe_is_ugly_logint ())
 	    reduced = ffeexpr_reduced_ugly2log_ (reduced, left_operand, operator,
-						 operand);
+						 operand, NULL);
 	  reduced = ffeexpr_reduced_bool2_ (reduced, left_operand, operator,
 					    operand);
 	  reduced = ffeexpr_collapse_neqv (reduced, operator->token);
@@ -10514,7 +10537,7 @@ ffeexpr_reduced_ugly2_ (ffebld reduced, 
 
 static ffebld
 ffeexpr_reduced_ugly2log_ (ffebld reduced, ffeexprExpr_ l, ffeexprExpr_ op,
-			   ffeexprExpr_ r)
+			   ffeexprExpr_ r, bool *bothlogical)
 {
   ffeinfo linfo, rinfo;
   ffeinfoBasictype lbt, rbt;
@@ -10592,6 +10615,32 @@ ffeexpr_reduced_ugly2log_ (ffebld reduce
 	}
       /* else Leave it alone. */
     }
+
+  if (lbt == FFEINFO_basictypeLOGICAL)
+    {
+      ffebld_set_left (reduced,
+		       ffeexpr_convert (ffebld_left (reduced),
+					l->token, op->token,
+					FFEINFO_basictypeINTEGER,
+					FFEINFO_kindtypeINTEGERDEFAULT, 0,
+					FFETARGET_charactersizeNONE,
+					FFEEXPR_contextLET));
+    }
+
+  if (rbt == FFEINFO_basictypeLOGICAL)
+    {
+      ffebld_set_right (reduced,
+			ffeexpr_convert (ffebld_right (reduced),
+					 r->token, op->token,
+					 FFEINFO_basictypeINTEGER,
+					 FFEINFO_kindtypeINTEGERDEFAULT, 0,
+					 FFETARGET_charactersizeNONE,
+					 FFEEXPR_contextLET));
+    }
+
+  if (bothlogical != NULL)
+    *bothlogical = (lbt == FFEINFO_basictypeLOGICAL
+		    && rbt == FFEINFO_basictypeLOGICAL);
 
   return reduced;
 }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]