public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/67280] New: [5 Regression] wrong C++11 code generated on arm-linux-gnueabihf
@ 2015-08-19 17:18 doko at gcc dot gnu.org
  2015-08-20  7:35 ` [Bug target/67280] " cbaylis at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: doko at gcc dot gnu.org @ 2015-08-19 17:18 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67280

            Bug ID: 67280
           Summary: [5 Regression] wrong C++11 code generated on
                    arm-linux-gnueabihf
           Product: gcc
           Version: 5.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: doko at gcc dot gnu.org
  Target Milestone: ---

seen with the 5 branch svn r226731 on arm-linux-gnueabihf, works with -O1,
fails with -O2. works on x86_64 and aarch64.

$ cat foo.cc
#include <iostream>
#include <exception>
#include <functional>

namespace
{
void run(std::function<void()> const& f)
{
    try
    {
        f();
    }
    catch (std::exception const& e)
    {
        std::cerr << "ignored exception: " << e.what() << std::endl;
    }
}
}

int main()
{
    run([]{ throw std::runtime_error("some error"); });
    run([]{ throw std::runtime_error("some error"); });
}

$ g++ -O1 -std=c++11 foo.cc && ./a.out
ignored exception: some error
ignored exception: some error
$ g++ -O2 -std=c++11 foo.cc && ./a.out
terminate called after throwing an instance of 'std::runtime_error'
  what():  some error
Aborted
$ g++ -Os -std=c++11 foo.cc && ./a.out
terminate called after throwing an instance of 'std::runtime_error'
  what():  some error
Aborted

$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-linux-gnueabihf/5/lto-wrapper
Target: arm-linux-gnueabihf
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 5.2.1-15ubuntu1'
--with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs
--enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr
--program-suffix=-5 --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes
--with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libitm
--disable-libquadmath --enable-plugin --with-system-zlib
--disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo
--with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-armhf/jre --enable-java-home
--with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-armhf
--with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-armhf
--with-arch-directory=arm --with-ecj-jar=/usr/share/java/eclipse-ecj.jar
--enable-objc-gc --enable-multiarch --enable-multilib --disable-sjlj-exceptions
--with-arch=armv7-a --with-fpu=vfpv3-d16 --with-float=hard --with-mode=thumb
--disable-werror --enable-multilib --enable-checking=release
--build=arm-linux-gnueabihf --host=arm-linux-gnueabihf
--target=arm-linux-gnueabihf
Thread model: posix
gcc version 5.2.1 20150808 (Ubuntu 5.2.1-15ubuntu1)


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug target/67280] [5 Regression] wrong C++11 code generated on arm-linux-gnueabihf
  2015-08-19 17:18 [Bug target/67280] New: [5 Regression] wrong C++11 code generated on arm-linux-gnueabihf doko at gcc dot gnu.org
@ 2015-08-20  7:35 ` cbaylis at gcc dot gnu.org
  2015-08-20 11:57 ` rguenth at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: cbaylis at gcc dot gnu.org @ 2015-08-20  7:35 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67280

cbaylis at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2015-08-20
                 CC|                            |cbaylis at gcc dot gnu.org
           Assignee|unassigned at gcc dot gnu.org      |cbaylis at gcc dot gnu.org
     Ever confirmed|0                           |1

--- Comment #1 from cbaylis at gcc dot gnu.org ---
I will have a look at this.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug target/67280] [5 Regression] wrong C++11 code generated on arm-linux-gnueabihf
  2015-08-19 17:18 [Bug target/67280] New: [5 Regression] wrong C++11 code generated on arm-linux-gnueabihf doko at gcc dot gnu.org
  2015-08-20  7:35 ` [Bug target/67280] " cbaylis at gcc dot gnu.org
@ 2015-08-20 11:57 ` rguenth at gcc dot gnu.org
  2015-08-28 14:18 ` cbaylis at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2015-08-20 11:57 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67280

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |5.3


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug target/67280] [5 Regression] wrong C++11 code generated on arm-linux-gnueabihf
  2015-08-19 17:18 [Bug target/67280] New: [5 Regression] wrong C++11 code generated on arm-linux-gnueabihf doko at gcc dot gnu.org
  2015-08-20  7:35 ` [Bug target/67280] " cbaylis at gcc dot gnu.org
  2015-08-20 11:57 ` rguenth at gcc dot gnu.org
@ 2015-08-28 14:18 ` cbaylis at gcc dot gnu.org
  2015-08-28 15:05 ` cbaylis at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: cbaylis at gcc dot gnu.org @ 2015-08-28 14:18 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67280

--- Comment #2 from cbaylis at gcc dot gnu.org ---

