Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

segmentation fault with icpc

daichi_f_
Beginner
438 Views

Hi,

 

Segmentation fault sometimes occurs in a program when icpc is used.

The version of icpc I am using is 17.0.2 20170213, and the version of g++ is 5.2.0.

It does not happen when g++ is used.

This issue was originally found in BOUT++ code. (https://github.com/boutproject/BOUT-dev)

Please have a look at the attached reproducer.

It was written based on BOUT++ code.

If g++ is used:

$ ./a.out
0
0
1
1
1
2
2
2

 

But if icpc is used:

$ ./a.out.intel
0
0
...
Segmentation fault (core dumped)

 

Please note that sometimes the segfault does not occur, but always the output is corrupted.(0 0 0....)

 

The problem does not happen even if icpc is used when

1) a copy constructor is defined (a.out.intel.copy)

2) reference variables are not used (a.out.intel.noref)

 

Though this issue had been fixed in BOUT++ code by doing 2) (https://github.com/boutproject/BOUT-dev/pull/468), but I still suspect this is a bug of intel compiler because the problem does not happen with g++.

Is this a bug of icpc?

 

Best regards,

Daichi

0 Kudos
3 Replies
Judith_W_Intel
Employee
438 Views

This looks like a user error. A copy constructor is needed to keep the reference data members valid.

 

DataIterator has several self-references, but no copy constructor to keep them consistent. And of course all the member functions of Test return an object of type DataIterator. At what do those references wind up pointing if the member functions aren’t inlined?

 

0 Kudos
daichi_f_
Beginner
438 Views

Judith,

Thank you very much for your answer.

g++ works in that case without user defined copy constructor, so it worked unexpectedly?

 

Best  regards,

Daichi

0 Kudos
Judith_W_Intel
Employee
438 Views

 

icc also "works" if you enable optimization (i.e. compiler at -O1 or higher so the code is inlined). That doesn't mean the code is correct.

0 Kudos
Reply