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

            Bug ID: 85659
           Summary: ICE with inline assembly inside virtual function
           Product: gcc
           Version: 6.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ldionne.2 at gmail dot com
  Target Milestone: ---

The following program causes an ICE with GCC 6.1.0 and up. GCC 5.5.0 compiles
this fine.

==============================================================================
#include <string>

template <class Tp>
void DoNotOptimize(Tp& value) {
  asm volatile("" : "+m,r"(value) : : "memory");
}

struct base {
  virtual void f1() = 0;
};

template <typename T>
struct derived : base {
  void f1() override { ::DoNotOptimize(value_); }
  T value_;
};

template struct derived<std::string>;

int main() { }
==============================================================================

The exact error given by GCC trunk is:

==============================================================================
during RTL pass: expand
prog.cc: In function 'void DoNotOptimize(Tp&) [with Tp =
std::__cxx11::basic_string<char>]':
prog.cc:5:48: internal compiler error: in assign_temp, at function.c:977
   asm volatile("" : "+m,r"(value) : : "memory");
                                                ^
0x59887a assign_temp(tree_node*, int, int)
  ../../source/gcc/function.c:977
0x7a5bde expand_asm_stmt
  ../../source/gcc/cfgexpand.c:3083
0x7aa007 expand_gimple_stmt_1
  ../../source/gcc/cfgexpand.c:3621
0x7aa007 expand_gimple_stmt
  ../../source/gcc/cfgexpand.c:3790
0x7ab7af expand_gimple_basic_block
  ../../source/gcc/cfgexpand.c:5819
0x7b0866 execute
  ../../source/gcc/cfgexpand.c:6425
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
==============================================================================

This is especially problematic as this code was reduced from a benchmark
written using the widely used GoogleBenchmark library. This is where
DoNotOptimize comes from -- I don't write inline assembly myself.

Live examples:
GCC 5.5.0 (works): https://wandbox.org/permlink/bVzSwbSlkoDy5vBt
GCC 6.1.0 (fails): https://wandbox.org/permlink/hgUJL0aEH8MDQgI1
GCC 6.3.0 (fails): https://wandbox.org/permlink/5qhSFDvLzsrmsVrT
GCC 7.3.0 (fails): https://wandbox.org/permlink/uNdVyOlaPUWhxPec
GCC 8.1.0 (fails): https://wandbox.org/permlink/qburemRl1AcqmaVl
GCC trunk (fails): https://wandbox.org/permlink/WcDrgDL9g4YLKsGN

Reply via email to