aboutsummaryrefslogtreecommitdiff
path: root/gcc/fortran/trans-expr.cc
diff options
context:
space:
mode:
authorHarald Anlauf <anlauf@gmx.de>2025-01-02 20:22:23 +0100
committerHarald Anlauf <anlauf@gmx.de>2025-01-03 17:24:05 +0100
commitc7754a2fb2e60987524947fe189f3ffac035ea1d (patch)
treefc49cfdebcd77b6804f197f226bb123c2ef8a2eb /gcc/fortran/trans-expr.cc
parent75da7a6bdc83d99b994c16764960ba0a7d18e135 (diff)
downloadgcc-c7754a2fb2e60987524947fe189f3ffac035ea1d.zip
gcc-c7754a2fb2e60987524947fe189f3ffac035ea1d.tar.gz
gcc-c7754a2fb2e60987524947fe189f3ffac035ea1d.tar.bz2
Fortran: Cray pointer comparison wrongly optimized away [PR106692]
PR fortran/106692 gcc/fortran/ChangeLog: * trans-expr.cc (gfc_conv_expr_op): Inhibit excessive optimization of Cray pointers by treating them as volatile in comparisons. gcc/testsuite/ChangeLog: * gfortran.dg/cray_pointers_13.f90: New test.
Diffstat (limited to 'gcc/fortran/trans-expr.cc')
-rw-r--r--gcc/fortran/trans-expr.cc13
1 files changed, 13 insertions, 0 deletions
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index f73e04b..bc24105 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -4150,6 +4150,19 @@ gfc_conv_expr_op (gfc_se * se, gfc_expr * expr)
if (lop)
{
+ // Inhibit overeager optimization of Cray pointer comparisons (PR106692).
+ if (expr->value.op.op1->expr_type == EXPR_VARIABLE
+ && expr->value.op.op1->ts.type == BT_INTEGER
+ && expr->value.op.op1->symtree
+ && expr->value.op.op1->symtree->n.sym->attr.cray_pointer)
+ TREE_THIS_VOLATILE (lse.expr) = 1;
+
+ if (expr->value.op.op2->expr_type == EXPR_VARIABLE
+ && expr->value.op.op2->ts.type == BT_INTEGER
+ && expr->value.op.op2->symtree
+ && expr->value.op.op2->symtree->n.sym->attr.cray_pointer)
+ TREE_THIS_VOLATILE (rse.expr) = 1;
+
/* The result of logical ops is always logical_type_node. */
tmp = fold_build2_loc (input_location, code, logical_type_node,
lse.expr, rse.expr);