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]

[PATCH] Fix va_arg ((ap), ...) on s390* with C++14 (PR c++/70084)


Hi!

As mentioned in the PR, on the following testcase we emit invalid
error on s390* in the va_arg ((ap), int) case, va_arg (ap, int) is fine
(and the former is fine in -std=c++11 or -std=c++98 too).
The bug only triggers in constructors (or destructors), and happens because
build_va_arg creates ADDR_EXPR that has slightly different type, and has
INDIRECT_REF inside of it.  copy_tree_body_r notices this and cancels the
two, but unlike e.g. build_fold_addr_expr_with_type_loc
  if (TREE_CODE (t) == INDIRECT_REF)
    {
      t = TREE_OPERAND (t, 0);

      if (TREE_TYPE (t) != ptrtype)
        t = build1_loc (loc, NOP_EXPR, ptrtype, t); <<<<<<---------- this
    }
it doesn't attempt to handle the case where ADDR_EXPR contained different
type from the type of INDIRECT_REF's operand.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux,
bootstrap/regtest on s390{,x}-linux pending.  Ok for trunk if it passes
even there?

2016-03-04  Jakub Jelinek  <jakub@redhat.com>

	PR c++/70084
	* tree-inline.c (copy_tree_body_r): When cancelling ADDR_EXPR
	of INDIRECT_REF and ADDR_EXPR changed type, fold_convert it
	to the right type.

	* g++.dg/expr/stdarg3.C: New test.

--- gcc/tree-inline.c.jj	2016-02-12 00:50:55.000000000 +0100
+++ gcc/tree-inline.c	2016-03-04 18:35:28.079458603 +0100
@@ -1266,7 +1266,12 @@ copy_tree_body_r (tree *tp, int *walk_su
 	  /* Handle the case where we substituted an INDIRECT_REF
 	     into the operand of the ADDR_EXPR.  */
 	  if (TREE_CODE (TREE_OPERAND (*tp, 0)) == INDIRECT_REF)
-	    *tp = TREE_OPERAND (TREE_OPERAND (*tp, 0), 0);
+	    {
+	      tree t = TREE_OPERAND (TREE_OPERAND (*tp, 0), 0);
+	      if (TREE_TYPE (t) != TREE_TYPE (*tp))
+		t = fold_convert (remap_type (TREE_TYPE (*tp), id), t);
+	      *tp = t;
+	    }
 	  else
 	    recompute_tree_invariant_for_addr_expr (*tp);
 
--- gcc/testsuite/g++.dg/expr/stdarg3.C.jj	2016-03-04 18:08:22.029669394 +0100
+++ gcc/testsuite/g++.dg/expr/stdarg3.C	2016-03-04 18:06:50.000000000 +0100
@@ -0,0 +1,18 @@
+// PR c++/70084
+// { dg-do compile }
+
+#include <stdarg.h>
+
+struct A
+{
+  A (const char *f, ...);
+};
+
+A::A (const char *f, ...)
+{
+  va_list ap;
+  va_start (ap, f);
+  int i = va_arg (ap, int);	// { dg-bogus "first argument to 'va_arg' not of type 'va_list'" }
+  int j = va_arg ((ap), int);	// { dg-bogus "first argument to 'va_arg' not of type 'va_list'" }
+  va_end (ap);
+}

	Jakub


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