From 41a9e940c7014f117738a9a59b31833047a1083d Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Wed, 5 Feb 2020 16:48:53 -0500 Subject: [PATCH] analyzer: fix ICE with fortran constant arguments (PR 93405) 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 | 6 ++++++ gcc/analyzer/region-model.cc | 13 +++++++++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gfortran.dg/analyzer/pr93405.f90 | 14 ++++++++++++++ 4 files changed, 38 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/analyzer/pr93405.f90 diff --git a/gcc/analyzer/ChangeLog b/gcc/analyzer/ChangeLog index ba59131ce4b..e24976bbefd 100644 --- a/gcc/analyzer/ChangeLog +++ b/gcc/analyzer/ChangeLog @@ -1,3 +1,9 @@ +2020-02-10 David Malcolm + + PR analyzer/93405 + * region-model.cc (region_model::get_lvalue_1): Implement + CONST_DECL. + 2020-02-06 David Malcolm * region-model.cc (region_model::maybe_cast_1): Attempt to provide diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-model.cc index 60363c726d7..86a5b424911 100644 --- a/gcc/analyzer/region-model.cc +++ b/gcc/analyzer/region-model.cc @@ -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); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3840833d66c..b3a875efb8b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2020-02-10 David Malcolm + + PR analyzer/93405 + * gfortran.dg/analyzer/pr93405.f90: New test. + 2020-02-10 David Malcolm * gfortran.dg/analyzer/analyzer.exp: New subdirectory and .exp 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.30.2