Commit 98e55cf7 authored by vaclav's avatar vaclav
Browse files

Merge branch...

Merge branch 'basop-2320-clang18-msan-use-of-uninitialized-value-in-lib_com-tools_fx-c-1354-16' into 'main'

[non-BE] Resolve [CLANG18] MSAN: use-of-uninitialized-value in ivas_corecoder_enc_reconfig_fx()

See merge request !2717
parents e890da97 2cabdfad
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -118,6 +118,7 @@
#define OPT_2308_FIND_TARGET                            /* VA: Issue 2308, Speeds up computation and improve accuracy of the impulse response */
#define OPT_NBE_2311_HARM_GSC_GAIN                      /* VA: issue 2311: non-BE part of the GSC gain harmonization */
#define FIX_2261_REMOVE_LP_RESCALING                    /* VA: Remove of unnecessary lpc coefficient rescaling */
#define FIX_2320_OOB_SCE_SWITCHING                      /* VA: basop issue 2320: Correct the length of the buffer to be scaled in SCE/CPE switching */

/* ##################### End NON-BE switches ########################### */

+40 −4
Original line number Diff line number Diff line
@@ -236,8 +236,13 @@ ivas_error ivas_corecoder_enc_reconfig_fx(
                st_ivas->hSCE[k]->hCoreCoder[0]->q_old_inp = add( st_ivas->hSCE[k]->hCoreCoder[0]->q_old_inp, shift );
                move16();
                q_com_sce = s_min( q_com_sce, st_ivas->hSCE[k]->hCoreCoder[0]->q_old_inp );
#ifdef FIX_2320_OOB_SCE_SWITCHING
                shift = sub( getScaleFactor16( st_ivas->hSCE[k]->hCoreCoder[0]->input_fx, input_frame ), Q1 );
                scale_sig( st_ivas->hSCE[k]->hCoreCoder[0]->input_fx, input_frame, shift ); /*  st_ivas->hSCE[k]->hCoreCoder[0]->q_inp + shift */
#else
                shift = sub( getScaleFactor16( st_ivas->hSCE[k]->hCoreCoder[0]->input_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ) ), Q1 );
                scale_sig( st_ivas->hSCE[k]->hCoreCoder[0]->input_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ), shift ); /*  st_ivas->hSCE[k]->hCoreCoder[0]->q_inp + shift */
#endif
                st_ivas->hSCE[k]->hCoreCoder[0]->q_inp = add( st_ivas->hSCE[k]->hCoreCoder[0]->q_inp, shift );
                move16();
                q_com_sce = s_min( q_com_sce, st_ivas->hSCE[k]->hCoreCoder[0]->q_inp );
@@ -247,8 +252,13 @@ ivas_error ivas_corecoder_enc_reconfig_fx(
                st_ivas->hSCE[k]->hCoreCoder[0]->q_old_inp32 = add( st_ivas->hSCE[k]->hCoreCoder[0]->q_old_inp32, shift );
                move16();
                q_com_sce32 = s_min( q_com_sce32, st_ivas->hSCE[k]->hCoreCoder[0]->q_old_inp32 );
#ifdef FIX_2320_OOB_SCE_SWITCHING
                shift = sub( getScaleFactor32( st_ivas->hSCE[k]->hCoreCoder[0]->input32_fx, input_frame ), Q1 );
                scale_sig32( st_ivas->hSCE[k]->hCoreCoder[0]->input32_fx, input_frame, shift ); /*  st_ivas->hSCE[k]->hCoreCoder[0]->q_inp + shift */
#else
                shift = sub( getScaleFactor32( st_ivas->hSCE[k]->hCoreCoder[0]->input32_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ) ), Q1 );
                scale_sig32( st_ivas->hSCE[k]->hCoreCoder[0]->input32_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ), shift ); /*  st_ivas->hSCE[k]->hCoreCoder[0]->q_inp + shift */
#endif
                st_ivas->hSCE[k]->hCoreCoder[0]->q_inp32 = add( st_ivas->hSCE[k]->hCoreCoder[0]->q_inp32, shift );
                move16();
                q_com_sce32 = s_min( q_com_sce32, st_ivas->hSCE[k]->hCoreCoder[0]->q_inp32 );
