swtv-kaist / cs458-fall22

1 stars 0 forks source link

HW6 About Branch Coverage #21

Closed 3-24 closed 1 year ago

3-24 commented 1 year ago

Suppose I have the following statement with AND clauses where A and B and C are boolean.

result = A && B && C

Then how do gcc --coverage and gcov measure the branch coverage on this? I thought it should be unfolded as below because the C compiler creates CFG similar to that. (https://godbolt.org/z/Pnrzebvnz)

if (A == true){
  if (B == true) {
    if (C == true) {
       // branch 1
    } else {
      // branch 2
    }
  } else {
    // branch 3
  }
} else {
  // branch 4
}

However, the actual result says that it has six branches.

moonzoo commented 1 year ago

You example actually has 6 branches (you missed 2 branches BRANCH 5 and BRANCH 6 ;-)

if (A == true){ //BRANCH 5
  if (B == true) {// BRANCH 6
    if (C == true) {
       // branch 1
    } else {
      // branch 2
    }
  } else {
    // branch 3
  }
} else {
  // branch 4
}
3-24 commented 1 year ago

Oh, now I realize that I missed them 👀