Unused variables in testsuite

Christophe LYON christophe.lyon@st.com
Fri Apr 28 14:45:00 GMT 2006


Hi all,

While fixing our compiler, I came across strange tests in the GDB 
testsuite: in some source files, some variables are defined but not used 
by the code, but are references in the .exp.

Is there anywhere a requirement that the compiler should allocate unused 
variable under -O0 ?

For instance, consider the test in gdb.cp/m-static.cc , m-static.h, 
m-static1.cc.
You can see that in main() one defines "test4" which is not used, thus 
need not be allocated. Then, using "print test4.elsewhere" under GDB 
fails. [note that in this case the default (empty) constructor for test4 
has no side effects, thus test4 can be eliminated safely]

In the same way, in gdb.mi/var-cmd.c , mi-var-display.exp, you can see 
that function do_special_tests() defines several variables (eg 'u') and 
does not use them, while the .exp file tries to "-var-create u * u".

I modified these tests so that the variables are used, and they now pass 
with our compiler.

May I submit this small patch, or is there a requirement on GCC to 
allocate even unused variables in -O0? (our compiler is not GCC)

Thanks,

Christophe.



More information about the Gdb mailing list