The following valid (though questionable) code snippet triggers an ICE since GCC 3.1: ========================================= #include <stdarg.h> void foo(int, ...) { va_list va; int i; i = va_arg(va, int&); } ========================================= bug.cc: In function 'void foo(int, ...)': bug.cc:7: warning: cannot receive objects of non-POD type 'int&' through '...'; call will abort at runtime bug.cc:7: internal compiler error: in build_modify_expr, at cp/typeck.c:5643 Please submit a full bug report, [etc.]
Confirmed, we should not ICE on undefined code.
I have a simple fix.
The patch which I am testing: Index: call.c =================================================================== --- call.c (revision 116493) +++ call.c (working copy) @@ -4544,10 +4544,12 @@ build_x_va_arg (tree expr, tree type) if (! pod_type_p (type)) { + /* Remove reference types so we don't ICE later on. */ + tree type1 = non_reference (type); /* Undefined behavior [expr.call] 5.2.2/7. */ warning (0, "cannot receive objects of non-POD type %q#T through %<...%>; " "call will abort at runtime", type); - expr = convert (build_pointer_type (type), null_node); + expr = convert (build_pointer_type (type1), null_node); expr = build2 (COMPOUND_EXPR, TREE_TYPE (expr), call_builtin_trap (), expr); expr = build_indirect_ref (expr, NULL); ------- Since we already build a pointer type, we don't need use the reference type.
Subject: Bug 28349 Author: pinskia Date: Wed Aug 30 04:33:10 2006 New Revision: 116577 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=116577 Log: 2006-08-29 Andrew Pinski <pinskia@physics.uc.edu> PR c++/28349 * testsuite/g++.dg/warn/var-args1.C: New test. 2006-08-29 Andrew Pinski <pinskia@physics.uc.edu> PR C++/28349 * call.c (build_x_va_arg): Remove the reference type from the type before creating the pointer type. Added: trunk/gcc/testsuite/g++.dg/warn/var-args1.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/call.c trunk/gcc/testsuite/ChangeLog
Fixed on the mainline, will most likely Apply this patch to the 4.1 branch this long weekend.
Fixed also on the 4.1 branch now.
Subject: Bug 28349 Author: pinskia Date: Fri Oct 6 02:51:33 2006 New Revision: 117479 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=117479 Log: 2006-10-05 Andrew Pinski <pinskia@physics.uc.edu> PR C++/28349 * call.c (build_x_va_arg): Remove the reference type from the type before creating the pointer type. 2006-10-05 Andrew Pinski <pinskia@physics.uc.edu> PR c++/28349 * testsuite/g++.dg/warn/var-args1.C: New test. Added: branches/gcc-4_1-branch/gcc/testsuite/g++.dg/warn/var-args1.C - copied unchanged from r116577, trunk/gcc/testsuite/g++.dg/warn/var-args1.C Modified: branches/gcc-4_1-branch/gcc/cp/ChangeLog branches/gcc-4_1-branch/gcc/cp/call.c branches/gcc-4_1-branch/gcc/testsuite/ChangeLog
Subject: Bug 28349 Author: pinskia Date: Tue Oct 10 04:38:25 2006 New Revision: 117595 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=117595 Log: 2006-10-09 Andrew Pinski <pinskia@physics.uc.edu> PR C++/28349 * call.c (build_x_va_arg): Remove the reference type from the type before creating the pointer type. 2006-10-09 Andrew Pinski <pinskia@physics.uc.edu> PR c++/28349 * testsuite/g++.dg/warn/var-args1.C: New test Added: branches/gcc-4_0-branch/gcc/testsuite/g++.dg/warn/var-args1.C - copied unchanged from r116577, trunk/gcc/testsuite/g++.dg/warn/var-args1.C Modified: branches/gcc-4_0-branch/gcc/cp/ChangeLog branches/gcc-4_0-branch/gcc/cp/call.c branches/gcc-4_0-branch/gcc/testsuite/ChangeLog
Fixed.