This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

C2000 code generation tools - MISRA 10.1 check problem when working with structures

Hello!

I suspect that MISRA checker doesn't handle structure member's data types correctly. Expression which passes MISRA check with normal variables fails when substituting them with structure members of the same data type. Violation of rule 10.1 is reported.

Here are some test cases to reproduce the problem. They were tested with Code generation tools 6.1.1.

Best regards,

Jernej

Misra_test.h:

#ifndef MISRA_TEST_H_
#define MISRA_TEST_H_

#include <stdint.h>

typedef struct
{
    int16_t var_16;
    int32_t var_32;
} struct_test_t;

extern int16_t Misra_Test_A(struct_test_t *misra_test);
extern int16_t Misra_Test_B(int16_t var1, int16_t var2);
 

#endif /*MISRA_TEST_H_*/

Misra_test.c:

#include "misra_test.h"

#include <stdint.h>

struct_test_t test_structure;


int16_t Misra_Test_A(struct_test_t *misra_test)
{
    int16_t result;
    int32_t var_32;
    
    var_32 = 128000;
    
    result = (int16_t)(var_32 / 25000);    /* MISRA OK */
    
    result = (int16_t)(misra_test->var_32 / 25000);    /* MISRA 10.1 violation message */
    
    return result;
}

int16_t Misra_Test_B(int16_t var1, int16_t var2)
{
    int16_t result;
    int32_t    tmp1;
    int32_t tmp2;
    
    tmp2 = 653948;
    
    if(var1 > 100)    /* MISRA OK */
    {
        result = 100;
    }
    
    if(test_structure.var_16 > 100)    /* MISRA 10.1 violation message */
    {
        result = 100;
    }
    
    tmp1 = tmp2 / 128;    /* MISRA OK */
    
    tmp1 = test_structure.var_32 / 128;    /* MISRA 10.1 violation message */
        
    return result;
}