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

C++11 in-class initialization lead to crash

Bert_Jonson
Beginner
2,374 Views

[cpp]

#include <stdio.h>

static struct {
    const char *s = "abcd";
} a;

int main() {
    printf("%s", a.s);
}
[/cpp]

GCC works correctly on it, when exe produced by icc crashes.

ICC 13.1 on win.

There is too many fails with ICC and today none of my bugreports was fixed, it has awful support of C++11 features, also no information about next release of ICC, so i'm moving to GCC.

0 Kudos
38 Replies
SergeyKostrov
Valued Contributor II
1,513 Views
I did a quick verification ( on WIndows XP with Intel C++ compiler version 12 ) and I could not compile the test case. Here is an output of Intel C++ compiler: ..>icl.exe /Qstd=c++0x /MD Main.cpp Intel(R) C++ Compiler XE for applications running on IA-32, Version 12.1.7.371 Build 20120928 Copyright (C) 1985-2012 Intel Corporation. All rights reserved. Main.cpp Main.cpp(5): error: data member initializer is not allowed const char *s = "abcd"; ^ compilation aborted for Main.cpp (code 2) What compiler options did you use?
0 Kudos
Bert_Jonson
Beginner
1,513 Views

I written in title that it's C++11, so it's need to specify /Qstd=c++11.

0 Kudos
SergeyKostrov
Valued Contributor II
1,513 Views
>>...I written in title that it's C++11, so it's need to specify /Qstd=c++11 /Qstd=c++11 and /Qstd=c++0x options do the same. Aslo, I see that you've changed the version of the compiler to 13.1 from 12.1 and it is a good thing to inform everybody about so important update in the inital post.
0 Kudos
Bert_Jonson
Beginner
1,513 Views

I know.

