* [PATCH] Fix va_arg ((ap), ...) on s390* with C++14 (PR c++/70084)
@ 2016-03-04 20:37 Jakub Jelinek
2016-03-04 22:49 ` Jeff Law
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2016-03-04 20:37 UTC (permalink / raw)
To: gcc-patches
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Fix va_arg ((ap), ...) on s390* with C++14 (PR c++/70084)
2016-03-04 20:37 [PATCH] Fix va_arg ((ap), ...) on s390* with C++14 (PR c++/70084) Jakub Jelinek
@ 2016-03-04 22:49 ` Jeff Law
0 siblings, 0 replies; 2+ messages in thread
From: Jeff Law @ 2016-03-04 22:49 UTC (permalink / raw)
To: Jakub Jelinek, gcc-patches
On 03/04/2016 01:37 PM, Jakub Jelinek wrote:
> 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.
OK.
jeff
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-03-04 22:49 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-04 20:37 [PATCH] Fix va_arg ((ap), ...) on s390* with C++14 (PR c++/70084) Jakub Jelinek
2016-03-04 22:49 ` Jeff Law
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).