Menu

IAR C compiler extensions mess up Cppcheck

2020-07-11
2020-07-15
  • Simon Large

    Simon Large - 2020-07-11

    The IAR C compiler for embedded MSP430 uses a non-standard syntax to declare variables at absolute locations.

    #define EEP_BASE 0x10000
    const char EEPROM_Variable @ (EEP_BASE + 0);
    

    Cppcheck doesn't like the @ character so it aborts any further processing of the file with syntaxError.

    It's easy to work around this by using a macro to define the absolute variables:

    #ifdef CPPCHECK
        #define MEM_ADDR(x)
    #else
        #define MEM_ADDR(x) @(x)
    #endif
    const char EEPROM_Variable MEM_ADDR(EEP_BASE + 0);
    

    Would you expect cppcheck to handle that sort of compiler extension, or is a macro always going to be needed? I think I've seen that before with a different compiler, although it was many years ago. And to be fair this is a very old IAR compiler. I don't know if they do the same thing now.

     
  • Daniel Marjamäki

    We want to handle that. I even thought we did. Yes I have also seen that syntax with some other compiler, do not remember which one.

    Problem is I don't have any real world such code.

    Do you know if there are any IAR sample project(s) that I can use to test Cppcheck?

     
  • Simon Large

    Simon Large - 2020-07-11

    I couldn't find any sample projects. I found a few files in the compiler directory. Some of them trigger this and some don't. It seems that if the address is a simple number then it is OK, but if the address is an expression then it throws a syntax error.

    Zip file attached. EEP.c is mine, the other two are IAR samples.

     
  • Daniel Marjamäki

    Thanks! I created ticket https://trac.cppcheck.net/ticket/9809

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.