Bug 51854 - [4.4/4.5/4.6 Regression] ICE in mangle.c with literal of complex floating type
Summary: [4.4/4.5/4.6 Regression] ICE in mangle.c with literal of complex floating type
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: 4.6.3
Assignee: Jason Merrill
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2012-01-13 22:21 UTC by Hubert Tong
Modified: 2012-01-16 21:53 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.3.6, 4.7.0
Known to fail: 4.4.0, 4.5.0, 4.6.0
Last reconfirmed: 2012-01-13 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Hubert Tong 2012-01-13 22:21:23 UTC
ICE with imaginary component in mangled expression.

## Small self-contained source (cmplxfMangle.cpp):
template <unsigned N> struct A;

template <typename U, typename V>
char foo(U, V);

template <typename U>
void bar(A<sizeof(foo(U(), 1.0fj))> *);

int main() {
   bar<int>(0);
}


## Compiler invocation:
g++-4.6.0 cmplxfMangle.cpp -c


## Compiler output:
cmplxfMangle.cpp: In instantiation of âvoid bar(A<sizeof (char foo(U(), (__complex__ float){0.0f, 1.0e+0f}))>*) [with U = int]â:
cmplxfMangle.cpp:10:15:   instantiated from here
cmplxfMangle.cpp:7:6: internal compiler error: in write_template_arg_literal, at cp/mangle.c:2772
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.


## g++ -v output:
Using built-in specs.
COLLECT_GCC=g++-4.6.0
COLLECT_LTO_WRAPPER=/data/gcc/libexec/gcc/powerpc64-unknown-linux-gnu/4.6.0/lto-wrapper
Target: powerpc64-unknown-linux-gnu
Configured with: ./configure --prefix=/data/gcc --program-suffix=-4.6.0 --disable-libssp --disable-libgcj --enable-version-specific-runtime-libs --with-cpu=default32 --enable-secureplt --with-long-double-128 --enable-shared --enable-__cxa_atexit --enable-threads=posix --enable-languages=c,c++,fortran --with-gmp=/usr/local
Thread model: posix
gcc version 4.6.0 (GCC)
Comment 1 Andrew Pinski 2012-01-13 22:25:28 UTC
4.3 gave the following sorry:
t.cc:11: sorry, unimplemented: call_expr cannot be mangled due to a defect in the C++ ABI

Confirmed.
Comment 2 Jakub Jelinek 2012-01-16 18:29:41 UTC
I wonder whether:
--- gcc/cp/mangle.c.jj	2012-01-13 21:47:31.000000000 +0100
+++ gcc/cp/mangle.c	2012-01-16 19:26:48.474088778 +0100
@@ -2927,6 +2927,25 @@ write_template_arg_literal (const tree v
 	write_real_cst (value);
 	break;
 
+      case COMPLEX_CST:
+	if (TREE_CODE (TREE_REALPART (value)) == INTEGER_CST
+	    && TREE_CODE (TREE_IMAGPART (value)) == INTEGER_CST)
+	  {
+	    write_integer_cst (TREE_REALPART (value));
+	    write_char ('_');
+	    write_integer_cst (TREE_IMAGPART (value));
+	  }
+	else if (TREE_CODE (TREE_REALPART (value)) == REAL_CST
+		 && TREE_CODE (TREE_IMAGPART (value)) == REAL_CST)
+	  {
+	    write_real_cst (TREE_REALPART (value));
+	    write_char ('_');
+	    write_real_cst (TREE_IMAGPART (value));
+	  }
+	else
+	  gcc_unreachable ();
+	break;
+
       case STRING_CST:
 	sorry ("string literal in function template signature");
 	break;


isn't the right fix for this (of course, missing testcases etc.).
Comment 3 Jason Merrill 2012-01-16 21:32:18 UTC
Author: jason
Date: Mon Jan 16 21:32:14 2012
New Revision: 183222

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=183222
Log:
	PR c++/51854
	* mangle.c (write_template_arg_literal): Handle complex.

Added:
    trunk/gcc/testsuite/g++.dg/abi/mangle60.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/mangle.c
    trunk/gcc/testsuite/ChangeLog
Comment 4 Jason Merrill 2012-01-16 21:50:02 UTC
Author: jason
Date: Mon Jan 16 21:49:58 2012
New Revision: 183224

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=183224
Log:
	PR c++/51854
	* mangle.c (write_template_arg_literal): Sorry instead of aborting.

Added:
    branches/gcc-4_6-branch/gcc/testsuite/g++.dg/abi/mangle60.C
Modified:
    branches/gcc-4_6-branch/gcc/cp/ChangeLog
    branches/gcc-4_6-branch/gcc/cp/mangle.c
    branches/gcc-4_6-branch/gcc/testsuite/ChangeLog
Comment 5 Jason Merrill 2012-01-16 21:53:37 UTC
ICE fixed for 4.6.3; mangling fixed for 4.7.0.  I don't think this is worth fixing in 4.4/4.5.