Issue 131505
Summary [MC/DC] missing conditions in macros from system headers with cast
Labels tools:llvm-cov
Assignees
Reporter whentojump
    Compiler explorer [link](https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:c%2B%2B,selection:(endColumn:22,endLineNumber:3,positionColumn:22,positionLineNumber:3,selectionStartColumn:22,selectionStartLineNumber:3,startColumn:22,startLineNumber:3),source:'%23ifdef+HEADER%0A%0A%23define+FOO(x)+(+x%5B0%5D+%26%26+x%5B1%5D+)%0A%23define+BAR(x)+(+((int+*)x)%5B0%5D+%26%26+((int+*)x)%5B1%5D+)%0A%0A%23else%0A%0A%23define+HEADER%0A%23include+%3Cexample.cpp%3E%0A%0Aint+buf%5B100%5D%3B%0Aint+a,+b,+c%3B%0A%0Aint+main(void)+%7B%0A++++if+(+FOO(buf)+%26%26+a+%26%26+b+)%0A++++++++return+1%3B%0A++++if+(+BAR(buf)+%26%26+a+%26%26+b+)%0A++++++++return+2%3B%0A++++return+3%3B%0A%7D%0A%23endif'),l:'5',n:'0',o:'C%2B%2B+source+%231',t:'0')),k:33.333333333333336,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:clang_assertions_trunk,filters:(b:'0',binary:'1',binaryObject:'1',commentOnly:'0',debugCalls:'1',demangle:'0',directives:'0',execute:'1',intel:'0',libraryCode:'0',trim:'1',verboseDemangling:'0'),flagsViewOpen:'1',fontScale:14,fontUsePx:'0',j:1,lang:c%2B%2B,libs:!(),options:'-fprofile-instr-generate+-fcoverage-mapping+-fcoverage-mcdc+-isystem.',overrides:!(),selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1),l:'5',n:'0',o:'+x86-64+clang+(assertions+trunk)+(Editor+%231)',t:'0')),header:(),k:33.333333333333336,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:tool,i:(args:'-show-mcdc',argsPanelShown:'0',compilerName:'x86-64+clang+(assertions+trunk)',editorid:1,fontScale:14,fontUsePx:'0',j:1,monacoEditorHasBeenAutoOpened:'1',monacoEditorOpen:'1',monacoStdin:'1',stdin:'',stdinPanelShown:'1',toolId:llvm-covtrunk,wrap:'1'),l:'5',n:'0',o:'llvm-cov+(clang-only)+x86-64+clang+(assertions+trunk)+(Editor+%231,+Compiler+%231)',t:'0')),k:33.33333333333333,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4).


test.c 

```c
// (1) macros defined in a system header
#include <test.h>

int buf[100];
int a, b, c;

int main(void) {
    if ( FOO(buf) && a && b )
 return 1;
    if ( BAR(buf) && a && b )
        return 2;
    return 3;
}
```

test.h

```c
#define FOO(x) ( x[0] && x[1] )
#define BAR(x) ( ((int *)x)[0] && ((int *)x)[1] ) // (2) cast
```

Expressions involving `FOO` or `BAR` exhibit different behaviors in terms of MC/DC: different numbers  of conditions are reported

```text
    7| 1|int main(void) {
    8|                   1|    if ( FOO(buf) && a && b )
  -------------------------------
  |---> MC/DC Decision Region (8:10) to (8:28)
  |
  |  Number of Conditions: 4
  |     Condition C1 --> (8:10)
 |     Condition C2 --> (8:10)
  |     Condition C3 --> (8:22)
  | Condition C4 --> (8:27)
  |
  |  Executed MC/DC Test Vectors:
  |
  | C1, C2, C3, C4    Result
  |  1 { F,  -,  -,  -  = F      }
  |
  | C1-Pair: not covered
  |  C2-Pair: not covered
  |  C3-Pair: not covered
 |  C4-Pair: not covered
  |  MC/DC Coverage for Decision: 0.00%
  |
 -------------------------------
    9|                   0|        return 1;
   10|                   1|    if ( BAR(buf) && a && b )
 -------------------------------
  |---> MC/DC Decision Region (10:10) to (10:28)
  |
  |  Number of Conditions: 3
  |     Condition C1 --> (10:10)
  |     Condition C2 --> (10:22)
  |     Condition C3 --> (10:27)
 |
  |  Executed MC/DC Test Vectors:
  |
  |     C1, C2, C3    Result
  | 1 { F,  -,  -  = F      }
  |
  |  C1-Pair: not covered
  |  C2-Pair: not covered
  |  C3-Pair: not covered
  |  MC/DC Coverage for Decision: 0.00%
 |
  -------------------------------
   11|                   0| return 2;
   12|                   1|    return 3;
   13| 1|}
```

Real-world example: https://sources.debian.org/src/hostname/3.23%2Bnmu1/hostname.c/#L312

cc: @evodius96 

_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to