Menu

False positives from inline assembler

2020-07-13
2020-07-15
  • Simon Large

    Simon Large - 2020-07-13

    This is another AVR problem. I have some old library code which pulls in various register writes depending on which registers are defined in the particular micro's I/O definitions file.

    #ifdef EEARL
            outb(EEARL,addr);    // warning
    #endif
    outb(EEDR,data);    // no warning
    

    I don't really understand why this is an error when the line with EEDR does not generate an error. Neither of those symbols is defined. If I provide the path to the AVR library headers then the error goes away, but analysis is very slow as they are pretty complex headers.

    I get the same sort of errors when comparing with a constant within #ifdef.

    #ifdef EEP_SHADOW_TOP
        if (addr < EEP_SHADOW_TOP) do_this();    // warning
        else if (addr < SOME_UNDEFINED_VALUE) do_that();    // no warning
    #endif
    

    I can silence them by setting an explicit definition, but I'm curious as to why this only raises a warning for the #ifdef case and not for general undefined symbols.

     
  • Daniel Marjamäki

    Do you mean such warnings:

    Skipping configuration 'EEARH;EEARL' since the value of 'EEARH' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.

    By default Cppcheck tries to guess configurations and check all code. It wants to check the code inside the #ifdef. But there is no way for Cppcheck to guess what it should tell the preprocessor that EEARL is. It must tell the preprocessor what EEARL is to check the code inside the #ifdef if it doesn't then the preprocessor will remove the code.

    Cppcheck does not tell the preprocessor what EEDR is.. so that will just be kept as is by the preprocessor.

    As the warnings say; you can fix these warnings either with -D or -U. Ignore them if you don't care that the code is not checked.

     

    Last edit: Daniel Marjamäki 2020-07-15

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.