Internships/ProjectIdeas/LibclangRefactoring: Difference between revisions

From QEMU
(Created page with "=== Automated === '''Summary:''' Automated maintenance and checking using clang-query, clang-tidy and libclang Currently QEMU is using a handwritten Perl script taken from th...")
 
 
Line 1: Line 1:
=== Automated ===
=== Automated maintenance and checking using clang-query, clang-tidy and libclang ===
'''Summary:''' Automated maintenance and checking using clang-query, clang-tidy and libclang
'''Summary:''' Convert QEMU's code analysis tools to clang-query, clang-tidy, and libclang


Currently QEMU is using a handwritten Perl script taken from the Linux kernel to
Currently QEMU is using a handwritten Perl script (scripts/checkpatch.pl) taken from the Linux kernel to
check that patches obey the QEMU coding standard.  In addition, the Coccinelle
check that patches obey the QEMU coding standard.  In addition, the Coccinelle
semantic diff tool is used periodically to do maintenance tasks, such as replacing
semantic diff tool is used periodically to do maintenance tasks, such as replacing

Latest revision as of 20:35, 29 March 2022

Automated maintenance and checking using clang-query, clang-tidy and libclang

Summary: Convert QEMU's code analysis tools to clang-query, clang-tidy, and libclang

Currently QEMU is using a handwritten Perl script (scripts/checkpatch.pl) taken from the Linux kernel to check that patches obey the QEMU coding standard. In addition, the Coccinelle semantic diff tool is used periodically to do maintenance tasks, such as replacing idioms that are less safe or harder-to-read with better equivalent code.

This project will look into converting these checks and scripts to use clang-based tools such as clang-query, clang-tidy and libclang. For example, the matching part of the exec_rw_const.cocci script:

@@
expression E1, E2, E3;
@@
(
- cpu_physical_memory_rw(E1, E2, E3, false)
+ cpu_physical_memory_read(E1, E2, E3)
|
- cpu_physical_memory_rw(E1, E2, E3, true)
+ cpu_physical_memory_write(E1, E2, E3)
)

could be rewritten to use the following query:

match callExpr(hasDeclaration(functionDecl(hasName("cpu_physical_memory_rw"))),
               hasArgument(3, integerLiteral().bind("write")))

and a diagnostic could then be implemented using clang-tidy.

The project will cover developing matchers for common "checkpatch.pl" checks and Coccinelle scripts, and integration in the build system and/or CI.

The project can be expanded to 350 hours by adding some of the following:

  • coding style checks (e.g. spacing) using clang tools
  • auto fixing of reported errors

Links:

Details:

  • Project size: 175 hours
  • Required skills: C and C++ programming
  • Optional skills: Python programming (if Python bindings for libclang are used)
  • Desirable skills: knowledge of basic parsing and compilation techniques and terminology
  • Mentor: Paolo Bonzini <pbonzini@redhat.com>