Bug 52582 - [4.7 Regression] g++ ICE when compiling qt-4.8.0 with -O2 on PPC (32bit)
Summary: [4.7 Regression] g++ ICE when compiling qt-4.8.0 with -O2 on PPC (32bit)
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: 4.7.1
Assignee: Not yet assigned to anyone
URL: https://bugzilla.redhat.com/show_bug....
Keywords:
Depends on:
Blocks:
 
Reported: 2012-03-13 17:58 UTC by karsten
Modified: 2012-03-29 13:46 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2012-03-13 00:00:00


Attachments
gzip compressed preprocessed source (232.60 KB, application/x-tar)
2012-03-13 18:01 UTC, karsten
Details
patch (416 bytes, patch)
2012-03-14 18:33 UTC, Jason Merrill
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description karsten 2012-03-13 17:58:10 UTC
gcc -v
Using built-in specs.
COLLECT_GCC=/usr/bin/gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/ppc64-redhat-linux/4.7.0/lto-wrapper
Target: ppc64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --disable-build-with-cxx --disable-build-poststage1-with-cxx --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --enable-secureplt --with-long-double-128 --build=ppc64-redhat-linux --target=ppc64-redhat-linux --with-cpu=default32
Thread model: posix
gcc version 4.7.0 20120308 (Red Hat 4.7.0-0.19) (GCC)


g++ -c -pipe -Wall -Wreturn-type -fno-strict-aliasing -Wcast-align -Wchar-subscripts -Wformat-security -Wreturn-type -Wno-unused-parameter -Wno-sign-compare -Wno-switch -Wno-switch-enum -Wundef -Wmissingnit-self -fno-stack-protector -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector --param=ssp-buffer-size=4 -m32 -O2 -fvisibility=hidden -fvisibility-inlines-hidden -D_REENTRANT -fPIC -DQT_SHARED -DJSC=QTJSC -Djscyyparse=qtjscyyparse -Djscyylex=qtjscyylex -Djscyyerror=qtjscyyerror -DWTF=QTWTF -DQT_BUILD_SCRIPT_LIB -DQT_NO_USING_NAMESPACE -DQLALR_NO_QSCRIPTGRAMMAR_DEBUG_INFO -DQT_NO_CAST_TO_ASCII -DQT_ASCII_CAST_WARNINGS -DQT3_SUPPORT -DQT_MOC_COMPAT -DQT_USE_QSTRINGBUILDER -DBUILDING_QT__=1 -DWTF_USE_ACCELERATED_COMPOSITING -DNDEBUG -DBUILDING_QT__ -DBUILDING_JavaScriptCore -DBUILDING_WTF -DWTF_USE_JAVASCRIPTCORE_BINDINGS=1 -DWTF_CHANGES=1 -DNDEBUG -DJS_NO_EXPORT -DQT_NO_DEBUG -DQT_CORE_LIB -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -I../../mkspecs/linux-g++ -I. -I../../include/QtCore -I../../include -I../3rdparty/javascriptcore/JavaScriptCore -I../3rdparty/javascriptcore -I../3rdparty/javascriptcore/JavaScriptCore/assembler -I../3rdparty/javascriptcore/JavaScriptCore/bytecode -I../3rdparty/javascriptcore/JavaScriptCore/bytecompiler -I../3rdparty/javascriptcore/JavaScriptCore/debugger -I../3rdparty/javascriptcore/JavaScriptCore/interpreter -I../3rdparty/javascriptcore/JavaScriptCore/jit -I../3rdparty/javascriptcore/JavaScriptCore/parser -I../3rdparty/javascriptcore/JavaScriptCore/pcre -I../3rdparty/javascriptcore/JavaScriptCore/profiler -I../3rdparty/javascriptcore/JavaScriptCore/runtime -I../3rdparty/javascriptcore/JavaScriptCore/wrec -I../3rdparty/javascriptcore/JavaScriptCore/wtf -I../3rdparty/javascriptcore/JavaScriptCore/wtf/symbian -I../3rdparty/javascriptcore/JavaScriptCore/wtf/unicode -I../3rdparty/javascriptcore/JavaScriptCore/yarr -I../3rdparty/javascriptcore/JavaScriptCore/API -I../3rdparty/javascriptcore/JavaScriptCore/ForwardingHeaders -I../3rdparty/javascriptcore/JavaScriptCore/generated -I../../include/QtScript -I.rcc/release-shared -I/builddir/build/BUILD/qt-everywhere-opensource-src-4.8.0/src/3rdparty/javascriptcore/WebKit/qt/Api -I../3rdparty/javascriptcore/JavaScriptCore/pcre -I/builddir/build/BUILD/qt-everywhere-opensource-src-4.8.0/src/3rdparty/javascriptcore/JavaScriptCore/tmp -I../3rdparty/javascriptcore/JavaScriptCore -I../3rdparty/javascriptcore/JavaScriptCore/parser -I../3rdparty/javascriptcore/JavaScriptCore/bytecompiler -I../3rdparty/javascriptcore/JavaScriptCore/debugger -I../3rdparty/javascriptcore/JavaScriptCore/runtime -I../3rdparty/javascriptcore/JavaScriptCore/wtf -I/builddir/build/BUILD/qt-everywhere-opensource-src-4.8.0/src/script/../3rdparty/javascriptcore/JavaScriptCore/unicode -I../3rdparty/javascriptcore/JavaScriptCore/interpreter -I../3rdparty/javascriptcore/JavaScriptCore/jit -I../3rdparty/javascriptcore/JavaScriptCore/profiler -I../3rdparty/javascriptcore/JavaScriptCore/wrec -I../3rdparty/javascriptcore/JavaScriptCore/API -I../3rdparty/javascriptcore/JavaScriptCore/bytecode -I../3rdparty/javascriptcore/JavaScriptCore/assembler -I../3rdparty/javascriptcore/JavaScriptCore/generated -I. -Iparser -I.moc/release-shared -o obj/release/JSGlobalData.o ../3rdparty/javascriptcore/JavaScriptCore/runtime/JSGlobalData.cpp
../3rdparty/javascriptcore/JavaScriptCore/runtime/JSGlobalData.cpp: In static member function 'static void QTJSC::JSGlobalData::storeVPtrs()':
../3rdparty/javascriptcore/JavaScriptCore/runtime/JSGlobalData.cpp:92:27: internal compiler error: Segmentation fault
Comment 1 karsten 2012-03-13 18:01:15 UTC
Created attachment 26886 [details]
gzip compressed preprocessed source
Comment 2 Jakub Jelinek 2012-03-13 21:12:57 UTC
Strange, with the 4.7-RH cc1plus I can reproduce the segfault even on
inline void *operator new (__SIZE_TYPE__, void *p) throw ()
{
  return p;
}
struct B
{
  virtual ~B ();
  B ();
};
struct A : B
{
  A () : B () {}
  virtual void bar ();
};
void
foo ()
{
  char a[64];
  B *b = new (&a) A ();
  b->~B ();
}

