* [C++ PATCH] Fix ICE when throwing va_list (PR c++/72809)
@ 2016-08-08 19:09 Jakub Jelinek
2016-08-08 21:16 ` Jason Merrill
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2016-08-08 19:09 UTC (permalink / raw)
To: Jason Merrill; +Cc: gcc-patches
Hi!
If va_list is one-entry array of structs, those RECORD_TYPEs don't
have TYPE_BINFO.
Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?
I've made the testcase compile instead of run, because while it with the
patch works both on x86_64-linux and i686-linux, not sure if it really
should be well defined - at least in C one can copy va_list only through
va_copy, by throwing it and catching it is copied in some other way.
2016-08-08 Jakub Jelinek <jakub@redhat.com>
PR c++/72809
* rtti.c (get_pseudo_ti_index): Return TK_CLASS_TYPE for
builtin aggregate types without TYPE_BINFO.
* g++.dg/eh/stdarg1.C: New test.
--- gcc/cp/rtti.c.jj 2016-04-22 18:21:27.000000000 +0200
+++ gcc/cp/rtti.c 2016-08-08 16:21:32.937053462 +0200
@@ -1293,7 +1293,8 @@ get_pseudo_ti_index (tree type)
ix = TK_CLASS_TYPE;
break;
}
- else if (!BINFO_N_BASE_BINFOS (TYPE_BINFO (type)))
+ else if (!TYPE_BINFO (type)
+ || !BINFO_N_BASE_BINFOS (TYPE_BINFO (type)))
{
ix = TK_CLASS_TYPE;
break;
--- gcc/testsuite/g++.dg/eh/stdarg1.C.jj 2016-08-08 16:31:52.553510463 +0200
+++ gcc/testsuite/g++.dg/eh/stdarg1.C 2016-08-08 16:30:20.000000000 +0200
@@ -0,0 +1,30 @@
+// PR c++/72809
+// { dg-do compile }
+
+#include <stdarg.h>
+
+int
+foo (int a, ...)
+{
+ va_list ap;
+ int r = 0;
+ va_start (ap, a);
+ try
+ {
+ if (a == 1)
+ throw (ap);
+ }
+ catch (va_list b)
+ {
+ r = va_arg (b, int);
+ }
+ va_end (ap);
+ return r;
+}
+
+int
+main ()
+{
+ if (foo (0) != 0 || foo (1, 7) != 7)
+ __builtin_abort ();
+}
Jakub
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [C++ PATCH] Fix ICE when throwing va_list (PR c++/72809)
2016-08-08 19:09 [C++ PATCH] Fix ICE when throwing va_list (PR c++/72809) Jakub Jelinek
@ 2016-08-08 21:16 ` Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2016-08-08 21:16 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: gcc-patches List
OK.
On Mon, Aug 8, 2016 at 3:09 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> Hi!
>
> If va_list is one-entry array of structs, those RECORD_TYPEs don't
> have TYPE_BINFO.
>
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
> trunk?
>
> I've made the testcase compile instead of run, because while it with the
> patch works both on x86_64-linux and i686-linux, not sure if it really
> should be well defined - at least in C one can copy va_list only through
> va_copy, by throwing it and catching it is copied in some other way.
>
> 2016-08-08 Jakub Jelinek <jakub@redhat.com>
>
> PR c++/72809
> * rtti.c (get_pseudo_ti_index): Return TK_CLASS_TYPE for
> builtin aggregate types without TYPE_BINFO.
>
> * g++.dg/eh/stdarg1.C: New test.
>
> --- gcc/cp/rtti.c.jj 2016-04-22 18:21:27.000000000 +0200
> +++ gcc/cp/rtti.c 2016-08-08 16:21:32.937053462 +0200
> @@ -1293,7 +1293,8 @@ get_pseudo_ti_index (tree type)
> ix = TK_CLASS_TYPE;
> break;
> }
> - else if (!BINFO_N_BASE_BINFOS (TYPE_BINFO (type)))
> + else if (!TYPE_BINFO (type)
> + || !BINFO_N_BASE_BINFOS (TYPE_BINFO (type)))
> {
> ix = TK_CLASS_TYPE;
> break;
> --- gcc/testsuite/g++.dg/eh/stdarg1.C.jj 2016-08-08 16:31:52.553510463 +0200
> +++ gcc/testsuite/g++.dg/eh/stdarg1.C 2016-08-08 16:30:20.000000000 +0200
> @@ -0,0 +1,30 @@
> +// PR c++/72809
> +// { dg-do compile }
> +
> +#include <stdarg.h>
> +
> +int
> +foo (int a, ...)
> +{
> + va_list ap;
> + int r = 0;
> + va_start (ap, a);
> + try
> + {
> + if (a == 1)
> + throw (ap);
> + }
> + catch (va_list b)
> + {
> + r = va_arg (b, int);
> + }
> + va_end (ap);
> + return r;
> +}
> +
> +int
> +main ()
> +{
> + if (foo (0) != 0 || foo (1, 7) != 7)
> + __builtin_abort ();
> +}
>
> Jakub
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-08-08 21:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-08 19:09 [C++ PATCH] Fix ICE when throwing va_list (PR c++/72809) Jakub Jelinek
2016-08-08 21:16 ` Jason Merrill
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).