@@ -267,8 +277,13 @@ ivas_error ivas_corecoder_enc_reconfig_fx(
                    st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_old_inp = add( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_old_inp, shift );
                    move16();
                    q_com_cpe = s_min( q_com_cpe, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_old_inp );
#ifdef FIX_2320_OOB_SCE_SWITCHING
                    shift = sub( getScaleFactor16( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_fx, input_frame ), Q1 );
                    scale_sig( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_fx, input_frame, shift ); /* st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp + shift */
#else
                    shift = sub( getScaleFactor16( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ) ), Q1 );
                    scale_sig( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ), shift ); /* st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp + shift */
#endif
                    st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp = add( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp, shift );
                    move16();
                    q_com_cpe = s_min( q_com_cpe, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp );
@@ -278,8 +293,13 @@ ivas_error ivas_corecoder_enc_reconfig_fx(
                    st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_old_inp32 = add( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_old_inp32, shift );
                    move16();
                    q_com_cpe32 = s_min( q_com_cpe32, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_old_inp32 );
#ifdef FIX_2320_OOB_SCE_SWITCHING
                    shift = sub( getScaleFactor32( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input32_fx, input_frame ), Q1 );
                    scale_sig32( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input32_fx, input_frame, shift ); /* st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp + shift */
#else
                    shift = sub( getScaleFactor32( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input32_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ) ), Q1 );
                    scale_sig32( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input32_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ), shift );                                                    /* st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp + shift */
#endif
                    st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp32 = add( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp32, shift );
                    move16();
                    q_com_cpe32 = s_min( q_com_cpe32, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp32 );
@@ -294,10 +314,18 @@ ivas_error ivas_corecoder_enc_reconfig_fx(
                scale_sig( st_ivas->hSCE[k]->hCoreCoder[0]->old_input_signal_fx, input_frame, sub( q_com, st_ivas->hSCE[k]->hCoreCoder[0]->q_old_inp ) ); /* q_com */
                st_ivas->hSCE[k]->hCoreCoder[0]->q_old_inp = q_com;
                move16();
#ifdef FIX_2320_OOB_SCE_SWITCHING
                scale_sig( st_ivas->hSCE[k]->hCoreCoder[0]->input_fx, input_frame, sub( q_com, st_ivas->hSCE[k]->hCoreCoder[0]->q_inp ) ); /* q_com */
#else
                scale_sig( st_ivas->hSCE[k]->hCoreCoder[0]->input_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ), sub( q_com, st_ivas->hSCE[k]->hCoreCoder[0]->q_inp ) );                  /* q_com */
#endif
                st_ivas->hSCE[k]->hCoreCoder[0]->q_inp = q_com;
                move16();
#ifdef FIX_2320_OOB_SCE_SWITCHING
                Copy_Scale_sig_16_32_DEPREC( st_ivas->hSCE[k]->hCoreCoder[0]->input_buff_fx, st_ivas->hSCE[k]->hCoreCoder[0]->input_buff32_fx, shl( input_frame, 1 ), Q6 ); /* Q6 + q_com */
#else
                Copy_Scale_sig_16_32_DEPREC( st_ivas->hSCE[k]->hCoreCoder[0]->input_buff_fx, st_ivas->hSCE[k]->hCoreCoder[0]->input_buff32_fx, L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS ) + L_FRAME48k, Q6 );               /* Q6 + q_com */
#endif
                st_ivas->hSCE[k]->hCoreCoder[0]->q_inp32 = add( Q6, q_com );
                st_ivas->hSCE[k]->hCoreCoder[0]->q_old_inp32 = add( Q6, q_com );
                move16();
@@ -314,10 +342,18 @@ ivas_error ivas_corecoder_enc_reconfig_fx(
                    scale_sig( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->old_input_signal_fx, input_frame, sub( q_com, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_old_inp ) ); /* q_com */
                    st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_old_inp = q_com;
                    move16();
#ifdef FIX_2320_OOB_SCE_SWITCHING
                    scale_sig( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_fx, input_frame, sub( q_com, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp ) ); /* q_com */
#else
                    scale_sig( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ), sub( q_com, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp ) );    /* q_com */
#endif
                    st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp = q_com;
                    move16();
#ifdef FIX_2320_OOB_SCE_SWITCHING
                    Copy_Scale_sig_16_32_DEPREC( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff_fx, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff32_fx, shl( input_frame, 1 ), Q6 ); /* Q6 + q_com */
#else
                    Copy_Scale_sig_16_32_DEPREC( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff_fx, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff32_fx, L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS ) + L_FRAME48k, Q6 ); /* Q6 + q_com */
#endif
                    st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp32 = add( Q6, q_com );
                    st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_old_inp32 = add( Q6, q_com );
                    move16();
