Menu

how value flow generate the values of a relational operator

wy163
2025-02-06
2025-02-06
  • wy163

    wy163 - 2025-02-06

    Hi, I made a test file and tried to figure out how the value flow works. I attached the input file and the output from the cppcheck.

    #include <stdio.h>
    
    int func();
    
    void main() {
        int k = 0;
        int j = 0;
        k = func();
        if(k > 0 && k < 10) {
            j = k + 1;
            printf("j is %d\n", j);
        }
    }
    
    3: int func ( ) ;
    4:
    5: void main ( ) {
    6: int k@var1 ; k@var1 = 0 ;
    7: int j@var2 ; j@var2 = 0 ;
    8: k@var1 =@exprUNIQUE func (@exprUNIQUE ) ;
    9: if ( k@var1 >@exprUNIQUE 0 &&@exprUNIQUE k@var1 <@exprUNIQUE 10 ) {
    10: j@var2 =@exprUNIQUE k@var1 +@exprUNIQUE 1 ;
    11: printf (@exprUNIQUE "j is %d\n"@exprUNIQUE ,@exprUNIQUE j@var2 ) ;
    12: }
    13: }
    
    Line 6
      = always 0
      0 always 0
    Line 7
      = always 0
      0 always 0
    Line 9
      > always {!<=-1,!>=2}
      0 always 0
      && always {!<=-1,!>=2}
      k {>=1,!<=0}
      < {!<=-1,!>=2,>=1}
      10 always 10
    Line 10
      = {>=2,!<=1,<=10,!>=11}
      k {>=1,!<=0,<=9,!>=10}
      + {>=2,!<=1,<=10,!>=11}
      1 always 1
    Line 11
      "j is %d\n" always "j is %d\n"
      j {symbolic=(k+1),>=2,<=10,!<=1,!>=11}
    

    For line 9,

    if(k > 0 && k < 10) {
    

    we get the output '> always {!<=-1,!>=2}'. As I understand, that '!<=-1' is output is because 'k > 0' and we have 'int k = 0' at the beginning, but I an not sure if I am right. But why '!>=2' is output?
    Thanks a lot!

     
  • CHR

    CHR - 2025-02-06

    The comparison operator is Boolean, so this > always {!<=-1,!>=2} is just the range of possible values.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.