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

Intel C++/Windows: optimization-dependent error

xtalswingyahoo_com
344 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
344 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]

0 Kudos
Reply