public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Martin Jambor <jamborm@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-8620] ipa: Force args obtined through pass-through maps to the expected type (PR 113964)
Date: Fri, 19 Apr 2024 14:58:27 +0000 (GMT)	[thread overview]
Message-ID: <20240419145827.1B58F384770C@sourceware.org> (raw)

https://gcc.gnu.org/g:5c3238b0d55ec13a2430aa606e2bfed9432e97ac

commit r13-8620-g5c3238b0d55ec13a2430aa606e2bfed9432e97ac
Author: Martin Jambor <mjambor@suse.cz>
Date:   Fri Apr 19 16:48:12 2024 +0200

    ipa: Force args obtined through pass-through maps to the expected type (PR 113964)
    
    Interactions of IPA-CP and IPA-SRA on the same data is a rather big
    source of issues, I'm afraid.  PR 113964 is a situation where IPA-CP
    propagates an unsigned short in a union parameter into a function
    which itself calls a different function which has a same union
    parameter and both these union parameters are split with IPA-SRA.  The
    leaf function however uses a signed short member of the union.
    
    In the calling function, we get the unsigned constant as the
    replacement for the union and it is then passed in the call without
    any type compatibility checks.  Apparently on riscv64 it matters
    whether the parameter is signed or unsigned short and so the leaf
    function can see different values.
    
    Fixed by using useless_type_conversion_p at the appropriate place and
    if it fails, use force_value_to type as elsewhere in similar
    situations.
    
    gcc/ChangeLog:
    
    2024-04-04  Martin Jambor  <mjambor@suse.cz>
    
            PR ipa/113964
            * ipa-param-manipulation.cc (ipa_param_adjustments::modify_call):
            Force values obtined through pass-through maps to the expected
            split type.
    
    gcc/testsuite/ChangeLog:
    
    2024-04-04  Patrick O'Neill  <patrick@rivosinc.com>
                Martin Jambor  <mjambor@suse.cz>
    
            PR ipa/113964
            * gcc.dg/ipa/pr114247.c: New test.
    
    (cherry picked from commit 8cd0d29270d4ed86c69b80c08de66dcb6c1e22fe)

Diff:
---
 gcc/ipa-param-manipulation.cc       |  6 ++++++
 gcc/testsuite/gcc.dg/ipa/pr114247.c | 31 +++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+)

diff --git a/gcc/ipa-param-manipulation.cc b/gcc/ipa-param-manipulation.cc
index e4f626ae95e..729d5e8e688 100644
--- a/gcc/ipa-param-manipulation.cc
+++ b/gcc/ipa-param-manipulation.cc
@@ -738,6 +738,12 @@ ipa_param_adjustments::modify_call (cgraph_edge *cs,
 	  }
       if (repl)
 	{
+	  if (!useless_type_conversion_p(apm->type, repl->typed.type))
+	    {
+	      repl = force_value_to_type (apm->type, repl);
+	      repl = force_gimple_operand_gsi (&gsi, repl,
+					       true, NULL, true, GSI_SAME_STMT);
+	    }
 	  vargs.quick_push (repl);
 	  continue;
 	}
diff --git a/gcc/testsuite/gcc.dg/ipa/pr114247.c b/gcc/testsuite/gcc.dg/ipa/pr114247.c
new file mode 100644
index 00000000000..60aa2bc0122
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/ipa/pr114247.c
@@ -0,0 +1,31 @@
+/* { dg-do run } */
+/* { dg-options "-O2 -fsigned-char -fno-strict-aliasing -fwrapv" } */
+
+union a {
+  unsigned short b;
+  int c;
+  signed short d;
+};
+int e, f = 1, g;
+long h;
+const int **i;
+void j(union a k, int l, unsigned m) {
+  const int *a[100];
+  i = &a[0];
+  h = k.d;
+}
+static int o(union a k) {
+  k.d = -1;
+  while (1)
+    if (f)
+      break;
+  j(k, g, e);
+  return 0;
+}
+int main() {
+  union a n = {1};
+  o(n);
+  if (h != -1)
+    __builtin_abort();
+  return 0;
+}

                 reply	other threads:[~2024-04-19 14:58 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=20240419145827.1B58F384770C@sourceware.org \
    --to=jamborm@gcc.gnu.org \
    --cc=gcc-cvs@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).