|
|
3db796 |
From 99c791361468b61976d6054e1ec1c81fe43e6559 Mon Sep 17 00:00:00 2001
|
|
|
3db796 |
From: Jim MacArthur <jim.macarthur@codethink.co.uk>
|
|
|
3db796 |
Date: Wed, 11 Nov 2015 15:37:00 +0000
|
|
|
3db796 |
Subject: [PATCH 14/23] Allow non-logical expressions in IF statements
|
|
|
3db796 |
|
|
|
3db796 |
This feature is enabled by the `-std=extra-legacy` compiler flag.
|
|
|
3db796 |
---
|
|
|
3db796 |
|
|
|
3db796 |
0014-Allow-non-logical-expressions-in-IF-statements.patch
|
|
|
3db796 |
|
|
|
3db796 |
diff --git a/gcc/fortran/match.c b/gcc/fortran/match.c
|
|
|
3db796 |
index 682f7b0..c63b834 100644
|
|
|
3db796 |
--- a/gcc/fortran/match.c
|
|
|
3db796 |
+++ b/gcc/fortran/match.c
|
|
|
3db796 |
@@ -25,6 +25,7 @@ along with GCC; see the file COPYING3. If not see
|
|
|
3db796 |
#include "gfortran.h"
|
|
|
3db796 |
#include "match.h"
|
|
|
3db796 |
#include "parse.h"
|
|
|
3db796 |
+#include "arith.h"
|
|
|
3db796 |
|
|
|
3db796 |
int gfc_matching_ptr_assignment = 0;
|
|
|
3db796 |
int gfc_matching_procptr_assignment = 0;
|
|
|
3db796 |
@@ -1666,7 +1667,17 @@ got_match:
|
|
|
3db796 |
*p->next = new_st;
|
|
|
3db796 |
p->next->loc = gfc_current_locus;
|
|
|
3db796 |
|
|
|
3db796 |
- p->expr1 = expr;
|
|
|
3db796 |
+ if ((gfc_option.allow_std & GFC_STD_EXTRA_LEGACY)
|
|
|
3db796 |
+ && expr->ts.type != BT_LOGICAL)
|
|
|
3db796 |
+ {
|
|
|
3db796 |
+ p->expr1 = gfc_ne (expr, gfc_get_int_expr (1, &gfc_current_locus, 0), INTRINSIC_NE);
|
|
|
3db796 |
+ gfc_warning_now (0, "The type of condition in this IF statement isn't LOGICAL; it will be true if it evaluates to nonzero.");
|
|
|
3db796 |
+ }
|
|
|
3db796 |
+ else
|
|
|
3db796 |
+ {
|
|
|
3db796 |
+ p->expr1 = expr;
|
|
|
3db796 |
+ }
|
|
|
3db796 |
+ p->op = EXEC_IF;
|
|
|
3db796 |
|
|
|
3db796 |
gfc_clear_new_st ();
|
|
|
3db796 |
|
|
|
3db796 |
diff --git a/gcc/fortran/parse.c b/gcc/fortran/parse.c
|
|
|
3db796 |
index 3aedb1d..e926ba6 100644
|
|
|
3db796 |
--- a/gcc/fortran/parse.c
|
|
|
3db796 |
+++ b/gcc/fortran/parse.c
|
|
|
3db796 |
@@ -26,6 +26,7 @@ along with GCC; see the file COPYING3. If not see
|
|
|
3db796 |
#include <setjmp.h>
|
|
|
3db796 |
#include "match.h"
|
|
|
3db796 |
#include "parse.h"
|
|
|
3db796 |
+#include "arith.h"
|
|
|
3db796 |
|
|
|
3db796 |
/* Current statement label. Zero means no statement label. Because new_st
|
|
|
3db796 |
can get wiped during statement matching, we have to keep it separate. */
|
|
|
3db796 |
@@ -4036,6 +4037,14 @@ parse_if_block (void)
|
|
|
3db796 |
d = add_statement ();
|
|
|
3db796 |
|
|
|
3db796 |
d->expr1 = top->expr1;
|
|
|
3db796 |
+
|
|
|
3db796 |
+ if ((gfc_option.allow_std & GFC_STD_EXTRA_LEGACY)
|
|
|
3db796 |
+ && top->expr1->ts.type != BT_LOGICAL)
|
|
|
3db796 |
+ {
|
|
|
3db796 |
+ d->expr1 = gfc_ne (top->expr1, gfc_get_int_expr (1, &gfc_current_locus, 0), INTRINSIC_NE);
|
|
|
3db796 |
+ gfc_warning_now (0, "The type of condition in this IF statement isn't LOGICAL; it will be true if it evaluates to nonzero.");
|
|
|
3db796 |
+ }
|
|
|
3db796 |
+
|
|
|
3db796 |
top->expr1 = NULL;
|
|
|
3db796 |
top->block = d;
|
|
|
3db796 |
|