PR analyzer/93405 reports an ICE with -fanalyzer when passing
a constant "by reference" in gfortran.

The issue is that the constant is passed as an ADDR_EXPR
of a CONST_DECL, and region_model::get_lvalue_1 doesn't
know how to handle CONST_DECL.

This patch implements it for CONST_DECL by providing
a placeholder region, holding the CONST_DECL's value,
fixing the ICE.

Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.

Is the Fortran testcase OK for master?  (this relies on patch 1 in
the kit, obviously)

gcc/analyzer/ChangeLog:
        PR analyzer/93405
        * region-model.cc (region_model::get_lvalue_1): Implement
        CONST_DECL.

gcc/testsuite/ChangeLog:
        PR analyzer/93405
        * gfortran.dg/analyzer/pr93405.f90: New test.
---
 gcc/analyzer/region-model.cc                   | 13 +++++++++++++
 gcc/testsuite/gfortran.dg/analyzer/pr93405.f90 | 14 ++++++++++++++
 2 files changed, 27 insertions(+)
 create mode 100644 gcc/testsuite/gfortran.dg/analyzer/pr93405.f90

diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-model.cc
index 8b57a623084..61390aa4cd1 100644
--- a/gcc/analyzer/region-model.cc
+++ b/gcc/analyzer/region-model.cc
@@ -4717,6 +4717,19 @@ region_model::get_lvalue_1 (path_var pv, 
region_model_context *ctxt)
       }
       break;
 
+    case CONST_DECL:
+      {
+       tree cst_type = TREE_TYPE (expr);
+       region_id cst_rid = add_region_for_type (m_root_rid, cst_type);
+       if (tree value = DECL_INITIAL (expr))
+         {
+           svalue_id sid = get_rvalue (value, ctxt);
+           get_region (cst_rid)->set_value (*this, cst_rid, sid, ctxt);
+         }
+       return cst_rid;
+      }
+      break;
+
     case STRING_CST:
       {
        tree cst_type = TREE_TYPE (expr);
diff --git a/gcc/testsuite/gfortran.dg/analyzer/pr93405.f90 
b/gcc/testsuite/gfortran.dg/analyzer/pr93405.f90
new file mode 100644
index 00000000000..e2c23753015
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/analyzer/pr93405.f90
@@ -0,0 +1,14 @@
+! { dg-do compile }
+real a(10), b(10), c(10)
+a = 0.
+b = 1.
+call sum(a, b, c, 10)
+print *, c(5)
+end
+subroutine sum(a, b, c, n)
+integer i, n
+real a(n), b(n), c(n)
+do i = 1, n
+   c(i) = a(i) + b(i)
+enddo
+end
-- 
2.21.0

Reply via email to