diffkemp icon indicating copy to clipboard operation
diffkemp copied to clipboard

Allow comparison including global variables initializations

Open PLukas2018 opened this issue 8 months ago • 0 comments

When assigning a global struct variable to a local variable, the values with which the global struct variable was initialized are not checked and the following program is evaluated as semantically equal.

 typedef struct {                                                                
     int y;                                                                      
 } b_t;                                                                          
                                                                                 
 typedef struct {                                                                
     b_t x;    // could be also b_t *x                                                                 
 } a_t;                                                                          
                                                                                 
 b_t c = {
-     .y = 4
+     .y = 5
 };                                                                              
                                                                                 
 int main() {                                                                    
     a_t var;                                                                    
     var.x = c; // uses memcpy or store if var.x would be `b_t *x`
     return var.x.y;                                                  
 }

Our current stand on this issue is that changing the initialization of a global variable 'does not change the semantics of programs' but for some types of projects checking if the global struct variables were initialized with the same values could be potentially useful for the user and for analyzing of semantic equality of the programs. In future, the compare command could have an optional option to compare initialization for used global struct variables.

PLukas2018 avatar Apr 16 '25 17:04 PLukas2018