analyzer: fix ICE with fortran constant arguments (PR 93405)
authorDavid Malcolm <dmalcolm@redhat.com>
Wed, 5 Feb 2020 21:48:53 +0000 (16:48 -0500)
committerDavid Malcolm <dmalcolm@redhat.com>
Mon, 10 Feb 2020 21:23:59 +0000 (16:23 -0500)
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.

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/ChangeLog
gcc/analyzer/region-model.cc
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/analyzer/pr93405.f90 [new file with mode: 0644]

index ba59131..e24976b 100644 (file)
@@ -1,3 +1,9 @@
+2020-02-10  David Malcolm  <dmalcolm@redhat.com>
+
+       PR analyzer/93405
+       * region-model.cc (region_model::get_lvalue_1): Implement
+       CONST_DECL.
+
 2020-02-06  David Malcolm  <dmalcolm@redhat.com>
 
        * region-model.cc (region_model::maybe_cast_1): Attempt to provide
index 60363c7..86a5b42 100644 (file)
@@ -4690,6 +4690,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);
index 3840833..b3a875e 100644 (file)
@@ -1,5 +1,10 @@
 2020-02-10  David Malcolm  <dmalcolm@redhat.com>
 
+       PR analyzer/93405
+       * gfortran.dg/analyzer/pr93405.f90: New test.
+
+2020-02-10  David Malcolm  <dmalcolm@redhat.com>
+
        * gfortran.dg/analyzer/analyzer.exp: New subdirectory and .exp
        suite.
        * gfortran.dg/analyzer/malloc-example.f90: New test.
diff --git a/gcc/testsuite/gfortran.dg/analyzer/pr93405.f90 b/gcc/testsuite/gfortran.dg/analyzer/pr93405.f90
new file mode 100644 (file)
index 0000000..e2c2375
--- /dev/null
@@ -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