(at -O2, both -m32 and -m64), but I can't reproduce it with a cross from x86_64-linux to powerpc64-linux.
Comment 3 Jakub Jelinek 2012-03-13 22:15:58 UTC
Ah, #define HAVE_AS_GNU_ATTRIBUTE 1 in auto-host.h is essential for this.
This is devirt in action, for some reason the devirtualized A::~A () doesn't have DECL_EXTERNAL set (not sure what should set it, the FE, the devirtualizer?)
and likely the rs6000 backend just should be more forgiving and if it can't find a cgraph node, IMHO call_ABI_of_interest should just return true as a conservative answer.
So, for 4.7.0 IMHO best would be to do:
--- gcc/config/rs6000/rs6000.c 2012-03-13 19:58:59.342625117 +0100
+++ gcc/config/rs6000/rs6000.c 2012-03-13 23:14:15.693828006 +0100
@@ -7452,6 +7452,9 @@ call_ABI_of_interest (tree fndecl)
       /* Interesting functions that we are emitting in this object file.  */
       c_node = cgraph_get_node (fndecl);
       c_node = cgraph_function_or_thunk_node (c_node, NULL);
+      if (c_node == NULL)
+        return true;
+
       return !cgraph_only_called_directly_p (c_node);
     }
   return false;
and for 4.7.1/4.8 (while this can perhaps stay) we should find out why DECL_EXTERNAL isn't set.
Comment 4 Richard Biener 2012-03-14 10:41:29 UTC
Does

Index: gcc/gimple-fold.c
===================================================================
--- gcc/gimple-fold.c   (revision 185376)
+++ gcc/gimple-fold.c   (working copy)
@@ -143,6 +143,8 @@ canonicalize_constructor_val (tree cval)
          if (cfun && gimple_referenced_vars (cfun))
            add_referenced_var (base);
        }
+      else if (base && TREE_CODE (base) == FUNCTION_DECL)
+       cgraph_get_create_node (base);
       /* Fixup types in global initializers.  */
       if (TREE_TYPE (TREE_TYPE (cval)) != TREE_TYPE (TREE_OPERAND (cval, 0)))
        cval = build_fold_addr_expr (TREE_OPERAND (cval, 0));
