18-11-2020, 09:50 PM

Rule 0-1-6 seems to be counter productive with Boolean variables. DU dataflow anomalies are normal and desirable with Boolean variables. For example:

The compliant and non-compliant code result in different binaries. Both seem equally safe, but the compliant solution is less efficient. Which seems at odds with the statement in MISRA spec claims

Code:

`extern bool random_bool ();`

bool non_compliant_and (void)

{

bool const b1 = random_bool();

bool const b2 = random_bool();

return b1 && b2; // b2 is DU dataflow anomaly when b1 is false

}

bool non_compliant_or (void)

{

bool const b1 = random_bool();

bool const b2 = random_bool();

return b1 || b2; // b2 is DU dataflow anomaly when b1 is true

}

bool compliant_and (void)

{

bool const b1 = random_bool();

bool const b2 = random_bool();

bool tmp = b1;

tmp = b2 && b1;

return tmp;

}

bool compliant_or (void)

{

bool const b1 = random_bool();

bool const b2 = random_bool();

bool tmp = b1;

tmp = b2 || b1;

return tmp;

}

Quote:At best this (DU dataflow anomaly) is inefficient, but may indicate a genuine problem.Is there any insight anyone can provide on such a perplexing problem?