public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <rguenther@suse.de>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH] Fix PR86505
Date: Thu, 02 Aug 2018 14:28:00 -0000	[thread overview]
Message-ID: <alpine.LSU.2.20.1808021627020.16707@zhemvz.fhfr.qr> (raw)


I am testing the following to fix another __builtin_va_arg_pack_len ()
inlining issue.

Bootstrap & regtest running on x86_64-unknown-linux-gnu.

2018-08-02  Richard Biener  <rguenther@suse.de>

	PR middle-end/86505
	* tree-inline.c (copy_bb): When inlining __builtin_va_arg_pack_len ()
	across a va-arg-pack using call adjust its return value accordingly.

	* gcc.dg/torture/pr86505.c: New testcase.

Index: gcc/tree-inline.c
===================================================================
--- gcc/tree-inline.c	(revision 263258)
+++ gcc/tree-inline.c	(working copy)
@@ -1940,8 +1940,7 @@ copy_bb (copy_body_data *id, basic_block
 		   && id->call_stmt
 		   && (decl = gimple_call_fndecl (stmt))
 		   && DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL
-		   && DECL_FUNCTION_CODE (decl) == BUILT_IN_VA_ARG_PACK_LEN
-		   && ! gimple_call_va_arg_pack_p (id->call_stmt))
+		   && DECL_FUNCTION_CODE (decl) == BUILT_IN_VA_ARG_PACK_LEN)
 	    {
 	      /* __builtin_va_arg_pack_len () should be replaced by
 		 the number of anonymous arguments.  */
@@ -1952,10 +1951,22 @@ copy_bb (copy_body_data *id, basic_block
 	      for (p = DECL_ARGUMENTS (id->src_fn); p; p = DECL_CHAIN (p))
 		nargs--;
 
-	      count = build_int_cst (integer_type_node, nargs);
-	      new_stmt = gimple_build_assign (gimple_call_lhs (stmt), count);
-	      gsi_replace (&copy_gsi, new_stmt, false);
-	      stmt = new_stmt;
+	      if (!gimple_call_va_arg_pack_p (id->call_stmt))
+		{
+		  count = build_int_cst (integer_type_node, nargs);
+		  new_stmt = gimple_build_assign (gimple_call_lhs (stmt), count);
+		  gsi_replace (&copy_gsi, new_stmt, false);
+		  stmt = new_stmt;
+		}
+	      else if (nargs != 0)
+		{
+		  tree newlhs = create_tmp_reg_or_ssa_name (integer_type_node);
+		  count = build_int_cst (integer_type_node, nargs);
+		  new_stmt = gimple_build_assign (gimple_call_lhs (stmt),
+						  PLUS_EXPR, newlhs, count);
+		  gimple_call_set_lhs (stmt, newlhs);
+		  gsi_insert_after (&copy_gsi, new_stmt, GSI_NEW_STMT);
+		}
 	    }
 	  else if (call_stmt
 		   && id->call_stmt
Index: gcc/testsuite/gcc.dg/torture/pr86505.c
===================================================================
--- gcc/testsuite/gcc.dg/torture/pr86505.c	(nonexistent)
+++ gcc/testsuite/gcc.dg/torture/pr86505.c	(working copy)
@@ -0,0 +1,32 @@
+/* { dg-do run } */
+
+static inline __attribute__(( __always_inline__)) int 
+funA(unsigned int param, ...) 
+{ 
+  return __builtin_va_arg_pack_len(); 
+}
+
+static inline __attribute__(( __always_inline__)) int
+funB(unsigned int param, ...)
+{ 
+  return funA(param,  2, 4, __builtin_va_arg_pack()); 
+}
+
+int 
+testBuiltin(void) 
+{ 
+  int rc = funB(0,1,2); 
+  if (rc != 4)
+    return 1;
+  return 0;
+}
+
+int
+main()
+{
+  int rc = testBuiltin();
+  if (rc == 1)
+    __builtin_abort ();
+
+  return 0;
+}

                 reply	other threads:[~2018-08-02 14:28 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=alpine.LSU.2.20.1808021627020.16707@zhemvz.fhfr.qr \
    --to=rguenther@suse.de \
    --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).