public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: David Malcolm <dmalcolm@redhat.com>
To: gcc-patches@gcc.gnu.org,	fortran@gcc.gnu.org
Cc: David Malcolm <dmalcolm@redhat.com>
Subject: [PATCH 2/2] analyzer: fix ICE with fortran constant arguments (PR 93405)
Date: Thu, 06 Feb 2020 20:01:00 -0000	[thread overview]
Message-ID: <20200206200144.14304-2-dmalcolm@redhat.com> (raw)
In-Reply-To: <20200206200144.14304-1-dmalcolm@redhat.com>

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	other threads:[~2020-02-06 20:01 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-06 20:02 [PATCH 1/2] analyzer: gfortran testsuite support David Malcolm
2020-02-06 20:01 ` David Malcolm [this message]
2020-02-09 20:16 ` Toon Moene
2020-02-09 20:55   ` Steve Kargl
2020-02-09 21:19     ` David Malcolm
2020-02-10  0:38       ` Steve Kargl
2020-02-10 20:52         ` David Malcolm
2020-02-10 20:57           ` Steve Kargl
2020-02-09 21:37     ` Toon Moene

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200206200144.14304-2-dmalcolm@redhat.com \
    --to=dmalcolm@redhat.com \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).