Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible shift by negative amount in modules arm_lms_norm_q31 and am_lms_norm_q15 #1567

Open
localuser2 opened this issue Oct 6, 2022 · 1 comment

Comments

@localuser2
Copy link

Compiling current CMSIS for Host platfom (AMD64) while gcc's static code analysis feature is active results in serious looking errors.

GCC version:

$ gcc --version
gcc (Ubuntu 11.2.0-19ubuntu1) 11.2.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

GCC arguments:

/usr/bin/x86_64-linux-gnu-gcc -DARM_MATH_LOOPUNROLL -D__GNUC_PYTHON__ -I/home/klose/projects/MARS2/mars/cxx/libraries/mars-processing/src/CMSIS/CMSIS/DSP/PrivateInclude -I/home/klose/projects/MARS2/mars/cxx/libraries/mars-processing/src/CMSIS/CMSIS/DSP/Include -g -Og -Wall -Wextra -Werror -I /home/klose/projects/MARS2/mars/dev_policies/cxx/cmake/../include/ -fanalyzer -MD -MT mars-processing-bin/src/cmsis_dsp_bin/FilteringFunctions/CMakeFiles/CMSISDSPFiltering.dir/arm_lms_norm_q15.c.obj -MF CMakeFiles/CMSISDSPFiltering.dir/arm_lms_norm_q15.c.obj.d -o CMakeFiles/CMSISDSPFiltering.dir/arm_lms_norm_q15.c.obj -c /home/klose/projects/MARS2/mars/cxx/libraries/mars-processing/src/CMSIS/CMSIS/DSP/Source/FilteringFunctions/arm_lms_norm_q15.c

GCC code analyzer warnings (with the configuration shown above this are errors due to -Werror):

