|
1 | 1 | This directory provides examples of Coccinelle (http://coccinelle.lip6.fr/)
|
2 | 2 | semantic patches that might be useful to developers.
|
| 3 | + |
| 4 | +There are two types of semantic patches: |
| 5 | + |
| 6 | + * Using the semantic transformation to check for bad patterns in the code; |
| 7 | + The target 'make coccicheck' is designed to check for these patterns and |
| 8 | + it is expected that any resulting patch indicates a regression. |
| 9 | + The patches resulting from 'make coccicheck' are small and infrequent, |
| 10 | + so once they are found, they can be sent to the mailing list as per usual. |
| 11 | + |
| 12 | + Example for introducing new patterns: |
| 13 | + 67947c34ae (convert "hashcmp() != 0" to "!hasheq()", 2018-08-28) |
| 14 | + b84c783882 (fsck: s/++i > 1/i++/, 2018-10-24) |
| 15 | + |
| 16 | + Example of fixes using this approach: |
| 17 | + 248f66ed8e (run-command: use strbuf_addstr() for adding a string to |
| 18 | + a strbuf, 2018-03-25) |
| 19 | + f919ffebed (Use MOVE_ARRAY, 2018-01-22) |
| 20 | + |
| 21 | + These types of semantic patches are usually part of testing, c.f. |
| 22 | + 0860a7641b (travis-ci: fail if Coccinelle static analysis found something |
| 23 | + to transform, 2018-07-23) |
| 24 | + |
| 25 | + * Using semantic transformations in large scale refactorings throughout |
| 26 | + the code base. |
| 27 | + |
| 28 | + When applying the semantic patch into a real patch, sending it to the |
| 29 | + mailing list in the usual way, such a patch would be expected to have a |
| 30 | + lot of textual and semantic conflicts as such large scale refactorings |
| 31 | + change function signatures that are used widely in the code base. |
| 32 | + A textual conflict would arise if surrounding code near any call of such |
| 33 | + function changes. A semantic conflict arises when other patch series in |
| 34 | + flight introduce calls to such functions. |
| 35 | + |
| 36 | + So to aid these large scale refactorings, semantic patches can be used. |
| 37 | + However we do not want to store them in the same place as the checks for |
| 38 | + bad patterns, as then automated builds would fail. |
| 39 | + That is why semantic patches 'contrib/coccinelle/*.pending.cocci' |
| 40 | + are ignored for checks, and can be applied using 'make coccicheck-pending'. |
| 41 | + |
| 42 | + This allows to expose plans of pending large scale refactorings without |
| 43 | + impacting the bad pattern checks. |
0 commit comments