Skip to content

Conversation

@gilles-peskine-arm
Copy link
Contributor

Check that macros are defined before conditionals on these macros. This is useful as a sanity check on our headers. Note that some false positives are expected.

Uses pcpp.


When a project macro (MBEDTLS_xxx, PSA_xxx, TF_PSA_CRYPTO_xxx) is used in
a preprocessor conditional, there should normally be a conditional #define
before the #if directive that uses this macro. This script prints macros
used in conditionals for which there is no previous #define.

#line 42 "crypto_config.h"
//#define MBEDTLS_OPTION    // the script works as with config.py realfull
#line 1 "some_header.h"
#if MBEDTLS_OPTION          // <-- ok (commented-out define in config.h)
#define MBEDTLS_INTERNAL
#endif
#if MBEDTLS_INTERNAL        // <-- ok (conditional define above)
#endif
#if MBEDTLS_VALUE           // <-- flagged
#endif
int x = MBEDTLS_VALUE;      // <-- ignored (only pp directives are checked)
#define MBEDTLS_VALUE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: In Development

Development

Successfully merging this pull request may close these issues.

1 participant