|
|
3db796 |
From 00f13a60974cb4145799593398cc61894326c222 Mon Sep 17 00:00:00 2001
|
|
|
3db796 |
From: Jim MacArthur <jim.macarthur@codethink.co.uk>
|
|
|
3db796 |
Date: Wed, 7 Oct 2015 16:31:18 -0400
|
|
|
3db796 |
Subject: [PATCH 09/23] Convert LOGICAL to INTEGER for arithmetic ops, and vice
|
|
|
3db796 |
versa
|
|
|
3db796 |
|
|
|
3db796 |
We allow converting LOGICAL types to INTEGER when doing arithmetic
|
|
|
3db796 |
operations, and converting INTEGER types to LOGICAL for use in
|
|
|
3db796 |
boolean operations.
|
|
|
3db796 |
|
|
|
3db796 |
This feature is enabled with the `-std=extra-legacy` compiler flag.
|
|
|
3db796 |
---
|
|
|
3db796 |
|
|
|
3db796 |
0009-Convert-LOGICAL-to-INTEGER-for-arithmetic-ops-and-vi.patch
|
|
|
3db796 |
Fixup
|
|
|
3db796 |
|
|
|
3db796 |
diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
|
|
|
3db796 |
index 667cc50..33b441a 100644
|
|
|
3db796 |
--- a/gcc/fortran/resolve.c
|
|
|
3db796 |
+++ b/gcc/fortran/resolve.c
|
|
|
3db796 |
@@ -3627,6 +3627,22 @@ is_character_based (bt type)
|
|
|
3db796 |
for the conversion. */
|
|
|
3db796 |
|
|
|
3db796 |
static void
|
|
|
3db796 |
+convert_integer_to_logical (gfc_expr *e)
|
|
|
3db796 |
+{
|
|
|
3db796 |
+ if (e->ts.type == BT_INTEGER)
|
|
|
3db796 |
+ {
|
|
|
3db796 |
+ /* Convert to LOGICAL */
|
|
|
3db796 |
+ gfc_typespec t;
|
|
|
3db796 |
+ t.type = BT_LOGICAL;
|
|
|
3db796 |
+ t.kind = 1;
|
|
|
3db796 |
+ gfc_convert_type_warn (e, &t, 2, 1);
|
|
|
3db796 |
+ }
|
|
|
3db796 |
+}
|
|
|
3db796 |
+
|
|
|
3db796 |
+/* If E is a logical, convert it to an integer and issue a warning
|
|
|
3db796 |
+ for the conversion. */
|
|
|
3db796 |
+
|
|
|
3db796 |
+static void
|
|
|
3db796 |
convert_logical_to_integer (gfc_expr *e)
|
|
|
3db796 |
{
|
|
|
3db796 |
if (e->ts.type == BT_LOGICAL)
|
|
|
3db796 |
@@ -3733,6 +3749,12 @@ resolve_operator (gfc_expr *e)
|
|
|
3db796 |
case INTRINSIC_OR:
|
|
|
3db796 |
case INTRINSIC_EQV:
|
|
|
3db796 |
case INTRINSIC_NEQV:
|
|
|
3db796 |
+ if (gfc_option.allow_std & GFC_STD_EXTRA_LEGACY)
|
|
|
3db796 |
+ {
|
|
|
3db796 |
+ convert_integer_to_logical (op1);
|
|
|
3db796 |
+ convert_integer_to_logical (op2);
|
|
|
3db796 |
+ }
|
|
|
3db796 |
+
|
|
|
3db796 |
if (op1->ts.type == BT_LOGICAL && op2->ts.type == BT_LOGICAL)
|
|
|
3db796 |
{
|
|
|
3db796 |
e->ts.type = BT_LOGICAL;
|
|
|
3db796 |
@@ -3774,6 +3796,11 @@ resolve_operator (gfc_expr *e)
|
|
|
3db796 |
return resolve_function (e);
|
|
|
3db796 |
}
|
|
|
3db796 |
|
|
|
3db796 |
+ if (gfc_option.allow_std & GFC_STD_EXTRA_LEGACY)
|
|
|
3db796 |
+ {
|
|
|
3db796 |
+ convert_integer_to_logical (op1);
|
|
|
3db796 |
+ }
|
|
|
3db796 |
+
|
|
|
3db796 |
if (op1->ts.type == BT_LOGICAL)
|
|
|
3db796 |
{
|
|
|
3db796 |
e->ts.type = BT_LOGICAL;
|