Intel® C++ Compiler
Support and discussions for creating C++ code that runs on platforms based on Intel® processors.
Announcements
The Intel sign-in experience is changing in February to support enhanced security controls. If you sign in, click here for more information.
7749 Discussions

Intel C++/Windows: optimization-dependent error

xtalswingyahoo_com
153 Views
Hello,
I'm porting some code from Linux -> Windows and getting an odd optimization-dependent error.
Essentially, when I compile with Intel C Compiler 11.066 (WinXP64 install, 32-bit target) with /O2 I get an error of the following form:
0xC0000005: Access violation reading location 0xffffffff.
at the following location:
else if(gb_algorithm==egbOBC) {
for(i=0;i {
rbi = born->bRad;
rb = rbi * rbi * born->drobc * dvda;
^^^^^^^^^^^^^^^^^^^^^^^^^^^
}
}

For what it's worth, the MS debugger reports the value of i equal to natoms.

If I recompile with /Od, the code runs.

Most interestingly, the following change makes the code work with /O2:
1617a1618
> volatile int idx;
1641c1642
< for(i=0;i---
> for(idx=0;idx1643,1644c1644,1645
< rbi = born->bRad;
< rb = rbi * rbi * born->drobc * dvda;
---
> rbi = born->bRad[idx];
> rb[idx] = rbi * rbi * born->drobc[idx] * dvda[idx];

Any thoughts on what might be causing this?
0 Kudos
1 Reply
JenniferJ
Moderator
153 Views
Please use the work-around for now. It is a bug in the compiler at -O2.

I tried with a simple testcase, it does not duplicate the problem. Is it possible for you to create a small testcase?

mytest.cpp: icl /O2 mytest.cpp.
[cpp]#define mysize 100

int main(void)
{
	int i = mysize;
	int natoms = mysize;
	struct {
		float bRad[mysize];
		float drobc[mysize];
	} temp, *born;
	float rb[mysize], dvda[mysize];
	float rbi;

	born = &temp;
	for(i=0;ibRad;
		rb = rbi * rbi * born->drobc * dvda;
	}
	return 0;
}[/cpp]

Reply