I have a “logic issue” with the attached code segment. This code segment does nothing except show the problem. The comments describe the sections which work as expected, and where it quits working as expected. Does this look like a compiler problem (IAR for ARM, V5.4), or am I off in the weeds ? I am compiling for a STM32.
uint32_t sum;
uint16_t num1;
uint16_t num2;
sum = 0;
//***********************************************
// These following two statements work correctly.
// For these statements, num < 2, so sum = 0xAAAA
// is executed.
//***********************************************
num1 = 0;
num2 = 0;
if( (num1 < 2) || (num2 > 10) )
sum = 0xAAAA;
num1 = 1;
num2 = 0;
if( (num1 < 2) || (num2 > 10) )
sum = 0xAAAA;
//***********************************************
// The next group of statements work correctly.
// num2 >= 2, and num2 < 10. sum = 0xAAAA is
// not executed.
//***********************************************
num1 = 2;
num2 = 0;
if( (num1 < 2) || (num2 > 10) )
sum = 0xAAAA;
num1 = 3;
num2 = 0;
if( (num1 < 2) || (num2 > 10) )
sum = 0xAAAA;
num1 = 4;
num2 = 0;
if( (num1 < 2) || (num2 > 10) )
sum = 0xAAAA;
num1 = 5;
num2 = 0;
if( (num1 < 2) || (num2 > 10) )
sum = 0xAAAA;
num1 = 6;
num2 = 0;
if( (num1 < 2) || (num2 > 10) )
sum = 0xAAAA;
num1 = 7;
num2 = 0;
if( (num1 < 2) || (num2 > 10) )
sum = 0xAAAA;
num1 = 8;
num2 = 0;
if( (num1 < 2) || (num2 > 10) )
sum = 0xAAAA;
num1 = 9;
num2 = 0;
if( (num1 < 2) || (num2 > 10) )
sum = 0xAAAA;
num1 = 10;
num2 = 0;
if( (num1 < 2) || (num2 > 10) )
sum = 0xAAAA;
//***********************************
// Stops working here. Why ?
// same conditions exist as above.
// Neither statement should evaluate
// to true, so sum = 0xAAAA should
// not be executed, but it does.
//**********************************
num1 = 11;
num2 = 0;
if( (num1 < 2) || (num2 > 10) )
sum = 0xAAAA;
num1 = 12;
num2 = 0;
if( (num1 < 2) || (num2 > 10) )
sum = 0xAAAA;
num1 = 13;
num2 = 0;
if( (num1 < 2) || (num2 > 10) )
sum = 0xAAAA;
num1 = 14;
num2 = 0;
if( (num1 < 2) || (num2 > 10) )
sum = 0xAAAA;
num1 = 15;
num2 = 0;
if( (num1 < 2) || (num2 > 10) )
sum = 0xAAAA;