一句话:通过分析 4,913 个 C 项目的 GCC builtin 使用与演化,量化工具所需支持并揭示现有工具的实现缺陷。
许多工具需要支持 C 编译器内建函数(builtins)才能处理流行项目,但维护者缺乏关于实现哪些 builtins 的指导。本文对 GitHub 上 4,913 个 C 项目的 builtin 使用进行大规模实证研究,分析其使用分布与随时间演化,并对现有工具的支持情况进行系统测试。结果表明,37% 的项目依赖至少一个 builtin;支持 30% 项目只需 10 个 builtins,支持 90% 项目约需 110 个 builtins,成本适中。多数项目随时间不断新增 builtins,说明其并非遗留特性。工具测试发现许多工具部分或完全缺乏 builtin 支持,且若干工具存在错误实现,甚至包括经形式验证的 CompCert 编译器。
C programs can use compiler builtins to provide functionality that the C language lacks. On Linux, GCC provides several thousands of builtins that are also supported by other mature compilers, such as Clang and ICC. Maintainers of other tools lack guidance on whether and which builtins should be implemented to support popular projects. To assist tool developers who want to support GCC builtins, we analyzed builtin use in 4,913 C projects from GitHub. We found that 37% of these projects relied on at least one builtin. Supporting an increasing proportion of projects requires support of an exponentially increasing number of builtins; however, implementing only 10 builtins already covers over 30% of the projects. Since we found that many builtins in our corpus remained unused, the effort needed to support 90% of the projects is moderate, requiring about 110 builtins to be implemented. For each project, we analyzed the evolution of builtin use over time and found that the majority of projects mostly added builtins. This suggests that builtins are not a legacy feature and must be supported in future tools. Systematic testing of builtin support in existing tools revealed that many lacked support for builtins either partially or completely; we also discovered incorrect implementations in various tools, including the formally verified CompCert compiler.