summaryrefslogtreecommitdiffstats
path: root/coccinelle/run-coccinelle.sh (follow)
Commit message (Collapse)AuthorAgeFilesLines
* coccinelle: drop a couple of FIXMEsFrantisek Sumsal2024-01-021-0/+1
| | | | | | | | | | | | | | | | | | 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: re-indent commentsYu Watanabe2023-12-281-4/+4
|
* Merge pull request #30639 from mrc0mmand/more-cocci-shenanigansYu Watanabe2023-12-271-17/+10
|\ | | | | Another batch of Coccinelle tweaks
| * coccinelle: dial back warnings about performanceFrantisek Sumsal2023-12-271-8/+2
| | | | | | | | | | | | | | | | Turns out I _really_ underestimated the impact of --include-headers-for-types, as it significantly reduces both runtime and storage penalties. For example, on my machine the runtime of uncached run goes down from ~15 minutes to ~2 minutes, and similarly the total storage needed by the cache goes from ~15 GiB down to ~3 GiB.
| * coccinelle: help Coccinelle with some more complex macrosFrantisek Sumsal2023-12-271-7/+1
| | | | | | | | | | | | | | | | | | | | Drop the original macro file, since it's not needed anymore thanks to resolving includes properly, but introduce a similar file - parsing_hacks.h - that helps Coccinelle in some specific corner cases. This eliminates most of the outstanding parsing errors in source files. The remaining ones are limitations of the parsing engine (see the FIXMEs in pasing_hacks.h) and need further investigation.
| * coccinelle: search the system include path for header files as wellFrantisek Sumsal2023-12-271-1/+4
| | | | | | | | | | | | | | Since Coccinelle is originally a kernel tool, it doesn't search the system include path by default for header files. Without this we're missing a lot of types provides by stdlib (and other libraries we make use of).
| * coccinelle: explicitly undefine SD_BOOTFrantisek Sumsal2023-12-261-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | So Coccinelle doesn't pull in includes guarded by #if SD_BOOT. For example: $ head -n5 main.c #if FOO #include "foo.h" #else #include "bar.h" #endif $ spatch --verbose-includes --recursive-includes --sp-file zz-drop-braces.cocci main.c init_defs_builtins: /usr/lib64/coccinelle/standard.h HANDLING: main.c including ./foo.h including ./bar.h $ spatch --verbose-includes --recursive-includes --sp-file zz-drop-braces.cocci main.c --undefined FOO init_defs_builtins: /usr/lib64/coccinelle/standard.h HANDLING: main.c including ./bar.h
* | coccinelle: fix typoYu Watanabe2023-12-261-2/+2
|/
* coccinelle: rework how we run the Coccinelle transformationsFrantisek Sumsal2023-12-251-4/+47
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Turns out that the original way we did things was quite broken, as it skipped a _lot_ of code. This was because we just threw everything into one pile and tried to spatch it, but this made Coccinelle sad, like when man page examples redefined some of our macros, causing typedef conflicts. For example, with a minimal reproducer that defines a cleanup macro in two source files, Coccinelle has no issues when spatch-ing each one separately: $ spatch --verbose-parsing --sp-file zz-drop-braces.cocci main.c init_defs_builtins: /usr/lib64/coccinelle/standard.h HANDLING: main.c SPECIAL NAMES: adding _cleanup_ as a attribute with arguments SPECIAL NAMES: adding _cleanup_free_ as a attribute $ spatch --verbose-parsing --sp-file zz-drop-braces.cocci logcontrol-example.c init_defs_builtins: /usr/lib64/coccinelle/standard.h HANDLING: logcontrol-example.c SPECIAL NAMES: adding _cleanup_ as a attribute with arguments But when you try to spatch both of them at once, Coccinelle starts complaining and skipping the "bad" code: $ spatch --verbose-parsing --sp-file zz-drop-braces.cocci main.c logcontrol-example.c init_defs_builtins: /usr/lib64/coccinelle/standard.h HANDLING: main.c logcontrol-example.c SPECIAL NAMES: adding _cleanup_ as a attribute with arguments SPECIAL NAMES: adding _cleanup_free_ as a attribute remapping: _cleanup_ to an ident in macro name ERROR-RECOV: found sync end of #define, line 44 parsing pass2: try again ERROR-RECOV: found sync end of #define, line 44 parse error = File "logcontrol-example.c", line 44, column 21, charpos = 1719 around = '__attribute__', whole content = #define _cleanup_(f) __attribute__((cleanup(f))) badcount: 2 bad: #include <systemd/sd-journal.h> bad: BAD:!!!!! #define _cleanup_(f) __attribute__((cleanup(f))) This was, unfortunately, hidden as it is visible only with --verbose-parsing (or --parse-error-msg). Another issue was how we handled includes. The original way of throwing them into the pile of source files doesn't really work, leading up to similar issues as above. The better way is to let Coccinelle properly resolve all includes by telling it where to find our own include files (basically the same thing we already do during compilation). After fixing all this, Coccinelle now has a chance to process much more of our code (there are still some issues in more complex macros, but that requires further investigation). However, there's a huge downside from all of this - doing a _proper_ code analysis is surprisingly time and resource heavy; meaning that processing just one Coccinelle rule now takes 15 - 30 minutes. To make this slightly less painful, Coccinelle supports caching the generated ASTs, which actually helps a lot - it gets the runtime of one rule from 15 - 30 minutes down to ~1 minute. It, of course, has its own downside - the cache is _really_ big (ATTOW the cache takes ~15 GiB). However, even with the aggressive AST caching you're still looking at ~1 hour for one full Coccinelle run, which is a bit annoying, but I guess that's the price of doing things _properly_ (but I'll definitely look into ways of further optimizing this).
* coccinelle: respect spacing from the semantic patchFrantisek Sumsal2023-03-181-1/+1
|
* Change all fixed-path bash shebangs to /u/b/env bash outside test/наб2021-12-121-1/+2
|
* ci: use LGPLv2+ for all our ci configurationZbigniew Jędrzejewski-Szmek2021-10-011-0/+1
|
* ci: shellcheck-ify CI scriptsFrantisek Sumsal2021-09-291-11/+14
|
* coccinelle: filter out a couple of 'false-positive' transformationsFrantisek Sumsal2021-03-181-0/+1
| | | | | | | | | | * flag-set.cocci: perform the transformation only if the second argument is a constant * sd-journal/lookup3.c: skip the cocci completely for this file, since it's not "ours" * strjoina.cocci: skip the transformation on the "test_strjoina" test, since it intentionally tests the "incorrect" expression we're trying to transform (the same thing was already done in strjoin.cocci)
* coccinelle: correctly resolve our own macrosFrantisek Sumsal2020-10-091-2/+2
| | | | | | | | Coccinelle can't do this automagically and requires we supply it respective header files. Unfortunately, the option for this (--macro-file=) can be used only once, so let's create our own macro file by collecting macros needed for the semantic parser to be happy.
* coccinelle: drop the custom isomorphismsFrantisek Sumsal2020-10-041-2/+1
| | | | | | | | My former dumb me didn't read the documentation properly, so with the introduction of custom isomorphisms I caused two issues: 1) Masked all standard isomorphisms defined by Coccinelle 2) Replace the original issue with a completely new one
* coccinelle: exclude certain paths from the transformationsFrantisek Sumsal2019-04-291-2/+17
| | | | | | There's no point in running these transformation for certain files, mainly anything from src/boot/efi and src/shared/linux, as this code doesn't have access to our internal utility functions
* coccinelle: add explicit statement isomorphismsFrantisek Sumsal2019-04-271-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | Coccinelle needs a custom isomorphism file with rules (isomorphisms) how to correctly rewrite conditions with explicit NULL checks (i.e. if (ptr == NULL)) to their shorter form (i.e. if (!ptr)). Coccinelle already contains such isomorphisms in its default .iso file, however, they're in the opposite direction, which results in useless output from coccinelle/equals-null.cocci. With this fix, `spatch` should no longer report patches like: @@ -628,8 +628,9 @@ static int path_deserialize_item(Unit *u f = path_result_from_string(value); if (f < 0) log_unit_debug(u, "Failed to parse result value: %s", value); - else if (f != PATH_SUCCESS) - p->result = f; + else {if (f != PATH_SUCCESS) + p->result = f; + } } else log_unit_debug(u, "Unknown serialization key: %s", key);
* scripts: use 4 space indentationZbigniew Jędrzejewski-Szmek2019-04-121-13/+13
| | | | | | | | | | | | | | | | | | We had all kinds of indentation: 2 sp, 3 sp, 4 sp, 8 sp, and mixed. 4 sp was the most common, in particular the majority of scripts under test/ used that. Let's standarize on 4 sp, because many commandlines are long and there's a lot of nesting, and with 8sp indentation less stuff fits. 4 sp also seems to be the default indentation, so this will make it less likely that people will mess up if they don't load the editor config. (I think people often use vi, and vi has no support to load project-wide configuration automatically. We distribute a .vimrc file, but it is not loaded by default, and even the instructions in it seem to discourage its use for security reasons.) Also remove the few vim config lines that were left. We should either have them on all files, or none. Also remove some strange stuff like '#!/bin/env bash', yikes.
* cocinelle: use GNU parallel to run spatchZbigniew Jędrzejewski-Szmek2018-06-131-2/+8
| | | | | | spatch is single-threaded, i.e. slow. On my machine it allocates 5 GB of memory and starts swapping, which makes it even slower. Using parallel makes the whole thing pleasantly fast.
* tools: make various scripts find the top-levle git dir automaticallyLennart Poettering2018-06-071-1/+2
|
* coccinelle: add option to make changes in placeZbigniew Jędrzejewski-Szmek2018-06-041-2/+10
|
* coccinelle: run spatch just on version-controlled filesZbigniew Jędrzejewski-Szmek2018-06-041-2/+5
| | | | | | | Also, allow run-cocinnelle.sh to be started from any directory. Unfortunately set -x does not work nicely anymore, because the list is too verbose. Replace it by an echo line.
* run-coccinelle.sh: use set -x for showing command line of "spatch"Lennart Poettering2018-03-231-4/+3
| | | | | Let's make sure run-coccinelle.sh generates similar output as run-integration-tests.sh, hence use the same "set -x" logic.
* coccinelle: slightly improve run-coccinelle.shLennart Poettering2018-02-281-2/+2
| | | | | | Let's include the command line to use to get the requested output. This makes it easy to copy/paste the command line out, and add "--in-place" to actually apply the changes "run-coccinelle.sh" outputs.
* coccinelle: drop empty-if.cocci scriptLennart Poettering2018-02-271-1/+0
| | | | | | It doesn't work, spits out only rubbish and was already excluded of run-coccinelle.sh. It's a pitty it doesn't work, but let's drop this dead piece of code for now.
* coccinelle: improve run-coccinelle.sh to take list of scripts to runLennart Poettering2017-12-071-1/+1
| | | | | Let's tweak run-coccinelle.sh to optionally take a list of scripts to run. If not specified, run all scripts, as before.
* coccinelle: add a run-coccinelle.sh script that runs all scriptsLennart Poettering2017-11-291-0/+11
One day we should start running something like this as part of CI so that non-well-formed commits are not even accepted...