C un C priekšprocesora statiskā analīze

Loading...
Thumbnail Image

Date

Journal Title

Journal ISSN

Volume Title

Publisher

Latvijas Universitāte

Language

N/A

Abstract

Ir ļoti daudz sistēmu, kas atļauj veikt C valodas statisko analīzi. Vairākas no tām pieņem, ka pirmkods ir jāanalizē tikai pēc priekšprocesora fāzes, kur visi priekšprocesora makrosi pirmkodā ir pārvērsti par "tīru" C kodu. Šis pieņēmums var novest pie kļūdām, jo priekšprocesora fāze izmet no koda izteiksmju kopu, kura var atšķirties dažādu kompilāciju ietvaros. Šajā darbā mēs piedāvājam instrumentu, kas atļauj ģenerēt abstrakto sintaktisko koku, kur ir iekļauti gan priekšprocesora, gan C valodas priekšraksti. Darbā tiek apskatīts arī parastais pielietojums mūsu instrumentam, lai atrastu kļūdas kodā pirms priekšprocesora fāzes. Izmantojot mūsu instrumentu, ir iespējams iegūt no koda ar priekšprocesora direktīvām visu iespējamu tīru C valodu pirmkodu. Pēc tam, analizējot katru variantu ar kādu statisko C valodas analizatoru, mēs varam pierādīt, ka pirmkods ir absolūti korekts šī analizatora ietvaros.
There exist many well-known systems for the static analysis of C code. Unfortunately, the majority of these tools only operate after full or selective preprocessing, where preprocessor macros embedded in source files are converted into pure C-language code. The implicit assumption, that sources may be fully or partially stripped of preprocessing directives without consequence, is harmful or even outright erroneous: the preprocessing phase collapses to a set of possible macro expressions, which may differ between compilations. In this document, we introduce a tool generating the full abstract syntax tree of both preprocessor and C statements. We then consider a simple application of this tool for discovering syntactic errors in mixed C and CPP code, where the produced combinations of C and collapsed preprocessor statements are analysed by a front-end, C-only static analysis tool.

Citation

Relation

Endorsement

Review

Supplemented By

Referenced By