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

[BUG] internal error: icc chokes on struct with function pointer

Sebastian_Freundt
460 Views
Following code:
extern struct stream_s make_stream(void);

struct stream_s {
	void *clo;
	/* for strctl */
	int(*ctl)(void*, ...);
};

struct stream_s
make_stream(void)
{
	static int x;
	return (struct stream_s){.clo = &x};
}

when compiled produces:

$ icc -std=c99 -g -O2 ./crash.c
": internal error: ** segmentation violation signal raised **
Access violation or stack overflow. Please contact Support.

compilation aborted for ./crash.c (code 4)

Interestingly, when the function pointer is the first slot in the struct the code will run just fine.

 

0 Kudos
5 Replies
Sebastian_Freundt
460 Views

Forgot to post versions:

$ icc -V
Intel(R) C Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 14.0.2.144 Build 20140120
Copyright (C) 1985-2014 Intel Corporation.  All rights reserved.
FOR NON-COMMERCIAL USE ONLY

 

0 Kudos
MalReddy_Y_Intel
Employee
460 Views

Hi,

I can also reproduce this issue, thanks for reporting. I have escalated to development team. I will inform you when I have an update.

Reddy

 

0 Kudos
Sebastian_Freundt
460 Views

Just to let you know, icc 16.0.0.069 Beta Build 20150527 still shows this issue.

 

0 Kudos
Sebastian_Freundt
460 Views
Just to let you know, icc 18.0.0 20170811 still shows this issue.
0 Kudos
Judith_W_Intel
Employee
460 Views

 

Yes this bug is still open in our database (as cmplrs-626).

There are two possible workarounds, as shown below under #ifdef OK or #ifdef OK2.
The bug has to do with placing a temporary declaration which uses x before the declaration of x on the list of static variables.

extern struct stream_s make_stream(void);
struct stream_s {
void *clo;
/* for strctl */
int(*ctl)(void*, ...);
};
struct stream_s
make_stream(void)
{
#ifdef OK
int x;
#else
static int x;
#endif

#ifdef OK2
struct stream_s tmp;
tmp.clo = &x;
return tmp;
#else
return (struct stream_s){.clo = &x};
#endif
}

 

0 Kudos
Reply