Bug 33435 - internal compiler error with templates and openmp
Summary: internal compiler error with templates and openmp
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-09-14 12:48 UTC by Eberhard Kuemmerle
Modified: 2008-06-18 07:20 UTC (History)
2 users (show)

See Also:
Host: x86_64-linux-gnu
Target: x86_64-linux-gnu
Build: x86_64-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2007-09-23 17:20:55


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Eberhard Kuemmerle 2007-09-14 12:48:47 UTC
I get the error message

bug.cpp:16: internal compiler error: in create_tmp_var, at gimplify.c:487

when compiling the following code with

g++ -fopenmp -DTVMET_OPTIMIZE -c bug.cpp

where bug.cpp contains:

#include <tvmet/Vector.h>           // Tiny Vector Matrix library using Expression Templates
#include <tvmet/VectorFunctions.h>  // http://tvmet.sourceforge.net/
using namespace tvmet;

int main() {
  Vector<int,3> a[10];
  int i;
#pragma omp parallel
  {
#pragma omp for schedule(dynamic)
    for (i=0; i<10; ++i) {
      // do something
    }
#pragma omp master
    {
	a[0] = a[1];
    }
#pragma omp for schedule(dynamic)
    for (i=0; i<10; ++i) {
      // do something
    }
  }
}

The problem is definitely related to openmp because the following code compiles without any error:

#include <tvmet/Vector.h>           // Tiny Vector Matrix library using Expression Templates
#include <tvmet/VectorFunctions.h>  // http://tvmet.sourceforge.net/
using namespace tvmet;

int main() {
  Vector<int,3> a[10];
  int i;
#pragma omp parallel for schedule(dynamic)
  for (i=0; i<10; ++i) {
    // do something
  }
  a[0] = a[1];
#pragma omp parallel for schedule(dynamic)
  for (i=0; i<10; ++i) {
    // do something
  }
}
Comment 1 Wolfgang Bangerth 2007-09-18 19:16:20 UTC
Can you try to come up with an example that is self-contained,
i.e. only contains those parts of the Tiny Vector Matrix library
that are really used (or none at all)?

W.
Comment 2 Eberhard Kuemmerle 2007-09-19 09:40:26 UTC
Here is a self-contained example:

template<class T, int Sz>
class Vector {
public:
  explicit Vector() {}
  ~Vector() {}
private:
  T						m_data[Sz];
};

int main() {
  Vector<int,3> a[10];
  int i;
#pragma omp parallel
  {
#pragma omp for schedule(dynamic)
    for (i=0; i<10; ++i) {
      // do something
    }
#pragma omp master
    {
	a[0] = a[1];
    }
#pragma omp for schedule(dynamic)
    for (i=0; i<10; ++i) {
      // do something
    }
  }
}

I can avoid the internal compiler error by:
 1) removing the '-fopenmp' option
 2) changing the '#pragma omp' statements as shown in the original example
 3) removing the destructor '~Vector() {}' from 'class Vector' in the new example!
Comment 3 Wolfgang Bangerth 2007-09-23 17:20:55 UTC
Confirmed.
W.
Comment 4 Eberhard Kuemmerle 2008-03-12 14:45:23 UTC
The bug ist still present in gcc 4.3.0:

bug.cpp:16: internal compiler error: in create_tmp_var, at gimplify.c:497

Comment 5 Wolfgang Bangerth 2008-06-16 15:03:38 UTC
This appears to work for me now with
  gcc version 4.4.0 20080527 (experimental) [trunk revision 136055] (GCC) 
Can you check whether it also works for you?

W.
Comment 6 Eberhard Kuemmerle 2008-06-17 14:06:38 UTC
I tried gcc 4.4.0 20080613 (experimental):
indeed, it works now!
Comment 7 Eberhard Kuemmerle 2008-06-18 07:20:37 UTC
gcc release 4.3.1 already works!