At first it was mistake(i'm sorry), i uses 13.1 compiler from the day when it was released.

0 Kudos
bernaske
New Contributor I
1,513 Views

hi Sergey, hi Bert

i have the sample code compile on openSUSE 12.3 Linux,

with icc

linux-cuda:/ibm_supercomputing/testprg # icc -std=c++11 c_11.c                                                                                               
icc: command line warning #10370: option '-std=c++11' is not valid for C compilations                                                                          
c_11.c(3): error: expected a ";"                                                                                                                               
      const char *s = "abcd";                                                                                                                                  
                    ^
this error output, then i have compile with following statement:

icpc -std=c++0x c_11.c -o c11
and the result , no compile errors,

i use the 64 Bit Parallel Studio XE for Linux, Compiler Versions icc and icpc 13.1.0.20130121

best regards

Franz

0 Kudos
SergeyKostrov
Valued Contributor II
1,513 Views
>>...GCC works correctly on it, when exe produced by icc crashes... Thank you for the report! This is simply to confirm that the problem is reproduced with Intel C++ compiler version 13.1.0.149 ( Update 2 ) on Windows 7 Professional and let's see a response from Intel software engineers. Technical details are as follows: // ..>icl.exe /MD /Qstd=c++11 Main.cpp - Problem ( Crash ) reproduced // ..>icl.exe /MD /Qstd=c++0x Main.cpp - Problem ( Crash ) reproduced #include "stdio.h" static struct { const char *s = "abcd"; } a; int main( void ) { printf("%s", a.s); } /* [ Compiler Output with /Qstd=c++11 ] ..>icl.exe /MD /Qstd=c++11 Main.cpp Intel(R) C++ Compiler XE for applications running on IA-32, Version 13.1.0.149 Build 20130118 Copyright (C) 1985-2013 Intel Corporation. All rights reserved. Main.cpp Microsoft (R) Incremental Linker Version 10.00.40219.01 Copyright (C) Microsoft Corporation. All rights reserved. -out:Main.exe Main.obj [ Compiler Output with /Qstd=c++0x ] ..>icl.exe /MD /Qstd=c++0x Main.cpp Intel(R) C++ Compiler XE for applications running on IA-32, Version 13.1.0.149 Build 20130118 Copyright (C) 1985-2013 Intel Corporation. All rights reserved. Main.cpp Microsoft (R) Incremental Linker Version 10.00.40219.01 Copyright (C) Microsoft Corporation. All rights reserved. -out:Main.exe Main.obj */
0 Kudos
SergeyKostrov
Valued Contributor II
1,513 Views
>>...then i have compile with following statement: >> >>icpc -std=c++0x c_11.c -o c11 >>and the result , no compile errors It is good to know that with -std=c++0x option on a Linux there are no compilation problems. Did you try to execute the test case?
0 Kudos
bernaske
New Contributor I
1,513 Views

Hi Sergey,

yes i have execute the testcase result is a segmentation fault , now i check it with debugger

best regards

Franz

0 Kudos
JenniferJ
Moderator
1,513 Views

Thanks all. 

I'll file a bug report for it. I checked with update3 on Windows, it still crash. 

Jennifer 

0 Kudos
SergeyKostrov
Valued Contributor II
1,513 Views
Hi Jennifer, >>... I checked with update3 on Windows, it still crash... Did Intel release Update 3 for C++ compiler? Thanks.
0 Kudos
SergeyKostrov
Valued Contributor II
1,513 Views
Hi Bert, >>...it has awful support of C++11 features, also no information about next release of ICC, so i'm moving to GCC... Look, just ~12 hours ago you've reported the problem and Jennifer already filed a bug report. So, it should be fixed in some update of Intel C++ compiler. Please try to consider a workaround, of course if it is possible. Do you need help? PS: One more thing, did you try to report any issues / problems with another big software companies, like Microsoft? I've done a few in the past and every time it looked like I'm a developer who created all these bugs and it is my job to fix them...
0 Kudos
bernaske
New Contributor I
1,513 Views

Hi Sergey, Hi Bert

now i have compile the testcase with gcc/g++ 4.7.2 and 4.8.0 under openSUSE 12.3 64 Bit Linux no problems till compile but

the executable produce the same segmentation fault as the ICC/ICPC , now my opinon, nothing is perfect ,every software has bugs

but i have excelllent expierence with the INTEL, IBM and NVIDIA Developer support for performnce critical application on linux i allways use my

INTEL Parallel Studio XE 2013, i like it, on the most cases its the right solution under Linux

best Regards

Franz

0 Kudos
bernaske
New Contributor I
1,513 Views

Hi Sergey,

now the g++/gcc executable produce the SIGSEGV on folllow:

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff72893a4 in __GI__IO_default_xsputn (f=0x7fffffffd260, data=<optimized out>, n=4)
    at genops.c:476
476                     *p++ = *s++;

the ICPC exec the SIGSEGV at:

Program received signal SIGSEGV, Segmentation fault.
strchrnul () at ../sysdeps/x86_64/strchrnul.S:33
33              movdqa  (%rdi), %xmm0
i'm not a assembler specialist, but i diassemble or generate an assembler listing and inspect it

best Regards

Franz

0 Kudos
Bernard
Valued Contributor I
1,513 Views

>>>33              movdqa  (%rdi), %xmm0>>>

It looks like a rdi is containing a invalid source pointer.Can you inspect the memory content of rdi register?

0 Kudos
Bernard
Valued Contributor I
1,513 Views

It looks like rdi register is containing a invalid source pointer.Can you inspect the content of rdi register?

0 Kudos
bernaske
New Contributor I
1,513 Views

Hi iliyapolak,

the content of the rdi register:

value          Description

0x4006f9    4196089

best regards

Franz

0 Kudos
bernaske
New Contributor I
1,513 Views

Hi iliyapolak, hi sergey

in the strchrnu.S  was the SIGSEGV produce

the statement on line 476

      *p++ = *s++; is the reason

0 Kudos
Bernard
Valued Contributor I
1,513 Views

Can you look in memory window to what values is this address 0x4006f9 initialized.

0 Kudos
bernaske
New Contributor I
1,513 Views

Hi iliyapolak, hi sergey

now the rdi register or the char pointer *p++ contents '/x' or '/d' depents on this for loop counter

for( i = count; --i >= 0; )

    *p++ = *s++;       this is the code sequence that crashed with SIGSEGV

before the char *p stores  _IO_write_ptr which contains the value 4196089 dec or 0x4006f9

the loop counter i has the value /x

you have right the source pointer contains a invalid value

best reagrds

Franz

0 Kudos
Bernard
Valued Contributor I
1,424 Views

>>>you have right the source pointer contains a invalid value>>>

It always pays off to learning some debugging magic:)

0 Kudos
Reply