@@ -3115,6 +3117,11 @@ gimple_get_virt_method_for_binfo (HOST_W
   if (!can_refer_decl_in_current_unit_p (fn))
     return NULL_TREE;
 
+  /* Make sure we create a cgraph node for functions we'll reference.
+     They can be non-existent if the reference comes from an entry
+     of an external vtable for example.  */
+  cgraph_get_create_node (fn);
+
   return fn;
 }
 
help?
Comment 5 Richard Biener 2012-03-14 13:01:52 UTC
Author: rguenth
Date: Wed Mar 14 13:01:46 2012
New Revision: 185381

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=185381
Log:
2012-03-14  Richard Guenther  <rguenther@suse.de>

	PR middle-end/52582
	* gimple-fold.c (canonicalize_constructor_val): Make sure
	we have a cgraph node for a FUNCTION_DECL that comes from
	a constructor.
	(gimple_get_virt_method_for_binfo): Likewise.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/gimple-fold.c
Comment 6 Jakub Jelinek 2012-03-14 14:21:22 UTC
Author: jakub
Date: Wed Mar 14 14:21:12 2012
New Revision: 185383

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=185383
Log:
	PR c++/52582
	* config/rs6000/rs6000.c (call_ABI_of_interest): Return true
	if c_node is NULL.

	* g++.dg/opt/pr52582.C: New test.

Added:
    branches/gcc-4_7-branch/gcc/testsuite/g++.dg/opt/pr52582.C
Modified:
    branches/gcc-4_7-branch/gcc/ChangeLog
    branches/gcc-4_7-branch/gcc/config/rs6000/rs6000.c
    branches/gcc-4_7-branch/gcc/testsuite/ChangeLog
Comment 7 Jakub Jelinek 2012-03-14 14:24:38 UTC
Author: jakub
Date: Wed Mar 14 14:24:32 2012
New Revision: 185384

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=185384
Log:
	PR c++/52582
	* config/rs6000/rs6000.c (call_ABI_of_interest): Return true
	if c_node is NULL.

	* g++.dg/opt/pr52582.C: New test.

Added:
    trunk/gcc/testsuite/g++.dg/opt/pr52582.C
Modified:
    trunk/gcc/testsuite/ChangeLog
Comment 8 Jakub Jelinek 2012-03-14 16:12:35 UTC
Temporarily worked around for 4.7.0.  We really should find out why we aren't setting DECL_EXTERNAL on this.
Comment 9 Jason Merrill 2012-03-14 18:33:07 UTC
Created attachment 26893 [details]
patch

Does this fix it?
Comment 10 Jakub Jelinek 2012-03-14 18:44:32 UTC
On this testcase?  Yes, it does.  Haven't done bootstrap/regtest with it though.
Comment 11 Jakub Jelinek 2012-03-15 09:48:31 UTC
Bootstrapped/regtested now on x86_64-linux and i686-linux (trunk) and {x86_64,i686,powerpc,powerpc64}-linux (4.7 branch, with the rs6000.c change backed out).  No regressions.  So this looks ok for 4.8/4.7.1 to me, for 4.7.0 I think we should just keep the rs6000 hack.  Thanks.
Comment 12 Jason Merrill 2012-03-15 21:22:48 UTC
Author: jason
Date: Thu Mar 15 21:22:38 2012
New Revision: 185443

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=185443
Log:
	PR c++/52582
	* method.c (implicitly_declare_fn): Set DECL_EXTERNAL.

Added:
    trunk/gcc/testsuite/g++.dg/torture/pr52582.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/method.c
    trunk/gcc/testsuite/ChangeLog
Comment 13 Richard Biener 2012-03-22 08:26:39 UTC
GCC 4.7.0 is being released, adjusting target milestone.
Comment 14 Jason Merrill 2012-03-22 18:34:30 UTC
Author: jason
Date: Thu Mar 22 18:34:24 2012
New Revision: 185705

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=185705
Log:
	PR c++/52582
	* method.c (implicitly_declare_fn): Set DECL_EXTERNAL.

Added:
    branches/gcc-4_7-branch/gcc/testsuite/g++.dg/torture/pr52582.C
Modified:
    branches/gcc-4_7-branch/gcc/cp/ChangeLog
    branches/gcc-4_7-branch/gcc/cp/method.c
    branches/gcc-4_7-branch/gcc/testsuite/ChangeLog
Comment 15 Jason Merrill 2012-03-29 13:46:28 UTC
Fixed.