Hello,
I have code, which looks more or less like this:
template<typename B>
struct A
{
B &b;
A(B &b) : b(b) {}
};
struct B {…};
void f(B b)
{
A(b) a;
int i = 0;
/* more code using "a", but NOT "b". */
}
int main()
{
B b{…};
#pragma omp parallel
{
#pragma omp for
for (int i = 0; i < 256; ++i)
f(b);
}
return 0;
}So I have a function "f", which is called multiple times in an OpenMP loop. This function is passed a class "B" by value. Inside this function, "b" is encapsulated in another class "A". After this encapsulation "b" is not used directly anymore, but over "a". However I noticed that although I make use of "a" a lot later in code, the (stack?) memory of the parameter "b" is reused. But as the data member "b" in "A" is a reference, this invalidates also my "a" variable.
Unfortunately this small code snippet does not reproduce the failing behaviour and my failing code is too big and too complex to show the behaviour. However as I noticed that the stack is reused I am curious whether I am able to disable this feature.
My code is running fine with -O1, but starts to fail for -O2. I tested the Intel C++ compiler version 17.0.0 and 17.0.2.
Thanks in advance and best regards,
Alexander Matthes