This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PR 33706: Fix fallout from __builtin_va_arg_pack()


The problem in PR 33706 was that we were missing annotations such as
the basic block pointer for a call statement.  This call had been
inlined from another function, and the original used
__builtin_va_arg_pack().  It was the replacement code that was
dropping the basic block annotation.  Fixed thusly.

Testcase reduced from the bug report, originally from glibc.

Bootstrapping and regtesting on x86_64-linux-gnu.  Ok?

for  gcc/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	PR middle-end/33706
	* tree-inline.c (copy_bb): Use bsi_replace to replace a
	__builtin_va_arg_pack-containing call stmt.

for  gcc/testsuite/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	PR middle-end/33706
	* gcc.dg/va-arg-pack-2.c: New.

Index: gcc/tree-inline.c
===================================================================
--- gcc/tree-inline.c.orig	2007-10-10 02:21:35.000000000 -0300
+++ gcc/tree-inline.c	2007-10-10 02:26:54.000000000 -0300
@@ -863,9 +863,18 @@ copy_bb (copy_body_data *id, basic_block
 		  if (TREE_CODE (*call_ptr) == WITH_SIZE_EXPR)
 		    call_ptr = &TREE_OPERAND (*call_ptr, 0);
 		  gcc_assert (*call_ptr == call);
-		  *call_ptr = new_call;
-		  stmt = *stmtp;
-		  update_stmt (stmt);
+		  if (call_ptr == stmtp)
+		    {
+		      bsi_replace (&copy_bsi, new_call, true);
+		      stmtp = bsi_stmt_ptr (copy_bsi);
+		      stmt = *stmtp;
+		    }
+		  else
+		    {
+		      *call_ptr = new_call;
+		      stmt = *stmtp;
+		      update_stmt (stmt);
+		    }
 		}
 	      else if (call
 		       && id->call_expr
Index: gcc/testsuite/gcc.dg/va-arg-pack-2.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ gcc/testsuite/gcc.dg/va-arg-pack-2.c	2007-10-10 02:30:15.000000000 -0300
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+extern void noreturn (int status, ...);
+
+extern inline __attribute ((always_inline)) void
+error (int status, ...)
+{
+  if (__builtin_constant_p (status))
+    noreturn (status, __builtin_va_arg_pack ());
+}
+
+void
+f (void)
+{
+  error (1);
+}
-- 
Alexandre Oliva         http://www.lsd.ic.unicamp.br/~oliva/
FSF Latin America Board Member         http://www.fsfla.org/
Red Hat Compiler Engineer   aoliva@{redhat.com, gcc.gnu.org}
Free Software Evangelist  oliva@{lsd.ic.unicamp.br, gnu.org}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]