/home/klose/projects/MARS2/mars/cxx/libraries/mars-processing/src/CMSIS/CMSIS/DSP/Source/FilteringFunctions/arm_lms_norm_q31.c:189:9: error: shift by negative count (‘-1’) [-Werror=analyzer-shift-count-negative]
  189 |     w = clip_q63_to_q31(((q63_t) errorXmu * oneByEnergy) >> (31 - postShift));
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  ‘arm_lms_norm_q31’: events 1-2
    |
    |  102 |   while (blkCnt > 0U)
    |      |          ~~~~~~~^~~~
    |      |                 |
    |      |                 (1) following ‘true’ branch (when ‘blkCnt != 0’)...
    |......
    |  105 |     *pStateCurnt++ = *pSrc;
    |      |     ~            
    |      |     |
    |      |     (2) ...to here
    |
  ‘arm_lms_norm_q31’: event 3
    |
    |/home/klose/projects/MARS2/mars/cxx/libraries/mars-processing/src/CMSIS/CMSIS/DSP/Include/dsp/none.h:65:10:
    |   65 |       if (data == 0U) { return 32U; }
    |      |          ^
    |      |          |
    |      |          (3) following ‘true’ branch...
    |
  ‘arm_lms_norm_q31’: events 4-6
    |
    |/home/klose/projects/MARS2/mars/cxx/libraries/mars-processing/src/CMSIS/CMSIS/DSP/Include/dsp/utils.h:63:31:
    |   63 |       signBits = ((uint32_t) (__CLZ( in) - 1));
    |      |                               ^~~~~~~~~~
    |      |                               |
    |      |                               (4) ...to here
    |......
    |   82 |     for (i = 0U; i < 2U; i++)
    |      |                  ~~~~~~        
    |      |                    |
    |      |                    (5) following ‘true’ branch (when ‘i <= 1’)...
    |   83 |     {
    |   84 |       tempVal = (uint32_t) (((q63_t) in * out) >> 31);
    |      |       ~~~~~~~                  
    |      |       |
    |      |       (6) ...to here
    |
  ‘arm_lms_norm_q31’: event 7
    |
    |/home/klose/projects/MARS2/mars/cxx/libraries/mars-processing/src/CMSIS/CMSIS/DSP/Source/FilteringFunctions/arm_lms_norm_q31.c:189:9:
    |  189 |     w = clip_q63_to_q31(((q63_t) errorXmu * oneByEnergy) >> (31 - postShift));
    |      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    |      |         |
    |      |         (7) shift by negative amount here (‘-1’)
    |
cc1: all warnings being treated as errors
make[2]: *** [mars-processing-bin/src/cmsis_dsp_bin/FilteringFunctions/CMakeFiles/CMSISDSPFiltering.dir/build.make:1420: mars-processing-bin/src/cmsis_dsp_bin/FilteringFunctions/CMakeFiles/CMSISDSPFiltering.dir/arm_lms_norm_q31.c.obj] Fehler 1
make[2]: *** Auf noch nicht beendete Prozesse wird gewartet …
/home/klose/projects/MARS2/mars/cxx/libraries/mars-processing/src/CMSIS/CMSIS/DSP/Include/dsp/utils.h: In function ‘arm_lms_norm_q15’:
/home/klose/projects/MARS2/mars/cxx/libraries/mars-processing/src/CMSIS/CMSIS/DSP/Source/FilteringFunctions/arm_lms_norm_q15.c:185:45: error: shift by negative count (‘-1’) [-Werror=analyzer-shift-count-negative]
  185 |     acc = (((q31_t) errorXmu * oneByEnergy) >> (15 - postShift));
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
  ‘arm_lms_norm_q15’: events 1-2
    |
    |  102 |   while (blkCnt > 0U)
    |      |          ~~~~~~~^~~~
    |      |                 |
    |      |                 (1) following ‘true’ branch (when ‘blkCnt != 0’)...
    |......
    |  105 |     *pStateCurnt++ = *pSrc;
    |      |     ~            
    |      |     |
    |      |     (2) ...to here
    |
  ‘arm_lms_norm_q15’: event 3
    |
    |/home/klose/projects/MARS2/mars/cxx/libraries/mars-processing/src/CMSIS/CMSIS/DSP/Include/dsp/none.h:65:10:
    |   65 |       if (data == 0U) { return 32U; }
    |      |          ^
    |      |          |
    |      |          (3) following ‘true’ branch...
    |
  ‘arm_lms_norm_q15’: events 4-6
    |
    |/home/klose/projects/MARS2/mars/cxx/libraries/mars-processing/src/CMSIS/CMSIS/DSP/Include/dsp/utils.h:114:30:
    |  114 |       signBits = ((uint32_t)(__CLZ( in) - 17));
    |      |                              ^~~~~~~~~~
    |      |                              |
    |      |                              (4) ...to here
    |......
    |  133 |     for (i = 0U; i < 2U; i++)
    |      |                  ~~~~~~       
    |      |                    |
    |      |                    (5) following ‘true’ branch (when ‘i <= 1’)...
    |  134 |     {
    |  135 |       tempVal = (uint32_t) (((q31_t) in * out) >> 15);
    |      |       ~~~~~~~                 
    |      |       |
    |      |       (6) ...to here
    |
  ‘arm_lms_norm_q15’: event 7
    |
    |/home/klose/projects/MARS2/mars/cxx/libraries/mars-processing/src/CMSIS/CMSIS/DSP/Source/FilteringFunctions/arm_lms_norm_q15.c:185:45:
    |  185 |     acc = (((q31_t) errorXmu * oneByEnergy) >> (15 - postShift));
    |      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
    |      |                                             |
    |      |                                             (7) shift by negative amount here (‘-1’)
    |
@JonatanAntoni
Copy link
Member

Hi @localuser2,

Please take note that CMSIS-DSP has moved into its own repository at https://github.com/ARM-software/CMSIS-DSP. Please consider raising your issue over there.

Thanks,
Jonatan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants