I have a piece of code with this structure:
__forceinline void problemFunction(bool condition, int & value)
{
if (condition)
{
value = 0;
return;
}
// ...
// a lot of calculations
// ...
}
void caller()
{
bool condition;
int value;
// ...
problemFunction(condition, value);
someOtherStuff();
}
But after building Release configuration with optimization turned on in Disassembly I get something like this:
void caller()
{
bool condition;
int value;
// ...
if (condition)
value = 0;
else
goto CalculateLabel;
ReturnProblemFunctionLabel:
someOtherStuff();
goto ReturnLabel;
CalculateLabel:
// ...
// a lot of calculations
// ...
goto ReturnProblemFunctionLabel;
ReturnLabel:
}
ProblemFunction
was splitted into two parts. And the proble is that the second part is located after the someOtherStuff
function call.
How can I locally suppress this kind of optimization?
I am using Visual Studio 2019 Version 16.4.2 on Windows 10.