Menu

Support for builtin functions

2018-10-26
2018-10-29
  • Johann Peter

    Johann Peter - 2018-10-26

    Hi,

    does cppcheck support builtin functions?

    Under gcc I tried:

        uint8_t test[10];
        __builtin_memset(test,0x00,1000); //no error
        memset(test,0x00,1000); //error
    

    The builtin memset does not show as an error.

    If this is not a bug but a feature, can I implement the same checks for builtin functions via library .cfg files?

    Best regards,
    Johann

     

    Last edit: Johann Peter 2018-10-26
  • orbitcowboy

    orbitcowboy - 2018-10-26

    Are you referring to GNU builtin functions?
    If yes, we could extend our gnu.cfg file about these definitions. The corresponding file is available here: https://github.com/danmar/cppcheck/blob/master/cfg/gnu.cfg

     
  • orbitcowboy

    orbitcowboy - 2018-10-27

    Experimental support for __builtin_memset has been added with https://github.com/danmar/cppcheck/commit/b998dcb5aaf76b0eba74fa2ae3c4fa081c75ca68
    Scanning following example

    int main()
    {
        uint8_t buf[42];
        __builtin_memset(buf,0,1000);
    }
    

    gives now
    (error) Buffer is accessed out of bounds: buf

     
  • Daniel Marjamäki

    yes it is possible by cfg file updates.
    I am curious, why do you encounter builtin_memset? I assume you include system headers and your code is corrupted by macros?

     
  • Johann Peter

    Johann Peter - 2018-10-29

    We have an embedded STM32 project (AC6 toolchain). We are fixed on the compiler version and the optimisation lvl. Using gcc builtins gives us a performance boost because the compiler replaces (if possible) the function call with just some ASM instructions. We use the whole bandwith of builtin functions, including stuff like __builtin_ tolower, strlen, memcmp, memcpy etc.

     

    Last edit: Johann Peter 2018-10-29
  • orbitcowboy

    orbitcowboy - 2018-10-29

    Are you intetested providing a Pull Request to support these builtin functions?

     

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.