stageGain is uninitialized in RISC-V

Laurent Pinchart laurent.pinchart at ideasonboard.com
Wed May 29 00:43:30 CEST 2024


Hi Dan,

On Tue, May 28, 2024 at 02:54:09PM +0100, Daniel Scally wrote:
> Hello
> 
> On 28/05/2024 03:31, U2FsdGVkX1 wrote:
> > In RISC-V, when optimization is enabled, it will fail to build with
> > the following:
> > ../src/ipa/libipa/exposure_mode_helper.cpp:210:52: error: ‘stageGain’
> > may be used uninitialized [-Werror=maybe-uninitialized]
> >    210 |         shutter = clampShutter(exposure / clampGain(stageGain));
> >        |                                           ~~~~~~~~~^~~~~~~~~~~
> > ../src/ipa/libipa/exposure_mode_helper.cpp:169:16: note: ‘stageGain’
> > was declared here
> >    169 |         double stageGain;
> >        |                ^~~~~~~~~
> >
> > I posted an issue on GitHub and need more people to test it
> > https://github.com/kbingham/libcamera/pull/95
> 
> That's interesting...I feel like the error is...erroneous...either
> gains_ is not empty in which case stageGain is initialised by at least
> one cycle of the for loop or it is empty, in which case it's
> initialised by the guarded statement you moved. What could the
> optimisation be doing to introduce the possibility of the variable
> being used uninitialised?

gcc may not understand that gains_.size() == 0 <=> gains_.empty().

> As to the actual change; declaring stageGain to be 1.0 initially is
> conceptually fine, but as Kieran says the comment would need to be
> tweaked; it can just be split in two with the first two sentences left
> where they are and the last sentence moved to explain why we're
> setting stageGain = 1.0 to begin with.

-- 
Regards,

Laurent Pinchart


More information about the libcamera-devel mailing list