OK, I have this benchmark from SPLASH2 which I am using to test a tool which I have created. The benchmark has the following struct.
typedef struct _interact {
struct _interact *next ; /* Next entry of the list */
Element *destination ; /* Partner of the interaction */
float formfactor_out ; /* Form factor from this patch */
float formfactor_err ; /* Error of FF */
float area_ratio ; /* Area(this) / Area(dest) */
float visibility ; /* Visibility (0 - 1.0) */
} Interaction ;
Looking into the code, I found that area_ratio is never used. However, in the end, I see that the value of area_ratio is not 0, as it is in the beginning. So I placed a watchpoint on this variable, and surprisingly gdb pointed me to a code which modifies visibility (the variable just below the area_ratio).
Now my question is why is this happening. How come area_ratio is modified by modifing visibility. What are the possibilties? Any clue? I’m really puzzled. Note that I’m testing my program on a 64-bit machine. Maybe 64 bit has to do something with it, but I don’t know!
The code is something like this:
/* Create links and finish the job */
inter = get_interaction(process_id) ;
*inter = i12 ;
inter->visibility = VISIBILITY_UNDEF ; // <---- This is what gdb is pointing to
Ah I got it! Actually what is happening is that i12 is a local variable, which is not initialized to 0 and when we perform *inter = i12;, the area_ratio of i12 is assigned to *inter and since i12‘s area_ratio is random and not necessarily 0, that value of area_ratio is assigned to *inter.
And by the way, now I’ve realized that gdb shows the line number of the one below the intended line, so its not pointing to the line inter->visibility = VISIBILITY_UNDEF, but the line *inter = i12;