Critical Compilation Warning in Generated Model for CMSIS Target

Critical Compilation Warning in Generated Model for CMSIS Target

I am facing a critical compilation warning when I try to compile a model generated for CMSIS target and I appreciate your attention into the matter.

Summary

Below is the generated code snippet that results in warning by the compiler:

TVM_DLL int32_t tvmgen_default_cmsis_nn_main_5(int8_t* input_, int8_t* filter_, int32_t* bias_, int8_t* output_, uint8_t* global_const_workspace_14_var, uint8_t* global_workspace_15_var) {
  // ...
  arm_cmsis_nn_status status = arm_fully_connected_s8(&context, &fc_params, &quant_params, &input_dims, input_, &filter_dims, filter_, &bias_dims, bias_, &output_dims, output_);
  switch (!status) {
  case ARM_CMSIS_NN_SUCCESS: break;
  case ARM_CMSIS_NN_ARG_ERROR: return -1;
  case ARM_CMSIS_NN_NO_IMPL_ERROR: return -1;
  }
  return 0;
}
    }

The warning is:

default_lib2.c: In function 'tvmgen_default_cmsis_nn_main_0':
default_lib2.c:41:3: warning: switch condition has boolean value [-Wswitch-bool]
   41 |   switch (!status) {
      |   ^~~~~~

As hinted by the compiler, the switch statement returns a boolean value, i.e. 0 or 1, regardless of value of Enum of type arm_cmsis_nn_status . This is obviously erroneous because the function will return 0 in the case of ARM_CMSIS_NN_ARG_ERROR or ARM_CMSIS_NN_NO_IMPL_ERROR, hence, no error.

I would like to give arm_cmsis_nn_status definition below as well for your reference:

typedef enum
{
    ARM_CMSIS_NN_SUCCESS = 0,        /**< No error */
    ARM_CMSIS_NN_ARG_ERROR = -1,     /**< One or more arguments are incorrect */
    ARM_CMSIS_NN_NO_IMPL_ERROR = -2, /**<  No implementation available */
} arm_cmsis_nn_status;

Expected Result

switch statement without the negation !.

Steps to Reproduce

Below is the steps to reproduce the error:

# Check tvmc version:
tvmc --version  # Outputs 0.14.dev163

# Download an example model:
wget https://github.com/tensorflow/tflite-micro/raw/a56087ffa2703b4d5632f024a8a4c899815c31bb/tensorflow/lite/micro/examples/micro_speech/micro_speech.tflite

# Run tvmc to compile the model for CMSIS:
 tvmc compile --target=cmsis-nn,c \
             --target-c-mcpu=cortex-m4 \
             --target-cmsis-nn-mcpu=cortex-m4 \
             --runtime=crt \
             --executor=aot \
             --executor-aot-interface-api=c \
             --executor-aot-unpacked-api=1 \
             --pass-config tir.usmp.enable=1 \
             --pass-config tir.usmp.algorithm=hill_climb \
             --pass-config tir.disable_storage_rewrite=1 \
             --pass-config tir.disable_vectorize=1 \
             micro_speech.tflite \
             --output-format=mlf \
             --output module.tar \
             -vvvv

# Extract the archive:
mkdir module
tar xvf module.tar --directory=module

# Open the model's `default_lib2.c` with a text editor:
vim module/codegen/host/src/default_lib2.c

# You will notice `!switch` statements on the functions. 

Thanks a lot for your attention.