Menu

why valueflow does not get the value of the whole expression

wy163
2025-01-15
2025-01-17
  • wy163

    wy163 - 2025-01-15

    HI,
    I used the cppcheck with --debug to see the value flow. The target file is as below.

    int func(int x) {
        int y = 1 + x * x;
        return y;
    }
    
    void main() {
        func(1);
        func(2);
    }
    

    I got the output from the cppcheck. I find that the possible values of x and x * x are listed, but why the token y is "always symbolic". Why the possible values of 'y' , '+', or '=' in the expression 'y = 1 + x * x' are no listed? Thanks!

    ##file ../cppcheck-2.16.0_new/wy_test/test/valueflow.c
    1: int func ( int x@var1 ) {
    2: int y@var2 ; y@var2 =@exprUNIQUE 1 +@exprUNIQUE x@var1 *@exprUNIQUE x@var1 ;
    3: return y@var2 ;
    4: }
    5:
    6: void main ( ) {
    7: func (@exprUNIQUE 1 ) ;
    8: func (@exprUNIQUE 2 ) ;
    9: }
    
    
    
    ##Value flow
    File ../cppcheck-2.16.0_new/wy_test/test/valueflow.c
    Line 2
      1 always 1
      x possible {1@1,2@2}
      * possible {1@1,4@2}
      x possible {1@1,2@2}
    Line 3
      y always symbolic=(1+x*x)
    Line 7
      1 always 1
    Line 8
      2 always 2
    
     
  • Daniel Marjamäki

    Good question.

    For me, latest git HEAD says:

    ##Value flow
    File test1.c
    Line 2
      1 always 1
      + possible {2,5}
      x possible {1@1,2@2}
      * possible {1@1,4@2}
      x possible {1@1,2@2}
    Line 3
      y {symbolic=(1+x*x),2,5}
    Line 7
      1 always 1
    Line 8
      2 always 2
    

    I get the same output as you with 2.16.0 and it's not optimal. I am not sure where/when it was fixed.

     

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.