Minimum optimisations to reproduce this are -O1 -fipa-icf-functions -fipa-sra.
These options also allow the bug to be reproduced on trunk (with -O2 the bug is
latent, I haven't investigated why).

The analysis here also uses -fno-inline, because the wrapper function is more
clearly visible. The problem occurs with and without inlining.

The failure is caused because the function:
   std::_Function_handler<void (),
main::{lambda()#1}>::_M_invoke(std::_Any_data const&)
is compiled to:

_ZNSt17_Function_handlerIFvvEZ4mainEUlvE_E9_M_invokeERKSt9_Any_data:
        .fnstart
.LFB2010:
        @ Volatile: function does not return.
        @ args = 0, pretend = 0, frame = 0
        @ frame_needed = 0, uses_anonymous_args = 0
        push    {r3, lr}
        bl     
_ZNSt17_Function_handlerIFvvEZ4mainEUlvE0_E9_M_invokeERKSt9_Any_data
        .cantunwind
        .fnend

This includes .cantunwind which is an ARM-specific directive which causes the
exception unwinder to stop at this function which causes execution to
terminate.

Going further back, the ARM backend emits this directive because the function
is marked "nothrow" in the ipa-pure-const phase. This is visible in the dump:
foo.cc.062i.pure-const:Function found to be nothrow: static void
std::_Function_handler<void(_ArgTypes ...), _Functor>::_M_invoke(const
std::_Any_data&, _ArgTypes&& ...) [with _Functor = main()::<lambda()>;
_ArgTypes = {}]

This is clearly wrong, because this function calls the lambda, which contains a
throw. This happens on all targets, but does not seem to cause problems on
non-ARM targets because they use the standard/generic unwinder mechanism.

The _ZNSt17_Function_handlerIFvvEZ4mainEUlvE_E9_M_invokeERKSt9_Any_data is a
wrapper, created by cgraph_node::create_wrapper(). When this function updates
the callgraph and creates the edge to the target function, it unconditionally
sets ->can_throw_external to false, which causes the ipa-pure-const phase to
mark the wrapper function as nothrow.

I will send a patch to the mailing list shortly.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug target/67280] [5 Regression] wrong C++11 code generated on arm-linux-gnueabihf
  2015-08-19 17:18 [Bug target/67280] New: [5 Regression] wrong C++11 code generated on arm-linux-gnueabihf doko at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2015-08-28 14:18 ` cbaylis at gcc dot gnu.org
@ 2015-08-28 15:05 ` cbaylis at gcc dot gnu.org
  2015-09-08  7:27 ` [Bug ipa/67280] " ramana at gcc dot gnu.org
  2015-09-08 17:33 ` cbaylis at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: cbaylis at gcc dot gnu.org @ 2015-08-28 15:05 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67280

--- Comment #3 from cbaylis at gcc dot gnu.org ---
Patch at https://gcc.gnu.org/ml/gcc-patches/2015-08/msg01791.html


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug ipa/67280] [5 Regression] wrong C++11 code generated on arm-linux-gnueabihf
  2015-08-19 17:18 [Bug target/67280] New: [5 Regression] wrong C++11 code generated on arm-linux-gnueabihf doko at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2015-08-28 15:05 ` cbaylis at gcc dot gnu.org
@ 2015-09-08  7:27 ` ramana at gcc dot gnu.org
  2015-09-08 17:33 ` cbaylis at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: ramana at gcc dot gnu.org @ 2015-09-08  7:27 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67280

Ramana Radhakrishnan <ramana at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|target                      |ipa

--- Comment #4 from Ramana Radhakrishnan <ramana at gcc dot gnu.org> ---
It's really an IPA issue.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug ipa/67280] [5 Regression] wrong C++11 code generated on arm-linux-gnueabihf
  2015-08-19 17:18 [Bug target/67280] New: [5 Regression] wrong C++11 code generated on arm-linux-gnueabihf doko at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2015-09-08  7:27 ` [Bug ipa/67280] " ramana at gcc dot gnu.org
@ 2015-09-08 17:33 ` cbaylis at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: cbaylis at gcc dot gnu.org @ 2015-09-08 17:33 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67280

--- Comment #5 from cbaylis at gcc dot gnu.org ---
Committed to trunk http://gcc.gnu.org/r227407 and gcc/ChangeLog corrected in
http://gcc.gnu.org/r227534


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-09-08 17:33 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-19 17:18 [Bug target/67280] New: [5 Regression] wrong C++11 code generated on arm-linux-gnueabihf doko at gcc dot gnu.org
2015-08-20  7:35 ` [Bug target/67280] " cbaylis at gcc dot gnu.org
2015-08-20 11:57 ` rguenth at gcc dot gnu.org
2015-08-28 14:18 ` cbaylis at gcc dot gnu.org
2015-08-28 15:05 ` cbaylis at gcc dot gnu.org
2015-09-08  7:27 ` [Bug ipa/67280] " ramana at gcc dot gnu.org
2015-09-08 17:33 ` cbaylis at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).