Tool/software: TI C/C++ Compiler
Hello!
Cross-compiling piece of code with Visual Studio I have noticed a warning on use of uninitialized variable, which was not reported by C6000 compiler. I've noticed it in somewhat larger piece masking the bug, but it can be reduced to something like
float sample(short *x) { float sum, a = 0.5, y, b; int i, cnt = 100; for ( i = 0; i < cnt; i++ ) { if ( b < 5) a += x[i]+3.0/4; else a -= x[i]+3.0/4; sum += a; } y = sum / (float) (cnt); return y; }
Compiler does not notice the 'sum' was not initialised prior use.
Complete command line was
'Invoking: C6000 Compiler' "D:/TI/ccsv7/tools/compiler/c6000_7.4.23/bin/cl6x" -mv6600 --abi=eabi -O3 -g --include_path="D:/TI/ccsv7/tools/compiler/c6000_7.4.23/include" --include_path="D:/TI/pdk_C6670_1_1_2_6/packages/ti/csl" --include_path="D:/TI/pdk_C6670_1_1_2_6/packages/ti/drv/pcie" --include_path="D:/TI/pdk_C6670_1_1_2_6/packages/ti/drv/cppi" --include_path="D:/TI/pdk_C6670_1_1_2_6/packages/ti/drv/qmss" --include_path="D:/TI/pdk_C6670_1_1_2_6/packages/ti/platform" --include_path="D:/TI/pdk_C6670_1_1_2_6/packages/ti/drv/fftc" --include_path="D:/TI/dsplib_c66x_3_4_0_0" --define=_L2SRAM2_4_ --define=_PCIE_MSI_ --define=_PCIE_BM_DMA_ --define=_FFT_WINDOW_COMPENSATION_ --define=_INTR_MASK_REG_NOT_IMPLEMENTED_ --define=_REBOOT_ENABLED_ --display_error_number --diag_warning=225 --debug_software_pipeline --optimizer_interlist --opt_for_speed=4 --gen_opt_info=1 -k --src_interlist --preproc_with_compile --preproc_dependency="frame.d_raw" --obj_directory="lte" --cmd_file="configPkg/compiler.opt" "frame.c"
Interestingly, if one comment out 'if' statement in the loop, compiler recognizes empty loop and removes it, but still does not see uninitialized 'sum'. Only when for loop removed compiler reports the problem with sum.
float sample(short *x) { float sum, a = 0.5, y; int i, cnt = 100; for ( i = 0; i < cnt; i++ ) { sum += a; } y = sum / (float) (cnt); return y; }
I'd like to hear from compiler experts, isn't that a bug?
Thanks.