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 cgtools: diagnostic desired for undefined behavior C statement

Compiler Team,

My C2000 customer (cgtools v6.4.2) has written some code that has "Undefined" behavior per the ANSI-C99 spec.  Here is an example

int x[10], y[10], i;
void foo() {
    for(i=0; i<10; ) {
        y[i] = x[i++]*x[i++];
    }
}

The ANSI-C spec violation is section 6.5 of the C99 spec:

“Between the previous and next sequence point an object shall have its stored value modified at most once by the evaluation of an expression.”

Very well.  The customer however wants to know if the compiler can flag a diagnostic for such occurrences.  I played around with various compiler options, such as K&R parsing, strict ANSI parsing, Issue Remarks, and so on.  I cannot get the compiler to issue a diagnostic.

Is it possible to get a diagnostic for the above?   (I suspect not)

Customer is pretty vocal that the compiler should be flagging undefined C-statements.  Maybe it should, or maybe not.  Seems reasonable here that the compiler should at least issue a very low level diagnostic (e.g., a remark at least).  Can you comment?

Thank you and regards,

David

 

  • You could try --check_misra=12.13 ...

    % cl2000 --check_misra=12.13 --verbose_diagnostics file.c
    "file.c", line 5: warning: (MISRA-C:2004 12.13/A) The increment (++) and
              decrement (--) operators should not be mixed with other operators in
              an expression
              y[i] = x[i++]*x[i++];
                       ^
    
    "file.c", line 5: warning: (MISRA-C:2004 12.13/A) The increment (++) and
              decrement (--) operators should not be mixed with other operators in
              an expression
              y[i] = x[i++]*x[i++];
                              ^

    If you are feeling very brave, you could turn on all the MISRA rules with --check_misra.  

    This customer probably ought to consider using standalone tools dedicated to this purpose.  An internet search on static code analysis shows many promising links.  The TI compiler will never compete with tools like that.

    Thanks and regards,

    -George