+39 −10
Original line number Diff line number Diff line
@@ -130,7 +130,10 @@ ivas_error ivas_cpe_enc_fx(
    Word16 NFFT_inner;
    move16();
    move16();
    Word16 q_com, shift, q_min, gb;
#ifdef FIX_2320_OOB_SCE_SWITCHING
    Word16 input_frame_2;
#endif
    Word16 i, j, q_com, shift, q_min, gb;

    error = IVAS_ERR_OK;
    move32();
@@ -156,6 +159,9 @@ ivas_error ivas_cpe_enc_fx(
     * Initialization - general
     *-----------------------------------------------------------------*/

#ifdef FIX_2320_OOB_SCE_SWITCHING
    input_frame_2 = shl( input_frame, 1 );
#endif
    set16_fx( q_re_im_buf, 0, CPE_CHANNELS );

    tdm_SM_or_LRTD_Pri = 0;
@@ -178,7 +184,7 @@ ivas_error ivas_cpe_enc_fx(
    set16_fx( voicing_fr_fx[0], 0, NB_SUBFR );
    set16_fx( voicing_fr_fx[1], 0, NB_SUBFR );

    FOR( Word16 i = 0; i < CPE_CHANNELS; i++ )
    FOR( i = 0; i < CPE_CHANNELS; i++ )
    {
        set16_zero_fx( fft_buff_fx[i], 2 * L_FFT );
        set16_zero_fx( old_inp_16k_16fx[i], L_INP );
@@ -252,9 +258,9 @@ ivas_error ivas_cpe_enc_fx(
        move16();
    }

    FOR( Word16 i = 0; i < CPE_CHANNELS; i++ )
    FOR( i = 0; i < CPE_CHANNELS; i++ )
    {
        FOR( Word16 j = 0; j < CLDFB_NO_COL_MAX; j++ )
        FOR( j = 0; j < CLDFB_NO_COL_MAX; j++ )
        {
            set_zero_fx( realBuffer_fx[i][j], CLDFB_NO_CHANNELS_MAX );
            set_zero_fx( imagBuffer_fx[i][j], CLDFB_NO_CHANNELS_MAX );
@@ -408,8 +414,13 @@ ivas_error ivas_cpe_enc_fx(
    IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) && EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) )
    {
        gb = find_guarded_bits_fx( sts[0]->encoderLookahead_FB );
#ifdef FIX_2320_OOB_SCE_SWITCHING
        shift = L_norm_arr( sts[1]->old_input_signal32_fx, input_frame_2 );
        shift = s_min( shift, L_norm_arr( sts[0]->old_input_signal32_fx, input_frame_2 ) );
#else
        shift = L_norm_arr( sts[1]->old_input_signal32_fx, shl( input_frame, 1 ) );
        shift = s_min( shift, L_norm_arr( sts[0]->old_input_signal32_fx, shl( input_frame, 1 ) ) );
#endif

        IF( LT_16( shift, gb ) )
        {
@@ -435,10 +446,17 @@ ivas_error ivas_cpe_enc_fx(
     * Temporal inter-channel alignment, stereo adjustment
     *----------------------------------------------------------------*/

#ifdef FIX_2320_OOB_SCE_SWITCHING
    shift = s_min( L_norm_arr( sts[0]->input_buff32_fx, input_frame_2 ), L_norm_arr( sts[1]->input_buff32_fx, input_frame_2 ) );
    q_min = add( sts[0]->q_inp32, sub( shift, find_guarded_bits_fx( input_frame ) ) );
    scale_sig32( sts[1]->input_buff32_fx, input_frame_2, sub( q_min, sts[1]->q_inp32 ) ); /* q_min */
    scale_sig32( sts[0]->input_buff32_fx, input_frame_2, sub( q_min, sts[0]->q_inp32 ) ); /* q_min */
#else
    shift = s_min( L_norm_arr( sts[0]->input_buff32_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ), L_norm_arr( sts[1]->input_buff32_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ) );
    q_min = add( sts[0]->q_inp32, sub( shift, find_guarded_bits_fx( input_frame ) ) );
    scale_sig32( sts[1]->input_buff32_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), sub( q_min, sts[1]->q_inp32 ) ); /* q_min */
    scale_sig32( sts[0]->input_buff32_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), sub( q_min, sts[0]->q_inp32 ) ); /* q_min */
#endif
    sts[0]->q_inp32 = sts[1]->q_inp32 = sts[0]->q_old_inp32 = sts[1]->q_old_inp32 = q_min;
    move16();
    move16();
@@ -447,11 +465,17 @@ ivas_error ivas_cpe_enc_fx(

    stereo_tca_enc_fx( hCPE, input_frame );

#ifdef FIX_2320_OOB_SCE_SWITCHING
    shift = sub( add( L_norm_arr( sts[0]->input_buff32_fx, input_frame_2 ), sts[0]->q_inp32 ), 16 );
    shift = s_min( shift, sub( add( L_norm_arr( sts[1]->input_buff32_fx, input_frame_2 ), sts[1]->q_inp32 ), 16 ) );
    Copy_Scale_sig32_16( sts[0]->input_buff32_fx, sts[0]->input_buff_fx, input_frame_2, sub( add( Q16, shift ), sts[0]->q_inp32 ) ); // shift
    Copy_Scale_sig32_16( sts[1]->input_buff32_fx, sts[1]->input_buff_fx, input_frame_2, sub( add( Q16, shift ), sts[1]->q_inp32 ) ); // shift
#else
    shift = sub( add( L_norm_arr( sts[0]->input_buff32_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ), sts[0]->q_inp32 ), 16 );
    shift = s_min( shift, sub( add( L_norm_arr( sts[1]->input_buff32_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ), sts[1]->q_inp32 ), 16 ) );
    Copy_Scale_sig32_16( sts[0]->input_buff32_fx, sts[0]->input_buff_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), sub( add( Q16, shift ), sts[0]->q_inp32 ) ); // shift
    Copy_Scale_sig32_16( sts[1]->input_buff32_fx, sts[1]->input_buff_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), sub( add( Q16, shift ), sts[1]->q_inp32 ) ); // shift

#endif
    sts[0]->q_inp = sts[1]->q_inp = sts[0]->q_old_inp = sts[1]->q_old_inp = shift;
    move16();
    move16();
@@ -715,12 +739,9 @@ ivas_error ivas_cpe_enc_fx(
        move16();

        /* Determine the energy ratio between the 2 channels */
        tdm_ratio_idx = stereo_tdm_ener_analysis_fx(
            ivas_format,
            hCPE, input_frame, &tdm_SM_or_LRTD_Pri, &tdm_ratio_idx_SM ); /* Q0 */
        tdm_ratio_idx = stereo_tdm_ener_analysis_fx( ivas_format, hCPE, input_frame, &tdm_SM_or_LRTD_Pri, &tdm_ratio_idx_SM ); /* Q0 */

        /* Compute the downmix signal based on the ratio index */

        Word16 tdm_SM_flag;
        IF( hCPE->hStereoTD->tdm_LRTD_flag == 0 )
        {
@@ -842,11 +863,19 @@ ivas_error ivas_cpe_enc_fx(

        // Normalise the input buffer from Q15
        Word16 input_norm, q_inp; //, common_q, fir_delay_len;
#ifdef FIX_2320_OOB_SCE_SWITCHING
        input_norm = L_norm_arr( sts[0]->input32_fx - input_frame, input_frame_2 );
#else
        input_norm = L_norm_arr( sts[0]->input32_fx - input_frame, shl( input_frame, 1 ) );
#endif
        q_inp = sub( add( Q15, input_norm ), 16 );

        // Rescale the old input, input and FIR delay section of input buffer
#ifdef FIX_2320_OOB_SCE_SWITCHING
        Copy_Scale_sig32_16( sts[0]->input32_fx - input_frame, sts[0]->input_fx - input_frame, input_frame_2, sub( add( Q16, q_inp ), Q15 ) ); // Q15 -> q_inp
#else
        Copy_Scale_sig32_16( sts[0]->input32_fx - input_frame, sts[0]->input_fx - input_frame, shl( input_frame, 1 ), sub( add( Q16, q_inp ), Q15 ) ); // Q15 -> q_inp
#endif

        // Update the Q-factors
        sts[0]->q_inp = q_inp;
@@ -1189,7 +1218,7 @@ ivas_error ivas_cpe_enc_fx(
                }
            }

            FOR( Word16 i = 0; i < CPE_CHANNELS; i++ )
            FOR( i = 0; i < CPE_CHANNELS; i++ )
            {
                Copy_Scale_sig_16_32_no_sat( old_inp_12k8_16fx[i], old_inp_12k8_fx[i], L_INP_12k8, Q16 ); // Q(-1) -> Q15
            }