Bug 28349 - [4.0 regression] ICE with "undefined" va_arg and references
Summary: [4.0 regression] ICE with "undefined" va_arg and references
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.2.0
: P2 normal
Target Milestone: 4.0.4
Assignee: Andrew Pinski
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: ice-on-valid-code, monitored, patch
Depends on:
Blocks:
 
Reported: 2006-07-11 16:29 UTC by Volker Reichelt
Modified: 2006-10-10 04:38 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.1.2 4.2.0
Known to fail:
Last reconfirmed: 2006-07-13 23:46:13


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Volker Reichelt 2006-07-11 16:29:49 UTC
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.]
Comment 1 Andrew Pinski 2006-07-13 23:46:13 UTC
Confirmed, we should not ICE on undefined code.
Comment 2 Andrew Pinski 2006-08-27 23:12:20 UTC
I have a simple fix.
Comment 3 Andrew Pinski 2006-08-27 23:23:22 UTC
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.
Comment 4 Andrew Pinski 2006-08-30 04:33:22 UTC
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

Comment 5 Andrew Pinski 2006-08-30 04:33:43 UTC
Fixed on the mainline, will most likely Apply this patch to the 4.1 branch this long weekend.
Comment 6 Andrew Pinski 2006-10-06 02:48:16 UTC
Fixed also on the 4.1 branch now.
Comment 7 Andrew Pinski 2006-10-06 02:51:41 UTC
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

Comment 8 Andrew Pinski 2006-10-10 04:38:35 UTC
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

Comment 9 Andrew Pinski 2006-10-10 04:38:38 UTC
Fixed.