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
Subject: [committed] analyzer: fix ICE on vector casts [PR104159]
Date: Sat, 22 Jan 2022 10:29:37 -0500	[thread overview]
Message-ID: <20220122152937.2510099-1-dmalcolm@redhat.com> (raw)

PR analyzer/104159 describes an ICE attempting to convert a vector_cst,
which occurs when symbolically executing within a recursive call on:

  _4 = BIT_FIELD_REF <w_3(D), 32, 0>;
  _1 = VIEW_CONVERT_EXPR<T>(_4);

where the BIT_FIELD_REF leads to a get_or_create_cast from
  VEC<long, 8> to VEC<unsigned 4>
which get_code_for_cast erroneously picks NOP_EXPR for the cast, leading
to a bogus input to the VIEW_CONVERT_EXPR.

This patch fixes the issue by giving up on attempts to cast symbolic
values of vector types, treating the result of such casts as unknowable.

Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
Pushed to trunk as r12-6817-g45b999f642a531c083c982dda79fa6ad65730a7c.

gcc/analyzer/ChangeLog:
	PR analyzer/104159
	* region-model-manager.cc
	(region_model_manager::get_or_create_cast): Bail out if the types
	are the same.  Don't attempt to handle casts involving vector
	types.

gcc/testsuite/ChangeLog:
	PR analyzer/104159
	* gcc.dg/analyzer/torture/pr104159.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
---
 gcc/analyzer/region-model-manager.cc           | 11 +++++++++++
 .../gcc.dg/analyzer/torture/pr104159.c         | 18 ++++++++++++++++++
 2 files changed, 29 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/analyzer/torture/pr104159.c

diff --git a/gcc/analyzer/region-model-manager.cc b/gcc/analyzer/region-model-manager.cc
index bb93526807f..e765e7f484f 100644
--- a/gcc/analyzer/region-model-manager.cc
+++ b/gcc/analyzer/region-model-manager.cc
@@ -497,6 +497,17 @@ const svalue *
 region_model_manager::get_or_create_cast (tree type, const svalue *arg)
 {
   gcc_assert (type);
+
+  /* No-op if the types are the same.  */
+  if (type == arg->get_type ())
+    return arg;
+
+  /* Don't attempt to handle casts involving vector types for now.  */
+  if (TREE_CODE (type) == VECTOR_TYPE
+      || (arg->get_type ()
+	  && TREE_CODE (arg->get_type ()) == VECTOR_TYPE))
+    return get_or_create_unknown_svalue (type);
+
   enum tree_code op = get_code_for_cast (type, arg->get_type ());
   return get_or_create_unaryop (type, op, arg);
 }
diff --git a/gcc/testsuite/gcc.dg/analyzer/torture/pr104159.c b/gcc/testsuite/gcc.dg/analyzer/torture/pr104159.c
new file mode 100644
index 00000000000..1346b4b6063
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/analyzer/torture/pr104159.c
@@ -0,0 +1,18 @@
+/* { dg-additional-options "-Wno-analyzer-use-of-uninitialized-value" } */
+
+typedef int __attribute__((__vector_size__(4))) T;
+typedef unsigned __attribute__((__vector_size__(4))) U;
+typedef unsigned __attribute__((__vector_size__(16))) V;
+typedef unsigned long __attribute__((__vector_size__(16))) W;
+
+U u;
+T t;
+
+void
+foo(W w) {
+  U u = __builtin_shufflevector((V)w, u, 0);
+  t = (T){} + u + u;
+  foo((W){});
+  for (;;)
+    ;
+}
-- 
2.26.3


                 reply	other threads:[~2022-01-22 15:29 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20220122152937.2510099-1-dmalcolm@redhat.com \
    --to=dmalcolm@redhat.com \
    --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).