Bug 24602 - g++: Internal error: Illegal instruction (program cc1plus)
Summary: g++: Internal error: Illegal instruction (program cc1plus)
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.4.2
: P3 normal
Target Milestone: 4.3.0
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-invalid-code, monitored
: 24606 35596 (view as bug list)
Depends on: 24606
Blocks:
  Show dependency treegraph
 
Reported: 2005-10-31 23:38 UTC by Christoph Mathys
Modified: 2008-03-29 17:32 UTC (History)
6 users (show)

See Also:
Host: i686-freebsd 5.4-p7
Target:
Build:
Known to work:
Known to fail: 2.95.3 3.3.3 3.4.0 4.0.0 4.1.0
Last reconfirmed: 2006-09-03 21:39:05


Attachments
preprocessed source file (112.35 KB, text/plain)
2005-10-31 23:46 UTC, Christoph Mathys
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Christoph Mathys 2005-10-31 23:38:32 UTC
I stumbled over a possible bug in g++ (at least it told me to file a bug report). I'm not exactly sure if the code I tried to compile is correct.

~/bug > g++ -v -save-temps -I/usr/local/include gpp_bug.cpp
Using built-in specs.
Configured with: FreeBSD/i386 system compiler
Thread model: posix
gcc version 3.4.2 [FreeBSD] 20040728
 /usr/libexec/cc1plus -E -quiet -v -I/usr/local/include -D_LONGLONG gpp_bug.cpp -o gpp_bug.ii
ignoring duplicate directory "/usr/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/include/c++/3.4
 /usr/include/c++/3.4/backward
 /usr/include
End of search list.
 /usr/libexec/cc1plus -fpreprocessed gpp_bug.ii -quiet -dumpbase gpp_bug.cpp -auxbase gpp_bug -version -o gpp_bug.s
GNU C++ version 3.4.2 [FreeBSD] 20040728 (i386-fbsdproj-freebsd)
        compiled by GNU C version 3.4.2 [FreeBSD] 20040728.
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
g++: Internal error: Illegal instruction (program cc1plus)
Please submit a full bug report.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
Comment 1 Christoph Mathys 2005-10-31 23:46:41 UTC
Created attachment 10092 [details]
preprocessed source file
Comment 2 Andrew Pinski 2005-11-01 00:33:58 UTC
This is a true C++ front-end problem, in that the seg fault is due to a stack overflow in the C++ front-end.  I think this is a regression but I have not tried to reduce it yet.
Comment 3 Andrew Pinski 2005-11-01 02:22:37 UTC
With the source here, I was able to find a different issue which I will be posting soon.
Comment 4 Andrew Pinski 2005-11-01 02:23:08 UTC
Note the backtrace for the orginal issue is:
#28 0x000000000040bb94 in convert_like_real (convs=Variable "convs" is not available.
) at /home/pinskia/src/newtest/trunk/gcc/cp/call.c:4379
#29 0x000000000040c241 in build_over_call (cand=0x15009b8, flags=1067) at /home/pinskia/src/newtest/trunk/gcc/cp/call.c:4804
#30 0x000000000040aacd in build_new_method_call (instance=0x2aaaadbb4a40, fns=Variable "fns" is not available.
) at /home/pinskia/src/newtest/trunk/gcc/cp/call.c:5441
#31 0x000000000040b5fa in convert_like_real (convs=0x15006e8, expr=0x2aaaabf002c0, fn=0x2aaaabacd100, argnum=0, inner=-1, issue_conversion_warnings=0 '\0', 
    c_cast_p=0 '\0') at /home/pinskia/src/newtest/trunk/gcc/cp/call.c:4293
#32 0x000000000040b71e in convert_like_real (convs=0x1500710, expr=0x2aaaabf002c0, fn=0x2aaaabacd100, argnum=0, inner=0, issue_conversion_warnings=1 '\001', 
    c_cast_p=0 '\0') at /home/pinskia/src/newtest/trunk/gcc/cp/call.c:4304
#33 0x000000000040c241 in build_over_call (cand=0x1500738, flags=3) at /home/pinskia/src/newtest/trunk/gcc/cp/call.c:4804
#34 0x000000000040aacd in build_new_method_call (instance=0x2aaaadbb49c0, fns=Variable "fns" is not available.
) at /home/pinskia/src/newtest/trunk/gcc/cp/call.c:5441
#35 0x00000000004b5c9f in ocp_convert (type=0x2aaaabab5420, expr=0x2aaaabf002c0, convtype=Variable "convtype" is not available.
) at /home/pinskia/src/newtest/trunk/gcc/cp/cvt.c:764
#
Comment 5 Andrew Pinski 2005-11-01 03:09:28 UTC
PR 24606 is the other issue I found.
Comment 6 Andrew Pinski 2005-11-01 04:36:53 UTC
Reduced testcase:
struct string;
struct _Deque_iterator     {
     string &operator*() const;
};
template<typename _Function>     void for_each(_Function __f)     {
  _Deque_iterator __first1;
  __f(*__first1);
}
struct locale   {
  locale(const locale& __other) throw();
};
template<typename SequenceT>
void trim(string& Input, const locale& Loc=locale());
int main() {
  for_each(trim<string>);
}
----

This one also ICEs with ICC.  I will let someone else decide if this is valid or invalid code and then confirm it.
Comment 7 Volker Reichelt 2005-11-17 11:59:15 UTC
Here's a sightly simpler testcase.
If I remove the copy-ctor from A, I get the failure from PR24606.

=========================================
template<typename F> void foo(F f)
{
    f();
}

struct A
{
    A();
    A(const A&);
};

template<int> void bar(A = A());

void baz()
{
    foo(bar<0>);
}
=========================================

Btw, removing the template from "bar" makes the code compile.
So it seems like the code is valid after all.
Comment 8 Volker Reichelt 2007-07-23 22:05:28 UTC
Since Nathan's patch for PR32839, we get the following error message for the testcase in comment #7 (and similar messages for the original testcase, the testcase in comment #6, and PR 24606):

bug.cc: In function 'void foo(F) [with F = void (*)(A)]':
bug.cc:16:   instantiated from here
bug.cc:3: error: too few arguments to function

I get the same error message if I make bar a non-template function.
In contrast to my last sentence of comment #7, I now think the compiler
does the right thing here.

Nathan, do you think so, too?
If yes, we can close this bug as fixed.
Comment 9 Volker Reichelt 2007-07-23 22:08:31 UTC
*** Bug 24606 has been marked as a duplicate of this bug. ***
Comment 10 Volker Reichelt 2007-11-01 12:52:54 UTC
Nathan confirmed in private mail that the compiler now does the right thing.
So closing as fixed.
Comment 11 Volker Reichelt 2008-03-29 17:32:53 UTC
*** Bug 35596 has been marked as a duplicate of this bug. ***