From cd4b16c0827f1f96aad19fb6e8952e03e419389d Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Thu, 28 Dec 2023 17:12:24 +0100 Subject: [PATCH] coccinelle: drop a couple of FIXMEs Turns out Coccinelle can handle compound literals just fine, the parsing errors were caused by incorrectly parsed macros in code before the literals, so let's just provide simplified versions for such macros. The parsing error in `Type *foo[ELEMENTSOF(bar)] = {};` is actually harmless; it occurs only when creating an array of pointers for a type that's in an external header and it occurs only on the first parser's pass, subsequent passes resolve the type correctly. Also, unset ENABLE_DEBUG_HASHMAP, so Coccinelle doesn't expand the hashmap debug macros. As for the remaining FIXMEs, I opened a couple of issues in the Coccinelle upstream to see if they can be fixed there (or at least properly analyzed). --- coccinelle/parsing_hacks.h | 16 +++++++++------- coccinelle/run-coccinelle.sh | 1 + 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/coccinelle/parsing_hacks.h b/coccinelle/parsing_hacks.h index 0b2f690f54e..9e77e514dd0 100644 --- a/coccinelle/parsing_hacks.h +++ b/coccinelle/parsing_hacks.h @@ -2,12 +2,11 @@ /* FIXME * - issues with parsing stuff like - * * int foo[ELEMENTSOF(bar)] = {}; - * * validchars = UPPERCASE_LETTERS DIGITS; - * * multiline compound literals (some instances) - * * compound literals in function calls (some instances) - * * keywords in macro invocations like FOREACH_DIRENT_ALL(de, d, return -errno) - * (also, see FIXME in the TEST stuff below) + * - validchars = UPPERCASE_LETTERS DIGITS; + * - see: https://github.com/coccinelle/coccinelle/issues/341 + * - keywords in macro invocations like FOREACH_DIRENT_ALL(de, d, return -errno) + * - see: https://github.com/coccinelle/coccinelle/issues/340 + * - also see the FIXME in the TEST() stuff below */ /* This file contains parsing hacks for Coccinelle (spatch), to make it happy with some of our more complex @@ -62,8 +61,9 @@ /* Coccinelle doesn't know this keyword, so just drop it, since it's not important for any of our rules. */ #define thread_local -/* Coccinelle fails to get this one from the included headers, so let's just drop it. */ +/* Coccinelle fails to parse these from the included headers, so let's just drop them. */ #define PAM_EXTERN +#define STACK_OF(x) /* Mark a couple of iterator explicitly as iterators, otherwise Coccinelle gets a bit confused. Coccinelle * can usually infer this information automagically, but in these specific cases it needs a bit of help. */ @@ -74,7 +74,9 @@ #define LIST_FOREACH(name, i, head) YACFE_ITERATOR #define ORDERED_HASHMAP_FOREACH(e, h) YACFE_ITERATOR #define SET_FOREACH(e, s) YACFE_ITERATOR +#define STRV_FOREACH_BACKWARDS YACFE_ITERATOR /* Coccinelle really doesn't like multiline macros that are not in the "usual" do { ... } while(0) format, so * let's help it a little here by providing simplified one-line versions. */ #define CMSG_BUFFER_TYPE(x) union { uint8_t align_check[(size) >= CMSG_SPACE(0) && (size) == CMSG_ALIGN(size) ? 1 : -1]; } +#define SD_ID128_MAKE(...) ((const sd_id128) {}) diff --git a/coccinelle/run-coccinelle.sh b/coccinelle/run-coccinelle.sh index bb49c8e0073..d4bccdc505b 100755 --- a/coccinelle/run-coccinelle.sh +++ b/coccinelle/run-coccinelle.sh @@ -74,6 +74,7 @@ for script in "${SCRIPTS[@]}"; do --recursive-includes \ --include-headers-for-types \ --undefined SD_BOOT \ + --undefined ENABLE_DEBUG_HASHMAP \ --macro-file-builtins "coccinelle/parsing_hacks.h" \ --smpl-spacing \ --sp-file "$script" \